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

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

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 setGlobal("foo", 1);
michael@0 13 yield cps.removeAllDomains(null, makeCallback());
michael@0 14 yield dbOK([
michael@0 15 [null, "foo", 1],
michael@0 16 ]);
michael@0 17 yield getGlobalOK(["foo"], 1);
michael@0 18 },
michael@0 19
michael@0 20 function domains() {
michael@0 21 yield set("a.com", "foo", 1);
michael@0 22 yield set("a.com", "bar", 2);
michael@0 23 yield setGlobal("foo", 3);
michael@0 24 yield setGlobal("bar", 4);
michael@0 25 yield set("b.com", "foo", 5);
michael@0 26 yield set("b.com", "bar", 6);
michael@0 27
michael@0 28 yield cps.removeAllDomains(null, makeCallback());
michael@0 29 yield dbOK([
michael@0 30 [null, "foo", 3],
michael@0 31 [null, "bar", 4],
michael@0 32 ]);
michael@0 33 yield getOK(["a.com", "foo"], undefined);
michael@0 34 yield getOK(["a.com", "bar"], undefined);
michael@0 35 yield getGlobalOK(["foo"], 3);
michael@0 36 yield getGlobalOK(["bar"], 4);
michael@0 37 yield getOK(["b.com", "foo"], undefined);
michael@0 38 yield getOK(["b.com", "bar"], undefined);
michael@0 39 },
michael@0 40
michael@0 41 function privateBrowsing() {
michael@0 42 yield set("a.com", "foo", 1);
michael@0 43 yield set("a.com", "bar", 2);
michael@0 44 yield setGlobal("foo", 3);
michael@0 45 yield setGlobal("bar", 4);
michael@0 46 yield set("b.com", "foo", 5);
michael@0 47
michael@0 48 let context = { usePrivateBrowsing: true };
michael@0 49 yield set("a.com", "foo", 6, context);
michael@0 50 yield setGlobal("foo", 7, context);
michael@0 51 yield cps.removeAllDomains(context, makeCallback());
michael@0 52 yield dbOK([
michael@0 53 [null, "foo", 3],
michael@0 54 [null, "bar", 4],
michael@0 55 ]);
michael@0 56 yield getOK(["a.com", "foo", context], undefined);
michael@0 57 yield getOK(["a.com", "bar", context], undefined);
michael@0 58 yield getGlobalOK(["foo", context], 7);
michael@0 59 yield getGlobalOK(["bar", context], 4);
michael@0 60 yield getOK(["b.com", "foo", context], undefined);
michael@0 61
michael@0 62 yield getOK(["a.com", "foo"], undefined);
michael@0 63 yield getOK(["a.com", "bar"], undefined);
michael@0 64 yield getGlobalOK(["foo"], 3);
michael@0 65 yield getGlobalOK(["bar"], 4);
michael@0 66 yield getOK(["b.com", "foo"], undefined);
michael@0 67 },
michael@0 68
michael@0 69 function erroneous() {
michael@0 70 do_check_throws(function () cps.removeAllDomains(null, "bogus"));
michael@0 71 yield true;
michael@0 72 },
michael@0 73
michael@0 74 function invalidateCache() {
michael@0 75 yield set("a.com", "foo", 1);
michael@0 76 yield set("b.com", "bar", 2);
michael@0 77 yield setGlobal("baz", 3);
michael@0 78 getCachedOK(["a.com", "foo"], true, 1);
michael@0 79 getCachedOK(["b.com", "bar"], true, 2);
michael@0 80 getCachedGlobalOK(["baz"], true, 3);
michael@0 81 cps.removeAllDomains(null, makeCallback());
michael@0 82 getCachedOK(["a.com", "foo"], false);
michael@0 83 getCachedOK(["b.com", "bar"], false);
michael@0 84 getCachedGlobalOK(["baz"], true, 3);
michael@0 85 yield;
michael@0 86 },
michael@0 87 ];

mercurial