toolkit/components/contentprefs/tests/unit_cps2/test_getCached.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_getCached.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,99 @@
     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 +    getCachedOK(["a.com", "foo"], false, undefined);
    1.16 +    getCachedGlobalOK(["foo"], false, undefined);
    1.17 +    yield true;
    1.18 +  },
    1.19 +
    1.20 +  function isomorphicDomains() {
    1.21 +    yield set("a.com", "foo", 1);
    1.22 +    getCachedOK(["a.com", "foo"], true, 1);
    1.23 +    getCachedOK(["http://a.com/huh", "foo"], true, 1, "a.com");
    1.24 +  },
    1.25 +
    1.26 +  function names() {
    1.27 +    yield set("a.com", "foo", 1);
    1.28 +    getCachedOK(["a.com", "foo"], true, 1);
    1.29 +
    1.30 +    yield set("a.com", "bar", 2);
    1.31 +    getCachedOK(["a.com", "foo"], true, 1);
    1.32 +    getCachedOK(["a.com", "bar"], true, 2);
    1.33 +
    1.34 +    yield setGlobal("foo", 3);
    1.35 +    getCachedOK(["a.com", "foo"], true, 1);
    1.36 +    getCachedOK(["a.com", "bar"], true, 2);
    1.37 +    getCachedGlobalOK(["foo"], true, 3);
    1.38 +
    1.39 +    yield setGlobal("bar", 4);
    1.40 +    getCachedOK(["a.com", "foo"], true, 1);
    1.41 +    getCachedOK(["a.com", "bar"], true, 2);
    1.42 +    getCachedGlobalOK(["foo"], true, 3);
    1.43 +    getCachedGlobalOK(["bar"], true, 4);
    1.44 +  },
    1.45 +
    1.46 +  function subdomains() {
    1.47 +    yield set("a.com", "foo", 1);
    1.48 +    yield set("b.a.com", "foo", 2);
    1.49 +    getCachedOK(["a.com", "foo"], true, 1);
    1.50 +    getCachedOK(["b.a.com", "foo"], true, 2);
    1.51 +  },
    1.52 +
    1.53 +  function privateBrowsing() {
    1.54 +    yield set("a.com", "foo", 1);
    1.55 +    yield set("a.com", "bar", 2);
    1.56 +    yield setGlobal("foo", 3);
    1.57 +    yield setGlobal("bar", 4);
    1.58 +    yield set("b.com", "foo", 5);
    1.59 +
    1.60 +    let context = { usePrivateBrowsing: true };
    1.61 +    yield set("a.com", "foo", 6, context);
    1.62 +    yield setGlobal("foo", 7, context);
    1.63 +    getCachedOK(["a.com", "foo", context], true, 6);
    1.64 +    getCachedOK(["a.com", "bar", context], true, 2);
    1.65 +    getCachedGlobalOK(["foo", context], true, 7);
    1.66 +    getCachedGlobalOK(["bar", context], true, 4);
    1.67 +    getCachedOK(["b.com", "foo", context], true, 5);
    1.68 +
    1.69 +    getCachedOK(["a.com", "foo"], true, 1);
    1.70 +    getCachedOK(["a.com", "bar"], true, 2);
    1.71 +    getCachedGlobalOK(["foo"], true, 3);
    1.72 +    getCachedGlobalOK(["bar"], true, 4);
    1.73 +    getCachedOK(["b.com", "foo"], true, 5);
    1.74 +  },
    1.75 +
    1.76 +  function erroneous() {
    1.77 +    do_check_throws(function ()
    1.78 +                    cps.getCachedByDomainAndName(null, "foo", null));
    1.79 +    do_check_throws(function ()
    1.80 +                    cps.getCachedByDomainAndName("", "foo", null));
    1.81 +    do_check_throws(function ()
    1.82 +                    cps.getCachedByDomainAndName("a.com", "", null));
    1.83 +    do_check_throws(function ()
    1.84 +                    cps.getCachedByDomainAndName("a.com", null, null));
    1.85 +    do_check_throws(function () cps.getCachedGlobal("", null));
    1.86 +    do_check_throws(function () cps.getCachedGlobal(null, null));
    1.87 +    yield true;
    1.88 +  },
    1.89 +
    1.90 +  function casts() {
    1.91 +    // SQLite casts booleans to integers.  This makes sure the values stored in
    1.92 +    // the cache are the same as the casted values in the database.
    1.93 +
    1.94 +    yield set("a.com", "foo", false);
    1.95 +    yield getOK(["a.com", "foo"], 0, "a.com", true);
    1.96 +    getCachedOK(["a.com", "foo"], true, 0, "a.com", true);
    1.97 +
    1.98 +    yield set("a.com", "bar", true);
    1.99 +    yield getOK(["a.com", "bar"], 1, "a.com", true);
   1.100 +    getCachedOK(["a.com", "bar"], true, 1, "a.com", true);
   1.101 +  },
   1.102 +];

mercurial