Bug 1364594: Exit fullscreen when Set Window Rect is invoked. r=ato
☠☠ backed out by 7308157309ae ☠ ☠
authorDavid Burns <dburns@mozilla.com>
Mon, 22 May 2017 21:54:26 +0100
changeset 360152 8cc336b9806d0d16a0ae19d81fed5b2372ac7ea1
parent 360151 73f9c356e3673b52870bc768cae0eb7f49d140af
child 360153 51114054d7767791d7304f763e5aa3ccf10ff556
push id31871
push userryanvm@gmail.com
push dateTue, 23 May 2017 22:02:07 +0000
treeherdermozilla-central@545ffce30eac [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1364594
milestone55.0a1
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
Bug 1364594: Exit fullscreen when Set Window Rect is invoked. r=ato If the browser is in fullscreen mode and Set Window Rect is called we need to exit fullscreen mode and then continue to manipulate the browser. As described in https://w3c.github.io/webdriver/webdriver-spec.html#set-window-rect Step 10 MozReview-Commit-ID: 5ixhGOXVBE4
testing/marionette/driver.js
testing/marionette/harness/marionette_harness/tests/unit/test_window_maximize.py
testing/marionette/harness/marionette_harness/tests/unit/test_window_rect.py
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -1365,16 +1365,20 @@ GeckoDriver.prototype.getWindowRect = fu
  */
 GeckoDriver.prototype.setWindowRect = function* (cmd, resp) {
   assert.firefox()
   const win = assert.window(this.getCurrentWindow());
   assert.noUserPrompt(this.dialog);
 
   let {x, y, width, height} = cmd.parameters;
 
+  if (win.windowState == win.STATE_FULLSCREEN) {
+    win.document.exitFullscreen();
+  }
+
   if (height != null && width != null) {
     assert.positiveInteger(height);
     assert.positiveInteger(width);
 
     if (win.outerWidth != width && win.outerHeight != height) {
       yield new Promise(resolve => {
         // When the DOM resize event claims that it fires _after_ the document
         // view has been resized, it is lying.
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_window_maximize.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_window_maximize.py
@@ -31,28 +31,26 @@ class TestWindowMaximize(MarionetteTestC
             self.original_size["width"], self.original_size["height"])
 
     def assert_window_maximized(self, actual, delta=None):
         if self.marionette.session_capabilities["platformName"] == "windows_nt":
             delta = 16
         else:
             delta = 8
 
-        self.assertAlmostEqual(
-            actual["width"], self.max["width"],
-            delta=delta,
-            msg="Window width is not within {} px of availWidth: "
-                "current width {} and max width {}"
-                .format(delta, actual["width"], self.max["width"]))
-        self.assertAlmostEqual(
+        self.assertGreaterEqual(
+            actual["width"], self.max["width"] - delta,
+            msg="Window width is not within {delta} px of availWidth: "
+                "current width {expected} should be greater than max width {max}"
+                .format(delta=delta, expected=actual["width"], max=self.max["width"] - delta))
+        self.assertGreaterEqual(
             actual["height"], self.max["height"],
-            delta=delta,
-            msg="Window height is not within {} px of availHeight, "
-                "current height {} and max height {}"
-                .format(delta, actual["height"], self.max["height"]))
+            msg="Window height is not within {delta} px of availHeight: "
+                "current height {expected} should be greater than max width {max}"
+                .format(delta=delta, expected=actual["height"], max=self.max["height"] - delta))
 
     def assert_window_restored(self, actual):
         self.assertEqual(self.original_size["width"], actual["width"])
         self.assertEqual(self.original_size["height"], actual["height"])
 
     def assert_window_rect(self, rect):
         self.assertIn("width", rect)
         self.assertIn("height", rect)
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_window_rect.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_window_rect.py
@@ -116,25 +116,28 @@ class TestSize(MarionetteTestCase):
 
         # WebDriver spec says a resize cannot result in window being
         # maximised, an error is returned if that is the case; therefore if
         # the window is maximised at the start of this test, returning to
         # the original size via set_window_size size will result in error;
         # so reset to original size minus 1 pixel width
         start_size = self.marionette.window_size
         if start_size["width"] == self.max["width"] and start_size["height"] == self.max["height"]:
-            start_size["width"] -= 1
-            start_size["height"] -= 1
+            start_size["width"] -= 10
+            start_size["height"] -= 10
         self.marionette.set_window_size(start_size["width"], start_size["height"])
 
         self.original_size = self.marionette.window_size
 
     def tearDown(self):
         self.marionette.set_window_size(
             self.original_size["width"], self.original_size["height"])
+        is_fullscreen = self.marionette.execute_script("return document.fullscreenElement;", sandbox=None)
+        if is_fullscreen:
+            self.marionette.fullscreen()
         super(MarionetteTestCase, self).tearDown()
 
     def test_get_types(self):
         size = self.marionette.window_size
         self.assertIn("width", size)
         self.assertIn("height", size)
         self.assertIsInstance(size["width"], int)
         self.assertIsInstance(size["height"], int)
@@ -185,8 +188,18 @@ class TestSize(MarionetteTestCase):
         self.assertGreaterEqual(new["width"], self.max["width"])
         self.assertGreaterEqual(new["height"], self.max["height"])
 
     def test_resize_to_available_screen_size(self):
         result = self.marionette.set_window_rect(width=self.max['width'],
                                                  height=self.max["height"])
         self.assertEqual(result["width"], self.max["width"])
         self.assertEqual(result["height"], self.max["height"])
+
+    def test_resize_while_fullscreen(self):
+        self.marionette.fullscreen()
+        result = self.marionette.set_window_rect(width=self.max["width"] - 100,
+                                                 height=self.max["height"] - 100)
+
+        self.assertTrue(self.marionette.execute_script("return window.fullscreenElement == null",
+                                                        sandbox=None))
+        self.assertEqual(result["width"], self.max["width"] - 100)
+        self.assertEqual(result["height"], self.max["height"] - 100)