diff --git a/Cargo.lock b/Cargo.lock index fca793218ed4..8670ba0bf276 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4027,6 +4027,7 @@ dependencies = [ "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "utf-8 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)", "uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", + "webdriver 0.40.0 (registry+https://github.com/rust-lang/crates.io-index)", "webrender_api 0.60.0 (git+https://github.com/servo/webrender)", "webvr_traits 0.0.1", "webxr-api 0.0.1 (git+https://github.com/servo/webxr)", @@ -4119,6 +4120,7 @@ dependencies = [ "style_traits 0.0.1", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "webdriver 0.40.0 (registry+https://github.com/rust-lang/crates.io-index)", "webrender_api 0.60.0 (git+https://github.com/servo/webrender)", "webvr_traits 0.0.1", "webxr-api 0.0.1 (git+https://github.com/servo/webxr)", diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml index cb03c00b873a..2473dba7c9cb 100644 --- a/components/script/Cargo.toml +++ b/components/script/Cargo.toml @@ -111,6 +111,7 @@ url = "1.6" utf-8 = "0.7" uuid = {version = "0.7", features = ["v4"]} xml5ever = {version = "0.14"} +webdriver = "0.40" webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]} webvr_traits = {path = "../webvr_traits"} webxr-api = {git = "https://github.com/servo/webxr", features = ["ipc"]} diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index b33a5c5a1264..09247103d0c2 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -964,7 +964,7 @@ impl WindowMethods for Window { #[allow(unsafe_code)] fn WebdriverCallback(&self, cx: JSContext, val: HandleValue) { - let rv = unsafe { jsval_to_webdriver(*cx, val) }; + let rv = unsafe { jsval_to_webdriver(*cx, &self.globalscope, val) }; let opt_chan = self.webdriver_script_chan.borrow_mut().take(); if let Some(chan) = opt_chan { chan.send(rv).unwrap(); diff --git a/components/script/webdriver_handlers.rs b/components/script/webdriver_handlers.rs index 874f707a739a..182f110c0c82 100644 --- a/components/script/webdriver_handlers.rs +++ b/components/script/webdriver_handlers.rs @@ -12,7 +12,10 @@ 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::{ - get_property_jsval, ConversionResult, FromJSValConvertible, StringificationBehavior, + get_property, get_property_jsval, is_array_like, root_from_object, +}; +use crate::dom::bindings::conversions::{ + ConversionBehavior, ConversionResult, FromJSValConvertible, StringificationBehavior, }; use crate::dom::bindings::error::throw_dom_exception; use crate::dom::bindings::inheritance::Castable; @@ -29,12 +32,13 @@ use crate::dom::node::{window_from_node, Node, ShadowIncluding}; use crate::dom::nodelist::NodeList; use crate::dom::window::Window; use crate::dom::xmlserializer::XMLSerializer; +use crate::script_runtime::JSContext as SafeJSContext; use crate::script_thread::Documents; use cookie::Cookie; use euclid::default::{Point2D, Rect, Size2D}; use hyper_serde::Serde; use ipc_channel::ipc::{self, IpcSender}; -use js::jsapi::JSContext; +use js::jsapi::{JSAutoRealm, JSContext}; use js::jsval::UndefinedValue; use js::rust::HandleValue; use msg::constellation_msg::BrowsingContextId; @@ -47,6 +51,7 @@ use script_traits::webdriver_msg::{ WebDriverFrameId, WebDriverJSError, WebDriverJSResult, WebDriverJSValue, }; use servo_url::ServoUrl; +use webdriver::common::WebElement; fn find_node_by_unique_id( documents: &Documents, @@ -106,9 +111,15 @@ fn first_matching_link( } #[allow(unsafe_code)] -pub unsafe fn jsval_to_webdriver(cx: *mut JSContext, val: HandleValue) -> WebDriverJSResult { +pub unsafe fn jsval_to_webdriver( + cx: *mut JSContext, + global_scope: &GlobalScope, + val: HandleValue, +) -> WebDriverJSResult { if val.get().is_undefined() { Ok(WebDriverJSValue::Undefined) + } else if val.get().is_null() { + Ok(WebDriverJSValue::Null) } else if val.get().is_boolean() { Ok(WebDriverJSValue::Boolean(val.get().to_boolean())) } else if val.get().is_double() || val.get().is_int32() { @@ -128,8 +139,52 @@ pub unsafe fn jsval_to_webdriver(cx: *mut JSContext, val: HandleValue) -> WebDri _ => unreachable!(), }; Ok(WebDriverJSValue::String(String::from(string))) - } else if val.get().is_null() { - Ok(WebDriverJSValue::Null) + } else if val.get().is_object() { + rooted!(in(cx) let object = match FromJSValConvertible::from_jsval(cx, val, ()).unwrap() { + ConversionResult::Success(object) => object, + _ => unreachable!(), + }); + let _ac = JSAutoRealm::new(cx, *object); + + if let Ok(element) = root_from_object::(*object, cx) { + return Ok(WebDriverJSValue::Element(WebElement( + element.upcast::().unique_id(), + ))); + } + + if !is_array_like(cx, val) { + return Err(WebDriverJSError::UnknownType); + } + + let mut result: Vec = Vec::new(); + + let length = + match get_property::(cx, object.handle(), "length", ConversionBehavior::Default) { + Ok(length) => match length { + Some(length) => length, + _ => return Err(WebDriverJSError::UnknownType), + }, + Err(error) => { + throw_dom_exception(SafeJSContext::from_ptr(cx), global_scope, error); + return Err(WebDriverJSError::JSError); + }, + }; + + for i in 0..length { + rooted!(in(cx) let mut item = UndefinedValue()); + match get_property_jsval(cx, object.handle(), &i.to_string(), item.handle_mut()) { + Ok(_) => match jsval_to_webdriver(cx, global_scope, item.handle()) { + Ok(converted_item) => result.push(converted_item), + err @ Err(_) => return err, + }, + Err(error) => { + throw_dom_exception(SafeJSContext::from_ptr(cx), global_scope, error); + return Err(WebDriverJSError::JSError); + }, + } + } + + Ok(WebDriverJSValue::ArrayLike(result)) } else { Err(WebDriverJSError::UnknownType) } @@ -149,7 +204,7 @@ pub fn handle_execute_script( window .upcast::() .evaluate_js_on_global_with_result(&eval, rval.handle_mut()); - jsval_to_webdriver(*cx, rval.handle()) + jsval_to_webdriver(*cx, &window.upcast::(), rval.handle()) }; reply.send(result).unwrap(); @@ -734,7 +789,9 @@ pub fn handle_get_property( property.handle_mut(), ) } { - Ok(_) => match unsafe { jsval_to_webdriver(*cx, property.handle()) } { + Ok(_) => match unsafe { + jsval_to_webdriver(*cx, &node.reflector().global(), property.handle()) + } { Ok(property) => Ok(property), Err(_) => Ok(WebDriverJSValue::Undefined), }, diff --git a/components/script_traits/Cargo.toml b/components/script_traits/Cargo.toml index 61e1dda74107..bd1011daad2c 100644 --- a/components/script_traits/Cargo.toml +++ b/components/script_traits/Cargo.toml @@ -38,6 +38,7 @@ servo_url = {path = "../url"} style_traits = {path = "../style_traits", features = ["servo"]} time = "0.1.12" url = "1.2" +webdriver = "0.40" webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]} webvr_traits = {path = "../webvr_traits"} webxr-api = {git = "https://github.com/servo/webxr", features = ["ipc"]} diff --git a/components/script_traits/webdriver_msg.rs b/components/script_traits/webdriver_msg.rs index 7849a8580efd..c33a5ae302d9 100644 --- a/components/script_traits/webdriver_msg.rs +++ b/components/script_traits/webdriver_msg.rs @@ -10,6 +10,7 @@ use hyper_serde::Serde; use ipc_channel::ipc::IpcSender; use msg::constellation_msg::BrowsingContextId; use servo_url::ServoUrl; +use webdriver::common::WebElement; #[derive(Debug, Deserialize, Serialize)] pub enum WebDriverScriptCommand { @@ -66,13 +67,16 @@ pub enum WebDriverJSValue { Null, Boolean(bool), Number(f64), - String(String), // TODO: Object and WebElement + String(String), + Element(WebElement), + ArrayLike(Vec), } #[derive(Debug, Deserialize, Serialize)] pub enum WebDriverJSError { Timeout, UnknownType, + JSError, /// Occurs when handler received an event message for a layout channel that is not /// associated with the current script thread BrowsingContextNotFound, diff --git a/components/webdriver_server/lib.rs b/components/webdriver_server/lib.rs index 9d6ab3355d15..fd141879ebdc 100644 --- a/components/webdriver_server/lib.rs +++ b/components/webdriver_server/lib.rs @@ -224,6 +224,12 @@ impl Serialize for SendableWebDriverJSValue { WebDriverJSValue::Boolean(x) => serializer.serialize_bool(x), WebDriverJSValue::Number(x) => serializer.serialize_f64(x), WebDriverJSValue::String(ref x) => serializer.serialize_str(&x), + WebDriverJSValue::Element(ref x) => x.serialize(serializer), + WebDriverJSValue::ArrayLike(ref x) => x + .iter() + .map(|element| SendableWebDriverJSValue(element.clone())) + .collect::>() + .serialize(serializer), } } } @@ -1397,6 +1403,10 @@ impl Handler { ErrorStatus::UnsupportedOperation, "Unsupported return type", )), + Err(WebDriverJSError::JSError) => Err(WebDriverError::new( + ErrorStatus::JavascriptError, + "JS evaluation raised an exception", + )), Err(WebDriverJSError::BrowsingContextNotFound) => Err(WebDriverError::new( ErrorStatus::JavascriptError, "Pipeline id not found in browsing context", diff --git a/tests/wpt/metadata/webdriver/tests/element_send_keys/events.py.ini b/tests/wpt/metadata/webdriver/tests/element_send_keys/events.py.ini index ceea4018cf39..aba9010ad1d9 100644 --- a/tests/wpt/metadata/webdriver/tests/element_send_keys/events.py.ini +++ b/tests/wpt/metadata/webdriver/tests/element_send_keys/events.py.ini @@ -5,12 +5,6 @@ [test_form_control_send_text[textarea\]] expected: FAIL - [test_not_blurred[input\]] - expected: FAIL - [test_file_upload] expected: FAIL - [test_not_blurred[textarea\]] - expected: FAIL - diff --git a/tests/wpt/metadata/webdriver/tests/element_send_keys/form_controls.py.ini b/tests/wpt/metadata/webdriver/tests/element_send_keys/form_controls.py.ini index 7c0014ddf6db..3601b6faeccf 100644 --- a/tests/wpt/metadata/webdriver/tests/element_send_keys/form_controls.py.ini +++ b/tests/wpt/metadata/webdriver/tests/element_send_keys/form_controls.py.ini @@ -1,13 +1,2 @@ [form_controls.py] - [test_textarea] - expected: FAIL - - [test_input_append] - expected: FAIL - - [test_textarea_append] - expected: FAIL - - [test_input] - expected: FAIL - + disabled: Triggers setup errors in other tests diff --git a/tests/wpt/metadata/webdriver/tests/execute_script/collections.py.ini b/tests/wpt/metadata/webdriver/tests/execute_script/collections.py.ini index f8a4b440ca87..a22f4f577343 100644 --- a/tests/wpt/metadata/webdriver/tests/execute_script/collections.py.ini +++ b/tests/wpt/metadata/webdriver/tests/execute_script/collections.py.ini @@ -1,25 +1,10 @@ [collections.py] - [test_html_form_controls_collection] - expected: FAIL - - [test_html_options_collection] - expected: FAIL - [test_file_list] expected: FAIL [test_arguments] expected: FAIL - [test_html_collection] - expected: FAIL - - [test_array] - expected: FAIL - - [test_node_list] - expected: FAIL - [test_html_all_collection] expected: FAIL diff --git a/tests/wpt/metadata/webdriver/tests/execute_script/cyclic.py.ini b/tests/wpt/metadata/webdriver/tests/execute_script/cyclic.py.ini index ac7fb3d407c0..15a6f71fb269 100644 --- a/tests/wpt/metadata/webdriver/tests/execute_script/cyclic.py.ini +++ b/tests/wpt/metadata/webdriver/tests/execute_script/cyclic.py.ini @@ -1,19 +1,13 @@ [cyclic.py] - [test_element_in_collection] - expected: FAIL - - [test_object_in_array] - expected: FAIL - [test_object] expected: FAIL - [test_array] - expected: FAIL - [test_array_in_object] expected: FAIL [test_element_in_object] expected: FAIL + [test_element_in_collection] + expected: + if os == "mac": FAIL diff --git a/tests/wpt/metadata/webdriver/tests/execute_script/execute.py.ini b/tests/wpt/metadata/webdriver/tests/execute_script/execute.py.ini index 5601b28f6365..84ba421e8aa7 100644 --- a/tests/wpt/metadata/webdriver/tests/execute_script/execute.py.ini +++ b/tests/wpt/metadata/webdriver/tests/execute_script/execute.py.ini @@ -23,6 +23,3 @@ [test_abort_by_user_prompt_twice[alert\]] expected: FAIL - [test_override_listeners] - expected: FAIL - diff --git a/tests/wpt/metadata/webdriver/tests/execute_script/properties.py.ini b/tests/wpt/metadata/webdriver/tests/execute_script/properties.py.ini deleted file mode 100644 index 589da852eec7..000000000000 --- a/tests/wpt/metadata/webdriver/tests/execute_script/properties.py.ini +++ /dev/null @@ -1,4 +0,0 @@ -[properties.py] - [test_idl_attribute_element] - expected: FAIL - diff --git a/tests/wpt/metadata/webdriver/tests/find_element/find.py.ini b/tests/wpt/metadata/webdriver/tests/find_element/find.py.ini index a03197015f7a..d3fdb6ebfc75 100644 --- a/tests/wpt/metadata/webdriver/tests/find_element/find.py.ini +++ b/tests/wpt/metadata/webdriver/tests/find_element/find.py.ini @@ -1,25 +1,13 @@ [find.py] - [test_xhtml_namespace[css selector-#linkText\]] - expected: FAIL - [test_htmldocument[xpath-/html\]] expected: FAIL [test_xhtml_namespace[xpath-//*[name()='a'\]\]] expected: FAIL - [test_xhtml_namespace[tag name-a\]] - expected: FAIL - - [test_xhtml_namespace[link text-full link text\]] - expected: FAIL - [test_no_element[css selector-#wontExist\]] expected: FAIL - [test_xhtml_namespace[partial link text-link text\]] - expected: FAIL - [test_find_element[xpath-//a\]] expected: FAIL diff --git a/tests/wpt/metadata/webdriver/tests/find_element_from_element/find.py.ini b/tests/wpt/metadata/webdriver/tests/find_element_from_element/find.py.ini index 26433cb614c0..3ebf48f3d1a7 100644 --- a/tests/wpt/metadata/webdriver/tests/find_element_from_element/find.py.ini +++ b/tests/wpt/metadata/webdriver/tests/find_element_from_element/find.py.ini @@ -1,28 +1,16 @@ [find.py] - [test_xhtml_namespace[css selector-#linkText\]] - expected: FAIL - [test_xhtml_namespace[xpath-//*[name()='a'\]\]] expected: FAIL [test_parent_htmldocument] expected: FAIL - [test_xhtml_namespace[tag name-a\]] - expected: FAIL - - [test_xhtml_namespace[link text-full link text\]] - expected: FAIL - [test_parent_of_document_node_errors] expected: FAIL [test_no_element[css selector-#wontExist\]] expected: FAIL - [test_xhtml_namespace[partial link text-link text\]] - expected: FAIL - [test_find_element[xpath-//a\]] expected: FAIL diff --git a/tests/wpt/metadata/webdriver/tests/find_elements/find.py.ini b/tests/wpt/metadata/webdriver/tests/find_elements/find.py.ini index f61c9e9c94b8..d6f1e5a7aea0 100644 --- a/tests/wpt/metadata/webdriver/tests/find_elements/find.py.ini +++ b/tests/wpt/metadata/webdriver/tests/find_elements/find.py.ini @@ -1,64 +1,25 @@ [find.py] - [test_xhtml_namespace[css selector-#linkText\]] - expected: FAIL - - [test_find_elements_link_text[LINK TEXT-LINK TEXT\]] - expected: FAIL - - [test_find_elements_link_text[link text-link text\]] - expected: FAIL - [test_xhtml_namespace[xpath-//*[name()='a'\]\]] expected: FAIL [test_find_elements_link_text[link text-LINK TEXT\]] expected: FAIL - [test_find_elements_partial_link_text[ partial link text -link\]] - expected: FAIL - - [test_xhtml_namespace[partial link text-link text\]] - expected: FAIL - [test_find_elements_partial_link_text[partial link
text
-k\nt\]] expected: FAIL - [test_find_elements_link_text[ link text -link text\]] - expected: FAIL - [test_htmldocument[xpath-/html\]] expected: FAIL - [test_xhtml_namespace[link text-full link text\]] - expected: FAIL - - [test_find_elements_partial_link_text[partial link text-k t\]] - expected: FAIL - - [test_find_elements_partial_link_text[partial link&text-k&t\]] - expected: FAIL - [test_find_elements[xpath-//a\]] expected: FAIL [test_find_elements_partial_link_text[partial link text-LINK\]] expected: FAIL - [test_find_elements_partial_link_text[PARTIAL LINK TEXT-LINK\]] - expected: FAIL - [test_find_elements_link_text[link
text
-link\ntext\]] expected: FAIL - [test_find_elements_link_text[link&text-link&text\]] - expected: FAIL - - [test_find_elements_partial_link_text[partial link text-link\]] - expected: FAIL - [test_no_browsing_context] expected: ERROR - [test_xhtml_namespace[tag name-a\]] - expected: FAIL - diff --git a/tests/wpt/metadata/webdriver/tests/find_elements_from_element/find.py.ini b/tests/wpt/metadata/webdriver/tests/find_elements_from_element/find.py.ini index 125027d9d0cf..47509ba91a88 100644 --- a/tests/wpt/metadata/webdriver/tests/find_elements_from_element/find.py.ini +++ b/tests/wpt/metadata/webdriver/tests/find_elements_from_element/find.py.ini @@ -1,67 +1,28 @@ [find.py] - [test_find_elements_link_text[LINK TEXT-LINK TEXT\]] - expected: FAIL - - [test_find_elements_link_text[link text-link text\]] - expected: FAIL - [test_xhtml_namespace[xpath-//*[name()='a'\]\]] expected: FAIL - [test_xhtml_namespace[css selector-#linkText\]] - expected: FAIL - [test_find_elements_link_text[link text-LINK TEXT\]] expected: FAIL - [test_find_elements_partial_link_text[ partial link text -link\]] - expected: FAIL - - [test_xhtml_namespace[partial link text-link text\]] - expected: FAIL - [test_find_elements_partial_link_text[partial link
text
-k\nt\]] expected: FAIL - [test_find_elements_link_text[ link text -link text\]] - expected: FAIL - [test_parent_htmldocument] expected: FAIL - [test_xhtml_namespace[link text-full link text\]] - expected: FAIL - - [test_find_elements_partial_link_text[partial link text-k t\]] - expected: FAIL - [test_parent_of_document_node_errors] expected: FAIL - [test_find_elements_partial_link_text[partial link&text-k&t\]] - expected: FAIL - [test_find_elements[xpath-//a\]] expected: FAIL [test_find_elements_partial_link_text[partial link text-LINK\]] expected: FAIL - [test_find_elements_partial_link_text[PARTIAL LINK TEXT-LINK\]] - expected: FAIL - [test_find_elements_link_text[link
text
-link\ntext\]] expected: FAIL - [test_find_elements_link_text[link&text-link&text\]] - expected: FAIL - - [test_find_elements_partial_link_text[partial link text-link\]] - expected: FAIL - [test_no_browsing_context] expected: ERROR - [test_xhtml_namespace[tag name-a\]] - expected: FAIL - diff --git a/tests/wpt/metadata/webdriver/tests/get_active_element/get.py.ini b/tests/wpt/metadata/webdriver/tests/get_active_element/get.py.ini index 9eea66b7a27c..2673df68da02 100644 --- a/tests/wpt/metadata/webdriver/tests/get_active_element/get.py.ini +++ b/tests/wpt/metadata/webdriver/tests/get_active_element/get.py.ini @@ -1,22 +1,7 @@ [get.py] - [test_sucess_input_non_interactable] - expected: FAIL - - [test_success_document] - expected: FAIL - - [test_sucess_input] - expected: FAIL - - [test_success_explicit_focus] - expected: FAIL - [test_no_browsing_context] expected: ERROR [test_missing_document_element] expected: FAIL - [test_success_iframe_content] - expected: FAIL - diff --git a/tests/wpt/metadata/webdriver/tests/get_current_url/get.py.ini b/tests/wpt/metadata/webdriver/tests/get_current_url/get.py.ini index 10212c3612d6..6cf1e1da10a2 100644 --- a/tests/wpt/metadata/webdriver/tests/get_current_url/get.py.ini +++ b/tests/wpt/metadata/webdriver/tests/get_current_url/get.py.ini @@ -2,6 +2,3 @@ [test_no_browsing_context] expected: ERROR - [test_get_current_url_nested_browsing_context] - expected: FAIL - diff --git a/tests/wpt/metadata/webdriver/tests/get_element_property/get.py.ini b/tests/wpt/metadata/webdriver/tests/get_element_property/get.py.ini index 1e970ff340b8..6ba107cdf754 100644 --- a/tests/wpt/metadata/webdriver/tests/get_element_property/get.py.ini +++ b/tests/wpt/metadata/webdriver/tests/get_element_property/get.py.ini @@ -11,9 +11,6 @@ [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 diff --git a/tests/wpt/metadata/webdriver/tests/get_title/get.py.ini b/tests/wpt/metadata/webdriver/tests/get_title/get.py.ini index 8c12e9fb3f83..6cf1e1da10a2 100644 --- a/tests/wpt/metadata/webdriver/tests/get_title/get.py.ini +++ b/tests/wpt/metadata/webdriver/tests/get_title/get.py.ini @@ -1,7 +1,4 @@ [get.py] - [test_title_from_frame] - expected: FAIL - [test_no_browsing_context] expected: ERROR diff --git a/tests/wpt/metadata/webdriver/tests/take_screenshot/screenshot.py.ini b/tests/wpt/metadata/webdriver/tests/take_screenshot/screenshot.py.ini index 73c9205fac25..49069e369560 100644 --- a/tests/wpt/metadata/webdriver/tests/take_screenshot/screenshot.py.ini +++ b/tests/wpt/metadata/webdriver/tests/take_screenshot/screenshot.py.ini @@ -2,6 +2,3 @@ [test_no_browsing_context] expected: ERROR - [test_format_and_dimensions] - expected: FAIL -