From c4d8c565b378a2091d917f3e7adc42449325ed90 Mon Sep 17 00:00:00 2001 From: David Burns Date: Mon, 22 May 2017 21:54:26 +0100 Subject: [PATCH] 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 --HG-- extra : rebase_source : be2b8b6da5cf78c6263502a6cb422e2de81c742d --- testing/marionette/driver.js | 4 ++++ .../tests/unit/test_window_maximize.py | 20 +++++++++---------- .../tests/unit/test_window_rect.py | 17 ++++++++++++++-- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/testing/marionette/driver.js b/testing/marionette/driver.js index df9c96686641..53269aa8b285 100644 --- a/testing/marionette/driver.js +++ b/testing/marionette/driver.js @@ -1370,6 +1370,10 @@ GeckoDriver.prototype.setWindowRect = function* (cmd, resp) { 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); diff --git a/testing/marionette/harness/marionette_harness/tests/unit/test_window_maximize.py b/testing/marionette/harness/marionette_harness/tests/unit/test_window_maximize.py index b66892884a34..c5775aafcb2f 100644 --- a/testing/marionette/harness/marionette_harness/tests/unit/test_window_maximize.py +++ b/testing/marionette/harness/marionette_harness/tests/unit/test_window_maximize.py @@ -36,18 +36,16 @@ class TestWindowMaximize(MarionetteTestCase): 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"]) diff --git a/testing/marionette/harness/marionette_harness/tests/unit/test_window_rect.py b/testing/marionette/harness/marionette_harness/tests/unit/test_window_rect.py index a2067aadfe69..04fa8a6073b2 100644 --- a/testing/marionette/harness/marionette_harness/tests/unit/test_window_rect.py +++ b/testing/marionette/harness/marionette_harness/tests/unit/test_window_rect.py @@ -121,8 +121,8 @@ class TestSize(MarionetteTestCase): # 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 @@ -130,6 +130,9 @@ class TestSize(MarionetteTestCase): 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): @@ -190,3 +193,13 @@ class TestSize(MarionetteTestCase): 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)