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

Side by Side Diff: third_party/WebKit/Source/web/tests/RootScrollerTest.cpp

Issue 2860673002: Change all test cases to use WebViewBase instead of WebViewImpl. (Closed)
Patch Set: Address code review comments. Created 3 years, 7 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 unified diff | Download patch
OLDNEW
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 "bindings/core/v8/NodeOrString.h" 5 #include "bindings/core/v8/NodeOrString.h"
6 #include "core/dom/ClientRect.h" 6 #include "core/dom/ClientRect.h"
7 #include "core/frame/BrowserControls.h" 7 #include "core/frame/BrowserControls.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"
11 #include "core/html/HTMLFrameOwnerElement.h" 11 #include "core/html/HTMLFrameOwnerElement.h"
12 #include "core/layout/LayoutBox.h" 12 #include "core/layout/LayoutBox.h"
13 #include "core/layout/api/LayoutViewItem.h" 13 #include "core/layout/api/LayoutViewItem.h"
14 #include "core/layout/compositing/CompositedLayerMapping.h" 14 #include "core/layout/compositing/CompositedLayerMapping.h"
15 #include "core/layout/compositing/PaintLayerCompositor.h" 15 #include "core/layout/compositing/PaintLayerCompositor.h"
16 #include "core/page/Page.h" 16 #include "core/page/Page.h"
17 #include "core/page/scrolling/RootScrollerController.h" 17 #include "core/page/scrolling/RootScrollerController.h"
18 #include "core/page/scrolling/TopDocumentRootScrollerController.h" 18 #include "core/page/scrolling/TopDocumentRootScrollerController.h"
19 #include "core/paint/PaintLayer.h" 19 #include "core/paint/PaintLayer.h"
20 #include "core/paint/PaintLayerScrollableArea.h" 20 #include "core/paint/PaintLayerScrollableArea.h"
21 #include "platform/testing/URLTestHelpers.h" 21 #include "platform/testing/URLTestHelpers.h"
22 #include "platform/testing/UnitTestHelpers.h" 22 #include "platform/testing/UnitTestHelpers.h"
23 #include "platform/wtf/Vector.h" 23 #include "platform/wtf/Vector.h"
24 #include "public/platform/Platform.h" 24 #include "public/platform/Platform.h"
25 #include "public/platform/WebCoalescedInputEvent.h"
25 #include "public/platform/WebURLLoaderMockFactory.h" 26 #include "public/platform/WebURLLoaderMockFactory.h"
26 #include "public/web/WebConsoleMessage.h" 27 #include "public/web/WebConsoleMessage.h"
27 #include "public/web/WebRemoteFrame.h" 28 #include "public/web/WebRemoteFrame.h"
28 #include "public/web/WebScriptSource.h" 29 #include "public/web/WebScriptSource.h"
29 #include "public/web/WebSettings.h" 30 #include "public/web/WebSettings.h"
30 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
31 #include "web/WebLocalFrameImpl.h" 32 #include "web/WebLocalFrameImpl.h"
32 #include "web/WebRemoteFrameImpl.h" 33 #include "web/WebRemoteFrameImpl.h"
33 #include "web/tests/FrameTestHelpers.h" 34 #include "web/tests/FrameTestHelpers.h"
34 35
(...skipping 14 matching lines...) Expand all
49 RegisterMockedHttpURLLoad("root-scroller-child.html"); 50 RegisterMockedHttpURLLoad("root-scroller-child.html");
50 } 51 }
51 52
52 ~RootScrollerTest() override { 53 ~RootScrollerTest() override {
53 features_backup_.restore(); 54 features_backup_.restore();
54 Platform::Current() 55 Platform::Current()
55 ->GetURLLoaderMockFactory() 56 ->GetURLLoaderMockFactory()
56 ->UnregisterAllURLsAndClearMemoryCache(); 57 ->UnregisterAllURLsAndClearMemoryCache();
57 } 58 }
58 59
59 WebViewImpl* Initialize(const std::string& page_name, 60 WebViewBase* Initialize(const std::string& page_name,
60 FrameTestHelpers::TestWebViewClient* client) { 61 FrameTestHelpers::TestWebViewClient* client) {
61 return InitializeInternal(base_url_ + page_name, client); 62 return InitializeInternal(base_url_ + page_name, client);
62 } 63 }
63 64
64 WebViewImpl* Initialize(const std::string& page_name) { 65 WebViewBase* Initialize(const std::string& page_name) {
65 return InitializeInternal(base_url_ + page_name, &client_); 66 return InitializeInternal(base_url_ + page_name, &client_);
66 } 67 }
67 68
68 WebViewImpl* Initialize() { 69 WebViewBase* Initialize() {
69 return InitializeInternal("about:blank", &client_); 70 return InitializeInternal("about:blank", &client_);
70 } 71 }
71 72
72 static void ConfigureSettings(WebSettings* settings) { 73 static void ConfigureSettings(WebSettings* settings) {
73 settings->SetJavaScriptEnabled(true); 74 settings->SetJavaScriptEnabled(true);
74 settings->SetAcceleratedCompositingEnabled(true); 75 settings->SetAcceleratedCompositingEnabled(true);
75 settings->SetPreferCompositingToLCDTextEnabled(true); 76 settings->SetPreferCompositingToLCDTextEnabled(true);
76 // Android settings. 77 // Android settings.
77 settings->SetViewportEnabled(true); 78 settings->SetViewportEnabled(true);
78 settings->SetViewportMetaEnabled(true); 79 settings->SetViewportMetaEnabled(true);
(...skipping 10 matching lines...) Expand all
89 void ExecuteScript(const WebString& code) { 90 void ExecuteScript(const WebString& code) {
90 ExecuteScript(code, *MainWebFrame()); 91 ExecuteScript(code, *MainWebFrame());
91 } 92 }
92 93
93 void ExecuteScript(const WebString& code, WebLocalFrame& frame) { 94 void ExecuteScript(const WebString& code, WebLocalFrame& frame) {
94 frame.ExecuteScript(WebScriptSource(code)); 95 frame.ExecuteScript(WebScriptSource(code));
95 frame.View()->UpdateAllLifecyclePhases(); 96 frame.View()->UpdateAllLifecyclePhases();
96 RunPendingTasks(); 97 RunPendingTasks();
97 } 98 }
98 99
99 WebViewImpl* GetWebViewImpl() const { return helper_.WebView(); } 100 WebViewBase* GetWebView() const { return helper_.WebView(); }
100 101
101 Page& GetPage() const { return *helper_.WebView()->GetPage(); } 102 Page& GetPage() const { return *helper_.WebView()->GetPage(); }
102 103
103 LocalFrame* MainFrame() const { 104 LocalFrame* MainFrame() const {
104 return GetWebViewImpl()->MainFrameImpl()->GetFrame(); 105 return GetWebView()->MainFrameImpl()->GetFrame();
105 } 106 }
106 107
107 WebLocalFrame* MainWebFrame() const { 108 WebLocalFrame* MainWebFrame() const { return GetWebView()->MainFrameImpl(); }
108 return GetWebViewImpl()->MainFrameImpl();
109 }
110 109
111 FrameView* MainFrameView() const { 110 FrameView* MainFrameView() const {
112 return GetWebViewImpl()->MainFrameImpl()->GetFrame()->View(); 111 return GetWebView()->MainFrameImpl()->GetFrame()->View();
113 } 112 }
114 113
115 VisualViewport& GetVisualViewport() const { 114 VisualViewport& GetVisualViewport() const {
116 return GetPage().GetVisualViewport(); 115 return GetPage().GetVisualViewport();
117 } 116 }
118 117
119 BrowserControls& GetBrowserControls() const { 118 BrowserControls& GetBrowserControls() const {
120 return GetPage().GetBrowserControls(); 119 return GetPage().GetBrowserControls();
121 } 120 }
122 121
(...skipping 25 matching lines...) Expand all
148 event.source_device = device; 147 event.source_device = device;
149 event.x = 100; 148 event.x = 100;
150 event.y = 100; 149 event.y = 100;
151 if (type == WebInputEvent::kGestureScrollUpdate) { 150 if (type == WebInputEvent::kGestureScrollUpdate) {
152 event.data.scroll_update.delta_x = delta_x; 151 event.data.scroll_update.delta_x = delta_x;
153 event.data.scroll_update.delta_y = delta_y; 152 event.data.scroll_update.delta_y = delta_y;
154 } 153 }
155 return WebCoalescedInputEvent(event); 154 return WebCoalescedInputEvent(event);
156 } 155 }
157 156
158 WebViewImpl* InitializeInternal(const std::string& url, 157 WebViewBase* InitializeInternal(const std::string& url,
159 FrameTestHelpers::TestWebViewClient* client) { 158 FrameTestHelpers::TestWebViewClient* client) {
160 RuntimeEnabledFeatures::setSetRootScrollerEnabled(true); 159 RuntimeEnabledFeatures::setSetRootScrollerEnabled(true);
161 160
162 helper_.InitializeAndLoad(url, true, nullptr, client, nullptr, 161 helper_.InitializeAndLoad(url, true, nullptr, client, nullptr,
163 &ConfigureSettings); 162 &ConfigureSettings);
164 163
165 // Initialize browser controls to be shown. 164 // Initialize browser controls to be shown.
166 GetWebViewImpl()->ResizeWithBrowserControls(IntSize(400, 400), 50, true); 165 GetWebView()->ResizeWithBrowserControls(IntSize(400, 400), 50, true);
167 GetWebViewImpl()->GetBrowserControls().SetShownRatio(1); 166 GetWebView()->GetBrowserControls().SetShownRatio(1);
168 167
169 MainFrameView()->UpdateAllLifecyclePhases(); 168 MainFrameView()->UpdateAllLifecyclePhases();
170 169
171 return GetWebViewImpl(); 170 return GetWebView();
172 } 171 }
173 172
174 std::string base_url_; 173 std::string base_url_;
175 FrameTestHelpers::TestWebViewClient client_; 174 FrameTestHelpers::TestWebViewClient client_;
176 FrameTestHelpers::WebViewHelper helper_; 175 FrameTestHelpers::WebViewHelper helper_;
177 RuntimeEnabledFeatures::Backup features_backup_; 176 RuntimeEnabledFeatures::Backup features_backup_;
178 }; 177 };
179 178
180 // 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
181 // any elements. The document Node should be the default effective root 180 // any elements. The document Node should be the default effective root
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 Initialize("root-scroller.html", &client); 234 Initialize("root-scroller.html", &client);
236 235
237 Element* container = MainFrame()->GetDocument()->getElementById("container"); 236 Element* container = MainFrame()->GetDocument()->getElementById("container");
238 MainFrame()->GetDocument()->setRootScroller(container); 237 MainFrame()->GetDocument()->setRootScroller(container);
239 ASSERT_EQ(container, MainFrame()->GetDocument()->rootScroller()); 238 ASSERT_EQ(container, MainFrame()->GetDocument()->rootScroller());
240 239
241 // Content is 1000x1000, WebView size is 400x400 but hiding the top controls 240 // Content is 1000x1000, WebView size is 400x400 but hiding the top controls
242 // makes it 400x450 so max scroll is 550px. 241 // makes it 400x450 so max scroll is 550px.
243 double maximum_scroll = 550; 242 double maximum_scroll = 550;
244 243
245 GetWebViewImpl()->HandleInputEvent( 244 GetWebView()->HandleInputEvent(
246 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollBegin)); 245 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollBegin));
247 246
248 { 247 {
249 // Scrolling over the #container DIV should cause the browser controls to 248 // Scrolling over the #container DIV should cause the browser controls to
250 // hide. 249 // hide.
251 EXPECT_FLOAT_EQ(1, GetBrowserControls().ShownRatio()); 250 EXPECT_FLOAT_EQ(1, GetBrowserControls().ShownRatio());
252 GetWebViewImpl()->HandleInputEvent( 251 GetWebView()->HandleInputEvent(
253 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollUpdate, 0, 252 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollUpdate, 0,
254 -GetBrowserControls().Height())); 253 -GetBrowserControls().Height()));
255 EXPECT_FLOAT_EQ(0, GetBrowserControls().ShownRatio()); 254 EXPECT_FLOAT_EQ(0, GetBrowserControls().ShownRatio());
256 } 255 }
257 256
258 { 257 {
259 // 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.
260 GetWebViewImpl()->HandleInputEvent(GenerateTouchGestureEvent( 259 GetWebView()->HandleInputEvent(GenerateTouchGestureEvent(
261 WebInputEvent::kGestureScrollUpdate, 0, -100)); 260 WebInputEvent::kGestureScrollUpdate, 0, -100));
262 EXPECT_FLOAT_EQ(100, container->scrollTop()); 261 EXPECT_FLOAT_EQ(100, container->scrollTop());
263 EXPECT_FLOAT_EQ(0, MainFrameView()->GetScrollOffset().Height()); 262 EXPECT_FLOAT_EQ(0, MainFrameView()->GetScrollOffset().Height());
264 } 263 }
265 264
266 { 265 {
267 // 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
268 // overscroll. 267 // overscroll.
269 EXPECT_CALL(client, DidOverscroll(WebFloatSize(0, 50), WebFloatSize(0, 50), 268 EXPECT_CALL(client, DidOverscroll(WebFloatSize(0, 50), WebFloatSize(0, 50),
270 WebFloatPoint(100, 100), WebFloatSize())); 269 WebFloatPoint(100, 100), WebFloatSize()));
271 GetWebViewImpl()->HandleInputEvent(GenerateTouchGestureEvent( 270 GetWebView()->HandleInputEvent(GenerateTouchGestureEvent(
272 WebInputEvent::kGestureScrollUpdate, 0, -500)); 271 WebInputEvent::kGestureScrollUpdate, 0, -500));
273 EXPECT_FLOAT_EQ(maximum_scroll, container->scrollTop()); 272 EXPECT_FLOAT_EQ(maximum_scroll, container->scrollTop());
274 EXPECT_FLOAT_EQ(0, MainFrameView()->GetScrollOffset().Height()); 273 EXPECT_FLOAT_EQ(0, MainFrameView()->GetScrollOffset().Height());
275 Mock::VerifyAndClearExpectations(&client); 274 Mock::VerifyAndClearExpectations(&client);
276 } 275 }
277 276
278 { 277 {
279 // Continue the gesture overscroll. 278 // Continue the gesture overscroll.
280 EXPECT_CALL(client, DidOverscroll(WebFloatSize(0, 20), WebFloatSize(0, 70), 279 EXPECT_CALL(client, DidOverscroll(WebFloatSize(0, 20), WebFloatSize(0, 70),
281 WebFloatPoint(100, 100), WebFloatSize())); 280 WebFloatPoint(100, 100), WebFloatSize()));
282 GetWebViewImpl()->HandleInputEvent( 281 GetWebView()->HandleInputEvent(
283 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollUpdate, 0, -20)); 282 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollUpdate, 0, -20));
284 EXPECT_FLOAT_EQ(maximum_scroll, container->scrollTop()); 283 EXPECT_FLOAT_EQ(maximum_scroll, container->scrollTop());
285 EXPECT_FLOAT_EQ(0, MainFrameView()->GetScrollOffset().Height()); 284 EXPECT_FLOAT_EQ(0, MainFrameView()->GetScrollOffset().Height());
286 Mock::VerifyAndClearExpectations(&client); 285 Mock::VerifyAndClearExpectations(&client);
287 } 286 }
288 287
289 GetWebViewImpl()->HandleInputEvent( 288 GetWebView()->HandleInputEvent(
290 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollEnd)); 289 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollEnd));
291 290
292 { 291 {
293 // Make sure a new gesture scroll still won't scroll the frameview and 292 // Make sure a new gesture scroll still won't scroll the frameview and
294 // overscrolls. 293 // overscrolls.
295 GetWebViewImpl()->HandleInputEvent( 294 GetWebView()->HandleInputEvent(
296 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollBegin)); 295 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollBegin));
297 296
298 EXPECT_CALL(client, DidOverscroll(WebFloatSize(0, 30), WebFloatSize(0, 30), 297 EXPECT_CALL(client, DidOverscroll(WebFloatSize(0, 30), WebFloatSize(0, 30),
299 WebFloatPoint(100, 100), WebFloatSize())); 298 WebFloatPoint(100, 100), WebFloatSize()));
300 GetWebViewImpl()->HandleInputEvent( 299 GetWebView()->HandleInputEvent(
301 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollUpdate, 0, -30)); 300 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollUpdate, 0, -30));
302 EXPECT_FLOAT_EQ(maximum_scroll, container->scrollTop()); 301 EXPECT_FLOAT_EQ(maximum_scroll, container->scrollTop());
303 EXPECT_FLOAT_EQ(0, MainFrameView()->GetScrollOffset().Height()); 302 EXPECT_FLOAT_EQ(0, MainFrameView()->GetScrollOffset().Height());
304 Mock::VerifyAndClearExpectations(&client); 303 Mock::VerifyAndClearExpectations(&client);
305 304
306 GetWebViewImpl()->HandleInputEvent( 305 GetWebView()->HandleInputEvent(
307 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollEnd)); 306 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollEnd));
308 } 307 }
309 308
310 { 309 {
311 // Scrolling up should show the browser controls. 310 // Scrolling up should show the browser controls.
312 GetWebViewImpl()->HandleInputEvent( 311 GetWebView()->HandleInputEvent(
313 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollBegin)); 312 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollBegin));
314 313
315 EXPECT_FLOAT_EQ(0, GetBrowserControls().ShownRatio()); 314 EXPECT_FLOAT_EQ(0, GetBrowserControls().ShownRatio());
316 GetWebViewImpl()->HandleInputEvent( 315 GetWebView()->HandleInputEvent(
317 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollUpdate, 0, 30)); 316 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollUpdate, 0, 30));
318 EXPECT_FLOAT_EQ(0.6, GetBrowserControls().ShownRatio()); 317 EXPECT_FLOAT_EQ(0.6, GetBrowserControls().ShownRatio());
319 318
320 GetWebViewImpl()->HandleInputEvent( 319 GetWebView()->HandleInputEvent(
321 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollEnd)); 320 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollEnd));
322 } 321 }
323 322
324 // Reset manually to avoid lifetime issues with custom WebViewClient. 323 // Reset manually to avoid lifetime issues with custom WebViewClient.
325 helper_.Reset(); 324 helper_.Reset();
326 } 325 }
327 326
328 // Tests that removing the element that is the root scroller from the DOM tree 327 // Tests that removing the element that is the root scroller from the DOM tree
329 // doesn't remove it as the root scroller but it does change the effective root 328 // doesn't remove it as the root scroller but it does change the effective root
330 // scroller. 329 // scroller.
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 FrameTestHelpers::TestWebRemoteFrameClient remote_client; 676 FrameTestHelpers::TestWebRemoteFrameClient remote_client;
678 FrameTestHelpers::TestWebWidgetClient web_widget_client; 677 FrameTestHelpers::TestWebWidgetClient web_widget_client;
679 WebFrameWidget* widget; 678 WebFrameWidget* widget;
680 WebLocalFrameImpl* local_frame; 679 WebLocalFrameImpl* local_frame;
681 680
682 Initialize("root-scroller-iframe.html"); 681 Initialize("root-scroller-iframe.html");
683 682
684 // Initialization: Set the main frame to be a RemoteFrame and add a local 683 // Initialization: Set the main frame to be a RemoteFrame and add a local
685 // child. 684 // child.
686 { 685 {
687 GetWebViewImpl()->SetMainFrame(remote_client.GetFrame()); 686 GetWebView()->SetMainFrame(remote_client.GetFrame());
688 WebRemoteFrame* root = GetWebViewImpl()->MainFrame()->ToWebRemoteFrame(); 687 WebRemoteFrame* root = GetWebView()->MainFrame()->ToWebRemoteFrame();
689 root->SetReplicatedOrigin(SecurityOrigin::CreateUnique()); 688 root->SetReplicatedOrigin(SecurityOrigin::CreateUnique());
690 WebFrameOwnerProperties properties; 689 WebFrameOwnerProperties properties;
691 local_frame = FrameTestHelpers::CreateLocalChild( 690 local_frame = FrameTestHelpers::CreateLocalChild(
692 root, "frameName", nullptr, nullptr, nullptr, properties); 691 root, "frameName", nullptr, nullptr, nullptr, properties);
693 692
694 FrameTestHelpers::LoadFrame(local_frame, 693 FrameTestHelpers::LoadFrame(local_frame,
695 base_url_ + "root-scroller-child.html"); 694 base_url_ + "root-scroller-child.html");
696 widget = local_frame->FrameWidget(); 695 widget = local_frame->FrameWidget();
697 widget->Resize(WebSize(400, 400)); 696 widget->Resize(WebSize(400, 400));
698 } 697 }
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 EXPECT_FALSE(container_scroller->HorizontalScrollbar()); 837 EXPECT_FALSE(container_scroller->HorizontalScrollbar());
839 EXPECT_FALSE(container_scroller->VerticalScrollbar()); 838 EXPECT_FALSE(container_scroller->VerticalScrollbar());
840 EXPECT_GT(container_scroller->MaximumScrollOffset().Width(), 0); 839 EXPECT_GT(container_scroller->MaximumScrollOffset().Width(), 0);
841 EXPECT_GT(container_scroller->MaximumScrollOffset().Height(), 0); 840 EXPECT_GT(container_scroller->MaximumScrollOffset().Height(), 0);
842 } 841 }
843 842
844 TEST_F(RootScrollerTest, TopControlsAdjustmentAppliedToRootScroller) { 843 TEST_F(RootScrollerTest, TopControlsAdjustmentAppliedToRootScroller) {
845 Initialize(); 844 Initialize();
846 845
847 WebURL base_url = URLTestHelpers::ToKURL("http://www.test.com/"); 846 WebURL base_url = URLTestHelpers::ToKURL("http://www.test.com/");
848 FrameTestHelpers::LoadHTMLString(GetWebViewImpl()->MainFrame(), 847 FrameTestHelpers::LoadHTMLString(GetWebView()->MainFrame(),
849 "<!DOCTYPE html>" 848 "<!DOCTYPE html>"
850 "<style>" 849 "<style>"
851 " body, html {" 850 " body, html {"
852 " width: 100%;" 851 " width: 100%;"
853 " height: 100%;" 852 " height: 100%;"
854 " margin: 0px;" 853 " margin: 0px;"
855 " }" 854 " }"
856 " #container {" 855 " #container {"
857 " width: 100%;" 856 " width: 100%;"
858 " height: 100%;" 857 " height: 100%;"
859 " overflow: auto;" 858 " overflow: auto;"
860 " }" 859 " }"
861 "</style>" 860 "</style>"
862 "<div id='container'>" 861 "<div id='container'>"
863 " <div style='height:1000px'>test</div>" 862 " <div style='height:1000px'>test</div>"
864 "</div>", 863 "</div>",
865 base_url); 864 base_url);
866 865
867 GetWebViewImpl()->ResizeWithBrowserControls(IntSize(400, 400), 50, true); 866 GetWebView()->ResizeWithBrowserControls(IntSize(400, 400), 50, true);
868 MainFrameView()->UpdateAllLifecyclePhases(); 867 MainFrameView()->UpdateAllLifecyclePhases();
869 868
870 Element* container = MainFrame()->GetDocument()->getElementById("container"); 869 Element* container = MainFrame()->GetDocument()->getElementById("container");
871 MainFrame()->GetDocument()->setRootScroller(container, ASSERT_NO_EXCEPTION); 870 MainFrame()->GetDocument()->setRootScroller(container, ASSERT_NO_EXCEPTION);
872 871
873 ScrollableArea* container_scroller = 872 ScrollableArea* container_scroller =
874 static_cast<PaintInvalidationCapableScrollableArea*>( 873 static_cast<PaintInvalidationCapableScrollableArea*>(
875 ToLayoutBox(container->GetLayoutObject())->GetScrollableArea()); 874 ToLayoutBox(container->GetLayoutObject())->GetScrollableArea());
876 875
877 // Hide the top controls and scroll down maximally. We should account for the 876 // Hide the top controls and scroll down maximally. We should account for the
878 // change in maximum scroll offset due to the top controls hiding. That is, 877 // change in maximum scroll offset due to the top controls hiding. That is,
879 // since the controls are hidden, the "content area" is taller so the maximum 878 // since the controls are hidden, the "content area" is taller so the maximum
880 // scroll offset should shrink. 879 // scroll offset should shrink.
881 ASSERT_EQ(1000 - 400, container_scroller->MaximumScrollOffset().Height()); 880 ASSERT_EQ(1000 - 400, container_scroller->MaximumScrollOffset().Height());
882 881
883 GetWebViewImpl()->HandleInputEvent( 882 GetWebView()->HandleInputEvent(
884 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollBegin)); 883 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollBegin));
885 ASSERT_EQ(1, GetBrowserControls().ShownRatio()); 884 ASSERT_EQ(1, GetBrowserControls().ShownRatio());
886 GetWebViewImpl()->HandleInputEvent(GenerateTouchGestureEvent( 885 GetWebView()->HandleInputEvent(GenerateTouchGestureEvent(
887 WebInputEvent::kGestureScrollUpdate, 0, -GetBrowserControls().Height())); 886 WebInputEvent::kGestureScrollUpdate, 0, -GetBrowserControls().Height()));
888 ASSERT_EQ(0, GetBrowserControls().ShownRatio()); 887 ASSERT_EQ(0, GetBrowserControls().ShownRatio());
889 EXPECT_EQ(1000 - 450, container_scroller->MaximumScrollOffset().Height()); 888 EXPECT_EQ(1000 - 450, container_scroller->MaximumScrollOffset().Height());
890 889
891 GetWebViewImpl()->HandleInputEvent( 890 GetWebView()->HandleInputEvent(
892 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollUpdate, 0, -3000)); 891 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollUpdate, 0, -3000));
893 EXPECT_EQ(1000 - 450, container_scroller->GetScrollOffset().Height()); 892 EXPECT_EQ(1000 - 450, container_scroller->GetScrollOffset().Height());
894 893
895 GetWebViewImpl()->HandleInputEvent( 894 GetWebView()->HandleInputEvent(
896 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollEnd)); 895 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollEnd));
897 GetWebViewImpl()->ResizeWithBrowserControls(IntSize(400, 450), 50, false); 896 GetWebView()->ResizeWithBrowserControls(IntSize(400, 450), 50, false);
898 EXPECT_EQ(1000 - 450, container_scroller->MaximumScrollOffset().Height()); 897 EXPECT_EQ(1000 - 450, container_scroller->MaximumScrollOffset().Height());
899 } 898 }
900 899
901 TEST_F(RootScrollerTest, RotationAnchoring) { 900 TEST_F(RootScrollerTest, RotationAnchoring) {
902 Initialize("root-scroller-rotation.html"); 901 Initialize("root-scroller-rotation.html");
903 902
904 ScrollableArea* container_scroller; 903 ScrollableArea* container_scroller;
905 904
906 { 905 {
907 GetWebViewImpl()->ResizeWithBrowserControls(IntSize(250, 1000), 0, true); 906 GetWebView()->ResizeWithBrowserControls(IntSize(250, 1000), 0, true);
908 MainFrameView()->UpdateAllLifecyclePhases(); 907 MainFrameView()->UpdateAllLifecyclePhases();
909 908
910 Element* container = 909 Element* container =
911 MainFrame()->GetDocument()->getElementById("container"); 910 MainFrame()->GetDocument()->getElementById("container");
912 NonThrowableExceptionState non_throw; 911 NonThrowableExceptionState non_throw;
913 MainFrame()->GetDocument()->setRootScroller(container, non_throw); 912 MainFrame()->GetDocument()->setRootScroller(container, non_throw);
914 MainFrameView()->UpdateAllLifecyclePhases(); 913 MainFrameView()->UpdateAllLifecyclePhases();
915 914
916 container_scroller = static_cast<PaintInvalidationCapableScrollableArea*>( 915 container_scroller = static_cast<PaintInvalidationCapableScrollableArea*>(
917 ToLayoutBox(container->GetLayoutObject())->GetScrollableArea()); 916 ToLayoutBox(container->GetLayoutObject())->GetScrollableArea());
918 } 917 }
919 918
920 Element* target = MainFrame()->GetDocument()->getElementById("target"); 919 Element* target = MainFrame()->GetDocument()->getElementById("target");
921 920
922 // Zoom in and scroll the viewport so that the target is fully in the 921 // Zoom in and scroll the viewport so that the target is fully in the
923 // viewport and the visual viewport is fully scrolled within the layout 922 // viewport and the visual viewport is fully scrolled within the layout
924 // viepwort. 923 // viepwort.
925 { 924 {
926 int scroll_x = 250 * 4; 925 int scroll_x = 250 * 4;
927 int scroll_y = 1000 * 4; 926 int scroll_y = 1000 * 4;
928 927
929 GetWebViewImpl()->SetPageScaleFactor(2); 928 GetWebView()->SetPageScaleFactor(2);
930 GetWebViewImpl()->HandleInputEvent( 929 GetWebView()->HandleInputEvent(
931 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollBegin)); 930 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollBegin));
932 GetWebViewImpl()->HandleInputEvent(GenerateTouchGestureEvent( 931 GetWebView()->HandleInputEvent(GenerateTouchGestureEvent(
933 WebInputEvent::kGestureScrollUpdate, -scroll_x, -scroll_y)); 932 WebInputEvent::kGestureScrollUpdate, -scroll_x, -scroll_y));
934 GetWebViewImpl()->HandleInputEvent( 933 GetWebView()->HandleInputEvent(
935 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollEnd)); 934 GenerateTouchGestureEvent(WebInputEvent::kGestureScrollEnd));
936 935
937 // The visual viewport should be 1.5 screens scrolled so that the target 936 // The visual viewport should be 1.5 screens scrolled so that the target
938 // occupies the bottom quadrant of the layout viewport. 937 // occupies the bottom quadrant of the layout viewport.
939 ASSERT_EQ((250 * 3) / 2, container_scroller->GetScrollOffset().Width()); 938 ASSERT_EQ((250 * 3) / 2, container_scroller->GetScrollOffset().Width());
940 ASSERT_EQ((1000 * 3) / 2, container_scroller->GetScrollOffset().Height()); 939 ASSERT_EQ((1000 * 3) / 2, container_scroller->GetScrollOffset().Height());
941 940
942 // The visual viewport should have scrolled the last half layout viewport. 941 // The visual viewport should have scrolled the last half layout viewport.
943 ASSERT_EQ((250) / 2, GetVisualViewport().GetScrollOffset().Width()); 942 ASSERT_EQ((250) / 2, GetVisualViewport().GetScrollOffset().Width());
944 ASSERT_EQ((1000) / 2, GetVisualViewport().GetScrollOffset().Height()); 943 ASSERT_EQ((1000) / 2, GetVisualViewport().GetScrollOffset().Height());
945 } 944 }
946 945
947 // Now do a rotation resize. 946 // Now do a rotation resize.
948 GetWebViewImpl()->ResizeWithBrowserControls(IntSize(1000, 250), 50, false); 947 GetWebView()->ResizeWithBrowserControls(IntSize(1000, 250), 50, false);
949 MainFrameView()->UpdateAllLifecyclePhases(); 948 MainFrameView()->UpdateAllLifecyclePhases();
950 949
951 // The visual viewport should remain fully filled by the target. 950 // The visual viewport should remain fully filled by the target.
952 ClientRect* rect = target->getBoundingClientRect(); 951 ClientRect* rect = target->getBoundingClientRect();
953 EXPECT_EQ(rect->left(), GetVisualViewport().GetScrollOffset().Width()); 952 EXPECT_EQ(rect->left(), GetVisualViewport().GetScrollOffset().Width());
954 EXPECT_EQ(rect->top(), GetVisualViewport().GetScrollOffset().Height()); 953 EXPECT_EQ(rect->top(), GetVisualViewport().GetScrollOffset().Height());
955 } 954 }
956 955
957 // Tests that we don't crash if the default documentElement isn't a valid root 956 // Tests that we don't crash if the default documentElement isn't a valid root
958 // scroller. This can happen in some edge cases where documentElement isn't 957 // scroller. This can happen in some edge cases where documentElement isn't
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 // FrameView without a layout. 997 // FrameView without a layout.
999 iframe->remove(); 998 iframe->remove();
1000 999
1001 EXPECT_EQ(MainFrameView()->LayoutViewportScrollableArea(), 1000 EXPECT_EQ(MainFrameView()->LayoutViewportScrollableArea(),
1002 &MainFrameView()->GetRootFrameViewport()->LayoutViewport()); 1001 &MainFrameView()->GetRootFrameViewport()->LayoutViewport());
1003 } 1002 }
1004 1003
1005 } // namespace 1004 } // namespace
1006 1005
1007 } // namespace blink 1006 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698