|
Lines 82-89
function causedException(func) {
a/LayoutTests/http/tests/canvas/webgl/origin-clean-conformance.html_sec1
|
| 82 |
return hadException; |
82 |
return hadException; |
| 83 |
} |
83 |
} |
| 84 |
|
84 |
|
| 85 |
var testVideo = false; |
|
|
| 86 |
|
| 87 |
function init() { |
85 |
function init() { |
| 88 |
var video = document.getElementById("video"); |
86 |
var video = document.getElementById("video"); |
| 89 |
|
87 |
|
|
Lines 110-116
function init() {
a/LayoutTests/http/tests/canvas/webgl/origin-clean-conformance.html_sec2
|
| 110 |
video.src = videoFile; |
108 |
video.src = videoFile; |
| 111 |
video.addEventListener("playing", runTests); |
109 |
video.addEventListener("playing", runTests); |
| 112 |
video.play(); |
110 |
video.play(); |
| 113 |
testVideo = true; |
|
|
| 114 |
} else { |
111 |
} else { |
| 115 |
// Still run the other tests, even if the video failed. |
112 |
// Still run the other tests, even if the video failed. |
| 116 |
runTests(); |
113 |
runTests(); |
|
Lines 118-139
function init() {
a/LayoutTests/http/tests/canvas/webgl/origin-clean-conformance.html_sec3
|
| 118 |
} |
115 |
} |
| 119 |
|
116 |
|
| 120 |
function runTests() { |
117 |
function runTests() { |
| 121 |
description("This test ensures WebGL implementations follow proper same-origin restrictions."); |
118 |
description("This test ensures WebGL implementations follow proper origin restrictions."); |
| 122 |
var img = document.getElementById("img"); |
119 |
var img = document.getElementById("img"); |
| 123 |
assertMsg(img.width > 0 && img.height > 0, "img was loaded"); |
120 |
assertMsg(img.width > 0 && img.height > 0, "img was loaded"); |
| 124 |
|
121 |
|
| 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 |
|
| 137 |
function makeReadPixels(gl) { |
122 |
function makeReadPixels(gl) { |
| 138 |
return function() { |
123 |
return function() { |
| 139 |
var buf = new Uint8Array(4); |
124 |
var buf = new Uint8Array(4); |
|
Lines 147-202
function runTests() {
a/LayoutTests/http/tests/canvas/webgl/origin-clean-conformance.html_sec4
|
| 147 |
} |
132 |
} |
| 148 |
} |
133 |
} |
| 149 |
|
134 |
|
| 150 |
var canvas1 = document.getElementById("canvas1"); |
|
|
| 151 |
var gl = create3DContext(canvas1); |
| 152 |
|
| 153 |
debug(""); |
135 |
debug(""); |
| 154 |
debug("check that an attempt to upload an image from another origin throws an exception."); |
136 |
debug("check that copying an img from another origin clears the origin-clean flag."); |
| 155 |
var tex = gl.createTexture(); |
137 |
var canvas1 = document.getElementById("canvas1"); |
| 156 |
gl.bindTexture(gl.TEXTURE_2D, tex); |
138 |
var gl1 = create3DContext(canvas1); |
| 157 |
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 256, 256, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); |
139 |
assertMsg(!causedException(makeReadPixels(gl1)), |
| 158 |
assertMsg(causedException(makeTexImage2D(gl, img)), |
140 |
"should not throw exception by readPixels for origin clean canvas."); |
| 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 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)), |
141 |
assertMsg(!causedException(makeToDataURL(canvas1)), |
| 167 |
"should not throw exception by toDataURL for WebGL canvas, which should stay origin clean."); |
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); |
| 168 |
|
147 |
|
| 169 |
debug("check that an attempt to upload a tainted canvas throws an exception."); |
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 |
|
| 153 |
debug(""); |
| 154 |
debug("check that copying from 1 unclean 3d canvas to another clears the origin-clean flag on the second canvas."); |
| 170 |
var canvas2 = document.getElementById("canvas2"); |
155 |
var canvas2 = document.getElementById("canvas2"); |
| 171 |
var ctx2d = canvas2.getContext("2d"); |
156 |
var gl2 = create3DContext(canvas2); |
| 172 |
ctx2d.drawImage(img, 0, 0); |
157 |
|
|
|
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."); |
| 173 |
assertMsg(causedException(makeToDataURL(canvas2)), |
170 |
assertMsg(causedException(makeToDataURL(canvas2)), |
| 174 |
"should throw exception by toDataURL for NON origin clean canvas."); |
171 |
"should throw exception by toDataURL for NON origin clean canvas."); |
| 175 |
assertMsg(causedException(makeTexImage2D(gl, canvas2)), |
172 |
|
| 176 |
"texImage2D with NON origin clean canvas should throw exception."); |
173 |
debug(""); |
| 177 |
assertMsg(causedException(makeTexSubImage2D(gl, canvas2)), |
174 |
debug("check that copying from 1 unclean 3d canvas to a 2d canvas clears the origin-clean flag on the 2d canvas."); |
| 178 |
"texSubImage2D with NON origin clean canvas should throw exception."); |
175 |
var canvas3 = document.getElementById("canvas3"); |
| 179 |
|
176 |
var ctx2d = canvas3.getContext("2d"); |
| 180 |
debug("check that readPixels and toDataURL continue to work against this canvas."); |
177 |
assertMsg(!causedException(makeToDataURL(canvas3)), |
| 181 |
assertMsg(!causedException(makeReadPixels(gl)), |
178 |
"should not throw exception by toDataURL for origin clean canvas."); |
| 182 |
"readPixels should never throw exception -- not possible to dirty origin of WebGL canvas."); |
179 |
ctx2d.drawImage(canvas2, 0, 0); |
| 183 |
assertMsg(!causedException(makeToDataURL(canvas1)), |
180 |
assertMsg(causedException(makeToDataURL(canvas3)), |
| 184 |
"should not throw exception by toDataURL for WebGL canvas, which should stay origin clean."); |
181 |
"should throw exception by toDataURL for NON origin clean canvas."); |
| 185 |
|
182 |
|
| 186 |
if (testVideo) { |
183 |
debug(""); |
| 187 |
debug("check that an attempt to upload a video from another origin throws an exception."); |
184 |
debug("check that copying a video from another origin clears the origin-clean flag."); |
| 188 |
var video = document.getElementById("video"); |
185 |
var canvas4 = document.getElementById("canvas4"); |
| 189 |
assertMsg(causedException(makeTexImage2D(gl, video)), |
186 |
var gl4 = create3DContext(canvas4); |
| 190 |
"texImage2D with cross-origin video should throw exception."); |
187 |
assertMsg(!causedException(makeReadPixels(gl4)), |
| 191 |
assertMsg(causedException(makeTexSubImage2D(gl, video)), |
188 |
"should not throw exception by readPixels for origin clean canvas."); |
| 192 |
"texSubImage2D with cross-origin video should throw exception."); |
189 |
assertMsg(!causedException(makeToDataURL(canvas4)), |
| 193 |
|
190 |
"should not throw exception by toDataURL for origin clean canvas."); |
| 194 |
debug("check that readPixels and toDataURL continue to work against this canvas."); |
191 |
var tex4 = gl4.createTexture(); |
| 195 |
assertMsg(!causedException(makeReadPixels(gl)), |
192 |
gl4.bindTexture(gl4.TEXTURE_2D, tex4); |
| 196 |
"readPixels should never throw exception -- not possible to dirty origin of WebGL canvas."); |
193 |
gl4.texImage2D( |
| 197 |
assertMsg(!causedException(makeToDataURL(canvas1)), |
194 |
gl4.TEXTURE_2D, 0, gl4.RGBA, gl4.RGBA, gl4.UNSIGNED_BYTE, video); |
| 198 |
"should not throw exception by toDataURL for WebGL canvas, which should stay origin clean."); |
195 |
assertMsg(causedException(makeReadPixels(gl4)), |
| 199 |
} |
196 |
"should throw exception by readPixels for NON origin clean canvas."); |
|
|
197 |
assertMsg(causedException(makeToDataURL(canvas4)), |
| 198 |
"should throw exception by toDataURL for NON origin clean canvas."); |
| 200 |
|
199 |
|
| 201 |
debug('<br /><span class="pass">TEST COMPLETE</span>'); |
200 |
debug('<br /><span class="pass">TEST COMPLETE</span>'); |
| 202 |
if (window.layoutTestController) |
201 |
if (window.layoutTestController) |
|
Lines 212-217
function runTests() {
a/LayoutTests/http/tests/canvas/webgl/origin-clean-conformance.html_sec5
|
| 212 |
<div id="console"></div> |
211 |
<div id="console"></div> |
| 213 |
<canvas id="canvas1"></canvas> |
212 |
<canvas id="canvas1"></canvas> |
| 214 |
<canvas id="canvas2"></canvas> |
213 |
<canvas id="canvas2"></canvas> |
|
|
214 |
<canvas id="canvas3"></canvas> |
| 215 |
<canvas id="canvas4"></canvas> |
| 215 |
<img id="img" src="http://localhost:8000/local/resources/abe.png" style="display:none;"> |
216 |
<img id="img" src="http://localhost:8000/local/resources/abe.png" style="display:none;"> |
| 216 |
<video id="video" style="display:none;"/> |
217 |
<video id="video" style="display:none;"/> |
| 217 |
</body> |
218 |
</body> |