From a372274ee1b947d65ce3c2a402e5ca4574a63790 Mon Sep 17 00:00:00 2001 From: Antoine Vandecreme Date: Thu, 26 Feb 2015 17:57:31 -0500 Subject: [PATCH] Fix Cross Origin policy not working (#612) Remove useless hostUrl field --- src/openseadragon.js | 3 --- src/viewer.js | 6 ++--- test/modules/basic.js | 50 +++++++++++++++++++++++++++++++++++++++ test/modules/navigator.js | 25 ++++++++++++++++++++ 4 files changed, 78 insertions(+), 6 deletions(-) diff --git a/src/openseadragon.js b/src/openseadragon.js index f2110e8e..8d231cbe 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -175,9 +175,6 @@ * these paths, prefer setting the option.prefixUrl rather than overriding * every image path directly through this setting. * - * @property {Object} [tileHost=null] - * TODO: Implement this. Currently not used. - * * @property {Boolean} [debugMode=false] * TODO: provide an in-screen panel providing event detail feedback. * diff --git a/src/viewer.js b/src/viewer.js index f36fe020..11b33e6d 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -409,10 +409,10 @@ $.Viewer = function( options ) { width: this.navigatorWidth, height: this.navigatorHeight, autoResize: this.navigatorAutoResize, - tileHost: this.tileHost, prefixUrl: this.prefixUrl, viewer: this, - navigatorRotate: this.navigatorRotate + navigatorRotate: this.navigatorRotate, + crossOriginPolicy: this.crossOriginPolicy }); } @@ -505,7 +505,6 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, height: this.referenceStripHeight, width: this.referenceStripWidth, tileSources: this.tileSources, - tileHost: this.tileHost, prefixUrl: this.prefixUrl, viewer: this }); @@ -1290,6 +1289,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, blendTime: _this.blendTime, alwaysBlend: _this.alwaysBlend, minPixelRatio: _this.minPixelRatio, + crossOriginPolicy: _this.crossOriginPolicy, debugMode: _this.debugMode }); diff --git a/test/modules/basic.js b/test/modules/basic.js index 9ef6ee8d..a4a37faf 100644 --- a/test/modules/basic.js +++ b/test/modules/basic.js @@ -301,4 +301,54 @@ viewer.open('/test/data/testpattern.dzi'); }); + function isCanvasTainted(context) { + var isTainted = false; + try { + // We test if the canvas is tainted by retrieving data from it. + // An exception will be raised if the canvas is tainted. + var url = context.getImageData(0, 0, 1, 1); + } catch (e) { + isTainted = true; + } + return isTainted; + } + + asyncTest( 'CrossOriginPolicyMissing', function () { + + viewer.crossOriginPolicy = false; + viewer.open( { + type: 'legacy-image-pyramid', + levels: [ { + // The Wikipedia logo has CORS enabled + url: 'http://upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png', + width: 135, + height: 155 + } ] + } ); + viewer.addHandler('tile-drawn', function() { + ok(isCanvasTainted(viewer.drawer.context), "Canvas should be tainted."); + start(); + }); + + } ); + + asyncTest( 'CrossOriginPolicyAnonymous', function () { + + viewer.crossOriginPolicy = 'Anonymous'; + viewer.open( { + type: 'legacy-image-pyramid', + levels: [ { + // The Wikipedia logo has CORS enabled + url: 'http://upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png', + width: 135, + height: 155 + } ] + } ); + viewer.addHandler('tile-drawn', function() { + ok(!isCanvasTainted(viewer.drawer.context), "Canvas should not be tainted."); + start(); + }); + + } ); + })(); diff --git a/test/modules/navigator.js b/test/modules/navigator.js index 7799f06d..c6381a20 100644 --- a/test/modules/navigator.js +++ b/test/modules/navigator.js @@ -843,4 +843,29 @@ viewer.addHandler('open', openHandler); }); + asyncTest('Viewer options transmitted to navigator', function() { + + viewer = OpenSeadragon({ + id: 'example', + prefixUrl: '/build/openseadragon/images/', + tileSources: ['/test/data/testpattern.dzi', '/test/data/testpattern.dzi'], + springStiffness: 100, // Faster animation = faster tests + showNavigator: true, + collectionMode: true, + crossOriginPolicy: 'Anonymous' + }); + viewer.addHandler('open', function openHandler() { + viewer.removeHandler('open', openHandler); + + var navigator = viewer.navigator; + + equal(navigator.prefixUrl, viewer.prefixUrl, + "Prefix URL should be transmitted to the navigator."); + equal(navigator.crossOriginPolicy, viewer.crossOriginPolicy, + "Cross origin policy should be transmitted to the navigator."); + start(); + }); + + }); + })();