Refactor util::prefs operations to be methods on static struct.

This commit is contained in:
Corey Farwell 2016-07-02 13:51:17 -04:00
parent 307844a8c1
commit 22928f50ac
30 changed files with 166 additions and 162 deletions

View file

@ -33,7 +33,7 @@ use std::sync::mpsc::Receiver;
use std::sync::{Arc, mpsc, RwLock};
use std::thread;
use url::Url;
use util::prefs;
use util::prefs::{self, PREFS};
const DEFAULT_USER_AGENT: &'static str = "Test-agent";
@ -1218,8 +1218,8 @@ fn test_load_errors_when_there_is_too_many_redirects() {
let ui_provider = TestProvider::new();
let redirect_limit = 13.;
prefs::set_pref("network.http.redirection-limit",
prefs::PrefValue::Number(redirect_limit));
PREFS.set("network.http.redirection-limit",
prefs::PrefValue::Number(redirect_limit));
match load(&load_data, &ui_provider, &http_state, None, &Factory,
DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None)) {
@ -1231,7 +1231,7 @@ fn test_load_errors_when_there_is_too_many_redirects() {
_ => panic!("expected max redirects to fail")
}
prefs::reset_pref("network.http.redirection-limit");
PREFS.reset("network.http.redirection-limit");
}
#[test]

View file

@ -30,8 +30,8 @@ fn test_viewport_rule<F>(css: &str,
callback: F)
where F: Fn(&Vec<ViewportDescriptorDeclaration>, &str)
{
::util::prefs::set_pref("layout.viewport.enabled",
::util::prefs::PrefValue::Boolean(true));
::util::prefs::PREFS.set("layout.viewport.enabled",
::util::prefs::PrefValue::Boolean(true));
let stylesheet = stylesheet!(css, Author, Box::new(CSSErrorReporterTest));
let mut rule_count = 0;
for rule in stylesheet.effective_rules(&device).viewport() {
@ -245,8 +245,8 @@ fn cascading_within_viewport_rule() {
#[test]
fn multiple_stylesheets_cascading() {
::util::prefs::set_pref("layout.viewport.enabled",
::util::prefs::PrefValue::Boolean(true));
::util::prefs::PREFS.set("layout.viewport.enabled",
::util::prefs::PrefValue::Boolean(true));
let device = Device::new(MediaType::Screen, Size2D::typed(800., 600.));
let error_reporter = CSSErrorReporterTest;
let stylesheets = vec![

View file

@ -5,7 +5,7 @@
use std::fs::{self, File};
use std::io::{Read, Write};
use util::basedir;
use util::prefs::{PrefValue, extend_prefs, read_prefs_from_file, get_pref, set_pref, reset_pref};
use util::prefs::{PREFS, PrefValue, read_prefs_from_file};
#[test]
fn test_create_pref() {
@ -30,20 +30,20 @@ fn test_get_set_reset_extend() {
\"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()));
assert_eq!(*PREFS.get("test"), PrefValue::Missing);
PREFS.set("test", PrefValue::String("hi".to_owned()));
assert_eq!(*PREFS.get("test"), PrefValue::String("hi".to_owned()));
assert_eq!(*PREFS.get("shell.homepage"), PrefValue::String("http://servo.org".to_owned()));
PREFS.set("shell.homepage", PrefValue::Boolean(true));
assert_eq!(*PREFS.get("shell.homepage"), PrefValue::Boolean(true));
PREFS.reset("shell.homepage");
assert_eq!(*PREFS.get("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));
PREFS.extend(extension);
assert_eq!(*PREFS.get("shell.homepage"), PrefValue::String("https://google.com".to_owned()));
assert_eq!(*PREFS.get("layout.writing-mode.enabled"), PrefValue::Boolean(true));
assert_eq!(*PREFS.get("extra.stuff"), PrefValue::Boolean(false));
}
#[test]