From 3d3f4dbee5a90ed8239b378adb056134df47b019 Mon Sep 17 00:00:00 2001 From: nein09 Date: Thu, 15 Jan 2015 12:36:01 -0800 Subject: [PATCH 1/9] More viewport unit tests - resize, get and set rotation, and the start of zoomBy and zoomTo. --- test/viewport.js | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/test/viewport.js b/test/viewport.js index 35402d87..cf6b020c 100644 --- a/test/viewport.js +++ b/test/viewport.js @@ -118,6 +118,7 @@ }; // Tests start here. + asyncTest('getContainerSize', function() { var openHandler = function(event) { viewer.removeHandler('open', openHandler); @@ -276,6 +277,84 @@ viewer.open(TALL_PATH); // use a different image for homeFillsViewer }); + asyncTest('zoomBy', function(){ + var openHandler = function(event) { + viewer.removeHandler('open', openHandler); + var viewport = viewer.viewport; + + var orig, expected, actual; + for (var i = 0; i < testZoomLevels.length; i++){ + viewport.zoomBy(testZoomLevels[i], null, true); + viewport.update(); // need to call this even with immediately=true + propEqual( + viewport.getZoom(), + testZoomLevels[i], + "Zoomed by the correct amount." + ); + } + + start(); + }; + viewer.addHandler('open', openHandler); + viewer.open(DZI_PATH); + }); + + asyncTest('zoomTo', function(){ + var openHandler = function(event) { + viewer.removeHandler('open', openHandler); + var viewport = viewer.viewport; + + var orig, expected, actual; + for (var i = 0; i < testZoomLevels.length; i++){ + viewport.zoomTo(testZoomLevels[i], null, true); + viewport.update(); // need to call this even with immediately=true + propEqual( + viewport.getZoom(), + testZoomLevels[i], + "Zoomed to the correct level." + ); + } + + start(); + }; + viewer.addHandler('open', openHandler); + viewer.open(DZI_PATH); + }); + + asyncTest('rotation', function(){ + var openHandler = function(event) { + viewer.removeHandler('open', openHandler); + var viewport = viewer.viewport; + + propEqual(viewport.getRotation, 0, "Original rotation should be 0 degrees"); + viewport.setRotation(90); + propEqual(viewport.getRotation, 90, "Rotation should be 90 degrees"); + viewport.setRotation(-75); + propEqual(viewport.getRotation, -75, "Rotation should be -75 degrees"); + start(); + }; + + viewer.addHandler('open', openHandler); + viewer.open(DZI_PATH); + }); + + asyncTest('resize', function() { + var openHandler = function(event) { + viewer.removeHandler('open', openHandler); + var viewport = viewer.viewport; + + for(var i = 0; i < testPoints.length; i++){ + var new_size = testPoints[i].times(viewer.source.dimensions.x); + viewport.resize(new_size); + viewport.update(); + propEqual(viewport.getContainerSize(), new_size, "Viewport resized successfully."); + } + start(); + }; + viewer.addHandler('open', openHandler); + viewer.open(DZI_PATH); + }); + asyncTest('deltaPixelsFromPoints', function() { loopingTestHelper({ testArray: testPoints, From cc382eb263f49a587c25148b2faa5dca81b1701a Mon Sep 17 00:00:00 2001 From: nein09 Date: Fri, 16 Jan 2015 15:45:04 -0800 Subject: [PATCH 2/9] add refpoint to zoom tests. --- test/viewport.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/viewport.js b/test/viewport.js index cf6b020c..063ce24d 100644 --- a/test/viewport.js +++ b/test/viewport.js @@ -291,6 +291,15 @@ testZoomLevels[i], "Zoomed by the correct amount." ); + + // now use a ref point + viewport.zoomBy(testZoomLevels[i], testPoints[i], true); + viewport.update(); + propEqual( + viewport.getZoom(), + testZoomLevels[i], + "Zoomed by the correct amount." + ); } start(); @@ -313,6 +322,15 @@ testZoomLevels[i], "Zoomed to the correct level." ); + + // now use a ref point + viewport.zoomTo(testZoomLevels[i], testPoints[i], true); + viewport.update(); // need to call this even with immediately=true + propEqual( + viewport.getZoom(), + testZoomLevels[i], + "Zoomed to the correct level." + ); } start(); From 9d7424b1ce870c558125d74d0af8210483db98eb Mon Sep 17 00:00:00 2001 From: nein09 Date: Fri, 16 Jan 2015 16:00:57 -0800 Subject: [PATCH 3/9] Add panning tests --- test/viewport.js | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/test/viewport.js b/test/viewport.js index 063ce24d..86e0bf8f 100644 --- a/test/viewport.js +++ b/test/viewport.js @@ -277,12 +277,54 @@ viewer.open(TALL_PATH); // use a different image for homeFillsViewer }); + asyncTest('panBy', function(){ + var openHandler = function(event) { + viewer.removeHandler('open', openHandler); + var viewport = viewer.viewport; + + for (var i = 0; i < testPoints.length; i++){ + var expected = viewport.getCenter().plus(testPoints[i]); + viewport.panBy(testPoints[i], true); + viewport.update(); // need to call this even with immediately=true + propEqual( + viewport.getCenter(), + expected, + "Panned by the correct amount." + ); + } + + start(); + }; + viewer.addHandler('open', openHandler); + viewer.open(DZI_PATH); + }); + + asyncTest('panTo', function(){ + var openHandler = function(event) { + viewer.removeHandler('open', openHandler); + var viewport = viewer.viewport; + + for (var i = 0; i < testPoints.length; i++){ + viewport.panTo(testPoints[i], true); + viewport.update(); // need to call this even with immediately=true + propEqual( + viewport.getCenter(), + testPoints[i], + "Panned to the correct location." + ); + } + + start(); + }; + viewer.addHandler('open', openHandler); + viewer.open(DZI_PATH); + }); + asyncTest('zoomBy', function(){ var openHandler = function(event) { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; - var orig, expected, actual; for (var i = 0; i < testZoomLevels.length; i++){ viewport.zoomBy(testZoomLevels[i], null, true); viewport.update(); // need to call this even with immediately=true @@ -313,7 +355,6 @@ viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; - var orig, expected, actual; for (var i = 0; i < testZoomLevels.length; i++){ viewport.zoomTo(testZoomLevels[i], null, true); viewport.update(); // need to call this even with immediately=true From 1debca9c4116d4128d7a6dc54f1ebd1975673eef Mon Sep 17 00:00:00 2001 From: nein09 Date: Fri, 16 Jan 2015 16:14:18 -0800 Subject: [PATCH 4/9] Add panning tests --- test/viewport.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/viewport.js b/test/viewport.js index 86e0bf8f..1fb7349a 100644 --- a/test/viewport.js +++ b/test/viewport.js @@ -33,6 +33,7 @@ var VIEWER_PADDING = new OpenSeadragon.Point(0.25, 0.25); var DZI_PATH = '/test/data/testpattern.dzi'; var TALL_PATH = '/test/data/tall.dzi'; + var WIDE_PATH = '/test/data/wide.dzi'; var testZoomLevels = [-1, 0, 0.1, 0.5, 4, 10]; @@ -277,6 +278,38 @@ viewer.open(TALL_PATH); // use a different image for homeFillsViewer }); + asyncTest('fitHorizontally', function(){ + var openHandler = function(event) { + viewer.removeHandler('open', openHandler); + var viewport = viewer.viewport; + viewport.fitHorizontally(true); + viewport.update(); + propEqual( + viewport.getBounds(), + new OpenSeadragon.Point(0,0), + "Viewport fit a tall image horizontally." + ); + }; + viewer.addHandler('open', openHandler); + viewer.open(TALL_PATH); + }); + + asyncTest('fitVertically', function(){ + var openHandler = function(event) { + viewer.removeHandler('open', openHandler); + var viewport = viewer.viewport; + viewport.fitVertically(true); + viewport.update(); + propEqual( + viewport.getBounds(), + new OpenSeadragon.Point(0,0), + "Viewport fit a wide image vertically." + ); + }; + viewer.addHandler('open', openHandler); + viewer.open(WIDE_PATH); + }); + asyncTest('panBy', function(){ var openHandler = function(event) { viewer.removeHandler('open', openHandler); From 500d8c2348f3eb3fa78cb2b02508e9a66eb0cff1 Mon Sep 17 00:00:00 2001 From: nein09 Date: Fri, 16 Jan 2015 16:30:54 -0800 Subject: [PATCH 5/9] Fit horizontally and vertically. --- test/viewport.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/viewport.js b/test/viewport.js index 1fb7349a..3e8f1590 100644 --- a/test/viewport.js +++ b/test/viewport.js @@ -286,9 +286,10 @@ viewport.update(); propEqual( viewport.getBounds(), - new OpenSeadragon.Point(0,0), + new OpenSeadragon.Rect(-1.5,0,4,4), "Viewport fit a tall image horizontally." ); + start(); }; viewer.addHandler('open', openHandler); viewer.open(TALL_PATH); @@ -302,9 +303,10 @@ viewport.update(); propEqual( viewport.getBounds(), - new OpenSeadragon.Point(0,0), + new OpenSeadragon.Rect(0,0,0.25,0.25), "Viewport fit a wide image vertically." ); + start(); }; viewer.addHandler('open', openHandler); viewer.open(WIDE_PATH); From 3d5efbdbf06bebed585d6381134a96c7855686b2 Mon Sep 17 00:00:00 2001 From: nein09 Date: Mon, 19 Jan 2015 15:51:55 -0800 Subject: [PATCH 6/9] Reset content size and goHome --- test/viewport.js | 107 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 106 insertions(+), 1 deletion(-) diff --git a/test/viewport.js b/test/viewport.js index 3e8f1590..d1bc8f08 100644 --- a/test/viewport.js +++ b/test/viewport.js @@ -1,4 +1,4 @@ -/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog, propEqual */ +/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog, propEqual, console */ (function () { var viewer; @@ -278,6 +278,111 @@ viewer.open(TALL_PATH); // use a different image for homeFillsViewer }); + asyncTest('resetContentSize', function(){ + var openHandler = function(event) { + viewer.removeHandler('open', openHandler); + var viewport = viewer.viewport; + + for(var i = 0; i < testRects.length; i++){ + var rect = testRects[i].times(viewport.getContainerSize()); + viewport.resetContentSize(rect); + viewport.update(); + propEqual( + viewport.contentSize, + rect, + "Reset content size correctly." + ); + } + start(); + }; + viewer.addHandler('open', openHandler); + viewer.open(DZI_PATH); + }); + + asyncTest('goHome', function(){ + var openHandler = function(event) { + viewer.removeHandler('open', openHandler); + var viewport = viewer.viewport; + + // zoom/pan somewhere + viewport.zoomTo(ZOOM_FACTOR, true); + viewport.update(); + + viewport.goHome(true); + viewport.update(); + propEqual( + viewport.getBounds(), + viewport.getHomeBounds(), + "Went home." + ); + start(); + }; + viewer.addHandler('open', openHandler); + viewer.open(DZI_PATH); + }); + + asyncTest('ensureVisible', function(){ + var openHandler = function(event) { + viewer.removeHandler('open', openHandler); + var viewport = viewer.viewport; + + // zoom/pan so that the image is out of view + viewport.zoomTo(ZOOM_FACTOR * -50, true); + viewport.panBy(new OpenSeadragon.Point(5000, 5000), null, true); + viewport.update(); + + viewport.ensureVisible(true); + viewport.update(); + var bounds = viewport.getBounds(); + ok(bounds.getSize().x > 1 && bounds.getSize().y > 1, "Moved viewport so that image is visible."); + start(); + }; + viewer.addHandler('open', openHandler); + viewer.open(DZI_PATH); + }); + + asyncTest('fitBounds', function(){ + var openHandler = function(event) { + viewer.removeHandler('open', openHandler); + var viewport = viewer.viewport; + + for(var i = 0; i < testRects.length; i++){ + var rect = testRects[i].times(viewport.getContainerSize()); + viewport.fitBounds(rect, true); + viewport.update(); + propEqual( + viewport.getBounds(), + rect, + "Fit bounds correctly." + ); + } + start(); + }; + viewer.addHandler('open', openHandler); + viewer.open(DZI_PATH); + }); + + asyncTest('fitBoundsWithConstraints', function(){ + var openHandler = function(event) { + viewer.removeHandler('open', openHandler); + var viewport = viewer.viewport; + + for(var i = 0; i < testRects.length; i++){ + var rect = testRects[i].times(viewport.getContainerSize()); + viewport.fitBoundsWithConstraints(rect, true); + viewport.update(); + propEqual( + viewport.getBounds(), + rect, + "Fit bounds correctly." + ); + } + start(); + }; + viewer.addHandler('open', openHandler); + viewer.open(DZI_PATH); + }); + asyncTest('fitHorizontally', function(){ var openHandler = function(event) { viewer.removeHandler('open', openHandler); From ed0ffb14cf176186a563931b4e97432cfe026c4d Mon Sep 17 00:00:00 2001 From: nein09 Date: Sun, 1 Feb 2015 23:29:30 -0800 Subject: [PATCH 7/9] Change the fitBoundsWithConstraints test according to feedback (I think) --- test/viewport.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/test/viewport.js b/test/viewport.js index d1bc8f08..3892f349 100644 --- a/test/viewport.js +++ b/test/viewport.js @@ -362,18 +362,35 @@ viewer.open(DZI_PATH); }); + var testRectsOutsideImage = [ + new OpenSeadragon.Rect(0, 0, 2000, 100), + new OpenSeadragon.Rect(0, 0, 2000, 100), + new OpenSeadragon.Rect(800, 800, 300, 300), + new OpenSeadragon.Rect(-40, -40, 500, 500) + ]; + + // Why is it always this!? + var expectedRectFitBounds = new OpenSeadragon.Rect( + -0.05555555555555558, + -0.05555555555555558, + 1.1111111111111112, + 1.1111111111111112 + ); + asyncTest('fitBoundsWithConstraints', function(){ var openHandler = function(event) { viewer.removeHandler('open', openHandler); var viewport = viewer.viewport; + viewport.zoomTo(ZOOM_FACTOR, null, true); + viewport.update(); + for(var i = 0; i < testRectsOutsideImage.length; i++){ + var rect = testRectsOutsideImage[i]; - for(var i = 0; i < testRects.length; i++){ - var rect = testRects[i].times(viewport.getContainerSize()); viewport.fitBoundsWithConstraints(rect, true); viewport.update(); propEqual( viewport.getBounds(), - rect, + expectedRectFitBounds, "Fit bounds correctly." ); } From 449e80bf24ded77898821ac42d4f362c2d9f1cdb Mon Sep 17 00:00:00 2001 From: nein09 Date: Sun, 8 Feb 2015 22:46:55 -0800 Subject: [PATCH 8/9] Fix the viewport bounds for fitBoundsWithConstraints --- test/viewport.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/test/viewport.js b/test/viewport.js index 3892f349..ebb6b2fc 100644 --- a/test/viewport.js +++ b/test/viewport.js @@ -362,20 +362,19 @@ viewer.open(DZI_PATH); }); - var testRectsOutsideImage = [ - new OpenSeadragon.Rect(0, 0, 2000, 100), - new OpenSeadragon.Rect(0, 0, 2000, 100), - new OpenSeadragon.Rect(800, 800, 300, 300), - new OpenSeadragon.Rect(-40, -40, 500, 500) + var testRectsFitBounds = [ + new OpenSeadragon.Rect(0, -0.75, 0.5, 1), + new OpenSeadragon.Rect(0.5, 0, 0.5, 0.8), + new OpenSeadragon.Rect(0.75, 0.75, 0.5, 0.5), + new OpenSeadragon.Rect(-0.3, -0.3, 0.5, 0.5) ]; - // Why is it always this!? - var expectedRectFitBounds = new OpenSeadragon.Rect( - -0.05555555555555558, - -0.05555555555555558, - 1.1111111111111112, - 1.1111111111111112 - ); + var expectedRectsFitBounds = [ + new OpenSeadragon.Rect(-0.25, -0.5, 1, 1), + new OpenSeadragon.Rect(0.35, 0, 0.8, 0.8), + new OpenSeadragon.Rect(0.75, 0.75, 0.5, 0.5), + new OpenSeadragon.Rect(-0.25, -0.25, 0.5, 0.5) + ]; asyncTest('fitBoundsWithConstraints', function(){ var openHandler = function(event) { @@ -383,14 +382,14 @@ var viewport = viewer.viewport; viewport.zoomTo(ZOOM_FACTOR, null, true); viewport.update(); - for(var i = 0; i < testRectsOutsideImage.length; i++){ - var rect = testRectsOutsideImage[i]; + for(var i = 0; i < testRectsFitBounds.length; i++){ + var rect = testRectsFitBounds[i]; viewport.fitBoundsWithConstraints(rect, true); viewport.update(); propEqual( viewport.getBounds(), - expectedRectFitBounds, + expectedRectsFitBounds[i], "Fit bounds correctly." ); } From 0e67b9c204f16f099dba0d650a0b6f6eaecb2668 Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Mon, 9 Feb 2015 09:24:43 -0800 Subject: [PATCH 9/9] Added TODO marker for #589 --- test/viewport.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/viewport.js b/test/viewport.js index ebb6b2fc..f0894397 100644 --- a/test/viewport.js +++ b/test/viewport.js @@ -491,6 +491,7 @@ ); // now use a ref point + // TODO: check the ending position due to ref point viewport.zoomBy(testZoomLevels[i], testPoints[i], true); viewport.update(); propEqual( @@ -521,6 +522,7 @@ ); // now use a ref point + // TODO: check the ending position due to ref point viewport.zoomTo(testZoomLevels[i], testPoints[i], true); viewport.update(); // need to call this even with immediately=true propEqual(