Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
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/. */
5 function run_test() {
6 runAsyncTests(tests);
7 }
9 let tests = [
11 function nonexistent() {
12 yield set("a.com", "foo", 1);
13 yield setGlobal("foo", 2);
15 yield cps.removeByDomain("bogus", null, makeCallback());
16 yield dbOK([
17 ["a.com", "foo", 1],
18 [null, "foo", 2],
19 ]);
20 yield getOK(["a.com", "foo"], 1);
21 yield getGlobalOK(["foo"], 2);
23 yield cps.removeBySubdomain("bogus", null, makeCallback());
24 yield dbOK([
25 ["a.com", "foo", 1],
26 [null, "foo", 2],
27 ]);
28 yield getOK(["a.com", "foo"], 1);
29 yield getGlobalOK(["foo"], 2);
30 },
32 function isomorphicDomains() {
33 yield set("a.com", "foo", 1);
34 yield cps.removeByDomain("a.com", null, makeCallback());
35 yield dbOK([]);
36 yield getOK(["a.com", "foo"], undefined);
38 yield set("a.com", "foo", 2);
39 yield cps.removeByDomain("http://a.com/huh", null, makeCallback());
40 yield dbOK([]);
41 yield getOK(["a.com", "foo"], undefined);
42 },
44 function domains() {
45 yield set("a.com", "foo", 1);
46 yield set("a.com", "bar", 2);
47 yield setGlobal("foo", 3);
48 yield setGlobal("bar", 4);
49 yield set("b.com", "foo", 5);
50 yield set("b.com", "bar", 6);
52 yield cps.removeByDomain("a.com", null, makeCallback());
53 yield dbOK([
54 [null, "foo", 3],
55 [null, "bar", 4],
56 ["b.com", "foo", 5],
57 ["b.com", "bar", 6],
58 ]);
59 yield getOK(["a.com", "foo"], undefined);
60 yield getOK(["a.com", "bar"], undefined);
61 yield getGlobalOK(["foo"], 3);
62 yield getGlobalOK(["bar"], 4);
63 yield getOK(["b.com", "foo"], 5);
64 yield getOK(["b.com", "bar"], 6);
66 yield cps.removeAllGlobals(null, makeCallback());
67 yield dbOK([
68 ["b.com", "foo", 5],
69 ["b.com", "bar", 6],
70 ]);
71 yield getOK(["a.com", "foo"], undefined);
72 yield getOK(["a.com", "bar"], undefined);
73 yield getGlobalOK(["foo"], undefined);
74 yield getGlobalOK(["bar"], undefined);
75 yield getOK(["b.com", "foo"], 5);
76 yield getOK(["b.com", "bar"], 6);
78 yield cps.removeByDomain("b.com", null, makeCallback());
79 yield dbOK([
80 ]);
81 yield getOK(["a.com", "foo"], undefined);
82 yield getOK(["a.com", "bar"], undefined);
83 yield getGlobalOK(["foo"], undefined);
84 yield getGlobalOK(["bar"], undefined);
85 yield getOK(["b.com", "foo"], undefined);
86 yield getOK(["b.com", "bar"], undefined);
87 },
89 function subdomains() {
90 yield set("a.com", "foo", 1);
91 yield set("b.a.com", "foo", 2);
92 yield cps.removeByDomain("a.com", null, makeCallback());
93 yield dbOK([
94 ["b.a.com", "foo", 2],
95 ]);
96 yield getSubdomainsOK(["a.com", "foo"], [["b.a.com", 2]]);
97 yield getSubdomainsOK(["b.a.com", "foo"], [["b.a.com", 2]]);
99 yield set("a.com", "foo", 3);
100 yield cps.removeBySubdomain("a.com", null, makeCallback());
101 yield dbOK([
102 ]);
103 yield getSubdomainsOK(["a.com", "foo"], []);
104 yield getSubdomainsOK(["b.a.com", "foo"], []);
106 yield set("a.com", "foo", 4);
107 yield set("b.a.com", "foo", 5);
108 yield cps.removeByDomain("b.a.com", null, makeCallback());
109 yield dbOK([
110 ["a.com", "foo", 4],
111 ]);
112 yield getSubdomainsOK(["a.com", "foo"], [["a.com", 4]]);
113 yield getSubdomainsOK(["b.a.com", "foo"], []);
115 yield set("b.a.com", "foo", 6);
116 yield cps.removeBySubdomain("b.a.com", null, makeCallback());
117 yield dbOK([
118 ["a.com", "foo", 4],
119 ]);
120 yield getSubdomainsOK(["a.com", "foo"], [["a.com", 4]]);
121 yield getSubdomainsOK(["b.a.com", "foo"], []);
122 },
124 function privateBrowsing() {
125 yield set("a.com", "foo", 1);
126 yield set("a.com", "bar", 2);
127 yield setGlobal("foo", 3);
128 yield setGlobal("bar", 4);
129 yield set("b.com", "foo", 5);
131 let context = { usePrivateBrowsing: true };
132 yield set("a.com", "foo", 6, context);
133 yield setGlobal("foo", 7, context);
134 yield cps.removeByDomain("a.com", context, makeCallback());
135 yield cps.removeAllGlobals(context, makeCallback());
136 yield dbOK([
137 ["b.com", "foo", 5],
138 ]);
139 yield getOK(["a.com", "foo", context], undefined);
140 yield getOK(["a.com", "bar", context], undefined);
141 yield getGlobalOK(["foo", context], undefined);
142 yield getGlobalOK(["bar", context], undefined);
143 yield getOK(["b.com", "foo", context], 5);
145 yield getOK(["a.com", "foo"], undefined);
146 yield getOK(["a.com", "bar"], undefined);
147 yield getGlobalOK(["foo"], undefined);
148 yield getGlobalOK(["bar"], undefined);
149 yield getOK(["b.com", "foo"], 5);
150 },
152 function erroneous() {
153 do_check_throws(function () cps.removeByDomain(null, null));
154 do_check_throws(function () cps.removeByDomain("", null));
155 do_check_throws(function () cps.removeByDomain("a.com", null, "bogus"));
156 do_check_throws(function () cps.removeBySubdomain(null, null));
157 do_check_throws(function () cps.removeBySubdomain("", null));
158 do_check_throws(function () cps.removeBySubdomain("a.com", null, "bogus"));
159 do_check_throws(function () cps.removeAllGlobals(null, "bogus"));
160 yield true;
161 },
163 function removeByDomain_invalidateCache() {
164 yield set("a.com", "foo", 1);
165 yield set("a.com", "bar", 2);
166 getCachedOK(["a.com", "foo"], true, 1);
167 getCachedOK(["a.com", "bar"], true, 2);
168 cps.removeByDomain("a.com", null, makeCallback());
169 getCachedOK(["a.com", "foo"], false);
170 getCachedOK(["a.com", "bar"], false);
171 yield;
172 },
174 function removeBySubdomain_invalidateCache() {
175 yield set("a.com", "foo", 1);
176 yield set("b.a.com", "foo", 2);
177 getCachedSubdomainsOK(["a.com", "foo"], [
178 ["a.com", 1],
179 ["b.a.com", 2],
180 ]);
181 cps.removeBySubdomain("a.com", null, makeCallback());
182 getCachedSubdomainsOK(["a.com", "foo"], []);
183 yield;
184 },
186 function removeAllGlobals_invalidateCache() {
187 yield setGlobal("foo", 1);
188 yield setGlobal("bar", 2);
189 getCachedGlobalOK(["foo"], true, 1);
190 getCachedGlobalOK(["bar"], true, 2);
191 cps.removeAllGlobals(null, makeCallback());
192 getCachedGlobalOK(["foo"], false);
193 getCachedGlobalOK(["bar"], false);
194 yield;
195 },
196 ];