diff --git a/testing/geckodriver/src/logging.rs b/testing/geckodriver/src/logging.rs index d9efd9ff7fc9..4a4faa86923c 100644 --- a/testing/geckodriver/src/logging.rs +++ b/testing/geckodriver/src/logging.rs @@ -27,14 +27,16 @@ //! [`init`]: fn.init.html //! [`init_with_level`]: fn.init_with_level.html -use chrono; -use log; use std::fmt; use std::io; use std::io::Write; use std::str; use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT}; +use chrono; +use log; +use mozprofile::preferences::Pref; + static MAX_LOG_LEVEL: AtomicUsize = ATOMIC_USIZE_INIT; const LOGGED_TARGETS: &'static [&'static str] = &[ "geckodriver", @@ -122,6 +124,21 @@ impl Into for Level { } } +impl Into for Level { + fn into(self) -> Pref { + use self::Level::*; + Pref::new(match self { + Fatal => "Fatal", + Error => "Error", + Warn => "Warn", + Info => "Info", + Config => "Config", + Debug => "Debug", + Trace => "Trace", + }) + } +} + impl From for Level { fn from(log_level: log::Level) -> Level { use log::Level::*; @@ -195,11 +212,14 @@ fn format_ts(ts: chrono::DateTime) -> String { #[cfg(test)] mod tests { use super::{format_ts, init_with_level, max_level, set_max_level, Level}; - use chrono; - use log; + use std::str::FromStr; use std::sync::Mutex; + use chrono; + use log; + use mozprofile::preferences::{Pref, PrefValue}; + lazy_static! { static ref LEVEL_MUTEX: Mutex<()> = Mutex::new(()); } @@ -246,6 +266,24 @@ mod tests { assert_eq!(Into::::into(Level::Trace), log::Level::Trace); } + #[test] + fn test_level_into_pref() { + let tests = [ + (Level::Fatal, "Fatal"), + (Level::Error, "Error"), + (Level::Warn, "Warn"), + (Level::Info, "Info"), + (Level::Config, "Config"), + (Level::Debug, "Debug"), + (Level::Trace, "Trace"), + ]; + + for &(lvl, s) in tests.iter() { + let expected = Pref { value: PrefValue::String(s.to_string()), sticky: false }; + assert_eq!(Into::::into(lvl), expected); + } + } + #[test] fn test_level_from_str() { assert_eq!(Level::from_str("fatal"), Ok(Level::Fatal)); diff --git a/testing/geckodriver/src/marionette.rs b/testing/geckodriver/src/marionette.rs index b00a2d4a7c1d..695ca34df5de 100644 --- a/testing/geckodriver/src/marionette.rs +++ b/testing/geckodriver/src/marionette.rs @@ -486,12 +486,19 @@ impl MarionetteHandler { Ok(()) } - pub fn set_prefs(&self, port: u16, profile: &mut Profile, custom_profile: bool, - extra_prefs: Vec<(String, Pref)>) - -> WebDriverResult<()> { - let prefs = try!(profile.user_prefs() - .map_err(|_| WebDriverError::new(ErrorStatus::UnknownError, - "Unable to read profile preferences file"))); + pub fn set_prefs( + &self, + port: u16, + profile: &mut Profile, + custom_profile: bool, + extra_prefs: Vec<(String, Pref)>, + ) -> WebDriverResult<()> { + let prefs = profile.user_prefs().map_err(|_| { + WebDriverError::new( + ErrorStatus::UnknownError, + "Unable to read profile preferences file", + ) + })?; for &(ref name, ref value) in prefs::DEFAULT.iter() { if !custom_profile || !prefs.contains_key(name) { @@ -509,11 +516,12 @@ impl MarionetteHandler { prefs.insert("marionette.debugging.clicktostart", Pref::new(true)); } - prefs.insert("marionette.log.level", Pref::new(logging::max_level().to_string())); + prefs.insert("marionette.log.level", logging::max_level().into()); prefs.insert("marionette.port", Pref::new(port)); - prefs.write().map_err(|_| WebDriverError::new(ErrorStatus::UnknownError, - "Unable to write Firefox profile")) + prefs.write().map_err(|_| { + WebDriverError::new(ErrorStatus::UnknownError, "Unable to write Firefox profile") + }) } }