Index: LayoutTests/resources/js-test.js |
diff --git a/LayoutTests/resources/js-test.js b/LayoutTests/resources/js-test.js |
index ba1d8acddd5a9f64898389d1ea286d6425746baf..781f378f2309a4dadce2489b07487c14e3980ea7 100644 |
--- a/LayoutTests/resources/js-test.js |
+++ b/LayoutTests/resources/js-test.js |
@@ -15,7 +15,7 @@ var isJsTest = true; |
var description, debug, successfullyParsed; |
-var expectingError; // set by shouldHaveError() |
+var expectingError; // set by expectError() |
var expectedErrorMessage; // set by onerror when expectingError is true |
var unexpectedErrorMessage; // set by onerror when expectingError is not true |
@@ -112,7 +112,8 @@ var unexpectedErrorMessage; // set by onerror when expectingError is not true |
if (self.expectingError) { |
self.expectedErrorMessage = message; |
self.expectingError = false; |
- return; |
+ // In workers, consume expected error so window doesn't fail the test. |
+ return isWorker(); |
} |
self.unexpectedErrorMessage = message; |
if (self.jsTestIsAsync) { |
@@ -706,7 +707,7 @@ function shouldBeNow(a, delta) |
function expectError() |
{ |
if (expectingError) { |
- testFailed("shouldHaveError() called twice before an error occurred!"); |
+ testFailed("expectError() called twice before an error occurred!"); |
} |
expectingError = true; |
} |
@@ -732,6 +733,22 @@ function shouldHaveHadError(message) |
testFailed("expectError() not called before shouldHaveHadError()"); |
} |
+// Waits for the global 'onerror' handler to fire, verifies the |
+// message with a regex, then calls another function. e.g. |
+// waitForError(/AbortError/, nextTestCase); |
+function waitForError(regex, continuation) |
+{ |
+ var original_onerror = self.onerror; |
+ self.onerror = function(message) { |
+ self.onerror = original_onerror; |
+ if (regex.test(message)) |
+ testPassed("Got expected error: '" + message + "'"); |
+ else |
+ testFailed("Unexpected error '" + message + "', expected: " + String(regex)); |
+ continuation(); |
+ }; |
+} |
+ |
// With Oilpan tests that rely on garbage collection need to go through |
// the event loop in order to get precise garbage collections. Oilpan |
// uses conservative stack scanning when not at the event loop and that |