summaryrefslogtreecommitdiffstats
path: root/toolkit/profile/xpcshell/test_conflict_profiles.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /toolkit/profile/xpcshell/test_conflict_profiles.js
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--toolkit/profile/xpcshell/test_conflict_profiles.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/toolkit/profile/xpcshell/test_conflict_profiles.js b/toolkit/profile/xpcshell/test_conflict_profiles.js
new file mode 100644
index 0000000000..7028c1d5c2
--- /dev/null
+++ b/toolkit/profile/xpcshell/test_conflict_profiles.js
@@ -0,0 +1,57 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/*
+ * Tests that the profile service refuses to flush when the profiles.ini file
+ * has been modified.
+ */
+
+function check_unchanged(service) {
+ Assert.ok(
+ !service.isListOutdated,
+ "Should not have detected a modification."
+ );
+ try {
+ service.flush();
+ Assert.ok(true, "Should have flushed.");
+ } catch (e) {
+ Assert.ok(false, "Should have succeeded flushing.");
+ }
+}
+
+function check_outdated(service) {
+ Assert.ok(service.isListOutdated, "Should have detected a modification.");
+ try {
+ service.flush();
+ Assert.ok(false, "Should have failed to flush.");
+ } catch (e) {
+ Assert.equal(
+ e.result,
+ Cr.NS_ERROR_DATABASE_CHANGED,
+ "Should have refused to flush."
+ );
+ }
+}
+
+add_task(async () => {
+ let service = getProfileService();
+
+ Assert.ok(!service.isListOutdated, "Should not be modified yet.");
+
+ let profilesini = gDataHome.clone();
+ profilesini.append("profiles.ini");
+
+ Assert.ok(!profilesini.exists(), "File should not exist yet.");
+ profilesini.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0o644);
+ check_outdated(service);
+
+ profilesini.remove(false);
+ check_unchanged(service);
+
+ let oldTime = profilesini.lastModifiedTime;
+ profilesini.lastModifiedTime = oldTime - 10000;
+ check_outdated(service);
+
+ // We can't reset the modification time back to exactly what it was, so I
+ // guess we can't do much more here :(
+});