webdriver: response: add WindowRectResponse and remove WindowPosition/WindowSize
authorAndreas Tolfsen <ato@mozilla.com>
Fri, 24 Mar 2017 15:40:56 +0000
changeset 428131 89d24fe294e00f2c3b64f5243fc2ffc209828dcc
parent 428130 5cd31994a52b49a383802eab478f2d2c1e9246d6
child 428132 f961322f2e2fab9f0f544ecb25aaf1e8ab4ff9a5
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: response: add WindowRectResponse and remove WindowPosition/WindowSize Source-Repo: https://github.com/mozilla/webdriver-rust Source-Revision: 4df53e9535c9bc3787f87438cc2eadbdc8bea268 committer: jgraham <james@hoppipolla.co.uk>
testing/webdriver/src/response.rs
--- a/testing/webdriver/src/response.rs
+++ b/testing/webdriver/src/response.rs
@@ -9,33 +9,31 @@ pub enum WebDriverResponse {
     CloseWindow(CloseWindowResponse),
     Cookie(CookieResponse),
     DeleteSession,
     ElementRect(ElementRectResponse),
     Generic(ValueResponse),
     NewSession(NewSessionResponse),
     Timeouts(TimeoutsResponse),
     Void,
-    WindowPosition(WindowPositionResponse),
-    WindowSize(WindowSizeResponse),
+    WindowRect(WindowRectResponse),
 }
 
 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()),
             WebDriverResponse::ElementRect(ref x) => json::encode(x),
             WebDriverResponse::Generic(ref x) => json::encode(x),
             WebDriverResponse::NewSession(ref x) => json::encode(x),
             WebDriverResponse::Timeouts(ref x) => json::encode(x),
             WebDriverResponse::Void => Ok("{}".to_string()),
-            WebDriverResponse::WindowPosition(ref x) => json::encode(x),
-            WebDriverResponse::WindowSize(ref x) => json::encode(x),
+            WebDriverResponse::WindowRect(ref x) => json::encode(x),
         }.unwrap();
 
         match self {
             WebDriverResponse::Generic(_) |
             WebDriverResponse::Cookie(_) => obj,
             _ => {
                 let mut data = String::with_capacity(11 + obj.len());
                 data.push_str("{\"value\": ");
@@ -108,40 +106,21 @@ impl ValueResponse {
     pub fn new(value: json::Json) -> ValueResponse {
         ValueResponse {
             value: value
         }
     }
 }
 
 #[derive(RustcEncodable, Debug)]
-pub struct WindowSizeResponse {
-    pub width: u64,
-    pub height: u64
-}
-
-impl WindowSizeResponse {
-    pub fn new(width: u64, height: u64) -> WindowSizeResponse {
-        WindowSizeResponse {
-            width: width,
-            height: height
-        }
-    }
-}
-
-#[derive(RustcEncodable, Debug)]
-pub struct WindowPositionResponse {
+pub struct WindowRectResponse {
     pub x: i64,
     pub y: i64,
-}
-
-impl WindowPositionResponse {
-    pub fn new(x: i64, y: i64) -> WindowPositionResponse {
-        WindowPositionResponse { x: x, y: y }
-    }
+    pub width: u64,
+    pub height: u64,
 }
 
 #[derive(RustcEncodable, Debug)]
 pub struct ElementRectResponse {
     pub x: f64,
     pub y: f64,
     pub width: f64,
     pub height: f64
@@ -228,18 +207,17 @@ mod tests {
     use rustc_serialize::json::Json;
     use super::{WebDriverResponse,
                 CloseWindowResponse,
                 CookieResponse,
                 ElementRectResponse,
                 NewSessionResponse,
                 ValueResponse,
                 TimeoutsResponse,
-                WindowPositionResponse,
-                WindowSizeResponse,
+                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);
@@ -274,16 +252,28 @@ mod tests {
     fn test_element_rect() {
         let resp = WebDriverResponse::ElementRect(ElementRectResponse::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 expected = r#"{"value": {"x": 0, "y": 1, "width": 2, "height": 3}}"#;
+        test(resp, expected);
+    }
+
+    #[test]
     fn test_new_session() {
         let resp = WebDriverResponse::NewSession(
             NewSessionResponse::new("test".into(),
                                     Json::Object(BTreeMap::new())));
         let expected = r#"{"value": {"sessionId": "test", "capabilities": {}}}"#;
         test(resp, expected);
     }
 
@@ -299,25 +289,9 @@ mod tests {
     fn test_value() {
         let mut value = BTreeMap::new();
         value.insert("example".into(), Json::Array(vec![Json::String("test".into())]));
         let resp = WebDriverResponse::Generic(ValueResponse::new(
             Json::Object(value)));
         let expected = r#"{"value": {"example": ["test"]}}"#;
         test(resp, expected);
     }
-
-    #[test]
-    fn test_window_position() {
-         let resp = WebDriverResponse::WindowPosition(WindowPositionResponse::new(
-            1, 2));
-        let expected = r#"{"value": {"x": 1, "y": 2}}"#;
-        test(resp, expected);
-    }
-
-    #[test]
-    fn test_window_size() {
-         let resp = WebDriverResponse::WindowSize(WindowSizeResponse::new(
-            1, 2));
-        let expected = r#"{"value": {"width": 1, "height": 2}}"#;
-        test(resp, expected);
-    }
 }