Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | function run_test() { |
michael@0 | 6 | runAsyncTests(tests); |
michael@0 | 7 | } |
michael@0 | 8 | |
michael@0 | 9 | let tests = [ |
michael@0 | 10 | |
michael@0 | 11 | function observerForName_set() { |
michael@0 | 12 | yield set("a.com", "foo", 1); |
michael@0 | 13 | let args = yield on("Set", ["foo", null, "bar"]); |
michael@0 | 14 | observerArgsOK(args.foo, [["a.com", "foo", 1]]); |
michael@0 | 15 | observerArgsOK(args.null, [["a.com", "foo", 1]]); |
michael@0 | 16 | observerArgsOK(args.bar, []); |
michael@0 | 17 | |
michael@0 | 18 | yield setGlobal("foo", 2); |
michael@0 | 19 | args = yield on("Set", ["foo", null, "bar"]); |
michael@0 | 20 | observerArgsOK(args.foo, [[null, "foo", 2]]); |
michael@0 | 21 | observerArgsOK(args.null, [[null, "foo", 2]]); |
michael@0 | 22 | observerArgsOK(args.bar, []); |
michael@0 | 23 | }, |
michael@0 | 24 | |
michael@0 | 25 | function observerForName_remove() { |
michael@0 | 26 | yield set("a.com", "foo", 1); |
michael@0 | 27 | yield setGlobal("foo", 2); |
michael@0 | 28 | |
michael@0 | 29 | yield cps.removeByDomainAndName("a.com", "bogus", null, makeCallback()); |
michael@0 | 30 | let args = yield on("Removed", ["foo", null, "bar"]); |
michael@0 | 31 | observerArgsOK(args.foo, []); |
michael@0 | 32 | observerArgsOK(args.null, []); |
michael@0 | 33 | observerArgsOK(args.bar, []); |
michael@0 | 34 | |
michael@0 | 35 | yield cps.removeByDomainAndName("a.com", "foo", null, makeCallback()); |
michael@0 | 36 | args = yield on("Removed", ["foo", null, "bar"]); |
michael@0 | 37 | observerArgsOK(args.foo, [["a.com", "foo"]]); |
michael@0 | 38 | observerArgsOK(args.null, [["a.com", "foo"]]); |
michael@0 | 39 | observerArgsOK(args.bar, []); |
michael@0 | 40 | |
michael@0 | 41 | yield cps.removeGlobal("foo", null, makeCallback()); |
michael@0 | 42 | args = yield on("Removed", ["foo", null, "bar"]); |
michael@0 | 43 | observerArgsOK(args.foo, [[null, "foo"]]); |
michael@0 | 44 | observerArgsOK(args.null, [[null, "foo"]]); |
michael@0 | 45 | observerArgsOK(args.bar, []); |
michael@0 | 46 | }, |
michael@0 | 47 | |
michael@0 | 48 | function observerForName_removeByDomain() { |
michael@0 | 49 | yield set("a.com", "foo", 1); |
michael@0 | 50 | yield set("b.a.com", "bar", 2); |
michael@0 | 51 | yield setGlobal("foo", 3); |
michael@0 | 52 | |
michael@0 | 53 | yield cps.removeByDomain("bogus", null, makeCallback()); |
michael@0 | 54 | let args = yield on("Removed", ["foo", null, "bar"]); |
michael@0 | 55 | observerArgsOK(args.foo, []); |
michael@0 | 56 | observerArgsOK(args.null, []); |
michael@0 | 57 | observerArgsOK(args.bar, []); |
michael@0 | 58 | |
michael@0 | 59 | yield cps.removeBySubdomain("a.com", null, makeCallback()); |
michael@0 | 60 | args = yield on("Removed", ["foo", null, "bar"]); |
michael@0 | 61 | observerArgsOK(args.foo, [["a.com", "foo"]]); |
michael@0 | 62 | observerArgsOK(args.null, [["a.com", "foo"], ["b.a.com", "bar"]]); |
michael@0 | 63 | observerArgsOK(args.bar, [["b.a.com", "bar"]]); |
michael@0 | 64 | |
michael@0 | 65 | yield cps.removeAllGlobals(null, makeCallback()); |
michael@0 | 66 | args = yield on("Removed", ["foo", null, "bar"]); |
michael@0 | 67 | observerArgsOK(args.foo, [[null, "foo"]]); |
michael@0 | 68 | observerArgsOK(args.null, [[null, "foo"]]); |
michael@0 | 69 | observerArgsOK(args.bar, []); |
michael@0 | 70 | }, |
michael@0 | 71 | |
michael@0 | 72 | function observerForName_removeAllDomains() { |
michael@0 | 73 | yield set("a.com", "foo", 1); |
michael@0 | 74 | yield setGlobal("foo", 2); |
michael@0 | 75 | yield set("b.com", "bar", 3); |
michael@0 | 76 | |
michael@0 | 77 | yield cps.removeAllDomains(null, makeCallback()); |
michael@0 | 78 | let args = yield on("Removed", ["foo", null, "bar"]); |
michael@0 | 79 | observerArgsOK(args.foo, [["a.com", "foo"]]); |
michael@0 | 80 | observerArgsOK(args.null, [["a.com", "foo"], ["b.com", "bar"]]); |
michael@0 | 81 | observerArgsOK(args.bar, [["b.com", "bar"]]); |
michael@0 | 82 | }, |
michael@0 | 83 | |
michael@0 | 84 | function observerForName_removeByName() { |
michael@0 | 85 | yield set("a.com", "foo", 1); |
michael@0 | 86 | yield set("a.com", "bar", 2); |
michael@0 | 87 | yield setGlobal("foo", 3); |
michael@0 | 88 | |
michael@0 | 89 | yield cps.removeByName("bogus", null, makeCallback()); |
michael@0 | 90 | let args = yield on("Removed", ["foo", null, "bar"]); |
michael@0 | 91 | observerArgsOK(args.foo, []); |
michael@0 | 92 | observerArgsOK(args.null, []); |
michael@0 | 93 | observerArgsOK(args.bar, []); |
michael@0 | 94 | |
michael@0 | 95 | yield cps.removeByName("foo", null, makeCallback()); |
michael@0 | 96 | args = yield on("Removed", ["foo", null, "bar"]); |
michael@0 | 97 | observerArgsOK(args.foo, [["a.com", "foo"], [null, "foo"]]); |
michael@0 | 98 | observerArgsOK(args.null, [["a.com", "foo"], [null, "foo"]]); |
michael@0 | 99 | observerArgsOK(args.bar, []); |
michael@0 | 100 | }, |
michael@0 | 101 | |
michael@0 | 102 | function removeObserverForName() { |
michael@0 | 103 | let args = yield on("Set", ["foo", null, "bar"], true); |
michael@0 | 104 | |
michael@0 | 105 | cps.removeObserverForName("foo", args.foo.observer); |
michael@0 | 106 | yield set("a.com", "foo", 1); |
michael@0 | 107 | yield wait(); |
michael@0 | 108 | observerArgsOK(args.foo, []); |
michael@0 | 109 | observerArgsOK(args.null, [["a.com", "foo", 1]]); |
michael@0 | 110 | observerArgsOK(args.bar, []); |
michael@0 | 111 | args.reset(); |
michael@0 | 112 | |
michael@0 | 113 | cps.removeObserverForName(null, args.null.observer); |
michael@0 | 114 | yield set("a.com", "foo", 2); |
michael@0 | 115 | yield wait(); |
michael@0 | 116 | observerArgsOK(args.foo, []); |
michael@0 | 117 | observerArgsOK(args.null, []); |
michael@0 | 118 | observerArgsOK(args.bar, []); |
michael@0 | 119 | args.reset(); |
michael@0 | 120 | }, |
michael@0 | 121 | ]; |