Bug 1867190 - Add prefs for PHC probablities r=glandium
[gecko.git] / toolkit / profile / xpcshell / test_fix_directory_case.js
blob60e3acbe4e0ebaee7da607add2fcd1d122da43da
1 /* Any copyright is dedicated to the Public Domain.
2    http://creativecommons.org/publicdomain/zero/1.0/ */
4 /**
5  * Tests the case where the user has an default profile set for the legacy
6  * install hash. This should be switched to the new hash and correctly used as
7  * the default.
8  */
10 add_task(async () => {
11   let currentHash = xreDirProvider.getInstallHash();
12   let legacyHash = "F87E39E944FE466E";
14   let defaultProfile = makeRandomProfileDir("default");
15   let dedicatedProfile = makeRandomProfileDir("dedicated");
16   let devProfile = makeRandomProfileDir("devedition");
18   // Make sure we don't steal the old-style default.
19   writeCompatibilityIni(defaultProfile);
21   writeProfilesIni({
22     profiles: [
23       {
24         name: "default",
25         path: defaultProfile.leafName,
26         default: true,
27       },
28       {
29         name: "dedicated",
30         path: dedicatedProfile.leafName,
31       },
32       {
33         name: "dev-edition-default",
34         path: devProfile.leafName,
35       },
36     ],
37     installs: {
38       [legacyHash]: {
39         default: dedicatedProfile.leafName,
40       },
41       otherhash: {
42         default: "foobar",
43       },
44     },
45   });
47   let { profile: selectedProfile, didCreate } = selectStartupProfile(
48     [],
49     false,
50     legacyHash
51   );
52   checkStartupReason("default");
54   let profileData = readProfilesIni();
56   Assert.ok(
57     profileData.options.startWithLastProfile,
58     "Should be set to start with the last profile."
59   );
60   Assert.equal(
61     profileData.profiles.length,
62     3,
63     "Should have the right number of profiles."
64   );
66   let profile = profileData.profiles[0];
67   Assert.equal(profile.name, `dedicated`, "Should have the right name.");
68   Assert.equal(
69     profile.path,
70     dedicatedProfile.leafName,
71     "Should be the expected dedicated profile."
72   );
73   Assert.ok(!profile.default, "Should not be marked as the old-style default.");
75   profile = profileData.profiles[1];
76   Assert.equal(profile.name, "default", "Should have the right name.");
77   Assert.equal(
78     profile.path,
79     defaultProfile.leafName,
80     "Should be the original default profile."
81   );
82   Assert.ok(profile.default, "Should be marked as the old-style default.");
84   Assert.equal(
85     Object.keys(profileData.installs).length,
86     3,
87     "Should be three known installs."
88   );
89   Assert.equal(
90     profileData.installs[currentHash].default,
91     dedicatedProfile.leafName,
92     "Should have switched to the new install hash."
93   );
94   Assert.equal(
95     profileData.installs[legacyHash].default,
96     dedicatedProfile.leafName,
97     "Should have kept the old install hash."
98   );
99   Assert.equal(
100     profileData.installs.otherhash.default,
101     "foobar",
102     "Should have kept the default for the other install."
103   );
105   checkProfileService(profileData);
107   Assert.ok(!didCreate, "Should not have created a new profile.");
108   Assert.ok(
109     selectedProfile.rootDir.equals(dedicatedProfile),
110     "Should be using the right directory."
111   );
112   Assert.equal(selectedProfile.name, "dedicated");