Bug 1529273 - replaces the current implementation of Profile::new with dedicated Profile::new and Profile::new_from_path. r=ato
authorKriti Singh <kritisingh1.ks@gmail.com>
Wed, 13 Mar 2019 16:42:23 +0000
changeset 521757 9f0635581b5c
parent 521756 b8c1398f5a90
child 521758 a4d1dd58552d
push id10867
push userdvarga@mozilla.com
push dateThu, 14 Mar 2019 15:20:45 +0000
treeherdermozilla-beta@abad13547875 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1529273
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 1529273 - replaces the current implementation of Profile::new with dedicated Profile::new and Profile::new_from_path. r=ato Differential Revision: https://phabricator.services.mozilla.com/D23310
testing/geckodriver/src/capabilities.rs
testing/geckodriver/src/marionette.rs
testing/mozbase/rust/mozprofile/src/profile.rs
--- a/testing/geckodriver/src/capabilities.rs
+++ b/testing/geckodriver/src/capabilities.rs
@@ -343,17 +343,17 @@ impl FirefoxOptions {
         if let Some(profile_json) = options.get("profile") {
             let profile_base64 = profile_json.as_str().ok_or(WebDriverError::new(
                 ErrorStatus::UnknownError,
                 "Profile is not a string"
             ))?;
             let profile_zip = &*base64::decode(profile_base64)?;
 
             // Create an emtpy profile directory
-            let profile = Profile::new(None)?;
+            let profile = Profile::new()?;
             unzip_buffer(
                 profile_zip,
                 profile
                     .temp_dir
                     .as_ref()
                     .expect("Profile doesn't have a path")
                     .path()
             )?;
--- a/testing/geckodriver/src/marionette.rs
+++ b/testing/geckodriver/src/marionette.rs
@@ -140,17 +140,17 @@ impl MarionetteHandler {
              'moz:firefoxOptions.binary' capability provided, and \
              no binary flag set on the command line",
         ))?;
 
         let is_custom_profile = options.profile.is_some();
 
         let mut profile = match options.profile {
             Some(x) => x,
-            None => Profile::new(None)?,
+            None => Profile::new()?,
         };
 
         self.set_prefs(port, &mut profile, is_custom_profile, options.prefs)
             .map_err(|e| {
                 WebDriverError::new(
                     ErrorStatus::SessionNotCreated,
                     format!("Failed to set preferences: {}", e),
                 )
@@ -1518,17 +1518,17 @@ mod tests {
     use mozprofile::preferences::PrefValue;
     use mozprofile::profile::Profile;
 
     // This is not a pretty test, mostly due to the nature of
     // mozprofile's and MarionetteHandler's APIs, but we have had
     // several regressions related to marionette.log.level.
     #[test]
     fn test_marionette_log_level() {
-        let mut profile = Profile::new(None).unwrap();
+        let mut profile = Profile::new().unwrap();
         let handler = MarionetteHandler::new(MarionetteSettings::default());
         handler.set_prefs(2828, &mut profile, false, vec![]).ok();
         let user_prefs = profile.user_prefs().unwrap();
 
         let pref = user_prefs.get("marionette.log.level").unwrap();
         let value = match pref.value {
             PrefValue::String(ref s) => s,
             _ => panic!(),
--- a/testing/mozbase/rust/mozprofile/src/profile.rs
+++ b/testing/mozbase/rust/mozprofile/src/profile.rs
@@ -11,28 +11,31 @@ use tempdir::TempDir;
 pub struct Profile {
     pub path: PathBuf,
     pub temp_dir: Option<TempDir>,
     prefs: Option<PrefFile>,
     user_prefs: Option<PrefFile>,
 }
 
 impl Profile {
-    pub fn new(opt_path: Option<&Path>) -> IoResult<Profile> {
-        let mut temp_dir = None;
-        let path = match opt_path {
-            Some(p) => p.to_path_buf(),
-            None => {
-                let dir = TempDir::new("rust_mozprofile")?;
-                let temp_path = dir.path().to_path_buf();
-                temp_dir = Some(dir);
-                temp_path
-            }
-        };
+    pub fn new() -> IoResult<Profile> {
+        let dir = TempDir::new("rust_mozprofile")?;
+        let path = dir.path().to_path_buf();
+        let temp_dir = Some(dir);
+        Ok(Profile {
+            path,
+            temp_dir,
+            prefs: None,
+            user_prefs: None,
+        })
+    }
 
+     pub fn new_from_path(p: &Path) -> IoResult<Profile> {
+        let path = p.to_path_buf();
+        let temp_dir = None;
         Ok(Profile {
             path,
             temp_dir,
             prefs: None,
             user_prefs: None,
         })
     }