Commit a841bb48 authored by Ryan Sturm's avatar Ryan Sturm Committed by Commit Bot

Removing the visual viewport restriction from Nav Predictor

This restriction has limited the data pool the predictor can choose
links from, and may severely limit coverage of the predictor. Instead of
only using links from the visual viewport, links from anywhere on the
page will be used as long as they have a size.

Bug: 1001593
Change-Id: Iea4387d72952e850a02a7f4fdc1818d252daae26
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1797135Reviewed-by: default avatarTarun Bansal <tbansal@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Auto-Submit: Ryan Sturm <ryansturm@chromium.org>
Commit-Queue: Kentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697034}
parent ef9d3934
...@@ -702,7 +702,7 @@ IN_PROC_BROWSER_TEST_F(NavigationPredictorBrowserTest, ...@@ -702,7 +702,7 @@ IN_PROC_BROWSER_TEST_F(NavigationPredictorBrowserTest,
WaitForLayout(); WaitForLayout();
histogram_tester.ExpectTotalCount("AnchorElementMetrics.Visible.RatioArea", histogram_tester.ExpectTotalCount("AnchorElementMetrics.Visible.RatioArea",
1); 2);
EXPECT_TRUE(content::ExecuteScript( EXPECT_TRUE(content::ExecuteScript(
browser()->tab_strip_model()->GetActiveWebContents(), browser()->tab_strip_model()->GetActiveWebContents(),
...@@ -727,7 +727,7 @@ IN_PROC_BROWSER_TEST_F(NavigationPredictorBrowserTest, ...@@ -727,7 +727,7 @@ IN_PROC_BROWSER_TEST_F(NavigationPredictorBrowserTest,
WaitForLayout(); WaitForLayout();
histogram_tester.ExpectTotalCount("AnchorElementMetrics.Visible.RatioArea", histogram_tester.ExpectTotalCount("AnchorElementMetrics.Visible.RatioArea",
1); 2);
EXPECT_TRUE(content::ExecuteScript( EXPECT_TRUE(content::ExecuteScript(
browser()->tab_strip_model()->GetActiveWebContents(), browser()->tab_strip_model()->GetActiveWebContents(),
...@@ -854,9 +854,7 @@ IN_PROC_BROWSER_TEST_F(NavigationPredictorBrowserTest, ...@@ -854,9 +854,7 @@ IN_PROC_BROWSER_TEST_F(NavigationPredictorBrowserTest,
NavigationPredictor::Action::kPrefetch, 1); NavigationPredictor::Action::kPrefetch, 1);
} }
// Tests that the browser only receives anchor elements that are in the // Tests that the browser receives anchors from anywhere on the page.
// viewport, and from anchor elements whose target differ from document URL
// by one digit.
IN_PROC_BROWSER_TEST_F(NavigationPredictorBrowserTest, IN_PROC_BROWSER_TEST_F(NavigationPredictorBrowserTest,
ViewportOnlyAndUrlIncrementByOne) { ViewportOnlyAndUrlIncrementByOne) {
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
...@@ -866,8 +864,7 @@ IN_PROC_BROWSER_TEST_F(NavigationPredictorBrowserTest, ...@@ -866,8 +864,7 @@ IN_PROC_BROWSER_TEST_F(NavigationPredictorBrowserTest,
WaitForLayout(); WaitForLayout();
histogram_tester.ExpectUniqueSample( histogram_tester.ExpectUniqueSample(
"AnchorElementMetrics.Visible.NumberOfAnchorElements", 2, 1); "AnchorElementMetrics.Visible.NumberOfAnchorElements", 3, 1);
// Same document anchor element should be removed after merge.
histogram_tester.ExpectUniqueSample( histogram_tester.ExpectUniqueSample(
"AnchorElementMetrics.Visible.NumberOfAnchorElementsAfterMerge", 2, 1); "AnchorElementMetrics.Visible.NumberOfAnchorElementsAfterMerge", 3, 1);
} }
...@@ -5,6 +5,6 @@ ...@@ -5,6 +5,6 @@
<a id="google" href="https://google.com">Google</a> <a id="google" href="https://google.com">Google</a>
<a id="google2" href="https://google.com">Google2</a> <a id="google2" href="https://google.com">Google2</a>
<a id="imageSameHref" href="https://google.com"><img height="1" width="1"></a> <a id="imageSameHref" href="https://google.com"><img height="1" width="1"></a>
<a id="diffHref" href="https://example.com"></a> <a id="diffHref" href="https://example.com">diff</a>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -283,10 +283,15 @@ void AnchorElementMetrics::MaybeReportViewportMetricsOnLoad( ...@@ -283,10 +283,15 @@ void AnchorElementMetrics::MaybeReportViewportMetricsOnLoad(
if (!anchor_element.Href().ProtocolIsInHTTPFamily()) if (!anchor_element.Href().ProtocolIsInHTTPFamily())
continue; continue;
if (anchor_element.VisibleBoundsInVisualViewport().IsEmpty() && // If the anchor doesn't have a valid frame/root document, skip it.
(!anchor_element.GetDocument().GetFrame() || if (!anchor_element.GetDocument().GetFrame() ||
!GetRootDocument(anchor_element) || !GetRootDocument(anchor_element)) {
!IsUrlIncrementedByOne(anchor_element))) { continue;
}
// Only anchors with width/height should be evaluated.
if (!anchor_element.GetLayoutObject() ||
anchor_element.GetLayoutObject()->AbsoluteBoundingBoxRect().IsEmpty()) {
continue; continue;
} }
......
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