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