Backed out changeset bf79d5b1b4b0 (bug 1404946)
authorSebastian Hengst <archaeopteryx@coole-files.de>
Mon, 09 Oct 2017 16:23:04 +0200
changeset 385115 35beb8d02dcc9069d97cbc6530cfe7344763fd60
parent 385114 567eafaa5efe59677570a1b30c157d0398105b3c
child 385116 ff635ffa3ab790e0369ba447a3419d731a5ef53b
push id52896
push userarchaeopteryx@coole-files.de
push dateMon, 09 Oct 2017 14:24:20 +0000
treeherderautoland@7aec94f0c517 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1404946
milestone58.0a1
backs outbf79d5b1b4b0a8e5b2b760ee17ac966ca295a608
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
Backed out changeset bf79d5b1b4b0 (bug 1404946)
testing/marionette/driver.js
testing/marionette/element.js
testing/marionette/sync.js
testing/marionette/test_sync.js
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -42,20 +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 {
-  PollPromise,
-  TimedPromise,
-} = Cu.import("chrome://marionette/content/sync.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";
 
@@ -1486,30 +1483,30 @@ GeckoDriver.prototype.setWindowRect = as
       win.resizeTo(width, height);
     });
   }
 
   // Wait until window size has changed.  We can't wait for the
   // user-requested window size as this may not be achievable on the
   // current system.
   const windowResizeChange = async () => {
-    return new PollPromise((resolve, reject) => {
+    return wait.until((resolve, reject) => {
       let curRect = this.curBrowser.rect;
       if (curRect.width != origRect.width &&
           curRect.height != origRect.height) {
         resolve();
       } else {
         reject();
       }
     });
   };
 
   // Wait for the window position to change.
   async function windowPosition(x, y) {
-    return new PollPromise((resolve, reject) => {
+    return wait.until((resolve, reject) => {
       if ((x == win.screenX && y == win.screenY) ||
           (win.screenX != origRect.x || win.screenY != origRect.y)) {
         resolve();
       } else {
         reject();
       }
     });
   }
@@ -3046,18 +3043,18 @@ GeckoDriver.prototype.maximizeWindow = a
   }
 
   const origSize = {
     outerWidth: win.outerWidth,
     outerHeight: win.outerHeight,
   };
 
   // Wait for the window size to change.
-  async function windowSizeChange(f) {
-    return new PollPromise((resolve, reject) => {
+  async function windowSizeChange() {
+    return wait.until((resolve, reject) => {
       let curSize = {
         outerWidth: win.outerWidth,
         outerHeight: win.outerHeight,
       };
       if (curSize.outerWidth != origSize.outerWidth ||
           curSize.outerHeight != origSize.outerHeight) {
         resolve();
       } else {
--- 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", {});
-const {PollPromise} = Cu.import("chrome://marionette/content/sync.js", {});
+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);
@@ -244,17 +244,17 @@ element.find = function(container, strat
   let searchFn;
   if (opts.all) {
     searchFn = findElements.bind(this);
   } else {
     searchFn = findElement.bind(this);
   }
 
   return new Promise((resolve, reject) => {
-    let findElements = new PollPromise((resolve, reject) => {
+    let findElements = wait.until((resolve, reject) => {
       let res = find_(container, strategy, selector, searchFn, opts);
       if (res.length > 0) {
         resolve(Array.from(res));
       } else {
         reject([]);
       }
     }, opts.timeout);
 
--- a/testing/marionette/sync.js
+++ b/testing/marionette/sync.js
@@ -7,17 +7,24 @@
 const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 
 const {
   error,
   TimeoutError,
 } = Cu.import("chrome://marionette/content/error.js", {});
 
 /* exported TimedPromise */
-this.EXPORTED_SYMBOLS = ["PollPromise", "TimedPromise"];
+this.EXPORTED_SYMBOLS = ["wait", "TimedPromise"];
+
+/**
+ * Poll-waiting utilities.
+ *
+ * @namespace
+ */
+this.wait = {};
 
 const {TYPE_ONE_SHOT, TYPE_REPEATING_SLACK} = Ci.nsITimer;
 
 /**
  * @callback Condition
  *
  * @param {function(*)} resolve
  *     To be called when the condition has been met.  Will return the
@@ -50,17 +57,17 @@ const {TYPE_ONE_SHOT, TYPE_REPEATING_SLA
  * <code>reject</code> will evaluate <var>func</var> again until
  * the <var>timeout</var> duration has elapsed or <var>func</var>
  * throws.  The passed value to <code>reject</code> will also be
  * returned to the caller once the wait has expired.
  *
  * Usage:
  *
  * <pre><code>
- *     let els = new PollPromise((resolve, reject) => {
+ *     let els = wait.until((resolve, reject) => {
  *       let res = document.querySelectorAll("p");
  *       if (res.length > 0) {
  *         resolve(Array.from(res));
  *       } else {
  *         reject([]);
  *       }
  *     });
  * </pre></code>
@@ -77,17 +84,17 @@ const {TYPE_ONE_SHOT, TYPE_REPEATING_SLA
  *
  * @return {Promise.<*>}
  *     Yields the value passed to <var>func</var>'s
  *     <code>resolve</code> or <code>reject</code> callbacks.
  *
  * @throws {*}
  *     If <var>func</var> throws, its error is propagated.
  */
-function PollPromise(func, timeout = 2000, interval = 10) {
+wait.until = function(func, timeout = 2000, interval = 10) {
   const timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
 
   return new Promise((resolve, reject) => {
     const start = new Date().getTime();
     const end = start + timeout;
 
     let evalFn = () => {
       new Promise(func).then(resolve, rejected => {
@@ -111,17 +118,17 @@ function PollPromise(func, timeout = 200
 
   }).then(res => {
     timer.cancel();
     return res;
   }, err => {
     timer.cancel();
     throw err;
   });
-}
+};
 
 /**
  * The <code>TimedPromise</code> object represents the timed, eventual
  * completion (or failure) of an asynchronous operation, and its
  * resulting value.
  *
  * In contrast to a regular {@link Promise}, it times out after
  * <var>timeout</var>.
--- a/testing/marionette/test_sync.js
+++ b/testing/marionette/test_sync.js
@@ -1,76 +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;
 
-const {PollPromise} = Cu.import("chrome://marionette/content/sync.js", {});
+Cu.import("chrome://marionette/content/sync.js");
 
 const DEFAULT_TIMEOUT = 2000;
 
-add_task(async function test_PollPromise_types() {
+add_task(async function test_until_types() {
   for (let typ of [true, false, "foo", 42, [], {}]) {
-    strictEqual(typ, await new PollPromise(resolve => resolve(typ)));
+    strictEqual(typ, await wait.until(resolve => resolve(typ)));
   }
 });
 
-add_task(async function test_PollPromise_timeoutElapse() {
+add_task(async function test_until_timeoutElapse() {
   let nevals = 0;
   let start = new Date().getTime();
-  await new PollPromise((resolve, reject) => {
+  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_PollPromise_rethrowError() {
+add_task(async function test_until_rethrowError() {
   let nevals = 0;
   let err;
   try {
-    await PollPromise(() => {
+    await wait.until(() => {
       ++nevals;
       throw new Error();
     });
   } catch (e) {
     err = e;
   }
   equal(1, nevals);
   ok(err instanceof Error);
 });
 
-add_task(async function test_PollPromise_noTimeout() {
+add_task(async function test_until_noTimeout() {
   // run at least once when timeout is 0
   let nevals = 0;
   let start = new Date().getTime();
-  await new PollPromise((resolve, reject) => {
+  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_PollPromise_timeout() {
+add_task(async function test_until_timeout() {
   let nevals = 0;
   let start = new Date().getTime();
-  await new PollPromise((resolve, reject) => {
+  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_PollPromise_interval() {
+add_task(async function test_until_interval() {
   let nevals = 0;
-  await new PollPromise((resolve, reject) => {
+  await wait.until((resolve, reject) => {
     ++nevals;
     reject();
   }, 100, 100);
   equal(2, nevals);
 });