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 | <title>WebGL cross-origin textures test</title> |
michael@0 | 3 | <script src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 4 | <link rel="stylesheet" href="/tests/SimpleTest/test.css"> |
michael@0 | 5 | <body> |
michael@0 | 6 | <canvas id="canvas" style="border: none;" width="100" height="100"> |
michael@0 | 7 | <p class="fallback"> FAIL (fallback content) </p> |
michael@0 | 8 | </canvas> |
michael@0 | 9 | <script> |
michael@0 | 10 | |
michael@0 | 11 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 12 | |
michael@0 | 13 | const OK = ""; |
michael@0 | 14 | |
michael@0 | 15 | var gl; |
michael@0 | 16 | var number_of_tests_live = 0; |
michael@0 | 17 | var all_tests_started = false; |
michael@0 | 18 | |
michael@0 | 19 | function verifyError(actual_error, expected_error, message) { |
michael@0 | 20 | ok(actual_error == expected_error, |
michael@0 | 21 | message + ": expected " + expected_error + ", got " + actual_error); |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | function testTexture(url, crossOriginAttribute, expected_error) { |
michael@0 | 25 | number_of_tests_live++; |
michael@0 | 26 | var image = new Image(); |
michael@0 | 27 | if (crossOriginAttribute == "just-crossOrigin-without-value") { |
michael@0 | 28 | var div = document.createElement('div'); |
michael@0 | 29 | div.innerHTML="<img crossOrigin>"; |
michael@0 | 30 | image = div.children[0]; |
michael@0 | 31 | } |
michael@0 | 32 | else if (crossOriginAttribute != "missing-value-default") |
michael@0 | 33 | image.crossOrigin = crossOriginAttribute; |
michael@0 | 34 | |
michael@0 | 35 | |
michael@0 | 36 | function testDone() { |
michael@0 | 37 | number_of_tests_live--; |
michael@0 | 38 | |
michael@0 | 39 | if (number_of_tests_live == 0 && all_tests_started) |
michael@0 | 40 | SimpleTest.finish(); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | image.onload = function() { |
michael@0 | 44 | var tex = gl.createTexture(); |
michael@0 | 45 | gl.bindTexture(gl.TEXTURE_2D, tex); |
michael@0 | 46 | var actual_error = OK; |
michael@0 | 47 | try { |
michael@0 | 48 | gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image); |
michael@0 | 49 | } catch(e) { |
michael@0 | 50 | actual_error = e.name; |
michael@0 | 51 | } |
michael@0 | 52 | verifyError(actual_error, expected_error, "texImage2D on " + url + " with crossOrigin=" + image.crossOrigin); |
michael@0 | 53 | |
michael@0 | 54 | testDone(); |
michael@0 | 55 | }; |
michael@0 | 56 | |
michael@0 | 57 | image.onerror = function(event) { |
michael@0 | 58 | ok(expected_error != OK, "Got an error but expected OK!"); |
michael@0 | 59 | |
michael@0 | 60 | testDone(); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | image.src = url; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | addLoadEvent(function () { |
michael@0 | 67 | var canvas = document.getElementById("canvas"); |
michael@0 | 68 | gl = canvas.getContext("experimental-webgl"); |
michael@0 | 69 | if (!gl) { |
michael@0 | 70 | todo(false, "Canvas WebGL not supported"); |
michael@0 | 71 | SimpleTest.finish(); |
michael@0 | 72 | return; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | |
michael@0 | 76 | testTexture("http://mochi.test:8888/tests/content/canvas/test/crossorigin/image.png", |
michael@0 | 77 | "missing-value-default", |
michael@0 | 78 | OK); |
michael@0 | 79 | testTexture("http://mochi.test:8888/tests/content/canvas/test/crossorigin/image.png", |
michael@0 | 80 | "", |
michael@0 | 81 | OK); |
michael@0 | 82 | testTexture("http://mochi.test:8888/tests/content/canvas/test/crossorigin/image.png", |
michael@0 | 83 | "just-crossOrigin-without-value", |
michael@0 | 84 | OK); |
michael@0 | 85 | testTexture("http://example.com/tests/content/canvas/test/crossorigin/image.png", |
michael@0 | 86 | "missing-value-default", |
michael@0 | 87 | "SecurityError"); |
michael@0 | 88 | testTexture("http://example.com/tests/content/canvas/test/crossorigin/image.png", |
michael@0 | 89 | "", |
michael@0 | 90 | "SecurityError"); |
michael@0 | 91 | testTexture("http://example.com/tests/content/canvas/test/crossorigin/image.png", |
michael@0 | 92 | "just-crossOrigin-without-value", |
michael@0 | 93 | "SecurityError"); |
michael@0 | 94 | |
michael@0 | 95 | testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-star.png", |
michael@0 | 96 | "missing-value-default", |
michael@0 | 97 | "SecurityError"); |
michael@0 | 98 | testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-star.png", |
michael@0 | 99 | "", |
michael@0 | 100 | OK); |
michael@0 | 101 | testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-star.png", |
michael@0 | 102 | "just-crossOrigin-without-value", |
michael@0 | 103 | OK); |
michael@0 | 104 | testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-star.png", |
michael@0 | 105 | "anonymous", |
michael@0 | 106 | OK); |
michael@0 | 107 | testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-star.png", |
michael@0 | 108 | "use-credentials", |
michael@0 | 109 | "SecurityError"); |
michael@0 | 110 | |
michael@0 | 111 | testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-credentials.png", |
michael@0 | 112 | "missing-value-default", |
michael@0 | 113 | "SecurityError"); |
michael@0 | 114 | testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-credentials.png", |
michael@0 | 115 | "", |
michael@0 | 116 | OK); |
michael@0 | 117 | testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-credentials.png", |
michael@0 | 118 | "just-crossOrigin-without-value", |
michael@0 | 119 | OK); |
michael@0 | 120 | testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-credentials.png", |
michael@0 | 121 | "anonymous", |
michael@0 | 122 | OK); |
michael@0 | 123 | testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-credentials.png", |
michael@0 | 124 | "use-credentials", |
michael@0 | 125 | OK); |
michael@0 | 126 | |
michael@0 | 127 | // Test that bad values for crossorigin="..." are interpreted as invalid-value-default which is "anonymous". |
michael@0 | 128 | testTexture("http://mochi.test:8888/tests/content/canvas/test/crossorigin/image.png", |
michael@0 | 129 | "foobar", |
michael@0 | 130 | OK); |
michael@0 | 131 | testTexture("http://example.com/tests/content/canvas/test/crossorigin/image.png", |
michael@0 | 132 | "foobar", |
michael@0 | 133 | "SecurityError"); |
michael@0 | 134 | testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-star.png", |
michael@0 | 135 | "foobar", |
michael@0 | 136 | OK); |
michael@0 | 137 | testTexture("http://example.com/tests/content/canvas/test/crossorigin/image-allow-credentials.png", |
michael@0 | 138 | "foobar", |
michael@0 | 139 | OK); |
michael@0 | 140 | |
michael@0 | 141 | all_tests_started = true; |
michael@0 | 142 | }); |
michael@0 | 143 | </script> |