mirror of
https://github.com/servo/servo.git
synced 2025-06-13 02:44:29 +00:00
Implement GetElementProperty WebDriver command
This commit is contained in:
parent
ef7b58f0cd
commit
e34a15c5ef
7 changed files with 107 additions and 18 deletions
|
@ -2013,6 +2013,15 @@ impl ScriptThread {
|
||||||
reply,
|
reply,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
WebDriverScriptCommand::GetElementProperty(node_id, name, reply) => {
|
||||||
|
webdriver_handlers::handle_get_property(
|
||||||
|
&*documents,
|
||||||
|
pipeline_id,
|
||||||
|
node_id,
|
||||||
|
name,
|
||||||
|
reply,
|
||||||
|
)
|
||||||
|
},
|
||||||
WebDriverScriptCommand::GetElementCSS(node_id, name, reply) => {
|
WebDriverScriptCommand::GetElementCSS(node_id, name, reply) => {
|
||||||
webdriver_handlers::handle_get_css(&*documents, pipeline_id, node_id, name, reply)
|
webdriver_handlers::handle_get_css(&*documents, pipeline_id, node_id, name, reply)
|
||||||
},
|
},
|
||||||
|
|
|
@ -12,9 +12,11 @@ use crate::dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||||
use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
||||||
use crate::dom::bindings::codegen::Bindings::XMLSerializerBinding::XMLSerializerMethods;
|
use crate::dom::bindings::codegen::Bindings::XMLSerializerBinding::XMLSerializerMethods;
|
||||||
use crate::dom::bindings::conversions::{
|
use crate::dom::bindings::conversions::{
|
||||||
ConversionResult, FromJSValConvertible, StringificationBehavior,
|
get_property_jsval, ConversionResult, FromJSValConvertible, StringificationBehavior,
|
||||||
};
|
};
|
||||||
|
use crate::dom::bindings::error::throw_dom_exception;
|
||||||
use crate::dom::bindings::inheritance::Castable;
|
use crate::dom::bindings::inheritance::Castable;
|
||||||
|
use crate::dom::bindings::reflector::DomObject;
|
||||||
use crate::dom::bindings::root::DomRoot;
|
use crate::dom::bindings::root::DomRoot;
|
||||||
use crate::dom::bindings::str::DOMString;
|
use crate::dom::bindings::str::DOMString;
|
||||||
use crate::dom::element::Element;
|
use crate::dom::element::Element;
|
||||||
|
@ -529,6 +531,43 @@ pub fn handle_get_attribute(
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unsafe_code)]
|
||||||
|
pub fn handle_get_property(
|
||||||
|
documents: &Documents,
|
||||||
|
pipeline: PipelineId,
|
||||||
|
node_id: String,
|
||||||
|
name: String,
|
||||||
|
reply: IpcSender<Result<WebDriverJSValue, ()>>,
|
||||||
|
) {
|
||||||
|
reply
|
||||||
|
.send(match find_node_by_unique_id(documents, pipeline, node_id) {
|
||||||
|
Some(node) => {
|
||||||
|
let cx = documents.find_document(pipeline).unwrap().window().get_cx();
|
||||||
|
|
||||||
|
rooted!(in(cx) let mut property = UndefinedValue());
|
||||||
|
match unsafe {
|
||||||
|
get_property_jsval(
|
||||||
|
cx,
|
||||||
|
node.reflector().get_jsobject(),
|
||||||
|
&name,
|
||||||
|
property.handle_mut(),
|
||||||
|
)
|
||||||
|
} {
|
||||||
|
Ok(_) => match unsafe { jsval_to_webdriver(cx, property.handle()) } {
|
||||||
|
Ok(property) => Ok(property),
|
||||||
|
Err(_) => Ok(WebDriverJSValue::Undefined),
|
||||||
|
},
|
||||||
|
Err(error) => {
|
||||||
|
unsafe { throw_dom_exception(cx, &node.reflector().global(), error) };
|
||||||
|
Ok(WebDriverJSValue::Undefined)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => Err(()),
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn handle_get_css(
|
pub fn handle_get_css(
|
||||||
documents: &Documents,
|
documents: &Documents,
|
||||||
pipeline: PipelineId,
|
pipeline: PipelineId,
|
||||||
|
|
|
@ -33,6 +33,7 @@ pub enum WebDriverScriptCommand {
|
||||||
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(String, String, IpcSender<Result<Option<String>, ()>>),
|
||||||
|
GetElementProperty(String, String, IpcSender<Result<WebDriverJSValue, ()>>),
|
||||||
GetElementCSS(String, String, IpcSender<Result<String, ()>>),
|
GetElementCSS(String, String, IpcSender<Result<String, ()>>),
|
||||||
GetElementRect(String, IpcSender<Result<Rect<f64>, ()>>),
|
GetElementRect(String, IpcSender<Result<Rect<f64>, ()>>),
|
||||||
GetElementTagName(String, IpcSender<Result<String, ()>>),
|
GetElementTagName(String, IpcSender<Result<String, ()>>),
|
||||||
|
@ -51,7 +52,7 @@ pub enum WebDriverCookieError {
|
||||||
UnableToSetCookie,
|
UnableToSetCookie,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub enum WebDriverJSValue {
|
pub enum WebDriverJSValue {
|
||||||
Undefined,
|
Undefined,
|
||||||
Null,
|
Null,
|
||||||
|
|
|
@ -211,6 +211,7 @@ impl WebDriverExtensionCommand for ServoExtensionCommand {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
struct SendableWebDriverJSValue(pub WebDriverJSValue);
|
struct SendableWebDriverJSValue(pub WebDriverJSValue);
|
||||||
|
|
||||||
impl Serialize for SendableWebDriverJSValue {
|
impl Serialize for SendableWebDriverJSValue {
|
||||||
|
@ -1087,6 +1088,28 @@ impl Handler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_element_property(
|
||||||
|
&self,
|
||||||
|
element: &WebElement,
|
||||||
|
name: &str,
|
||||||
|
) -> WebDriverResult<WebDriverResponse> {
|
||||||
|
let (sender, receiver) = ipc::channel().unwrap();
|
||||||
|
|
||||||
|
let cmd =
|
||||||
|
WebDriverScriptCommand::GetElementProperty(element.id.clone(), name.to_owned(), sender);
|
||||||
|
self.browsing_context_script_command(cmd)?;
|
||||||
|
|
||||||
|
match receiver.recv().unwrap() {
|
||||||
|
Ok(value) => Ok(WebDriverResponse::Generic(ValueResponse(
|
||||||
|
serde_json::to_value(SendableWebDriverJSValue(value))?,
|
||||||
|
))),
|
||||||
|
Err(_) => Err(WebDriverError::new(
|
||||||
|
ErrorStatus::StaleElementReference,
|
||||||
|
"Unable to find element in document",
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn handle_element_css(
|
fn handle_element_css(
|
||||||
&self,
|
&self,
|
||||||
element: &WebElement,
|
element: &WebElement,
|
||||||
|
@ -1510,6 +1533,9 @@ impl WebDriverHandler<ServoExtensionRoute> for Handler {
|
||||||
WebDriverCommand::GetElementAttribute(ref element, ref name) => {
|
WebDriverCommand::GetElementAttribute(ref element, ref name) => {
|
||||||
self.handle_element_attribute(element, name)
|
self.handle_element_attribute(element, name)
|
||||||
},
|
},
|
||||||
|
WebDriverCommand::GetElementProperty(ref element, ref name) => {
|
||||||
|
self.handle_element_property(element, name)
|
||||||
|
},
|
||||||
WebDriverCommand::GetCSSValue(ref element, ref name) => {
|
WebDriverCommand::GetCSSValue(ref element, ref name) => {
|
||||||
self.handle_element_css(element, name)
|
self.handle_element_css(element, name)
|
||||||
},
|
},
|
||||||
|
|
|
@ -8,24 +8,15 @@
|
||||||
[test_visibility_hidden]
|
[test_visibility_hidden]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[test_transparent_element]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[test_iframe_is_interactable]
|
[test_iframe_is_interactable]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[test_readonly_element]
|
[test_readonly_element]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[test_obscured_element]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[test_document_element_is_interactable]
|
[test_document_element_is_interactable]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[test_body_is_interactable]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[test_hidden]
|
[test_hidden]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,31 @@
|
||||||
[get.py]
|
[get.py]
|
||||||
disabled: Unimplemented WebDriver command
|
[test_primitives[js_primitive3-py_primitive3\]]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[test_idl_attribute]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[test_element_not_found]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[test_primitives_set_by_execute_script[42-42\]]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[test_primitives[js_primitive2-py_primitive2\]]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[test_primitives_set_by_execute_script[js_primitive2-py_primitive2\]]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[test_mutated_element]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[test_no_browsing_context]
|
||||||
|
expected: ERROR
|
||||||
|
|
||||||
|
[test_primitives_set_by_execute_script[js_primitive3-py_primitive3\]]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
[test_primitives_set_by_execute_script["foobar"-foobar\]]
|
||||||
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -2,15 +2,9 @@
|
||||||
[test_history_pushstate]
|
[test_history_pushstate]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[test_basic]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[test_refresh_switches_to_parent_browsing_context]
|
[test_refresh_switches_to_parent_browsing_context]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[test_no_browsing_context]
|
[test_no_browsing_context]
|
||||||
expected: ERROR
|
expected: ERROR
|
||||||
|
|
||||||
[test_dismissed_beforeunload]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue