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 f8618151f6be13253f4f4efeefa617b8fe13d3b2..a3d18601e675fc257b7f601eeef134726c28c5d0 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,73 @@ 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; }" |
+ " .background_scroller { overflow: scroll; width: 250px; height: 250px;" |
+ " position: absolute; z-index: -1;}" |
+ " body { height: 2000px; width: 1000px; } " |
+ "</style>" |
+ "<div class='translucent box'><div class='spacer'></div></div>" |
+ "<div id='under' class='background_scroller'>" |
+ " <div class='spacer'></div>" |
+ "</div>" |
+ "<div class='composited box'>" |
+ " <div class='spacer'></div>" |
+ "</div>"); |
+ |
+ page().settings().setAcceleratedCompositingEnabled(true); |
+ document().view()->setParentVisible(true); |
+ document().view()->setSelfVisible(true); |
+ document().view()->updateAllLifecyclePhases(); |
+ |
+ HistogramTester histogramTester; |
+ // 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); |
+ |
+ // Scroll a composited scroller A over a non-composited scroller B should |
+ // cause the scroll events to go to the main thread because B is non fast |
+ // scrollable region. If none of the scrollers from A's containing scroll |
+ // chain has a reason, UnknownNonCompositedRegion should be added. |
+ wheelScrollBegin.y = wheelScrollBegin.globalY = 150; |
+ document().frame()->eventHandler().handleGestureEvent(wheelScrollBegin); |
+ document().frame()->eventHandler().handleGestureEvent(wheelScrollEnd); |
+ histogramTester.expectBucketCount("Renderer4.MainThreadWheelScrollReason", 23, |
+ 1); |
+ |
+ // UnknownNonCompositedRegion is not added if the scroller underneath has a |
+ // reason. |
+ document().getElementById("under")->setAttribute("style", "position:fixed;"); |
+ document().frame()->eventHandler().handleGestureEvent(wheelScrollBegin); |
+ document().frame()->eventHandler().handleGestureEvent(wheelScrollEnd); |
+ histogramTester.expectBucketCount("Renderer4.MainThreadWheelScrollReason", 23, |
+ 1); |
+ // 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); |
+} |
+ |
class TooltipCapturingChromeClient : public EmptyChromeClient { |
public: |
TooltipCapturingChromeClient() {} |