2 var printFullTestDetails = true; // This is optionaly switched of by test whose tested values can differ. (see disableFullTestDetailsPrinting())
6 if (window.testRunner) {
7 if (window.runPixelTests)
8 testRunner.dumpAsTextWithPixelResults();
10 testRunner.dumpAsText();
11 testRunner.waitUntilDone();
14 function runWithKeyDown(fn)
17 document.removeEventListener("keypress", thunk, false);
20 document.addEventListener("keypress", thunk, false);
22 if (window.eventSender)
23 eventSender.keyDown(" ", []);
28 if (!console && document.body) {
29 console = document.createElement('div');
30 document.body.appendChild(console);
35 function testAndEnd(testFuncString)
37 test(testFuncString, true);
40 function test(testFuncString, endit)
42 logResult(eval(testFuncString), "TEST(" + testFuncString + ")");
47 function testExpected(testFuncString, expected, comparison)
50 var observed = eval(testFuncString);
56 if (comparison === undefined)
62 case '<': success = observed < expected; break;
63 case '<=': success = observed <= expected; break;
64 case '>': success = observed > expected; break;
65 case '>=': success = observed >= expected; break;
66 case '!=': success = observed != expected; break;
67 case '==': success = observed == expected; break;
70 reportExpected(success, testFuncString, comparison, expected, observed)
75 function reportExpected(success, testFuncString, comparison, expected, observed)
79 var msg = "Test " + testNumber;
81 if (printFullTestDetails || !success)
82 msg = "EXPECTED (<em>" + testFuncString + " </em>" + comparison + " '<em>" + expected + "</em>')";
85 msg += ", OBSERVED '<em>" + observed + "</em>'";
87 logResult(success, msg);
90 function waitForEventAndEnd(element, eventName, funcString)
92 waitForEvent(element, eventName, funcString, true)
95 function waitForEventOnce(element, eventName, func, endit)
97 waitForEvent(element, eventName, func, endit, true)
100 function waitForEvent(element, eventName, func, endit, once)
102 function _eventCallback(event)
105 element.removeEventListener(eventName, _eventCallback);
107 consoleWrite("EVENT(" + eventName + ")");
116 element.addEventListener(eventName, _eventCallback);
119 function waitForEventAndTest(element, eventName, testFuncString, endit)
121 function _eventCallback(event)
123 logResult(eval(testFuncString), "EVENT(" + eventName + ") TEST(" + testFuncString + ")");
128 element.addEventListener(eventName, _eventCallback);
131 function waitForEventTestAndEnd(element, eventName, testFuncString)
133 waitForEventAndTest(element, eventName, testFuncString, true);
136 var testEnded = false;
140 consoleWrite("END OF TEST");
142 if (window.testRunner)
143 testRunner.notifyDone();
146 function logResult(success, text)
149 consoleWrite(text + " <span style='color:green'>OK</span>");
151 consoleWrite(text + " <span style='color:red'>FAIL</span>");
154 function consoleWrite(text)
158 logConsole().innerHTML += text + "<br>";