Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
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 nonexistent() { |
michael@0 | 12 | getCachedSubdomainsOK(["a.com", "foo"], []); |
michael@0 | 13 | yield true; |
michael@0 | 14 | }, |
michael@0 | 15 | |
michael@0 | 16 | function isomorphicDomains() { |
michael@0 | 17 | yield set("a.com", "foo", 1); |
michael@0 | 18 | getCachedSubdomainsOK(["a.com", "foo"], [["a.com", 1]]); |
michael@0 | 19 | getCachedSubdomainsOK(["http://a.com/huh", "foo"], [["a.com", 1]]); |
michael@0 | 20 | }, |
michael@0 | 21 | |
michael@0 | 22 | function names() { |
michael@0 | 23 | yield set("a.com", "foo", 1); |
michael@0 | 24 | getCachedSubdomainsOK(["a.com", "foo"], [["a.com", 1]]); |
michael@0 | 25 | |
michael@0 | 26 | yield set("a.com", "bar", 2); |
michael@0 | 27 | getCachedSubdomainsOK(["a.com", "foo"], [["a.com", 1]]); |
michael@0 | 28 | getCachedSubdomainsOK(["a.com", "bar"], [["a.com", 2]]); |
michael@0 | 29 | |
michael@0 | 30 | yield setGlobal("foo", 3); |
michael@0 | 31 | getCachedSubdomainsOK(["a.com", "foo"], [["a.com", 1]]); |
michael@0 | 32 | getCachedSubdomainsOK(["a.com", "bar"], [["a.com", 2]]); |
michael@0 | 33 | getCachedGlobalOK(["foo"], true, 3); |
michael@0 | 34 | |
michael@0 | 35 | yield setGlobal("bar", 4); |
michael@0 | 36 | getCachedSubdomainsOK(["a.com", "foo"], [["a.com", 1]]); |
michael@0 | 37 | getCachedSubdomainsOK(["a.com", "bar"], [["a.com", 2]]); |
michael@0 | 38 | getCachedGlobalOK(["foo"], true, 3); |
michael@0 | 39 | getCachedGlobalOK(["bar"], true, 4); |
michael@0 | 40 | }, |
michael@0 | 41 | |
michael@0 | 42 | function subdomains() { |
michael@0 | 43 | yield set("a.com", "foo", 1); |
michael@0 | 44 | yield set("b.a.com", "foo", 2); |
michael@0 | 45 | getCachedSubdomainsOK(["a.com", "foo"], [["a.com", 1], ["b.a.com", 2]]); |
michael@0 | 46 | getCachedSubdomainsOK(["b.a.com", "foo"], [["b.a.com", 2]]); |
michael@0 | 47 | }, |
michael@0 | 48 | |
michael@0 | 49 | function populateViaGet() { |
michael@0 | 50 | yield cps.getByDomainAndName("a.com", "foo", null, makeCallback()); |
michael@0 | 51 | getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); |
michael@0 | 52 | |
michael@0 | 53 | yield cps.getGlobal("foo", null, makeCallback()); |
michael@0 | 54 | getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); |
michael@0 | 55 | getCachedGlobalOK(["foo"], true, undefined); |
michael@0 | 56 | }, |
michael@0 | 57 | |
michael@0 | 58 | function populateViaGetSubdomains() { |
michael@0 | 59 | yield cps.getBySubdomainAndName("a.com", "foo", null, makeCallback()); |
michael@0 | 60 | getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); |
michael@0 | 61 | }, |
michael@0 | 62 | |
michael@0 | 63 | function populateViaRemove() { |
michael@0 | 64 | yield cps.removeByDomainAndName("a.com", "foo", null, makeCallback()); |
michael@0 | 65 | getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); |
michael@0 | 66 | |
michael@0 | 67 | yield cps.removeBySubdomainAndName("b.com", "foo", null, makeCallback()); |
michael@0 | 68 | getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); |
michael@0 | 69 | getCachedSubdomainsOK(["b.com", "foo"], [["b.com", undefined]]); |
michael@0 | 70 | |
michael@0 | 71 | yield cps.removeGlobal("foo", null, makeCallback()); |
michael@0 | 72 | getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); |
michael@0 | 73 | getCachedSubdomainsOK(["b.com", "foo"], [["b.com", undefined]]); |
michael@0 | 74 | getCachedGlobalOK(["foo"], true, undefined); |
michael@0 | 75 | |
michael@0 | 76 | yield set("a.com", "foo", 1); |
michael@0 | 77 | yield cps.removeByDomainAndName("a.com", "foo", null, makeCallback()); |
michael@0 | 78 | getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); |
michael@0 | 79 | getCachedSubdomainsOK(["b.com", "foo"], [["b.com", undefined]]); |
michael@0 | 80 | getCachedGlobalOK(["foo"], true, undefined); |
michael@0 | 81 | |
michael@0 | 82 | yield set("a.com", "foo", 2); |
michael@0 | 83 | yield set("b.a.com", "foo", 3); |
michael@0 | 84 | yield cps.removeBySubdomainAndName("a.com", "foo", null, makeCallback()); |
michael@0 | 85 | getCachedSubdomainsOK(["a.com", "foo"], |
michael@0 | 86 | [["a.com", undefined], ["b.a.com", undefined]]); |
michael@0 | 87 | getCachedSubdomainsOK(["b.com", "foo"], [["b.com", undefined]]); |
michael@0 | 88 | getCachedGlobalOK(["foo"], true, undefined); |
michael@0 | 89 | getCachedSubdomainsOK(["b.a.com", "foo"], [["b.a.com", undefined]]); |
michael@0 | 90 | |
michael@0 | 91 | yield setGlobal("foo", 4); |
michael@0 | 92 | yield cps.removeGlobal("foo", null, makeCallback()); |
michael@0 | 93 | getCachedSubdomainsOK(["a.com", "foo"], |
michael@0 | 94 | [["a.com", undefined], ["b.a.com", undefined]]); |
michael@0 | 95 | getCachedSubdomainsOK(["b.com", "foo"], [["b.com", undefined]]); |
michael@0 | 96 | getCachedGlobalOK(["foo"], true, undefined); |
michael@0 | 97 | getCachedSubdomainsOK(["b.a.com", "foo"], [["b.a.com", undefined]]); |
michael@0 | 98 | }, |
michael@0 | 99 | |
michael@0 | 100 | function populateViaRemoveByDomain() { |
michael@0 | 101 | yield set("a.com", "foo", 1); |
michael@0 | 102 | yield set("a.com", "bar", 2); |
michael@0 | 103 | yield set("b.a.com", "foo", 3); |
michael@0 | 104 | yield set("b.a.com", "bar", 4); |
michael@0 | 105 | yield cps.removeByDomain("a.com", null, makeCallback()); |
michael@0 | 106 | getCachedSubdomainsOK(["a.com", "foo"], |
michael@0 | 107 | [["a.com", undefined], ["b.a.com", 3]]); |
michael@0 | 108 | getCachedSubdomainsOK(["a.com", "bar"], |
michael@0 | 109 | [["a.com", undefined], ["b.a.com", 4]]); |
michael@0 | 110 | |
michael@0 | 111 | yield set("a.com", "foo", 5); |
michael@0 | 112 | yield set("a.com", "bar", 6); |
michael@0 | 113 | yield cps.removeBySubdomain("a.com", null, makeCallback()); |
michael@0 | 114 | getCachedSubdomainsOK(["a.com", "foo"], |
michael@0 | 115 | [["a.com", undefined], ["b.a.com", undefined]]); |
michael@0 | 116 | getCachedSubdomainsOK(["a.com", "bar"], |
michael@0 | 117 | [["a.com", undefined], ["b.a.com", undefined]]); |
michael@0 | 118 | |
michael@0 | 119 | yield setGlobal("foo", 7); |
michael@0 | 120 | yield setGlobal("bar", 8); |
michael@0 | 121 | yield cps.removeAllGlobals(null, makeCallback()); |
michael@0 | 122 | getCachedGlobalOK(["foo"], true, undefined); |
michael@0 | 123 | getCachedGlobalOK(["bar"], true, undefined); |
michael@0 | 124 | }, |
michael@0 | 125 | |
michael@0 | 126 | function populateViaRemoveAllDomains() { |
michael@0 | 127 | yield set("a.com", "foo", 1); |
michael@0 | 128 | yield set("a.com", "bar", 2); |
michael@0 | 129 | yield set("b.com", "foo", 3); |
michael@0 | 130 | yield set("b.com", "bar", 4); |
michael@0 | 131 | yield cps.removeAllDomains(null, makeCallback()); |
michael@0 | 132 | getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); |
michael@0 | 133 | getCachedSubdomainsOK(["a.com", "bar"], [["a.com", undefined]]); |
michael@0 | 134 | getCachedSubdomainsOK(["b.com", "foo"], [["b.com", undefined]]); |
michael@0 | 135 | getCachedSubdomainsOK(["b.com", "bar"], [["b.com", undefined]]); |
michael@0 | 136 | }, |
michael@0 | 137 | |
michael@0 | 138 | function populateViaRemoveByName() { |
michael@0 | 139 | yield set("a.com", "foo", 1); |
michael@0 | 140 | yield set("a.com", "bar", 2); |
michael@0 | 141 | yield setGlobal("foo", 3); |
michael@0 | 142 | yield setGlobal("bar", 4); |
michael@0 | 143 | yield cps.removeByName("foo", null, makeCallback()); |
michael@0 | 144 | getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); |
michael@0 | 145 | getCachedSubdomainsOK(["a.com", "bar"], [["a.com", 2]]); |
michael@0 | 146 | getCachedGlobalOK(["foo"], true, undefined); |
michael@0 | 147 | getCachedGlobalOK(["bar"], true, 4); |
michael@0 | 148 | |
michael@0 | 149 | yield cps.removeByName("bar", null, makeCallback()); |
michael@0 | 150 | getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); |
michael@0 | 151 | getCachedSubdomainsOK(["a.com", "bar"], [["a.com", undefined]]); |
michael@0 | 152 | getCachedGlobalOK(["foo"], true, undefined); |
michael@0 | 153 | getCachedGlobalOK(["bar"], true, undefined); |
michael@0 | 154 | }, |
michael@0 | 155 | |
michael@0 | 156 | function privateBrowsing() { |
michael@0 | 157 | yield set("a.com", "foo", 1); |
michael@0 | 158 | yield set("a.com", "bar", 2); |
michael@0 | 159 | yield setGlobal("foo", 3); |
michael@0 | 160 | yield setGlobal("bar", 4); |
michael@0 | 161 | yield set("b.com", "foo", 5); |
michael@0 | 162 | |
michael@0 | 163 | let context = { usePrivateBrowsing: true }; |
michael@0 | 164 | yield set("a.com", "foo", 6, context); |
michael@0 | 165 | yield setGlobal("foo", 7, context); |
michael@0 | 166 | getCachedSubdomainsOK(["a.com", "foo", context], [["a.com", 6]]); |
michael@0 | 167 | getCachedSubdomainsOK(["a.com", "bar", context], [["a.com", 2]]); |
michael@0 | 168 | getCachedGlobalOK(["foo", context], true, 7); |
michael@0 | 169 | getCachedGlobalOK(["bar", context], true, 4); |
michael@0 | 170 | getCachedSubdomainsOK(["b.com", "foo", context], [["b.com", 5]]); |
michael@0 | 171 | |
michael@0 | 172 | getCachedSubdomainsOK(["a.com", "foo"], [["a.com", 1]]); |
michael@0 | 173 | getCachedSubdomainsOK(["a.com", "bar"], [["a.com", 2]]); |
michael@0 | 174 | getCachedGlobalOK(["foo"], true, 3); |
michael@0 | 175 | getCachedGlobalOK(["bar"], true, 4); |
michael@0 | 176 | getCachedSubdomainsOK(["b.com", "foo"], [["b.com", 5]]); |
michael@0 | 177 | }, |
michael@0 | 178 | |
michael@0 | 179 | function erroneous() { |
michael@0 | 180 | do_check_throws(function () |
michael@0 | 181 | cps.getCachedBySubdomainAndName(null, "foo", null)); |
michael@0 | 182 | do_check_throws(function () |
michael@0 | 183 | cps.getCachedBySubdomainAndName("", "foo", null)); |
michael@0 | 184 | do_check_throws(function () |
michael@0 | 185 | cps.getCachedBySubdomainAndName("a.com", "", null)); |
michael@0 | 186 | do_check_throws(function () |
michael@0 | 187 | cps.getCachedBySubdomainAndName("a.com", null, null)); |
michael@0 | 188 | yield true; |
michael@0 | 189 | }, |
michael@0 | 190 | ]; |