Merge pull request #1005 from openseadragon/loaded

Fixed test issues
This commit is contained in:
Ian Gilman 2016-08-17 10:50:48 -07:00 committed by GitHub
commit 23f3a9fb0d
2 changed files with 44 additions and 37 deletions

View File

@ -211,44 +211,51 @@
asyncTest('Transparent image on top of others', function() { asyncTest('Transparent image on top of others', function() {
viewer.open('/test/data/testpattern.dzi'); viewer.open('/test/data/testpattern.dzi');
// TODO: replace with fully-loaded event listener when available. var density = OpenSeadragon.pixelDensityRatio;
setTimeout(function() {
var imageData = viewer.drawer.context.getImageData(0, 0, 500, 500);
// Pixel 250,250 will be in the hole of the A
var expectedVal = getPixelValue(imageData, 250, 250);
notEqual(expectedVal.r, 0, 'Red channel should not be 0'); viewer.addHandler('open', function() {
notEqual(expectedVal.g, 0, 'Green channel should not be 0'); var firstImage = viewer.world.getItemAt(0);
notEqual(expectedVal.b, 0, 'Blue channel should not be 0'); firstImage.addHandler('fully-loaded-change', function() {
notEqual(expectedVal.a, 0, 'Alpha channel should not be 0'); var imageData = viewer.drawer.context.getImageData(0, 0,
500 * OpenSeadragon.pixelDensityRatio, 500 * density);
viewer.addSimpleImage({ // Pixel 250,250 will be in the hole of the A
url: '/test/data/A.png' var expectedVal = getPixelValue(imageData, 250 * density, 250 * density);
notEqual(expectedVal.r, 0, 'Red channel should not be 0');
notEqual(expectedVal.g, 0, 'Green channel should not be 0');
notEqual(expectedVal.b, 0, 'Blue channel should not be 0');
notEqual(expectedVal.a, 0, 'Alpha channel should not be 0');
viewer.addSimpleImage({
url: '/test/data/A.png',
success: function() {
var secondImage = viewer.world.getItemAt(1);
secondImage.addHandler('fully-loaded-change', function() {
var imageData = viewer.drawer.context.getImageData(0, 0, 500 * density, 500 * density);
var actualVal = getPixelValue(imageData, 250 * density, 250 * density);
equal(actualVal.r, expectedVal.r,
'Red channel should not change in transparent part of the A');
equal(actualVal.g, expectedVal.g,
'Green channel should not change in transparent part of the A');
equal(actualVal.b, expectedVal.b,
'Blue channel should not change in transparent part of the A');
equal(actualVal.a, expectedVal.a,
'Alpha channel should not change in transparent part of the A');
var onAVal = getPixelValue(imageData, 333 * density, 250 * density);
equal(onAVal.r, 0, 'Red channel should be null on the A');
equal(onAVal.g, 0, 'Green channel should be null on the A');
equal(onAVal.b, 0, 'Blue channel should be null on the A');
equal(onAVal.a, 255, 'Alpha channel should be 255 on the A');
start();
});
}
});
}); });
});
// TODO: replace with fully-loaded event listener when available.
setTimeout(function() {
var imageData = viewer.drawer.context.getImageData(0, 0, 500, 500);
var actualVal = getPixelValue(imageData, 250, 250);
equal(actualVal.r, expectedVal.r,
'Red channel should not change in transparent part of the A');
equal(actualVal.g, expectedVal.g,
'Green channel should not change in transparent part of the A');
equal(actualVal.b, expectedVal.b,
'Blue channel should not change in transparent part of the A');
equal(actualVal.a, expectedVal.a,
'Alpha channel should not change in transparent part of the A');
var onAVal = getPixelValue(imageData, 333, 250);
equal(onAVal.r, 0, 'Red channel should be null on the A');
equal(onAVal.g, 0, 'Green channel should be null on the A');
equal(onAVal.b, 0, 'Blue channel should be null on the A');
equal(onAVal.a, 255, 'Alpha channel should be 255 on the A');
start();
}, 500);
}, 500);
function getPixelValue(imageData, x, y) { function getPixelValue(imageData, x, y) {
var offset = 4 * (y * imageData.width + x); var offset = 4 * (y * imageData.width + x);

View File

@ -207,8 +207,8 @@
Util.spyOnce(viewer.drawer, 'setClip', function(rect) { Util.spyOnce(viewer.drawer, 'setClip', function(rect) {
var homeBounds = viewer.viewport.getHomeBounds(); var homeBounds = viewer.viewport.getHomeBounds();
var canvasClip = viewer.viewport var canvasClip = viewer.drawer
.viewportToViewerElementRectangle(homeBounds); .viewportToDrawerRectangle(homeBounds);
var precision = 0.00000001; var precision = 0.00000001;
Util.assertRectangleEquals(rect, canvasClip, precision, Util.assertRectangleEquals(rect, canvasClip, precision,
'clipping should be ' + canvasClip); 'clipping should be ' + canvasClip);