Bug 1885602 - Part 5: Implement navigating to the SUMO help topic from the menu heade...
[gecko.git] / toolkit / profile / xpcshell / test_skip_locked_environment.js
blobf98f6dd88f1d1e3141a2a2f6c47f7465f8094c06
1 /* Any copyright is dedicated to the Public Domain.
2    http://creativecommons.org/publicdomain/zero/1.0/ */
4 /*
5  * Tests that the environment variables are used to select a profile and that
6  * on the first run of a dedicated profile build we don't snatch it if it is
7  * locked by another install.
8  */
10 add_task(async () => {
11   let root = makeRandomProfileDir("foo");
12   let local = gDataHomeLocal.clone();
13   local.append("foo");
15   writeCompatibilityIni(root);
17   let profileData = {
18     options: {
19       startWithLastProfile: true,
20     },
21     profiles: [
22       {
23         name: PROFILE_DEFAULT,
24         path: root.leafName,
25         default: true,
26       },
27       {
28         name: "Profile2",
29         path: "Path2",
30       },
31       {
32         name: "Profile3",
33         path: "Path3",
34       },
35     ],
36     // Another install is using the profile and it is locked.
37     installs: {
38       otherinstall: {
39         default: root.leafName,
40         locked: true,
41       },
42     },
43   };
45   writeProfilesIni(profileData);
46   checkProfileService(profileData);
48   Services.env.set("XRE_PROFILE_PATH", root.path);
49   Services.env.set("XRE_PROFILE_LOCAL_PATH", local.path);
51   let { rootDir, localDir, profile, didCreate } = selectStartupProfile();
52   checkStartupReason("restart-skipped-default");
54   // Since there is already a profile with the desired name on dev-edition, a
55   // unique version will be used.
56   let expectedName = AppConstants.MOZ_DEV_EDITION
57     ? `${DEDICATED_NAME}-1`
58     : DEDICATED_NAME;
60   Assert.ok(didCreate, "Should have created a new profile.");
61   Assert.ok(!rootDir.equals(root), "Should have selected the right root dir.");
62   Assert.ok(
63     !localDir.equals(local),
64     "Should have selected the right local dir."
65   );
66   Assert.ok(profile, "A named profile was returned.");
67   Assert.equal(profile.name, expectedName, "The right profile name was used.");
69   let service = getProfileService();
70   Assert.equal(
71     service.defaultProfile,
72     profile,
73     "Should be the default profile."
74   );
75   Assert.equal(
76     service.currentProfile,
77     profile,
78     "Should be the current profile."
79   );
81   profileData = readProfilesIni();
83   Assert.equal(
84     profileData.profiles[0].name,
85     PROFILE_DEFAULT,
86     "Should be the right profile."
87   );
88   Assert.ok(
89     profileData.profiles[0].default,
90     "Should be the old default profile."
91   );
92   Assert.equal(
93     profileData.profiles[0].path,
94     root.leafName,
95     "Should be the correct path."
96   );
97   Assert.equal(
98     profileData.profiles[1].name,
99     expectedName,
100     "Should be the right profile."
101   );
102   Assert.ok(
103     !profileData.profiles[1].default,
104     "Should not be the old default profile."
105   );
107   let hash = xreDirProvider.getInstallHash();
108   Assert.equal(
109     Object.keys(profileData.installs).length,
110     2,
111     "Should be one known install."
112   );
113   Assert.notEqual(
114     profileData.installs[hash].default,
115     root.leafName,
116     "Should have marked the original default profile as the default for this install."
117   );
118   Assert.ok(
119     profileData.installs[hash].locked,
120     "Should have locked as we created the profile for this install."
121   );
122   Assert.equal(
123     profileData.installs.otherinstall.default,
124     root.leafName,
125     "Should have left the other profile as the default for the other install."
126   );
127   Assert.ok(
128     profileData.installs[hash].locked,
129     "Should still be locked to the other install."
130   );