commit bc69ef737f2549be242bc6d64e075b25a22517cc
parent c5279abf3b4a56aa9ab1d0a6e5f38e242333684a
Author: Jan Varga <Jan.Varga@gmail.com>
Date: Sat, 29 Nov 2025 07:53:00 +0000
Bug 1988590 - QM: Add a way to simulate older initial origin access times; r=dom-storage-reviewers,jari
Add support for simulating older initial access times when creating new origins
in temporary storage. This allows tests to exercise eviction and
recency-based cleanup logic.
The behavior is controlled via the pref
dom.quotaManager.temporaryStorage.initialOriginAccessTimeOffsetSec:
- 0 disables the behavior (default).
- Positive values subtract the given number of seconds from the current time.
This is intended for testing only and must not be enabled in production.
Testing: This testing only feature is exercised in a new xpcshell test
(test_temporaryStorageCleanup.js) added in a follow-up patch for this bug.
Differential Revision: https://phabricator.services.mozilla.com/D267042
Diffstat:
2 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/dom/quota/ActorsParent.cpp b/dom/quota/ActorsParent.cpp
@@ -6500,7 +6500,33 @@ QuotaManager::EnsureTemporaryOriginIsInitializedInternal(
return std::pair(std::move(directory), false);
}
- const int64_t timestamp = PR_Now();
+ // We apply the offset only here when setting the initial access time for
+ // a new origin. In theory PersistOp::DoDirectoryWork could also honor this
+ // pref, but since the pref is intended for testing only, we do it only
+ // here for now for simplicity.
+ const int64_t timestamp = []() {
+ const int64_t now = PR_Now();
+ const uint32_t offsetSec = StaticPrefs::
+ dom_quotaManager_temporaryStorage_initialOriginAccessTimeOffsetSec();
+
+ if (offsetSec > 0) {
+ CheckedInt<int64_t> ts(now);
+
+ ts -= CheckedInt<int64_t>(offsetSec) * PR_USEC_PER_SEC;
+ if (!ts.isValid()) {
+ // Offset too large (underflow), use current time as if there was no
+ // offset.
+
+ QM_WARNING("Initial origin access time offset too large!");
+
+ return now;
+ }
+
+ return ts.value();
+ }
+
+ return now;
+ }();
FullOriginMetadata fullOriginMetadata{
aOriginMetadata,
diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml
@@ -4007,6 +4007,24 @@
value: -1
mirror: always
+# Controls the time offset (in seconds) applied when initializing the access
+# time for a newly created origin in temporary storage. When set to a positive
+# value, the stored access time is artificially adjusted by subtracting the
+# specified number of seconds from the current time. This can be used to
+# simulate older origins for testing eviction and recency-based cleanup
+# behavior.
+#
+# If the offset value is too large and would cause integer underflow, the
+# current time is used as it would have been used normally.
+#
+# A value of 0 disables this behavior (default).
+#
+# This setting is for testing only and must not be enabled in production.
+- name: dom.quotaManager.temporaryStorage.initialOriginAccessTimeOffsetSec
+ type: RelaxedAtomicUint32
+ value: 0
+ mirror: always
+
# Controls whether the quota manager updates the last access time for origins
# in temporary storage. When enabled, the access time is updated only when an
# origin is accessed by a quota client for the first time during a session or