diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /extensions/pref/autoconfig/test/unit/test_autoconfig_snap.js | |
parent | Initial commit. (diff) | |
download | firefox-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_snap.js')
-rw-r--r-- | extensions/pref/autoconfig/test/unit/test_autoconfig_snap.js | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/extensions/pref/autoconfig/test/unit/test_autoconfig_snap.js b/extensions/pref/autoconfig/test/unit/test_autoconfig_snap.js new file mode 100644 index 0000000000..1a58e11cf5 --- /dev/null +++ b/extensions/pref/autoconfig/test/unit/test_autoconfig_snap.js @@ -0,0 +1,77 @@ +/* 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 */ + +const { updateAppInfo } = ChromeUtils.importESModule( + "resource://testing-common/AppInfo.sys.mjs" +); + +function ensureRemove(file) { + try { + file.remove(false); + } catch (e) { + if (e.result != Cr.NS_ERROR_FILE_NOT_FOUND) { + throw e; + } + } +} + +async function run_test() { + let prefs = Services.prefs.getBranch(null); + + let testDir = do_get_cwd(); + let confDir = testDir.clone(); + confDir.append("MozSystemConfigDir"); + Services.env.set("MOZ_SYSTEM_CONFIG_DIR", confDir.path); + Services.env.set("SNAP_INSTANCE_NAME", "xpcshell"); + + updateAppInfo(); + + let sysConfD = Services.dirsvc.get("SysConfD", Ci.nsIFile); + + let defaultPrefDExtra = sysConfD.clone(); + defaultPrefDExtra.append("defaults"); + defaultPrefDExtra.append("pref"); + + await IOUtils.makeDirectory(defaultPrefDExtra.path); + + const kAutoConfigFile = defaultPrefDExtra.clone(); + kAutoConfigFile.append("autoconfig_snap.js"); + const kAutoConfigCfg = sysConfD.clone(); + kAutoConfigCfg.append("autoconfig-snap.cfg"); + + let autoConfigJS = testDir.clone(); + autoConfigJS.append(kAutoConfigFile.leafName); + + let autoConfigCfg = testDir.clone(); + autoConfigCfg.append(kAutoConfigCfg.leafName); + + try { + autoConfigJS.copyTo(kAutoConfigFile.parent, kAutoConfigFile.leafName); + autoConfigCfg.copyTo(kAutoConfigCfg.parent, kAutoConfigCfg.leafName); + + // Make sure nsReadConfig is initialized. + Cc["@mozilla.org/readconfig;1"].getService(Ci.nsISupports); + Services.prefs.resetPrefs(); + + Services.obs.notifyObservers( + Services.prefs, + "prefservice:before-read-userprefs" + ); + + ok(prefs.prefHasUserValue("_autoconfig_.test.userpref-snap")); + equal( + "userpref-snap", + prefs.getStringPref("_autoconfig_.test.userpref-snap") + ); + + Services.prefs.resetPrefs(); + } finally { + ensureRemove(kAutoConfigFile); + ensureRemove(kAutoConfigCfg); + Services.prefs.resetPrefs(); + } +} |