1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/contentprefs/tests/unit_cps2/test_getCachedSubdomains.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,190 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +function run_test() { 1.9 + runAsyncTests(tests); 1.10 +} 1.11 + 1.12 +let tests = [ 1.13 + 1.14 + function nonexistent() { 1.15 + getCachedSubdomainsOK(["a.com", "foo"], []); 1.16 + yield true; 1.17 + }, 1.18 + 1.19 + function isomorphicDomains() { 1.20 + yield set("a.com", "foo", 1); 1.21 + getCachedSubdomainsOK(["a.com", "foo"], [["a.com", 1]]); 1.22 + getCachedSubdomainsOK(["http://a.com/huh", "foo"], [["a.com", 1]]); 1.23 + }, 1.24 + 1.25 + function names() { 1.26 + yield set("a.com", "foo", 1); 1.27 + getCachedSubdomainsOK(["a.com", "foo"], [["a.com", 1]]); 1.28 + 1.29 + yield set("a.com", "bar", 2); 1.30 + getCachedSubdomainsOK(["a.com", "foo"], [["a.com", 1]]); 1.31 + getCachedSubdomainsOK(["a.com", "bar"], [["a.com", 2]]); 1.32 + 1.33 + yield setGlobal("foo", 3); 1.34 + getCachedSubdomainsOK(["a.com", "foo"], [["a.com", 1]]); 1.35 + getCachedSubdomainsOK(["a.com", "bar"], [["a.com", 2]]); 1.36 + getCachedGlobalOK(["foo"], true, 3); 1.37 + 1.38 + yield setGlobal("bar", 4); 1.39 + getCachedSubdomainsOK(["a.com", "foo"], [["a.com", 1]]); 1.40 + getCachedSubdomainsOK(["a.com", "bar"], [["a.com", 2]]); 1.41 + getCachedGlobalOK(["foo"], true, 3); 1.42 + getCachedGlobalOK(["bar"], true, 4); 1.43 + }, 1.44 + 1.45 + function subdomains() { 1.46 + yield set("a.com", "foo", 1); 1.47 + yield set("b.a.com", "foo", 2); 1.48 + getCachedSubdomainsOK(["a.com", "foo"], [["a.com", 1], ["b.a.com", 2]]); 1.49 + getCachedSubdomainsOK(["b.a.com", "foo"], [["b.a.com", 2]]); 1.50 + }, 1.51 + 1.52 + function populateViaGet() { 1.53 + yield cps.getByDomainAndName("a.com", "foo", null, makeCallback()); 1.54 + getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); 1.55 + 1.56 + yield cps.getGlobal("foo", null, makeCallback()); 1.57 + getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); 1.58 + getCachedGlobalOK(["foo"], true, undefined); 1.59 + }, 1.60 + 1.61 + function populateViaGetSubdomains() { 1.62 + yield cps.getBySubdomainAndName("a.com", "foo", null, makeCallback()); 1.63 + getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); 1.64 + }, 1.65 + 1.66 + function populateViaRemove() { 1.67 + yield cps.removeByDomainAndName("a.com", "foo", null, makeCallback()); 1.68 + getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); 1.69 + 1.70 + yield cps.removeBySubdomainAndName("b.com", "foo", null, makeCallback()); 1.71 + getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); 1.72 + getCachedSubdomainsOK(["b.com", "foo"], [["b.com", undefined]]); 1.73 + 1.74 + yield cps.removeGlobal("foo", null, makeCallback()); 1.75 + getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); 1.76 + getCachedSubdomainsOK(["b.com", "foo"], [["b.com", undefined]]); 1.77 + getCachedGlobalOK(["foo"], true, undefined); 1.78 + 1.79 + yield set("a.com", "foo", 1); 1.80 + yield cps.removeByDomainAndName("a.com", "foo", null, makeCallback()); 1.81 + getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); 1.82 + getCachedSubdomainsOK(["b.com", "foo"], [["b.com", undefined]]); 1.83 + getCachedGlobalOK(["foo"], true, undefined); 1.84 + 1.85 + yield set("a.com", "foo", 2); 1.86 + yield set("b.a.com", "foo", 3); 1.87 + yield cps.removeBySubdomainAndName("a.com", "foo", null, makeCallback()); 1.88 + getCachedSubdomainsOK(["a.com", "foo"], 1.89 + [["a.com", undefined], ["b.a.com", undefined]]); 1.90 + getCachedSubdomainsOK(["b.com", "foo"], [["b.com", undefined]]); 1.91 + getCachedGlobalOK(["foo"], true, undefined); 1.92 + getCachedSubdomainsOK(["b.a.com", "foo"], [["b.a.com", undefined]]); 1.93 + 1.94 + yield setGlobal("foo", 4); 1.95 + yield cps.removeGlobal("foo", null, makeCallback()); 1.96 + getCachedSubdomainsOK(["a.com", "foo"], 1.97 + [["a.com", undefined], ["b.a.com", undefined]]); 1.98 + getCachedSubdomainsOK(["b.com", "foo"], [["b.com", undefined]]); 1.99 + getCachedGlobalOK(["foo"], true, undefined); 1.100 + getCachedSubdomainsOK(["b.a.com", "foo"], [["b.a.com", undefined]]); 1.101 + }, 1.102 + 1.103 + function populateViaRemoveByDomain() { 1.104 + yield set("a.com", "foo", 1); 1.105 + yield set("a.com", "bar", 2); 1.106 + yield set("b.a.com", "foo", 3); 1.107 + yield set("b.a.com", "bar", 4); 1.108 + yield cps.removeByDomain("a.com", null, makeCallback()); 1.109 + getCachedSubdomainsOK(["a.com", "foo"], 1.110 + [["a.com", undefined], ["b.a.com", 3]]); 1.111 + getCachedSubdomainsOK(["a.com", "bar"], 1.112 + [["a.com", undefined], ["b.a.com", 4]]); 1.113 + 1.114 + yield set("a.com", "foo", 5); 1.115 + yield set("a.com", "bar", 6); 1.116 + yield cps.removeBySubdomain("a.com", null, makeCallback()); 1.117 + getCachedSubdomainsOK(["a.com", "foo"], 1.118 + [["a.com", undefined], ["b.a.com", undefined]]); 1.119 + getCachedSubdomainsOK(["a.com", "bar"], 1.120 + [["a.com", undefined], ["b.a.com", undefined]]); 1.121 + 1.122 + yield setGlobal("foo", 7); 1.123 + yield setGlobal("bar", 8); 1.124 + yield cps.removeAllGlobals(null, makeCallback()); 1.125 + getCachedGlobalOK(["foo"], true, undefined); 1.126 + getCachedGlobalOK(["bar"], true, undefined); 1.127 + }, 1.128 + 1.129 + function populateViaRemoveAllDomains() { 1.130 + yield set("a.com", "foo", 1); 1.131 + yield set("a.com", "bar", 2); 1.132 + yield set("b.com", "foo", 3); 1.133 + yield set("b.com", "bar", 4); 1.134 + yield cps.removeAllDomains(null, makeCallback()); 1.135 + getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); 1.136 + getCachedSubdomainsOK(["a.com", "bar"], [["a.com", undefined]]); 1.137 + getCachedSubdomainsOK(["b.com", "foo"], [["b.com", undefined]]); 1.138 + getCachedSubdomainsOK(["b.com", "bar"], [["b.com", undefined]]); 1.139 + }, 1.140 + 1.141 + function populateViaRemoveByName() { 1.142 + yield set("a.com", "foo", 1); 1.143 + yield set("a.com", "bar", 2); 1.144 + yield setGlobal("foo", 3); 1.145 + yield setGlobal("bar", 4); 1.146 + yield cps.removeByName("foo", null, makeCallback()); 1.147 + getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); 1.148 + getCachedSubdomainsOK(["a.com", "bar"], [["a.com", 2]]); 1.149 + getCachedGlobalOK(["foo"], true, undefined); 1.150 + getCachedGlobalOK(["bar"], true, 4); 1.151 + 1.152 + yield cps.removeByName("bar", null, makeCallback()); 1.153 + getCachedSubdomainsOK(["a.com", "foo"], [["a.com", undefined]]); 1.154 + getCachedSubdomainsOK(["a.com", "bar"], [["a.com", undefined]]); 1.155 + getCachedGlobalOK(["foo"], true, undefined); 1.156 + getCachedGlobalOK(["bar"], true, undefined); 1.157 + }, 1.158 + 1.159 + function privateBrowsing() { 1.160 + yield set("a.com", "foo", 1); 1.161 + yield set("a.com", "bar", 2); 1.162 + yield setGlobal("foo", 3); 1.163 + yield setGlobal("bar", 4); 1.164 + yield set("b.com", "foo", 5); 1.165 + 1.166 + let context = { usePrivateBrowsing: true }; 1.167 + yield set("a.com", "foo", 6, context); 1.168 + yield setGlobal("foo", 7, context); 1.169 + getCachedSubdomainsOK(["a.com", "foo", context], [["a.com", 6]]); 1.170 + getCachedSubdomainsOK(["a.com", "bar", context], [["a.com", 2]]); 1.171 + getCachedGlobalOK(["foo", context], true, 7); 1.172 + getCachedGlobalOK(["bar", context], true, 4); 1.173 + getCachedSubdomainsOK(["b.com", "foo", context], [["b.com", 5]]); 1.174 + 1.175 + getCachedSubdomainsOK(["a.com", "foo"], [["a.com", 1]]); 1.176 + getCachedSubdomainsOK(["a.com", "bar"], [["a.com", 2]]); 1.177 + getCachedGlobalOK(["foo"], true, 3); 1.178 + getCachedGlobalOK(["bar"], true, 4); 1.179 + getCachedSubdomainsOK(["b.com", "foo"], [["b.com", 5]]); 1.180 + }, 1.181 + 1.182 + function erroneous() { 1.183 + do_check_throws(function () 1.184 + cps.getCachedBySubdomainAndName(null, "foo", null)); 1.185 + do_check_throws(function () 1.186 + cps.getCachedBySubdomainAndName("", "foo", null)); 1.187 + do_check_throws(function () 1.188 + cps.getCachedBySubdomainAndName("a.com", "", null)); 1.189 + do_check_throws(function () 1.190 + cps.getCachedBySubdomainAndName("a.com", null, null)); 1.191 + yield true; 1.192 + }, 1.193 +];