toolkit/components/contentprefs/tests/unit_cps2/test_removeByDomain.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 function run_test() {
michael@0 6 runAsyncTests(tests);
michael@0 7 }
michael@0 8
michael@0 9 let tests = [
michael@0 10
michael@0 11 function nonexistent() {
michael@0 12 yield set("a.com", "foo", 1);
michael@0 13 yield setGlobal("foo", 2);
michael@0 14
michael@0 15 yield cps.removeByDomain("bogus", null, makeCallback());
michael@0 16 yield dbOK([
michael@0 17 ["a.com", "foo", 1],
michael@0 18 [null, "foo", 2],
michael@0 19 ]);
michael@0 20 yield getOK(["a.com", "foo"], 1);
michael@0 21 yield getGlobalOK(["foo"], 2);
michael@0 22
michael@0 23 yield cps.removeBySubdomain("bogus", null, makeCallback());
michael@0 24 yield dbOK([
michael@0 25 ["a.com", "foo", 1],
michael@0 26 [null, "foo", 2],
michael@0 27 ]);
michael@0 28 yield getOK(["a.com", "foo"], 1);
michael@0 29 yield getGlobalOK(["foo"], 2);
michael@0 30 },
michael@0 31
michael@0 32 function isomorphicDomains() {
michael@0 33 yield set("a.com", "foo", 1);
michael@0 34 yield cps.removeByDomain("a.com", null, makeCallback());
michael@0 35 yield dbOK([]);
michael@0 36 yield getOK(["a.com", "foo"], undefined);
michael@0 37
michael@0 38 yield set("a.com", "foo", 2);
michael@0 39 yield cps.removeByDomain("http://a.com/huh", null, makeCallback());
michael@0 40 yield dbOK([]);
michael@0 41 yield getOK(["a.com", "foo"], undefined);
michael@0 42 },
michael@0 43
michael@0 44 function domains() {
michael@0 45 yield set("a.com", "foo", 1);
michael@0 46 yield set("a.com", "bar", 2);
michael@0 47 yield setGlobal("foo", 3);
michael@0 48 yield setGlobal("bar", 4);
michael@0 49 yield set("b.com", "foo", 5);
michael@0 50 yield set("b.com", "bar", 6);
michael@0 51
michael@0 52 yield cps.removeByDomain("a.com", null, makeCallback());
michael@0 53 yield dbOK([
michael@0 54 [null, "foo", 3],
michael@0 55 [null, "bar", 4],
michael@0 56 ["b.com", "foo", 5],
michael@0 57 ["b.com", "bar", 6],
michael@0 58 ]);
michael@0 59 yield getOK(["a.com", "foo"], undefined);
michael@0 60 yield getOK(["a.com", "bar"], undefined);
michael@0 61 yield getGlobalOK(["foo"], 3);
michael@0 62 yield getGlobalOK(["bar"], 4);
michael@0 63 yield getOK(["b.com", "foo"], 5);
michael@0 64 yield getOK(["b.com", "bar"], 6);
michael@0 65
michael@0 66 yield cps.removeAllGlobals(null, makeCallback());
michael@0 67 yield dbOK([
michael@0 68 ["b.com", "foo", 5],
michael@0 69 ["b.com", "bar", 6],
michael@0 70 ]);
michael@0 71 yield getOK(["a.com", "foo"], undefined);
michael@0 72 yield getOK(["a.com", "bar"], undefined);
michael@0 73 yield getGlobalOK(["foo"], undefined);
michael@0 74 yield getGlobalOK(["bar"], undefined);
michael@0 75 yield getOK(["b.com", "foo"], 5);
michael@0 76 yield getOK(["b.com", "bar"], 6);
michael@0 77
michael@0 78 yield cps.removeByDomain("b.com", null, makeCallback());
michael@0 79 yield dbOK([
michael@0 80 ]);
michael@0 81 yield getOK(["a.com", "foo"], undefined);
michael@0 82 yield getOK(["a.com", "bar"], undefined);
michael@0 83 yield getGlobalOK(["foo"], undefined);
michael@0 84 yield getGlobalOK(["bar"], undefined);
michael@0 85 yield getOK(["b.com", "foo"], undefined);
michael@0 86 yield getOK(["b.com", "bar"], undefined);
michael@0 87 },
michael@0 88
michael@0 89 function subdomains() {
michael@0 90 yield set("a.com", "foo", 1);
michael@0 91 yield set("b.a.com", "foo", 2);
michael@0 92 yield cps.removeByDomain("a.com", null, makeCallback());
michael@0 93 yield dbOK([
michael@0 94 ["b.a.com", "foo", 2],
michael@0 95 ]);
michael@0 96 yield getSubdomainsOK(["a.com", "foo"], [["b.a.com", 2]]);
michael@0 97 yield getSubdomainsOK(["b.a.com", "foo"], [["b.a.com", 2]]);
michael@0 98
michael@0 99 yield set("a.com", "foo", 3);
michael@0 100 yield cps.removeBySubdomain("a.com", null, makeCallback());
michael@0 101 yield dbOK([
michael@0 102 ]);
michael@0 103 yield getSubdomainsOK(["a.com", "foo"], []);
michael@0 104 yield getSubdomainsOK(["b.a.com", "foo"], []);
michael@0 105
michael@0 106 yield set("a.com", "foo", 4);
michael@0 107 yield set("b.a.com", "foo", 5);
michael@0 108 yield cps.removeByDomain("b.a.com", null, makeCallback());
michael@0 109 yield dbOK([
michael@0 110 ["a.com", "foo", 4],
michael@0 111 ]);
michael@0 112 yield getSubdomainsOK(["a.com", "foo"], [["a.com", 4]]);
michael@0 113 yield getSubdomainsOK(["b.a.com", "foo"], []);
michael@0 114
michael@0 115 yield set("b.a.com", "foo", 6);
michael@0 116 yield cps.removeBySubdomain("b.a.com", null, makeCallback());
michael@0 117 yield dbOK([
michael@0 118 ["a.com", "foo", 4],
michael@0 119 ]);
michael@0 120 yield getSubdomainsOK(["a.com", "foo"], [["a.com", 4]]);
michael@0 121 yield getSubdomainsOK(["b.a.com", "foo"], []);
michael@0 122 },
michael@0 123
michael@0 124 function privateBrowsing() {
michael@0 125 yield set("a.com", "foo", 1);
michael@0 126 yield set("a.com", "bar", 2);
michael@0 127 yield setGlobal("foo", 3);
michael@0 128 yield setGlobal("bar", 4);
michael@0 129 yield set("b.com", "foo", 5);
michael@0 130
michael@0 131 let context = { usePrivateBrowsing: true };
michael@0 132 yield set("a.com", "foo", 6, context);
michael@0 133 yield setGlobal("foo", 7, context);
michael@0 134 yield cps.removeByDomain("a.com", context, makeCallback());
michael@0 135 yield cps.removeAllGlobals(context, makeCallback());
michael@0 136 yield dbOK([
michael@0 137 ["b.com", "foo", 5],
michael@0 138 ]);
michael@0 139 yield getOK(["a.com", "foo", context], undefined);
michael@0 140 yield getOK(["a.com", "bar", context], undefined);
michael@0 141 yield getGlobalOK(["foo", context], undefined);
michael@0 142 yield getGlobalOK(["bar", context], undefined);
michael@0 143 yield getOK(["b.com", "foo", context], 5);
michael@0 144
michael@0 145 yield getOK(["a.com", "foo"], undefined);
michael@0 146 yield getOK(["a.com", "bar"], undefined);
michael@0 147 yield getGlobalOK(["foo"], undefined);
michael@0 148 yield getGlobalOK(["bar"], undefined);
michael@0 149 yield getOK(["b.com", "foo"], 5);
michael@0 150 },
michael@0 151
michael@0 152 function erroneous() {
michael@0 153 do_check_throws(function () cps.removeByDomain(null, null));
michael@0 154 do_check_throws(function () cps.removeByDomain("", null));
michael@0 155 do_check_throws(function () cps.removeByDomain("a.com", null, "bogus"));
michael@0 156 do_check_throws(function () cps.removeBySubdomain(null, null));
michael@0 157 do_check_throws(function () cps.removeBySubdomain("", null));
michael@0 158 do_check_throws(function () cps.removeBySubdomain("a.com", null, "bogus"));
michael@0 159 do_check_throws(function () cps.removeAllGlobals(null, "bogus"));
michael@0 160 yield true;
michael@0 161 },
michael@0 162
michael@0 163 function removeByDomain_invalidateCache() {
michael@0 164 yield set("a.com", "foo", 1);
michael@0 165 yield set("a.com", "bar", 2);
michael@0 166 getCachedOK(["a.com", "foo"], true, 1);
michael@0 167 getCachedOK(["a.com", "bar"], true, 2);
michael@0 168 cps.removeByDomain("a.com", null, makeCallback());
michael@0 169 getCachedOK(["a.com", "foo"], false);
michael@0 170 getCachedOK(["a.com", "bar"], false);
michael@0 171 yield;
michael@0 172 },
michael@0 173
michael@0 174 function removeBySubdomain_invalidateCache() {
michael@0 175 yield set("a.com", "foo", 1);
michael@0 176 yield set("b.a.com", "foo", 2);
michael@0 177 getCachedSubdomainsOK(["a.com", "foo"], [
michael@0 178 ["a.com", 1],
michael@0 179 ["b.a.com", 2],
michael@0 180 ]);
michael@0 181 cps.removeBySubdomain("a.com", null, makeCallback());
michael@0 182 getCachedSubdomainsOK(["a.com", "foo"], []);
michael@0 183 yield;
michael@0 184 },
michael@0 185
michael@0 186 function removeAllGlobals_invalidateCache() {
michael@0 187 yield setGlobal("foo", 1);
michael@0 188 yield setGlobal("bar", 2);
michael@0 189 getCachedGlobalOK(["foo"], true, 1);
michael@0 190 getCachedGlobalOK(["bar"], true, 2);
michael@0 191 cps.removeAllGlobals(null, makeCallback());
michael@0 192 getCachedGlobalOK(["foo"], false);
michael@0 193 getCachedGlobalOK(["bar"], false);
michael@0 194 yield;
michael@0 195 },
michael@0 196 ];

mercurial