webdriver: Merge pull request #72 from andreastt/set-timeouts-format
authorAndreas Tolfsen <ato@mozilla.com>
Fri, 24 Feb 2017 16:27:17 +0000
changeset 428113 ce6ce5a7e4853f1f5c3b6733369720e3b76cdf8c
parent 428112 80e0fe063f153b8992dd5e302e93ae7557cb86b9
child 428114 754c742e9d9ae772ea210c4e1760099bc671ccee
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone57.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
webdriver: Merge pull request #72 from andreastt/set-timeouts-format Align timeouts format with spec Source-Repo: https://github.com/mozilla/webdriver-rust Source-Revision: 426ea889f298133c12bdd9a4b107f130d18ac592
testing/webdriver/src/command.rs
testing/webdriver/src/response.rs
--- a/testing/webdriver/src/command.rs
+++ b/testing/webdriver/src/command.rs
@@ -517,49 +517,74 @@ impl ToJson for GetParameters {
         let mut data = BTreeMap::new();
         data.insert("url".to_string(), self.url.to_json());
         Json::Object(data)
     }
 }
 
 #[derive(PartialEq)]
 pub struct TimeoutsParameters {
-    pub type_: String,
-    pub ms: f64
+    pub script: Option<u64>,
+    pub page_load: Option<u64>,
+    pub implicit: Option<u64>,
 }
 
 impl Parameters for TimeoutsParameters {
     fn from_json(body: &Json) -> WebDriverResult<TimeoutsParameters> {
-        let data = try_opt!(body.as_object(), ErrorStatus::UnknownError,
+        let data = try_opt!(body.as_object(),
+                            ErrorStatus::UnknownError,
                             "Message body was not an object");
-        let type_ = try_opt!(
-            try_opt!(data.get("type"),
-                     ErrorStatus::InvalidArgument,
-                     "Missing 'type' parameter").as_string(),
-            ErrorStatus::InvalidArgument,
-            "'type' not a string");
+
+        let script = match data.get("script") {
+            Some(json) => {
+                Some(try_opt!(json.as_u64(),
+                              ErrorStatus::InvalidArgument,
+                              "Script timeout duration was not a signed integer"))
+            }
+            None => None,
+        };
 
-        let ms = try_opt!(
-            try_opt!(data.get("ms"),
-                     ErrorStatus::InvalidArgument,
-                     "Missing 'ms' parameter").as_f64(),
-            ErrorStatus::InvalidArgument,
-            "'ms' not a float");
-        return Ok(TimeoutsParameters {
-            type_: type_.to_string(),
-            ms: ms
+        let page_load = match data.get("pageLoad") {
+            Some(json) => {
+                Some(try_opt!(json.as_u64(),
+                              ErrorStatus::InvalidArgument,
+                              "Script timeout duration was not a signed integer"))
+            }
+            None => None,
+        };
+
+        let implicit = match data.get("script") {
+            Some(json) => {
+                Some(try_opt!(json.as_u64(),
+                              ErrorStatus::InvalidArgument,
+                              "Script timeout duration was not a signed integer"))
+            }
+            None => None,
+        };
+
+        Ok(TimeoutsParameters {
+            script: script,
+            page_load: page_load,
+            implicit: implicit,
         })
     }
 }
 
 impl ToJson for TimeoutsParameters {
     fn to_json(&self) -> Json {
         let mut data = BTreeMap::new();
-        data.insert("type".to_string(), self.type_.to_json());
-        data.insert("ms".to_string(), self.ms.to_json());
+        if let Some(ms) = self.script {
+            data.insert("script".into(), ms.to_json());
+        }
+        if let Some(ms) = self.page_load {
+            data.insert("pageLoad".into(), ms.to_json());
+        }
+        if let Some(ms) = self.implicit {
+            data.insert("implicit".into(), ms.to_json());
+        }
         Json::Object(data)
     }
 }
 
 #[derive(PartialEq)]
 pub struct WindowSizeParameters {
     pub width: u64,
     pub height: u64,
--- a/testing/webdriver/src/response.rs
+++ b/testing/webdriver/src/response.rs
@@ -7,30 +7,32 @@ use time;
 #[derive(Debug)]
 pub enum WebDriverResponse {
     CloseWindow(CloseWindowResponse),
     Cookie(CookieResponse),
     DeleteSession,
     ElementRect(ElementRectResponse),
     Generic(ValueResponse),
     NewSession(NewSessionResponse),
+    Timeouts(TimeoutsResponse),
     Void,
     WindowPosition(WindowPositionResponse),
     WindowSize(WindowSizeResponse),
 }
 
 impl WebDriverResponse {
     pub fn to_json_string(self) -> String {
         match self {
             WebDriverResponse::CloseWindow(x) => json::encode(&x),
             WebDriverResponse::Cookie(x) => json::encode(&x),
             WebDriverResponse::DeleteSession => Ok("{}".to_string()),
             WebDriverResponse::ElementRect(x) => json::encode(&x),
             WebDriverResponse::Generic(x) => json::encode(&x),
             WebDriverResponse::NewSession(x) => json::encode(&x),
+            WebDriverResponse::Timeouts(x) => json::encode(&x),
             WebDriverResponse::Void => Ok("{}".to_string()),
             WebDriverResponse::WindowPosition(x) => json::encode(&x),
             WebDriverResponse::WindowSize(x) => json::encode(&x),
         }.unwrap()
     }
 }
 
 #[derive(RustcEncodable, Debug)]
@@ -55,16 +57,23 @@ impl NewSessionResponse {
         NewSessionResponse {
             value: value,
             sessionId: session_id
         }
     }
 }
 
 #[derive(RustcEncodable, Debug)]
+pub struct TimeoutsResponse {
+    pub script: u64,
+    pub pageLoad: u64,
+    pub implicit: u64,
+}
+
+#[derive(RustcEncodable, Debug)]
 pub struct ValueResponse {
     pub value: json::Json
 }
 
 impl ValueResponse {
     pub fn new(value: json::Json) -> ValueResponse {
         ValueResponse {
             value: value