Backed out 2 changesets (bug 1893434) for causing xpcshell failures on test_bouncetracking_importUserActivationPermissions.js CLOSED TREE

Backed out changeset f85c87baf5db (bug 1893434)
Backed out changeset f2662a25f169 (bug 1893434)
This commit is contained in:
Norisz Fay 2024-04-26 23:06:30 +03:00
Родитель 87291f677e
Коммит 915fa64561
8 изменённых файлов: 4 добавлений и 297 удалений

Просмотреть файл

@ -45,20 +45,6 @@ export let PermissionTestUtils = {
add(subject, ...args) {
return pm.addFromPrincipal(convertToPrincipal(subject), ...args);
},
/**
* Add permission information for a given subject.
* Subject can be a principal, uri or origin string.
*
* This is a variant of add that allows specifying modification time.
*
* @see nsIPermissionManager for documentation
*
* @param {Ci.nsIPrincipal|Ci.nsIURI|string} subject
* @param {*} args
*/
addWithModificationTime(subject, ...args) {
return pm.testAddFromPrincipalByTime(convertToPrincipal(subject), ...args);
},
/**
* Get all custom permissions for a given subject.
* Subject can be a principal, uri or origin string.

Просмотреть файл

@ -14303,13 +14303,6 @@
value: false
mirror: always
# Whether the migration ran to import user activation flags into the BTP user
# activation store. Set to false to trigger a new migration.
- name: privacy.bounceTrackingProtection.hasMigratedUserActivationData
type: bool
value: false
mirror: always
#---------------------------------------------------------------------------
# Prefs starting with "prompts."
#---------------------------------------------------------------------------

Просмотреть файл

@ -21,7 +21,6 @@
#include "nsHashPropertyBag.h"
#include "nsIClearDataService.h"
#include "nsIObserverService.h"
#include "nsIPermissionManager.h"
#include "nsIPrincipal.h"
#include "nsISupports.h"
#include "nsServiceManagerUtils.h"
@ -79,12 +78,6 @@ BounceTrackingProtection::BounceTrackingProtection() {
return;
}
rv = MaybeMigrateUserInteractionPermissions();
if (NS_WARN_IF(NS_FAILED(rv))) {
MOZ_LOG(gBounceTrackingProtectionLog, LogLevel::Error,
("user activation permission migration failed"));
}
// Schedule timer for tracker purging. The timer interval is determined by
// pref.
uint32_t purgeTimerPeriod = StaticPrefs::
@ -232,7 +225,7 @@ nsresult BounceTrackingProtection::RecordStatefulBounces(
}
nsresult BounceTrackingProtection::RecordUserActivation(
nsIPrincipal* aPrincipal, Maybe<PRTime> aActivationTime) {
nsIPrincipal* aPrincipal) {
MOZ_ASSERT(XRE_IsParentProcess());
NS_ENSURE_ARG_POINTER(aPrincipal);
@ -251,12 +244,7 @@ nsresult BounceTrackingProtection::RecordUserActivation(
mStorage->GetOrCreateStateGlobal(aPrincipal);
MOZ_ASSERT(globalState);
// Default to current time if not timestamp is provided.
if (aActivationTime.isNothing()) {
aActivationTime = Some(PR_Now());
}
return globalState->RecordUserActivation(siteHost, aActivationTime.extract());
return globalState->RecordUserActivation(siteHost, PR_Now());
}
NS_IMETHODIMP
@ -438,11 +426,6 @@ BounceTrackingProtection::TestAddUserActivation(
return stateGlobal->RecordUserActivation(host, aActivationTime);
}
NS_IMETHODIMP
BounceTrackingProtection::TestMaybeMigrateUserInteractionPermissions() {
return MaybeMigrateUserInteractionPermissions();
}
RefPtr<BounceTrackingProtection::PurgeBounceTrackersMozPromise>
BounceTrackingProtection::PurgeBounceTrackers() {
// Prevent multiple purge operations from running at the same time.
@ -672,82 +655,6 @@ nsresult BounceTrackingProtection::ClearExpiredUserInteractions(
return NS_OK;
}
nsresult BounceTrackingProtection::MaybeMigrateUserInteractionPermissions() {
// Only run the migration once.
if (StaticPrefs::
privacy_bounceTrackingProtection_hasMigratedUserActivationData()) {
return NS_OK;
}
MOZ_LOG(
gBounceTrackingProtectionLog, LogLevel::Info,
("%s: Importing user activation data from permissions", __FUNCTION__));
// Get all user activation permissions that are within our user activation
// lifetime. We don't care about the rest since they are considered expired
// for BTP.
nsresult rv = NS_OK;
nsCOMPtr<nsIPermissionManager> permManager =
do_GetService(NS_PERMISSIONMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(permManager, NS_ERROR_FAILURE);
// Construct the since time param. The permission manager expects epoch in
// miliseconds.
int64_t nowMS = PR_Now() / PR_USEC_PER_MSEC;
int64_t activationLifetimeMS =
static_cast<int64_t>(
StaticPrefs::
privacy_bounceTrackingProtection_bounceTrackingActivationLifetimeSec()) *
PR_MSEC_PER_SEC;
int64_t since = nowMS - activationLifetimeMS;
// Get all user activation permissions last modified between "since" and now.
nsTArray<RefPtr<nsIPermission>> userActivationPermissions;
rv = permManager->GetAllByTypeSince("storageAccessAPI"_ns, since,
userActivationPermissions);
NS_ENSURE_SUCCESS(rv, rv);
MOZ_LOG(gBounceTrackingProtectionLog, LogLevel::Debug,
("%s: Found %zu (non-expired) user activation permissions",
__FUNCTION__, userActivationPermissions.Length()));
for (const auto& perm : userActivationPermissions) {
nsCOMPtr<nsIPrincipal> permPrincipal;
rv = perm->GetPrincipal(getter_AddRefs(permPrincipal));
if (NS_WARN_IF(NS_FAILED(rv))) {
continue;
}
MOZ_ASSERT(permPrincipal);
// The time the permission was last modified is the time of last user
// activation.
int64_t modificationTimeMS;
rv = perm->GetModificationTime(&modificationTimeMS);
NS_ENSURE_SUCCESS(rv, rv);
MOZ_ASSERT(modificationTimeMS >= since && modificationTimeMS <= nowMS,
"Unexpected permission modification time");
// We may end up with duplicates here since user activation permissions are
// tracked by origin, while BTP tracks user activation by site host.
// RecordUserActivation is responsible for only keeping the most recent user
// activation flag for a given site host and needs to make sure existing
// activation flags are not overwritten by older timestamps.
// RecordUserActivation expects epoch in microseconds.
rv = RecordUserActivation(permPrincipal,
Some(modificationTimeMS * PR_USEC_PER_MSEC));
if (NS_WARN_IF(NS_FAILED(rv))) {
continue;
}
}
// Migration successful, set the pref to indicate that we have migrated.
return mozilla::Preferences::SetBool(
"privacy.bounceTrackingProtection.hasMigratedUserActivationData", true);
}
// ClearDataCallback
NS_IMPL_ISUPPORTS(BounceTrackingProtection::ClearDataCallback,

Просмотреть файл

@ -37,11 +37,8 @@ class BounceTrackingProtection final : public nsIBounceTrackingProtection {
[[nodiscard]] nsresult RecordStatefulBounces(
BounceTrackingState* aBounceTrackingState);
// Stores a user activation flag with a timestamp for the given principal. The
// timestamp defaults to the current time, but can be overridden via
// aActivationTime.
[[nodiscard]] nsresult RecordUserActivation(
nsIPrincipal* aPrincipal, Maybe<PRTime> aActivationTime = Nothing());
// Stores a user activation flag with a timestamp for the given principal.
[[nodiscard]] nsresult RecordUserActivation(nsIPrincipal* aPrincipal);
// Clears expired user interaction flags for the given state global. If
// aStateGlobal == nullptr, clears expired user interaction flags for all
@ -94,11 +91,6 @@ class BounceTrackingProtection final : public nsIBounceTrackingProtection {
nsCString mHost;
RefPtr<ClearDataMozPromise::Private> mPromise;
};
// Imports user activation permissions from permission manager if needed. This
// is important so we don't purge data for sites the user has interacted with
// before the feature was enabled.
[[nodiscard]] nsresult MaybeMigrateUserInteractionPermissions();
};
} // namespace mozilla

Просмотреть файл

@ -42,19 +42,6 @@ nsresult BounceTrackingStateGlobal::RecordUserActivation(
__FUNCTION__, PromiseFlatCString(aSiteHost).get()));
}
// Make sure we don't overwrite an existing, more recent user activation. This
// is only relevant for callers that pass in a timestamp that isn't PR_Now(),
// e.g. when importing user activation data.
Maybe<PRTime> existingUserActivation = mUserActivation.MaybeGet(aSiteHost);
if (existingUserActivation.isSome() &&
existingUserActivation.value() >= aTime) {
MOZ_LOG(gBounceTrackingProtectionLog, LogLevel::Debug,
("%s: Skip: A more recent user activation "
"already exists for %s",
__FUNCTION__, PromiseFlatCString(aSiteHost).get()));
return NS_OK;
}
mUserActivation.InsertOrUpdate(aSiteHost, aTime);
if (aSkipStorage || !ShouldPersistToDisk()) {

Просмотреть файл

@ -47,10 +47,4 @@ interface nsIBounceTrackingProtection : nsISupports {
[implicit_jscontext]
void testAddUserActivation(in jsval originAttributes, in ACString aSiteHost, in PRTime aActivationTime);
// Test helper to trigger user activation import from the permission
// manager. Will only import if the pref
// privacy.bounceTrackingProtection.hasMigratedUserActivationData is set to
// false.
void testMaybeMigrateUserInteractionPermissions();
};

Просмотреть файл

@ -1,150 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
https://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const { PermissionTestUtils } = ChromeUtils.importESModule(
"resource://testing-common/PermissionTestUtils.sys.mjs"
);
const DOMAIN_A = "example.com";
const SUB_DOMAIN_A = "sub." + DOMAIN_A;
const DOMAIN_B = "example.org";
const DOMAIN_C = "example.net";
const ORIGIN_A = "https://" + DOMAIN_A;
const ORIGIN_SUB_A = "https://" + SUB_DOMAIN_A;
const ORIGIN_B = "https://" + DOMAIN_B;
const ORIGIN_C = "https://" + DOMAIN_C;
const ORIGIN_NON_HTTP = "file:///foo/bar.html";
const OA_PBM = { privateBrowsingId: 1 };
const PRINCIPAL_C_PBM = Services.scriptSecurityManager.createContentPrincipal(
Services.io.newURI(ORIGIN_C),
OA_PBM
);
let btp;
let userActivationLifetimeSec = Services.prefs.getIntPref(
"privacy.bounceTrackingProtection.bounceTrackingActivationLifetimeSec"
);
function cleanup() {
btp.clearAll();
Services.perms.removeAll();
Services.prefs.setBoolPref(
"privacy.bounceTrackingProtection.hasMigratedUserActivationData",
false
);
}
add_setup(function () {
// Need a profile to data clearing calls.
do_get_profile();
btp = Cc["@mozilla.org/bounce-tracking-protection;1"].getService(
Ci.nsIBounceTrackingProtection
);
// Clean initial state.
cleanup();
});
add_task(async function test_user_activation_perm_migration() {
// Assert initial test state.
Assert.deepEqual(
btp.testGetUserActivationHosts({}),
[],
"No user activation hosts initially."
);
Assert.equal(
Services.perms.getAllByTypes(["storageAccessAPI"]).length,
0,
"No user activation permissions initially."
);
info("Add test user activation permissions.");
let now = Date.now();
// Non-expired permissions.
PermissionTestUtils.addWithModificationTime(
ORIGIN_A,
"storageAccessAPI",
Services.perms.ALLOW_ACTION,
now
);
PermissionTestUtils.addWithModificationTime(
ORIGIN_C,
"storageAccessAPI",
Services.perms.ALLOW_ACTION,
now - 1000
);
// A non expired permission for a subdomain of DOMAIN_A that has an older modification time.
PermissionTestUtils.addWithModificationTime(
ORIGIN_SUB_A,
"storageAccessAPI",
Services.perms.ALLOW_ACTION,
now - 500
);
// An expired permission.
PermissionTestUtils.addWithModificationTime(
ORIGIN_B,
"storageAccessAPI",
Services.perms.ALLOW_ACTION,
now - userActivationLifetimeSec * 1.2 * 1000
);
// A non-HTTP permission.
PermissionTestUtils.addWithModificationTime(
ORIGIN_NON_HTTP,
"storageAccessAPI",
Services.perms.ALLOW_ACTION,
now
);
// A permission for PBM. Ideally we'd test a more persistent permission type
// here with custom oa, but permission seperation by userContextId isn't
// enabled yet (Bug 1641584).
PermissionTestUtils.addWithModificationTime(
PRINCIPAL_C_PBM,
"storageAccessAPI",
Services.perms.ALLOW_ACTION,
now
);
info("Trigger migration.");
btp.testMaybeMigrateUserInteractionPermissions();
Assert.deepEqual(
btp.testGetUserActivationHosts({}).sort(),
[DOMAIN_A, DOMAIN_C].sort(),
"Should have imported the correct user activation flags."
);
Assert.deepEqual(
btp.testGetUserActivationHosts(OA_PBM).sort(),
[DOMAIN_C],
"Should have imported the correct user activation flags for PBM."
);
info("Reset the BTP user activation store");
btp.clearAll();
info("Trigger migration again.");
btp.testMaybeMigrateUserInteractionPermissions();
Assert.deepEqual(
btp.testGetUserActivationHosts({}),
[],
"Should not have imported the user activation flags again."
);
Assert.deepEqual(
btp.testGetUserActivationHosts(OA_PBM),
[],
"Should not have imported the user activation flags again for PBM."
);
cleanup();
});

Просмотреть файл

@ -8,6 +8,4 @@ prefs = [
["test_bouncetracking_clearExpiredUserActivation.js"]
["test_bouncetracking_importUserActivationPermissions.js"]
["test_bouncetracking_purge.js"]