Bug 1507283 - [geckodriver] Relax deserialization of timeouts parameters. r=ato
authorHenrik Skupin <mail@hskupin.info>
Fri, 25 Jan 2019 19:54:53 +0000
changeset 515504 8c311adb2434ba9fddc61b8f80cb787392e56050
parent 515503 98859fd44b4132b42d9c4f237e58954907015264
child 515505 4be8f5920abed49744da0df35400b1ac00c5c50c
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1507283, 1396821
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 1507283 - [geckodriver] Relax deserialization of timeouts parameters. r=ato It fixes the regression from the transition to Serde (bug 1396821), which accidentally denied unknown fields. Differential Revision: https://phabricator.services.mozilla.com/D17634
testing/webdriver/src/command.rs
--- a/testing/webdriver/src/command.rs
+++ b/testing/webdriver/src/command.rs
@@ -493,17 +493,16 @@ pub struct SwitchToWindowParameters {
 }
 
 #[derive(Debug, PartialEq, Serialize, Deserialize)]
 pub struct TakeScreenshotParameters {
     pub element: Option<WebElement>,
 }
 
 #[derive(Debug, PartialEq, Serialize, Deserialize)]
-#[serde(deny_unknown_fields)]
 pub struct TimeoutsParameters {
     #[serde(
         default, skip_serializing_if = "Option::is_none", deserialize_with = "deserialize_to_u64"
     )]
     pub implicit: Option<u64>,
     #[serde(
         default,
         rename = "pageLoad",
@@ -670,16 +669,24 @@ mod tests {
     fn test_json_action_parameters_empty_list() {
         let json = r#"{"actions":[]}"#;
         let data = ActionsParameters { actions: vec![] };
 
         check_deserialize(&json, &data);
     }
 
     #[test]
+    fn test_json_action_parameters_with_unknown_field() {
+        let json = r#"{"actions":[],"foo":"bar"}"#;
+        let data = ActionsParameters { actions: vec![] };
+
+        check_deserialize(&json, &data);
+    }
+
+    #[test]
     fn test_json_add_cookie_parameters_with_values() {
         let json = r#"{"cookie":{
             "name":"foo",
             "value":"bar",
             "path":"/",
             "domain":"foo.bar",
             "expiry":123,
             "secure":true,
@@ -746,16 +753,38 @@ mod tests {
     #[test]
     fn test_json_add_cookie_parameters_with_invalid_cookie_field() {
         let json = r#"{"name":"foo"}"#;
 
         assert!(serde_json::from_str::<AddCookieParameters>(&json).is_err());
     }
 
     #[test]
+    fn test_json_add_cookie_parameters_with_unknown_field() {
+        let json = r#"{"cookie":{
+            "name":"foo",
+            "value":"bar",
+            "secure":true,
+            "httpOnly":false,
+            "foo":"bar"
+        },"foo":"bar"}"#;
+        let data = AddCookieParameters {
+            name: "foo".into(),
+            value: "bar".into(),
+            path: None,
+            domain: None,
+            expiry: None,
+            secure: true,
+            httpOnly: false,
+        };
+
+        check_deserialize(&json, &data);
+    }
+
+    #[test]
     fn test_json_get_parameters_with_url() {
         let json = r#"{"url":"foo.bar"}"#;
         let data = GetParameters {
             url: "foo.bar".into(),
         };
 
         check_deserialize(&json, &data);
     }
@@ -770,16 +799,26 @@ mod tests {
     #[test]
     fn test_json_get_parameters_with_invalid_url_field() {
         let json = r#"{"foo":"bar"}"#;
 
         assert!(serde_json::from_str::<GetParameters>(&json).is_err());
     }
 
     #[test]
+    fn test_json_get_parameters_with_unknown_field() {
+        let json = r#"{"url":"foo.bar","foo":"bar"}"#;
+        let data = GetParameters {
+            url: "foo.bar".into(),
+        };
+
+        check_deserialize(&json, &data);
+    }
+
+    #[test]
     fn test_json_get_named_cookie_parameters_with_value() {
         let json = r#"{"name":"foo"}"#;
         let data = GetNamedCookieParameters {
             name: Some("foo".into()),
         };
 
         check_deserialize(&json, &data);
     }
@@ -803,16 +842,26 @@ mod tests {
     #[test]
     fn test_json_get_named_cookie_parameters_with_invalid_name_field() {
         let json = r#"{"name":3"#;
 
         assert!(serde_json::from_str::<GetNamedCookieParameters>(&json).is_err());
     }
 
     #[test]
+    fn test_json_get_named_cookie_parameters_with_unknown_field() {
+        let json = r#"{"name":"foo","foo":"bar"}"#;
+        let data = GetNamedCookieParameters {
+            name: Some("foo".into()),
+        };
+
+        check_deserialize(&json, &data);
+    }
+
+    #[test]
     fn test_json_javascript_command_parameters_with_values() {
         let json = r#"{"script":"foo","args":["1",2]}"#;
         let data = JavascriptCommandParameters {
             script: "foo".into(),
             args: Some(vec!["1".into(), 2.into()]),
         };
 
         check_deserialize(&json, &data);
@@ -857,16 +906,27 @@ mod tests {
     #[test]
     fn test_json_javascript_command_parameters_missing_script_field() {
         let json = r#"{"args":null}"#;
 
         assert!(serde_json::from_str::<JavascriptCommandParameters>(&json).is_err());
     }
 
     #[test]
+    fn test_json_javascript_command_parameters_with_unknown_field() {
+        let json = r#"{"script":"foo","foo":"bar"}"#;
+        let data = JavascriptCommandParameters {
+            script: "foo".into(),
+            args: None,
+        };
+
+        check_deserialize(&json, &data);
+    }
+
+    #[test]
     fn test_json_locator_parameters_with_values() {
         let json = r#"{"using":"xpath","value":"bar"}"#;
         let data = LocatorParameters {
             using: LocatorStrategy::XPath,
             value: "bar".into(),
         };
 
         check_deserialize(&json, &data);
@@ -896,16 +956,27 @@ mod tests {
     #[test]
     fn test_json_locator_parameters_missing_value_field() {
         let json = r#"{"using":"xpath"}"#;
 
         assert!(serde_json::from_str::<LocatorParameters>(&json).is_err());
     }
 
     #[test]
+    fn test_json_locator_parameters_with_unknown_field() {
+        let json = r#"{"using":"xpath","value":"bar","foo":"bar"}"#;
+        let data = LocatorParameters {
+            using: LocatorStrategy::XPath,
+            value: "bar".into(),
+        };
+
+        check_deserialize(&json, &data);
+    }
+
+    #[test]
     fn test_json_new_session_parameters_spec() {
         let json = r#"{"capabilities":{"alwaysMatch":{},"firstMatch":[{}]}}"#;
         let data = NewSessionParameters::Spec(SpecNewSessionParameters {
             alwaysMatch: Capabilities::new(),
             firstMatch: vec![Capabilities::new()],
         });
 
         check_deserialize(&json, &data);
@@ -943,16 +1014,32 @@ mod tests {
             alwaysMatch: Capabilities::new(),
             firstMatch: vec![Capabilities::new()],
         });
 
         check_deserialize(&json, &data);
     }
 
     #[test]
+    fn test_json_new_session_parameters_with_unknown_field() {
+        let json = r#"{
+            "capabilities":{
+                "alwaysMatch":{},
+                "firstMatch":[{}]
+            },
+            "foo":"bar"}"#;
+        let data = NewSessionParameters::Spec(SpecNewSessionParameters {
+            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]
@@ -982,16 +1069,26 @@ mod tests {
     #[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_new_window_parameters_with_unknown_field() {
+        let json = r#"{"type":"tab","foo":"bar"}"#;
+        let data = NewWindowParameters {
+            type_hint: Some("tab".into())
+        };
+
+        check_deserialize(&json, &data);
+    }
+
+    #[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]
@@ -1004,16 +1101,24 @@ mod tests {
     #[test]
     fn test_json_send_keys_parameters_missing_text_field() {
         let json = r#"{}"#;
 
         assert!(serde_json::from_str::<SendKeysParameters>(&json).is_err());
     }
 
     #[test]
+    fn test_json_send_keys_parameters_with_unknown_field() {
+        let json = r#"{"text":"foo","foo":"bar"}"#;
+        let data = SendKeysParameters { text: "foo".into() };
+
+        check_deserialize(&json, &data);
+    }
+
+    #[test]
     fn test_json_switch_to_frame_parameters_with_value() {
         let json = r#"{"id":3}"#;
         let data = SwitchToFrameParameters {
             id: Some(FrameId::Short(3)),
         };
 
         check_deserialize(&json, &data);
     }
@@ -1037,16 +1142,26 @@ mod tests {
     #[test]
     fn test_json_switch_to_frame_parameters_with_invalid_id_field() {
         let json = r#"{"id":"3"}"#;
 
         assert!(serde_json::from_str::<SwitchToFrameParameters>(&json).is_err());
     }
 
     #[test]
+    fn test_json_switch_to_frame_parameters_with_unknown_field() {
+        let json = r#"{"id":3,"foo":"bar"}"#;
+        let data = SwitchToFrameParameters {
+            id: Some(FrameId::Short(3)),
+        };
+
+        check_deserialize(&json, &data);
+    }
+
+    #[test]
     fn test_json_switch_to_window_parameters_with_value() {
         let json = r#"{"handle":"foo"}"#;
         let data = SwitchToWindowParameters {
             handle: "foo".into(),
         };
 
         check_deserialize(&json, &data);
     }
@@ -1061,16 +1176,26 @@ mod tests {
     #[test]
     fn test_json_switch_to_window_parameters_missing_handle_field() {
         let json = r#"{}"#;
 
         assert!(serde_json::from_str::<SwitchToWindowParameters>(&json).is_err());
     }
 
     #[test]
+    fn test_json_switch_to_window_parameters_with_unknown_field() {
+        let json = r#"{"handle":"foo","foo":"bar"}"#;
+        let data = SwitchToWindowParameters {
+            handle: "foo".into(),
+        };
+
+        check_deserialize(&json, &data);
+    }
+
+    #[test]
     fn test_json_take_screenshot_parameters_with_element() {
         let json = r#"{"element":{"element-6066-11e4-a52e-4f735466cecf":"elem"}}"#;
         let data = TakeScreenshotParameters {
             element: Some(WebElement::new("elem".into())),
         };
 
         check_deserialize(&json, &data);
     }
@@ -1093,16 +1218,26 @@ mod tests {
 
     #[test]
     fn test_json_take_screenshot_parameters_with_invalid_element_field() {
         let json = r#"{"element":"foo"}"#;
         assert!(serde_json::from_str::<TakeScreenshotParameters>(&json).is_err());
     }
 
     #[test]
+    fn test_json_take_screenshot_parameters_with_unknown_field() {
+        let json = r#"{"element":{"element-6066-11e4-a52e-4f735466cecf":"elem"},"foo":"bar"}"#;
+        let data = TakeScreenshotParameters {
+            element: Some(WebElement::new("elem".into())),
+        };
+
+        check_deserialize(&json, &data);
+    }
+
+    #[test]
     fn test_json_timeout_parameters_with_values() {
         let json = r#"{"implicit":0,"pageLoad":2.0,"script":9007199254740991}"#;
         let data = TimeoutsParameters {
             implicit: Some(0u64),
             page_load: Some(2u64),
             script: Some(Some(9007199254740991u64)),
         };
 
@@ -1130,16 +1265,28 @@ mod tests {
             page_load: None,
             script: None,
         };
 
         check_deserialize(&json, &data);
     }
 
     #[test]
+    fn test_json_timeout_parameters_with_unknown_field() {
+        let json = r#"{"script":60000,"foo":"bar"}"#;
+        let data = TimeoutsParameters {
+            implicit: None,
+            page_load: None,
+            script: Some(Some(60000)),
+        };
+
+        check_deserialize(&json, &data);
+    }
+
+    #[test]
     fn test_json_window_rect_parameters_with_values() {
         let json = r#"{"x":0,"y":1,"width":2,"height":3}"#;
         let data = WindowRectParameters {
             x: Some(0i32),
             y: Some(1i32),
             width: Some(2i32),
             height: Some(3i32),
         };
@@ -1180,9 +1327,22 @@ mod tests {
             x: Some(1),
             y: Some(2),
             width: Some(3),
             height: Some(4),
         };
 
         check_deserialize(&json, &data);
     }
+
+    #[test]
+    fn test_json_window_rect_parameters_with_unknown_field() {
+        let json = r#"{"x":1.1,"y":2.2,"foo":"bar"}"#;
+        let data = WindowRectParameters {
+            x: Some(1),
+            y: Some(2),
+            width: None,
+            height: None,
+        };
+
+        check_deserialize(&json, &data);
+    }
 }