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

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

Issue 59903016: LayoutTests/resources/js-test.js onerror tweak. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Removed setTimeout from js-tests changes. Created 7 years, 1 month 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
OLDNEW
1 // 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
2 if (self.testRunner) { 2 if (self.testRunner) {
3 if (self.enablePixelTesting) 3 if (self.enablePixelTesting)
4 testRunner.dumpAsTextWithPixelResults(); 4 testRunner.dumpAsTextWithPixelResults();
5 else 5 else
6 testRunner.dumpAsText(); 6 testRunner.dumpAsText();
7 } 7 }
8 8
9 var description, debug, successfullyParsed, errorMessage; 9 var description, debug, successfullyParsed;
10
11 var expectingError; // set by shouldHaveError()
12 var expectedErrorMessage; // set by onerror when expectingError is true
13 var unexpectedErrorMessage; // set by onerror when expectingError is not true
10 14
11 (function() { 15 (function() {
12 16
13 function getOrCreate(id, tagName) 17 function getOrCreate(id, tagName)
14 { 18 {
15 var element = document.getElementById(id); 19 var element = document.getElementById(id);
16 if (element) 20 if (element)
17 return element; 21 return element;
18 22
19 element = document.createElement(tagName); 23 element = document.createElement(tagName);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 } 91 }
88 92
89 if (!isWorker()) { 93 if (!isWorker()) {
90 window.addEventListener('DOMContentLoaded', handleTestFinished, false); 94 window.addEventListener('DOMContentLoaded', handleTestFinished, false);
91 insertStyleSheet(); 95 insertStyleSheet();
92 } 96 }
93 97
94 if (!self.isOnErrorTest) { 98 if (!self.isOnErrorTest) {
95 self.onerror = function(message) 99 self.onerror = function(message)
96 { 100 {
97 errorMessage = message; 101 if (self.expectingError) {
102 self.expectedErrorMessage = message;
103 self.expectingError = false;
104 return;
105 }
106 self.unexpectedErrorMessage = message;
107 if (self.jsTestIsAsync) {
108 self.testFailed("Unexpected error: " + message);
109 finishJSTest();
110 }
98 }; 111 };
99 } 112 }
100 })(); 113 })();
101 114
102 function isWorker() 115 function isWorker()
103 { 116 {
104 // It's conceivable that someone would stub out 'document' in a worker so 117 // It's conceivable that someone would stub out 'document' in a worker so
105 // also check for childNodes, an arbitrary DOM-related object that is 118 // also check for childNodes, an arbitrary DOM-related object that is
106 // meaningless in a WorkerContext. 119 // meaningless in a WorkerContext.
107 return (typeof document === 'undefined' || typeof document.childNodes === 'u ndefined') && !!self.importScripts; 120 return (typeof document === 'undefined' || typeof document.childNodes === 'u ndefined') && !!self.importScripts;
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 if (typeof _e == "undefined" || exception == _ev) 560 if (typeof _e == "undefined" || exception == _ev)
548 testPassed(_a + " threw exception " + exception + "."); 561 testPassed(_a + " threw exception " + exception + ".");
549 else 562 else
550 testFailed(_a + " should throw " + (typeof _e == "undefined" ? "an excepti on" : _ev) + ". Threw exception " + exception + "."); 563 testFailed(_a + " should throw " + (typeof _e == "undefined" ? "an excepti on" : _ev) + ". Threw exception " + exception + ".");
551 } else if (typeof _av == "undefined") 564 } else if (typeof _av == "undefined")
552 testFailed(_a + " should throw " + (typeof _e == "undefined" ? "an exception " : _ev) + ". Was undefined."); 565 testFailed(_a + " should throw " + (typeof _e == "undefined" ? "an exception " : _ev) + ". Was undefined.");
553 else 566 else
554 testFailed(_a + " should throw " + (typeof _e == "undefined" ? "an exception " : _ev) + ". Was " + _av + "."); 567 testFailed(_a + " should throw " + (typeof _e == "undefined" ? "an exception " : _ev) + ". Was " + _av + ".");
555 } 568 }
556 569
570 function expectError()
571 {
572 if (expectingError) {
573 testFailed("shouldHaveError() called twice before an error occurred!");
574 }
575 expectingError = true;
576 }
577
557 function shouldHaveHadError(message) 578 function shouldHaveHadError(message)
558 { 579 {
559 if (errorMessage) { 580 if (expectingError) {
581 testFailed("No error thrown between expectError() and shouldHaveHadError ()");
582 return;
583 }
584
585 if (expectedErrorMessage) {
560 if (!message) 586 if (!message)
561 testPassed("Got expected error"); 587 testPassed("Got expected error");
562 else if (errorMessage.indexOf(message) !== -1) 588 else if (expectedErrorMessage.indexOf(message) !== -1)
563 testPassed("Got expected error: '" + message + "'"); 589 testPassed("Got expected error: '" + message + "'");
564 else 590 else
565 testFailed("Unexpexted error '" + message + "'"); 591 testFailed("Unexpected error '" + message + "'");
566 } else 592 expectedErrorMessage = undefined;
567 testFailed("Missing expexted error"); 593 return;
568 errorMessage = undefined; 594 }
595
596 testFailed("expectError() not called before shouldHaveHadError()");
569 } 597 }
570 598
571 function gc() { 599 function gc() {
572 if (typeof GCController !== "undefined") 600 if (typeof GCController !== "undefined")
573 GCController.collect(); 601 GCController.collect();
574 else { 602 else {
575 var gcRec = function (n) { 603 var gcRec = function (n) {
576 if (n < 1) 604 if (n < 1)
577 return {}; 605 return {};
578 var temp = {i: "ab" + i + (i / 100000)}; 606 var temp = {i: "ab" + i + (i / 100000)};
579 temp += "foo"; 607 temp += "foo";
580 gcRec(n-1); 608 gcRec(n-1);
581 }; 609 };
582 for (var i = 0; i < 1000; i++) 610 for (var i = 0; i < 1000; i++)
583 gcRec(10) 611 gcRec(10)
584 } 612 }
585 } 613 }
586 614
587 function minorGC() { 615 function minorGC() {
588 if (typeof GCController !== "undefined") 616 if (typeof GCController !== "undefined")
589 GCController.minorCollect(); 617 GCController.minorCollect();
590 else 618 else
591 testFailed("Minor GC is available only when you enable the --expose-gc o ption in V8."); 619 testFailed("Minor GC is available only when you enable the --expose-gc o ption in V8.");
592 } 620 }
593 621
594 function isSuccessfullyParsed() 622 function isSuccessfullyParsed()
595 { 623 {
596 // FIXME: Remove this and only report unexpected syntax errors. 624 // FIXME: Remove this and only report unexpected syntax errors.
597 if (!errorMessage) 625 successfullyParsed = !unexpectedErrorMessage;
598 successfullyParsed = true;
599 shouldBeTrue("successfullyParsed"); 626 shouldBeTrue("successfullyParsed");
600 debug('<br /><span class="pass">TEST COMPLETE</span>'); 627 debug('<br /><span class="pass">TEST COMPLETE</span>');
601 } 628 }
602 629
603 // It's possible for an async test to call finishJSTest() before js-test-post.js 630 // It's possible for an async test to call finishJSTest() before js-test-post.js
604 // has been parsed. 631 // has been parsed.
605 function finishJSTest() 632 function finishJSTest()
606 { 633 {
607 wasFinishJSTestCalled = true; 634 wasFinishJSTestCalled = true;
608 if (!self.wasPostTestScriptParsed) 635 if (!self.wasPostTestScriptParsed)
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 testPassed = function(msg) { 712 testPassed = function(msg) {
686 workerPort.postMessage('PASS:' + msg); 713 workerPort.postMessage('PASS:' + msg);
687 } 714 }
688 finishJSTest = function() { 715 finishJSTest = function() {
689 workerPort.postMessage('DONE:'); 716 workerPort.postMessage('DONE:');
690 } 717 }
691 debug = function(msg) { 718 debug = function(msg) {
692 workerPort.postMessage(msg); 719 workerPort.postMessage(msg);
693 } 720 }
694 } 721 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698