0

Add override feature to runtime enable cross app web Attribution

Reporting

This CL adds a flag which will be used to move the feature out of OT and
ship.

Bug: 1518936
Change-Id: Icf05d16ab5895fefefe4671c33f92c8c03b5eb71
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5202347
Commit-Queue: Nan Lin <linnan@chromium.org>
Reviewed-by: John Delaney <johnidel@chromium.org>
Reviewed-by: Avi Drissman <avi@chromium.org>
Reviewed-by: Ian Vollick <vollick@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1248803}
This commit is contained in:
Nan Lin
2024-01-18 16:13:05 +00:00
committed by Chromium LUCI CQ
parent 377fca81fb
commit df4f86b86f
5 changed files with 117 additions and 9 deletions
content
third_party/blink/renderer/platform

@ -2,10 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <vector>
#include "base/strings/strcat.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "components/attribution_reporting/features.h"
#include "content/browser/fenced_frame/fenced_document_data.h"
#include "content/common/features.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
@ -22,7 +26,6 @@ namespace content {
namespace {
constexpr char kBaseDataDir[] = "content/test/data/attribution_reporting/";
} // namespace
class CrossAppWebAttributionBrowserTestBase : public ContentBrowserTest {
public:
@ -51,6 +54,14 @@ class CrossAppWebAttributionBrowserTestBase : public ContentBrowserTest {
void TearDownOnMainThread() override { url_loader_interceptor_.reset(); }
// Helper function that returns whether the ARA cross app web feature is set
// on the browser-side.
bool CheckBrowserSideCrossAppWebRuntimeFeature() {
RenderFrameHost* rfh = shell()->web_contents()->GetPrimaryMainFrame();
return FencedDocumentData::GetForCurrentDocument(rfh)->features().Has(
network::AttributionReportingRuntimeFeature::kCrossAppWeb);
}
protected:
network::mojom::AttributionReportingEligibility
last_request_attribution_reporting_eligibility_;
@ -67,14 +78,6 @@ class CrossAppWebAttributionEnabledBrowserTest
network::features::kAttributionReportingCrossAppWeb);
}
// Helper function that returns whether the ARA cross app web feature is set
// on the browser-side.
bool CheckBrowserSideCrossAppWebRuntimeFeature() {
RenderFrameHost* rfh = shell()->web_contents()->GetPrimaryMainFrame();
return FencedDocumentData::GetForCurrentDocument(rfh)->features().Has(
network::AttributionReportingRuntimeFeature::kCrossAppWeb);
}
private:
base::test::ScopedFeatureList feature_list_;
};
@ -235,4 +238,84 @@ IN_PROC_BROWSER_TEST_F(CrossAppWebAttributionDisabledBrowserTest,
"attribution-reporting')"));
}
struct OverrideTestCase {
bool conversion_measurement_enabled;
bool attribution_reporting_cross_app_web_enabled;
bool expected;
};
class CrossAppWebAttributionOverrideBrowserTest
: public CrossAppWebAttributionBrowserTestBase,
public ::testing::WithParamInterface<OverrideTestCase> {
public:
CrossAppWebAttributionOverrideBrowserTest() {
std::vector<base::test::FeatureRef> enabled_features;
std::vector<base::test::FeatureRef> disabled_features;
enabled_features.emplace_back(
features::kAttributionReportingCrossAppWebOverride);
if (GetParam().conversion_measurement_enabled) {
enabled_features.emplace_back(
attribution_reporting::features::kConversionMeasurement);
} else {
disabled_features.emplace_back(
attribution_reporting::features::kConversionMeasurement);
}
if (GetParam().attribution_reporting_cross_app_web_enabled) {
enabled_features.emplace_back(
network::features::kAttributionReportingCrossAppWeb);
} else {
disabled_features.emplace_back(
network::features::kAttributionReportingCrossAppWeb);
}
feature_list_.InitWithFeatures(enabled_features, disabled_features);
}
protected:
base::test::ScopedFeatureList feature_list_;
};
INSTANTIATE_TEST_SUITE_P(
All,
CrossAppWebAttributionOverrideBrowserTest,
::testing::Values(
OverrideTestCase{
.conversion_measurement_enabled = true,
.attribution_reporting_cross_app_web_enabled = true,
.expected = true,
},
OverrideTestCase{
.conversion_measurement_enabled = false,
.attribution_reporting_cross_app_web_enabled = true,
.expected = false,
},
OverrideTestCase{
.conversion_measurement_enabled = true,
.attribution_reporting_cross_app_web_enabled = false,
.expected = false,
},
OverrideTestCase{
.conversion_measurement_enabled = false,
.attribution_reporting_cross_app_web_enabled = false,
.expected = false,
}));
IN_PROC_BROWSER_TEST_P(CrossAppWebAttributionOverrideBrowserTest, NoOT) {
// Navigate to a page without an OT token.
ASSERT_TRUE(NavigateToURL(
shell(),
GURL("https://example.test/page_without_cross_app_web_ot.html")));
EXPECT_EQ(GetParam().expected,
EvalJs(shell(),
"document.featurePolicy.features().includes('"
"attribution-reporting')"));
EXPECT_EQ(GetParam().expected, CheckBrowserSideCrossAppWebRuntimeFeature());
}
} // namespace
} // namespace content

@ -382,6 +382,8 @@ void SetRuntimeFeaturesFromChromiumFeatures() {
{"AttributionReportingCrossAppWeb",
raw_ref(features::kPrivacySandboxAdsAPIsOverride),
kSetOnlyIfOverridden},
{"AttributionReportingCrossAppWeb",
raw_ref(features::kAttributionReportingCrossAppWebOverride)},
{"AndroidDownloadableFontsMatching",
raw_ref(features::kAndroidDownloadableFontsMatching)},
#if BUILDFLAG(IS_ANDROID)
@ -706,6 +708,21 @@ void ResolveInvalidConfigurations() {
WebRuntimeFeatures::EnableAttributionReporting(false);
}
if (!base::FeatureList::IsEnabled(
attribution_reporting::features::kConversionMeasurement) ||
!base::FeatureList::IsEnabled(
network::features::kAttributionReportingCrossAppWeb)) {
LOG_IF(WARNING,
WebRuntimeFeatures::IsAttributionReportingCrossAppWebEnabled())
<< "AttributionReportingCrossAppWeb cannot be enabled in this "
"configuration. Use --"
<< switches::kEnableFeatures << "="
<< attribution_reporting::features::kConversionMeasurement.name << ","
<< network::features::kAttributionReportingCrossAppWeb.name
<< " in addition.";
WebRuntimeFeatures::EnableAttributionReportingCrossAppWeb(false);
}
if (!base::FeatureList::IsEnabled(blink::features::kInterestGroupStorage)) {
LOG_IF(WARNING, WebRuntimeFeatures::IsAdInterestGroupAPIEnabled())
<< "AdInterestGroupAPI cannot be enabled in this "

@ -24,6 +24,12 @@ BASE_FEATURE(kAndroidDownloadableFontsMatching,
"AndroidDownloadableFontsMatching",
base::FEATURE_ENABLED_BY_DEFAULT);
// Enables exposure of the Cross App Web Attribution Reporting in the renderer
// without an origin trial token.
BASE_FEATURE(kAttributionReportingCrossAppWebOverride,
"AttributionReportingCrossAppWebOverride",
base::FEATURE_DISABLED_BY_DEFAULT);
// Enables controlling the time to live for pages in the BackForwardCache.
// The time to live is defined by the param 'time_to_live_seconds'; if this
// param is not specified then this feature is ignored and the default is used.

@ -15,6 +15,7 @@ namespace features {
// Please keep features in alphabetical order.
CONTENT_EXPORT BASE_DECLARE_FEATURE(kAllowContentInitiatedDataUrlNavigations);
CONTENT_EXPORT BASE_DECLARE_FEATURE(kAndroidDownloadableFontsMatching);
CONTENT_EXPORT BASE_DECLARE_FEATURE(kAttributionReportingCrossAppWebOverride);
CONTENT_EXPORT BASE_DECLARE_FEATURE(kBackForwardCacheTimeToLiveControl);
BASE_DECLARE_FEATURE(kBeforeUnloadBrowserResponseQueue);
CONTENT_EXPORT BASE_DECLARE_FEATURE(

@ -348,6 +348,7 @@
origin_trial_feature_name: "AttributionReportingCrossAppWeb",
origin_trial_allows_third_party: true,
base_feature: "none",
public: true,
},
{
// This only exists so we can use RuntimeEnabled in the IDL file