Bug 1885565 - Part 2: Fix up parameter ordering and kDoc descriptions in NavigationBa...
[gecko.git] / toolkit / profile / xpcshell / test_snatch_environment_default.js
blobd93a0cfc1274ea053792355e4f30b16a112f807c
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 snatch it if it was the
7  * default profile and lock it when we're the default app.
8  */
10 add_task(async () => {
11   gIsDefaultApp = true;
13   let root = makeRandomProfileDir("foo");
14   let local = gDataHomeLocal.clone();
15   local.append("foo");
17   writeCompatibilityIni(root);
19   let profileData = {
20     options: {
21       startWithLastProfile: true,
22     },
23     profiles: [
24       {
25         name: PROFILE_DEFAULT,
26         path: root.leafName,
27         default: true,
28       },
29       {
30         name: "Profile2",
31         path: "Path2",
32       },
33       {
34         name: "Profile3",
35         path: "Path3",
36       },
37     ],
38     // Another install is using the profile but it isn't locked.
39     installs: {
40       otherinstall: {
41         default: root.leafName,
42       },
43     },
44   };
46   writeProfilesIni(profileData);
47   checkProfileService(profileData);
49   Services.env.set("XRE_PROFILE_PATH", root.path);
50   Services.env.set("XRE_PROFILE_LOCAL_PATH", local.path);
52   let { rootDir, localDir, profile, didCreate } = selectStartupProfile();
53   checkStartupReason("restart-claimed-default");
55   Assert.ok(!didCreate, "Should not have created a new profile.");
56   Assert.ok(rootDir.equals(root), "Should have selected the right root dir.");
57   Assert.ok(
58     localDir.equals(local),
59     "Should have selected the right local dir."
60   );
61   Assert.ok(!!profile, "A named profile matches this.");
62   Assert.equal(profile.name, PROFILE_DEFAULT, "The right profile was matched.");
64   let service = getProfileService();
65   Assert.ok(
66     service.defaultProfile === profile,
67     "Should be the default profile."
68   );
69   Assert.ok(
70     service.currentProfile === profile,
71     "Should be the current profile."
72   );
74   profileData = readProfilesIni();
75   Assert.equal(
76     profileData.profiles[0].name,
77     PROFILE_DEFAULT,
78     "Should be the right profile."
79   );
80   Assert.ok(
81     profileData.profiles[0].default,
82     "Should still be the old default profile."
83   );
85   let hash = xreDirProvider.getInstallHash();
86   // The info about the other install will have been removed so it goes through first run on next startup.
87   Assert.equal(
88     Object.keys(profileData.installs).length,
89     1,
90     "Should be one known install."
91   );
92   Assert.equal(
93     profileData.installs[hash].default,
94     root.leafName,
95     "Should have marked the original default profile as the default for this install."
96   );
97   Assert.ok(
98     profileData.installs[hash].locked,
99     "Should have locked as we're the default app."
100   );