Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=682299 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 682299</title> |
michael@0 | 8 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 10 | <script type="application/javascript" src="/tests/content/media/test/manifest.js"></script> |
michael@0 | 11 | </head> |
michael@0 | 12 | <body> |
michael@0 | 13 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=682299">Mozilla Bug 682299</a> |
michael@0 | 14 | <p id="display"></p> |
michael@0 | 15 | <div id="content" style="display: none"> |
michael@0 | 16 | |
michael@0 | 17 | </div> |
michael@0 | 18 | <pre id="test"> |
michael@0 | 19 | <script type="application/javascript"> |
michael@0 | 20 | |
michael@0 | 21 | /** Test for Bug 682299 **/ |
michael@0 | 22 | |
michael@0 | 23 | function createCanvas(width, height) { |
michael@0 | 24 | var c = document.createElement("canvas"); |
michael@0 | 25 | c.width = width; |
michael@0 | 26 | c.height = height; |
michael@0 | 27 | return c; |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | function testCanvasDrawImage(v) { |
michael@0 | 31 | var c = createCanvas(v.width, v.height); |
michael@0 | 32 | var ctx = c.getContext("2d"); |
michael@0 | 33 | ctx.drawImage(v, 0, 0); |
michael@0 | 34 | |
michael@0 | 35 | try { |
michael@0 | 36 | var data = ctx.getImageData(0, 0, 1, 1); |
michael@0 | 37 | ok(true, "drawImage '" + v.src + "' then getImageData with crossOrigin='" + v.crossOrigin + "' worked"); |
michael@0 | 38 | } catch(error) { |
michael@0 | 39 | ok(!v.crossOrigin && error.name === "SecurityError", "drawImage '" + v.src + "' then getImageData with crossOrigin='" + v.crossOrigin + "' failed"); |
michael@0 | 40 | v.tainted = true; |
michael@0 | 41 | } |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | function testCanvasCreatePattern(v) { |
michael@0 | 45 | var c = createCanvas(v.width, v.height); |
michael@0 | 46 | var ctx = c.getContext("2d"); |
michael@0 | 47 | ctx.fillStyle = ctx.createPattern(v, ""); |
michael@0 | 48 | ctx.fillRect(0, 0, c.width, c.height); |
michael@0 | 49 | |
michael@0 | 50 | try { |
michael@0 | 51 | var data = ctx.getImageData(0, 0, 1, 1); |
michael@0 | 52 | ok(true, "createPattern '" + v.src + "' then getImageData with crossOrigin='" + v.crossOrigin + "' worked"); |
michael@0 | 53 | } catch(error) { |
michael@0 | 54 | ok(!v.crossOrigin && error.name === "SecurityError", "createPattern '" + v.src + "' then getImageData with crossOrigin='" + v.crossOrigin + "' failed"); |
michael@0 | 55 | v.tainted = true; |
michael@0 | 56 | } |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | function testWebGL(v) { |
michael@0 | 60 | var tex = gl.createTexture(); |
michael@0 | 61 | gl.bindTexture(gl.TEXTURE_2D, tex); |
michael@0 | 62 | |
michael@0 | 63 | try { |
michael@0 | 64 | gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, v); |
michael@0 | 65 | ok(true, "createTexture from '" + v.src + "' with crossOrigin='" + v.crossOrigin + "' worked"); |
michael@0 | 66 | } catch (error) { |
michael@0 | 67 | ok(!v.crossOrigin && error.name === "SecurityError", "createTexture from '" + v.src + "' with crossOrigin='" + v.crossOrigin + "' failed"); |
michael@0 | 68 | v.tainted = true; |
michael@0 | 69 | } |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | function testTaintedCanvas(v) { |
michael@0 | 73 | var c = createCanvas(v.width, v.height); |
michael@0 | 74 | var ctx = c.getContext("2d"); |
michael@0 | 75 | ctx.drawImage(v, 0, 0); |
michael@0 | 76 | |
michael@0 | 77 | try { |
michael@0 | 78 | var data = ctx.getImageData(0, 0, 1, 1); |
michael@0 | 79 | ok(false, "changing the CORS mode should not allow reading data from remote videos"); |
michael@0 | 80 | } catch (error) { |
michael@0 | 81 | ok(error.name === "SecurityError", "changing the CORS mode, drawImage '" + v.src + "' then getImageData with crossOrigin='" + v.crossOrigin + "' failed"); |
michael@0 | 82 | } |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | function vidDataSuccess(e) { |
michael@0 | 86 | ok(!e.target.error, "Load '" + e.target.src + "' with crossOrigin='" + e.target.crossOrigin + "'"); |
michael@0 | 87 | |
michael@0 | 88 | testCanvasDrawImage(e.target); |
michael@0 | 89 | testCanvasCreatePattern(e.target); |
michael@0 | 90 | if (gl) { |
michael@0 | 91 | testWebGL(e.target); |
michael@0 | 92 | } |
michael@0 | 93 | // If we change the CORS mode after loading the file without CORS it should still throw a security error |
michael@0 | 94 | if (e.target.tainted) { |
michael@0 | 95 | e.target.crossOrigin = "anonymous"; |
michael@0 | 96 | testTaintedCanvas(e.target); |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | doneTest(e); |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | function vidLoadFailure(e) { |
michael@0 | 103 | ok(false, "Load '" + e.target.src + "' with crossOrigin='" + e.target.crossOrigin + "'"); |
michael@0 | 104 | doneTest(e); |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | function vidErrorSuccess(e) { |
michael@0 | 108 | ok(e.target.error.code === MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED, |
michael@0 | 109 | "Load '" + e.target.src + "' with crossOrigin='" + e.target.crossOrigin + "'"); |
michael@0 | 110 | doneTest(e); |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | function startTest(test, token) { |
michael@0 | 114 | var v = document.createElement('video'); |
michael@0 | 115 | if (test.cors === "just-crossOrigin-without-value") { |
michael@0 | 116 | var div = document.createElement('div'); |
michael@0 | 117 | div.innerHTML="<video crossOrigin>"; |
michael@0 | 118 | v = div.children[0]; |
michael@0 | 119 | } else if (test.cors !== "missing-value-default") { |
michael@0 | 120 | v.crossOrigin = test.cors; |
michael@0 | 121 | } |
michael@0 | 122 | v.token = token; |
michael@0 | 123 | manager.started(token); |
michael@0 | 124 | v.autoplay = true; |
michael@0 | 125 | v.preload = "auto"; |
michael@0 | 126 | v.style.display = "none"; |
michael@0 | 127 | if (test.nameIntent === test.corsIntent || test.corsIntent === "none" || |
michael@0 | 128 | (test.nameIntent === "use-credentials" && test.corsIntent === "anonymous")) { |
michael@0 | 129 | v.addEventListener("loadeddata", vidDataSuccess, false); |
michael@0 | 130 | v.addEventListener("error", vidLoadFailure, false); |
michael@0 | 131 | } else { |
michael@0 | 132 | v.addEventListener("loadeddata", vidLoadFailure, false); |
michael@0 | 133 | v.addEventListener("error", vidErrorSuccess, false); |
michael@0 | 134 | } |
michael@0 | 135 | v.src = test.name; |
michael@0 | 136 | document.body.appendChild(v); |
michael@0 | 137 | } |
michael@0 | 138 | |
michael@0 | 139 | function doneTest(e) { |
michael@0 | 140 | var v = e.target; |
michael@0 | 141 | v.parentNode.removeChild(v); |
michael@0 | 142 | manager.finished(v.token); |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | var videoFile = getPlayableVideo(gSmallTests); |
michael@0 | 146 | if (!videoFile) { |
michael@0 | 147 | SimpleTest.finish(); |
michael@0 | 148 | } |
michael@0 | 149 | videoFile = "?name=tests/content/media/test/" + videoFile.name + "&type=" + videoFile.type; |
michael@0 | 150 | |
michael@0 | 151 | var gl; |
michael@0 | 152 | try { |
michael@0 | 153 | gl = createCanvas(16, 16).getContext("experimental-webgl"); |
michael@0 | 154 | } catch (ex) { |
michael@0 | 155 | // Mac OS X 10.5 doesn't support WebGL, so we won't run the WebGL tests |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | var manager = new MediaTestManager; |
michael@0 | 159 | var corsTests = []; |
michael@0 | 160 | |
michael@0 | 161 | const host = "http://example.com/tests/content/canvas/test/crossorigin/video.sjs"; |
michael@0 | 162 | const serverAttrValues = [ |
michael@0 | 163 | [ "&cors=none", "none" ], |
michael@0 | 164 | [ "&cors=anonymous", "anonymous" ], |
michael@0 | 165 | [ "&cors=use-credentials", "use-credentials" ] |
michael@0 | 166 | ]; |
michael@0 | 167 | const clientAttrValues = [ |
michael@0 | 168 | [ "missing-value-default", "none" ], |
michael@0 | 169 | [ "", "anonymous" ], |
michael@0 | 170 | [ "just-crossOrigin-without-value", "anonymous" ], |
michael@0 | 171 | [ "anonymous", "anonymous" ], |
michael@0 | 172 | [ "use-credentials", "use-credentials" ], |
michael@0 | 173 | [ "foobar", "anonymous" ] |
michael@0 | 174 | ]; |
michael@0 | 175 | |
michael@0 | 176 | // Build the video file test array |
michael@0 | 177 | for (var i = 0; i < serverAttrValues.length; i++) { |
michael@0 | 178 | for (var n = 0; n < clientAttrValues.length; n++) { |
michael@0 | 179 | corsTests.push({ |
michael@0 | 180 | name: host + videoFile + serverAttrValues[i][0], |
michael@0 | 181 | nameIntent: serverAttrValues[i][1], |
michael@0 | 182 | cors: clientAttrValues[n][0], |
michael@0 | 183 | corsIntent: clientAttrValues[n][1] |
michael@0 | 184 | }); |
michael@0 | 185 | } |
michael@0 | 186 | } |
michael@0 | 187 | |
michael@0 | 188 | manager.runTests(corsTests, startTest); |
michael@0 | 189 | |
michael@0 | 190 | </script> |
michael@0 | 191 | </pre> |
michael@0 | 192 | </body> |
michael@0 | 193 | </html> |