| OLD | NEW |
| 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 | |
| 3 // this option, call setPrintTestResultsLazily() before running any tests. | |
| 4 var _lazyTestResults; // Set by setPrintTestResultsLazily(). | |
| 5 | |
| 6 // svg/dynamic-updates tests set enablePixelTesting=true, as we want to dump tex
t + pixel results | 1 // svg/dynamic-updates tests set enablePixelTesting=true, as we want to dump tex
t + pixel results |
| 7 if (self.testRunner) { | 2 if (self.testRunner) { |
| 8 if (self.enablePixelTesting) | 3 if (self.enablePixelTesting) |
| 9 testRunner.dumpAsTextWithPixelResults(); | 4 testRunner.dumpAsTextWithPixelResults(); |
| 10 else | 5 else |
| 11 testRunner.dumpAsText(); | 6 testRunner.dumpAsText(); |
| 12 } | 7 } |
| 13 | 8 |
| 14 var isJsTest = true; | 9 var isJsTest = true; |
| 15 | 10 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 | 46 |
| 52 var description = getOrCreate("description", "p"); | 47 var description = getOrCreate("description", "p"); |
| 53 if (description.firstChild) | 48 if (description.firstChild) |
| 54 description.replaceChild(span, description.firstChild); | 49 description.replaceChild(span, description.firstChild); |
| 55 else | 50 else |
| 56 description.appendChild(span); | 51 description.appendChild(span); |
| 57 }; | 52 }; |
| 58 | 53 |
| 59 debug = function debug(msg) | 54 debug = function debug(msg) |
| 60 { | 55 { |
| 61 if (self._lazyTestResults) { | 56 var span = document.createElement("span"); |
| 62 self._lazyTestResults.push(msg); | 57 getOrCreate("console", "div").appendChild(span); // insert it first so X
HTML knows the namespace |
| 63 } else { | 58 span.innerHTML = msg + '<br />'; |
| 64 var span = document.createElement("span"); | |
| 65 getOrCreate("console", "div").appendChild(span); // insert it first
so XHTML knows the namespace | |
| 66 span.innerHTML = msg + '<br />'; | |
| 67 } | |
| 68 }; | 59 }; |
| 69 | 60 |
| 70 var css = | 61 var css = |
| 71 ".pass {" + | 62 ".pass {" + |
| 72 "font-weight: bold;" + | 63 "font-weight: bold;" + |
| 73 "color: green;" + | 64 "color: green;" + |
| 74 "}" + | 65 "}" + |
| 75 ".fail {" + | 66 ".fail {" + |
| 76 "font-weight: bold;" + | 67 "font-weight: bold;" + |
| 77 "color: red;" + | 68 "color: red;" + |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 // http://crbug.com/308818 : The new implementation of SVGListProperties do
not necessary return the same wrapper object, so === operator would not work. We
compare for their string representation instead. | 174 // http://crbug.com/308818 : The new implementation of SVGListProperties do
not necessary return the same wrapper object, so === operator would not work. We
compare for their string representation instead. |
| 184 if (isNewSVGTearOffType(expected) && typeof(expected) == typeof(actual) && a
ctual.valueAsString == expected.valueAsString) | 175 if (isNewSVGTearOffType(expected) && typeof(expected) == typeof(actual) && a
ctual.valueAsString == expected.valueAsString) |
| 185 return true; | 176 return true; |
| 186 if (typeof(expected) == "number" && isNaN(expected)) | 177 if (typeof(expected) == "number" && isNaN(expected)) |
| 187 return typeof(actual) == "number" && isNaN(actual); | 178 return typeof(actual) == "number" && isNaN(actual); |
| 188 if (expected && (Object.prototype.toString.call(expected) == Object.prototyp
e.toString.call([]))) | 179 if (expected && (Object.prototype.toString.call(expected) == Object.prototyp
e.toString.call([]))) |
| 189 return areArraysEqual(actual, expected); | 180 return areArraysEqual(actual, expected); |
| 190 return false; | 181 return false; |
| 191 } | 182 } |
| 192 | 183 |
| 193 // Returns a sorted array of property names of object. This function returns | |
| 194 // not only own properties but also properties on prototype chains. | |
| 195 function getAllPropertyNames(object) { | |
| 196 var properties = []; | |
| 197 for (var property in object) { | |
| 198 properties.push(property); | |
| 199 } | |
| 200 return properties.sort(); | |
| 201 } | |
| 202 | |
| 203 function stringify(v) | 184 function stringify(v) |
| 204 { | 185 { |
| 205 if (isNewSVGTearOffType(v)) | 186 if (isNewSVGTearOffType(v)) |
| 206 return v.valueAsString; | 187 return v.valueAsString; |
| 207 if (v === 0 && 1/v < 0) | 188 if (v === 0 && 1/v < 0) |
| 208 return "-0"; | 189 return "-0"; |
| 209 else return "" + v; | 190 else return "" + v; |
| 210 } | 191 } |
| 211 | 192 |
| 212 // Stringifies a DOM object. This function stringifies not only own properties | |
| 213 // but also DOM attributes which are on a prototype chain. Note that | |
| 214 // JSON.stringify only stringifies own properties. | |
| 215 function stringifyDOMObject(object) | |
| 216 { | |
| 217 function deepCopy(src) { | |
| 218 if (typeof src != "object") | |
| 219 return src; | |
| 220 var dst = Array.isArray(src) ? [] : {}; | |
| 221 for (var property in src) { | |
| 222 dst[property] = deepCopy(src[property]); | |
| 223 } | |
| 224 return dst; | |
| 225 } | |
| 226 return JSON.stringify(deepCopy(object)); | |
| 227 } | |
| 228 | |
| 229 function evalAndLog(_a, _quiet) | 193 function evalAndLog(_a, _quiet) |
| 230 { | 194 { |
| 231 if (typeof _a != "string") | 195 if (typeof _a != "string") |
| 232 debug("WARN: tryAndLog() expects a string argument"); | 196 debug("WARN: tryAndLog() expects a string argument"); |
| 233 | 197 |
| 234 // Log first in case things go horribly wrong or this causes a sync event. | 198 // Log first in case things go horribly wrong or this causes a sync event. |
| 235 if (!_quiet) | 199 if (!_quiet) |
| 236 debug(_a); | 200 debug(_a); |
| 237 | 201 |
| 238 var _av; | 202 var _av; |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 } | 684 } |
| 721 | 685 |
| 722 // With Oilpan tests that rely on garbage collection need to go through | 686 // With Oilpan tests that rely on garbage collection need to go through |
| 723 // the event loop in order to get precise garbage collections. Oilpan | 687 // the event loop in order to get precise garbage collections. Oilpan |
| 724 // uses conservative stack scanning when not at the event loop and that | 688 // uses conservative stack scanning when not at the event loop and that |
| 725 // can artificially keep objects alive. Therefore, tests that need to check | 689 // can artificially keep objects alive. Therefore, tests that need to check |
| 726 // that something is dead need to use this asynchronous collectGarbage | 690 // that something is dead need to use this asynchronous collectGarbage |
| 727 // function. | 691 // function. |
| 728 function asyncGC(callback) { | 692 function asyncGC(callback) { |
| 729 GCController.collectAll(); | 693 GCController.collectAll(); |
| 730 // FIXME: we need a better way of waiting for chromium events to happen | |
| 731 setTimeout(callback, 0); | 694 setTimeout(callback, 0); |
| 732 } | 695 } |
| 733 | 696 |
| 734 function gc() { | 697 function gc() { |
| 735 if (typeof GCController !== "undefined") | 698 if (typeof GCController !== "undefined") |
| 736 GCController.collectAll(); | 699 GCController.collectAll(); |
| 737 else { | 700 else { |
| 738 var gcRec = function (n) { | 701 var gcRec = function (n) { |
| 739 if (n < 1) | 702 if (n < 1) |
| 740 return {}; | 703 return {}; |
| 741 var temp = {i: "ab" + i + (i / 100000)}; | 704 var temp = {i: "ab" + i + (i / 100000)}; |
| 742 temp += "foo"; | 705 temp += "foo"; |
| 743 gcRec(n-1); | 706 gcRec(n-1); |
| 744 }; | 707 }; |
| 745 for (var i = 0; i < 1000; i++) | 708 for (var i = 0; i < 1000; i++) |
| 746 gcRec(10); | 709 gcRec(10); |
| 747 } | 710 } |
| 748 } | 711 } |
| 749 | 712 |
| 750 function asyncMinorGC(callback) { | 713 function asyncMinorGC(callback) { |
| 751 if (typeof GCController !== "undefined") | 714 if (typeof GCController !== "undefined") |
| 752 GCController.minorCollect(); | 715 GCController.minorCollect(); |
| 753 else | 716 else |
| 754 testFailed("Minor GC is available only when you enable the --expose-gc o
ption in V8."); | 717 testFailed("Minor GC is available only when you enable the --expose-gc o
ption in V8."); |
| 755 // FIXME: we need a better way of waiting for chromium events to happen | |
| 756 setTimeout(callback, 0); | 718 setTimeout(callback, 0); |
| 757 } | 719 } |
| 758 | 720 |
| 759 function setPrintTestResultsLazily() { | |
| 760 self._lazyTestResults = self._lazyTestResults || []; | |
| 761 } | |
| 762 | |
| 763 function isSuccessfullyParsed() | 721 function isSuccessfullyParsed() |
| 764 { | 722 { |
| 765 // FIXME: Remove this and only report unexpected syntax errors. | 723 // FIXME: Remove this and only report unexpected syntax errors. |
| 766 successfullyParsed = !unexpectedErrorMessage; | 724 successfullyParsed = !unexpectedErrorMessage; |
| 767 shouldBeTrue("successfullyParsed"); | 725 shouldBeTrue("successfullyParsed"); |
| 768 debug('<br /><span class="pass">TEST COMPLETE</span>'); | 726 debug('<br /><span class="pass">TEST COMPLETE</span>'); |
| 769 } | 727 } |
| 770 | 728 |
| 771 var wasPostTestScriptParsed, wasFinishJSTestCalled, jsTestIsAsync; | 729 var wasPostTestScriptParsed, wasFinishJSTestCalled, jsTestIsAsync; |
| 772 | 730 |
| 773 // It's possible for an async test to call finishJSTest() before js-test-post.js | 731 // It's possible for an async test to call finishJSTest() before js-test-post.js |
| 774 // has been parsed. | 732 // has been parsed. |
| 775 function finishJSTest() | 733 function finishJSTest() |
| 776 { | 734 { |
| 777 wasFinishJSTestCalled = true; | 735 wasFinishJSTestCalled = true; |
| 778 if (!self.wasPostTestScriptParsed) | 736 if (!self.wasPostTestScriptParsed) |
| 779 return; | 737 return; |
| 780 isSuccessfullyParsed(); | 738 isSuccessfullyParsed(); |
| 781 | |
| 782 if (self._lazyTestResults && self._lazyTestResults.length > 0) { | |
| 783 var consoleElement = document.getElementById("console"); | |
| 784 if (!consoleElement) { | |
| 785 consoleElement = document.createElement("div"); | |
| 786 consoleElement.id = "console"; | |
| 787 var parent = document.body || document.documentElement; | |
| 788 parent.insertBefore(consoleElement, parent.firstChild); | |
| 789 } | |
| 790 self._lazyTestResults.forEach(function(msg) { | |
| 791 var span = document.createElement("span"); | |
| 792 span.innerHTML = msg + '<br />'; | |
| 793 consoleElement.appendChild(span); | |
| 794 }); | |
| 795 } | |
| 796 | |
| 797 if (self.jsTestIsAsync && self.testRunner) | 739 if (self.jsTestIsAsync && self.testRunner) |
| 798 testRunner.notifyDone(); | 740 testRunner.notifyDone(); |
| 799 } | 741 } |
| 800 | 742 |
| 801 function startWorker(testScriptURL, shared) | 743 function startWorker(testScriptURL, shared) |
| 802 { | 744 { |
| 803 self.jsTestIsAsync = true; | 745 self.jsTestIsAsync = true; |
| 804 debug('Starting worker: ' + testScriptURL); | 746 debug('Starting worker: ' + testScriptURL); |
| 805 var worker = shared ? new SharedWorker(testScriptURL, "Shared Worker") : new
Worker(testScriptURL); | 747 var worker = shared ? new SharedWorker(testScriptURL, "Shared Worker") : new
Worker(testScriptURL); |
| 806 worker.onmessage = function(event) | 748 worker.onmessage = function(event) |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 871 testPassed = function(msg) { | 813 testPassed = function(msg) { |
| 872 workerPort.postMessage('PASS:' + msg); | 814 workerPort.postMessage('PASS:' + msg); |
| 873 }; | 815 }; |
| 874 finishJSTest = function() { | 816 finishJSTest = function() { |
| 875 workerPort.postMessage('DONE:'); | 817 workerPort.postMessage('DONE:'); |
| 876 }; | 818 }; |
| 877 debug = function(msg) { | 819 debug = function(msg) { |
| 878 workerPort.postMessage(msg); | 820 workerPort.postMessage(msg); |
| 879 }; | 821 }; |
| 880 } | 822 } |
| OLD | NEW |