Chromium Code Reviews| Index: third_party/WebKit/Source/core/input/EventHandlerTest.cpp |
| diff --git a/third_party/WebKit/Source/core/input/EventHandlerTest.cpp b/third_party/WebKit/Source/core/input/EventHandlerTest.cpp |
| index fd1d83710e613c6562a55c148db4514b11f6f1ee..2817b385648d5d982f9edf26d5fd9ce45aadfd5a 100644 |
| --- a/third_party/WebKit/Source/core/input/EventHandlerTest.cpp |
| +++ b/third_party/WebKit/Source/core/input/EventHandlerTest.cpp |
| @@ -20,6 +20,7 @@ |
| #include "core/paint/PaintLayerScrollableArea.h" |
| #include "core/testing/DummyPageHolder.h" |
| #include "platform/scroll/MainThreadScrollingReason.h" |
| +#include "platform/scroll/ScrollerSize.h" |
| #include "platform/testing/HistogramTester.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -52,8 +53,8 @@ class EventHandlerTest : public ::testing::Test { |
| FrameSelection& Selection() const { |
| return GetDocument().GetFrame()->Selection(); |
| } |
| - |
| void SetHtmlInnerHTML(const char* html_content); |
| + void Scroll(Element*, const WebGestureDevice); |
| protected: |
| std::unique_ptr<DummyPageHolder> dummy_page_holder_; |
| @@ -62,43 +63,7 @@ class EventHandlerTest : public ::testing::Test { |
| class NonCompositedMainThreadScrollingReasonRecordTest |
| : public EventHandlerTest { |
| protected: |
| - class ScrollBeginEventBuilder : public WebGestureEvent { |
| - public: |
| - ScrollBeginEventBuilder(IntPoint position, |
| - FloatPoint delta, |
| - WebGestureDevice device) |
| - : WebGestureEvent() { |
| - type_ = WebInputEvent::kGestureScrollBegin; |
| - x = global_x = position.X(); |
| - y = global_y = position.Y(); |
| - data.scroll_begin.delta_y_hint = delta.Y(); |
| - source_device = device; |
| - frame_scale_ = 1; |
| - } |
| - }; |
| - |
| - class ScrollUpdateEventBuilder : public WebGestureEvent { |
| - public: |
| - ScrollUpdateEventBuilder() : WebGestureEvent() { |
| - type_ = WebInputEvent::kGestureScrollUpdate; |
| - data.scroll_update.delta_x = 0.0f; |
| - data.scroll_update.delta_y = 1.0f; |
| - data.scroll_update.velocity_x = 0; |
| - data.scroll_update.velocity_y = 1; |
| - frame_scale_ = 1; |
| - } |
| - }; |
| - |
| - class ScrollEndEventBuilder : public WebGestureEvent { |
| - public: |
| - ScrollEndEventBuilder() : WebGestureEvent() { |
| - type_ = WebInputEvent::kGestureScrollEnd; |
| - frame_scale_ = 1; |
| - } |
| - }; |
| - |
| int GetBucketIndex(uint32_t reason); |
| - void Scroll(Element*, const WebGestureDevice); |
| }; |
| class TapEventBuilder : public WebGestureEvent { |
| @@ -146,6 +111,41 @@ class MousePressEventBuilder : public WebMouseEvent { |
| } |
| }; |
| +class ScrollBeginEventBuilder : public WebGestureEvent { |
| + public: |
| + ScrollBeginEventBuilder(IntPoint position, |
| + FloatPoint delta, |
| + WebGestureDevice device) |
| + : WebGestureEvent() { |
| + type_ = WebInputEvent::kGestureScrollBegin; |
| + x = global_x = position.X(); |
| + y = global_y = position.Y(); |
| + data.scroll_begin.delta_y_hint = delta.Y(); |
| + source_device = device; |
| + frame_scale_ = 1; |
| + } |
| +}; |
| + |
| +class ScrollUpdateEventBuilder : public WebGestureEvent { |
| + public: |
| + ScrollUpdateEventBuilder() : WebGestureEvent() { |
| + type_ = WebInputEvent::kGestureScrollUpdate; |
| + data.scroll_update.delta_x = 0.0f; |
| + data.scroll_update.delta_y = 1.0f; |
| + data.scroll_update.velocity_x = 0; |
| + data.scroll_update.velocity_y = 1; |
| + frame_scale_ = 1; |
| + } |
| +}; |
| + |
| +class ScrollEndEventBuilder : public WebGestureEvent { |
| + public: |
| + ScrollEndEventBuilder() : WebGestureEvent() { |
| + type_ = WebInputEvent::kGestureScrollEnd; |
| + frame_scale_ = 1; |
| + } |
| +}; |
| + |
| void EventHandlerTest::SetUp() { |
| dummy_page_holder_ = DummyPageHolder::Create(IntSize(300, 400)); |
| } |
| @@ -166,9 +166,7 @@ int NonCompositedMainThreadScrollingReasonRecordTest::GetBucketIndex( |
| return index; |
| } |
| -void NonCompositedMainThreadScrollingReasonRecordTest::Scroll( |
| - Element* element, |
| - const WebGestureDevice device) { |
| +void EventHandlerTest::Scroll(Element* element, const WebGestureDevice device) { |
| DCHECK(element); |
| DCHECK(element->getBoundingClientRect()); |
| ClientRect* rect = element->getBoundingClientRect(); |
| @@ -581,6 +579,49 @@ TEST_F(EventHandlerTest, dragEndInNewDrag) { |
| // This test passes if it doesn't crash. |
| } |
| +TEST_F(EventHandlerTest, |
| + ScrollerSizeOfMainThreadScrollingHistogramRecordingTest) { |
| + SetHtmlInnerHTML( |
| + "<style>" |
| + " .container { width: 200px; height: 200px; overflow: scroll; }" |
| + " .box { width: 100px; height: 100px; overflow: scroll; }" |
| + " .spacer { height: 1000px;} body { height: 2000px; }" |
| + "</style>" |
| + "<div class='container'>" |
| + " <div id='box' class='box'>" |
| + " <div id='content' class='spacer'></div>" |
| + " </div>" |
| + "</div>"); |
| + |
| + Element* box = GetDocument().getElementById("box"); |
| + HistogramTester histogram_tester; |
| + |
| + // Test wheel scroll on the box. |
| + Scroll(box, kWebGestureDeviceTouchpad); |
| + histogram_tester.ExpectBucketCount("Event.Scroll.ScrollerSize.OnScroll_Wheel", |
| + 10000, 1); |
| + // Only the first scrollable area is recorded. |
| + histogram_tester.ExpectBucketCount("Event.Scroll.ScrollerSize.OnScroll_Wheel", |
| + 40000, 0); |
| + histogram_tester.ExpectTotalCount("Event.Scroll.ScrollerSize.OnScroll_Wheel", |
| + 1); |
| + |
| + // Test touch scroll on the main frame. |
|
bokan
2017/04/18 19:24:39
You're not trying to scroll the main frame here th
yigu
2017/04/19 20:53:05
No.
|
| + Scroll(box, kWebGestureDeviceTouchscreen); |
| + histogram_tester.ExpectBucketCount("Event.Scroll.ScrollerSize.OnScroll_Touch", |
| + 10000, 1); |
| + histogram_tester.ExpectTotalCount("Event.Scroll.ScrollerSize.OnScroll_Touch", |
| + 1); |
| + |
| + // Scrolling root layer doesn't add to count. |
| + Element* body = GetDocument().body(); |
| + Scroll(body, kWebGestureDeviceTouchscreen); |
|
bokan
2017/04/18 19:24:39
In general, this won't work since Scroll() will se
yigu
2017/04/19 20:53:05
In general it may not work. But in the example abo
|
| + histogram_tester.ExpectBucketCount("Event.Scroll.ScrollerSize.OnScroll_Touch", |
| + kMaxScrollerSize, 0); |
| + histogram_tester.ExpectTotalCount("Event.Scroll.ScrollerSize.OnScroll_Touch", |
| + 1); |
| +} |
| + |
| class TooltipCapturingChromeClient : public EmptyChromeClient { |
| public: |
| TooltipCapturingChromeClient() {} |