aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/webdriver_handlers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/webdriver_handlers.rs')
-rw-r--r--components/script/webdriver_handlers.rs84
1 files changed, 82 insertions, 2 deletions
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,