This repository has been archived by the owner on Feb 1, 2019. It is now read-only.
/
test_js_prefs.py
60 lines (46 loc) · 1.71 KB
/
test_js_prefs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from js_helper import _do_test_raw
def test_pref_innocuous_branch():
"""
Tests that innocuous preferences created outside of the "extensions." branch
from defaults/preferences/*.js files throw warnings, and that ones created
in proper branches don't.
"""
assert _do_test_raw("""
pref("foo.bar", true);
""", path="defaults/preferences/prefs.js").failed()
assert _do_test_raw("""
user_pref("foo.bar", true);
""", path="defaults/preferences/prefs.js").failed()
assert _do_test_raw("""
pref("extensions.foo-bar", true);
""", path="defaults/preferences/prefs.js").failed()
assert not _do_test_raw("""
pref("extensions.foo-bar.baz", true);
""", path="defaults/preferences/prefs.js").failed()
def test_pref_dangerous_branch():
"""
Test that preferences created in dangerous branches from
defaults/preferences/*.js files throw warnings.
"""
assert _do_test_raw("""
pref("extensions.getAddons.get.url", "http://evil.com/");
""", path="defaults/preferences/prefs.js").failed()
assert _do_test_raw("""
user_pref("extensions.getAddons.get.url", "http://evil.com/");
""", path="defaults/preferences/prefs.js").failed()
def test_pref_complex_code():
"""
Test that calls to functions other than pref() or user_pref() in default
preference files throw warnings and that calls to pref() and user_pref()
don't.
"""
assert not _do_test_raw("""
pref();
user_pref();
""", path="defaults/preferences/prefs.js").failed()
assert _do_test_raw("""
foo();
""", path="defaults/preferences/prefs.js").failed()
assert _do_test_raw("""
foo.bar();
""", path="defaults/preferences/prefs.js").failed()