michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: function run_test() { michael@0: runAsyncTests(tests); michael@0: } michael@0: michael@0: let tests = [ michael@0: michael@0: function nonexistent() { michael@0: yield set("a.com", "foo", 1); michael@0: yield setGlobal("foo", 2); michael@0: michael@0: yield cps.removeByName("bogus", null, makeCallback()); michael@0: yield dbOK([ michael@0: ["a.com", "foo", 1], michael@0: [null, "foo", 2], michael@0: ]); michael@0: yield getOK(["a.com", "foo"], 1); michael@0: yield getGlobalOK(["foo"], 2); michael@0: }, michael@0: michael@0: function names() { michael@0: yield set("a.com", "foo", 1); michael@0: yield set("a.com", "bar", 2); michael@0: yield setGlobal("foo", 3); michael@0: yield setGlobal("bar", 4); michael@0: yield set("b.com", "foo", 5); michael@0: yield set("b.com", "bar", 6); michael@0: michael@0: yield cps.removeByName("foo", null, makeCallback()); michael@0: yield dbOK([ michael@0: ["a.com", "bar", 2], michael@0: [null, "bar", 4], michael@0: ["b.com", "bar", 6], michael@0: ]); michael@0: yield getOK(["a.com", "foo"], undefined); michael@0: yield getOK(["a.com", "bar"], 2); michael@0: yield getGlobalOK(["foo"], undefined); michael@0: yield getGlobalOK(["bar"], 4); michael@0: yield getOK(["b.com", "foo"], undefined); michael@0: yield getOK(["b.com", "bar"], 6); michael@0: }, michael@0: michael@0: function privateBrowsing() { michael@0: yield set("a.com", "foo", 1); michael@0: yield set("a.com", "bar", 2); michael@0: yield setGlobal("foo", 3); michael@0: yield setGlobal("bar", 4); michael@0: yield set("b.com", "foo", 5); michael@0: yield set("b.com", "bar", 6); michael@0: michael@0: let context = { usePrivateBrowsing: true }; michael@0: yield set("a.com", "foo", 7, context); michael@0: yield setGlobal("foo", 8, context); michael@0: yield set("b.com", "bar", 9, context); michael@0: yield cps.removeByName("bar", context, makeCallback()); michael@0: yield dbOK([ michael@0: ["a.com", "foo", 1], michael@0: [null, "foo", 3], michael@0: ["b.com", "foo", 5], michael@0: ]); michael@0: yield getOK(["a.com", "foo", context], 7); michael@0: yield getOK(["a.com", "bar", context], undefined); michael@0: yield getGlobalOK(["foo", context], 8); michael@0: yield getGlobalOK(["bar", context], undefined); michael@0: yield getOK(["b.com", "foo", context], 5); michael@0: yield getOK(["b.com", "bar", context], undefined); michael@0: michael@0: yield getOK(["a.com", "foo"], 1); michael@0: yield getOK(["a.com", "bar"], undefined); michael@0: yield getGlobalOK(["foo"], 3); michael@0: yield getGlobalOK(["bar"], undefined); michael@0: yield getOK(["b.com", "foo"], 5); michael@0: yield getOK(["b.com", "bar"], undefined); michael@0: }, michael@0: michael@0: function erroneous() { michael@0: do_check_throws(function () cps.removeByName("", null)); michael@0: do_check_throws(function () cps.removeByName(null, null)); michael@0: do_check_throws(function () cps.removeByName("foo", null, "bogus")); michael@0: yield true; michael@0: }, michael@0: michael@0: function invalidateCache() { michael@0: yield set("a.com", "foo", 1); michael@0: yield set("b.com", "foo", 2); michael@0: getCachedOK(["a.com", "foo"], true, 1); michael@0: getCachedOK(["b.com", "foo"], true, 2); michael@0: cps.removeByName("foo", null, makeCallback()); michael@0: getCachedOK(["a.com", "foo"], false); michael@0: getCachedOK(["b.com", "foo"], false); michael@0: yield; michael@0: }, michael@0: ];