toolkit/components/contentprefs/tests/unit_cps2/test_getSubdomains.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_getSubdomains.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,73 @@
     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 get_nonexistent() {
    1.15 +    yield getSubdomainsOK(["a.com", "foo"], []);
    1.16 +  },
    1.17 +
    1.18 +  function isomorphicDomains() {
    1.19 +    yield set("a.com", "foo", 1);
    1.20 +    yield getSubdomainsOK(["a.com", "foo"], [["a.com", 1]]);
    1.21 +    yield getSubdomainsOK(["http://a.com/huh", "foo"], [["a.com", 1]]);
    1.22 +  },
    1.23 +
    1.24 +  function names() {
    1.25 +    yield set("a.com", "foo", 1);
    1.26 +    yield getSubdomainsOK(["a.com", "foo"], [["a.com", 1]]);
    1.27 +
    1.28 +    yield set("a.com", "bar", 2);
    1.29 +    yield getSubdomainsOK(["a.com", "foo"], [["a.com", 1]]);
    1.30 +    yield getSubdomainsOK(["a.com", "bar"], [["a.com", 2]]);
    1.31 +
    1.32 +    yield setGlobal("foo", 3);
    1.33 +    yield getSubdomainsOK(["a.com", "foo"], [["a.com", 1]]);
    1.34 +    yield getSubdomainsOK(["a.com", "bar"], [["a.com", 2]]);
    1.35 +  },
    1.36 +
    1.37 +  function subdomains() {
    1.38 +    yield set("a.com", "foo", 1);
    1.39 +    yield set("b.a.com", "foo", 2);
    1.40 +    yield getSubdomainsOK(["a.com", "foo"], [["a.com", 1], ["b.a.com", 2]]);
    1.41 +    yield getSubdomainsOK(["b.a.com", "foo"], [["b.a.com", 2]]);
    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 getSubdomainsOK(["a.com", "foo", context], [["a.com", 6]]);
    1.55 +    yield getSubdomainsOK(["a.com", "bar", context], [["a.com", 2]]);
    1.56 +    yield getSubdomainsOK(["b.com", "foo", context], [["b.com", 5]]);
    1.57 +
    1.58 +    yield getSubdomainsOK(["a.com", "foo"], [["a.com", 1]]);
    1.59 +    yield getSubdomainsOK(["a.com", "bar"], [["a.com", 2]]);
    1.60 +    yield getSubdomainsOK(["b.com", "foo"], [["b.com", 5]]);
    1.61 +  },
    1.62 +
    1.63 +  function erroneous() {
    1.64 +    do_check_throws(function ()
    1.65 +                    cps.getBySubdomainAndName(null, "foo", null, {}));
    1.66 +    do_check_throws(function ()
    1.67 +                    cps.getBySubdomainAndName("", "foo", null, {}));
    1.68 +    do_check_throws(function ()
    1.69 +                    cps.getBySubdomainAndName("a.com", "", null, {}));
    1.70 +    do_check_throws(function ()
    1.71 +                    cps.getBySubdomainAndName("a.com", null, null, {}));
    1.72 +    do_check_throws(function ()
    1.73 +                    cps.getBySubdomainAndName("a.com", "foo", null, null));
    1.74 +    yield true;
    1.75 +  },
    1.76 +];

mercurial