Commit cf1d4a2e authored by David Van Cleve's avatar David Van Cleve Committed by Chromium LUCI CQ

Trust Tokens: Start capturing Element.setAttribute in the TrustTokenIframe use counter

The TrustTokenIframe use counter is intended to roughly trigger whenever a page will load an iframe that has its 'trusttoken' attribute set. Currently, this doesn't capture calls to Element.setAttribute: see the discussion on blink-reviews-bindings at https://groups.google.com/a/chromium.org/g/blink-reviews-bindings/c/HAEfgM7JkDk/m/JUAZuxI1AQAJ. This makes it undercount use of the feature in the wild. This change adds an additional UseCounter::Count call in html_iframe_element.cc in order to cover this case. 

Change-Id: Id4830632cdc234962762bf601fc902deb6f7ab0b
Test: Adds a browser test covering this case
Bug: 1072163
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2616246Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Commit-Queue: Matt Menke <mmenke@chromium.org>
Auto-Submit: David Van Cleve <davidvc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841640}
parent f86346c4
...@@ -137,4 +137,34 @@ IN_PROC_BROWSER_TEST_F(TrustTokenUseCountersBrowsertest, CountsIframeUse) { ...@@ -137,4 +137,34 @@ IN_PROC_BROWSER_TEST_F(TrustTokenUseCountersBrowsertest, CountsIframeUse) {
blink::mojom::WebFeature::kTrustTokenIframe, 1); blink::mojom::WebFeature::kTrustTokenIframe, 1);
} }
IN_PROC_BROWSER_TEST_F(TrustTokenUseCountersBrowsertest, CountsIframeUseViaSetattribute) {
base::HistogramTester histograms;
GURL start_url(server_.GetURL("/iframe.html"));
EXPECT_TRUE(ui_test_utils::NavigateToURL(browser(), start_url));
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
// It's important to set the trust token arguments before updating src, as
// the latter triggers a load. It's also important to JsReplace the trustToken
// argument here, because iframe.trustToken expects a (properly escaped)
// JSON-encoded string as its value, not a JS object.
EXPECT_TRUE(ExecJs(web_contents,
JsReplace(
R"( const myFrame = document.getElementById("test");
myFrame.setAttribute('trustToken', $1);
myFrame.src = $2;)",
R"({"type": "token-request"})", "/page404.html")));
TestNavigationObserver load_observer(web_contents);
load_observer.Wait();
// Navigate away in order to flush use counters.
EXPECT_TRUE(
ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)));
histograms.ExpectBucketCount("Blink.UseCounter.Features",
blink::mojom::WebFeature::kTrustTokenIframe, 1);
}
} // namespace content } // namespace content
...@@ -247,6 +247,7 @@ void HTMLIFrameElement::ParseAttribute( ...@@ -247,6 +247,7 @@ void HTMLIFrameElement::ParseAttribute(
UpdateRequiredPolicy(); UpdateRequiredPolicy();
} }
} else if (name == html_names::kTrusttokenAttr) { } else if (name == html_names::kTrusttokenAttr) {
UseCounter::Count(GetDocument(), WebFeature::kTrustTokenIframe);
trust_token_ = value; trust_token_ = value;
} else { } else {
// Websites picked up a Chromium article that used this non-specified // Websites picked up a Chromium article that used this non-specified
......
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