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

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     3  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 function run_test() {
     6   runAsyncTests(tests);
     7 }
     9 let tests = [
    11   function nonexistent() {
    12     yield set("a.com", "foo", 1);
    13     yield setGlobal("foo", 2);
    15     yield cps.removeByName("bogus", null, makeCallback());
    16     yield dbOK([
    17       ["a.com", "foo", 1],
    18       [null, "foo", 2],
    19     ]);
    20     yield getOK(["a.com", "foo"], 1);
    21     yield getGlobalOK(["foo"], 2);
    22   },
    24   function names() {
    25     yield set("a.com", "foo", 1);
    26     yield set("a.com", "bar", 2);
    27     yield setGlobal("foo", 3);
    28     yield setGlobal("bar", 4);
    29     yield set("b.com", "foo", 5);
    30     yield set("b.com", "bar", 6);
    32     yield cps.removeByName("foo", null, makeCallback());
    33     yield dbOK([
    34       ["a.com", "bar", 2],
    35       [null, "bar", 4],
    36       ["b.com", "bar", 6],
    37     ]);
    38     yield getOK(["a.com", "foo"], undefined);
    39     yield getOK(["a.com", "bar"], 2);
    40     yield getGlobalOK(["foo"], undefined);
    41     yield getGlobalOK(["bar"], 4);
    42     yield getOK(["b.com", "foo"], undefined);
    43     yield getOK(["b.com", "bar"], 6);
    44   },
    46   function privateBrowsing() {
    47     yield set("a.com", "foo", 1);
    48     yield set("a.com", "bar", 2);
    49     yield setGlobal("foo", 3);
    50     yield setGlobal("bar", 4);
    51     yield set("b.com", "foo", 5);
    52     yield set("b.com", "bar", 6);
    54     let context = { usePrivateBrowsing: true };
    55     yield set("a.com", "foo", 7, context);
    56     yield setGlobal("foo", 8, context);
    57     yield set("b.com", "bar", 9, context);
    58     yield cps.removeByName("bar", context, makeCallback());
    59     yield dbOK([
    60       ["a.com", "foo", 1],
    61       [null, "foo", 3],
    62       ["b.com", "foo", 5],
    63     ]);
    64     yield getOK(["a.com", "foo", context], 7);
    65     yield getOK(["a.com", "bar", context], undefined);
    66     yield getGlobalOK(["foo", context], 8);
    67     yield getGlobalOK(["bar", context], undefined);
    68     yield getOK(["b.com", "foo", context], 5);
    69     yield getOK(["b.com", "bar", context], undefined);
    71     yield getOK(["a.com", "foo"], 1);
    72     yield getOK(["a.com", "bar"], undefined);
    73     yield getGlobalOK(["foo"], 3);
    74     yield getGlobalOK(["bar"], undefined);
    75     yield getOK(["b.com", "foo"], 5);
    76     yield getOK(["b.com", "bar"], undefined);
    77   },
    79   function erroneous() {
    80     do_check_throws(function () cps.removeByName("", null));
    81     do_check_throws(function () cps.removeByName(null, null));
    82     do_check_throws(function () cps.removeByName("foo", null, "bogus"));
    83     yield true;
    84   },
    86   function invalidateCache() {
    87     yield set("a.com", "foo", 1);
    88     yield set("b.com", "foo", 2);
    89     getCachedOK(["a.com", "foo"], true, 1);
    90     getCachedOK(["b.com", "foo"], true, 2);
    91     cps.removeByName("foo", null, makeCallback());
    92     getCachedOK(["a.com", "foo"], false);
    93     getCachedOK(["b.com", "foo"], false);
    94     yield;
    95   },
    96 ];

mercurial