Auto merge of #23008 - georgeroman:implement_webdriver_find_elem_from_elem, r=Manishearth

Implement WebDriver FindElementFromElement command

<!-- 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

<!-- 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/23008)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2019-03-11 20:47:27 -04:00 committed by GitHub
commit 9513544e91
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 0 deletions

View file

@ -1859,6 +1859,15 @@ impl ScriptThread {
reply,
)
},
WebDriverScriptCommand::FindElementElementCSS(selector, element_id, reply) => {
webdriver_handlers::handle_find_element_element_css(
&*documents,
pipeline_id,
element_id,
selector,
reply,
)
},
WebDriverScriptCommand::FocusElement(element_id, reply) => {
webdriver_handlers::handle_focus_element(
&*documents,

View file

@ -203,6 +203,23 @@ pub fn handle_find_elements_css(
reply.send(node_ids).unwrap();
}
pub fn handle_find_element_element_css(
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| {
node.query_selector(DOMString::from(selector))
.map_err(|_| ())
})
.map(|node| node.map(|x| x.upcast::<Node>().unique_id()));
reply.send(node_id).unwrap();
}
pub fn handle_focus_element(
documents: &Documents,
pipeline: PipelineId,