Chromium Code Reviews| Index: Source/WebKit/chromium/tests/WebFrameTest.cpp |
| diff --git a/Source/WebKit/chromium/tests/WebFrameTest.cpp b/Source/WebKit/chromium/tests/WebFrameTest.cpp |
| index d75bebc7d2075d71193097f00221c001beb0d53c..ee1fe959bdfc854cb2f249f5104b67d6d049fa4b 100644 |
| --- a/Source/WebKit/chromium/tests/WebFrameTest.cpp |
| +++ b/Source/WebKit/chromium/tests/WebFrameTest.cpp |
| @@ -37,6 +37,7 @@ |
| #include "Frame.h" |
| #include "FrameTestHelpers.h" |
| #include "FrameView.h" |
| +#include "HitTestResult.h" |
| #include "PlatformContextSkia.h" |
| #include "Range.h" |
| #include "RenderView.h" |
| @@ -655,6 +656,122 @@ TEST_F(WebFrameTest, targetDensityDpiDevice) |
| } |
| } |
| +class WebFrameResizeTest : public WebFrameTest { |
| +protected: |
| + |
| + static WebCore::FloatSize computeRelativeOffset(const WebCore::IntPoint& absoluteOffset, const WebCore::LayoutRect& rect) |
| + { |
| + WebCore::FloatSize relativeOffset = WebCore::FloatPoint(absoluteOffset) - rect.location(); |
| + relativeOffset.scale(1.f / rect.width(), 1.f / rect.height()); |
| + return relativeOffset; |
| + } |
| + |
| + void TestResizeYieldsCorrectScrollAndScale(const char* url, |
| + const float initialPageScaleFactor, |
| + const WebSize scrollOffset, |
| + const WebSize viewportSize, |
| + const bool useFixedLayout, |
|
aelias_OOO_until_Jul13
2013/04/15 18:25:39
Delete this
jdduke (slow)
2013/04/16 15:40:26
Done.
|
| + const bool shouldScaleRelativeToViewportWidth) { |
| + registerMockedHttpURLLoad(url); |
| + |
| + const float aspectRatio = (float)viewportSize.width / viewportSize.height; |
|
aelias_OOO_until_Jul13
2013/04/15 18:25:39
Nit: static_cast<float>
jdduke (slow)
2013/04/16 15:40:26
Done.
|
| + |
| + m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + url, true); |
| + m_webView->settings()->setViewportEnabled(true); |
| + m_webView->enableFixedLayoutMode(useFixedLayout); |
|
aelias_OOO_until_Jul13
2013/04/15 18:25:39
This setting is always true on the Android platfor
jdduke (slow)
2013/04/16 15:40:26
Done.
|
| + WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView); |
| + |
| + // Origin scrollOffsets preserved under resize. |
| + { |
| + webViewImpl->resize(WebSize(viewportSize.width, viewportSize.height)); |
| + m_webView->setPageScaleFactor(initialPageScaleFactor, WebPoint()); |
| + webViewImpl->resize(WebSize(viewportSize.height, viewportSize.width)); |
| + float expectedPageScaleFactor = initialPageScaleFactor * (shouldScaleRelativeToViewportWidth ? 1 / aspectRatio : 1); |
| + EXPECT_NEAR(expectedPageScaleFactor, webViewImpl->pageScaleFactor(), 0.05f); |
| + EXPECT_EQ(WebSize(), webViewImpl->mainFrame()->scrollOffset()); |
| + } |
| + |
| + // Resizing just the height should not affect pageScaleFactor. |
| + { |
| + webViewImpl->resize(WebSize(viewportSize.width, viewportSize.height)); |
| + m_webView->setPageScaleFactor(initialPageScaleFactor, WebPoint()); |
| + webViewImpl->resize(WebSize(viewportSize.width, viewportSize.height * 1.25f)); |
| + EXPECT_EQ(initialPageScaleFactor, webViewImpl->pageScaleFactor()); |
| + webViewImpl->resize(WebSize(viewportSize.width, viewportSize.height * .8f)); |
| + EXPECT_EQ(initialPageScaleFactor, webViewImpl->pageScaleFactor()); |
| + } |
| + |
| + // Generic resize preserves scrollOffset relative to anchor node located |
| + // the top center of the screen. |
| + { |
| + webViewImpl->resize(WebSize(viewportSize.height, viewportSize.width)); |
| + float pageScaleFactor = webViewImpl->pageScaleFactor(); |
| + webViewImpl->resize(WebSize(viewportSize.width, viewportSize.height)); |
| + float expectedPageScaleFactor = pageScaleFactor * (shouldScaleRelativeToViewportWidth ? aspectRatio : 1); |
| + EXPECT_NEAR(expectedPageScaleFactor, webViewImpl->pageScaleFactor(), 0.05f); |
| + webViewImpl->mainFrame()->setScrollOffset(scrollOffset); |
| + |
| + WebCore::IntPoint anchorPoint = WebCore::IntPoint(scrollOffset) + WebCore::IntPoint(viewportSize.width / 2, 0); |
| + RefPtr<WebCore::Node> anchorNode = webViewImpl->mainFrameImpl()->frame()->eventHandler()->hitTestResultAtPoint(anchorPoint).innerNode(); |
| + ASSERT(anchorNode); |
| + |
| + pageScaleFactor = webViewImpl->pageScaleFactor(); |
| + const WebCore::FloatSize preResizeRelativeOffset |
| + = computeRelativeOffset(anchorPoint, anchorNode->boundingBox()); |
| + webViewImpl->resize(WebSize(viewportSize.height, viewportSize.width)); |
| + WebCore::IntPoint newAnchorPoint = WebCore::IntPoint(webViewImpl->mainFrame()->scrollOffset()) + WebCore::IntPoint(viewportSize.height / 2, 0); |
| + const WebCore::FloatSize postResizeRelativeOffset |
| + = computeRelativeOffset(newAnchorPoint, anchorNode->boundingBox()); |
| + EXPECT_NEAR(preResizeRelativeOffset.width(), postResizeRelativeOffset.width(), 0.1f); |
| + expectedPageScaleFactor = pageScaleFactor * (shouldScaleRelativeToViewportWidth ? 1 / aspectRatio : 1); |
| + EXPECT_NEAR(expectedPageScaleFactor, webViewImpl->pageScaleFactor(), 0.05f); |
| + } |
| + } |
| +}; |
| + |
| +TEST_F(WebFrameResizeTest, ResizeYieldsCorrectScrollAndScaleForWidthEqualsDeviceWidth) |
| +{ |
| + // With width=device-width, pageScaleFactor is preserved across resizes as |
| + // long as the content adjusts according to the device-width. |
| + const char* url = "resize_scroll_mobile.html"; |
| + const float initialPageScaleFactor = 1; |
| + const WebSize scrollOffset = WebSize(0, 200); |
| + const WebSize viewportSize = WebSize(240, 320); |
| + const bool useFixedLayout = false; |
| + const bool shouldScaleRelativeToViewportWidth = false; |
| + |
| + TestResizeYieldsCorrectScrollAndScale( |
| + url, initialPageScaleFactor, scrollOffset, viewportSize, useFixedLayout, shouldScaleRelativeToViewportWidth); |
| +} |
| + |
| +TEST_F(WebFrameResizeTest, ResizeYieldsCorrectScrollAndScaleForFixedWidth) |
| +{ |
| + // With a fixed width, pageScaleFactor scales by the relative change in viewport width. |
| + const char* url = "resize_scroll_fixed_width.html"; |
| + const float initialPageScaleFactor = 2; |
| + const WebSize scrollOffset = WebSize(200, 400); |
| + const WebSize viewportSize = WebSize(320, 240); |
| + const bool useFixedLayout = false; |
| + const bool shouldScaleRelativeToViewportWidth = true; |
| + |
| + TestResizeYieldsCorrectScrollAndScale( |
| + url, initialPageScaleFactor, scrollOffset, viewportSize, useFixedLayout, shouldScaleRelativeToViewportWidth); |
| +} |
| + |
| +TEST_F(WebFrameResizeTest, ResizeYieldsCorrectScrollAndScaleForFixedLayout) |
| +{ |
| + // With a fixed layout, pageScaleFactor scales by the relative change in viewport width. |
| + const char* url = "resize_scroll_fixed_layout.html"; |
| + const float initialPageScaleFactor = 2; |
| + const WebSize scrollOffset = WebSize(200, 400); |
| + const WebSize viewportSize = WebSize(320, 240); |
| + const bool useFixedLayout = true; |
| + const bool shouldScaleRelativeToViewportWidth = true; |
| + |
| + TestResizeYieldsCorrectScrollAndScale( |
| + url, initialPageScaleFactor, scrollOffset, viewportSize, useFixedLayout, shouldScaleRelativeToViewportWidth); |
| +} |
| + |
| TEST_F(WebFrameTest, pageScaleFactorScalesPaintClip) |
| { |
| registerMockedHttpURLLoad("fixed_layout.html"); |