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.removeByDomain("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.removeBySubdomain("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.removeByDomain("a.com", 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.removeByDomain("http://a.com/huh", null, makeCallback()); michael@0: yield dbOK([]); michael@0: yield getOK(["a.com", "foo"], undefined); michael@0: }, michael@0: michael@0: function domains() { 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.removeByDomain("a.com", null, makeCallback()); michael@0: yield dbOK([ michael@0: [null, "foo", 3], michael@0: [null, "bar", 4], michael@0: ["b.com", "foo", 5], michael@0: ["b.com", "bar", 6], michael@0: ]); michael@0: yield getOK(["a.com", "foo"], undefined); michael@0: yield getOK(["a.com", "bar"], undefined); michael@0: yield getGlobalOK(["foo"], 3); michael@0: yield getGlobalOK(["bar"], 4); michael@0: yield getOK(["b.com", "foo"], 5); michael@0: yield getOK(["b.com", "bar"], 6); michael@0: michael@0: yield cps.removeAllGlobals(null, makeCallback()); michael@0: yield dbOK([ michael@0: ["b.com", "foo", 5], michael@0: ["b.com", "bar", 6], 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: yield getOK(["b.com", "foo"], 5); michael@0: yield getOK(["b.com", "bar"], 6); michael@0: michael@0: yield cps.removeByDomain("b.com", 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: yield getOK(["b.com", "foo"], undefined); michael@0: yield getOK(["b.com", "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.removeByDomain("a.com", 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.removeBySubdomain("a.com", 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.removeByDomain("b.a.com", 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.removeBySubdomain("b.a.com", 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 set("b.com", "foo", 5); michael@0: michael@0: let context = { usePrivateBrowsing: true }; michael@0: yield set("a.com", "foo", 6, context); michael@0: yield setGlobal("foo", 7, context); michael@0: yield cps.removeByDomain("a.com", context, makeCallback()); michael@0: yield cps.removeAllGlobals(context, makeCallback()); michael@0: yield dbOK([ michael@0: ["b.com", "foo", 5], michael@0: ]); michael@0: yield getOK(["a.com", "foo", context], undefined); michael@0: yield getOK(["a.com", "bar", context], undefined); michael@0: yield getGlobalOK(["foo", context], undefined); michael@0: yield getGlobalOK(["bar", context], undefined); michael@0: yield getOK(["b.com", "foo", context], 5); 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: yield getOK(["b.com", "foo"], 5); michael@0: }, michael@0: michael@0: function erroneous() { michael@0: do_check_throws(function () cps.removeByDomain(null, null)); michael@0: do_check_throws(function () cps.removeByDomain("", null)); michael@0: do_check_throws(function () cps.removeByDomain("a.com", null, "bogus")); michael@0: do_check_throws(function () cps.removeBySubdomain(null, null)); michael@0: do_check_throws(function () cps.removeBySubdomain("", null)); michael@0: do_check_throws(function () cps.removeBySubdomain("a.com", null, "bogus")); michael@0: do_check_throws(function () cps.removeAllGlobals(null, "bogus")); michael@0: yield true; michael@0: }, michael@0: michael@0: function removeByDomain_invalidateCache() { michael@0: yield set("a.com", "foo", 1); michael@0: yield set("a.com", "bar", 2); michael@0: getCachedOK(["a.com", "foo"], true, 1); michael@0: getCachedOK(["a.com", "bar"], true, 2); michael@0: cps.removeByDomain("a.com", null, makeCallback()); michael@0: getCachedOK(["a.com", "foo"], false); michael@0: getCachedOK(["a.com", "bar"], false); michael@0: yield; michael@0: }, michael@0: michael@0: function removeBySubdomain_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.removeBySubdomain("a.com", null, makeCallback()); michael@0: getCachedSubdomainsOK(["a.com", "foo"], []); michael@0: yield; michael@0: }, michael@0: michael@0: function removeAllGlobals_invalidateCache() { michael@0: yield setGlobal("foo", 1); michael@0: yield setGlobal("bar", 2); michael@0: getCachedGlobalOK(["foo"], true, 1); michael@0: getCachedGlobalOK(["bar"], true, 2); michael@0: cps.removeAllGlobals(null, makeCallback()); michael@0: getCachedGlobalOK(["foo"], false); michael@0: getCachedGlobalOK(["bar"], false); michael@0: yield; michael@0: }, michael@0: ];