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 getCachedSubdomainsOK(["a.com", "foo"], []);
13 yield true;
14 },
16 function isomorphicDomains() {
17 yield set("a.com", "foo", 1);
18 getCachedSubdomainsOK(["a.com", "foo"], [["a.com", 1]]);
19 getCachedSubdomainsOK(["http://a.com/huh", "foo"], [["a.com", 1]]);
20 },
22 function names() {
23 yield set("a.com", "foo", 1);
24 getCachedSubdomainsOK(["a.com", "foo"], [["a.com", 1]]);
26 yield set("a.com", "bar", 2);
27 getCachedSubdomainsOK(["a.com", "foo"], [["a.com", 1]]);
28 getCachedSubdomainsOK(["a.com", "bar"], [["a.com", 2]]);
30 yield setGlobal("foo", 3);
31 getCachedSubdomainsOK(["a.com", "foo"], [["a.com", 1]]);
32 getCachedSubdomainsOK(["a.com", "bar"], [["a.com", 2]]);
33 getCachedGlobalOK(["foo"], true, 3);
35 yield setGlobal("bar", 4);
36 getCachedSubdomainsOK(["a.com", "foo"], [["a.com", 1]]);
37 getCachedSubdomainsOK(["a.com", "bar"], [["a.com", 2]]);
38 getCachedGlobalOK(["foo"], true, 3);
39 getCachedGlobalOK(["bar"], true, 4);
40 },
42 function subdomains() {
43 yield set("a.com", "foo", 1);
44 yield set("b.a.com", "foo", 2);
45 getCachedSubdomainsOK(["a.com", "foo"], [["a.com", 1], ["b.a.com", 2]]);
46 getCachedSubdomainsOK(["b.a.com", "foo"], [["b.a.com", 2]]);
47 },
49 function populateViaGet() {
50 yield cps.getByDomainAndName("a.com", "foo", null, makeCallback());
51 getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]);
53 yield cps.getGlobal("foo", null, makeCallback());
54 getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]);
55 getCachedGlobalOK(["foo"], true, undefined);
56 },
58 function populateViaGetSubdomains() {
59 yield cps.getBySubdomainAndName("a.com", "foo", null, makeCallback());
60 getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]);
61 },
63 function populateViaRemove() {
64 yield cps.removeByDomainAndName("a.com", "foo", null, makeCallback());
65 getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]);
67 yield cps.removeBySubdomainAndName("b.com", "foo", null, makeCallback());
68 getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]);
69 getCachedSubdomainsOK(["b.com", "foo"], [["b.com", undefined]]);
71 yield cps.removeGlobal("foo", null, makeCallback());
72 getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]);
73 getCachedSubdomainsOK(["b.com", "foo"], [["b.com", undefined]]);
74 getCachedGlobalOK(["foo"], true, undefined);
76 yield set("a.com", "foo", 1);
77 yield cps.removeByDomainAndName("a.com", "foo", null, makeCallback());
78 getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]);
79 getCachedSubdomainsOK(["b.com", "foo"], [["b.com", undefined]]);
80 getCachedGlobalOK(["foo"], true, undefined);
82 yield set("a.com", "foo", 2);
83 yield set("b.a.com", "foo", 3);
84 yield cps.removeBySubdomainAndName("a.com", "foo", null, makeCallback());
85 getCachedSubdomainsOK(["a.com", "foo"],
86 [["a.com", undefined], ["b.a.com", undefined]]);
87 getCachedSubdomainsOK(["b.com", "foo"], [["b.com", undefined]]);
88 getCachedGlobalOK(["foo"], true, undefined);
89 getCachedSubdomainsOK(["b.a.com", "foo"], [["b.a.com", undefined]]);
91 yield setGlobal("foo", 4);
92 yield cps.removeGlobal("foo", null, makeCallback());
93 getCachedSubdomainsOK(["a.com", "foo"],
94 [["a.com", undefined], ["b.a.com", undefined]]);
95 getCachedSubdomainsOK(["b.com", "foo"], [["b.com", undefined]]);
96 getCachedGlobalOK(["foo"], true, undefined);
97 getCachedSubdomainsOK(["b.a.com", "foo"], [["b.a.com", undefined]]);
98 },
100 function populateViaRemoveByDomain() {
101 yield set("a.com", "foo", 1);
102 yield set("a.com", "bar", 2);
103 yield set("b.a.com", "foo", 3);
104 yield set("b.a.com", "bar", 4);
105 yield cps.removeByDomain("a.com", null, makeCallback());
106 getCachedSubdomainsOK(["a.com", "foo"],
107 [["a.com", undefined], ["b.a.com", 3]]);
108 getCachedSubdomainsOK(["a.com", "bar"],
109 [["a.com", undefined], ["b.a.com", 4]]);
111 yield set("a.com", "foo", 5);
112 yield set("a.com", "bar", 6);
113 yield cps.removeBySubdomain("a.com", null, makeCallback());
114 getCachedSubdomainsOK(["a.com", "foo"],
115 [["a.com", undefined], ["b.a.com", undefined]]);
116 getCachedSubdomainsOK(["a.com", "bar"],
117 [["a.com", undefined], ["b.a.com", undefined]]);
119 yield setGlobal("foo", 7);
120 yield setGlobal("bar", 8);
121 yield cps.removeAllGlobals(null, makeCallback());
122 getCachedGlobalOK(["foo"], true, undefined);
123 getCachedGlobalOK(["bar"], true, undefined);
124 },
126 function populateViaRemoveAllDomains() {
127 yield set("a.com", "foo", 1);
128 yield set("a.com", "bar", 2);
129 yield set("b.com", "foo", 3);
130 yield set("b.com", "bar", 4);
131 yield cps.removeAllDomains(null, makeCallback());
132 getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]);
133 getCachedSubdomainsOK(["a.com", "bar"], [["a.com", undefined]]);
134 getCachedSubdomainsOK(["b.com", "foo"], [["b.com", undefined]]);
135 getCachedSubdomainsOK(["b.com", "bar"], [["b.com", undefined]]);
136 },
138 function populateViaRemoveByName() {
139 yield set("a.com", "foo", 1);
140 yield set("a.com", "bar", 2);
141 yield setGlobal("foo", 3);
142 yield setGlobal("bar", 4);
143 yield cps.removeByName("foo", null, makeCallback());
144 getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]);
145 getCachedSubdomainsOK(["a.com", "bar"], [["a.com", 2]]);
146 getCachedGlobalOK(["foo"], true, undefined);
147 getCachedGlobalOK(["bar"], true, 4);
149 yield cps.removeByName("bar", null, makeCallback());
150 getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]);
151 getCachedSubdomainsOK(["a.com", "bar"], [["a.com", undefined]]);
152 getCachedGlobalOK(["foo"], true, undefined);
153 getCachedGlobalOK(["bar"], true, undefined);
154 },
156 function privateBrowsing() {
157 yield set("a.com", "foo", 1);
158 yield set("a.com", "bar", 2);
159 yield setGlobal("foo", 3);
160 yield setGlobal("bar", 4);
161 yield set("b.com", "foo", 5);
163 let context = { usePrivateBrowsing: true };
164 yield set("a.com", "foo", 6, context);
165 yield setGlobal("foo", 7, context);
166 getCachedSubdomainsOK(["a.com", "foo", context], [["a.com", 6]]);
167 getCachedSubdomainsOK(["a.com", "bar", context], [["a.com", 2]]);
168 getCachedGlobalOK(["foo", context], true, 7);
169 getCachedGlobalOK(["bar", context], true, 4);
170 getCachedSubdomainsOK(["b.com", "foo", context], [["b.com", 5]]);
172 getCachedSubdomainsOK(["a.com", "foo"], [["a.com", 1]]);
173 getCachedSubdomainsOK(["a.com", "bar"], [["a.com", 2]]);
174 getCachedGlobalOK(["foo"], true, 3);
175 getCachedGlobalOK(["bar"], true, 4);
176 getCachedSubdomainsOK(["b.com", "foo"], [["b.com", 5]]);
177 },
179 function erroneous() {
180 do_check_throws(function ()
181 cps.getCachedBySubdomainAndName(null, "foo", null));
182 do_check_throws(function ()
183 cps.getCachedBySubdomainAndName("", "foo", null));
184 do_check_throws(function ()
185 cps.getCachedBySubdomainAndName("a.com", "", null));
186 do_check_throws(function ()
187 cps.getCachedBySubdomainAndName("a.com", null, null));
188 yield true;
189 },
190 ];