Bug 1391691 - Make WebDriver:MinimizeWindow idempotent. r?automatedtester draft
authorAndreas Tolfsen <ato@sny.no>
Fri, 18 Aug 2017 18:30:50 +0100
changeset 649131 9094d8f067d257598489289cf55a13db7c859ed0
parent 649130 690035743b74942efb4d111abc571dffa36261af
child 649132 1e74874ab0f027a55494afba8babbf8913fda734
push id74962
push userbmo:ato@sny.no
push dateFri, 18 Aug 2017 17:50:50 +0000
reviewersautomatedtester
bugs1391691
milestone57.0a1
Bug 1391691 - Make WebDriver:MinimizeWindow idempotent. r?automatedtester MozReview-Commit-ID: 4XBw0UFfZ1O
testing/marionette/driver.js
testing/marionette/harness/marionette_harness/tests/unit/test_window_minimize.py
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -2999,17 +2999,19 @@ GeckoDriver.prototype.setScreenOrientati
 
   if (!win.screen.mozLockOrientation(mozOr)) {
     throw new WebDriverError(`Unable to set screen orientation: ${or}`);
   }
 };
 
 /**
  * Synchronously minimizes the user agent window as if the user pressed
- * the minimize button, or restores it if it is already minimized.
+ * the minimize button.
+ *
+ * No action is taken if the window is already minimized.
  *
  * Not supported on Fennec.
  *
  * @return {Object.<string, number>}
  *     Window rect and window state.
  *
  * @throws {UnsupportedOperationError}
  *     Not available for current application.
@@ -3018,25 +3020,22 @@ GeckoDriver.prototype.setScreenOrientati
  * @throws {UnexpectedAlertOpenError}
  *     A modal dialog is open, blocking this operation.
  */
 GeckoDriver.prototype.minimizeWindow = async function(cmd, resp) {
   assert.firefox();
   const win = assert.window(this.getCurrentWindow());
   assert.noUserPrompt(this.dialog);
 
-  await new Promise(resolve => {
-    win.addEventListener("sizemodechange", resolve, {once: true});
-
-    if (win.windowState == win.STATE_MINIMIZED) {
-      win.restore();
-    } else {
+  if (win.windowState != win.STATE_MINIMIZED) {
+    await new Promise(resolve => {
+      win.addEventListener("sizemodechange", resolve, {once: true});
       win.minimize();
-    }
-  });
+    });
+  }
 
   return this.curBrowser.rect;
 };
 
 /**
  * Synchronously maximizes the user agent window as if the user pressed
  * the maximize button, or restores it if it is already maximized.
  *
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_window_minimize.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_window_minimize.py
@@ -16,25 +16,22 @@ class TestWindowMinimize(MarionetteTestC
     def assert_window_minimized(self, resp):
         self.assertEqual("minimized", resp["state"])
 
     def assert_window_restored(self, actual):
         self.assertEqual("normal", actual["state"])
         self.assertEqual(self.original_size["width"], actual["width"])
         self.assertEqual(self.original_size["height"], actual["height"])
 
-    def test_minimize_twice_restores(self):
-        resp = self.marionette.minimize_window()
-        self.assert_window_minimized(resp)
-
-        # restore the window
-        resp = self.marionette.minimize_window()
-        self.assert_window_restored(resp)
+    def test_minimize_twice_is_idempotent(self):
+        self.assert_window_minimized(self.marionette.minimize_window())
+        self.assert_window_minimized(self.marionette.minimize_window())
 
     def test_minimize_stress(self):
         for i in range(1, 25):
             expect_minimized = bool(i % 2)
 
-            resp = self.marionette.minimize_window()
             if expect_minimized:
+                resp = self.marionette.minimize_window()
                 self.assert_window_minimized(resp)
             else:
+                self.marionette.set_window_rect(width=800, height=600)
                 self.assert_window_restored(resp)