OLD | NEW |
| 1 /* globals preparePrefs, restorePrefs, Prefs */ |
| 2 |
1 "use strict"; | 3 "use strict"; |
2 | 4 |
| 5 /* eslint-disable max-len */ |
3 { | 6 { |
4 module("Preferences", | 7 module("Preferences", { |
5 { | |
6 setup() | 8 setup() |
7 { | 9 { |
8 preparePrefs.call(this); | 10 preparePrefs.call(this); |
9 }, | 11 }, |
10 | 12 |
11 teardown() | 13 teardown() |
12 { | 14 { |
13 restorePrefs.call(this); | 15 restorePrefs.call(this); |
14 } | 16 } |
15 }); | 17 }); |
(...skipping 16 matching lines...) Expand all Loading... |
32 chrome.storage.local.get(key, items => | 34 chrome.storage.local.get(key, items => |
33 { | 35 { |
34 deepEqual(items[key], expectedValue, description); | 36 deepEqual(items[key], expectedValue, description); |
35 done(); | 37 done(); |
36 }); | 38 }); |
37 } | 39 } |
38 | 40 |
39 test("Numerical pref", assert => | 41 test("Numerical pref", assert => |
40 { | 42 { |
41 Prefs.patternsbackups = 5; | 43 Prefs.patternsbackups = 5; |
42 equal(Prefs.patternsbackups, 5, "Prefs object returns the correct value afte
r setting pref to default value"); | 44 equal( |
43 checkPrefExists("patternsbackups", false, "User-defined pref has been remove
d", assert); | 45 Prefs.patternsbackups, 5, |
| 46 "Prefs object returns the correct value after setting pref to default valu
e" |
| 47 ); |
| 48 checkPrefExists( |
| 49 "patternsbackups", false, "User-defined pref has been removed", assert |
| 50 ); |
44 Prefs.patternsbackups = 12; | 51 Prefs.patternsbackups = 12; |
45 equal(Prefs.patternsbackups, 12, "Prefs object returns the correct value aft
er setting pref to non-default value"); | 52 equal( |
46 checkPrefExists("patternsbackups", true, "User-defined pref has been created
", assert); | 53 Prefs.patternsbackups, 12, |
| 54 "Prefs object returns the correct value after setting pref to non-default
value" |
| 55 ); |
| 56 checkPrefExists( |
| 57 "patternsbackups", true, "User-defined pref has been created", assert |
| 58 ); |
47 checkPref("patternsbackups", 12, "Value has been written", assert); | 59 checkPref("patternsbackups", 12, "Value has been written", assert); |
48 }); | 60 }); |
49 | 61 |
50 test("Boolean pref", assert => | 62 test("Boolean pref", assert => |
51 { | 63 { |
52 Prefs.enabled = true; | 64 Prefs.enabled = true; |
53 equal(Prefs.enabled, true, "Prefs object returns the correct value after set
ting pref to default value"); | 65 equal( |
54 checkPrefExists("enabled", false, "User-defined pref has been removed", asse
rt); | 66 Prefs.enabled, true, |
| 67 "Prefs object returns the correct value after setting pref to default valu
e" |
| 68 ); |
| 69 checkPrefExists("enabled", false, "User-defined pref has been removed", |
| 70 assert); |
55 Prefs.enabled = false; | 71 Prefs.enabled = false; |
56 equal(Prefs.enabled, false, "Prefs object returns the correct value after se
tting pref to non-default value"); | 72 equal( |
57 checkPrefExists("enabled", true, "User-defined pref has been created", asser
t); | 73 Prefs.enabled, false, |
| 74 "Prefs object returns the correct value after setting pref to non-default
value" |
| 75 ); |
| 76 checkPrefExists("enabled", true, "User-defined pref has been created", |
| 77 assert); |
58 checkPref("enabled", false, "Value has been written", assert); | 78 checkPref("enabled", false, "Value has been written", assert); |
59 }); | 79 }); |
60 | 80 |
61 test("String pref", assert => | 81 test("String pref", assert => |
62 { | 82 { |
63 let defaultValue = "https://notification.adblockplus.org/notification.json"; | 83 let defaultValue = "https://notification.adblockplus.org/notification.json"; |
64 Prefs.notificationurl = defaultValue; | 84 Prefs.notificationurl = defaultValue; |
65 equal(Prefs.notificationurl, defaultValue, "Prefs object returns the correct
value after setting pref to default value"); | 85 equal( |
66 checkPrefExists("notificationurl", false, "User-defined pref has been remove
d", assert); | 86 Prefs.notificationurl, defaultValue, |
| 87 "Prefs object returns the correct value after setting pref to default valu
e" |
| 88 ); |
| 89 checkPrefExists("notificationurl", false, |
| 90 "User-defined pref has been removed", assert); |
67 | 91 |
68 let newValue = "https://notification.adblockplus.org/foo\u1234bar.json"; | 92 let newValue = "https://notification.adblockplus.org/foo\u1234bar.json"; |
69 Prefs.notificationurl = newValue; | 93 Prefs.notificationurl = newValue; |
70 equal(Prefs.notificationurl, newValue, "Prefs object returns the correct val
ue after setting pref to non-default value"); | 94 equal( |
71 checkPrefExists("notificationurl", true, "User-defined pref has been created
", assert); | 95 Prefs.notificationurl, newValue, |
| 96 "Prefs object returns the correct value after setting pref to non-default
value" |
| 97 ); |
| 98 checkPrefExists("notificationurl", true, |
| 99 "User-defined pref has been created", assert); |
72 checkPref("notificationurl", newValue, "Value has been written", assert); | 100 checkPref("notificationurl", newValue, "Value has been written", assert); |
73 }); | 101 }); |
74 | 102 |
75 test("Object pref (complete replacement)", assert => | 103 test("Object pref (complete replacement)", assert => |
76 { | 104 { |
77 Prefs.notificationdata = {}; | 105 Prefs.notificationdata = {}; |
78 deepEqual(Prefs.notificationdata, {}, "Prefs object returns the correct valu
e after setting pref to default value"); | 106 deepEqual( |
| 107 Prefs.notificationdata, {}, |
| 108 "Prefs object returns the correct value after setting pref to default valu
e" |
| 109 ); |
79 | 110 |
80 let newValue = {foo:1, bar: "adsf\u1234"}; | 111 let newValue = {foo: 1, bar: "adsf\u1234"}; |
81 Prefs.notificationdata = newValue; | 112 Prefs.notificationdata = newValue; |
82 equal(Prefs.notificationdata, newValue, "Prefs object returns the correct va
lue after setting pref to non-default value"); | 113 equal( |
83 checkPrefExists("notificationdata", true, "User-defined pref has been create
d", assert); | 114 Prefs.notificationdata, newValue, |
| 115 "Prefs object returns the correct value after setting pref to non-default
value" |
| 116 ); |
| 117 checkPrefExists("notificationdata", true, |
| 118 "User-defined pref has been created", assert); |
84 checkPref("notificationdata", newValue, "Value has been written", assert); | 119 checkPref("notificationdata", newValue, "Value has been written", assert); |
85 }); | 120 }); |
86 | 121 |
87 test("Property-wise modification", assert => | 122 test("Property-wise modification", assert => |
88 { | 123 { |
89 Prefs.notificationdata = {}; | 124 Prefs.notificationdata = {}; |
90 | 125 |
91 Prefs.notificationdata.foo = 1; | 126 Prefs.notificationdata.foo = 1; |
92 Prefs.notificationdata.bar = 2; | 127 Prefs.notificationdata.bar = 2; |
93 Prefs.notificationdata = JSON.parse(JSON.stringify(Prefs.notificationdata)); | 128 Prefs.notificationdata = JSON.parse(JSON.stringify(Prefs.notificationdata)); |
94 deepEqual(Prefs.notificationdata, {foo:1, bar: 2}, "Prefs object returns the
correct value after setting pref to non-default value"); | 129 deepEqual( |
95 checkPrefExists("notificationdata", true, "User-defined pref has been create
d", assert); | 130 Prefs.notificationdata, {foo: 1, bar: 2}, |
96 checkPref("notificationdata", {foo:1, bar: 2}, "Value has been written", ass
ert); | 131 "Prefs object returns the correct value after setting pref to non-default
value" |
| 132 ); |
| 133 checkPrefExists("notificationdata", true, |
| 134 "User-defined pref has been created", assert); |
| 135 checkPref("notificationdata", {foo: 1, bar: 2}, "Value has been written", |
| 136 assert); |
97 | 137 |
98 delete Prefs.notificationdata.foo; | 138 delete Prefs.notificationdata.foo; |
99 delete Prefs.notificationdata.bar; | 139 delete Prefs.notificationdata.bar; |
100 Prefs.notificationdata = JSON.parse(JSON.stringify(Prefs.notificationdata)); | 140 Prefs.notificationdata = JSON.parse(JSON.stringify(Prefs.notificationdata)); |
101 deepEqual(Prefs.notificationdata, {}, "Prefs object returns the correct valu
e after setting pref to default value"); | 141 deepEqual( |
| 142 Prefs.notificationdata, {}, |
| 143 "Prefs object returns the correct value after setting pref to default valu
e" |
| 144 ); |
102 }); | 145 }); |
103 } | 146 } |
| 147 /* eslint-enable max-len */ |
OLD | NEW |