Bug 1796551 [wpt PR 36570] - WebKit export of https://bugs.webkit.org/show_bug.cgi...
[gecko.git] / toolkit / profile / xpcshell / test_clean.js
blob3132d5457dcdb2336bda30bf0bef7df43f92e7ae
1 /* Any copyright is dedicated to the Public Domain.
2    http://creativecommons.org/publicdomain/zero/1.0/ */
4 /*
5  * Tests from a clean state.
6  * Then does some testing that creating new profiles and marking them as
7  * selected works.
8  */
10 add_task(async () => {
11   let service = getProfileService();
13   let target = gDataHome.clone();
14   target.append("profiles.ini");
15   Assert.ok(!target.exists(), "profiles.ini should not exist yet.");
16   target.leafName = "installs.ini";
17   Assert.ok(!target.exists(), "installs.ini should not exist yet.");
19   // Create a new profile to use.
20   let newProfile = service.createProfile(null, "dedicated");
21   service.flush();
23   let profileData = readProfilesIni();
25   Assert.equal(
26     profileData.profiles.length,
27     1,
28     "Should have the right number of profiles."
29   );
31   let profile = profileData.profiles[0];
32   Assert.equal(profile.name, "dedicated", "Should have the right name.");
33   Assert.ok(!profile.default, "Should not be marked as the old-style default.");
35   // The new profile hasn't been marked as the default yet!
36   Assert.equal(
37     Object.keys(profileData.installs).length,
38     0,
39     "Should be no defaults for installs yet."
40   );
42   checkProfileService(profileData);
44   Assert.ok(
45     service.startWithLastProfile,
46     "Should be set to start with the last profile."
47   );
48   service.startWithLastProfile = false;
49   Assert.ok(
50     !service.startWithLastProfile,
51     "Should be set to not start with the last profile."
52   );
54   service.defaultProfile = newProfile;
55   service.flush();
57   profileData = readProfilesIni();
59   Assert.equal(
60     profileData.profiles.length,
61     1,
62     "Should have the right number of profiles."
63   );
65   profile = profileData.profiles[0];
66   Assert.equal(profile.name, "dedicated", "Should have the right name.");
67   Assert.ok(!profile.default, "Should not be marked as the old-style default.");
69   let hash = xreDirProvider.getInstallHash();
70   Assert.equal(
71     Object.keys(profileData.installs).length,
72     1,
73     "Should be only one known install."
74   );
75   Assert.equal(
76     profileData.installs[hash].default,
77     profileData.profiles[0].path,
78     "Should have marked the new profile as the default for this install."
79   );
81   checkProfileService(profileData);
83   let otherProfile = service.createProfile(null, "another");
84   service.defaultProfile = otherProfile;
86   service.flush();
88   profileData = readProfilesIni();
90   Assert.equal(
91     profileData.profiles.length,
92     2,
93     "Should have the right number of profiles."
94   );
96   profile = profileData.profiles[0];
97   Assert.equal(profile.name, "another", "Should have the right name.");
98   Assert.ok(!profile.default, "Should not be marked as the old-style default.");
100   profile = profileData.profiles[1];
101   Assert.equal(profile.name, "dedicated", "Should have the right name.");
102   Assert.ok(!profile.default, "Should not be marked as the old-style default.");
104   Assert.equal(
105     Object.keys(profileData.installs).length,
106     1,
107     "Should be only one known install."
108   );
109   Assert.equal(
110     profileData.installs[hash].default,
111     profileData.profiles[0].path,
112     "Should have marked the new profile as the default for this install."
113   );
115   checkProfileService(profileData);
117   newProfile.remove(true);
118   service.flush();
120   profileData = readProfilesIni();
122   Assert.equal(
123     profileData.profiles.length,
124     1,
125     "Should have the right number of profiles."
126   );
128   profile = profileData.profiles[0];
129   Assert.equal(profile.name, "another", "Should have the right name.");
130   Assert.ok(!profile.default, "Should not be marked as the old-style default.");
132   Assert.equal(
133     Object.keys(profileData.installs).length,
134     1,
135     "Should be only one known install."
136   );
137   Assert.equal(
138     profileData.installs[hash].default,
139     profileData.profiles[0].path,
140     "Should have marked the new profile as the default for this install."
141   );
143   checkProfileService(profileData);
145   otherProfile.remove(true);
146   service.flush();
148   profileData = readProfilesIni();
150   Assert.equal(
151     profileData.profiles.length,
152     0,
153     "Should have the right number of profiles."
154   );
156   // We leave a reference to the missing profile to stop us trying to steal the
157   // old-style default profile on next startup.
158   Assert.equal(
159     Object.keys(profileData.installs).length,
160     1,
161     "Should be only one known install."
162   );
164   checkProfileService(profileData);