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 nonexistent() { |
michael@0 | 12 | getCachedOK(["a.com", "foo"], false, undefined); |
michael@0 | 13 | getCachedGlobalOK(["foo"], false, undefined); |
michael@0 | 14 | yield true; |
michael@0 | 15 | }, |
michael@0 | 16 | |
michael@0 | 17 | function isomorphicDomains() { |
michael@0 | 18 | yield set("a.com", "foo", 1); |
michael@0 | 19 | getCachedOK(["a.com", "foo"], true, 1); |
michael@0 | 20 | getCachedOK(["http://a.com/huh", "foo"], true, 1, "a.com"); |
michael@0 | 21 | }, |
michael@0 | 22 | |
michael@0 | 23 | function names() { |
michael@0 | 24 | yield set("a.com", "foo", 1); |
michael@0 | 25 | getCachedOK(["a.com", "foo"], true, 1); |
michael@0 | 26 | |
michael@0 | 27 | yield set("a.com", "bar", 2); |
michael@0 | 28 | getCachedOK(["a.com", "foo"], true, 1); |
michael@0 | 29 | getCachedOK(["a.com", "bar"], true, 2); |
michael@0 | 30 | |
michael@0 | 31 | yield setGlobal("foo", 3); |
michael@0 | 32 | getCachedOK(["a.com", "foo"], true, 1); |
michael@0 | 33 | getCachedOK(["a.com", "bar"], true, 2); |
michael@0 | 34 | getCachedGlobalOK(["foo"], true, 3); |
michael@0 | 35 | |
michael@0 | 36 | yield setGlobal("bar", 4); |
michael@0 | 37 | getCachedOK(["a.com", "foo"], true, 1); |
michael@0 | 38 | getCachedOK(["a.com", "bar"], true, 2); |
michael@0 | 39 | getCachedGlobalOK(["foo"], true, 3); |
michael@0 | 40 | getCachedGlobalOK(["bar"], true, 4); |
michael@0 | 41 | }, |
michael@0 | 42 | |
michael@0 | 43 | function subdomains() { |
michael@0 | 44 | yield set("a.com", "foo", 1); |
michael@0 | 45 | yield set("b.a.com", "foo", 2); |
michael@0 | 46 | getCachedOK(["a.com", "foo"], true, 1); |
michael@0 | 47 | getCachedOK(["b.a.com", "foo"], true, 2); |
michael@0 | 48 | }, |
michael@0 | 49 | |
michael@0 | 50 | function privateBrowsing() { |
michael@0 | 51 | yield set("a.com", "foo", 1); |
michael@0 | 52 | yield set("a.com", "bar", 2); |
michael@0 | 53 | yield setGlobal("foo", 3); |
michael@0 | 54 | yield setGlobal("bar", 4); |
michael@0 | 55 | yield set("b.com", "foo", 5); |
michael@0 | 56 | |
michael@0 | 57 | let context = { usePrivateBrowsing: true }; |
michael@0 | 58 | yield set("a.com", "foo", 6, context); |
michael@0 | 59 | yield setGlobal("foo", 7, context); |
michael@0 | 60 | getCachedOK(["a.com", "foo", context], true, 6); |
michael@0 | 61 | getCachedOK(["a.com", "bar", context], true, 2); |
michael@0 | 62 | getCachedGlobalOK(["foo", context], true, 7); |
michael@0 | 63 | getCachedGlobalOK(["bar", context], true, 4); |
michael@0 | 64 | getCachedOK(["b.com", "foo", context], true, 5); |
michael@0 | 65 | |
michael@0 | 66 | getCachedOK(["a.com", "foo"], true, 1); |
michael@0 | 67 | getCachedOK(["a.com", "bar"], true, 2); |
michael@0 | 68 | getCachedGlobalOK(["foo"], true, 3); |
michael@0 | 69 | getCachedGlobalOK(["bar"], true, 4); |
michael@0 | 70 | getCachedOK(["b.com", "foo"], true, 5); |
michael@0 | 71 | }, |
michael@0 | 72 | |
michael@0 | 73 | function erroneous() { |
michael@0 | 74 | do_check_throws(function () |
michael@0 | 75 | cps.getCachedByDomainAndName(null, "foo", null)); |
michael@0 | 76 | do_check_throws(function () |
michael@0 | 77 | cps.getCachedByDomainAndName("", "foo", null)); |
michael@0 | 78 | do_check_throws(function () |
michael@0 | 79 | cps.getCachedByDomainAndName("a.com", "", null)); |
michael@0 | 80 | do_check_throws(function () |
michael@0 | 81 | cps.getCachedByDomainAndName("a.com", null, null)); |
michael@0 | 82 | do_check_throws(function () cps.getCachedGlobal("", null)); |
michael@0 | 83 | do_check_throws(function () cps.getCachedGlobal(null, null)); |
michael@0 | 84 | yield true; |
michael@0 | 85 | }, |
michael@0 | 86 | |
michael@0 | 87 | function casts() { |
michael@0 | 88 | // SQLite casts booleans to integers. This makes sure the values stored in |
michael@0 | 89 | // the cache are the same as the casted values in the database. |
michael@0 | 90 | |
michael@0 | 91 | yield set("a.com", "foo", false); |
michael@0 | 92 | yield getOK(["a.com", "foo"], 0, "a.com", true); |
michael@0 | 93 | getCachedOK(["a.com", "foo"], true, 0, "a.com", true); |
michael@0 | 94 | |
michael@0 | 95 | yield set("a.com", "bar", true); |
michael@0 | 96 | yield getOK(["a.com", "bar"], 1, "a.com", true); |
michael@0 | 97 | getCachedOK(["a.com", "bar"], true, 1, "a.com", true); |
michael@0 | 98 | }, |
michael@0 | 99 | ]; |