зеркало из https://github.com/mozilla/gecko-dev.git
Bug 805475: add the ability to switch to active element in the document; r=jgriffin
This commit is contained in:
Родитель
875807e9db
Коммит
90373ae680
|
@ -496,6 +496,10 @@ class Marionette(object):
|
|||
elements.append(HTMLElement(self, x))
|
||||
return elements
|
||||
|
||||
def get_active_element(self):
|
||||
response = self._send_message('getActiveElement', 'value')
|
||||
return HTMLElement(self, response)
|
||||
|
||||
def log(self, msg, level=None):
|
||||
return self._send_message('log', 'ok', value=msg, level=level)
|
||||
|
||||
|
|
|
@ -137,6 +137,13 @@ class TestElements(MarionetteTestCase):
|
|||
found_els = nav_el.find_elements("css selector", "a")
|
||||
self.assertFalse(el.id in [found_el.id for found_el in found_els])
|
||||
|
||||
def test_finding_active_element_returns_element(self):
|
||||
test_html = self.marionette.absolute_url("test.html")
|
||||
self.marionette.navigate(test_html)
|
||||
fbody = self.marionette.find_element('tag name', 'body')
|
||||
abody = self.marionette.get_active_element()
|
||||
self.assertEqual(fbody, abody)
|
||||
|
||||
class TestElementsChrome(MarionetteTestCase):
|
||||
def setUp(self):
|
||||
MarionetteTestCase.setUp(self)
|
||||
|
|
|
@ -1320,9 +1320,17 @@ MarionetteDriverActor.prototype = {
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Return the active element on the page
|
||||
*/
|
||||
getActiveElement: function MDA_getActiveElement(){
|
||||
let command_id = this.command_id = this.getCommandId();
|
||||
this.sendAsync("getActiveElement", {command_id: command_id});
|
||||
},
|
||||
|
||||
/**
|
||||
* Send click event to element
|
||||
*
|
||||
*
|
||||
* @param object aRequest
|
||||
* 'element' member holds the reference id to
|
||||
* the element that will be clicked
|
||||
|
@ -2011,7 +2019,8 @@ MarionetteDriverActor.prototype.requestTypes = {
|
|||
"addCookie": MarionetteDriverActor.prototype.addCookie,
|
||||
"getAllCookies": MarionetteDriverActor.prototype.getAllCookies,
|
||||
"deleteAllCookies": MarionetteDriverActor.prototype.deleteAllCookies,
|
||||
"deleteCookie": MarionetteDriverActor.prototype.deleteCookie
|
||||
"deleteCookie": MarionetteDriverActor.prototype.deleteCookie,
|
||||
"getActiveElement": MarionetteDriverActor.prototype.getActiveElement
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -102,6 +102,7 @@ function startListeners() {
|
|||
addMessageListenerId("Marionette:refresh", refresh);
|
||||
addMessageListenerId("Marionette:findElementContent", findElementContent);
|
||||
addMessageListenerId("Marionette:findElementsContent", findElementsContent);
|
||||
addMessageListenerId("Marionette:getActiveElement", getActiveElement);
|
||||
addMessageListenerId("Marionette:clickElement", clickElement);
|
||||
addMessageListenerId("Marionette:getElementAttribute", getElementAttribute);
|
||||
addMessageListenerId("Marionette:getElementText", getElementText);
|
||||
|
@ -188,6 +189,7 @@ function deleteSession(msg) {
|
|||
removeMessageListenerId("Marionette:refresh", refresh);
|
||||
removeMessageListenerId("Marionette:findElementContent", findElementContent);
|
||||
removeMessageListenerId("Marionette:findElementsContent", findElementsContent);
|
||||
removeMessageListenerId("Marionette:getActiveElement", getActiveElement);
|
||||
removeMessageListenerId("Marionette:clickElement", clickElement);
|
||||
removeMessageListenerId("Marionette:getElementAttribute", getElementAttribute);
|
||||
removeMessageListenerId("Marionette:getElementTagName", getElementTagName);
|
||||
|
@ -655,6 +657,16 @@ function findElementsContent(msg) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find and return the active element on the page
|
||||
*/
|
||||
function getActiveElement(msg) {
|
||||
let command_id = msg.json.command_id;
|
||||
var element = curWindow.document.activeElement;
|
||||
var id = elementManager.addToKnownElements(element);
|
||||
sendResponse({value: id}, command_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send click event to element
|
||||
*/
|
||||
|
|
Загрузка…
Ссылка в новой задаче