summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/unit/test_promises_object_creationtimestamp.js
diff options
context:
space:
mode:
Diffstat (limited to 'devtools/server/tests/unit/test_promises_object_creationtimestamp.js')
-rw-r--r--devtools/server/tests/unit/test_promises_object_creationtimestamp.js71
1 files changed, 71 insertions, 0 deletions
diff --git a/devtools/server/tests/unit/test_promises_object_creationtimestamp.js b/devtools/server/tests/unit/test_promises_object_creationtimestamp.js
new file mode 100644
index 000000000..1360be56a
--- /dev/null
+++ b/devtools/server/tests/unit/test_promises_object_creationtimestamp.js
@@ -0,0 +1,71 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Test that we get the approximate time range for promise creation timestamp.
+ */
+
+"use strict";
+
+const { PromisesFront } = require("devtools/shared/fronts/promises");
+
+var events = require("sdk/event/core");
+
+add_task(function* () {
+ let client = yield startTestDebuggerServer("promises-object-test");
+ let chromeActors = yield getChromeActors(client);
+
+ ok(Promise.toString().includes("native code"), "Expect native DOM Promise.");
+
+ // We have to attach the chrome TabActor before playing with the PromiseActor
+ yield attachTab(client, chromeActors);
+ yield testPromiseCreationTimestamp(client, chromeActors, v => {
+ return new Promise(resolve => resolve(v));
+ });
+
+ let response = yield listTabs(client);
+ let targetTab = findTab(response.tabs, "promises-object-test");
+ ok(targetTab, "Found our target tab.");
+
+ yield testPromiseCreationTimestamp(client, targetTab, v => {
+ const debuggee = DebuggerServer.getTestGlobal("promises-object-test");
+ return debuggee.Promise.resolve(v);
+ });
+
+ yield close(client);
+});
+
+function* testPromiseCreationTimestamp(client, form, makePromise) {
+ let front = PromisesFront(client, form);
+ let resolution = "MyLittleSecret" + Math.random();
+
+ yield front.attach();
+ yield front.listPromises();
+
+ let onNewPromise = new Promise(resolve => {
+ events.on(front, "new-promises", promises => {
+ for (let p of promises) {
+ if (p.promiseState.state === "fulfilled" &&
+ p.promiseState.value === resolution) {
+ resolve(p);
+ }
+ }
+ });
+ });
+
+ let start = Date.now();
+ let promise = makePromise(resolution);
+ let end = Date.now();
+
+ let grip = yield onNewPromise;
+ ok(grip, "Found our new promise.");
+
+ let creationTimestamp = grip.promiseState.creationTimestamp;
+
+ ok(start - 1 <= creationTimestamp && creationTimestamp <= end + 1,
+ "Expect promise creation timestamp to be within elapsed time range.");
+
+ yield front.detach();
+ // Appease eslint
+ void promise;
+}