OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 const int touchPointPadding = 32; | 160 const int touchPointPadding = 32; |
161 | 161 |
162 #define EXPECT_RECT_EQ(expected, actual) \ | 162 #define EXPECT_RECT_EQ(expected, actual) \ |
163 do { \ | 163 do { \ |
164 EXPECT_EQ(expected.x(), actual.x()); \ | 164 EXPECT_EQ(expected.x(), actual.x()); \ |
165 EXPECT_EQ(expected.y(), actual.y()); \ | 165 EXPECT_EQ(expected.y(), actual.y()); \ |
166 EXPECT_EQ(expected.width(), actual.width()); \ | 166 EXPECT_EQ(expected.width(), actual.width()); \ |
167 EXPECT_EQ(expected.height(), actual.height()); \ | 167 EXPECT_EQ(expected.height(), actual.height()); \ |
168 } while (false) | 168 } while (false) |
169 | 169 |
170 #define EXPECT_POINT_EQ(expected, actual) \ | 170 #define EXPECT_SIZE_EQ(expected, actual) \ |
171 do { \ | 171 do { \ |
172 EXPECT_EQ(expected.x(), actual.x()); \ | 172 EXPECT_EQ(expected.width(), actual.width()); \ |
173 EXPECT_EQ(expected.y(), actual.y()); \ | 173 EXPECT_EQ(expected.height(), actual.height()); \ |
174 } while (false) | 174 } while (false) |
175 | 175 |
176 #define EXPECT_FLOAT_POINT_EQ(expected, actual) \ | 176 #define EXPECT_FLOAT_POINT_EQ(expected, actual) \ |
177 do { \ | 177 do { \ |
178 EXPECT_FLOAT_EQ(expected.x(), actual.x()); \ | 178 EXPECT_FLOAT_EQ(expected.x(), actual.x()); \ |
179 EXPECT_FLOAT_EQ(expected.y(), actual.y()); \ | 179 EXPECT_FLOAT_EQ(expected.y(), actual.y()); \ |
180 } while (false) | 180 } while (false) |
181 | 181 |
182 class WebFrameTest : public ::testing::Test { | 182 class WebFrameTest : public ::testing::Test { |
183 protected: | 183 protected: |
(...skipping 2748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2932 | 2932 |
2933 void setScaleAndScrollAndLayout(WebViewImpl* webView, | 2933 void setScaleAndScrollAndLayout(WebViewImpl* webView, |
2934 WebPoint scroll, | 2934 WebPoint scroll, |
2935 float scale) { | 2935 float scale) { |
2936 webView->setPageScaleFactor(scale); | 2936 webView->setPageScaleFactor(scale); |
2937 webView->mainFrame()->setScrollOffset(WebSize(scroll.x, scroll.y)); | 2937 webView->mainFrame()->setScrollOffset(WebSize(scroll.x, scroll.y)); |
2938 webView->updateAllLifecyclePhases(); | 2938 webView->updateAllLifecyclePhases(); |
2939 } | 2939 } |
2940 | 2940 |
2941 void simulatePageScale(WebViewImpl* webViewImpl, float& scale) { | 2941 void simulatePageScale(WebViewImpl* webViewImpl, float& scale) { |
2942 IntSize scrollDelta = | 2942 ScrollOffset scrollDelta = |
2943 webViewImpl->fakePageScaleAnimationTargetPositionForTesting() - | 2943 toScrollOffset( |
2944 webViewImpl->mainFrameImpl()->frameView()->scrollPosition(); | 2944 webViewImpl->fakePageScaleAnimationTargetPositionForTesting()) - |
| 2945 webViewImpl->mainFrameImpl()->frameView()->scrollOffset(); |
2945 float scaleDelta = webViewImpl->fakePageScaleAnimationPageScaleForTesting() / | 2946 float scaleDelta = webViewImpl->fakePageScaleAnimationPageScaleForTesting() / |
2946 webViewImpl->pageScaleFactor(); | 2947 webViewImpl->pageScaleFactor(); |
2947 webViewImpl->applyViewportDeltas(WebFloatSize(), FloatSize(scrollDelta), | 2948 webViewImpl->applyViewportDeltas(WebFloatSize(), FloatSize(scrollDelta), |
2948 WebFloatSize(), scaleDelta, 0); | 2949 WebFloatSize(), scaleDelta, 0); |
2949 scale = webViewImpl->pageScaleFactor(); | 2950 scale = webViewImpl->pageScaleFactor(); |
2950 } | 2951 } |
2951 | 2952 |
2952 void simulateMultiTargetZoom(WebViewImpl* webViewImpl, | 2953 void simulateMultiTargetZoom(WebViewImpl* webViewImpl, |
2953 const WebRect& rect, | 2954 const WebRect& rect, |
2954 float& scale) { | 2955 float& scale) { |
(...skipping 2795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5750 | 5751 |
5751 WebViewImpl* webViewImpl = webViewHelper.webView(); | 5752 WebViewImpl* webViewImpl = webViewHelper.webView(); |
5752 ASSERT_TRUE(webViewImpl); | 5753 ASSERT_TRUE(webViewImpl); |
5753 LocalFrame* frame = webViewImpl->mainFrameImpl()->frame(); | 5754 LocalFrame* frame = webViewImpl->mainFrameImpl()->frame(); |
5754 ASSERT_TRUE(frame); | 5755 ASSERT_TRUE(frame); |
5755 | 5756 |
5756 webViewHelper.resize(WebSize(100, 200)); | 5757 webViewHelper.resize(WebSize(100, 200)); |
5757 | 5758 |
5758 // Scroll main frame to the bottom of the document | 5759 // Scroll main frame to the bottom of the document |
5759 webViewImpl->mainFrame()->setScrollOffset(WebSize(0, 400)); | 5760 webViewImpl->mainFrame()->setScrollOffset(WebSize(0, 400)); |
5760 EXPECT_POINT_EQ(IntPoint(0, 400), frame->view()->scrollPosition()); | 5761 EXPECT_SIZE_EQ(ScrollOffset(0, 400), frame->view()->scrollOffset()); |
5761 | 5762 |
5762 webViewImpl->setPageScaleFactor(2.0); | 5763 webViewImpl->setPageScaleFactor(2.0); |
5763 | 5764 |
5764 // Scroll visual viewport to the top of the main frame. | 5765 // Scroll visual viewport to the top of the main frame. |
5765 VisualViewport& visualViewport = frame->page()->frameHost().visualViewport(); | 5766 VisualViewport& visualViewport = frame->page()->frameHost().visualViewport(); |
5766 visualViewport.setLocation(FloatPoint(0, 0)); | 5767 visualViewport.setLocation(FloatPoint(0, 0)); |
5767 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), visualViewport.location()); | 5768 EXPECT_SIZE_EQ(ScrollOffset(0, 0), visualViewport.scrollOffset()); |
5768 | 5769 |
5769 // Tap at the top: there is nothing there. | 5770 // Tap at the top: there is nothing there. |
5770 client.resetTriggered(); | 5771 client.resetTriggered(); |
5771 webViewHelper.webView()->handleInputEvent(fatTap(10, 60)); | 5772 webViewHelper.webView()->handleInputEvent(fatTap(10, 60)); |
5772 EXPECT_FALSE(client.triggered()); | 5773 EXPECT_FALSE(client.triggered()); |
5773 | 5774 |
5774 // Scroll visual viewport to the bottom of the main frame. | 5775 // Scroll visual viewport to the bottom of the main frame. |
5775 visualViewport.setLocation(FloatPoint(0, 200)); | 5776 visualViewport.setLocation(FloatPoint(0, 200)); |
5776 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 200), visualViewport.location()); | 5777 EXPECT_SIZE_EQ(ScrollOffset(0, 200), visualViewport.scrollOffset()); |
5777 | 5778 |
5778 // Now the tap with the same coordinates should hit two elements. | 5779 // Now the tap with the same coordinates should hit two elements. |
5779 client.resetTriggered(); | 5780 client.resetTriggered(); |
5780 webViewHelper.webView()->handleInputEvent(fatTap(10, 60)); | 5781 webViewHelper.webView()->handleInputEvent(fatTap(10, 60)); |
5781 EXPECT_TRUE(client.triggered()); | 5782 EXPECT_TRUE(client.triggered()); |
5782 | 5783 |
5783 // The same tap shouldn't trigger didTapMultipleTargets() after disabling the | 5784 // The same tap shouldn't trigger didTapMultipleTargets() after disabling the |
5784 // notification for multi-target-tap. | 5785 // notification for multi-target-tap. |
5785 webViewHelper.webView()->settings()->setMultiTargetTapNotificationEnabled( | 5786 webViewHelper.webView()->settings()->setMultiTargetTapNotificationEnabled( |
5786 false); | 5787 false); |
(...skipping 1512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7299 | 7300 |
7300 WebViewImpl* webView = webViewHelper.webView(); | 7301 WebViewImpl* webView = webViewHelper.webView(); |
7301 FrameView* frameView = webViewHelper.webView()->mainFrameImpl()->frameView(); | 7302 FrameView* frameView = webViewHelper.webView()->mainFrameImpl()->frameView(); |
7302 | 7303 |
7303 float topControlsHeight = 40; | 7304 float topControlsHeight = 40; |
7304 webView->resizeWithTopControls(WebSize(100, 100), topControlsHeight, false); | 7305 webView->resizeWithTopControls(WebSize(100, 100), topControlsHeight, false); |
7305 webView->setPageScaleFactor(2.0f); | 7306 webView->setPageScaleFactor(2.0f); |
7306 webView->updateAllLifecyclePhases(); | 7307 webView->updateAllLifecyclePhases(); |
7307 | 7308 |
7308 webView->mainFrame()->setScrollOffset(WebSize(0, 2000)); | 7309 webView->mainFrame()->setScrollOffset(WebSize(0, 2000)); |
7309 EXPECT_POINT_EQ(IntPoint(0, 1900), IntPoint(frameView->scrollOffset())); | 7310 EXPECT_SIZE_EQ(ScrollOffset(0, 1900), frameView->scrollOffset()); |
7310 | 7311 |
7311 // Simulate the top controls showing by 20px, thus shrinking the viewport | 7312 // Simulate the top controls showing by 20px, thus shrinking the viewport |
7312 // and allowing it to scroll an additional 20px. | 7313 // and allowing it to scroll an additional 20px. |
7313 webView->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), | 7314 webView->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), |
7314 1.0f, 20.0f / topControlsHeight); | 7315 1.0f, 20.0f / topControlsHeight); |
7315 EXPECT_POINT_EQ(IntPoint(0, 1920), frameView->maximumScrollPosition()); | 7316 EXPECT_SIZE_EQ(ScrollOffset(0, 1920), frameView->maximumScrollOffset()); |
7316 | 7317 |
7317 // Show more, make sure the scroll actually gets clamped. | 7318 // Show more, make sure the scroll actually gets clamped. |
7318 webView->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), | 7319 webView->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), |
7319 1.0f, 20.0f / topControlsHeight); | 7320 1.0f, 20.0f / topControlsHeight); |
7320 webView->mainFrame()->setScrollOffset(WebSize(0, 2000)); | 7321 webView->mainFrame()->setScrollOffset(WebSize(0, 2000)); |
7321 EXPECT_POINT_EQ(IntPoint(0, 1940), IntPoint(frameView->scrollOffset())); | 7322 EXPECT_SIZE_EQ(ScrollOffset(0, 1940), frameView->scrollOffset()); |
7322 | 7323 |
7323 // Hide until there's 10px showing. | 7324 // Hide until there's 10px showing. |
7324 webView->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), | 7325 webView->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), |
7325 1.0f, -30.0f / topControlsHeight); | 7326 1.0f, -30.0f / topControlsHeight); |
7326 EXPECT_POINT_EQ(IntPoint(0, 1910), frameView->maximumScrollPosition()); | 7327 EXPECT_SIZE_EQ(ScrollOffset(0, 1910), frameView->maximumScrollOffset()); |
7327 | 7328 |
7328 // Simulate a LayoutPart::resize. The frame is resized to accomodate | 7329 // Simulate a LayoutPart::resize. The frame is resized to accomodate |
7329 // the top controls and Blink's view of the top controls matches that of | 7330 // the top controls and Blink's view of the top controls matches that of |
7330 // the CC | 7331 // the CC |
7331 webView->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), | 7332 webView->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), |
7332 1.0f, 30.0f / topControlsHeight); | 7333 1.0f, 30.0f / topControlsHeight); |
7333 webView->resizeWithTopControls(WebSize(100, 60), 40.0f, true); | 7334 webView->resizeWithTopControls(WebSize(100, 60), 40.0f, true); |
7334 webView->updateAllLifecyclePhases(); | 7335 webView->updateAllLifecyclePhases(); |
7335 EXPECT_POINT_EQ(IntPoint(0, 1940), frameView->maximumScrollPosition()); | 7336 EXPECT_SIZE_EQ(ScrollOffset(0, 1940), frameView->maximumScrollOffset()); |
7336 | 7337 |
7337 // Now simulate hiding. | 7338 // Now simulate hiding. |
7338 webView->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), | 7339 webView->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), |
7339 1.0f, -10.0f / topControlsHeight); | 7340 1.0f, -10.0f / topControlsHeight); |
7340 EXPECT_POINT_EQ(IntPoint(0, 1930), frameView->maximumScrollPosition()); | 7341 EXPECT_SIZE_EQ(ScrollOffset(0, 1930), frameView->maximumScrollOffset()); |
7341 | 7342 |
7342 // Reset to original state: 100px widget height, top controls fully hidden. | 7343 // Reset to original state: 100px widget height, top controls fully hidden. |
7343 webView->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), | 7344 webView->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), |
7344 1.0f, -30.0f / topControlsHeight); | 7345 1.0f, -30.0f / topControlsHeight); |
7345 webView->resizeWithTopControls(WebSize(100, 100), topControlsHeight, false); | 7346 webView->resizeWithTopControls(WebSize(100, 100), topControlsHeight, false); |
7346 webView->updateAllLifecyclePhases(); | 7347 webView->updateAllLifecyclePhases(); |
7347 EXPECT_POINT_EQ(IntPoint(0, 1900), frameView->maximumScrollPosition()); | 7348 EXPECT_SIZE_EQ(ScrollOffset(0, 1900), frameView->maximumScrollOffset()); |
7348 | 7349 |
7349 // Show the top controls by just 1px, since we're zoomed in to 2X, that | 7350 // Show the top controls by just 1px, since we're zoomed in to 2X, that |
7350 // should allow an extra 0.5px of scrolling in the visual viewport. Make | 7351 // should allow an extra 0.5px of scrolling in the visual viewport. Make |
7351 // sure we're not losing any pixels when applying the adjustment on the | 7352 // sure we're not losing any pixels when applying the adjustment on the |
7352 // main frame. | 7353 // main frame. |
7353 webView->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), | 7354 webView->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), |
7354 1.0f, 1.0f / topControlsHeight); | 7355 1.0f, 1.0f / topControlsHeight); |
7355 EXPECT_POINT_EQ(IntPoint(0, 1901), frameView->maximumScrollPosition()); | 7356 EXPECT_SIZE_EQ(ScrollOffset(0, 1901), frameView->maximumScrollOffset()); |
7356 | 7357 |
7357 webView->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), | 7358 webView->applyViewportDeltas(WebFloatSize(), WebFloatSize(), WebFloatSize(), |
7358 1.0f, 2.0f / topControlsHeight); | 7359 1.0f, 2.0f / topControlsHeight); |
7359 EXPECT_POINT_EQ(IntPoint(0, 1903), frameView->maximumScrollPosition()); | 7360 EXPECT_SIZE_EQ(ScrollOffset(0, 1903), frameView->maximumScrollOffset()); |
7360 } | 7361 } |
7361 | 7362 |
7362 TEST_F(WebFrameTest, MaximumScrollPositionCanBeNegative) { | 7363 TEST_F(WebFrameTest, MaximumScrollPositionCanBeNegative) { |
7363 registerMockedHttpURLLoad("rtl-overview-mode.html"); | 7364 registerMockedHttpURLLoad("rtl-overview-mode.html"); |
7364 | 7365 |
7365 FixedLayoutTestWebViewClient client; | 7366 FixedLayoutTestWebViewClient client; |
7366 client.m_screenInfo.deviceScaleFactor = 1; | 7367 client.m_screenInfo.deviceScaleFactor = 1; |
7367 int viewportWidth = 640; | 7368 int viewportWidth = 640; |
7368 int viewportHeight = 480; | 7369 int viewportHeight = 480; |
7369 | 7370 |
7370 FrameTestHelpers::WebViewHelper webViewHelper; | 7371 FrameTestHelpers::WebViewHelper webViewHelper; |
7371 webViewHelper.initializeAndLoad(m_baseURL + "rtl-overview-mode.html", true, | 7372 webViewHelper.initializeAndLoad(m_baseURL + "rtl-overview-mode.html", true, |
7372 nullptr, &client, nullptr, | 7373 nullptr, &client, nullptr, |
7373 enableViewportSettings); | 7374 enableViewportSettings); |
7374 webViewHelper.webView()->setInitialPageScaleOverride(-1); | 7375 webViewHelper.webView()->setInitialPageScaleOverride(-1); |
7375 webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true); | 7376 webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true); |
7376 webViewHelper.webView()->settings()->setLoadWithOverviewMode(true); | 7377 webViewHelper.webView()->settings()->setLoadWithOverviewMode(true); |
7377 webViewHelper.webView()->settings()->setUseWideViewport(true); | 7378 webViewHelper.webView()->settings()->setUseWideViewport(true); |
7378 webViewHelper.resize(WebSize(viewportWidth, viewportHeight)); | 7379 webViewHelper.resize(WebSize(viewportWidth, viewportHeight)); |
7379 webViewHelper.webView()->updateAllLifecyclePhases(); | 7380 webViewHelper.webView()->updateAllLifecyclePhases(); |
7380 | 7381 |
7381 FrameView* frameView = webViewHelper.webView()->mainFrameImpl()->frameView(); | 7382 FrameView* frameView = webViewHelper.webView()->mainFrameImpl()->frameView(); |
7382 EXPECT_LT(frameView->maximumScrollPosition().x(), 0); | 7383 EXPECT_LT(frameView->maximumScrollOffset().width(), 0); |
7383 } | 7384 } |
7384 | 7385 |
7385 TEST_P(ParameterizedWebFrameTest, FullscreenLayerSize) { | 7386 TEST_P(ParameterizedWebFrameTest, FullscreenLayerSize) { |
7386 FakeCompositingWebViewClient client; | 7387 FakeCompositingWebViewClient client; |
7387 registerMockedHttpURLLoad("fullscreen_div.html"); | 7388 registerMockedHttpURLLoad("fullscreen_div.html"); |
7388 FrameTestHelpers::WebViewHelper webViewHelper; | 7389 FrameTestHelpers::WebViewHelper webViewHelper; |
7389 int viewportWidth = 640; | 7390 int viewportWidth = 640; |
7390 int viewportHeight = 480; | 7391 int viewportHeight = 480; |
7391 client.m_screenInfo.rect.width = viewportWidth; | 7392 client.m_screenInfo.rect.width = viewportWidth; |
7392 client.m_screenInfo.rect.height = viewportHeight; | 7393 client.m_screenInfo.rect.height = viewportHeight; |
(...skipping 2769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10162 Platform::current()->getURLLoaderMockFactory()->setLoaderDelegate(nullptr); | 10163 Platform::current()->getURLLoaderMockFactory()->setLoaderDelegate(nullptr); |
10163 | 10164 |
10164 Document* document = | 10165 Document* document = |
10165 toLocalFrame(helper.webView()->page()->mainFrame())->document(); | 10166 toLocalFrame(helper.webView()->page()->mainFrame())->document(); |
10166 EXPECT_TRUE(document->isImageDocument()); | 10167 EXPECT_TRUE(document->isImageDocument()); |
10167 EXPECT_EQ(Resource::DecodeError, | 10168 EXPECT_EQ(Resource::DecodeError, |
10168 toImageDocument(document)->cachedImage()->getStatus()); | 10169 toImageDocument(document)->cachedImage()->getStatus()); |
10169 } | 10170 } |
10170 | 10171 |
10171 } // namespace blink | 10172 } // namespace blink |
OLD | NEW |