toolkit/components/contentprefs/tests/unit_cps2/test_removeByName.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_removeByName.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,96 @@
     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 set("a.com", "foo", 1);
    1.16 +    yield setGlobal("foo", 2);
    1.17 +
    1.18 +    yield cps.removeByName("bogus", null, makeCallback());
    1.19 +    yield dbOK([
    1.20 +      ["a.com", "foo", 1],
    1.21 +      [null, "foo", 2],
    1.22 +    ]);
    1.23 +    yield getOK(["a.com", "foo"], 1);
    1.24 +    yield getGlobalOK(["foo"], 2);
    1.25 +  },
    1.26 +
    1.27 +  function names() {
    1.28 +    yield set("a.com", "foo", 1);
    1.29 +    yield set("a.com", "bar", 2);
    1.30 +    yield setGlobal("foo", 3);
    1.31 +    yield setGlobal("bar", 4);
    1.32 +    yield set("b.com", "foo", 5);
    1.33 +    yield set("b.com", "bar", 6);
    1.34 +
    1.35 +    yield cps.removeByName("foo", null, makeCallback());
    1.36 +    yield dbOK([
    1.37 +      ["a.com", "bar", 2],
    1.38 +      [null, "bar", 4],
    1.39 +      ["b.com", "bar", 6],
    1.40 +    ]);
    1.41 +    yield getOK(["a.com", "foo"], undefined);
    1.42 +    yield getOK(["a.com", "bar"], 2);
    1.43 +    yield getGlobalOK(["foo"], undefined);
    1.44 +    yield getGlobalOK(["bar"], 4);
    1.45 +    yield getOK(["b.com", "foo"], undefined);
    1.46 +    yield getOK(["b.com", "bar"], 6);
    1.47 +  },
    1.48 +
    1.49 +  function privateBrowsing() {
    1.50 +    yield set("a.com", "foo", 1);
    1.51 +    yield set("a.com", "bar", 2);
    1.52 +    yield setGlobal("foo", 3);
    1.53 +    yield setGlobal("bar", 4);
    1.54 +    yield set("b.com", "foo", 5);
    1.55 +    yield set("b.com", "bar", 6);
    1.56 +
    1.57 +    let context = { usePrivateBrowsing: true };
    1.58 +    yield set("a.com", "foo", 7, context);
    1.59 +    yield setGlobal("foo", 8, context);
    1.60 +    yield set("b.com", "bar", 9, context);
    1.61 +    yield cps.removeByName("bar", context, makeCallback());
    1.62 +    yield dbOK([
    1.63 +      ["a.com", "foo", 1],
    1.64 +      [null, "foo", 3],
    1.65 +      ["b.com", "foo", 5],
    1.66 +    ]);
    1.67 +    yield getOK(["a.com", "foo", context], 7);
    1.68 +    yield getOK(["a.com", "bar", context], undefined);
    1.69 +    yield getGlobalOK(["foo", context], 8);
    1.70 +    yield getGlobalOK(["bar", context], undefined);
    1.71 +    yield getOK(["b.com", "foo", context], 5);
    1.72 +    yield getOK(["b.com", "bar", context], undefined);
    1.73 +
    1.74 +    yield getOK(["a.com", "foo"], 1);
    1.75 +    yield getOK(["a.com", "bar"], undefined);
    1.76 +    yield getGlobalOK(["foo"], 3);
    1.77 +    yield getGlobalOK(["bar"], undefined);
    1.78 +    yield getOK(["b.com", "foo"], 5);
    1.79 +    yield getOK(["b.com", "bar"], undefined);
    1.80 +  },
    1.81 +
    1.82 +  function erroneous() {
    1.83 +    do_check_throws(function () cps.removeByName("", null));
    1.84 +    do_check_throws(function () cps.removeByName(null, null));
    1.85 +    do_check_throws(function () cps.removeByName("foo", null, "bogus"));
    1.86 +    yield true;
    1.87 +  },
    1.88 +
    1.89 +  function invalidateCache() {
    1.90 +    yield set("a.com", "foo", 1);
    1.91 +    yield set("b.com", "foo", 2);
    1.92 +    getCachedOK(["a.com", "foo"], true, 1);
    1.93 +    getCachedOK(["b.com", "foo"], true, 2);
    1.94 +    cps.removeByName("foo", null, makeCallback());
    1.95 +    getCachedOK(["a.com", "foo"], false);
    1.96 +    getCachedOK(["b.com", "foo"], false);
    1.97 +    yield;
    1.98 +  },
    1.99 +];

mercurial