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.removeByDomainAndName("a.com", "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: yield cps.removeBySubdomainAndName("a.com", "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: yield cps.removeGlobal("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: yield cps.removeByDomainAndName("bogus", "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 isomorphicDomains() { michael@0: yield set("a.com", "foo", 1); michael@0: yield cps.removeByDomainAndName("a.com", "foo", null, makeCallback()); michael@0: yield dbOK([]); michael@0: yield getOK(["a.com", "foo"], undefined); michael@0: michael@0: yield set("a.com", "foo", 2); michael@0: yield cps.removeByDomainAndName("http://a.com/huh", "foo", null, michael@0: makeCallback()); michael@0: yield dbOK([]); michael@0: yield getOK(["a.com", "foo"], undefined); 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: michael@0: yield cps.removeByDomainAndName("a.com", "foo", null, makeCallback()); michael@0: yield dbOK([ michael@0: ["a.com", "bar", 2], michael@0: [null, "foo", 3], michael@0: [null, "bar", 4], michael@0: ]); michael@0: yield getOK(["a.com", "foo"], undefined); michael@0: yield getOK(["a.com", "bar"], 2); michael@0: yield getGlobalOK(["foo"], 3); michael@0: yield getGlobalOK(["bar"], 4); michael@0: michael@0: yield cps.removeGlobal("foo", null, makeCallback()); michael@0: yield dbOK([ michael@0: ["a.com", "bar", 2], michael@0: [null, "bar", 4], 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: michael@0: yield cps.removeByDomainAndName("a.com", "bar", null, makeCallback()); michael@0: yield dbOK([ michael@0: [null, "bar", 4], michael@0: ]); michael@0: yield getOK(["a.com", "foo"], undefined); michael@0: yield getOK(["a.com", "bar"], undefined); michael@0: yield getGlobalOK(["foo"], undefined); michael@0: yield getGlobalOK(["bar"], 4); michael@0: michael@0: yield cps.removeGlobal("bar", null, makeCallback()); michael@0: yield dbOK([ michael@0: ]); michael@0: yield getOK(["a.com", "foo"], undefined); michael@0: yield getOK(["a.com", "bar"], undefined); michael@0: yield getGlobalOK(["foo"], undefined); michael@0: yield getGlobalOK(["bar"], undefined); michael@0: }, michael@0: michael@0: function subdomains() { michael@0: yield set("a.com", "foo", 1); michael@0: yield set("b.a.com", "foo", 2); michael@0: yield cps.removeByDomainAndName("a.com", "foo", null, makeCallback()); michael@0: yield dbOK([ michael@0: ["b.a.com", "foo", 2], michael@0: ]); michael@0: yield getSubdomainsOK(["a.com", "foo"], [["b.a.com", 2]]); michael@0: yield getSubdomainsOK(["b.a.com", "foo"], [["b.a.com", 2]]); michael@0: michael@0: yield set("a.com", "foo", 3); michael@0: yield cps.removeBySubdomainAndName("a.com", "foo", null, makeCallback()); michael@0: yield dbOK([ michael@0: ]); michael@0: yield getSubdomainsOK(["a.com", "foo"], []); michael@0: yield getSubdomainsOK(["b.a.com", "foo"], []); michael@0: michael@0: yield set("a.com", "foo", 4); michael@0: yield set("b.a.com", "foo", 5); michael@0: yield cps.removeByDomainAndName("b.a.com", "foo", null, makeCallback()); michael@0: yield dbOK([ michael@0: ["a.com", "foo", 4], michael@0: ]); michael@0: yield getSubdomainsOK(["a.com", "foo"], [["a.com", 4]]); michael@0: yield getSubdomainsOK(["b.a.com", "foo"], []); michael@0: michael@0: yield set("b.a.com", "foo", 6); michael@0: yield cps.removeBySubdomainAndName("b.a.com", "foo", null, makeCallback()); michael@0: yield dbOK([ michael@0: ["a.com", "foo", 4], michael@0: ]); michael@0: yield getSubdomainsOK(["a.com", "foo"], [["a.com", 4]]); michael@0: yield getSubdomainsOK(["b.a.com", "foo"], []); 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 setGlobal("qux", 5); michael@0: yield set("b.com", "foo", 6); michael@0: yield set("b.com", "bar", 7); michael@0: michael@0: let context = { usePrivateBrowsing: true }; michael@0: yield set("a.com", "foo", 8, context); michael@0: yield setGlobal("foo", 9, context); michael@0: yield cps.removeByDomainAndName("a.com", "foo", context, makeCallback()); michael@0: yield cps.removeGlobal("foo", context, makeCallback()); michael@0: yield cps.removeGlobal("qux", context, makeCallback()); michael@0: yield cps.removeByDomainAndName("b.com", "foo", context, makeCallback()); michael@0: yield dbOK([ michael@0: ["a.com", "bar", 2], michael@0: [null, "bar", 4], michael@0: ["b.com", "bar", 7], michael@0: ]); michael@0: yield getOK(["a.com", "foo", context], undefined); michael@0: yield getOK(["a.com", "bar", context], 2); michael@0: yield getGlobalOK(["foo", context], undefined); michael@0: yield getGlobalOK(["bar", context], 4); michael@0: yield getGlobalOK(["qux", context], undefined); michael@0: yield getOK(["b.com", "foo", context], undefined); michael@0: yield getOK(["b.com", "bar", context], 7); 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 getGlobalOK(["qux"], undefined); michael@0: yield getOK(["b.com", "foo"], undefined); michael@0: yield getOK(["b.com", "bar"], 7); michael@0: }, michael@0: michael@0: function erroneous() { michael@0: do_check_throws(function () cps.removeByDomainAndName(null, "foo", null)); michael@0: do_check_throws(function () cps.removeByDomainAndName("", "foo", null)); michael@0: do_check_throws(function () cps.removeByDomainAndName("a.com", "foo", null, michael@0: "bogus")); michael@0: do_check_throws(function () cps.removeBySubdomainAndName(null, "foo", michael@0: null)); michael@0: do_check_throws(function () cps.removeBySubdomainAndName("", "foo", null)); michael@0: do_check_throws(function () cps.removeBySubdomainAndName("a.com", "foo", michael@0: null, "bogus")); michael@0: do_check_throws(function () cps.removeGlobal("", null)); michael@0: do_check_throws(function () cps.removeGlobal(null, null)); michael@0: do_check_throws(function () cps.removeGlobal("foo", null, "bogus")); michael@0: yield true; michael@0: }, michael@0: michael@0: function removeByDomainAndName_invalidateCache() { michael@0: yield set("a.com", "foo", 1); michael@0: getCachedOK(["a.com", "foo"], true, 1); michael@0: cps.removeByDomainAndName("a.com", "foo", null, makeCallback()); michael@0: getCachedOK(["a.com", "foo"], false); michael@0: yield; michael@0: }, michael@0: michael@0: function removeBySubdomainAndName_invalidateCache() { michael@0: yield set("a.com", "foo", 1); michael@0: yield set("b.a.com", "foo", 2); michael@0: getCachedSubdomainsOK(["a.com", "foo"], [ michael@0: ["a.com", 1], michael@0: ["b.a.com", 2], michael@0: ]); michael@0: cps.removeBySubdomainAndName("a.com", "foo", null, makeCallback()); michael@0: getCachedSubdomainsOK(["a.com", "foo"], []); michael@0: yield; michael@0: }, michael@0: michael@0: function removeGlobal_invalidateCache() { michael@0: yield setGlobal("foo", 1); michael@0: getCachedGlobalOK(["foo"], true, 1); michael@0: cps.removeGlobal("foo", null, makeCallback()); michael@0: getCachedGlobalOK(["foo"], false); michael@0: yield; michael@0: }, michael@0: ];