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

Side by Side Diff: third_party/webgl/sdk/tests/resources/js-test-pre.js

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 ** Copyright (c) 2012 The Khronos Group Inc.
3 **
4 ** Permission is hereby granted, free of charge, to any person obtaining a
5 ** copy of this software and/or associated documentation files (the
6 ** "Materials"), to deal in the Materials without restriction, including
7 ** without limitation the rights to use, copy, modify, merge, publish,
8 ** distribute, sublicense, and/or sell copies of the Materials, and to
9 ** permit persons to whom the Materials are furnished to do so, subject to
10 ** the following conditions:
11 **
12 ** The above copyright notice and this permission notice shall be included
13 ** in all copies or substantial portions of the Materials.
14 **
15 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
22 */
23
24 // WebKit Specfic code. Add your own here.
25 function initNonKhronosFramework(waitUntilDone) {
26 if (window.layoutTestController) {
27 layoutTestController.overridePreference("WebKitWebGLEnabled", "1");
28 layoutTestController.dumpAsText();
29 if (waitUntilDone) {
30 layoutTestController.waitUntilDone();
31 }
32 }
33 }
34
35 function nonKhronosFrameworkNotifyDone() {
36 if (window.layoutTestController) {
37 layoutTestController.notifyDone();
38 }
39 }
40
41 function reportTestResultsToHarness(success, msg) {
42 if (window.parent.webglTestHarness) {
43 window.parent.webglTestHarness.reportResults(success, msg);
44 }
45 }
46
47 function notifyFinishedToHarness() {
48 if (window.parent.webglTestHarness) {
49 window.parent.webglTestHarness.notifyFinished();
50 }
51 }
52
53 function description(msg)
54 {
55 if (msg === undefined) {
56 msg = document.title;
57 }
58 // For MSIE 6 compatibility
59 var span = document.createElement("span");
60 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>';
61 var description = document.getElementById("description");
62 if (description.firstChild)
63 description.replaceChild(span, description.firstChild);
64 else
65 description.appendChild(span);
66 }
67
68 function debug(msg)
69 {
70 var span = document.createElement("span");
71 document.getElementById("console").appendChild(span); // insert it first so XHTML knows the namespace
72 span.innerHTML = msg + '<br />';
73 }
74
75 function escapeHTML(text)
76 {
77 return text.replace(/&/g, "&amp;").replace(/</g, "&lt;");
78 }
79
80 function testPassed(msg)
81 {
82 reportTestResultsToHarness(true, msg);
83 debug('<span><span class="pass">PASS</span> ' + escapeHTML(msg) + '</span>') ;
84 }
85
86 function testFailed(msg)
87 {
88 reportTestResultsToHarness(false, msg);
89 debug('<span><span class="fail">FAIL</span> ' + escapeHTML(msg) + '</span>') ;
90 }
91
92 function areArraysEqual(_a, _b)
93 {
94 try {
95 if (_a.length !== _b.length)
96 return false;
97 for (var i = 0; i < _a.length; i++)
98 if (_a[i] !== _b[i])
99 return false;
100 } catch (ex) {
101 return false;
102 }
103 return true;
104 }
105
106 function isMinusZero(n)
107 {
108 // the only way to tell 0 from -0 in JS is the fact that 1/-0 is
109 // -Infinity instead of Infinity
110 return n === 0 && 1/n < 0;
111 }
112
113 function isResultCorrect(_actual, _expected)
114 {
115 if (_expected === 0)
116 return _actual === _expected && (1/_actual) === (1/_expected);
117 if (_actual === _expected)
118 return true;
119 if (typeof(_expected) == "number" && isNaN(_expected))
120 return typeof(_actual) == "number" && isNaN(_actual);
121 if (Object.prototype.toString.call(_expected) == Object.prototype.toString.c all([]))
122 return areArraysEqual(_actual, _expected);
123 return false;
124 }
125
126 function stringify(v)
127 {
128 if (v === 0 && 1/v < 0)
129 return "-0";
130 else return "" + v;
131 }
132
133 function evalAndLog(_a)
134 {
135 if (typeof _a != "string")
136 debug("WARN: tryAndLog() expects a string argument");
137
138 // Log first in case things go horribly wrong or this causes a sync event.
139 debug(_a);
140
141 var _av;
142 try {
143 _av = eval(_a);
144 } catch (e) {
145 testFailed(_a + " threw exception " + e);
146 }
147 return _av;
148 }
149
150 function shouldBe(_a, _b, quiet)
151 {
152 if (typeof _a != "string" || typeof _b != "string")
153 debug("WARN: shouldBe() expects string arguments");
154 var exception;
155 var _av;
156 try {
157 _av = eval(_a);
158 } catch (e) {
159 exception = e;
160 }
161 var _bv = eval(_b);
162
163 if (exception)
164 testFailed(_a + " should be " + _bv + ". Threw exception " + exception);
165 else if (isResultCorrect(_av, _bv)) {
166 if (!quiet) {
167 testPassed(_a + " is " + _b);
168 }
169 } else if (typeof(_av) == typeof(_bv))
170 testFailed(_a + " should be " + _bv + ". Was " + stringify(_av) + ".");
171 else
172 testFailed(_a + " should be " + _bv + " (of type " + typeof _bv + "). Wa s " + _av + " (of type " + typeof _av + ").");
173 }
174
175 function shouldNotBe(_a, _b, quiet)
176 {
177 if (typeof _a != "string" || typeof _b != "string")
178 debug("WARN: shouldNotBe() expects string arguments");
179 var exception;
180 var _av;
181 try {
182 _av = eval(_a);
183 } catch (e) {
184 exception = e;
185 }
186 var _bv = eval(_b);
187
188 if (exception)
189 testFailed(_a + " should not be " + _bv + ". Threw exception " + excepti on);
190 else if (!isResultCorrect(_av, _bv)) {
191 if (!quiet) {
192 testPassed(_a + " is not " + _b);
193 }
194 } else
195 testFailed(_a + " should not be " + _bv + ".");
196 }
197
198 function shouldBeTrue(_a) { shouldBe(_a, "true"); }
199 function shouldBeFalse(_a) { shouldBe(_a, "false"); }
200 function shouldBeNaN(_a) { shouldBe(_a, "NaN"); }
201 function shouldBeNull(_a) { shouldBe(_a, "null"); }
202
203 function shouldBeEqualToString(a, b)
204 {
205 var unevaledString = '"' + b.replace(/"/g, "\"") + '"';
206 shouldBe(a, unevaledString);
207 }
208
209 function shouldEvaluateTo(actual, expected) {
210 // A general-purpose comparator. 'actual' should be a string to be
211 // evaluated, as for shouldBe(). 'expected' may be any type and will be
212 // used without being eval'ed.
213 if (expected == null) {
214 // Do this before the object test, since null is of type 'object'.
215 shouldBeNull(actual);
216 } else if (typeof expected == "undefined") {
217 shouldBeUndefined(actual);
218 } else if (typeof expected == "function") {
219 // All this fuss is to avoid the string-arg warning from shouldBe().
220 try {
221 actualValue = eval(actual);
222 } catch (e) {
223 testFailed("Evaluating " + actual + ": Threw exception " + e);
224 return;
225 }
226 shouldBe("'" + actualValue.toString().replace(/\n/g, "") + "'",
227 "'" + expected.toString().replace(/\n/g, "") + "'");
228 } else if (typeof expected == "object") {
229 shouldBeTrue(actual + " == '" + expected + "'");
230 } else if (typeof expected == "string") {
231 shouldBe(actual, expected);
232 } else if (typeof expected == "boolean") {
233 shouldBe("typeof " + actual, "'boolean'");
234 if (expected)
235 shouldBeTrue(actual);
236 else
237 shouldBeFalse(actual);
238 } else if (typeof expected == "number") {
239 shouldBe(actual, stringify(expected));
240 } else {
241 debug(expected + " is unknown type " + typeof expected);
242 shouldBeTrue(actual, "'" +expected.toString() + "'");
243 }
244 }
245
246 function shouldBeNonZero(_a)
247 {
248 var exception;
249 var _av;
250 try {
251 _av = eval(_a);
252 } catch (e) {
253 exception = e;
254 }
255
256 if (exception)
257 testFailed(_a + " should be non-zero. Threw exception " + exception);
258 else if (_av != 0)
259 testPassed(_a + " is non-zero.");
260 else
261 testFailed(_a + " should be non-zero. Was " + _av);
262 }
263
264 function shouldBeNonNull(_a)
265 {
266 var exception;
267 var _av;
268 try {
269 _av = eval(_a);
270 } catch (e) {
271 exception = e;
272 }
273
274 if (exception)
275 testFailed(_a + " should be non-null. Threw exception " + exception);
276 else if (_av != null)
277 testPassed(_a + " is non-null.");
278 else
279 testFailed(_a + " should be non-null. Was " + _av);
280 }
281
282 function shouldBeUndefined(_a)
283 {
284 var exception;
285 var _av;
286 try {
287 _av = eval(_a);
288 } catch (e) {
289 exception = e;
290 }
291
292 if (exception)
293 testFailed(_a + " should be undefined. Threw exception " + exception);
294 else if (typeof _av == "undefined")
295 testPassed(_a + " is undefined.");
296 else
297 testFailed(_a + " should be undefined. Was " + _av);
298 }
299
300 function shouldBeDefined(_a)
301 {
302 var exception;
303 var _av;
304 try {
305 _av = eval(_a);
306 } catch (e) {
307 exception = e;
308 }
309
310 if (exception)
311 testFailed(_a + " should be defined. Threw exception " + exception);
312 else if (_av !== undefined)
313 testPassed(_a + " is defined.");
314 else
315 testFailed(_a + " should be defined. Was " + _av);
316 }
317
318 function shouldBeGreaterThanOrEqual(_a, _b) {
319 if (typeof _a != "string" || typeof _b != "string")
320 debug("WARN: shouldBeGreaterThanOrEqual expects string arguments");
321
322 var exception;
323 var _av;
324 try {
325 _av = eval(_a);
326 } catch (e) {
327 exception = e;
328 }
329 var _bv = eval(_b);
330
331 if (exception)
332 testFailed(_a + " should be >= " + _b + ". Threw exception " + exception );
333 else if (typeof _av == "undefined" || _av < _bv)
334 testFailed(_a + " should be >= " + _b + ". Was " + _av + " (of type " + typeof _av + ").");
335 else
336 testPassed(_a + " is >= " + _b);
337 }
338
339 function expectTrue(v, msg) {
340 if (v) {
341 testPassed(msg);
342 } else {
343 testFailed(msg);
344 }
345 }
346
347 function shouldThrow(_a, _e)
348 {
349 var exception;
350 var _av;
351 try {
352 _av = eval(_a);
353 } catch (e) {
354 exception = e;
355 }
356
357 var _ev;
358 if (_e)
359 _ev = eval(_e);
360
361 if (exception) {
362 if (typeof _e == "undefined" || exception == _ev)
363 testPassed(_a + " threw exception " + exception + ".");
364 else
365 testFailed(_a + " should throw " + (typeof _e == "undefined" ? "an excepti on" : _ev) + ". Threw exception " + exception + ".");
366 } else if (typeof _av == "undefined")
367 testFailed(_a + " should throw " + (typeof _e == "undefined" ? "an exception " : _ev) + ". Was undefined.");
368 else
369 testFailed(_a + " should throw " + (typeof _e == "undefined" ? "an exception " : _ev) + ". Was " + _av + ".");
370 }
371
372 function shouldBeType(_a, _type) {
373 var exception;
374 var _av;
375 try {
376 _av = eval(_a);
377 } catch (e) {
378 exception = e;
379 }
380
381 var _typev = eval(_type);
382
383 if (_av instanceof _typev) {
384 testPassed(_a + " is an instance of " + _type);
385 } else {
386 testFailed(_a + " is not an instance of " + _type);
387 }
388 }
389
390 function assertMsg(assertion, msg) {
391 if (assertion) {
392 testPassed(msg);
393 } else {
394 testFailed(msg);
395 }
396 }
397
398 function gc() {
399 if (window.GCController) {
400 window.GCController.collect();
401 return;
402 }
403
404 if (window.opera && window.opera.collect) {
405 window.opera.collect();
406 return;
407 }
408
409 try {
410 window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
411 .getInterface(Components.interfaces.nsIDOMWindowUtils)
412 .garbageCollect();
413 return;
414 } catch(e) {}
415
416 function gcRec(n) {
417 if (n < 1)
418 return {};
419 var temp = {i: "ab" + i + (i / 100000)};
420 temp += "foo";
421 gcRec(n-1);
422 }
423 for (var i = 0; i < 1000; i++)
424 gcRec(10);
425 }
426
427 function finishTest() {
428 successfullyParsed = true;
429 var epilogue = document.createElement("script");
430 epilogue.onload = function() {
431 if (window.nonKhronosFrameworkNotifyDone) {
432 window.nonKhronosFrameworkNotifyDone();
433 }
434 };
435
436 var basePath = "";
437 var expectedBase = "js-test-pre.js";
438 var scripts = document.getElementsByTagName('script');
439 for (var script, i = 0; script = scripts[i]; i++) {
440 var src = script.src;
441 var l = src.length;
442 if (src.substr(l - expectedBase.length) == expectedBase) {
443 basePath = src.substr(0, l - expectedBase.length);
444 break;
445 }
446 }
447 epilogue.src = basePath + "js-test-post.js";
448 document.body.appendChild(epilogue);
449 }
450
OLDNEW
« no previous file with comments | « third_party/webgl/sdk/tests/resources/js-test-post.js ('k') | third_party/webgl/sdk/tests/resources/js-test-style.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698