Skip to content
Permalink
Browse files

Implement GetElementProperty WebDriver command

  • Loading branch information...
georgeroman committed Jun 18, 2019
1 parent ef7b58f commit e34a15c5ef268149daef79376a981108545fa34d
@@ -2013,6 +2013,15 @@ impl ScriptThread {
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) => {
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::XMLSerializerBinding::XMLSerializerMethods;
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::reflector::DomObject;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::element::Element;
@@ -529,6 +531,43 @@ pub fn handle_get_attribute(
.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(
documents: &Documents,
pipeline: PipelineId,
@@ -33,6 +33,7 @@ pub enum WebDriverScriptCommand {
GetCookie(String, IpcSender<Vec<Serde<Cookie<'static>>>>),
GetCookies(IpcSender<Vec<Serde<Cookie<'static>>>>),
GetElementAttribute(String, String, IpcSender<Result<Option<String>, ()>>),
GetElementProperty(String, String, IpcSender<Result<WebDriverJSValue, ()>>),
GetElementCSS(String, String, IpcSender<Result<String, ()>>),
GetElementRect(String, IpcSender<Result<Rect<f64>, ()>>),
GetElementTagName(String, IpcSender<Result<String, ()>>),
@@ -51,7 +52,7 @@ pub enum WebDriverCookieError {
UnableToSetCookie,
}

#[derive(Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum WebDriverJSValue {
Undefined,
Null,
@@ -211,6 +211,7 @@ impl WebDriverExtensionCommand for ServoExtensionCommand {
}
}

#[derive(Clone)]
struct SendableWebDriverJSValue(pub WebDriverJSValue);

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(
&self,
element: &WebElement,
@@ -1510,6 +1533,9 @@ impl WebDriverHandler<ServoExtensionRoute> for Handler {
WebDriverCommand::GetElementAttribute(ref element, ref 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) => {
self.handle_element_css(element, name)
},
@@ -8,24 +8,15 @@
[test_visibility_hidden]
expected: FAIL

[test_transparent_element]
expected: FAIL

[test_iframe_is_interactable]
expected: FAIL

[test_readonly_element]
expected: FAIL

[test_obscured_element]
expected: FAIL

[test_document_element_is_interactable]
expected: FAIL

[test_body_is_interactable]
expected: FAIL

[test_hidden]
expected: FAIL

@@ -1,2 +1,31 @@
[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]
expected: FAIL

[test_basic]
expected: FAIL

[test_refresh_switches_to_parent_browsing_context]
expected: FAIL

[test_no_browsing_context]
expected: ERROR

[test_dismissed_beforeunload]
expected: FAIL

0 comments on commit e34a15c

Please sign in to comment.
You can’t perform that action at this time.