summaryrefslogtreecommitdiffstats
path: root/toolkit/profile/xpcshell/test_snatch_environment_default.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /toolkit/profile/xpcshell/test_snatch_environment_default.js
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/profile/xpcshell/test_snatch_environment_default.js')
-rw-r--r--toolkit/profile/xpcshell/test_snatch_environment_default.js101
1 files changed, 101 insertions, 0 deletions
diff --git a/toolkit/profile/xpcshell/test_snatch_environment_default.js b/toolkit/profile/xpcshell/test_snatch_environment_default.js
new file mode 100644
index 0000000000..d93a0cfc12
--- /dev/null
+++ b/toolkit/profile/xpcshell/test_snatch_environment_default.js
@@ -0,0 +1,101 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/*
+ * Tests that the environment variables are used to select a profile and that
+ * on the first run of a dedicated profile build we snatch it if it was the
+ * default profile and lock it when we're the default app.
+ */
+
+add_task(async () => {
+ gIsDefaultApp = true;
+
+ let root = makeRandomProfileDir("foo");
+ let local = gDataHomeLocal.clone();
+ local.append("foo");
+
+ writeCompatibilityIni(root);
+
+ let profileData = {
+ options: {
+ startWithLastProfile: true,
+ },
+ profiles: [
+ {
+ name: PROFILE_DEFAULT,
+ path: root.leafName,
+ default: true,
+ },
+ {
+ name: "Profile2",
+ path: "Path2",
+ },
+ {
+ name: "Profile3",
+ path: "Path3",
+ },
+ ],
+ // Another install is using the profile but it isn't locked.
+ installs: {
+ otherinstall: {
+ default: root.leafName,
+ },
+ },
+ };
+
+ writeProfilesIni(profileData);
+ checkProfileService(profileData);
+
+ Services.env.set("XRE_PROFILE_PATH", root.path);
+ Services.env.set("XRE_PROFILE_LOCAL_PATH", local.path);
+
+ let { rootDir, localDir, profile, didCreate } = selectStartupProfile();
+ checkStartupReason("restart-claimed-default");
+
+ Assert.ok(!didCreate, "Should not have created a new profile.");
+ Assert.ok(rootDir.equals(root), "Should have selected the right root dir.");
+ Assert.ok(
+ localDir.equals(local),
+ "Should have selected the right local dir."
+ );
+ Assert.ok(!!profile, "A named profile matches this.");
+ Assert.equal(profile.name, PROFILE_DEFAULT, "The right profile was matched.");
+
+ let service = getProfileService();
+ Assert.ok(
+ service.defaultProfile === profile,
+ "Should be the default profile."
+ );
+ Assert.ok(
+ service.currentProfile === profile,
+ "Should be the current profile."
+ );
+
+ profileData = readProfilesIni();
+ Assert.equal(
+ profileData.profiles[0].name,
+ PROFILE_DEFAULT,
+ "Should be the right profile."
+ );
+ Assert.ok(
+ profileData.profiles[0].default,
+ "Should still be the old default profile."
+ );
+
+ let hash = xreDirProvider.getInstallHash();
+ // The info about the other install will have been removed so it goes through first run on next startup.
+ Assert.equal(
+ Object.keys(profileData.installs).length,
+ 1,
+ "Should be one known install."
+ );
+ Assert.equal(
+ profileData.installs[hash].default,
+ root.leafName,
+ "Should have marked the original default profile as the default for this install."
+ );
+ Assert.ok(
+ profileData.installs[hash].locked,
+ "Should have locked as we're the default app."
+ );
+});