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

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

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