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: getCachedOK(["a.com", "foo"], false, undefined); michael@0: getCachedGlobalOK(["foo"], false, undefined); michael@0: yield true; michael@0: }, michael@0: michael@0: function isomorphicDomains() { michael@0: yield set("a.com", "foo", 1); michael@0: getCachedOK(["a.com", "foo"], true, 1); michael@0: getCachedOK(["http://a.com/huh", "foo"], true, 1, "a.com"); michael@0: }, michael@0: michael@0: function names() { michael@0: yield set("a.com", "foo", 1); michael@0: getCachedOK(["a.com", "foo"], true, 1); michael@0: 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: michael@0: yield setGlobal("foo", 3); michael@0: getCachedOK(["a.com", "foo"], true, 1); michael@0: getCachedOK(["a.com", "bar"], true, 2); michael@0: getCachedGlobalOK(["foo"], true, 3); michael@0: michael@0: yield setGlobal("bar", 4); michael@0: getCachedOK(["a.com", "foo"], true, 1); michael@0: getCachedOK(["a.com", "bar"], true, 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: getCachedOK(["a.com", "foo"], true, 1); michael@0: getCachedOK(["b.a.com", "foo"], true, 2); 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: getCachedOK(["a.com", "foo", context], true, 6); michael@0: getCachedOK(["a.com", "bar", context], true, 2); michael@0: getCachedGlobalOK(["foo", context], true, 7); michael@0: getCachedGlobalOK(["bar", context], true, 4); michael@0: getCachedOK(["b.com", "foo", context], true, 5); michael@0: michael@0: getCachedOK(["a.com", "foo"], true, 1); michael@0: getCachedOK(["a.com", "bar"], true, 2); michael@0: getCachedGlobalOK(["foo"], true, 3); michael@0: getCachedGlobalOK(["bar"], true, 4); michael@0: getCachedOK(["b.com", "foo"], true, 5); michael@0: }, michael@0: michael@0: function erroneous() { michael@0: do_check_throws(function () michael@0: cps.getCachedByDomainAndName(null, "foo", null)); michael@0: do_check_throws(function () michael@0: cps.getCachedByDomainAndName("", "foo", null)); michael@0: do_check_throws(function () michael@0: cps.getCachedByDomainAndName("a.com", "", null)); michael@0: do_check_throws(function () michael@0: cps.getCachedByDomainAndName("a.com", null, null)); michael@0: do_check_throws(function () cps.getCachedGlobal("", null)); michael@0: do_check_throws(function () cps.getCachedGlobal(null, null)); michael@0: yield true; michael@0: }, michael@0: michael@0: function casts() { michael@0: // SQLite casts booleans to integers. This makes sure the values stored in michael@0: // the cache are the same as the casted values in the database. michael@0: michael@0: yield set("a.com", "foo", false); michael@0: yield getOK(["a.com", "foo"], 0, "a.com", true); michael@0: getCachedOK(["a.com", "foo"], true, 0, "a.com", true); michael@0: michael@0: yield set("a.com", "bar", true); michael@0: yield getOK(["a.com", "bar"], 1, "a.com", true); michael@0: getCachedOK(["a.com", "bar"], true, 1, "a.com", true); michael@0: }, michael@0: ];