Skip to content

Commit b1ff30f

Browse files
committed
Allow setting preferences to false in WPT tests. closes #10161
1 parent f2f0586 commit b1ff30f

File tree

7 files changed

+38
-3
lines changed

7 files changed

+38
-3
lines changed

components/script/dom/testbinding.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use js::jsval::{JSVal, NullValue};
2727
use std::borrow::ToOwned;
2828
use std::ptr;
2929
use std::rc::Rc;
30+
use util::prefs::{get_pref};
3031
use util::str::DOMString;
3132

3233
#[dom_struct]
@@ -486,6 +487,9 @@ impl TestBindingMethods for TestBinding {
486487
fn PassVariadicUnion6(&self, _: Vec<UnsignedLongOrBoolean>) {}
487488
fn PassVariadicAny(&self, _: *mut JSContext, _: Vec<HandleValue>) {}
488489
fn PassVariadicObject(&self, _: *mut JSContext, _: Vec<*mut JSObject>) {}
490+
fn BooleanMozPreference(&self, pref_name: DOMString) -> bool {
491+
get_pref(pref_name.as_ref()).as_boolean().unwrap_or(false)
492+
}
489493
}
490494

491495
impl TestBinding {

components/script/dom/webidls/TestBinding.webidl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,4 +398,5 @@ interface TestBinding {
398398

399399
static attribute boolean booleanAttributeStatic;
400400
static void receiveVoidStatic();
401+
boolean BooleanMozPreference(DOMString pref_name);
401402
};

components/util/opts.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ pub fn default_opts() -> Opts {
507507
}
508508
}
509509

510+
#[allow(str_to_string)]
510511
pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult {
511512
let (app_name, args) = args.split_first().unwrap();
512513

@@ -767,7 +768,14 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult {
767768
// This must happen after setting the default options, since the prefs rely on
768769
// on the resource path.
769770
for pref in opt_match.opt_strs("pref").iter() {
770-
prefs::set_pref(pref, PrefValue::Boolean(true));
771+
let split: Vec<&str> = pref.splitn(2, '=').collect();
772+
let pref_name = split[0];
773+
let value = split.get(1);
774+
match value {
775+
Some(&"false") => prefs::set_pref(pref_name, PrefValue::Boolean(false)),
776+
Some(&"true") | None => prefs::set_pref(pref_name, PrefValue::Boolean(true)),
777+
_ => prefs::set_pref(pref_name, PrefValue::String(value.unwrap().to_string()))
778+
};
771779
}
772780

773781
ArgumentParsingResult::ChromeProcess

tests/wpt/harness/wptrunner/executors/executorservo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ def do_test(self, test):
7474
"-z", self.test_url(test)]
7575
for stylesheet in self.browser.user_stylesheets:
7676
args += ["--user-stylesheet", stylesheet]
77-
for pref in test.environment.get('prefs', {}):
78-
args += ["--pref", pref]
77+
for pref, value in test.environment.get('prefs', {}).iteritems():
78+
args += ["--pref", "%s=%s" % (pref, value)]
7979
debug_args, command = browser_command(self.binary, args, self.debug_info)
8080

8181
self.command = command

tests/wpt/mozilla/meta/MANIFEST.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6144,6 +6144,12 @@
61446144
"url": "/_mozilla/mozilla/parentnodes.html"
61456145
}
61466146
],
6147+
"mozilla/preferences.html": [
6148+
{
6149+
"path": "mozilla/preferences.html",
6150+
"url": "/_mozilla/mozilla/preferences.html"
6151+
}
6152+
],
61476153
"mozilla/preserve_wrapper_callback.html": [
61486154
{
61496155
"path": "mozilla/preserve_wrapper_callback.html",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[preferences.html]
2+
type: testharness
3+
prefs: [dom.testbinding.preference_value.falsy:false, dom.testbinding.preference_value.truthy:true]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<meta charset="utf-8">
3+
<title></title>
4+
<script src="/resources/testharness.js"></script>
5+
<script src="/resources/testharnessreport.js"></script>
6+
<script>
7+
test(function() {
8+
var testBinding = new TestBinding();
9+
assert_equals(typeof testBinding.BooleanMozPreference, "function");
10+
assert_equals(testBinding.BooleanMozPreference("dom.testbinding.preference_value.falsy"), false);
11+
assert_equals(testBinding.BooleanMozPreference("dom.testbinding.preference_value.truthy"), true);
12+
}, "prefs");
13+
</script>

0 commit comments

Comments
 (0)