Bug 1529289 - Add web frame and web window types to web webdriver Rust crate. r=ato
authorNupur Baghel <nupurbaghel@gmail.com>
Sat, 09 Mar 2019 14:09:48 +0000
changeset 521264 654492de5212c9ee50796d77c62287b0db26424d
parent 521263 c7d8b2c0ada2332e724fc8940d6fb2f38cfc63e0
child 521265 5bc7479ef4a1d60e014bfe4759374d2d00e53ffb
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1529289
milestone67.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 1529289 - Add web frame and web window types to web webdriver Rust crate. r=ato Differential Revision: https://phabricator.services.mozilla.com/D22842
testing/webdriver/src/common.rs
--- a/testing/webdriver/src/common.rs
+++ b/testing/webdriver/src/common.rs
@@ -85,16 +85,72 @@ impl<'de> Deserialize<'de> for WebElemen
 }
 
 impl WebElement {
     pub fn to_string(&self) -> String {
         self.0.clone()
     }
 }
 
+#[derive(Clone, Debug, PartialEq)]
+pub struct WebFrame(pub String);
+
+// private
+#[derive(Serialize, Deserialize)]
+struct WebFrameObject {
+    #[serde(rename = "frame-075b-4da1-b6ba-e579c2d3230a")]
+    id: String,
+}
+
+impl Serialize for WebFrame {
+    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+    where
+        S: Serializer,
+    {
+        WebFrameObject { id: self.0.clone() }.serialize(serializer)
+    }
+}
+
+impl<'de> Deserialize<'de> for WebFrame {
+    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+    where
+        D: Deserializer<'de>,
+    {
+        Deserialize::deserialize(deserializer).map(|WebFrameObject { id }| WebFrame(id))
+    }
+}
+
+#[derive(Clone, Debug, PartialEq)]
+pub struct WebWindow(pub String);
+
+// private
+#[derive(Serialize, Deserialize)]
+struct WebWindowObject {
+    #[serde(rename = "window-fcc6-11e5-b4f8-330a88ab9d7f")]
+    id: String,
+}
+
+impl Serialize for WebWindow {
+    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+    where
+        S: Serializer,
+    {
+        WebWindowObject { id: self.0.clone() }.serialize(serializer)
+    }
+}
+
+impl<'de> Deserialize<'de> for WebWindow {
+    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+    where
+        D: Deserializer<'de>,
+    {
+        Deserialize::deserialize(deserializer).map(|WebWindowObject { id }| WebWindow(id))
+    }
+}
+
 #[cfg(test)]
 mod tests {
     use super::*;
     use crate::test::{check_serialize, check_serialize_deserialize};
     use serde_json;
 
     #[test]
     fn test_json_date() {
@@ -186,9 +242,37 @@ mod tests {
         check_serialize_deserialize(&json, &data);
     }
 
     #[test]
     fn test_json_webelement_invalid() {
         let data = r#"{"elem-6066-11e4-a52e-4f735466cecf":"elem"}"#;
         assert!(serde_json::from_str::<WebElement>(&data).is_err());
     }
+
+    #[test]
+    fn test_json_webframe() {
+        let json = r#"{"frame-075b-4da1-b6ba-e579c2d3230a":"frm"}"#;
+        let data = WebFrame("frm".into());
+
+        check_serialize_deserialize(&json, &data);
+    }
+
+    #[test]
+    fn test_json_webframe_invalid() {
+        let data = r#"{"frm-075b-4da1-b6ba-e579c2d3230a":"frm"}"#;
+        assert!(serde_json::from_str::<WebFrame>(&data).is_err());
+    }
+
+    #[test]
+    fn test_json_webwindow() {
+        let json = r#"{"window-fcc6-11e5-b4f8-330a88ab9d7f":"window"}"#;
+        let data = WebWindow("window".into());
+
+        check_serialize_deserialize(&json, &data);
+    }
+
+    #[test]
+    fn test_json_webwindow_invalid() {
+        let data = r#"{""wind-fcc6-11e5-b4f8-330a88ab9d7f":"window"}"#;
+        assert!(serde_json::from_str::<WebWindow>(&data).is_err());
+    }
 }