Bug 1404946 - Rename wait module to sync. r=whimboo
authorAndreas Tolfsen <ato@sny.no>
Mon, 02 Oct 2017 16:38:33 +0100
changeset 427859 88012e76b4afccdb068adc3214795c0a93621b3e
parent 427858 f1e4eb9ed51302c62f9d800bdcb02f34c9bcbf38
child 427860 3665cb253cb88050891c26b891617b602e9ba4e4
push id97
push userfmarier@mozilla.com
push dateSat, 14 Oct 2017 01:12:59 +0000
reviewerswhimboo
bugs1404946
milestone58.0a1
Bug 1404946 - Rename wait module to sync. r=whimboo testing/marionette/wait.js originally contained a utility for poll-waiting on a condition. The module has since been expanded to also include TimedPromise, which is a specialisation of Promise that is rejected after a duration. The latter is not a wait utility but a synchronisation primitive. This terminology also covers the first, and this change renames the wait module to sync. MozReview-Commit-ID: Fd3LqfpiEaU
testing/marionette/driver.js
testing/marionette/element.js
testing/marionette/jar.mn
testing/marionette/sync.js
testing/marionette/test_sync.js
testing/marionette/test_wait.js
testing/marionette/unit.ini
testing/marionette/wait.js
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -42,17 +42,17 @@ Cu.import("chrome://marionette/content/e
 Cu.import("chrome://marionette/content/event.js");
 Cu.import("chrome://marionette/content/interaction.js");
 Cu.import("chrome://marionette/content/l10n.js");
 Cu.import("chrome://marionette/content/legacyaction.js");
 Cu.import("chrome://marionette/content/modal.js");
 Cu.import("chrome://marionette/content/proxy.js");
 Cu.import("chrome://marionette/content/reftest.js");
 Cu.import("chrome://marionette/content/session.js");
-const {wait, TimedPromise} = Cu.import("chrome://marionette/content/wait.js", {});
+const {wait, TimedPromise} = Cu.import("chrome://marionette/content/sync.js", {});
 
 Cu.importGlobalProperties(["URL"]);
 
 this.EXPORTED_SYMBOLS = ["GeckoDriver", "Context"];
 
 const FRAME_SCRIPT = "chrome://marionette/content/listener.js";
 const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 
--- a/testing/marionette/element.js
+++ b/testing/marionette/element.js
@@ -10,17 +10,17 @@ const {classes: Cc, interfaces: Ci, util
 Cu.import("chrome://marionette/content/assert.js");
 Cu.import("chrome://marionette/content/atom.js");
 const {
   InvalidSelectorError,
   NoSuchElementError,
   pprint,
   StaleElementReferenceError,
 } = Cu.import("chrome://marionette/content/error.js", {});
-Cu.import("chrome://marionette/content/wait.js");
+const {wait} = Cu.import("chrome://marionette/content/sync.js", {});
 
 this.EXPORTED_SYMBOLS = ["element"];
 
 const XMLNS = "http://www.w3.org/1999/xhtml";
 const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 
 const uuidGen = Cc["@mozilla.org/uuid-generator;1"]
     .getService(Ci.nsIUUIDGenerator);
--- a/testing/marionette/jar.mn
+++ b/testing/marionette/jar.mn
@@ -12,17 +12,17 @@ marionette.jar:
   content/interaction.js (interaction.js)
   content/accessibility.js (accessibility.js)
   content/listener.js (listener.js)
   content/element.js (element.js)
   content/frame.js (frame.js)
   content/cert.js (cert.js)
   content/event.js  (event.js)
   content/error.js (error.js)
-  content/wait.js (wait.js)
+  content/sync.js (sync.js)
   content/message.js (message.js)
   content/modal.js (modal.js)
   content/proxy.js (proxy.js)
   content/capture.js (capture.js)
   content/cookie.js (cookie.js)
   content/atom.js (atom.js)
   content/evaluate.js (evaluate.js)
   content/navigate.js (navigate.js)
rename from testing/marionette/wait.js
rename to testing/marionette/sync.js
new file mode 100644
--- /dev/null
+++ b/testing/marionette/test_sync.js
@@ -0,0 +1,76 @@
+/* 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/. */
+
+const {utils: Cu} = Components;
+
+Cu.import("chrome://marionette/content/sync.js");
+
+const DEFAULT_TIMEOUT = 2000;
+
+add_task(async function test_until_types() {
+  for (let typ of [true, false, "foo", 42, [], {}]) {
+    strictEqual(typ, await wait.until(resolve => resolve(typ)));
+  }
+});
+
+add_task(async function test_until_timeoutElapse() {
+  let nevals = 0;
+  let start = new Date().getTime();
+  await wait.until((resolve, reject) => {
+    ++nevals;
+    reject();
+  });
+  let end = new Date().getTime();
+  greaterOrEqual((end - start), DEFAULT_TIMEOUT);
+  greaterOrEqual(nevals, 15);
+});
+
+add_task(async function test_until_rethrowError() {
+  let nevals = 0;
+  let err;
+  try {
+    await wait.until(() => {
+      ++nevals;
+      throw new Error();
+    });
+  } catch (e) {
+    err = e;
+  }
+  equal(1, nevals);
+  ok(err instanceof Error);
+});
+
+add_task(async function test_until_noTimeout() {
+  // run at least once when timeout is 0
+  let nevals = 0;
+  let start = new Date().getTime();
+  await wait.until((resolve, reject) => {
+    ++nevals;
+    reject();
+  }, 0);
+  let end = new Date().getTime();
+  equal(1, nevals);
+  less((end - start), DEFAULT_TIMEOUT);
+});
+
+add_task(async function test_until_timeout() {
+  let nevals = 0;
+  let start = new Date().getTime();
+  await wait.until((resolve, reject) => {
+    ++nevals;
+    reject();
+  }, 100);
+  let end = new Date().getTime();
+  greater(nevals, 1);
+  greaterOrEqual((end - start), 100);
+});
+
+add_task(async function test_until_interval() {
+  let nevals = 0;
+  await wait.until((resolve, reject) => {
+    ++nevals;
+    reject();
+  }, 100, 100);
+  equal(2, nevals);
+});
deleted file mode 100644
--- a/testing/marionette/test_wait.js
+++ /dev/null
@@ -1,74 +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/. */
-
-const {utils: Cu} = Components;
-
-Cu.import("chrome://marionette/content/wait.js");
-
-add_task(async function test_until_types() {
-  for (let typ of [true, false, "foo", 42, [], {}]) {
-    strictEqual(typ, await wait.until(resolve => resolve(typ)));
-  }
-});
-
-add_task(async function test_until_timeoutElapse() {
-  let nevals = 0;
-  let start = new Date().getTime();
-  await wait.until((resolve, reject) => {
-    ++nevals;
-    reject();
-  });
-  let end = new Date().getTime();
-  greaterOrEqual((end - start), 2000);
-  greaterOrEqual(nevals, 15);
-});
-
-add_task(async function test_until_rethrowError() {
-  let nevals = 0;
-  let err;
-  try {
-    await wait.until(() => {
-      ++nevals;
-      throw new Error();
-    });
-  } catch (e) {
-    err = e;
-  }
-  equal(1, nevals);
-  ok(err instanceof Error);
-});
-
-add_task(async function test_until_noTimeout() {
-  // run at least once when timeout is 0
-  let nevals = 0;
-  let start = new Date().getTime();
-  await wait.until((resolve, reject) => {
-    ++nevals;
-    reject();
-  }, 0);
-  let end = new Date().getTime();
-  equal(1, nevals);
-  less((end - start), 2000);
-});
-
-add_task(async function test_until_timeout() {
-  let nevals = 0;
-  let start = new Date().getTime();
-  await wait.until((resolve, reject) => {
-    ++nevals;
-    reject();
-  }, 100);
-  let end = new Date().getTime();
-  greater(nevals, 1);
-  greaterOrEqual((end - start), 100);
-});
-
-add_task(async function test_until_interval() {
-  let nevals = 0;
-  await wait.until((resolve, reject) => {
-    ++nevals;
-    reject();
-  }, 100, 100);
-  equal(2, nevals);
-});
--- a/testing/marionette/unit.ini
+++ b/testing/marionette/unit.ini
@@ -11,9 +11,9 @@ skip-if = appname == "thunderbird"
 [test_assert.js]
 [test_cookie.js]
 [test_dom.js]
 [test_element.js]
 [test_error.js]
 [test_message.js]
 [test_navigate.js]
 [test_session.js]
-[test_wait.js]
+[test_sync.js]