Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / security / webgl-remote-read-remote-image-allowed.html
blob8f0f6806fa046322a6a19b075d003d659d09e145
1 <!doctype html>
2 <html>
3 <body>
4 <pre id="console"></pre>
5 <script>
6 if (window.testRunner) {
7 testRunner.overridePreference("WebKitWebGLEnabled", "1");
8 testRunner.dumpAsText();
9 testRunner.waitUntilDone();
12 log = function(msg)
14 document.getElementById('console').appendChild(document.createTextNode(msg + "\n"));
17 testTexImage2D = function(gl, source, description)
19 description = "Calling texImage2D() with an untainted " + description;
20 try {
21 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source);
22 log("PASS: " + description + " was allowed");
23 } catch (e) {
24 log("FAIL: " + description + " was not allowed: Threw error: " + e + ".");
28 testReadPixels = function(gl, description)
30 description = "Calling readPixels() from a canvas tainted by a " + description;
31 try {
32 var pixels = new Uint8Array(4);
33 gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
34 log("PASS: " + description + " was allowed.");
35 } catch (e) {
36 log("FAIL: " + description + " was not allowed - Threw error: " + e + ".");
40 testToDataURL = function(canvas, description)
42 description = "Calling toDataURL() on a canvas CORS-untainted by a " + description;
43 try {
44 var dataURL = canvas.toDataURL();
45 log("PASS: " + description + " was allowed.");
46 } catch (e) {
47 log("FAIL: " + description + " was not allowed - Threw error: " + e + ".");
51 test = function(canvas, description)
53 testReadPixels(canvas.getContext("webgl"), description);
54 testToDataURL(canvas, description);
57 testResource = function (resource, resourceType, continuation)
59 log("");
60 log("Testing " + resourceType + "...");
62 var canvas = document.createElement("canvas");
63 canvas.width = 100;
64 canvas.height = 100;
65 var gl = canvas.getContext("webgl");
67 // Control tests
68 log("Untainted canvas:");
69 try {
70 var pixels = new Uint8Array(4);
71 gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
72 log("PASS: Calling readPixels() from an untainted canvas was allowed.");
73 } catch (e) {
74 log("FAIL: Calling readPixels() from an untainted canvas was not allowed: Threw error: " + e + ".");
76 try {
77 var dataURL = canvas.toDataURL();
78 log("PASS: Calling toDataURL() on an untainted canvas was allowed.");
79 } catch (e) {
80 log("FAIL: Calling toDataURL() on an untainted canvas was not allowed: Threw error: " + e + ".");
83 log("\n");
84 log("Tainted canvas:");
85 // Test reading from a canvas after uploading a remote resource as a texture
86 var texture = gl.createTexture();
87 gl.bindTexture(gl.TEXTURE_2D, texture);
88 testTexImage2D(gl, resource, resourceType);
90 test(canvas, "remote " + resourceType);
92 // Now test reading from a canvas after uploading a tainted canvas onto it
93 var dirtyCanvas = document.createElement("canvas");
94 dirtyCanvas.width = 100;
95 dirtyCanvas.height = 100;
96 var dirtyContext = dirtyCanvas.getContext("2d");
97 dirtyContext.drawImage(resource, 0, 0, 100, 100);
98 testTexImage2D(gl, dirtyCanvas, "canvas");
100 test(canvas, "CORS-untained canvas");
102 continuation();
105 testImage = function ()
107 var image = new Image();
108 image.onload = testResource.bind(null, image, "image", testVideo);
109 image.crossOrigin = "anonymous";
110 image.src = "http://localhost:8000/security/resources/abe-allow-star.php";
113 testVideo = function ()
115 var video = document.createElement('video');
116 video.oncanplay = testResource.bind(null, video, "video", finishUp);
117 video.crossOrigin = "anonymous";
118 var name = "../../media/resources/test.ogv";
119 var type = "video/ogg";
120 video.src = "http://localhost:8000/security/resources/video-cross-origin-allow.php?name=" + name + "&type=" + type;
123 finishUp = function ()
125 log("DONE");
126 if (window.testRunner)
127 testRunner.notifyDone();
130 testImage();
131 </script>
132 </body>
133 </html>