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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/contentprefs/tests/unit_cps2/test_removeAllDomains.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,87 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +function run_test() {
     1.9 +  runAsyncTests(tests);
    1.10 +}
    1.11 +
    1.12 +let tests = [
    1.13 +
    1.14 +  function nonexistent() {
    1.15 +    yield setGlobal("foo", 1);
    1.16 +    yield cps.removeAllDomains(null, makeCallback());
    1.17 +    yield dbOK([
    1.18 +      [null, "foo", 1],
    1.19 +    ]);
    1.20 +    yield getGlobalOK(["foo"], 1);
    1.21 +  },
    1.22 +
    1.23 +  function domains() {
    1.24 +    yield set("a.com", "foo", 1);
    1.25 +    yield set("a.com", "bar", 2);
    1.26 +    yield setGlobal("foo", 3);
    1.27 +    yield setGlobal("bar", 4);
    1.28 +    yield set("b.com", "foo", 5);
    1.29 +    yield set("b.com", "bar", 6);
    1.30 +
    1.31 +    yield cps.removeAllDomains(null, makeCallback());
    1.32 +    yield dbOK([
    1.33 +      [null, "foo", 3],
    1.34 +      [null, "bar", 4],
    1.35 +    ]);
    1.36 +    yield getOK(["a.com", "foo"], undefined);
    1.37 +    yield getOK(["a.com", "bar"], undefined);
    1.38 +    yield getGlobalOK(["foo"], 3);
    1.39 +    yield getGlobalOK(["bar"], 4);
    1.40 +    yield getOK(["b.com", "foo"], undefined);
    1.41 +    yield getOK(["b.com", "bar"], undefined);
    1.42 +  },
    1.43 +
    1.44 +  function privateBrowsing() {
    1.45 +    yield set("a.com", "foo", 1);
    1.46 +    yield set("a.com", "bar", 2);
    1.47 +    yield setGlobal("foo", 3);
    1.48 +    yield setGlobal("bar", 4);
    1.49 +    yield set("b.com", "foo", 5);
    1.50 +
    1.51 +    let context = { usePrivateBrowsing: true };
    1.52 +    yield set("a.com", "foo", 6, context);
    1.53 +    yield setGlobal("foo", 7, context);
    1.54 +    yield cps.removeAllDomains(context, makeCallback());
    1.55 +    yield dbOK([
    1.56 +      [null, "foo", 3],
    1.57 +      [null, "bar", 4],
    1.58 +    ]);
    1.59 +    yield getOK(["a.com", "foo", context], undefined);
    1.60 +    yield getOK(["a.com", "bar", context], undefined);
    1.61 +    yield getGlobalOK(["foo", context], 7);
    1.62 +    yield getGlobalOK(["bar", context], 4);
    1.63 +    yield getOK(["b.com", "foo", context], undefined);
    1.64 +
    1.65 +    yield getOK(["a.com", "foo"], undefined);
    1.66 +    yield getOK(["a.com", "bar"], undefined);
    1.67 +    yield getGlobalOK(["foo"], 3);
    1.68 +    yield getGlobalOK(["bar"], 4);
    1.69 +    yield getOK(["b.com", "foo"], undefined);
    1.70 +  },
    1.71 +
    1.72 +  function erroneous() {
    1.73 +    do_check_throws(function () cps.removeAllDomains(null, "bogus"));
    1.74 +    yield true;
    1.75 +  },
    1.76 +
    1.77 +  function invalidateCache() {
    1.78 +    yield set("a.com", "foo", 1);
    1.79 +    yield set("b.com", "bar", 2);
    1.80 +    yield setGlobal("baz", 3);
    1.81 +    getCachedOK(["a.com", "foo"], true, 1);
    1.82 +    getCachedOK(["b.com", "bar"], true, 2);
    1.83 +    getCachedGlobalOK(["baz"], true, 3);
    1.84 +    cps.removeAllDomains(null, makeCallback());
    1.85 +    getCachedOK(["a.com", "foo"], false);
    1.86 +    getCachedOK(["b.com", "bar"], false);
    1.87 +    getCachedGlobalOK(["baz"], true, 3);
    1.88 +    yield;
    1.89 +  },
    1.90 +];

mercurial