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