Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 getCachedOK(["a.com", "foo"], false, undefined);
13 getCachedGlobalOK(["foo"], false, undefined);
14 yield true;
15 },
17 function isomorphicDomains() {
18 yield set("a.com", "foo", 1);
19 getCachedOK(["a.com", "foo"], true, 1);
20 getCachedOK(["http://a.com/huh", "foo"], true, 1, "a.com");
21 },
23 function names() {
24 yield set("a.com", "foo", 1);
25 getCachedOK(["a.com", "foo"], true, 1);
27 yield set("a.com", "bar", 2);
28 getCachedOK(["a.com", "foo"], true, 1);
29 getCachedOK(["a.com", "bar"], true, 2);
31 yield setGlobal("foo", 3);
32 getCachedOK(["a.com", "foo"], true, 1);
33 getCachedOK(["a.com", "bar"], true, 2);
34 getCachedGlobalOK(["foo"], true, 3);
36 yield setGlobal("bar", 4);
37 getCachedOK(["a.com", "foo"], true, 1);
38 getCachedOK(["a.com", "bar"], true, 2);
39 getCachedGlobalOK(["foo"], true, 3);
40 getCachedGlobalOK(["bar"], true, 4);
41 },
43 function subdomains() {
44 yield set("a.com", "foo", 1);
45 yield set("b.a.com", "foo", 2);
46 getCachedOK(["a.com", "foo"], true, 1);
47 getCachedOK(["b.a.com", "foo"], true, 2);
48 },
50 function privateBrowsing() {
51 yield set("a.com", "foo", 1);
52 yield set("a.com", "bar", 2);
53 yield setGlobal("foo", 3);
54 yield setGlobal("bar", 4);
55 yield set("b.com", "foo", 5);
57 let context = { usePrivateBrowsing: true };
58 yield set("a.com", "foo", 6, context);
59 yield setGlobal("foo", 7, context);
60 getCachedOK(["a.com", "foo", context], true, 6);
61 getCachedOK(["a.com", "bar", context], true, 2);
62 getCachedGlobalOK(["foo", context], true, 7);
63 getCachedGlobalOK(["bar", context], true, 4);
64 getCachedOK(["b.com", "foo", context], true, 5);
66 getCachedOK(["a.com", "foo"], true, 1);
67 getCachedOK(["a.com", "bar"], true, 2);
68 getCachedGlobalOK(["foo"], true, 3);
69 getCachedGlobalOK(["bar"], true, 4);
70 getCachedOK(["b.com", "foo"], true, 5);
71 },
73 function erroneous() {
74 do_check_throws(function ()
75 cps.getCachedByDomainAndName(null, "foo", null));
76 do_check_throws(function ()
77 cps.getCachedByDomainAndName("", "foo", null));
78 do_check_throws(function ()
79 cps.getCachedByDomainAndName("a.com", "", null));
80 do_check_throws(function ()
81 cps.getCachedByDomainAndName("a.com", null, null));
82 do_check_throws(function () cps.getCachedGlobal("", null));
83 do_check_throws(function () cps.getCachedGlobal(null, null));
84 yield true;
85 },
87 function casts() {
88 // SQLite casts booleans to integers. This makes sure the values stored in
89 // the cache are the same as the casted values in the database.
91 yield set("a.com", "foo", false);
92 yield getOK(["a.com", "foo"], 0, "a.com", true);
93 getCachedOK(["a.com", "foo"], true, 0, "a.com", true);
95 yield set("a.com", "bar", true);
96 yield getOK(["a.com", "bar"], 1, "a.com", true);
97 getCachedOK(["a.com", "bar"], true, 1, "a.com", true);
98 },
99 ];