Bug 1470659 - Add setWindowRect capability to geckodriver. r=automatedtester
authorAndreas Tolfsen <ato@sny.no>
Sat, 21 Jul 2018 18:32:01 +0100
changeset 825615 e99e43a1e400b532ae84c36519da8e0cbc7143ac
parent 825614 203d1449aa592dfa527ed6e7a79d07dcaad8018f
child 825616 a3d141d56e531d882111ccf569c76427091ed088
push id118150
push usermaglione.k@gmail.com
push dateThu, 02 Aug 2018 04:47:08 +0000
reviewersautomatedtester
bugs1470659
milestone63.0a1
Bug 1470659 - Add setWindowRect capability to geckodriver. r=automatedtester It will never be possible to configure setWindowRect, and trying to do so will cause geckodriver to return with an error.
testing/geckodriver/src/capabilities.rs
testing/webdriver/src/capabilities.rs
--- a/testing/geckodriver/src/capabilities.rs
+++ b/testing/geckodriver/src/capabilities.rs
@@ -136,16 +136,20 @@ impl<'a> BrowserCapabilities for Firefox
         let version_str = self.version();
         if let Some(x) = version_str {
             Ok(try!(Version::from_str(&*x).or_else(|x| Err(convert_version_error(x)))).major >= 52)
         } else {
             Ok(false)
         }
     }
 
+    fn set_window_rect(&mut self, _: &Capabilities) -> WebDriverResult<bool> {
+        Ok(true)
+    }
+
     fn compare_browser_version(&mut self,
                                version: &str,
                                comparison: &str)
                                -> WebDriverResult<bool> {
         try!(Version::from_str(version).or_else(|x| Err(convert_version_error(x))))
             .matches(comparison)
             .or_else(|x| Err(convert_version_error(x)))
     }
--- a/testing/webdriver/src/capabilities.rs
+++ b/testing/webdriver/src/capabilities.rs
@@ -4,54 +4,74 @@ use rustc_serialize::json::{Json, ToJson
 use std::collections::BTreeMap;
 use url::Url;
 
 pub type Capabilities = BTreeMap<String, Json>;
 
 /// Trait for objects that can be used to inspect browser capabilities
 ///
 /// The main methods in this trait are called with a Capabilites object
-/// resulting from a full set of potential capabilites for the session.
-/// Given those Capabilities they return a property of the browser instance
-/// that would be initiated. In many cases this will be independent of the
-/// input, but in the case of e.g. browser version, it might depend on a
-/// path to the binary provided as a capability.
+/// resulting from a full set of potential capabilites for the session.  Given
+/// those Capabilities they return a property of the browser instance that
+/// would be initiated. In many cases this will be independent of the input,
+/// but in the case of e.g. browser version, it might depend on a path to the
+/// binary provided as a capability.
 pub trait BrowserCapabilities {
     /// Set up the Capabilites object
     ///
     /// Typically used to create any internal caches
     fn init(&mut self, &Capabilities);
 
     /// Name of the browser
     fn browser_name(&mut self, &Capabilities) -> WebDriverResult<Option<String>>;
+
     /// Version number of the browser
     fn browser_version(&mut self, &Capabilities) -> WebDriverResult<Option<String>>;
+
     /// Compare actual browser version to that provided in a version specifier
     ///
     /// Parameters are the actual browser version and the comparison string,
-    /// respectively. The format of the comparison string is implementation-defined.
-    fn compare_browser_version(&mut self, version: &str, comparison: &str) -> WebDriverResult<bool>;
+    /// respectively. The format of the comparison string is
+    /// implementation-defined.
+    fn compare_browser_version(&mut self, version: &str, comparison: &str)
+        -> WebDriverResult<bool>;
+
     /// Name of the platform/OS
     fn platform_name(&mut self, &Capabilities) -> WebDriverResult<Option<String>>;
+
     /// Whether insecure certificates are supported
     fn accept_insecure_certs(&mut self, &Capabilities) -> WebDriverResult<bool>;
 
-    fn accept_proxy(&mut self, proxy_settings: &BTreeMap<String, Json>, &Capabilities) -> WebDriverResult<bool>;
+    /// Indicates whether driver supports all of the window resizing and
+    /// repositioning commands.
+    fn set_window_rect(&mut self, &Capabilities) -> WebDriverResult<bool>;
+
+    fn accept_proxy(
+        &mut self,
+        proxy_settings: &BTreeMap<String, Json>,
+        &Capabilities,
+    ) -> WebDriverResult<bool>;
 
     /// Type check custom properties
     ///
     /// Check that custom properties containing ":" have the correct data types.
     /// Properties that are unrecognised must be ignored i.e. return without
     /// error.
     fn validate_custom(&self, name: &str, value: &Json) -> WebDriverResult<()>;
+
     /// Check if custom properties are accepted capabilites
     ///
     /// Check that custom properties containing ":" are compatible with
     /// the implementation.
-    fn accept_custom(&mut self, name: &str, value: &Json, merged: &Capabilities) -> WebDriverResult<bool>;
+    fn accept_custom(
+        &mut self,
+        name: &str,
+        value: &Json,
+        merged: &Capabilities,
+    ) -> WebDriverResult<bool>;
 }
 
 /// Trait to abstract over various version of the new session parameters
 ///
 /// This trait is expected to be implemented on objects holding the capabilities
 /// from a new session command.
 pub trait CapabilitiesMatching {
     /// Match the BrowserCapabilities against some candidate capabilites
@@ -65,59 +85,64 @@ pub trait CapabilitiesMatching {
 
 #[derive(Debug, PartialEq)]
 pub struct SpecNewSessionParameters {
     pub alwaysMatch: Capabilities,
     pub firstMatch: Vec<Capabilities>,
 }
 
 impl SpecNewSessionParameters {
-    fn validate<T: BrowserCapabilities>(&self,
-                                        mut capabilities: Capabilities,
-                                        browser_capabilities: &T) -> WebDriverResult<Capabilities> {
+    fn validate<T: BrowserCapabilities>(
+        &self,
+        mut capabilities: Capabilities,
+        browser_capabilities: &T,
+    ) -> WebDriverResult<Capabilities> {
         // Filter out entries with the value `null`
         let null_entries = capabilities
             .iter()
             .filter(|&(_, ref value)| **value == Json::Null)
             .map(|(k, _)| k.clone())
             .collect::<Vec<String>>();
         for key in null_entries {
             capabilities.remove(&key);
         }
 
         for (key, value) in capabilities.iter() {
             match &**key {
-                "acceptInsecureCerts" => if !value.is_boolean() {
-                        return Err(WebDriverError::new(ErrorStatus::InvalidArgument,
-                                                       format!("acceptInsecureCerts is not boolean: {}", value)))
-                    },
-                x @ "browserName" |
-                x @ "browserVersion" |
-                x @ "platformName" => if !value.is_string() {
-                        return Err(WebDriverError::new(ErrorStatus::InvalidArgument,
-                                                       format!("{} is not a string: {}", x, value)))
-                    },
-                "pageLoadStrategy" => {
-                    try!(SpecNewSessionParameters::validate_page_load_strategy(value))
+                x @ "acceptInsecureCerts" | x @ "setWindowRect" => if !value.is_boolean() {
+                    return Err(WebDriverError::new(
+                        ErrorStatus::InvalidArgument,
+                        format!("{} is not boolean: {}", x, value),
+                    ));
+                },
+                x @ "browserName" | x @ "browserVersion" | x @ "platformName" => {
+                    if !value.is_string() {
+                        return Err(WebDriverError::new(
+                            ErrorStatus::InvalidArgument,
+                            format!("{} is not a string: {}", x, value),
+                        ));
+                    }
                 }
-                "proxy" => {
-                    try!(SpecNewSessionParameters::validate_proxy(value))
-                },
-                "timeouts" => {
-                    try!(SpecNewSessionParameters::validate_timeouts(value))
-                },
+                "pageLoadStrategy" => SpecNewSessionParameters::validate_page_load_strategy(value)?,
+                "proxy" => SpecNewSessionParameters::validate_proxy(value)?,
+                "timeouts" => SpecNewSessionParameters::validate_timeouts(value)?,
                 "unhandledPromptBehavior" => {
-                    try!(SpecNewSessionParameters::validate_unhandled_prompt_behaviour(value))
+                    SpecNewSessionParameters::validate_unhandled_prompt_behaviour(value)?
                 }
                 x => {
                     if !x.contains(":") {
-                        return Err(WebDriverError::new(ErrorStatus::InvalidArgument,
-                                                       format!("{} is not the name of a known capability or extension capability", x)))
+                        return Err(WebDriverError::new(
+                            ErrorStatus::InvalidArgument,
+                            format!(
+                                "{} is not the name of a known capability or extension capability",
+                                x
+                            ),
+                        ));
                     } else {
-                        try!(browser_capabilities.validate_custom(x, value));
+                        browser_capabilities.validate_custom(x, value)?
                     }
                 }
             }
         }
         Ok(capabilities)
     }
 
     fn validate_page_load_strategy(value: &Json) -> WebDriverResult<()> {
@@ -453,16 +478,25 @@ impl CapabilitiesMatching for SpecNewSes
                             if value.as_boolean().unwrap_or(false) &&
                                 !browser_capabilities
                                     .accept_insecure_certs(merged)
                                     .unwrap_or(false)
                             {
                                 return None;
                             }
                         }
+                        "setWindowRect" => {
+                            if value.as_boolean().unwrap_or(false) &&
+                                !browser_capabilities
+                                    .set_window_rect(merged)
+                                    .unwrap_or(false)
+                            {
+                                return None;
+                            }
+                        }
                         "proxy" => {
                             let default = BTreeMap::new();
                             let proxy = value.as_object().unwrap_or(&default);
                             if !browser_capabilities
                                 .accept_proxy(&proxy, merged)
                                 .unwrap_or(false)
                             {
                                 return None;