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.
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/licenses/publicdomain/ */
4 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
5 Components.utils.import("resource://gre/modules/Services.jsm");
7 // The profile directory is already set up in the head_ files.
9 function arrayenumerator(a)
10 {
11 return {
12 i_: 0,
13 QueryInterface: XPCOMUtils.generateQI([Ci.nsISimpleEnumerator]),
14 hasMoreElements: function ae_hasMoreElements() {
15 return this.i_ < a.length;
16 },
17 getNext: function ae_getNext() {
18 return a[this.i_++];
19 }
20 };
21 }
23 function run_test() {
24 var ps = Cc["@mozilla.org/preferences-service;1"].
25 getService(Ci.nsIPrefService).QueryInterface(Ci.nsIPrefBranch);
27 var extprefs = [do_get_file("extdata")];
29 var extProvider = {
30 QueryInterface: XPCOMUtils.generateQI([Ci.nsIDirectoryServiceProvider,
31 Ci.nsIDirectoryServiceProvider2]),
32 getFile: function ep_getFile() {
33 throw Cr.NS_ERROR_FAILURE;
34 },
36 getFiles: function ep_getFiles(key) {
37 if (key != "ExtPrefDL")
38 throw Cr.NS_ERROR_FAILURE;
40 return arrayenumerator(extprefs);
41 }
42 };
44 let prefFile = do_get_file("data/testPref.js");
46 do_check_throws(function() {
47 ps.getBoolPref("testExtPref.bool");
48 }, Cr.NS_ERROR_UNEXPECTED);
49 do_check_throws(function() {
50 ps.getBoolPref("testPref.bool1");
51 }, Cr.NS_ERROR_UNEXPECTED);
53 ps.readUserPrefs(prefFile);
55 do_check_true(ps.getBoolPref("testPref.bool1"));
56 ps.setBoolPref("testPref.bool1", false);
57 do_check_false(ps.getBoolPref("testPref.bool1"));
59 dirSvc.registerProvider(extProvider);
60 Services.obs.notifyObservers(null, "load-extension-defaults", null);
62 // The extension default should be available.
63 do_check_true(ps.getBoolPref("testExtPref.bool"));
65 // The extension default should not override existing user prefs
66 do_check_false(ps.getBoolPref("testPref.bool2"));
68 // The extension default should not modify existing set values
69 do_check_false(ps.getBoolPref("testPref.bool1"));
70 }