Bug 1070842 - Tests. r=bz
authorBobby Holley <bobbyholley@gmail.com>
Mon, 29 Sep 2014 15:34:22 +0200
changeset 207704 8b19763dd5f1681073257fe504637b1d8a7c74e0
parent 207703 b3c7b542dbc25c56c9843a8a090f06b59b00391d
child 207705 67b4334af9b1e6236838dc922dab4dbd1bbdd059
push id27564
push userryanvm@gmail.com
push dateMon, 29 Sep 2014 18:57:04 +0000
treeherdermozilla-central@ce9a0b34225e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1070842
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1070842 - Tests. r=bz
dom/tests/mochitest/bugs/mochitest.ini
dom/tests/mochitest/bugs/test_errorReporting.html
--- a/dom/tests/mochitest/bugs/mochitest.ini
+++ b/dom/tests/mochitest/bugs/mochitest.ini
@@ -150,16 +150,17 @@ skip-if = (buildapp == 'b2g' && toolkit 
 [test_bug850517.html]
 [test_bug857555.html]
 [test_bug862540.html]
 [test_bug876098.html]
 [test_bug927901.html]
 [test_devicemotion_multiple_listeners.html]
 skip-if = toolkit == 'android' || e10s #bug 775227
 [test_domparser_after_blank.html]
+[test_errorReporting.html]
 [test_onerror_message.html]
 [test_protochains.html]
 [test_resize_move_windows.html]
 skip-if = buildapp == 'mulet' || buildapp == 'b2g' || toolkit == 'android' || e10s #Windows can't change size and position on Android # b2g(Windows can't change size and position on B2G) b2g-debug(Windows can't change size and position on B2G) b2g-desktop(Windows can't change size and position on B2G)
 [test_sizetocontent_clamp.html]
 skip-if = buildapp == 'mulet' || buildapp == 'b2g' || toolkit == 'android' || e10s #Windows can't change size on Android # b2g(Windows can't change size on B2G) b2g-debug(Windows can't change size on B2G) b2g-desktop(Windows can't change size on B2G)
 [test_toJSON.html]
 [test_window_bar.html]
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/bugs/test_errorReporting.html
@@ -0,0 +1,73 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1070842
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1070842</title>
+  <script type="application/javascript" 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 l(e) {
+        window.removeEventListener('error', l);
+        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);
+      });
+
+      // 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>