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 get_nonexistent() { |
michael@0 | 12 | yield getOK(["a.com", "foo"], undefined); |
michael@0 | 13 | yield getGlobalOK(["foo"], undefined); |
michael@0 | 14 | }, |
michael@0 | 15 | |
michael@0 | 16 | function isomorphicDomains() { |
michael@0 | 17 | yield set("a.com", "foo", 1); |
michael@0 | 18 | yield dbOK([ |
michael@0 | 19 | ["a.com", "foo", 1], |
michael@0 | 20 | ]); |
michael@0 | 21 | yield getOK(["a.com", "foo"], 1); |
michael@0 | 22 | yield getOK(["http://a.com/huh", "foo"], 1, "a.com"); |
michael@0 | 23 | |
michael@0 | 24 | yield set("http://a.com/huh", "foo", 2); |
michael@0 | 25 | yield dbOK([ |
michael@0 | 26 | ["a.com", "foo", 2], |
michael@0 | 27 | ]); |
michael@0 | 28 | yield getOK(["a.com", "foo"], 2); |
michael@0 | 29 | yield getOK(["http://a.com/yeah", "foo"], 2, "a.com"); |
michael@0 | 30 | }, |
michael@0 | 31 | |
michael@0 | 32 | function names() { |
michael@0 | 33 | yield set("a.com", "foo", 1); |
michael@0 | 34 | yield dbOK([ |
michael@0 | 35 | ["a.com", "foo", 1], |
michael@0 | 36 | ]); |
michael@0 | 37 | yield getOK(["a.com", "foo"], 1); |
michael@0 | 38 | |
michael@0 | 39 | yield set("a.com", "bar", 2); |
michael@0 | 40 | yield dbOK([ |
michael@0 | 41 | ["a.com", "foo", 1], |
michael@0 | 42 | ["a.com", "bar", 2], |
michael@0 | 43 | ]); |
michael@0 | 44 | yield getOK(["a.com", "foo"], 1); |
michael@0 | 45 | yield getOK(["a.com", "bar"], 2); |
michael@0 | 46 | |
michael@0 | 47 | yield setGlobal("foo", 3); |
michael@0 | 48 | yield dbOK([ |
michael@0 | 49 | ["a.com", "foo", 1], |
michael@0 | 50 | ["a.com", "bar", 2], |
michael@0 | 51 | [null, "foo", 3], |
michael@0 | 52 | ]); |
michael@0 | 53 | yield getOK(["a.com", "foo"], 1); |
michael@0 | 54 | yield getOK(["a.com", "bar"], 2); |
michael@0 | 55 | yield getGlobalOK(["foo"], 3); |
michael@0 | 56 | |
michael@0 | 57 | yield setGlobal("bar", 4); |
michael@0 | 58 | yield dbOK([ |
michael@0 | 59 | ["a.com", "foo", 1], |
michael@0 | 60 | ["a.com", "bar", 2], |
michael@0 | 61 | [null, "foo", 3], |
michael@0 | 62 | [null, "bar", 4], |
michael@0 | 63 | ]); |
michael@0 | 64 | yield getOK(["a.com", "foo"], 1); |
michael@0 | 65 | yield getOK(["a.com", "bar"], 2); |
michael@0 | 66 | yield getGlobalOK(["foo"], 3); |
michael@0 | 67 | yield getGlobalOK(["bar"], 4); |
michael@0 | 68 | }, |
michael@0 | 69 | |
michael@0 | 70 | function subdomains() { |
michael@0 | 71 | yield set("a.com", "foo", 1); |
michael@0 | 72 | yield set("b.a.com", "foo", 2); |
michael@0 | 73 | yield dbOK([ |
michael@0 | 74 | ["a.com", "foo", 1], |
michael@0 | 75 | ["b.a.com", "foo", 2], |
michael@0 | 76 | ]); |
michael@0 | 77 | yield getOK(["a.com", "foo"], 1); |
michael@0 | 78 | yield getOK(["b.a.com", "foo"], 2); |
michael@0 | 79 | }, |
michael@0 | 80 | |
michael@0 | 81 | function privateBrowsing() { |
michael@0 | 82 | yield set("a.com", "foo", 1); |
michael@0 | 83 | yield set("a.com", "bar", 2); |
michael@0 | 84 | yield setGlobal("foo", 3); |
michael@0 | 85 | yield setGlobal("bar", 4); |
michael@0 | 86 | yield set("b.com", "foo", 5); |
michael@0 | 87 | |
michael@0 | 88 | let context = { usePrivateBrowsing: true }; |
michael@0 | 89 | yield set("a.com", "foo", 6, context); |
michael@0 | 90 | yield setGlobal("foo", 7, context); |
michael@0 | 91 | yield dbOK([ |
michael@0 | 92 | ["a.com", "foo", 1], |
michael@0 | 93 | ["a.com", "bar", 2], |
michael@0 | 94 | [null, "foo", 3], |
michael@0 | 95 | [null, "bar", 4], |
michael@0 | 96 | ["b.com", "foo", 5], |
michael@0 | 97 | ]); |
michael@0 | 98 | yield getOK(["a.com", "foo", context], 6, "a.com"); |
michael@0 | 99 | yield getOK(["a.com", "bar", context], 2); |
michael@0 | 100 | yield getGlobalOK(["foo", context], 7); |
michael@0 | 101 | yield getGlobalOK(["bar", context], 4); |
michael@0 | 102 | yield getOK(["b.com", "foo", context], 5); |
michael@0 | 103 | |
michael@0 | 104 | yield getOK(["a.com", "foo"], 1); |
michael@0 | 105 | yield getOK(["a.com", "bar"], 2); |
michael@0 | 106 | yield getGlobalOK(["foo"], 3); |
michael@0 | 107 | yield getGlobalOK(["bar"], 4); |
michael@0 | 108 | yield getOK(["b.com", "foo"], 5); |
michael@0 | 109 | }, |
michael@0 | 110 | |
michael@0 | 111 | function set_erroneous() { |
michael@0 | 112 | do_check_throws(function () cps.set(null, "foo", 1, null)); |
michael@0 | 113 | do_check_throws(function () cps.set("", "foo", 1, null)); |
michael@0 | 114 | do_check_throws(function () cps.set("a.com", "", 1, null)); |
michael@0 | 115 | do_check_throws(function () cps.set("a.com", null, 1, null)); |
michael@0 | 116 | do_check_throws(function () cps.set("a.com", "foo", undefined, null)); |
michael@0 | 117 | do_check_throws(function () cps.set("a.com", "foo", 1, null, "bogus")); |
michael@0 | 118 | do_check_throws(function () cps.setGlobal("", 1, null)); |
michael@0 | 119 | do_check_throws(function () cps.setGlobal(null, 1, null)); |
michael@0 | 120 | do_check_throws(function () cps.setGlobal("foo", undefined, null)); |
michael@0 | 121 | do_check_throws(function () cps.setGlobal("foo", 1, null, "bogus")); |
michael@0 | 122 | yield true; |
michael@0 | 123 | }, |
michael@0 | 124 | |
michael@0 | 125 | function get_erroneous() { |
michael@0 | 126 | do_check_throws(function () cps.getByDomainAndName(null, "foo", null, {})); |
michael@0 | 127 | do_check_throws(function () cps.getByDomainAndName("", "foo", null, {})); |
michael@0 | 128 | do_check_throws(function () cps.getByDomainAndName("a.com", "", null, {})); |
michael@0 | 129 | do_check_throws(function () |
michael@0 | 130 | cps.getByDomainAndName("a.com", null, null, {})); |
michael@0 | 131 | do_check_throws(function () |
michael@0 | 132 | cps.getByDomainAndName("a.com", "foo", null, null)); |
michael@0 | 133 | do_check_throws(function () cps.getGlobal("", null, {})); |
michael@0 | 134 | do_check_throws(function () cps.getGlobal(null, null, {})); |
michael@0 | 135 | do_check_throws(function () cps.getGlobal("foo", null, null)); |
michael@0 | 136 | yield true; |
michael@0 | 137 | }, |
michael@0 | 138 | |
michael@0 | 139 | function set_invalidateCache() { |
michael@0 | 140 | // (1) Set a pref and wait for it to finish. |
michael@0 | 141 | yield set("a.com", "foo", 1); |
michael@0 | 142 | |
michael@0 | 143 | // (2) It should be cached. |
michael@0 | 144 | getCachedOK(["a.com", "foo"], true, 1); |
michael@0 | 145 | |
michael@0 | 146 | // (3) Set the pref to a new value but don't wait for it to finish. |
michael@0 | 147 | cps.set("a.com", "foo", 2, null, { |
michael@0 | 148 | handleCompletion: function () { |
michael@0 | 149 | // (6) The pref should be cached after setting it. |
michael@0 | 150 | getCachedOK(["a.com", "foo"], true, 2); |
michael@0 | 151 | }, |
michael@0 | 152 | }); |
michael@0 | 153 | |
michael@0 | 154 | // (4) Group "a.com" and name "foo" should no longer be cached. |
michael@0 | 155 | getCachedOK(["a.com", "foo"], false); |
michael@0 | 156 | |
michael@0 | 157 | // (5) Call getByDomainAndName. |
michael@0 | 158 | var fetchedPref; |
michael@0 | 159 | cps.getByDomainAndName("a.com", "foo", null, { |
michael@0 | 160 | handleResult: function (pref) { |
michael@0 | 161 | fetchedPref = pref; |
michael@0 | 162 | }, |
michael@0 | 163 | handleCompletion: function () { |
michael@0 | 164 | // (7) Finally, this callback should be called after set's above. |
michael@0 | 165 | do_check_true(!!fetchedPref); |
michael@0 | 166 | do_check_eq(fetchedPref.value, 2); |
michael@0 | 167 | next(); |
michael@0 | 168 | }, |
michael@0 | 169 | }); |
michael@0 | 170 | |
michael@0 | 171 | yield; |
michael@0 | 172 | }, |
michael@0 | 173 | |
michael@0 | 174 | function get_nameOnly() { |
michael@0 | 175 | yield set("a.com", "foo", 1); |
michael@0 | 176 | yield set("a.com", "bar", 2); |
michael@0 | 177 | yield set("b.com", "foo", 3); |
michael@0 | 178 | yield setGlobal("foo", 4); |
michael@0 | 179 | |
michael@0 | 180 | yield getOKEx("getByName", ["foo", undefined], [ |
michael@0 | 181 | {"domain": "a.com", "name": "foo", "value": 1}, |
michael@0 | 182 | {"domain": "b.com", "name": "foo", "value": 3}, |
michael@0 | 183 | {"domain": null, "name": "foo", "value": 4} |
michael@0 | 184 | ]); |
michael@0 | 185 | |
michael@0 | 186 | let context = { usePrivateBrowsing: true }; |
michael@0 | 187 | yield set("b.com", "foo", 5, context); |
michael@0 | 188 | |
michael@0 | 189 | yield getOKEx("getByName", ["foo", context], [ |
michael@0 | 190 | {"domain": "a.com", "name": "foo", "value": 1}, |
michael@0 | 191 | {"domain": null, "name": "foo", "value": 4}, |
michael@0 | 192 | {"domain": "b.com", "name": "foo", "value": 5} |
michael@0 | 193 | ]); |
michael@0 | 194 | } |
michael@0 | 195 | ]; |