Commit d895def7 authored by David Bokan's avatar David Bokan Committed by Chromium LUCI CQ

Fix counter for ForceLoadAtTop DocumentPolicy

ForceLoadAtTop is a DocumentPolicy header but was originally shipped as
an OriginTrial since it was needed before DocumentPolicy was shipped.
The OriginTrial worked by enabling a RuntimeEnabledFeature; the use
counter was based on this REF.

However, once DocumentPolicy shipped, the OriginTrial was abandoned and
ForceLoadAtTop was enabled using a DocumentPolicy header. However, we
forgot to update the UseCounter code to use the DocumentPolicy header.

This CL updates the UseCounter to be based on the DocumentPolicy header.
A followup CL will remove the REF.

Bug: 1165340
Change-Id: I163f20620e1b63ef46cb202a1511059468e43abb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2622323Reviewed-by: default avatarNick Burris <nburris@chromium.org>
Commit-Queue: David Bokan <bokan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842815}
parent 92844d6e
...@@ -2001,8 +2001,10 @@ void DocumentLoader::RecordUseCountersForCommit() { ...@@ -2001,8 +2001,10 @@ void DocumentLoader::RecordUseCountersForCommit() {
CountUse( CountUse(
WebFeature::kCertificateTransparencyNonCompliantResourceInSubframe); WebFeature::kCertificateTransparencyNonCompliantResourceInSubframe);
} }
if (RuntimeEnabledFeatures::ForceLoadAtTopEnabled(frame_->DomWindow())) if (frame_->DomWindow()->IsFeatureEnabled(
mojom::blink::DocumentPolicyFeature::kForceLoadAtTop)) {
CountUse(WebFeature::kForceLoadAtTop); CountUse(WebFeature::kForceLoadAtTop);
}
if (response_.IsSignedExchangeInnerResponse()) { if (response_.IsSignedExchangeInnerResponse()) {
CountUse(WebFeature::kSignedExchangeInnerResponse); CountUse(WebFeature::kSignedExchangeInnerResponse);
......
...@@ -1620,4 +1620,60 @@ TEST_F(TextFragmentAnchorMetricsTest, LinkOpenedFailedUKM) { ...@@ -1620,4 +1620,60 @@ TEST_F(TextFragmentAnchorMetricsTest, LinkOpenedFailedUKM) {
EXPECT_TRUE(ukm_recorder()->GetEntryMetric(entry, kSourceUkmMetric)); EXPECT_TRUE(ukm_recorder()->GetEntryMetric(entry, kSourceUkmMetric));
} }
// Tests that loading a page that has a ForceLoadAtTop DocumentPolicy invokes
// the UseCounter.
TEST_F(TextFragmentAnchorMetricsTest, ForceLoadAtTopUseCounter) {
SimRequest::Params params;
params.response_http_headers.insert("Document-Policy", "force-load-at-top");
SimRequest request("https://example.com/test.html", "text/html", params);
LoadURL("https://example.com/test.html");
request.Complete(R"HTML(
<!DOCTYPE html>
<p>This is a test page</p>
)HTML");
RunAsyncMatchingTasks();
// Render two frames to handle the async step added by the beforematch event.
Compositor().BeginFrame();
BeginEmptyFrame();
EXPECT_TRUE(GetDocument().IsUseCounted(WebFeature::kForceLoadAtTop));
}
// Tests that loading a page that explicitly disables ForceLoadAtTop
// DocumentPolicy or has no DocumentPolicy doesn't invoke the UseCounter for
// ForceLoadAtTop.
TEST_F(TextFragmentAnchorMetricsTest, NoForceLoadAtTopUseCounter) {
SimRequest::Params params;
params.response_http_headers.insert("Document-Policy",
"no-force-load-at-top");
SimRequest request("https://example.com/test.html", "text/html", params);
LoadURL("https://example.com/test.html");
request.Complete(R"HTML(
<!DOCTYPE html>
<p>This is a test page</p>
)HTML");
RunAsyncMatchingTasks();
// Render two frames to handle the async step added by the beforematch event.
Compositor().BeginFrame();
BeginEmptyFrame();
EXPECT_FALSE(GetDocument().IsUseCounted(WebFeature::kForceLoadAtTop));
// Try without any DocumentPolicy headers.
SimRequest request2("https://example.com/test2.html", "text/html");
LoadURL("https://example.com/test2.html");
request2.Complete(R"HTML(
<!DOCTYPE html>
<p>This is a different test page</p>
)HTML");
RunAsyncMatchingTasks();
Compositor().BeginFrame();
BeginEmptyFrame();
EXPECT_FALSE(GetDocument().IsUseCounted(WebFeature::kForceLoadAtTop));
}
} // namespace blink } // namespace blink
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment