2 <title>WebGL cross-origin textures test
</title>
3 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
4 <link rel=
"stylesheet" href=
"/tests/SimpleTest/test.css">
6 <canvas id=
"canvas" style=
"border: none;" width=
"100" height=
"100">
7 <p class=
"fallback"> FAIL (fallback content)
</p>
11 SimpleTest
.waitForExplicitFinish();
16 var number_of_tests_live
= 0;
17 var all_tests_started
= false;
19 function verifyError(actual_error
, expected_error
, message
) {
20 ok(actual_error
== expected_error
,
21 message
+ ": expected " + expected_error
+ ", got " + actual_error
);
24 function testTexture(url
, crossOriginAttribute
, expected_error
) {
25 number_of_tests_live
++;
26 var image
= new Image();
27 if (crossOriginAttribute
== "just-crossOrigin-without-value") {
28 var div
= document
.createElement('div');
29 div
.innerHTML
="<img crossOrigin>";
30 image
= div
.children
[0];
32 else if (crossOriginAttribute
!= "missing-value-default")
33 image
.crossOrigin
= crossOriginAttribute
;
37 number_of_tests_live
--;
39 if (number_of_tests_live
== 0 && all_tests_started
)
43 image
.onload = function() {
44 var tex
= gl
.createTexture();
45 gl
.bindTexture(gl
.TEXTURE_2D
, tex
);
46 var actual_error
= OK
;
48 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
.RGBA
, gl
.RGBA
, gl
.UNSIGNED_BYTE
, image
);
50 actual_error
= e
.name
;
52 verifyError(actual_error
, expected_error
, "texImage2D on " + url
+ " with crossOrigin=" + image
.crossOrigin
);
57 image
.onerror = function(event
) {
58 ok(expected_error
!= OK
, "Got an error but expected OK!");
66 addLoadEvent(function () {
67 var canvas
= document
.getElementById("canvas");
68 gl
= canvas
.getContext("experimental-webgl");
70 todo(false, "Canvas WebGL not supported");
76 testTexture("http://mochi.test:8888/tests/dom/canvas/test/crossorigin/image.png",
77 "missing-value-default",
79 testTexture("http://mochi.test:8888/tests/dom/canvas/test/crossorigin/image.png",
82 testTexture("http://mochi.test:8888/tests/dom/canvas/test/crossorigin/image.png",
83 "just-crossOrigin-without-value",
85 testTexture("http://example.com/tests/dom/canvas/test/crossorigin/image.png",
86 "missing-value-default",
88 testTexture("http://example.com/tests/dom/canvas/test/crossorigin/image.png",
91 testTexture("http://example.com/tests/dom/canvas/test/crossorigin/image.png",
92 "just-crossOrigin-without-value",
95 testTexture("http://example.com/tests/dom/canvas/test/crossorigin/image-allow-star.png",
96 "missing-value-default",
98 testTexture("http://example.com/tests/dom/canvas/test/crossorigin/image-allow-star.png",
101 testTexture("http://example.com/tests/dom/canvas/test/crossorigin/image-allow-star.png",
102 "just-crossOrigin-without-value",
104 testTexture("http://example.com/tests/dom/canvas/test/crossorigin/image-allow-star.png",
107 testTexture("http://example.com/tests/dom/canvas/test/crossorigin/image-allow-star.png",
111 testTexture("http://example.com/tests/dom/canvas/test/crossorigin/image-allow-credentials.png",
112 "missing-value-default",
114 testTexture("http://example.com/tests/dom/canvas/test/crossorigin/image-allow-credentials.png",
117 testTexture("http://example.com/tests/dom/canvas/test/crossorigin/image-allow-credentials.png",
118 "just-crossOrigin-without-value",
120 testTexture("http://example.com/tests/dom/canvas/test/crossorigin/image-allow-credentials.png",
123 testTexture("http://example.com/tests/dom/canvas/test/crossorigin/image-allow-credentials.png",
127 // Test that bad values for crossorigin="..." are interpreted as invalid-value-default which is "anonymous".
128 testTexture("http://mochi.test:8888/tests/dom/canvas/test/crossorigin/image.png",
131 testTexture("http://example.com/tests/dom/canvas/test/crossorigin/image.png",
134 testTexture("http://example.com/tests/dom/canvas/test/crossorigin/image-allow-star.png",
137 testTexture("http://example.com/tests/dom/canvas/test/crossorigin/image-allow-credentials.png",
141 all_tests_started
= true;