Bug 1885565 - Part 2: Fix up parameter ordering and kDoc descriptions in NavigationBa...
[gecko.git] / toolkit / profile / xpcshell / test_conflict_profiles.js
blob7028c1d5c23684cf2f8ebef3264ad30d21af000c
1 /* Any copyright is dedicated to the Public Domain.
2    http://creativecommons.org/publicdomain/zero/1.0/ */
4 /*
5  * Tests that the profile service refuses to flush when the profiles.ini file
6  * has been modified.
7  */
9 function check_unchanged(service) {
10   Assert.ok(
11     !service.isListOutdated,
12     "Should not have detected a modification."
13   );
14   try {
15     service.flush();
16     Assert.ok(true, "Should have flushed.");
17   } catch (e) {
18     Assert.ok(false, "Should have succeeded flushing.");
19   }
22 function check_outdated(service) {
23   Assert.ok(service.isListOutdated, "Should have detected a modification.");
24   try {
25     service.flush();
26     Assert.ok(false, "Should have failed to flush.");
27   } catch (e) {
28     Assert.equal(
29       e.result,
30       Cr.NS_ERROR_DATABASE_CHANGED,
31       "Should have refused to flush."
32     );
33   }
36 add_task(async () => {
37   let service = getProfileService();
39   Assert.ok(!service.isListOutdated, "Should not be modified yet.");
41   let profilesini = gDataHome.clone();
42   profilesini.append("profiles.ini");
44   Assert.ok(!profilesini.exists(), "File should not exist yet.");
45   profilesini.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0o644);
46   check_outdated(service);
48   profilesini.remove(false);
49   check_unchanged(service);
51   let oldTime = profilesini.lastModifiedTime;
52   profilesini.lastModifiedTime = oldTime - 10000;
53   check_outdated(service);
55   // We can't reset the modification time back to exactly what it was, so I
56   // guess we can't do much more here :(
57 });