Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / canvas / webgl / origin-clean-conformance.html
blob7b1a4719491e558003756bb4539da5d39a89816c
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2 "http://www.w3.org/TR/html4/loose.dtd">
3 <html>
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6 <title>WebGL Origin Restrictions Conformance Tests</title>
7 <script>
8 function create3DContext(canvas, attributes)
10 if (!canvas)
11 canvas = document.createElement("canvas");
12 var context = null;
13 try {
14 context = canvas.getContext("webgl", attributes);
15 } catch(e) {}
16 if (!context) {
17 try {
18 context = canvas.getContext("webkit-3d", attributes);
19 } catch(e) {}
21 if (!context) {
22 try {
23 context = canvas.getContext("moz-webgl", attributes);
24 } catch(e) {}
26 if (!context) {
27 throw "Unable to fetch WebGL rendering context for Canvas";
29 return context;
32 function description(msg)
34 // For MSIE 6 compatibility
35 var span = document.createElement("span");
36 span.innerHTML = '<p>' + msg + '</p><p>On success, you will see a series of "<span class="pass">PASS</span>" messages, followed by "<span class="pass">TEST COMPLETE</span>".</p>';
37 var description = document.getElementById("description");
38 if (description.firstChild)
39 description.replaceChild(span, description.firstChild);
40 else
41 description.appendChild(span);
44 function debug(msg)
46 var span = document.createElement("span");
47 document.getElementById("console").appendChild(span); // insert it first so XHTML knows the namespace
48 span.innerHTML = msg + '<br />';
51 function escapeHTML(text)
53 return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/\0/g, "\\0");
56 function testPassed(msg)
58 debug('<span><span class="pass">PASS</span> ' + escapeHTML(msg) + '</span>');
61 function testFailed(msg)
63 debug('<span><span class="fail">FAIL</span> ' + escapeHTML(msg) + '</span>');
66 function assertMsg(assertion, msg) {
67 if (assertion) {
68 testPassed(msg);
69 } else {
70 testFailed(msg);
74 // Checks if function throws an exception.
75 function causedException(func) {
76 var hadException = false;
77 try {
78 func();
79 } catch(e) {
80 hadException = true;
82 return hadException;
85 var testVideo = false;
87 function init() {
88 var video = document.getElementById("video");
90 var base = "http://localhost:8000/resources/";
91 var videos = [
92 ["video/mp4", base + "test.mp4"],
93 ["video/ogg", base + "test.ogv"],
95 var videoFile = null;
96 for (var i = 0; i < videos.length; ++i) {
97 if (video.canPlayType(videos[i][0])) {
98 videoFile = videos[i][1];
99 break;
102 assertMsg(videoFile, "Playable video format found");
104 if (videoFile) {
105 if (window.testRunner) {
106 testRunner.overridePreference("WebKitWebGLEnabled", "1");
107 testRunner.dumpAsText();
108 testRunner.waitUntilDone();
110 video.src = videoFile;
111 video.addEventListener("playing", runTests);
112 video.play();
113 testVideo = true;
114 } else {
115 // Still run the other tests, even if the video failed.
116 runTests();
120 function runTests() {
121 description("This test ensures WebGL implementations follow proper same-origin restrictions.");
122 var img = document.getElementById("img");
123 assertMsg(img.width > 0 && img.height > 0, "img was loaded");
125 function makeTexImage2D(gl, src) {
126 return function() {
127 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, src);
131 function makeTexSubImage2D(gl, src) {
132 return function() {
133 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, src);
137 function makeReadPixels(gl) {
138 return function() {
139 var buf = new Uint8Array(4);
140 gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf);
144 function makeToDataURL(canvas) {
145 return function() {
146 var data = canvas.toDataURL();
150 var canvas1 = document.getElementById("canvas1");
151 var gl = create3DContext(canvas1);
153 debug("");
154 debug("check that an attempt to upload an image from another origin throws an exception.");
155 var tex = gl.createTexture();
156 gl.bindTexture(gl.TEXTURE_2D, tex);
157 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 256, 256, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
158 assertMsg(causedException(makeTexImage2D(gl, img)),
159 "texImage2D with cross-origin image should throw exception.");
160 assertMsg(causedException(makeTexSubImage2D(gl, img)),
161 "texSubImage2D with cross-origin image should throw exception.");
163 debug("check that readPixels and toDataURL continue to work against this canvas.");
164 assertMsg(!causedException(makeReadPixels(gl)),
165 "readPixels should never throw exception -- not possible to dirty origin of WebGL canvas.");
166 assertMsg(!causedException(makeToDataURL(canvas1)),
167 "should not throw exception by toDataURL for WebGL canvas, which should stay origin clean.");
169 debug("check that an attempt to upload a tainted canvas throws an exception.");
170 var canvas2 = document.getElementById("canvas2");
171 var ctx2d = canvas2.getContext("2d");
172 ctx2d.drawImage(img, 0, 0);
173 assertMsg(causedException(makeToDataURL(canvas2)),
174 "should throw exception by toDataURL for NON origin clean canvas.");
175 assertMsg(causedException(makeTexImage2D(gl, canvas2)),
176 "texImage2D with NON origin clean canvas should throw exception.");
177 assertMsg(causedException(makeTexSubImage2D(gl, canvas2)),
178 "texSubImage2D with NON origin clean canvas should throw exception.");
180 debug("check that readPixels and toDataURL continue to work against this canvas.");
181 assertMsg(!causedException(makeReadPixels(gl)),
182 "readPixels should never throw exception -- not possible to dirty origin of WebGL canvas.");
183 assertMsg(!causedException(makeToDataURL(canvas1)),
184 "should not throw exception by toDataURL for WebGL canvas, which should stay origin clean.");
186 if (testVideo) {
187 debug("check that an attempt to upload a video from another origin throws an exception.");
188 var video = document.getElementById("video");
189 assertMsg(causedException(makeTexImage2D(gl, video)),
190 "texImage2D with cross-origin video should throw exception.");
191 assertMsg(causedException(makeTexSubImage2D(gl, video)),
192 "texSubImage2D with cross-origin video should throw exception.");
194 debug("check that readPixels and toDataURL continue to work against this canvas.");
195 assertMsg(!causedException(makeReadPixels(gl)),
196 "readPixels should never throw exception -- not possible to dirty origin of WebGL canvas.");
197 assertMsg(!causedException(makeToDataURL(canvas1)),
198 "should not throw exception by toDataURL for WebGL canvas, which should stay origin clean.");
201 debug('<br /><span class="pass">TEST COMPLETE</span>');
202 if (window.testRunner)
203 testRunner.waitUntilDone();
204 if (window.testRunner) {
205 testRunner.notifyDone();
208 </script>
209 </head>
210 <body onload="init()">
211 <div id="description"></div>
212 <div id="console"></div>
213 <canvas id="canvas1"></canvas>
214 <canvas id="canvas2"></canvas>
215 <img id="img" src="http://localhost:8000/local/resources/abe.png" style="display:none;">
216 <video id="video" style="display:none;"/>
217 </body>
218 </html>