Backed out changeset b462e7b742d8 (bug 1908261) for causing multiple reftest failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / more / unit.js
blob3ca21c4cae82226e5a2cc35b77417525dacce033
1 /*
2 Unit testing library for the OpenGL ES 2.0 HTML Canvas context
3 */
5 /*
6 Copyright (c) 2019 The Khronos Group Inc.
7 Use of this source code is governed by an MIT-style license that can be
8 found in the LICENSE.txt file.
9 */
11 /* -- plaform specific code -- */
13 // WebKit
14 if (window.testRunner && !window.layoutTestController) {
15 window.layoutTestController = window.testRunner;
18 if (window.layoutTestController) {
19 layoutTestController.dumpAsText();
20 layoutTestController.waitUntilDone();
22 // The WebKit testing system compares console output.
23 // Because the output of the WebGL Tests is GPU dependent
24 // we turn off console messages.
25 window.console.log = function() { };
26 window.console.error = function() { };
28 // RAF doesn't work in LayoutTests. Disable it so the tests will
29 // use setTimeout instead.
30 window.requestAnimationFrame = undefined;
31 window.webkitRequestAnimationFrame = undefined;
34 if (window.internals) {
35 window.internals.settings.setWebGLErrorsToConsoleEnabled(false);
38 /* -- end platform specific code --*/
39 Tests = {
40 autorun : true,
41 message : null,
42 delay : 0,
43 autoinit: true,
45 startUnit : function(){ return []; },
46 setup : function() { return arguments; },
47 teardown : function() {},
48 endUnit : function() {}
51 var __testSuccess__ = true;
52 var __testFailCount__ = 0;
53 var __testLog__;
54 var __backlog__ = [];
56 var getUrlOptions = (function() {
57 var _urlOptionsParsed = false;
58 var _urlOptions = {};
59 return function() {
60 if (!_urlOptionsParsed) {
61 var s = window.location.href;
62 var q = s.indexOf("?");
63 var e = s.indexOf("#");
64 if (e < 0) {
65 e = s.length;
67 var query = s.substring(q + 1, e);
68 var pairs = query.split("&");
69 for (var ii = 0; ii < pairs.length; ++ii) {
70 var keyValue = pairs[ii].split("=");
71 var key = keyValue[0];
72 var value = decodeURIComponent(keyValue[1]);
73 _urlOptions[key] = value;
75 _urlOptionsParsed = true;
78 return _urlOptions;
80 })();
82 if (typeof quietMode == 'undefined') {
83 var quietMode = (function() {
84 var _quietModeChecked = false;
85 var _isQuiet = false;
86 return function() {
87 if (!_quietModeChecked) {
88 _isQuiet = (getUrlOptions().quiet == 1);
89 _quietModeChecked = true;
91 return _isQuiet;
93 })();
96 Object.toSource = function(a, seen){
97 if (a == null) return "null";
98 if (typeof a == 'boolean') return a ? "true" : "false";
99 if (typeof a == 'string') return '"' + a.replace(/"/g, '\\"') + '"';
100 if (a instanceof HTMLElement) return a.toString();
101 if (a.width && a.height && a.data) return "[ImageData]";
102 if (a instanceof Array) {
103 if (!seen) seen = [];
104 var idx = seen.indexOf(a);
105 if (idx != -1) return '#'+(idx+1)+'#';
106 seen.unshift(a);
107 var srcs = a.map(function(o){ return Object.toSource(o,seen) });
108 var prefix = '';
109 idx = seen.indexOf(a);
110 if (idx != -1) prefix = '#'+(idx+1)+'=';
111 return prefix + '[' + srcs.join(", ") + ']';
113 if (typeof a == 'object') {
114 if (!seen) seen = [];
115 var idx = seen.indexOf(a);
116 if (idx != -1) return '#'+(idx+1)+'#';
117 seen.unshift(a);
118 var members = [];
119 var name;
120 try {
121 for (var i in a) {
122 if (i.search(/^[a-zA-Z0-9]+$/) != -1)
123 name = i;
124 else
125 name = '"' + i.replace(/"/g, '\\"') + '"';
126 var ai;
127 try { ai = a[i]; }
128 catch(e) { ai = 'null /*ERROR_ACCESSING*/'; }
129 var s = name + ':' + Object.toSource(ai, seen);
130 members.push(s);
132 } catch (e) {}
133 var prefix = '';
134 idx = seen.indexOf(a);
135 if (idx != -1) prefix = '#'+(idx+1)+'=';
136 return prefix + '{' + members.join(", ") + '}'
138 if (typeof a == 'function')
139 return '('+a.toString().replace(/\n/g, " ").replace(/\s+/g, " ")+')';
140 return a.toString();
143 function formatError(e) {
144 if (window.console) console.log(e);
145 var pathSegs = location.href.toString().split("/");
146 var currentDoc = e.lineNumber != null ? pathSegs[pathSegs.length - 1] : null;
147 var trace = (e.filename || currentDoc) + ":" + e.lineNumber + (e.trace ? "\n"+e.trace : "");
148 return e.message + "\n" + trace;
151 function runTests() {
152 var h = document.getElementById('test-status');
153 if (h == null) {
154 h = document.createElement('h1');
155 h.id = 'test-status';
156 document.body.appendChild(h);
158 h.textContent = "";
159 var log = document.getElementById('test-log');
160 if (log == null) {
161 log = document.createElement('div');
162 log.id = 'test-log';
163 document.body.appendChild(log);
165 while (log.childNodes.length > 0)
166 log.removeChild(log.firstChild);
168 var setup_args = [];
170 if (Tests.startUnit != null) {
171 __testLog__ = document.createElement('div');
172 try {
173 setup_args = Tests.startUnit();
174 if (__testLog__.childNodes.length > 0)
175 log.appendChild(__testLog__);
176 } catch(e) {
177 testFailed("startUnit", formatError(e));
178 log.appendChild(__testLog__);
179 printTestStatus();
180 return;
184 var testsRun = false;
185 var allTestsSuccessful = true;
187 for (var i in Tests) {
188 if (i.substring(0,4) != "test") continue;
189 __testLog__ = document.createElement('div');
190 __testSuccess__ = true;
191 try {
192 doTestNotify (i);
193 var args = setup_args;
194 if (Tests.setup != null)
195 args = Tests.setup.apply(Tests, setup_args);
196 Tests[i].apply(Tests, args);
197 if (Tests.teardown != null)
198 Tests.teardown.apply(Tests, args);
200 catch (e) {
201 testFailed(i, e.name, formatError(e));
203 if (__testSuccess__ == false) {
204 ++__testFailCount__;
206 var h = document.createElement('h2');
207 h.textContent = i;
208 __testLog__.insertBefore(h, __testLog__.firstChild);
209 log.appendChild(__testLog__);
210 allTestsSuccessful = allTestsSuccessful && __testSuccess__ == true;
211 reportTestResultsToHarness(__testSuccess__, i);
212 doTestNotify (i+"--"+(__testSuccess__?"OK":"FAIL"));
213 testsRun = true;
216 printTestStatus(testsRun);
217 if (Tests.endUnit != null) {
218 __testLog__ = document.createElement('div');
219 try {
220 Tests.endUnit.apply(Tests, setup_args);
221 if (__testLog__.childNodes.length > 0)
222 log.appendChild(__testLog__);
223 } catch(e) {
224 testFailed("endUnit", e.name, formatError(e));
225 log.appendChild(__testLog__);
228 notifyFinishedToHarness(allTestsSuccessful, "finished tests");
231 function doTestNotify(name) {
232 //try {
233 // var xhr = new XMLHttpRequest();
234 // xhr.open("GET", "http://localhost:8888/"+name, true);
235 // xhr.send(null);
236 //} catch(e) {}
239 function testFailed(assertName, name) {
240 var d = document.createElement('div');
241 var h = document.createElement('h3');
242 var d1 = document.createElement("span");
243 h.appendChild(d1);
244 d1.appendChild(document.createTextNode("FAIL: "));
245 d1.style.color = "red";
246 h.appendChild(document.createTextNode(
247 name==null ? assertName : name + " (in " + assertName + ")"));
248 d.appendChild(h);
249 var args = []
250 for (var i=2; i<arguments.length; i++) {
251 var a = arguments[i];
252 var p = document.createElement('p');
253 p.style.whiteSpace = 'pre';
254 p.textContent = (a == null) ? "null" :
255 (typeof a == 'boolean' || typeof a == 'string') ? a : Object.toSource(a);
256 args.push(p.textContent);
257 d.appendChild(p);
259 __testLog__.appendChild(d);
260 __testSuccess__ = false;
261 doTestNotify([assertName, name].concat(args).join("--"));
264 function testPassed(assertName, name) {
265 if (!quietMode()) {
266 var d = document.createElement('div');
267 var h = document.createElement('h3');
268 var d1 = document.createElement("span");
269 h.appendChild(d1);
270 d1.appendChild(document.createTextNode("PASS: "));
271 d1.style.color = "green";
272 h.appendChild(document.createTextNode(
273 name==null ? assertName : name + " (in " + assertName + ")"));
274 d.appendChild(h);
275 var args = []
276 for (var i=2; i<arguments.length; i++) {
277 var a = arguments[i];
278 var p = document.createElement('p');
279 p.style.whiteSpace = 'pre';
280 p.textContent = (a == null) ? "null" :
281 (typeof a == 'boolean' || typeof a == 'string') ? a : Object.toSource(a);
282 args.push(p.textContent);
283 d.appendChild(p);
285 __testLog__.appendChild(d);
287 doTestNotify([assertName, name].concat(args).join("--"));
290 function checkTestSuccess() {
291 return __testFailCount__ == 0;
294 window.addEventListener('load', function(){
295 for (var i=0; i<__backlog__.length; i++)
296 log(__backlog__[i]);
297 }, false);
299 function log(msg) {
300 var p = document.createElement('p');
301 var a = [];
302 for (var i=0; i<arguments.length; i++)
303 a.push(arguments[i]);
304 p.textContent = a.join(", ");
305 if (!__testLog__) {
306 if (document.body)
307 document.body.appendChild(p);
308 else
309 __backlog__.push(msg);
310 } else {
311 __testLog__.appendChild(p);
315 function printTestStatus(testsRun) {
316 var status = document.getElementById('test-status');
317 if (testsRun) {
318 status.className = checkTestSuccess() ? 'ok' : 'fail';
319 status.textContent = checkTestSuccess() ? "PASS" : "FAIL";
320 } else {
321 status.className = 'fail';
322 status.textContent = "NO TESTS FOUND";
326 function assertFail(name, f) {
327 if (f == null) { f = name; name = null; }
328 var r = false;
329 try { f(); } catch(e) { r=true; }
330 if (!r) {
331 testFailed("assertFail", name, f);
332 return false;
333 } else {
334 testPassed("assertFail", name, f);
335 return true;
339 function assertOk(name, f) {
340 if (f == null) { f = name; name = null; }
341 var r = false;
342 var err;
343 try { f(); r=true; } catch(e) { err = e; }
344 if (!r) {
345 testFailed("assertOk", name, f, err.toString());
346 return false;
347 } else {
348 testPassed("assertOk", name, f);
349 return true;
353 function assert(name, v) {
354 if (v == null) { v = name; name = null; }
355 if (!v) {
356 testFailed("assert", name, v);
357 return false;
358 } else {
359 testPassed("assert", name, v);
360 return true;
364 function assertProperty(name, v, p) {
365 if (p == null) { p = v; v = name; name = p; }
366 if (v[p] == null) {
367 testFailed("assertProperty", name);
368 return false;
369 } else {
370 testPassed("assertProperty", name);
371 return true;
375 function compare(a,b) {
376 if (typeof a == 'number' && typeof b == 'number') {
377 return a == b;
378 } else {
379 return Object.toSource(a) == Object.toSource(b);
383 function assertEquals(name, v, p) {
384 if (p == null) { p = v; v = name; name = null; }
385 if (!compare(v, p)) {
386 testFailed("assertEquals", name, v, p);
387 return false;
388 } else {
389 testPassed("assertEquals", name, v, p);
390 return true;
394 function assertArrayEquals(name, v, p) {
395 if (p == null) { p = v; v = name; name = null; }
396 if (!v) {
397 testFailed("assertArrayEquals: first array undefined", name, v, p);
398 return false;
400 if (!p) {
401 testFailed("assertArrayEquals: second array undefined", name, v, p);
402 return false;
404 if (v.length != p.length) {
405 testFailed("assertArrayEquals", name, v, p);
406 return false;
408 for (var ii = 0; ii < v.length; ++ii) {
409 if (v[ii] != p[ii]) {
410 testFailed("assertArrayEquals", name, v, p);
411 return false;
414 testPassed("assertArrayEquals", name, v, p);
415 return true;
418 function assertArrayEqualsWithEpsilon(name, v, p, l) {
419 if (l == null) { l = p; p = v; v = name; name = null; }
420 if (!v) {
421 testFailed("assertArrayEqualsWithEpsilon: first array undefined", name, v, p);
422 return false;
424 if (!p) {
425 testFailed("assertArrayEqualsWithEpsilon: second array undefined", name, v, p);
426 return false;
428 if (!l) {
429 testFailed("assertArrayEqualsWithEpsilon: limit array undefined", name, v, p);
430 return false;
432 if (v.length != p.length) {
433 testFailed("assertArrayEqualsWithEpsilon", name, v, p, l);
434 return false;
436 if (v.length != l.length) {
437 testFailed("assertArrayEqualsWithEpsilon", name, v, p, l);
438 return false;
440 for (var ii = 0; ii < v.length; ++ii) {
441 if (Math.abs(v[ii]- p[ii])>l[ii]) {
442 testFailed("assertArrayEqualsWithEpsilon", name, v, p, l);
443 return false;
446 testPassed("assertArrayEqualsWithEpsilon", name, v, p, l);
447 return true;
450 function assertNotEquals(name, v, p) {
451 if (p == null) { p = v; v = name; name = null; }
452 if (compare(v, p)) {
453 testFailed("assertNotEquals", name, v, p)
454 return false;
455 } else {
456 testPassed("assertNotEquals", name, v, p)
457 return true;
461 function time(elementId, f) {
462 var s = document.getElementById(elementId);
463 var t0 = new Date().getTime();
464 f();
465 var t1 = new Date().getTime();
466 s.textContent = 'Elapsed: '+(t1-t0)+' ms';
469 function randomFloat () {
470 // note that in fuzz-testing, this can used as the size of a buffer to allocate.
471 // so it shouldn't return astronomic values. The maximum value 10000000 is already quite big.
472 var fac = 1.0;
473 var r = Math.random();
474 if (r < 0.25)
475 fac = 10;
476 else if (r < 0.4)
477 fac = 100;
478 else if (r < 0.5)
479 fac = 1000;
480 else if (r < 0.6)
481 fac = 100000;
482 else if (r < 0.7)
483 fac = 10000000;
484 else if (r < 0.8)
485 fac = NaN;
486 return -0.5*fac + Math.random() * fac;
488 function randomFloatFromRange(lo, hi) {
489 var r = Math.random();
490 if (r < 0.05)
491 return lo;
492 else if (r > 0.95)
493 return hi;
494 else
495 return lo + Math.random()*(hi-lo);
497 function randomInt (sz) {
498 if (sz != null)
499 return Math.floor(Math.random()*sz);
500 else
501 return Math.floor(randomFloat());
503 function randomIntFromRange(lo, hi) {
504 return Math.floor(randomFloatFromRange(lo, hi));
506 function randomLength () {
507 var l = Math.floor(Math.random() * 256);
508 if (Math.random < 0.5) l = l / 10;
509 if (Math.random < 0.3) l = l / 10;
510 return l;
512 function randomSmallIntArray () {
513 var l = randomLength();
514 var s = new Array(l);
515 for (var i=0; i<l; i++)
516 s[i] = Math.floor(Math.random() * 256)-1;
517 return s;
519 function randomFloatArray () {
520 var l = randomLength();
521 var s = new Array(l);
522 for (var i=0; i<l; i++)
523 s[i] = randomFloat();
524 return s;
526 function randomIntArray () {
527 var l = randomLength();
528 var s = new Array(l);
529 for (var i=0; i<l; i++)
530 s[i] = randomFloat();
531 return s;
533 function randomMixedArray () {
534 var l = randomLength();
535 var s = new Array(l);
536 for (var i=0; i<l; i++)
537 s[i] = randomNonArray();
538 return s;
540 function randomArray () {
541 var r = Math.random();
542 if (r < 0.3)
543 return randomFloatArray();
544 else if (r < 0.6)
545 return randomIntArray();
546 else if (r < 0.8)
547 return randomSmallIntArray();
548 else
549 return randomMixedArray();
551 function randomString () {
552 return String.fromCharCode.apply(String, randomSmallIntArray());
554 function randomGLConstant () {
555 return GLConstants[Math.floor(Math.random() * GLConstants.length)];
558 function randomNonArray() {
559 var r = Math.random();
560 if (r < 0.25) {
561 return randomFloat();
562 } else if (r < 0.6) {
563 return randomInt();
564 } else if (r < 0.7) {
565 return (r < 0.65);
566 } else if (r < 0.87) {
567 return randomString();
568 } else if (r < 0.98) {
569 return randomGLConstant();
570 } else {
571 return null;
575 function generateRandomArg(pos, count) {
576 if (pos == 0 && Math.random() < 0.5)
577 return randomGLConstant();
578 if (pos == count-1 && Math.random() < 0.25)
579 if (Math.random() < 0.5)
580 return randomString();
581 else
582 return randomArray();
583 var r = Math.random();
584 if (r < 0.25) {
585 return randomFloat();
586 } else if (r < 0.6) {
587 return randomInt();
588 } else if (r < 0.7) {
589 return (r < 0.65);
590 } else if (r < 0.77) {
591 return randomString();
592 } else if (r < 0.84) {
593 return randomArray();
594 } else if (r < 0.98) {
595 return randomGLConstant();
596 } else {
597 return null;
602 function generateRandomArgs(count) {
603 var arr = new Array(count);
604 for (var i=0; i<count; i++)
605 arr[i] = generateRandomArg(i, count);
606 return arr;
609 // qc (arg1gen, arg2gen, ..., predicate)
610 // qc (randomString, randomInt, randomInt, function(s,i,j){ s.substring(i,j) })
611 function qc() {
614 GLConstants = [
616 0x00000100,
617 0x00000400,
618 0x00004000,
619 0x0000,
620 0x0001,
621 0x0002,
622 0x0003,
623 0x0004,
624 0x0005,
625 0x0006,
628 0x0300,
629 0x0301,
630 0x0302,
631 0x0303,
632 0x0304,
633 0x0305,
634 0x0306,
635 0x0307,
636 0x0308,
637 0x8006,
638 0x8009,
639 0x8009,
640 0x883D,
641 0x800A,
642 0x800B,
643 0x80C8,
644 0x80C9,
645 0x80CA,
646 0x80CB,
647 0x8001,
648 0x8002,
649 0x8003,
650 0x8004,
651 0x8005,
652 0x8892,
653 0x8893,
654 0x8894,
655 0x8895,
656 0x88E0,
657 0x88E4,
658 0x88E8,
659 0x8764,
660 0x8765,
661 0x8626,
662 0x0404,
663 0x0405,
664 0x0408,
665 0x0DE1,
666 0x0B44,
667 0x0BE2,
668 0x0BD0,
669 0x0B90,
670 0x0B71,
671 0x0C11,
672 0x8037,
673 0x809E,
674 0x80A0,
676 0x0500,
677 0x0501,
678 0x0502,
679 0x0505,
680 0x0900,
681 0x0901,
682 0x0B21,
683 0x846D,
684 0x846E,
685 0x0B45,
686 0x0B46,
687 0x0B70,
688 0x0B72,
689 0x0B73,
690 0x0B74,
691 0x0B91,
692 0x0B92,
693 0x0B94,
694 0x0B95,
695 0x0B96,
696 0x0B97,
697 0x0B93,
698 0x0B98,
699 0x8800,
700 0x8801,
701 0x8802,
702 0x8803,
703 0x8CA3,
704 0x8CA4,
705 0x8CA5,
706 0x0BA2,
707 0x0C10,
708 0x0C22,
709 0x0C23,
710 0x0CF5,
711 0x0D05,
712 0x0D33,
713 0x0D3A,
714 0x0D50,
715 0x0D52,
716 0x0D53,
717 0x0D54,
718 0x0D55,
719 0x0D56,
720 0x0D57,
721 0x2A00,
722 0x8038,
723 0x8069,
724 0x80A8,
725 0x80A9,
726 0x80AA,
727 0x80AB,
728 0x86A2,
729 0x86A3,
730 0x1100,
731 0x1101,
732 0x1102,
733 0x8192,
734 0x1400,
735 0x1401,
736 0x1402,
737 0x1403,
738 0x1404,
739 0x1405,
740 0x1406,
741 0x140C,
742 0x1902,
743 0x1906,
744 0x1907,
745 0x1908,
746 0x1909,
747 0x190A,
748 0x8033,
749 0x8034,
750 0x8363,
751 0x8B30,
752 0x8B31,
753 0x8869,
754 0x8DFB,
755 0x8DFC,
756 0x8B4D,
757 0x8B4C,
758 0x8872,
759 0x8DFD,
760 0x8B4F,
761 0x8B80,
762 0x8B82,
763 0x8B83,
764 0x8B85,
765 0x8B86,
766 0x8B87,
767 0x8B89,
768 0x8B8A,
769 0x8B8C,
770 0x8B8D,
771 0x0200,
772 0x0201,
773 0x0202,
774 0x0203,
775 0x0204,
776 0x0205,
777 0x0206,
778 0x0207,
779 0x1E00,
780 0x1E01,
781 0x1E02,
782 0x1E03,
783 0x150A,
784 0x8507,
785 0x8508,
786 0x1F00,
787 0x1F01,
788 0x1F02,
789 0x1F03,
790 0x2600,
791 0x2601,
792 0x2700,
793 0x2701,
794 0x2702,
795 0x2703,
796 0x2800,
797 0x2801,
798 0x2802,
799 0x2803,
800 0x1702,
801 0x8513,
802 0x8514,
803 0x8515,
804 0x8516,
805 0x8517,
806 0x8518,
807 0x8519,
808 0x851A,
809 0x851C,
810 0x84C0,
811 0x84C1,
812 0x84C2,
813 0x84C3,
814 0x84C4,
815 0x84C5,
816 0x84C6,
817 0x84C7,
818 0x84C8,
819 0x84C9,
820 0x84CA,
821 0x84CB,
822 0x84CC,
823 0x84CD,
824 0x84CE,
825 0x84CF,
826 0x84D0,
827 0x84D1,
828 0x84D2,
829 0x84D3,
830 0x84D4,
831 0x84D5,
832 0x84D6,
833 0x84D7,
834 0x84D8,
835 0x84D9,
836 0x84DA,
837 0x84DB,
838 0x84DC,
839 0x84DD,
840 0x84DE,
841 0x84DF,
842 0x84E0,
843 0x2901,
844 0x812F,
845 0x8370,
846 0x8B50,
847 0x8B51,
848 0x8B52,
849 0x8B53,
850 0x8B54,
851 0x8B55,
852 0x8B56,
853 0x8B57,
854 0x8B58,
855 0x8B59,
856 0x8B5A,
857 0x8B5B,
858 0x8B5C,
859 0x8B5E,
860 0x8B60,
861 0x8622,
862 0x8623,
863 0x8624,
864 0x8625,
865 0x886A,
866 0x8645,
867 0x889F,
868 0x8B9A,
869 0x8B9B,
870 0x8B81,
871 0x8B84,
872 0x8B88,
873 0x8DFA,
874 0x8DF8,
875 0x8DF9,
876 0x8DF0,
877 0x8DF1,
878 0x8DF2,
879 0x8DF3,
880 0x8DF4,
881 0x8DF5,
882 0x8D40,
883 0x8D41,
884 0x8056,
885 0x8057,
886 0x8D62,
887 0x81A5,
888 0x1901,
889 0x8D48,
890 0x8D42,
891 0x8D43,
892 0x8D44,
893 0x8D50,
894 0x8D51,
895 0x8D52,
896 0x8D53,
897 0x8D54,
898 0x8D55,
899 0x8CD0,
900 0x8CD1,
901 0x8CD2,
902 0x8CD3,
903 0x8CE0,
904 0x8D00,
905 0x8D20,
907 0x8CD5,
908 0x8CD6,
909 0x8CD7,
910 0x8CD9,
911 0x8CDD,
912 0x8CA6,
913 0x8CA7,
914 0x84E8,
915 0x0506,
916 0x809D
919 function reportTestResultsToHarness(success, msg) {
920 if (window.parent.webglTestHarness) {
921 window.parent.webglTestHarness.reportResults(window.location.pathname, success, msg);
925 function notifyFinishedToHarness() {
926 if (window.parent.webglTestHarness) {
927 window.parent.webglTestHarness.notifyFinished(window.location.pathname);
931 function initTests() {
932 if (Tests.message != null) {
933 var h = document.getElementById('test-message');
934 if (h == null) {
935 h = document.createElement('p');
936 h.id = 'test-message';
937 document.body.insertBefore(h, document.body.firstChild);
939 h.textContent = Tests.message;
941 if (Tests.autorun) {
942 runTests();
943 } else {
944 var h = document.getElementById('test-run');
945 if (h == null) {
946 h = document.createElement('input');
947 h.type = 'submit';
948 h.value = "Run tests";
949 h.addEventListener('click', function(ev){
950 runTests();
951 ev.preventDefault();
952 }, false);
953 h.id = 'test-run';
954 document.body.insertBefore(h, document.body.firstChild);
956 h.textContent = Tests.message;
961 window.addEventListener('load', function(){
962 if (Tests.autoinit) {
963 // let the browser hopefully finish updating the gl canvas surfaces if we are given a delay
964 if (Tests.delay)
965 setTimeout(initTests, Tests.delay);
966 else
967 initTests()
969 }, false);