Bug 1407000 - Lint match_browser. r=automatedtester
authorAndreas Tolfsen <ato@sny.no>
Mon, 09 Oct 2017 19:11:31 +0100
changeset 385313 8751f6fd042183b476e6bddc051ebbb6f231427e
parent 385312 5caa7a4686ab573a554c5d3ed503782cb05b7d0d
child 385314 3d20d5f37ca56295118f8031920f32d1548878d7
push id32652
push userarchaeopteryx@coole-files.de
push dateTue, 10 Oct 2017 21:49:31 +0000
treeherdermozilla-central@f1ecd5c26948 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersautomatedtester
bugs1407000
milestone58.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 1407000 - Lint match_browser. r=automatedtester No functional changes here, but the indentation was wrong in many places, making it very hard to read the code. MozReview-Commit-ID: Iku7yPD30QV
testing/webdriver/src/capabilities.rs
--- a/testing/webdriver/src/capabilities.rs
+++ b/testing/webdriver/src/capabilities.rs
@@ -328,121 +328,131 @@ impl ToJson for SpecNewSessionParameters
         capabilities.insert("alwaysMatch".into(), self.alwaysMatch.to_json());
         capabilities.insert("firstMatch".into(), self.firstMatch.to_json());
         body.insert("capabilities".into(), capabilities.to_json());
         Json::Object(body)
     }
 }
 
 impl CapabilitiesMatching for SpecNewSessionParameters {
-    fn match_browser<T: BrowserCapabilities>(&self, browser_capabilities: &mut T)
-                                             -> WebDriverResult<Option<Capabilities>> {
+    fn match_browser<T: BrowserCapabilities>(
+        &self,
+        browser_capabilities: &mut T,
+    ) -> WebDriverResult<Option<Capabilities>> {
         let default = vec![BTreeMap::new()];
         let capabilities_list = if self.firstMatch.len() > 0 {
             &self.firstMatch
         } else {
             &default
         };
 
-        let merged_capabilities = try!(capabilities_list
+        let merged_capabilities = capabilities_list
             .iter()
             .map(|first_match_entry| {
-                if first_match_entry.keys().any(|k| {
-                    self.alwaysMatch.contains_key(k)
-                }) {
+                if first_match_entry.keys().any(
+                    |k| self.alwaysMatch.contains_key(k),
+                )
+                {
                     return Err(WebDriverError::new(
                         ErrorStatus::InvalidArgument,
-                        "'firstMatch' key shadowed a value in 'alwaysMatch'"));
+                        "'firstMatch' key shadowed a value in 'alwaysMatch'",
+                    ));
                 }
                 let mut merged = self.alwaysMatch.clone();
                 merged.append(&mut first_match_entry.clone());
                 Ok(merged)
             })
-            .map(|merged| merged.and_then(|x| self.validate(x, browser_capabilities)))
-            .collect::<WebDriverResult<Vec<Capabilities>>>());
+            .map(|merged| {
+                merged.and_then(|x| self.validate(x, browser_capabilities))
+            })
+            .collect::<WebDriverResult<Vec<Capabilities>>>()?;
 
         let selected = merged_capabilities
             .iter()
             .filter_map(|merged| {
                 browser_capabilities.init(merged);
 
                 for (key, value) in merged.iter() {
                     match &**key {
                         "browserName" => {
                             let browserValue = browser_capabilities
                                 .browser_name(merged)
                                 .ok()
                                 .and_then(|x| x);
 
                             if value.as_string() != browserValue.as_ref().map(|x| &**x) {
-                                    return None;
+                                return None;
                             }
-                        },
+                        }
                         "browserVersion" => {
                             let browserValue = browser_capabilities
                                 .browser_version(merged)
                                 .ok()
                                 .and_then(|x| x);
                             // We already validated this was a string
                             let version_cond = value.as_string().unwrap_or("");
                             if let Some(version) = browserValue {
                                 if !browser_capabilities
                                     .compare_browser_version(&*version, version_cond)
-                                    .unwrap_or(false) {
-                                        return None;
-                                    }
+                                    .unwrap_or(false)
+                                {
+                                    return None;
+                                }
                             } else {
-                                return None
+                                return None;
                             }
-                        },
+                        }
                         "platformName" => {
                             let browserValue = browser_capabilities
                                 .platform_name(merged)
                                 .ok()
                                 .and_then(|x| x);
                             if value.as_string() != browserValue.as_ref().map(|x| &**x) {
                                 return None;
                             }
                         }
                         "acceptInsecureCerts" => {
                             if value.as_boolean().unwrap_or(false) &&
                                 !browser_capabilities
-                                .accept_insecure_certs(merged)
-                                .unwrap_or(false) {
+                                    .accept_insecure_certs(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
+                            if !browser_capabilities
+                                .accept_proxy(&proxy, merged)
+                                .unwrap_or(false)
+                            {
+                                return None;
                             }
-                        },
+                        }
                         name => {
                             if name.contains(":") {
                                 if !browser_capabilities
                                     .accept_custom(name, value, merged)
-                                    .unwrap_or(false) {
-                                        return None
-                                    }
+                                    .unwrap_or(false)
+                                {
+                                    return None;
+                                }
                             } else {
                                 // Accept the capability
                             }
                         }
                     }
                 }
 
-                return Some(merged)
+                return Some(merged);
             })
             .next()
             .map(|x| x.clone());
-            Ok(selected)
+        Ok(selected)
     }
 }
 
 #[derive(Debug, PartialEq)]
 pub struct LegacyNewSessionParameters {
     pub desired: Capabilities,
     pub required: Capabilities,
 }