Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: qunit/tests/prefs.js

Issue 29356068: Issue 4495 - Update adblockplustests dependency (Closed)
Patch Set: Remove adblockplustests Created Oct. 6, 2016, 9:37 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« metadata.common ('K') | « qunit/qunit.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: qunit/tests/prefs.js
diff --git a/qunit/tests/prefs.js b/qunit/tests/prefs.js
new file mode 100644
index 0000000000000000000000000000000000000000..f620ca9a555056d0a53856fb805a0cc64120011a
--- /dev/null
+++ b/qunit/tests/prefs.js
@@ -0,0 +1,102 @@
+(function()
+{
+ module("Preferences",
+ {
+ setup: function()
+ {
+ preparePrefs.call(this);
+ },
+
+ teardown: function()
+ {
+ restorePrefs.call(this);
+ }
+ });
+
+ function checkPrefExists(name, expectedValue, description, assert)
+ {
+ let done = assert.async();
+ let key = "pref:" + name;
+ chrome.storage.local.get(key, function(items)
+ {
+ equal(key in items, expectedValue, description);
+ done();
+ });
+ }
+
+ function checkPref(name, expectedValue, description, assert)
+ {
+ let done = assert.async();
+ let key = "pref:" + name;
+ chrome.storage.local.get(key, function(items)
+ {
+ deepEqual(items[key], expectedValue, description);
+ done();
+ });
+ }
+
+ test("Numerical pref", function(assert)
+ {
+ Prefs.patternsbackups = 5;
+ equal(Prefs.patternsbackups, 5, "Prefs object returns the correct value after setting pref to default value");
+ checkPrefExists("patternsbackups", false, "User-defined pref has been removed", assert);
+ Prefs.patternsbackups = 12;
+ equal(Prefs.patternsbackups, 12, "Prefs object returns the correct value after setting pref to non-default value");
+ checkPrefExists("patternsbackups", true, "User-defined pref has been created", assert);
+ checkPref("patternsbackups", 12, "Value has been written", assert);
+ });
+
+ test("Boolean pref", function(assert)
+ {
+ Prefs.enabled = true;
+ equal(Prefs.enabled, true, "Prefs object returns the correct value after setting pref to default value");
+ checkPrefExists("enabled", false, "User-defined pref has been removed", assert);
+ Prefs.enabled = false;
+ equal(Prefs.enabled, false, "Prefs object returns the correct value after setting pref to non-default value");
+ checkPrefExists("enabled", true, "User-defined pref has been created", assert);
+ checkPref("enabled", false, "Value has been written", assert);
+ });
+
+ test("String pref", function(assert)
+ {
+ let defaultValue = "https://notification.adblockplus.org/notification.json";
+ Prefs.notificationurl = defaultValue;
+ equal(Prefs.notificationurl, defaultValue, "Prefs object returns the correct value after setting pref to default value");
+ checkPrefExists("notificationurl", false, "User-defined pref has been removed", assert);
+
+ let newValue = "https://notification.adblockplus.org/foo\u1234bar.json";
+ Prefs.notificationurl = newValue;
+ equal(Prefs.notificationurl, newValue, "Prefs object returns the correct value after setting pref to non-default value");
+ checkPrefExists("notificationurl", true, "User-defined pref has been created", assert);
+ checkPref("notificationurl", newValue, "Value has been written", assert);
+ });
+
+ test("Object pref (complete replacement)", function(assert)
+ {
+ Prefs.notificationdata = {};
+ deepEqual(Prefs.notificationdata, {}, "Prefs object returns the correct value after setting pref to default value");
+
+ let newValue = {foo:1, bar: "adsf\u1234"};
+ Prefs.notificationdata = newValue;
+ equal(Prefs.notificationdata, newValue, "Prefs object returns the correct value after setting pref to non-default value");
+ checkPrefExists("notificationdata", true, "User-defined pref has been created", assert);
+ checkPref("notificationdata", newValue, "Value has been written", assert);
+ });
+
+ test("Property-wise modification", function(assert)
+ {
+ Prefs.notificationdata = {};
+
+ Prefs.notificationdata.foo = 1;
+ Prefs.notificationdata.bar = 2;
+ Prefs.notificationdata = JSON.parse(JSON.stringify(Prefs.notificationdata));
+ deepEqual(Prefs.notificationdata, {foo:1, bar: 2}, "Prefs object returns the correct value after setting pref to non-default value");
+ checkPrefExists("notificationdata", true, "User-defined pref has been created", assert);
+ checkPref("notificationdata", {foo:1, bar: 2}, "Value has been written", assert);
+
+ delete Prefs.notificationdata.foo;
+ delete Prefs.notificationdata.bar;
+ Prefs.notificationdata = JSON.parse(JSON.stringify(Prefs.notificationdata));
+ deepEqual(Prefs.notificationdata, {}, "Prefs object returns the correct value after setting pref to default value");
+ });
+})();
« metadata.common ('K') | « qunit/qunit.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld