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 |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | |
michael@0 | 6 | var prefObserver = { |
michael@0 | 7 | setCalledNum: 0, |
michael@0 | 8 | onContentPrefSet: function(aGroup, aName, aValue) { |
michael@0 | 9 | this.setCalledNum++; |
michael@0 | 10 | }, |
michael@0 | 11 | removedCalledNum: 0, |
michael@0 | 12 | onContentPrefRemoved: function(aGroup, aName) { |
michael@0 | 13 | this.removedCalledNum++; |
michael@0 | 14 | } |
michael@0 | 15 | }; |
michael@0 | 16 | |
michael@0 | 17 | function run_test() { |
michael@0 | 18 | let loadContext = { get usePrivateBrowsing() { return gInPrivateBrowsing; } }; |
michael@0 | 19 | |
michael@0 | 20 | var cps = new ContentPrefInstance(loadContext); |
michael@0 | 21 | cps.removeGroupedPrefs(); |
michael@0 | 22 | |
michael@0 | 23 | var uri = ContentPrefTest.getURI("http://www.example.com/"); |
michael@0 | 24 | var group = cps.grouper.group(uri); |
michael@0 | 25 | |
michael@0 | 26 | // first, set a pref in normal mode |
michael@0 | 27 | cps.setPref(uri, "value", "foo"); |
michael@0 | 28 | cps.setPref(null, "value-global", "foo-global"); |
michael@0 | 29 | |
michael@0 | 30 | var num; |
michael@0 | 31 | cps.addObserver("value", prefObserver); |
michael@0 | 32 | cps.addObserver("value-global", prefObserver); |
michael@0 | 33 | |
michael@0 | 34 | enterPBMode(); |
michael@0 | 35 | |
michael@0 | 36 | // test setPref |
michael@0 | 37 | num = prefObserver.setCalledNum; |
michael@0 | 38 | cps.setPref(uri, "value", "foo-private-browsing"); |
michael@0 | 39 | do_check_eq(cps.hasPref(uri, "value"), true); |
michael@0 | 40 | do_check_eq(cps.getPref(uri, "value"), "foo-private-browsing"); |
michael@0 | 41 | do_check_eq(prefObserver.setCalledNum, num + 1); |
michael@0 | 42 | |
michael@0 | 43 | num = prefObserver.setCalledNum; |
michael@0 | 44 | cps.setPref(null, "value-global", "foo-private-browsing-global"); |
michael@0 | 45 | do_check_eq(cps.hasPref(null, "value-global"), true); |
michael@0 | 46 | do_check_eq(cps.getPref(null, "value-global"), "foo-private-browsing-global"); |
michael@0 | 47 | do_check_eq(prefObserver.setCalledNum, num + 1); |
michael@0 | 48 | |
michael@0 | 49 | // test removePref |
michael@0 | 50 | num = prefObserver.removedCalledNum; |
michael@0 | 51 | cps.removePref(uri, "value"); |
michael@0 | 52 | do_check_eq(cps.hasPref(uri, "value"), true); |
michael@0 | 53 | // fallback to non private mode value |
michael@0 | 54 | do_check_eq(cps.getPref(uri, "value"), "foo"); |
michael@0 | 55 | do_check_eq(prefObserver.removedCalledNum, num + 1); |
michael@0 | 56 | |
michael@0 | 57 | num = prefObserver.removedCalledNum; |
michael@0 | 58 | cps.removePref(null, "value-global"); |
michael@0 | 59 | do_check_eq(cps.hasPref(null, "value-global"), true); |
michael@0 | 60 | // fallback to non private mode value |
michael@0 | 61 | do_check_eq(cps.getPref(null, "value-global"), "foo-global") ; |
michael@0 | 62 | do_check_eq(prefObserver.removedCalledNum, num + 1); |
michael@0 | 63 | |
michael@0 | 64 | // test removeGroupedPrefs |
michael@0 | 65 | cps.setPref(uri, "value", "foo-private-browsing"); |
michael@0 | 66 | cps.removeGroupedPrefs(); |
michael@0 | 67 | do_check_eq(cps.hasPref(uri, "value"), false); |
michael@0 | 68 | do_check_eq(cps.getPref(uri, "value"), undefined); |
michael@0 | 69 | |
michael@0 | 70 | cps.setPref(null, "value-global", "foo-private-browsing-global"); |
michael@0 | 71 | cps.removeGroupedPrefs(); |
michael@0 | 72 | do_check_eq(cps.hasPref(null, "value-global"), true); |
michael@0 | 73 | do_check_eq(cps.getPref(null, "value-global"), "foo-private-browsing-global"); |
michael@0 | 74 | |
michael@0 | 75 | // test removePrefsByName |
michael@0 | 76 | num = prefObserver.removedCalledNum; |
michael@0 | 77 | cps.setPref(uri, "value", "foo-private-browsing"); |
michael@0 | 78 | cps.removePrefsByName("value"); |
michael@0 | 79 | do_check_eq(cps.hasPref(uri, "value"), false); |
michael@0 | 80 | do_check_eq(cps.getPref(uri, "value"), undefined); |
michael@0 | 81 | do_check_true(prefObserver.removedCalledNum > num); |
michael@0 | 82 | |
michael@0 | 83 | num = prefObserver.removedCalledNum; |
michael@0 | 84 | cps.setPref(null, "value-global", "foo-private-browsing"); |
michael@0 | 85 | cps.removePrefsByName("value-global"); |
michael@0 | 86 | do_check_eq(cps.hasPref(null, "value-global"), false); |
michael@0 | 87 | do_check_eq(cps.getPref(null, "value-global"), undefined); |
michael@0 | 88 | do_check_true(prefObserver.removedCalledNum > num); |
michael@0 | 89 | |
michael@0 | 90 | // test getPrefs |
michael@0 | 91 | cps.setPref(uri, "value", "foo-private-browsing"); |
michael@0 | 92 | do_check_eq(cps.getPrefs(uri).getProperty("value"), "foo-private-browsing"); |
michael@0 | 93 | |
michael@0 | 94 | cps.setPref(null, "value-global", "foo-private-browsing-global"); |
michael@0 | 95 | do_check_eq(cps.getPrefs(null).getProperty("value-global"), "foo-private-browsing-global"); |
michael@0 | 96 | |
michael@0 | 97 | // test getPrefsByName |
michael@0 | 98 | do_check_eq(cps.getPrefsByName("value").getProperty(group), "foo-private-browsing"); |
michael@0 | 99 | do_check_eq(cps.getPrefsByName("value-global").getProperty(null), "foo-private-browsing-global"); |
michael@0 | 100 | |
michael@0 | 101 | cps.removeObserver("value", prefObserver); |
michael@0 | 102 | cps.removeObserver("value-global", prefObserver); |
michael@0 | 103 | } |