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

Side by Side Diff: conformance/textures/origin-clean-conformance.html

Issue 8342021: Add webgl conformance tests r15841. (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/webgl/sdk/tests/
Patch Set: Created 9 years, 2 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 | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 <!--
2 Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 Use of this source code is governed by a BSD-style license that can be
4 found in the LICENSE file.
5 -->
6 <!DOCTYPE html>
7 <html>
8 <head>
9 <meta charset="utf-8">
10 <title>WebGL Origin Restrictions Conformance Tests</title>
11 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
12 <script src="../../resources/desktop-gl-constants.js" type="text/javascript"></s cript>
13 <script src="../../resources/js-test-pre.js"></script>
14 <script src="../resources/webgl-test.js"></script>
15 <script>
16 // This function returns the last 2 words of the domain of a URL
17 // This is probably not the correct check but it will do for now.
18 function getBaseDomain(str) {
19 str = str.replace("\\", "/");
20 var pos = str.indexOf("://");
21 if (pos >= 0) {
22 str = str.substr(pos + 3);
23 }
24 var parts = str.split('/');
25 var domain = parts[0].match(/\w+\.\w+$/);
26 return domain || '';
27 }
28
29 // Checks if function throws an exception.
30 function causedException(func) {
31 var hadException = false;
32 try {
33 func();
34 } catch(e) {
35 hadException = true;
36 }
37 return hadException;
38 }
39
40 window.onload = function() {
41 description("This test ensures WebGL implementations follow proper same-origin restrictions.");
42 var img = document.getElementById("img");
43 assertMsg(img.width > 0 && img.height > 0, "img was loaded");
44 imgDomain = getBaseDomain(img.src);
45 pageDomain = getBaseDomain(window.location.toString());
46 assertMsg(imgDomain != pageDomain,
47 "img domain (" + imgDomain + ") and page domain (" + pageDomain + ") are not the same.");
48
49 function makeTexImage2D(gl, src) {
50 return function() {
51 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, src);
52 };
53 }
54
55 function makeTexSubImage2D(gl, src) {
56 return function() {
57 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, src);
58 };
59 }
60
61 function makeReadPixels(gl) {
62 return function() {
63 var buf = new Uint8Array(4);
64 gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf);
65 };
66 }
67
68 function makeToDataURL(canvas) {
69 return function() {
70 var data = canvas.toDataURL();
71 }
72 }
73
74 var canvas1 = document.getElementById("canvas1");
75 var gl = create3DContext(canvas1);
76
77 debug("");
78 debug("check that an attempt to upload an image from another origin throws an exception.");
79 var tex = gl.createTexture();
80 gl.bindTexture(gl.TEXTURE_2D, tex);
81 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 256, 256, 0, gl.RGBA, gl.UNSIGNED_BYT E, null);
82 assertMsg(causedException(makeTexImage2D(gl, img)),
83 "texImage2D with cross-origin image should throw exception.");
84 assertMsg(causedException(makeTexSubImage2D(gl, img)),
85 "texSubImage2D with cross-origin image should throw exception.");
86
87 debug("check that readPixels and toDataURL continue to work against this canva s.");
88 assertMsg(!causedException(makeReadPixels(gl)),
89 "readPixels should never throw exception -- not possible to dirty or igin of WebGL canvas.");
90 assertMsg(!causedException(makeToDataURL(canvas1)),
91 "should not throw exception by toDataURL for WebGL canvas, which sho uld stay origin clean.");
92
93 debug("check that an attempt to upload a tainted canvas throws an exception.") ;
94 var canvas2 = document.getElementById("canvas2");
95 var ctx2d = canvas2.getContext("2d");
96 ctx2d.drawImage(img, 0, 0);
97 assertMsg(causedException(makeToDataURL(canvas2)),
98 "should throw exception by toDataURL for NON origin clean canvas.");
99 assertMsg(causedException(makeTexImage2D(gl, canvas2)),
100 "texImage2D with NON origin clean canvas should throw exception.");
101 assertMsg(causedException(makeTexSubImage2D(gl, canvas2)),
102 "texSubImage2D with NON origin clean canvas should throw exception." );
103
104 debug("check that readPixels and toDataURL continue to work against this canva s.");
105 assertMsg(!causedException(makeReadPixels(gl)),
106 "readPixels should never throw exception -- not possible to dirty or igin of WebGL canvas.");
107 assertMsg(!causedException(makeToDataURL(canvas1)),
108 "should not throw exception by toDataURL for WebGL canvas, which sho uld stay origin clean.");
109
110 // TODO: Should check video.
111 // TODO: Should check CORS support.
112
113 debug("");
114 successfullyParsed = true;
115 shouldBeTrue("successfullyParsed");
116 debug('<br /><span class="pass">TEST COMPLETE</span>');
117 notifyFinishedToHarness();
118 }
119 </script>
120 </head>
121 <body>
122 <div id="description"></div>
123 <div id="console"></div>
124 <canvas id="canvas1"></canvas>
125 <canvas id="canvas2"></canvas>
126 <img id="img" src="http://www.opengl.org/img/opengl_logo.jpg" style="display:non e;">
127 </body>
128 </html>
OLDNEW
« no previous file with comments | « conformance/textures/gl-teximage.html ('k') | conformance/textures/tex-image-and-sub-image-2d-with-array-buffer-view.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698