summaryrefslogtreecommitdiffstats
path: root/extensions/pref/autoconfig/test/unit/test_autoconfig.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /extensions/pref/autoconfig/test/unit/test_autoconfig.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'extensions/pref/autoconfig/test/unit/test_autoconfig.js')
-rw-r--r--extensions/pref/autoconfig/test/unit/test_autoconfig.js83
1 files changed, 83 insertions, 0 deletions
diff --git a/extensions/pref/autoconfig/test/unit/test_autoconfig.js b/extensions/pref/autoconfig/test/unit/test_autoconfig.js
new file mode 100644
index 0000000000..60284c4544
--- /dev/null
+++ b/extensions/pref/autoconfig/test/unit/test_autoconfig.js
@@ -0,0 +1,83 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/* eslint no-unsafe-finally: "off"*/
+/* Turning off this rule to allow control flow operations in finally block
+ * http://eslint.org/docs/rules/no-unsafe-finally */
+
+function run_test() {
+ let prefs = Services.prefs.getBranch(null);
+ let defPrefs = Services.prefs.getDefaultBranch(null);
+
+ let greD = Services.dirsvc.get("GreD", Ci.nsIFile);
+ let defaultPrefD = Services.dirsvc.get("PrfDef", Ci.nsIFile);
+ let testDir = do_get_cwd();
+
+ try {
+ let autoConfigJS = testDir.clone();
+ autoConfigJS.append("autoconfig.js");
+ autoConfigJS.copyTo(defaultPrefD, "autoconfig.js");
+
+ // Make sure nsReadConfig is initialized.
+ Cc["@mozilla.org/readconfig;1"].getService(Ci.nsISupports);
+ Services.prefs.resetPrefs();
+
+ let autoConfigCfg = testDir.clone();
+ autoConfigCfg.append("autoconfig-all.cfg");
+ autoConfigCfg.copyTo(greD, "autoconfig.cfg");
+
+ Services.env.set("AUTOCONFIG_TEST_GETENV", "getenv");
+
+ Services.obs.notifyObservers(
+ Services.prefs,
+ "prefservice:before-read-userprefs"
+ );
+
+ ok(prefs.prefHasUserValue("_autoconfig_.test.userpref"));
+ equal("userpref", prefs.getStringPref("_autoconfig_.test.userpref"));
+
+ equal(
+ "defaultpref",
+ defPrefs.getStringPref("_autoconfig_.test.defaultpref")
+ );
+ equal("defaultpref", prefs.getStringPref("_autoconfig_.test.defaultpref"));
+
+ ok(prefs.prefIsLocked("_autoconfig_.test.lockpref"));
+ equal("lockpref", prefs.getStringPref("_autoconfig_.test.lockpref"));
+
+ ok(!prefs.prefIsLocked("_autoconfig_.test.unlockpref"));
+ equal("unlockpref", prefs.getStringPref("_autoconfig_.test.unlockpref"));
+
+ ok(!prefs.prefHasUserValue("_autoconfig_.test.clearpref"));
+
+ equal("getpref", prefs.getStringPref("_autoconfig_.test.getpref"));
+
+ equal("getenv", prefs.getStringPref("_autoconfig_.test.getenv"));
+
+ equal("function", prefs.getStringPref("_autoconfig_.test.displayerror"));
+
+ Services.prefs.resetPrefs();
+ } finally {
+ try {
+ let autoConfigJS = defaultPrefD.clone();
+ autoConfigJS.append("autoconfig.js");
+ autoConfigJS.remove(false);
+ } catch (e) {
+ if (e.result != Cr.NS_ERROR_FILE_NOT_FOUND) {
+ throw e;
+ }
+ }
+
+ try {
+ let autoConfigCfg = greD.clone();
+ autoConfigCfg.append("autoconfig.cfg");
+ autoConfigCfg.remove(false);
+ } catch (e) {
+ if (e.result != Cr.NS_ERROR_FILE_NOT_FOUND) {
+ throw e;
+ }
+ }
+
+ Services.prefs.resetPrefs();
+ }
+}