mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Return ErrorStatus from webdriver_handlers
This commit is contained in:
parent
6a637ceffb
commit
d7b9fede99
12 changed files with 482 additions and 438 deletions
|
@ -1654,7 +1654,7 @@ impl Node {
|
||||||
|
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
fn new_(flags: NodeFlags, doc: Option<&Document>) -> Node {
|
fn new_(flags: NodeFlags, doc: Option<&Document>) -> Node {
|
||||||
Node {
|
let node = Node {
|
||||||
eventtarget: EventTarget::new_inherited(),
|
eventtarget: EventTarget::new_inherited(),
|
||||||
|
|
||||||
parent_node: Default::default(),
|
parent_node: Default::default(),
|
||||||
|
@ -1673,7 +1673,11 @@ impl Node {
|
||||||
style_and_layout_data: Cell::new(None),
|
style_and_layout_data: Cell::new(None),
|
||||||
|
|
||||||
unique_id: UniqueId::new(),
|
unique_id: UniqueId::new(),
|
||||||
}
|
};
|
||||||
|
|
||||||
|
ScriptThread::save_node_id(node.unique_id());
|
||||||
|
|
||||||
|
node
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#concept-node-adopt
|
// https://dom.spec.whatwg.org/#concept-node-adopt
|
||||||
|
|
|
@ -687,6 +687,9 @@ pub struct ScriptThread {
|
||||||
|
|
||||||
/// A mechanism to force the compositor's event loop to process events.
|
/// A mechanism to force the compositor's event loop to process events.
|
||||||
event_loop_waker: Option<Box<dyn EventLoopWaker>>,
|
event_loop_waker: Option<Box<dyn EventLoopWaker>>,
|
||||||
|
|
||||||
|
/// A set of all nodes ever created in this script thread
|
||||||
|
node_ids: DomRefCell<HashSet<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// In the event of thread panic, all data on the stack runs its destructor. However, there
|
/// In the event of thread panic, all data on the stack runs its destructor. However, there
|
||||||
|
@ -1183,6 +1186,25 @@ impl ScriptThread {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn save_node_id(node_id: String) {
|
||||||
|
SCRIPT_THREAD_ROOT.with(|root| {
|
||||||
|
if let Some(script_thread) = root.get() {
|
||||||
|
let script_thread = unsafe { &*script_thread };
|
||||||
|
script_thread.node_ids.borrow_mut().insert(node_id);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn has_node_id(node_id: &str) -> bool {
|
||||||
|
SCRIPT_THREAD_ROOT.with(|root| match root.get() {
|
||||||
|
Some(script_thread) => {
|
||||||
|
let script_thread = unsafe { &*script_thread };
|
||||||
|
script_thread.node_ids.borrow().contains(node_id)
|
||||||
|
},
|
||||||
|
None => false,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates a new script thread.
|
/// Creates a new script thread.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
state: InitialScriptState,
|
state: InitialScriptState,
|
||||||
|
@ -1315,6 +1337,8 @@ impl ScriptThread {
|
||||||
user_agent,
|
user_agent,
|
||||||
player_context: state.player_context,
|
player_context: state.player_context,
|
||||||
event_loop_waker: state.event_loop_waker,
|
event_loop_waker: state.event_loop_waker,
|
||||||
|
|
||||||
|
node_ids: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ use crate::dom::nodelist::NodeList;
|
||||||
use crate::dom::window::Window;
|
use crate::dom::window::Window;
|
||||||
use crate::dom::xmlserializer::XMLSerializer;
|
use crate::dom::xmlserializer::XMLSerializer;
|
||||||
use crate::script_runtime::JSContext as SafeJSContext;
|
use crate::script_runtime::JSContext as SafeJSContext;
|
||||||
use crate::script_thread::Documents;
|
use crate::script_thread::{Documents, ScriptThread};
|
||||||
use cookie::Cookie;
|
use cookie::Cookie;
|
||||||
use euclid::default::{Point2D, Rect, Size2D};
|
use euclid::default::{Point2D, Rect, Size2D};
|
||||||
use hyper_serde::Serde;
|
use hyper_serde::Serde;
|
||||||
|
@ -52,18 +52,28 @@ use script_traits::webdriver_msg::{
|
||||||
};
|
};
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
use webdriver::common::WebElement;
|
use webdriver::common::WebElement;
|
||||||
|
use webdriver::error::ErrorStatus;
|
||||||
|
|
||||||
fn find_node_by_unique_id(
|
fn find_node_by_unique_id(
|
||||||
documents: &Documents,
|
documents: &Documents,
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
node_id: String,
|
node_id: String,
|
||||||
) -> Option<DomRoot<Node>> {
|
) -> Result<DomRoot<Node>, ErrorStatus> {
|
||||||
documents.find_document(pipeline).and_then(|document| {
|
match documents.find_document(pipeline).and_then(|document| {
|
||||||
document
|
document
|
||||||
.upcast::<Node>()
|
.upcast::<Node>()
|
||||||
.traverse_preorder(ShadowIncluding::Yes)
|
.traverse_preorder(ShadowIncluding::Yes)
|
||||||
.find(|candidate| candidate.unique_id() == node_id)
|
.find(|node| node.unique_id() == node_id)
|
||||||
})
|
}) {
|
||||||
|
Some(node) => Ok(node),
|
||||||
|
None => {
|
||||||
|
if ScriptThread::has_node_id(&node_id) {
|
||||||
|
Err(ErrorStatus::StaleElementReference)
|
||||||
|
} else {
|
||||||
|
Err(ErrorStatus::NoSuchElement)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn matching_links<'a>(
|
fn matching_links<'a>(
|
||||||
|
@ -92,10 +102,10 @@ fn all_matching_links(
|
||||||
root_node: &Node,
|
root_node: &Node,
|
||||||
link_text: String,
|
link_text: String,
|
||||||
partial: bool,
|
partial: bool,
|
||||||
) -> Result<Vec<String>, ()> {
|
) -> Result<Vec<String>, ErrorStatus> {
|
||||||
root_node
|
root_node
|
||||||
.query_selector_all(DOMString::from("a"))
|
.query_selector_all(DOMString::from("a"))
|
||||||
.map_err(|_| ())
|
.map_err(|_| ErrorStatus::UnknownError)
|
||||||
.map(|nodes| matching_links(&nodes, link_text, partial).collect())
|
.map(|nodes| matching_links(&nodes, link_text, partial).collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,10 +113,10 @@ fn first_matching_link(
|
||||||
root_node: &Node,
|
root_node: &Node,
|
||||||
link_text: String,
|
link_text: String,
|
||||||
partial: bool,
|
partial: bool,
|
||||||
) -> Result<Option<String>, ()> {
|
) -> Result<Option<String>, ErrorStatus> {
|
||||||
root_node
|
root_node
|
||||||
.query_selector_all(DOMString::from("a"))
|
.query_selector_all(DOMString::from("a"))
|
||||||
.map_err(|_| ())
|
.map_err(|_| ErrorStatus::UnknownError)
|
||||||
.map(|nodes| matching_links(&nodes, link_text, partial).take(1).next())
|
.map(|nodes| matching_links(&nodes, link_text, partial).take(1).next())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,45 +253,53 @@ pub fn handle_get_browsing_context_id(
|
||||||
documents: &Documents,
|
documents: &Documents,
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
webdriver_frame_id: WebDriverFrameId,
|
webdriver_frame_id: WebDriverFrameId,
|
||||||
reply: IpcSender<Result<BrowsingContextId, ()>>,
|
reply: IpcSender<Result<BrowsingContextId, ErrorStatus>>,
|
||||||
) {
|
) {
|
||||||
let result = match webdriver_frame_id {
|
reply
|
||||||
WebDriverFrameId::Short(_) => {
|
.send(match webdriver_frame_id {
|
||||||
// This isn't supported yet
|
WebDriverFrameId::Short(_) => {
|
||||||
Err(())
|
// This isn't supported yet
|
||||||
},
|
Err(ErrorStatus::UnsupportedOperation)
|
||||||
WebDriverFrameId::Element(x) => find_node_by_unique_id(documents, pipeline, x)
|
},
|
||||||
.and_then(|node| {
|
WebDriverFrameId::Element(element_id) => {
|
||||||
node.downcast::<HTMLIFrameElement>()
|
find_node_by_unique_id(documents, pipeline, element_id).and_then(|node| {
|
||||||
.and_then(|elem| elem.browsing_context_id())
|
node.downcast::<HTMLIFrameElement>()
|
||||||
})
|
.and_then(|element| element.browsing_context_id())
|
||||||
.ok_or(()),
|
.ok_or(ErrorStatus::NoSuchFrame)
|
||||||
WebDriverFrameId::Parent => documents
|
})
|
||||||
.find_window(pipeline)
|
},
|
||||||
.and_then(|window| {
|
WebDriverFrameId::Parent => documents
|
||||||
window
|
.find_window(pipeline)
|
||||||
.window_proxy()
|
.and_then(|window| {
|
||||||
.parent()
|
window
|
||||||
.map(|parent| parent.browsing_context_id())
|
.window_proxy()
|
||||||
})
|
.parent()
|
||||||
.ok_or(()),
|
.map(|parent| parent.browsing_context_id())
|
||||||
};
|
})
|
||||||
|
.ok_or(ErrorStatus::NoSuchFrame),
|
||||||
reply.send(result).unwrap()
|
})
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_find_element_css(
|
pub fn handle_find_element_css(
|
||||||
documents: &Documents,
|
documents: &Documents,
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
selector: String,
|
selector: String,
|
||||||
reply: IpcSender<Result<Option<String>, ()>>,
|
reply: IpcSender<Result<Option<String>, ErrorStatus>>,
|
||||||
) {
|
) {
|
||||||
let node_id = documents
|
reply
|
||||||
.find_document(pipeline)
|
.send(
|
||||||
.ok_or(())
|
documents
|
||||||
.and_then(|doc| doc.QuerySelector(DOMString::from(selector)).map_err(|_| ()))
|
.find_document(pipeline)
|
||||||
.map(|node| node.map(|x| x.upcast::<Node>().unique_id()));
|
.ok_or(ErrorStatus::UnknownError)
|
||||||
reply.send(node_id).unwrap();
|
.and_then(|document| {
|
||||||
|
document
|
||||||
|
.QuerySelector(DOMString::from(selector))
|
||||||
|
.map_err(|_| ErrorStatus::InvalidSelector)
|
||||||
|
})
|
||||||
|
.map(|node| node.map(|x| x.upcast::<Node>().unique_id())),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_find_element_link_text(
|
pub fn handle_find_element_link_text(
|
||||||
|
@ -289,54 +307,66 @@ pub fn handle_find_element_link_text(
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
selector: String,
|
selector: String,
|
||||||
partial: bool,
|
partial: bool,
|
||||||
reply: IpcSender<Result<Option<String>, ()>>,
|
reply: IpcSender<Result<Option<String>, ErrorStatus>>,
|
||||||
) {
|
) {
|
||||||
let node_id = documents
|
reply
|
||||||
.find_document(pipeline)
|
.send(
|
||||||
.ok_or(())
|
documents
|
||||||
.and_then(|doc| first_matching_link(&doc.upcast::<Node>(), selector.clone(), partial));
|
.find_document(pipeline)
|
||||||
reply.send(node_id).unwrap();
|
.ok_or(ErrorStatus::UnknownError)
|
||||||
|
.and_then(|document| {
|
||||||
|
first_matching_link(&document.upcast::<Node>(), selector.clone(), partial)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_find_element_tag_name(
|
pub fn handle_find_element_tag_name(
|
||||||
documents: &Documents,
|
documents: &Documents,
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
selector: String,
|
selector: String,
|
||||||
reply: IpcSender<Result<Option<String>, ()>>,
|
reply: IpcSender<Result<Option<String>, ErrorStatus>>,
|
||||||
) {
|
) {
|
||||||
let node_id = documents
|
reply
|
||||||
.find_document(pipeline)
|
.send(
|
||||||
.ok_or(())
|
documents
|
||||||
.and_then(|doc| {
|
.find_document(pipeline)
|
||||||
Ok(doc
|
.ok_or(ErrorStatus::UnknownError)
|
||||||
.GetElementsByTagName(DOMString::from(selector))
|
.and_then(|document| {
|
||||||
.elements_iter()
|
Ok(document
|
||||||
.next())
|
.GetElementsByTagName(DOMString::from(selector))
|
||||||
})
|
.elements_iter()
|
||||||
.map(|node| node.map(|x| x.upcast::<Node>().unique_id()));
|
.next())
|
||||||
reply.send(node_id).unwrap();
|
})
|
||||||
|
.map(|node| node.map(|x| x.upcast::<Node>().unique_id())),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_find_elements_css(
|
pub fn handle_find_elements_css(
|
||||||
documents: &Documents,
|
documents: &Documents,
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
selector: String,
|
selector: String,
|
||||||
reply: IpcSender<Result<Vec<String>, ()>>,
|
reply: IpcSender<Result<Vec<String>, ErrorStatus>>,
|
||||||
) {
|
) {
|
||||||
let node_ids = documents
|
reply
|
||||||
.find_document(pipeline)
|
.send(
|
||||||
.ok_or(())
|
documents
|
||||||
.and_then(|doc| {
|
.find_document(pipeline)
|
||||||
doc.QuerySelectorAll(DOMString::from(selector))
|
.ok_or(ErrorStatus::UnknownError)
|
||||||
.map_err(|_| ())
|
.and_then(|document| {
|
||||||
})
|
document
|
||||||
.map(|nodes| {
|
.QuerySelectorAll(DOMString::from(selector))
|
||||||
nodes
|
.map_err(|_| ErrorStatus::InvalidSelector)
|
||||||
.iter()
|
})
|
||||||
.map(|x| x.upcast::<Node>().unique_id())
|
.map(|nodes| {
|
||||||
.collect()
|
nodes
|
||||||
});
|
.iter()
|
||||||
reply.send(node_ids).unwrap();
|
.map(|x| x.upcast::<Node>().unique_id())
|
||||||
|
.collect()
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_find_elements_link_text(
|
pub fn handle_find_elements_link_text(
|
||||||
|
@ -344,32 +374,40 @@ pub fn handle_find_elements_link_text(
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
selector: String,
|
selector: String,
|
||||||
partial: bool,
|
partial: bool,
|
||||||
reply: IpcSender<Result<Vec<String>, ()>>,
|
reply: IpcSender<Result<Vec<String>, ErrorStatus>>,
|
||||||
) {
|
) {
|
||||||
let node_ids = documents
|
reply
|
||||||
.find_document(pipeline)
|
.send(
|
||||||
.ok_or(())
|
documents
|
||||||
.and_then(|doc| all_matching_links(&doc.upcast::<Node>(), selector.clone(), partial));
|
.find_document(pipeline)
|
||||||
reply.send(node_ids).unwrap();
|
.ok_or(ErrorStatus::UnknownError)
|
||||||
|
.and_then(|document| {
|
||||||
|
all_matching_links(&document.upcast::<Node>(), selector.clone(), partial)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_find_elements_tag_name(
|
pub fn handle_find_elements_tag_name(
|
||||||
documents: &Documents,
|
documents: &Documents,
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
selector: String,
|
selector: String,
|
||||||
reply: IpcSender<Result<Vec<String>, ()>>,
|
reply: IpcSender<Result<Vec<String>, ErrorStatus>>,
|
||||||
) {
|
) {
|
||||||
let node_ids = documents
|
reply
|
||||||
.find_document(pipeline)
|
.send(
|
||||||
.ok_or(())
|
documents
|
||||||
.and_then(|doc| Ok(doc.GetElementsByTagName(DOMString::from(selector))))
|
.find_document(pipeline)
|
||||||
.map(|nodes| {
|
.ok_or(ErrorStatus::UnknownError)
|
||||||
nodes
|
.and_then(|document| Ok(document.GetElementsByTagName(DOMString::from(selector))))
|
||||||
.elements_iter()
|
.map(|nodes| {
|
||||||
.map(|x| x.upcast::<Node>().unique_id())
|
nodes
|
||||||
.collect::<Vec<String>>()
|
.elements_iter()
|
||||||
});
|
.map(|x| x.upcast::<Node>().unique_id())
|
||||||
reply.send(node_ids).unwrap();
|
.collect::<Vec<String>>()
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_find_element_element_css(
|
pub fn handle_find_element_element_css(
|
||||||
|
@ -377,16 +415,17 @@ pub fn handle_find_element_element_css(
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
element_id: String,
|
element_id: String,
|
||||||
selector: String,
|
selector: String,
|
||||||
reply: IpcSender<Result<Option<String>, ()>>,
|
reply: IpcSender<Result<Option<String>, ErrorStatus>>,
|
||||||
) {
|
) {
|
||||||
let node_id = find_node_by_unique_id(documents, pipeline, element_id)
|
reply
|
||||||
.ok_or(())
|
.send(
|
||||||
.and_then(|node| {
|
find_node_by_unique_id(documents, pipeline, element_id).and_then(|node| {
|
||||||
node.query_selector(DOMString::from(selector))
|
node.query_selector(DOMString::from(selector))
|
||||||
.map_err(|_| ())
|
.map_err(|_| ErrorStatus::InvalidSelector)
|
||||||
})
|
.map(|node| node.map(|x| x.upcast::<Node>().unique_id()))
|
||||||
.map(|node| node.map(|x| x.upcast::<Node>().unique_id()));
|
}),
|
||||||
reply.send(node_id).unwrap();
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_find_element_element_link_text(
|
pub fn handle_find_element_element_link_text(
|
||||||
|
@ -395,12 +434,14 @@ pub fn handle_find_element_element_link_text(
|
||||||
element_id: String,
|
element_id: String,
|
||||||
selector: String,
|
selector: String,
|
||||||
partial: bool,
|
partial: bool,
|
||||||
reply: IpcSender<Result<Option<String>, ()>>,
|
reply: IpcSender<Result<Option<String>, ErrorStatus>>,
|
||||||
) {
|
) {
|
||||||
let node_id = find_node_by_unique_id(documents, pipeline, element_id)
|
reply
|
||||||
.ok_or(())
|
.send(
|
||||||
.and_then(|node| first_matching_link(&node, selector.clone(), partial));
|
find_node_by_unique_id(documents, pipeline, element_id)
|
||||||
reply.send(node_id).unwrap();
|
.and_then(|node| first_matching_link(&node, selector.clone(), partial)),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_find_element_element_tag_name(
|
pub fn handle_find_element_element_tag_name(
|
||||||
|
@ -408,19 +449,22 @@ pub fn handle_find_element_element_tag_name(
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
element_id: String,
|
element_id: String,
|
||||||
selector: String,
|
selector: String,
|
||||||
reply: IpcSender<Result<Option<String>, ()>>,
|
reply: IpcSender<Result<Option<String>, ErrorStatus>>,
|
||||||
) {
|
) {
|
||||||
let node_id = find_node_by_unique_id(documents, pipeline, element_id)
|
reply
|
||||||
.ok_or(())
|
.send(
|
||||||
.and_then(|node| match node.downcast::<Element>() {
|
find_node_by_unique_id(documents, pipeline, element_id).and_then(|node| match node
|
||||||
Some(elem) => Ok(elem
|
.downcast::<Element>(
|
||||||
.GetElementsByTagName(DOMString::from(selector))
|
) {
|
||||||
.elements_iter()
|
Some(element) => Ok(element
|
||||||
.next()),
|
.GetElementsByTagName(DOMString::from(selector))
|
||||||
None => Err(()),
|
.elements_iter()
|
||||||
})
|
.next()
|
||||||
.map(|node| node.map(|x| x.upcast::<Node>().unique_id()));
|
.map(|x| x.upcast::<Node>().unique_id())),
|
||||||
reply.send(node_id).unwrap();
|
None => Err(ErrorStatus::UnknownError),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_find_element_elements_css(
|
pub fn handle_find_element_elements_css(
|
||||||
|
@ -428,21 +472,22 @@ pub fn handle_find_element_elements_css(
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
element_id: String,
|
element_id: String,
|
||||||
selector: String,
|
selector: String,
|
||||||
reply: IpcSender<Result<Vec<String>, ()>>,
|
reply: IpcSender<Result<Vec<String>, ErrorStatus>>,
|
||||||
) {
|
) {
|
||||||
let node_ids = find_node_by_unique_id(documents, pipeline, element_id)
|
reply
|
||||||
.ok_or(())
|
.send(
|
||||||
.and_then(|node| {
|
find_node_by_unique_id(documents, pipeline, element_id).and_then(|node| {
|
||||||
node.query_selector_all(DOMString::from(selector))
|
node.query_selector_all(DOMString::from(selector))
|
||||||
.map_err(|_| ())
|
.map_err(|_| ErrorStatus::InvalidSelector)
|
||||||
})
|
.map(|nodes| {
|
||||||
.map(|nodes| {
|
nodes
|
||||||
nodes
|
.iter()
|
||||||
.iter()
|
.map(|x| x.upcast::<Node>().unique_id())
|
||||||
.map(|x| x.upcast::<Node>().unique_id())
|
.collect()
|
||||||
.collect()
|
})
|
||||||
});
|
}),
|
||||||
reply.send(node_ids).unwrap();
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_find_element_elements_link_text(
|
pub fn handle_find_element_elements_link_text(
|
||||||
|
@ -451,12 +496,14 @@ pub fn handle_find_element_elements_link_text(
|
||||||
element_id: String,
|
element_id: String,
|
||||||
selector: String,
|
selector: String,
|
||||||
partial: bool,
|
partial: bool,
|
||||||
reply: IpcSender<Result<Vec<String>, ()>>,
|
reply: IpcSender<Result<Vec<String>, ErrorStatus>>,
|
||||||
) {
|
) {
|
||||||
let node_ids = find_node_by_unique_id(documents, pipeline, element_id)
|
reply
|
||||||
.ok_or(())
|
.send(
|
||||||
.and_then(|node| all_matching_links(&node, selector.clone(), partial));
|
find_node_by_unique_id(documents, pipeline, element_id)
|
||||||
reply.send(node_ids).unwrap();
|
.and_then(|node| all_matching_links(&node, selector.clone(), partial)),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_find_element_elements_tag_name(
|
pub fn handle_find_element_elements_tag_name(
|
||||||
|
@ -464,44 +511,42 @@ pub fn handle_find_element_elements_tag_name(
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
element_id: String,
|
element_id: String,
|
||||||
selector: String,
|
selector: String,
|
||||||
reply: IpcSender<Result<Vec<String>, ()>>,
|
reply: IpcSender<Result<Vec<String>, ErrorStatus>>,
|
||||||
) {
|
) {
|
||||||
let node_ids = find_node_by_unique_id(documents, pipeline, element_id)
|
reply
|
||||||
.ok_or(())
|
.send(
|
||||||
.and_then(|node| match node.downcast::<Element>() {
|
find_node_by_unique_id(documents, pipeline, element_id).and_then(|node| match node
|
||||||
Some(elem) => Ok(elem.GetElementsByTagName(DOMString::from(selector))),
|
.downcast::<Element>(
|
||||||
None => Err(()),
|
) {
|
||||||
})
|
Some(element) => Ok(element
|
||||||
.map(|nodes| {
|
.GetElementsByTagName(DOMString::from(selector))
|
||||||
nodes
|
.elements_iter()
|
||||||
.elements_iter()
|
.map(|x| x.upcast::<Node>().unique_id())
|
||||||
.map(|x| x.upcast::<Node>().unique_id())
|
.collect::<Vec<String>>()),
|
||||||
.collect::<Vec<String>>()
|
None => Err(ErrorStatus::UnknownError),
|
||||||
});
|
}),
|
||||||
reply.send(node_ids).unwrap();
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_focus_element(
|
pub fn handle_focus_element(
|
||||||
documents: &Documents,
|
documents: &Documents,
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
element_id: String,
|
element_id: String,
|
||||||
reply: IpcSender<Result<(), ()>>,
|
reply: IpcSender<Result<(), ErrorStatus>>,
|
||||||
) {
|
) {
|
||||||
reply
|
reply
|
||||||
.send(
|
.send(
|
||||||
match find_node_by_unique_id(documents, pipeline, element_id) {
|
find_node_by_unique_id(documents, pipeline, element_id).and_then(|node| {
|
||||||
Some(ref node) => {
|
match node.downcast::<HTMLElement>() {
|
||||||
match node.downcast::<HTMLElement>() {
|
Some(element) => {
|
||||||
Some(ref elem) => {
|
// Need a way to find if this actually succeeded
|
||||||
// Need a way to find if this actually succeeded
|
element.Focus();
|
||||||
elem.Focus();
|
Ok(())
|
||||||
Ok(())
|
},
|
||||||
},
|
None => Err(ErrorStatus::UnknownError),
|
||||||
None => Err(()),
|
}
|
||||||
}
|
}),
|
||||||
},
|
|
||||||
None => Err(()),
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
@ -515,8 +560,8 @@ pub fn handle_get_active_element(
|
||||||
.send(
|
.send(
|
||||||
documents
|
documents
|
||||||
.find_document(pipeline)
|
.find_document(pipeline)
|
||||||
.and_then(|doc| doc.GetActiveElement())
|
.and_then(|document| document.GetActiveElement())
|
||||||
.map(|elem| elem.upcast::<Node>().unique_id()),
|
.map(|element| element.upcast::<Node>().unique_id()),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
@ -524,25 +569,28 @@ pub fn handle_get_active_element(
|
||||||
pub fn handle_get_page_source(
|
pub fn handle_get_page_source(
|
||||||
documents: &Documents,
|
documents: &Documents,
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
reply: IpcSender<Result<String, ()>>,
|
reply: IpcSender<Result<String, ErrorStatus>>,
|
||||||
) {
|
) {
|
||||||
reply
|
reply
|
||||||
.send(documents.find_document(pipeline).ok_or(()).and_then(|doc| {
|
.send(
|
||||||
match doc.GetDocumentElement() {
|
documents
|
||||||
Some(elem) => match elem.GetOuterHTML() {
|
.find_document(pipeline)
|
||||||
Ok(source) => Ok(source.to_string()),
|
.ok_or(ErrorStatus::UnknownError)
|
||||||
Err(_) => {
|
.and_then(|document| match document.GetDocumentElement() {
|
||||||
match XMLSerializer::new(doc.window())
|
Some(element) => match element.GetOuterHTML() {
|
||||||
.SerializeToString(elem.upcast::<Node>())
|
Ok(source) => Ok(source.to_string()),
|
||||||
{
|
Err(_) => {
|
||||||
Ok(source) => Ok(source.to_string()),
|
match XMLSerializer::new(document.window())
|
||||||
Err(_) => Err(()),
|
.SerializeToString(element.upcast::<Node>())
|
||||||
}
|
{
|
||||||
|
Ok(source) => Ok(source.to_string()),
|
||||||
|
Err(_) => Err(ErrorStatus::UnknownError),
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
None => Err(ErrorStatus::UnknownError),
|
||||||
None => Err(()),
|
}),
|
||||||
}
|
)
|
||||||
}))
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -551,21 +599,24 @@ pub fn handle_get_cookies(
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
reply: IpcSender<Vec<Serde<Cookie<'static>>>>,
|
reply: IpcSender<Vec<Serde<Cookie<'static>>>>,
|
||||||
) {
|
) {
|
||||||
// TODO: Return an error if the pipeline doesn't exist?
|
reply
|
||||||
let cookies = match documents.find_document(pipeline) {
|
.send(
|
||||||
None => Vec::new(),
|
// TODO: Return an error if the pipeline doesn't exist
|
||||||
Some(document) => {
|
match documents.find_document(pipeline) {
|
||||||
let url = document.url();
|
Some(document) => {
|
||||||
let (sender, receiver) = ipc::channel().unwrap();
|
let url = document.url();
|
||||||
let _ = document
|
let (sender, receiver) = ipc::channel().unwrap();
|
||||||
.window()
|
let _ = document
|
||||||
.upcast::<GlobalScope>()
|
.window()
|
||||||
.resource_threads()
|
.upcast::<GlobalScope>()
|
||||||
.send(GetCookiesDataForUrl(url, sender, NonHTTP));
|
.resource_threads()
|
||||||
receiver.recv().unwrap()
|
.send(GetCookiesDataForUrl(url, sender, NonHTTP));
|
||||||
},
|
receiver.recv().unwrap()
|
||||||
};
|
},
|
||||||
reply.send(cookies).unwrap();
|
None => Vec::new(),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://w3c.github.io/webdriver/webdriver-spec.html#get-cookie
|
// https://w3c.github.io/webdriver/webdriver-spec.html#get-cookie
|
||||||
|
@ -575,22 +626,27 @@ pub fn handle_get_cookie(
|
||||||
name: String,
|
name: String,
|
||||||
reply: IpcSender<Vec<Serde<Cookie<'static>>>>,
|
reply: IpcSender<Vec<Serde<Cookie<'static>>>>,
|
||||||
) {
|
) {
|
||||||
// TODO: Return an error if the pipeline doesn't exist?
|
|
||||||
let cookies = match documents.find_document(pipeline) {
|
|
||||||
None => Vec::new(),
|
|
||||||
Some(document) => {
|
|
||||||
let url = document.url();
|
|
||||||
let (sender, receiver) = ipc::channel().unwrap();
|
|
||||||
let _ = document
|
|
||||||
.window()
|
|
||||||
.upcast::<GlobalScope>()
|
|
||||||
.resource_threads()
|
|
||||||
.send(GetCookiesDataForUrl(url, sender, NonHTTP));
|
|
||||||
receiver.recv().unwrap()
|
|
||||||
},
|
|
||||||
};
|
|
||||||
reply
|
reply
|
||||||
.send(cookies.into_iter().filter(|c| c.name() == &*name).collect())
|
.send(
|
||||||
|
// TODO: Return an error if the pipeline doesn't exist
|
||||||
|
match documents.find_document(pipeline) {
|
||||||
|
Some(document) => {
|
||||||
|
let url = document.url();
|
||||||
|
let (sender, receiver) = ipc::channel().unwrap();
|
||||||
|
let _ = document
|
||||||
|
.window()
|
||||||
|
.upcast::<GlobalScope>()
|
||||||
|
.resource_threads()
|
||||||
|
.send(GetCookiesDataForUrl(url, sender, NonHTTP));
|
||||||
|
let cookies = receiver.recv().unwrap();
|
||||||
|
cookies
|
||||||
|
.into_iter()
|
||||||
|
.filter(|cookie| cookie.name() == &*name)
|
||||||
|
.collect()
|
||||||
|
},
|
||||||
|
None => Vec::new(),
|
||||||
|
},
|
||||||
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -601,7 +657,7 @@ pub fn handle_add_cookie(
|
||||||
cookie: Cookie<'static>,
|
cookie: Cookie<'static>,
|
||||||
reply: IpcSender<Result<(), WebDriverCookieError>>,
|
reply: IpcSender<Result<(), WebDriverCookieError>>,
|
||||||
) {
|
) {
|
||||||
// TODO: Return a different error if the pipeline doesn't exist?
|
// TODO: Return a different error if the pipeline doesn't exist
|
||||||
let document = match documents.find_document(pipeline) {
|
let document = match documents.find_document(pipeline) {
|
||||||
Some(document) => document,
|
Some(document) => document,
|
||||||
None => {
|
None => {
|
||||||
|
@ -645,12 +701,12 @@ pub fn handle_add_cookie(
|
||||||
pub fn handle_delete_cookies(
|
pub fn handle_delete_cookies(
|
||||||
documents: &Documents,
|
documents: &Documents,
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
reply: IpcSender<Result<(), ()>>,
|
reply: IpcSender<Result<(), ErrorStatus>>,
|
||||||
) {
|
) {
|
||||||
let document = match documents.find_document(pipeline) {
|
let document = match documents.find_document(pipeline) {
|
||||||
Some(document) => document,
|
Some(document) => document,
|
||||||
None => {
|
None => {
|
||||||
return reply.send(Err(())).unwrap();
|
return reply.send(Err(ErrorStatus::UnknownError)).unwrap();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let url = document.url();
|
let url = document.url();
|
||||||
|
@ -660,62 +716,62 @@ pub fn handle_delete_cookies(
|
||||||
.resource_threads()
|
.resource_threads()
|
||||||
.send(DeleteCookies(url))
|
.send(DeleteCookies(url))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let _ = reply.send(Ok(()));
|
reply.send(Ok(())).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_get_title(documents: &Documents, pipeline: PipelineId, reply: IpcSender<String>) {
|
pub fn handle_get_title(documents: &Documents, pipeline: PipelineId, reply: IpcSender<String>) {
|
||||||
// TODO: Return an error if the pipeline doesn't exist.
|
reply
|
||||||
let title = documents
|
.send(
|
||||||
.find_document(pipeline)
|
// TODO: Return an error if the pipeline doesn't exist
|
||||||
.map(|doc| String::from(doc.Title()))
|
documents
|
||||||
.unwrap_or_default();
|
.find_document(pipeline)
|
||||||
reply.send(title).unwrap();
|
.map(|document| String::from(document.Title()))
|
||||||
|
.unwrap_or_default(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_get_rect(
|
pub fn handle_get_rect(
|
||||||
documents: &Documents,
|
documents: &Documents,
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
element_id: String,
|
element_id: String,
|
||||||
reply: IpcSender<Result<Rect<f64>, ()>>,
|
reply: IpcSender<Result<Rect<f64>, ErrorStatus>>,
|
||||||
) {
|
) {
|
||||||
reply
|
reply
|
||||||
.send(
|
.send(
|
||||||
match find_node_by_unique_id(documents, pipeline, element_id) {
|
find_node_by_unique_id(documents, pipeline, element_id).and_then(|node| {
|
||||||
Some(elem) => {
|
// https://w3c.github.io/webdriver/webdriver-spec.html#dfn-calculate-the-absolute-position
|
||||||
// https://w3c.github.io/webdriver/webdriver-spec.html#dfn-calculate-the-absolute-position
|
match node.downcast::<HTMLElement>() {
|
||||||
match elem.downcast::<HTMLElement>() {
|
Some(html_element) => {
|
||||||
Some(html_elem) => {
|
// Step 1
|
||||||
// Step 1
|
let mut x = 0;
|
||||||
let mut x = 0;
|
let mut y = 0;
|
||||||
let mut y = 0;
|
|
||||||
|
|
||||||
let mut offset_parent = html_elem.GetOffsetParent();
|
let mut offset_parent = html_element.GetOffsetParent();
|
||||||
|
|
||||||
// Step 2
|
// Step 2
|
||||||
while let Some(element) = offset_parent {
|
while let Some(element) = offset_parent {
|
||||||
offset_parent = match element.downcast::<HTMLElement>() {
|
offset_parent = match element.downcast::<HTMLElement>() {
|
||||||
Some(elem) => {
|
Some(elem) => {
|
||||||
x += elem.OffsetLeft();
|
x += elem.OffsetLeft();
|
||||||
y += elem.OffsetTop();
|
y += elem.OffsetTop();
|
||||||
elem.GetOffsetParent()
|
elem.GetOffsetParent()
|
||||||
},
|
},
|
||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// Step 3
|
// Step 3
|
||||||
Ok(Rect::new(
|
Ok(Rect::new(
|
||||||
Point2D::new(x as f64, y as f64),
|
Point2D::new(x as f64, y as f64),
|
||||||
Size2D::new(
|
Size2D::new(
|
||||||
html_elem.OffsetWidth() as f64,
|
html_element.OffsetWidth() as f64,
|
||||||
html_elem.OffsetHeight() as f64,
|
html_element.OffsetHeight() as f64,
|
||||||
),
|
),
|
||||||
))
|
))
|
||||||
},
|
},
|
||||||
None => Err(()),
|
None => Err(ErrorStatus::UnknownError),
|
||||||
}
|
}
|
||||||
},
|
}),
|
||||||
None => Err(()),
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
@ -724,13 +780,13 @@ pub fn handle_get_text(
|
||||||
documents: &Documents,
|
documents: &Documents,
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
node_id: String,
|
node_id: String,
|
||||||
reply: IpcSender<Result<String, ()>>,
|
reply: IpcSender<Result<String, ErrorStatus>>,
|
||||||
) {
|
) {
|
||||||
reply
|
reply
|
||||||
.send(match find_node_by_unique_id(documents, pipeline, node_id) {
|
.send(
|
||||||
Some(ref node) => Ok(node.GetTextContent().map_or("".to_owned(), String::from)),
|
find_node_by_unique_id(documents, pipeline, node_id)
|
||||||
None => Err(()),
|
.and_then(|node| Ok(node.GetTextContent().map_or("".to_owned(), String::from))),
|
||||||
})
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -738,13 +794,13 @@ pub fn handle_get_name(
|
||||||
documents: &Documents,
|
documents: &Documents,
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
node_id: String,
|
node_id: String,
|
||||||
reply: IpcSender<Result<String, ()>>,
|
reply: IpcSender<Result<String, ErrorStatus>>,
|
||||||
) {
|
) {
|
||||||
reply
|
reply
|
||||||
.send(match find_node_by_unique_id(documents, pipeline, node_id) {
|
.send(
|
||||||
Some(node) => Ok(String::from(node.downcast::<Element>().unwrap().TagName())),
|
find_node_by_unique_id(documents, pipeline, node_id)
|
||||||
None => Err(()),
|
.and_then(|node| Ok(String::from(node.downcast::<Element>().unwrap().TagName()))),
|
||||||
})
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -753,17 +809,18 @@ pub fn handle_get_attribute(
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
node_id: String,
|
node_id: String,
|
||||||
name: String,
|
name: String,
|
||||||
reply: IpcSender<Result<Option<String>, ()>>,
|
reply: IpcSender<Result<Option<String>, ErrorStatus>>,
|
||||||
) {
|
) {
|
||||||
reply
|
reply
|
||||||
.send(match find_node_by_unique_id(documents, pipeline, node_id) {
|
.send(
|
||||||
Some(node) => Ok(node
|
find_node_by_unique_id(documents, pipeline, node_id).and_then(|node| {
|
||||||
.downcast::<Element>()
|
Ok(node
|
||||||
.unwrap()
|
.downcast::<Element>()
|
||||||
.GetAttribute(DOMString::from(name))
|
.unwrap()
|
||||||
.map(String::from)),
|
.GetAttribute(DOMString::from(name))
|
||||||
None => Err(()),
|
.map(String::from))
|
||||||
})
|
}),
|
||||||
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -773,11 +830,11 @@ pub fn handle_get_property(
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
node_id: String,
|
node_id: String,
|
||||||
name: String,
|
name: String,
|
||||||
reply: IpcSender<Result<WebDriverJSValue, ()>>,
|
reply: IpcSender<Result<WebDriverJSValue, ErrorStatus>>,
|
||||||
) {
|
) {
|
||||||
reply
|
reply
|
||||||
.send(match find_node_by_unique_id(documents, pipeline, node_id) {
|
.send(
|
||||||
Some(node) => {
|
find_node_by_unique_id(documents, pipeline, node_id).and_then(|node| {
|
||||||
let cx = documents.find_document(pipeline).unwrap().window().get_cx();
|
let cx = documents.find_document(pipeline).unwrap().window().get_cx();
|
||||||
|
|
||||||
rooted!(in(*cx) let mut property = UndefinedValue());
|
rooted!(in(*cx) let mut property = UndefinedValue());
|
||||||
|
@ -800,9 +857,8 @@ pub fn handle_get_property(
|
||||||
Ok(WebDriverJSValue::Undefined)
|
Ok(WebDriverJSValue::Undefined)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
}),
|
||||||
None => Err(()),
|
)
|
||||||
})
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -811,48 +867,49 @@ pub fn handle_get_css(
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
node_id: String,
|
node_id: String,
|
||||||
name: String,
|
name: String,
|
||||||
reply: IpcSender<Result<String, ()>>,
|
reply: IpcSender<Result<String, ErrorStatus>>,
|
||||||
) {
|
) {
|
||||||
reply
|
reply
|
||||||
.send(match find_node_by_unique_id(documents, pipeline, node_id) {
|
.send(
|
||||||
Some(node) => {
|
find_node_by_unique_id(documents, pipeline, node_id).and_then(|node| {
|
||||||
let window = window_from_node(&*node);
|
let window = window_from_node(&*node);
|
||||||
let elem = node.downcast::<Element>().unwrap();
|
let element = node.downcast::<Element>().unwrap();
|
||||||
Ok(String::from(
|
Ok(String::from(
|
||||||
window
|
window
|
||||||
.GetComputedStyle(&elem, None)
|
.GetComputedStyle(&element, None)
|
||||||
.GetPropertyValue(DOMString::from(name)),
|
.GetPropertyValue(DOMString::from(name)),
|
||||||
))
|
))
|
||||||
},
|
}),
|
||||||
None => Err(()),
|
)
|
||||||
})
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_get_url(documents: &Documents, pipeline: PipelineId, reply: IpcSender<ServoUrl>) {
|
pub fn handle_get_url(documents: &Documents, pipeline: PipelineId, reply: IpcSender<ServoUrl>) {
|
||||||
// TODO: Return an error if the pipeline doesn't exist.
|
reply
|
||||||
let url = documents
|
.send(
|
||||||
.find_document(pipeline)
|
// TODO: Return an error if the pipeline doesn't exist.
|
||||||
.map(|document| document.url())
|
documents
|
||||||
.unwrap_or_else(|| ServoUrl::parse("about:blank").expect("infallible"));
|
.find_document(pipeline)
|
||||||
reply.send(url).unwrap();
|
.map(|document| document.url())
|
||||||
|
.unwrap_or_else(|| ServoUrl::parse("about:blank").expect("infallible")),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_is_enabled(
|
pub fn handle_is_enabled(
|
||||||
documents: &Documents,
|
documents: &Documents,
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
element_id: String,
|
element_id: String,
|
||||||
reply: IpcSender<Result<bool, ()>>,
|
reply: IpcSender<Result<bool, ErrorStatus>>,
|
||||||
) {
|
) {
|
||||||
reply
|
reply
|
||||||
.send(
|
.send(
|
||||||
match find_node_by_unique_id(&documents, pipeline, element_id) {
|
find_node_by_unique_id(&documents, pipeline, element_id).and_then(|node| match node
|
||||||
Some(ref node) => match node.downcast::<Element>() {
|
.downcast::<Element>(
|
||||||
Some(elem) => Ok(elem.enabled_state()),
|
) {
|
||||||
None => Err(()),
|
Some(element) => Ok(element.enabled_state()),
|
||||||
},
|
None => Err(ErrorStatus::UnknownError),
|
||||||
None => Err(()),
|
}),
|
||||||
},
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
@ -861,24 +918,21 @@ pub fn handle_is_selected(
|
||||||
documents: &Documents,
|
documents: &Documents,
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
element_id: String,
|
element_id: String,
|
||||||
reply: IpcSender<Result<bool, ()>>,
|
reply: IpcSender<Result<bool, ErrorStatus>>,
|
||||||
) {
|
) {
|
||||||
reply
|
reply
|
||||||
.send(
|
.send(
|
||||||
match find_node_by_unique_id(documents, pipeline, element_id) {
|
find_node_by_unique_id(documents, pipeline, element_id).and_then(|node| {
|
||||||
Some(ref node) => {
|
if let Some(input_element) = node.downcast::<HTMLInputElement>() {
|
||||||
if let Some(input_element) = node.downcast::<HTMLInputElement>() {
|
Ok(input_element.Checked())
|
||||||
Ok(input_element.Checked())
|
} else if let Some(option_element) = node.downcast::<HTMLOptionElement>() {
|
||||||
} else if let Some(option_element) = node.downcast::<HTMLOptionElement>() {
|
Ok(option_element.Selected())
|
||||||
Ok(option_element.Selected())
|
} else if node.is::<HTMLElement>() {
|
||||||
} else if node.is::<HTMLElement>() {
|
Ok(false) // regular elements are not selectable
|
||||||
Ok(false) // regular elements are not selectable
|
} else {
|
||||||
} else {
|
Err(ErrorStatus::UnknownError)
|
||||||
Err(())
|
}
|
||||||
}
|
}),
|
||||||
},
|
|
||||||
None => Err(()),
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ use ipc_channel::ipc::IpcSender;
|
||||||
use msg::constellation_msg::BrowsingContextId;
|
use msg::constellation_msg::BrowsingContextId;
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
use webdriver::common::WebElement;
|
use webdriver::common::WebElement;
|
||||||
|
use webdriver::error::ErrorStatus;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
pub enum WebDriverScriptCommand {
|
pub enum WebDriverScriptCommand {
|
||||||
|
@ -22,36 +23,65 @@ pub enum WebDriverScriptCommand {
|
||||||
Cookie<'static>,
|
Cookie<'static>,
|
||||||
IpcSender<Result<(), WebDriverCookieError>>,
|
IpcSender<Result<(), WebDriverCookieError>>,
|
||||||
),
|
),
|
||||||
DeleteCookies(IpcSender<Result<(), ()>>),
|
DeleteCookies(IpcSender<Result<(), ErrorStatus>>),
|
||||||
ExecuteScript(String, IpcSender<WebDriverJSResult>),
|
ExecuteScript(String, IpcSender<WebDriverJSResult>),
|
||||||
ExecuteAsyncScript(String, IpcSender<WebDriverJSResult>),
|
ExecuteAsyncScript(String, IpcSender<WebDriverJSResult>),
|
||||||
FindElementCSS(String, IpcSender<Result<Option<String>, ()>>),
|
FindElementCSS(String, IpcSender<Result<Option<String>, ErrorStatus>>),
|
||||||
FindElementLinkText(String, bool, IpcSender<Result<Option<String>, ()>>),
|
FindElementLinkText(String, bool, IpcSender<Result<Option<String>, ErrorStatus>>),
|
||||||
FindElementTagName(String, IpcSender<Result<Option<String>, ()>>),
|
FindElementTagName(String, IpcSender<Result<Option<String>, ErrorStatus>>),
|
||||||
FindElementsCSS(String, IpcSender<Result<Vec<String>, ()>>),
|
FindElementsCSS(String, IpcSender<Result<Vec<String>, ErrorStatus>>),
|
||||||
FindElementsLinkText(String, bool, IpcSender<Result<Vec<String>, ()>>),
|
FindElementsLinkText(String, bool, IpcSender<Result<Vec<String>, ErrorStatus>>),
|
||||||
FindElementsTagName(String, IpcSender<Result<Vec<String>, ()>>),
|
FindElementsTagName(String, IpcSender<Result<Vec<String>, ErrorStatus>>),
|
||||||
FindElementElementCSS(String, String, IpcSender<Result<Option<String>, ()>>),
|
FindElementElementCSS(
|
||||||
FindElementElementLinkText(String, String, bool, IpcSender<Result<Option<String>, ()>>),
|
String,
|
||||||
FindElementElementTagName(String, String, IpcSender<Result<Option<String>, ()>>),
|
String,
|
||||||
FindElementElementsCSS(String, String, IpcSender<Result<Vec<String>, ()>>),
|
IpcSender<Result<Option<String>, ErrorStatus>>,
|
||||||
FindElementElementsLinkText(String, String, bool, IpcSender<Result<Vec<String>, ()>>),
|
),
|
||||||
FindElementElementsTagName(String, String, IpcSender<Result<Vec<String>, ()>>),
|
FindElementElementLinkText(
|
||||||
FocusElement(String, IpcSender<Result<(), ()>>),
|
String,
|
||||||
|
String,
|
||||||
|
bool,
|
||||||
|
IpcSender<Result<Option<String>, ErrorStatus>>,
|
||||||
|
),
|
||||||
|
FindElementElementTagName(
|
||||||
|
String,
|
||||||
|
String,
|
||||||
|
IpcSender<Result<Option<String>, ErrorStatus>>,
|
||||||
|
),
|
||||||
|
FindElementElementsCSS(String, String, IpcSender<Result<Vec<String>, ErrorStatus>>),
|
||||||
|
FindElementElementsLinkText(
|
||||||
|
String,
|
||||||
|
String,
|
||||||
|
bool,
|
||||||
|
IpcSender<Result<Vec<String>, ErrorStatus>>,
|
||||||
|
),
|
||||||
|
FindElementElementsTagName(String, String, IpcSender<Result<Vec<String>, ErrorStatus>>),
|
||||||
|
FocusElement(String, IpcSender<Result<(), ErrorStatus>>),
|
||||||
GetActiveElement(IpcSender<Option<String>>),
|
GetActiveElement(IpcSender<Option<String>>),
|
||||||
GetCookie(String, IpcSender<Vec<Serde<Cookie<'static>>>>),
|
GetCookie(String, IpcSender<Vec<Serde<Cookie<'static>>>>),
|
||||||
GetCookies(IpcSender<Vec<Serde<Cookie<'static>>>>),
|
GetCookies(IpcSender<Vec<Serde<Cookie<'static>>>>),
|
||||||
GetElementAttribute(String, String, IpcSender<Result<Option<String>, ()>>),
|
GetElementAttribute(
|
||||||
GetElementProperty(String, String, IpcSender<Result<WebDriverJSValue, ()>>),
|
String,
|
||||||
GetElementCSS(String, String, IpcSender<Result<String, ()>>),
|
String,
|
||||||
GetElementRect(String, IpcSender<Result<Rect<f64>, ()>>),
|
IpcSender<Result<Option<String>, ErrorStatus>>,
|
||||||
GetElementTagName(String, IpcSender<Result<String, ()>>),
|
),
|
||||||
GetElementText(String, IpcSender<Result<String, ()>>),
|
GetElementProperty(
|
||||||
GetBrowsingContextId(WebDriverFrameId, IpcSender<Result<BrowsingContextId, ()>>),
|
String,
|
||||||
|
String,
|
||||||
|
IpcSender<Result<WebDriverJSValue, ErrorStatus>>,
|
||||||
|
),
|
||||||
|
GetElementCSS(String, String, IpcSender<Result<String, ErrorStatus>>),
|
||||||
|
GetElementRect(String, IpcSender<Result<Rect<f64>, ErrorStatus>>),
|
||||||
|
GetElementTagName(String, IpcSender<Result<String, ErrorStatus>>),
|
||||||
|
GetElementText(String, IpcSender<Result<String, ErrorStatus>>),
|
||||||
|
GetBrowsingContextId(
|
||||||
|
WebDriverFrameId,
|
||||||
|
IpcSender<Result<BrowsingContextId, ErrorStatus>>,
|
||||||
|
),
|
||||||
GetUrl(IpcSender<ServoUrl>),
|
GetUrl(IpcSender<ServoUrl>),
|
||||||
GetPageSource(IpcSender<Result<String, ()>>),
|
GetPageSource(IpcSender<Result<String, ErrorStatus>>),
|
||||||
IsEnabled(String, IpcSender<Result<bool, ()>>),
|
IsEnabled(String, IpcSender<Result<bool, ErrorStatus>>),
|
||||||
IsSelected(String, IpcSender<Result<bool, ()>>),
|
IsSelected(String, IpcSender<Result<bool, ErrorStatus>>),
|
||||||
GetTitle(IpcSender<String>),
|
GetTitle(IpcSender<String>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -735,10 +735,7 @@ impl Handler {
|
||||||
Ok(is_enabled) => Ok(WebDriverResponse::Generic(ValueResponse(
|
Ok(is_enabled) => Ok(WebDriverResponse::Generic(ValueResponse(
|
||||||
serde_json::to_value(is_enabled)?,
|
serde_json::to_value(is_enabled)?,
|
||||||
))),
|
))),
|
||||||
Err(_) => Err(WebDriverError::new(
|
Err(error) => Err(WebDriverError::new(error, "")),
|
||||||
ErrorStatus::StaleElementReference,
|
|
||||||
"Element not found",
|
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -754,10 +751,7 @@ impl Handler {
|
||||||
Ok(is_selected) => Ok(WebDriverResponse::Generic(ValueResponse(
|
Ok(is_selected) => Ok(WebDriverResponse::Generic(ValueResponse(
|
||||||
serde_json::to_value(is_selected)?,
|
serde_json::to_value(is_selected)?,
|
||||||
))),
|
))),
|
||||||
Err(_) => Err(WebDriverError::new(
|
Err(error) => Err(WebDriverError::new(error, "")),
|
||||||
ErrorStatus::StaleElementReference,
|
|
||||||
"Element not found",
|
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -860,10 +854,7 @@ impl Handler {
|
||||||
)?;
|
)?;
|
||||||
Ok(WebDriverResponse::Generic(ValueResponse(value_resp)))
|
Ok(WebDriverResponse::Generic(ValueResponse(value_resp)))
|
||||||
},
|
},
|
||||||
Err(_) => Err(WebDriverError::new(
|
Err(error) => Err(WebDriverError::new(error, "")),
|
||||||
ErrorStatus::InvalidSelector,
|
|
||||||
"Invalid selector",
|
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -922,13 +913,13 @@ impl Handler {
|
||||||
let cmd = WebDriverScriptCommand::GetBrowsingContextId(frame_id, sender);
|
let cmd = WebDriverScriptCommand::GetBrowsingContextId(frame_id, sender);
|
||||||
self.browsing_context_script_command(cmd)?;
|
self.browsing_context_script_command(cmd)?;
|
||||||
|
|
||||||
let browsing_context_id = receiver.recv().unwrap().or(Err(WebDriverError::new(
|
match receiver.recv().unwrap() {
|
||||||
ErrorStatus::NoSuchFrame,
|
Ok(browsing_context_id) => {
|
||||||
"Frame does not exist",
|
self.session_mut()?.browsing_context_id = browsing_context_id;
|
||||||
)))?;
|
Ok(WebDriverResponse::Void)
|
||||||
|
},
|
||||||
self.session_mut()?.browsing_context_id = browsing_context_id;
|
Err(error) => Err(WebDriverError::new(error, "")),
|
||||||
Ok(WebDriverResponse::Void)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://w3c.github.io/webdriver/#find-elements
|
// https://w3c.github.io/webdriver/#find-elements
|
||||||
|
@ -974,10 +965,7 @@ impl Handler {
|
||||||
serde_json::to_value(resp_value)?,
|
serde_json::to_value(resp_value)?,
|
||||||
)))
|
)))
|
||||||
},
|
},
|
||||||
Err(_) => Err(WebDriverError::new(
|
Err(error) => Err(WebDriverError::new(error, "")),
|
||||||
ErrorStatus::InvalidSelector,
|
|
||||||
"Invalid selector",
|
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1030,10 +1018,7 @@ impl Handler {
|
||||||
)?;
|
)?;
|
||||||
Ok(WebDriverResponse::Generic(ValueResponse(value_resp)))
|
Ok(WebDriverResponse::Generic(ValueResponse(value_resp)))
|
||||||
},
|
},
|
||||||
Err(_) => Err(WebDriverError::new(
|
Err(error) => Err(WebDriverError::new(error, "")),
|
||||||
ErrorStatus::InvalidSelector,
|
|
||||||
"Invalid selector",
|
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1089,10 +1074,7 @@ impl Handler {
|
||||||
serde_json::to_value(resp_value)?,
|
serde_json::to_value(resp_value)?,
|
||||||
)))
|
)))
|
||||||
},
|
},
|
||||||
Err(_) => Err(WebDriverError::new(
|
Err(error) => Err(WebDriverError::new(error, "")),
|
||||||
ErrorStatus::InvalidSelector,
|
|
||||||
"Invalid selector",
|
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1111,10 +1093,7 @@ impl Handler {
|
||||||
};
|
};
|
||||||
Ok(WebDriverResponse::ElementRect(response))
|
Ok(WebDriverResponse::ElementRect(response))
|
||||||
},
|
},
|
||||||
Err(_) => Err(WebDriverError::new(
|
Err(error) => Err(WebDriverError::new(error, "")),
|
||||||
ErrorStatus::StaleElementReference,
|
|
||||||
"Unable to find element in document",
|
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1126,10 +1105,7 @@ impl Handler {
|
||||||
Ok(value) => Ok(WebDriverResponse::Generic(ValueResponse(
|
Ok(value) => Ok(WebDriverResponse::Generic(ValueResponse(
|
||||||
serde_json::to_value(value)?,
|
serde_json::to_value(value)?,
|
||||||
))),
|
))),
|
||||||
Err(_) => Err(WebDriverError::new(
|
Err(error) => Err(WebDriverError::new(error, "")),
|
||||||
ErrorStatus::StaleElementReference,
|
|
||||||
"Unable to find element in document",
|
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1154,10 +1130,7 @@ impl Handler {
|
||||||
Ok(value) => Ok(WebDriverResponse::Generic(ValueResponse(
|
Ok(value) => Ok(WebDriverResponse::Generic(ValueResponse(
|
||||||
serde_json::to_value(value)?,
|
serde_json::to_value(value)?,
|
||||||
))),
|
))),
|
||||||
Err(_) => Err(WebDriverError::new(
|
Err(error) => Err(WebDriverError::new(error, "")),
|
||||||
ErrorStatus::StaleElementReference,
|
|
||||||
"Unable to find element in document",
|
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1177,10 +1150,7 @@ impl Handler {
|
||||||
Ok(value) => Ok(WebDriverResponse::Generic(ValueResponse(
|
Ok(value) => Ok(WebDriverResponse::Generic(ValueResponse(
|
||||||
serde_json::to_value(value)?,
|
serde_json::to_value(value)?,
|
||||||
))),
|
))),
|
||||||
Err(_) => Err(WebDriverError::new(
|
Err(error) => Err(WebDriverError::new(error, "")),
|
||||||
ErrorStatus::StaleElementReference,
|
|
||||||
"Unable to find element in document",
|
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1202,10 +1172,7 @@ impl Handler {
|
||||||
Ok(value) => Ok(WebDriverResponse::Generic(ValueResponse(
|
Ok(value) => Ok(WebDriverResponse::Generic(ValueResponse(
|
||||||
serde_json::to_value(SendableWebDriverJSValue(value))?,
|
serde_json::to_value(SendableWebDriverJSValue(value))?,
|
||||||
))),
|
))),
|
||||||
Err(_) => Err(WebDriverError::new(
|
Err(error) => Err(WebDriverError::new(error, "")),
|
||||||
ErrorStatus::StaleElementReference,
|
|
||||||
"Unable to find element in document",
|
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1222,10 +1189,7 @@ impl Handler {
|
||||||
Ok(value) => Ok(WebDriverResponse::Generic(ValueResponse(
|
Ok(value) => Ok(WebDriverResponse::Generic(ValueResponse(
|
||||||
serde_json::to_value(value)?,
|
serde_json::to_value(value)?,
|
||||||
))),
|
))),
|
||||||
Err(_) => Err(WebDriverError::new(
|
Err(error) => Err(WebDriverError::new(error, "")),
|
||||||
ErrorStatus::StaleElementReference,
|
|
||||||
"Unable to find element in document",
|
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1295,10 +1259,7 @@ impl Handler {
|
||||||
self.browsing_context_script_command(cmd)?;
|
self.browsing_context_script_command(cmd)?;
|
||||||
match receiver.recv().unwrap() {
|
match receiver.recv().unwrap() {
|
||||||
Ok(_) => Ok(WebDriverResponse::Void),
|
Ok(_) => Ok(WebDriverResponse::Void),
|
||||||
Err(_) => Err(WebDriverError::new(
|
Err(error) => Err(WebDriverError::new(error, "")),
|
||||||
ErrorStatus::NoSuchWindow,
|
|
||||||
"No such window found.",
|
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1355,10 +1316,7 @@ impl Handler {
|
||||||
Ok(source) => Ok(WebDriverResponse::Generic(ValueResponse(
|
Ok(source) => Ok(WebDriverResponse::Generic(ValueResponse(
|
||||||
serde_json::to_value(source)?,
|
serde_json::to_value(source)?,
|
||||||
))),
|
))),
|
||||||
Err(_) => Err(WebDriverError::new(
|
Err(error) => Err(WebDriverError::new(error, "")),
|
||||||
ErrorStatus::UnknownError,
|
|
||||||
"Unknown error",
|
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1469,12 +1427,10 @@ impl Handler {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// TODO: distinguish the not found and not focusable cases
|
// TODO: distinguish the not found and not focusable cases
|
||||||
receiver.recv().unwrap().or_else(|_| {
|
receiver
|
||||||
Err(WebDriverError::new(
|
.recv()
|
||||||
ErrorStatus::StaleElementReference,
|
.unwrap()
|
||||||
"Element not found or not focusable",
|
.or_else(|error| Err(WebDriverError::new(error, "")))?;
|
||||||
))
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let input_events = send_keys(&keys.text);
|
let input_events = send_keys(&keys.text);
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,6 @@
|
||||||
[test_boolean_attribute[video-attrs17\]]
|
[test_boolean_attribute[video-attrs17\]]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[test_element_not_found]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[test_global_boolean_attributes]
|
[test_global_boolean_attributes]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
[get.py]
|
[get.py]
|
||||||
[test_element_not_found]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[test_no_browsing_context]
|
[test_no_browsing_context]
|
||||||
expected: ERROR
|
expected: ERROR
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,6 @@
|
||||||
[test_idl_attribute]
|
[test_idl_attribute]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[test_element_not_found]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[test_primitives_set_by_execute_script[42-42\]]
|
[test_primitives_set_by_execute_script[42-42\]]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
[get.py]
|
[get.py]
|
||||||
[test_element_not_found]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[test_no_browsing_context]
|
[test_no_browsing_context]
|
||||||
expected: ERROR
|
expected: ERROR
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
[get.py]
|
[get.py]
|
||||||
[test_element_not_found]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[test_no_browsing_context]
|
[test_no_browsing_context]
|
||||||
expected: ERROR
|
expected: ERROR
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
[get.py]
|
[get.py]
|
||||||
[test_getting_text_of_a_non_existant_element_is_an_error]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[test_no_browsing_context]
|
[test_no_browsing_context]
|
||||||
expected: ERROR
|
expected: ERROR
|
||||||
|
|
||||||
|
|
|
@ -8,18 +8,12 @@
|
||||||
[test_frame_id_webelement_frame[0-foo\]]
|
[test_frame_id_webelement_frame[0-foo\]]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[test_frame_id_webelement_no_element_reference]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[test_frame_id_number_index_out_of_bounds]
|
[test_frame_id_number_index_out_of_bounds]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[test_frame_id_number_index[0-foo\]]
|
[test_frame_id_number_index[0-foo\]]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[test_frame_id_webelement_stale_reference]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[test_no_browsing_context]
|
[test_no_browsing_context]
|
||||||
expected: ERROR
|
expected: ERROR
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue