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.
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.removeByDomainAndName("a.com", "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.removeBySubdomainAndName("a.com", "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 | yield cps.removeGlobal("bogus", null, makeCallback()); |
michael@0 | 32 | yield dbOK([ |
michael@0 | 33 | ["a.com", "foo", 1], |
michael@0 | 34 | [null, "foo", 2], |
michael@0 | 35 | ]); |
michael@0 | 36 | yield getOK(["a.com", "foo"], 1); |
michael@0 | 37 | yield getGlobalOK(["foo"], 2); |
michael@0 | 38 | |
michael@0 | 39 | yield cps.removeByDomainAndName("bogus", "bogus", null, makeCallback()); |
michael@0 | 40 | yield dbOK([ |
michael@0 | 41 | ["a.com", "foo", 1], |
michael@0 | 42 | [null, "foo", 2], |
michael@0 | 43 | ]); |
michael@0 | 44 | yield getOK(["a.com", "foo"], 1); |
michael@0 | 45 | yield getGlobalOK(["foo"], 2); |
michael@0 | 46 | }, |
michael@0 | 47 | |
michael@0 | 48 | function isomorphicDomains() { |
michael@0 | 49 | yield set("a.com", "foo", 1); |
michael@0 | 50 | yield cps.removeByDomainAndName("a.com", "foo", null, makeCallback()); |
michael@0 | 51 | yield dbOK([]); |
michael@0 | 52 | yield getOK(["a.com", "foo"], undefined); |
michael@0 | 53 | |
michael@0 | 54 | yield set("a.com", "foo", 2); |
michael@0 | 55 | yield cps.removeByDomainAndName("http://a.com/huh", "foo", null, |
michael@0 | 56 | makeCallback()); |
michael@0 | 57 | yield dbOK([]); |
michael@0 | 58 | yield getOK(["a.com", "foo"], undefined); |
michael@0 | 59 | }, |
michael@0 | 60 | |
michael@0 | 61 | function names() { |
michael@0 | 62 | yield set("a.com", "foo", 1); |
michael@0 | 63 | yield set("a.com", "bar", 2); |
michael@0 | 64 | yield setGlobal("foo", 3); |
michael@0 | 65 | yield setGlobal("bar", 4); |
michael@0 | 66 | |
michael@0 | 67 | yield cps.removeByDomainAndName("a.com", "foo", null, makeCallback()); |
michael@0 | 68 | yield dbOK([ |
michael@0 | 69 | ["a.com", "bar", 2], |
michael@0 | 70 | [null, "foo", 3], |
michael@0 | 71 | [null, "bar", 4], |
michael@0 | 72 | ]); |
michael@0 | 73 | yield getOK(["a.com", "foo"], undefined); |
michael@0 | 74 | yield getOK(["a.com", "bar"], 2); |
michael@0 | 75 | yield getGlobalOK(["foo"], 3); |
michael@0 | 76 | yield getGlobalOK(["bar"], 4); |
michael@0 | 77 | |
michael@0 | 78 | yield cps.removeGlobal("foo", null, makeCallback()); |
michael@0 | 79 | yield dbOK([ |
michael@0 | 80 | ["a.com", "bar", 2], |
michael@0 | 81 | [null, "bar", 4], |
michael@0 | 82 | ]); |
michael@0 | 83 | yield getOK(["a.com", "foo"], undefined); |
michael@0 | 84 | yield getOK(["a.com", "bar"], 2); |
michael@0 | 85 | yield getGlobalOK(["foo"], undefined); |
michael@0 | 86 | yield getGlobalOK(["bar"], 4); |
michael@0 | 87 | |
michael@0 | 88 | yield cps.removeByDomainAndName("a.com", "bar", null, makeCallback()); |
michael@0 | 89 | yield dbOK([ |
michael@0 | 90 | [null, "bar", 4], |
michael@0 | 91 | ]); |
michael@0 | 92 | yield getOK(["a.com", "foo"], undefined); |
michael@0 | 93 | yield getOK(["a.com", "bar"], undefined); |
michael@0 | 94 | yield getGlobalOK(["foo"], undefined); |
michael@0 | 95 | yield getGlobalOK(["bar"], 4); |
michael@0 | 96 | |
michael@0 | 97 | yield cps.removeGlobal("bar", null, makeCallback()); |
michael@0 | 98 | yield dbOK([ |
michael@0 | 99 | ]); |
michael@0 | 100 | yield getOK(["a.com", "foo"], undefined); |
michael@0 | 101 | yield getOK(["a.com", "bar"], undefined); |
michael@0 | 102 | yield getGlobalOK(["foo"], undefined); |
michael@0 | 103 | yield getGlobalOK(["bar"], undefined); |
michael@0 | 104 | }, |
michael@0 | 105 | |
michael@0 | 106 | function subdomains() { |
michael@0 | 107 | yield set("a.com", "foo", 1); |
michael@0 | 108 | yield set("b.a.com", "foo", 2); |
michael@0 | 109 | yield cps.removeByDomainAndName("a.com", "foo", null, makeCallback()); |
michael@0 | 110 | yield dbOK([ |
michael@0 | 111 | ["b.a.com", "foo", 2], |
michael@0 | 112 | ]); |
michael@0 | 113 | yield getSubdomainsOK(["a.com", "foo"], [["b.a.com", 2]]); |
michael@0 | 114 | yield getSubdomainsOK(["b.a.com", "foo"], [["b.a.com", 2]]); |
michael@0 | 115 | |
michael@0 | 116 | yield set("a.com", "foo", 3); |
michael@0 | 117 | yield cps.removeBySubdomainAndName("a.com", "foo", null, makeCallback()); |
michael@0 | 118 | yield dbOK([ |
michael@0 | 119 | ]); |
michael@0 | 120 | yield getSubdomainsOK(["a.com", "foo"], []); |
michael@0 | 121 | yield getSubdomainsOK(["b.a.com", "foo"], []); |
michael@0 | 122 | |
michael@0 | 123 | yield set("a.com", "foo", 4); |
michael@0 | 124 | yield set("b.a.com", "foo", 5); |
michael@0 | 125 | yield cps.removeByDomainAndName("b.a.com", "foo", null, makeCallback()); |
michael@0 | 126 | yield dbOK([ |
michael@0 | 127 | ["a.com", "foo", 4], |
michael@0 | 128 | ]); |
michael@0 | 129 | yield getSubdomainsOK(["a.com", "foo"], [["a.com", 4]]); |
michael@0 | 130 | yield getSubdomainsOK(["b.a.com", "foo"], []); |
michael@0 | 131 | |
michael@0 | 132 | yield set("b.a.com", "foo", 6); |
michael@0 | 133 | yield cps.removeBySubdomainAndName("b.a.com", "foo", null, makeCallback()); |
michael@0 | 134 | yield dbOK([ |
michael@0 | 135 | ["a.com", "foo", 4], |
michael@0 | 136 | ]); |
michael@0 | 137 | yield getSubdomainsOK(["a.com", "foo"], [["a.com", 4]]); |
michael@0 | 138 | yield getSubdomainsOK(["b.a.com", "foo"], []); |
michael@0 | 139 | }, |
michael@0 | 140 | |
michael@0 | 141 | function privateBrowsing() { |
michael@0 | 142 | yield set("a.com", "foo", 1); |
michael@0 | 143 | yield set("a.com", "bar", 2); |
michael@0 | 144 | yield setGlobal("foo", 3); |
michael@0 | 145 | yield setGlobal("bar", 4); |
michael@0 | 146 | yield setGlobal("qux", 5); |
michael@0 | 147 | yield set("b.com", "foo", 6); |
michael@0 | 148 | yield set("b.com", "bar", 7); |
michael@0 | 149 | |
michael@0 | 150 | let context = { usePrivateBrowsing: true }; |
michael@0 | 151 | yield set("a.com", "foo", 8, context); |
michael@0 | 152 | yield setGlobal("foo", 9, context); |
michael@0 | 153 | yield cps.removeByDomainAndName("a.com", "foo", context, makeCallback()); |
michael@0 | 154 | yield cps.removeGlobal("foo", context, makeCallback()); |
michael@0 | 155 | yield cps.removeGlobal("qux", context, makeCallback()); |
michael@0 | 156 | yield cps.removeByDomainAndName("b.com", "foo", context, makeCallback()); |
michael@0 | 157 | yield dbOK([ |
michael@0 | 158 | ["a.com", "bar", 2], |
michael@0 | 159 | [null, "bar", 4], |
michael@0 | 160 | ["b.com", "bar", 7], |
michael@0 | 161 | ]); |
michael@0 | 162 | yield getOK(["a.com", "foo", context], undefined); |
michael@0 | 163 | yield getOK(["a.com", "bar", context], 2); |
michael@0 | 164 | yield getGlobalOK(["foo", context], undefined); |
michael@0 | 165 | yield getGlobalOK(["bar", context], 4); |
michael@0 | 166 | yield getGlobalOK(["qux", context], undefined); |
michael@0 | 167 | yield getOK(["b.com", "foo", context], undefined); |
michael@0 | 168 | yield getOK(["b.com", "bar", context], 7); |
michael@0 | 169 | |
michael@0 | 170 | yield getOK(["a.com", "foo"], undefined); |
michael@0 | 171 | yield getOK(["a.com", "bar"], 2); |
michael@0 | 172 | yield getGlobalOK(["foo"], undefined); |
michael@0 | 173 | yield getGlobalOK(["bar"], 4); |
michael@0 | 174 | yield getGlobalOK(["qux"], undefined); |
michael@0 | 175 | yield getOK(["b.com", "foo"], undefined); |
michael@0 | 176 | yield getOK(["b.com", "bar"], 7); |
michael@0 | 177 | }, |
michael@0 | 178 | |
michael@0 | 179 | function erroneous() { |
michael@0 | 180 | do_check_throws(function () cps.removeByDomainAndName(null, "foo", null)); |
michael@0 | 181 | do_check_throws(function () cps.removeByDomainAndName("", "foo", null)); |
michael@0 | 182 | do_check_throws(function () cps.removeByDomainAndName("a.com", "foo", null, |
michael@0 | 183 | "bogus")); |
michael@0 | 184 | do_check_throws(function () cps.removeBySubdomainAndName(null, "foo", |
michael@0 | 185 | null)); |
michael@0 | 186 | do_check_throws(function () cps.removeBySubdomainAndName("", "foo", null)); |
michael@0 | 187 | do_check_throws(function () cps.removeBySubdomainAndName("a.com", "foo", |
michael@0 | 188 | null, "bogus")); |
michael@0 | 189 | do_check_throws(function () cps.removeGlobal("", null)); |
michael@0 | 190 | do_check_throws(function () cps.removeGlobal(null, null)); |
michael@0 | 191 | do_check_throws(function () cps.removeGlobal("foo", null, "bogus")); |
michael@0 | 192 | yield true; |
michael@0 | 193 | }, |
michael@0 | 194 | |
michael@0 | 195 | function removeByDomainAndName_invalidateCache() { |
michael@0 | 196 | yield set("a.com", "foo", 1); |
michael@0 | 197 | getCachedOK(["a.com", "foo"], true, 1); |
michael@0 | 198 | cps.removeByDomainAndName("a.com", "foo", null, makeCallback()); |
michael@0 | 199 | getCachedOK(["a.com", "foo"], false); |
michael@0 | 200 | yield; |
michael@0 | 201 | }, |
michael@0 | 202 | |
michael@0 | 203 | function removeBySubdomainAndName_invalidateCache() { |
michael@0 | 204 | yield set("a.com", "foo", 1); |
michael@0 | 205 | yield set("b.a.com", "foo", 2); |
michael@0 | 206 | getCachedSubdomainsOK(["a.com", "foo"], [ |
michael@0 | 207 | ["a.com", 1], |
michael@0 | 208 | ["b.a.com", 2], |
michael@0 | 209 | ]); |
michael@0 | 210 | cps.removeBySubdomainAndName("a.com", "foo", null, makeCallback()); |
michael@0 | 211 | getCachedSubdomainsOK(["a.com", "foo"], []); |
michael@0 | 212 | yield; |
michael@0 | 213 | }, |
michael@0 | 214 | |
michael@0 | 215 | function removeGlobal_invalidateCache() { |
michael@0 | 216 | yield setGlobal("foo", 1); |
michael@0 | 217 | getCachedGlobalOK(["foo"], true, 1); |
michael@0 | 218 | cps.removeGlobal("foo", null, makeCallback()); |
michael@0 | 219 | getCachedGlobalOK(["foo"], false); |
michael@0 | 220 | yield; |
michael@0 | 221 | }, |
michael@0 | 222 | ]; |