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

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

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

Powered by Google App Engine
This is Rietveld