toolkit/components/contentprefs/tests/unit_cps2/test_removeByDomain.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_removeByDomain.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,196 @@
     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.removeByDomain("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 +    yield cps.removeBySubdomain("bogus", null, makeCallback());
    1.27 +    yield dbOK([
    1.28 +      ["a.com", "foo", 1],
    1.29 +      [null, "foo", 2],
    1.30 +    ]);
    1.31 +    yield getOK(["a.com", "foo"], 1);
    1.32 +    yield getGlobalOK(["foo"], 2);
    1.33 +  },
    1.34 +
    1.35 +  function isomorphicDomains() {
    1.36 +    yield set("a.com", "foo", 1);
    1.37 +    yield cps.removeByDomain("a.com", null, makeCallback());
    1.38 +    yield dbOK([]);
    1.39 +    yield getOK(["a.com", "foo"], undefined);
    1.40 +
    1.41 +    yield set("a.com", "foo", 2);
    1.42 +    yield cps.removeByDomain("http://a.com/huh", null, makeCallback());
    1.43 +    yield dbOK([]);
    1.44 +    yield getOK(["a.com", "foo"], undefined);
    1.45 +  },
    1.46 +
    1.47 +  function domains() {
    1.48 +    yield set("a.com", "foo", 1);
    1.49 +    yield set("a.com", "bar", 2);
    1.50 +    yield setGlobal("foo", 3);
    1.51 +    yield setGlobal("bar", 4);
    1.52 +    yield set("b.com", "foo", 5);
    1.53 +    yield set("b.com", "bar", 6);
    1.54 +
    1.55 +    yield cps.removeByDomain("a.com", null, makeCallback());
    1.56 +    yield dbOK([
    1.57 +      [null, "foo", 3],
    1.58 +      [null, "bar", 4],
    1.59 +      ["b.com", "foo", 5],
    1.60 +      ["b.com", "bar", 6],
    1.61 +    ]);
    1.62 +    yield getOK(["a.com", "foo"], undefined);
    1.63 +    yield getOK(["a.com", "bar"], undefined);
    1.64 +    yield getGlobalOK(["foo"], 3);
    1.65 +    yield getGlobalOK(["bar"], 4);
    1.66 +    yield getOK(["b.com", "foo"], 5);
    1.67 +    yield getOK(["b.com", "bar"], 6);
    1.68 +
    1.69 +    yield cps.removeAllGlobals(null, makeCallback());
    1.70 +    yield dbOK([
    1.71 +      ["b.com", "foo", 5],
    1.72 +      ["b.com", "bar", 6],
    1.73 +    ]);
    1.74 +    yield getOK(["a.com", "foo"], undefined);
    1.75 +    yield getOK(["a.com", "bar"], undefined);
    1.76 +    yield getGlobalOK(["foo"], undefined);
    1.77 +    yield getGlobalOK(["bar"], undefined);
    1.78 +    yield getOK(["b.com", "foo"], 5);
    1.79 +    yield getOK(["b.com", "bar"], 6);
    1.80 +
    1.81 +    yield cps.removeByDomain("b.com", null, makeCallback());
    1.82 +    yield dbOK([
    1.83 +    ]);
    1.84 +    yield getOK(["a.com", "foo"], undefined);
    1.85 +    yield getOK(["a.com", "bar"], undefined);
    1.86 +    yield getGlobalOK(["foo"], undefined);
    1.87 +    yield getGlobalOK(["bar"], undefined);
    1.88 +    yield getOK(["b.com", "foo"], undefined);
    1.89 +    yield getOK(["b.com", "bar"], undefined);
    1.90 +  },
    1.91 +
    1.92 +  function subdomains() {
    1.93 +    yield set("a.com", "foo", 1);
    1.94 +    yield set("b.a.com", "foo", 2);
    1.95 +    yield cps.removeByDomain("a.com", null, makeCallback());
    1.96 +    yield dbOK([
    1.97 +      ["b.a.com", "foo", 2],
    1.98 +    ]);
    1.99 +    yield getSubdomainsOK(["a.com", "foo"], [["b.a.com", 2]]);
   1.100 +    yield getSubdomainsOK(["b.a.com", "foo"], [["b.a.com", 2]]);
   1.101 +
   1.102 +    yield set("a.com", "foo", 3);
   1.103 +    yield cps.removeBySubdomain("a.com", null, makeCallback());
   1.104 +    yield dbOK([
   1.105 +    ]);
   1.106 +    yield getSubdomainsOK(["a.com", "foo"], []);
   1.107 +    yield getSubdomainsOK(["b.a.com", "foo"], []);
   1.108 +
   1.109 +    yield set("a.com", "foo", 4);
   1.110 +    yield set("b.a.com", "foo", 5);
   1.111 +    yield cps.removeByDomain("b.a.com", null, makeCallback());
   1.112 +    yield dbOK([
   1.113 +      ["a.com", "foo", 4],
   1.114 +    ]);
   1.115 +    yield getSubdomainsOK(["a.com", "foo"], [["a.com", 4]]);
   1.116 +    yield getSubdomainsOK(["b.a.com", "foo"], []);
   1.117 +
   1.118 +    yield set("b.a.com", "foo", 6);
   1.119 +    yield cps.removeBySubdomain("b.a.com", null, makeCallback());
   1.120 +    yield dbOK([
   1.121 +      ["a.com", "foo", 4],
   1.122 +    ]);
   1.123 +    yield getSubdomainsOK(["a.com", "foo"], [["a.com", 4]]);
   1.124 +    yield getSubdomainsOK(["b.a.com", "foo"], []);
   1.125 +  },
   1.126 +
   1.127 +  function privateBrowsing() {
   1.128 +    yield set("a.com", "foo", 1);
   1.129 +    yield set("a.com", "bar", 2);
   1.130 +    yield setGlobal("foo", 3);
   1.131 +    yield setGlobal("bar", 4);
   1.132 +    yield set("b.com", "foo", 5);
   1.133 +
   1.134 +    let context = { usePrivateBrowsing: true };
   1.135 +    yield set("a.com", "foo", 6, context);
   1.136 +    yield setGlobal("foo", 7, context);
   1.137 +    yield cps.removeByDomain("a.com", context, makeCallback());
   1.138 +    yield cps.removeAllGlobals(context, makeCallback());
   1.139 +    yield dbOK([
   1.140 +      ["b.com", "foo", 5],
   1.141 +    ]);
   1.142 +    yield getOK(["a.com", "foo", context], undefined);
   1.143 +    yield getOK(["a.com", "bar", context], undefined);
   1.144 +    yield getGlobalOK(["foo", context], undefined);
   1.145 +    yield getGlobalOK(["bar", context], undefined);
   1.146 +    yield getOK(["b.com", "foo", context], 5);
   1.147 +
   1.148 +    yield getOK(["a.com", "foo"], undefined);
   1.149 +    yield getOK(["a.com", "bar"], undefined);
   1.150 +    yield getGlobalOK(["foo"], undefined);
   1.151 +    yield getGlobalOK(["bar"], undefined);
   1.152 +    yield getOK(["b.com", "foo"], 5);
   1.153 +  },
   1.154 +
   1.155 +  function erroneous() {
   1.156 +    do_check_throws(function () cps.removeByDomain(null, null));
   1.157 +    do_check_throws(function () cps.removeByDomain("", null));
   1.158 +    do_check_throws(function () cps.removeByDomain("a.com", null, "bogus"));
   1.159 +    do_check_throws(function () cps.removeBySubdomain(null, null));
   1.160 +    do_check_throws(function () cps.removeBySubdomain("", null));
   1.161 +    do_check_throws(function () cps.removeBySubdomain("a.com", null, "bogus"));
   1.162 +    do_check_throws(function () cps.removeAllGlobals(null, "bogus"));
   1.163 +    yield true;
   1.164 +  },
   1.165 +
   1.166 +  function removeByDomain_invalidateCache() {
   1.167 +    yield set("a.com", "foo", 1);
   1.168 +    yield set("a.com", "bar", 2);
   1.169 +    getCachedOK(["a.com", "foo"], true, 1);
   1.170 +    getCachedOK(["a.com", "bar"], true, 2);
   1.171 +    cps.removeByDomain("a.com", null, makeCallback());
   1.172 +    getCachedOK(["a.com", "foo"], false);
   1.173 +    getCachedOK(["a.com", "bar"], false);
   1.174 +    yield;
   1.175 +  },
   1.176 +
   1.177 +  function removeBySubdomain_invalidateCache() {
   1.178 +    yield set("a.com", "foo", 1);
   1.179 +    yield set("b.a.com", "foo", 2);
   1.180 +    getCachedSubdomainsOK(["a.com", "foo"], [
   1.181 +      ["a.com", 1],
   1.182 +      ["b.a.com", 2],
   1.183 +    ]);
   1.184 +    cps.removeBySubdomain("a.com", null, makeCallback());
   1.185 +    getCachedSubdomainsOK(["a.com", "foo"], []);
   1.186 +    yield;
   1.187 +  },
   1.188 +
   1.189 +  function removeAllGlobals_invalidateCache() {
   1.190 +    yield setGlobal("foo", 1);
   1.191 +    yield setGlobal("bar", 2);
   1.192 +    getCachedGlobalOK(["foo"], true, 1);
   1.193 +    getCachedGlobalOK(["bar"], true, 2);
   1.194 +    cps.removeAllGlobals(null, makeCallback());
   1.195 +    getCachedGlobalOK(["foo"], false);
   1.196 +    getCachedGlobalOK(["bar"], false);
   1.197 +    yield;
   1.198 +  },
   1.199 +];

mercurial