Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(463)

Unified Diff: third_party/WebKit/Source/core/input/EventHandlerTest.cpp

Issue 2773893003: Record size of scroller that user scrolls (Closed)
Patch Set: nit Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..a6d2ca486937cc3e85ceb10b12da2c95b47c2ae4 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/ScrollerSizeMetrics.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();
@@ -181,6 +179,7 @@ void NonCompositedMainThreadScrollingReasonRecordTest::Scroll(
GetDocument().GetFrame()->GetEventHandler().HandleGestureEvent(scroll_begin);
GetDocument().GetFrame()->GetEventHandler().HandleGestureEvent(scroll_update);
GetDocument().GetFrame()->GetEventHandler().HandleGestureEvent(scroll_end);
+ ASSERT_GT(scroll_update.DeltaYInRootFrame(), 0);
}
TEST_F(EventHandlerTest, dragSelectionAfterScroll) {
@@ -581,6 +580,51 @@ TEST_F(EventHandlerTest, dragEndInNewDrag) {
// This test passes if it doesn't crash.
}
+TEST_F(EventHandlerTest,
+ ScrollerSizeOfMainThreadScrollingHistogramRecordingTest) {
+ SetHtmlInnerHTML(
+ "<style>"
bokan 2017/04/20 19:27:58 Please add <!DOCTYPE html>
yigu 2017/04/20 20:22:35 Done.
+ " .container { width: 200px; height: 200px; overflow: scroll; }"
bokan 2017/04/20 19:27:58 I think the intent is to have the container scroll
yigu 2017/04/20 20:22:35 I think the container itself doesn't need to be sc
+ " .box { width: 100px; height: 100px; overflow: scroll; }"
+ " .fixed { position: fixed; }"
+ " .spacer { height: 1000px;} body { height: 2000px; }"
bokan 2017/04/20 19:27:58 Place the body style on a new line (I almost misse
yigu 2017/04/20 20:22:35 Done.
+ "</style>"
+ "<div class='container'>"
+ " <div id='box' class='box'>"
+ " <div id='content' class='spacer'></div>"
+ " </div>"
+ "</div>"
+ "<img src='image.png' class='fixed'></img>");
bokan 2017/04/20 19:27:58 Why do you need a image?
yigu 2017/04/20 20:22:35 Without a fix positioned image, the main scroller
+
+ 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",
bokan 2017/04/20 19:27:58 Please also add after this 1) programmatically fu
bokan 2017/04/20 20:07:31 Never mind, ScrollBegin will always hit the top sc
+ 1);
+
+ // Test touch scroll.
+ 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/20 19:27:58 This works but is fragile. The way Scroll() works
yigu 2017/04/20 20:22:35 Done.
+ histogram_tester.ExpectBucketCount("Event.Scroll.ScrollerSize.OnScroll_Touch",
+ kScrollerSizeLargestBucket, 0);
+ histogram_tester.ExpectTotalCount("Event.Scroll.ScrollerSize.OnScroll_Touch",
+ 1);
+}
+
class TooltipCapturingChromeClient : public EmptyChromeClient {
public:
TooltipCapturingChromeClient() {}

Powered by Google App Engine
This is Rietveld 408576698