mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 800956: adding the ability to get the size of elements to marionette; r=mdas
This commit is contained in:
parent
ca5d080497
commit
24a17d4186
@ -74,6 +74,10 @@ class HTMLElement(object):
|
||||
|
||||
def is_displayed(self):
|
||||
return self.marionette._send_message('isElementDisplayed', 'value', element=self.id)
|
||||
|
||||
@property
|
||||
def size(self):
|
||||
return self.marionette._send_message('getElementSize', 'value', element=self.id)
|
||||
|
||||
@property
|
||||
def tag_name(self):
|
||||
|
@ -0,0 +1,40 @@
|
||||
# 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 marionette_test import MarionetteTestCase
|
||||
|
||||
class TestElementSize(MarionetteTestCase):
|
||||
def testShouldReturnTheSizeOfALink(self):
|
||||
test_html = self.marionette.absolute_url("testSize.html")
|
||||
self.marionette.navigate(test_html)
|
||||
shrinko = self.marionette.find_element('id', 'linkId')
|
||||
size = shrinko.size
|
||||
self.assertTrue(size['width'] > 0)
|
||||
self.assertTrue(size['height'] > 0)
|
||||
|
||||
class TestElementSizeChrome(MarionetteTestCase):
|
||||
def setUp(self):
|
||||
MarionetteTestCase.setUp(self)
|
||||
self.marionette.set_context("chrome")
|
||||
self.win = self.marionette.current_window_handle
|
||||
self.marionette.execute_script("window.open('chrome://marionette/content/test2.xul', 'foo', 'chrome,centerscreen');")
|
||||
self.marionette.switch_to_window('foo')
|
||||
self.assertNotEqual(self.win, self.marionette.current_window_handle)
|
||||
|
||||
def tearDown(self):
|
||||
self.assertNotEqual(self.win, self.marionette.current_window_handle)
|
||||
self.marionette.execute_script("window.close();")
|
||||
self.marionette.switch_to_window(self.win)
|
||||
MarionetteTestCase.tearDown(self)
|
||||
|
||||
def testShouldReturnTheSizeOfAnInput(self):
|
||||
wins = self.marionette.window_handles
|
||||
wins.remove(self.win)
|
||||
newWin = wins.pop()
|
||||
self.marionette.switch_to_window(newWin)
|
||||
shrinko = self.marionette.find_element('id', 'textInput')
|
||||
size = shrinko.size
|
||||
self.assertTrue(size['width'] > 0)
|
||||
self.assertTrue(size['height'] > 0)
|
||||
|
9
testing/marionette/client/marionette/www/testSize.html
Normal file
9
testing/marionette/client/marionette/www/testSize.html
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0"?>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<title>Test page for element size</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Let's get the size of <a href='#' id='linkId'>some really cool link</a></p>
|
||||
</body>
|
||||
</html>
|
@ -1337,6 +1337,22 @@ MarionetteDriverActor.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
getElementSize: function MDA_getElementSize(aRequest) {
|
||||
if (this.context == "chrome") {
|
||||
try {
|
||||
let el = this.curBrowser.elementManager.getKnownElement(aRequest.element, this.getCurrentWindow());
|
||||
let clientRect = el.getBoundingClientRect();
|
||||
this.sendResponse({width: clientRect.width, height: clientRect.height});
|
||||
}
|
||||
catch (e) {
|
||||
this.sendError(e.message, e.code, e.stack);
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.sendAsync("getElementSize", {element:aRequest.element});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Send key presses to element after focusing on it
|
||||
*
|
||||
@ -1688,6 +1704,7 @@ MarionetteDriverActor.prototype.requestTypes = {
|
||||
"getElementText": MarionetteDriverActor.prototype.getElementText,
|
||||
"getElementTagName": MarionetteDriverActor.prototype.getElementTagName,
|
||||
"isElementDisplayed": MarionetteDriverActor.prototype.isElementDisplayed,
|
||||
"getElementSize": MarionetteDriverActor.prototype.getElementSize,
|
||||
"isElementEnabled": MarionetteDriverActor.prototype.isElementEnabled,
|
||||
"isElementSelected": MarionetteDriverActor.prototype.isElementSelected,
|
||||
"sendKeysToElement": MarionetteDriverActor.prototype.sendKeysToElement,
|
||||
|
@ -105,6 +105,7 @@ function startListeners() {
|
||||
addMessageListenerId("Marionette:getElementText", getElementText);
|
||||
addMessageListenerId("Marionette:getElementTagName", getElementTagName);
|
||||
addMessageListenerId("Marionette:isElementDisplayed", isElementDisplayed);
|
||||
addMessageListenerId("Marionette:getElementSize", getElementSize);
|
||||
addMessageListenerId("Marionette:isElementEnabled", isElementEnabled);
|
||||
addMessageListenerId("Marionette:isElementSelected", isElementSelected);
|
||||
addMessageListenerId("Marionette:sendKeysToElement", sendKeysToElement);
|
||||
@ -168,6 +169,7 @@ function deleteSession(msg) {
|
||||
removeMessageListenerId("Marionette:getElementAttribute", getElementAttribute);
|
||||
removeMessageListenerId("Marionette:getElementTagName", getElementTagName);
|
||||
removeMessageListenerId("Marionette:isElementDisplayed", isElementDisplayed);
|
||||
removeMessageListenerId("Marionette:getElementSize", getElementSize);
|
||||
removeMessageListenerId("Marionette:isElementEnabled", isElementEnabled);
|
||||
removeMessageListenerId("Marionette:isElementSelected", isElementSelected);
|
||||
removeMessageListenerId("Marionette:sendKeysToElement", sendKeysToElement);
|
||||
@ -671,6 +673,20 @@ function isElementDisplayed(msg) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the element and return it
|
||||
*/
|
||||
function getElementSize(msg){
|
||||
try {
|
||||
let el = elementManager.getKnownElement(msg.json.element, curWindow);
|
||||
let clientRect = el.getBoundingClientRect();
|
||||
sendResponse({value: {width: clientRect.width, height: clientRect.height}});
|
||||
}
|
||||
catch (e) {
|
||||
sendError(e.message, e.code, e.stack);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if element is enabled
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user