Bug 1084525 - Part 11: Add test for asserting the list of Promise objects returned from the PromiseActor onPromiseSettled event handler r=fitzgen
authorGabriel Luong <gabriel.luong@gmail.com>
Thu, 25 Jun 2015 12:32:17 -0700
changeset 280984 7b21fda089ff93d7998c0b8d63d725f2f326c4e8
parent 280983 4af7a65a817885a9538958ba8db9c46e3ebf2ed3
child 280985 060770ae1170b44a4a55f601bbca0016fe4b87d1
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfitzgen
bugs1084525
milestone41.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 1084525 - Part 11: Add test for asserting the list of Promise objects returned from the PromiseActor onPromiseSettled event handler r=fitzgen
toolkit/devtools/server/tests/unit/test_promises_actor_onpromisesettled.js
toolkit/devtools/server/tests/unit/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/server/tests/unit/test_promises_actor_onpromisesettled.js
@@ -0,0 +1,87 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Test that we can get the list of Promise objects that have settled from the
+ * PromisesActor onPromiseSettled event handler.
+ */
+
+"use strict";
+
+const { PromisesFront } = devtools.require("devtools/server/actors/promises");
+
+let events = devtools.require("sdk/event/core");
+
+add_task(function*() {
+  let client = yield startTestDebuggerServer("promises-actor-test");
+  let chromeActors = yield getChromeActors(client);
+
+  ok(Promise.toString().contains("native code"), "Expect native DOM Promise");
+
+  yield testPromisesSettled(client, chromeActors,
+    v => new Promise(resolve => resolve(v)),
+    v => new Promise((resolve, reject) => reject(v)));
+
+  let response = yield listTabs(client);
+  let targetTab = findTab(response.tabs, "promises-actor-test");
+  ok(targetTab, "Found our target tab.");
+
+  yield testPromisesSettled(client, targetTab, v => {
+    const debuggee = DebuggerServer.getTestGlobal("promises-actor-test");
+    return debuggee.Promise.resolve(v);
+  }, v => {
+    const debuggee = DebuggerServer.getTestGlobal("promises-actor-test");
+    return debuggee.Promise.reject(v);
+  });
+
+  yield close(client);
+});
+
+function* testPromisesSettled(client, form, makeResolvePromise,
+    makeRejectPromise) {
+  let front = PromisesFront(client, form);
+  let resolution = "MyLittleSecret" + Math.random();
+
+  yield front.attach();
+  yield front.listPromises();
+
+  let onPromiseSettled = oncePromiseSettled(front, resolution, true, false);
+  let resolvedPromise = makeResolvePromise(resolution);
+  let foundResolvedPromise = yield onPromiseSettled;
+  ok(foundResolvedPromise, "Found our resolved promise");
+
+  onPromiseSettled = oncePromiseSettled(front, resolution, false, true);
+  let rejectedPromise = makeRejectPromise(resolution);
+  let foundRejectedPromise = yield onPromiseSettled;
+  ok(foundRejectedPromise, "Found our rejected promise");
+
+  yield front.detach();
+  // Appease eslint
+  void resolvedPromise;
+  void rejectedPromise;
+}
+
+function oncePromiseSettled(front, resolution, resolveValue, rejectValue) {
+  return new Promise(resolve => {
+    events.on(front, "promises-settled", promises => {
+      for (let p of promises) {
+        equal(p.type, "object", "Expect type to be Object");
+        equal(p.class, "Promise", "Expect class to be Promise");
+        equal(typeof p.promiseState.creationTimestamp, "number",
+          "Expect creation timestamp to be a number");
+        equal(typeof p.promiseState.timeToSettle, "number",
+          "Expect time to settle to be a number");
+
+        if (p.promiseState.state === "fulfilled" &&
+            p.promiseState.value === resolution) {
+          resolve(resolveValue);
+        } else if (p.promiseState.state === "rejected" &&
+                   p.promiseState.reason === resolution) {
+          resolve(rejectValue);
+        } else {
+          dump("Found non-target promise\n");
+        }
+      }
+    });
+  });
+}
--- a/toolkit/devtools/server/tests/unit/xpcshell.ini
+++ b/toolkit/devtools/server/tests/unit/xpcshell.ini
@@ -82,16 +82,17 @@ support-files =
 [test_eval-03.js]
 [test_eval-04.js]
 [test_eval-05.js]
 [test_originAttributesToCookieJar.js]
 [test_promises_actor_attach.js]
 [test_promises_actor_exist.js]
 [test_promises_actor_list_promises.js]
 [test_promises_actor_onnewpromise.js]
+[test_promises_actor_onpromisesettled.js]
 [test_promises_client_getdependentpromises.js]
 [test_promises_object_creationtimestamp.js]
 [test_promises_object_timetosettle-01.js]
 [test_promises_object_timetosettle-02.js]
 [test_protocol_abort.js]
 [test_protocol_async.js]
 [test_protocol_children.js]
 [test_protocol_formtype.js]