| 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 | 5 |
| 6 // svg/dynamic-updates tests set enablePixelTesting=true, as we want to dump tex
t + pixel results | 6 // svg/dynamic-updates tests set enablePixelTesting=true, as we want to dump tex
t + pixel results |
| 7 if (self.testRunner) { | 7 if (self.testRunner) { |
| 8 if (self.enablePixelTesting) | 8 if (self.enablePixelTesting) |
| 9 testRunner.dumpAsTextWithPixelResults(); | 9 testRunner.dumpAsTextWithPixelResults(); |
| 10 else | 10 else |
| 11 testRunner.dumpAsText(); | 11 testRunner.dumpAsText(); |
| 12 } | 12 } |
| 13 | 13 |
| 14 var isJsTest = true; | 14 var isJsTest = true; |
| 15 | 15 |
| 16 var description, debug, successfullyParsed; | 16 var description, debug, successfullyParsed; |
| 17 | 17 |
| 18 var expectingError; // set by shouldHaveError() | 18 var expectingError; // set by expectError() |
| 19 var expectedErrorMessage; // set by onerror when expectingError is true | 19 var expectedErrorMessage; // set by onerror when expectingError is true |
| 20 var unexpectedErrorMessage; // set by onerror when expectingError is not true | 20 var unexpectedErrorMessage; // set by onerror when expectingError is not true |
| 21 | 21 |
| 22 (function() { | 22 (function() { |
| 23 | 23 |
| 24 function getOrCreate(id, tagName) | 24 function getOrCreate(id, tagName) |
| 25 { | 25 { |
| 26 var element = document.getElementById(id); | 26 var element = document.getElementById(id); |
| 27 if (element) | 27 if (element) |
| 28 return element; | 28 return element; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 window.addEventListener('DOMContentLoaded', handleTestFinished, false); | 105 window.addEventListener('DOMContentLoaded', handleTestFinished, false); |
| 106 insertStyleSheet(); | 106 insertStyleSheet(); |
| 107 } | 107 } |
| 108 | 108 |
| 109 if (!self.isOnErrorTest) { | 109 if (!self.isOnErrorTest) { |
| 110 self.onerror = function(message) | 110 self.onerror = function(message) |
| 111 { | 111 { |
| 112 if (self.expectingError) { | 112 if (self.expectingError) { |
| 113 self.expectedErrorMessage = message; | 113 self.expectedErrorMessage = message; |
| 114 self.expectingError = false; | 114 self.expectingError = false; |
| 115 return; | 115 // In workers, consume expected error so window doesn't fail the
test. |
| 116 return isWorker(); |
| 116 } | 117 } |
| 117 self.unexpectedErrorMessage = message; | 118 self.unexpectedErrorMessage = message; |
| 118 if (self.jsTestIsAsync) { | 119 if (self.jsTestIsAsync) { |
| 119 self.testFailed("Unexpected error: " + message); | 120 self.testFailed("Unexpected error: " + message); |
| 120 finishJSTest(); | 121 finishJSTest(); |
| 121 } | 122 } |
| 122 }; | 123 }; |
| 123 } | 124 } |
| 124 })(); | 125 })(); |
| 125 | 126 |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 | 700 |
| 700 testPassed(a + " is equivalent to Date.now()."); | 701 testPassed(a + " is equivalent to Date.now()."); |
| 701 return; | 702 return; |
| 702 } | 703 } |
| 703 testFailed(a + " cannot be tested against the current time. The clock is goi
ng backwards too often."); | 704 testFailed(a + " cannot be tested against the current time. The clock is goi
ng backwards too often."); |
| 704 } | 705 } |
| 705 | 706 |
| 706 function expectError() | 707 function expectError() |
| 707 { | 708 { |
| 708 if (expectingError) { | 709 if (expectingError) { |
| 709 testFailed("shouldHaveError() called twice before an error occurred!"); | 710 testFailed("expectError() called twice before an error occurred!"); |
| 710 } | 711 } |
| 711 expectingError = true; | 712 expectingError = true; |
| 712 } | 713 } |
| 713 | 714 |
| 714 function shouldHaveHadError(message) | 715 function shouldHaveHadError(message) |
| 715 { | 716 { |
| 716 if (expectingError) { | 717 if (expectingError) { |
| 717 testFailed("No error thrown between expectError() and shouldHaveHadError
()"); | 718 testFailed("No error thrown between expectError() and shouldHaveHadError
()"); |
| 718 return; | 719 return; |
| 719 } | 720 } |
| 720 | 721 |
| 721 if (expectedErrorMessage) { | 722 if (expectedErrorMessage) { |
| 722 if (!message) | 723 if (!message) |
| 723 testPassed("Got expected error"); | 724 testPassed("Got expected error"); |
| 724 else if (expectedErrorMessage.indexOf(message) !== -1) | 725 else if (expectedErrorMessage.indexOf(message) !== -1) |
| 725 testPassed("Got expected error: '" + message + "'"); | 726 testPassed("Got expected error: '" + message + "'"); |
| 726 else | 727 else |
| 727 testFailed("Unexpected error '" + message + "'"); | 728 testFailed("Unexpected error '" + message + "'"); |
| 728 expectedErrorMessage = undefined; | 729 expectedErrorMessage = undefined; |
| 729 return; | 730 return; |
| 730 } | 731 } |
| 731 | 732 |
| 732 testFailed("expectError() not called before shouldHaveHadError()"); | 733 testFailed("expectError() not called before shouldHaveHadError()"); |
| 733 } | 734 } |
| 734 | 735 |
| 736 // Waits for the global 'onerror' handler to fire, verifies the |
| 737 // message with a regex, then calls another function. e.g. |
| 738 // waitForError(/AbortError/, nextTestCase); |
| 739 function waitForError(regex, continuation) |
| 740 { |
| 741 var original_onerror = self.onerror; |
| 742 self.onerror = function(message) { |
| 743 self.onerror = original_onerror; |
| 744 if (regex.test(message)) |
| 745 testPassed("Got expected error: '" + message + "'"); |
| 746 else |
| 747 testFailed("Unexpected error '" + message + "', expected: " + String
(regex)); |
| 748 continuation(); |
| 749 }; |
| 750 } |
| 751 |
| 735 // With Oilpan tests that rely on garbage collection need to go through | 752 // With Oilpan tests that rely on garbage collection need to go through |
| 736 // the event loop in order to get precise garbage collections. Oilpan | 753 // the event loop in order to get precise garbage collections. Oilpan |
| 737 // uses conservative stack scanning when not at the event loop and that | 754 // uses conservative stack scanning when not at the event loop and that |
| 738 // can artificially keep objects alive. Therefore, tests that need to check | 755 // can artificially keep objects alive. Therefore, tests that need to check |
| 739 // that something is dead need to use this asynchronous collectGarbage | 756 // that something is dead need to use this asynchronous collectGarbage |
| 740 // function. | 757 // function. |
| 741 function asyncGC(callback) { | 758 function asyncGC(callback) { |
| 742 GCController.collectAll(); | 759 GCController.collectAll(); |
| 743 // FIXME: we need a better way of waiting for chromium events to happen | 760 // FIXME: we need a better way of waiting for chromium events to happen |
| 744 setTimeout(callback, 0); | 761 setTimeout(callback, 0); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 testPassed = function(msg) { | 907 testPassed = function(msg) { |
| 891 workerPort.postMessage('PASS:' + msg); | 908 workerPort.postMessage('PASS:' + msg); |
| 892 }; | 909 }; |
| 893 finishJSTest = function() { | 910 finishJSTest = function() { |
| 894 workerPort.postMessage('DONE:'); | 911 workerPort.postMessage('DONE:'); |
| 895 }; | 912 }; |
| 896 debug = function(msg) { | 913 debug = function(msg) { |
| 897 workerPort.postMessage(msg); | 914 workerPort.postMessage(msg); |
| 898 }; | 915 }; |
| 899 } | 916 } |
| OLD | NEW |