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: getCachedSubdomainsOK(["a.com", "foo"], []); michael@0: yield true; michael@0: }, michael@0: michael@0: function isomorphicDomains() { michael@0: yield set("a.com", "foo", 1); michael@0: getCachedSubdomainsOK(["a.com", "foo"], [["a.com", 1]]); michael@0: getCachedSubdomainsOK(["http://a.com/huh", "foo"], [["a.com", 1]]); michael@0: }, michael@0: michael@0: function names() { michael@0: yield set("a.com", "foo", 1); michael@0: getCachedSubdomainsOK(["a.com", "foo"], [["a.com", 1]]); michael@0: michael@0: yield set("a.com", "bar", 2); michael@0: getCachedSubdomainsOK(["a.com", "foo"], [["a.com", 1]]); michael@0: getCachedSubdomainsOK(["a.com", "bar"], [["a.com", 2]]); michael@0: michael@0: yield setGlobal("foo", 3); michael@0: getCachedSubdomainsOK(["a.com", "foo"], [["a.com", 1]]); michael@0: getCachedSubdomainsOK(["a.com", "bar"], [["a.com", 2]]); michael@0: getCachedGlobalOK(["foo"], true, 3); michael@0: michael@0: yield setGlobal("bar", 4); michael@0: getCachedSubdomainsOK(["a.com", "foo"], [["a.com", 1]]); michael@0: getCachedSubdomainsOK(["a.com", "bar"], [["a.com", 2]]); michael@0: getCachedGlobalOK(["foo"], true, 3); michael@0: getCachedGlobalOK(["bar"], true, 4); 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: getCachedSubdomainsOK(["a.com", "foo"], [["a.com", 1], ["b.a.com", 2]]); michael@0: getCachedSubdomainsOK(["b.a.com", "foo"], [["b.a.com", 2]]); michael@0: }, michael@0: michael@0: function populateViaGet() { michael@0: yield cps.getByDomainAndName("a.com", "foo", null, makeCallback()); michael@0: getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); michael@0: michael@0: yield cps.getGlobal("foo", null, makeCallback()); michael@0: getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); michael@0: getCachedGlobalOK(["foo"], true, undefined); michael@0: }, michael@0: michael@0: function populateViaGetSubdomains() { michael@0: yield cps.getBySubdomainAndName("a.com", "foo", null, makeCallback()); michael@0: getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); michael@0: }, michael@0: michael@0: function populateViaRemove() { michael@0: yield cps.removeByDomainAndName("a.com", "foo", null, makeCallback()); michael@0: getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); michael@0: michael@0: yield cps.removeBySubdomainAndName("b.com", "foo", null, makeCallback()); michael@0: getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); michael@0: getCachedSubdomainsOK(["b.com", "foo"], [["b.com", undefined]]); michael@0: michael@0: yield cps.removeGlobal("foo", null, makeCallback()); michael@0: getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); michael@0: getCachedSubdomainsOK(["b.com", "foo"], [["b.com", undefined]]); michael@0: getCachedGlobalOK(["foo"], true, undefined); michael@0: michael@0: yield set("a.com", "foo", 1); michael@0: yield cps.removeByDomainAndName("a.com", "foo", null, makeCallback()); michael@0: getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); michael@0: getCachedSubdomainsOK(["b.com", "foo"], [["b.com", undefined]]); michael@0: getCachedGlobalOK(["foo"], true, undefined); michael@0: michael@0: yield set("a.com", "foo", 2); michael@0: yield set("b.a.com", "foo", 3); michael@0: yield cps.removeBySubdomainAndName("a.com", "foo", null, makeCallback()); michael@0: getCachedSubdomainsOK(["a.com", "foo"], michael@0: [["a.com", undefined], ["b.a.com", undefined]]); michael@0: getCachedSubdomainsOK(["b.com", "foo"], [["b.com", undefined]]); michael@0: getCachedGlobalOK(["foo"], true, undefined); michael@0: getCachedSubdomainsOK(["b.a.com", "foo"], [["b.a.com", undefined]]); michael@0: michael@0: yield setGlobal("foo", 4); michael@0: yield cps.removeGlobal("foo", null, makeCallback()); michael@0: getCachedSubdomainsOK(["a.com", "foo"], michael@0: [["a.com", undefined], ["b.a.com", undefined]]); michael@0: getCachedSubdomainsOK(["b.com", "foo"], [["b.com", undefined]]); michael@0: getCachedGlobalOK(["foo"], true, undefined); michael@0: getCachedSubdomainsOK(["b.a.com", "foo"], [["b.a.com", undefined]]); michael@0: }, michael@0: michael@0: function populateViaRemoveByDomain() { michael@0: yield set("a.com", "foo", 1); michael@0: yield set("a.com", "bar", 2); michael@0: yield set("b.a.com", "foo", 3); michael@0: yield set("b.a.com", "bar", 4); michael@0: yield cps.removeByDomain("a.com", null, makeCallback()); michael@0: getCachedSubdomainsOK(["a.com", "foo"], michael@0: [["a.com", undefined], ["b.a.com", 3]]); michael@0: getCachedSubdomainsOK(["a.com", "bar"], michael@0: [["a.com", undefined], ["b.a.com", 4]]); michael@0: michael@0: yield set("a.com", "foo", 5); michael@0: yield set("a.com", "bar", 6); michael@0: yield cps.removeBySubdomain("a.com", null, makeCallback()); michael@0: getCachedSubdomainsOK(["a.com", "foo"], michael@0: [["a.com", undefined], ["b.a.com", undefined]]); michael@0: getCachedSubdomainsOK(["a.com", "bar"], michael@0: [["a.com", undefined], ["b.a.com", undefined]]); michael@0: michael@0: yield setGlobal("foo", 7); michael@0: yield setGlobal("bar", 8); michael@0: yield cps.removeAllGlobals(null, makeCallback()); michael@0: getCachedGlobalOK(["foo"], true, undefined); michael@0: getCachedGlobalOK(["bar"], true, undefined); michael@0: }, michael@0: michael@0: function populateViaRemoveAllDomains() { michael@0: yield set("a.com", "foo", 1); michael@0: yield set("a.com", "bar", 2); michael@0: yield set("b.com", "foo", 3); michael@0: yield set("b.com", "bar", 4); michael@0: yield cps.removeAllDomains(null, makeCallback()); michael@0: getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); michael@0: getCachedSubdomainsOK(["a.com", "bar"], [["a.com", undefined]]); michael@0: getCachedSubdomainsOK(["b.com", "foo"], [["b.com", undefined]]); michael@0: getCachedSubdomainsOK(["b.com", "bar"], [["b.com", undefined]]); michael@0: }, michael@0: michael@0: function populateViaRemoveByName() { 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 cps.removeByName("foo", null, makeCallback()); michael@0: getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); michael@0: getCachedSubdomainsOK(["a.com", "bar"], [["a.com", 2]]); michael@0: getCachedGlobalOK(["foo"], true, undefined); michael@0: getCachedGlobalOK(["bar"], true, 4); michael@0: michael@0: yield cps.removeByName("bar", null, makeCallback()); michael@0: getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); michael@0: getCachedSubdomainsOK(["a.com", "bar"], [["a.com", undefined]]); michael@0: getCachedGlobalOK(["foo"], true, undefined); michael@0: getCachedGlobalOK(["bar"], true, undefined); 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: getCachedSubdomainsOK(["a.com", "foo", context], [["a.com", 6]]); michael@0: getCachedSubdomainsOK(["a.com", "bar", context], [["a.com", 2]]); michael@0: getCachedGlobalOK(["foo", context], true, 7); michael@0: getCachedGlobalOK(["bar", context], true, 4); michael@0: getCachedSubdomainsOK(["b.com", "foo", context], [["b.com", 5]]); michael@0: michael@0: getCachedSubdomainsOK(["a.com", "foo"], [["a.com", 1]]); michael@0: getCachedSubdomainsOK(["a.com", "bar"], [["a.com", 2]]); michael@0: getCachedGlobalOK(["foo"], true, 3); michael@0: getCachedGlobalOK(["bar"], true, 4); michael@0: getCachedSubdomainsOK(["b.com", "foo"], [["b.com", 5]]); michael@0: }, michael@0: michael@0: function erroneous() { michael@0: do_check_throws(function () michael@0: cps.getCachedBySubdomainAndName(null, "foo", null)); michael@0: do_check_throws(function () michael@0: cps.getCachedBySubdomainAndName("", "foo", null)); michael@0: do_check_throws(function () michael@0: cps.getCachedBySubdomainAndName("a.com", "", null)); michael@0: do_check_throws(function () michael@0: cps.getCachedBySubdomainAndName("a.com", null, null)); michael@0: yield true; michael@0: }, michael@0: ];