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,11 +211,16 @@
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); viewer.addHandler('open', function() {
var firstImage = viewer.world.getItemAt(0);
firstImage.addHandler('fully-loaded-change', function() {
var imageData = viewer.drawer.context.getImageData(0, 0,
500 * OpenSeadragon.pixelDensityRatio, 500 * density);
// Pixel 250,250 will be in the hole of the A // Pixel 250,250 will be in the hole of the A
var expectedVal = getPixelValue(imageData, 250, 250); var expectedVal = getPixelValue(imageData, 250 * density, 250 * density);
notEqual(expectedVal.r, 0, 'Red channel should not be 0'); notEqual(expectedVal.r, 0, 'Red channel should not be 0');
notEqual(expectedVal.g, 0, 'Green channel should not be 0'); notEqual(expectedVal.g, 0, 'Green channel should not be 0');
@ -223,13 +228,12 @@
notEqual(expectedVal.a, 0, 'Alpha channel should not be 0'); notEqual(expectedVal.a, 0, 'Alpha channel should not be 0');
viewer.addSimpleImage({ viewer.addSimpleImage({
url: '/test/data/A.png' url: '/test/data/A.png',
}); success: function() {
var secondImage = viewer.world.getItemAt(1);
// TODO: replace with fully-loaded event listener when available. secondImage.addHandler('fully-loaded-change', function() {
setTimeout(function() { var imageData = viewer.drawer.context.getImageData(0, 0, 500 * density, 500 * density);
var imageData = viewer.drawer.context.getImageData(0, 0, 500, 500); var actualVal = getPixelValue(imageData, 250 * density, 250 * density);
var actualVal = getPixelValue(imageData, 250, 250);
equal(actualVal.r, expectedVal.r, equal(actualVal.r, expectedVal.r,
'Red channel should not change in transparent part of the A'); 'Red channel should not change in transparent part of the A');
@ -240,15 +244,18 @@
equal(actualVal.a, expectedVal.a, equal(actualVal.a, expectedVal.a,
'Alpha channel should not change in transparent part of the A'); 'Alpha channel should not change in transparent part of the A');
var onAVal = getPixelValue(imageData, 333, 250); var onAVal = getPixelValue(imageData, 333 * density, 250 * density);
equal(onAVal.r, 0, 'Red channel should be null on the A'); 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.g, 0, 'Green channel should be null on the A');
equal(onAVal.b, 0, 'Blue 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'); equal(onAVal.a, 255, 'Alpha channel should be 255 on the A');
start(); 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);