Bug 1157714 - Move browser_monitorUncaught to a xpcshell test. a=test-only
authorDavid Rajchenbach-Teller <dteller@mozilla.com>
Tue, 19 May 2015 12:21:28 +0200
changeset 274995 23a9b4381ad9508d3b7c4253ef8264731f41f808
parent 274994 be081630e5f114d418e3f32619af879c4e01dd32
child 274996 3b3b9a96c8a361c6746c733883e9b124b617b772
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstest-only
bugs1157714
milestone40.0a2
Bug 1157714 - Move browser_monitorUncaught to a xpcshell test. a=test-only CLOSED TREE
dom/promise/moz.build
dom/promise/tests/browser.ini
dom/promise/tests/browser_monitorUncaught.js
dom/promise/tests/unit/test_monitor_uncaught.js
dom/promise/tests/unit/xpcshell.ini
--- a/dom/promise/moz.build
+++ b/dom/promise/moz.build
@@ -30,9 +30,10 @@ LOCAL_INCLUDES += [
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
 
 MOCHITEST_MANIFESTS += ['tests/mochitest.ini']
 
 MOCHITEST_CHROME_MANIFESTS += ['tests/chrome.ini']
-BROWSER_CHROME_MANIFESTS += ['tests/browser.ini']
+
+XPCSHELL_TESTS_MANIFESTS += ['tests/unit/xpcshell.ini']
deleted file mode 100644
--- a/dom/promise/tests/browser.ini
+++ /dev/null
@@ -1,7 +0,0 @@
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-[DEFAULT]
-
-[browser_monitorUncaught.js]
\ No newline at end of file
rename from dom/promise/tests/browser_monitorUncaught.js
rename to dom/promise/tests/unit/test_monitor_uncaught.js
--- a/dom/promise/tests/browser_monitorUncaught.js
+++ b/dom/promise/tests/unit/test_monitor_uncaught.js
@@ -1,29 +1,31 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
+const { utils: Cu } = Components;
+
 Cu.import("resource://gre/modules/Timer.jsm", this);
 
 add_task(function* test_globals() {
   Assert.equal(Promise.defer || undefined, undefined, "We are testing DOM Promise.");
   Assert.notEqual(PromiseDebugging, undefined, "PromiseDebugging is available.");
 });
 
 add_task(function* test_promiseID() {
   let p1 = new Promise(resolve => {});
   let p2 = new Promise(resolve => {});
   let p3 = p2.then(null, null);
   let promise = [p1, p2, p3];
 
   let identifiers = promise.map(PromiseDebugging.getPromiseID);
-  info("Identifiers: " + JSON.stringify(identifiers));
+  do_print("Identifiers: " + JSON.stringify(identifiers));
   let idSet = new Set(identifiers);
   Assert.equal(idSet.size, identifiers.length,
     "PromiseDebugging.getPromiseID returns a distinct id per promise");
 
   let identifiers2 = promise.map(PromiseDebugging.getPromiseID);
   Assert.equal(JSON.stringify(identifiers),
                JSON.stringify(identifiers2),
                "Successive calls to PromiseDebugging.getPromiseID return the same id for the same promise");
@@ -37,17 +39,17 @@ add_task(function* test_observe_uncaught
   let CallbackResults = function(name) {
     this.name = name;
     this.expected = new Set();
     this.observed = new Set();
     this.blocker = new Promise(resolve => this.resolve = resolve);
   };
   CallbackResults.prototype = {
     observe: function(promise) {
-      info(this.name + " observing Promise " + names.get(promise));
+      do_print(this.name + " observing Promise " + names.get(promise));
       Assert.equal(PromiseDebugging.getState(promise).state, "rejected",
                    this.name + " observed a rejected Promise");
       if (!this.expected.has(promise)) {
         Assert.ok(false,
             this.name + " observed a Promise that it expected to observe, " +
             names.get(promise) +
             " (" + PromiseDebugging.getPromiseID(promise) +
             ", " + PromiseDebugging.getAllocationStack(promise) + ")");
@@ -57,18 +59,18 @@ add_task(function* test_observe_uncaught
                 this.name + " observed a Promise that it expected to observe, " +
                 names.get(promise)  + " (" + PromiseDebugging.getPromiseID(promise) + ")");
       Assert.ok(!this.observed.has(promise),
                 this.name + " observed a Promise that it has not observed yet");
       this.observed.add(promise);
       if (this.expected.size == 0) {
         this.resolve();
       } else {
-        info(this.name + " is still waiting for " + this.expected.size + " observations:");
-        info(JSON.stringify([names.get(x) for (x of this.expected.values())]));
+        do_print(this.name + " is still waiting for " + this.expected.size + " observations:");
+        do_print(JSON.stringify([names.get(x) for (x of this.expected.values())]));
       }
     },
   };
 
   let onLeftUncaught = new CallbackResults("onLeftUncaught");
   let onConsumed = new CallbackResults("onConsumed");
 
   let observer = {
@@ -112,17 +114,17 @@ add_task(function* test_observe_uncaught
       leftUncaught: true,
       consumed: false,
       name: "Promise.reject",
     };
 
     // Reject a promise now, consume it later.
     let p = Promise.reject("Reject now, consume later");
     setTimeout(() => p.then(null, () => {
-      info("Consumed promise");
+      do_print("Consumed promise");
     }), 200);
     yield {
       promise: p,
       leftUncaught: true,
       consumed: true,
       name: "Reject now, consume later",
     };
 
@@ -185,42 +187,42 @@ add_task(function* test_observe_uncaught
       leftUncaught: true,
       consumed: false,
       name: "Throwing during the call to the success callback",
     };
   };
   let samples = [];
   for (let s of makeSamples()) {
     samples.push(s);
-    info("Promise '" + s.name + "' has id " + PromiseDebugging.getPromiseID(s.promise));
+    do_print("Promise '" + s.name + "' has id " + PromiseDebugging.getPromiseID(s.promise));
   }
 
   PromiseDebugging.addUncaughtRejectionObserver(observer);
 
   for (let s of samples) {
     names.set(s.promise, s.name);
     if (s.leftUncaught || false) {
       onLeftUncaught.expected.add(s.promise);
     }
     if (s.consumed || false) {
       onConsumed.expected.add(s.promise);
     }
   }
 
-  info("Test setup, waiting for callbacks.");
+  do_print("Test setup, waiting for callbacks.");
   yield onLeftUncaught.blocker;
 
-  info("All calls to onLeftUncaught are complete.");
+  do_print("All calls to onLeftUncaught are complete.");
   if (onConsumed.expected.size != 0) {
-    info("onConsumed is still waiting for the following Promise:");
-    info(JSON.stringify([names.get(x) for (x of onConsumed.expected.values())]));
+    do_print("onConsumed is still waiting for the following Promise:");
+    do_print(JSON.stringify([names.get(x) for (x of onConsumed.expected.values())]));
     yield onConsumed.blocker;
   }
 
-  info("All calls to onConsumed are complete.");
+  do_print("All calls to onConsumed are complete.");
   let removed = PromiseDebugging.removeUncaughtRejectionObserver(observer);
   Assert.ok(removed, "removeUncaughtRejectionObserver succeeded");
   removed = PromiseDebugging.removeUncaughtRejectionObserver(observer);
   Assert.ok(!removed, "second call to removeUncaughtRejectionObserver didn't remove anything");
 });
 
 
 add_task(function* test_uninstall_observer() {
@@ -241,26 +243,28 @@ add_task(function* test_uninstall_observ
       Assert.ok(this._active, "This observer is active.");
       this.resolve();
     },
     onConsumed: function() {
       Assert.ok(false, "We should not consume any Promise.");
     },
   };
 
-  info("Adding an observer.");
+  do_print("Adding an observer.");
   let deactivate = new Observer();
   Promise.reject("I am an uncaught rejection.");
   yield deactivate.blocker;
   Assert.ok(true, "The observer has observed an uncaught Promise.");
   deactivate.active = false;
-  info("Removing the observer, it should not observe any further uncaught Promise.");
+  do_print("Removing the observer, it should not observe any further uncaught Promise.");
 
-  info("Rejecting a Promise and waiting a little to give a chance to observers.");
+  do_print("Rejecting a Promise and waiting a little to give a chance to observers.");
   let wait = new Observer();
   Promise.reject("I am another uncaught rejection.");
   yield wait.blocker;
   yield new Promise(resolve => setTimeout(resolve, 100));
   // Normally, `deactivate` should not be notified of the uncaught rejection.
   wait.active = false;
-
 });
 
+function run_test() {
+  run_next_test();
+}
new file mode 100644
--- /dev/null
+++ b/dom/promise/tests/unit/xpcshell.ini
@@ -0,0 +1,5 @@
+[DEFAULT]
+head =
+tail =
+
+[test_monitor_uncaught.js]