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 observerForName_set() { michael@0: yield set("a.com", "foo", 1); michael@0: let args = yield on("Set", ["foo", null, "bar"]); michael@0: observerArgsOK(args.foo, [["a.com", "foo", 1]]); michael@0: observerArgsOK(args.null, [["a.com", "foo", 1]]); michael@0: observerArgsOK(args.bar, []); michael@0: michael@0: yield setGlobal("foo", 2); michael@0: args = yield on("Set", ["foo", null, "bar"]); michael@0: observerArgsOK(args.foo, [[null, "foo", 2]]); michael@0: observerArgsOK(args.null, [[null, "foo", 2]]); michael@0: observerArgsOK(args.bar, []); michael@0: }, michael@0: michael@0: function observerForName_remove() { 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: let args = yield on("Removed", ["foo", null, "bar"]); michael@0: observerArgsOK(args.foo, []); michael@0: observerArgsOK(args.null, []); michael@0: observerArgsOK(args.bar, []); michael@0: michael@0: yield cps.removeByDomainAndName("a.com", "foo", null, makeCallback()); michael@0: args = yield on("Removed", ["foo", null, "bar"]); michael@0: observerArgsOK(args.foo, [["a.com", "foo"]]); michael@0: observerArgsOK(args.null, [["a.com", "foo"]]); michael@0: observerArgsOK(args.bar, []); michael@0: michael@0: yield cps.removeGlobal("foo", null, makeCallback()); michael@0: args = yield on("Removed", ["foo", null, "bar"]); michael@0: observerArgsOK(args.foo, [[null, "foo"]]); michael@0: observerArgsOK(args.null, [[null, "foo"]]); michael@0: observerArgsOK(args.bar, []); michael@0: }, michael@0: michael@0: function observerForName_removeByDomain() { michael@0: yield set("a.com", "foo", 1); michael@0: yield set("b.a.com", "bar", 2); michael@0: yield setGlobal("foo", 3); michael@0: michael@0: yield cps.removeByDomain("bogus", null, makeCallback()); michael@0: let args = yield on("Removed", ["foo", null, "bar"]); michael@0: observerArgsOK(args.foo, []); michael@0: observerArgsOK(args.null, []); michael@0: observerArgsOK(args.bar, []); michael@0: michael@0: yield cps.removeBySubdomain("a.com", null, makeCallback()); michael@0: args = yield on("Removed", ["foo", null, "bar"]); michael@0: observerArgsOK(args.foo, [["a.com", "foo"]]); michael@0: observerArgsOK(args.null, [["a.com", "foo"], ["b.a.com", "bar"]]); michael@0: observerArgsOK(args.bar, [["b.a.com", "bar"]]); michael@0: michael@0: yield cps.removeAllGlobals(null, makeCallback()); michael@0: args = yield on("Removed", ["foo", null, "bar"]); michael@0: observerArgsOK(args.foo, [[null, "foo"]]); michael@0: observerArgsOK(args.null, [[null, "foo"]]); michael@0: observerArgsOK(args.bar, []); michael@0: }, michael@0: michael@0: function observerForName_removeAllDomains() { michael@0: yield set("a.com", "foo", 1); michael@0: yield setGlobal("foo", 2); michael@0: yield set("b.com", "bar", 3); michael@0: michael@0: yield cps.removeAllDomains(null, makeCallback()); michael@0: let args = yield on("Removed", ["foo", null, "bar"]); michael@0: observerArgsOK(args.foo, [["a.com", "foo"]]); michael@0: observerArgsOK(args.null, [["a.com", "foo"], ["b.com", "bar"]]); michael@0: observerArgsOK(args.bar, [["b.com", "bar"]]); michael@0: }, michael@0: michael@0: function observerForName_removeByName() { michael@0: yield set("a.com", "foo", 1); michael@0: yield set("a.com", "bar", 2); michael@0: yield setGlobal("foo", 3); michael@0: michael@0: yield cps.removeByName("bogus", null, makeCallback()); michael@0: let args = yield on("Removed", ["foo", null, "bar"]); michael@0: observerArgsOK(args.foo, []); michael@0: observerArgsOK(args.null, []); michael@0: observerArgsOK(args.bar, []); michael@0: michael@0: yield cps.removeByName("foo", null, makeCallback()); michael@0: args = yield on("Removed", ["foo", null, "bar"]); michael@0: observerArgsOK(args.foo, [["a.com", "foo"], [null, "foo"]]); michael@0: observerArgsOK(args.null, [["a.com", "foo"], [null, "foo"]]); michael@0: observerArgsOK(args.bar, []); michael@0: }, michael@0: michael@0: function removeObserverForName() { michael@0: let args = yield on("Set", ["foo", null, "bar"], true); michael@0: michael@0: cps.removeObserverForName("foo", args.foo.observer); michael@0: yield set("a.com", "foo", 1); michael@0: yield wait(); michael@0: observerArgsOK(args.foo, []); michael@0: observerArgsOK(args.null, [["a.com", "foo", 1]]); michael@0: observerArgsOK(args.bar, []); michael@0: args.reset(); michael@0: michael@0: cps.removeObserverForName(null, args.null.observer); michael@0: yield set("a.com", "foo", 2); michael@0: yield wait(); michael@0: observerArgsOK(args.foo, []); michael@0: observerArgsOK(args.null, []); michael@0: observerArgsOK(args.bar, []); michael@0: args.reset(); michael@0: }, michael@0: ];