mirror of
https://github.com/servo/servo.git
synced 2025-08-10 16:05:43 +01:00
#8539 Config preferences backend restructure
This commit is contained in:
parent
34fda66dfa
commit
8bfd4dc1e2
53 changed files with 1748 additions and 680 deletions
|
@ -2,8 +2,11 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#[macro_use]
|
||||
extern crate servo_config;
|
||||
|
||||
use servo_config::opts::{parse_pref_from_command_line, parse_url_or_filename};
|
||||
use servo_config::prefs::{PrefValue, PREFS};
|
||||
use servo_config::{prefs, prefs::PrefValue};
|
||||
use std::path::Path;
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
|
@ -86,25 +89,53 @@ fn test_argument_parsing_special() {
|
|||
assert_eq!(url.fragment(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_prefs_from_command_line_panics() {
|
||||
let err_msg = std::panic::catch_unwind(|| {
|
||||
parse_pref_from_command_line("doesntexist=true");
|
||||
})
|
||||
.err()
|
||||
.and_then(|a| a.downcast_ref::<String>().cloned())
|
||||
.expect("Should panic");
|
||||
assert!(
|
||||
err_msg.starts_with("Error setting preference"),
|
||||
"Message should describe the problem"
|
||||
);
|
||||
assert!(
|
||||
err_msg.contains("doesntexist"),
|
||||
"Message should mention the name of the preference"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_pref_from_command_line() {
|
||||
// Test with boolean values.
|
||||
parse_pref_from_command_line("testtrue=true");
|
||||
assert_eq!(*PREFS.get("testtrue"), PrefValue::Boolean(true));
|
||||
parse_pref_from_command_line("testfalse=false");
|
||||
assert_eq!(*PREFS.get("testfalse"), PrefValue::Boolean(false));
|
||||
parse_pref_from_command_line("dom.bluetooth.enabled=true");
|
||||
assert_eq!(
|
||||
prefs::pref_map().get("dom.bluetooth.enabled"),
|
||||
PrefValue::Bool(true)
|
||||
);
|
||||
assert_eq!(pref!(dom.bluetooth.enabled), true);
|
||||
|
||||
// Test with numbers.
|
||||
parse_pref_from_command_line("testint=42");
|
||||
assert_eq!(*PREFS.get("testint"), PrefValue::Number(42 as f64));
|
||||
parse_pref_from_command_line("testfloat=4.2");
|
||||
assert_eq!(*PREFS.get("testfloat"), PrefValue::Number(4.2));
|
||||
parse_pref_from_command_line("dom.bluetooth.enabled=false");
|
||||
assert_eq!(
|
||||
prefs::pref_map().get("dom.bluetooth.enabled"),
|
||||
PrefValue::Bool(false)
|
||||
);
|
||||
assert_eq!(pref!(dom.bluetooth.enabled), false);
|
||||
|
||||
// Test default (string).
|
||||
parse_pref_from_command_line("teststr=str");
|
||||
assert_eq!(*PREFS.get("teststr"), PrefValue::String("str".to_owned()));
|
||||
// Test with numbers
|
||||
parse_pref_from_command_line("layout.threads=42");
|
||||
assert_eq!(pref!(layout.threads), 42);
|
||||
|
||||
// Test with no value.
|
||||
parse_pref_from_command_line("testempty");
|
||||
assert_eq!(*PREFS.get("testempty"), PrefValue::Boolean(true));
|
||||
// Test string.
|
||||
parse_pref_from_command_line("shell.homepage=str");
|
||||
assert_eq!(pref!(shell.homepage), "str");
|
||||
|
||||
// Test with no value (defaults to true).
|
||||
prefs::pref_map()
|
||||
.set("dom.bluetooth.enabled", false)
|
||||
.unwrap();
|
||||
parse_pref_from_command_line("dom.bluetooth.enabled");
|
||||
assert_eq!(pref!(dom.bluetooth.enabled), true);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue