| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/frame/VisualViewport.h" | 5 #include "core/frame/VisualViewport.h" |
| 6 | 6 |
| 7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
| 8 #include "core/frame/BrowserControls.h" | 8 #include "core/frame/BrowserControls.h" |
| 9 #include "core/frame/FrameView.h" | 9 #include "core/frame/FrameView.h" |
| 10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 } while (false) | 80 } while (false) |
| 81 | 81 |
| 82 #define EXPECT_FLOAT_RECT_EQ(expected, actual) \ | 82 #define EXPECT_FLOAT_RECT_EQ(expected, actual) \ |
| 83 do { \ | 83 do { \ |
| 84 EXPECT_FLOAT_EQ((expected).X(), (actual).X()); \ | 84 EXPECT_FLOAT_EQ((expected).X(), (actual).X()); \ |
| 85 EXPECT_FLOAT_EQ((expected).Y(), (actual).Y()); \ | 85 EXPECT_FLOAT_EQ((expected).Y(), (actual).Y()); \ |
| 86 EXPECT_FLOAT_EQ((expected).Width(), (actual).Width()); \ | 86 EXPECT_FLOAT_EQ((expected).Width(), (actual).Width()); \ |
| 87 EXPECT_FLOAT_EQ((expected).Height(), (actual).Height()); \ | 87 EXPECT_FLOAT_EQ((expected).Height(), (actual).Height()); \ |
| 88 } while (false) | 88 } while (false) |
| 89 | 89 |
| 90 using namespace blink; | |
| 91 | |
| 92 using ::testing::_; | 90 using ::testing::_; |
| 93 using ::testing::PrintToString; | 91 using ::testing::PrintToString; |
| 94 using ::testing::Mock; | 92 using ::testing::Mock; |
| 95 using blink::URLTestHelpers::ToKURL; | 93 using blink::URLTestHelpers::ToKURL; |
| 96 | 94 |
| 97 namespace blink { | 95 namespace blink { |
| 96 |
| 98 ::std::ostream& operator<<(::std::ostream& os, const WebContextMenuData& data) { | 97 ::std::ostream& operator<<(::std::ostream& os, const WebContextMenuData& data) { |
| 99 return os << "Context menu location: [" << data.mouse_position.x << ", " | 98 return os << "Context menu location: [" << data.mouse_position.x << ", " |
| 100 << data.mouse_position.y << "]"; | 99 << data.mouse_position.y << "]"; |
| 101 } | 100 } |
| 102 } | |
| 103 | 101 |
| 104 namespace { | 102 namespace { |
| 105 | 103 |
| 106 typedef bool TestParamRootLayerScrolling; | 104 typedef bool TestParamRootLayerScrolling; |
| 107 class VisualViewportTest | 105 class VisualViewportTest |
| 108 : public ::testing::Test, | 106 : public ::testing::Test, |
| 109 public ::testing::WithParamInterface<TestParamRootLayerScrolling>, | 107 public ::testing::WithParamInterface<TestParamRootLayerScrolling>, |
| 110 private ScopedRootLayerScrollingForTest { | 108 private ScopedRootLayerScrollingForTest { |
| 111 public: | 109 public: |
| 112 VisualViewportTest() | 110 VisualViewportTest() |
| 113 : ScopedRootLayerScrollingForTest(GetParam()), | 111 : ScopedRootLayerScrollingForTest(GetParam()), |
| 114 m_baseURL("http://www.test.com/") {} | 112 base_url_("http://www.test.com/") {} |
| 115 | 113 |
| 116 void initializeWithDesktopSettings( | 114 void InitializeWithDesktopSettings( |
| 117 void (*overrideSettingsFunc)(WebSettings*) = 0) { | 115 void (*override_settings_func)(WebSettings*) = 0) { |
| 118 if (!overrideSettingsFunc) | 116 if (!override_settings_func) |
| 119 overrideSettingsFunc = &configureSettings; | 117 override_settings_func = &ConfigureSettings; |
| 120 m_helper.Initialize(true, nullptr, &m_mockWebViewClient, nullptr, | 118 helper_.Initialize(true, nullptr, &mock_web_view_client_, nullptr, |
| 121 overrideSettingsFunc); | 119 override_settings_func); |
| 122 webViewImpl()->SetDefaultPageScaleLimits(1, 4); | 120 WebViewImpl()->SetDefaultPageScaleLimits(1, 4); |
| 123 } | 121 } |
| 124 | 122 |
| 125 void initializeWithAndroidSettings( | 123 void InitializeWithAndroidSettings( |
| 126 void (*overrideSettingsFunc)(WebSettings*) = 0) { | 124 void (*override_settings_func)(WebSettings*) = 0) { |
| 127 if (!overrideSettingsFunc) | 125 if (!override_settings_func) |
| 128 overrideSettingsFunc = &configureAndroidSettings; | 126 override_settings_func = &ConfigureAndroidSettings; |
| 129 m_helper.Initialize(true, nullptr, &m_mockWebViewClient, nullptr, | 127 helper_.Initialize(true, nullptr, &mock_web_view_client_, nullptr, |
| 130 overrideSettingsFunc); | 128 override_settings_func); |
| 131 webViewImpl()->SetDefaultPageScaleLimits(0.25f, 5); | 129 WebViewImpl()->SetDefaultPageScaleLimits(0.25f, 5); |
| 132 } | 130 } |
| 133 | 131 |
| 134 ~VisualViewportTest() override { | 132 ~VisualViewportTest() override { |
| 135 Platform::Current() | 133 Platform::Current() |
| 136 ->GetURLLoaderMockFactory() | 134 ->GetURLLoaderMockFactory() |
| 137 ->UnregisterAllURLsAndClearMemoryCache(); | 135 ->UnregisterAllURLsAndClearMemoryCache(); |
| 138 } | 136 } |
| 139 | 137 |
| 140 void navigateTo(const std::string& url) { | 138 void NavigateTo(const std::string& url) { |
| 141 FrameTestHelpers::LoadFrame(webViewImpl()->MainFrame(), url); | 139 FrameTestHelpers::LoadFrame(WebViewImpl()->MainFrame(), url); |
| 142 } | 140 } |
| 143 | 141 |
| 144 void forceFullCompositingUpdate() { | 142 void ForceFullCompositingUpdate() { |
| 145 webViewImpl()->UpdateAllLifecyclePhases(); | 143 WebViewImpl()->UpdateAllLifecyclePhases(); |
| 146 } | 144 } |
| 147 | 145 |
| 148 void registerMockedHttpURLLoad(const std::string& fileName) { | 146 void RegisterMockedHttpURLLoad(const std::string& fileName) { |
| 149 URLTestHelpers::RegisterMockedURLLoadFromBase( | 147 URLTestHelpers::RegisterMockedURLLoadFromBase( |
| 150 WebString::FromUTF8(m_baseURL), blink::testing::WebTestDataPath(), | 148 WebString::FromUTF8(base_url_), blink::testing::WebTestDataPath(), |
| 151 WebString::FromUTF8(fileName)); | 149 WebString::FromUTF8(fileName)); |
| 152 } | 150 } |
| 153 | 151 |
| 154 void registerMockedHttpURLLoad(const std::string& url, | 152 void RegisterMockedHttpURLLoad(const std::string& url, |
| 155 const std::string& fileName) { | 153 const std::string& fileName) { |
| 156 URLTestHelpers::RegisterMockedURLLoad( | 154 URLTestHelpers::RegisterMockedURLLoad( |
| 157 ToKURL(url), | 155 ToKURL(url), |
| 158 blink::testing::WebTestDataPath(WebString::FromUTF8(fileName))); | 156 blink::testing::WebTestDataPath(WebString::FromUTF8(fileName))); |
| 159 } | 157 } |
| 160 | 158 |
| 161 WebLayer* getRootScrollLayer() { | 159 WebViewBase* WebViewImpl() const { return helper_.WebView(); } |
| 162 PaintLayerCompositor* compositor = | 160 LocalFrame* GetFrame() const { |
| 163 frame()->ContentLayoutItem().Compositor(); | 161 return helper_.WebView()->MainFrameImpl()->GetFrame(); |
| 164 DCHECK(compositor); | |
| 165 DCHECK(compositor->ScrollLayer()); | |
| 166 | |
| 167 WebLayer* webScrollLayer = compositor->ScrollLayer()->PlatformLayer(); | |
| 168 return webScrollLayer; | |
| 169 } | 162 } |
| 170 | 163 |
| 171 WebViewBase* webViewImpl() const { return m_helper.WebView(); } | 164 static void ConfigureSettings(WebSettings* settings) { |
| 172 LocalFrame* frame() const { | |
| 173 return m_helper.WebView()->MainFrameImpl()->GetFrame(); | |
| 174 } | |
| 175 | |
| 176 static void configureSettings(WebSettings* settings) { | |
| 177 settings->SetJavaScriptEnabled(true); | 165 settings->SetJavaScriptEnabled(true); |
| 178 settings->SetPreferCompositingToLCDTextEnabled(true); | 166 settings->SetPreferCompositingToLCDTextEnabled(true); |
| 179 } | 167 } |
| 180 | 168 |
| 181 static void configureAndroidSettings(WebSettings* settings) { | 169 static void ConfigureAndroidSettings(WebSettings* settings) { |
| 182 configureSettings(settings); | 170 ConfigureSettings(settings); |
| 183 settings->SetViewportEnabled(true); | 171 settings->SetViewportEnabled(true); |
| 184 settings->SetViewportMetaEnabled(true); | 172 settings->SetViewportMetaEnabled(true); |
| 185 settings->SetShrinksViewportContentToFit(true); | 173 settings->SetShrinksViewportContentToFit(true); |
| 186 settings->SetMainFrameResizesAreOrientationChanges(true); | 174 settings->SetMainFrameResizesAreOrientationChanges(true); |
| 187 } | 175 } |
| 188 | 176 |
| 189 protected: | 177 protected: |
| 190 std::string m_baseURL; | 178 std::string base_url_; |
| 191 FrameTestHelpers::TestWebViewClient m_mockWebViewClient; | 179 FrameTestHelpers::TestWebViewClient mock_web_view_client_; |
| 192 | 180 |
| 193 private: | 181 private: |
| 194 FrameTestHelpers::WebViewHelper m_helper; | 182 FrameTestHelpers::WebViewHelper helper_; |
| 195 }; | 183 }; |
| 196 | 184 |
| 197 INSTANTIATE_TEST_CASE_P(All, VisualViewportTest, ::testing::Bool()); | 185 INSTANTIATE_TEST_CASE_P(All, VisualViewportTest, ::testing::Bool()); |
| 198 | 186 |
| 199 // Test that resizing the VisualViewport works as expected and that resizing the | 187 // Test that resizing the VisualViewport works as expected and that resizing the |
| 200 // WebView resizes the VisualViewport. | 188 // WebView resizes the VisualViewport. |
| 201 TEST_P(VisualViewportTest, TestResize) { | 189 TEST_P(VisualViewportTest, TestResize) { |
| 202 initializeWithDesktopSettings(); | 190 InitializeWithDesktopSettings(); |
| 203 webViewImpl()->Resize(IntSize(320, 240)); | 191 WebViewImpl()->Resize(IntSize(320, 240)); |
| 204 | 192 |
| 205 navigateTo("about:blank"); | 193 NavigateTo("about:blank"); |
| 206 forceFullCompositingUpdate(); | 194 ForceFullCompositingUpdate(); |
| 207 | 195 |
| 208 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 196 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 209 | 197 |
| 210 IntSize webViewSize = webViewImpl()->Size(); | 198 IntSize web_view_size = WebViewImpl()->Size(); |
| 211 | 199 |
| 212 // Make sure the visual viewport was initialized. | 200 // Make sure the visual viewport was initialized. |
| 213 EXPECT_SIZE_EQ(webViewSize, visualViewport.Size()); | 201 EXPECT_SIZE_EQ(web_view_size, visual_viewport.Size()); |
| 214 | 202 |
| 215 // Resizing the WebView should change the VisualViewport. | 203 // Resizing the WebView should change the VisualViewport. |
| 216 webViewSize = IntSize(640, 480); | 204 web_view_size = IntSize(640, 480); |
| 217 webViewImpl()->Resize(webViewSize); | 205 WebViewImpl()->Resize(web_view_size); |
| 218 EXPECT_SIZE_EQ(webViewSize, IntSize(webViewImpl()->Size())); | 206 EXPECT_SIZE_EQ(web_view_size, IntSize(WebViewImpl()->Size())); |
| 219 EXPECT_SIZE_EQ(webViewSize, visualViewport.Size()); | 207 EXPECT_SIZE_EQ(web_view_size, visual_viewport.Size()); |
| 220 | 208 |
| 221 // Resizing the visual viewport shouldn't affect the WebView. | 209 // Resizing the visual viewport shouldn't affect the WebView. |
| 222 IntSize newViewportSize = IntSize(320, 200); | 210 IntSize new_viewport_size = IntSize(320, 200); |
| 223 visualViewport.SetSize(newViewportSize); | 211 visual_viewport.SetSize(new_viewport_size); |
| 224 EXPECT_SIZE_EQ(webViewSize, IntSize(webViewImpl()->Size())); | 212 EXPECT_SIZE_EQ(web_view_size, IntSize(WebViewImpl()->Size())); |
| 225 EXPECT_SIZE_EQ(newViewportSize, visualViewport.Size()); | 213 EXPECT_SIZE_EQ(new_viewport_size, visual_viewport.Size()); |
| 226 } | 214 } |
| 227 | 215 |
| 228 // Make sure that the visibleContentRect method acurately reflects the scale and | 216 // Make sure that the visibleContentRect method acurately reflects the scale and |
| 229 // scroll location of the viewport with and without scrollbars. | 217 // scroll location of the viewport with and without scrollbars. |
| 230 TEST_P(VisualViewportTest, TestVisibleContentRect) { | 218 TEST_P(VisualViewportTest, TestVisibleContentRect) { |
| 231 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(false); | 219 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(false); |
| 232 initializeWithDesktopSettings(); | 220 InitializeWithDesktopSettings(); |
| 233 | 221 |
| 234 registerMockedHttpURLLoad("200-by-300.html"); | 222 RegisterMockedHttpURLLoad("200-by-300.html"); |
| 235 navigateTo(m_baseURL + "200-by-300.html"); | 223 NavigateTo(base_url_ + "200-by-300.html"); |
| 236 | 224 |
| 237 IntSize size = IntSize(150, 100); | 225 IntSize size = IntSize(150, 100); |
| 238 // Vertical scrollbar width and horizontal scrollbar height. | 226 // Vertical scrollbar width and horizontal scrollbar height. |
| 239 IntSize scrollbarSize = IntSize(15, 15); | 227 IntSize scrollbar_size = IntSize(15, 15); |
| 240 | 228 |
| 241 webViewImpl()->Resize(size); | 229 WebViewImpl()->Resize(size); |
| 242 | 230 |
| 243 // Scroll layout viewport and verify visibleContentRect. | 231 // Scroll layout viewport and verify visibleContentRect. |
| 244 webViewImpl()->MainFrame()->SetScrollOffset(WebSize(0, 50)); | 232 WebViewImpl()->MainFrame()->SetScrollOffset(WebSize(0, 50)); |
| 245 | 233 |
| 246 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 234 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 247 EXPECT_EQ(IntRect(IntPoint(0, 0), size - scrollbarSize), | 235 EXPECT_EQ(IntRect(IntPoint(0, 0), size - scrollbar_size), |
| 248 visualViewport.VisibleContentRect(kExcludeScrollbars)); | 236 visual_viewport.VisibleContentRect(kExcludeScrollbars)); |
| 249 EXPECT_EQ(IntRect(IntPoint(0, 0), size), | 237 EXPECT_EQ(IntRect(IntPoint(0, 0), size), |
| 250 visualViewport.VisibleContentRect(kIncludeScrollbars)); | 238 visual_viewport.VisibleContentRect(kIncludeScrollbars)); |
| 251 | 239 |
| 252 webViewImpl()->SetPageScaleFactor(2.0); | 240 WebViewImpl()->SetPageScaleFactor(2.0); |
| 253 | 241 |
| 254 // Scroll visual viewport and verify visibleContentRect. | 242 // Scroll visual viewport and verify visibleContentRect. |
| 255 size.Scale(0.5); | 243 size.Scale(0.5); |
| 256 scrollbarSize.Scale(0.5); | 244 scrollbar_size.Scale(0.5); |
| 257 visualViewport.SetLocation(FloatPoint(10, 10)); | 245 visual_viewport.SetLocation(FloatPoint(10, 10)); |
| 258 EXPECT_EQ(IntRect(IntPoint(10, 10), size - scrollbarSize), | 246 EXPECT_EQ(IntRect(IntPoint(10, 10), size - scrollbar_size), |
| 259 visualViewport.VisibleContentRect(kExcludeScrollbars)); | 247 visual_viewport.VisibleContentRect(kExcludeScrollbars)); |
| 260 EXPECT_EQ(IntRect(IntPoint(10, 10), size), | 248 EXPECT_EQ(IntRect(IntPoint(10, 10), size), |
| 261 visualViewport.VisibleContentRect(kIncludeScrollbars)); | 249 visual_viewport.VisibleContentRect(kIncludeScrollbars)); |
| 262 } | 250 } |
| 263 | 251 |
| 264 // This tests that shrinking the WebView while the page is fully scrolled | 252 // This tests that shrinking the WebView while the page is fully scrolled |
| 265 // doesn't move the viewport up/left, it should keep the visible viewport | 253 // doesn't move the viewport up/left, it should keep the visible viewport |
| 266 // unchanged from the user's perspective (shrinking the FrameView will clamp | 254 // unchanged from the user's perspective (shrinking the FrameView will clamp |
| 267 // the VisualViewport so we need to counter scroll the FrameView to make it | 255 // the VisualViewport so we need to counter scroll the FrameView to make it |
| 268 // appear to stay still). This caused bugs like crbug.com/453859. | 256 // appear to stay still). This caused bugs like crbug.com/453859. |
| 269 TEST_P(VisualViewportTest, TestResizeAtFullyScrolledPreservesViewportLocation) { | 257 TEST_P(VisualViewportTest, TestResizeAtFullyScrolledPreservesViewportLocation) { |
| 270 initializeWithDesktopSettings(); | 258 InitializeWithDesktopSettings(); |
| 271 webViewImpl()->Resize(IntSize(800, 600)); | 259 WebViewImpl()->Resize(IntSize(800, 600)); |
| 272 | 260 |
| 273 registerMockedHttpURLLoad("content-width-1000.html"); | 261 RegisterMockedHttpURLLoad("content-width-1000.html"); |
| 274 navigateTo(m_baseURL + "content-width-1000.html"); | 262 NavigateTo(base_url_ + "content-width-1000.html"); |
| 275 | 263 |
| 276 FrameView& frameView = *webViewImpl()->MainFrameImpl()->GetFrameView(); | 264 FrameView& frame_view = *WebViewImpl()->MainFrameImpl()->GetFrameView(); |
| 277 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 265 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 278 | 266 |
| 279 visualViewport.SetScale(2); | 267 visual_viewport.SetScale(2); |
| 280 | 268 |
| 281 // Fully scroll both viewports. | 269 // Fully scroll both viewports. |
| 282 frameView.LayoutViewportScrollableArea()->SetScrollOffset( | 270 frame_view.LayoutViewportScrollableArea()->SetScrollOffset( |
| 283 ScrollOffset(10000, 10000), kProgrammaticScroll); | 271 ScrollOffset(10000, 10000), kProgrammaticScroll); |
| 284 visualViewport.Move(FloatSize(10000, 10000)); | 272 visual_viewport.Move(FloatSize(10000, 10000)); |
| 285 | 273 |
| 286 // Sanity check. | 274 // Sanity check. |
| 287 ASSERT_SIZE_EQ(FloatSize(400, 300), visualViewport.GetScrollOffset()); | 275 ASSERT_SIZE_EQ(FloatSize(400, 300), visual_viewport.GetScrollOffset()); |
| 288 ASSERT_SIZE_EQ(ScrollOffset(200, 1400), | 276 ASSERT_SIZE_EQ(ScrollOffset(200, 1400), |
| 289 frameView.LayoutViewportScrollableArea()->GetScrollOffset()); | 277 frame_view.LayoutViewportScrollableArea()->GetScrollOffset()); |
| 290 | 278 |
| 291 IntPoint expectedLocation = | 279 IntPoint expected_location = |
| 292 frameView.GetScrollableArea()->VisibleContentRect().Location(); | 280 frame_view.GetScrollableArea()->VisibleContentRect().Location(); |
| 293 | 281 |
| 294 // Shrink the WebView, this should cause both viewports to shrink and | 282 // Shrink the WebView, this should cause both viewports to shrink and |
| 295 // WebView should do whatever it needs to do to preserve the visible | 283 // WebView should do whatever it needs to do to preserve the visible |
| 296 // location. | 284 // location. |
| 297 webViewImpl()->Resize(IntSize(700, 550)); | 285 WebViewImpl()->Resize(IntSize(700, 550)); |
| 298 | 286 |
| 299 EXPECT_POINT_EQ( | 287 EXPECT_POINT_EQ( |
| 300 expectedLocation, | 288 expected_location, |
| 301 frameView.GetScrollableArea()->VisibleContentRect().Location()); | 289 frame_view.GetScrollableArea()->VisibleContentRect().Location()); |
| 302 | 290 |
| 303 webViewImpl()->Resize(IntSize(800, 600)); | 291 WebViewImpl()->Resize(IntSize(800, 600)); |
| 304 | 292 |
| 305 EXPECT_POINT_EQ( | 293 EXPECT_POINT_EQ( |
| 306 expectedLocation, | 294 expected_location, |
| 307 frameView.GetScrollableArea()->VisibleContentRect().Location()); | 295 frame_view.GetScrollableArea()->VisibleContentRect().Location()); |
| 308 } | 296 } |
| 309 | 297 |
| 310 // Test that the VisualViewport works as expected in case of a scaled | 298 // Test that the VisualViewport works as expected in case of a scaled |
| 311 // and scrolled viewport - scroll down. | 299 // and scrolled viewport - scroll down. |
| 312 TEST_P(VisualViewportTest, TestResizeAfterVerticalScroll) { | 300 TEST_P(VisualViewportTest, TestResizeAfterVerticalScroll) { |
| 313 /* | 301 /* |
| 314 200 200 | 302 200 200 |
| 315 | | | | | 303 | | | | |
| 316 | | | | | 304 | | | | |
| 317 | | 800 | | 800 | 305 | | 800 | | 800 |
| 318 |-------------------| | | | 306 |-------------------| | | |
| 319 | | | | | 307 | | | | |
| 320 | | | | | 308 | | | | |
| 321 | | | | | 309 | | | | |
| 322 | | --------> | | | 310 | | --------> | | |
| 323 | 300 | | | | 311 | 300 | | | |
| 324 | | | | | 312 | | | | |
| 325 | 400 | | | | 313 | 400 | | | |
| 326 | | |-------------------| | 314 | | |-------------------| |
| 327 | | | 75 | | 315 | | | 75 | |
| 328 | 50 | | 50 100| | 316 | 50 | | 50 100| |
| 329 o----- | o---- | | 317 o----- | o---- | |
| 330 | | | | | 25 | | 318 | | | | | 25 | |
| 331 | |100 | |-------------------| | 319 | |100 | |-------------------| |
| 332 | | | | | | 320 | | | | | |
| 333 | | | | | | 321 | | | | | |
| 334 -------------------- -------------------- | 322 -------------------- -------------------- |
| 335 | 323 |
| 336 */ | 324 */ |
| 337 initializeWithAndroidSettings(); | 325 InitializeWithAndroidSettings(); |
| 338 | 326 |
| 339 registerMockedHttpURLLoad("200-by-800-viewport.html"); | 327 RegisterMockedHttpURLLoad("200-by-800-viewport.html"); |
| 340 navigateTo(m_baseURL + "200-by-800-viewport.html"); | 328 NavigateTo(base_url_ + "200-by-800-viewport.html"); |
| 341 | 329 |
| 342 webViewImpl()->Resize(IntSize(100, 200)); | 330 WebViewImpl()->Resize(IntSize(100, 200)); |
| 343 | 331 |
| 344 // Scroll main frame to the bottom of the document | 332 // Scroll main frame to the bottom of the document |
| 345 webViewImpl()->MainFrame()->SetScrollOffset(WebSize(0, 400)); | 333 WebViewImpl()->MainFrame()->SetScrollOffset(WebSize(0, 400)); |
| 346 EXPECT_SIZE_EQ( | 334 EXPECT_SIZE_EQ( |
| 347 ScrollOffset(0, 400), | 335 ScrollOffset(0, 400), |
| 348 frame()->View()->LayoutViewportScrollableArea()->GetScrollOffset()); | 336 GetFrame()->View()->LayoutViewportScrollableArea()->GetScrollOffset()); |
| 349 | 337 |
| 350 webViewImpl()->SetPageScaleFactor(2.0); | 338 WebViewImpl()->SetPageScaleFactor(2.0); |
| 351 | 339 |
| 352 // Scroll visual viewport to the bottom of the main frame | 340 // Scroll visual viewport to the bottom of the main frame |
| 353 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 341 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 354 visualViewport.SetLocation(FloatPoint(0, 300)); | 342 visual_viewport.SetLocation(FloatPoint(0, 300)); |
| 355 EXPECT_FLOAT_SIZE_EQ(FloatSize(0, 300), visualViewport.GetScrollOffset()); | 343 EXPECT_FLOAT_SIZE_EQ(FloatSize(0, 300), visual_viewport.GetScrollOffset()); |
| 356 | 344 |
| 357 // Verify the initial size of the visual viewport in the CSS pixels | 345 // Verify the initial size of the visual viewport in the CSS pixels |
| 358 EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 100), visualViewport.VisibleRect().Size()); | 346 EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 100), |
| 347 visual_viewport.VisibleRect().Size()); |
| 359 | 348 |
| 360 // Perform the resizing | 349 // Perform the resizing |
| 361 webViewImpl()->Resize(IntSize(200, 100)); | 350 WebViewImpl()->Resize(IntSize(200, 100)); |
| 362 | 351 |
| 363 // After resizing the scale changes 2.0 -> 4.0 | 352 // After resizing the scale changes 2.0 -> 4.0 |
| 364 EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 25), visualViewport.VisibleRect().Size()); | 353 EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 25), visual_viewport.VisibleRect().Size()); |
| 365 | 354 |
| 366 EXPECT_SIZE_EQ( | 355 EXPECT_SIZE_EQ( |
| 367 ScrollOffset(0, 625), | 356 ScrollOffset(0, 625), |
| 368 frame()->View()->LayoutViewportScrollableArea()->GetScrollOffset()); | 357 GetFrame()->View()->LayoutViewportScrollableArea()->GetScrollOffset()); |
| 369 EXPECT_FLOAT_SIZE_EQ(FloatSize(0, 75), visualViewport.GetScrollOffset()); | 358 EXPECT_FLOAT_SIZE_EQ(FloatSize(0, 75), visual_viewport.GetScrollOffset()); |
| 370 } | 359 } |
| 371 | 360 |
| 372 // Test that the VisualViewport works as expected in case if a scaled | 361 // Test that the VisualViewport works as expected in case if a scaled |
| 373 // and scrolled viewport - scroll right. | 362 // and scrolled viewport - scroll right. |
| 374 TEST_P(VisualViewportTest, TestResizeAfterHorizontalScroll) { | 363 TEST_P(VisualViewportTest, TestResizeAfterHorizontalScroll) { |
| 375 /* | 364 /* |
| 376 200 200 | 365 200 200 |
| 377 ---------------o----- ---------------o----- | 366 ---------------o----- ---------------o----- |
| 378 | | | | 25| | | 367 | | | | 25| | |
| 379 | | | | -----| | 368 | | | | -----| |
| 380 | 100| | |100 50 | | 369 | 100| | |100 50 | |
| 381 | | | | | | 370 | | | | | |
| 382 | ---- | |-------------------| | 371 | ---- | |-------------------| |
| 383 | | | | | 372 | | | | |
| 384 | | | | | 373 | | | | |
| 385 | | | | | 374 | | | | |
| 386 | | | | | 375 | | | | |
| 387 | | | | | 376 | | | | |
| 388 |400 | ---------> | | | 377 |400 | ---------> | | |
| 389 | | | | | 378 | | | | |
| 390 | | | | | 379 | | | | |
| 391 | | | | | 380 | | | | |
| 392 | | | | | 381 | | | | |
| 393 | | | | | 382 | | | | |
| 394 | | | | | 383 | | | | |
| 395 | | | | | 384 | | | | |
| 396 | | | | | 385 | | | | |
| 397 |-------------------| | | | 386 |-------------------| | | |
| 398 | | | | | 387 | | | | |
| 399 | 388 |
| 400 */ | 389 */ |
| 401 initializeWithAndroidSettings(); | 390 InitializeWithAndroidSettings(); |
| 402 | 391 |
| 403 registerMockedHttpURLLoad("200-by-800-viewport.html"); | 392 RegisterMockedHttpURLLoad("200-by-800-viewport.html"); |
| 404 navigateTo(m_baseURL + "200-by-800-viewport.html"); | 393 NavigateTo(base_url_ + "200-by-800-viewport.html"); |
| 405 | 394 |
| 406 webViewImpl()->Resize(IntSize(100, 200)); | 395 WebViewImpl()->Resize(IntSize(100, 200)); |
| 407 | 396 |
| 408 // Outer viewport takes the whole width of the document. | 397 // Outer viewport takes the whole width of the document. |
| 409 | 398 |
| 410 webViewImpl()->SetPageScaleFactor(2.0); | 399 WebViewImpl()->SetPageScaleFactor(2.0); |
| 411 | 400 |
| 412 // Scroll visual viewport to the right edge of the frame | 401 // Scroll visual viewport to the right edge of the frame |
| 413 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 402 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 414 visualViewport.SetLocation(FloatPoint(150, 0)); | 403 visual_viewport.SetLocation(FloatPoint(150, 0)); |
| 415 EXPECT_FLOAT_SIZE_EQ(FloatSize(150, 0), visualViewport.GetScrollOffset()); | 404 EXPECT_FLOAT_SIZE_EQ(FloatSize(150, 0), visual_viewport.GetScrollOffset()); |
| 416 | 405 |
| 417 // Verify the initial size of the visual viewport in the CSS pixels | 406 // Verify the initial size of the visual viewport in the CSS pixels |
| 418 EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 100), visualViewport.VisibleRect().Size()); | 407 EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 100), |
| 419 | 408 visual_viewport.VisibleRect().Size()); |
| 420 webViewImpl()->Resize(IntSize(200, 100)); | 409 |
| 410 WebViewImpl()->Resize(IntSize(200, 100)); |
| 421 | 411 |
| 422 // After resizing the scale changes 2.0 -> 4.0 | 412 // After resizing the scale changes 2.0 -> 4.0 |
| 423 EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 25), visualViewport.VisibleRect().Size()); | 413 EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 25), visual_viewport.VisibleRect().Size()); |
| 424 | 414 |
| 425 EXPECT_SIZE_EQ(ScrollOffset(0, 0), frame()->View()->GetScrollOffset()); | 415 EXPECT_SIZE_EQ(ScrollOffset(0, 0), GetFrame()->View()->GetScrollOffset()); |
| 426 EXPECT_FLOAT_SIZE_EQ(FloatSize(150, 0), visualViewport.GetScrollOffset()); | 416 EXPECT_FLOAT_SIZE_EQ(FloatSize(150, 0), visual_viewport.GetScrollOffset()); |
| 427 } | 417 } |
| 428 | 418 |
| 429 // Test that the container layer gets sized properly if the WebView is resized | 419 // Test that the container layer gets sized properly if the WebView is resized |
| 430 // prior to the VisualViewport being attached to the layer tree. | 420 // prior to the VisualViewport being attached to the layer tree. |
| 431 TEST_P(VisualViewportTest, TestWebViewResizedBeforeAttachment) { | 421 TEST_P(VisualViewportTest, TestWebViewResizedBeforeAttachment) { |
| 432 initializeWithDesktopSettings(); | 422 InitializeWithDesktopSettings(); |
| 433 FrameView& frameView = *webViewImpl()->MainFrameImpl()->GetFrameView(); | 423 FrameView& frame_view = *WebViewImpl()->MainFrameImpl()->GetFrameView(); |
| 434 | 424 |
| 435 // Make sure that a resize that comes in while there's no root layer is | 425 // Make sure that a resize that comes in while there's no root layer is |
| 436 // honoured when we attach to the layer tree. | 426 // honoured when we attach to the layer tree. |
| 437 WebFrameWidgetBase* mainFrameWidget = | 427 WebFrameWidgetBase* main_frame_widget = |
| 438 webViewImpl()->MainFrameImpl()->FrameWidget(); | 428 WebViewImpl()->MainFrameImpl()->FrameWidget(); |
| 439 mainFrameWidget->SetRootGraphicsLayer(nullptr); | 429 main_frame_widget->SetRootGraphicsLayer(nullptr); |
| 440 webViewImpl()->Resize(IntSize(320, 240)); | 430 WebViewImpl()->Resize(IntSize(320, 240)); |
| 441 | 431 |
| 442 navigateTo("about:blank"); | 432 NavigateTo("about:blank"); |
| 443 webViewImpl()->UpdateAllLifecyclePhases(); | 433 WebViewImpl()->UpdateAllLifecyclePhases(); |
| 444 mainFrameWidget->SetRootGraphicsLayer( | 434 main_frame_widget->SetRootGraphicsLayer( |
| 445 frameView.GetLayoutViewItem().Compositor()->RootGraphicsLayer()); | 435 frame_view.GetLayoutViewItem().Compositor()->RootGraphicsLayer()); |
| 446 | 436 |
| 447 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 437 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 448 EXPECT_FLOAT_SIZE_EQ(FloatSize(320, 240), | 438 EXPECT_FLOAT_SIZE_EQ(FloatSize(320, 240), |
| 449 visualViewport.ContainerLayer()->Size()); | 439 visual_viewport.ContainerLayer()->Size()); |
| 450 } | 440 } |
| 451 | 441 |
| 452 // Make sure that the visibleRect method acurately reflects the scale and scroll | 442 // Make sure that the visibleRect method acurately reflects the scale and scroll |
| 453 // location of the viewport. | 443 // location of the viewport. |
| 454 TEST_P(VisualViewportTest, TestVisibleRect) { | 444 TEST_P(VisualViewportTest, TestVisibleRect) { |
| 455 initializeWithDesktopSettings(); | 445 InitializeWithDesktopSettings(); |
| 456 webViewImpl()->Resize(IntSize(320, 240)); | 446 WebViewImpl()->Resize(IntSize(320, 240)); |
| 457 | 447 |
| 458 navigateTo("about:blank"); | 448 NavigateTo("about:blank"); |
| 459 forceFullCompositingUpdate(); | 449 ForceFullCompositingUpdate(); |
| 460 | 450 |
| 461 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 451 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 462 | 452 |
| 463 // Initial visible rect should be the whole frame. | 453 // Initial visible rect should be the whole frame. |
| 464 EXPECT_SIZE_EQ(IntSize(webViewImpl()->Size()), visualViewport.Size()); | 454 EXPECT_SIZE_EQ(IntSize(WebViewImpl()->Size()), visual_viewport.Size()); |
| 465 | 455 |
| 466 // Viewport is whole frame. | 456 // Viewport is whole frame. |
| 467 IntSize size = IntSize(400, 200); | 457 IntSize size = IntSize(400, 200); |
| 468 webViewImpl()->Resize(size); | 458 WebViewImpl()->Resize(size); |
| 469 webViewImpl()->UpdateAllLifecyclePhases(); | 459 WebViewImpl()->UpdateAllLifecyclePhases(); |
| 470 visualViewport.SetSize(size); | 460 visual_viewport.SetSize(size); |
| 471 | 461 |
| 472 // Scale the viewport to 2X; size should not change. | 462 // Scale the viewport to 2X; size should not change. |
| 473 FloatRect expectedRect(FloatPoint(0, 0), FloatSize(size)); | 463 FloatRect expected_rect(FloatPoint(0, 0), FloatSize(size)); |
| 474 expectedRect.Scale(0.5); | 464 expected_rect.Scale(0.5); |
| 475 visualViewport.SetScale(2); | 465 visual_viewport.SetScale(2); |
| 476 EXPECT_EQ(2, visualViewport.Scale()); | 466 EXPECT_EQ(2, visual_viewport.Scale()); |
| 477 EXPECT_SIZE_EQ(size, visualViewport.Size()); | 467 EXPECT_SIZE_EQ(size, visual_viewport.Size()); |
| 478 EXPECT_FLOAT_RECT_EQ(expectedRect, visualViewport.VisibleRect()); | 468 EXPECT_FLOAT_RECT_EQ(expected_rect, visual_viewport.VisibleRect()); |
| 479 | 469 |
| 480 // Move the viewport. | 470 // Move the viewport. |
| 481 expectedRect.SetLocation(FloatPoint(5, 7)); | 471 expected_rect.SetLocation(FloatPoint(5, 7)); |
| 482 visualViewport.SetLocation(expectedRect.Location()); | 472 visual_viewport.SetLocation(expected_rect.Location()); |
| 483 EXPECT_FLOAT_RECT_EQ(expectedRect, visualViewport.VisibleRect()); | 473 EXPECT_FLOAT_RECT_EQ(expected_rect, visual_viewport.VisibleRect()); |
| 484 | 474 |
| 485 expectedRect.SetLocation(FloatPoint(200, 100)); | 475 expected_rect.SetLocation(FloatPoint(200, 100)); |
| 486 visualViewport.SetLocation(expectedRect.Location()); | 476 visual_viewport.SetLocation(expected_rect.Location()); |
| 487 EXPECT_FLOAT_RECT_EQ(expectedRect, visualViewport.VisibleRect()); | 477 EXPECT_FLOAT_RECT_EQ(expected_rect, visual_viewport.VisibleRect()); |
| 488 | 478 |
| 489 // Scale the viewport to 3X to introduce some non-int values. | 479 // Scale the viewport to 3X to introduce some non-int values. |
| 490 FloatPoint oldLocation = expectedRect.Location(); | 480 FloatPoint oldLocation = expected_rect.Location(); |
| 491 expectedRect = FloatRect(FloatPoint(), FloatSize(size)); | 481 expected_rect = FloatRect(FloatPoint(), FloatSize(size)); |
| 492 expectedRect.Scale(1 / 3.0f); | 482 expected_rect.Scale(1 / 3.0f); |
| 493 expectedRect.SetLocation(oldLocation); | 483 expected_rect.SetLocation(oldLocation); |
| 494 visualViewport.SetScale(3); | 484 visual_viewport.SetScale(3); |
| 495 EXPECT_FLOAT_RECT_EQ(expectedRect, visualViewport.VisibleRect()); | 485 EXPECT_FLOAT_RECT_EQ(expected_rect, visual_viewport.VisibleRect()); |
| 496 | 486 |
| 497 expectedRect.SetLocation(FloatPoint(0.25f, 0.333f)); | 487 expected_rect.SetLocation(FloatPoint(0.25f, 0.333f)); |
| 498 visualViewport.SetLocation(expectedRect.Location()); | 488 visual_viewport.SetLocation(expected_rect.Location()); |
| 499 EXPECT_FLOAT_RECT_EQ(expectedRect, visualViewport.VisibleRect()); | 489 EXPECT_FLOAT_RECT_EQ(expected_rect, visual_viewport.VisibleRect()); |
| 500 } | 490 } |
| 501 | 491 |
| 502 // Make sure that the visibleRectInDocument method acurately reflects the scale | 492 // Make sure that the visibleRectInDocument method acurately reflects the scale |
| 503 // and scroll location of the viewport relative to the document. | 493 // and scroll location of the viewport relative to the document. |
| 504 TEST_P(VisualViewportTest, TestVisibleRectInDocument) { | 494 TEST_P(VisualViewportTest, TestVisibleRectInDocument) { |
| 505 initializeWithDesktopSettings(); | 495 InitializeWithDesktopSettings(); |
| 506 webViewImpl()->Resize(IntSize(100, 400)); | 496 WebViewImpl()->Resize(IntSize(100, 400)); |
| 507 | 497 |
| 508 registerMockedHttpURLLoad("200-by-800-viewport.html"); | 498 RegisterMockedHttpURLLoad("200-by-800-viewport.html"); |
| 509 navigateTo(m_baseURL + "200-by-800-viewport.html"); | 499 NavigateTo(base_url_ + "200-by-800-viewport.html"); |
| 510 | 500 |
| 511 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 501 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 512 | 502 |
| 513 // Scale the viewport to 2X and move it. | 503 // Scale the viewport to 2X and move it. |
| 514 visualViewport.SetScale(2); | 504 visual_viewport.SetScale(2); |
| 515 visualViewport.SetLocation(FloatPoint(10, 15)); | 505 visual_viewport.SetLocation(FloatPoint(10, 15)); |
| 516 EXPECT_FLOAT_RECT_EQ(FloatRect(10, 15, 50, 200), | 506 EXPECT_FLOAT_RECT_EQ(FloatRect(10, 15, 50, 200), |
| 517 visualViewport.VisibleRectInDocument()); | 507 visual_viewport.VisibleRectInDocument()); |
| 518 | 508 |
| 519 // Scroll the layout viewport. Ensure its offset is reflected in | 509 // Scroll the layout viewport. Ensure its offset is reflected in |
| 520 // visibleRectInDocument(). | 510 // visibleRectInDocument(). |
| 521 FrameView& frameView = *webViewImpl()->MainFrameImpl()->GetFrameView(); | 511 FrameView& frame_view = *WebViewImpl()->MainFrameImpl()->GetFrameView(); |
| 522 frameView.LayoutViewportScrollableArea()->SetScrollOffset( | 512 frame_view.LayoutViewportScrollableArea()->SetScrollOffset( |
| 523 ScrollOffset(40, 100), kProgrammaticScroll); | 513 ScrollOffset(40, 100), kProgrammaticScroll); |
| 524 EXPECT_FLOAT_RECT_EQ(FloatRect(50, 115, 50, 200), | 514 EXPECT_FLOAT_RECT_EQ(FloatRect(50, 115, 50, 200), |
| 525 visualViewport.VisibleRectInDocument()); | 515 visual_viewport.VisibleRectInDocument()); |
| 526 } | 516 } |
| 527 | 517 |
| 528 TEST_P(VisualViewportTest, TestFractionalScrollOffsetIsNotOverwritten) { | 518 TEST_P(VisualViewportTest, TestFractionalScrollOffsetIsNotOverwritten) { |
| 529 bool origFractionalOffsetsEnabled = | 519 bool orig_fractional_offsets_enabled = |
| 530 RuntimeEnabledFeatures::fractionalScrollOffsetsEnabled(); | 520 RuntimeEnabledFeatures::fractionalScrollOffsetsEnabled(); |
| 531 RuntimeEnabledFeatures::setFractionalScrollOffsetsEnabled(true); | 521 RuntimeEnabledFeatures::setFractionalScrollOffsetsEnabled(true); |
| 532 | 522 |
| 533 initializeWithAndroidSettings(); | 523 InitializeWithAndroidSettings(); |
| 534 webViewImpl()->Resize(IntSize(200, 250)); | 524 WebViewImpl()->Resize(IntSize(200, 250)); |
| 535 | 525 |
| 536 registerMockedHttpURLLoad("200-by-800-viewport.html"); | 526 RegisterMockedHttpURLLoad("200-by-800-viewport.html"); |
| 537 navigateTo(m_baseURL + "200-by-800-viewport.html"); | 527 NavigateTo(base_url_ + "200-by-800-viewport.html"); |
| 538 | 528 |
| 539 FrameView& frameView = *webViewImpl()->MainFrameImpl()->GetFrameView(); | 529 FrameView& frame_view = *WebViewImpl()->MainFrameImpl()->GetFrameView(); |
| 540 frameView.LayoutViewportScrollableArea()->SetScrollOffset( | 530 frame_view.LayoutViewportScrollableArea()->SetScrollOffset( |
| 541 ScrollOffset(0, 10.5), kProgrammaticScroll); | 531 ScrollOffset(0, 10.5), kProgrammaticScroll); |
| 542 frameView.LayoutViewportScrollableArea()->ScrollableArea::SetScrollOffset( | 532 frame_view.LayoutViewportScrollableArea()->ScrollableArea::SetScrollOffset( |
| 543 ScrollOffset(10, 30.5), kCompositorScroll); | 533 ScrollOffset(10, 30.5), kCompositorScroll); |
| 544 | 534 |
| 545 EXPECT_EQ( | 535 EXPECT_EQ( |
| 546 30.5, | 536 30.5, |
| 547 frameView.LayoutViewportScrollableArea()->GetScrollOffset().Height()); | 537 frame_view.LayoutViewportScrollableArea()->GetScrollOffset().Height()); |
| 548 | 538 |
| 549 RuntimeEnabledFeatures::setFractionalScrollOffsetsEnabled( | 539 RuntimeEnabledFeatures::setFractionalScrollOffsetsEnabled( |
| 550 origFractionalOffsetsEnabled); | 540 orig_fractional_offsets_enabled); |
| 551 } | 541 } |
| 552 | 542 |
| 553 // Test that the viewport's scroll offset is always appropriately bounded such | 543 // Test that the viewport's scroll offset is always appropriately bounded such |
| 554 // that the visual viewport always stays within the bounds of the main frame. | 544 // that the visual viewport always stays within the bounds of the main frame. |
| 555 TEST_P(VisualViewportTest, TestOffsetClamping) { | 545 TEST_P(VisualViewportTest, TestOffsetClamping) { |
| 556 initializeWithDesktopSettings(); | 546 InitializeWithDesktopSettings(); |
| 557 webViewImpl()->Resize(IntSize(320, 240)); | 547 WebViewImpl()->Resize(IntSize(320, 240)); |
| 558 | 548 |
| 559 navigateTo("about:blank"); | 549 NavigateTo("about:blank"); |
| 560 forceFullCompositingUpdate(); | 550 ForceFullCompositingUpdate(); |
| 561 | 551 |
| 562 // Visual viewport should be initialized to same size as frame so no scrolling | 552 // Visual viewport should be initialized to same size as frame so no scrolling |
| 563 // possible. | 553 // possible. |
| 564 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 554 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 565 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), | 555 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), |
| 566 visualViewport.VisibleRect().Location()); | 556 visual_viewport.VisibleRect().Location()); |
| 567 | 557 |
| 568 visualViewport.SetLocation(FloatPoint(-1, -2)); | 558 visual_viewport.SetLocation(FloatPoint(-1, -2)); |
| 569 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), | 559 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), |
| 570 visualViewport.VisibleRect().Location()); | 560 visual_viewport.VisibleRect().Location()); |
| 571 | 561 |
| 572 visualViewport.SetLocation(FloatPoint(100, 200)); | 562 visual_viewport.SetLocation(FloatPoint(100, 200)); |
| 573 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), | 563 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), |
| 574 visualViewport.VisibleRect().Location()); | 564 visual_viewport.VisibleRect().Location()); |
| 575 | 565 |
| 576 visualViewport.SetLocation(FloatPoint(-5, 10)); | 566 visual_viewport.SetLocation(FloatPoint(-5, 10)); |
| 577 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), | 567 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), |
| 578 visualViewport.VisibleRect().Location()); | 568 visual_viewport.VisibleRect().Location()); |
| 579 | 569 |
| 580 // Scale by 2x. The viewport's visible rect should now have a size of 160x120. | 570 // Scale by 2x. The viewport's visible rect should now have a size of 160x120. |
| 581 visualViewport.SetScale(2); | 571 visual_viewport.SetScale(2); |
| 582 FloatPoint location(10, 50); | 572 FloatPoint location(10, 50); |
| 583 visualViewport.SetLocation(location); | 573 visual_viewport.SetLocation(location); |
| 584 EXPECT_FLOAT_POINT_EQ(location, visualViewport.VisibleRect().Location()); | 574 EXPECT_FLOAT_POINT_EQ(location, visual_viewport.VisibleRect().Location()); |
| 585 | 575 |
| 586 visualViewport.SetLocation(FloatPoint(1000, 2000)); | 576 visual_viewport.SetLocation(FloatPoint(1000, 2000)); |
| 587 EXPECT_FLOAT_POINT_EQ(FloatPoint(160, 120), | 577 EXPECT_FLOAT_POINT_EQ(FloatPoint(160, 120), |
| 588 visualViewport.VisibleRect().Location()); | 578 visual_viewport.VisibleRect().Location()); |
| 589 | 579 |
| 590 visualViewport.SetLocation(FloatPoint(-1000, -2000)); | 580 visual_viewport.SetLocation(FloatPoint(-1000, -2000)); |
| 591 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), | 581 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), |
| 592 visualViewport.VisibleRect().Location()); | 582 visual_viewport.VisibleRect().Location()); |
| 593 | 583 |
| 594 // Make sure offset gets clamped on scale out. Scale to 1.25 so the viewport | 584 // Make sure offset gets clamped on scale out. Scale to 1.25 so the viewport |
| 595 // is 256x192. | 585 // is 256x192. |
| 596 visualViewport.SetLocation(FloatPoint(160, 120)); | 586 visual_viewport.SetLocation(FloatPoint(160, 120)); |
| 597 visualViewport.SetScale(1.25); | 587 visual_viewport.SetScale(1.25); |
| 598 EXPECT_FLOAT_POINT_EQ(FloatPoint(64, 48), | 588 EXPECT_FLOAT_POINT_EQ(FloatPoint(64, 48), |
| 599 visualViewport.VisibleRect().Location()); | 589 visual_viewport.VisibleRect().Location()); |
| 600 | 590 |
| 601 // Scale out smaller than 1. | 591 // Scale out smaller than 1. |
| 602 visualViewport.SetScale(0.25); | 592 visual_viewport.SetScale(0.25); |
| 603 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), | 593 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), |
| 604 visualViewport.VisibleRect().Location()); | 594 visual_viewport.VisibleRect().Location()); |
| 605 } | 595 } |
| 606 | 596 |
| 607 // Test that the viewport can be scrolled around only within the main frame in | 597 // Test that the viewport can be scrolled around only within the main frame in |
| 608 // the presence of viewport resizes, as would be the case if the on screen | 598 // the presence of viewport resizes, as would be the case if the on screen |
| 609 // keyboard came up. | 599 // keyboard came up. |
| 610 TEST_P(VisualViewportTest, TestOffsetClampingWithResize) { | 600 TEST_P(VisualViewportTest, TestOffsetClampingWithResize) { |
| 611 initializeWithDesktopSettings(); | 601 InitializeWithDesktopSettings(); |
| 612 webViewImpl()->Resize(IntSize(320, 240)); | 602 WebViewImpl()->Resize(IntSize(320, 240)); |
| 613 | 603 |
| 614 navigateTo("about:blank"); | 604 NavigateTo("about:blank"); |
| 615 forceFullCompositingUpdate(); | 605 ForceFullCompositingUpdate(); |
| 616 | 606 |
| 617 // Visual viewport should be initialized to same size as frame so no scrolling | 607 // Visual viewport should be initialized to same size as frame so no scrolling |
| 618 // possible. | 608 // possible. |
| 619 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 609 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 620 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), | 610 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), |
| 621 visualViewport.VisibleRect().Location()); | 611 visual_viewport.VisibleRect().Location()); |
| 622 | 612 |
| 623 // Shrink the viewport vertically. The resize shouldn't affect the location, | 613 // Shrink the viewport vertically. The resize shouldn't affect the location, |
| 624 // but it should allow vertical scrolling. | 614 // but it should allow vertical scrolling. |
| 625 visualViewport.SetSize(IntSize(320, 200)); | 615 visual_viewport.SetSize(IntSize(320, 200)); |
| 626 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), | 616 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), |
| 627 visualViewport.VisibleRect().Location()); | 617 visual_viewport.VisibleRect().Location()); |
| 628 visualViewport.SetLocation(FloatPoint(10, 20)); | 618 visual_viewport.SetLocation(FloatPoint(10, 20)); |
| 629 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 20), | 619 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 20), |
| 630 visualViewport.VisibleRect().Location()); | 620 visual_viewport.VisibleRect().Location()); |
| 631 visualViewport.SetLocation(FloatPoint(0, 100)); | 621 visual_viewport.SetLocation(FloatPoint(0, 100)); |
| 632 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 40), | 622 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 40), |
| 633 visualViewport.VisibleRect().Location()); | 623 visual_viewport.VisibleRect().Location()); |
| 634 visualViewport.SetLocation(FloatPoint(0, 10)); | 624 visual_viewport.SetLocation(FloatPoint(0, 10)); |
| 635 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 10), | 625 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 10), |
| 636 visualViewport.VisibleRect().Location()); | 626 visual_viewport.VisibleRect().Location()); |
| 637 visualViewport.SetLocation(FloatPoint(0, -100)); | 627 visual_viewport.SetLocation(FloatPoint(0, -100)); |
| 638 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), | 628 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), |
| 639 visualViewport.VisibleRect().Location()); | 629 visual_viewport.VisibleRect().Location()); |
| 640 | 630 |
| 641 // Repeat the above but for horizontal dimension. | 631 // Repeat the above but for horizontal dimension. |
| 642 visualViewport.SetSize(IntSize(280, 240)); | 632 visual_viewport.SetSize(IntSize(280, 240)); |
| 643 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), | 633 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), |
| 644 visualViewport.VisibleRect().Location()); | 634 visual_viewport.VisibleRect().Location()); |
| 645 visualViewport.SetLocation(FloatPoint(10, 20)); | 635 visual_viewport.SetLocation(FloatPoint(10, 20)); |
| 646 EXPECT_FLOAT_POINT_EQ(FloatPoint(10, 0), | 636 EXPECT_FLOAT_POINT_EQ(FloatPoint(10, 0), |
| 647 visualViewport.VisibleRect().Location()); | 637 visual_viewport.VisibleRect().Location()); |
| 648 visualViewport.SetLocation(FloatPoint(100, 0)); | 638 visual_viewport.SetLocation(FloatPoint(100, 0)); |
| 649 EXPECT_FLOAT_POINT_EQ(FloatPoint(40, 0), | 639 EXPECT_FLOAT_POINT_EQ(FloatPoint(40, 0), |
| 650 visualViewport.VisibleRect().Location()); | 640 visual_viewport.VisibleRect().Location()); |
| 651 visualViewport.SetLocation(FloatPoint(10, 0)); | 641 visual_viewport.SetLocation(FloatPoint(10, 0)); |
| 652 EXPECT_FLOAT_POINT_EQ(FloatPoint(10, 0), | 642 EXPECT_FLOAT_POINT_EQ(FloatPoint(10, 0), |
| 653 visualViewport.VisibleRect().Location()); | 643 visual_viewport.VisibleRect().Location()); |
| 654 visualViewport.SetLocation(FloatPoint(-100, 0)); | 644 visual_viewport.SetLocation(FloatPoint(-100, 0)); |
| 655 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), | 645 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), |
| 656 visualViewport.VisibleRect().Location()); | 646 visual_viewport.VisibleRect().Location()); |
| 657 | 647 |
| 658 // Now with both dimensions. | 648 // Now with both dimensions. |
| 659 visualViewport.SetSize(IntSize(280, 200)); | 649 visual_viewport.SetSize(IntSize(280, 200)); |
| 660 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), | 650 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), |
| 661 visualViewport.VisibleRect().Location()); | 651 visual_viewport.VisibleRect().Location()); |
| 662 visualViewport.SetLocation(FloatPoint(10, 20)); | 652 visual_viewport.SetLocation(FloatPoint(10, 20)); |
| 663 EXPECT_FLOAT_POINT_EQ(FloatPoint(10, 20), | 653 EXPECT_FLOAT_POINT_EQ(FloatPoint(10, 20), |
| 664 visualViewport.VisibleRect().Location()); | 654 visual_viewport.VisibleRect().Location()); |
| 665 visualViewport.SetLocation(FloatPoint(100, 100)); | 655 visual_viewport.SetLocation(FloatPoint(100, 100)); |
| 666 EXPECT_FLOAT_POINT_EQ(FloatPoint(40, 40), | 656 EXPECT_FLOAT_POINT_EQ(FloatPoint(40, 40), |
| 667 visualViewport.VisibleRect().Location()); | 657 visual_viewport.VisibleRect().Location()); |
| 668 visualViewport.SetLocation(FloatPoint(10, 3)); | 658 visual_viewport.SetLocation(FloatPoint(10, 3)); |
| 669 EXPECT_FLOAT_POINT_EQ(FloatPoint(10, 3), | 659 EXPECT_FLOAT_POINT_EQ(FloatPoint(10, 3), |
| 670 visualViewport.VisibleRect().Location()); | 660 visual_viewport.VisibleRect().Location()); |
| 671 visualViewport.SetLocation(FloatPoint(-10, -4)); | 661 visual_viewport.SetLocation(FloatPoint(-10, -4)); |
| 672 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), | 662 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), |
| 673 visualViewport.VisibleRect().Location()); | 663 visual_viewport.VisibleRect().Location()); |
| 674 } | 664 } |
| 675 | 665 |
| 676 // Test that the viewport is scrollable but bounded appropriately within the | 666 // Test that the viewport is scrollable but bounded appropriately within the |
| 677 // main frame when we apply both scaling and resizes. | 667 // main frame when we apply both scaling and resizes. |
| 678 TEST_P(VisualViewportTest, TestOffsetClampingWithResizeAndScale) { | 668 TEST_P(VisualViewportTest, TestOffsetClampingWithResizeAndScale) { |
| 679 initializeWithDesktopSettings(); | 669 InitializeWithDesktopSettings(); |
| 680 webViewImpl()->Resize(IntSize(320, 240)); | 670 WebViewImpl()->Resize(IntSize(320, 240)); |
| 681 | 671 |
| 682 navigateTo("about:blank"); | 672 NavigateTo("about:blank"); |
| 683 forceFullCompositingUpdate(); | 673 ForceFullCompositingUpdate(); |
| 684 | 674 |
| 685 // Visual viewport should be initialized to same size as WebView so no | 675 // Visual viewport should be initialized to same size as WebView so no |
| 686 // scrolling possible. | 676 // scrolling possible. |
| 687 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 677 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 688 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), | 678 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), |
| 689 visualViewport.VisibleRect().Location()); | 679 visual_viewport.VisibleRect().Location()); |
| 690 | 680 |
| 691 // Zoom in to 2X so we can scroll the viewport to 160x120. | 681 // Zoom in to 2X so we can scroll the viewport to 160x120. |
| 692 visualViewport.SetScale(2); | 682 visual_viewport.SetScale(2); |
| 693 visualViewport.SetLocation(FloatPoint(200, 200)); | 683 visual_viewport.SetLocation(FloatPoint(200, 200)); |
| 694 EXPECT_FLOAT_POINT_EQ(FloatPoint(160, 120), | 684 EXPECT_FLOAT_POINT_EQ(FloatPoint(160, 120), |
| 695 visualViewport.VisibleRect().Location()); | 685 visual_viewport.VisibleRect().Location()); |
| 696 | 686 |
| 697 // Now resize the viewport to make it 10px smaller. Since we're zoomed in by | 687 // Now resize the viewport to make it 10px smaller. Since we're zoomed in by |
| 698 // 2X it should allow us to scroll by 5px more. | 688 // 2X it should allow us to scroll by 5px more. |
| 699 visualViewport.SetSize(IntSize(310, 230)); | 689 visual_viewport.SetSize(IntSize(310, 230)); |
| 700 visualViewport.SetLocation(FloatPoint(200, 200)); | 690 visual_viewport.SetLocation(FloatPoint(200, 200)); |
| 701 EXPECT_FLOAT_POINT_EQ(FloatPoint(165, 125), | 691 EXPECT_FLOAT_POINT_EQ(FloatPoint(165, 125), |
| 702 visualViewport.VisibleRect().Location()); | 692 visual_viewport.VisibleRect().Location()); |
| 703 | 693 |
| 704 // The viewport can be larger than the main frame (currently 320, 240) though | 694 // The viewport can be larger than the main frame (currently 320, 240) though |
| 705 // typically the scale will be clamped to prevent it from actually being | 695 // typically the scale will be clamped to prevent it from actually being |
| 706 // larger. | 696 // larger. |
| 707 visualViewport.SetSize(IntSize(330, 250)); | 697 visual_viewport.SetSize(IntSize(330, 250)); |
| 708 EXPECT_SIZE_EQ(IntSize(330, 250), visualViewport.Size()); | 698 EXPECT_SIZE_EQ(IntSize(330, 250), visual_viewport.Size()); |
| 709 | 699 |
| 710 // Resize both the viewport and the frame to be larger. | 700 // Resize both the viewport and the frame to be larger. |
| 711 webViewImpl()->Resize(IntSize(640, 480)); | 701 WebViewImpl()->Resize(IntSize(640, 480)); |
| 712 webViewImpl()->UpdateAllLifecyclePhases(); | 702 WebViewImpl()->UpdateAllLifecyclePhases(); |
| 713 EXPECT_SIZE_EQ(IntSize(webViewImpl()->Size()), visualViewport.Size()); | 703 EXPECT_SIZE_EQ(IntSize(WebViewImpl()->Size()), visual_viewport.Size()); |
| 714 EXPECT_SIZE_EQ(IntSize(webViewImpl()->Size()), | 704 EXPECT_SIZE_EQ(IntSize(WebViewImpl()->Size()), |
| 715 frame()->View()->FrameRect().Size()); | 705 GetFrame()->View()->FrameRect().Size()); |
| 716 visualViewport.SetLocation(FloatPoint(1000, 1000)); | 706 visual_viewport.SetLocation(FloatPoint(1000, 1000)); |
| 717 EXPECT_FLOAT_POINT_EQ(FloatPoint(320, 240), | 707 EXPECT_FLOAT_POINT_EQ(FloatPoint(320, 240), |
| 718 visualViewport.VisibleRect().Location()); | 708 visual_viewport.VisibleRect().Location()); |
| 719 | 709 |
| 720 // Make sure resizing the viewport doesn't change its offset if the resize | 710 // Make sure resizing the viewport doesn't change its offset if the resize |
| 721 // doesn't make the viewport go out of bounds. | 711 // doesn't make the viewport go out of bounds. |
| 722 visualViewport.SetLocation(FloatPoint(200, 200)); | 712 visual_viewport.SetLocation(FloatPoint(200, 200)); |
| 723 visualViewport.SetSize(IntSize(880, 560)); | 713 visual_viewport.SetSize(IntSize(880, 560)); |
| 724 EXPECT_FLOAT_POINT_EQ(FloatPoint(200, 200), | 714 EXPECT_FLOAT_POINT_EQ(FloatPoint(200, 200), |
| 725 visualViewport.VisibleRect().Location()); | 715 visual_viewport.VisibleRect().Location()); |
| 726 } | 716 } |
| 727 | 717 |
| 728 // The main FrameView's size should be set such that its the size of the visual | 718 // The main FrameView's size should be set such that its the size of the visual |
| 729 // viewport at minimum scale. If there's no explicit minimum scale set, the | 719 // viewport at minimum scale. If there's no explicit minimum scale set, the |
| 730 // FrameView should be set to the content width and height derived by the aspect | 720 // FrameView should be set to the content width and height derived by the aspect |
| 731 // ratio. | 721 // ratio. |
| 732 TEST_P(VisualViewportTest, TestFrameViewSizedToContent) { | 722 TEST_P(VisualViewportTest, TestFrameViewSizedToContent) { |
| 733 initializeWithAndroidSettings(); | 723 InitializeWithAndroidSettings(); |
| 734 webViewImpl()->Resize(IntSize(320, 240)); | 724 WebViewImpl()->Resize(IntSize(320, 240)); |
| 735 | 725 |
| 736 registerMockedHttpURLLoad("200-by-300-viewport.html"); | 726 RegisterMockedHttpURLLoad("200-by-300-viewport.html"); |
| 737 navigateTo(m_baseURL + "200-by-300-viewport.html"); | 727 NavigateTo(base_url_ + "200-by-300-viewport.html"); |
| 738 | 728 |
| 739 webViewImpl()->Resize(IntSize(600, 800)); | 729 WebViewImpl()->Resize(IntSize(600, 800)); |
| 740 webViewImpl()->UpdateAllLifecyclePhases(); | 730 WebViewImpl()->UpdateAllLifecyclePhases(); |
| 741 | 731 |
| 742 // Note: the size is ceiled and should match the behavior in CC's | 732 // Note: the size is ceiled and should match the behavior in CC's |
| 743 // LayerImpl::bounds(). | 733 // LayerImpl::bounds(). |
| 744 EXPECT_SIZE_EQ( | 734 EXPECT_SIZE_EQ( |
| 745 IntSize(200, 267), | 735 IntSize(200, 267), |
| 746 webViewImpl()->MainFrameImpl()->GetFrameView()->FrameRect().Size()); | 736 WebViewImpl()->MainFrameImpl()->GetFrameView()->FrameRect().Size()); |
| 747 } | 737 } |
| 748 | 738 |
| 749 // The main FrameView's size should be set such that its the size of the visual | 739 // The main FrameView's size should be set such that its the size of the visual |
| 750 // viewport at minimum scale. On Desktop, the minimum scale is set at 1 so make | 740 // viewport at minimum scale. On Desktop, the minimum scale is set at 1 so make |
| 751 // sure the FrameView is sized to the viewport. | 741 // sure the FrameView is sized to the viewport. |
| 752 TEST_P(VisualViewportTest, TestFrameViewSizedToMinimumScale) { | 742 TEST_P(VisualViewportTest, TestFrameViewSizedToMinimumScale) { |
| 753 initializeWithDesktopSettings(); | 743 InitializeWithDesktopSettings(); |
| 754 webViewImpl()->Resize(IntSize(320, 240)); | 744 WebViewImpl()->Resize(IntSize(320, 240)); |
| 755 | 745 |
| 756 registerMockedHttpURLLoad("200-by-300.html"); | 746 RegisterMockedHttpURLLoad("200-by-300.html"); |
| 757 navigateTo(m_baseURL + "200-by-300.html"); | 747 NavigateTo(base_url_ + "200-by-300.html"); |
| 758 | 748 |
| 759 webViewImpl()->Resize(IntSize(100, 160)); | 749 WebViewImpl()->Resize(IntSize(100, 160)); |
| 760 webViewImpl()->UpdateAllLifecyclePhases(); | 750 WebViewImpl()->UpdateAllLifecyclePhases(); |
| 761 | 751 |
| 762 EXPECT_SIZE_EQ( | 752 EXPECT_SIZE_EQ( |
| 763 IntSize(100, 160), | 753 IntSize(100, 160), |
| 764 webViewImpl()->MainFrameImpl()->GetFrameView()->FrameRect().Size()); | 754 WebViewImpl()->MainFrameImpl()->GetFrameView()->FrameRect().Size()); |
| 765 } | 755 } |
| 766 | 756 |
| 767 // Test that attaching a new frame view resets the size of the inner viewport | 757 // Test that attaching a new frame view resets the size of the inner viewport |
| 768 // scroll layer. crbug.com/423189. | 758 // scroll layer. crbug.com/423189. |
| 769 TEST_P(VisualViewportTest, TestAttachingNewFrameSetsInnerScrollLayerSize) { | 759 TEST_P(VisualViewportTest, TestAttachingNewFrameSetsInnerScrollLayerSize) { |
| 770 initializeWithAndroidSettings(); | 760 InitializeWithAndroidSettings(); |
| 771 webViewImpl()->Resize(IntSize(320, 240)); | 761 WebViewImpl()->Resize(IntSize(320, 240)); |
| 772 | 762 |
| 773 // Load a wider page first, the navigation should resize the scroll layer to | 763 // Load a wider page first, the navigation should resize the scroll layer to |
| 774 // the smaller size on the second navigation. | 764 // the smaller size on the second navigation. |
| 775 registerMockedHttpURLLoad("content-width-1000.html"); | 765 RegisterMockedHttpURLLoad("content-width-1000.html"); |
| 776 navigateTo(m_baseURL + "content-width-1000.html"); | 766 NavigateTo(base_url_ + "content-width-1000.html"); |
| 777 webViewImpl()->UpdateAllLifecyclePhases(); | 767 WebViewImpl()->UpdateAllLifecyclePhases(); |
| 778 | 768 |
| 779 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 769 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 780 visualViewport.SetScale(2); | 770 visual_viewport.SetScale(2); |
| 781 visualViewport.Move(ScrollOffset(50, 60)); | 771 visual_viewport.Move(ScrollOffset(50, 60)); |
| 782 | 772 |
| 783 // Move and scale the viewport to make sure it gets reset in the navigation. | 773 // Move and scale the viewport to make sure it gets reset in the navigation. |
| 784 EXPECT_SIZE_EQ(FloatSize(50, 60), visualViewport.GetScrollOffset()); | 774 EXPECT_SIZE_EQ(FloatSize(50, 60), visual_viewport.GetScrollOffset()); |
| 785 EXPECT_EQ(2, visualViewport.Scale()); | 775 EXPECT_EQ(2, visual_viewport.Scale()); |
| 786 | 776 |
| 787 // Navigate again, this time the FrameView should be smaller. | 777 // Navigate again, this time the FrameView should be smaller. |
| 788 registerMockedHttpURLLoad("viewport-device-width.html"); | 778 RegisterMockedHttpURLLoad("viewport-device-width.html"); |
| 789 navigateTo(m_baseURL + "viewport-device-width.html"); | 779 NavigateTo(base_url_ + "viewport-device-width.html"); |
| 790 | 780 |
| 791 // Ensure the scroll layer matches the frame view's size. | 781 // Ensure the scroll layer matches the frame view's size. |
| 792 EXPECT_SIZE_EQ(FloatSize(320, 240), visualViewport.ScrollLayer()->Size()); | 782 EXPECT_SIZE_EQ(FloatSize(320, 240), visual_viewport.ScrollLayer()->Size()); |
| 793 | 783 |
| 794 EXPECT_EQ(static_cast<int>(CompositorSubElementId::kViewport), | 784 EXPECT_EQ(static_cast<int>(CompositorSubElementId::kViewport), |
| 795 visualViewport.ScrollLayer()->GetElementId().secondaryId); | 785 visual_viewport.ScrollLayer()->GetElementId().secondaryId); |
| 796 | 786 |
| 797 // Ensure the location and scale were reset. | 787 // Ensure the location and scale were reset. |
| 798 EXPECT_SIZE_EQ(FloatSize(), visualViewport.GetScrollOffset()); | 788 EXPECT_SIZE_EQ(FloatSize(), visual_viewport.GetScrollOffset()); |
| 799 EXPECT_EQ(1, visualViewport.Scale()); | 789 EXPECT_EQ(1, visual_viewport.Scale()); |
| 800 } | 790 } |
| 801 | 791 |
| 802 // The main FrameView's size should be set such that its the size of the visual | 792 // The main FrameView's size should be set such that its the size of the visual |
| 803 // viewport at minimum scale. Test that the FrameView is appropriately sized in | 793 // viewport at minimum scale. Test that the FrameView is appropriately sized in |
| 804 // the presence of a viewport <meta> tag. | 794 // the presence of a viewport <meta> tag. |
| 805 TEST_P(VisualViewportTest, TestFrameViewSizedToViewportMetaMinimumScale) { | 795 TEST_P(VisualViewportTest, TestFrameViewSizedToViewportMetaMinimumScale) { |
| 806 initializeWithAndroidSettings(); | 796 InitializeWithAndroidSettings(); |
| 807 webViewImpl()->Resize(IntSize(320, 240)); | 797 WebViewImpl()->Resize(IntSize(320, 240)); |
| 808 | 798 |
| 809 registerMockedHttpURLLoad("200-by-300-min-scale-2.html"); | 799 RegisterMockedHttpURLLoad("200-by-300-min-scale-2.html"); |
| 810 navigateTo(m_baseURL + "200-by-300-min-scale-2.html"); | 800 NavigateTo(base_url_ + "200-by-300-min-scale-2.html"); |
| 811 | 801 |
| 812 webViewImpl()->Resize(IntSize(100, 160)); | 802 WebViewImpl()->Resize(IntSize(100, 160)); |
| 813 webViewImpl()->UpdateAllLifecyclePhases(); | 803 WebViewImpl()->UpdateAllLifecyclePhases(); |
| 814 | 804 |
| 815 EXPECT_SIZE_EQ( | 805 EXPECT_SIZE_EQ( |
| 816 IntSize(50, 80), | 806 IntSize(50, 80), |
| 817 webViewImpl()->MainFrameImpl()->GetFrameView()->FrameRect().Size()); | 807 WebViewImpl()->MainFrameImpl()->GetFrameView()->FrameRect().Size()); |
| 818 } | 808 } |
| 819 | 809 |
| 820 // Test that the visual viewport still gets sized in AutoSize/AutoResize mode. | 810 // Test that the visual viewport still gets sized in AutoSize/AutoResize mode. |
| 821 TEST_P(VisualViewportTest, TestVisualViewportGetsSizeInAutoSizeMode) { | 811 TEST_P(VisualViewportTest, TestVisualViewportGetsSizeInAutoSizeMode) { |
| 822 initializeWithDesktopSettings(); | 812 InitializeWithDesktopSettings(); |
| 823 | 813 |
| 824 EXPECT_SIZE_EQ(IntSize(0, 0), IntSize(webViewImpl()->Size())); | 814 EXPECT_SIZE_EQ(IntSize(0, 0), IntSize(WebViewImpl()->Size())); |
| 825 EXPECT_SIZE_EQ(IntSize(0, 0), frame()->GetPage()->GetVisualViewport().Size()); | 815 EXPECT_SIZE_EQ(IntSize(0, 0), |
| 816 GetFrame()->GetPage()->GetVisualViewport().Size()); |
| 826 | 817 |
| 827 webViewImpl()->EnableAutoResizeMode(WebSize(10, 10), WebSize(1000, 1000)); | 818 WebViewImpl()->EnableAutoResizeMode(WebSize(10, 10), WebSize(1000, 1000)); |
| 828 | 819 |
| 829 registerMockedHttpURLLoad("200-by-300.html"); | 820 RegisterMockedHttpURLLoad("200-by-300.html"); |
| 830 navigateTo(m_baseURL + "200-by-300.html"); | 821 NavigateTo(base_url_ + "200-by-300.html"); |
| 831 | 822 |
| 832 EXPECT_SIZE_EQ(IntSize(200, 300), | 823 EXPECT_SIZE_EQ(IntSize(200, 300), |
| 833 frame()->GetPage()->GetVisualViewport().Size()); | 824 GetFrame()->GetPage()->GetVisualViewport().Size()); |
| 834 } | 825 } |
| 835 | 826 |
| 836 // Test that the text selection handle's position accounts for the visual | 827 // Test that the text selection handle's position accounts for the visual |
| 837 // viewport. | 828 // viewport. |
| 838 TEST_P(VisualViewportTest, TestTextSelectionHandles) { | 829 TEST_P(VisualViewportTest, TestTextSelectionHandles) { |
| 839 initializeWithDesktopSettings(); | 830 InitializeWithDesktopSettings(); |
| 840 webViewImpl()->Resize(IntSize(500, 800)); | 831 WebViewImpl()->Resize(IntSize(500, 800)); |
| 841 | 832 |
| 842 registerMockedHttpURLLoad("pinch-viewport-input-field.html"); | 833 RegisterMockedHttpURLLoad("pinch-viewport-input-field.html"); |
| 843 navigateTo(m_baseURL + "pinch-viewport-input-field.html"); | 834 NavigateTo(base_url_ + "pinch-viewport-input-field.html"); |
| 844 | 835 |
| 845 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 836 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 846 webViewImpl()->SetInitialFocus(false); | 837 WebViewImpl()->SetInitialFocus(false); |
| 847 | 838 |
| 848 WebRect originalAnchor; | 839 WebRect original_anchor; |
| 849 WebRect originalFocus; | 840 WebRect original_focus; |
| 850 webViewImpl()->SelectionBounds(originalAnchor, originalFocus); | 841 WebViewImpl()->SelectionBounds(original_anchor, original_focus); |
| 851 | 842 |
| 852 webViewImpl()->SetPageScaleFactor(2); | 843 WebViewImpl()->SetPageScaleFactor(2); |
| 853 visualViewport.SetLocation(FloatPoint(100, 400)); | 844 visual_viewport.SetLocation(FloatPoint(100, 400)); |
| 854 | 845 |
| 855 WebRect anchor; | 846 WebRect anchor; |
| 856 WebRect focus; | 847 WebRect focus; |
| 857 webViewImpl()->SelectionBounds(anchor, focus); | 848 WebViewImpl()->SelectionBounds(anchor, focus); |
| 858 | 849 |
| 859 IntPoint expected(IntRect(originalAnchor).Location()); | 850 IntPoint expected(IntRect(original_anchor).Location()); |
| 860 expected.MoveBy(-FlooredIntPoint(visualViewport.VisibleRect().Location())); | 851 expected.MoveBy(-FlooredIntPoint(visual_viewport.VisibleRect().Location())); |
| 861 expected.Scale(visualViewport.Scale(), visualViewport.Scale()); | 852 expected.Scale(visual_viewport.Scale(), visual_viewport.Scale()); |
| 862 | 853 |
| 863 EXPECT_POINT_EQ(expected, IntRect(anchor).Location()); | 854 EXPECT_POINT_EQ(expected, IntRect(anchor).Location()); |
| 864 EXPECT_POINT_EQ(expected, IntRect(focus).Location()); | 855 EXPECT_POINT_EQ(expected, IntRect(focus).Location()); |
| 865 | 856 |
| 866 // FIXME(bokan) - http://crbug.com/364154 - Figure out how to test text | 857 // FIXME(bokan) - http://crbug.com/364154 - Figure out how to test text |
| 867 // selection as well rather than just carret. | 858 // selection as well rather than just carret. |
| 868 } | 859 } |
| 869 | 860 |
| 870 // Test that the HistoryItem for the page stores the visual viewport's offset | 861 // Test that the HistoryItem for the page stores the visual viewport's offset |
| 871 // and scale. | 862 // and scale. |
| 872 TEST_P(VisualViewportTest, TestSavedToHistoryItem) { | 863 TEST_P(VisualViewportTest, TestSavedToHistoryItem) { |
| 873 initializeWithDesktopSettings(); | 864 InitializeWithDesktopSettings(); |
| 874 webViewImpl()->Resize(IntSize(200, 300)); | 865 WebViewImpl()->Resize(IntSize(200, 300)); |
| 875 webViewImpl()->UpdateAllLifecyclePhases(); | 866 WebViewImpl()->UpdateAllLifecyclePhases(); |
| 876 | 867 |
| 877 registerMockedHttpURLLoad("200-by-300.html"); | 868 RegisterMockedHttpURLLoad("200-by-300.html"); |
| 878 navigateTo(m_baseURL + "200-by-300.html"); | 869 NavigateTo(base_url_ + "200-by-300.html"); |
| 879 | 870 |
| 880 EXPECT_SIZE_EQ(ScrollOffset(0, 0), | 871 EXPECT_SIZE_EQ(ScrollOffset(0, 0), |
| 881 ToLocalFrame(webViewImpl()->GetPage()->MainFrame()) | 872 ToLocalFrame(WebViewImpl()->GetPage()->MainFrame()) |
| 882 ->Loader() | 873 ->Loader() |
| 883 .GetDocumentLoader() | 874 .GetDocumentLoader() |
| 884 ->GetHistoryItem() | 875 ->GetHistoryItem() |
| 885 ->VisualViewportScrollOffset()); | 876 ->VisualViewportScrollOffset()); |
| 886 | 877 |
| 887 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 878 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 888 visualViewport.SetScale(2); | 879 visual_viewport.SetScale(2); |
| 889 | 880 |
| 890 EXPECT_EQ(2, ToLocalFrame(webViewImpl()->GetPage()->MainFrame()) | 881 EXPECT_EQ(2, ToLocalFrame(WebViewImpl()->GetPage()->MainFrame()) |
| 891 ->Loader() | 882 ->Loader() |
| 892 .GetDocumentLoader() | 883 .GetDocumentLoader() |
| 893 ->GetHistoryItem() | 884 ->GetHistoryItem() |
| 894 ->PageScaleFactor()); | 885 ->PageScaleFactor()); |
| 895 | 886 |
| 896 visualViewport.SetLocation(FloatPoint(10, 20)); | 887 visual_viewport.SetLocation(FloatPoint(10, 20)); |
| 897 | 888 |
| 898 EXPECT_SIZE_EQ(ScrollOffset(10, 20), | 889 EXPECT_SIZE_EQ(ScrollOffset(10, 20), |
| 899 ToLocalFrame(webViewImpl()->GetPage()->MainFrame()) | 890 ToLocalFrame(WebViewImpl()->GetPage()->MainFrame()) |
| 900 ->Loader() | 891 ->Loader() |
| 901 .GetDocumentLoader() | 892 .GetDocumentLoader() |
| 902 ->GetHistoryItem() | 893 ->GetHistoryItem() |
| 903 ->VisualViewportScrollOffset()); | 894 ->VisualViewportScrollOffset()); |
| 904 } | 895 } |
| 905 | 896 |
| 906 // Test restoring a HistoryItem properly restores the visual viewport's state. | 897 // Test restoring a HistoryItem properly restores the visual viewport's state. |
| 907 TEST_P(VisualViewportTest, TestRestoredFromHistoryItem) { | 898 TEST_P(VisualViewportTest, TestRestoredFromHistoryItem) { |
| 908 initializeWithDesktopSettings(); | 899 InitializeWithDesktopSettings(); |
| 909 webViewImpl()->Resize(IntSize(200, 300)); | 900 WebViewImpl()->Resize(IntSize(200, 300)); |
| 910 | 901 |
| 911 registerMockedHttpURLLoad("200-by-300.html"); | 902 RegisterMockedHttpURLLoad("200-by-300.html"); |
| 912 | 903 |
| 913 WebHistoryItem item; | 904 WebHistoryItem item; |
| 914 item.Initialize(); | 905 item.Initialize(); |
| 915 WebURL destinationURL(URLTestHelpers::ToKURL(m_baseURL + "200-by-300.html")); | 906 WebURL destination_url(URLTestHelpers::ToKURL(base_url_ + "200-by-300.html")); |
| 916 item.SetURLString(destinationURL.GetString()); | 907 item.SetURLString(destination_url.GetString()); |
| 917 item.SetVisualViewportScrollOffset(WebFloatPoint(100, 120)); | 908 item.SetVisualViewportScrollOffset(WebFloatPoint(100, 120)); |
| 918 item.SetPageScaleFactor(2); | 909 item.SetPageScaleFactor(2); |
| 919 | 910 |
| 920 FrameTestHelpers::LoadHistoryItem(webViewImpl()->MainFrame(), item, | 911 FrameTestHelpers::LoadHistoryItem(WebViewImpl()->MainFrame(), item, |
| 921 kWebHistoryDifferentDocumentLoad, | 912 kWebHistoryDifferentDocumentLoad, |
| 922 WebCachePolicy::kUseProtocolCachePolicy); | 913 WebCachePolicy::kUseProtocolCachePolicy); |
| 923 | 914 |
| 924 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 915 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 925 EXPECT_EQ(2, visualViewport.Scale()); | 916 EXPECT_EQ(2, visual_viewport.Scale()); |
| 926 | 917 |
| 927 EXPECT_FLOAT_POINT_EQ(FloatPoint(100, 120), | 918 EXPECT_FLOAT_POINT_EQ(FloatPoint(100, 120), |
| 928 visualViewport.VisibleRect().Location()); | 919 visual_viewport.VisibleRect().Location()); |
| 929 } | 920 } |
| 930 | 921 |
| 931 // Test restoring a HistoryItem without the visual viewport offset falls back to | 922 // Test restoring a HistoryItem without the visual viewport offset falls back to |
| 932 // distributing the scroll offset between the main frame and the visual | 923 // distributing the scroll offset between the main frame and the visual |
| 933 // viewport. | 924 // viewport. |
| 934 TEST_P(VisualViewportTest, TestRestoredFromLegacyHistoryItem) { | 925 TEST_P(VisualViewportTest, TestRestoredFromLegacyHistoryItem) { |
| 935 initializeWithDesktopSettings(); | 926 InitializeWithDesktopSettings(); |
| 936 webViewImpl()->Resize(IntSize(100, 150)); | 927 WebViewImpl()->Resize(IntSize(100, 150)); |
| 937 | 928 |
| 938 registerMockedHttpURLLoad("200-by-300-viewport.html"); | 929 RegisterMockedHttpURLLoad("200-by-300-viewport.html"); |
| 939 | 930 |
| 940 WebHistoryItem item; | 931 WebHistoryItem item; |
| 941 item.Initialize(); | 932 item.Initialize(); |
| 942 WebURL destinationURL( | 933 WebURL destination_url( |
| 943 URLTestHelpers::ToKURL(m_baseURL + "200-by-300-viewport.html")); | 934 URLTestHelpers::ToKURL(base_url_ + "200-by-300-viewport.html")); |
| 944 item.SetURLString(destinationURL.GetString()); | 935 item.SetURLString(destination_url.GetString()); |
| 945 // (-1, -1) will be used if the HistoryItem is an older version prior to | 936 // (-1, -1) will be used if the HistoryItem is an older version prior to |
| 946 // having visual viewport scroll offset. | 937 // having visual viewport scroll offset. |
| 947 item.SetVisualViewportScrollOffset(WebFloatPoint(-1, -1)); | 938 item.SetVisualViewportScrollOffset(WebFloatPoint(-1, -1)); |
| 948 item.SetScrollOffset(WebPoint(120, 180)); | 939 item.SetScrollOffset(WebPoint(120, 180)); |
| 949 item.SetPageScaleFactor(2); | 940 item.SetPageScaleFactor(2); |
| 950 | 941 |
| 951 FrameTestHelpers::LoadHistoryItem(webViewImpl()->MainFrame(), item, | 942 FrameTestHelpers::LoadHistoryItem(WebViewImpl()->MainFrame(), item, |
| 952 kWebHistoryDifferentDocumentLoad, | 943 kWebHistoryDifferentDocumentLoad, |
| 953 WebCachePolicy::kUseProtocolCachePolicy); | 944 WebCachePolicy::kUseProtocolCachePolicy); |
| 954 | 945 |
| 955 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 946 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 956 EXPECT_EQ(2, visualViewport.Scale()); | 947 EXPECT_EQ(2, visual_viewport.Scale()); |
| 957 EXPECT_SIZE_EQ( | 948 EXPECT_SIZE_EQ( |
| 958 ScrollOffset(100, 150), | 949 ScrollOffset(100, 150), |
| 959 frame()->View()->LayoutViewportScrollableArea()->GetScrollOffset()); | 950 GetFrame()->View()->LayoutViewportScrollableArea()->GetScrollOffset()); |
| 960 EXPECT_FLOAT_POINT_EQ(FloatPoint(20, 30), | 951 EXPECT_FLOAT_POINT_EQ(FloatPoint(20, 30), |
| 961 visualViewport.VisibleRect().Location()); | 952 visual_viewport.VisibleRect().Location()); |
| 962 } | 953 } |
| 963 | 954 |
| 964 // Test that navigation to a new page with a different sized main frame doesn't | 955 // Test that navigation to a new page with a different sized main frame doesn't |
| 965 // clobber the history item's main frame scroll offset. crbug.com/371867 | 956 // clobber the history item's main frame scroll offset. crbug.com/371867 |
| 966 TEST_P(VisualViewportTest, | 957 TEST_P(VisualViewportTest, |
| 967 TestNavigateToSmallerFrameViewHistoryItemClobberBug) { | 958 TestNavigateToSmallerFrameViewHistoryItemClobberBug) { |
| 968 initializeWithAndroidSettings(); | 959 InitializeWithAndroidSettings(); |
| 969 webViewImpl()->Resize(IntSize(400, 400)); | 960 WebViewImpl()->Resize(IntSize(400, 400)); |
| 970 webViewImpl()->UpdateAllLifecyclePhases(); | 961 WebViewImpl()->UpdateAllLifecyclePhases(); |
| 971 | 962 |
| 972 registerMockedHttpURLLoad("content-width-1000.html"); | 963 RegisterMockedHttpURLLoad("content-width-1000.html"); |
| 973 navigateTo(m_baseURL + "content-width-1000.html"); | 964 NavigateTo(base_url_ + "content-width-1000.html"); |
| 974 | 965 |
| 975 FrameView* frameView = webViewImpl()->MainFrameImpl()->GetFrameView(); | 966 FrameView* frame_view = WebViewImpl()->MainFrameImpl()->GetFrameView(); |
| 976 frameView->LayoutViewportScrollableArea()->SetScrollOffset( | 967 frame_view->LayoutViewportScrollableArea()->SetScrollOffset( |
| 977 ScrollOffset(0, 1000), kProgrammaticScroll); | 968 ScrollOffset(0, 1000), kProgrammaticScroll); |
| 978 | 969 |
| 979 EXPECT_SIZE_EQ(IntSize(1000, 1000), frameView->FrameRect().Size()); | 970 EXPECT_SIZE_EQ(IntSize(1000, 1000), frame_view->FrameRect().Size()); |
| 980 | 971 |
| 981 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 972 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 982 visualViewport.SetScale(2); | 973 visual_viewport.SetScale(2); |
| 983 visualViewport.SetLocation(FloatPoint(350, 350)); | 974 visual_viewport.SetLocation(FloatPoint(350, 350)); |
| 984 | 975 |
| 985 Persistent<HistoryItem> firstItem = webViewImpl() | 976 Persistent<HistoryItem> firstItem = WebViewImpl() |
| 986 ->MainFrameImpl() | 977 ->MainFrameImpl() |
| 987 ->GetFrame() | 978 ->GetFrame() |
| 988 ->Loader() | 979 ->Loader() |
| 989 .GetDocumentLoader() | 980 .GetDocumentLoader() |
| 990 ->GetHistoryItem(); | 981 ->GetHistoryItem(); |
| 991 EXPECT_SIZE_EQ(ScrollOffset(0, 1000), firstItem->GetScrollOffset()); | 982 EXPECT_SIZE_EQ(ScrollOffset(0, 1000), firstItem->GetScrollOffset()); |
| 992 | 983 |
| 993 // Now navigate to a page which causes a smaller frameView. Make sure that | 984 // Now navigate to a page which causes a smaller frame_view. Make sure that |
| 994 // navigating doesn't cause the history item to set a new scroll offset | 985 // navigating doesn't cause the history item to set a new scroll offset |
| 995 // before the item was replaced. | 986 // before the item was replaced. |
| 996 navigateTo("about:blank"); | 987 NavigateTo("about:blank"); |
| 997 frameView = webViewImpl()->MainFrameImpl()->GetFrameView(); | 988 frame_view = WebViewImpl()->MainFrameImpl()->GetFrameView(); |
| 998 | 989 |
| 999 EXPECT_NE(firstItem, webViewImpl() | 990 EXPECT_NE(firstItem, WebViewImpl() |
| 1000 ->MainFrameImpl() | 991 ->MainFrameImpl() |
| 1001 ->GetFrame() | 992 ->GetFrame() |
| 1002 ->Loader() | 993 ->Loader() |
| 1003 .GetDocumentLoader() | 994 .GetDocumentLoader() |
| 1004 ->GetHistoryItem()); | 995 ->GetHistoryItem()); |
| 1005 EXPECT_LT(frameView->FrameRect().Size().Width(), 1000); | 996 EXPECT_LT(frame_view->FrameRect().Size().Width(), 1000); |
| 1006 EXPECT_SIZE_EQ(ScrollOffset(0, 1000), firstItem->GetScrollOffset()); | 997 EXPECT_SIZE_EQ(ScrollOffset(0, 1000), firstItem->GetScrollOffset()); |
| 1007 } | 998 } |
| 1008 | 999 |
| 1009 // Test that the coordinates sent into moveRangeSelection are offset by the | 1000 // Test that the coordinates sent into moveRangeSelection are offset by the |
| 1010 // visual viewport's location. | 1001 // visual viewport's location. |
| 1011 TEST_P(VisualViewportTest, | 1002 TEST_P(VisualViewportTest, |
| 1012 DISABLED_TestWebFrameRangeAccountsForVisualViewportScroll) { | 1003 DISABLED_TestWebFrameRangeAccountsForVisualViewportScroll) { |
| 1013 initializeWithDesktopSettings(); | 1004 InitializeWithDesktopSettings(); |
| 1014 webViewImpl()->GetSettings()->SetDefaultFontSize(12); | 1005 WebViewImpl()->GetSettings()->SetDefaultFontSize(12); |
| 1015 webViewImpl()->Resize(WebSize(640, 480)); | 1006 WebViewImpl()->Resize(WebSize(640, 480)); |
| 1016 registerMockedHttpURLLoad("move_range.html"); | 1007 RegisterMockedHttpURLLoad("move_range.html"); |
| 1017 navigateTo(m_baseURL + "move_range.html"); | 1008 NavigateTo(base_url_ + "move_range.html"); |
| 1018 | 1009 |
| 1019 WebRect baseRect; | 1010 WebRect base_rect; |
| 1020 WebRect extentRect; | 1011 WebRect extent_rect; |
| 1021 | 1012 |
| 1022 webViewImpl()->SetPageScaleFactor(2); | 1013 WebViewImpl()->SetPageScaleFactor(2); |
| 1023 WebFrame* mainFrame = webViewImpl()->MainFrame(); | 1014 WebFrame* mainFrame = WebViewImpl()->MainFrame(); |
| 1024 | 1015 |
| 1025 // Select some text and get the base and extent rects (that's the start of | 1016 // Select some text and get the base and extent rects (that's the start of |
| 1026 // the range and its end). Do a sanity check that the expected text is | 1017 // the range and its end). Do a sanity check that the expected text is |
| 1027 // selected | 1018 // selected |
| 1028 mainFrame->ExecuteScript(WebScriptSource("selectRange();")); | 1019 mainFrame->ExecuteScript(WebScriptSource("selectRange();")); |
| 1029 EXPECT_EQ("ir", mainFrame->ToWebLocalFrame()->SelectionAsText().Utf8()); | 1020 EXPECT_EQ("ir", mainFrame->ToWebLocalFrame()->SelectionAsText().Utf8()); |
| 1030 | 1021 |
| 1031 webViewImpl()->SelectionBounds(baseRect, extentRect); | 1022 WebViewImpl()->SelectionBounds(base_rect, extent_rect); |
| 1032 WebPoint initialPoint(baseRect.x, baseRect.y); | 1023 WebPoint initialPoint(base_rect.x, base_rect.y); |
| 1033 WebPoint endPoint(extentRect.x, extentRect.y); | 1024 WebPoint endPoint(extent_rect.x, extent_rect.y); |
| 1034 | 1025 |
| 1035 // Move the visual viewport over and make the selection in the same | 1026 // Move the visual viewport over and make the selection in the same |
| 1036 // screen-space location. The selection should change to two characters to the | 1027 // screen-space location. The selection should change to two characters to the |
| 1037 // right and down one line. | 1028 // right and down one line. |
| 1038 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 1029 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 1039 visualViewport.Move(ScrollOffset(60, 25)); | 1030 visual_viewport.Move(ScrollOffset(60, 25)); |
| 1040 mainFrame->ToWebLocalFrame()->MoveRangeSelection(initialPoint, endPoint); | 1031 mainFrame->ToWebLocalFrame()->MoveRangeSelection(initialPoint, endPoint); |
| 1041 EXPECT_EQ("t ", mainFrame->ToWebLocalFrame()->SelectionAsText().Utf8()); | 1032 EXPECT_EQ("t ", mainFrame->ToWebLocalFrame()->SelectionAsText().Utf8()); |
| 1042 } | 1033 } |
| 1043 | 1034 |
| 1044 // Test that the scrollFocusedEditableElementIntoRect method works with the | 1035 // Test that the scrollFocusedEditableElementIntoRect method works with the |
| 1045 // visual viewport. | 1036 // visual viewport. |
| 1046 TEST_P(VisualViewportTest, DISABLED_TestScrollFocusedEditableElementIntoRect) { | 1037 TEST_P(VisualViewportTest, DISABLED_TestScrollFocusedEditableElementIntoRect) { |
| 1047 initializeWithDesktopSettings(); | 1038 InitializeWithDesktopSettings(); |
| 1048 webViewImpl()->Resize(IntSize(500, 300)); | 1039 WebViewImpl()->Resize(IntSize(500, 300)); |
| 1049 | 1040 |
| 1050 registerMockedHttpURLLoad("pinch-viewport-input-field.html"); | 1041 RegisterMockedHttpURLLoad("pinch-viewport-input-field.html"); |
| 1051 navigateTo(m_baseURL + "pinch-viewport-input-field.html"); | 1042 NavigateTo(base_url_ + "pinch-viewport-input-field.html"); |
| 1052 | 1043 |
| 1053 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 1044 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 1054 webViewImpl()->ResizeVisualViewport(IntSize(200, 100)); | 1045 WebViewImpl()->ResizeVisualViewport(IntSize(200, 100)); |
| 1055 webViewImpl()->SetInitialFocus(false); | 1046 WebViewImpl()->SetInitialFocus(false); |
| 1056 visualViewport.SetLocation(FloatPoint()); | 1047 visual_viewport.SetLocation(FloatPoint()); |
| 1057 webViewImpl()->ScrollFocusedEditableElementIntoRect(IntRect(0, 0, 500, 200)); | 1048 WebViewImpl()->ScrollFocusedEditableElementIntoRect(IntRect(0, 0, 500, 200)); |
| 1058 | 1049 |
| 1059 EXPECT_SIZE_EQ( | 1050 EXPECT_SIZE_EQ( |
| 1060 ScrollOffset(0, frame()->View()->MaximumScrollOffset().Height()), | 1051 ScrollOffset(0, GetFrame()->View()->MaximumScrollOffset().Height()), |
| 1061 frame()->View()->GetScrollOffset()); | 1052 GetFrame()->View()->GetScrollOffset()); |
| 1062 EXPECT_FLOAT_POINT_EQ(FloatPoint(150, 200), | 1053 EXPECT_FLOAT_POINT_EQ(FloatPoint(150, 200), |
| 1063 visualViewport.VisibleRect().Location()); | 1054 visual_viewport.VisibleRect().Location()); |
| 1064 | 1055 |
| 1065 // Try it again but with the page zoomed in | 1056 // Try it again but with the page zoomed in |
| 1066 frame()->View()->SetScrollOffset(ScrollOffset(0, 0), kProgrammaticScroll); | 1057 GetFrame()->View()->SetScrollOffset(ScrollOffset(0, 0), kProgrammaticScroll); |
| 1067 webViewImpl()->ResizeVisualViewport(IntSize(500, 300)); | 1058 WebViewImpl()->ResizeVisualViewport(IntSize(500, 300)); |
| 1068 visualViewport.SetLocation(FloatPoint(0, 0)); | 1059 visual_viewport.SetLocation(FloatPoint(0, 0)); |
| 1069 | 1060 |
| 1070 webViewImpl()->SetPageScaleFactor(2); | 1061 WebViewImpl()->SetPageScaleFactor(2); |
| 1071 webViewImpl()->ScrollFocusedEditableElementIntoRect(IntRect(0, 0, 500, 200)); | 1062 WebViewImpl()->ScrollFocusedEditableElementIntoRect(IntRect(0, 0, 500, 200)); |
| 1072 EXPECT_SIZE_EQ( | 1063 EXPECT_SIZE_EQ( |
| 1073 ScrollOffset(0, frame()->View()->MaximumScrollOffset().Height()), | 1064 ScrollOffset(0, GetFrame()->View()->MaximumScrollOffset().Height()), |
| 1074 frame()->View()->GetScrollOffset()); | 1065 GetFrame()->View()->GetScrollOffset()); |
| 1075 EXPECT_FLOAT_POINT_EQ(FloatPoint(125, 150), | 1066 EXPECT_FLOAT_POINT_EQ(FloatPoint(125, 150), |
| 1076 visualViewport.VisibleRect().Location()); | 1067 visual_viewport.VisibleRect().Location()); |
| 1077 | 1068 |
| 1078 // Once more but make sure that we don't move the visual viewport unless | 1069 // Once more but make sure that we don't move the visual viewport unless |
| 1079 // necessary. | 1070 // necessary. |
| 1080 registerMockedHttpURLLoad("pinch-viewport-input-field-long-and-wide.html"); | 1071 RegisterMockedHttpURLLoad("pinch-viewport-input-field-long-and-wide.html"); |
| 1081 navigateTo(m_baseURL + "pinch-viewport-input-field-long-and-wide.html"); | 1072 NavigateTo(base_url_ + "pinch-viewport-input-field-long-and-wide.html"); |
| 1082 webViewImpl()->SetInitialFocus(false); | 1073 WebViewImpl()->SetInitialFocus(false); |
| 1083 visualViewport.SetLocation(FloatPoint()); | 1074 visual_viewport.SetLocation(FloatPoint()); |
| 1084 frame()->View()->SetScrollOffset(ScrollOffset(0, 0), kProgrammaticScroll); | 1075 GetFrame()->View()->SetScrollOffset(ScrollOffset(0, 0), kProgrammaticScroll); |
| 1085 webViewImpl()->ResizeVisualViewport(IntSize(500, 300)); | 1076 WebViewImpl()->ResizeVisualViewport(IntSize(500, 300)); |
| 1086 visualViewport.SetLocation(FloatPoint(30, 50)); | 1077 visual_viewport.SetLocation(FloatPoint(30, 50)); |
| 1087 | 1078 |
| 1088 webViewImpl()->SetPageScaleFactor(2); | 1079 WebViewImpl()->SetPageScaleFactor(2); |
| 1089 webViewImpl()->ScrollFocusedEditableElementIntoRect(IntRect(0, 0, 500, 200)); | 1080 WebViewImpl()->ScrollFocusedEditableElementIntoRect(IntRect(0, 0, 500, 200)); |
| 1090 EXPECT_SIZE_EQ(ScrollOffset(200 - 30 - 75, 600 - 50 - 65), | 1081 EXPECT_SIZE_EQ(ScrollOffset(200 - 30 - 75, 600 - 50 - 65), |
| 1091 frame()->View()->GetScrollOffset()); | 1082 GetFrame()->View()->GetScrollOffset()); |
| 1092 EXPECT_FLOAT_POINT_EQ(FloatPoint(30, 50), | 1083 EXPECT_FLOAT_POINT_EQ(FloatPoint(30, 50), |
| 1093 visualViewport.VisibleRect().Location()); | 1084 visual_viewport.VisibleRect().Location()); |
| 1094 } | 1085 } |
| 1095 | 1086 |
| 1096 // Test that resizing the WebView causes ViewportConstrained objects to | 1087 // Test that resizing the WebView causes ViewportConstrained objects to |
| 1097 // relayout. | 1088 // relayout. |
| 1098 TEST_P(VisualViewportTest, TestWebViewResizeCausesViewportConstrainedLayout) { | 1089 TEST_P(VisualViewportTest, TestWebViewResizeCausesViewportConstrainedLayout) { |
| 1099 initializeWithDesktopSettings(); | 1090 InitializeWithDesktopSettings(); |
| 1100 webViewImpl()->Resize(IntSize(500, 300)); | 1091 WebViewImpl()->Resize(IntSize(500, 300)); |
| 1101 | 1092 |
| 1102 registerMockedHttpURLLoad("pinch-viewport-fixed-pos.html"); | 1093 RegisterMockedHttpURLLoad("pinch-viewport-fixed-pos.html"); |
| 1103 navigateTo(m_baseURL + "pinch-viewport-fixed-pos.html"); | 1094 NavigateTo(base_url_ + "pinch-viewport-fixed-pos.html"); |
| 1104 | 1095 |
| 1105 LayoutObject* navbar = | 1096 LayoutObject* navbar = |
| 1106 frame()->GetDocument()->getElementById("navbar")->GetLayoutObject(); | 1097 GetFrame()->GetDocument()->getElementById("navbar")->GetLayoutObject(); |
| 1107 | 1098 |
| 1108 EXPECT_FALSE(navbar->NeedsLayout()); | 1099 EXPECT_FALSE(navbar->NeedsLayout()); |
| 1109 | 1100 |
| 1110 frame()->View()->Resize(IntSize(500, 200)); | 1101 GetFrame()->View()->Resize(IntSize(500, 200)); |
| 1111 | 1102 |
| 1112 EXPECT_TRUE(navbar->NeedsLayout()); | 1103 EXPECT_TRUE(navbar->NeedsLayout()); |
| 1113 } | 1104 } |
| 1114 | 1105 |
| 1115 class MockWebFrameClient : public FrameTestHelpers::TestWebFrameClient { | 1106 class MockWebFrameClient : public FrameTestHelpers::TestWebFrameClient { |
| 1116 public: | 1107 public: |
| 1117 MOCK_METHOD1(ShowContextMenu, void(const WebContextMenuData&)); | 1108 MOCK_METHOD1(ShowContextMenu, void(const WebContextMenuData&)); |
| 1118 MOCK_METHOD0(DidChangeScrollOffset, void()); | 1109 MOCK_METHOD0(DidChangeScrollOffset, void()); |
| 1119 }; | 1110 }; |
| 1120 | 1111 |
| 1121 MATCHER_P2(ContextMenuAtLocation, | 1112 MATCHER_P2(ContextMenuAtLocation, |
| 1122 x, | 1113 x, |
| 1123 y, | 1114 y, |
| 1124 std::string(negation ? "is" : "isn't") + " at expected location [" + | 1115 std::string(negation ? "is" : "isn't") + " at expected location [" + |
| 1125 PrintToString(x) + | 1116 PrintToString(x) + |
| 1126 ", " + | 1117 ", " + |
| 1127 PrintToString(y) + | 1118 PrintToString(y) + |
| 1128 "]") { | 1119 "]") { |
| 1129 return arg.mouse_position.x == x && arg.mouse_position.y == y; | 1120 return arg.mouse_position.x == x && arg.mouse_position.y == y; |
| 1130 } | 1121 } |
| 1131 | 1122 |
| 1132 // Test that the context menu's location is correct in the presence of visual | 1123 // Test that the context menu's location is correct in the presence of visual |
| 1133 // viewport offset. | 1124 // viewport offset. |
| 1134 TEST_P(VisualViewportTest, TestContextMenuShownInCorrectLocation) { | 1125 TEST_P(VisualViewportTest, TestContextMenuShownInCorrectLocation) { |
| 1135 initializeWithDesktopSettings(); | 1126 InitializeWithDesktopSettings(); |
| 1136 webViewImpl()->Resize(IntSize(200, 300)); | 1127 WebViewImpl()->Resize(IntSize(200, 300)); |
| 1137 | 1128 |
| 1138 registerMockedHttpURLLoad("200-by-300.html"); | 1129 RegisterMockedHttpURLLoad("200-by-300.html"); |
| 1139 navigateTo(m_baseURL + "200-by-300.html"); | 1130 NavigateTo(base_url_ + "200-by-300.html"); |
| 1140 | 1131 |
| 1141 WebMouseEvent mouseDownEvent(WebInputEvent::kMouseDown, | 1132 WebMouseEvent mouse_down_event(WebInputEvent::kMouseDown, |
| 1142 WebInputEvent::kNoModifiers, | 1133 WebInputEvent::kNoModifiers, |
| 1143 WebInputEvent::kTimeStampForTesting); | 1134 WebInputEvent::kTimeStampForTesting); |
| 1144 mouseDownEvent.SetPositionInWidget(10, 10); | 1135 mouse_down_event.SetPositionInWidget(10, 10); |
| 1145 mouseDownEvent.SetPositionInScreen(110, 210); | 1136 mouse_down_event.SetPositionInScreen(110, 210); |
| 1146 mouseDownEvent.click_count = 1; | 1137 mouse_down_event.click_count = 1; |
| 1147 mouseDownEvent.button = WebMouseEvent::Button::kRight; | 1138 mouse_down_event.button = WebMouseEvent::Button::kRight; |
| 1148 | 1139 |
| 1149 // Corresponding release event (Windows shows context menu on release). | 1140 // Corresponding release event (Windows shows context menu on release). |
| 1150 WebMouseEvent mouseUpEvent(mouseDownEvent); | 1141 WebMouseEvent mouse_up_event(mouse_down_event); |
| 1151 mouseUpEvent.SetType(WebInputEvent::kMouseUp); | 1142 mouse_up_event.SetType(WebInputEvent::kMouseUp); |
| 1152 | 1143 |
| 1153 WebFrameClient* oldClient = webViewImpl()->MainFrameImpl()->Client(); | 1144 WebFrameClient* old_client = WebViewImpl()->MainFrameImpl()->Client(); |
| 1154 MockWebFrameClient mockWebFrameClient; | 1145 MockWebFrameClient mock_web_frame_client; |
| 1155 EXPECT_CALL(mockWebFrameClient, ShowContextMenu(ContextMenuAtLocation( | 1146 EXPECT_CALL(mock_web_frame_client, |
| 1156 mouseDownEvent.PositionInWidget().x, | 1147 ShowContextMenu(ContextMenuAtLocation( |
| 1157 mouseDownEvent.PositionInWidget().y))); | 1148 mouse_down_event.PositionInWidget().x, |
| 1149 mouse_down_event.PositionInWidget().y))); |
| 1158 | 1150 |
| 1159 // Do a sanity check with no scale applied. | 1151 // Do a sanity check with no scale applied. |
| 1160 webViewImpl()->MainFrameImpl()->SetClient(&mockWebFrameClient); | 1152 WebViewImpl()->MainFrameImpl()->SetClient(&mock_web_frame_client); |
| 1161 webViewImpl()->HandleInputEvent(WebCoalescedInputEvent(mouseDownEvent)); | 1153 WebViewImpl()->HandleInputEvent(WebCoalescedInputEvent(mouse_down_event)); |
| 1162 webViewImpl()->HandleInputEvent(WebCoalescedInputEvent(mouseUpEvent)); | 1154 WebViewImpl()->HandleInputEvent(WebCoalescedInputEvent(mouse_up_event)); |
| 1163 | 1155 |
| 1164 Mock::VerifyAndClearExpectations(&mockWebFrameClient); | 1156 Mock::VerifyAndClearExpectations(&mock_web_frame_client); |
| 1165 mouseDownEvent.button = WebMouseEvent::Button::kLeft; | 1157 mouse_down_event.button = WebMouseEvent::Button::kLeft; |
| 1166 webViewImpl()->HandleInputEvent(WebCoalescedInputEvent(mouseDownEvent)); | 1158 WebViewImpl()->HandleInputEvent(WebCoalescedInputEvent(mouse_down_event)); |
| 1167 | 1159 |
| 1168 // Now pinch zoom into the page and move the visual viewport. The context menu | 1160 // Now pinch zoom into the page and move the visual viewport. The context menu |
| 1169 // should still appear at the location of the event, relative to the WebView. | 1161 // should still appear at the location of the event, relative to the WebView. |
| 1170 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 1162 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 1171 webViewImpl()->SetPageScaleFactor(2); | 1163 WebViewImpl()->SetPageScaleFactor(2); |
| 1172 EXPECT_CALL(mockWebFrameClient, DidChangeScrollOffset()); | 1164 EXPECT_CALL(mock_web_frame_client, DidChangeScrollOffset()); |
| 1173 visualViewport.SetLocation(FloatPoint(60, 80)); | 1165 visual_viewport.SetLocation(FloatPoint(60, 80)); |
| 1174 EXPECT_CALL(mockWebFrameClient, ShowContextMenu(ContextMenuAtLocation( | 1166 EXPECT_CALL(mock_web_frame_client, |
| 1175 mouseDownEvent.PositionInWidget().x, | 1167 ShowContextMenu(ContextMenuAtLocation( |
| 1176 mouseDownEvent.PositionInWidget().y))); | 1168 mouse_down_event.PositionInWidget().x, |
| 1177 | 1169 mouse_down_event.PositionInWidget().y))); |
| 1178 mouseDownEvent.button = WebMouseEvent::Button::kRight; | 1170 |
| 1179 webViewImpl()->HandleInputEvent(WebCoalescedInputEvent(mouseDownEvent)); | 1171 mouse_down_event.button = WebMouseEvent::Button::kRight; |
| 1180 webViewImpl()->HandleInputEvent(WebCoalescedInputEvent(mouseUpEvent)); | 1172 WebViewImpl()->HandleInputEvent(WebCoalescedInputEvent(mouse_down_event)); |
| 1173 WebViewImpl()->HandleInputEvent(WebCoalescedInputEvent(mouse_up_event)); |
| 1181 | 1174 |
| 1182 // Reset the old client so destruction can occur naturally. | 1175 // Reset the old client so destruction can occur naturally. |
| 1183 webViewImpl()->MainFrameImpl()->SetClient(oldClient); | 1176 WebViewImpl()->MainFrameImpl()->SetClient(old_client); |
| 1184 } | 1177 } |
| 1185 | 1178 |
| 1186 // Test that the client is notified if page scroll events. | 1179 // Test that the client is notified if page scroll events. |
| 1187 TEST_P(VisualViewportTest, TestClientNotifiedOfScrollEvents) { | 1180 TEST_P(VisualViewportTest, TestClientNotifiedOfScrollEvents) { |
| 1188 initializeWithAndroidSettings(); | 1181 InitializeWithAndroidSettings(); |
| 1189 webViewImpl()->Resize(IntSize(200, 300)); | 1182 WebViewImpl()->Resize(IntSize(200, 300)); |
| 1190 | 1183 |
| 1191 registerMockedHttpURLLoad("200-by-300.html"); | 1184 RegisterMockedHttpURLLoad("200-by-300.html"); |
| 1192 navigateTo(m_baseURL + "200-by-300.html"); | 1185 NavigateTo(base_url_ + "200-by-300.html"); |
| 1193 | 1186 |
| 1194 WebFrameClient* oldClient = webViewImpl()->MainFrameImpl()->Client(); | 1187 WebFrameClient* old_client = WebViewImpl()->MainFrameImpl()->Client(); |
| 1195 MockWebFrameClient mockWebFrameClient; | 1188 MockWebFrameClient mock_web_frame_client; |
| 1196 webViewImpl()->MainFrameImpl()->SetClient(&mockWebFrameClient); | 1189 WebViewImpl()->MainFrameImpl()->SetClient(&mock_web_frame_client); |
| 1197 | 1190 |
| 1198 webViewImpl()->SetPageScaleFactor(2); | 1191 WebViewImpl()->SetPageScaleFactor(2); |
| 1199 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 1192 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 1200 | 1193 |
| 1201 EXPECT_CALL(mockWebFrameClient, DidChangeScrollOffset()); | 1194 EXPECT_CALL(mock_web_frame_client, DidChangeScrollOffset()); |
| 1202 visualViewport.SetLocation(FloatPoint(60, 80)); | 1195 visual_viewport.SetLocation(FloatPoint(60, 80)); |
| 1203 Mock::VerifyAndClearExpectations(&mockWebFrameClient); | 1196 Mock::VerifyAndClearExpectations(&mock_web_frame_client); |
| 1204 | 1197 |
| 1205 // Scroll vertically. | 1198 // Scroll vertically. |
| 1206 EXPECT_CALL(mockWebFrameClient, DidChangeScrollOffset()); | 1199 EXPECT_CALL(mock_web_frame_client, DidChangeScrollOffset()); |
| 1207 visualViewport.SetLocation(FloatPoint(60, 90)); | 1200 visual_viewport.SetLocation(FloatPoint(60, 90)); |
| 1208 Mock::VerifyAndClearExpectations(&mockWebFrameClient); | 1201 Mock::VerifyAndClearExpectations(&mock_web_frame_client); |
| 1209 | 1202 |
| 1210 // Scroll horizontally. | 1203 // Scroll horizontally. |
| 1211 EXPECT_CALL(mockWebFrameClient, DidChangeScrollOffset()); | 1204 EXPECT_CALL(mock_web_frame_client, DidChangeScrollOffset()); |
| 1212 visualViewport.SetLocation(FloatPoint(70, 90)); | 1205 visual_viewport.SetLocation(FloatPoint(70, 90)); |
| 1213 | 1206 |
| 1214 // Reset the old client so destruction can occur naturally. | 1207 // Reset the old client so destruction can occur naturally. |
| 1215 webViewImpl()->MainFrameImpl()->SetClient(oldClient); | 1208 WebViewImpl()->MainFrameImpl()->SetClient(old_client); |
| 1216 } | 1209 } |
| 1217 | 1210 |
| 1218 // Tests that calling scroll into view on a visible element doesn't cause | 1211 // Tests that calling scroll into view on a visible element doesn't cause |
| 1219 // a scroll due to a fractional offset. Bug crbug.com/463356. | 1212 // a scroll due to a fractional offset. Bug crbug.com/463356. |
| 1220 TEST_P(VisualViewportTest, ScrollIntoViewFractionalOffset) { | 1213 TEST_P(VisualViewportTest, ScrollIntoViewFractionalOffset) { |
| 1221 initializeWithAndroidSettings(); | 1214 InitializeWithAndroidSettings(); |
| 1222 | 1215 |
| 1223 webViewImpl()->Resize(IntSize(1000, 1000)); | 1216 WebViewImpl()->Resize(IntSize(1000, 1000)); |
| 1224 | 1217 |
| 1225 registerMockedHttpURLLoad("scroll-into-view.html"); | 1218 RegisterMockedHttpURLLoad("scroll-into-view.html"); |
| 1226 navigateTo(m_baseURL + "scroll-into-view.html"); | 1219 NavigateTo(base_url_ + "scroll-into-view.html"); |
| 1227 | 1220 |
| 1228 FrameView& frameView = *webViewImpl()->MainFrameImpl()->GetFrameView(); | 1221 FrameView& frame_view = *WebViewImpl()->MainFrameImpl()->GetFrameView(); |
| 1229 ScrollableArea* layoutViewportScrollableArea = | 1222 ScrollableArea* layout_viewport_scrollable_area = |
| 1230 frameView.LayoutViewportScrollableArea(); | 1223 frame_view.LayoutViewportScrollableArea(); |
| 1231 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 1224 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 1232 Element* inputBox = frame()->GetDocument()->getElementById("box"); | 1225 Element* inputBox = GetFrame()->GetDocument()->getElementById("box"); |
| 1233 | 1226 |
| 1234 webViewImpl()->SetPageScaleFactor(2); | 1227 WebViewImpl()->SetPageScaleFactor(2); |
| 1235 | 1228 |
| 1236 // The element is already in the view so the scrollIntoView shouldn't move | 1229 // The element is already in the view so the scrollIntoView shouldn't move |
| 1237 // the viewport at all. | 1230 // the viewport at all. |
| 1238 webViewImpl()->SetVisualViewportOffset(WebFloatPoint(250.25f, 100.25f)); | 1231 WebViewImpl()->SetVisualViewportOffset(WebFloatPoint(250.25f, 100.25f)); |
| 1239 layoutViewportScrollableArea->SetScrollOffset(ScrollOffset(0, 900.75), | 1232 layout_viewport_scrollable_area->SetScrollOffset(ScrollOffset(0, 900.75), |
| 1240 kProgrammaticScroll); | 1233 kProgrammaticScroll); |
| 1241 inputBox->scrollIntoViewIfNeeded(false); | 1234 inputBox->scrollIntoViewIfNeeded(false); |
| 1242 | 1235 |
| 1243 EXPECT_SIZE_EQ(ScrollOffset(0, 900), | 1236 EXPECT_SIZE_EQ(ScrollOffset(0, 900), |
| 1244 layoutViewportScrollableArea->GetScrollOffset()); | 1237 layout_viewport_scrollable_area->GetScrollOffset()); |
| 1245 EXPECT_SIZE_EQ(FloatSize(250.25f, 100.25f), visualViewport.GetScrollOffset()); | 1238 EXPECT_SIZE_EQ(FloatSize(250.25f, 100.25f), |
| 1239 visual_viewport.GetScrollOffset()); |
| 1246 | 1240 |
| 1247 // Change the fractional part of the frameview to one that would round down. | 1241 // Change the fractional part of the frameview to one that would round down. |
| 1248 layoutViewportScrollableArea->SetScrollOffset(ScrollOffset(0, 900.125), | 1242 layout_viewport_scrollable_area->SetScrollOffset(ScrollOffset(0, 900.125), |
| 1249 kProgrammaticScroll); | 1243 kProgrammaticScroll); |
| 1250 inputBox->scrollIntoViewIfNeeded(false); | 1244 inputBox->scrollIntoViewIfNeeded(false); |
| 1251 | 1245 |
| 1252 EXPECT_SIZE_EQ(ScrollOffset(0, 900), | 1246 EXPECT_SIZE_EQ(ScrollOffset(0, 900), |
| 1253 layoutViewportScrollableArea->GetScrollOffset()); | 1247 layout_viewport_scrollable_area->GetScrollOffset()); |
| 1254 EXPECT_SIZE_EQ(FloatSize(250.25f, 100.25f), visualViewport.GetScrollOffset()); | 1248 EXPECT_SIZE_EQ(FloatSize(250.25f, 100.25f), |
| 1249 visual_viewport.GetScrollOffset()); |
| 1255 | 1250 |
| 1256 // Repeat both tests above with the visual viewport at a high fractional. | 1251 // Repeat both tests above with the visual viewport at a high fractional. |
| 1257 webViewImpl()->SetVisualViewportOffset(WebFloatPoint(250.875f, 100.875f)); | 1252 WebViewImpl()->SetVisualViewportOffset(WebFloatPoint(250.875f, 100.875f)); |
| 1258 layoutViewportScrollableArea->SetScrollOffset(ScrollOffset(0, 900.75), | 1253 layout_viewport_scrollable_area->SetScrollOffset(ScrollOffset(0, 900.75), |
| 1259 kProgrammaticScroll); | 1254 kProgrammaticScroll); |
| 1260 inputBox->scrollIntoViewIfNeeded(false); | 1255 inputBox->scrollIntoViewIfNeeded(false); |
| 1261 | 1256 |
| 1262 EXPECT_SIZE_EQ(ScrollOffset(0, 900), | 1257 EXPECT_SIZE_EQ(ScrollOffset(0, 900), |
| 1263 layoutViewportScrollableArea->GetScrollOffset()); | 1258 layout_viewport_scrollable_area->GetScrollOffset()); |
| 1264 EXPECT_SIZE_EQ(FloatSize(250.875f, 100.875f), | 1259 EXPECT_SIZE_EQ(FloatSize(250.875f, 100.875f), |
| 1265 visualViewport.GetScrollOffset()); | 1260 visual_viewport.GetScrollOffset()); |
| 1266 | 1261 |
| 1267 // Change the fractional part of the frameview to one that would round down. | 1262 // Change the fractional part of the frameview to one that would round down. |
| 1268 layoutViewportScrollableArea->SetScrollOffset(ScrollOffset(0, 900.125), | 1263 layout_viewport_scrollable_area->SetScrollOffset(ScrollOffset(0, 900.125), |
| 1269 kProgrammaticScroll); | 1264 kProgrammaticScroll); |
| 1270 inputBox->scrollIntoViewIfNeeded(false); | 1265 inputBox->scrollIntoViewIfNeeded(false); |
| 1271 | 1266 |
| 1272 EXPECT_SIZE_EQ(ScrollOffset(0, 900), | 1267 EXPECT_SIZE_EQ(ScrollOffset(0, 900), |
| 1273 layoutViewportScrollableArea->GetScrollOffset()); | 1268 layout_viewport_scrollable_area->GetScrollOffset()); |
| 1274 EXPECT_SIZE_EQ(FloatSize(250.875f, 100.875f), | 1269 EXPECT_SIZE_EQ(FloatSize(250.875f, 100.875f), |
| 1275 visualViewport.GetScrollOffset()); | 1270 visual_viewport.GetScrollOffset()); |
| 1276 | 1271 |
| 1277 // Both viewports with a 0.5 fraction. | 1272 // Both viewports with a 0.5 fraction. |
| 1278 webViewImpl()->SetVisualViewportOffset(WebFloatPoint(250.5f, 100.5f)); | 1273 WebViewImpl()->SetVisualViewportOffset(WebFloatPoint(250.5f, 100.5f)); |
| 1279 layoutViewportScrollableArea->SetScrollOffset(ScrollOffset(0, 900.5), | 1274 layout_viewport_scrollable_area->SetScrollOffset(ScrollOffset(0, 900.5), |
| 1280 kProgrammaticScroll); | 1275 kProgrammaticScroll); |
| 1281 inputBox->scrollIntoViewIfNeeded(false); | 1276 inputBox->scrollIntoViewIfNeeded(false); |
| 1282 | 1277 |
| 1283 EXPECT_SIZE_EQ(ScrollOffset(0, 900), | 1278 EXPECT_SIZE_EQ(ScrollOffset(0, 900), |
| 1284 layoutViewportScrollableArea->GetScrollOffset()); | 1279 layout_viewport_scrollable_area->GetScrollOffset()); |
| 1285 EXPECT_SIZE_EQ(FloatSize(250.5f, 100.5f), visualViewport.GetScrollOffset()); | 1280 EXPECT_SIZE_EQ(FloatSize(250.5f, 100.5f), visual_viewport.GetScrollOffset()); |
| 1286 } | 1281 } |
| 1287 | 1282 |
| 1288 static ScrollOffset expectedMaxFrameViewScrollOffset( | 1283 static ScrollOffset expectedMaxFrameViewScrollOffset( |
| 1289 VisualViewport& visualViewport, | 1284 VisualViewport& visual_viewport, |
| 1290 FrameView& frameView) { | 1285 FrameView& frame_view) { |
| 1291 float aspectRatio = visualViewport.VisibleRect().Width() / | 1286 float aspect_ratio = visual_viewport.VisibleRect().Width() / |
| 1292 visualViewport.VisibleRect().Height(); | 1287 visual_viewport.VisibleRect().Height(); |
| 1293 float newHeight = frameView.FrameRect().Width() / aspectRatio; | 1288 float new_height = frame_view.FrameRect().Width() / aspect_ratio; |
| 1294 return ScrollOffset( | 1289 return ScrollOffset( |
| 1295 frameView.ContentsSize().Width() - frameView.FrameRect().Width(), | 1290 frame_view.ContentsSize().Width() - frame_view.FrameRect().Width(), |
| 1296 frameView.ContentsSize().Height() - newHeight); | 1291 frame_view.ContentsSize().Height() - new_height); |
| 1297 } | 1292 } |
| 1298 | 1293 |
| 1299 TEST_P(VisualViewportTest, TestBrowserControlsAdjustment) { | 1294 TEST_P(VisualViewportTest, TestBrowserControlsAdjustment) { |
| 1300 initializeWithAndroidSettings(); | 1295 InitializeWithAndroidSettings(); |
| 1301 webViewImpl()->ResizeWithBrowserControls(IntSize(500, 450), 20, false); | 1296 WebViewImpl()->ResizeWithBrowserControls(IntSize(500, 450), 20, false); |
| 1302 | 1297 |
| 1303 registerMockedHttpURLLoad("content-width-1000.html"); | 1298 RegisterMockedHttpURLLoad("content-width-1000.html"); |
| 1304 navigateTo(m_baseURL + "content-width-1000.html"); | 1299 NavigateTo(base_url_ + "content-width-1000.html"); |
| 1305 | 1300 |
| 1306 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 1301 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 1307 FrameView& frameView = *webViewImpl()->MainFrameImpl()->GetFrameView(); | 1302 FrameView& frame_view = *WebViewImpl()->MainFrameImpl()->GetFrameView(); |
| 1308 | 1303 |
| 1309 visualViewport.SetScale(1); | 1304 visual_viewport.SetScale(1); |
| 1310 EXPECT_SIZE_EQ(IntSize(500, 450), visualViewport.VisibleRect().Size()); | 1305 EXPECT_SIZE_EQ(IntSize(500, 450), visual_viewport.VisibleRect().Size()); |
| 1311 EXPECT_SIZE_EQ(IntSize(1000, 900), frameView.FrameRect().Size()); | 1306 EXPECT_SIZE_EQ(IntSize(1000, 900), frame_view.FrameRect().Size()); |
| 1312 | 1307 |
| 1313 // Simulate bringing down the browser controls by 20px. | 1308 // Simulate bringing down the browser controls by 20px. |
| 1314 webViewImpl()->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), | 1309 WebViewImpl()->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), |
| 1315 WebFloatSize(), 1, 1); | 1310 WebFloatSize(), 1, 1); |
| 1316 EXPECT_SIZE_EQ(IntSize(500, 430), visualViewport.VisibleRect().Size()); | 1311 EXPECT_SIZE_EQ(IntSize(500, 430), visual_viewport.VisibleRect().Size()); |
| 1317 | 1312 |
| 1318 // Test that the scroll bounds are adjusted appropriately: the visual viewport | 1313 // Test that the scroll bounds are adjusted appropriately: the visual viewport |
| 1319 // should be shrunk by 20px to 430px. The outer viewport was shrunk to | 1314 // should be shrunk by 20px to 430px. The outer viewport was shrunk to |
| 1320 // maintain the | 1315 // maintain the |
| 1321 // aspect ratio so it's height is 860px. | 1316 // aspect ratio so it's height is 860px. |
| 1322 visualViewport.Move(ScrollOffset(10000, 10000)); | 1317 visual_viewport.Move(ScrollOffset(10000, 10000)); |
| 1323 EXPECT_SIZE_EQ(FloatSize(500, 860 - 430), visualViewport.GetScrollOffset()); | 1318 EXPECT_SIZE_EQ(FloatSize(500, 860 - 430), visual_viewport.GetScrollOffset()); |
| 1324 | 1319 |
| 1325 // The outer viewport (FrameView) should be affected as well. | 1320 // The outer viewport (FrameView) should be affected as well. |
| 1326 frameView.LayoutViewportScrollableArea()->ScrollBy(ScrollOffset(10000, 10000), | 1321 frame_view.LayoutViewportScrollableArea()->ScrollBy( |
| 1327 kUserScroll); | 1322 ScrollOffset(10000, 10000), kUserScroll); |
| 1328 EXPECT_SIZE_EQ(expectedMaxFrameViewScrollOffset(visualViewport, frameView), | 1323 EXPECT_SIZE_EQ(expectedMaxFrameViewScrollOffset(visual_viewport, frame_view), |
| 1329 frameView.LayoutViewportScrollableArea()->GetScrollOffset()); | 1324 frame_view.LayoutViewportScrollableArea()->GetScrollOffset()); |
| 1330 | 1325 |
| 1331 // Simulate bringing up the browser controls by 10.5px. | 1326 // Simulate bringing up the browser controls by 10.5px. |
| 1332 webViewImpl()->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), | 1327 WebViewImpl()->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), |
| 1333 WebFloatSize(), 1, -10.5f / 20); | 1328 WebFloatSize(), 1, -10.5f / 20); |
| 1334 EXPECT_FLOAT_SIZE_EQ(FloatSize(500, 440.5f), | 1329 EXPECT_FLOAT_SIZE_EQ(FloatSize(500, 440.5f), |
| 1335 visualViewport.VisibleRect().Size()); | 1330 visual_viewport.VisibleRect().Size()); |
| 1336 | 1331 |
| 1337 // maximumScrollPosition |ceil|s the browser controls adjustment. | 1332 // maximumScrollPosition |ceil|s the browser controls adjustment. |
| 1338 visualViewport.Move(ScrollOffset(10000, 10000)); | 1333 visual_viewport.Move(ScrollOffset(10000, 10000)); |
| 1339 EXPECT_FLOAT_SIZE_EQ(FloatSize(500, 881 - 441), | 1334 EXPECT_FLOAT_SIZE_EQ(FloatSize(500, 881 - 441), |
| 1340 visualViewport.GetScrollOffset()); | 1335 visual_viewport.GetScrollOffset()); |
| 1341 | 1336 |
| 1342 // The outer viewport (FrameView) should be affected as well. | 1337 // The outer viewport (FrameView) should be affected as well. |
| 1343 frameView.LayoutViewportScrollableArea()->ScrollBy(ScrollOffset(10000, 10000), | 1338 frame_view.LayoutViewportScrollableArea()->ScrollBy( |
| 1344 kUserScroll); | 1339 ScrollOffset(10000, 10000), kUserScroll); |
| 1345 EXPECT_SIZE_EQ(expectedMaxFrameViewScrollOffset(visualViewport, frameView), | 1340 EXPECT_SIZE_EQ(expectedMaxFrameViewScrollOffset(visual_viewport, frame_view), |
| 1346 frameView.LayoutViewportScrollableArea()->GetScrollOffset()); | 1341 frame_view.LayoutViewportScrollableArea()->GetScrollOffset()); |
| 1347 } | 1342 } |
| 1348 | 1343 |
| 1349 TEST_P(VisualViewportTest, TestBrowserControlsAdjustmentWithScale) { | 1344 TEST_P(VisualViewportTest, TestBrowserControlsAdjustmentWithScale) { |
| 1350 initializeWithAndroidSettings(); | 1345 InitializeWithAndroidSettings(); |
| 1351 webViewImpl()->ResizeWithBrowserControls(IntSize(500, 450), 20, false); | 1346 WebViewImpl()->ResizeWithBrowserControls(IntSize(500, 450), 20, false); |
| 1352 | 1347 |
| 1353 registerMockedHttpURLLoad("content-width-1000.html"); | 1348 RegisterMockedHttpURLLoad("content-width-1000.html"); |
| 1354 navigateTo(m_baseURL + "content-width-1000.html"); | 1349 NavigateTo(base_url_ + "content-width-1000.html"); |
| 1355 | 1350 |
| 1356 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 1351 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 1357 FrameView& frameView = *webViewImpl()->MainFrameImpl()->GetFrameView(); | 1352 FrameView& frame_view = *WebViewImpl()->MainFrameImpl()->GetFrameView(); |
| 1358 | 1353 |
| 1359 visualViewport.SetScale(2); | 1354 visual_viewport.SetScale(2); |
| 1360 EXPECT_SIZE_EQ(IntSize(250, 225), visualViewport.VisibleRect().Size()); | 1355 EXPECT_SIZE_EQ(IntSize(250, 225), visual_viewport.VisibleRect().Size()); |
| 1361 EXPECT_SIZE_EQ(IntSize(1000, 900), frameView.FrameRect().Size()); | 1356 EXPECT_SIZE_EQ(IntSize(1000, 900), frame_view.FrameRect().Size()); |
| 1362 | 1357 |
| 1363 // Simulate bringing down the browser controls by 20px. Since we're zoomed in, | 1358 // Simulate bringing down the browser controls by 20px. Since we're zoomed in, |
| 1364 // the browser controls take up half as much space (in document-space) than | 1359 // the browser controls take up half as much space (in document-space) than |
| 1365 // they do at an unzoomed level. | 1360 // they do at an unzoomed level. |
| 1366 webViewImpl()->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), | 1361 WebViewImpl()->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), |
| 1367 WebFloatSize(), 1, 1); | 1362 WebFloatSize(), 1, 1); |
| 1368 EXPECT_SIZE_EQ(IntSize(250, 215), visualViewport.VisibleRect().Size()); | 1363 EXPECT_SIZE_EQ(IntSize(250, 215), visual_viewport.VisibleRect().Size()); |
| 1369 | 1364 |
| 1370 // Test that the scroll bounds are adjusted appropriately. | 1365 // Test that the scroll bounds are adjusted appropriately. |
| 1371 visualViewport.Move(ScrollOffset(10000, 10000)); | 1366 visual_viewport.Move(ScrollOffset(10000, 10000)); |
| 1372 EXPECT_SIZE_EQ(FloatSize(750, 860 - 215), visualViewport.GetScrollOffset()); | 1367 EXPECT_SIZE_EQ(FloatSize(750, 860 - 215), visual_viewport.GetScrollOffset()); |
| 1373 | 1368 |
| 1374 // The outer viewport (FrameView) should be affected as well. | 1369 // The outer viewport (FrameView) should be affected as well. |
| 1375 frameView.LayoutViewportScrollableArea()->ScrollBy(ScrollOffset(10000, 10000), | 1370 frame_view.LayoutViewportScrollableArea()->ScrollBy( |
| 1376 kUserScroll); | 1371 ScrollOffset(10000, 10000), kUserScroll); |
| 1377 ScrollOffset expected = | 1372 ScrollOffset expected = |
| 1378 expectedMaxFrameViewScrollOffset(visualViewport, frameView); | 1373 expectedMaxFrameViewScrollOffset(visual_viewport, frame_view); |
| 1379 EXPECT_SIZE_EQ(expected, | 1374 EXPECT_SIZE_EQ(expected, |
| 1380 frameView.LayoutViewportScrollableArea()->GetScrollOffset()); | 1375 frame_view.LayoutViewportScrollableArea()->GetScrollOffset()); |
| 1381 | 1376 |
| 1382 // Scale back out, FrameView max scroll shouldn't have changed. Visual | 1377 // Scale back out, FrameView max scroll shouldn't have changed. Visual |
| 1383 // viewport should be moved up to accomodate larger view. | 1378 // viewport should be moved up to accomodate larger view. |
| 1384 webViewImpl()->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), | 1379 WebViewImpl()->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), |
| 1385 WebFloatSize(), 0.5f, 0); | 1380 WebFloatSize(), 0.5f, 0); |
| 1386 EXPECT_EQ(1, visualViewport.Scale()); | 1381 EXPECT_EQ(1, visual_viewport.Scale()); |
| 1387 EXPECT_SIZE_EQ(expected, | 1382 EXPECT_SIZE_EQ(expected, |
| 1388 frameView.LayoutViewportScrollableArea()->GetScrollOffset()); | 1383 frame_view.LayoutViewportScrollableArea()->GetScrollOffset()); |
| 1389 frameView.LayoutViewportScrollableArea()->ScrollBy(ScrollOffset(10000, 10000), | 1384 frame_view.LayoutViewportScrollableArea()->ScrollBy( |
| 1390 kUserScroll); | 1385 ScrollOffset(10000, 10000), kUserScroll); |
| 1391 EXPECT_SIZE_EQ(expected, | 1386 EXPECT_SIZE_EQ(expected, |
| 1392 frameView.LayoutViewportScrollableArea()->GetScrollOffset()); | 1387 frame_view.LayoutViewportScrollableArea()->GetScrollOffset()); |
| 1393 | 1388 |
| 1394 EXPECT_SIZE_EQ(FloatSize(500, 860 - 430), visualViewport.GetScrollOffset()); | 1389 EXPECT_SIZE_EQ(FloatSize(500, 860 - 430), visual_viewport.GetScrollOffset()); |
| 1395 visualViewport.Move(ScrollOffset(10000, 10000)); | 1390 visual_viewport.Move(ScrollOffset(10000, 10000)); |
| 1396 EXPECT_SIZE_EQ(FloatSize(500, 860 - 430), visualViewport.GetScrollOffset()); | 1391 EXPECT_SIZE_EQ(FloatSize(500, 860 - 430), visual_viewport.GetScrollOffset()); |
| 1397 | 1392 |
| 1398 // Scale out, use a scale that causes fractional rects. | 1393 // Scale out, use a scale that causes fractional rects. |
| 1399 webViewImpl()->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), | 1394 WebViewImpl()->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), |
| 1400 WebFloatSize(), 0.8f, -1); | 1395 WebFloatSize(), 0.8f, -1); |
| 1401 EXPECT_SIZE_EQ(FloatSize(625, 562.5), visualViewport.VisibleRect().Size()); | 1396 EXPECT_SIZE_EQ(FloatSize(625, 562.5), visual_viewport.VisibleRect().Size()); |
| 1402 | 1397 |
| 1403 // Bring out the browser controls by 11 | 1398 // Bring out the browser controls by 11 |
| 1404 webViewImpl()->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), | 1399 WebViewImpl()->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), |
| 1405 WebFloatSize(), 1, 11 / 20.f); | 1400 WebFloatSize(), 1, 11 / 20.f); |
| 1406 EXPECT_SIZE_EQ(FloatSize(625, 548.75), visualViewport.VisibleRect().Size()); | 1401 EXPECT_SIZE_EQ(FloatSize(625, 548.75), visual_viewport.VisibleRect().Size()); |
| 1407 | 1402 |
| 1408 // Ensure max scroll offsets are updated properly. | 1403 // Ensure max scroll offsets are updated properly. |
| 1409 visualViewport.Move(ScrollOffset(10000, 10000)); | 1404 visual_viewport.Move(ScrollOffset(10000, 10000)); |
| 1410 EXPECT_FLOAT_SIZE_EQ(FloatSize(375, 877.5 - 548.75), | 1405 EXPECT_FLOAT_SIZE_EQ(FloatSize(375, 877.5 - 548.75), |
| 1411 visualViewport.GetScrollOffset()); | 1406 visual_viewport.GetScrollOffset()); |
| 1412 | 1407 |
| 1413 frameView.LayoutViewportScrollableArea()->ScrollBy(ScrollOffset(10000, 10000), | 1408 frame_view.LayoutViewportScrollableArea()->ScrollBy( |
| 1414 kUserScroll); | 1409 ScrollOffset(10000, 10000), kUserScroll); |
| 1415 EXPECT_SIZE_EQ(expectedMaxFrameViewScrollOffset(visualViewport, frameView), | 1410 EXPECT_SIZE_EQ(expectedMaxFrameViewScrollOffset(visual_viewport, frame_view), |
| 1416 frameView.LayoutViewportScrollableArea()->GetScrollOffset()); | 1411 frame_view.LayoutViewportScrollableArea()->GetScrollOffset()); |
| 1417 } | 1412 } |
| 1418 | 1413 |
| 1419 // Tests that a scroll all the way to the bottom of the page, while hiding the | 1414 // Tests that a scroll all the way to the bottom of the page, while hiding the |
| 1420 // browser controls doesn't cause a clamp in the viewport scroll offset when the | 1415 // browser controls doesn't cause a clamp in the viewport scroll offset when the |
| 1421 // top controls initiated resize occurs. | 1416 // top controls initiated resize occurs. |
| 1422 TEST_P(VisualViewportTest, TestBrowserControlsAdjustmentAndResize) { | 1417 TEST_P(VisualViewportTest, TestBrowserControlsAdjustmentAndResize) { |
| 1423 int browserControlsHeight = 20; | 1418 int browser_controls_height = 20; |
| 1424 int visualViewportHeight = 450; | 1419 int visual_viewport_height = 450; |
| 1425 int layoutViewportHeight = 900; | 1420 int layout_viewport_height = 900; |
| 1426 float pageScale = 2; | 1421 float page_scale = 2; |
| 1427 float minPageScale = 0.5; | 1422 float min_page_scale = 0.5; |
| 1428 | 1423 |
| 1429 initializeWithAndroidSettings(); | 1424 InitializeWithAndroidSettings(); |
| 1430 | 1425 |
| 1431 // Initialize with browser controls showing and shrinking the Blink size. | 1426 // Initialize with browser controls showing and shrinking the Blink size. |
| 1432 webViewImpl()->ResizeWithBrowserControls( | 1427 WebViewImpl()->ResizeWithBrowserControls( |
| 1433 WebSize(500, visualViewportHeight - browserControlsHeight), 20, true); | 1428 WebSize(500, visual_viewport_height - browser_controls_height), 20, true); |
| 1434 webViewImpl()->GetBrowserControls().SetShownRatio(1); | 1429 WebViewImpl()->GetBrowserControls().SetShownRatio(1); |
| 1435 | 1430 |
| 1436 registerMockedHttpURLLoad("content-width-1000.html"); | 1431 RegisterMockedHttpURLLoad("content-width-1000.html"); |
| 1437 navigateTo(m_baseURL + "content-width-1000.html"); | 1432 NavigateTo(base_url_ + "content-width-1000.html"); |
| 1438 | 1433 |
| 1439 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 1434 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 1440 FrameView& frameView = *webViewImpl()->MainFrameImpl()->GetFrameView(); | 1435 FrameView& frame_view = *WebViewImpl()->MainFrameImpl()->GetFrameView(); |
| 1441 | 1436 |
| 1442 visualViewport.SetScale(pageScale); | 1437 visual_viewport.SetScale(page_scale); |
| 1443 EXPECT_SIZE_EQ( | 1438 EXPECT_SIZE_EQ( |
| 1444 IntSize(250, (visualViewportHeight - browserControlsHeight) / pageScale), | 1439 IntSize(250, |
| 1445 visualViewport.VisibleRect().Size()); | 1440 (visual_viewport_height - browser_controls_height) / page_scale), |
| 1446 EXPECT_SIZE_EQ(IntSize(1000, layoutViewportHeight - | 1441 visual_viewport.VisibleRect().Size()); |
| 1447 browserControlsHeight / minPageScale), | 1442 EXPECT_SIZE_EQ(IntSize(1000, layout_viewport_height - |
| 1448 frameView.FrameRect().Size()); | 1443 browser_controls_height / min_page_scale), |
| 1449 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight - browserControlsHeight), | 1444 frame_view.FrameRect().Size()); |
| 1450 visualViewport.Size()); | 1445 EXPECT_SIZE_EQ(IntSize(500, visual_viewport_height - browser_controls_height), |
| 1446 visual_viewport.Size()); |
| 1451 | 1447 |
| 1452 // Scroll all the way to the bottom, hiding the browser controls in the | 1448 // Scroll all the way to the bottom, hiding the browser controls in the |
| 1453 // process. | 1449 // process. |
| 1454 visualViewport.Move(ScrollOffset(10000, 10000)); | 1450 visual_viewport.Move(ScrollOffset(10000, 10000)); |
| 1455 frameView.LayoutViewportScrollableArea()->ScrollBy(ScrollOffset(10000, 10000), | 1451 frame_view.LayoutViewportScrollableArea()->ScrollBy( |
| 1456 kUserScroll); | 1452 ScrollOffset(10000, 10000), kUserScroll); |
| 1457 webViewImpl()->GetBrowserControls().SetShownRatio(0); | 1453 WebViewImpl()->GetBrowserControls().SetShownRatio(0); |
| 1458 | 1454 |
| 1459 EXPECT_SIZE_EQ(IntSize(250, visualViewportHeight / pageScale), | 1455 EXPECT_SIZE_EQ(IntSize(250, visual_viewport_height / page_scale), |
| 1460 visualViewport.VisibleRect().Size()); | 1456 visual_viewport.VisibleRect().Size()); |
| 1461 | 1457 |
| 1462 ScrollOffset frameViewExpected = | 1458 ScrollOffset frame_view_expected = |
| 1463 expectedMaxFrameViewScrollOffset(visualViewport, frameView); | 1459 expectedMaxFrameViewScrollOffset(visual_viewport, frame_view); |
| 1464 ScrollOffset visualViewportExpected = ScrollOffset( | 1460 ScrollOffset visual_viewport_expected = ScrollOffset( |
| 1465 750, layoutViewportHeight - visualViewportHeight / pageScale); | 1461 750, layout_viewport_height - visual_viewport_height / page_scale); |
| 1466 | 1462 |
| 1467 EXPECT_SIZE_EQ(visualViewportExpected, visualViewport.GetScrollOffset()); | 1463 EXPECT_SIZE_EQ(visual_viewport_expected, visual_viewport.GetScrollOffset()); |
| 1468 EXPECT_SIZE_EQ(frameViewExpected, | 1464 EXPECT_SIZE_EQ(frame_view_expected, |
| 1469 frameView.LayoutViewportScrollableArea()->GetScrollOffset()); | 1465 frame_view.LayoutViewportScrollableArea()->GetScrollOffset()); |
| 1470 | 1466 |
| 1471 ScrollOffset totalExpected = visualViewportExpected + frameViewExpected; | 1467 ScrollOffset total_expected = visual_viewport_expected + frame_view_expected; |
| 1472 | 1468 |
| 1473 // Resize the widget to match the browser controls adjustment. Ensure that the | 1469 // Resize the widget to match the browser controls adjustment. Ensure that the |
| 1474 // total offset (i.e. what the user sees) doesn't change because of clamping | 1470 // total offset (i.e. what the user sees) doesn't change because of clamping |
| 1475 // the offsets to valid values. | 1471 // the offsets to valid values. |
| 1476 webViewImpl()->ResizeWithBrowserControls(WebSize(500, visualViewportHeight), | 1472 WebViewImpl()->ResizeWithBrowserControls(WebSize(500, visual_viewport_height), |
| 1477 20, false); | 1473 20, false); |
| 1478 | 1474 |
| 1479 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight), visualViewport.Size()); | 1475 EXPECT_SIZE_EQ(IntSize(500, visual_viewport_height), visual_viewport.Size()); |
| 1480 EXPECT_SIZE_EQ(IntSize(250, visualViewportHeight / pageScale), | 1476 EXPECT_SIZE_EQ(IntSize(250, visual_viewport_height / page_scale), |
| 1481 visualViewport.VisibleRect().Size()); | 1477 visual_viewport.VisibleRect().Size()); |
| 1482 EXPECT_SIZE_EQ(IntSize(1000, layoutViewportHeight), | 1478 EXPECT_SIZE_EQ(IntSize(1000, layout_viewport_height), |
| 1483 frameView.FrameRect().Size()); | 1479 frame_view.FrameRect().Size()); |
| 1484 EXPECT_SIZE_EQ( | 1480 EXPECT_SIZE_EQ( |
| 1485 totalExpected, | 1481 total_expected, |
| 1486 visualViewport.GetScrollOffset() + | 1482 visual_viewport.GetScrollOffset() + |
| 1487 frameView.LayoutViewportScrollableArea()->GetScrollOffset()); | 1483 frame_view.LayoutViewportScrollableArea()->GetScrollOffset()); |
| 1488 } | 1484 } |
| 1489 | 1485 |
| 1490 // Tests that a scroll all the way to the bottom while showing the browser | 1486 // Tests that a scroll all the way to the bottom while showing the browser |
| 1491 // controls doesn't cause a clamp to the viewport scroll offset when the browser | 1487 // controls doesn't cause a clamp to the viewport scroll offset when the browser |
| 1492 // controls initiated resize occurs. | 1488 // controls initiated resize occurs. |
| 1493 TEST_P(VisualViewportTest, TestBrowserControlsShrinkAdjustmentAndResize) { | 1489 TEST_P(VisualViewportTest, TestBrowserControlsShrinkAdjustmentAndResize) { |
| 1494 int browserControlsHeight = 20; | 1490 int browser_controls_height = 20; |
| 1495 int visualViewportHeight = 500; | 1491 int visual_viewport_height = 500; |
| 1496 int layoutViewportHeight = 1000; | 1492 int layout_viewport_height = 1000; |
| 1497 int contentHeight = 2000; | 1493 int content_height = 2000; |
| 1498 float pageScale = 2; | 1494 float page_scale = 2; |
| 1499 float minPageScale = 0.5; | 1495 float min_page_scale = 0.5; |
| 1500 | 1496 |
| 1501 initializeWithAndroidSettings(); | 1497 InitializeWithAndroidSettings(); |
| 1502 | 1498 |
| 1503 // Initialize with browser controls hidden and not shrinking the Blink size. | 1499 // Initialize with browser controls hidden and not shrinking the Blink size. |
| 1504 webViewImpl()->ResizeWithBrowserControls(IntSize(500, visualViewportHeight), | 1500 WebViewImpl()->ResizeWithBrowserControls(IntSize(500, visual_viewport_height), |
| 1505 20, false); | 1501 20, false); |
| 1506 webViewImpl()->GetBrowserControls().SetShownRatio(0); | 1502 WebViewImpl()->GetBrowserControls().SetShownRatio(0); |
| 1507 | 1503 |
| 1508 registerMockedHttpURLLoad("content-width-1000.html"); | 1504 RegisterMockedHttpURLLoad("content-width-1000.html"); |
| 1509 navigateTo(m_baseURL + "content-width-1000.html"); | 1505 NavigateTo(base_url_ + "content-width-1000.html"); |
| 1510 | 1506 |
| 1511 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 1507 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 1512 FrameView& frameView = *webViewImpl()->MainFrameImpl()->GetFrameView(); | 1508 FrameView& frame_view = *WebViewImpl()->MainFrameImpl()->GetFrameView(); |
| 1513 | 1509 |
| 1514 visualViewport.SetScale(pageScale); | 1510 visual_viewport.SetScale(page_scale); |
| 1515 EXPECT_SIZE_EQ(IntSize(250, visualViewportHeight / pageScale), | 1511 EXPECT_SIZE_EQ(IntSize(250, visual_viewport_height / page_scale), |
| 1516 visualViewport.VisibleRect().Size()); | 1512 visual_viewport.VisibleRect().Size()); |
| 1517 EXPECT_SIZE_EQ(IntSize(1000, layoutViewportHeight), | 1513 EXPECT_SIZE_EQ(IntSize(1000, layout_viewport_height), |
| 1518 frameView.FrameRect().Size()); | 1514 frame_view.FrameRect().Size()); |
| 1519 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight), visualViewport.Size()); | 1515 EXPECT_SIZE_EQ(IntSize(500, visual_viewport_height), visual_viewport.Size()); |
| 1520 | 1516 |
| 1521 // Scroll all the way to the bottom, showing the the browser controls in the | 1517 // Scroll all the way to the bottom, showing the the browser controls in the |
| 1522 // process. (This could happen via window.scrollTo during a scroll, for | 1518 // process. (This could happen via window.scrollTo during a scroll, for |
| 1523 // example). | 1519 // example). |
| 1524 webViewImpl()->GetBrowserControls().SetShownRatio(1); | 1520 WebViewImpl()->GetBrowserControls().SetShownRatio(1); |
| 1525 visualViewport.Move(ScrollOffset(10000, 10000)); | 1521 visual_viewport.Move(ScrollOffset(10000, 10000)); |
| 1526 frameView.LayoutViewportScrollableArea()->ScrollBy(ScrollOffset(10000, 10000), | 1522 frame_view.LayoutViewportScrollableArea()->ScrollBy( |
| 1527 kUserScroll); | 1523 ScrollOffset(10000, 10000), kUserScroll); |
| 1528 | 1524 |
| 1529 EXPECT_SIZE_EQ( | 1525 EXPECT_SIZE_EQ( |
| 1530 IntSize(250, (visualViewportHeight - browserControlsHeight) / pageScale), | 1526 IntSize(250, |
| 1531 visualViewport.VisibleRect().Size()); | 1527 (visual_viewport_height - browser_controls_height) / page_scale), |
| 1532 | 1528 visual_viewport.VisibleRect().Size()); |
| 1533 ScrollOffset frameViewExpected( | 1529 |
| 1534 0, contentHeight - | 1530 ScrollOffset frame_view_expected( |
| 1535 (layoutViewportHeight - browserControlsHeight / minPageScale)); | 1531 0, content_height - (layout_viewport_height - |
| 1536 ScrollOffset visualViewportExpected = ScrollOffset( | 1532 browser_controls_height / min_page_scale)); |
| 1537 750, (layoutViewportHeight - browserControlsHeight / minPageScale - | 1533 ScrollOffset visual_viewport_expected = ScrollOffset( |
| 1538 visualViewport.VisibleRect().Height())); | 1534 750, (layout_viewport_height - browser_controls_height / min_page_scale - |
| 1539 | 1535 visual_viewport.VisibleRect().Height())); |
| 1540 EXPECT_SIZE_EQ(visualViewportExpected, visualViewport.GetScrollOffset()); | 1536 |
| 1541 EXPECT_SIZE_EQ(frameViewExpected, | 1537 EXPECT_SIZE_EQ(visual_viewport_expected, visual_viewport.GetScrollOffset()); |
| 1542 frameView.LayoutViewportScrollableArea()->GetScrollOffset()); | 1538 EXPECT_SIZE_EQ(frame_view_expected, |
| 1543 | 1539 frame_view.LayoutViewportScrollableArea()->GetScrollOffset()); |
| 1544 ScrollOffset totalExpected = visualViewportExpected + frameViewExpected; | 1540 |
| 1541 ScrollOffset total_expected = visual_viewport_expected + frame_view_expected; |
| 1545 | 1542 |
| 1546 // Resize the widget to match the browser controls adjustment. Ensure that the | 1543 // Resize the widget to match the browser controls adjustment. Ensure that the |
| 1547 // total offset (i.e. what the user sees) doesn't change because of clamping | 1544 // total offset (i.e. what the user sees) doesn't change because of clamping |
| 1548 // the offsets to valid values. | 1545 // the offsets to valid values. |
| 1549 webViewImpl()->ResizeWithBrowserControls( | 1546 WebViewImpl()->ResizeWithBrowserControls( |
| 1550 WebSize(500, visualViewportHeight - browserControlsHeight), 20, true); | 1547 WebSize(500, visual_viewport_height - browser_controls_height), 20, true); |
| 1551 | 1548 |
| 1552 EXPECT_SIZE_EQ(IntSize(500, visualViewportHeight - browserControlsHeight), | 1549 EXPECT_SIZE_EQ(IntSize(500, visual_viewport_height - browser_controls_height), |
| 1553 visualViewport.Size()); | 1550 visual_viewport.Size()); |
| 1554 EXPECT_SIZE_EQ( | 1551 EXPECT_SIZE_EQ( |
| 1555 IntSize(250, (visualViewportHeight - browserControlsHeight) / pageScale), | 1552 IntSize(250, |
| 1556 visualViewport.VisibleRect().Size()); | 1553 (visual_viewport_height - browser_controls_height) / page_scale), |
| 1557 EXPECT_SIZE_EQ(IntSize(1000, layoutViewportHeight - | 1554 visual_viewport.VisibleRect().Size()); |
| 1558 browserControlsHeight / minPageScale), | 1555 EXPECT_SIZE_EQ(IntSize(1000, layout_viewport_height - |
| 1559 frameView.FrameRect().Size()); | 1556 browser_controls_height / min_page_scale), |
| 1557 frame_view.FrameRect().Size()); |
| 1560 EXPECT_SIZE_EQ( | 1558 EXPECT_SIZE_EQ( |
| 1561 totalExpected, | 1559 total_expected, |
| 1562 visualViewport.GetScrollOffset() + | 1560 visual_viewport.GetScrollOffset() + |
| 1563 frameView.LayoutViewportScrollableArea()->GetScrollOffset()); | 1561 frame_view.LayoutViewportScrollableArea()->GetScrollOffset()); |
| 1564 } | 1562 } |
| 1565 | 1563 |
| 1566 // Tests that a resize due to browser controls hiding doesn't incorrectly clamp | 1564 // Tests that a resize due to browser controls hiding doesn't incorrectly clamp |
| 1567 // the main frame's scroll offset. crbug.com/428193. | 1565 // the main frame's scroll offset. crbug.com/428193. |
| 1568 TEST_P(VisualViewportTest, TestTopControlHidingResizeDoesntClampMainFrame) { | 1566 TEST_P(VisualViewportTest, TestTopControlHidingResizeDoesntClampMainFrame) { |
| 1569 initializeWithAndroidSettings(); | 1567 InitializeWithAndroidSettings(); |
| 1570 webViewImpl()->ResizeWithBrowserControls(webViewImpl()->Size(), 500, false); | 1568 WebViewImpl()->ResizeWithBrowserControls(WebViewImpl()->Size(), 500, false); |
| 1571 webViewImpl()->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), | 1569 WebViewImpl()->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), |
| 1572 WebFloatSize(), 1, 1); | 1570 WebFloatSize(), 1, 1); |
| 1573 webViewImpl()->ResizeWithBrowserControls(WebSize(1000, 1000), 500, true); | 1571 WebViewImpl()->ResizeWithBrowserControls(WebSize(1000, 1000), 500, true); |
| 1574 | 1572 |
| 1575 registerMockedHttpURLLoad("content-width-1000.html"); | 1573 RegisterMockedHttpURLLoad("content-width-1000.html"); |
| 1576 navigateTo(m_baseURL + "content-width-1000.html"); | 1574 NavigateTo(base_url_ + "content-width-1000.html"); |
| 1577 | 1575 |
| 1578 // Scroll the FrameView to the bottom of the page but "hide" the browser | 1576 // Scroll the FrameView to the bottom of the page but "hide" the browser |
| 1579 // controls on the compositor side so the max scroll position should account | 1577 // controls on the compositor side so the max scroll position should account |
| 1580 // for the full viewport height. | 1578 // for the full viewport height. |
| 1581 webViewImpl()->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), | 1579 WebViewImpl()->ApplyViewportDeltas(WebFloatSize(), WebFloatSize(), |
| 1582 WebFloatSize(), 1, -1); | 1580 WebFloatSize(), 1, -1); |
| 1583 FrameView& frameView = *webViewImpl()->MainFrameImpl()->GetFrameView(); | 1581 FrameView& frame_view = *WebViewImpl()->MainFrameImpl()->GetFrameView(); |
| 1584 frameView.LayoutViewportScrollableArea()->SetScrollOffset( | 1582 frame_view.LayoutViewportScrollableArea()->SetScrollOffset( |
| 1585 ScrollOffset(0, 10000), kProgrammaticScroll); | 1583 ScrollOffset(0, 10000), kProgrammaticScroll); |
| 1586 EXPECT_EQ( | 1584 EXPECT_EQ( |
| 1587 500, | 1585 500, |
| 1588 frameView.LayoutViewportScrollableArea()->GetScrollOffset().Height()); | 1586 frame_view.LayoutViewportScrollableArea()->GetScrollOffset().Height()); |
| 1589 | 1587 |
| 1590 // Now send the resize, make sure the scroll offset doesn't change. | 1588 // Now send the resize, make sure the scroll offset doesn't change. |
| 1591 webViewImpl()->ResizeWithBrowserControls(WebSize(1000, 1500), 500, false); | 1589 WebViewImpl()->ResizeWithBrowserControls(WebSize(1000, 1500), 500, false); |
| 1592 EXPECT_EQ( | 1590 EXPECT_EQ( |
| 1593 500, | 1591 500, |
| 1594 frameView.LayoutViewportScrollableArea()->GetScrollOffset().Height()); | 1592 frame_view.LayoutViewportScrollableArea()->GetScrollOffset().Height()); |
| 1595 } | 1593 } |
| 1596 | 1594 |
| 1597 static void configureHiddenScrollbarsSettings(WebSettings* settings) { | 1595 static void configureHiddenScrollbarsSettings(WebSettings* settings) { |
| 1598 VisualViewportTest::configureAndroidSettings(settings); | 1596 VisualViewportTest::ConfigureAndroidSettings(settings); |
| 1599 settings->SetHideScrollbars(true); | 1597 settings->SetHideScrollbars(true); |
| 1600 } | 1598 } |
| 1601 | 1599 |
| 1602 // Tests that scrollbar layers are not attached to the inner viewport container | 1600 // Tests that scrollbar layers are not attached to the inner viewport container |
| 1603 // layer when hideScrollbars WebSetting is true. | 1601 // layer when hideScrollbars WebSetting is true. |
| 1604 TEST_P(VisualViewportTest, | 1602 TEST_P(VisualViewportTest, |
| 1605 TestScrollbarsNotAttachedWhenHideScrollbarsSettingIsTrue) { | 1603 TestScrollbarsNotAttachedWhenHideScrollbarsSettingIsTrue) { |
| 1606 initializeWithAndroidSettings(configureHiddenScrollbarsSettings); | 1604 InitializeWithAndroidSettings(configureHiddenScrollbarsSettings); |
| 1607 webViewImpl()->Resize(IntSize(100, 150)); | 1605 WebViewImpl()->Resize(IntSize(100, 150)); |
| 1608 navigateTo("about:blank"); | 1606 NavigateTo("about:blank"); |
| 1609 | 1607 |
| 1610 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 1608 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 1611 EXPECT_FALSE(visualViewport.LayerForHorizontalScrollbar()->Parent()); | 1609 EXPECT_FALSE(visual_viewport.LayerForHorizontalScrollbar()->Parent()); |
| 1612 EXPECT_FALSE(visualViewport.LayerForVerticalScrollbar()->Parent()); | 1610 EXPECT_FALSE(visual_viewport.LayerForVerticalScrollbar()->Parent()); |
| 1613 } | 1611 } |
| 1614 | 1612 |
| 1615 // Tests that scrollbar layers are attached to the inner viewport container | 1613 // Tests that scrollbar layers are attached to the inner viewport container |
| 1616 // layer when hideScrollbars WebSetting is false. | 1614 // layer when hideScrollbars WebSetting is false. |
| 1617 TEST_P(VisualViewportTest, | 1615 TEST_P(VisualViewportTest, |
| 1618 TestScrollbarsAttachedWhenHideScrollbarsSettingIsFalse) { | 1616 TestScrollbarsAttachedWhenHideScrollbarsSettingIsFalse) { |
| 1619 initializeWithAndroidSettings(); | 1617 InitializeWithAndroidSettings(); |
| 1620 webViewImpl()->Resize(IntSize(100, 150)); | 1618 WebViewImpl()->Resize(IntSize(100, 150)); |
| 1621 navigateTo("about:blank"); | 1619 NavigateTo("about:blank"); |
| 1622 | 1620 |
| 1623 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 1621 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 1624 EXPECT_TRUE(visualViewport.LayerForHorizontalScrollbar()->Parent()); | 1622 EXPECT_TRUE(visual_viewport.LayerForHorizontalScrollbar()->Parent()); |
| 1625 EXPECT_TRUE(visualViewport.LayerForVerticalScrollbar()->Parent()); | 1623 EXPECT_TRUE(visual_viewport.LayerForVerticalScrollbar()->Parent()); |
| 1626 } | 1624 } |
| 1627 | 1625 |
| 1628 // Tests that the layout viewport's scroll layer bounds are updated in a | 1626 // Tests that the layout viewport's scroll layer bounds are updated in a |
| 1629 // compositing change update. crbug.com/423188. | 1627 // compositing change update. crbug.com/423188. |
| 1630 TEST_P(VisualViewportTest, TestChangingContentSizeAffectsScrollBounds) { | 1628 TEST_P(VisualViewportTest, TestChangingContentSizeAffectsScrollBounds) { |
| 1631 initializeWithAndroidSettings(); | 1629 InitializeWithAndroidSettings(); |
| 1632 webViewImpl()->Resize(IntSize(100, 150)); | 1630 WebViewImpl()->Resize(IntSize(100, 150)); |
| 1633 | 1631 |
| 1634 registerMockedHttpURLLoad("content-width-1000.html"); | 1632 RegisterMockedHttpURLLoad("content-width-1000.html"); |
| 1635 navigateTo(m_baseURL + "content-width-1000.html"); | 1633 NavigateTo(base_url_ + "content-width-1000.html"); |
| 1636 | 1634 |
| 1637 FrameView& frameView = *webViewImpl()->MainFrameImpl()->GetFrameView(); | 1635 FrameView& frame_view = *WebViewImpl()->MainFrameImpl()->GetFrameView(); |
| 1638 | 1636 |
| 1639 webViewImpl()->MainFrame()->ExecuteScript( | 1637 WebViewImpl()->MainFrame()->ExecuteScript( |
| 1640 WebScriptSource("var content = document.getElementById(\"content\");" | 1638 WebScriptSource("var content = document.getElementById(\"content\");" |
| 1641 "content.style.width = \"1500px\";" | 1639 "content.style.width = \"1500px\";" |
| 1642 "content.style.height = \"2400px\";")); | 1640 "content.style.height = \"2400px\";")); |
| 1643 frameView.UpdateAllLifecyclePhases(); | 1641 frame_view.UpdateAllLifecyclePhases(); |
| 1644 WebLayer* scrollLayer = frameView.LayoutViewportScrollableArea() | 1642 WebLayer* scrollLayer = frame_view.LayoutViewportScrollableArea() |
| 1645 ->LayerForScrolling() | 1643 ->LayerForScrolling() |
| 1646 ->PlatformLayer(); | 1644 ->PlatformLayer(); |
| 1647 | 1645 |
| 1648 EXPECT_SIZE_EQ(IntSize(1500, 2400), IntSize(scrollLayer->Bounds())); | 1646 EXPECT_SIZE_EQ(IntSize(1500, 2400), IntSize(scrollLayer->Bounds())); |
| 1649 } | 1647 } |
| 1650 | 1648 |
| 1651 // Tests that resizing the visual viepwort keeps its bounds within the outer | 1649 // Tests that resizing the visual viepwort keeps its bounds within the outer |
| 1652 // viewport. | 1650 // viewport. |
| 1653 TEST_P(VisualViewportTest, ResizeVisualViewportStaysWithinOuterViewport) { | 1651 TEST_P(VisualViewportTest, ResizeVisualViewportStaysWithinOuterViewport) { |
| 1654 initializeWithDesktopSettings(); | 1652 InitializeWithDesktopSettings(); |
| 1655 webViewImpl()->Resize(IntSize(100, 200)); | 1653 WebViewImpl()->Resize(IntSize(100, 200)); |
| 1656 | 1654 |
| 1657 navigateTo("about:blank"); | 1655 NavigateTo("about:blank"); |
| 1658 webViewImpl()->UpdateAllLifecyclePhases(); | 1656 WebViewImpl()->UpdateAllLifecyclePhases(); |
| 1659 | 1657 |
| 1660 webViewImpl()->ResizeVisualViewport(IntSize(100, 100)); | 1658 WebViewImpl()->ResizeVisualViewport(IntSize(100, 100)); |
| 1661 | 1659 |
| 1662 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 1660 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 1663 visualViewport.Move(ScrollOffset(0, 100)); | 1661 visual_viewport.Move(ScrollOffset(0, 100)); |
| 1664 | 1662 |
| 1665 EXPECT_EQ(100, visualViewport.GetScrollOffset().Height()); | 1663 EXPECT_EQ(100, visual_viewport.GetScrollOffset().Height()); |
| 1666 | 1664 |
| 1667 webViewImpl()->ResizeVisualViewport(IntSize(100, 200)); | 1665 WebViewImpl()->ResizeVisualViewport(IntSize(100, 200)); |
| 1668 | 1666 |
| 1669 EXPECT_EQ(0, visualViewport.GetScrollOffset().Height()); | 1667 EXPECT_EQ(0, visual_viewport.GetScrollOffset().Height()); |
| 1670 } | 1668 } |
| 1671 | 1669 |
| 1672 TEST_P(VisualViewportTest, ElementBoundsInViewportSpaceAccountsForViewport) { | 1670 TEST_P(VisualViewportTest, ElementBoundsInViewportSpaceAccountsForViewport) { |
| 1673 initializeWithAndroidSettings(); | 1671 InitializeWithAndroidSettings(); |
| 1674 | 1672 |
| 1675 webViewImpl()->Resize(IntSize(500, 800)); | 1673 WebViewImpl()->Resize(IntSize(500, 800)); |
| 1676 | 1674 |
| 1677 registerMockedHttpURLLoad("pinch-viewport-input-field.html"); | 1675 RegisterMockedHttpURLLoad("pinch-viewport-input-field.html"); |
| 1678 navigateTo(m_baseURL + "pinch-viewport-input-field.html"); | 1676 NavigateTo(base_url_ + "pinch-viewport-input-field.html"); |
| 1679 | 1677 |
| 1680 webViewImpl()->SetInitialFocus(false); | 1678 WebViewImpl()->SetInitialFocus(false); |
| 1681 Element* inputElement = webViewImpl()->FocusedElement(); | 1679 Element* input_element = WebViewImpl()->FocusedElement(); |
| 1682 | 1680 |
| 1683 IntRect bounds = inputElement->GetLayoutObject()->AbsoluteBoundingBoxRect(); | 1681 IntRect bounds = input_element->GetLayoutObject()->AbsoluteBoundingBoxRect(); |
| 1684 | 1682 |
| 1685 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 1683 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 1686 IntPoint scrollDelta(250, 400); | 1684 IntPoint scrollDelta(250, 400); |
| 1687 visualViewport.SetScale(2); | 1685 visual_viewport.SetScale(2); |
| 1688 visualViewport.SetLocation(scrollDelta); | 1686 visual_viewport.SetLocation(scrollDelta); |
| 1689 | 1687 |
| 1690 const IntRect boundsInViewport = inputElement->BoundsInViewport(); | 1688 const IntRect bounds_in_viewport = input_element->BoundsInViewport(); |
| 1691 IntRect expectedBounds = bounds; | 1689 IntRect expectedBounds = bounds; |
| 1692 expectedBounds.Scale(2.f); | 1690 expectedBounds.Scale(2.f); |
| 1693 IntPoint expectedScrollDelta = scrollDelta; | 1691 IntPoint expectedScrollDelta = scrollDelta; |
| 1694 expectedScrollDelta.Scale(2.f, 2.f); | 1692 expectedScrollDelta.Scale(2.f, 2.f); |
| 1695 | 1693 |
| 1696 EXPECT_POINT_EQ(IntPoint(expectedBounds.Location() - expectedScrollDelta), | 1694 EXPECT_POINT_EQ(IntPoint(expectedBounds.Location() - expectedScrollDelta), |
| 1697 boundsInViewport.Location()); | 1695 bounds_in_viewport.Location()); |
| 1698 EXPECT_SIZE_EQ(expectedBounds.Size(), boundsInViewport.Size()); | 1696 EXPECT_SIZE_EQ(expectedBounds.Size(), bounds_in_viewport.Size()); |
| 1699 } | 1697 } |
| 1700 | 1698 |
| 1701 TEST_P(VisualViewportTest, ElementVisibleBoundsInVisualViewport) { | 1699 TEST_P(VisualViewportTest, ElementVisibleBoundsInVisualViewport) { |
| 1702 initializeWithAndroidSettings(); | 1700 InitializeWithAndroidSettings(); |
| 1703 webViewImpl()->Resize(IntSize(640, 1080)); | 1701 WebViewImpl()->Resize(IntSize(640, 1080)); |
| 1704 registerMockedHttpURLLoad("viewport-select.html"); | 1702 RegisterMockedHttpURLLoad("viewport-select.html"); |
| 1705 navigateTo(m_baseURL + "viewport-select.html"); | 1703 NavigateTo(base_url_ + "viewport-select.html"); |
| 1706 | 1704 |
| 1707 ASSERT_EQ(2.0f, webViewImpl()->PageScaleFactor()); | 1705 ASSERT_EQ(2.0f, WebViewImpl()->PageScaleFactor()); |
| 1708 webViewImpl()->SetInitialFocus(false); | 1706 WebViewImpl()->SetInitialFocus(false); |
| 1709 Element* element = webViewImpl()->FocusedElement(); | 1707 Element* element = WebViewImpl()->FocusedElement(); |
| 1710 EXPECT_FALSE(element->VisibleBoundsInVisualViewport().IsEmpty()); | 1708 EXPECT_FALSE(element->VisibleBoundsInVisualViewport().IsEmpty()); |
| 1711 | 1709 |
| 1712 webViewImpl()->SetPageScaleFactor(4.0); | 1710 WebViewImpl()->SetPageScaleFactor(4.0); |
| 1713 EXPECT_TRUE(element->VisibleBoundsInVisualViewport().IsEmpty()); | 1711 EXPECT_TRUE(element->VisibleBoundsInVisualViewport().IsEmpty()); |
| 1714 } | 1712 } |
| 1715 | 1713 |
| 1716 // Test that the various window.scroll and document.body.scroll properties and | 1714 // Test that the various window.scroll and document.body.scroll properties and |
| 1717 // methods work unchanged from the pre-virtual viewport mode. | 1715 // methods work unchanged from the pre-virtual viewport mode. |
| 1718 TEST_P(VisualViewportTest, bodyAndWindowScrollPropertiesAccountForViewport) { | 1716 TEST_P(VisualViewportTest, bodyAndWindowScrollPropertiesAccountForViewport) { |
| 1719 initializeWithAndroidSettings(); | 1717 InitializeWithAndroidSettings(); |
| 1720 | 1718 |
| 1721 webViewImpl()->Resize(IntSize(200, 300)); | 1719 WebViewImpl()->Resize(IntSize(200, 300)); |
| 1722 | 1720 |
| 1723 // Load page with no main frame scrolling. | 1721 // Load page with no main frame scrolling. |
| 1724 registerMockedHttpURLLoad("200-by-300-viewport.html"); | 1722 RegisterMockedHttpURLLoad("200-by-300-viewport.html"); |
| 1725 navigateTo(m_baseURL + "200-by-300-viewport.html"); | 1723 NavigateTo(base_url_ + "200-by-300-viewport.html"); |
| 1726 | 1724 |
| 1727 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 1725 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 1728 visualViewport.SetScale(2); | 1726 visual_viewport.SetScale(2); |
| 1729 | 1727 |
| 1730 // Chrome's quirky behavior regarding viewport scrolling means we treat the | 1728 // Chrome's quirky behavior regarding viewport scrolling means we treat the |
| 1731 // body element as the viewport and don't apply scrolling to the HTML element. | 1729 // body element as the viewport and don't apply scrolling to the HTML element. |
| 1732 RuntimeEnabledFeatures::setScrollTopLeftInteropEnabled(false); | 1730 RuntimeEnabledFeatures::setScrollTopLeftInteropEnabled(false); |
| 1733 | 1731 |
| 1734 LocalDOMWindow* window = | 1732 LocalDOMWindow* window = |
| 1735 webViewImpl()->MainFrameImpl()->GetFrame()->DomWindow(); | 1733 WebViewImpl()->MainFrameImpl()->GetFrame()->DomWindow(); |
| 1736 window->scrollTo(100, 150); | 1734 window->scrollTo(100, 150); |
| 1737 EXPECT_EQ(100, window->scrollX()); | 1735 EXPECT_EQ(100, window->scrollX()); |
| 1738 EXPECT_EQ(150, window->scrollY()); | 1736 EXPECT_EQ(150, window->scrollY()); |
| 1739 EXPECT_FLOAT_SIZE_EQ(FloatSize(100, 150), visualViewport.GetScrollOffset()); | 1737 EXPECT_FLOAT_SIZE_EQ(FloatSize(100, 150), visual_viewport.GetScrollOffset()); |
| 1740 | 1738 |
| 1741 HTMLElement* body = toHTMLBodyElement(window->document()->body()); | 1739 HTMLElement* body = toHTMLBodyElement(window->document()->body()); |
| 1742 body->setScrollLeft(50); | 1740 body->setScrollLeft(50); |
| 1743 body->setScrollTop(130); | 1741 body->setScrollTop(130); |
| 1744 EXPECT_EQ(50, body->scrollLeft()); | 1742 EXPECT_EQ(50, body->scrollLeft()); |
| 1745 EXPECT_EQ(130, body->scrollTop()); | 1743 EXPECT_EQ(130, body->scrollTop()); |
| 1746 EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 130), visualViewport.GetScrollOffset()); | 1744 EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 130), visual_viewport.GetScrollOffset()); |
| 1747 | 1745 |
| 1748 HTMLElement* documentElement = | 1746 HTMLElement* document_element = |
| 1749 ToHTMLElement(window->document()->documentElement()); | 1747 ToHTMLElement(window->document()->documentElement()); |
| 1750 documentElement->setScrollLeft(40); | 1748 document_element->setScrollLeft(40); |
| 1751 documentElement->setScrollTop(50); | 1749 document_element->setScrollTop(50); |
| 1752 EXPECT_EQ(0, documentElement->scrollLeft()); | 1750 EXPECT_EQ(0, document_element->scrollLeft()); |
| 1753 EXPECT_EQ(0, documentElement->scrollTop()); | 1751 EXPECT_EQ(0, document_element->scrollTop()); |
| 1754 EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 130), visualViewport.GetScrollOffset()); | 1752 EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 130), visual_viewport.GetScrollOffset()); |
| 1755 | 1753 |
| 1756 visualViewport.SetLocation(FloatPoint(10, 20)); | 1754 visual_viewport.SetLocation(FloatPoint(10, 20)); |
| 1757 EXPECT_EQ(10, body->scrollLeft()); | 1755 EXPECT_EQ(10, body->scrollLeft()); |
| 1758 EXPECT_EQ(20, body->scrollTop()); | 1756 EXPECT_EQ(20, body->scrollTop()); |
| 1759 EXPECT_EQ(0, documentElement->scrollLeft()); | 1757 EXPECT_EQ(0, document_element->scrollLeft()); |
| 1760 EXPECT_EQ(0, documentElement->scrollTop()); | 1758 EXPECT_EQ(0, document_element->scrollTop()); |
| 1761 EXPECT_EQ(10, window->scrollX()); | 1759 EXPECT_EQ(10, window->scrollX()); |
| 1762 EXPECT_EQ(20, window->scrollY()); | 1760 EXPECT_EQ(20, window->scrollY()); |
| 1763 | 1761 |
| 1764 // Turning on the standards-compliant viewport scrolling impl should make the | 1762 // Turning on the standards-compliant viewport scrolling impl should make the |
| 1765 // document element the viewport and not body. | 1763 // document element the viewport and not body. |
| 1766 RuntimeEnabledFeatures::setScrollTopLeftInteropEnabled(true); | 1764 RuntimeEnabledFeatures::setScrollTopLeftInteropEnabled(true); |
| 1767 | 1765 |
| 1768 window->scrollTo(100, 150); | 1766 window->scrollTo(100, 150); |
| 1769 EXPECT_EQ(100, window->scrollX()); | 1767 EXPECT_EQ(100, window->scrollX()); |
| 1770 EXPECT_EQ(150, window->scrollY()); | 1768 EXPECT_EQ(150, window->scrollY()); |
| 1771 EXPECT_FLOAT_SIZE_EQ(FloatSize(100, 150), visualViewport.GetScrollOffset()); | 1769 EXPECT_FLOAT_SIZE_EQ(FloatSize(100, 150), visual_viewport.GetScrollOffset()); |
| 1772 | 1770 |
| 1773 body->setScrollLeft(50); | 1771 body->setScrollLeft(50); |
| 1774 body->setScrollTop(130); | 1772 body->setScrollTop(130); |
| 1775 EXPECT_EQ(0, body->scrollLeft()); | 1773 EXPECT_EQ(0, body->scrollLeft()); |
| 1776 EXPECT_EQ(0, body->scrollTop()); | 1774 EXPECT_EQ(0, body->scrollTop()); |
| 1777 EXPECT_FLOAT_SIZE_EQ(FloatSize(100, 150), visualViewport.GetScrollOffset()); | 1775 EXPECT_FLOAT_SIZE_EQ(FloatSize(100, 150), visual_viewport.GetScrollOffset()); |
| 1778 | 1776 |
| 1779 documentElement->setScrollLeft(40); | 1777 document_element->setScrollLeft(40); |
| 1780 documentElement->setScrollTop(50); | 1778 document_element->setScrollTop(50); |
| 1781 EXPECT_EQ(40, documentElement->scrollLeft()); | 1779 EXPECT_EQ(40, document_element->scrollLeft()); |
| 1782 EXPECT_EQ(50, documentElement->scrollTop()); | 1780 EXPECT_EQ(50, document_element->scrollTop()); |
| 1783 EXPECT_FLOAT_SIZE_EQ(FloatSize(40, 50), visualViewport.GetScrollOffset()); | 1781 EXPECT_FLOAT_SIZE_EQ(FloatSize(40, 50), visual_viewport.GetScrollOffset()); |
| 1784 | 1782 |
| 1785 visualViewport.SetLocation(FloatPoint(10, 20)); | 1783 visual_viewport.SetLocation(FloatPoint(10, 20)); |
| 1786 EXPECT_EQ(0, body->scrollLeft()); | 1784 EXPECT_EQ(0, body->scrollLeft()); |
| 1787 EXPECT_EQ(0, body->scrollTop()); | 1785 EXPECT_EQ(0, body->scrollTop()); |
| 1788 EXPECT_EQ(10, documentElement->scrollLeft()); | 1786 EXPECT_EQ(10, document_element->scrollLeft()); |
| 1789 EXPECT_EQ(20, documentElement->scrollTop()); | 1787 EXPECT_EQ(20, document_element->scrollTop()); |
| 1790 EXPECT_EQ(10, window->scrollX()); | 1788 EXPECT_EQ(10, window->scrollX()); |
| 1791 EXPECT_EQ(20, window->scrollY()); | 1789 EXPECT_EQ(20, window->scrollY()); |
| 1792 } | 1790 } |
| 1793 | 1791 |
| 1794 // Tests that when a new frame is created, it is created with the intended size | 1792 // Tests that when a new frame is created, it is created with the intended size |
| 1795 // (i.e. viewport at minimum scale, 100x200 / 0.5). | 1793 // (i.e. viewport at minimum scale, 100x200 / 0.5). |
| 1796 TEST_P(VisualViewportTest, TestMainFrameInitializationSizing) { | 1794 TEST_P(VisualViewportTest, TestMainFrameInitializationSizing) { |
| 1797 initializeWithAndroidSettings(); | 1795 InitializeWithAndroidSettings(); |
| 1798 | 1796 |
| 1799 webViewImpl()->Resize(IntSize(100, 200)); | 1797 WebViewImpl()->Resize(IntSize(100, 200)); |
| 1800 | 1798 |
| 1801 registerMockedHttpURLLoad("content-width-1000-min-scale.html"); | 1799 RegisterMockedHttpURLLoad("content-width-1000-min-scale.html"); |
| 1802 navigateTo(m_baseURL + "content-width-1000-min-scale.html"); | 1800 NavigateTo(base_url_ + "content-width-1000-min-scale.html"); |
| 1803 | 1801 |
| 1804 WebLocalFrameImpl* localFrame = webViewImpl()->MainFrameImpl(); | 1802 WebLocalFrameImpl* local_frame = WebViewImpl()->MainFrameImpl(); |
| 1805 // The shutdown() calls are a hack to prevent this test from violating | 1803 // The shutdown() calls are a hack to prevent this test from violating |
| 1806 // invariants about frame state during navigation/detach. | 1804 // invariants about frame state during navigation/detach. |
| 1807 localFrame->GetFrame()->GetDocument()->Shutdown(); | 1805 local_frame->GetFrame()->GetDocument()->Shutdown(); |
| 1808 localFrame->CreateFrameView(); | 1806 local_frame->CreateFrameView(); |
| 1809 | 1807 |
| 1810 FrameView& frameView = *localFrame->GetFrameView(); | 1808 FrameView& frame_view = *local_frame->GetFrameView(); |
| 1811 EXPECT_SIZE_EQ(IntSize(200, 400), frameView.FrameRect().Size()); | 1809 EXPECT_SIZE_EQ(IntSize(200, 400), frame_view.FrameRect().Size()); |
| 1812 frameView.Dispose(); | 1810 frame_view.Dispose(); |
| 1813 } | 1811 } |
| 1814 | 1812 |
| 1815 // Tests that the maximum scroll offset of the viewport can be fractional. | 1813 // Tests that the maximum scroll offset of the viewport can be fractional. |
| 1816 TEST_P(VisualViewportTest, FractionalMaxScrollOffset) { | 1814 TEST_P(VisualViewportTest, FractionalMaxScrollOffset) { |
| 1817 initializeWithDesktopSettings(); | 1815 InitializeWithDesktopSettings(); |
| 1818 webViewImpl()->Resize(IntSize(101, 201)); | 1816 WebViewImpl()->Resize(IntSize(101, 201)); |
| 1819 navigateTo("about:blank"); | 1817 NavigateTo("about:blank"); |
| 1820 | 1818 |
| 1821 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 1819 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 1822 ScrollableArea* scrollableArea = &visualViewport; | 1820 ScrollableArea* scrollable_area = &visual_viewport; |
| 1823 | 1821 |
| 1824 webViewImpl()->SetPageScaleFactor(1.0); | 1822 WebViewImpl()->SetPageScaleFactor(1.0); |
| 1825 EXPECT_SIZE_EQ(ScrollOffset(), scrollableArea->MaximumScrollOffset()); | 1823 EXPECT_SIZE_EQ(ScrollOffset(), scrollable_area->MaximumScrollOffset()); |
| 1826 | 1824 |
| 1827 webViewImpl()->SetPageScaleFactor(2); | 1825 WebViewImpl()->SetPageScaleFactor(2); |
| 1828 EXPECT_SIZE_EQ(ScrollOffset(101. / 2., 201. / 2.), | 1826 EXPECT_SIZE_EQ(ScrollOffset(101. / 2., 201. / 2.), |
| 1829 scrollableArea->MaximumScrollOffset()); | 1827 scrollable_area->MaximumScrollOffset()); |
| 1830 } | 1828 } |
| 1831 | 1829 |
| 1832 // Tests that the slow scrolling after an impl scroll on the visual viewport is | 1830 // Tests that the slow scrolling after an impl scroll on the visual viewport is |
| 1833 // continuous. crbug.com/453460 was caused by the impl-path not updating the | 1831 // continuous. crbug.com/453460 was caused by the impl-path not updating the |
| 1834 // ScrollAnimatorBase class. | 1832 // ScrollAnimatorBase class. |
| 1835 TEST_P(VisualViewportTest, SlowScrollAfterImplScroll) { | 1833 TEST_P(VisualViewportTest, SlowScrollAfterImplScroll) { |
| 1836 initializeWithDesktopSettings(); | 1834 InitializeWithDesktopSettings(); |
| 1837 webViewImpl()->Resize(IntSize(800, 600)); | 1835 WebViewImpl()->Resize(IntSize(800, 600)); |
| 1838 navigateTo("about:blank"); | 1836 NavigateTo("about:blank"); |
| 1839 | 1837 |
| 1840 VisualViewport& visualViewport = frame()->GetPage()->GetVisualViewport(); | 1838 VisualViewport& visual_viewport = GetFrame()->GetPage()->GetVisualViewport(); |
| 1841 | 1839 |
| 1842 // Apply some scroll and scale from the impl-side. | 1840 // Apply some scroll and scale from the impl-side. |
| 1843 webViewImpl()->ApplyViewportDeltas(WebFloatSize(300, 200), WebFloatSize(0, 0), | 1841 WebViewImpl()->ApplyViewportDeltas(WebFloatSize(300, 200), WebFloatSize(0, 0), |
| 1844 WebFloatSize(0, 0), 2, 0); | 1842 WebFloatSize(0, 0), 2, 0); |
| 1845 | 1843 |
| 1846 EXPECT_SIZE_EQ(FloatSize(300, 200), visualViewport.GetScrollOffset()); | 1844 EXPECT_SIZE_EQ(FloatSize(300, 200), visual_viewport.GetScrollOffset()); |
| 1847 | 1845 |
| 1848 // Send a scroll event on the main thread path. | 1846 // Send a scroll event on the main thread path. |
| 1849 WebGestureEvent gsu(WebInputEvent::kGestureScrollUpdate, | 1847 WebGestureEvent gsu(WebInputEvent::kGestureScrollUpdate, |
| 1850 WebInputEvent::kNoModifiers, | 1848 WebInputEvent::kNoModifiers, |
| 1851 WebInputEvent::kTimeStampForTesting); | 1849 WebInputEvent::kTimeStampForTesting); |
| 1852 gsu.SetFrameScale(1); | 1850 gsu.SetFrameScale(1); |
| 1853 gsu.source_device = kWebGestureDeviceTouchpad; | 1851 gsu.source_device = kWebGestureDeviceTouchpad; |
| 1854 gsu.data.scroll_update.delta_x = -50; | 1852 gsu.data.scroll_update.delta_x = -50; |
| 1855 gsu.data.scroll_update.delta_y = -60; | 1853 gsu.data.scroll_update.delta_y = -60; |
| 1856 gsu.data.scroll_update.delta_units = WebGestureEvent::kPrecisePixels; | 1854 gsu.data.scroll_update.delta_units = WebGestureEvent::kPrecisePixels; |
| 1857 gsu.data.scroll_update.velocity_x = 1; | 1855 gsu.data.scroll_update.velocity_x = 1; |
| 1858 gsu.data.scroll_update.velocity_y = 1; | 1856 gsu.data.scroll_update.velocity_y = 1; |
| 1859 | 1857 |
| 1860 frame()->GetEventHandler().HandleGestureEvent(gsu); | 1858 GetFrame()->GetEventHandler().HandleGestureEvent(gsu); |
| 1861 | 1859 |
| 1862 // The scroll sent from the impl-side must not be overwritten. | 1860 // The scroll sent from the impl-side must not be overwritten. |
| 1863 EXPECT_SIZE_EQ(FloatSize(350, 260), visualViewport.GetScrollOffset()); | 1861 EXPECT_SIZE_EQ(FloatSize(350, 260), visual_viewport.GetScrollOffset()); |
| 1864 } | 1862 } |
| 1865 | 1863 |
| 1866 static void accessibilitySettings(WebSettings* settings) { | 1864 static void accessibilitySettings(WebSettings* settings) { |
| 1867 VisualViewportTest::configureSettings(settings); | 1865 VisualViewportTest::ConfigureSettings(settings); |
| 1868 settings->SetAccessibilityEnabled(true); | 1866 settings->SetAccessibilityEnabled(true); |
| 1869 } | 1867 } |
| 1870 | 1868 |
| 1871 TEST_P(VisualViewportTest, AccessibilityHitTestWhileZoomedIn) { | 1869 TEST_P(VisualViewportTest, AccessibilityHitTestWhileZoomedIn) { |
| 1872 initializeWithDesktopSettings(accessibilitySettings); | 1870 InitializeWithDesktopSettings(accessibilitySettings); |
| 1873 | 1871 |
| 1874 registerMockedHttpURLLoad("hit-test.html"); | 1872 RegisterMockedHttpURLLoad("hit-test.html"); |
| 1875 navigateTo(m_baseURL + "hit-test.html"); | 1873 NavigateTo(base_url_ + "hit-test.html"); |
| 1876 | 1874 |
| 1877 webViewImpl()->Resize(IntSize(500, 500)); | 1875 WebViewImpl()->Resize(IntSize(500, 500)); |
| 1878 webViewImpl()->UpdateAllLifecyclePhases(); | 1876 WebViewImpl()->UpdateAllLifecyclePhases(); |
| 1879 | 1877 |
| 1880 WebDocument webDoc = webViewImpl()->MainFrame()->GetDocument(); | 1878 WebDocument web_doc = WebViewImpl()->MainFrame()->GetDocument(); |
| 1881 FrameView& frameView = *webViewImpl()->MainFrameImpl()->GetFrameView(); | 1879 FrameView& frame_view = *WebViewImpl()->MainFrameImpl()->GetFrameView(); |
| 1882 | 1880 |
| 1883 webViewImpl()->SetPageScaleFactor(2); | 1881 WebViewImpl()->SetPageScaleFactor(2); |
| 1884 webViewImpl()->SetVisualViewportOffset(WebFloatPoint(200, 230)); | 1882 WebViewImpl()->SetVisualViewportOffset(WebFloatPoint(200, 230)); |
| 1885 frameView.LayoutViewportScrollableArea()->SetScrollOffset( | 1883 frame_view.LayoutViewportScrollableArea()->SetScrollOffset( |
| 1886 ScrollOffset(400, 1100), kProgrammaticScroll); | 1884 ScrollOffset(400, 1100), kProgrammaticScroll); |
| 1887 | 1885 |
| 1888 // FIXME(504057): PaintLayerScrollableArea dirties the compositing state. | 1886 // FIXME(504057): PaintLayerScrollableArea dirties the compositing state. |
| 1889 forceFullCompositingUpdate(); | 1887 ForceFullCompositingUpdate(); |
| 1890 | 1888 |
| 1891 // Because of where the visual viewport is located, this should hit the bottom | 1889 // Because of where the visual viewport is located, this should hit the bottom |
| 1892 // right target (target 4). | 1890 // right target (target 4). |
| 1893 WebAXObject hitNode = | 1891 WebAXObject hitNode = |
| 1894 webDoc.AccessibilityObject().HitTest(WebPoint(154, 165)); | 1892 web_doc.AccessibilityObject().HitTest(WebPoint(154, 165)); |
| 1895 WebAXNameFrom nameFrom; | 1893 WebAXNameFrom name_from; |
| 1896 WebVector<WebAXObject> nameObjects; | 1894 WebVector<WebAXObject> name_objects; |
| 1897 EXPECT_EQ(std::string("Target4"), | 1895 EXPECT_EQ(std::string("Target4"), |
| 1898 hitNode.GetName(nameFrom, nameObjects).Utf8()); | 1896 hitNode.GetName(name_from, name_objects).Utf8()); |
| 1899 } | 1897 } |
| 1900 | 1898 |
| 1901 // Tests that the maximum scroll offset of the viewport can be fractional. | 1899 // Tests that the maximum scroll offset of the viewport can be fractional. |
| 1902 TEST_P(VisualViewportTest, TestCoordinateTransforms) { | 1900 TEST_P(VisualViewportTest, TestCoordinateTransforms) { |
| 1903 initializeWithAndroidSettings(); | 1901 InitializeWithAndroidSettings(); |
| 1904 webViewImpl()->Resize(IntSize(800, 600)); | 1902 WebViewImpl()->Resize(IntSize(800, 600)); |
| 1905 registerMockedHttpURLLoad("content-width-1000.html"); | 1903 RegisterMockedHttpURLLoad("content-width-1000.html"); |
| 1906 navigateTo(m_baseURL + "content-width-1000.html"); | 1904 NavigateTo(base_url_ + "content-width-1000.html"); |
| 1907 | 1905 |
| 1908 VisualViewport& visualViewport = | 1906 VisualViewport& visual_viewport = |
| 1909 webViewImpl()->GetPage()->GetVisualViewport(); | 1907 WebViewImpl()->GetPage()->GetVisualViewport(); |
| 1910 FrameView& frameView = *webViewImpl()->MainFrameImpl()->GetFrameView(); | 1908 FrameView& frame_view = *WebViewImpl()->MainFrameImpl()->GetFrameView(); |
| 1911 | 1909 |
| 1912 // At scale = 1 the transform should be a no-op. | 1910 // At scale = 1 the transform should be a no-op. |
| 1913 visualViewport.SetScale(1); | 1911 visual_viewport.SetScale(1); |
| 1914 EXPECT_FLOAT_POINT_EQ( | 1912 EXPECT_FLOAT_POINT_EQ( |
| 1915 FloatPoint(314, 273), | 1913 FloatPoint(314, 273), |
| 1916 visualViewport.ViewportToRootFrame(FloatPoint(314, 273))); | 1914 visual_viewport.ViewportToRootFrame(FloatPoint(314, 273))); |
| 1917 EXPECT_FLOAT_POINT_EQ( | 1915 EXPECT_FLOAT_POINT_EQ( |
| 1918 FloatPoint(314, 273), | 1916 FloatPoint(314, 273), |
| 1919 visualViewport.RootFrameToViewport(FloatPoint(314, 273))); | 1917 visual_viewport.RootFrameToViewport(FloatPoint(314, 273))); |
| 1920 | 1918 |
| 1921 // At scale = 2. | 1919 // At scale = 2. |
| 1922 visualViewport.SetScale(2); | 1920 visual_viewport.SetScale(2); |
| 1923 EXPECT_FLOAT_POINT_EQ(FloatPoint(55, 75), visualViewport.ViewportToRootFrame( | 1921 EXPECT_FLOAT_POINT_EQ(FloatPoint(55, 75), visual_viewport.ViewportToRootFrame( |
| 1924 FloatPoint(110, 150))); | 1922 FloatPoint(110, 150))); |
| 1925 EXPECT_FLOAT_POINT_EQ(FloatPoint(110, 150), | 1923 EXPECT_FLOAT_POINT_EQ( |
| 1926 visualViewport.RootFrameToViewport(FloatPoint(55, 75))); | 1924 FloatPoint(110, 150), |
| 1925 visual_viewport.RootFrameToViewport(FloatPoint(55, 75))); |
| 1927 | 1926 |
| 1928 // At scale = 2 and with the visual viewport offset. | 1927 // At scale = 2 and with the visual viewport offset. |
| 1929 visualViewport.SetLocation(FloatPoint(10, 12)); | 1928 visual_viewport.SetLocation(FloatPoint(10, 12)); |
| 1930 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 62), visualViewport.ViewportToRootFrame( | 1929 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 62), visual_viewport.ViewportToRootFrame( |
| 1931 FloatPoint(80, 100))); | 1930 FloatPoint(80, 100))); |
| 1932 EXPECT_FLOAT_POINT_EQ(FloatPoint(80, 100), | 1931 EXPECT_FLOAT_POINT_EQ( |
| 1933 visualViewport.RootFrameToViewport(FloatPoint(50, 62))); | 1932 FloatPoint(80, 100), |
| 1933 visual_viewport.RootFrameToViewport(FloatPoint(50, 62))); |
| 1934 | 1934 |
| 1935 // Test points that will cause non-integer values. | 1935 // Test points that will cause non-integer values. |
| 1936 EXPECT_FLOAT_POINT_EQ( | 1936 EXPECT_FLOAT_POINT_EQ( |
| 1937 FloatPoint(50.5, 62.4), | 1937 FloatPoint(50.5, 62.4), |
| 1938 visualViewport.ViewportToRootFrame(FloatPoint(81, 100.8))); | 1938 visual_viewport.ViewportToRootFrame(FloatPoint(81, 100.8))); |
| 1939 EXPECT_FLOAT_POINT_EQ( | 1939 EXPECT_FLOAT_POINT_EQ( |
| 1940 FloatPoint(81, 100.8), | 1940 FloatPoint(81, 100.8), |
| 1941 visualViewport.RootFrameToViewport(FloatPoint(50.5, 62.4))); | 1941 visual_viewport.RootFrameToViewport(FloatPoint(50.5, 62.4))); |
| 1942 | 1942 |
| 1943 // Scrolling the main frame should have no effect. | 1943 // Scrolling the main frame should have no effect. |
| 1944 frameView.LayoutViewportScrollableArea()->SetScrollOffset( | 1944 frame_view.LayoutViewportScrollableArea()->SetScrollOffset( |
| 1945 ScrollOffset(100, 120), kProgrammaticScroll); | 1945 ScrollOffset(100, 120), kProgrammaticScroll); |
| 1946 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 62), visualViewport.ViewportToRootFrame( | 1946 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 62), visual_viewport.ViewportToRootFrame( |
| 1947 FloatPoint(80, 100))); | 1947 FloatPoint(80, 100))); |
| 1948 EXPECT_FLOAT_POINT_EQ(FloatPoint(80, 100), | 1948 EXPECT_FLOAT_POINT_EQ( |
| 1949 visualViewport.RootFrameToViewport(FloatPoint(50, 62))); | 1949 FloatPoint(80, 100), |
| 1950 visual_viewport.RootFrameToViewport(FloatPoint(50, 62))); |
| 1950 } | 1951 } |
| 1951 | 1952 |
| 1952 // Tests that the window dimensions are available before a full layout occurs. | 1953 // Tests that the window dimensions are available before a full layout occurs. |
| 1953 // More specifically, it checks that the innerWidth and innerHeight window | 1954 // More specifically, it checks that the innerWidth and innerHeight window |
| 1954 // properties will trigger a layout which will cause an update to viewport | 1955 // properties will trigger a layout which will cause an update to viewport |
| 1955 // constraints and a refreshed initial scale. crbug.com/466718 | 1956 // constraints and a refreshed initial scale. crbug.com/466718 |
| 1956 TEST_P(VisualViewportTest, WindowDimensionsOnLoad) { | 1957 TEST_P(VisualViewportTest, WindowDimensionsOnLoad) { |
| 1957 initializeWithAndroidSettings(); | 1958 InitializeWithAndroidSettings(); |
| 1958 registerMockedHttpURLLoad("window_dimensions.html"); | 1959 RegisterMockedHttpURLLoad("window_dimensions.html"); |
| 1959 webViewImpl()->Resize(IntSize(800, 600)); | 1960 WebViewImpl()->Resize(IntSize(800, 600)); |
| 1960 navigateTo(m_baseURL + "window_dimensions.html"); | 1961 NavigateTo(base_url_ + "window_dimensions.html"); |
| 1961 | 1962 |
| 1962 Element* output = frame()->GetDocument()->getElementById("output"); | 1963 Element* output = GetFrame()->GetDocument()->getElementById("output"); |
| 1963 DCHECK(output); | 1964 DCHECK(output); |
| 1964 EXPECT_EQ(std::string("1600x1200"), | 1965 EXPECT_EQ(std::string("1600x1200"), |
| 1965 std::string(output->innerHTML().Ascii().data())); | 1966 std::string(output->innerHTML().Ascii().data())); |
| 1966 } | 1967 } |
| 1967 | 1968 |
| 1968 // Similar to above but make sure the initial scale is updated with the content | 1969 // Similar to above but make sure the initial scale is updated with the content |
| 1969 // width for a very wide page. That is, make that innerWidth/Height actually | 1970 // width for a very wide page. That is, make that innerWidth/Height actually |
| 1970 // trigger a layout of the content, and not just an update of the viepwort. | 1971 // trigger a layout of the content, and not just an update of the viepwort. |
| 1971 // crbug.com/466718 | 1972 // crbug.com/466718 |
| 1972 TEST_P(VisualViewportTest, WindowDimensionsOnLoadWideContent) { | 1973 TEST_P(VisualViewportTest, WindowDimensionsOnLoadWideContent) { |
| 1973 initializeWithAndroidSettings(); | 1974 InitializeWithAndroidSettings(); |
| 1974 registerMockedHttpURLLoad("window_dimensions_wide_div.html"); | 1975 RegisterMockedHttpURLLoad("window_dimensions_wide_div.html"); |
| 1975 webViewImpl()->Resize(IntSize(800, 600)); | 1976 WebViewImpl()->Resize(IntSize(800, 600)); |
| 1976 navigateTo(m_baseURL + "window_dimensions_wide_div.html"); | 1977 NavigateTo(base_url_ + "window_dimensions_wide_div.html"); |
| 1977 | 1978 |
| 1978 Element* output = frame()->GetDocument()->getElementById("output"); | 1979 Element* output = GetFrame()->GetDocument()->getElementById("output"); |
| 1979 DCHECK(output); | 1980 DCHECK(output); |
| 1980 EXPECT_EQ(std::string("2000x1500"), | 1981 EXPECT_EQ(std::string("2000x1500"), |
| 1981 std::string(output->innerHTML().Ascii().data())); | 1982 std::string(output->innerHTML().Ascii().data())); |
| 1982 } | 1983 } |
| 1983 | 1984 |
| 1984 TEST_P(VisualViewportTest, PinchZoomGestureScrollsVisualViewportOnly) { | 1985 TEST_P(VisualViewportTest, PinchZoomGestureScrollsVisualViewportOnly) { |
| 1985 initializeWithDesktopSettings(); | 1986 InitializeWithDesktopSettings(); |
| 1986 webViewImpl()->Resize(IntSize(100, 100)); | 1987 WebViewImpl()->Resize(IntSize(100, 100)); |
| 1987 | 1988 |
| 1988 registerMockedHttpURLLoad("200-by-800-viewport.html"); | 1989 RegisterMockedHttpURLLoad("200-by-800-viewport.html"); |
| 1989 navigateTo(m_baseURL + "200-by-800-viewport.html"); | 1990 NavigateTo(base_url_ + "200-by-800-viewport.html"); |
| 1990 | 1991 |
| 1991 WebGestureEvent pinchUpdate(WebInputEvent::kGesturePinchUpdate, | 1992 WebGestureEvent pinch_update(WebInputEvent::kGesturePinchUpdate, |
| 1992 WebInputEvent::kNoModifiers, | 1993 WebInputEvent::kNoModifiers, |
| 1993 WebInputEvent::kTimeStampForTesting); | 1994 WebInputEvent::kTimeStampForTesting); |
| 1994 pinchUpdate.source_device = kWebGestureDeviceTouchpad; | 1995 pinch_update.source_device = kWebGestureDeviceTouchpad; |
| 1995 pinchUpdate.x = 100; | 1996 pinch_update.x = 100; |
| 1996 pinchUpdate.y = 100; | 1997 pinch_update.y = 100; |
| 1997 pinchUpdate.data.pinch_update.scale = 2; | 1998 pinch_update.data.pinch_update.scale = 2; |
| 1998 pinchUpdate.data.pinch_update.zoom_disabled = false; | 1999 pinch_update.data.pinch_update.zoom_disabled = false; |
| 1999 | 2000 |
| 2000 webViewImpl()->HandleInputEvent(WebCoalescedInputEvent(pinchUpdate)); | 2001 WebViewImpl()->HandleInputEvent(WebCoalescedInputEvent(pinch_update)); |
| 2001 | 2002 |
| 2002 VisualViewport& visualViewport = | 2003 VisualViewport& visual_viewport = |
| 2003 webViewImpl()->GetPage()->GetVisualViewport(); | 2004 WebViewImpl()->GetPage()->GetVisualViewport(); |
| 2004 FrameView& frameView = *webViewImpl()->MainFrameImpl()->GetFrameView(); | 2005 FrameView& frame_view = *WebViewImpl()->MainFrameImpl()->GetFrameView(); |
| 2005 | 2006 |
| 2006 EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 50), visualViewport.GetScrollOffset()); | 2007 EXPECT_FLOAT_SIZE_EQ(FloatSize(50, 50), visual_viewport.GetScrollOffset()); |
| 2007 EXPECT_SIZE_EQ(ScrollOffset(0, 0), | 2008 EXPECT_SIZE_EQ(ScrollOffset(0, 0), |
| 2008 frameView.LayoutViewportScrollableArea()->GetScrollOffset()); | 2009 frame_view.LayoutViewportScrollableArea()->GetScrollOffset()); |
| 2009 } | 2010 } |
| 2010 | 2011 |
| 2011 TEST_P(VisualViewportTest, ResizeWithScrollAnchoring) { | 2012 TEST_P(VisualViewportTest, ResizeWithScrollAnchoring) { |
| 2012 bool wasScrollAnchoringEnabled = | 2013 bool wasScrollAnchoringEnabled = |
| 2013 RuntimeEnabledFeatures::scrollAnchoringEnabled(); | 2014 RuntimeEnabledFeatures::scrollAnchoringEnabled(); |
| 2014 RuntimeEnabledFeatures::setScrollAnchoringEnabled(true); | 2015 RuntimeEnabledFeatures::setScrollAnchoringEnabled(true); |
| 2015 | 2016 |
| 2016 initializeWithDesktopSettings(); | 2017 InitializeWithDesktopSettings(); |
| 2017 webViewImpl()->Resize(IntSize(800, 600)); | 2018 WebViewImpl()->Resize(IntSize(800, 600)); |
| 2018 | 2019 |
| 2019 registerMockedHttpURLLoad("icb-relative-content.html"); | 2020 RegisterMockedHttpURLLoad("icb-relative-content.html"); |
| 2020 navigateTo(m_baseURL + "icb-relative-content.html"); | 2021 NavigateTo(base_url_ + "icb-relative-content.html"); |
| 2021 | 2022 |
| 2022 FrameView& frameView = *webViewImpl()->MainFrameImpl()->GetFrameView(); | 2023 FrameView& frame_view = *WebViewImpl()->MainFrameImpl()->GetFrameView(); |
| 2023 frameView.LayoutViewportScrollableArea()->SetScrollOffset( | 2024 frame_view.LayoutViewportScrollableArea()->SetScrollOffset( |
| 2024 ScrollOffset(700, 500), kProgrammaticScroll); | 2025 ScrollOffset(700, 500), kProgrammaticScroll); |
| 2025 webViewImpl()->UpdateAllLifecyclePhases(); | 2026 WebViewImpl()->UpdateAllLifecyclePhases(); |
| 2026 | 2027 |
| 2027 webViewImpl()->Resize(IntSize(800, 300)); | 2028 WebViewImpl()->Resize(IntSize(800, 300)); |
| 2028 EXPECT_SIZE_EQ(ScrollOffset(700, 200), | 2029 EXPECT_SIZE_EQ(ScrollOffset(700, 200), |
| 2029 frameView.LayoutViewportScrollableArea()->GetScrollOffset()); | 2030 frame_view.LayoutViewportScrollableArea()->GetScrollOffset()); |
| 2030 | 2031 |
| 2031 RuntimeEnabledFeatures::setScrollAnchoringEnabled(wasScrollAnchoringEnabled); | 2032 RuntimeEnabledFeatures::setScrollAnchoringEnabled(wasScrollAnchoringEnabled); |
| 2032 } | 2033 } |
| 2033 | 2034 |
| 2034 // Ensure that resize anchoring as happens when browser controls hide/show | 2035 // Ensure that resize anchoring as happens when browser controls hide/show |
| 2035 // affects the scrollable area that's currently set as the root scroller. | 2036 // affects the scrollable area that's currently set as the root scroller. |
| 2036 TEST_P(VisualViewportTest, ResizeAnchoringWithRootScroller) { | 2037 TEST_P(VisualViewportTest, ResizeAnchoringWithRootScroller) { |
| 2037 bool wasRootScrollerEnabled = | 2038 bool wasRootScrollerEnabled = |
| 2038 RuntimeEnabledFeatures::setRootScrollerEnabled(); | 2039 RuntimeEnabledFeatures::setRootScrollerEnabled(); |
| 2039 RuntimeEnabledFeatures::setSetRootScrollerEnabled(true); | 2040 RuntimeEnabledFeatures::setSetRootScrollerEnabled(true); |
| 2040 | 2041 |
| 2041 initializeWithAndroidSettings(); | 2042 InitializeWithAndroidSettings(); |
| 2042 webViewImpl()->Resize(IntSize(800, 600)); | 2043 WebViewImpl()->Resize(IntSize(800, 600)); |
| 2043 | 2044 |
| 2044 registerMockedHttpURLLoad("root-scroller-div.html"); | 2045 RegisterMockedHttpURLLoad("root-scroller-div.html"); |
| 2045 navigateTo(m_baseURL + "root-scroller-div.html"); | 2046 NavigateTo(base_url_ + "root-scroller-div.html"); |
| 2046 | 2047 |
| 2047 FrameView& frameView = *webViewImpl()->MainFrameImpl()->GetFrameView(); | 2048 FrameView& frame_view = *WebViewImpl()->MainFrameImpl()->GetFrameView(); |
| 2048 | 2049 |
| 2049 Element* scroller = frame()->GetDocument()->getElementById("rootScroller"); | 2050 Element* scroller = GetFrame()->GetDocument()->getElementById("rootScroller"); |
| 2050 NonThrowableExceptionState nonThrow; | 2051 NonThrowableExceptionState non_throw; |
| 2051 frame()->GetDocument()->setRootScroller(scroller, nonThrow); | 2052 GetFrame()->GetDocument()->setRootScroller(scroller, non_throw); |
| 2052 | 2053 |
| 2053 webViewImpl()->SetPageScaleFactor(3.f); | 2054 WebViewImpl()->SetPageScaleFactor(3.f); |
| 2054 frameView.GetScrollableArea()->SetScrollOffset(ScrollOffset(0, 400), | 2055 frame_view.GetScrollableArea()->SetScrollOffset(ScrollOffset(0, 400), |
| 2055 kProgrammaticScroll); | 2056 kProgrammaticScroll); |
| 2056 | 2057 |
| 2057 VisualViewport& visualViewport = | 2058 VisualViewport& visual_viewport = |
| 2058 webViewImpl()->GetPage()->GetVisualViewport(); | 2059 WebViewImpl()->GetPage()->GetVisualViewport(); |
| 2059 visualViewport.SetScrollOffset(ScrollOffset(0, 400), kProgrammaticScroll); | 2060 visual_viewport.SetScrollOffset(ScrollOffset(0, 400), kProgrammaticScroll); |
| 2060 | 2061 |
| 2061 webViewImpl()->Resize(IntSize(800, 500)); | 2062 WebViewImpl()->Resize(IntSize(800, 500)); |
| 2062 | 2063 |
| 2063 EXPECT_SIZE_EQ(ScrollOffset(), | 2064 EXPECT_SIZE_EQ(ScrollOffset(), |
| 2064 frameView.LayoutViewportScrollableArea()->GetScrollOffset()); | 2065 frame_view.LayoutViewportScrollableArea()->GetScrollOffset()); |
| 2065 | 2066 |
| 2066 RuntimeEnabledFeatures::setSetRootScrollerEnabled(wasRootScrollerEnabled); | 2067 RuntimeEnabledFeatures::setSetRootScrollerEnabled(wasRootScrollerEnabled); |
| 2067 } | 2068 } |
| 2068 | 2069 |
| 2069 // Ensure that resize anchoring as happens when the device is rotated affects | 2070 // Ensure that resize anchoring as happens when the device is rotated affects |
| 2070 // the scrollable area that's currently set as the root scroller. | 2071 // the scrollable area that's currently set as the root scroller. |
| 2071 TEST_P(VisualViewportTest, RotationAnchoringWithRootScroller) { | 2072 TEST_P(VisualViewportTest, RotationAnchoringWithRootScroller) { |
| 2072 bool wasRootScrollerEnabled = | 2073 bool wasRootScrollerEnabled = |
| 2073 RuntimeEnabledFeatures::setRootScrollerEnabled(); | 2074 RuntimeEnabledFeatures::setRootScrollerEnabled(); |
| 2074 RuntimeEnabledFeatures::setSetRootScrollerEnabled(true); | 2075 RuntimeEnabledFeatures::setSetRootScrollerEnabled(true); |
| 2075 | 2076 |
| 2076 initializeWithAndroidSettings(); | 2077 InitializeWithAndroidSettings(); |
| 2077 webViewImpl()->Resize(IntSize(800, 600)); | 2078 WebViewImpl()->Resize(IntSize(800, 600)); |
| 2078 | 2079 |
| 2079 registerMockedHttpURLLoad("root-scroller-div.html"); | 2080 RegisterMockedHttpURLLoad("root-scroller-div.html"); |
| 2080 navigateTo(m_baseURL + "root-scroller-div.html"); | 2081 NavigateTo(base_url_ + "root-scroller-div.html"); |
| 2081 | 2082 |
| 2082 FrameView& frameView = *webViewImpl()->MainFrameImpl()->GetFrameView(); | 2083 FrameView& frame_view = *WebViewImpl()->MainFrameImpl()->GetFrameView(); |
| 2083 | 2084 |
| 2084 Element* scroller = frame()->GetDocument()->getElementById("rootScroller"); | 2085 Element* scroller = GetFrame()->GetDocument()->getElementById("rootScroller"); |
| 2085 NonThrowableExceptionState nonThrow; | 2086 NonThrowableExceptionState non_throw; |
| 2086 frame()->GetDocument()->setRootScroller(scroller, nonThrow); | 2087 GetFrame()->GetDocument()->setRootScroller(scroller, non_throw); |
| 2087 webViewImpl()->UpdateAllLifecyclePhases(); | 2088 WebViewImpl()->UpdateAllLifecyclePhases(); |
| 2088 | 2089 |
| 2089 scroller->setScrollTop(800); | 2090 scroller->setScrollTop(800); |
| 2090 | 2091 |
| 2091 webViewImpl()->Resize(IntSize(600, 800)); | 2092 WebViewImpl()->Resize(IntSize(600, 800)); |
| 2092 | 2093 |
| 2093 EXPECT_SIZE_EQ(ScrollOffset(), | 2094 EXPECT_SIZE_EQ(ScrollOffset(), |
| 2094 frameView.LayoutViewportScrollableArea()->GetScrollOffset()); | 2095 frame_view.LayoutViewportScrollableArea()->GetScrollOffset()); |
| 2095 EXPECT_EQ(600, scroller->scrollTop()); | 2096 EXPECT_EQ(600, scroller->scrollTop()); |
| 2096 | 2097 |
| 2097 RuntimeEnabledFeatures::setSetRootScrollerEnabled(wasRootScrollerEnabled); | 2098 RuntimeEnabledFeatures::setSetRootScrollerEnabled(wasRootScrollerEnabled); |
| 2098 } | 2099 } |
| 2099 | 2100 |
| 2100 static void configureAndroidCompositing(WebSettings* settings) { | 2101 static void configureAndroidCompositing(WebSettings* settings) { |
| 2101 settings->SetAcceleratedCompositingEnabled(true); | 2102 settings->SetAcceleratedCompositingEnabled(true); |
| 2102 settings->SetPreferCompositingToLCDTextEnabled(true); | 2103 settings->SetPreferCompositingToLCDTextEnabled(true); |
| 2103 settings->SetViewportMetaEnabled(true); | 2104 settings->SetViewportMetaEnabled(true); |
| 2104 settings->SetViewportEnabled(true); | 2105 settings->SetViewportEnabled(true); |
| 2105 settings->SetMainFrameResizesAreOrientationChanges(true); | 2106 settings->SetMainFrameResizesAreOrientationChanges(true); |
| 2106 settings->SetShrinksViewportContentToFit(true); | 2107 settings->SetShrinksViewportContentToFit(true); |
| 2107 } | 2108 } |
| 2108 | 2109 |
| 2109 // Make sure a composited background-attachment:fixed background gets resized | 2110 // Make sure a composited background-attachment:fixed background gets resized |
| 2110 // when using inert (non-layout affecting) browser controls. | 2111 // when using inert (non-layout affecting) browser controls. |
| 2111 TEST_P(VisualViewportTest, ResizeCompositedAndFixedBackground) { | 2112 TEST_P(VisualViewportTest, ResizeCompositedAndFixedBackground) { |
| 2112 bool originalInertTopControls = | 2113 bool originalInertTopControls = |
| 2113 RuntimeEnabledFeatures::inertTopControlsEnabled(); | 2114 RuntimeEnabledFeatures::inertTopControlsEnabled(); |
| 2114 RuntimeEnabledFeatures::setInertTopControlsEnabled(true); | 2115 RuntimeEnabledFeatures::setInertTopControlsEnabled(true); |
| 2115 | 2116 |
| 2116 std::unique_ptr<FrameTestHelpers::TestWebViewClient> | 2117 std::unique_ptr<FrameTestHelpers::TestWebViewClient> |
| 2117 fakeCompositingWebViewClient = | 2118 fake_compositing_web_view_client = |
| 2118 WTF::MakeUnique<FrameTestHelpers::TestWebViewClient>(); | 2119 WTF::MakeUnique<FrameTestHelpers::TestWebViewClient>(); |
| 2119 FrameTestHelpers::WebViewHelper webViewHelper; | 2120 FrameTestHelpers::WebViewHelper web_view_helper; |
| 2120 WebViewBase* webViewImpl = webViewHelper.Initialize( | 2121 WebViewBase* web_view_impl = web_view_helper.Initialize( |
| 2121 true, nullptr, fakeCompositingWebViewClient.get(), nullptr, | 2122 true, nullptr, fake_compositing_web_view_client.get(), nullptr, |
| 2122 &configureAndroidCompositing); | 2123 &configureAndroidCompositing); |
| 2123 | 2124 |
| 2124 int pageWidth = 640; | 2125 int page_width = 640; |
| 2125 int pageHeight = 480; | 2126 int page_height = 480; |
| 2126 float browserControlsHeight = 50.0f; | 2127 float browser_controls_height = 50.0f; |
| 2127 int smallestHeight = pageHeight - browserControlsHeight; | 2128 int smallest_height = page_height - browser_controls_height; |
| 2128 | 2129 |
| 2129 webViewImpl->ResizeWithBrowserControls(WebSize(pageWidth, pageHeight), | 2130 web_view_impl->ResizeWithBrowserControls(WebSize(page_width, page_height), |
| 2130 browserControlsHeight, false); | 2131 browser_controls_height, false); |
| 2131 | 2132 |
| 2132 registerMockedHttpURLLoad("http://example.com/foo.png", "white-1x1.png"); | 2133 RegisterMockedHttpURLLoad("http://example.com/foo.png", "white-1x1.png"); |
| 2133 WebURL baseURL = URLTestHelpers::ToKURL("http://example.com/"); | 2134 WebURL base_url = URLTestHelpers::ToKURL("http://example.com/"); |
| 2134 FrameTestHelpers::LoadHTMLString(webViewImpl->MainFrame(), | 2135 FrameTestHelpers::LoadHTMLString(web_view_impl->MainFrame(), |
| 2135 "<!DOCTYPE html>" | 2136 "<!DOCTYPE html>" |
| 2136 "<style>" | 2137 "<style>" |
| 2137 " body {" | 2138 " body {" |
| 2138 " background: url('foo.png');" | 2139 " background: url('foo.png');" |
| 2139 " background-attachment: fixed;" | 2140 " background-attachment: fixed;" |
| 2140 " background-size: cover;" | 2141 " background-size: cover;" |
| 2141 " background-repeat: no-repeat;" | 2142 " background-repeat: no-repeat;" |
| 2142 " }" | 2143 " }" |
| 2143 " div { height:1000px; width: 200px; }" | 2144 " div { height:1000px; width: 200px; }" |
| 2144 "</style>" | 2145 "</style>" |
| 2145 "<div></div>", | 2146 "<div></div>", |
| 2146 baseURL); | 2147 base_url); |
| 2147 webViewImpl->UpdateAllLifecyclePhases(); | 2148 web_view_impl->UpdateAllLifecyclePhases(); |
| 2148 | 2149 |
| 2149 Document* document = | 2150 Document* document = |
| 2150 ToLocalFrame(webViewImpl->GetPage()->MainFrame())->GetDocument(); | 2151 ToLocalFrame(web_view_impl->GetPage()->MainFrame())->GetDocument(); |
| 2151 PaintLayerCompositor* compositor = document->GetLayoutView()->Compositor(); | 2152 PaintLayerCompositor* compositor = document->GetLayoutView()->Compositor(); |
| 2152 | 2153 |
| 2153 ASSERT_TRUE(compositor->NeedsFixedRootBackgroundLayer( | 2154 ASSERT_TRUE(compositor->NeedsFixedRootBackgroundLayer( |
| 2154 document->GetLayoutView()->Layer())); | 2155 document->GetLayoutView()->Layer())); |
| 2155 ASSERT_TRUE(compositor->FixedRootBackgroundLayer()); | 2156 ASSERT_TRUE(compositor->FixedRootBackgroundLayer()); |
| 2156 | 2157 |
| 2157 ASSERT_EQ(pageWidth, compositor->FixedRootBackgroundLayer()->Size().Width()); | 2158 ASSERT_EQ(page_width, compositor->FixedRootBackgroundLayer()->Size().Width()); |
| 2158 ASSERT_EQ(pageHeight, | 2159 ASSERT_EQ(page_height, |
| 2159 compositor->FixedRootBackgroundLayer()->Size().Height()); | 2160 compositor->FixedRootBackgroundLayer()->Size().Height()); |
| 2160 ASSERT_EQ(pageWidth, document->View()->GetLayoutSize().Width()); | 2161 ASSERT_EQ(page_width, document->View()->GetLayoutSize().Width()); |
| 2161 ASSERT_EQ(smallestHeight, document->View()->GetLayoutSize().Height()); | 2162 ASSERT_EQ(smallest_height, document->View()->GetLayoutSize().Height()); |
| 2162 | 2163 |
| 2163 webViewImpl->ResizeWithBrowserControls(WebSize(pageWidth, smallestHeight), | 2164 web_view_impl->ResizeWithBrowserControls(WebSize(page_width, smallest_height), |
| 2164 browserControlsHeight, true); | 2165 browser_controls_height, true); |
| 2165 | 2166 |
| 2166 // The layout size should not have changed. | 2167 // The layout size should not have changed. |
| 2167 ASSERT_EQ(pageWidth, document->View()->GetLayoutSize().Width()); | 2168 ASSERT_EQ(page_width, document->View()->GetLayoutSize().Width()); |
| 2168 ASSERT_EQ(smallestHeight, document->View()->GetLayoutSize().Height()); | 2169 ASSERT_EQ(smallest_height, document->View()->GetLayoutSize().Height()); |
| 2169 | 2170 |
| 2170 // The background layer's size should have changed though. | 2171 // The background layer's size should have changed though. |
| 2171 EXPECT_EQ(pageWidth, compositor->FixedRootBackgroundLayer()->Size().Width()); | 2172 EXPECT_EQ(page_width, compositor->FixedRootBackgroundLayer()->Size().Width()); |
| 2172 EXPECT_EQ(smallestHeight, | 2173 EXPECT_EQ(smallest_height, |
| 2173 compositor->FixedRootBackgroundLayer()->Size().Height()); | 2174 compositor->FixedRootBackgroundLayer()->Size().Height()); |
| 2174 | 2175 |
| 2175 webViewImpl->ResizeWithBrowserControls(WebSize(pageWidth, pageHeight), | 2176 web_view_impl->ResizeWithBrowserControls(WebSize(page_width, page_height), |
| 2176 browserControlsHeight, true); | 2177 browser_controls_height, true); |
| 2177 | 2178 |
| 2178 // The background layer's size should change again. | 2179 // The background layer's size should change again. |
| 2179 EXPECT_EQ(pageWidth, compositor->FixedRootBackgroundLayer()->Size().Width()); | 2180 EXPECT_EQ(page_width, compositor->FixedRootBackgroundLayer()->Size().Width()); |
| 2180 EXPECT_EQ(pageHeight, | 2181 EXPECT_EQ(page_height, |
| 2181 compositor->FixedRootBackgroundLayer()->Size().Height()); | 2182 compositor->FixedRootBackgroundLayer()->Size().Height()); |
| 2182 | 2183 |
| 2183 RuntimeEnabledFeatures::setInertTopControlsEnabled(originalInertTopControls); | 2184 RuntimeEnabledFeatures::setInertTopControlsEnabled(originalInertTopControls); |
| 2184 } | 2185 } |
| 2185 | 2186 |
| 2186 static void configureAndroidNonCompositing(WebSettings* settings) { | 2187 static void configureAndroidNonCompositing(WebSettings* settings) { |
| 2187 settings->SetAcceleratedCompositingEnabled(true); | 2188 settings->SetAcceleratedCompositingEnabled(true); |
| 2188 settings->SetPreferCompositingToLCDTextEnabled(false); | 2189 settings->SetPreferCompositingToLCDTextEnabled(false); |
| 2189 settings->SetViewportMetaEnabled(true); | 2190 settings->SetViewportMetaEnabled(true); |
| 2190 settings->SetViewportEnabled(true); | 2191 settings->SetViewportEnabled(true); |
| 2191 settings->SetMainFrameResizesAreOrientationChanges(true); | 2192 settings->SetMainFrameResizesAreOrientationChanges(true); |
| 2192 settings->SetShrinksViewportContentToFit(true); | 2193 settings->SetShrinksViewportContentToFit(true); |
| 2193 } | 2194 } |
| 2194 | 2195 |
| 2195 // Make sure a non-composited background-attachment:fixed background gets | 2196 // Make sure a non-composited background-attachment:fixed background gets |
| 2196 // resized when using inert (non-layout affecting) browser controls. | 2197 // resized when using inert (non-layout affecting) browser controls. |
| 2197 TEST_P(VisualViewportTest, ResizeNonCompositedAndFixedBackground) { | 2198 TEST_P(VisualViewportTest, ResizeNonCompositedAndFixedBackground) { |
| 2198 bool originalInertTopControls = | 2199 bool originalInertTopControls = |
| 2199 RuntimeEnabledFeatures::inertTopControlsEnabled(); | 2200 RuntimeEnabledFeatures::inertTopControlsEnabled(); |
| 2200 RuntimeEnabledFeatures::setInertTopControlsEnabled(true); | 2201 RuntimeEnabledFeatures::setInertTopControlsEnabled(true); |
| 2201 | 2202 |
| 2202 FrameTestHelpers::WebViewHelper webViewHelper; | 2203 FrameTestHelpers::WebViewHelper web_view_helper; |
| 2203 WebViewBase* webViewImpl = webViewHelper.Initialize( | 2204 WebViewBase* web_view_impl = web_view_helper.Initialize( |
| 2204 true, nullptr, nullptr, nullptr, &configureAndroidNonCompositing); | 2205 true, nullptr, nullptr, nullptr, &configureAndroidNonCompositing); |
| 2205 | 2206 |
| 2206 int pageWidth = 640; | 2207 int page_width = 640; |
| 2207 int pageHeight = 480; | 2208 int page_height = 480; |
| 2208 float browserControlsHeight = 50.0f; | 2209 float browser_controls_height = 50.0f; |
| 2209 int smallestHeight = pageHeight - browserControlsHeight; | 2210 int smallest_height = page_height - browser_controls_height; |
| 2210 | 2211 |
| 2211 webViewImpl->ResizeWithBrowserControls(WebSize(pageWidth, pageHeight), | 2212 web_view_impl->ResizeWithBrowserControls(WebSize(page_width, page_height), |
| 2212 browserControlsHeight, false); | 2213 browser_controls_height, false); |
| 2213 | 2214 |
| 2214 registerMockedHttpURLLoad("http://example.com/foo.png", "white-1x1.png"); | 2215 RegisterMockedHttpURLLoad("http://example.com/foo.png", "white-1x1.png"); |
| 2215 WebURL baseURL = URLTestHelpers::ToKURL("http://example.com/"); | 2216 WebURL base_url = URLTestHelpers::ToKURL("http://example.com/"); |
| 2216 FrameTestHelpers::LoadHTMLString(webViewImpl->MainFrame(), | 2217 FrameTestHelpers::LoadHTMLString(web_view_impl->MainFrame(), |
| 2217 "<!DOCTYPE html>" | 2218 "<!DOCTYPE html>" |
| 2218 "<style>" | 2219 "<style>" |
| 2219 " body {" | 2220 " body {" |
| 2220 " margin: 0px;" | 2221 " margin: 0px;" |
| 2221 " background: url('foo.png');" | 2222 " background: url('foo.png');" |
| 2222 " background-attachment: fixed;" | 2223 " background-attachment: fixed;" |
| 2223 " background-size: cover;" | 2224 " background-size: cover;" |
| 2224 " background-repeat: no-repeat;" | 2225 " background-repeat: no-repeat;" |
| 2225 " }" | 2226 " }" |
| 2226 " div { height:1000px; width: 200px; }" | 2227 " div { height:1000px; width: 200px; }" |
| 2227 "</style>" | 2228 "</style>" |
| 2228 "<div></div>", | 2229 "<div></div>", |
| 2229 baseURL); | 2230 base_url); |
| 2230 webViewImpl->UpdateAllLifecyclePhases(); | 2231 web_view_impl->UpdateAllLifecyclePhases(); |
| 2231 | 2232 |
| 2232 Document* document = | 2233 Document* document = |
| 2233 ToLocalFrame(webViewImpl->GetPage()->MainFrame())->GetDocument(); | 2234 ToLocalFrame(web_view_impl->GetPage()->MainFrame())->GetDocument(); |
| 2234 PaintLayerCompositor* compositor = document->GetLayoutView()->Compositor(); | 2235 PaintLayerCompositor* compositor = document->GetLayoutView()->Compositor(); |
| 2235 | 2236 |
| 2236 ASSERT_FALSE(compositor->NeedsFixedRootBackgroundLayer( | 2237 ASSERT_FALSE(compositor->NeedsFixedRootBackgroundLayer( |
| 2237 document->GetLayoutView()->Layer())); | 2238 document->GetLayoutView()->Layer())); |
| 2238 ASSERT_FALSE(compositor->FixedRootBackgroundLayer()); | 2239 ASSERT_FALSE(compositor->FixedRootBackgroundLayer()); |
| 2239 | 2240 |
| 2240 document->View()->SetTracksPaintInvalidations(true); | 2241 document->View()->SetTracksPaintInvalidations(true); |
| 2241 webViewImpl->ResizeWithBrowserControls(WebSize(pageWidth, smallestHeight), | 2242 web_view_impl->ResizeWithBrowserControls(WebSize(page_width, smallest_height), |
| 2242 browserControlsHeight, true); | 2243 browser_controls_height, true); |
| 2243 | 2244 |
| 2244 // The layout size should not have changed. | 2245 // The layout size should not have changed. |
| 2245 ASSERT_EQ(pageWidth, document->View()->GetLayoutSize().Width()); | 2246 ASSERT_EQ(page_width, document->View()->GetLayoutSize().Width()); |
| 2246 ASSERT_EQ(smallestHeight, document->View()->GetLayoutSize().Height()); | 2247 ASSERT_EQ(smallest_height, document->View()->GetLayoutSize().Height()); |
| 2247 | 2248 |
| 2248 const RasterInvalidationTracking* invalidationTracking = | 2249 const RasterInvalidationTracking* invalidation_tracking = |
| 2249 document->GetLayoutView() | 2250 document->GetLayoutView() |
| 2250 ->Layer() | 2251 ->Layer() |
| 2251 ->GraphicsLayerBacking(document->GetLayoutView()) | 2252 ->GraphicsLayerBacking(document->GetLayoutView()) |
| 2252 ->GetRasterInvalidationTracking(); | 2253 ->GetRasterInvalidationTracking(); |
| 2253 // If no invalidations occured, this will be a nullptr. | 2254 // If no invalidations occured, this will be a nullptr. |
| 2254 ASSERT_TRUE(invalidationTracking); | 2255 ASSERT_TRUE(invalidation_tracking); |
| 2255 | 2256 |
| 2256 const auto* rasterInvalidations = | 2257 const auto* raster_invalidations = |
| 2257 &invalidationTracking->tracked_raster_invalidations; | 2258 &invalidation_tracking->tracked_raster_invalidations; |
| 2258 | 2259 |
| 2259 bool rootLayerScrolling = GetParam(); | 2260 bool root_layer_scrolling = GetParam(); |
| 2260 | 2261 |
| 2261 // Without root-layer-scrolling, the LayoutView is the size of the document | 2262 // Without root-layer-scrolling, the LayoutView is the size of the document |
| 2262 // content so invalidating it for background-attachment: fixed | 2263 // content so invalidating it for background-attachment: fixed |
| 2263 // overinvalidates as we should only need to invalidate the viewport size. | 2264 // overinvalidates as we should only need to invalidate the viewport size. |
| 2264 // With root-layer-scrolling, we should invalidate the entire viewport height. | 2265 // With root-layer-scrolling, we should invalidate the entire viewport height. |
| 2265 int expectedHeight = rootLayerScrolling ? pageHeight : 1000; | 2266 int expectedHeight = root_layer_scrolling ? page_height : 1000; |
| 2266 | 2267 |
| 2267 // The entire viewport should have been invalidated. | 2268 // The entire viewport should have been invalidated. |
| 2268 EXPECT_EQ(1u, rasterInvalidations->size()); | 2269 EXPECT_EQ(1u, raster_invalidations->size()); |
| 2269 EXPECT_EQ(IntRect(0, 0, 640, expectedHeight), (*rasterInvalidations)[0].rect); | 2270 EXPECT_EQ(IntRect(0, 0, 640, expectedHeight), |
| 2271 (*raster_invalidations)[0].rect); |
| 2270 document->View()->SetTracksPaintInvalidations(false); | 2272 document->View()->SetTracksPaintInvalidations(false); |
| 2271 | 2273 |
| 2272 invalidationTracking = document->GetLayoutView() | 2274 invalidation_tracking = document->GetLayoutView() |
| 2273 ->Layer() | 2275 ->Layer() |
| 2274 ->GraphicsLayerBacking(document->GetLayoutView()) | 2276 ->GraphicsLayerBacking(document->GetLayoutView()) |
| 2275 ->GetRasterInvalidationTracking(); | 2277 ->GetRasterInvalidationTracking(); |
| 2276 ASSERT_FALSE(invalidationTracking); | 2278 ASSERT_FALSE(invalidation_tracking); |
| 2277 | 2279 |
| 2278 document->View()->SetTracksPaintInvalidations(true); | 2280 document->View()->SetTracksPaintInvalidations(true); |
| 2279 webViewImpl->ResizeWithBrowserControls(WebSize(pageWidth, pageHeight), | 2281 web_view_impl->ResizeWithBrowserControls(WebSize(page_width, page_height), |
| 2280 browserControlsHeight, true); | 2282 browser_controls_height, true); |
| 2281 | 2283 |
| 2282 invalidationTracking = document->GetLayoutView() | 2284 invalidation_tracking = document->GetLayoutView() |
| 2283 ->Layer() | 2285 ->Layer() |
| 2284 ->GraphicsLayerBacking(document->GetLayoutView()) | 2286 ->GraphicsLayerBacking(document->GetLayoutView()) |
| 2285 ->GetRasterInvalidationTracking(); | 2287 ->GetRasterInvalidationTracking(); |
| 2286 ASSERT_TRUE(invalidationTracking); | 2288 ASSERT_TRUE(invalidation_tracking); |
| 2287 rasterInvalidations = &invalidationTracking->tracked_raster_invalidations; | 2289 raster_invalidations = &invalidation_tracking->tracked_raster_invalidations; |
| 2288 | 2290 |
| 2289 // Once again, the entire page should have been invalidated. | 2291 // Once again, the entire page should have been invalidated. |
| 2290 expectedHeight = rootLayerScrolling ? 480 : 1000; | 2292 expectedHeight = root_layer_scrolling ? 480 : 1000; |
| 2291 EXPECT_EQ(1u, rasterInvalidations->size()); | 2293 EXPECT_EQ(1u, raster_invalidations->size()); |
| 2292 EXPECT_EQ(IntRect(0, 0, 640, expectedHeight), (*rasterInvalidations)[0].rect); | 2294 EXPECT_EQ(IntRect(0, 0, 640, expectedHeight), |
| 2295 (*raster_invalidations)[0].rect); |
| 2293 | 2296 |
| 2294 document->View()->SetTracksPaintInvalidations(false); | 2297 document->View()->SetTracksPaintInvalidations(false); |
| 2295 RuntimeEnabledFeatures::setInertTopControlsEnabled(originalInertTopControls); | 2298 RuntimeEnabledFeatures::setInertTopControlsEnabled(originalInertTopControls); |
| 2296 } | 2299 } |
| 2297 | 2300 |
| 2298 // Make sure a browser control resize with background-attachment:not-fixed | 2301 // Make sure a browser control resize with background-attachment:not-fixed |
| 2299 // background doesn't cause invalidation or layout. | 2302 // background doesn't cause invalidation or layout. |
| 2300 TEST_P(VisualViewportTest, ResizeNonFixedBackgroundNoLayoutOrInvalidation) { | 2303 TEST_P(VisualViewportTest, ResizeNonFixedBackgroundNoLayoutOrInvalidation) { |
| 2301 bool originalInertTopControls = | 2304 bool originalInertTopControls = |
| 2302 RuntimeEnabledFeatures::inertTopControlsEnabled(); | 2305 RuntimeEnabledFeatures::inertTopControlsEnabled(); |
| 2303 RuntimeEnabledFeatures::setInertTopControlsEnabled(true); | 2306 RuntimeEnabledFeatures::setInertTopControlsEnabled(true); |
| 2304 | 2307 |
| 2305 std::unique_ptr<FrameTestHelpers::TestWebViewClient> | 2308 std::unique_ptr<FrameTestHelpers::TestWebViewClient> |
| 2306 fakeCompositingWebViewClient = | 2309 fake_compositing_web_view_client = |
| 2307 WTF::MakeUnique<FrameTestHelpers::TestWebViewClient>(); | 2310 WTF::MakeUnique<FrameTestHelpers::TestWebViewClient>(); |
| 2308 FrameTestHelpers::WebViewHelper webViewHelper; | 2311 FrameTestHelpers::WebViewHelper web_view_helper; |
| 2309 WebViewBase* webViewImpl = webViewHelper.Initialize( | 2312 WebViewBase* web_view_impl = web_view_helper.Initialize( |
| 2310 true, nullptr, fakeCompositingWebViewClient.get(), nullptr, | 2313 true, nullptr, fake_compositing_web_view_client.get(), nullptr, |
| 2311 &configureAndroidCompositing); | 2314 &configureAndroidCompositing); |
| 2312 | 2315 |
| 2313 int pageWidth = 640; | 2316 int page_width = 640; |
| 2314 int pageHeight = 480; | 2317 int page_height = 480; |
| 2315 float browserControlsHeight = 50.0f; | 2318 float browser_controls_height = 50.0f; |
| 2316 int smallestHeight = pageHeight - browserControlsHeight; | 2319 int smallest_height = page_height - browser_controls_height; |
| 2317 | 2320 |
| 2318 webViewImpl->ResizeWithBrowserControls(WebSize(pageWidth, pageHeight), | 2321 web_view_impl->ResizeWithBrowserControls(WebSize(page_width, page_height), |
| 2319 browserControlsHeight, false); | 2322 browser_controls_height, false); |
| 2320 | 2323 |
| 2321 registerMockedHttpURLLoad("http://example.com/foo.png", "white-1x1.png"); | 2324 RegisterMockedHttpURLLoad("http://example.com/foo.png", "white-1x1.png"); |
| 2322 WebURL baseURL = URLTestHelpers::ToKURL("http://example.com/"); | 2325 WebURL base_url = URLTestHelpers::ToKURL("http://example.com/"); |
| 2323 // This time the background is the default attachment. | 2326 // This time the background is the default attachment. |
| 2324 FrameTestHelpers::LoadHTMLString(webViewImpl->MainFrame(), | 2327 FrameTestHelpers::LoadHTMLString(web_view_impl->MainFrame(), |
| 2325 "<!DOCTYPE html>" | 2328 "<!DOCTYPE html>" |
| 2326 "<style>" | 2329 "<style>" |
| 2327 " body {" | 2330 " body {" |
| 2328 " margin: 0px;" | 2331 " margin: 0px;" |
| 2329 " background: url('foo.png');" | 2332 " background: url('foo.png');" |
| 2330 " background-size: cover;" | 2333 " background-size: cover;" |
| 2331 " background-repeat: no-repeat;" | 2334 " background-repeat: no-repeat;" |
| 2332 " }" | 2335 " }" |
| 2333 " div { height:1000px; width: 200px; }" | 2336 " div { height:1000px; width: 200px; }" |
| 2334 "</style>" | 2337 "</style>" |
| 2335 "<div></div>", | 2338 "<div></div>", |
| 2336 baseURL); | 2339 base_url); |
| 2337 webViewImpl->UpdateAllLifecyclePhases(); | 2340 web_view_impl->UpdateAllLifecyclePhases(); |
| 2338 | 2341 |
| 2339 Document* document = | 2342 Document* document = |
| 2340 ToLocalFrame(webViewImpl->GetPage()->MainFrame())->GetDocument(); | 2343 ToLocalFrame(web_view_impl->GetPage()->MainFrame())->GetDocument(); |
| 2341 | 2344 |
| 2342 // A resize will do a layout synchronously so manually check that we don't | 2345 // A resize will do a layout synchronously so manually check that we don't |
| 2343 // setNeedsLayout from viewportSizeChanged. | 2346 // setNeedsLayout from viewportSizeChanged. |
| 2344 document->View()->ViewportSizeChanged(false, true); | 2347 document->View()->ViewportSizeChanged(false, true); |
| 2345 unsigned needsLayoutObjects = 0; | 2348 unsigned needs_layout_objects = 0; |
| 2346 unsigned totalObjects = 0; | 2349 unsigned total_objects = 0; |
| 2347 bool isSubtree = false; | 2350 bool is_subtree = false; |
| 2348 EXPECT_FALSE(document->View()->NeedsLayout()); | 2351 EXPECT_FALSE(document->View()->NeedsLayout()); |
| 2349 document->View()->CountObjectsNeedingLayout(needsLayoutObjects, totalObjects, | 2352 document->View()->CountObjectsNeedingLayout(needs_layout_objects, |
| 2350 isSubtree); | 2353 total_objects, is_subtree); |
| 2351 EXPECT_EQ(0u, needsLayoutObjects); | 2354 EXPECT_EQ(0u, needs_layout_objects); |
| 2352 | 2355 |
| 2353 webViewImpl->UpdateAllLifecyclePhases(); | 2356 web_view_impl->UpdateAllLifecyclePhases(); |
| 2354 | 2357 |
| 2355 // Do a real resize to check for invalidations. | 2358 // Do a real resize to check for invalidations. |
| 2356 document->View()->SetTracksPaintInvalidations(true); | 2359 document->View()->SetTracksPaintInvalidations(true); |
| 2357 webViewImpl->ResizeWithBrowserControls(WebSize(pageWidth, smallestHeight), | 2360 web_view_impl->ResizeWithBrowserControls(WebSize(page_width, smallest_height), |
| 2358 browserControlsHeight, true); | 2361 browser_controls_height, true); |
| 2359 | 2362 |
| 2360 // The layout size should not have changed. | 2363 // The layout size should not have changed. |
| 2361 ASSERT_EQ(pageWidth, document->View()->GetLayoutSize().Width()); | 2364 ASSERT_EQ(page_width, document->View()->GetLayoutSize().Width()); |
| 2362 ASSERT_EQ(smallestHeight, document->View()->GetLayoutSize().Height()); | 2365 ASSERT_EQ(smallest_height, document->View()->GetLayoutSize().Height()); |
| 2363 | 2366 |
| 2364 const RasterInvalidationTracking* invalidationTracking = | 2367 const RasterInvalidationTracking* invalidation_tracking = |
| 2365 document->GetLayoutView() | 2368 document->GetLayoutView() |
| 2366 ->Layer() | 2369 ->Layer() |
| 2367 ->GraphicsLayerBacking(document->GetLayoutView()) | 2370 ->GraphicsLayerBacking(document->GetLayoutView()) |
| 2368 ->GetRasterInvalidationTracking(); | 2371 ->GetRasterInvalidationTracking(); |
| 2369 | 2372 |
| 2370 // No invalidations should have occured in FrameView scrolling. If | 2373 // No invalidations should have occured in FrameView scrolling. If |
| 2371 // root-layer-scrolls is on, an invalidation is necessary for now, see the | 2374 // root-layer-scrolls is on, an invalidation is necessary for now, see the |
| 2372 // comment and TODO in FrameView::viewportSizeChanged. | 2375 // comment and TODO in FrameView::viewportSizeChanged. |
| 2373 // http://crbug.com/568847. | 2376 // http://crbug.com/568847. |
| 2374 bool rootLayerScrolling = GetParam(); | 2377 bool root_layer_scrolling = GetParam(); |
| 2375 if (rootLayerScrolling) | 2378 if (root_layer_scrolling) |
| 2376 EXPECT_TRUE(invalidationTracking); | 2379 EXPECT_TRUE(invalidation_tracking); |
| 2377 else | 2380 else |
| 2378 EXPECT_FALSE(invalidationTracking); | 2381 EXPECT_FALSE(invalidation_tracking); |
| 2379 | 2382 |
| 2380 document->View()->SetTracksPaintInvalidations(false); | 2383 document->View()->SetTracksPaintInvalidations(false); |
| 2381 RuntimeEnabledFeatures::setInertTopControlsEnabled(originalInertTopControls); | 2384 RuntimeEnabledFeatures::setInertTopControlsEnabled(originalInertTopControls); |
| 2382 } | 2385 } |
| 2383 | 2386 |
| 2384 TEST_P(VisualViewportTest, InvalidateLayoutViewWhenDocumentSmallerThanView) { | 2387 TEST_P(VisualViewportTest, InvalidateLayoutViewWhenDocumentSmallerThanView) { |
| 2385 bool originalInertTopControls = | 2388 bool originalInertTopControls = |
| 2386 RuntimeEnabledFeatures::inertTopControlsEnabled(); | 2389 RuntimeEnabledFeatures::inertTopControlsEnabled(); |
| 2387 RuntimeEnabledFeatures::setInertTopControlsEnabled(true); | 2390 RuntimeEnabledFeatures::setInertTopControlsEnabled(true); |
| 2388 | 2391 |
| 2389 std::unique_ptr<FrameTestHelpers::TestWebViewClient> | 2392 std::unique_ptr<FrameTestHelpers::TestWebViewClient> |
| 2390 fakeCompositingWebViewClient = | 2393 fake_compositing_web_view_client = |
| 2391 WTF::MakeUnique<FrameTestHelpers::TestWebViewClient>(); | 2394 WTF::MakeUnique<FrameTestHelpers::TestWebViewClient>(); |
| 2392 FrameTestHelpers::WebViewHelper webViewHelper; | 2395 FrameTestHelpers::WebViewHelper web_view_helper; |
| 2393 WebViewBase* webViewImpl = webViewHelper.Initialize( | 2396 WebViewBase* web_view_impl = web_view_helper.Initialize( |
| 2394 true, nullptr, fakeCompositingWebViewClient.get(), nullptr, | 2397 true, nullptr, fake_compositing_web_view_client.get(), nullptr, |
| 2395 &configureAndroidCompositing); | 2398 &configureAndroidCompositing); |
| 2396 | 2399 |
| 2397 int pageWidth = 320; | 2400 int page_width = 320; |
| 2398 int pageHeight = 590; | 2401 int page_height = 590; |
| 2399 float browserControlsHeight = 50.0f; | 2402 float browser_controls_height = 50.0f; |
| 2400 int largestHeight = pageHeight + browserControlsHeight; | 2403 int largest_height = page_height + browser_controls_height; |
| 2401 | 2404 |
| 2402 webViewImpl->ResizeWithBrowserControls(WebSize(pageWidth, pageHeight), | 2405 web_view_impl->ResizeWithBrowserControls(WebSize(page_width, page_height), |
| 2403 browserControlsHeight, true); | 2406 browser_controls_height, true); |
| 2404 | 2407 |
| 2405 FrameTestHelpers::LoadFrame(webViewImpl->MainFrame(), "about:blank"); | 2408 FrameTestHelpers::LoadFrame(web_view_impl->MainFrame(), "about:blank"); |
| 2406 webViewImpl->UpdateAllLifecyclePhases(); | 2409 web_view_impl->UpdateAllLifecyclePhases(); |
| 2407 | 2410 |
| 2408 Document* document = | 2411 Document* document = |
| 2409 ToLocalFrame(webViewImpl->GetPage()->MainFrame())->GetDocument(); | 2412 ToLocalFrame(web_view_impl->GetPage()->MainFrame())->GetDocument(); |
| 2410 | 2413 |
| 2411 // Do a resize to check for invalidations. | 2414 // Do a resize to check for invalidations. |
| 2412 document->View()->SetTracksPaintInvalidations(true); | 2415 document->View()->SetTracksPaintInvalidations(true); |
| 2413 webViewImpl->ResizeWithBrowserControls(WebSize(pageWidth, largestHeight), | 2416 web_view_impl->ResizeWithBrowserControls(WebSize(page_width, largest_height), |
| 2414 browserControlsHeight, false); | 2417 browser_controls_height, false); |
| 2415 | 2418 |
| 2416 // The layout size should not have changed. | 2419 // The layout size should not have changed. |
| 2417 ASSERT_EQ(pageWidth, document->View()->GetLayoutSize().Width()); | 2420 ASSERT_EQ(page_width, document->View()->GetLayoutSize().Width()); |
| 2418 ASSERT_EQ(pageHeight, document->View()->GetLayoutSize().Height()); | 2421 ASSERT_EQ(page_height, document->View()->GetLayoutSize().Height()); |
| 2419 | 2422 |
| 2420 // The entire viewport should have been invalidated. | 2423 // The entire viewport should have been invalidated. |
| 2421 { | 2424 { |
| 2422 const RasterInvalidationTracking* invalidationTracking = | 2425 const RasterInvalidationTracking* invalidation_tracking = |
| 2423 document->GetLayoutView() | 2426 document->GetLayoutView() |
| 2424 ->Layer() | 2427 ->Layer() |
| 2425 ->GraphicsLayerBacking() | 2428 ->GraphicsLayerBacking() |
| 2426 ->GetRasterInvalidationTracking(); | 2429 ->GetRasterInvalidationTracking(); |
| 2427 ASSERT_TRUE(invalidationTracking); | 2430 ASSERT_TRUE(invalidation_tracking); |
| 2428 const auto* rasterInvalidations = | 2431 const auto* raster_invalidations = |
| 2429 &invalidationTracking->tracked_raster_invalidations; | 2432 &invalidation_tracking->tracked_raster_invalidations; |
| 2430 ASSERT_EQ(1u, rasterInvalidations->size()); | 2433 ASSERT_EQ(1u, raster_invalidations->size()); |
| 2431 EXPECT_EQ(IntRect(0, 0, pageWidth, largestHeight), | 2434 EXPECT_EQ(IntRect(0, 0, page_width, largest_height), |
| 2432 (*rasterInvalidations)[0].rect); | 2435 (*raster_invalidations)[0].rect); |
| 2433 } | 2436 } |
| 2434 | 2437 |
| 2435 document->View()->SetTracksPaintInvalidations(false); | 2438 document->View()->SetTracksPaintInvalidations(false); |
| 2436 RuntimeEnabledFeatures::setInertTopControlsEnabled(originalInertTopControls); | 2439 RuntimeEnabledFeatures::setInertTopControlsEnabled(originalInertTopControls); |
| 2437 } | 2440 } |
| 2438 | 2441 |
| 2439 // Make sure we don't crash when the visual viewport's height is 0. This can | 2442 // Make sure we don't crash when the visual viewport's height is 0. This can |
| 2440 // happen transiently in autoresize mode and cause a crash. This test passes if | 2443 // happen transiently in autoresize mode and cause a crash. This test passes if |
| 2441 // it doesn't crash. | 2444 // it doesn't crash. |
| 2442 TEST_P(VisualViewportTest, AutoResizeNoHeightUsesMinimumHeight) { | 2445 TEST_P(VisualViewportTest, AutoResizeNoHeightUsesMinimumHeight) { |
| 2443 initializeWithDesktopSettings(); | 2446 InitializeWithDesktopSettings(); |
| 2444 webViewImpl()->ResizeWithBrowserControls(WebSize(0, 0), 0, false); | 2447 WebViewImpl()->ResizeWithBrowserControls(WebSize(0, 0), 0, false); |
| 2445 webViewImpl()->EnableAutoResizeMode(WebSize(25, 25), WebSize(100, 100)); | 2448 WebViewImpl()->EnableAutoResizeMode(WebSize(25, 25), WebSize(100, 100)); |
| 2446 WebURL baseURL = URLTestHelpers::ToKURL("http://example.com/"); | 2449 WebURL base_url = URLTestHelpers::ToKURL("http://example.com/"); |
| 2447 FrameTestHelpers::LoadHTMLString(webViewImpl()->MainFrame(), | 2450 FrameTestHelpers::LoadHTMLString(WebViewImpl()->MainFrame(), |
| 2448 "<!DOCTYPE html>" | 2451 "<!DOCTYPE html>" |
| 2449 "<style>" | 2452 "<style>" |
| 2450 " body {" | 2453 " body {" |
| 2451 " margin: 0px;" | 2454 " margin: 0px;" |
| 2452 " }" | 2455 " }" |
| 2453 " div { height:110vh; width: 110vw; }" | 2456 " div { height:110vh; width: 110vw; }" |
| 2454 "</style>" | 2457 "</style>" |
| 2455 "<div></div>", | 2458 "<div></div>", |
| 2456 baseURL); | 2459 base_url); |
| 2457 } | 2460 } |
| 2458 | 2461 |
| 2459 } // namespace | 2462 } // namespace |
| 2463 } // namespace blink |
| OLD | NEW |