Bug 1885565 - Part 2: Fix up parameter ordering and kDoc descriptions in NavigationBa...
[gecko.git] / toolkit / profile / xpcshell / test_remove_default.js
blobf77f2d87d995c7d81775119f3f5aa068ae051234
1 /* Any copyright is dedicated to the Public Domain.
2    http://creativecommons.org/publicdomain/zero/1.0/ */
4 /**
5  * Tests that calling nsIToolkitProfile.remove on the default profile correctly
6  * removes the profile.
7  */
9 add_task(async () => {
10   let hash = xreDirProvider.getInstallHash();
11   let defaultProfile = makeRandomProfileDir("default");
13   let profilesIni = {
14     profiles: [
15       {
16         name: "default",
17         path: defaultProfile.leafName,
18         default: true,
19       },
20     ],
21     installs: {
22       [hash]: {
23         default: defaultProfile.leafName,
24       },
25     },
26   };
27   writeProfilesIni(profilesIni);
29   let service = getProfileService();
30   checkProfileService(profilesIni);
32   let { profile, didCreate } = selectStartupProfile();
33   Assert.ok(!didCreate, "Should have not created a new profile.");
34   Assert.equal(
35     profile.name,
36     "default",
37     "Should have selected the default profile."
38   );
39   Assert.equal(
40     profile,
41     service.defaultProfile,
42     "Should have selected the default profile."
43   );
45   checkProfileService(profilesIni);
47   // In an actual run of Firefox we wouldn't be able to delete the profile in
48   // use because it would be locked. But we don't actually lock the profile in
49   // tests.
50   profile.remove(false);
52   Assert.ok(!service.defaultProfile, "Should no longer be a default profile.");
53   Assert.equal(
54     profile,
55     service.currentProfile,
56     "Should still be the profile in use."
57   );
59   // These are the modifications that should have been made.
60   profilesIni.profiles.pop();
61   profilesIni.installs[hash].default = "";
63   // The data isn't flushed to disk so don't check the backup here.
64   checkProfileService(profilesIni, false);
66   service.flush();
68   // And that should have flushed to disk correctly.
69   checkProfileService();
71   // checkProfileService doesn't differentiate between a blank default profile
72   // for the install and a missing install.
73   profilesIni = readProfilesIni();
74   Assert.equal(
75     profilesIni.installs[hash].default,
76     "",
77     "Should be a blank default profile."
78   );
79 });