Bug 1319237 - Avoid reposition waiting if position is unchanged; r=maja_zf draft
authorAndreas Tolfsen <ato@mozilla.com>
Thu, 02 Feb 2017 14:58:36 +0000
changeset 482819 c8d623d7168a4010fd08f5d85a573ac91100862c
parent 482818 baecae60af14ee4f5a16b553054c1e8c919547ba
child 482820 3ec71a66bcd234a20649e19896199f39beeaa36e
push id45172
push userbmo:ato@mozilla.com
push dateMon, 13 Feb 2017 14:08:30 +0000
reviewersmaja_zf
bugs1319237
milestone54.0a1
Bug 1319237 - Avoid reposition waiting if position is unchanged; r=maja_zf When the requested window position is the same as the current position, we should avoid the wait condition. MozReview-Commit-ID: 3koG5BeOkFC
testing/marionette/driver.js
testing/marionette/harness/marionette_harness/tests/unit/test_window_position.py
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -1183,18 +1183,24 @@ GeckoDriver.prototype.setWindowPosition 
   let {x, y} = cmd.parameters;
   assert.positiveInteger(x);
   assert.positiveInteger(y);
 
   let win = this.getCurrentWindow();
   let orig = {screenX: win.screenX, screenY: win.screenY};
 
   win.moveTo(x, y);
-  yield wait.until(() => win.screenX != orig.screenX ||
-      win.screenY != orig.screenY);
+  yield wait.until((resolve, reject) => {
+    if ((x == win.screenX && y == win.screenY) ||
+      (win.screenX != orig.screenX || win.screenY != orig.screenY)) {
+      resolve();
+    } else {
+      reject();
+    }
+  });
 
   return this.curBrowser.position;
 };
 
 /**
  * Switch current top-level browsing context by name or server-assigned ID.
  * Searches for windows by name, then ID.  Content windows take precedence.
  *
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_window_position.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_window_position.py
@@ -26,8 +26,15 @@ class TestWindowPosition(MarionetteTestC
                 self.marionette.set_window_position(x, y)
 
     def test_move_to_new_position(self):
         old_position = self.marionette.get_window_position()
         new_position = {"x": old_position["x"] + 10, "y": old_position["y"] + 10}
         self.marionette.set_window_position(new_position["x"], new_position["y"])
         self.assertNotEqual(old_position["x"], new_position["x"])
         self.assertNotEqual(old_position["y"], new_position["y"])
+
+    def test_move_to_existing_position(self):
+        old_position = self.marionette.get_window_position()
+        self.marionette.set_window_position(old_position["x"], old_position["y"])
+        new_position = self.marionette.get_window_position()
+        self.assertEqual(old_position["x"], new_position["x"])
+        self.assertEqual(old_position["y"], new_position["y"])