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

Unified Diff: Source/web/tests/WebFrameTest.cpp

Issue 1056983004: OverscrollGlow for mainThread-{BLINK CHANGES} (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: addressed review comments of bokan Created 5 years, 6 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: Source/web/tests/WebFrameTest.cpp
diff --git a/Source/web/tests/WebFrameTest.cpp b/Source/web/tests/WebFrameTest.cpp
index 8fb12ccf6801050fdfda693a3160fbb0b3e3f54c..afff9a2fff1e228e1e675154269afd9771b0176d 100644
--- a/Source/web/tests/WebFrameTest.cpp
+++ b/Source/web/tests/WebFrameTest.cpp
@@ -152,6 +152,12 @@ const int touchPointPadding = 32;
EXPECT_FLOAT_EQ(expected.y(), actual.y()); \
} while (false)
+#define EXPECT_WEB_FLOAT_SIZE_EQ(expected, actual) \
+ do { \
+ EXPECT_FLOAT_EQ(expected.width, actual.width); \
+ EXPECT_FLOAT_EQ(expected.height, actual.height); \
+ } while (false)
+
class WebFrameTest : public ::testing::Test {
protected:
WebFrameTest()
@@ -7437,4 +7443,258 @@ TEST_P(ParametrizedWebFrameTest, CreateLocalChildWithPreviousSibling)
view->close();
}
+class OverscrollWebViewClient : public FrameTestHelpers::TestWebViewClient {
+public:
+ virtual void didOverscroll(const WebFloatSize& unusedDelta, const WebFloatSize& accumulatedRootOverScroll, const WebFloatPoint& position, const WebFloatSize& velocity) override
+ {
+ m_unusedDelta = unusedDelta;
+ m_accumulatedRootOverScroll = accumulatedRootOverScroll;
+ }
+
+ WebFloatSize m_unusedDelta;
+ WebFloatSize m_accumulatedRootOverScroll;
+};
+
+class WebFrameOverscrollTest : public WebFrameTest {
+protected:
+ WebGestureEvent generateEvent(WebInputEvent::Type type, int deltaX = 0, int deltaY = 0)
+ {
+ WebGestureEvent event;
+ event.type = type;
+ event.x = 100;
+ event.y = 100;
+ if (type == WebInputEvent::GestureScrollUpdate) {
+ event.data.scrollUpdate.deltaX = deltaX;
+ event.data.scrollUpdate.deltaY = deltaY;
+ }
+ return event;
+ }
+
+ void ScrollBegin(FrameTestHelpers::WebViewHelper* webViewHelper)
+ {
+ webViewHelper->webViewImpl()->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin));
+ }
+
+ void ScrollUpdate(FrameTestHelpers::WebViewHelper* webViewHelper, float deltaX, float deltaY)
+ {
+ webViewHelper->webViewImpl()->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, deltaX, deltaY));
+ }
+
+ void ScrollEnd(FrameTestHelpers::WebViewHelper* webViewHelper)
+ {
+ webViewHelper->webViewImpl()->handleInputEvent(generateEvent(WebInputEvent::GestureScrollEnd));
+ }
+};
+
+TEST_F(WebFrameOverscrollTest, AccumulatedRootOverscrollAndUnsedDeltaValuesOnOverscroll)
+{
+ OverscrollWebViewClient client;
+ registerMockedHttpURLLoad("overscroll/overscroll.html");
+ FrameTestHelpers::WebViewHelper webViewHelper;
+ WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(m_baseURL + "overscroll/overscroll.html", true, 0, &client, configureAndroid);
+ webViewImpl->layout();
bokan 2015/06/04 14:45:44 Nit: I don't think you need these layout calls.
MuVen 2015/06/04 17:58:56 Done.
+
+ // Calculation of accumulatedRootOverscroll and unusedDelta on multiple scrollUpdate.
+ ScrollBegin(&webViewHelper);
+ ScrollUpdate(&webViewHelper, -308, -316);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScroll);
bokan 2015/06/04 14:45:44 Shouldn't these be non-0 now that the unusedDelta
MuVen 2015/06/04 17:58:56 Done.
+
+ ScrollUpdate(&webViewHelper, 0, -13);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 13), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 13), client.m_accumulatedRootOverScroll);
+
+ ScrollUpdate(&webViewHelper, -20, -13);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(20, 13), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(20, 26), client.m_accumulatedRootOverScroll);
+
+ // Overscroll is not reported due to which OverscrollWebViewClient retains last
+ // UnusedDelta and AccumulatedRootOverscroll values.
bokan 2015/06/04 14:45:44 We should use the GMock in these tests, it'll make
MuVen 2015/06/04 17:58:56 Done.
+ ScrollUpdate(&webViewHelper, 0, 1);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(20, 13), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(20, 26), client.m_accumulatedRootOverScroll);
+
+ ScrollUpdate(&webViewHelper, 1, 0);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(20, 13), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(20, 26), client.m_accumulatedRootOverScroll);
+
bokan 2015/06/04 14:45:44 I would add another overscroll here to make sure t
MuVen 2015/06/04 17:58:56 Done.
+ ScrollEnd(&webViewHelper);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(20, 13), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(20, 26), client.m_accumulatedRootOverScroll);
+}
+
+TEST_F(WebFrameOverscrollTest, AccumulatedOverscrollAndUnusedDeltaValuesOnDifferentAxesOverscroll)
+{
+ OverscrollWebViewClient client;
+ registerMockedHttpURLLoad("overscroll/div-overscroll.html");
+ FrameTestHelpers::WebViewHelper webViewHelper;
+ WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(m_baseURL + "overscroll/div-overscroll.html", true, 0, &client, configureAndroid);
+ webViewImpl->layout();
+
+ ScrollBegin(&webViewHelper);
+
+ // Scroll the Div to the end.
+ ScrollUpdate(&webViewHelper, 0, -316);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScroll);
+
+ // Now On Scrolling DIV, scroll is bubbled and root layer is over-scrolled.
+ ScrollUpdate(&webViewHelper, 0, -50);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 50), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 50), client.m_accumulatedRootOverScroll);
bokan 2015/06/04 14:45:44 This is tested in the below test. You should keep
MuVen 2015/06/04 17:58:56 Done.
+
+ // Overscroll is not reported, so client retains last UnusedDelta and AccumulatedRootOverscroll values.
+ ScrollUpdate(&webViewHelper, 0, 1);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 50), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 50), client.m_accumulatedRootOverScroll);
+
+ // Overscroll is reported.
+ ScrollUpdate(&webViewHelper, 0, -2);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 1), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 1), client.m_accumulatedRootOverScroll);
+
+ // Now On Scrolling DIV, scroll is bubbled and root layer is over-scrolled.
+ ScrollUpdate(&webViewHelper, 0, -100);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 100), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 101), client.m_accumulatedRootOverScroll);
+
+ // Page scrolls vertically, but over-scrolls horizontally.
+ ScrollUpdate(&webViewHelper, 100, 50);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-100, 0), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-100, 0), client.m_accumulatedRootOverScroll);
+
+ // Scrolling up, Overscroll is not reported, so client retains last UnusedDelta and AccumulatedRootOverscroll values.
+ ScrollUpdate(&webViewHelper, 0, -50);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-100, 0), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-100, 0), client.m_accumulatedRootOverScroll);
+
+ // Page scrolls horizontally, but over-scrolls vertically.
+ ScrollUpdate(&webViewHelper, -100, -100);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 100), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 100), client.m_accumulatedRootOverScroll);
+}
+
+TEST_F(WebFrameOverscrollTest, RootLayerOverscrolledOnInnerDivOverScroll)
+{
+ OverscrollWebViewClient client;
+ registerMockedHttpURLLoad("overscroll/div-overscroll.html");
+ FrameTestHelpers::WebViewHelper webViewHelper;
+ WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(m_baseURL + "overscroll/div-overscroll.html", true, 0, &client, configureAndroid);
+ webViewImpl->layout();
+
+ ScrollBegin(&webViewHelper);
+
+ // Scroll the Div to the end.
+ ScrollUpdate(&webViewHelper, 0, -316);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScroll);
+
+ // Now On Scrolling DIV, scroll is bubbled and root layer is over-scrolled.
+ ScrollUpdate(&webViewHelper, 0, -50);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 50), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 50), client.m_accumulatedRootOverScroll);
+}
+
+TEST_F(WebFrameOverscrollTest, RootLayerOverscrolledOnInnerIFrameOverScroll)
+{
+ OverscrollWebViewClient client;
+ registerMockedHttpURLLoad("overscroll/iframe-overscroll.html");
+ registerMockedHttpURLLoad("overscroll/scrollable-iframe.html");
+ FrameTestHelpers::WebViewHelper webViewHelper;
+ WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(m_baseURL + "overscroll/iframe-overscroll.html", true, 0, &client, configureAndroid);
+ webViewImpl->layout();
+
+ ScrollBegin(&webViewHelper);
+
+ // Scroll the IFrame to the end.
+ ScrollUpdate(&webViewHelper, 0, -320);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScroll);
+
+ // Now On Scrolling IFrame, scroll is bubbled and root layer is over-scrolled.
+ ScrollUpdate(&webViewHelper, 0, -50);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 50), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 50), client.m_accumulatedRootOverScroll);
+}
+
+TEST_F(WebFrameOverscrollTest, NoOverscrollOnNonScrollableaxes)
+{
+ OverscrollWebViewClient client;
+ registerMockedHttpURLLoad("overscroll/no-overscroll-on-nonscrollable-axes.html");
+ FrameTestHelpers::WebViewHelper webViewHelper;
+ WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(m_baseURL + "overscroll/no-overscroll-on-nonscrollable-axes.html", true, 0, &client, configureAndroid);
+ webViewImpl->layout();
+
+ // Overscroll is not reported in all the directions.
+ ScrollBegin(&webViewHelper);
+ ScrollUpdate(&webViewHelper, 0, -1);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScroll);
+
+ ScrollUpdate(&webViewHelper, 0, 1);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScroll);
+
+ ScrollUpdate(&webViewHelper, 1, 0);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScroll);
+
+ ScrollUpdate(&webViewHelper, -1, 0);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScroll);
+
+ ScrollUpdate(&webViewHelper, 1, 1);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScroll);
+
+ ScrollUpdate(&webViewHelper, -1, 1);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScroll);
+
+ ScrollUpdate(&webViewHelper, 1, -1);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScroll);
+
+ ScrollUpdate(&webViewHelper, -1, -1);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScroll);
+
+ ScrollEnd(&webViewHelper);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScroll);
+}
+
+TEST_F(WebFrameOverscrollTest, ScaledPageRootLayerOverscrolled)
bokan 2015/06/04 14:45:43 Awesome, thanks for testing under page scale :)
MuVen 2015/06/04 17:58:56 Thanks to majidvp :)
+{
+ OverscrollWebViewClient client;
+ registerMockedHttpURLLoad("overscroll/overscroll.html");
+ FrameTestHelpers::WebViewHelper webViewHelper;
+ WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(m_baseURL + "overscroll/overscroll.html", true, 0, &client, configureAndroid);
+ webViewImpl->setPageScaleFactor(3.f);
+ webViewImpl->layout();
+
+ // Calculation of accumulatedRootOverscroll and unusedDelta on scaled page.
+ ScrollBegin(&webViewHelper);
+ ScrollUpdate(&webViewHelper, 0, 30);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, -10), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, -10), client.m_accumulatedRootOverScroll);
+
+ ScrollUpdate(&webViewHelper, 0, 30);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, -10), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, -20), client.m_accumulatedRootOverScroll);
+
+ ScrollUpdate(&webViewHelper, 30, 30);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-10, -10), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-10, -30), client.m_accumulatedRootOverScroll);
+
+ ScrollUpdate(&webViewHelper, 30, 0);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-10, 0), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-20, -30), client.m_accumulatedRootOverScroll);
+
+ // Overscroll is not reported, so client retains last UnusedDelta and AccumulatedRootOverscroll values.
+ ScrollEnd(&webViewHelper);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-10, 0), client.m_unusedDelta);
+ EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-20, -30), client.m_accumulatedRootOverScroll);
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698