Bug 1242505 - Part 4 - Add self-tests for unhandled rejection handling in browser-chrome tests. r=Mossop
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Sat, 27 May 2017 09:15:19 +0100
changeset 409172 971751d97bb4c13a565f35db82cd411d68fa36e7
parent 409171 0411e687044ecc7b56684196238e6e6e68a9d685
child 409173 5809a30a0c4817509beb1078cf336d8367b8107a
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMossop
bugs1242505
milestone55.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 1242505 - Part 4 - Add self-tests for unhandled rejection handling in browser-chrome tests. r=Mossop MozReview-Commit-ID: 9gloXfhfZ3x
testing/mochitest/tests/browser/browser.ini
testing/mochitest/tests/browser/browser_fail_add_task_uncaught_rejection.js
testing/mochitest/tests/browser/browser_fail_uncaught_rejection.js
testing/mochitest/tests/browser/browser_fail_uncaught_rejection_expected.js
testing/mochitest/tests/browser/browser_fail_uncaught_rejection_expected_multi.js
testing/mochitest/tests/browser/browser_uncaught_rejection_expected.js
--- a/testing/mochitest/tests/browser/browser.ini
+++ b/testing/mochitest/tests/browser/browser.ini
@@ -5,35 +5,39 @@ support-files =
 [browser_add_task.js]
 [browser_async.js]
 [browser_browserLoaded_content_loaded.js]
 [browser_BrowserTestUtils.js]
 support-files =
   dummy.html
 [browser_fail.js]
 [browser_fail_add_task.js]
+[browser_fail_add_task_uncaught_rejection.js]
 [browser_fail_async.js]
 [browser_fail_if.js]
 fail-if = true
 [browser_fail_throw.js]
 [browser_fail_timeout.js]
 skip-if = true # Disabled beacuse it takes too long (bug 1178959)
 [browser_fail_uncaught_rejection.js]
+[browser_fail_uncaught_rejection_expected.js]
+[browser_fail_uncaught_rejection_expected_multi.js]
 [browser_fail_unexpectedTimeout.js]
 skip-if = true # Disabled beacuse it takes too long (bug 1178959)
 [browser_getTestFile.js]
 support-files =
   test-dir/*
   waitForFocusPage.html
 [browser_head.js]
 [browser_pass.js]
 [browser_parameters.js]
 [browser_popupNode.js]
 [browser_popupNode_check.js]
 [browser_privileges.js]
 [browser_requestLongerTimeout.js]
 skip-if = true # Disabled beacuse it takes too long (bug 1178959)
 [browser_sanityException.js]
 [browser_sanityException2.js]
+[browser_uncaught_rejection_expected.js]
 [browser_waitForFocus.js]
 skip-if = (os == "win" && e10s && debug)
 [browser_zz_fail_openwindow.js]
 skip-if = true # this catches outside of the main loop to find an extra window
copy from testing/mochitest/tests/browser/browser_fail_add_task.js
copy to testing/mochitest/tests/browser/browser_fail_add_task_uncaught_rejection.js
--- a/testing/mochitest/tests/browser/browser_fail_add_task.js
+++ b/testing/mochitest/tests/browser/browser_fail_add_task_uncaught_rejection.js
@@ -1,17 +1,23 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
-setExpectedFailuresForSelfTest(4);
+setExpectedFailuresForSelfTest(8);
+
+// Keep "JSMPromise" separate so "Promise" still refers to native Promises.
+let JSMPromise = Cu.import("resource://gre/modules/Promise.jsm", {}).Promise;
 
-function rejectOnNextTick(error) {
-  return new Promise((resolve, reject) => executeSoon(() => reject(error)));
+async function rejectOnNextTick(error) {
+  await Promise.resolve();
+
+  Promise.reject(error);
+  JSMPromise.reject(error);
 }
 
 add_task(function failWithoutError() {
   yield rejectOnNextTick(undefined);
 });
 
 add_task(function failWithString() {
   yield rejectOnNextTick("This is a string");
--- a/testing/mochitest/tests/browser/browser_fail_uncaught_rejection.js
+++ b/testing/mochitest/tests/browser/browser_fail_uncaught_rejection.js
@@ -1,6 +1,19 @@
-setExpectedFailuresForSelfTest(1);
+setExpectedFailuresForSelfTest(3);
+
+// Keep "JSMPromise" separate so "Promise" still refers to native Promises.
+let JSMPromise = Cu.import("resource://gre/modules/Promise.jsm", {}).Promise;
 
 function test() {
-  Components.utils.import("resource://gre/modules/Promise.jsm", this);
   Promise.reject(new Error("Promise rejection."));
+  JSMPromise.reject(new Error("Promise.jsm rejection."));
+  (async () => {
+    throw "Synchronous rejection from async function.";
+  })();
+
+  // The following rejections are caught, so they won't result in failures.
+  Promise.reject(new Error("Promise rejection.")).catch(() => {});
+  JSMPromise.reject(new Error("Promise.jsm rejection.")).catch(() => {});
+  (async () => {
+    throw "Synchronous rejection from async function.";
+  })().catch(() => {});
 }
new file mode 100644
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser_fail_uncaught_rejection_expected.js
@@ -0,0 +1,10 @@
+setExpectedFailuresForSelfTest(1);
+
+// The test will fail because there is only one of two expected rejections.
+Cu.import("resource://testing-common/PromiseTestUtils.jsm", this);
+PromiseTestUtils.expectUncaughtRejection(/Promise rejection./);
+PromiseTestUtils.expectUncaughtRejection(/Promise rejection./);
+
+function test() {
+  Promise.reject(new Error("Promise rejection."));
+}
new file mode 100644
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser_fail_uncaught_rejection_expected_multi.js
@@ -0,0 +1,9 @@
+setExpectedFailuresForSelfTest(1);
+
+// The test will fail because an expected uncaught rejection is actually caught.
+Cu.import("resource://testing-common/PromiseTestUtils.jsm", this);
+PromiseTestUtils.expectUncaughtRejection(/Promise rejection./);
+
+function test() {
+  Promise.reject(new Error("Promise rejection.")).catch(() => {});
+}
new file mode 100644
--- /dev/null
+++ b/testing/mochitest/tests/browser/browser_uncaught_rejection_expected.js
@@ -0,0 +1,18 @@
+// Keep "JSMPromise" separate so "Promise" still refers to native Promises.
+let JSMPromise = Cu.import("resource://gre/modules/Promise.jsm", {}).Promise;
+
+Cu.import("resource://testing-common/PromiseTestUtils.jsm", this);
+PromiseTestUtils.whitelistRejectionsGlobally(/Whitelisted rejection./);
+PromiseTestUtils.expectUncaughtRejection(/Promise.jsm rejection./);
+PromiseTestUtils.expectUncaughtRejection(/Promise.jsm rejection./);
+PromiseTestUtils.expectUncaughtRejection(/Promise rejection./);
+PromiseTestUtils.expectUncaughtRejection(/Promise rejection./);
+
+function test() {
+  Promise.reject(new Error("Promise rejection."));
+  Promise.reject(new Error("Promise rejection."));
+  Promise.reject(new Error("Whitelisted rejection."));
+  JSMPromise.reject(new Error("Promise.jsm rejection."));
+  JSMPromise.reject(new Error("Promise.jsm rejection."));
+  JSMPromise.reject(new Error("Whitelisted rejection."));
+}