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 get_nonexistent() { michael@0: yield getOK(["a.com", "foo"], undefined); michael@0: yield getGlobalOK(["foo"], undefined); michael@0: }, michael@0: michael@0: function isomorphicDomains() { michael@0: yield set("a.com", "foo", 1); michael@0: yield dbOK([ michael@0: ["a.com", "foo", 1], michael@0: ]); michael@0: yield getOK(["a.com", "foo"], 1); michael@0: yield getOK(["http://a.com/huh", "foo"], 1, "a.com"); michael@0: michael@0: yield set("http://a.com/huh", "foo", 2); michael@0: yield dbOK([ michael@0: ["a.com", "foo", 2], michael@0: ]); michael@0: yield getOK(["a.com", "foo"], 2); michael@0: yield getOK(["http://a.com/yeah", "foo"], 2, "a.com"); michael@0: }, michael@0: michael@0: function names() { michael@0: yield set("a.com", "foo", 1); michael@0: yield dbOK([ michael@0: ["a.com", "foo", 1], michael@0: ]); michael@0: yield getOK(["a.com", "foo"], 1); michael@0: michael@0: yield set("a.com", "bar", 2); michael@0: yield dbOK([ michael@0: ["a.com", "foo", 1], michael@0: ["a.com", "bar", 2], michael@0: ]); michael@0: yield getOK(["a.com", "foo"], 1); michael@0: yield getOK(["a.com", "bar"], 2); michael@0: michael@0: yield setGlobal("foo", 3); michael@0: yield dbOK([ michael@0: ["a.com", "foo", 1], michael@0: ["a.com", "bar", 2], michael@0: [null, "foo", 3], michael@0: ]); michael@0: yield getOK(["a.com", "foo"], 1); michael@0: yield getOK(["a.com", "bar"], 2); michael@0: yield getGlobalOK(["foo"], 3); michael@0: michael@0: yield setGlobal("bar", 4); michael@0: yield dbOK([ michael@0: ["a.com", "foo", 1], 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"], 1); michael@0: yield getOK(["a.com", "bar"], 2); michael@0: yield getGlobalOK(["foo"], 3); michael@0: yield getGlobalOK(["bar"], 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: yield dbOK([ michael@0: ["a.com", "foo", 1], michael@0: ["b.a.com", "foo", 2], michael@0: ]); michael@0: yield getOK(["a.com", "foo"], 1); michael@0: yield getOK(["b.a.com", "foo"], 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: yield dbOK([ michael@0: ["a.com", "foo", 1], michael@0: ["a.com", "bar", 2], michael@0: [null, "foo", 3], michael@0: [null, "bar", 4], michael@0: ["b.com", "foo", 5], michael@0: ]); michael@0: yield getOK(["a.com", "foo", context], 6, "a.com"); michael@0: yield getOK(["a.com", "bar", context], 2); michael@0: yield getGlobalOK(["foo", context], 7); michael@0: yield getGlobalOK(["bar", context], 4); michael@0: yield getOK(["b.com", "foo", context], 5); michael@0: michael@0: yield getOK(["a.com", "foo"], 1); michael@0: yield getOK(["a.com", "bar"], 2); michael@0: yield getGlobalOK(["foo"], 3); michael@0: yield getGlobalOK(["bar"], 4); michael@0: yield getOK(["b.com", "foo"], 5); michael@0: }, michael@0: michael@0: function set_erroneous() { michael@0: do_check_throws(function () cps.set(null, "foo", 1, null)); michael@0: do_check_throws(function () cps.set("", "foo", 1, null)); michael@0: do_check_throws(function () cps.set("a.com", "", 1, null)); michael@0: do_check_throws(function () cps.set("a.com", null, 1, null)); michael@0: do_check_throws(function () cps.set("a.com", "foo", undefined, null)); michael@0: do_check_throws(function () cps.set("a.com", "foo", 1, null, "bogus")); michael@0: do_check_throws(function () cps.setGlobal("", 1, null)); michael@0: do_check_throws(function () cps.setGlobal(null, 1, null)); michael@0: do_check_throws(function () cps.setGlobal("foo", undefined, null)); michael@0: do_check_throws(function () cps.setGlobal("foo", 1, null, "bogus")); michael@0: yield true; michael@0: }, michael@0: michael@0: function get_erroneous() { michael@0: do_check_throws(function () cps.getByDomainAndName(null, "foo", null, {})); michael@0: do_check_throws(function () cps.getByDomainAndName("", "foo", null, {})); michael@0: do_check_throws(function () cps.getByDomainAndName("a.com", "", null, {})); michael@0: do_check_throws(function () michael@0: cps.getByDomainAndName("a.com", null, null, {})); michael@0: do_check_throws(function () michael@0: cps.getByDomainAndName("a.com", "foo", null, null)); michael@0: do_check_throws(function () cps.getGlobal("", null, {})); michael@0: do_check_throws(function () cps.getGlobal(null, null, {})); michael@0: do_check_throws(function () cps.getGlobal("foo", null, null)); michael@0: yield true; michael@0: }, michael@0: michael@0: function set_invalidateCache() { michael@0: // (1) Set a pref and wait for it to finish. michael@0: yield set("a.com", "foo", 1); michael@0: michael@0: // (2) It should be cached. michael@0: getCachedOK(["a.com", "foo"], true, 1); michael@0: michael@0: // (3) Set the pref to a new value but don't wait for it to finish. michael@0: cps.set("a.com", "foo", 2, null, { michael@0: handleCompletion: function () { michael@0: // (6) The pref should be cached after setting it. michael@0: getCachedOK(["a.com", "foo"], true, 2); michael@0: }, michael@0: }); michael@0: michael@0: // (4) Group "a.com" and name "foo" should no longer be cached. michael@0: getCachedOK(["a.com", "foo"], false); michael@0: michael@0: // (5) Call getByDomainAndName. michael@0: var fetchedPref; michael@0: cps.getByDomainAndName("a.com", "foo", null, { michael@0: handleResult: function (pref) { michael@0: fetchedPref = pref; michael@0: }, michael@0: handleCompletion: function () { michael@0: // (7) Finally, this callback should be called after set's above. michael@0: do_check_true(!!fetchedPref); michael@0: do_check_eq(fetchedPref.value, 2); michael@0: next(); michael@0: }, michael@0: }); michael@0: michael@0: yield; michael@0: }, michael@0: michael@0: function get_nameOnly() { 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 setGlobal("foo", 4); michael@0: michael@0: yield getOKEx("getByName", ["foo", undefined], [ michael@0: {"domain": "a.com", "name": "foo", "value": 1}, michael@0: {"domain": "b.com", "name": "foo", "value": 3}, michael@0: {"domain": null, "name": "foo", "value": 4} michael@0: ]); michael@0: michael@0: let context = { usePrivateBrowsing: true }; michael@0: yield set("b.com", "foo", 5, context); michael@0: michael@0: yield getOKEx("getByName", ["foo", context], [ michael@0: {"domain": "a.com", "name": "foo", "value": 1}, michael@0: {"domain": null, "name": "foo", "value": 4}, michael@0: {"domain": "b.com", "name": "foo", "value": 5} michael@0: ]); michael@0: } michael@0: ];