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..c4b08b18409aa179548599e6401024be54f712ea |
--- /dev/null |
+++ b/LayoutTests/fast/events/resources/onerror-test.js |
@@ -0,0 +1,60 @@ |
+if (window.testRunner) |
do-not-use
2013/07/23 14:46:09
Would becomes optional if we used js-test-pre.js
|
+ testRunner.dumpAsText(); |
+ |
+var output; |
+ |
+function log(message) { |
do-not-use
2013/07/23 14:46:09
Any reason we are not using js-test-pre.js? We cou
Mike West
2013/07/23 14:51:54
I thought about it, and decided that the advantage
|
+ if (!output) { |
+ output = document.createElement('pre') |
+ document.body.appendChild(output); |
+ } |
+ |
+ output.appendChild(document.createTextNode(message + "\n")); |
+} |
+ |
+function stripURL(url) { |
+ return url ? url.match( /[^\/]+\/?$/ )[0] : url; |
+} |
+ |
+function throwException(message) { |
+ throw new Error(message ? message : "An exception"); |
+} |
+ |
+function DumpOnErrorArgumentValuesAndReturn(returnValue, callback) { |
+ window.onerror = function (message, url, line, column) { |
+ log("window.onerror: \"" + message + "\" at " + stripURL(url) + " (" + line + ", " + column + ")"); |
+ if (callback) |
+ callback(); |
+ if (returnValue) |
+ log("- Returning 'true': the error should not be reported in the console as an unhandled exception."); |
+ else |
+ log("- Returning 'false': the error should be reported in the console as an unhandled exception."); |
+ return returnValue; |
+ }; |
+} |
+ |
+function DumpErrorEventAndAllowDefault(callback) { |
+ window.addEventListener('error', function (e) { |
+ DumpErrorEvent(e) |
+ log("- Not calling e.preventDefault(): the error should be reported in the console as an unhandled exception."); |
+ if (callback) |
+ callback(); |
+ }); |
+} |
+ |
+function DumpErrorEventAndPreventDefault(callback) { |
+ window.addEventListener('error', function (e) { |
+ DumpErrorEvent(e); |
+ log("- Calling e.preventDefault(): the error should not be reported in the console as an unhandled exception."); |
+ e.preventDefault(); |
+ if (callback) |
+ callback(); |
+ }); |
+} |
+ |
+function DumpErrorEvent(e) { |
+ log("Handling '" + e.type + "' event (phase " + e.eventPhase + "): \"" + e.message + "\" at " + stripURL(e.filename) + ":" + e.lineno); |
+ |
+ log("PASS: event passed to the listener is the same as 'window.event': " + (window.event === e)); |
+ log("PASS: 'currentTarget' is the global object: " + (e.currentTarget === window)); |
+} |