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

Side by Side Diff: third_party/webgl/sdk/tests/conformance/textures/origin-clean-conformance.html

Issue 10399113: Roll webgl conformance tests to r17874: part 2, adding r17874 (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/
Patch Set: Created 8 years, 7 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
3 /*
4 ** Copyright (c) 2012 The Khronos Group Inc.
5 **
6 ** Permission is hereby granted, free of charge, to any person obtaining a
7 ** copy of this software and/or associated documentation files (the
8 ** "Materials"), to deal in the Materials without restriction, including
9 ** without limitation the rights to use, copy, modify, merge, publish,
10 ** distribute, sublicense, and/or sell copies of the Materials, and to
11 ** permit persons to whom the Materials are furnished to do so, subject to
12 ** the following conditions:
13 **
14 ** The above copyright notice and this permission notice shall be included
15 ** in all copies or substantial portions of the Materials.
16 **
17 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
24 */
25
26 -->
27
28 <!DOCTYPE html>
29 <html>
30 <head>
31 <meta charset="utf-8">
32 <title>WebGL Origin Restrictions Conformance Tests</title>
33 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
34 <script src="../../resources/desktop-gl-constants.js" type="text/javascript"></s cript>
35 <script src="../../resources/js-test-pre.js"></script>
36 <script src="../resources/webgl-test.js"></script>
37 <script>
38 // This function returns the last 2 words of the domain of a URL
39 // This is probably not the correct check but it will do for now.
40 function getBaseDomain(str) {
41 str = str.replace("\\", "/");
42 var pos = str.indexOf("://");
43 if (pos >= 0) {
44 str = str.substr(pos + 3);
45 }
46 var parts = str.split('/');
47 var domain = parts[0].match(/\w+\.\w+$/);
48 return domain || '';
49 }
50
51 // Checks if function throws an exception.
52 function causedException(func) {
53 var hadException = false;
54 try {
55 func();
56 } catch(e) {
57 hadException = true;
58 }
59 return hadException;
60 }
61
62 window.onload = function() {
63 description("This test ensures WebGL implementations follow proper same-origin restrictions.");
64 var img = document.getElementById("img");
65 assertMsg(img.width > 0 && img.height > 0, "img was loaded");
66 imgDomain = getBaseDomain(img.src);
67 pageDomain = getBaseDomain(window.location.toString());
68 assertMsg(imgDomain != pageDomain,
69 "img domain (" + imgDomain + ") and page domain (" + pageDomain + ") are not the same.");
70
71 function makeTexImage2D(gl, src) {
72 return function() {
73 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, src);
74 };
75 }
76
77 function makeTexSubImage2D(gl, src) {
78 return function() {
79 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, src);
80 };
81 }
82
83 function makeReadPixels(gl) {
84 return function() {
85 var buf = new Uint8Array(4);
86 gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf);
87 };
88 }
89
90 function makeToDataURL(canvas) {
91 return function() {
92 var data = canvas.toDataURL();
93 }
94 }
95
96 var canvas1 = document.getElementById("canvas1");
97 var gl = create3DContext(canvas1);
98
99 debug("");
100 debug("check that an attempt to upload an image from another origin throws an exception.");
101 var tex = gl.createTexture();
102 gl.bindTexture(gl.TEXTURE_2D, tex);
103 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 256, 256, 0, gl.RGBA, gl.UNSIGNED_BYT E, null);
104 assertMsg(causedException(makeTexImage2D(gl, img)),
105 "texImage2D with cross-origin image should throw exception.");
106 assertMsg(causedException(makeTexSubImage2D(gl, img)),
107 "texSubImage2D with cross-origin image should throw exception.");
108
109 debug("check that readPixels and toDataURL continue to work against this canva s.");
110 assertMsg(!causedException(makeReadPixels(gl)),
111 "readPixels should never throw exception -- not possible to dirty or igin of WebGL canvas.");
112 assertMsg(!causedException(makeToDataURL(canvas1)),
113 "should not throw exception by toDataURL for WebGL canvas, which sho uld stay origin clean.");
114
115 debug("check that an attempt to upload a tainted canvas throws an exception.") ;
116 var canvas2 = document.getElementById("canvas2");
117 var ctx2d = canvas2.getContext("2d");
118 ctx2d.drawImage(img, 0, 0);
119 assertMsg(causedException(makeToDataURL(canvas2)),
120 "should throw exception by toDataURL for NON origin clean canvas.");
121 assertMsg(causedException(makeTexImage2D(gl, canvas2)),
122 "texImage2D with NON origin clean canvas should throw exception.");
123 assertMsg(causedException(makeTexSubImage2D(gl, canvas2)),
124 "texSubImage2D with NON origin clean canvas should throw exception." );
125
126 debug("check that readPixels and toDataURL continue to work against this canva s.");
127 assertMsg(!causedException(makeReadPixels(gl)),
128 "readPixels should never throw exception -- not possible to dirty or igin of WebGL canvas.");
129 assertMsg(!causedException(makeToDataURL(canvas1)),
130 "should not throw exception by toDataURL for WebGL canvas, which sho uld stay origin clean.");
131
132 // TODO: Should check video.
133 // TODO: Should check CORS support.
134
135 debug("");
136 successfullyParsed = true;
137 shouldBeTrue("successfullyParsed");
138 debug('<br /><span class="pass">TEST COMPLETE</span>');
139 notifyFinishedToHarness();
140 }
141 </script>
142 </head>
143 <body>
144 <div id="description"></div>
145 <div id="console"></div>
146 <canvas id="canvas1"></canvas>
147 <canvas id="canvas2"></canvas>
148 <img id="img" src="http://www.opengl.org/img/opengl_logo.jpg" style="display:non e;">
149 </body>
150 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698