Bug 1509513 - [webdriver] Add support for the "New Window" command. r=ato
authorHenrik Skupin <mail@hskupin.info>
Tue, 15 Jan 2019 16:29:23 +0000
changeset 511183 7c8c157560bbad6e93fd3bdf609e394c8bac7cea
parent 511182 16709683a80e03a024abd1c0e90f1b223cbf9fb0
child 511184 6b7ee8555b8f6e5b8db9d99d1720243bb6bf777a
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1509513
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1509513 - [webdriver] Add support for the "New Window" command. r=ato Differential Revision: https://phabricator.services.mozilla.com/D16503
testing/webdriver/src/command.rs
testing/webdriver/src/httpapi.rs
testing/webdriver/src/response.rs
--- a/testing/webdriver/src/command.rs
+++ b/testing/webdriver/src/command.rs
@@ -18,16 +18,17 @@ pub enum WebDriverCommand<T: WebDriverEx
     GetCurrentUrl,
     GoBack,
     GoForward,
     Refresh,
     GetTitle,
     GetPageSource,
     GetWindowHandle,
     GetWindowHandles,
+    NewWindow(NewWindowParameters),
     CloseWindow,
     GetWindowRect,
     SetWindowRect(WindowRectParameters),
     MinimizeWindow,
     MaximizeWindow,
     FullscreenWindow,
     SwitchToWindow(SwitchToWindowParameters),
     SwitchToFrame(SwitchToFrameParameters),
@@ -115,16 +116,17 @@ impl<U: WebDriverExtensionRoute> WebDriv
             Route::GetCurrentUrl => WebDriverCommand::GetCurrentUrl,
             Route::GoBack => WebDriverCommand::GoBack,
             Route::GoForward => WebDriverCommand::GoForward,
             Route::Refresh => WebDriverCommand::Refresh,
             Route::GetTitle => WebDriverCommand::GetTitle,
             Route::GetPageSource => WebDriverCommand::GetPageSource,
             Route::GetWindowHandle => WebDriverCommand::GetWindowHandle,
             Route::GetWindowHandles => WebDriverCommand::GetWindowHandles,
+            Route::NewWindow => WebDriverCommand::NewWindow(serde_json::from_str(raw_body)?),
             Route::CloseWindow => WebDriverCommand::CloseWindow,
             Route::GetTimeouts => WebDriverCommand::GetTimeouts,
             Route::SetTimeouts => WebDriverCommand::SetTimeouts(serde_json::from_str(raw_body)?),
             Route::GetWindowRect | Route::GetWindowPosition | Route::GetWindowSize => {
                 WebDriverCommand::GetWindowRect
             }
             Route::SetWindowRect | Route::SetWindowPosition | Route::SetWindowSize => {
                 WebDriverCommand::SetWindowRect(serde_json::from_str(raw_body)?)
@@ -465,16 +467,22 @@ impl CapabilitiesMatching for NewSession
         match self {
             NewSessionParameters::Spec(x) => x.match_browser(browser_capabilities),
             NewSessionParameters::Legacy(x) => x.match_browser(browser_capabilities),
         }
     }
 }
 
 #[derive(Debug, PartialEq, Serialize, Deserialize)]
+pub struct NewWindowParameters {
+    #[serde(rename = "type")]
+    pub type_hint: Option<String>,
+}
+
+#[derive(Debug, PartialEq, Serialize, Deserialize)]
 pub struct SendKeysParameters {
     pub text: String,
 }
 
 #[derive(Debug, PartialEq, Serialize, Deserialize)]
 pub struct SwitchToFrameParameters {
     pub id: Option<FrameId>,
 }
@@ -935,16 +943,55 @@ mod tests {
             alwaysMatch: Capabilities::new(),
             firstMatch: vec![Capabilities::new()],
         });
 
         check_deserialize(&json, &data);
     }
 
     #[test]
+    fn test_json_new_window_parameters_without_type() {
+        let json = r#"{}"#;
+        let data = NewWindowParameters { type_hint: None };
+
+        check_deserialize(&json, &data);
+    }
+
+    #[test]
+    fn test_json_new_window_parameters_with_optional_null_type() {
+        let json = r#"{"type":null}"#;
+        let data = NewWindowParameters { type_hint: None };
+
+        check_deserialize(&json, &data);
+    }
+
+    #[test]
+    fn test_json_new_window_parameters_with_supported_type() {
+        let json = r#"{"type":"tab"}"#;
+        let data = NewWindowParameters { type_hint: Some("tab".into()) };
+
+        check_deserialize(&json, &data);
+    }
+
+    #[test]
+    fn test_json_new_window_parameters_with_unknown_type() {
+        let json = r#"{"type":"foo"}"#;
+        let data = NewWindowParameters { type_hint: Some("foo".into()) };
+
+        check_deserialize(&json, &data);
+    }
+
+    #[test]
+    fn test_json_new_window_parameters_with_invalid_type() {
+        let json = r#"{"type":3}"#;
+
+        assert!(serde_json::from_str::<NewWindowParameters>(&json).is_err());
+    }
+
+    #[test]
     fn test_json_send_keys_parameters_with_value() {
         let json = r#"{"text":"foo"}"#;
         let data = SendKeysParameters { text: "foo".into() };
 
         check_deserialize(&json, &data);
     }
 
     #[test]
--- a/testing/webdriver/src/httpapi.rs
+++ b/testing/webdriver/src/httpapi.rs
@@ -20,16 +20,17 @@ fn standard_routes<U: WebDriverExtension
         (Method::GET, "/session/{sessionId}/title", Route::GetTitle),
         (Method::GET, "/session/{sessionId}/source", Route::GetPageSource),
         (Method::GET, "/session/{sessionId}/window", Route::GetWindowHandle),
         (
             Method::GET,
             "/session/{sessionId}/window/handles",
             Route::GetWindowHandles,
         ),
+        (Method::POST, "/session/{sessionId}/window/new", Route::NewWindow),
         (Method::DELETE, "/session/{sessionId}/window", Route::CloseWindow),
         (
             Method::GET,
             "/session/{sessionId}/window/size",
             Route::GetWindowSize,
         ),
         (
             Method::POST,
@@ -224,16 +225,17 @@ pub enum Route<U: WebDriverExtensionRout
     GetCurrentUrl,
     GoBack,
     GoForward,
     Refresh,
     GetTitle,
     GetPageSource,
     GetWindowHandle,
     GetWindowHandles,
+    NewWindow,
     CloseWindow,
     GetWindowSize,     // deprecated
     SetWindowSize,     // deprecated
     GetWindowPosition, // deprecated
     SetWindowPosition, // deprecated
     GetWindowRect,
     SetWindowRect,
     MinimizeWindow,
--- a/testing/webdriver/src/response.rs
+++ b/testing/webdriver/src/response.rs
@@ -1,15 +1,16 @@
 use crate::common::Cookie;
 use serde::ser::{Serialize, Serializer};
 use serde_json::Value;
 
 #[derive(Debug, PartialEq, Serialize)]
 #[serde(untagged, remote = "Self")]
 pub enum WebDriverResponse {
+    NewWindow(NewWindowResponse),
     CloseWindow(CloseWindowResponse),
     Cookie(CookieResponse),
     Cookies(CookiesResponse),
     DeleteSession,
     ElementRect(ElementRectResponse),
     Generic(ValueResponse),
     NewSession(NewSessionResponse),
     Timeouts(TimeoutsResponse),
@@ -28,16 +29,23 @@ impl Serialize for WebDriverResponse {
             value: &'a WebDriverResponse,
         }
 
         Wrapper { value: self }.serialize(serializer)
     }
 }
 
 #[derive(Debug, PartialEq, Serialize)]
+pub struct NewWindowResponse {
+    pub handle: String,
+    #[serde(rename = "type")]
+    pub typ: String,
+}
+
+#[derive(Debug, PartialEq, Serialize)]
 pub struct CloseWindowResponse(pub Vec<String>);
 
 #[derive(Clone, Debug, PartialEq, Serialize)]
 pub struct CookieResponse(pub Cookie);
 
 #[derive(Debug, PartialEq, Serialize)]
 pub struct CookiesResponse(pub Vec<Cookie>);
 
@@ -129,16 +137,27 @@ pub struct WindowRectResponse {
 #[cfg(test)]
 mod tests {
     use super::*;
     use crate::common::Date;
     use crate::test::check_serialize;
     use serde_json;
 
     #[test]
+    fn test_json_new_window_response() {
+        let json = r#"{"value":{"handle":"42","type":"window"}}"#;
+        let data = WebDriverResponse::NewWindow(NewWindowResponse {
+            handle: "42".into(),
+            typ: "window".into(),
+        });
+
+        check_serialize(&json, &data);
+    }
+
+    #[test]
     fn test_json_close_window_response() {
         let json = r#"{"value":["1234"]}"#;
         let data = WebDriverResponse::CloseWindow(CloseWindowResponse(vec!["1234".into()]));
 
         check_serialize(&json, &data);
     }
 
     #[test]