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

Side by Side Diff: qunit/tests/prefs.js

Issue 29371763: Issue 4795 - Use modern JavaScript syntax (Closed)
Patch Set: Created Jan. 13, 2017, 12:11 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 (function()
2 { 1 {
3 module("Preferences", 2 module("Preferences",
4 { 3 {
5 setup: function() 4 setup: function()
6 { 5 {
7 preparePrefs.call(this); 6 preparePrefs.call(this);
8 }, 7 },
9 8
10 teardown: function() 9 teardown: function()
11 { 10 {
12 restorePrefs.call(this); 11 restorePrefs.call(this);
13 } 12 }
14 }); 13 });
15 14
16 function checkPrefExists(name, expectedValue, description, assert) 15 function checkPrefExists(name, expectedValue, description, assert)
17 { 16 {
18 let done = assert.async(); 17 let done = assert.async();
19 let key = "pref:" + name; 18 let key = "pref:" + name;
20 chrome.storage.local.get(key, function(items) 19 chrome.storage.local.get(key, items =>
21 { 20 {
22 equal(key in items, expectedValue, description); 21 equal(key in items, expectedValue, description);
23 done(); 22 done();
24 }); 23 });
25 } 24 }
26 25
27 function checkPref(name, expectedValue, description, assert) 26 function checkPref(name, expectedValue, description, assert)
28 { 27 {
29 let done = assert.async(); 28 let done = assert.async();
30 let key = "pref:" + name; 29 let key = "pref:" + name;
31 chrome.storage.local.get(key, function(items) 30 chrome.storage.local.get(key, items =>
32 { 31 {
33 deepEqual(items[key], expectedValue, description); 32 deepEqual(items[key], expectedValue, description);
34 done(); 33 done();
35 }); 34 });
36 } 35 }
37 36
38 test("Numerical pref", function(assert) 37 test("Numerical pref", assert =>
39 { 38 {
40 Prefs.patternsbackups = 5; 39 Prefs.patternsbackups = 5;
41 equal(Prefs.patternsbackups, 5, "Prefs object returns the correct value afte r setting pref to default value"); 40 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); 41 checkPrefExists("patternsbackups", false, "User-defined pref has been remove d", assert);
43 Prefs.patternsbackups = 12; 42 Prefs.patternsbackups = 12;
44 equal(Prefs.patternsbackups, 12, "Prefs object returns the correct value aft er setting pref to non-default value"); 43 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); 44 checkPrefExists("patternsbackups", true, "User-defined pref has been created ", assert);
46 checkPref("patternsbackups", 12, "Value has been written", assert); 45 checkPref("patternsbackups", 12, "Value has been written", assert);
47 }); 46 });
48 47
49 test("Boolean pref", function(assert) 48 test("Boolean pref", assert =>
50 { 49 {
51 Prefs.enabled = true; 50 Prefs.enabled = true;
52 equal(Prefs.enabled, true, "Prefs object returns the correct value after set ting pref to default value"); 51 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); 52 checkPrefExists("enabled", false, "User-defined pref has been removed", asse rt);
54 Prefs.enabled = false; 53 Prefs.enabled = false;
55 equal(Prefs.enabled, false, "Prefs object returns the correct value after se tting pref to non-default value"); 54 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); 55 checkPrefExists("enabled", true, "User-defined pref has been created", asser t);
57 checkPref("enabled", false, "Value has been written", assert); 56 checkPref("enabled", false, "Value has been written", assert);
58 }); 57 });
59 58
60 test("String pref", function(assert) 59 test("String pref", assert =>
61 { 60 {
62 let defaultValue = "https://notification.adblockplus.org/notification.json"; 61 let defaultValue = "https://notification.adblockplus.org/notification.json";
63 Prefs.notificationurl = defaultValue; 62 Prefs.notificationurl = defaultValue;
64 equal(Prefs.notificationurl, defaultValue, "Prefs object returns the correct value after setting pref to default value"); 63 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); 64 checkPrefExists("notificationurl", false, "User-defined pref has been remove d", assert);
66 65
67 let newValue = "https://notification.adblockplus.org/foo\u1234bar.json"; 66 let newValue = "https://notification.adblockplus.org/foo\u1234bar.json";
68 Prefs.notificationurl = newValue; 67 Prefs.notificationurl = newValue;
69 equal(Prefs.notificationurl, newValue, "Prefs object returns the correct val ue after setting pref to non-default value"); 68 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); 69 checkPrefExists("notificationurl", true, "User-defined pref has been created ", assert);
71 checkPref("notificationurl", newValue, "Value has been written", assert); 70 checkPref("notificationurl", newValue, "Value has been written", assert);
72 }); 71 });
73 72
74 test("Object pref (complete replacement)", function(assert) 73 test("Object pref (complete replacement)", assert =>
75 { 74 {
76 Prefs.notificationdata = {}; 75 Prefs.notificationdata = {};
77 deepEqual(Prefs.notificationdata, {}, "Prefs object returns the correct valu e after setting pref to default value"); 76 deepEqual(Prefs.notificationdata, {}, "Prefs object returns the correct valu e after setting pref to default value");
78 77
79 let newValue = {foo:1, bar: "adsf\u1234"}; 78 let newValue = {foo:1, bar: "adsf\u1234"};
80 Prefs.notificationdata = newValue; 79 Prefs.notificationdata = newValue;
81 equal(Prefs.notificationdata, newValue, "Prefs object returns the correct va lue after setting pref to non-default value"); 80 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); 81 checkPrefExists("notificationdata", true, "User-defined pref has been create d", assert);
83 checkPref("notificationdata", newValue, "Value has been written", assert); 82 checkPref("notificationdata", newValue, "Value has been written", assert);
84 }); 83 });
85 84
86 test("Property-wise modification", function(assert) 85 test("Property-wise modification", assert =>
87 { 86 {
88 Prefs.notificationdata = {}; 87 Prefs.notificationdata = {};
89 88
90 Prefs.notificationdata.foo = 1; 89 Prefs.notificationdata.foo = 1;
91 Prefs.notificationdata.bar = 2; 90 Prefs.notificationdata.bar = 2;
92 Prefs.notificationdata = JSON.parse(JSON.stringify(Prefs.notificationdata)); 91 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"); 92 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); 93 checkPrefExists("notificationdata", true, "User-defined pref has been create d", assert);
95 checkPref("notificationdata", {foo:1, bar: 2}, "Value has been written", ass ert); 94 checkPref("notificationdata", {foo:1, bar: 2}, "Value has been written", ass ert);
96 95
97 delete Prefs.notificationdata.foo; 96 delete Prefs.notificationdata.foo;
98 delete Prefs.notificationdata.bar; 97 delete Prefs.notificationdata.bar;
99 Prefs.notificationdata = JSON.parse(JSON.stringify(Prefs.notificationdata)); 98 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"); 99 deepEqual(Prefs.notificationdata, {}, "Prefs object returns the correct valu e after setting pref to default value");
101 }); 100 });
102 })(); 101 }
OLDNEW
« chrome/ext/common.js ('K') | « qunit/tests/filterValidation.js ('k') | qunit/tests/url.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld