зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1045103 - add Marionette support for setWindowSize; r=jgrffin
This commit is contained in:
Родитель
9aa0cb1372
Коммит
25d257bb02
|
@ -31,6 +31,7 @@ class ErrorCodes(object):
|
||||||
INVALID_RESPONSE = 53
|
INVALID_RESPONSE = 53
|
||||||
FRAME_SEND_NOT_INITIALIZED_ERROR = 54
|
FRAME_SEND_NOT_INITIALIZED_ERROR = 54
|
||||||
FRAME_SEND_FAILURE_ERROR = 55
|
FRAME_SEND_FAILURE_ERROR = 55
|
||||||
|
UNSUPPORTED_OPERATION = 405
|
||||||
MARIONETTE_ERROR = 500
|
MARIONETTE_ERROR = 500
|
||||||
|
|
||||||
class MarionetteException(Exception):
|
class MarionetteException(Exception):
|
||||||
|
@ -138,3 +139,6 @@ class FrameSendNotInitializedError(MarionetteException):
|
||||||
|
|
||||||
class FrameSendFailureError(MarionetteException):
|
class FrameSendFailureError(MarionetteException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class UnsupportedOperationException(MarionetteException):
|
||||||
|
pass
|
||||||
|
|
|
@ -708,6 +708,8 @@ class Marionette(object):
|
||||||
raise errors.FrameSendNotInitializedError(message=message, status=status, stacktrace=stacktrace)
|
raise errors.FrameSendNotInitializedError(message=message, status=status, stacktrace=stacktrace)
|
||||||
elif status == errors.ErrorCodes.FRAME_SEND_FAILURE_ERROR:
|
elif status == errors.ErrorCodes.FRAME_SEND_FAILURE_ERROR:
|
||||||
raise errors.FrameSendFailureError(message=message, status=status, stacktrace=stacktrace)
|
raise errors.FrameSendFailureError(message=message, status=status, stacktrace=stacktrace)
|
||||||
|
elif status == errors.ErrorCodes.UNSUPPORTED_OPERATION:
|
||||||
|
raise errors.UnsupportedOperationException(message=message, status=status, stacktrace=stacktrace)
|
||||||
else:
|
else:
|
||||||
raise errors.MarionetteException(message=message, status=status, stacktrace=stacktrace)
|
raise errors.MarionetteException(message=message, status=status, stacktrace=stacktrace)
|
||||||
raise errors.MarionetteException(message=response, status=500)
|
raise errors.MarionetteException(message=response, status=500)
|
||||||
|
@ -883,7 +885,6 @@ class Marionette(object):
|
||||||
:rtype: string
|
:rtype: string
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.window = self._send_message("getWindowHandle", "value")
|
self.window = self._send_message("getWindowHandle", "value")
|
||||||
return self.window
|
return self.window
|
||||||
|
|
||||||
|
@ -1515,3 +1516,31 @@ class Marionette(object):
|
||||||
self._send_message("setScreenOrientation", "ok", orientation=orientation)
|
self._send_message("setScreenOrientation", "ok", orientation=orientation)
|
||||||
if self.emulator:
|
if self.emulator:
|
||||||
self.emulator.screen.orientation = orientation.lower()
|
self.emulator.screen.orientation = orientation.lower()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def window_size(self):
|
||||||
|
"""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
|
||||||
|
|
||||||
|
"""
|
||||||
|
return self._send_message("getWindowSize", "value")
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
An error will be returned if the requested window size would result
|
||||||
|
in the window being in the maximised state.
|
||||||
|
|
||||||
|
:param width: The width to resize the window to.
|
||||||
|
:param height: The height to resize the window to.
|
||||||
|
|
||||||
|
"""
|
||||||
|
self._send_message("setWindowSize", "ok", width=width, height=height)
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
from errors import MarionetteException
|
||||||
|
from marionette_test import MarionetteTestCase
|
||||||
|
|
||||||
|
class TestSetWindowSize(MarionetteTestCase):
|
||||||
|
def setUp(self):
|
||||||
|
super(MarionetteTestCase, self).setUp()
|
||||||
|
self.start_size = self.marionette.window_size
|
||||||
|
self.max_width = self.marionette.execute_script("return window.screen.availWidth;")
|
||||||
|
self.max_height = self.marionette.execute_script("return window.screen.availHeight;")
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
# WebDriver spec says a resize cannot result in window being maximized, an
|
||||||
|
# error is returned if that is the case; therefore if the window is maximized
|
||||||
|
# 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
|
||||||
|
if self.start_size['width'] == self.max_width and self.start_size['height'] == self.max_height:
|
||||||
|
self.start_size['width']-=1
|
||||||
|
self.marionette.set_window_size(self.start_size['width'], self.start_size['height'])
|
||||||
|
super(MarionetteTestCase, self).tearDown()
|
||||||
|
|
||||||
|
def test_set_window_size(self):
|
||||||
|
# event handler
|
||||||
|
self.marionette.execute_script("""
|
||||||
|
window.wrappedJSObject.rcvd_event = false;
|
||||||
|
window.onresize = function() {
|
||||||
|
window.wrappedJSObject.rcvd_event = true;
|
||||||
|
};
|
||||||
|
""")
|
||||||
|
|
||||||
|
# valid size
|
||||||
|
width = self.max_width - 100
|
||||||
|
height = self.max_height - 100
|
||||||
|
self.marionette.set_window_size(width, height)
|
||||||
|
self.wait_for_condition(lambda m: m.execute_script("return window.wrappedJSObject.rcvd_event;"))
|
||||||
|
size = self.marionette.window_size
|
||||||
|
self.assertEqual(size['width'], width,
|
||||||
|
"Window width is %s but should be %s" % (size['width'], width))
|
||||||
|
self.assertEqual(size['height'], height,
|
||||||
|
"Window height is %s but should be %s" % (size['height'], height))
|
||||||
|
|
||||||
|
# invalid size (cannot maximize)
|
||||||
|
with self.assertRaisesRegexp(MarionetteException, "Invalid requested size"):
|
||||||
|
self.marionette.set_window_size(self.max_width, self.max_height)
|
||||||
|
size = self.marionette.window_size
|
||||||
|
self.assertEqual(size['width'], width, "Window width should not have changed")
|
||||||
|
self.assertEqual(size['height'], height, "Window height should not have changed")
|
|
@ -120,5 +120,7 @@ browser = false
|
||||||
[test_click_scrolling.py]
|
[test_click_scrolling.py]
|
||||||
[test_profile_management.py]
|
[test_profile_management.py]
|
||||||
b2g = false
|
b2g = false
|
||||||
|
[test_set_window_size.py]
|
||||||
|
b2g = false
|
||||||
|
|
||||||
[include:oop/manifest.ini]
|
[include:oop/manifest.ini]
|
||||||
|
|
|
@ -2353,6 +2353,59 @@ MarionetteServerConnection.prototype = {
|
||||||
this.sendOk(this.command_id);
|
this.sendOk(this.command_id);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
getWindowSize: function MDA_getWindowSize(aRequest) {
|
||||||
|
this.command_id = this.getCommandId();
|
||||||
|
let curWindow = this.getCurrentWindow();
|
||||||
|
let curWidth = curWindow.outerWidth;
|
||||||
|
let curHeight = curWindow.outerHeight;
|
||||||
|
this.sendResponse({width: curWidth, height: curHeight}, this.command_id);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the size of the browser window currently in focus.
|
||||||
|
*
|
||||||
|
* Not supported on B2G. The supplied width and height values refer to
|
||||||
|
* the window outerWidth and outerHeight values, which include scroll
|
||||||
|
* bars, title bars, etc.
|
||||||
|
*
|
||||||
|
* An error will be returned if the requested window size would result
|
||||||
|
* in the window being in the maximized state.
|
||||||
|
*/
|
||||||
|
setWindowSize: function MDA_setWindowSize(aRequest) {
|
||||||
|
this.command_id = this.getCommandId();
|
||||||
|
|
||||||
|
if (appName == "B2G") {
|
||||||
|
this.sendError("Not supported on B2G", 405, null, this.command_id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
var width = parseInt(aRequest.parameters.width);
|
||||||
|
var height = parseInt(aRequest.parameters.height);
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
this.sendError(e.message, e.code, e.stack, this.command_id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let curWindow = this.getCurrentWindow();
|
||||||
|
if (width >= curWindow.screen.availWidth && height >= curWindow.screen.availHeight) {
|
||||||
|
this.sendError("Invalid requested size, cannot maximize", 405, null, this.command_id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
curWindow.resizeTo(width, height);
|
||||||
|
this.sendOk(this.command_id);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to convert an outerWindowID into a UID that Marionette
|
* Helper function to convert an outerWindowID into a UID that Marionette
|
||||||
* tracks.
|
* tracks.
|
||||||
|
@ -2558,7 +2611,9 @@ MarionetteServerConnection.prototype.requestTypes = {
|
||||||
"deleteCookie": MarionetteServerConnection.prototype.deleteCookie,
|
"deleteCookie": MarionetteServerConnection.prototype.deleteCookie,
|
||||||
"getActiveElement": MarionetteServerConnection.prototype.getActiveElement,
|
"getActiveElement": MarionetteServerConnection.prototype.getActiveElement,
|
||||||
"getScreenOrientation": MarionetteServerConnection.prototype.getScreenOrientation,
|
"getScreenOrientation": MarionetteServerConnection.prototype.getScreenOrientation,
|
||||||
"setScreenOrientation": MarionetteServerConnection.prototype.setScreenOrientation
|
"setScreenOrientation": MarionetteServerConnection.prototype.setScreenOrientation,
|
||||||
|
"getWindowSize": MarionetteServerConnection.prototype.getWindowSize,
|
||||||
|
"setWindowSize": MarionetteServerConnection.prototype.setWindowSize
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Загрузка…
Ссылка в новой задаче