| OLD | NEW |
| 1 // js-test now supports lazily printing test results which dumps all test | 1 // js-test now supports lazily printing test results which dumps all test |
| 2 // results once at the end of the test instead of building them up. To enable | 2 // results once at the end of the test instead of building them up. To enable |
| 3 // this option, call setPrintTestResultsLazily() before running any tests. | 3 // this option, call setPrintTestResultsLazily() before running any tests. |
| 4 var _lazyTestResults; // Set by setPrintTestResultsLazily(). | 4 var _lazyTestResults; // Set by setPrintTestResultsLazily(). |
| 5 var _lazyDescription; // Set by description() after setPrintTestResultsLazily(). |
| 5 | 6 |
| 6 // svg/dynamic-updates tests set enablePixelTesting=true, as we want to dump tex
t + pixel results | 7 // svg/dynamic-updates tests set enablePixelTesting=true, as we want to dump tex
t + pixel results |
| 7 if (self.testRunner) { | 8 if (self.testRunner) { |
| 8 if (self.enablePixelTesting) | 9 if (self.enablePixelTesting) |
| 9 testRunner.dumpAsTextWithPixelResults(); | 10 testRunner.dumpAsTextWithPixelResults(); |
| 10 else | 11 else |
| 11 testRunner.dumpAsText(); | 12 testRunner.dumpAsText(); |
| 12 } | 13 } |
| 13 | 14 |
| 14 var isJsTest = true; | 15 var isJsTest = true; |
| 15 | 16 |
| 16 var description, debug, successfullyParsed; | 17 var description, debug, successfullyParsed, getOrCreateTestElement; |
| 17 | 18 |
| 18 var expectingError; // set by shouldHaveError() | 19 var expectingError; // set by shouldHaveError() |
| 19 var expectedErrorMessage; // set by onerror when expectingError is true | 20 var expectedErrorMessage; // set by onerror when expectingError is true |
| 20 var unexpectedErrorMessage; // set by onerror when expectingError is not true | 21 var unexpectedErrorMessage; // set by onerror when expectingError is not true |
| 21 | 22 |
| 22 (function() { | 23 (function() { |
| 23 | 24 |
| 24 function getOrCreate(id, tagName) | 25 getOrCreateTestElement = function(id, tagName) |
| 25 { | 26 { |
| 26 var element = document.getElementById(id); | 27 var element = document.getElementById(id); |
| 27 if (element) | 28 if (element) |
| 28 return element; | 29 return element; |
| 29 | 30 |
| 30 element = document.createElement(tagName); | 31 element = document.createElement(tagName); |
| 31 element.id = id; | 32 element.id = id; |
| 32 var refNode; | 33 var refNode; |
| 33 var parent = document.body || document.documentElement; | 34 var parent = document.body || document.documentElement; |
| 34 if (id == "description") | 35 if (id == "description") |
| 35 refNode = getOrCreate("console", "div"); | 36 refNode = getOrCreateTestElement("console", "div"); |
| 36 else | 37 else |
| 37 refNode = parent.firstChild; | 38 refNode = parent.firstChild; |
| 38 | 39 |
| 39 parent.insertBefore(element, refNode); | 40 parent.insertBefore(element, refNode); |
| 40 return element; | 41 return element; |
| 41 } | 42 } |
| 42 | 43 |
| 43 description = function description(msg, quiet) | 44 description = function description(msg, quiet) |
| 44 { | 45 { |
| 45 // For MSIE 6 compatibility | 46 // For MSIE 6 compatibility |
| 46 var span = document.createElement("span"); | 47 var span = document.createElement("span"); |
| 47 if (quiet) | 48 if (quiet) |
| 48 span.innerHTML = '<p>' + msg + '</p><p>On success, you will see no "
<span class="fail">FAIL</span>" messages, followed by "<span class="pass">TEST C
OMPLETE</span>".</p>'; | 49 span.innerHTML = '<p>' + msg + '</p><p>On success, you will see no "
<span class="fail">FAIL</span>" messages, followed by "<span class="pass">TEST C
OMPLETE</span>".</p>'; |
| 49 else | 50 else |
| 50 span.innerHTML = '<p>' + msg + '</p><p>On success, you will see a se
ries of "<span class="pass">PASS</span>" messages, followed by "<span class="pas
s">TEST COMPLETE</span>".</p>'; | 51 span.innerHTML = '<p>' + msg + '</p><p>On success, you will see a se
ries of "<span class="pass">PASS</span>" messages, followed by "<span class="pas
s">TEST COMPLETE</span>".</p>'; |
| 51 | 52 |
| 52 var description = getOrCreate("description", "p"); | 53 if (_lazyTestResults) { |
| 54 _lazyDescription = span; |
| 55 return; |
| 56 } |
| 57 |
| 58 var description = getOrCreateTestElement("description", "p"); |
| 53 if (description.firstChild) | 59 if (description.firstChild) |
| 54 description.replaceChild(span, description.firstChild); | 60 description.replaceChild(span, description.firstChild); |
| 55 else | 61 else |
| 56 description.appendChild(span); | 62 description.appendChild(span); |
| 57 }; | 63 }; |
| 58 | 64 |
| 59 debug = function debug(msg) | 65 debug = function debug(msg) |
| 60 { | 66 { |
| 61 if (self._lazyTestResults) { | 67 if (self._lazyTestResults) { |
| 62 self._lazyTestResults.push(msg); | 68 self._lazyTestResults.push(msg); |
| 63 } else { | 69 } else { |
| 64 var span = document.createElement("span"); | 70 var span = document.createElement("span"); |
| 65 getOrCreate("console", "div").appendChild(span); // insert it first
so XHTML knows the namespace | 71 // insert it first so XHTML knows the namespace; |
| 72 getOrCreateTestElement("console", "div").appendChild(span); |
| 66 span.innerHTML = msg + '<br />'; | 73 span.innerHTML = msg + '<br />'; |
| 67 } | 74 } |
| 68 }; | 75 }; |
| 69 | 76 |
| 70 var css = | 77 var css = |
| 71 ".pass {" + | 78 ".pass {" + |
| 72 "font-weight: bold;" + | 79 "font-weight: bold;" + |
| 73 "color: green;" + | 80 "color: green;" + |
| 74 "}" + | 81 "}" + |
| 75 ".fail {" + | 82 ".fail {" + |
| (...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 | 811 |
| 805 // It's possible for an async test to call finishJSTest() before js-test-post.js | 812 // It's possible for an async test to call finishJSTest() before js-test-post.js |
| 806 // has been parsed. | 813 // has been parsed. |
| 807 function finishJSTest() | 814 function finishJSTest() |
| 808 { | 815 { |
| 809 wasFinishJSTestCalled = true; | 816 wasFinishJSTestCalled = true; |
| 810 if (!self.wasPostTestScriptParsed) | 817 if (!self.wasPostTestScriptParsed) |
| 811 return; | 818 return; |
| 812 isSuccessfullyParsed(); | 819 isSuccessfullyParsed(); |
| 813 | 820 |
| 821 if (self._lazyDescription) |
| 822 getOrCreateTestElement("description", "p").appendChild(self._lazyDescripti
on); |
| 823 |
| 814 if (self._lazyTestResults && self._lazyTestResults.length > 0) { | 824 if (self._lazyTestResults && self._lazyTestResults.length > 0) { |
| 815 var consoleElement = document.getElementById("console"); | 825 var consoleElement = getOrCreateTestElement("console", "div"); |
| 816 if (!consoleElement) { | |
| 817 consoleElement = document.createElement("div"); | |
| 818 consoleElement.id = "console"; | |
| 819 var parent = document.body || document.documentElement; | |
| 820 parent.insertBefore(consoleElement, parent.firstChild); | |
| 821 } | |
| 822 self._lazyTestResults.forEach(function(msg) { | 826 self._lazyTestResults.forEach(function(msg) { |
| 823 var span = document.createElement("span"); | 827 var span = document.createElement("span"); |
| 828 consoleElement.appendChild(span); |
| 824 span.innerHTML = msg + '<br />'; | 829 span.innerHTML = msg + '<br />'; |
| 825 consoleElement.appendChild(span); | |
| 826 }); | 830 }); |
| 827 } | 831 } |
| 828 | 832 |
| 829 if (self.jsTestIsAsync && self.testRunner) | 833 if (self.jsTestIsAsync && self.testRunner) |
| 830 testRunner.notifyDone(); | 834 testRunner.notifyDone(); |
| 831 } | 835 } |
| 832 | 836 |
| 833 function startWorker(testScriptURL, workerType) | 837 function startWorker(testScriptURL, workerType) |
| 834 { | 838 { |
| 835 self.jsTestIsAsync = true; | 839 self.jsTestIsAsync = true; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 testPassed = function(msg) { | 913 testPassed = function(msg) { |
| 910 workerPort.postMessage('PASS:' + msg); | 914 workerPort.postMessage('PASS:' + msg); |
| 911 }; | 915 }; |
| 912 finishJSTest = function() { | 916 finishJSTest = function() { |
| 913 workerPort.postMessage('DONE:'); | 917 workerPort.postMessage('DONE:'); |
| 914 }; | 918 }; |
| 915 debug = function(msg) { | 919 debug = function(msg) { |
| 916 workerPort.postMessage(msg); | 920 workerPort.postMessage(msg); |
| 917 }; | 921 }; |
| 918 } | 922 } |
| OLD | NEW |