diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /extensions/pref/autoconfig/test | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'extensions/pref/autoconfig/test')
21 files changed, 595 insertions, 0 deletions
diff --git a/extensions/pref/autoconfig/test/marionette/autoconfig.cfg b/extensions/pref/autoconfig/test/marionette/autoconfig.cfg new file mode 100644 index 0000000000..1e6fde18bf --- /dev/null +++ b/extensions/pref/autoconfig/test/marionette/autoconfig.cfg @@ -0,0 +1,18 @@ +// # don't remove this comment! (the first line is ignored by Mozilla) + +// Verify this one has a user value +pref("_autoconfig_.test.userpref", "userpref"); + +// Verify this one has a default pref +defaultPref("_autoconfig_.test.defaultpref", "defaultpref"); + +// Verify this one is locked +lockPref("_autoconfig_.test.lockpref", "lockpref"); + +lockPref("_autoconfig_.test.unlockpref", "unlockpref"); +// Verify this one is unlocked +unlockPref("_autoconfig_.test.unlockpref"); + +pref("_autoconfig_.test.clearpref", "clearpref"); +// Verify this one has no value +clearPref("_autoconfig_.test.clearpref"); diff --git a/extensions/pref/autoconfig/test/marionette/autoconfig.js b/extensions/pref/autoconfig/test/marionette/autoconfig.js new file mode 100644 index 0000000000..c891c5d108 --- /dev/null +++ b/extensions/pref/autoconfig/test/marionette/autoconfig.js @@ -0,0 +1,5 @@ +/* global pref */ +pref("general.config.sandbox_enabled", true); +pref("general.config.filename", "autoconfig.cfg"); +pref("general.config.vendor", "autoconfig"); +pref("general.config.obscure_value", 0); diff --git a/extensions/pref/autoconfig/test/marionette/manifest.ini b/extensions/pref/autoconfig/test/marionette/manifest.ini new file mode 100644 index 0000000000..c10c20c2ae --- /dev/null +++ b/extensions/pref/autoconfig/test/marionette/manifest.ini @@ -0,0 +1 @@ +[test_autoconfig.py]
diff --git a/extensions/pref/autoconfig/test/marionette/test_autoconfig.py b/extensions/pref/autoconfig/test/marionette/test_autoconfig.py new file mode 100644 index 0000000000..0cdc0feede --- /dev/null +++ b/extensions/pref/autoconfig/test/marionette/test_autoconfig.py @@ -0,0 +1,101 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import os +import shutil + +from marionette_harness import MarionetteTestCase + + +class TestAutoConfig(MarionetteTestCase): + def tearDown(self): + self.marionette.quit(in_app=False, clean=True) + + if hasattr(self, "pref_file"): + os.remove(self.pref_file) + if hasattr(self, "autoconfig_file"): + os.remove(self.autoconfig_file) + + super(TestAutoConfig, self).tearDown() + + def pref_has_user_value(self, pref): + with self.marionette.using_context("chrome"): + return self.marionette.execute_script( + """ + return Services.prefs.prefHasUserValue(arguments[0]); + """, + script_args=(pref,), + ) + + def pref_is_locked(self, pref): + with self.marionette.using_context("chrome"): + return self.marionette.execute_script( + """ + return Services.prefs.prefIsLocked(arguments[0]); + """, + script_args=(pref,), + ) + + def test_autoconfig(self): + with self.marionette.using_context("chrome"): + self.exe_dir = self.marionette.execute_script( + """ + return Services.dirsvc.get("GreD", Ci.nsIFile).path; + """ + ) + + self.marionette.quit() + + test_dir = os.path.dirname(__file__) + self.pref_file = os.path.join(self.exe_dir, "defaults", "pref", "autoconfig.js") + shutil.copyfile(os.path.join(test_dir, "autoconfig.js"), self.pref_file) + self.autoconfig_file = os.path.join(self.exe_dir, "autoconfig.cfg") + shutil.copyfile(os.path.join(test_dir, "autoconfig.cfg"), self.autoconfig_file) + + self.marionette.start_session() + + with self.marionette.using_context("chrome"): + self.assertTrue( + self.pref_has_user_value("_autoconfig_.test.userpref"), + "Pref should have user value", + ) + + self.assertEqual( + self.marionette.get_pref("_autoconfig_.test.userpref"), + "userpref", + "User pref should be set", + ) + + self.assertEqual( + self.marionette.get_pref("_autoconfig_.test.defaultpref", True), + "defaultpref", + "Default pref should be set", + ) + + self.assertTrue( + self.pref_is_locked("_autoconfig_.test.lockpref"), + "Pref should be locked", + ) + + self.assertEqual( + self.marionette.get_pref("_autoconfig_.test.lockpref"), + "lockpref", + "Locked pref should be set", + ) + + self.assertFalse( + self.pref_is_locked("_autoconfig_.test.unlockpref"), + "Pref should be unlocked", + ) + + self.assertEqual( + self.marionette.get_pref("_autoconfig_.test.unlockpref"), + "unlockpref", + "Unlocked pref should be set", + ) + + self.assertFalse( + self.pref_has_user_value("_autoconfig_.test.clearpref"), + "Pref should be cleared", + ) diff --git a/extensions/pref/autoconfig/test/unit/autoconfig-all.cfg b/extensions/pref/autoconfig/test/unit/autoconfig-all.cfg new file mode 100644 index 0000000000..f636c3ec22 --- /dev/null +++ b/extensions/pref/autoconfig/test/unit/autoconfig-all.cfg @@ -0,0 +1,31 @@ +// # don't remove this comment! (the first line is ignored by Mozilla) + +// Verify this one has a user value +pref("_autoconfig_.test.userpref", "userpref"); + +// Verify this one has a default pref +defaultPref("_autoconfig_.test.defaultpref", "defaultpref"); + +// Verify this one is locked +lockPref("_autoconfig_.test.lockpref", "lockpref"); + +lockPref("_autoconfig_.test.unlockpref", "unlockpref"); +// Verify this one is unlocked +unlockPref("_autoconfig_.test.unlockpref"); + +pref("_autoconfig_.test.clearpref", "clearpref"); +// Verify this one has no value +clearPref("_autoconfig_.test.clearpref"); + +// Verify this one is set to the correct value +pref("_autoconfig_.test.getpref.query", "getpref"); +pref("_autoconfig_.test.getpref", getPref("_autoconfig_.test.getpref.query")); + +// Verify this one is set to the correct value +pref("_autoconfig_.test.getenv", getenv("AUTOCONFIG_TEST_GETENV")); + +// Since we can't test displayError directly, verify that it +// exists and is a function +pref("_autoconfig_.test.displayerror", typeof(displayError)); + +// We are not getPrefBranch because it is being removed diff --git a/extensions/pref/autoconfig/test/unit/autoconfig-chromecheck.cfg b/extensions/pref/autoconfig/test/unit/autoconfig-chromecheck.cfg new file mode 100644 index 0000000000..2af6cfc109 --- /dev/null +++ b/extensions/pref/autoconfig/test/unit/autoconfig-chromecheck.cfg @@ -0,0 +1,5 @@ +// # don't remove this comment! (the first line is ignored by Mozilla) + +lockPref("_test.string.typeofComponents", typeof Components); +lockPref("_test.string.typeofChromeUtils", typeof ChromeUtils); +lockPref("_test.string.typeofServices", typeof Services); diff --git a/extensions/pref/autoconfig/test/unit/autoconfig-latin1.cfg b/extensions/pref/autoconfig/test/unit/autoconfig-latin1.cfg new file mode 100644 index 0000000000..6b96c65fd0 --- /dev/null +++ b/extensions/pref/autoconfig/test/unit/autoconfig-latin1.cfg @@ -0,0 +1,6 @@ +// # don't remove this comment! (the first line is ignored by Mozilla) +// © +lockPref("_test.string.ASCII", "ASCII"); +lockPref("_test.string.non-ASCII", "日本語"); +lockPref("_test.string.getPref", getPref("_test.string.non-ASCII")); +lockPref("_test.string.gIsUTF8", String(this.gIsUTF8)); diff --git a/extensions/pref/autoconfig/test/unit/autoconfig-no-sandbox-check.cfg b/extensions/pref/autoconfig/test/unit/autoconfig-no-sandbox-check.cfg new file mode 100644 index 0000000000..a39080562f --- /dev/null +++ b/extensions/pref/autoconfig/test/unit/autoconfig-no-sandbox-check.cfg @@ -0,0 +1,5 @@ +// # don't remove this comment! (the first line is ignored by Mozilla) + +lockPref("_test.typeof_Components", typeof Components); +lockPref("_test.typeof_ChromeUtils", typeof ChromeUtils); +lockPref("_test.typeof_Services", typeof Services); diff --git a/extensions/pref/autoconfig/test/unit/autoconfig-no-sandbox.js b/extensions/pref/autoconfig/test/unit/autoconfig-no-sandbox.js new file mode 100644 index 0000000000..a53b53dfb6 --- /dev/null +++ b/extensions/pref/autoconfig/test/unit/autoconfig-no-sandbox.js @@ -0,0 +1,5 @@ +/* global pref */ +pref("general.config.sandbox_enabled", false); +pref("general.config.filename", "autoconfig.cfg"); +pref("general.config.vendor", "autoconfig"); +pref("general.config.obscure_value", 0); diff --git a/extensions/pref/autoconfig/test/unit/autoconfig-snap.cfg b/extensions/pref/autoconfig/test/unit/autoconfig-snap.cfg new file mode 100644 index 0000000000..c5c67bfbb7 --- /dev/null +++ b/extensions/pref/autoconfig/test/unit/autoconfig-snap.cfg @@ -0,0 +1,4 @@ +// # don't remove this comment! (the first line is ignored by Mozilla) + +// Verify this one has a user value +pref("_autoconfig_.test.userpref-snap", "userpref-snap"); diff --git a/extensions/pref/autoconfig/test/unit/autoconfig-utf8.cfg b/extensions/pref/autoconfig/test/unit/autoconfig-utf8.cfg new file mode 100644 index 0000000000..eec7899420 --- /dev/null +++ b/extensions/pref/autoconfig/test/unit/autoconfig-utf8.cfg @@ -0,0 +1,6 @@ +// # don't remove this comment! (the first line is ignored by Mozilla) + +lockPref("_test.string.ASCII", "UTF-8"); +lockPref("_test.string.non-ASCII", "日本語"); +lockPref("_test.string.getPref", getPref("_test.string.non-ASCII")); +lockPref("_test.string.gIsUTF8", String(this.gIsUTF8)); diff --git a/extensions/pref/autoconfig/test/unit/autoconfig.js b/extensions/pref/autoconfig/test/unit/autoconfig.js new file mode 100644 index 0000000000..c891c5d108 --- /dev/null +++ b/extensions/pref/autoconfig/test/unit/autoconfig.js @@ -0,0 +1,5 @@ +/* global pref */ +pref("general.config.sandbox_enabled", true); +pref("general.config.filename", "autoconfig.cfg"); +pref("general.config.vendor", "autoconfig"); +pref("general.config.obscure_value", 0); diff --git a/extensions/pref/autoconfig/test/unit/autoconfig_snap.js b/extensions/pref/autoconfig/test/unit/autoconfig_snap.js new file mode 100644 index 0000000000..bfa1df4859 --- /dev/null +++ b/extensions/pref/autoconfig/test/unit/autoconfig_snap.js @@ -0,0 +1,5 @@ +/* global pref */ +pref("general.config.sandbox_enabled", true); +pref("general.config.filename", "autoconfig-snap.cfg"); +pref("general.config.vendor", "autoconfig-snap"); +pref("general.config.obscure_value", 0); 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(); + } +} diff --git a/extensions/pref/autoconfig/test/unit/test_autoconfig_custom_path.js b/extensions/pref/autoconfig/test/unit/test_autoconfig_custom_path.js new file mode 100644 index 0000000000..abfa8881b9 --- /dev/null +++ b/extensions/pref/autoconfig/test/unit/test_autoconfig_custom_path.js @@ -0,0 +1,22 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +const { updateAppInfo } = ChromeUtils.importESModule( + "resource://testing-common/AppInfo.sys.mjs" +); + +function run_test() { + let testDirName = do_get_cwd().clone(); + Services.env.set("MOZ_SYSTEM_CONFIG_DIR", testDirName.path); + + updateAppInfo(); + + try { + Services.dirsvc.undefine("SysConfD"); + } catch (e) {} + let customSysConfD = Services.dirsvc.get("SysConfD", Ci.nsIFile); + let parent = customSysConfD.parent; + let child = customSysConfD.leafName; + notEqual("/etc", parent.path, "SysConfD is not in /etc"); + equal("xpcshell", child, "SysConfD is xpcshell"); +} diff --git a/extensions/pref/autoconfig/test/unit/test_autoconfig_default_path.js b/extensions/pref/autoconfig/test/unit/test_autoconfig_default_path.js new file mode 100644 index 0000000000..20d3801ab1 --- /dev/null +++ b/extensions/pref/autoconfig/test/unit/test_autoconfig_default_path.js @@ -0,0 +1,16 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +const { updateAppInfo } = ChromeUtils.importESModule( + "resource://testing-common/AppInfo.sys.mjs" +); + +function run_test() { + updateAppInfo(); + + try { + Services.dirsvc.undefine("SysConfD"); + } catch (e) {} + let defaultSysConfD = Services.dirsvc.get("SysConfD", Ci.nsIFile); + equal("/etc/xpcshell", defaultSysConfD.path, "SysConfD is in /etc"); +} diff --git a/extensions/pref/autoconfig/test/unit/test_autoconfig_no_sandbox.js b/extensions/pref/autoconfig/test/unit/test_autoconfig_no_sandbox.js new file mode 100644 index 0000000000..7553432bc0 --- /dev/null +++ b/extensions/pref/autoconfig/test/unit/test_autoconfig_no_sandbox.js @@ -0,0 +1,59 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/* eslint no-unsafe-finally: "off"*/ + +function run_test() { + let prefs = Services.prefs.getBranch(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-no-sandbox.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-no-sandbox-check.cfg"); + autoConfigCfg.copyTo(greD, "autoconfig.cfg"); + + Services.obs.notifyObservers( + Services.prefs, + "prefservice:before-read-userprefs" + ); + + equal("object", prefs.getStringPref("_test.typeof_Components")); + equal("object", prefs.getStringPref("_test.typeof_ChromeUtils")); + equal("object", prefs.getStringPref("_test.typeof_Services")); + + 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(); + } +} diff --git a/extensions/pref/autoconfig/test/unit/test_autoconfig_nonascii.js b/extensions/pref/autoconfig/test/unit/test_autoconfig_nonascii.js new file mode 100644 index 0000000000..e535469360 --- /dev/null +++ b/extensions/pref/autoconfig/test/unit/test_autoconfig_nonascii.js @@ -0,0 +1,110 @@ +/* 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 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(); + + var tests = [ + { + filename: "autoconfig-utf8.cfg", + prefs: { + "_test.string.ASCII": "UTF-8", + "_test.string.non-ASCII": "日本語", + "_test.string.getPref": "日本語", + "_test.string.gIsUTF8": "true", + }, + }, + { + filename: "autoconfig-latin1.cfg", + prefs: { + "_test.string.ASCII": "ASCII", + "_test.string.non-ASCII": "日本語", + "_test.string.getPref": "日本語", + "_test.string.gIsUTF8": "false", + }, + }, + { + filename: "autoconfig-chromecheck.cfg", + prefs: { + "_test.string.typeofComponents": "undefined", + "_test.string.typeofChromeUtils": "undefined", + "_test.string.typeofServices": "undefined", + }, + }, + ]; + + function testAutoConfig(test) { + // Make sure pref values are unset. + for (let prefName in test.prefs) { + Assert.equal( + Ci.nsIPrefBranch.PREF_INVALID, + Services.prefs.getPrefType(prefName) + ); + } + + let autoConfigCfg = testDir.clone(); + autoConfigCfg.append(test.filename); + autoConfigCfg.copyTo(greD, "autoconfig.cfg"); + + Services.obs.notifyObservers( + Services.prefs, + "prefservice:before-read-userprefs" + ); + + for (let prefName in test.prefs) { + Assert.equal( + test.prefs[prefName], + Services.prefs.getStringPref(prefName) + ); + } + + Services.prefs.resetPrefs(); + // Make sure pref values are reset. + for (let prefName in test.prefs) { + Assert.equal( + Ci.nsIPrefBranch.PREF_INVALID, + Services.prefs.getPrefType(prefName) + ); + } + } + + tests.forEach(testAutoConfig); + } 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(); + } +} 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(); + } +} diff --git a/extensions/pref/autoconfig/test/unit/xpcshell.ini b/extensions/pref/autoconfig/test/unit/xpcshell.ini new file mode 100644 index 0000000000..fd09da01af --- /dev/null +++ b/extensions/pref/autoconfig/test/unit/xpcshell.ini @@ -0,0 +1,23 @@ +[DEFAULT] +head = +skip-if = + toolkit == 'android' + os == 'win' && msix # Does not work in MSIX builds. +support-files = + autoconfig-all.cfg + autoconfig-latin1.cfg + autoconfig-utf8.cfg + autoconfig-chromecheck.cfg + autoconfig-no-sandbox-check.cfg + autoconfig.js + autoconfig-no-sandbox.js + +[test_autoconfig.js] +[test_autoconfig_nonascii.js] +run-sequentially = very high failure rate in parallel +[test_autoconfig_no_sandbox.js] +run-sequentially = very high failure rate in parallel +[test_autoconfig_default_path.js] +run-if = os == 'linux' +[test_autoconfig_custom_path.js] +run-if = os == 'linux' diff --git a/extensions/pref/autoconfig/test/unit/xpcshell_snap.ini b/extensions/pref/autoconfig/test/unit/xpcshell_snap.ini new file mode 100644 index 0000000000..ff24d46646 --- /dev/null +++ b/extensions/pref/autoconfig/test/unit/xpcshell_snap.ini @@ -0,0 +1,8 @@ +[DEFAULT] +head = +skip-if = os != 'linux' + +[test_autoconfig_snap.js] +support-files = + autoconfig_snap.js + autoconfig-snap.cfg |