Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(475)

Side by Side Diff: third_party/WebKit/LayoutTests/resources/js-test.js

Issue 1362953003: Fire window.onerror for uncaught IndexedDB errors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/storage/indexeddb/error-attributes.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 var _lazyDescription; // Set by description() after setPrintTestResultsLazily().
6 6
7 // 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
8 if (self.testRunner) { 8 if (self.testRunner) {
9 if (self.enablePixelTesting) 9 if (self.enablePixelTesting)
10 testRunner.dumpAsTextWithPixelResults(); 10 testRunner.dumpAsTextWithPixelResults();
11 else 11 else
12 testRunner.dumpAsText(); 12 testRunner.dumpAsText();
13 } 13 }
14 14
15 var isJsTest = true; 15 var isJsTest = true;
16 16
17 var description, debug, successfullyParsed, getOrCreateTestElement; 17 var description, debug, successfullyParsed, getOrCreateTestElement;
18 18
19 var expectingError; // set by shouldHaveError() 19 var expectingError; // set by expectError()
20 var expectedErrorMessage; // set by onerror when expectingError is true 20 var expectedErrorMessage; // set by onerror when expectingError is true
21 var unexpectedErrorMessage; // set by onerror when expectingError is not true 21 var unexpectedErrorMessage; // set by onerror when expectingError is not true
22 22
23 (function() { 23 (function() {
24 24
25 getOrCreateTestElement = function(id, tagName) 25 getOrCreateTestElement = function(id, tagName)
26 { 26 {
27 var element = document.getElementById(id); 27 var element = document.getElementById(id);
28 if (element) 28 if (element)
29 return element; 29 return element;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 window.addEventListener('DOMContentLoaded', handleTestFinished, false); 112 window.addEventListener('DOMContentLoaded', handleTestFinished, false);
113 insertStyleSheet(); 113 insertStyleSheet();
114 } 114 }
115 115
116 if (!self.isOnErrorTest) { 116 if (!self.isOnErrorTest) {
117 self.onerror = function(message) 117 self.onerror = function(message)
118 { 118 {
119 if (self.expectingError) { 119 if (self.expectingError) {
120 self.expectedErrorMessage = message; 120 self.expectedErrorMessage = message;
121 self.expectingError = false; 121 self.expectingError = false;
122 return; 122 // In workers, consume expected error so window doesn't fail the test.
123 return isWorker();
123 } 124 }
124 self.unexpectedErrorMessage = message; 125 self.unexpectedErrorMessage = message;
125 if (self.jsTestIsAsync) { 126 if (self.jsTestIsAsync) {
126 self.testFailed("Unexpected error: " + message); 127 self.testFailed("Unexpected error: " + message);
127 finishJSTest(); 128 finishJSTest();
128 } 129 }
129 }; 130 };
130 } 131 }
131 })(); 132 })();
132 133
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 709
709 testPassed(a + " is equivalent to Date.now()."); 710 testPassed(a + " is equivalent to Date.now().");
710 return; 711 return;
711 } 712 }
712 testFailed(a + " cannot be tested against the current time. The clock is goi ng backwards too often."); 713 testFailed(a + " cannot be tested against the current time. The clock is goi ng backwards too often.");
713 } 714 }
714 715
715 function expectError() 716 function expectError()
716 { 717 {
717 if (expectingError) { 718 if (expectingError) {
718 testFailed("shouldHaveError() called twice before an error occurred!"); 719 testFailed("expectError() called twice before an error occurred!");
719 } 720 }
720 expectingError = true; 721 expectingError = true;
721 } 722 }
722 723
723 function shouldHaveHadError(message) 724 function shouldHaveHadError(message)
724 { 725 {
725 if (expectingError) { 726 if (expectingError) {
726 testFailed("No error thrown between expectError() and shouldHaveHadError ()"); 727 testFailed("No error thrown between expectError() and shouldHaveHadError ()");
727 return; 728 return;
728 } 729 }
729 730
730 if (expectedErrorMessage) { 731 if (expectedErrorMessage) {
731 if (!message) 732 if (!message)
732 testPassed("Got expected error"); 733 testPassed("Got expected error");
733 else if (expectedErrorMessage.indexOf(message) !== -1) 734 else if (expectedErrorMessage.indexOf(message) !== -1)
734 testPassed("Got expected error: '" + message + "'"); 735 testPassed("Got expected error: '" + message + "'");
735 else 736 else
736 testFailed("Unexpected error '" + message + "'"); 737 testFailed("Unexpected error '" + message + "'");
737 expectedErrorMessage = undefined; 738 expectedErrorMessage = undefined;
738 return; 739 return;
739 } 740 }
740 741
741 testFailed("expectError() not called before shouldHaveHadError()"); 742 testFailed("expectError() not called before shouldHaveHadError()");
742 } 743 }
743 744
745 // Waits for the global 'onerror' handler to fire, verifies the
746 // message with a regex, then calls another function. e.g.
747 // waitForError(/AbortError/, nextTestCase);
748 function waitForError(regex, continuation)
749 {
750 var original_onerror = self.onerror;
751 self.onerror = function(message) {
752 self.onerror = original_onerror;
753 if (regex.test(message))
754 testPassed("Got expected error: '" + message + "'");
755 else
756 testFailed("Unexpected error '" + message + "', expected: " + String (regex));
757 continuation();
758 };
759 }
760
744 // With Oilpan tests that rely on garbage collection need to go through 761 // With Oilpan tests that rely on garbage collection need to go through
745 // the event loop in order to get precise garbage collections. Oilpan 762 // the event loop in order to get precise garbage collections. Oilpan
746 // uses conservative stack scanning when not at the event loop and that 763 // uses conservative stack scanning when not at the event loop and that
747 // can artificially keep objects alive. Therefore, tests that need to check 764 // can artificially keep objects alive. Therefore, tests that need to check
748 // that something is dead need to use this asynchronous collectGarbage 765 // that something is dead need to use this asynchronous collectGarbage
749 // function. 766 // function.
750 function asyncGC(callback) { 767 function asyncGC(callback) {
751 var documentsBefore = window.internals.numberOfLiveDocuments(); 768 var documentsBefore = window.internals.numberOfLiveDocuments();
752 GCController.collectAll(); 769 GCController.collectAll();
753 // FIXME: we need a better way of waiting for chromium events to happen 770 // FIXME: we need a better way of waiting for chromium events to happen
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 testPassed = function(msg) { 920 testPassed = function(msg) {
904 workerPort.postMessage('PASS:' + msg); 921 workerPort.postMessage('PASS:' + msg);
905 }; 922 };
906 finishJSTest = function() { 923 finishJSTest = function() {
907 workerPort.postMessage('DONE:'); 924 workerPort.postMessage('DONE:');
908 }; 925 };
909 debug = function(msg) { 926 debug = function(msg) {
910 workerPort.postMessage(msg); 927 workerPort.postMessage(msg);
911 }; 928 };
912 } 929 }
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/storage/indexeddb/error-attributes.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698