test_errorReporting.html (2700B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1070842 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 1070842</title> 9 <script src="/tests/SimpleTest/SimpleTest.js"></script> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 11 <script type="application/javascript"> 12 13 /** Test for error reporting behavior. */ 14 SimpleTest.waitForExplicitFinish(); 15 16 function testErrorReportingHelper(f, rgxp, preventDefault) { 17 return new Promise(function(resolve, reject) { 18 window.addEventListener('error', function(e) { 19 ok(rgxp.test(e.message), "Should get message matching " + rgxp + ". Got: " + e.message); 20 var expectedMessages; 21 if (preventDefault) { 22 e.preventDefault(); 23 expectedMessages = []; 24 } else { 25 expectedMessages = [{message: rgxp}]; 26 } 27 SimpleTest.monitorConsole(resolve, expectedMessages, /* forbidUnexpectedMsgs = */ true); 28 setTimeout(SimpleTest.endMonitorConsole.bind(SimpleTest), 0); 29 }, {once: true}); 30 31 // Notify the test harness to avoid treating the next exception as a test failure. 32 SimpleTest.expectUncaughtException(); 33 34 // Invoke the function async so that the exception doesn't get eaten by 35 // the Promise machinery. 36 setTimeout(f, 0); 37 }); 38 } 39 function testErrorReporting(f, rgxp) { 40 return new Promise(function(resolve, reject) { 41 testErrorReportingHelper.bind(null, f, rgxp, false)().then( 42 testErrorReportingHelper.bind(null, f, rgxp, true)).then( 43 resolve); 44 }); 45 } 46 47 function go() { 48 var otherWin = $('emptyFrame').contentWindow; 49 var clickMe = $('clickMe'); 50 testErrorReporting.bind(null, () => { throw Error("Simple Error") }, /Simple Error/)().then( 51 testErrorReporting.bind(null, () => otherWin.eval('throw Error("Cross Global Error")'), /Cross Global Error/)).then( 52 testErrorReporting.bind(null, () => clickMe.dispatchEvent(new MouseEvent('click')), /thrwan/)).then( 53 testErrorReporting.bind(null, () => { clickMe.setAttribute('onclick', ' '); /* Make sure we recompile. */ 54 clickMe.setAttribute('onclick', '?'); 55 clickMe.onclick; }, /SyntaxError/)).then( 56 SimpleTest.finish.bind(SimpleTest)); 57 } 58 59 </script> 60 </head> 61 <body onload="go();"> 62 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1070842">Mozilla Bug 1070842</a> 63 <p id="display"></p> 64 <div id="content" style="display: none"> 65 <button id="clickMe" onclick="thrwan.error;">Click Me</button> 66 <iframe id="emptyFrame"></iframe> 67 68 </div> 69 <pre id="test"> 70 </pre> 71 </body> 72 </html>