mirror of
https://github.com/servo/servo.git
synced 2025-08-23 14:25:33 +01:00
Embedding API: prefs r/w
This commit is contained in:
parent
7df4655b60
commit
479afcfb8e
10 changed files with 460 additions and 157 deletions
|
@ -2,11 +2,7 @@
|
|||
* 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, prefs::PrefValue};
|
||||
use servo_config::opts::parse_url_or_filename;
|
||||
use std::path::Path;
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
|
@ -88,54 +84,3 @@ fn test_argument_parsing_special() {
|
|||
assert_eq!(url.query(), None);
|
||||
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("dom.bluetooth.enabled=true");
|
||||
assert_eq!(
|
||||
prefs::pref_map().get("dom.bluetooth.enabled"),
|
||||
PrefValue::Bool(true)
|
||||
);
|
||||
assert_eq!(pref!(dom.bluetooth.enabled), true);
|
||||
|
||||
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 with numbers
|
||||
parse_pref_from_command_line("layout.threads=42");
|
||||
assert_eq!(pref!(layout.threads), 42);
|
||||
|
||||
// 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