Commit 98c0da5e authored by David Bokan's avatar David Bokan Committed by Commit Bot

Add use counter for implicit root scroller

Bug: 798719
Change-Id: Iee4735a21292c8de2d5f638358844a3b279f92d5
Reviewed-on: https://chromium-review.googlesource.com/c/1320193
Commit-Queue: David Bokan <bokan@chromium.org>
Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606463}
parent 212fdaab
......@@ -2074,6 +2074,7 @@ enum WebFeature {
kUpdateWithoutShippingOptionOnShippingAddressChange = 2622,
kUpdateWithoutShippingOptionOnShippingOptionChange = 2623,
kCSSSelectorEmptyWhitespaceOnlyFail = 2624,
kActivatedImplicitRootScroller = 2625,
// Add new features immediately above this line. Don't change assigned
// numbers of any item, and don't reuse removed slots.
// Also, run update_use_counter_feature_enum.py in
......
......@@ -9,6 +9,7 @@
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/frame/browser_controls.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/frame/use_counter.h"
#include "third_party/blink/renderer/core/fullscreen/document_fullscreen.h"
#include "third_party/blink/renderer/core/html/html_frame_owner_element.h"
#include "third_party/blink/renderer/core/layout/layout_box.h"
......@@ -181,10 +182,13 @@ void RootScrollerController::RecomputeEffectiveRootScroller() {
if (!DocumentFullscreen::fullscreenElement(*document_)) {
bool root_scroller_valid =
root_scroller_ && IsValidRootScroller(*root_scroller_);
if (root_scroller_valid)
if (root_scroller_valid) {
new_effective_root_scroller = root_scroller_;
else if (implicit_root_scroller_)
} else if (implicit_root_scroller_) {
new_effective_root_scroller = implicit_root_scroller_;
UseCounter::Count(document_->GetFrame(),
WebFeature::kActivatedImplicitRootScroller);
}
}
if (effective_root_scroller_ == new_effective_root_scroller)
......
......@@ -1944,6 +1944,150 @@ TEST_F(ImplicitRootScrollerSimTest, ImplicitRootScrollerIframe) {
GetDocument().GetRootScrollerController().EffectiveRootScroller());
}
// Tests use counter for implicit root scroller. Ensure it's not counted on a
// page without an implicit root scroller.
TEST_F(ImplicitRootScrollerSimTest, UseCounterNegative) {
WebView().Resize(WebSize(800, 600));
SimRequest request("https://example.com/test.html", "text/html");
LoadURL("https://example.com/test.html");
request.Complete(R"HTML(
<!DOCTYPE html>
<style>
::-webkit-scrollbar {
width: 0px;
height: 0px;
}
body, html {
width: 100%;
height: 100%;
margin: 0px;
}
div {
width: 100%;
height: 100%;
}
</style>
<div id="container"></div>
)HTML");
Compositor().BeginFrame();
Element* container = GetDocument().getElementById("container");
ASSERT_NE(container,
GetDocument().GetRootScrollerController().EffectiveRootScroller());
EXPECT_FALSE(UseCounter::IsCounted(
GetDocument(), WebFeature::kActivatedImplicitRootScroller));
container->style()->setProperty(&GetDocument(), "height", "150%", String(),
ASSERT_NO_EXCEPTION);
Compositor().BeginFrame();
EXPECT_FALSE(UseCounter::IsCounted(
GetDocument(), WebFeature::kActivatedImplicitRootScroller));
}
// Tests use counter for implicit root scroller. Ensure it's counted on a
// page that loads with an implicit root scroller.
TEST_F(ImplicitRootScrollerSimTest, UseCounterPositive) {
WebView().Resize(WebSize(800, 600));
SimRequest request("https://example.com/test.html", "text/html");
LoadURL("https://example.com/test.html");
request.Complete(R"HTML(
<!DOCTYPE html>
<style>
::-webkit-scrollbar {
width: 0px;
height: 0px;
}
body, html {
width: 100%;
height: 100%;
margin: 0px;
}
#container {
width: 100%;
height: 100%;
overflow: auto;
}
#spacer {
height: 2000px;
}
</style>
<div id="container">
<div id="spacer"></div>
</div>
)HTML");
Compositor().BeginFrame();
Element* container = GetDocument().getElementById("container");
ASSERT_EQ(container,
GetDocument().GetRootScrollerController().EffectiveRootScroller());
EXPECT_TRUE(UseCounter::IsCounted(
GetDocument(), WebFeature::kActivatedImplicitRootScroller));
container->style()->setProperty(&GetDocument(), "height", "150%", String(),
ASSERT_NO_EXCEPTION);
Compositor().BeginFrame();
ASSERT_NE(container,
GetDocument().GetRootScrollerController().EffectiveRootScroller());
EXPECT_TRUE(UseCounter::IsCounted(
GetDocument(), WebFeature::kActivatedImplicitRootScroller));
}
// Tests use counter for implicit root scroller. Ensure it's counted on a
// page that loads without an implicit root scroller but later gets one.
TEST_F(ImplicitRootScrollerSimTest, UseCounterPositiveAfterLoad) {
WebView().Resize(WebSize(800, 600));
SimRequest request("https://example.com/test.html", "text/html");
LoadURL("https://example.com/test.html");
request.Complete(R"HTML(
<!DOCTYPE html>
<style>
::-webkit-scrollbar {
width: 0px;
height: 0px;
}
body, html {
width: 100%;
height: 100%;
margin: 0px;
}
#container {
width: 100%;
height: 40%;
overflow: auto;
}
#spacer {
height: 2000px;
}
</style>
<div id="container">
<div id="spacer"></div>
</div>
)HTML");
Compositor().BeginFrame();
Element* container = GetDocument().getElementById("container");
ASSERT_NE(container,
GetDocument().GetRootScrollerController().EffectiveRootScroller());
EXPECT_FALSE(UseCounter::IsCounted(
GetDocument(), WebFeature::kActivatedImplicitRootScroller));
container->style()->setProperty(&GetDocument(), "height", "100%", String(),
ASSERT_NO_EXCEPTION);
Compositor().BeginFrame();
ASSERT_EQ(container,
GetDocument().GetRootScrollerController().EffectiveRootScroller());
EXPECT_TRUE(UseCounter::IsCounted(
GetDocument(), WebFeature::kActivatedImplicitRootScroller));
}
// Tests that if we have multiple valid candidates for implicit promotion, we
// don't promote either.
TEST_F(ImplicitRootScrollerSimTest, DontPromoteWhenMultipleAreValid) {
......
......@@ -20681,6 +20681,7 @@ Called by update_net_error_codes.py.-->
<int value="2622" label="UpdateWithoutShippingOptionOnShippingAddressChange"/>
<int value="2623" label="UpdateWithoutShippingOptionOnShippingOptionChange"/>
<int value="2624" label="CSSSelectorEmptyWhitespaceOnlyFail"/>
<int value="2625" label="ActivatedImplicitRootScroller"/>
</enum>
<enum name="FeaturePolicyFeature">
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