modules/libpref/test/unit/test_extprefs.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial