summaryrefslogtreecommitdiffstats
path: root/modules/libpref/test/unit/test_extprefs.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /modules/libpref/test/unit/test_extprefs.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'modules/libpref/test/unit/test_extprefs.js')
-rw-r--r--modules/libpref/test/unit/test_extprefs.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/modules/libpref/test/unit/test_extprefs.js b/modules/libpref/test/unit/test_extprefs.js
new file mode 100644
index 000000000..37f8de167
--- /dev/null
+++ b/modules/libpref/test/unit/test_extprefs.js
@@ -0,0 +1,70 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/ */
+
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+Components.utils.import("resource://gre/modules/Services.jsm");
+
+// The profile directory is already set up in the head_ files.
+
+function arrayenumerator(a)
+{
+ return {
+ i_: 0,
+ QueryInterface: XPCOMUtils.generateQI([Ci.nsISimpleEnumerator]),
+ hasMoreElements: function ae_hasMoreElements() {
+ return this.i_ < a.length;
+ },
+ getNext: function ae_getNext() {
+ return a[this.i_++];
+ }
+ };
+}
+
+function run_test() {
+ var ps = Cc["@mozilla.org/preferences-service;1"].
+ getService(Ci.nsIPrefService).QueryInterface(Ci.nsIPrefBranch);
+
+ var extprefs = [do_get_file("extdata")];
+
+ var extProvider = {
+ QueryInterface: XPCOMUtils.generateQI([Ci.nsIDirectoryServiceProvider,
+ Ci.nsIDirectoryServiceProvider2]),
+ getFile: function ep_getFile() {
+ throw Cr.NS_ERROR_FAILURE;
+ },
+
+ getFiles: function ep_getFiles(key) {
+ if (key != "ExtPrefDL")
+ throw Cr.NS_ERROR_FAILURE;
+
+ return arrayenumerator(extprefs);
+ }
+ };
+
+ let prefFile = do_get_file("data/testPref.js");
+
+ do_check_throws(function() {
+ ps.getBoolPref("testExtPref.bool");
+ }, Cr.NS_ERROR_UNEXPECTED);
+ do_check_throws(function() {
+ ps.getBoolPref("testPref.bool1");
+ }, Cr.NS_ERROR_UNEXPECTED);
+
+ ps.readUserPrefs(prefFile);
+
+ do_check_true(ps.getBoolPref("testPref.bool1"));
+ ps.setBoolPref("testPref.bool1", false);
+ do_check_false(ps.getBoolPref("testPref.bool1"));
+
+ dirSvc.registerProvider(extProvider);
+ Services.obs.notifyObservers(null, "load-extension-defaults", null);
+
+ // The extension default should be available.
+ do_check_true(ps.getBoolPref("testExtPref.bool"));
+
+ // The extension default should not override existing user prefs
+ do_check_false(ps.getBoolPref("testPref.bool2"));
+
+ // The extension default should not modify existing set values
+ do_check_false(ps.getBoolPref("testPref.bool1"));
+}