diff --git a/components/util/opts.rs b/components/util/opts.rs index 0fd41e4ea96..3e18c9d9d25 100644 --- a/components/util/opts.rs +++ b/components/util/opts.rs @@ -801,7 +801,7 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult { // These must happen after setting the default options, since the prefs rely on // on the resource path. - // Note that command line preferences have the highest precedent + // Note that command line preferences have the highest precedence if get().profile_dir.is_some() { prefs::add_user_prefs(); } diff --git a/components/util/prefs.rs b/components/util/prefs.rs index 6aa831f9687..c6033213fc8 100644 --- a/components/util/prefs.rs +++ b/components/util/prefs.rs @@ -2,9 +2,9 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use opts; use resource_files::resources_dir_path; use rustc_serialize::json::{Json, ToJson}; -use opts; use std::borrow::ToOwned; use std::collections::HashMap; use std::fs::File; diff --git a/tests/unit/util/lib.rs b/tests/unit/util/lib.rs index a844057a4b0..d124036bef2 100644 --- a/tests/unit/util/lib.rs +++ b/tests/unit/util/lib.rs @@ -16,3 +16,4 @@ extern crate util; #[cfg(test)] mod opts; #[cfg(test)] mod str; #[cfg(test)] mod thread; +#[cfg(test)] mod prefs; diff --git a/tests/unit/util/prefs.rs b/tests/unit/util/prefs.rs new file mode 100644 index 00000000000..bb0226a7d25 --- /dev/null +++ b/tests/unit/util/prefs.rs @@ -0,0 +1,44 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +use util::prefs::{PrefValue, extend_prefs, read_prefs_from_file, get_pref, set_pref, reset_pref, reset_all_prefs}; + +#[test] +fn test_create_pref() { + let json_str = "{\ + \"layout.writing-mode.enabled\": true,\ + \"net.mime.sniff\": false,\ + \"shell.homepage\": \"http://servo.org\"\ +}"; + + let prefs = read_prefs_from_file(json_str.as_bytes()); + assert!(prefs.is_ok()); + let prefs = prefs.unwrap(); + + assert_eq!(prefs.len(), 3); +} + +#[test] +fn test_get_set_reset_extend() { + let json_str = "{\ + \"layout.writing-mode.enabled\": true,\ + \"extra.stuff\": false,\ + \"shell.homepage\": \"https://google.com\"\ +}"; + + assert_eq!(*get_pref("test"), PrefValue::Missing); + set_pref("test", PrefValue::String("hi".to_owned())); + assert_eq!(*get_pref("test"), PrefValue::String("hi".to_owned())); + assert_eq!(*get_pref("shell.homepage"), PrefValue::String("http://servo.org".to_owned())); + set_pref("shell.homepage", PrefValue::Boolean(true)); + assert_eq!(*get_pref("shell.homepage"), PrefValue::Boolean(true)); + reset_pref("shell.homepage"); + assert_eq!(*get_pref("shell.homepage"), PrefValue::String("http://servo.org".to_owned())); + + let extension = read_prefs_from_file(json_str.as_bytes()).unwrap(); + extend_prefs(extension); + assert_eq!(*get_pref("shell.homepage"), PrefValue::String("https://google.com".to_owned())); + assert_eq!(*get_pref("layout.writing-mode.enabled"), PrefValue::Boolean(true)); + assert_eq!(*get_pref("extra.stuff"), PrefValue::Boolean(false)); +}