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

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

Issue 2936423003: Move Get/SetScrollOffset methods from WebFrame to WebLocalFrame. (Closed)
Patch Set: Added TODOs as suggested by dcheng@ (this patchset also accidentally includes a rebase...). Created 3 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 3032 matching lines...) Expand 10 before | Expand all | Expand 10 after
3043 ASSERT_EQ(initial_page_scale_factor, 3043 ASSERT_EQ(initial_page_scale_factor,
3044 web_view_helper.WebView()->PageScaleFactor()); 3044 web_view_helper.WebView()->PageScaleFactor());
3045 web_view_helper.Resize( 3045 web_view_helper.Resize(
3046 WebSize(viewport_size.height, viewport_size.width)); 3046 WebSize(viewport_size.height, viewport_size.width));
3047 float expected_page_scale_factor = 3047 float expected_page_scale_factor =
3048 initial_page_scale_factor * 3048 initial_page_scale_factor *
3049 (should_scale_relative_to_viewport_width ? 1 / aspect_ratio : 1); 3049 (should_scale_relative_to_viewport_width ? 1 / aspect_ratio : 1);
3050 EXPECT_NEAR(expected_page_scale_factor, 3050 EXPECT_NEAR(expected_page_scale_factor,
3051 web_view_helper.WebView()->PageScaleFactor(), 0.05f); 3051 web_view_helper.WebView()->PageScaleFactor(), 0.05f);
3052 EXPECT_EQ(WebSize(), 3052 EXPECT_EQ(WebSize(),
3053 web_view_helper.WebView()->MainFrame()->GetScrollOffset()); 3053 web_view_helper.WebView()->MainFrameImpl()->GetScrollOffset());
3054 } 3054 }
3055 3055
3056 // Resizing just the height should not affect pageScaleFactor or 3056 // Resizing just the height should not affect pageScaleFactor or
3057 // scrollOffset. 3057 // scrollOffset.
3058 { 3058 {
3059 web_view_helper.Resize( 3059 web_view_helper.Resize(
3060 WebSize(viewport_size.width, viewport_size.height)); 3060 WebSize(viewport_size.width, viewport_size.height));
3061 web_view_helper.WebView()->SetPageScaleFactor(initial_page_scale_factor); 3061 web_view_helper.WebView()->SetPageScaleFactor(initial_page_scale_factor);
3062 web_view_helper.WebView()->MainFrame()->SetScrollOffset(scroll_offset); 3062 web_view_helper.WebView()->MainFrameImpl()->SetScrollOffset(
3063 scroll_offset);
3063 web_view_helper.WebView()->UpdateAllLifecyclePhases(); 3064 web_view_helper.WebView()->UpdateAllLifecyclePhases();
3064 const WebSize expected_scroll_offset = 3065 const WebSize expected_scroll_offset =
3065 web_view_helper.WebView()->MainFrame()->GetScrollOffset(); 3066 web_view_helper.WebView()->MainFrameImpl()->GetScrollOffset();
3066 web_view_helper.Resize( 3067 web_view_helper.Resize(
3067 WebSize(viewport_size.width, viewport_size.height * 0.8f)); 3068 WebSize(viewport_size.width, viewport_size.height * 0.8f));
3068 EXPECT_EQ(initial_page_scale_factor, 3069 EXPECT_EQ(initial_page_scale_factor,
3069 web_view_helper.WebView()->PageScaleFactor()); 3070 web_view_helper.WebView()->PageScaleFactor());
3070 EXPECT_EQ(expected_scroll_offset, 3071 EXPECT_EQ(expected_scroll_offset,
3071 web_view_helper.WebView()->MainFrame()->GetScrollOffset()); 3072 web_view_helper.WebView()->MainFrameImpl()->GetScrollOffset());
3072 web_view_helper.Resize( 3073 web_view_helper.Resize(
3073 WebSize(viewport_size.width, viewport_size.height * 0.8f)); 3074 WebSize(viewport_size.width, viewport_size.height * 0.8f));
3074 EXPECT_EQ(initial_page_scale_factor, 3075 EXPECT_EQ(initial_page_scale_factor,
3075 web_view_helper.WebView()->PageScaleFactor()); 3076 web_view_helper.WebView()->PageScaleFactor());
3076 EXPECT_EQ(expected_scroll_offset, 3077 EXPECT_EQ(expected_scroll_offset,
3077 web_view_helper.WebView()->MainFrame()->GetScrollOffset()); 3078 web_view_helper.WebView()->MainFrameImpl()->GetScrollOffset());
3078 } 3079 }
3079 } 3080 }
3080 }; 3081 };
3081 3082
3082 INSTANTIATE_TEST_CASE_P(All, WebFrameResizeTest, ::testing::Bool()); 3083 INSTANTIATE_TEST_CASE_P(All, WebFrameResizeTest, ::testing::Bool());
3083 3084
3084 TEST_P(WebFrameResizeTest, 3085 TEST_P(WebFrameResizeTest,
3085 ResizeYieldsCorrectScrollAndScaleForWidthEqualsDeviceWidth) { 3086 ResizeYieldsCorrectScrollAndScaleForWidthEqualsDeviceWidth) {
3086 // With width=device-width, pageScaleFactor is preserved across resizes as 3087 // With width=device-width, pageScaleFactor is preserved across resizes as
3087 // long as the content adjusts according to the device-width. 3088 // long as the content adjusts according to the device-width.
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
3235 EXPECT_FALSE( 3236 EXPECT_FALSE(
3236 view->GetLayoutViewItem().Compositor()->LayerForHorizontalScrollbar()); 3237 view->GetLayoutViewItem().Compositor()->LayerForHorizontalScrollbar());
3237 EXPECT_FALSE( 3238 EXPECT_FALSE(
3238 view->GetLayoutViewItem().Compositor()->LayerForVerticalScrollbar()); 3239 view->GetLayoutViewItem().Compositor()->LayerForVerticalScrollbar());
3239 } 3240 }
3240 3241
3241 void SetScaleAndScrollAndLayout(WebViewBase* web_view, 3242 void SetScaleAndScrollAndLayout(WebViewBase* web_view,
3242 WebPoint scroll, 3243 WebPoint scroll,
3243 float scale) { 3244 float scale) {
3244 web_view->SetPageScaleFactor(scale); 3245 web_view->SetPageScaleFactor(scale);
3245 web_view->MainFrame()->SetScrollOffset(WebSize(scroll.x, scroll.y)); 3246 web_view->MainFrameImpl()->SetScrollOffset(WebSize(scroll.x, scroll.y));
3246 web_view->UpdateAllLifecyclePhases(); 3247 web_view->UpdateAllLifecyclePhases();
3247 } 3248 }
3248 3249
3249 void SimulatePageScale(WebViewBase* web_view_impl, float& scale) { 3250 void SimulatePageScale(WebViewBase* web_view_impl, float& scale) {
3250 ScrollOffset scroll_delta = 3251 ScrollOffset scroll_delta =
3251 ToScrollOffset( 3252 ToScrollOffset(
3252 web_view_impl->FakePageScaleAnimationTargetPositionForTesting()) - 3253 web_view_impl->FakePageScaleAnimationTargetPositionForTesting()) -
3253 web_view_impl->MainFrameImpl()->GetFrameView()->GetScrollOffset(); 3254 web_view_impl->MainFrameImpl()->GetFrameView()->GetScrollOffset();
3254 float scale_delta = 3255 float scale_delta =
3255 web_view_impl->FakePageScaleAnimationPageScaleForTesting() / 3256 web_view_impl->FakePageScaleAnimationPageScaleForTesting() /
(...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after
4236 const int kPageHeight = 100; 4237 const int kPageHeight = 100;
4237 4238
4238 RegisterMockedHttpURLLoad(first_url); 4239 RegisterMockedHttpURLLoad(first_url);
4239 RegisterMockedHttpURLLoad(second_url); 4240 RegisterMockedHttpURLLoad(second_url);
4240 RegisterMockedHttpURLLoad(third_url); 4241 RegisterMockedHttpURLLoad(third_url);
4241 4242
4242 ClearScrollStateOnCommitWebFrameClient client; 4243 ClearScrollStateOnCommitWebFrameClient client;
4243 FrameTestHelpers::WebViewHelper web_view_helper; 4244 FrameTestHelpers::WebViewHelper web_view_helper;
4244 web_view_helper.InitializeAndLoad(base_url_ + first_url, &client); 4245 web_view_helper.InitializeAndLoad(base_url_ + first_url, &client);
4245 web_view_helper.Resize(WebSize(kPageWidth, kPageHeight)); 4246 web_view_helper.Resize(WebSize(kPageWidth, kPageHeight));
4246 web_view_helper.WebView()->MainFrame()->SetScrollOffset( 4247 web_view_helper.WebView()->MainFrameImpl()->SetScrollOffset(
4247 WebSize(kPageWidth / 4, kPageHeight / 4)); 4248 WebSize(kPageWidth / 4, kPageHeight / 4));
4248 web_view_helper.WebView()->SetPageScaleFactor(kPageScaleFactor); 4249 web_view_helper.WebView()->SetPageScaleFactor(kPageScaleFactor);
4249 4250
4250 // Reload the page and end up at the same url. State should not be propagated. 4251 // Reload the page and end up at the same url. State should not be propagated.
4251 web_view_helper.WebView()->MainFrame()->ReloadWithOverrideURL( 4252 web_view_helper.WebView()->MainFrame()->ReloadWithOverrideURL(
4252 ToKURL(base_url_ + first_url), WebFrameLoadType::kReload); 4253 ToKURL(base_url_ + first_url), WebFrameLoadType::kReload);
4253 FrameTestHelpers::PumpPendingRequestsForFrameToLoad( 4254 FrameTestHelpers::PumpPendingRequestsForFrameToLoad(
4254 web_view_helper.WebView()->MainFrame()); 4255 web_view_helper.WebView()->MainFrame());
4255 EXPECT_EQ(0, web_view_helper.WebView()->MainFrame()->GetScrollOffset().width); 4256 EXPECT_EQ(
4256 EXPECT_EQ(0, 4257 0, web_view_helper.WebView()->MainFrameImpl()->GetScrollOffset().width);
4257 web_view_helper.WebView()->MainFrame()->GetScrollOffset().height); 4258 EXPECT_EQ(
4259 0, web_view_helper.WebView()->MainFrameImpl()->GetScrollOffset().height);
4258 EXPECT_EQ(1.0f, web_view_helper.WebView()->PageScaleFactor()); 4260 EXPECT_EQ(1.0f, web_view_helper.WebView()->PageScaleFactor());
4259 4261
4260 // Reload the page using the cache. State should not be propagated. 4262 // Reload the page using the cache. State should not be propagated.
4261 web_view_helper.WebView()->MainFrame()->ReloadWithOverrideURL( 4263 web_view_helper.WebView()->MainFrame()->ReloadWithOverrideURL(
4262 ToKURL(base_url_ + second_url), WebFrameLoadType::kReload); 4264 ToKURL(base_url_ + second_url), WebFrameLoadType::kReload);
4263 FrameTestHelpers::PumpPendingRequestsForFrameToLoad( 4265 FrameTestHelpers::PumpPendingRequestsForFrameToLoad(
4264 web_view_helper.WebView()->MainFrame()); 4266 web_view_helper.WebView()->MainFrame());
4265 EXPECT_EQ(0, web_view_helper.WebView()->MainFrame()->GetScrollOffset().width); 4267 EXPECT_EQ(
4266 EXPECT_EQ(0, 4268 0, web_view_helper.WebView()->MainFrameImpl()->GetScrollOffset().width);
4267 web_view_helper.WebView()->MainFrame()->GetScrollOffset().height); 4269 EXPECT_EQ(
4270 0, web_view_helper.WebView()->MainFrameImpl()->GetScrollOffset().height);
4268 EXPECT_EQ(1.0f, web_view_helper.WebView()->PageScaleFactor()); 4271 EXPECT_EQ(1.0f, web_view_helper.WebView()->PageScaleFactor());
4269 4272
4270 // Reload the page while bypassing the cache. State should not be propagated. 4273 // Reload the page while bypassing the cache. State should not be propagated.
4271 web_view_helper.WebView()->MainFrame()->ReloadWithOverrideURL( 4274 web_view_helper.WebView()->MainFrame()->ReloadWithOverrideURL(
4272 ToKURL(base_url_ + third_url), WebFrameLoadType::kReloadBypassingCache); 4275 ToKURL(base_url_ + third_url), WebFrameLoadType::kReloadBypassingCache);
4273 FrameTestHelpers::PumpPendingRequestsForFrameToLoad( 4276 FrameTestHelpers::PumpPendingRequestsForFrameToLoad(
4274 web_view_helper.WebView()->MainFrame()); 4277 web_view_helper.WebView()->MainFrame());
4275 EXPECT_EQ(0, web_view_helper.WebView()->MainFrame()->GetScrollOffset().width); 4278 EXPECT_EQ(
4276 EXPECT_EQ(0, 4279 0, web_view_helper.WebView()->MainFrameImpl()->GetScrollOffset().width);
4277 web_view_helper.WebView()->MainFrame()->GetScrollOffset().height); 4280 EXPECT_EQ(
4281 0, web_view_helper.WebView()->MainFrameImpl()->GetScrollOffset().height);
4278 EXPECT_EQ(1.0f, web_view_helper.WebView()->PageScaleFactor()); 4282 EXPECT_EQ(1.0f, web_view_helper.WebView()->PageScaleFactor());
4279 } 4283 }
4280 4284
4281 TEST_P(ParameterizedWebFrameTest, ReloadWhileProvisional) { 4285 TEST_P(ParameterizedWebFrameTest, ReloadWhileProvisional) {
4282 // Test that reloading while the previous load is still pending does not cause 4286 // Test that reloading while the previous load is still pending does not cause
4283 // the initial request to get lost. 4287 // the initial request to get lost.
4284 RegisterMockedHttpURLLoad("fixed_layout.html"); 4288 RegisterMockedHttpURLLoad("fixed_layout.html");
4285 4289
4286 FrameTestHelpers::WebViewHelper web_view_helper; 4290 FrameTestHelpers::WebViewHelper web_view_helper;
4287 web_view_helper.Initialize(); 4291 web_view_helper.Initialize();
(...skipping 2029 matching lines...) Expand 10 before | Expand all | Expand 10 after
6317 nullptr, ConfigureAndroid); 6321 nullptr, ConfigureAndroid);
6318 6322
6319 WebViewBase* web_view_impl = web_view_helper.WebView(); 6323 WebViewBase* web_view_impl = web_view_helper.WebView();
6320 ASSERT_TRUE(web_view_impl); 6324 ASSERT_TRUE(web_view_impl);
6321 LocalFrame* frame = web_view_impl->MainFrameImpl()->GetFrame(); 6325 LocalFrame* frame = web_view_impl->MainFrameImpl()->GetFrame();
6322 ASSERT_TRUE(frame); 6326 ASSERT_TRUE(frame);
6323 6327
6324 web_view_helper.Resize(WebSize(100, 200)); 6328 web_view_helper.Resize(WebSize(100, 200));
6325 6329
6326 // Scroll main frame to the bottom of the document 6330 // Scroll main frame to the bottom of the document
6327 web_view_impl->MainFrame()->SetScrollOffset(WebSize(0, 400)); 6331 web_view_impl->MainFrameImpl()->SetScrollOffset(WebSize(0, 400));
6328 EXPECT_SIZE_EQ(ScrollOffset(0, 400), frame->View()->GetScrollOffset()); 6332 EXPECT_SIZE_EQ(ScrollOffset(0, 400), frame->View()->GetScrollOffset());
6329 6333
6330 web_view_impl->SetPageScaleFactor(2.0); 6334 web_view_impl->SetPageScaleFactor(2.0);
6331 6335
6332 // Scroll visual viewport to the top of the main frame. 6336 // Scroll visual viewport to the top of the main frame.
6333 VisualViewport& visual_viewport = frame->GetPage()->GetVisualViewport(); 6337 VisualViewport& visual_viewport = frame->GetPage()->GetVisualViewport();
6334 visual_viewport.SetLocation(FloatPoint(0, 0)); 6338 visual_viewport.SetLocation(FloatPoint(0, 0));
6335 EXPECT_SIZE_EQ(ScrollOffset(0, 0), visual_viewport.GetScrollOffset()); 6339 EXPECT_SIZE_EQ(ScrollOffset(0, 0), visual_viewport.GetScrollOffset());
6336 6340
6337 // Tap at the top: there is nothing there. 6341 // Tap at the top: there is nothing there.
(...skipping 1549 matching lines...) Expand 10 before | Expand all | Expand 10 after
7887 WebViewBase* web_view = web_view_helper.WebView(); 7891 WebViewBase* web_view = web_view_helper.WebView();
7888 LocalFrameView* frame_view = 7892 LocalFrameView* frame_view =
7889 web_view_helper.WebView()->MainFrameImpl()->GetFrameView(); 7893 web_view_helper.WebView()->MainFrameImpl()->GetFrameView();
7890 7894
7891 float browser_controls_height = 40; 7895 float browser_controls_height = 40;
7892 web_view->ResizeWithBrowserControls(WebSize(100, 100), 7896 web_view->ResizeWithBrowserControls(WebSize(100, 100),
7893 browser_controls_height, false); 7897 browser_controls_height, false);
7894 web_view->SetPageScaleFactor(2.0f); 7898 web_view->SetPageScaleFactor(2.0f);
7895 web_view->UpdateAllLifecyclePhases(); 7899 web_view->UpdateAllLifecyclePhases();
7896 7900
7897 web_view->MainFrame()->SetScrollOffset(WebSize(0, 2000)); 7901 web_view->MainFrameImpl()->SetScrollOffset(WebSize(0, 2000));
7898 EXPECT_SIZE_EQ(ScrollOffset(0, 1900), frame_view->GetScrollOffset()); 7902 EXPECT_SIZE_EQ(ScrollOffset(0, 1900), frame_view->GetScrollOffset());
7899 7903
7900 // Simulate the browser controls showing by 20px, thus shrinking the viewport 7904 // Simulate the browser controls showing by 20px, thus shrinking the viewport
7901 // and allowing it to scroll an additional 20px. 7905 // and allowing it to scroll an additional 20px.
7902 web_view->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), 7906 web_view->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(),
7903 1.0f, 20.0f / browser_controls_height); 7907 1.0f, 20.0f / browser_controls_height);
7904 EXPECT_SIZE_EQ(ScrollOffset(0, 1920), frame_view->MaximumScrollOffset()); 7908 EXPECT_SIZE_EQ(ScrollOffset(0, 1920), frame_view->MaximumScrollOffset());
7905 7909
7906 // Show more, make sure the scroll actually gets clamped. 7910 // Show more, make sure the scroll actually gets clamped.
7907 web_view->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), 7911 web_view->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(),
7908 1.0f, 20.0f / browser_controls_height); 7912 1.0f, 20.0f / browser_controls_height);
7909 web_view->MainFrame()->SetScrollOffset(WebSize(0, 2000)); 7913 web_view->MainFrameImpl()->SetScrollOffset(WebSize(0, 2000));
7910 EXPECT_SIZE_EQ(ScrollOffset(0, 1940), frame_view->GetScrollOffset()); 7914 EXPECT_SIZE_EQ(ScrollOffset(0, 1940), frame_view->GetScrollOffset());
7911 7915
7912 // Hide until there's 10px showing. 7916 // Hide until there's 10px showing.
7913 web_view->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), 7917 web_view->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(),
7914 1.0f, -30.0f / browser_controls_height); 7918 1.0f, -30.0f / browser_controls_height);
7915 EXPECT_SIZE_EQ(ScrollOffset(0, 1910), frame_view->MaximumScrollOffset()); 7919 EXPECT_SIZE_EQ(ScrollOffset(0, 1910), frame_view->MaximumScrollOffset());
7916 7920
7917 // Simulate a LayoutEmbeddedContent::resize. The frame is resized to 7921 // Simulate a LayoutEmbeddedContent::resize. The frame is resized to
7918 // accomodate the browser controls and Blink's view of the browser controls 7922 // accomodate the browser controls and Blink's view of the browser controls
7919 // matches that of the CC 7923 // matches that of the CC
(...skipping 4298 matching lines...) Expand 10 before | Expand all | Expand 10 after
12218 if (obj->IsText()) { 12222 if (obj->IsText()) {
12219 LayoutText* layout_text = ToLayoutText(obj); 12223 LayoutText* layout_text = ToLayoutText(obj);
12220 text = layout_text->GetText(); 12224 text = layout_text->GetText();
12221 break; 12225 break;
12222 } 12226 }
12223 } 12227 }
12224 EXPECT_EQ("foo alt", text.Utf8()); 12228 EXPECT_EQ("foo alt", text.Utf8());
12225 } 12229 }
12226 12230
12227 } // namespace blink 12231 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698