| 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 3052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3063 ASSERT_EQ(initial_page_scale_factor, | 3063 ASSERT_EQ(initial_page_scale_factor, |
| 3064 web_view_helper.WebView()->PageScaleFactor()); | 3064 web_view_helper.WebView()->PageScaleFactor()); |
| 3065 web_view_helper.Resize( | 3065 web_view_helper.Resize( |
| 3066 WebSize(viewport_size.height, viewport_size.width)); | 3066 WebSize(viewport_size.height, viewport_size.width)); |
| 3067 float expected_page_scale_factor = | 3067 float expected_page_scale_factor = |
| 3068 initial_page_scale_factor * | 3068 initial_page_scale_factor * |
| 3069 (should_scale_relative_to_viewport_width ? 1 / aspect_ratio : 1); | 3069 (should_scale_relative_to_viewport_width ? 1 / aspect_ratio : 1); |
| 3070 EXPECT_NEAR(expected_page_scale_factor, | 3070 EXPECT_NEAR(expected_page_scale_factor, |
| 3071 web_view_helper.WebView()->PageScaleFactor(), 0.05f); | 3071 web_view_helper.WebView()->PageScaleFactor(), 0.05f); |
| 3072 EXPECT_EQ(WebSize(), | 3072 EXPECT_EQ(WebSize(), |
| 3073 web_view_helper.WebView()->MainFrame()->GetScrollOffset()); | 3073 web_view_helper.WebView()->MainFrameImpl()->GetScrollOffset()); |
| 3074 } | 3074 } |
| 3075 | 3075 |
| 3076 // Resizing just the height should not affect pageScaleFactor or | 3076 // Resizing just the height should not affect pageScaleFactor or |
| 3077 // scrollOffset. | 3077 // scrollOffset. |
| 3078 { | 3078 { |
| 3079 web_view_helper.Resize( | 3079 web_view_helper.Resize( |
| 3080 WebSize(viewport_size.width, viewport_size.height)); | 3080 WebSize(viewport_size.width, viewport_size.height)); |
| 3081 web_view_helper.WebView()->SetPageScaleFactor(initial_page_scale_factor); | 3081 web_view_helper.WebView()->SetPageScaleFactor(initial_page_scale_factor); |
| 3082 web_view_helper.WebView()->MainFrame()->SetScrollOffset(scroll_offset); | 3082 web_view_helper.WebView()->MainFrameImpl()->SetScrollOffset( |
| 3083 scroll_offset); |
| 3083 web_view_helper.WebView()->UpdateAllLifecyclePhases(); | 3084 web_view_helper.WebView()->UpdateAllLifecyclePhases(); |
| 3084 const WebSize expected_scroll_offset = | 3085 const WebSize expected_scroll_offset = |
| 3085 web_view_helper.WebView()->MainFrame()->GetScrollOffset(); | 3086 web_view_helper.WebView()->MainFrameImpl()->GetScrollOffset(); |
| 3086 web_view_helper.Resize( | 3087 web_view_helper.Resize( |
| 3087 WebSize(viewport_size.width, viewport_size.height * 0.8f)); | 3088 WebSize(viewport_size.width, viewport_size.height * 0.8f)); |
| 3088 EXPECT_EQ(initial_page_scale_factor, | 3089 EXPECT_EQ(initial_page_scale_factor, |
| 3089 web_view_helper.WebView()->PageScaleFactor()); | 3090 web_view_helper.WebView()->PageScaleFactor()); |
| 3090 EXPECT_EQ(expected_scroll_offset, | 3091 EXPECT_EQ(expected_scroll_offset, |
| 3091 web_view_helper.WebView()->MainFrame()->GetScrollOffset()); | 3092 web_view_helper.WebView()->MainFrameImpl()->GetScrollOffset()); |
| 3092 web_view_helper.Resize( | 3093 web_view_helper.Resize( |
| 3093 WebSize(viewport_size.width, viewport_size.height * 0.8f)); | 3094 WebSize(viewport_size.width, viewport_size.height * 0.8f)); |
| 3094 EXPECT_EQ(initial_page_scale_factor, | 3095 EXPECT_EQ(initial_page_scale_factor, |
| 3095 web_view_helper.WebView()->PageScaleFactor()); | 3096 web_view_helper.WebView()->PageScaleFactor()); |
| 3096 EXPECT_EQ(expected_scroll_offset, | 3097 EXPECT_EQ(expected_scroll_offset, |
| 3097 web_view_helper.WebView()->MainFrame()->GetScrollOffset()); | 3098 web_view_helper.WebView()->MainFrameImpl()->GetScrollOffset()); |
| 3098 } | 3099 } |
| 3099 } | 3100 } |
| 3100 }; | 3101 }; |
| 3101 | 3102 |
| 3102 INSTANTIATE_TEST_CASE_P(All, WebFrameResizeTest, ::testing::Bool()); | 3103 INSTANTIATE_TEST_CASE_P(All, WebFrameResizeTest, ::testing::Bool()); |
| 3103 | 3104 |
| 3104 TEST_P(WebFrameResizeTest, | 3105 TEST_P(WebFrameResizeTest, |
| 3105 ResizeYieldsCorrectScrollAndScaleForWidthEqualsDeviceWidth) { | 3106 ResizeYieldsCorrectScrollAndScaleForWidthEqualsDeviceWidth) { |
| 3106 // With width=device-width, pageScaleFactor is preserved across resizes as | 3107 // With width=device-width, pageScaleFactor is preserved across resizes as |
| 3107 // long as the content adjusts according to the device-width. | 3108 // long as the content adjusts according to the device-width. |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3257 EXPECT_FALSE( | 3258 EXPECT_FALSE( |
| 3258 view->GetLayoutViewItem().Compositor()->LayerForHorizontalScrollbar()); | 3259 view->GetLayoutViewItem().Compositor()->LayerForHorizontalScrollbar()); |
| 3259 EXPECT_FALSE( | 3260 EXPECT_FALSE( |
| 3260 view->GetLayoutViewItem().Compositor()->LayerForVerticalScrollbar()); | 3261 view->GetLayoutViewItem().Compositor()->LayerForVerticalScrollbar()); |
| 3261 } | 3262 } |
| 3262 | 3263 |
| 3263 void SetScaleAndScrollAndLayout(WebViewBase* web_view, | 3264 void SetScaleAndScrollAndLayout(WebViewBase* web_view, |
| 3264 WebPoint scroll, | 3265 WebPoint scroll, |
| 3265 float scale) { | 3266 float scale) { |
| 3266 web_view->SetPageScaleFactor(scale); | 3267 web_view->SetPageScaleFactor(scale); |
| 3267 web_view->MainFrame()->SetScrollOffset(WebSize(scroll.x, scroll.y)); | 3268 web_view->MainFrameImpl()->SetScrollOffset(WebSize(scroll.x, scroll.y)); |
| 3268 web_view->UpdateAllLifecyclePhases(); | 3269 web_view->UpdateAllLifecyclePhases(); |
| 3269 } | 3270 } |
| 3270 | 3271 |
| 3271 void SimulatePageScale(WebViewBase* web_view_impl, float& scale) { | 3272 void SimulatePageScale(WebViewBase* web_view_impl, float& scale) { |
| 3272 ScrollOffset scroll_delta = | 3273 ScrollOffset scroll_delta = |
| 3273 ToScrollOffset( | 3274 ToScrollOffset( |
| 3274 web_view_impl->FakePageScaleAnimationTargetPositionForTesting()) - | 3275 web_view_impl->FakePageScaleAnimationTargetPositionForTesting()) - |
| 3275 web_view_impl->MainFrameImpl()->GetFrameView()->GetScrollOffset(); | 3276 web_view_impl->MainFrameImpl()->GetFrameView()->GetScrollOffset(); |
| 3276 float scale_delta = | 3277 float scale_delta = |
| 3277 web_view_impl->FakePageScaleAnimationPageScaleForTesting() / | 3278 web_view_impl->FakePageScaleAnimationPageScaleForTesting() / |
| (...skipping 983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4261 const int kPageHeight = 100; | 4262 const int kPageHeight = 100; |
| 4262 | 4263 |
| 4263 RegisterMockedHttpURLLoad(first_url); | 4264 RegisterMockedHttpURLLoad(first_url); |
| 4264 RegisterMockedHttpURLLoad(second_url); | 4265 RegisterMockedHttpURLLoad(second_url); |
| 4265 RegisterMockedHttpURLLoad(third_url); | 4266 RegisterMockedHttpURLLoad(third_url); |
| 4266 | 4267 |
| 4267 ClearScrollStateOnCommitWebFrameClient client; | 4268 ClearScrollStateOnCommitWebFrameClient client; |
| 4268 FrameTestHelpers::WebViewHelper web_view_helper; | 4269 FrameTestHelpers::WebViewHelper web_view_helper; |
| 4269 web_view_helper.InitializeAndLoad(base_url_ + first_url, true, &client); | 4270 web_view_helper.InitializeAndLoad(base_url_ + first_url, true, &client); |
| 4270 web_view_helper.Resize(WebSize(kPageWidth, kPageHeight)); | 4271 web_view_helper.Resize(WebSize(kPageWidth, kPageHeight)); |
| 4271 web_view_helper.WebView()->MainFrame()->SetScrollOffset( | 4272 web_view_helper.WebView()->MainFrameImpl()->SetScrollOffset( |
| 4272 WebSize(kPageWidth / 4, kPageHeight / 4)); | 4273 WebSize(kPageWidth / 4, kPageHeight / 4)); |
| 4273 web_view_helper.WebView()->SetPageScaleFactor(kPageScaleFactor); | 4274 web_view_helper.WebView()->SetPageScaleFactor(kPageScaleFactor); |
| 4274 | 4275 |
| 4275 // Reload the page and end up at the same url. State should not be propagated. | 4276 // Reload the page and end up at the same url. State should not be propagated. |
| 4276 web_view_helper.WebView()->MainFrame()->ReloadWithOverrideURL( | 4277 web_view_helper.WebView()->MainFrame()->ReloadWithOverrideURL( |
| 4277 ToKURL(base_url_ + first_url), WebFrameLoadType::kReload); | 4278 ToKURL(base_url_ + first_url), WebFrameLoadType::kReload); |
| 4278 FrameTestHelpers::PumpPendingRequestsForFrameToLoad( | 4279 FrameTestHelpers::PumpPendingRequestsForFrameToLoad( |
| 4279 web_view_helper.WebView()->MainFrame()); | 4280 web_view_helper.WebView()->MainFrame()); |
| 4280 EXPECT_EQ(0, web_view_helper.WebView()->MainFrame()->GetScrollOffset().width); | 4281 EXPECT_EQ( |
| 4281 EXPECT_EQ(0, | 4282 0, web_view_helper.WebView()->MainFrameImpl()->GetScrollOffset().width); |
| 4282 web_view_helper.WebView()->MainFrame()->GetScrollOffset().height); | 4283 EXPECT_EQ( |
| 4284 0, web_view_helper.WebView()->MainFrameImpl()->GetScrollOffset().height); |
| 4283 EXPECT_EQ(1.0f, web_view_helper.WebView()->PageScaleFactor()); | 4285 EXPECT_EQ(1.0f, web_view_helper.WebView()->PageScaleFactor()); |
| 4284 | 4286 |
| 4285 // Reload the page using the cache. State should not be propagated. | 4287 // Reload the page using the cache. State should not be propagated. |
| 4286 web_view_helper.WebView()->MainFrame()->ReloadWithOverrideURL( | 4288 web_view_helper.WebView()->MainFrame()->ReloadWithOverrideURL( |
| 4287 ToKURL(base_url_ + second_url), WebFrameLoadType::kReload); | 4289 ToKURL(base_url_ + second_url), WebFrameLoadType::kReload); |
| 4288 FrameTestHelpers::PumpPendingRequestsForFrameToLoad( | 4290 FrameTestHelpers::PumpPendingRequestsForFrameToLoad( |
| 4289 web_view_helper.WebView()->MainFrame()); | 4291 web_view_helper.WebView()->MainFrame()); |
| 4290 EXPECT_EQ(0, web_view_helper.WebView()->MainFrame()->GetScrollOffset().width); | 4292 EXPECT_EQ( |
| 4291 EXPECT_EQ(0, | 4293 0, web_view_helper.WebView()->MainFrameImpl()->GetScrollOffset().width); |
| 4292 web_view_helper.WebView()->MainFrame()->GetScrollOffset().height); | 4294 EXPECT_EQ( |
| 4295 0, web_view_helper.WebView()->MainFrameImpl()->GetScrollOffset().height); |
| 4293 EXPECT_EQ(1.0f, web_view_helper.WebView()->PageScaleFactor()); | 4296 EXPECT_EQ(1.0f, web_view_helper.WebView()->PageScaleFactor()); |
| 4294 | 4297 |
| 4295 // Reload the page while bypassing the cache. State should not be propagated. | 4298 // Reload the page while bypassing the cache. State should not be propagated. |
| 4296 web_view_helper.WebView()->MainFrame()->ReloadWithOverrideURL( | 4299 web_view_helper.WebView()->MainFrame()->ReloadWithOverrideURL( |
| 4297 ToKURL(base_url_ + third_url), WebFrameLoadType::kReloadBypassingCache); | 4300 ToKURL(base_url_ + third_url), WebFrameLoadType::kReloadBypassingCache); |
| 4298 FrameTestHelpers::PumpPendingRequestsForFrameToLoad( | 4301 FrameTestHelpers::PumpPendingRequestsForFrameToLoad( |
| 4299 web_view_helper.WebView()->MainFrame()); | 4302 web_view_helper.WebView()->MainFrame()); |
| 4300 EXPECT_EQ(0, web_view_helper.WebView()->MainFrame()->GetScrollOffset().width); | 4303 EXPECT_EQ( |
| 4301 EXPECT_EQ(0, | 4304 0, web_view_helper.WebView()->MainFrameImpl()->GetScrollOffset().width); |
| 4302 web_view_helper.WebView()->MainFrame()->GetScrollOffset().height); | 4305 EXPECT_EQ( |
| 4306 0, web_view_helper.WebView()->MainFrameImpl()->GetScrollOffset().height); |
| 4303 EXPECT_EQ(1.0f, web_view_helper.WebView()->PageScaleFactor()); | 4307 EXPECT_EQ(1.0f, web_view_helper.WebView()->PageScaleFactor()); |
| 4304 } | 4308 } |
| 4305 | 4309 |
| 4306 TEST_P(ParameterizedWebFrameTest, ReloadWhileProvisional) { | 4310 TEST_P(ParameterizedWebFrameTest, ReloadWhileProvisional) { |
| 4307 // Test that reloading while the previous load is still pending does not cause | 4311 // Test that reloading while the previous load is still pending does not cause |
| 4308 // the initial request to get lost. | 4312 // the initial request to get lost. |
| 4309 RegisterMockedHttpURLLoad("fixed_layout.html"); | 4313 RegisterMockedHttpURLLoad("fixed_layout.html"); |
| 4310 | 4314 |
| 4311 FrameTestHelpers::WebViewHelper web_view_helper; | 4315 FrameTestHelpers::WebViewHelper web_view_helper; |
| 4312 web_view_helper.Initialize(); | 4316 web_view_helper.Initialize(); |
| (...skipping 2033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6346 &client, nullptr, ConfigureAndroid); | 6350 &client, nullptr, ConfigureAndroid); |
| 6347 | 6351 |
| 6348 WebViewBase* web_view_impl = web_view_helper.WebView(); | 6352 WebViewBase* web_view_impl = web_view_helper.WebView(); |
| 6349 ASSERT_TRUE(web_view_impl); | 6353 ASSERT_TRUE(web_view_impl); |
| 6350 LocalFrame* frame = web_view_impl->MainFrameImpl()->GetFrame(); | 6354 LocalFrame* frame = web_view_impl->MainFrameImpl()->GetFrame(); |
| 6351 ASSERT_TRUE(frame); | 6355 ASSERT_TRUE(frame); |
| 6352 | 6356 |
| 6353 web_view_helper.Resize(WebSize(100, 200)); | 6357 web_view_helper.Resize(WebSize(100, 200)); |
| 6354 | 6358 |
| 6355 // Scroll main frame to the bottom of the document | 6359 // Scroll main frame to the bottom of the document |
| 6356 web_view_impl->MainFrame()->SetScrollOffset(WebSize(0, 400)); | 6360 web_view_impl->MainFrameImpl()->SetScrollOffset(WebSize(0, 400)); |
| 6357 EXPECT_SIZE_EQ(ScrollOffset(0, 400), frame->View()->GetScrollOffset()); | 6361 EXPECT_SIZE_EQ(ScrollOffset(0, 400), frame->View()->GetScrollOffset()); |
| 6358 | 6362 |
| 6359 web_view_impl->SetPageScaleFactor(2.0); | 6363 web_view_impl->SetPageScaleFactor(2.0); |
| 6360 | 6364 |
| 6361 // Scroll visual viewport to the top of the main frame. | 6365 // Scroll visual viewport to the top of the main frame. |
| 6362 VisualViewport& visual_viewport = frame->GetPage()->GetVisualViewport(); | 6366 VisualViewport& visual_viewport = frame->GetPage()->GetVisualViewport(); |
| 6363 visual_viewport.SetLocation(FloatPoint(0, 0)); | 6367 visual_viewport.SetLocation(FloatPoint(0, 0)); |
| 6364 EXPECT_SIZE_EQ(ScrollOffset(0, 0), visual_viewport.GetScrollOffset()); | 6368 EXPECT_SIZE_EQ(ScrollOffset(0, 0), visual_viewport.GetScrollOffset()); |
| 6365 | 6369 |
| 6366 // Tap at the top: there is nothing there. | 6370 // Tap at the top: there is nothing there. |
| (...skipping 1557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7924 WebViewBase* web_view = web_view_helper.WebView(); | 7928 WebViewBase* web_view = web_view_helper.WebView(); |
| 7925 LocalFrameView* frame_view = | 7929 LocalFrameView* frame_view = |
| 7926 web_view_helper.WebView()->MainFrameImpl()->GetFrameView(); | 7930 web_view_helper.WebView()->MainFrameImpl()->GetFrameView(); |
| 7927 | 7931 |
| 7928 float browser_controls_height = 40; | 7932 float browser_controls_height = 40; |
| 7929 web_view->ResizeWithBrowserControls(WebSize(100, 100), | 7933 web_view->ResizeWithBrowserControls(WebSize(100, 100), |
| 7930 browser_controls_height, false); | 7934 browser_controls_height, false); |
| 7931 web_view->SetPageScaleFactor(2.0f); | 7935 web_view->SetPageScaleFactor(2.0f); |
| 7932 web_view->UpdateAllLifecyclePhases(); | 7936 web_view->UpdateAllLifecyclePhases(); |
| 7933 | 7937 |
| 7934 web_view->MainFrame()->SetScrollOffset(WebSize(0, 2000)); | 7938 web_view->MainFrameImpl()->SetScrollOffset(WebSize(0, 2000)); |
| 7935 EXPECT_SIZE_EQ(ScrollOffset(0, 1900), frame_view->GetScrollOffset()); | 7939 EXPECT_SIZE_EQ(ScrollOffset(0, 1900), frame_view->GetScrollOffset()); |
| 7936 | 7940 |
| 7937 // Simulate the browser controls showing by 20px, thus shrinking the viewport | 7941 // Simulate the browser controls showing by 20px, thus shrinking the viewport |
| 7938 // and allowing it to scroll an additional 20px. | 7942 // and allowing it to scroll an additional 20px. |
| 7939 web_view->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), | 7943 web_view->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), |
| 7940 1.0f, 20.0f / browser_controls_height); | 7944 1.0f, 20.0f / browser_controls_height); |
| 7941 EXPECT_SIZE_EQ(ScrollOffset(0, 1920), frame_view->MaximumScrollOffset()); | 7945 EXPECT_SIZE_EQ(ScrollOffset(0, 1920), frame_view->MaximumScrollOffset()); |
| 7942 | 7946 |
| 7943 // Show more, make sure the scroll actually gets clamped. | 7947 // Show more, make sure the scroll actually gets clamped. |
| 7944 web_view->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), | 7948 web_view->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), |
| 7945 1.0f, 20.0f / browser_controls_height); | 7949 1.0f, 20.0f / browser_controls_height); |
| 7946 web_view->MainFrame()->SetScrollOffset(WebSize(0, 2000)); | 7950 web_view->MainFrameImpl()->SetScrollOffset(WebSize(0, 2000)); |
| 7947 EXPECT_SIZE_EQ(ScrollOffset(0, 1940), frame_view->GetScrollOffset()); | 7951 EXPECT_SIZE_EQ(ScrollOffset(0, 1940), frame_view->GetScrollOffset()); |
| 7948 | 7952 |
| 7949 // Hide until there's 10px showing. | 7953 // Hide until there's 10px showing. |
| 7950 web_view->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), | 7954 web_view->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), |
| 7951 1.0f, -30.0f / browser_controls_height); | 7955 1.0f, -30.0f / browser_controls_height); |
| 7952 EXPECT_SIZE_EQ(ScrollOffset(0, 1910), frame_view->MaximumScrollOffset()); | 7956 EXPECT_SIZE_EQ(ScrollOffset(0, 1910), frame_view->MaximumScrollOffset()); |
| 7953 | 7957 |
| 7954 // Simulate a LayoutEmbeddedContent::resize. The frame is resized to | 7958 // Simulate a LayoutEmbeddedContent::resize. The frame is resized to |
| 7955 // accomodate the browser controls and Blink's view of the browser controls | 7959 // accomodate the browser controls and Blink's view of the browser controls |
| 7956 // matches that of the CC | 7960 // matches that of the CC |
| (...skipping 4301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12258 if (obj->IsText()) { | 12262 if (obj->IsText()) { |
| 12259 LayoutText* layout_text = ToLayoutText(obj); | 12263 LayoutText* layout_text = ToLayoutText(obj); |
| 12260 text = layout_text->GetText(); | 12264 text = layout_text->GetText(); |
| 12261 break; | 12265 break; |
| 12262 } | 12266 } |
| 12263 } | 12267 } |
| 12264 EXPECT_EQ("foo alt", text.Utf8()); | 12268 EXPECT_EQ("foo alt", text.Utf8()); |
| 12265 } | 12269 } |
| 12266 | 12270 |
| 12267 } // namespace blink | 12271 } // namespace blink |
| OLD | NEW |