webdriver: Simplify Responses for Rect type calls to use same struct and impl (#101)
authorDavid Burns <david.burns@theautomatedtester.co.uk>
Thu, 15 Jun 2017 15:05:39 +0100
changeset 428153 4370e7c6af136ae51159bd1716b25c043a9241f5
parent 428152 2ec39a37b289376c8d796725b0007eae52c5a88b
child 428154 ac919ddfbcc3db7ca10c0d5219caea795527e79e
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: Simplify Responses for Rect type calls to use same struct and impl (#101) This merges the WindowRectResponse and ElementRectResponse into a single struct. It also moves the types in the struct to floats which aligns with the WebDriver specification as in https://w3c.github.io/webdriver/webdriver-spec.html#get-element-rect and in https://w3c.github.io/webdriver/webdriver-spec.html#dfn-window-rect. Source-Repo: https://github.com/mozilla/webdriver-rust Source-Revision: 1c59375428214f3f8e2d61b1bee6182a8eaca5f8 committer: Andreas Tolfsen <ato@mozilla.com>
testing/webdriver/src/response.rs
--- a/testing/webdriver/src/response.rs
+++ b/testing/webdriver/src/response.rs
@@ -4,22 +4,22 @@ use common::{Nullable, Date};
 use cookie;
 use time;
 
 #[derive(Debug)]
 pub enum WebDriverResponse {
     CloseWindow(CloseWindowResponse),
     Cookie(CookieResponse),
     DeleteSession,
-    ElementRect(ElementRectResponse),
+    ElementRect(RectResponse),
     Generic(ValueResponse),
     NewSession(NewSessionResponse),
     Timeouts(TimeoutsResponse),
     Void,
-    WindowRect(WindowRectResponse),
+    WindowRect(RectResponse),
 }
 
 impl WebDriverResponse {
     pub fn to_json_string(self) -> String {
         let obj = match self {
             WebDriverResponse::CloseWindow(ref x) => json::encode(&x.to_json()),
             WebDriverResponse::Cookie(ref x) => json::encode(x),
             WebDriverResponse::DeleteSession => Ok("{}".to_string()),
@@ -106,34 +106,26 @@ impl ValueResponse {
     pub fn new(value: json::Json) -> ValueResponse {
         ValueResponse {
             value: value
         }
     }
 }
 
 #[derive(RustcEncodable, Debug)]
-pub struct WindowRectResponse {
-    pub x: i64,
-    pub y: i64,
-    pub width: u64,
-    pub height: u64,
-}
-
-#[derive(RustcEncodable, Debug)]
-pub struct ElementRectResponse {
+pub struct RectResponse {
     pub x: f64,
     pub y: f64,
     pub width: f64,
     pub height: f64
 }
 
-impl ElementRectResponse {
-    pub fn new(x: f64, y: f64, width: f64, height: f64) -> ElementRectResponse {
-        ElementRectResponse {
+impl RectResponse {
+    pub fn new(x: f64, y: f64, width: f64, height: f64) -> RectResponse {
+        RectResponse {
             x: x,
             y: y,
             width: width,
             height: height
         }
     }
 }
 
@@ -203,21 +195,20 @@ impl CookieResponse {
 
 #[cfg(test)]
 mod tests {
     use std::collections::BTreeMap;
     use rustc_serialize::json::Json;
     use super::{WebDriverResponse,
                 CloseWindowResponse,
                 CookieResponse,
-                ElementRectResponse,
+                RectResponse,
                 NewSessionResponse,
                 ValueResponse,
                 TimeoutsResponse,
-                WindowRectResponse,
                 Cookie,
                 Nullable};
 
     fn test(resp: WebDriverResponse, expected_str: &str) {
         let data = resp.to_json_string();
         let actual = Json::from_str(&*data).unwrap();
         let expected = Json::from_str(expected_str).unwrap();
         assert_eq!(actual, expected);
@@ -245,31 +236,31 @@ mod tests {
             ]));
         let expected = r#"{"value": [{"name": "test", "value": "test_value", "path": "/",
 "domain": null, "expiry": null, "secure": true, "httpOnly": false}]}"#;
         test(resp, expected);
     }
 
     #[test]
     fn test_element_rect() {
-        let resp = WebDriverResponse::ElementRect(ElementRectResponse::new(
+        let resp = WebDriverResponse::ElementRect(RectResponse::new(
             0f64, 1f64, 2f64, 3f64));
         let expected = r#"{"value": {"x": 0.0, "y": 1.0, "width": 2.0, "height": 3.0}}"#;
         test(resp, expected);
     }
 
     #[test]
     fn test_window_rect() {
-        let resp = WebDriverResponse::WindowRect(WindowRectResponse {
-            x: 0i64,
-            y: 1i64,
-            width: 2u64,
-            height: 3u64,
+        let resp = WebDriverResponse::WindowRect(RectResponse {
+            x: 0f64,
+            y: 1f64,
+            width: 2f64,
+            height: 3f64,
         });
-        let expected = r#"{"value": {"x": 0, "y": 1, "width": 2, "height": 3}}"#;
+        let expected = r#"{"value": {"x": 0.0, "y": 1.0, "width": 2.0, "height": 3.0}}"#;
         test(resp, expected);
     }
 
     #[test]
     fn test_new_session() {
         let resp = WebDriverResponse::NewSession(
             NewSessionResponse::new("test".into(),
                                     Json::Object(BTreeMap::new())));