LEFT | RIGHT |
(no file at all) | |
| 1 (function() |
| 2 { |
| 3 module("Preferences", |
| 4 { |
| 5 setup: function() |
| 6 { |
| 7 preparePrefs.call(this); |
| 8 }, |
| 9 |
| 10 teardown: function() |
| 11 { |
| 12 restorePrefs.call(this); |
| 13 } |
| 14 }); |
| 15 |
| 16 function checkPrefExists(name, expectedValue, description, assert) |
| 17 { |
| 18 let done = assert.async(); |
| 19 let key = "pref:" + name; |
| 20 chrome.storage.local.get(key, function(items) |
| 21 { |
| 22 equal(key in items, expectedValue, description); |
| 23 done(); |
| 24 }); |
| 25 } |
| 26 |
| 27 function checkPref(name, expectedValue, description, assert) |
| 28 { |
| 29 let done = assert.async(); |
| 30 let key = "pref:" + name; |
| 31 chrome.storage.local.get(key, function(items) |
| 32 { |
| 33 deepEqual(items[key], expectedValue, description); |
| 34 done(); |
| 35 }); |
| 36 } |
| 37 |
| 38 test("Numerical pref", function(assert) |
| 39 { |
| 40 Prefs.patternsbackups = 5; |
| 41 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 Prefs.patternsbackups = 12; |
| 44 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 checkPref("patternsbackups", 12, "Value has been written", assert); |
| 47 }); |
| 48 |
| 49 test("Boolean pref", function(assert) |
| 50 { |
| 51 Prefs.enabled = true; |
| 52 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 Prefs.enabled = false; |
| 55 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 checkPref("enabled", false, "Value has been written", assert); |
| 58 }); |
| 59 |
| 60 test("String pref", function(assert) |
| 61 { |
| 62 let defaultValue = "https://notification.adblockplus.org/notification.json"; |
| 63 Prefs.notificationurl = defaultValue; |
| 64 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 |
| 67 let newValue = "https://notification.adblockplus.org/foo\u1234bar.json"; |
| 68 Prefs.notificationurl = newValue; |
| 69 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 checkPref("notificationurl", newValue, "Value has been written", assert); |
| 72 }); |
| 73 |
| 74 test("Object pref (complete replacement)", function(assert) |
| 75 { |
| 76 Prefs.notificationdata = {}; |
| 77 deepEqual(Prefs.notificationdata, {}, "Prefs object returns the correct valu
e after setting pref to default value"); |
| 78 |
| 79 let newValue = {foo:1, bar: "adsf\u1234"}; |
| 80 Prefs.notificationdata = newValue; |
| 81 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 checkPref("notificationdata", newValue, "Value has been written", assert); |
| 84 }); |
| 85 |
| 86 test("Property-wise modification", function(assert) |
| 87 { |
| 88 Prefs.notificationdata = {}; |
| 89 |
| 90 Prefs.notificationdata.foo = 1; |
| 91 Prefs.notificationdata.bar = 2; |
| 92 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 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 |
| 97 delete Prefs.notificationdata.foo; |
| 98 delete Prefs.notificationdata.bar; |
| 99 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 }); |
| 102 })(); |
LEFT | RIGHT |