From ed72ae748ff84c3204f12a5c4cc1257a4ed35050 Mon Sep 17 00:00:00 2001 From: Antoine Vandecreme Date: Fri, 27 Feb 2015 14:07:42 -0500 Subject: [PATCH] Fix tests and coverage --- test/coverage.html | 2 +- test/modules/basic.js | 53 +++++++++++++++++++++++++++++++------------ 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/test/coverage.html b/test/coverage.html index 2c3bc093..fe75c797 100644 --- a/test/coverage.html +++ b/test/coverage.html @@ -39,7 +39,7 @@ - + diff --git a/test/modules/basic.js b/test/modules/basic.js index a4a37faf..7f095777 100644 --- a/test/modules/basic.js +++ b/test/modules/basic.js @@ -301,6 +301,24 @@ viewer.open('/test/data/testpattern.dzi'); }); + + // The Wikipedia logo has CORS enabled + var corsImg = 'http://upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png'; + + // PhantomJS always taint the canvas, so we only run some tests on browsers + // supporting CORS images. + function browserSupportsImgCrossOrigin(callback) { + var img = new Image(); + img.crossOrigin = 'anonymous'; + img.onload = function() { + var canvas = document.createElement("canvas"); + var ctx = canvas.getContext("2d"); + ctx.drawImage(img, 0, 0); + callback(!isCanvasTainted(ctx)); + }; + img.src = corsImg; + } + function isCanvasTainted(context) { var isTainted = false; try { @@ -319,8 +337,7 @@ viewer.open( { type: 'legacy-image-pyramid', levels: [ { - // The Wikipedia logo has CORS enabled - url: 'http://upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png', + url: corsImg, width: 135, height: 155 } ] @@ -334,19 +351,25 @@ 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(); + browserSupportsImgCrossOrigin(function(supported) { + if (!supported) { + expect(0); + start(); + } else { + viewer.crossOriginPolicy = 'Anonymous'; + viewer.open( { + type: 'legacy-image-pyramid', + levels: [ { + url: corsImg, + width: 135, + height: 155 + } ] + } ); + viewer.addHandler('tile-drawn', function() { + ok(!isCanvasTainted(viewer.drawer.context), "Canvas should not be tainted."); + start(); + }); + } }); } );