Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: LayoutTests/http/tests/canvas/webgl/origin-clean-conformance.html

Issue 7171012: Merge 88489 - 2011-06-09 Kenneth Russell <kbr@google.com> (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/782/
Patch Set: Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2 "http://www.w3.org/TR/html4/loose.dtd"> 2 "http://www.w3.org/TR/html4/loose.dtd">
3 <html> 3 <html>
4 <head> 4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6 <title>WebGL Origin Restrictions Conformance Tests</title> 6 <title>WebGL Origin Restrictions Conformance Tests</title>
7 <script> 7 <script>
8 function create3DContext(canvas, attributes) 8 function create3DContext(canvas, attributes)
9 { 9 {
10 if (!canvas) 10 if (!canvas)
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 function causedException(func) { 75 function causedException(func) {
76 var hadException = false; 76 var hadException = false;
77 try { 77 try {
78 func(); 78 func();
79 } catch(e) { 79 } catch(e) {
80 hadException = true; 80 hadException = true;
81 } 81 }
82 return hadException; 82 return hadException;
83 } 83 }
84 84
85 var testVideo = false;
86
85 function init() { 87 function init() {
86 var video = document.getElementById("video"); 88 var video = document.getElementById("video");
87 89
88 var base = "http://localhost:8000/resources/"; 90 var base = "http://localhost:8000/resources/";
89 var videos = [ 91 var videos = [
90 ["video/mp4", base + "test.mp4"], 92 ["video/mp4", base + "test.mp4"],
91 ["video/ogg", base + "test.ogv"], 93 ["video/ogg", base + "test.ogv"],
92 ]; 94 ];
93 var videoFile = null; 95 var videoFile = null;
94 for (var i = 0; i < videos.length; ++i) { 96 for (var i = 0; i < videos.length; ++i) {
95 if (video.canPlayType(videos[i][0])) { 97 if (video.canPlayType(videos[i][0])) {
96 videoFile = videos[i][1]; 98 videoFile = videos[i][1];
97 break; 99 break;
98 } 100 }
99 } 101 }
100 assertMsg(videoFile, "Playable video format found"); 102 assertMsg(videoFile, "Playable video format found");
101 103
102 if (videoFile) { 104 if (videoFile) {
103 if (window.layoutTestController) { 105 if (window.layoutTestController) {
104 layoutTestController.overridePreference("WebKitWebGLEnabled", "1"); 106 layoutTestController.overridePreference("WebKitWebGLEnabled", "1");
105 layoutTestController.dumpAsText(); 107 layoutTestController.dumpAsText();
106 layoutTestController.waitUntilDone(); 108 layoutTestController.waitUntilDone();
107 } 109 }
108 video.src = videoFile; 110 video.src = videoFile;
109 video.addEventListener("playing", runTests); 111 video.addEventListener("playing", runTests);
110 video.play(); 112 video.play();
113 testVideo = true;
111 } else { 114 } else {
112 // Still run the other tests, even if the video failed. 115 // Still run the other tests, even if the video failed.
113 runTests(); 116 runTests();
114 } 117 }
115 } 118 }
116 119
117 function runTests() { 120 function runTests() {
118 description("This test ensures WebGL implementations follow proper origin rest rictions."); 121 description("This test ensures WebGL implementations follow proper same-origin restrictions.");
119 var img = document.getElementById("img"); 122 var img = document.getElementById("img");
120 assertMsg(img.width > 0 && img.height > 0, "img was loaded"); 123 assertMsg(img.width > 0 && img.height > 0, "img was loaded");
121 124
125 function makeTexImage2D(gl, src) {
126 return function() {
127 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, src);
128 };
129 }
130
131 function makeTexSubImage2D(gl, src) {
132 return function() {
133 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, src);
134 };
135 }
136
122 function makeReadPixels(gl) { 137 function makeReadPixels(gl) {
123 return function() { 138 return function() {
124 var buf = new Uint8Array(4); 139 var buf = new Uint8Array(4);
125 gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf); 140 gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf);
126 }; 141 };
127 } 142 }
128 143
129 function makeToDataURL(canvas) { 144 function makeToDataURL(canvas) {
130 return function() { 145 return function() {
131 var data = canvas.toDataURL(); 146 var data = canvas.toDataURL();
132 } 147 }
133 } 148 }
134 149
135 debug("");
136 debug("check that copying an img from another origin clears the origin-clean f lag.");
137 var canvas1 = document.getElementById("canvas1"); 150 var canvas1 = document.getElementById("canvas1");
138 var gl1 = create3DContext(canvas1); 151 var gl = create3DContext(canvas1);
139 assertMsg(!causedException(makeReadPixels(gl1)),
140 "should not throw exception by readPixels for origin clean canvas.") ;
141 assertMsg(!causedException(makeToDataURL(canvas1)),
142 "should not throw exception by toDataURL for origin clean canvas.");
143
144 var tex = gl1.createTexture();
145 gl1.bindTexture(gl1.TEXTURE_2D, tex);
146 gl1.texImage2D(gl1.TEXTURE_2D, 0, gl1.RGBA, gl1.RGBA, gl1.UNSIGNED_BYTE, img);
147
148 assertMsg(causedException(makeReadPixels(gl1)),
149 "should throw exception by readPixels for NON origin clean canvas.") ;
150 assertMsg(causedException(makeToDataURL(canvas1)),
151 "should throw exception by toDataURL for NON origin clean canvas.");
152 152
153 debug(""); 153 debug("");
154 debug("check that copying from 1 unclean 3d canvas to another clears the origi n-clean flag on the second canvas."); 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_BYT E, 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.");
162
163 debug("check that readPixels and toDataURL continue to work against this canva s.");
164 assertMsg(!causedException(makeReadPixels(gl)),
165 "readPixels should never throw exception -- not possible to dirty or igin of WebGL canvas.");
166 assertMsg(!causedException(makeToDataURL(canvas1)),
167 "should not throw exception by toDataURL for WebGL canvas, which sho uld stay origin clean.");
168
169 debug("check that an attempt to upload a tainted canvas throws an exception.") ;
155 var canvas2 = document.getElementById("canvas2"); 170 var canvas2 = document.getElementById("canvas2");
156 var gl2 = create3DContext(canvas2); 171 var ctx2d = canvas2.getContext("2d");
157 172 ctx2d.drawImage(img, 0, 0);
158 assertMsg(!causedException(makeReadPixels(gl2)),
159 "should not throw exception by readPixels for origin clean canvas.") ;
160 assertMsg(!causedException(makeToDataURL(canvas2)),
161 "should not throw exception by toDataURL for origin clean canvas.");
162
163 var tex = gl2.createTexture();
164 gl2.bindTexture(gl2.TEXTURE_2D, tex);
165 gl2.texImage2D(
166 gl2.TEXTURE_2D, 0, gl2.RGBA, gl2.RGBA, gl2.UNSIGNED_BYTE, canvas1);
167
168 assertMsg(causedException(makeReadPixels(gl2)),
169 "should throw exception by readPixels for NON origin clean canvas.") ;
170 assertMsg(causedException(makeToDataURL(canvas2)), 173 assertMsg(causedException(makeToDataURL(canvas2)),
171 "should throw exception by toDataURL for NON origin clean canvas."); 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." );
172 179
173 debug(""); 180 debug("check that readPixels and toDataURL continue to work against this canva s.");
174 debug("check that copying from 1 unclean 3d canvas to a 2d canvas clears the o rigin-clean flag on the 2d canvas."); 181 assertMsg(!causedException(makeReadPixels(gl)),
175 var canvas3 = document.getElementById("canvas3"); 182 "readPixels should never throw exception -- not possible to dirty or igin of WebGL canvas.");
176 var ctx2d = canvas3.getContext("2d"); 183 assertMsg(!causedException(makeToDataURL(canvas1)),
177 assertMsg(!causedException(makeToDataURL(canvas3)), 184 "should not throw exception by toDataURL for WebGL canvas, which sho uld stay origin clean.");
178 "should not throw exception by toDataURL for origin clean canvas.");
179 ctx2d.drawImage(canvas2, 0, 0);
180 assertMsg(causedException(makeToDataURL(canvas3)),
181 "should throw exception by toDataURL for NON origin clean canvas.");
182 185
183 debug(""); 186 if (testVideo) {
184 debug("check that copying a video from another origin clears the origin-clean flag."); 187 debug("check that an attempt to upload a video from another origin throws an exception.");
185 var canvas4 = document.getElementById("canvas4"); 188 var video = document.getElementById("video");
186 var gl4 = create3DContext(canvas4); 189 assertMsg(causedException(makeTexImage2D(gl, video)),
187 assertMsg(!causedException(makeReadPixels(gl4)), 190 "texImage2D with cross-origin video should throw exception.");
188 "should not throw exception by readPixels for origin clean canvas.") ; 191 assertMsg(causedException(makeTexSubImage2D(gl, video)),
189 assertMsg(!causedException(makeToDataURL(canvas4)), 192 "texSubImage2D with cross-origin video should throw exception.");
190 "should not throw exception by toDataURL for origin clean canvas."); 193
191 var tex4 = gl4.createTexture(); 194 debug("check that readPixels and toDataURL continue to work against this can vas.");
192 gl4.bindTexture(gl4.TEXTURE_2D, tex4); 195 assertMsg(!causedException(makeReadPixels(gl)),
193 gl4.texImage2D( 196 "readPixels should never throw exception -- not possible to dirty origin of WebGL canvas.");
194 gl4.TEXTURE_2D, 0, gl4.RGBA, gl4.RGBA, gl4.UNSIGNED_BYTE, video); 197 assertMsg(!causedException(makeToDataURL(canvas1)),
195 assertMsg(causedException(makeReadPixels(gl4)), 198 "should not throw exception by toDataURL for WebGL canvas, which s hould stay origin clean.");
196 "should throw exception by readPixels for NON origin clean canvas.") ; 199 }
197 assertMsg(causedException(makeToDataURL(canvas4)),
198 "should throw exception by toDataURL for NON origin clean canvas.");
199 200
200 debug('<br /><span class="pass">TEST COMPLETE</span>'); 201 debug('<br /><span class="pass">TEST COMPLETE</span>');
201 if (window.layoutTestController) 202 if (window.layoutTestController)
202 layoutTestController.waitUntilDone(); 203 layoutTestController.waitUntilDone();
203 if (window.layoutTestController) { 204 if (window.layoutTestController) {
204 layoutTestController.notifyDone(); 205 layoutTestController.notifyDone();
205 } 206 }
206 } 207 }
207 </script> 208 </script>
208 </head> 209 </head>
209 <body onload="init()"> 210 <body onload="init()">
210 <div id="description"></div> 211 <div id="description"></div>
211 <div id="console"></div> 212 <div id="console"></div>
212 <canvas id="canvas1"></canvas> 213 <canvas id="canvas1"></canvas>
213 <canvas id="canvas2"></canvas> 214 <canvas id="canvas2"></canvas>
214 <canvas id="canvas3"></canvas>
215 <canvas id="canvas4"></canvas>
216 <img id="img" src="http://localhost:8000/local/resources/abe.png" style="display :none;"> 215 <img id="img" src="http://localhost:8000/local/resources/abe.png" style="display :none;">
217 <video id="video" style="display:none;"/> 216 <video id="video" style="display:none;"/>
218 </body> 217 </body>
219 </html> 218 </html>
OLDNEW
« no previous file with comments | « LayoutTests/ChangeLog ('k') | LayoutTests/http/tests/canvas/webgl/origin-clean-conformance-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698