OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/dom/ClientRect.h" | 5 #include "core/dom/ClientRect.h" |
6 #include "core/frame/BrowserControls.h" | 6 #include "core/frame/BrowserControls.h" |
7 #include "core/frame/FrameHost.h" | 7 #include "core/frame/FrameHost.h" |
8 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
9 #include "core/frame/RootFrameViewport.h" | 9 #include "core/frame/RootFrameViewport.h" |
10 #include "core/frame/VisualViewport.h" | 10 #include "core/frame/VisualViewport.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 } | 51 } |
52 | 52 |
53 ~RootScrollerTest() override { | 53 ~RootScrollerTest() override { |
54 m_featuresBackup.restore(); | 54 m_featuresBackup.restore(); |
55 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); | 55 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); |
56 WebCache::clear(); | 56 WebCache::clear(); |
57 } | 57 } |
58 | 58 |
59 WebViewImpl* initialize(const std::string& pageName, | 59 WebViewImpl* initialize(const std::string& pageName, |
60 FrameTestHelpers::TestWebViewClient* client) { | 60 FrameTestHelpers::TestWebViewClient* client) { |
61 RuntimeEnabledFeatures::setSetRootScrollerEnabled(true); | 61 return initializeInternal(m_baseURL + pageName, client); |
62 | |
63 m_helper.initializeAndLoad(m_baseURL + pageName, true, nullptr, client, | |
64 nullptr, &configureSettings); | |
65 | |
66 // Initialize browser controls to be shown. | |
67 webViewImpl()->resizeWithBrowserControls(IntSize(400, 400), 50, true); | |
68 webViewImpl()->browserControls().setShownRatio(1); | |
69 | |
70 mainFrameView()->updateAllLifecyclePhases(); | |
71 | |
72 return webViewImpl(); | |
73 } | 62 } |
74 | 63 |
75 WebViewImpl* initialize(const std::string& pageName) { | 64 WebViewImpl* initialize(const std::string& pageName) { |
76 return initialize(pageName, &m_client); | 65 return initializeInternal(m_baseURL + pageName, &m_client); |
| 66 } |
| 67 |
| 68 WebViewImpl* initialize() { |
| 69 return initializeInternal("about:blank", &m_client); |
77 } | 70 } |
78 | 71 |
79 static void configureSettings(WebSettings* settings) { | 72 static void configureSettings(WebSettings* settings) { |
80 settings->setJavaScriptEnabled(true); | 73 settings->setJavaScriptEnabled(true); |
81 settings->setAcceleratedCompositingEnabled(true); | 74 settings->setAcceleratedCompositingEnabled(true); |
82 settings->setPreferCompositingToLCDTextEnabled(true); | 75 settings->setPreferCompositingToLCDTextEnabled(true); |
83 // Android settings. | 76 // Android settings. |
84 settings->setViewportEnabled(true); | 77 settings->setViewportEnabled(true); |
85 settings->setViewportMetaEnabled(true); | 78 settings->setViewportMetaEnabled(true); |
86 settings->setShrinksViewportContentToFit(true); | 79 settings->setShrinksViewportContentToFit(true); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 event.sourceDevice = device; | 147 event.sourceDevice = device; |
155 event.x = 100; | 148 event.x = 100; |
156 event.y = 100; | 149 event.y = 100; |
157 if (type == WebInputEvent::GestureScrollUpdate) { | 150 if (type == WebInputEvent::GestureScrollUpdate) { |
158 event.data.scrollUpdate.deltaX = deltaX; | 151 event.data.scrollUpdate.deltaX = deltaX; |
159 event.data.scrollUpdate.deltaY = deltaY; | 152 event.data.scrollUpdate.deltaY = deltaY; |
160 } | 153 } |
161 return event; | 154 return event; |
162 } | 155 } |
163 | 156 |
| 157 WebViewImpl* initializeInternal(const std::string& url, |
| 158 FrameTestHelpers::TestWebViewClient* client) { |
| 159 RuntimeEnabledFeatures::setSetRootScrollerEnabled(true); |
| 160 |
| 161 m_helper.initializeAndLoad(url, true, nullptr, client, nullptr, |
| 162 &configureSettings); |
| 163 |
| 164 // Initialize browser controls to be shown. |
| 165 webViewImpl()->resizeWithBrowserControls(IntSize(400, 400), 50, true); |
| 166 webViewImpl()->browserControls().setShownRatio(1); |
| 167 |
| 168 mainFrameView()->updateAllLifecyclePhases(); |
| 169 |
| 170 return webViewImpl(); |
| 171 } |
| 172 |
164 std::string m_baseURL; | 173 std::string m_baseURL; |
165 FrameTestHelpers::TestWebViewClient m_client; | 174 FrameTestHelpers::TestWebViewClient m_client; |
166 FrameTestHelpers::WebViewHelper m_helper; | 175 FrameTestHelpers::WebViewHelper m_helper; |
167 RuntimeEnabledFeatures::Backup m_featuresBackup; | 176 RuntimeEnabledFeatures::Backup m_featuresBackup; |
168 }; | 177 }; |
169 | 178 |
170 // Test that no root scroller element is set if setRootScroller isn't called on | 179 // Test that no root scroller element is set if setRootScroller isn't called on |
171 // any elements. The document Node should be the default effective root | 180 // any elements. The document Node should be the default effective root |
172 // scroller. | 181 // scroller. |
173 TEST_F(RootScrollerTest, TestDefaultRootScroller) { | 182 TEST_F(RootScrollerTest, TestDefaultRootScroller) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 // bar hiding and overscroll. | 231 // bar hiding and overscroll. |
223 TEST_F(RootScrollerTest, TestSetRootScroller) { | 232 TEST_F(RootScrollerTest, TestSetRootScroller) { |
224 OverscrollTestWebViewClient client; | 233 OverscrollTestWebViewClient client; |
225 initialize("root-scroller.html", &client); | 234 initialize("root-scroller.html", &client); |
226 | 235 |
227 Element* container = mainFrame()->document()->getElementById("container"); | 236 Element* container = mainFrame()->document()->getElementById("container"); |
228 DummyExceptionStateForTesting exceptionState; | 237 DummyExceptionStateForTesting exceptionState; |
229 mainFrame()->document()->setRootScroller(container, exceptionState); | 238 mainFrame()->document()->setRootScroller(container, exceptionState); |
230 ASSERT_EQ(container, mainFrame()->document()->rootScroller()); | 239 ASSERT_EQ(container, mainFrame()->document()->rootScroller()); |
231 | 240 |
232 // Content is 1000x1000, WebView size is 400x400 so max scroll is 600px. | 241 // Content is 1000x1000, WebView size is 400x400 but hiding the top controls |
233 double maximumScroll = 600; | 242 // makes it 400x450 so max scroll is 550px. |
| 243 double maximumScroll = 550; |
234 | 244 |
235 webViewImpl()->handleInputEvent( | 245 webViewImpl()->handleInputEvent( |
236 generateTouchGestureEvent(WebInputEvent::GestureScrollBegin)); | 246 generateTouchGestureEvent(WebInputEvent::GestureScrollBegin)); |
237 | 247 |
238 { | 248 { |
239 // Scrolling over the #container DIV should cause the browser controls to | 249 // Scrolling over the #container DIV should cause the browser controls to |
240 // hide. | 250 // hide. |
241 EXPECT_FLOAT_EQ(1, browserControls().shownRatio()); | 251 EXPECT_FLOAT_EQ(1, browserControls().shownRatio()); |
242 webViewImpl()->handleInputEvent(generateTouchGestureEvent( | 252 webViewImpl()->handleInputEvent(generateTouchGestureEvent( |
243 WebInputEvent::GestureScrollUpdate, 0, -browserControls().height())); | 253 WebInputEvent::GestureScrollUpdate, 0, -browserControls().height())); |
244 EXPECT_FLOAT_EQ(0, browserControls().shownRatio()); | 254 EXPECT_FLOAT_EQ(0, browserControls().shownRatio()); |
245 } | 255 } |
246 | 256 |
247 { | 257 { |
248 // Make sure we're actually scrolling the DIV and not the FrameView. | 258 // Make sure we're actually scrolling the DIV and not the FrameView. |
249 webViewImpl()->handleInputEvent( | 259 webViewImpl()->handleInputEvent( |
250 generateTouchGestureEvent(WebInputEvent::GestureScrollUpdate, 0, -100)); | 260 generateTouchGestureEvent(WebInputEvent::GestureScrollUpdate, 0, -100)); |
251 EXPECT_FLOAT_EQ(100, container->scrollTop()); | 261 EXPECT_FLOAT_EQ(100, container->scrollTop()); |
252 EXPECT_FLOAT_EQ(0, mainFrameView()->getScrollOffset().height()); | 262 EXPECT_FLOAT_EQ(0, mainFrameView()->getScrollOffset().height()); |
253 } | 263 } |
254 | 264 |
255 { | 265 { |
256 // Scroll 50 pixels past the end. Ensure we report the 50 pixels as | 266 // Scroll 50 pixels past the end. Ensure we report the 50 pixels as |
257 // overscroll. | 267 // overscroll. |
258 EXPECT_CALL(client, didOverscroll(WebFloatSize(0, 50), WebFloatSize(0, 50), | 268 EXPECT_CALL(client, didOverscroll(WebFloatSize(0, 50), WebFloatSize(0, 50), |
259 WebFloatPoint(100, 100), WebFloatSize())); | 269 WebFloatPoint(100, 100), WebFloatSize())); |
260 webViewImpl()->handleInputEvent( | 270 webViewImpl()->handleInputEvent( |
261 generateTouchGestureEvent(WebInputEvent::GestureScrollUpdate, 0, -550)); | 271 generateTouchGestureEvent(WebInputEvent::GestureScrollUpdate, 0, -500)); |
262 EXPECT_FLOAT_EQ(maximumScroll, container->scrollTop()); | 272 EXPECT_FLOAT_EQ(maximumScroll, container->scrollTop()); |
263 EXPECT_FLOAT_EQ(0, mainFrameView()->getScrollOffset().height()); | 273 EXPECT_FLOAT_EQ(0, mainFrameView()->getScrollOffset().height()); |
264 Mock::VerifyAndClearExpectations(&client); | 274 Mock::VerifyAndClearExpectations(&client); |
265 } | 275 } |
266 | 276 |
267 { | 277 { |
268 // Continue the gesture overscroll. | 278 // Continue the gesture overscroll. |
269 EXPECT_CALL(client, didOverscroll(WebFloatSize(0, 20), WebFloatSize(0, 70), | 279 EXPECT_CALL(client, didOverscroll(WebFloatSize(0, 20), WebFloatSize(0, 70), |
270 WebFloatPoint(100, 100), WebFloatSize())); | 280 WebFloatPoint(100, 100), WebFloatSize())); |
271 webViewImpl()->handleInputEvent( | 281 webViewImpl()->handleInputEvent( |
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1138 mainFrameView()->updateAllLifecyclePhases(); | 1148 mainFrameView()->updateAllLifecyclePhases(); |
1139 | 1149 |
1140 ScrollableArea* containerScroller = childFrame->view(); | 1150 ScrollableArea* containerScroller = childFrame->view(); |
1141 | 1151 |
1142 EXPECT_FALSE(containerScroller->horizontalScrollbar()); | 1152 EXPECT_FALSE(containerScroller->horizontalScrollbar()); |
1143 EXPECT_FALSE(containerScroller->verticalScrollbar()); | 1153 EXPECT_FALSE(containerScroller->verticalScrollbar()); |
1144 EXPECT_GT(containerScroller->maximumScrollOffset().width(), 0); | 1154 EXPECT_GT(containerScroller->maximumScrollOffset().width(), 0); |
1145 EXPECT_GT(containerScroller->maximumScrollOffset().height(), 0); | 1155 EXPECT_GT(containerScroller->maximumScrollOffset().height(), 0); |
1146 } | 1156 } |
1147 | 1157 |
| 1158 TEST_F(RootScrollerTest, TopControlsAdjustmentAppliedToRootScroller) { |
| 1159 initialize(); |
| 1160 |
| 1161 WebURL baseURL = URLTestHelpers::toKURL("http://www.test.com/"); |
| 1162 FrameTestHelpers::loadHTMLString(webViewImpl()->mainFrame(), |
| 1163 "<!DOCTYPE html>" |
| 1164 "<style>" |
| 1165 " body, html {" |
| 1166 " width: 100%;" |
| 1167 " height: 100%;" |
| 1168 " margin: 0px;" |
| 1169 " }" |
| 1170 " #container {" |
| 1171 " width: 100%;" |
| 1172 " height: 100%;" |
| 1173 " overflow: auto;" |
| 1174 " }" |
| 1175 "</style>" |
| 1176 "<div id='container'>" |
| 1177 " <div style='height:1000px'>test</div>" |
| 1178 "</div>", |
| 1179 baseURL); |
| 1180 |
| 1181 webViewImpl()->resizeWithBrowserControls(IntSize(400, 400), 50, true); |
| 1182 mainFrameView()->updateAllLifecyclePhases(); |
| 1183 |
| 1184 Element* container = mainFrame()->document()->getElementById("container"); |
| 1185 mainFrame()->document()->setRootScroller(container, ASSERT_NO_EXCEPTION); |
| 1186 |
| 1187 ScrollableArea* containerScroller = |
| 1188 static_cast<PaintInvalidationCapableScrollableArea*>( |
| 1189 toLayoutBox(container->layoutObject())->getScrollableArea()); |
| 1190 |
| 1191 // Hide the top controls and scroll down maximally. We should account for the |
| 1192 // change in maximum scroll offset due to the top controls hiding. That is, |
| 1193 // since the controls are hidden, the "content area" is taller so the maximum |
| 1194 // scroll offset should shrink. |
| 1195 ASSERT_EQ(1000 - 400, containerScroller->maximumScrollOffset().height()); |
| 1196 |
| 1197 webViewImpl()->handleInputEvent( |
| 1198 generateTouchGestureEvent(WebInputEvent::GestureScrollBegin)); |
| 1199 ASSERT_EQ(1, browserControls().shownRatio()); |
| 1200 webViewImpl()->handleInputEvent(generateTouchGestureEvent( |
| 1201 WebInputEvent::GestureScrollUpdate, 0, -browserControls().height())); |
| 1202 ASSERT_EQ(0, browserControls().shownRatio()); |
| 1203 EXPECT_EQ(1000 - 450, containerScroller->maximumScrollOffset().height()); |
| 1204 |
| 1205 webViewImpl()->handleInputEvent( |
| 1206 generateTouchGestureEvent(WebInputEvent::GestureScrollUpdate, 0, -3000)); |
| 1207 EXPECT_EQ(1000 - 450, containerScroller->getScrollOffset().height()); |
| 1208 |
| 1209 webViewImpl()->handleInputEvent( |
| 1210 generateTouchGestureEvent(WebInputEvent::GestureScrollEnd)); |
| 1211 webViewImpl()->resizeWithBrowserControls(IntSize(400, 450), 50, false); |
| 1212 EXPECT_EQ(1000 - 450, containerScroller->maximumScrollOffset().height()); |
| 1213 } |
| 1214 |
1148 TEST_F(RootScrollerTest, RotationAnchoring) { | 1215 TEST_F(RootScrollerTest, RotationAnchoring) { |
1149 initialize("root-scroller-rotation.html"); | 1216 initialize("root-scroller-rotation.html"); |
1150 | 1217 |
1151 ScrollableArea* containerScroller; | 1218 ScrollableArea* containerScroller; |
1152 | 1219 |
1153 { | 1220 { |
1154 webViewImpl()->resizeWithBrowserControls(IntSize(250, 1000), 0, true); | 1221 webViewImpl()->resizeWithBrowserControls(IntSize(250, 1000), 0, true); |
1155 mainFrameView()->updateAllLifecyclePhases(); | 1222 mainFrameView()->updateAllLifecyclePhases(); |
1156 | 1223 |
1157 Element* container = mainFrame()->document()->getElementById("container"); | 1224 Element* container = mainFrame()->document()->getElementById("container"); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1245 // FrameView without a layout. | 1312 // FrameView without a layout. |
1246 iframe->remove(); | 1313 iframe->remove(); |
1247 | 1314 |
1248 EXPECT_EQ(mainFrameView()->layoutViewportScrollableArea(), | 1315 EXPECT_EQ(mainFrameView()->layoutViewportScrollableArea(), |
1249 &mainFrameView()->getRootFrameViewport()->layoutViewport()); | 1316 &mainFrameView()->getRootFrameViewport()->layoutViewport()); |
1250 } | 1317 } |
1251 | 1318 |
1252 } // namespace | 1319 } // namespace |
1253 | 1320 |
1254 } // namespace blink | 1321 } // namespace blink |
OLD | NEW |