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

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

Issue 2773593005: Move logic of recording main thread scrolling reasons from cc to blink::ScrollManager (Closed)
Patch Set: Add unit tests 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 2161408f393ec7d446dfdfd76ba156d7e96eecda..5923ef873be729ef7758889399fc79cd1642b74c 100644
--- a/third_party/WebKit/Source/core/input/EventHandlerTest.cpp
+++ b/third_party/WebKit/Source/core/input/EventHandlerTest.cpp
@@ -16,6 +16,7 @@
#include "core/page/AutoscrollController.h"
#include "core/page/Page.h"
#include "core/testing/DummyPageHolder.h"
+#include "platform/testing/HistogramTester.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace blink {
@@ -79,6 +80,29 @@ class MousePressEventBuilder : public WebMouseEvent {
}
};
+class ScrollBeginEventBuilder : public WebGestureEvent {
+ public:
+ ScrollBeginEventBuilder(IntPoint position,
+ FloatPoint delta,
+ WebGestureDevice device)
+ : WebGestureEvent() {
+ m_type = WebInputEvent::GestureScrollBegin;
+ x = globalX = position.x();
+ y = globalY = position.y();
+ data.scrollBegin.deltaYHint = delta.y();
+ sourceDevice = device;
+ m_frameScale = 1;
+ }
+};
+
+class ScrollEndEventBuilder : public WebGestureEvent {
+ public:
+ ScrollEndEventBuilder() : WebGestureEvent() {
+ m_type = WebInputEvent::GestureScrollEnd;
+ m_frameScale = 1;
+ }
+};
+
void EventHandlerTest::SetUp() {
m_dummyPageHolder = DummyPageHolder::create(IntSize(300, 400));
}
@@ -461,6 +485,114 @@ TEST_F(EventHandlerTest, dragEndInNewDrag) {
// This test passes if it doesn't crash.
}
+TEST_F(EventHandlerTest, NonCompositedMainThreadScrollingReasonTest) {
+ setHtmlInnerHTML(
+ "<style>.box { overflow:scroll; width: 100px; height: 100px; }"
+ " .translucent { opacity: 0.5; }"
+ " .spacer { height: 1000px; }"
+ " .composited { will-change: transform; }"
+ " .hidden { overflow: hidden; }"
+ "</style>"
+ "<div id='box' class='translucent box'><div class='spacer'></div></div>"
+ "<div class='composited translucent box'>"
+ " <div class='spacer'></div>"
+ "</div>");
+
+ page().settings().setAcceleratedCompositingEnabled(true);
+ document().view()->setParentVisible(true);
+ document().view()->setSelfVisible(true);
+ document().view()->updateAllLifecyclePhases();
+
+ HistogramTester histogramTester;
+
+ // Test touch scroll.
+ ScrollBeginEventBuilder touchScrollBegin(
+ IntPoint(50, 50), FloatPoint(0.f, 1.f), WebGestureDeviceTouchscreen);
+ ScrollEndEventBuilder touchScrollEnd;
+ document().frame()->eventHandler().handleGestureEvent(touchScrollBegin);
+ document().frame()->eventHandler().handleGestureEvent(touchScrollEnd);
+ histogramTester.expectBucketCount("Renderer4.MainThreadGestureScrollReason",
+ 17, 1);
+
+ document().frame()->eventHandler().handleGestureEvent(touchScrollBegin);
+ document().frame()->eventHandler().handleGestureEvent(touchScrollEnd);
+ histogramTester.expectBucketCount("Renderer4.MainThreadGestureScrollReason",
+ 17, 2);
+
+ // Test wheel scroll.
+ ScrollBeginEventBuilder wheelScrollBegin(
+ IntPoint(50, 50), FloatPoint(0.f, 1.f), WebGestureDeviceTouchpad);
+ ScrollEndEventBuilder wheelScrollEnd;
+ document().frame()->eventHandler().handleGestureEvent(wheelScrollBegin);
+ document().frame()->eventHandler().handleGestureEvent(wheelScrollEnd);
+ histogramTester.expectBucketCount("Renderer4.MainThreadWheelScrollReason", 17,
+ 1);
+ histogramTester.expectBucketCount("Renderer4.MainThreadWheelScrollReason", 19,
+ 1);
+ histogramTester.expectTotalCount("Renderer4.MainThreadWheelScrollReason", 2);
+
+ Element* box = document().getElementById("box");
+ box->setAttribute("class", "hidden");
bokan 2017/04/07 17:39:03 This is testing my request for non-scrollable area
yigu 2017/04/07 19:26:27 Done.
+ document().view()->updateAllLifecyclePhases();
+ document().frame()->eventHandler().handleGestureEvent(wheelScrollBegin);
+ document().frame()->eventHandler().handleGestureEvent(wheelScrollEnd);
+ histogramTester.expectTotalCount("Renderer4.MainThreadWheelScrollReason", 2);
+
+ wheelScrollBegin.y = wheelScrollBegin.globalY = 150;
+ document().frame()->eventHandler().handleGestureEvent(wheelScrollBegin);
+ document().frame()->eventHandler().handleGestureEvent(wheelScrollEnd);
+ histogramTester.expectBucketCount("Renderer4.MainThreadWheelScrollReason", 17,
bokan 2017/04/07 17:39:03 Please use names for the bucket constants here. Yo
yigu 2017/04/07 19:26:27 Done.
+ 1);
+}
+
+TEST_F(EventHandlerTest,
+ NonCompositedMainThreadScrollingReasonWithNestedScrollersTest) {
+ setHtmlInnerHTML(
+ "<style>.container { overflow:scroll; width: 200px; height: 200px; }"
bokan 2017/04/07 17:39:03 nit: .container should be on new line
yigu 2017/04/07 19:26:27 Done.
+ " .box { overflow:scroll; width: 100px; height: 100px; }"
+ " .translucent { opacity: 0.5; }"
+ " .with-border-radius { border: 5px solid; border-radius: 5px; }"
+ " .spacer { height: 1000px; }"
+ " .composited { will-change: transform; }"
+ "</style>"
+ "<div id='container' class='translucent container'>"
+ " <div class='composited box'>"
+ " <div class='box with-border-radius'>"
bokan 2017/04/07 17:39:03 You're testing the non-scrollable case here as wel
yigu 2017/04/07 19:26:27 Done.
+ " <div class='spacer'></div>"
+ " </div>"
+ " </div>"
+ " <div class='composited translucent box'></div>"
+ "</div>");
+
+ page().settings().setAcceleratedCompositingEnabled(true);
+ document().view()->setParentVisible(true);
+ document().view()->setSelfVisible(true);
+ document().view()->updateAllLifecyclePhases();
+
+ HistogramTester histogramTester;
+
+ ScrollBeginEventBuilder wheelScrollBegin(
+ IntPoint(50, 50), FloatPoint(0.f, 1.f), WebGestureDeviceTouchpad);
+ ScrollEndEventBuilder wheelScrollEnd;
+ document().frame()->eventHandler().handleGestureEvent(wheelScrollBegin);
+ document().frame()->eventHandler().handleGestureEvent(wheelScrollEnd);
+ histogramTester.expectBucketCount("Renderer4.MainThreadWheelScrollReason", 17,
+ 1);
+ histogramTester.expectBucketCount("Renderer4.MainThreadWheelScrollReason", 19,
+ 1);
+ histogramTester.expectBucketCount("Renderer4.MainThreadWheelScrollReason", 20,
+ 1);
+ histogramTester.expectTotalCount("Renderer4.MainThreadWheelScrollReason", 3);
+
+ Element* container = document().getElementById("container");
+ container->setAttribute("class", "composited");
bokan 2017/04/07 17:39:03 Ditto for the will-change bit here. Split it out i
yigu 2017/04/07 19:26:27 Done.
+ document().view()->updateAllLifecyclePhases();
+ wheelScrollBegin.y = wheelScrollBegin.globalY = 150;
+ document().frame()->eventHandler().handleGestureEvent(wheelScrollBegin);
+ document().frame()->eventHandler().handleGestureEvent(wheelScrollEnd);
+ histogramTester.expectTotalCount("Renderer4.MainThreadWheelScrollReason", 3);
+}
+
class TooltipCapturingChromeClient : public EmptyChromeClient {
public:
TooltipCapturingChromeClient() {}

Powered by Google App Engine
This is Rietveld 408576698