| OLD | NEW |
| 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 3018 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3029 ASSERT_EQ(viewport_size, web_view_helper.WebView()->Size()); | 3029 ASSERT_EQ(viewport_size, web_view_helper.WebView()->Size()); |
| 3030 ASSERT_EQ(initial_page_scale_factor, | 3030 ASSERT_EQ(initial_page_scale_factor, |
| 3031 web_view_helper.WebView()->PageScaleFactor()); | 3031 web_view_helper.WebView()->PageScaleFactor()); |
| 3032 web_view_helper.Resize( | 3032 web_view_helper.Resize( |
| 3033 WebSize(viewport_size.height, viewport_size.width)); | 3033 WebSize(viewport_size.height, viewport_size.width)); |
| 3034 float expected_page_scale_factor = | 3034 float expected_page_scale_factor = |
| 3035 initial_page_scale_factor * | 3035 initial_page_scale_factor * |
| 3036 (should_scale_relative_to_viewport_width ? 1 / aspect_ratio : 1); | 3036 (should_scale_relative_to_viewport_width ? 1 / aspect_ratio : 1); |
| 3037 EXPECT_NEAR(expected_page_scale_factor, | 3037 EXPECT_NEAR(expected_page_scale_factor, |
| 3038 web_view_helper.WebView()->PageScaleFactor(), 0.05f); | 3038 web_view_helper.WebView()->PageScaleFactor(), 0.05f); |
| 3039 EXPECT_EQ(WebSize(), | 3039 EXPECT_EQ(WebSize(), web_view_helper.LocalMainFrame()->GetScrollOffset()); |
| 3040 web_view_helper.WebView()->MainFrame()->GetScrollOffset()); | |
| 3041 } | 3040 } |
| 3042 | 3041 |
| 3043 // Resizing just the height should not affect pageScaleFactor or | 3042 // Resizing just the height should not affect pageScaleFactor or |
| 3044 // scrollOffset. | 3043 // scrollOffset. |
| 3045 { | 3044 { |
| 3046 web_view_helper.Resize( | 3045 web_view_helper.Resize( |
| 3047 WebSize(viewport_size.width, viewport_size.height)); | 3046 WebSize(viewport_size.width, viewport_size.height)); |
| 3048 web_view_helper.WebView()->SetPageScaleFactor(initial_page_scale_factor); | 3047 web_view_helper.WebView()->SetPageScaleFactor(initial_page_scale_factor); |
| 3049 web_view_helper.WebView()->MainFrame()->SetScrollOffset(scroll_offset); | 3048 web_view_helper.LocalMainFrame()->SetScrollOffset(scroll_offset); |
| 3050 web_view_helper.WebView()->UpdateAllLifecyclePhases(); | 3049 web_view_helper.WebView()->UpdateAllLifecyclePhases(); |
| 3051 const WebSize expected_scroll_offset = | 3050 const WebSize expected_scroll_offset = |
| 3052 web_view_helper.WebView()->MainFrame()->GetScrollOffset(); | 3051 web_view_helper.LocalMainFrame()->GetScrollOffset(); |
| 3053 web_view_helper.Resize( | 3052 web_view_helper.Resize( |
| 3054 WebSize(viewport_size.width, viewport_size.height * 0.8f)); | 3053 WebSize(viewport_size.width, viewport_size.height * 0.8f)); |
| 3055 EXPECT_EQ(initial_page_scale_factor, | 3054 EXPECT_EQ(initial_page_scale_factor, |
| 3056 web_view_helper.WebView()->PageScaleFactor()); | 3055 web_view_helper.WebView()->PageScaleFactor()); |
| 3057 EXPECT_EQ(expected_scroll_offset, | 3056 EXPECT_EQ(expected_scroll_offset, |
| 3058 web_view_helper.WebView()->MainFrame()->GetScrollOffset()); | 3057 web_view_helper.LocalMainFrame()->GetScrollOffset()); |
| 3059 web_view_helper.Resize( | 3058 web_view_helper.Resize( |
| 3060 WebSize(viewport_size.width, viewport_size.height * 0.8f)); | 3059 WebSize(viewport_size.width, viewport_size.height * 0.8f)); |
| 3061 EXPECT_EQ(initial_page_scale_factor, | 3060 EXPECT_EQ(initial_page_scale_factor, |
| 3062 web_view_helper.WebView()->PageScaleFactor()); | 3061 web_view_helper.WebView()->PageScaleFactor()); |
| 3063 EXPECT_EQ(expected_scroll_offset, | 3062 EXPECT_EQ(expected_scroll_offset, |
| 3064 web_view_helper.WebView()->MainFrame()->GetScrollOffset()); | 3063 web_view_helper.LocalMainFrame()->GetScrollOffset()); |
| 3065 } | 3064 } |
| 3066 } | 3065 } |
| 3067 }; | 3066 }; |
| 3068 | 3067 |
| 3069 INSTANTIATE_TEST_CASE_P(All, WebFrameResizeTest, ::testing::Bool()); | 3068 INSTANTIATE_TEST_CASE_P(All, WebFrameResizeTest, ::testing::Bool()); |
| 3070 | 3069 |
| 3071 TEST_P(WebFrameResizeTest, | 3070 TEST_P(WebFrameResizeTest, |
| 3072 ResizeYieldsCorrectScrollAndScaleForWidthEqualsDeviceWidth) { | 3071 ResizeYieldsCorrectScrollAndScaleForWidthEqualsDeviceWidth) { |
| 3073 // With width=device-width, pageScaleFactor is preserved across resizes as | 3072 // With width=device-width, pageScaleFactor is preserved across resizes as |
| 3074 // long as the content adjusts according to the device-width. | 3073 // long as the content adjusts according to the device-width. |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3222 EXPECT_FALSE( | 3221 EXPECT_FALSE( |
| 3223 view->GetLayoutViewItem().Compositor()->LayerForHorizontalScrollbar()); | 3222 view->GetLayoutViewItem().Compositor()->LayerForHorizontalScrollbar()); |
| 3224 EXPECT_FALSE( | 3223 EXPECT_FALSE( |
| 3225 view->GetLayoutViewItem().Compositor()->LayerForVerticalScrollbar()); | 3224 view->GetLayoutViewItem().Compositor()->LayerForVerticalScrollbar()); |
| 3226 } | 3225 } |
| 3227 | 3226 |
| 3228 void SetScaleAndScrollAndLayout(WebViewBase* web_view, | 3227 void SetScaleAndScrollAndLayout(WebViewBase* web_view, |
| 3229 WebPoint scroll, | 3228 WebPoint scroll, |
| 3230 float scale) { | 3229 float scale) { |
| 3231 web_view->SetPageScaleFactor(scale); | 3230 web_view->SetPageScaleFactor(scale); |
| 3232 web_view->MainFrame()->SetScrollOffset(WebSize(scroll.x, scroll.y)); | 3231 web_view->MainFrameImpl()->SetScrollOffset(WebSize(scroll.x, scroll.y)); |
| 3233 web_view->UpdateAllLifecyclePhases(); | 3232 web_view->UpdateAllLifecyclePhases(); |
| 3234 } | 3233 } |
| 3235 | 3234 |
| 3236 void SimulatePageScale(WebViewBase* web_view_impl, float& scale) { | 3235 void SimulatePageScale(WebViewBase* web_view_impl, float& scale) { |
| 3237 ScrollOffset scroll_delta = | 3236 ScrollOffset scroll_delta = |
| 3238 ToScrollOffset( | 3237 ToScrollOffset( |
| 3239 web_view_impl->FakePageScaleAnimationTargetPositionForTesting()) - | 3238 web_view_impl->FakePageScaleAnimationTargetPositionForTesting()) - |
| 3240 web_view_impl->MainFrameImpl()->GetFrameView()->GetScrollOffset(); | 3239 web_view_impl->MainFrameImpl()->GetFrameView()->GetScrollOffset(); |
| 3241 float scale_delta = | 3240 float scale_delta = |
| 3242 web_view_impl->FakePageScaleAnimationPageScaleForTesting() / | 3241 web_view_impl->FakePageScaleAnimationPageScaleForTesting() / |
| (...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4223 const int kPageHeight = 100; | 4222 const int kPageHeight = 100; |
| 4224 | 4223 |
| 4225 RegisterMockedHttpURLLoad(first_url); | 4224 RegisterMockedHttpURLLoad(first_url); |
| 4226 RegisterMockedHttpURLLoad(second_url); | 4225 RegisterMockedHttpURLLoad(second_url); |
| 4227 RegisterMockedHttpURLLoad(third_url); | 4226 RegisterMockedHttpURLLoad(third_url); |
| 4228 | 4227 |
| 4229 ClearScrollStateOnCommitWebFrameClient client; | 4228 ClearScrollStateOnCommitWebFrameClient client; |
| 4230 FrameTestHelpers::WebViewHelper web_view_helper; | 4229 FrameTestHelpers::WebViewHelper web_view_helper; |
| 4231 web_view_helper.InitializeAndLoad(base_url_ + first_url, &client); | 4230 web_view_helper.InitializeAndLoad(base_url_ + first_url, &client); |
| 4232 web_view_helper.Resize(WebSize(kPageWidth, kPageHeight)); | 4231 web_view_helper.Resize(WebSize(kPageWidth, kPageHeight)); |
| 4233 web_view_helper.WebView()->MainFrame()->SetScrollOffset( | 4232 web_view_helper.LocalMainFrame()->SetScrollOffset( |
| 4234 WebSize(kPageWidth / 4, kPageHeight / 4)); | 4233 WebSize(kPageWidth / 4, kPageHeight / 4)); |
| 4235 web_view_helper.WebView()->SetPageScaleFactor(kPageScaleFactor); | 4234 web_view_helper.WebView()->SetPageScaleFactor(kPageScaleFactor); |
| 4236 | 4235 |
| 4237 // Reload the page and end up at the same url. State should not be propagated. | 4236 // Reload the page and end up at the same url. State should not be propagated. |
| 4238 web_view_helper.WebView()->MainFrameImpl()->ReloadWithOverrideURL( | 4237 web_view_helper.WebView()->MainFrameImpl()->ReloadWithOverrideURL( |
| 4239 ToKURL(base_url_ + first_url), WebFrameLoadType::kReload); | 4238 ToKURL(base_url_ + first_url), WebFrameLoadType::kReload); |
| 4240 FrameTestHelpers::PumpPendingRequestsForFrameToLoad( | 4239 FrameTestHelpers::PumpPendingRequestsForFrameToLoad( |
| 4241 web_view_helper.WebView()->MainFrame()); | 4240 web_view_helper.WebView()->MainFrame()); |
| 4242 EXPECT_EQ(0, web_view_helper.WebView()->MainFrame()->GetScrollOffset().width); | 4241 EXPECT_EQ(0, web_view_helper.LocalMainFrame()->GetScrollOffset().width); |
| 4243 EXPECT_EQ(0, | 4242 EXPECT_EQ(0, web_view_helper.LocalMainFrame()->GetScrollOffset().height); |
| 4244 web_view_helper.WebView()->MainFrame()->GetScrollOffset().height); | |
| 4245 EXPECT_EQ(1.0f, web_view_helper.WebView()->PageScaleFactor()); | 4243 EXPECT_EQ(1.0f, web_view_helper.WebView()->PageScaleFactor()); |
| 4246 | 4244 |
| 4247 // Reload the page using the cache. State should not be propagated. | 4245 // Reload the page using the cache. State should not be propagated. |
| 4248 web_view_helper.WebView()->MainFrameImpl()->ReloadWithOverrideURL( | 4246 web_view_helper.WebView()->MainFrameImpl()->ReloadWithOverrideURL( |
| 4249 ToKURL(base_url_ + second_url), WebFrameLoadType::kReload); | 4247 ToKURL(base_url_ + second_url), WebFrameLoadType::kReload); |
| 4250 FrameTestHelpers::PumpPendingRequestsForFrameToLoad( | 4248 FrameTestHelpers::PumpPendingRequestsForFrameToLoad( |
| 4251 web_view_helper.WebView()->MainFrame()); | 4249 web_view_helper.WebView()->MainFrame()); |
| 4252 EXPECT_EQ(0, web_view_helper.WebView()->MainFrame()->GetScrollOffset().width); | 4250 EXPECT_EQ(0, web_view_helper.LocalMainFrame()->GetScrollOffset().width); |
| 4253 EXPECT_EQ(0, | 4251 EXPECT_EQ(0, web_view_helper.LocalMainFrame()->GetScrollOffset().height); |
| 4254 web_view_helper.WebView()->MainFrame()->GetScrollOffset().height); | |
| 4255 EXPECT_EQ(1.0f, web_view_helper.WebView()->PageScaleFactor()); | 4252 EXPECT_EQ(1.0f, web_view_helper.WebView()->PageScaleFactor()); |
| 4256 | 4253 |
| 4257 // Reload the page while bypassing the cache. State should not be propagated. | 4254 // Reload the page while bypassing the cache. State should not be propagated. |
| 4258 web_view_helper.WebView()->MainFrameImpl()->ReloadWithOverrideURL( | 4255 web_view_helper.WebView()->MainFrameImpl()->ReloadWithOverrideURL( |
| 4259 ToKURL(base_url_ + third_url), WebFrameLoadType::kReloadBypassingCache); | 4256 ToKURL(base_url_ + third_url), WebFrameLoadType::kReloadBypassingCache); |
| 4260 FrameTestHelpers::PumpPendingRequestsForFrameToLoad( | 4257 FrameTestHelpers::PumpPendingRequestsForFrameToLoad( |
| 4261 web_view_helper.WebView()->MainFrame()); | 4258 web_view_helper.WebView()->MainFrame()); |
| 4262 EXPECT_EQ(0, web_view_helper.WebView()->MainFrame()->GetScrollOffset().width); | 4259 EXPECT_EQ(0, web_view_helper.LocalMainFrame()->GetScrollOffset().width); |
| 4263 EXPECT_EQ(0, | 4260 EXPECT_EQ(0, web_view_helper.LocalMainFrame()->GetScrollOffset().height); |
| 4264 web_view_helper.WebView()->MainFrame()->GetScrollOffset().height); | |
| 4265 EXPECT_EQ(1.0f, web_view_helper.WebView()->PageScaleFactor()); | 4261 EXPECT_EQ(1.0f, web_view_helper.WebView()->PageScaleFactor()); |
| 4266 } | 4262 } |
| 4267 | 4263 |
| 4268 TEST_P(ParameterizedWebFrameTest, ReloadWhileProvisional) { | 4264 TEST_P(ParameterizedWebFrameTest, ReloadWhileProvisional) { |
| 4269 // Test that reloading while the previous load is still pending does not cause | 4265 // Test that reloading while the previous load is still pending does not cause |
| 4270 // the initial request to get lost. | 4266 // the initial request to get lost. |
| 4271 RegisterMockedHttpURLLoad("fixed_layout.html"); | 4267 RegisterMockedHttpURLLoad("fixed_layout.html"); |
| 4272 | 4268 |
| 4273 FrameTestHelpers::WebViewHelper web_view_helper; | 4269 FrameTestHelpers::WebViewHelper web_view_helper; |
| 4274 web_view_helper.Initialize(); | 4270 web_view_helper.Initialize(); |
| (...skipping 2029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6304 nullptr, ConfigureAndroid); | 6300 nullptr, ConfigureAndroid); |
| 6305 | 6301 |
| 6306 WebViewBase* web_view_impl = web_view_helper.WebView(); | 6302 WebViewBase* web_view_impl = web_view_helper.WebView(); |
| 6307 ASSERT_TRUE(web_view_impl); | 6303 ASSERT_TRUE(web_view_impl); |
| 6308 LocalFrame* frame = web_view_impl->MainFrameImpl()->GetFrame(); | 6304 LocalFrame* frame = web_view_impl->MainFrameImpl()->GetFrame(); |
| 6309 ASSERT_TRUE(frame); | 6305 ASSERT_TRUE(frame); |
| 6310 | 6306 |
| 6311 web_view_helper.Resize(WebSize(100, 200)); | 6307 web_view_helper.Resize(WebSize(100, 200)); |
| 6312 | 6308 |
| 6313 // Scroll main frame to the bottom of the document | 6309 // Scroll main frame to the bottom of the document |
| 6314 web_view_impl->MainFrame()->SetScrollOffset(WebSize(0, 400)); | 6310 web_view_impl->MainFrameImpl()->SetScrollOffset(WebSize(0, 400)); |
| 6315 EXPECT_SIZE_EQ(ScrollOffset(0, 400), frame->View()->GetScrollOffset()); | 6311 EXPECT_SIZE_EQ(ScrollOffset(0, 400), frame->View()->GetScrollOffset()); |
| 6316 | 6312 |
| 6317 web_view_impl->SetPageScaleFactor(2.0); | 6313 web_view_impl->SetPageScaleFactor(2.0); |
| 6318 | 6314 |
| 6319 // Scroll visual viewport to the top of the main frame. | 6315 // Scroll visual viewport to the top of the main frame. |
| 6320 VisualViewport& visual_viewport = frame->GetPage()->GetVisualViewport(); | 6316 VisualViewport& visual_viewport = frame->GetPage()->GetVisualViewport(); |
| 6321 visual_viewport.SetLocation(FloatPoint(0, 0)); | 6317 visual_viewport.SetLocation(FloatPoint(0, 0)); |
| 6322 EXPECT_SIZE_EQ(ScrollOffset(0, 0), visual_viewport.GetScrollOffset()); | 6318 EXPECT_SIZE_EQ(ScrollOffset(0, 0), visual_viewport.GetScrollOffset()); |
| 6323 | 6319 |
| 6324 // Tap at the top: there is nothing there. | 6320 // Tap at the top: there is nothing there. |
| (...skipping 1549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7874 WebViewBase* web_view = web_view_helper.WebView(); | 7870 WebViewBase* web_view = web_view_helper.WebView(); |
| 7875 LocalFrameView* frame_view = | 7871 LocalFrameView* frame_view = |
| 7876 web_view_helper.WebView()->MainFrameImpl()->GetFrameView(); | 7872 web_view_helper.WebView()->MainFrameImpl()->GetFrameView(); |
| 7877 | 7873 |
| 7878 float browser_controls_height = 40; | 7874 float browser_controls_height = 40; |
| 7879 web_view->ResizeWithBrowserControls(WebSize(100, 100), | 7875 web_view->ResizeWithBrowserControls(WebSize(100, 100), |
| 7880 browser_controls_height, false); | 7876 browser_controls_height, false); |
| 7881 web_view->SetPageScaleFactor(2.0f); | 7877 web_view->SetPageScaleFactor(2.0f); |
| 7882 web_view->UpdateAllLifecyclePhases(); | 7878 web_view->UpdateAllLifecyclePhases(); |
| 7883 | 7879 |
| 7884 web_view->MainFrame()->SetScrollOffset(WebSize(0, 2000)); | 7880 web_view->MainFrameImpl()->SetScrollOffset(WebSize(0, 2000)); |
| 7885 EXPECT_SIZE_EQ(ScrollOffset(0, 1900), frame_view->GetScrollOffset()); | 7881 EXPECT_SIZE_EQ(ScrollOffset(0, 1900), frame_view->GetScrollOffset()); |
| 7886 | 7882 |
| 7887 // Simulate the browser controls showing by 20px, thus shrinking the viewport | 7883 // Simulate the browser controls showing by 20px, thus shrinking the viewport |
| 7888 // and allowing it to scroll an additional 20px. | 7884 // and allowing it to scroll an additional 20px. |
| 7889 web_view->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), | 7885 web_view->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), |
| 7890 1.0f, 20.0f / browser_controls_height); | 7886 1.0f, 20.0f / browser_controls_height); |
| 7891 EXPECT_SIZE_EQ(ScrollOffset(0, 1920), frame_view->MaximumScrollOffset()); | 7887 EXPECT_SIZE_EQ(ScrollOffset(0, 1920), frame_view->MaximumScrollOffset()); |
| 7892 | 7888 |
| 7893 // Show more, make sure the scroll actually gets clamped. | 7889 // Show more, make sure the scroll actually gets clamped. |
| 7894 web_view->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), | 7890 web_view->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), |
| 7895 1.0f, 20.0f / browser_controls_height); | 7891 1.0f, 20.0f / browser_controls_height); |
| 7896 web_view->MainFrame()->SetScrollOffset(WebSize(0, 2000)); | 7892 web_view->MainFrameImpl()->SetScrollOffset(WebSize(0, 2000)); |
| 7897 EXPECT_SIZE_EQ(ScrollOffset(0, 1940), frame_view->GetScrollOffset()); | 7893 EXPECT_SIZE_EQ(ScrollOffset(0, 1940), frame_view->GetScrollOffset()); |
| 7898 | 7894 |
| 7899 // Hide until there's 10px showing. | 7895 // Hide until there's 10px showing. |
| 7900 web_view->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), | 7896 web_view->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), |
| 7901 1.0f, -30.0f / browser_controls_height); | 7897 1.0f, -30.0f / browser_controls_height); |
| 7902 EXPECT_SIZE_EQ(ScrollOffset(0, 1910), frame_view->MaximumScrollOffset()); | 7898 EXPECT_SIZE_EQ(ScrollOffset(0, 1910), frame_view->MaximumScrollOffset()); |
| 7903 | 7899 |
| 7904 // Simulate a LayoutEmbeddedContent::resize. The frame is resized to | 7900 // Simulate a LayoutEmbeddedContent::resize. The frame is resized to |
| 7905 // accomodate the browser controls and Blink's view of the browser controls | 7901 // accomodate the browser controls and Blink's view of the browser controls |
| 7906 // matches that of the CC | 7902 // matches that of the CC |
| (...skipping 4106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12013 if (obj->IsText()) { | 12009 if (obj->IsText()) { |
| 12014 LayoutText* layout_text = ToLayoutText(obj); | 12010 LayoutText* layout_text = ToLayoutText(obj); |
| 12015 text = layout_text->GetText(); | 12011 text = layout_text->GetText(); |
| 12016 break; | 12012 break; |
| 12017 } | 12013 } |
| 12018 } | 12014 } |
| 12019 EXPECT_EQ("foo alt", text.Utf8()); | 12015 EXPECT_EQ("foo alt", text.Utf8()); |
| 12020 } | 12016 } |
| 12021 | 12017 |
| 12022 } // namespace blink | 12018 } // namespace blink |
| OLD | NEW |