aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2019-07-21 09:44:26 -0400
committerGitHub <noreply@github.com>2019-07-21 09:44:26 -0400
commit75275965f08d7b34be73254b7b4df9135cc8fcf8 (patch)
tree1666583d79798f506f417bbea71ecec39cd5c04e /components/script
parent4128a3893662c61a19b9316cd19eab7533518453 (diff)
parentbf6ea64e8c2b12b57fbb755a81c2de3f3a3c3c83 (diff)
downloadservo-75275965f08d7b34be73254b7b4df9135cc8fcf8.tar.gz
servo-75275965f08d7b34be73254b7b4df9135cc8fcf8.zip
Auto merge of #23585 - georgeroman:tag_name_selector_for_find_element_wd_commands, r=jdm
Implement tag name selector for FindElement and related WebDriver commands <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors <!-- Either: --> - [X] There are tests for these changes <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23585) <!-- Reviewable:end -->
Diffstat (limited to 'components/script')
-rw-r--r--components/script/script_thread.rs34
-rw-r--r--components/script/webdriver_handlers.rs84
2 files changed, 116 insertions, 2 deletions
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs
index ba1741ba321..ae18f075b0e 100644
--- a/components/script/script_thread.rs
+++ b/components/script/script_thread.rs
@@ -2019,6 +2019,14 @@ impl ScriptThread {
reply,
)
},
+ WebDriverScriptCommand::FindElementTagName(selector, reply) => {
+ webdriver_handlers::handle_find_element_tag_name(
+ &*documents,
+ pipeline_id,
+ selector,
+ reply,
+ )
+ },
WebDriverScriptCommand::FindElementsCSS(selector, reply) => {
webdriver_handlers::handle_find_elements_css(
&*documents,
@@ -2027,6 +2035,14 @@ impl ScriptThread {
reply,
)
},
+ WebDriverScriptCommand::FindElementsTagName(selector, reply) => {
+ webdriver_handlers::handle_find_elements_tag_name(
+ &*documents,
+ pipeline_id,
+ selector,
+ reply,
+ )
+ },
WebDriverScriptCommand::FindElementElementCSS(selector, element_id, reply) => {
webdriver_handlers::handle_find_element_element_css(
&*documents,
@@ -2036,6 +2052,15 @@ impl ScriptThread {
reply,
)
},
+ WebDriverScriptCommand::FindElementElementTagName(selector, element_id, reply) => {
+ webdriver_handlers::handle_find_element_element_tag_name(
+ &*documents,
+ pipeline_id,
+ element_id,
+ selector,
+ reply,
+ )
+ },
WebDriverScriptCommand::FindElementElementsCSS(selector, element_id, reply) => {
webdriver_handlers::handle_find_element_elements_css(
&*documents,
@@ -2045,6 +2070,15 @@ impl ScriptThread {
reply,
)
},
+ WebDriverScriptCommand::FindElementElementsTagName(selector, element_id, reply) => {
+ webdriver_handlers::handle_find_element_elements_tag_name(
+ &*documents,
+ pipeline_id,
+ element_id,
+ selector,
+ reply,
+ )
+ },
WebDriverScriptCommand::FocusElement(element_id, reply) => {
webdriver_handlers::handle_focus_element(
&*documents,
diff --git a/components/script/webdriver_handlers.rs b/components/script/webdriver_handlers.rs
index 5574451bd5b..c960878f60d 100644
--- a/components/script/webdriver_handlers.rs
+++ b/components/script/webdriver_handlers.rs
@@ -182,6 +182,25 @@ pub fn handle_find_element_css(
reply.send(node_id).unwrap();
}
+pub fn handle_find_element_tag_name(
+ documents: &Documents,
+ pipeline: PipelineId,
+ selector: String,
+ reply: IpcSender<Result<Option<String>, ()>>,
+) {
+ let node_id = documents
+ .find_document(pipeline)
+ .ok_or(())
+ .and_then(|doc| {
+ Ok(doc
+ .GetElementsByTagName(DOMString::from(selector))
+ .elements_iter()
+ .next())
+ })
+ .map(|node| node.map(|x| x.upcast::<Node>().unique_id()));
+ reply.send(node_id).unwrap();
+}
+
pub fn handle_find_elements_css(
documents: &Documents,
pipeline: PipelineId,
@@ -204,6 +223,25 @@ pub fn handle_find_elements_css(
reply.send(node_ids).unwrap();
}
+pub fn handle_find_elements_tag_name(
+ documents: &Documents,
+ pipeline: PipelineId,
+ selector: String,
+ reply: IpcSender<Result<Vec<String>, ()>>,
+) {
+ let node_ids = documents
+ .find_document(pipeline)
+ .ok_or(())
+ .and_then(|doc| Ok(doc.GetElementsByTagName(DOMString::from(selector))))
+ .map(|nodes| {
+ nodes
+ .elements_iter()
+ .map(|x| x.upcast::<Node>().unique_id())
+ .collect::<Vec<String>>()
+ });
+ reply.send(node_ids).unwrap();
+}
+
pub fn handle_find_element_element_css(
documents: &Documents,
pipeline: PipelineId,
@@ -221,13 +259,33 @@ pub fn handle_find_element_element_css(
reply.send(node_id).unwrap();
}
-pub fn handle_find_element_elements_css(
+pub fn handle_find_element_element_tag_name(
documents: &Documents,
pipeline: PipelineId,
element_id: String,
selector: String,
reply: IpcSender<Result<Option<String>, ()>>,
) {
+ let node_id = find_node_by_unique_id(documents, pipeline, element_id)
+ .ok_or(())
+ .and_then(|node| match node.downcast::<Element>() {
+ Some(elem) => Ok(elem
+ .GetElementsByTagName(DOMString::from(selector))
+ .elements_iter()
+ .next()),
+ None => Err(()),
+ })
+ .map(|node| node.map(|x| x.upcast::<Node>().unique_id()));
+ reply.send(node_id).unwrap();
+}
+
+pub fn handle_find_element_elements_css(
+ documents: &Documents,
+ pipeline: PipelineId,
+ element_id: String,
+ selector: String,
+ reply: IpcSender<Result<Vec<String>, ()>>,
+) {
let node_ids = find_node_by_unique_id(documents, pipeline, element_id)
.ok_or(())
.and_then(|node| {
@@ -237,12 +295,34 @@ pub fn handle_find_element_elements_css(
.map(|nodes| {
nodes
.iter()
- .map(|x| Some(x.upcast::<Node>().unique_id()))
+ .map(|x| x.upcast::<Node>().unique_id())
.collect()
});
reply.send(node_ids).unwrap();
}
+pub fn handle_find_element_elements_tag_name(
+ documents: &Documents,
+ pipeline: PipelineId,
+ element_id: String,
+ selector: String,
+ reply: IpcSender<Result<Vec<String>, ()>>,
+) {
+ let node_ids = find_node_by_unique_id(documents, pipeline, element_id)
+ .ok_or(())
+ .and_then(|node| match node.downcast::<Element>() {
+ Some(elem) => Ok(elem.GetElementsByTagName(DOMString::from(selector))),
+ None => Err(()),
+ })
+ .map(|nodes| {
+ nodes
+ .elements_iter()
+ .map(|x| x.upcast::<Node>().unique_id())
+ .collect::<Vec<String>>()
+ });
+ reply.send(node_ids).unwrap();
+}
+
pub fn handle_focus_element(
documents: &Documents,
pipeline: PipelineId,