Bug 1347589: Implement Marionette Get Window Rect. r?ato
Brings the getWindowPosition and getWindowSize calls into
one call. This aligns Marionette with the W3C WebDriver call
`Get Window Rect`.
MozReview-Commit-ID: ItWI6YpCJkx
--- a/testing/marionette/client/marionette_driver/marionette.py
+++ b/testing/marionette/client/marionette_driver/marionette.py
@@ -1456,16 +1456,18 @@ class Marionette(object):
"getCurrentChromeWindowHandle", key="value")
return self.chrome_window
def get_window_position(self):
"""Get the current window's position.
:returns: a dictionary with x and y
"""
+ warnings.warn("get_window_position() has been deprecated, please use get_window_rect()",
+ DeprecationWarning)
return self._send_message(
"getWindowPosition", key="value" if self.protocol == 1 else None)
def set_window_position(self, x, y):
"""Set the position of the current window
:param x: x coordinate for the top left of the window
:param y: y coordinate for the top left of the window
@@ -1491,16 +1493,20 @@ class Marionette(object):
if (x is None and y is None) and (height is None and width is None):
raise errors.InvalidArgumentException("x and y or height and width need values")
return self._send_message("setWindowRect", {"x": x, "y": y,
"height": height,
"width": width})
@property
+ def window_rect(self):
+ return self._send_message("getWindowRect")
+
+ @property
def title(self):
"""Current title of the active window."""
return self._send_message("getTitle", key="value")
@property
def window_handles(self):
"""Get list of windows in the current context.
@@ -2174,16 +2180,18 @@ class Marionette(object):
"""Get the current browser window size.
Will return the current browser window size in pixels. Refers to
window outerWidth and outerHeight values, which include scroll bars,
title bars, etc.
:returns: dictionary representation of current window width and height
"""
+ warnings.warn("window_size property has been deprecated, please use get_window_rect()",
+ DeprecationWarning)
return self._send_message("getWindowSize",
key="value" if self.protocol == 1 else None)
def set_window_size(self, width, height):
"""Resize the browser window currently in focus.
The supplied ``width`` and ``height`` values refer to the window `outerWidth`
and `outerHeight` values, which include scroll bars, title bars, etc.
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -1242,27 +1242,33 @@ GeckoDriver.prototype.getChromeWindowHan
* @return {Array.<string>}
* Unique window handles.
*/
GeckoDriver.prototype.getChromeWindowHandles = function (cmd, resp) {
return this.chromeWindowHandles;
}
/**
- * Get the current window position.
+ * Get the current position and size of the browser window currently in focus.
+ *
+ * Will return the current browser window size in pixels. Refers to
+ * window outerWidth and outerHeight values, which include scroll bars,
+ * title bars, etc.
*
* @return {Object.<string, number>}
- * Object with |x| and |y| coordinates.
+ * Object with |x| and |y| coordinates, and |width| and |height|
+ * of browser window.
*/
-GeckoDriver.prototype.getWindowPosition = function (cmd, resp) {
+GeckoDriver.prototype.getWindowRect = function (cmd, resp) {
let win = assert.window(this.getCurrentWindow());
-
return {
x: win.screenX,
y: win.screenY,
+ width: win.outerWidth,
+ height: win.outerHeight,
};
};
/**
* Set the window position and size of the browser on the OS Window Manager
*
* The supplied width and height values refer to the window outerWidth
* and outerHeight values, which include browser chrome and OS-level
@@ -2577,31 +2583,16 @@ GeckoDriver.prototype.setScreenOrientati
}
if (!win.screen.mozLockOrientation(mozOr)) {
throw new WebDriverError(`Unable to set screen orientation: ${or}`);
}
};
/**
- * Get the size of the browser window currently in focus.
- *
- * Will return the current browser window size in pixels. Refers to
- * window outerWidth and outerHeight values, which include scroll bars,
- * title bars, etc.
- */
-GeckoDriver.prototype.getWindowSize = function (cmd, resp) {
- let win = assert.window(this.getCurrentWindow());
- return {
- width: win.outerWidth,
- height: win.outerHeight,
- };
-};
-
-/**
* Maximizes the user agent window as if the user pressed the maximise
* button.
*
* Not Supported on B2G or Fennec.
*/
GeckoDriver.prototype.maximizeWindow = function (cmd, resp) {
assert.firefox()
let win = assert.window(this.getCurrentWindow());
@@ -3010,19 +3001,20 @@ GeckoDriver.prototype.commands = {
"goBack": GeckoDriver.prototype.goBack,
"goForward": GeckoDriver.prototype.goForward,
"refresh": GeckoDriver.prototype.refresh,
"getWindowHandle": GeckoDriver.prototype.getWindowHandle,
"getChromeWindowHandle": GeckoDriver.prototype.getChromeWindowHandle,
"getCurrentChromeWindowHandle": GeckoDriver.prototype.getChromeWindowHandle,
"getWindowHandles": GeckoDriver.prototype.getWindowHandles,
"getChromeWindowHandles": GeckoDriver.prototype.getChromeWindowHandles,
- "getWindowPosition": GeckoDriver.prototype.getWindowPosition,
+ "getWindowPosition": GeckoDriver.prototype.getWindowRect, // Redirecting for compatibility
"setWindowPosition": GeckoDriver.prototype.setWindowRect, // Redirecting for compatibility
"setWindowRect": GeckoDriver.prototype.setWindowRect,
+ "getWindowRect": GeckoDriver.prototype.getWindowRect,
"getActiveFrame": GeckoDriver.prototype.getActiveFrame,
"switchToFrame": GeckoDriver.prototype.switchToFrame,
"switchToParentFrame": GeckoDriver.prototype.switchToParentFrame,
"switchToWindow": GeckoDriver.prototype.switchToWindow,
"switchToShadowRoot": GeckoDriver.prototype.switchToShadowRoot,
"deleteSession": GeckoDriver.prototype.deleteSession,
"importScript": GeckoDriver.prototype.importScript,
"clearImportedScripts": GeckoDriver.prototype.clearImportedScripts,
@@ -3033,17 +3025,17 @@ GeckoDriver.prototype.commands = {
"takeScreenshot": GeckoDriver.prototype.takeScreenshot,
"addCookie": GeckoDriver.prototype.addCookie,
"getCookies": GeckoDriver.prototype.getCookies,
"deleteAllCookies": GeckoDriver.prototype.deleteAllCookies,
"deleteCookie": GeckoDriver.prototype.deleteCookie,
"getActiveElement": GeckoDriver.prototype.getActiveElement,
"getScreenOrientation": GeckoDriver.prototype.getScreenOrientation,
"setScreenOrientation": GeckoDriver.prototype.setScreenOrientation,
- "getWindowSize": GeckoDriver.prototype.getWindowSize,
+ "getWindowSize": GeckoDriver.prototype.getWindowRect, // Redirecting for compatibility
"setWindowSize": GeckoDriver.prototype.setWindowRect, // Redirecting for compatibility
"maximizeWindow": GeckoDriver.prototype.maximizeWindow,
"dismissDialog": GeckoDriver.prototype.dismissDialog,
"acceptDialog": GeckoDriver.prototype.acceptDialog,
"getTextFromDialog": GeckoDriver.prototype.getTextFromDialog,
"sendKeysToDialog": GeckoDriver.prototype.sendKeysToDialog,
"acceptConnections": GeckoDriver.prototype.acceptConnections,
"quitApplication": GeckoDriver.prototype.quit, // deprecated, can be removed in Firefox 56
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_window_position.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_window_position.py
@@ -30,17 +30,17 @@ class TestWindowPosition(MarionetteTestC
self.marionette.set_window_position(x, y)
def test_setting_window_rect_with_nulls_errors(self):
with self.assertRaises(InvalidArgumentException):
self.marionette.set_window_rect(height=None, width=None,
x=None, y=None)
def test_set_position_with_rect(self):
- old_position = self.marionette.get_window_position()
+ old_position = self.marionette.window_rect
wanted_position = {"x": old_position["x"] + 10, "y": old_position["y"] + 10}
new_position = self.marionette.set_window_rect(x=wanted_position["x"], y=wanted_position["y"])
self.assertNotEqual(old_position["x"], new_position["x"])
self.assertNotEqual(old_position["y"], new_position["y"])
def test_set_size_with_rect(self):