Skip to content

Commit

Permalink
Revert "[Topics] implement browsingTopics for XHR"
Browse files Browse the repository at this point in the history
This reverts commit 08389ed.

Reason for revert: cause build failure:https://ci.chromium.org/ui/p/chromium/builders/ci/Cast%20Audio%20Linux/156481/overview 

Original change's description:
> [Topics] implement browsingTopics for XHR
>
> Add support for XHR (temporarily only, e.g., during OT only) per
> discussion in:
> patcg-individual-drafts/topics#7 (comment)
>
> - Use a separate flag so that we can ship Topics without shipping XHR
> support.
> - Improve/fix the checks in ResolveInvalidConfigurations(): drop the
> check for kPrivacySandboxAdsAPIsOverride, as an inconsistent configuration can occur via
> "--enable-blink-features=TopicsAPI --disable-features=BrowsingTopics"
> as well, and it's insufficient to only scope to when
> kPrivacySandboxAdsAPIsOverride is enabled.
>
> Bug: 1400744
> Change-Id: Id3b31d8c60e69c4f4b6d88ba34107a7ae399e69a
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4103742
> Reviewed-by: John Delaney <[email protected]>
> Commit-Queue: Yao Xiao <[email protected]>
> Reviewed-by: Kouhei Ueno <[email protected]>
> Reviewed-by: Josh Karlin <[email protected]>
> Reviewed-by: Hiroshige Hayashizaki <[email protected]>
> Cr-Commit-Position: refs/heads/main@{#1091402}

Bug: 1400744
Change-Id: I64354a391993c64654984ca4b7ea5fc8971bc5d5
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4156735
Reviewed-by: Tom Lukaszewicz <[email protected]>
Owners-Override: Tom Lukaszewicz <[email protected]>
Reviewed-by: Yao Xiao <[email protected]>
Commit-Queue: Victor Tan <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1091422}
  • Loading branch information
Tanych authored and Chromium LUCI CQ committed Jan 11, 2023
1 parent eb52659 commit 01cb859
Show file tree
Hide file tree
Showing 10 changed files with 8 additions and 372 deletions.
164 changes: 1 addition & 163 deletions chrome/browser/browsing_topics/browsing_topics_service_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ class BrowsingTopicsBrowserTest : public BrowsingTopicsBrowserTestBase {
base::Unretained(this))) {
scoped_feature_list_.InitWithFeatures(
/*enabled_features=*/
{blink::features::kBrowsingTopics, blink::features::kBrowsingTopicsXHR,
{blink::features::kBrowsingTopics,
blink::features::kBrowsingTopicsBypassIPIsPubliclyRoutableCheck,
features::kPrivacySandboxAdsAPIsOverride, blink::features::kPortals},
/*disabled_features=*/{});
Expand Down Expand Up @@ -1620,166 +1620,4 @@ IN_PROC_BROWSER_TEST_F(
EXPECT_EQ(api_usage_contexts[1].hashed_context_domain, HashedDomain(1));
}

IN_PROC_BROWSER_TEST_F(BrowsingTopicsBrowserTest, XhrWithoutTopicsFlagSet) {
GURL main_frame_url =
https_server_.GetURL("b.test", "/browsing_topics/empty_page.html");
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), main_frame_url));

GURL xhr_url = https_server_.GetURL(
"b.test", "/browsing_topics/page_with_custom_topics_header.html");

{
// Send a XHR without the `deprecatedBrowsingTopics` flag. This request
// isn't eligible for topics.
EXPECT_EQ("success", EvalJs(web_contents()->GetPrimaryMainFrame(),
content::JsReplace(R"(
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
domAutomationController.send('success');
}
}
xhr.open('GET', $1);
xhr.send();)",
xhr_url),
content::EXECUTE_SCRIPT_USE_MANUAL_REPLY));

absl::optional<std::string> topics_header_value =
GetTopicsHeaderForRequestPath(
"/browsing_topics/page_with_custom_topics_header.html");

// Expect no topics header as the request did not set
// xhr.deprecatedBrowsingTopics.
EXPECT_FALSE(topics_header_value);
}

{
// Send a XHR with the `deprecatedBrowsingTopics` flag set to false. This
// request isn't eligible for topics.
EXPECT_EQ("success", EvalJs(web_contents()->GetPrimaryMainFrame(),
content::JsReplace(R"(
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
domAutomationController.send('success');
}
}
xhr.open('GET', $1);
xhr.deprecatedBrowsingTopics = false;
xhr.send();)",
xhr_url),
content::EXECUTE_SCRIPT_USE_MANUAL_REPLY));

absl::optional<std::string> topics_header_value =
GetTopicsHeaderForRequestPath(
"/browsing_topics/page_with_custom_topics_header.html");

// Expect no topics header as xhr.deprecatedBrowsingTopics was false.
EXPECT_FALSE(topics_header_value);
}
}

// On an insecure site (i.e. URL with http scheme), test XHR request that
// attempts to set their `deprecatedBrowsingTopics` to true. Expect that the
// request is not eligible for topics.
IN_PROC_BROWSER_TEST_F(
BrowsingTopicsBrowserTest,
XhrCrossOrigin_TopicsNotEligibleDueToInsecureInitiatorContext) {
GURL main_frame_url = embedded_test_server()->GetURL(
"b.test", "/browsing_topics/empty_page.html");
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), main_frame_url));

GURL xhr_url = https_server_.GetURL(
"b.test", "/browsing_topics/page_with_custom_topics_header.html");

EXPECT_EQ("success", EvalJs(web_contents()->GetPrimaryMainFrame(),
content::JsReplace(R"(
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
domAutomationController.send('success');
}
}
xhr.open('GET', $1);
// This will no-op.
xhr.deprecatedBrowsingTopics = true;
xhr.send();)",
xhr_url),
content::EXECUTE_SCRIPT_USE_MANUAL_REPLY));

absl::optional<std::string> topics_header_value =
GetTopicsHeaderForRequestPath(
"/browsing_topics/page_with_custom_topics_header.html");

// Expect no topics header as the request was not eligible for topics due to
// insecure initiator context.
EXPECT_FALSE(topics_header_value);
}

IN_PROC_BROWSER_TEST_F(
BrowsingTopicsBrowserTest,
XhrCrossOrigin_TopicsEligible_SendOneTopic_HasObserveResponse) {
GURL main_frame_url =
https_server_.GetURL("b.test", "/browsing_topics/empty_page.html");
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), main_frame_url));

base::StringPairs replacement;
replacement.emplace_back(std::make_pair("{{STATUS}}", "200 OK"));
replacement.emplace_back(std::make_pair("{{OBSERVE_BROWSING_TOPICS_HEADER}}",
"Observe-Browsing-Topics: ?1"));
replacement.emplace_back(std::make_pair("{{REDIRECT_HEADER}}", ""));

GURL xhr_url = https_server_.GetURL(
"a.test", net::test_server::GetFilePathWithReplacements(
"/browsing_topics/"
"page_with_custom_topics_header.html",
replacement));

EXPECT_EQ("success", EvalJs(web_contents()->GetPrimaryMainFrame(),
content::JsReplace(R"(
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
domAutomationController.send('success');
}
}
xhr.open('GET', $1);
xhr.deprecatedBrowsingTopics = true;
xhr.send();)",
xhr_url),
content::EXECUTE_SCRIPT_USE_MANUAL_REPLY));

absl::optional<std::string> topics_header_value =
GetTopicsHeaderForRequestPath(
"/browsing_topics/page_with_custom_topics_header.html");

EXPECT_TRUE(topics_header_value);
EXPECT_EQ(*topics_header_value, kExpectedHeaderValueForSiteB);

// A new observation should have been recorded in addition to the pre-existing
// one, as the response had the `Observe-Browsing-Topics: ?1` header and the
// request was eligible for topics.
std::vector<ApiUsageContext> api_usage_contexts =
content::GetBrowsingTopicsApiUsage(browsing_topics_site_data_manager());
EXPECT_EQ(api_usage_contexts.size(), 2u);
EXPECT_EQ(
api_usage_contexts[0].hashed_main_frame_host,
HashMainFrameHostForStorage(https_server_.GetURL("b.test", "/").host()));
EXPECT_EQ(api_usage_contexts[0].hashed_context_domain,
GetHashedDomain("a.test"));
EXPECT_EQ(api_usage_contexts[1].hashed_main_frame_host,
HashMainFrameHostForStorage("foo1.com"));
EXPECT_EQ(api_usage_contexts[1].hashed_context_domain, HashedDomain(1));
}

} // namespace browsing_topics
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class PrivacySandboxAdsAPIsAllEnabledBrowserTest
PrivacySandboxAdsAPIsAllEnabledBrowserTest() {
feature_list_.InitWithFeatures(
{blink::features::kPrivacySandboxAdsAPIs,
blink::features::kBrowsingTopics, blink::features::kBrowsingTopicsXHR,
blink::features::kBrowsingTopics,
blink::features::kInterestGroupStorage, blink::features::kFencedFrames,
blink::features::kSharedStorageAPI},
/*disabled_features=*/{});
Expand Down Expand Up @@ -230,66 +230,12 @@ IN_PROC_BROWSER_TEST_F(PrivacySandboxAdsAPIsAllEnabledBrowserTest,
EXPECT_FALSE(last_topics_header());
}

IN_PROC_BROWSER_TEST_F(PrivacySandboxAdsAPIsAllEnabledBrowserTest,
OriginTrialEnabled_TopicsAllowedForXhr) {
EXPECT_TRUE(NavigateToURL(
shell(), GURL("https://example.test/page_with_ads_apis_ot.html")));

EXPECT_EQ("success", EvalJs(shell()->web_contents(),
R"(
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
domAutomationController.send('success');
}
}
xhr.open('GET', 'https://example.test/page_without_ads_apis_ot.html');
xhr.deprecatedBrowsingTopics = true;
xhr.send();)",
EXECUTE_SCRIPT_USE_MANUAL_REPLY));

EXPECT_TRUE(last_request_is_topics_request());
EXPECT_TRUE(last_topics_header());
EXPECT_EQ(last_topics_header().value(),
"1;version=\"chrome.1:1:2\";config_version=\"chrome.1\";model_"
"version=\"2\";taxonomy_version=\"1\"");
}

IN_PROC_BROWSER_TEST_F(PrivacySandboxAdsAPIsAllEnabledBrowserTest,
OriginTrialDisabled_TopicsNotAllowedForXhr) {
// Navigate to a page without an OT token.
EXPECT_TRUE(NavigateToURL(
shell(), GURL("https://example.test/page_without_ads_apis_ot.html")));

EXPECT_EQ("success", EvalJs(shell()->web_contents(),
R"(
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
domAutomationController.send('success');
}
}
xhr.open('GET', 'https://example.test/page_without_ads_apis_ot.html');
xhr.deprecatedBrowsingTopics = true;
xhr.send();)",
EXECUTE_SCRIPT_USE_MANUAL_REPLY));

EXPECT_FALSE(last_request_is_topics_request());
EXPECT_FALSE(last_topics_header());
}

class PrivacySandboxAdsAPIsTopicsDisabledBrowserTest
: public PrivacySandboxAdsAPIsBrowserTestBase {
public:
PrivacySandboxAdsAPIsTopicsDisabledBrowserTest() {
feature_list_.InitWithFeatures(
/*enabled_features=*/{blink::features::kPrivacySandboxAdsAPIs,
blink::features::kBrowsingTopicsXHR},
/*disabled_features=*/{blink::features::kBrowsingTopics});
feature_list_.InitWithFeatures({blink::features::kPrivacySandboxAdsAPIs},
{blink::features::kBrowsingTopics});
}

private:
Expand All @@ -311,113 +257,6 @@ IN_PROC_BROWSER_TEST_F(PrivacySandboxAdsAPIsTopicsDisabledBrowserTest,
EXPECT_EQ(false, EvalJs(shell(), "document.browsingTopics !== undefined"));
}

IN_PROC_BROWSER_TEST_F(PrivacySandboxAdsAPIsTopicsDisabledBrowserTest,
OriginTrialEnabled_TopicsNotAllowedForFetch) {
EXPECT_TRUE(NavigateToURL(
shell(), GURL("https://example.test/page_with_ads_apis_ot.html")));

EXPECT_TRUE(
ExecJs(shell()->web_contents(),
content::JsReplace(
"fetch($1, {browsingTopics: true})",
GURL("https://example.test/page_without_ads_apis_ot.html"))));

EXPECT_FALSE(last_request_is_topics_request());
EXPECT_FALSE(last_topics_header());
}

IN_PROC_BROWSER_TEST_F(PrivacySandboxAdsAPIsTopicsDisabledBrowserTest,
OriginTrialEnabled_TopicsNotAllowedForXhr) {
EXPECT_TRUE(NavigateToURL(
shell(), GURL("https://example.test/page_with_ads_apis_ot.html")));

EXPECT_EQ("success", EvalJs(shell()->web_contents(),
R"(
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
domAutomationController.send('success');
}
}
xhr.open('GET', 'https://example.test/page_without_ads_apis_ot.html');
xhr.deprecatedBrowsingTopics = true;
xhr.send();)",
EXECUTE_SCRIPT_USE_MANUAL_REPLY));

EXPECT_FALSE(last_request_is_topics_request());
EXPECT_FALSE(last_topics_header());
}

class PrivacySandboxAdsAPIsTopicsXHRDisabledBrowserTest
: public PrivacySandboxAdsAPIsBrowserTestBase {
public:
PrivacySandboxAdsAPIsTopicsXHRDisabledBrowserTest() {
feature_list_.InitWithFeatures(
/*enabled_features=*/{blink::features::kPrivacySandboxAdsAPIs,
blink::features::kBrowsingTopics},
/*disabled_features=*/{blink::features::kBrowsingTopicsXHR});
}

private:
base::test::ScopedFeatureList feature_list_;
};

IN_PROC_BROWSER_TEST_F(PrivacySandboxAdsAPIsTopicsXHRDisabledBrowserTest,
OriginTrialEnabled_TopicsFeatureDetected) {
EXPECT_TRUE(NavigateToURL(
shell(), GURL("https://example.test/page_with_ads_apis_ot.html")));

EXPECT_EQ(true, EvalJs(shell(),
"document.featurePolicy.features().includes('"
"browsing-topics')"));

EXPECT_EQ(true, EvalJs(shell(), "document.browsingTopics !== undefined"));
}

IN_PROC_BROWSER_TEST_F(PrivacySandboxAdsAPIsTopicsXHRDisabledBrowserTest,
OriginTrialEnabled_TopicsAllowedForFetch) {
EXPECT_TRUE(NavigateToURL(
shell(), GURL("https://example.test/page_with_ads_apis_ot.html")));

EXPECT_TRUE(
ExecJs(shell()->web_contents(),
content::JsReplace(
"fetch($1, {browsingTopics: true})",
GURL("https://example.test/page_without_ads_apis_ot.html"))));

EXPECT_TRUE(last_request_is_topics_request());
EXPECT_TRUE(last_topics_header());
EXPECT_EQ(last_topics_header().value(),
"1;version=\"chrome.1:1:2\";config_version=\"chrome.1\";model_"
"version=\"2\";taxonomy_version=\"1\"");
}

IN_PROC_BROWSER_TEST_F(PrivacySandboxAdsAPIsTopicsXHRDisabledBrowserTest,
OriginTrialEnabled_TopicsNotAllowedForXhr) {
EXPECT_TRUE(NavigateToURL(
shell(), GURL("https://example.test/page_with_ads_apis_ot.html")));

EXPECT_EQ("success", EvalJs(shell()->web_contents(),
R"(
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
domAutomationController.send('success');
}
}
xhr.open('GET', 'https://example.test/page_without_ads_apis_ot.html');
xhr.deprecatedBrowsingTopics = true;
xhr.send();)",
EXECUTE_SCRIPT_USE_MANUAL_REPLY));

EXPECT_FALSE(last_request_is_topics_request());
EXPECT_FALSE(last_topics_header());
}

class PrivacySandboxAdsAPIsSharedStorageDisabledBrowserTest
: public PrivacySandboxAdsAPIsBrowserTestBase {
public:
Expand Down
Loading

0 comments on commit 01cb859

Please sign in to comment.