Chromium Code Reviews| Index: LayoutTests/fast/events/resources/onerror-test.js |
| diff --git a/LayoutTests/fast/events/resources/onerror-test.js b/LayoutTests/fast/events/resources/onerror-test.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d9ca93bd5b8ed51dd2db669e3d805644a93b4139 |
| --- /dev/null |
| +++ b/LayoutTests/fast/events/resources/onerror-test.js |
| @@ -0,0 +1,54 @@ |
| +function stripURL(url) { |
| + return url ? url.match( /[^\/]+\/?$/ )[0] : url; |
| +} |
| + |
| +function throwException(message) { |
| + throw new Error(message ? message : "An exception"); |
| +} |
| + |
| +var errorsSeen = 0; |
| +function DumpOnErrorArgumentValuesAndReturn(returnValue, callback) { |
|
do-not-use
2013/07/24 13:18:01
nit: function usually start with a lowercase in Bl
Mike West
2013/07/24 15:28:32
Done.
|
| + window.onerror = function (message, url, line, column) { |
| + debug("window.onerror: \"" + message + "\" at " + stripURL(url) + " (" + line + ", " + column + ")"); |
|
do-not-use
2013/07/24 13:18:01
nit: I find the output in expected results not ver
Mike West
2013/07/24 15:28:32
Done.
|
| + |
| + if (callback) |
| + callback(++errorsSeen); |
| + if (returnValue) |
| + debug("- Returning 'true': the error should not be reported in the console as an unhandled exception."); |
|
do-not-use
2013/07/24 13:18:01
I think we can remove the "- " prefix, I don't fin
Mike West
2013/07/24 15:28:32
Done.
|
| + else |
| + debug("- Returning 'false': the error should be reported in the console as an unhandled exception."); |
| + return returnValue; |
| + }; |
| +} |
| + |
| +function DumpErrorEventAndAllowDefault(callback) { |
|
do-not-use
2013/07/24 13:18:01
Ditto.
Mike West
2013/07/24 15:28:32
Done.
|
| + window.addEventListener('error', function (e) { |
| + DumpErrorEvent(e) |
| + debug("- Not calling e.preventDefault(): the error should be reported in the console as an unhandled exception."); |
| + if (callback) |
| + callback(++errorsSeen); |
| + }); |
| +} |
| + |
| +function DumpErrorEventAndPreventDefault(callback) { |
|
do-not-use
2013/07/24 13:18:01
ditto.
Mike West
2013/07/24 15:28:32
Done.
|
| + window.addEventListener('error', function (e) { |
| + DumpErrorEvent(e); |
| + debug("- Calling e.preventDefault(): the error should not be reported in the console as an unhandled exception."); |
| + e.preventDefault(); |
| + if (callback) |
| + callback(++errorsSeen); |
| + }); |
| +} |
| + |
| +var eventPassedToTheErrorListener = null; |
| +var eventCurrentTarget = null; |
| +function DumpErrorEvent(e) { |
|
do-not-use
2013/07/24 13:18:01
Ditto.
Mike West
2013/07/24 15:28:32
Done.
|
| + debug("Handling '" + e.type + "' event (phase " + e.eventPhase + "): \"" + e.message + "\" at " + stripURL(e.filename) + ":" + e.lineno); |
| + |
| + eventPassedToTheErrorListener = e; |
| + eventCurrentTarget = e.currentTarget; |
| + shouldBe('eventPassedToTheErrorListener', 'window.event'); |
| + shouldBe('eventCurrentTarget', 'window'); |
| + eventPassedToTheErrorListener = null; |
| + eventCurrentTarget = null; |
| +} |