diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/tests/mochitest/bugs/test_errorReporting.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | dom/tests/mochitest/bugs/test_errorReporting.html | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/dom/tests/mochitest/bugs/test_errorReporting.html b/dom/tests/mochitest/bugs/test_errorReporting.html new file mode 100644 index 0000000000..aa299c98cc --- /dev/null +++ b/dom/tests/mochitest/bugs/test_errorReporting.html @@ -0,0 +1,72 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1070842 +--> +<head> + <meta charset="utf-8"> + <title>Test for Bug 1070842</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> + <script type="application/javascript"> + + /** Test for error reporting behavior. **/ + SimpleTest.waitForExplicitFinish(); + + function testErrorReportingHelper(f, rgxp, preventDefault) { + return new Promise(function(resolve, reject) { + window.addEventListener('error', function(e) { + ok(rgxp.test(e.message), "Should get message matching " + rgxp + ". Got: " + e.message); + var expectedMessages; + if (preventDefault) { + e.preventDefault(); + expectedMessages = []; + } else { + expectedMessages = [{message: rgxp}]; + } + SimpleTest.monitorConsole(resolve, expectedMessages, /* forbidUnexpectedMsgs = */ true); + setTimeout(SimpleTest.endMonitorConsole.bind(SimpleTest), 0); + }, {once: true}); + + // Notify the test harness to avoid treating the next exception as a test failure. + SimpleTest.expectUncaughtException(); + + // Invoke the function async so that the exception doesn't get eaten by + // the Promise machinery. + setTimeout(f, 0); + }); + } + function testErrorReporting(f, rgxp) { + return new Promise(function(resolve, reject) { + testErrorReportingHelper.bind(null, f, rgxp, false)().then( + testErrorReportingHelper.bind(null, f, rgxp, true)).then( + resolve); + }); + } + + function go() { + var otherWin = $('emptyFrame').contentWindow; + var clickMe = $('clickMe'); + testErrorReporting.bind(null, () => { throw Error("Simple Error") }, /Simple Error/)().then( + testErrorReporting.bind(null, () => otherWin.eval('throw Error("Cross Global Error")'), /Cross Global Error/)).then( + testErrorReporting.bind(null, () => clickMe.dispatchEvent(new MouseEvent('click')), /thrwan/)).then( + testErrorReporting.bind(null, () => { clickMe.setAttribute('onclick', ' '); /* Make sure we recompile. */ + clickMe.setAttribute('onclick', '?'); + clickMe.onclick; }, /SyntaxError/)).then( + SimpleTest.finish.bind(SimpleTest)); + } + + </script> +</head> +<body onload="go();"> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1070842">Mozilla Bug 1070842</a> +<p id="display"></p> +<div id="content" style="display: none"> +<button id="clickMe" onclick="thrwan.error;">Click Me</button> +<iframe id="emptyFrame"></iframe> + +</div> +<pre id="test"> +</pre> +</body> +</html> |