OLD | NEW |
1 (function() | 1 "use strict"; |
| 2 |
2 { | 3 { |
3 module("Preferences", | 4 module("Preferences", |
4 { | 5 { |
5 setup: function() | 6 setup() |
6 { | 7 { |
7 preparePrefs.call(this); | 8 preparePrefs.call(this); |
8 }, | 9 }, |
9 | 10 |
10 teardown: function() | 11 teardown() |
11 { | 12 { |
12 restorePrefs.call(this); | 13 restorePrefs.call(this); |
13 } | 14 } |
14 }); | 15 }); |
15 | 16 |
16 function checkPrefExists(name, expectedValue, description, assert) | 17 function checkPrefExists(name, expectedValue, description, assert) |
17 { | 18 { |
18 let done = assert.async(); | 19 let done = assert.async(); |
19 let key = "pref:" + name; | 20 let key = "pref:" + name; |
20 chrome.storage.local.get(key, function(items) | 21 chrome.storage.local.get(key, items => |
21 { | 22 { |
22 equal(key in items, expectedValue, description); | 23 equal(key in items, expectedValue, description); |
23 done(); | 24 done(); |
24 }); | 25 }); |
25 } | 26 } |
26 | 27 |
27 function checkPref(name, expectedValue, description, assert) | 28 function checkPref(name, expectedValue, description, assert) |
28 { | 29 { |
29 let done = assert.async(); | 30 let done = assert.async(); |
30 let key = "pref:" + name; | 31 let key = "pref:" + name; |
31 chrome.storage.local.get(key, function(items) | 32 chrome.storage.local.get(key, items => |
32 { | 33 { |
33 deepEqual(items[key], expectedValue, description); | 34 deepEqual(items[key], expectedValue, description); |
34 done(); | 35 done(); |
35 }); | 36 }); |
36 } | 37 } |
37 | 38 |
38 test("Numerical pref", function(assert) | 39 test("Numerical pref", assert => |
39 { | 40 { |
40 Prefs.patternsbackups = 5; | 41 Prefs.patternsbackups = 5; |
41 equal(Prefs.patternsbackups, 5, "Prefs object returns the correct value afte
r setting pref to default value"); | 42 equal(Prefs.patternsbackups, 5, "Prefs object returns the correct value afte
r setting pref to default value"); |
42 checkPrefExists("patternsbackups", false, "User-defined pref has been remove
d", assert); | 43 checkPrefExists("patternsbackups", false, "User-defined pref has been remove
d", assert); |
43 Prefs.patternsbackups = 12; | 44 Prefs.patternsbackups = 12; |
44 equal(Prefs.patternsbackups, 12, "Prefs object returns the correct value aft
er setting pref to non-default value"); | 45 equal(Prefs.patternsbackups, 12, "Prefs object returns the correct value aft
er setting pref to non-default value"); |
45 checkPrefExists("patternsbackups", true, "User-defined pref has been created
", assert); | 46 checkPrefExists("patternsbackups", true, "User-defined pref has been created
", assert); |
46 checkPref("patternsbackups", 12, "Value has been written", assert); | 47 checkPref("patternsbackups", 12, "Value has been written", assert); |
47 }); | 48 }); |
48 | 49 |
49 test("Boolean pref", function(assert) | 50 test("Boolean pref", assert => |
50 { | 51 { |
51 Prefs.enabled = true; | 52 Prefs.enabled = true; |
52 equal(Prefs.enabled, true, "Prefs object returns the correct value after set
ting pref to default value"); | 53 equal(Prefs.enabled, true, "Prefs object returns the correct value after set
ting pref to default value"); |
53 checkPrefExists("enabled", false, "User-defined pref has been removed", asse
rt); | 54 checkPrefExists("enabled", false, "User-defined pref has been removed", asse
rt); |
54 Prefs.enabled = false; | 55 Prefs.enabled = false; |
55 equal(Prefs.enabled, false, "Prefs object returns the correct value after se
tting pref to non-default value"); | 56 equal(Prefs.enabled, false, "Prefs object returns the correct value after se
tting pref to non-default value"); |
56 checkPrefExists("enabled", true, "User-defined pref has been created", asser
t); | 57 checkPrefExists("enabled", true, "User-defined pref has been created", asser
t); |
57 checkPref("enabled", false, "Value has been written", assert); | 58 checkPref("enabled", false, "Value has been written", assert); |
58 }); | 59 }); |
59 | 60 |
60 test("String pref", function(assert) | 61 test("String pref", assert => |
61 { | 62 { |
62 let defaultValue = "https://notification.adblockplus.org/notification.json"; | 63 let defaultValue = "https://notification.adblockplus.org/notification.json"; |
63 Prefs.notificationurl = defaultValue; | 64 Prefs.notificationurl = defaultValue; |
64 equal(Prefs.notificationurl, defaultValue, "Prefs object returns the correct
value after setting pref to default value"); | 65 equal(Prefs.notificationurl, defaultValue, "Prefs object returns the correct
value after setting pref to default value"); |
65 checkPrefExists("notificationurl", false, "User-defined pref has been remove
d", assert); | 66 checkPrefExists("notificationurl", false, "User-defined pref has been remove
d", assert); |
66 | 67 |
67 let newValue = "https://notification.adblockplus.org/foo\u1234bar.json"; | 68 let newValue = "https://notification.adblockplus.org/foo\u1234bar.json"; |
68 Prefs.notificationurl = newValue; | 69 Prefs.notificationurl = newValue; |
69 equal(Prefs.notificationurl, newValue, "Prefs object returns the correct val
ue after setting pref to non-default value"); | 70 equal(Prefs.notificationurl, newValue, "Prefs object returns the correct val
ue after setting pref to non-default value"); |
70 checkPrefExists("notificationurl", true, "User-defined pref has been created
", assert); | 71 checkPrefExists("notificationurl", true, "User-defined pref has been created
", assert); |
71 checkPref("notificationurl", newValue, "Value has been written", assert); | 72 checkPref("notificationurl", newValue, "Value has been written", assert); |
72 }); | 73 }); |
73 | 74 |
74 test("Object pref (complete replacement)", function(assert) | 75 test("Object pref (complete replacement)", assert => |
75 { | 76 { |
76 Prefs.notificationdata = {}; | 77 Prefs.notificationdata = {}; |
77 deepEqual(Prefs.notificationdata, {}, "Prefs object returns the correct valu
e after setting pref to default value"); | 78 deepEqual(Prefs.notificationdata, {}, "Prefs object returns the correct valu
e after setting pref to default value"); |
78 | 79 |
79 let newValue = {foo:1, bar: "adsf\u1234"}; | 80 let newValue = {foo:1, bar: "adsf\u1234"}; |
80 Prefs.notificationdata = newValue; | 81 Prefs.notificationdata = newValue; |
81 equal(Prefs.notificationdata, newValue, "Prefs object returns the correct va
lue after setting pref to non-default value"); | 82 equal(Prefs.notificationdata, newValue, "Prefs object returns the correct va
lue after setting pref to non-default value"); |
82 checkPrefExists("notificationdata", true, "User-defined pref has been create
d", assert); | 83 checkPrefExists("notificationdata", true, "User-defined pref has been create
d", assert); |
83 checkPref("notificationdata", newValue, "Value has been written", assert); | 84 checkPref("notificationdata", newValue, "Value has been written", assert); |
84 }); | 85 }); |
85 | 86 |
86 test("Property-wise modification", function(assert) | 87 test("Property-wise modification", assert => |
87 { | 88 { |
88 Prefs.notificationdata = {}; | 89 Prefs.notificationdata = {}; |
89 | 90 |
90 Prefs.notificationdata.foo = 1; | 91 Prefs.notificationdata.foo = 1; |
91 Prefs.notificationdata.bar = 2; | 92 Prefs.notificationdata.bar = 2; |
92 Prefs.notificationdata = JSON.parse(JSON.stringify(Prefs.notificationdata)); | 93 Prefs.notificationdata = JSON.parse(JSON.stringify(Prefs.notificationdata)); |
93 deepEqual(Prefs.notificationdata, {foo:1, bar: 2}, "Prefs object returns the
correct value after setting pref to non-default value"); | 94 deepEqual(Prefs.notificationdata, {foo:1, bar: 2}, "Prefs object returns the
correct value after setting pref to non-default value"); |
94 checkPrefExists("notificationdata", true, "User-defined pref has been create
d", assert); | 95 checkPrefExists("notificationdata", true, "User-defined pref has been create
d", assert); |
95 checkPref("notificationdata", {foo:1, bar: 2}, "Value has been written", ass
ert); | 96 checkPref("notificationdata", {foo:1, bar: 2}, "Value has been written", ass
ert); |
96 | 97 |
97 delete Prefs.notificationdata.foo; | 98 delete Prefs.notificationdata.foo; |
98 delete Prefs.notificationdata.bar; | 99 delete Prefs.notificationdata.bar; |
99 Prefs.notificationdata = JSON.parse(JSON.stringify(Prefs.notificationdata)); | 100 Prefs.notificationdata = JSON.parse(JSON.stringify(Prefs.notificationdata)); |
100 deepEqual(Prefs.notificationdata, {}, "Prefs object returns the correct valu
e after setting pref to default value"); | 101 deepEqual(Prefs.notificationdata, {}, "Prefs object returns the correct valu
e after setting pref to default value"); |
101 }); | 102 }); |
102 })(); | 103 } |
OLD | NEW |