mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Auto merge of #12178 - frewsxcv:prefs, r=emilio
Refactor `util::prefs` operations to be methods on static struct. <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12178) <!-- Reviewable:end -->
This commit is contained in:
commit
b0a8ce5341
30 changed files with 167 additions and 163 deletions
|
@ -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]
|
||||
|
|
|
@ -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![
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue