|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 function run_test() { |
|
6 runAsyncTests(tests); |
|
7 } |
|
8 |
|
9 let tests = [ |
|
10 |
|
11 function get_nonexistent() { |
|
12 yield getOK(["a.com", "foo"], undefined); |
|
13 yield getGlobalOK(["foo"], undefined); |
|
14 }, |
|
15 |
|
16 function isomorphicDomains() { |
|
17 yield set("a.com", "foo", 1); |
|
18 yield dbOK([ |
|
19 ["a.com", "foo", 1], |
|
20 ]); |
|
21 yield getOK(["a.com", "foo"], 1); |
|
22 yield getOK(["http://a.com/huh", "foo"], 1, "a.com"); |
|
23 |
|
24 yield set("http://a.com/huh", "foo", 2); |
|
25 yield dbOK([ |
|
26 ["a.com", "foo", 2], |
|
27 ]); |
|
28 yield getOK(["a.com", "foo"], 2); |
|
29 yield getOK(["http://a.com/yeah", "foo"], 2, "a.com"); |
|
30 }, |
|
31 |
|
32 function names() { |
|
33 yield set("a.com", "foo", 1); |
|
34 yield dbOK([ |
|
35 ["a.com", "foo", 1], |
|
36 ]); |
|
37 yield getOK(["a.com", "foo"], 1); |
|
38 |
|
39 yield set("a.com", "bar", 2); |
|
40 yield dbOK([ |
|
41 ["a.com", "foo", 1], |
|
42 ["a.com", "bar", 2], |
|
43 ]); |
|
44 yield getOK(["a.com", "foo"], 1); |
|
45 yield getOK(["a.com", "bar"], 2); |
|
46 |
|
47 yield setGlobal("foo", 3); |
|
48 yield dbOK([ |
|
49 ["a.com", "foo", 1], |
|
50 ["a.com", "bar", 2], |
|
51 [null, "foo", 3], |
|
52 ]); |
|
53 yield getOK(["a.com", "foo"], 1); |
|
54 yield getOK(["a.com", "bar"], 2); |
|
55 yield getGlobalOK(["foo"], 3); |
|
56 |
|
57 yield setGlobal("bar", 4); |
|
58 yield dbOK([ |
|
59 ["a.com", "foo", 1], |
|
60 ["a.com", "bar", 2], |
|
61 [null, "foo", 3], |
|
62 [null, "bar", 4], |
|
63 ]); |
|
64 yield getOK(["a.com", "foo"], 1); |
|
65 yield getOK(["a.com", "bar"], 2); |
|
66 yield getGlobalOK(["foo"], 3); |
|
67 yield getGlobalOK(["bar"], 4); |
|
68 }, |
|
69 |
|
70 function subdomains() { |
|
71 yield set("a.com", "foo", 1); |
|
72 yield set("b.a.com", "foo", 2); |
|
73 yield dbOK([ |
|
74 ["a.com", "foo", 1], |
|
75 ["b.a.com", "foo", 2], |
|
76 ]); |
|
77 yield getOK(["a.com", "foo"], 1); |
|
78 yield getOK(["b.a.com", "foo"], 2); |
|
79 }, |
|
80 |
|
81 function privateBrowsing() { |
|
82 yield set("a.com", "foo", 1); |
|
83 yield set("a.com", "bar", 2); |
|
84 yield setGlobal("foo", 3); |
|
85 yield setGlobal("bar", 4); |
|
86 yield set("b.com", "foo", 5); |
|
87 |
|
88 let context = { usePrivateBrowsing: true }; |
|
89 yield set("a.com", "foo", 6, context); |
|
90 yield setGlobal("foo", 7, context); |
|
91 yield dbOK([ |
|
92 ["a.com", "foo", 1], |
|
93 ["a.com", "bar", 2], |
|
94 [null, "foo", 3], |
|
95 [null, "bar", 4], |
|
96 ["b.com", "foo", 5], |
|
97 ]); |
|
98 yield getOK(["a.com", "foo", context], 6, "a.com"); |
|
99 yield getOK(["a.com", "bar", context], 2); |
|
100 yield getGlobalOK(["foo", context], 7); |
|
101 yield getGlobalOK(["bar", context], 4); |
|
102 yield getOK(["b.com", "foo", context], 5); |
|
103 |
|
104 yield getOK(["a.com", "foo"], 1); |
|
105 yield getOK(["a.com", "bar"], 2); |
|
106 yield getGlobalOK(["foo"], 3); |
|
107 yield getGlobalOK(["bar"], 4); |
|
108 yield getOK(["b.com", "foo"], 5); |
|
109 }, |
|
110 |
|
111 function set_erroneous() { |
|
112 do_check_throws(function () cps.set(null, "foo", 1, null)); |
|
113 do_check_throws(function () cps.set("", "foo", 1, null)); |
|
114 do_check_throws(function () cps.set("a.com", "", 1, null)); |
|
115 do_check_throws(function () cps.set("a.com", null, 1, null)); |
|
116 do_check_throws(function () cps.set("a.com", "foo", undefined, null)); |
|
117 do_check_throws(function () cps.set("a.com", "foo", 1, null, "bogus")); |
|
118 do_check_throws(function () cps.setGlobal("", 1, null)); |
|
119 do_check_throws(function () cps.setGlobal(null, 1, null)); |
|
120 do_check_throws(function () cps.setGlobal("foo", undefined, null)); |
|
121 do_check_throws(function () cps.setGlobal("foo", 1, null, "bogus")); |
|
122 yield true; |
|
123 }, |
|
124 |
|
125 function get_erroneous() { |
|
126 do_check_throws(function () cps.getByDomainAndName(null, "foo", null, {})); |
|
127 do_check_throws(function () cps.getByDomainAndName("", "foo", null, {})); |
|
128 do_check_throws(function () cps.getByDomainAndName("a.com", "", null, {})); |
|
129 do_check_throws(function () |
|
130 cps.getByDomainAndName("a.com", null, null, {})); |
|
131 do_check_throws(function () |
|
132 cps.getByDomainAndName("a.com", "foo", null, null)); |
|
133 do_check_throws(function () cps.getGlobal("", null, {})); |
|
134 do_check_throws(function () cps.getGlobal(null, null, {})); |
|
135 do_check_throws(function () cps.getGlobal("foo", null, null)); |
|
136 yield true; |
|
137 }, |
|
138 |
|
139 function set_invalidateCache() { |
|
140 // (1) Set a pref and wait for it to finish. |
|
141 yield set("a.com", "foo", 1); |
|
142 |
|
143 // (2) It should be cached. |
|
144 getCachedOK(["a.com", "foo"], true, 1); |
|
145 |
|
146 // (3) Set the pref to a new value but don't wait for it to finish. |
|
147 cps.set("a.com", "foo", 2, null, { |
|
148 handleCompletion: function () { |
|
149 // (6) The pref should be cached after setting it. |
|
150 getCachedOK(["a.com", "foo"], true, 2); |
|
151 }, |
|
152 }); |
|
153 |
|
154 // (4) Group "a.com" and name "foo" should no longer be cached. |
|
155 getCachedOK(["a.com", "foo"], false); |
|
156 |
|
157 // (5) Call getByDomainAndName. |
|
158 var fetchedPref; |
|
159 cps.getByDomainAndName("a.com", "foo", null, { |
|
160 handleResult: function (pref) { |
|
161 fetchedPref = pref; |
|
162 }, |
|
163 handleCompletion: function () { |
|
164 // (7) Finally, this callback should be called after set's above. |
|
165 do_check_true(!!fetchedPref); |
|
166 do_check_eq(fetchedPref.value, 2); |
|
167 next(); |
|
168 }, |
|
169 }); |
|
170 |
|
171 yield; |
|
172 }, |
|
173 |
|
174 function get_nameOnly() { |
|
175 yield set("a.com", "foo", 1); |
|
176 yield set("a.com", "bar", 2); |
|
177 yield set("b.com", "foo", 3); |
|
178 yield setGlobal("foo", 4); |
|
179 |
|
180 yield getOKEx("getByName", ["foo", undefined], [ |
|
181 {"domain": "a.com", "name": "foo", "value": 1}, |
|
182 {"domain": "b.com", "name": "foo", "value": 3}, |
|
183 {"domain": null, "name": "foo", "value": 4} |
|
184 ]); |
|
185 |
|
186 let context = { usePrivateBrowsing: true }; |
|
187 yield set("b.com", "foo", 5, context); |
|
188 |
|
189 yield getOKEx("getByName", ["foo", context], [ |
|
190 {"domain": "a.com", "name": "foo", "value": 1}, |
|
191 {"domain": null, "name": "foo", "value": 4}, |
|
192 {"domain": "b.com", "name": "foo", "value": 5} |
|
193 ]); |
|
194 } |
|
195 ]; |