| Index: Source/WebKit/chromium/tests/WebFrameTest.cpp
|
| diff --git a/Source/WebKit/chromium/tests/WebFrameTest.cpp b/Source/WebKit/chromium/tests/WebFrameTest.cpp
|
| index 306f31a60fdec8b72b1ab0816256328c96e2004c..009c7d6cbd61d41612bde560e2f92947a4c2bbf0 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"
|
| @@ -624,6 +625,119 @@ TEST_F(WebFrameTest, targetDensityDpiDevice)
|
| }
|
| #endif
|
|
|
| +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 shouldScaleRelativeToViewportWidth) {
|
| + registerMockedHttpURLLoad(url);
|
| +
|
| + const float aspectRatio = static_cast<float>(viewportSize.width) / viewportSize.height;
|
| +
|
| + m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + url, true);
|
| + m_webView->settings()->setViewportEnabled(true);
|
| + m_webView->enableFixedLayoutMode(true);
|
| + 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->mainFrame()->setScrollOffset(WebSize(0, 10));
|
| + 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.15f);
|
| + 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(120, 160);
|
| + const bool shouldScaleRelativeToViewportWidth = true;
|
| +
|
| + TestResizeYieldsCorrectScrollAndScale(
|
| + url, initialPageScaleFactor, scrollOffset, viewportSize, 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(0, 200);
|
| + const WebSize viewportSize = WebSize(240, 320);
|
| + const bool shouldScaleRelativeToViewportWidth = true;
|
| +
|
| + TestResizeYieldsCorrectScrollAndScale(
|
| + url, initialPageScaleFactor, scrollOffset, viewportSize, 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 shouldScaleRelativeToViewportWidth = true;
|
| +
|
| + TestResizeYieldsCorrectScrollAndScale(
|
| + url, initialPageScaleFactor, scrollOffset, viewportSize, shouldScaleRelativeToViewportWidth);
|
| +}
|
| +
|
| TEST_F(WebFrameTest, pageScaleFactorScalesPaintClip)
|
| {
|
| registerMockedHttpURLLoad("fixed_layout.html");
|
| @@ -665,6 +779,31 @@ TEST_F(WebFrameTest, pageScaleFactorScalesPaintClip)
|
| EXPECT_EQ_RECT(clippedRect, platformContext.opaqueRegion().asRect());
|
| }
|
|
|
| +TEST_F(WebFrameTest, pageScaleFactorUpdatesScrollbars)
|
| +{
|
| + registerMockedHttpURLLoad("fixed_layout.html");
|
| +
|
| + FixedLayoutTestWebViewClient client;
|
| + client.m_screenInfo.deviceScaleFactor = 1;
|
| + int viewportWidth = 640;
|
| + int viewportHeight = 480;
|
| +
|
| + m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout.html", true, 0, &client);
|
| + m_webView->enableFixedLayoutMode(true);
|
| + m_webView->settings()->setViewportEnabled(true);
|
| + m_webView->resize(WebSize(viewportWidth, viewportHeight));
|
| + m_webView->layout();
|
| +
|
| + WebCore::FrameView* view = static_cast<WebViewImpl*>(m_webView)->mainFrameImpl()->frameView();
|
| + EXPECT_EQ(view->scrollSize(WebCore::HorizontalScrollbar), view->contentsSize().width() - view->visibleContentRect().width());
|
| + EXPECT_EQ(view->scrollSize(WebCore::VerticalScrollbar), view->contentsSize().height() - view->visibleContentRect().height());
|
| +
|
| + m_webView->setPageScaleFactor(10, WebPoint());
|
| +
|
| + EXPECT_EQ(view->scrollSize(WebCore::HorizontalScrollbar), view->contentsSize().width() - view->visibleContentRect().width());
|
| + EXPECT_EQ(view->scrollSize(WebCore::VerticalScrollbar), view->contentsSize().height() - view->visibleContentRect().height());
|
| +}
|
| +
|
| TEST_F(WebFrameTest, CanOverrideMaximumScaleFactor)
|
| {
|
| registerMockedHttpURLLoad("no_scale_for_you.html");
|
|
|