Chromium Code Reviews| Index: third_party/WebKit/Source/web/tests/WebViewTest.cpp |
| diff --git a/third_party/WebKit/Source/web/tests/WebViewTest.cpp b/third_party/WebKit/Source/web/tests/WebViewTest.cpp |
| index a32e4562bcd64f4aa8be19556a92a42d1114d5fa..c9cd57c9d855ed4326d6ba33e047879eb66bebac 100644 |
| --- a/third_party/WebKit/Source/web/tests/WebViewTest.cpp |
| +++ b/third_party/WebKit/Source/web/tests/WebViewTest.cpp |
| @@ -40,6 +40,8 @@ |
| #include "core/frame/FrameHost.h" |
| #include "core/frame/FrameView.h" |
| #include "core/frame/LocalFrame.h" |
| +#include "core/frame/PageScaleConstraints.h" |
| +#include "core/frame/PageScaleConstraintsSet.h" |
| #include "core/frame/Settings.h" |
| #include "core/frame/VisualViewport.h" |
| #include "core/html/HTMLDocument.h" |
| @@ -110,6 +112,27 @@ using blink::testing::runPendingTasks; |
| namespace blink { |
| +#define EXPECT_POINT_EQ(expected, actual) \ |
| + do { \ |
| + EXPECT_DOUBLE_EQ((expected).x(), (actual).x()); \ |
| + EXPECT_DOUBLE_EQ((expected).y(), (actual).y()); \ |
| + } while (false) |
| + |
| +#define EXPECT_SIZE_EQ(expected, actual) \ |
| + do { \ |
| + EXPECT_DOUBLE_EQ((expected).width(), (actual).width()); \ |
| + EXPECT_DOUBLE_EQ((expected).height(), (actual).height()); \ |
| + } while (false) |
| + |
| +#define EXPECT_SCROLL_AND_SCALE(expectedScrollPosition, expectedVisualPosition, expectedScale, frameView, visualViewport) \ |
| + do { \ |
| + EXPECT_POINT_EQ(expectedScrollPosition, frameView->scrollPositionDouble()); \ |
| + EXPECT_POINT_EQ(expectedScrollPosition, frameView->scrollAnimator().currentPosition()); \ |
| + EXPECT_POINT_EQ(expectedVisualPosition, visualViewport->scrollPositionDouble()); \ |
| + EXPECT_POINT_EQ(expectedVisualPosition, visualViewport->scrollAnimator().currentPosition()); \ |
| + EXPECT_EQ(expectedScale, visualViewport->scale()); \ |
| + } while (false) |
| + |
| enum HorizontalScrollbarState { |
| NoHorizontalScrollbar, |
| VisibleHorizontalScrollbar, |
| @@ -1067,6 +1090,469 @@ TEST_F(WebViewTest, IsSelectionAnchorFirst) |
| EXPECT_FALSE(webView->isSelectionAnchorFirst()); |
| } |
| +TEST_F(WebViewTest, DeviceEmulationOverridesMoveAndZoomViewports) |
| +{ |
| + URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("200-by-300.html")); |
| + WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "200-by-300.html"); |
| + webViewImpl->resize(WebSize(100, 150)); |
| + webViewImpl->resizeVisualViewport(WebSize(50, 75)); |
| + |
| + FrameView* frameView = webViewImpl->mainFrameImpl()->frame()->view(); |
| + VisualViewport* visualViewport = &webViewImpl->page()->frameHost().visualViewport(); |
| + WebDeviceEmulationParams params; |
| + |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + |
| + // Scroll position override moves layout viewport. |
| + params.scrollPosition = WebPoint(100, 100); |
| + params.visualViewportPosition = WebFloatPoint(-1, -1); |
| + params.visualViewportScale = 0; |
| + webViewImpl->enableDeviceEmulation(params); |
| + EXPECT_FALSE(frameView->layoutPending()); |
| + EXPECT_FALSE(frameView->needsLayout()); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 100), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + |
| + params.scrollPosition = WebPoint(50, 50); |
| + webViewImpl->enableDeviceEmulation(params); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + |
| + webViewImpl->disableDeviceEmulation(); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + |
| + // Visual viewport scroll position override moves visual viewport. |
| + params.scrollPosition = WebPoint(-1, -1); |
| + params.visualViewportPosition = WebFloatPoint(50, 50); |
| + params.visualViewportScale = 0; |
| + webViewImpl->enableDeviceEmulation(params); |
| + EXPECT_FALSE(frameView->layoutPending()); |
| + EXPECT_FALSE(frameView->needsLayout()); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(50, 50), 1.0, frameView, visualViewport); |
| + |
| + params.visualViewportPosition = WebFloatPoint(25, 25); |
| + webViewImpl->enableDeviceEmulation(params); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(25, 25), 1.0, frameView, visualViewport); |
| + |
| + webViewImpl->disableDeviceEmulation(); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + |
| + // Page scale override zooms into page. |
| + params.scrollPosition = WebPoint(-1, -1); |
| + params.visualViewportPosition = WebFloatPoint(-1, -1); |
| + params.visualViewportScale = 2; |
| + webViewImpl->enableDeviceEmulation(params); |
| + // Scale override is enforced via constraints, which require a layout. |
| + EXPECT_TRUE(frameView->layoutPending()); |
| + EXPECT_TRUE(frameView->needsLayout()); |
| + frameView->layout(); |
|
bokan
2016/07/11 13:52:10
I would use webViewImpl->updateAllLifecyclePhases,
Eric Seckler
2016/07/11 16:37:13
Done.
|
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 2.0, frameView, visualViewport); |
| + |
| + params.visualViewportScale = 1.5; |
| + webViewImpl->enableDeviceEmulation(params); |
| + EXPECT_TRUE(frameView->layoutPending()); |
| + EXPECT_TRUE(frameView->needsLayout()); |
| + frameView->layout(); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.5, frameView, visualViewport); |
| + |
| + webViewImpl->disableDeviceEmulation(); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
|
bokan
2016/07/11 13:52:10
Should we also expect needsLayout/layoutPending he
Eric Seckler
2016/07/11 16:37:13
Theoretically yes, but disableDeviceEmulation() pe
|
| + |
| + // Combined override of all factors repositions and scales viewports. |
| + params.scrollPosition = WebPoint(100, 100); |
| + params.visualViewportPosition = WebFloatPoint(50, 50); |
| + params.visualViewportScale = 2; |
| + webViewImpl->enableDeviceEmulation(params); |
| + EXPECT_TRUE(frameView->layoutPending()); |
| + EXPECT_TRUE(frameView->needsLayout()); |
| + frameView->layout(); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 100), DoublePoint(50, 50), 2.0, frameView, visualViewport); |
| + |
| + params.scrollPosition = WebPoint(50, 50); |
| + params.visualViewportPosition = WebFloatPoint(25, 25); |
| + params.visualViewportScale = 1.5; |
| + webViewImpl->enableDeviceEmulation(params); |
| + EXPECT_TRUE(frameView->layoutPending()); |
| + EXPECT_TRUE(frameView->needsLayout()); |
| + frameView->layout(); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(25, 25), 1.5, frameView, visualViewport); |
| + |
| + webViewImpl->disableDeviceEmulation(); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| +} |
| + |
| +TEST_F(WebViewTest, DeviceEmulationOverridesFixScaleAndScrollPositions) |
| +{ |
| + URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("200-by-300.html")); |
| + WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "200-by-300.html"); |
| + webViewImpl->resize(WebSize(100, 150)); |
| + webViewImpl->resizeVisualViewport(WebSize(50, 75)); |
| + |
| + // We don't want to have to service animations for the test. |
| + webViewImpl->settings()->setEnableScrollAnimator(false); |
| + |
| + FrameView* frameView = webViewImpl->mainFrameImpl()->frame()->view(); |
| + VisualViewport* visualViewport = &webViewImpl->page()->frameHost().visualViewport(); |
| + ScrollableArea* rootScroller = frameView->getScrollableArea(); |
| + WebDeviceEmulationParams params; |
| + |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + |
| + // Empty overrides allow scrolling and zooming. |
| + params.scrollPosition = WebPoint(-1, -1); |
| + params.visualViewportPosition = WebFloatPoint(-1, -1); |
| + params.visualViewportScale = 0; |
| + webViewImpl->enableDeviceEmulation(params); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + |
| + frameView->setScrollPosition(DoublePoint(100, 100), ProgrammaticScroll, ScrollBehaviorInstant); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 100), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + visualViewport->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll, ScrollBehaviorInstant); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 100), DoublePoint(50, 50), 1.0, frameView, visualViewport); |
| + EXPECT_TRUE(rootScroller->userScroll(ScrollByPixel, FloatSize(-50, -50)).didScroll()); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 100), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + EXPECT_TRUE(rootScroller->userScroll(ScrollByPixel, FloatSize(-50, -50)).didScroll()); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + webViewImpl->setPageScaleFactor(2.0); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(0, 0), 2.0, frameView, visualViewport); |
| + |
| + webViewImpl->disableDeviceEmulation(); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + |
| + // Override of scroll position fixes layout viewport, but not visual one. |
| + params.scrollPosition = WebPoint(50, 50); |
| + params.visualViewportPosition = WebFloatPoint(-1, -1); |
| + params.visualViewportScale = 0; |
| + webViewImpl->enableDeviceEmulation(params); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + |
| + frameView->setScrollPosition(DoublePoint(100, 100), ProgrammaticScroll, ScrollBehaviorInstant); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + visualViewport->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll, ScrollBehaviorInstant); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(50, 50), 1.0, frameView, visualViewport); |
| + EXPECT_TRUE(rootScroller->userScroll(ScrollByPixel, FloatSize(-50, -50)).didScroll()); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + EXPECT_FALSE(rootScroller->userScroll(ScrollByPixel, FloatSize(-50, -50)).didScroll()); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + EXPECT_TRUE(rootScroller->userScroll(ScrollByPixel, FloatSize(1000, 1000)).didScroll()); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(50, 75), 1.0, frameView, visualViewport); |
| + webViewImpl->setPageScaleFactor(2.0); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(50, 75), 2.0, frameView, visualViewport); |
| + |
| + webViewImpl->disableDeviceEmulation(); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + |
| + // Override of visual position fixes visual viewport, but not layout one. |
| + params.scrollPosition = WebPoint(-1, -1); |
| + params.visualViewportPosition = WebFloatPoint(25, 25); |
| + params.visualViewportScale = 0; |
| + webViewImpl->enableDeviceEmulation(params); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(25, 25), 1.0, frameView, visualViewport); |
| + |
| + frameView->setScrollPosition(DoublePoint(100, 100), ProgrammaticScroll, ScrollBehaviorInstant); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 100), DoublePoint(25, 25), 1.0, frameView, visualViewport); |
| + visualViewport->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll, ScrollBehaviorInstant); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 100), DoublePoint(25, 25), 1.0, frameView, visualViewport); |
| + EXPECT_TRUE(rootScroller->userScroll(ScrollByPixel, FloatSize(-100, -100)).didScroll()); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(25, 25), 1.0, frameView, visualViewport); |
| + EXPECT_FALSE(rootScroller->userScroll(ScrollByPixel, FloatSize(-50, -50)).didScroll()); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(25, 25), 1.0, frameView, visualViewport); |
| + EXPECT_TRUE(rootScroller->userScroll(ScrollByPixel, FloatSize(1000, 1000)).didScroll()); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 150), DoublePoint(25, 25), 1.0, frameView, visualViewport); |
| + webViewImpl->setPageScaleFactor(2.0); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 150), DoublePoint(25, 25), 2.0, frameView, visualViewport); |
| + |
| + webViewImpl->disableDeviceEmulation(); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + |
| + // Scroll position: override of one coordinate doesn't fix other one. |
| + params.scrollPosition = WebPoint(-1, 50); |
| + params.visualViewportPosition = WebFloatPoint(-1, -1); |
| + params.visualViewportScale = 0; |
| + webViewImpl->enableDeviceEmulation(params); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 50), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + |
| + frameView->setScrollPosition(DoublePoint(100, 100), ProgrammaticScroll, ScrollBehaviorInstant); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 50), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + EXPECT_TRUE(rootScroller->userScroll(ScrollByPixel, FloatSize(-100, -100)).didScroll()); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 50), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + |
| + params.scrollPosition = WebPoint(50, -1); |
| + webViewImpl->enableDeviceEmulation(params); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + frameView->setScrollPosition(DoublePoint(100, 100), ProgrammaticScroll, ScrollBehaviorInstant); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 100), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + EXPECT_TRUE(rootScroller->userScroll(ScrollByPixel, FloatSize(-100, -100)).didScroll()); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + |
| + webViewImpl->disableDeviceEmulation(); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + |
| + // Visual position: override of one coordinate doesn't fix other one. |
| + params.scrollPosition = WebPoint(-1, -1); |
| + params.visualViewportPosition = WebFloatPoint(-1, 25); |
| + params.visualViewportScale = 0; |
| + webViewImpl->enableDeviceEmulation(params); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 25), 1.0, frameView, visualViewport); |
| + |
| + visualViewport->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll, ScrollBehaviorInstant); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(50, 25), 1.0, frameView, visualViewport); |
| + EXPECT_TRUE(rootScroller->userScroll(ScrollByPixel, FloatSize(-50, -50)).didScroll()); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 25), 1.0, frameView, visualViewport); |
| + |
| + params.visualViewportPosition = WebFloatPoint(25, -1); |
| + webViewImpl->enableDeviceEmulation(params); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(25, 25), 1.0, frameView, visualViewport); |
| + visualViewport->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll, ScrollBehaviorInstant); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(25, 50), 1.0, frameView, visualViewport); |
| + EXPECT_TRUE(rootScroller->userScroll(ScrollByPixel, FloatSize(-50, -50)).didScroll()); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(25, 0), 1.0, frameView, visualViewport); |
| + |
| + webViewImpl->disableDeviceEmulation(); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + |
| + // Scale change is ignored when scale is overridden, but scrolls work. |
| + params.scrollPosition = WebPoint(-1, -1); |
| + params.visualViewportPosition = WebFloatPoint(-1, -1); |
| + params.visualViewportScale = 1.5; |
| + webViewImpl->enableDeviceEmulation(params); |
| + frameView->layout(); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.5, frameView, visualViewport); |
| + |
| + frameView->setScrollPosition(DoublePoint(100, 100), ProgrammaticScroll, ScrollBehaviorInstant); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 100), DoublePoint(0, 0), 1.5, frameView, visualViewport); |
| + visualViewport->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll, ScrollBehaviorInstant); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 100), DoublePoint(50, 50), 1.5, frameView, visualViewport); |
| + EXPECT_TRUE(rootScroller->userScroll(ScrollByPixel, FloatSize(-50, -50)).didScroll()); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 100), DoublePoint(0, 0), 1.5, frameView, visualViewport); |
| + EXPECT_TRUE(rootScroller->userScroll(ScrollByPixel, FloatSize(-50, -50)).didScroll()); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(0, 0), 1.5, frameView, visualViewport); |
| + webViewImpl->setPageScaleFactor(2.0); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(0, 0), 1.5, frameView, visualViewport); |
| + |
| + webViewImpl->disableDeviceEmulation(); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + |
| + // Scrolling is ignored when both scroll positions are fixed, but not zoom. |
| + params.scrollPosition = WebPoint(50, 50); |
| + params.visualViewportPosition = WebFloatPoint(25, 25); |
| + params.visualViewportScale = 0; |
| + webViewImpl->enableDeviceEmulation(params); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(25, 25), 1.0, frameView, visualViewport); |
| + |
| + frameView->setScrollPosition(DoublePoint(100, 100), ProgrammaticScroll, ScrollBehaviorInstant); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(25, 25), 1.0, frameView, visualViewport); |
| + visualViewport->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll, ScrollBehaviorInstant); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(25, 25), 1.0, frameView, visualViewport); |
| + EXPECT_FALSE(rootScroller->userScroll(ScrollByPixel, FloatSize(-50, -50)).didScroll()); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(25, 25), 1.0, frameView, visualViewport); |
| + EXPECT_FALSE(rootScroller->userScroll(ScrollByPixel, FloatSize(1000, 1000)).didScroll()); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(25, 25), 1.0, frameView, visualViewport); |
| + webViewImpl->setPageScaleFactor(2.0); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(25, 25), 2.0, frameView, visualViewport); |
| + |
| + webViewImpl->disableDeviceEmulation(); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + |
| + // Both scrolling and scale changes are ignored when they are all fixed. |
| + params.scrollPosition = WebPoint(50, 50); |
| + params.visualViewportPosition = WebFloatPoint(25, 25); |
| + params.visualViewportScale = 1.5; |
| + webViewImpl->enableDeviceEmulation(params); |
| + frameView->layout(); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(25, 25), 1.5, frameView, visualViewport); |
| + |
| + frameView->setScrollPosition(DoublePoint(100, 100), ProgrammaticScroll, ScrollBehaviorInstant); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(25, 25), 1.5, frameView, visualViewport); |
| + visualViewport->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll, ScrollBehaviorInstant); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(25, 25), 1.5, frameView, visualViewport); |
| + EXPECT_FALSE(rootScroller->userScroll(ScrollByPixel, FloatSize(-50, -50)).didScroll()); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(25, 25), 1.5, frameView, visualViewport); |
| + EXPECT_FALSE(rootScroller->userScroll(ScrollByPixel, FloatSize(1000, 1000)).didScroll()); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(25, 25), 1.5, frameView, visualViewport); |
| + webViewImpl->setPageScaleFactor(2.0); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(25, 25), 1.5, frameView, visualViewport); |
| + |
| + webViewImpl->disableDeviceEmulation(); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| +} |
| + |
| +TEST_F(WebViewTest, DeviceEmulationScrollOverridesAreClamped) |
| +{ |
| + URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("200-by-300.html")); |
| + WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "200-by-300.html"); |
| + webViewImpl->resize(WebSize(100, 150)); |
| + webViewImpl->resizeVisualViewport(WebSize(50, 75)); |
| + |
| + FrameView* frameView = webViewImpl->mainFrameImpl()->frame()->view(); |
| + VisualViewport* visualViewport = &webViewImpl->page()->frameHost().visualViewport(); |
| + WebDeviceEmulationParams params; |
| + |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + |
| + // Scroll position override is clamped to maximum. |
| + params.scrollPosition = WebPoint(1000, 1000); |
| + params.visualViewportPosition = WebFloatPoint(-1, -1); |
| + params.visualViewportScale = 0; |
| + webViewImpl->enableDeviceEmulation(params); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 150), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + |
| + webViewImpl->disableDeviceEmulation(); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + |
| + // Viewport scroll position override is clamped to maximum. |
| + params.scrollPosition = WebPoint(-1, -1); |
| + params.visualViewportPosition = WebFloatPoint(1000, 1000); |
| + params.visualViewportScale = 0; |
| + webViewImpl->enableDeviceEmulation(params); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(50, 75), 1.0, frameView, visualViewport); |
| + |
| + webViewImpl->disableDeviceEmulation(); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| +} |
| + |
| +TEST_F(WebViewTest, DeviceEmulationDisablesAndRestoresThreadedScrolling) |
| +{ |
| + URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("200-by-300.html")); |
| + WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "200-by-300.html"); |
| + webViewImpl->resize(WebSize(100, 150)); |
| + webViewImpl->resizeVisualViewport(WebSize(50, 75)); |
| + |
| + FrameView* frameView = webViewImpl->mainFrameImpl()->frame()->view(); |
| + VisualViewport* visualViewport = &webViewImpl->page()->frameHost().visualViewport(); |
| + WebDeviceEmulationParams params; |
| + |
| + EXPECT_TRUE(webViewImpl->page()->settings().threadedScrollingEnabled()); |
| + |
| + // Setting scroll override disables threaded scrolling and sets main thread |
| + // scrolling reasons. |
| + params.scrollPosition = WebPoint(0, 0); |
| + params.visualViewportPosition = WebFloatPoint(0, 0); |
| + webViewImpl->enableDeviceEmulation(params); |
| + EXPECT_FALSE(webViewImpl->page()->settings().threadedScrollingEnabled()); |
| + webViewImpl->updateAllLifecyclePhases(); |
| + EXPECT_TRUE(frameView->layerForScrolling()->platformLayer()->shouldScrollOnMainThread()); |
| + EXPECT_TRUE(visualViewport->layerForScrolling()->platformLayer()->shouldScrollOnMainThread()); |
| + |
| + // Clearing override restores original setting. |
| + webViewImpl->disableDeviceEmulation(); |
| + EXPECT_TRUE(webViewImpl->page()->settings().threadedScrollingEnabled()); |
| + webViewImpl->updateAllLifecyclePhases(); |
| + EXPECT_FALSE(frameView->layerForScrolling()->platformLayer()->shouldScrollOnMainThread()); |
| + EXPECT_FALSE(visualViewport->layerForScrolling()->platformLayer()->shouldScrollOnMainThread()); |
| + |
| + // Updating scroll override does not override stored default. |
| + params.scrollPosition = WebPoint(0, 0); |
| + params.visualViewportPosition = WebFloatPoint(0, 0); |
| + webViewImpl->enableDeviceEmulation(params); |
| + params.scrollPosition = WebPoint(100, 100); |
| + webViewImpl->enableDeviceEmulation(params); |
| + EXPECT_FALSE(webViewImpl->page()->settings().threadedScrollingEnabled()); |
| + webViewImpl->updateAllLifecyclePhases(); |
| + EXPECT_TRUE(frameView->layerForScrolling()->platformLayer()->shouldScrollOnMainThread()); |
| + EXPECT_TRUE(visualViewport->layerForScrolling()->platformLayer()->shouldScrollOnMainThread()); |
| + |
| + webViewImpl->disableDeviceEmulation(); |
| + EXPECT_TRUE(webViewImpl->page()->settings().threadedScrollingEnabled()); |
| + webViewImpl->updateAllLifecyclePhases(); |
| + EXPECT_FALSE(frameView->layerForScrolling()->platformLayer()->shouldScrollOnMainThread()); |
| + EXPECT_FALSE(visualViewport->layerForScrolling()->platformLayer()->shouldScrollOnMainThread()); |
| +} |
| + |
| +TEST_F(WebViewTest, DeviceEmulationScaleOverrideDoesNotAffectMainFrameSize) |
| +{ |
| + URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("200-by-300.html")); |
| + WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "200-by-300.html"); |
| + webViewImpl->resize(WebSize(100, 150)); |
| + webViewImpl->resizeVisualViewport(WebSize(50, 75)); |
| + |
| + FrameView* frameView = webViewImpl->mainFrameImpl()->frame()->view(); |
| + VisualViewport* visualViewport = &webViewImpl->page()->frameHost().visualViewport(); |
| + WebDeviceEmulationParams params; |
| + |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + |
| + // Main frame size is normally calculated by dividing by minimum scale. |
| + // Since scale override changes minimum scale, we need to ensure that the |
| + // calculated main frame size does not change. |
| + IntSize expectedSize = webViewImpl->mainFrameSize(); |
| + params.visualViewportScale = 2.0; |
| + webViewImpl->enableDeviceEmulation(params); |
| + frameView->layout(); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 2.0, frameView, visualViewport); |
| + EXPECT_SIZE_EQ(expectedSize, webViewImpl->mainFrameSize()); |
| + |
| + webViewImpl->disableDeviceEmulation(); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + EXPECT_SIZE_EQ(expectedSize, webViewImpl->mainFrameSize()); |
| + |
| + // Same behavior for non-default minimum scale. |
| + webViewImpl->setDefaultPageScaleLimits(0.25, 5.0); |
| + frameView->layout(); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 0.25, frameView, visualViewport); |
| + expectedSize = webViewImpl->mainFrameSize(); |
| + params.visualViewportScale = 2.0; |
| + webViewImpl->enableDeviceEmulation(params); |
| + frameView->layout(); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 2.0, frameView, visualViewport); |
| + EXPECT_SIZE_EQ(expectedSize, webViewImpl->mainFrameSize()); |
|
bokan
2016/07/11 13:52:10
Maybe add a resize while the override is in place
Eric Seckler
2016/07/11 16:37:13
Done.
|
| + |
| + webViewImpl->disableDeviceEmulation(); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 0.25, frameView, visualViewport); |
| + EXPECT_SIZE_EQ(expectedSize, webViewImpl->mainFrameSize()); |
| +} |
| + |
| +TEST_F(WebViewTest, DeviceEmulationScaleOverrideSetsAndRestoresPageScaleConstraints) |
| +{ |
| + URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("200-by-300.html")); |
| + WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "200-by-300.html"); |
| + webViewImpl->resize(WebSize(100, 150)); |
| + webViewImpl->resizeVisualViewport(WebSize(50, 75)); |
| + |
| + FrameView* frameView = webViewImpl->mainFrameImpl()->frame()->view(); |
| + VisualViewport* visualViewport = &webViewImpl->page()->frameHost().visualViewport(); |
| + WebDeviceEmulationParams params; |
| + |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + PageScaleConstraints originalConstraints(1.0, 0.5, 2.0); |
| + webViewImpl->page()->frameHost().setUserAgentPageScaleConstraints(originalConstraints); |
| + frameView->layout(); |
| + EXPECT_EQ(originalConstraints.initialScale, webViewImpl->pageScaleConstraintsSet().userAgentConstraints().initialScale); |
| + EXPECT_EQ(originalConstraints.minimumScale, webViewImpl->pageScaleConstraintsSet().userAgentConstraints().minimumScale); |
| + EXPECT_EQ(originalConstraints.maximumScale, webViewImpl->pageScaleConstraintsSet().userAgentConstraints().maximumScale); |
| + |
| + // Setting and clearing scale override restores original user-agent page |
| + // scale constraints setting. |
| + params.visualViewportScale = 3.0; |
| + webViewImpl->enableDeviceEmulation(params); |
| + frameView->layout(); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 3.0, frameView, visualViewport); |
| + EXPECT_EQ(3.0, webViewImpl->pageScaleConstraintsSet().userAgentConstraints().initialScale); |
| + EXPECT_EQ(3.0, webViewImpl->pageScaleConstraintsSet().userAgentConstraints().minimumScale); |
| + EXPECT_EQ(3.0, webViewImpl->pageScaleConstraintsSet().userAgentConstraints().maximumScale); |
| + |
| + params.visualViewportScale = 0; |
| + webViewImpl->enableDeviceEmulation(params); |
| + frameView->layout(); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 2.0, frameView, visualViewport); |
| + EXPECT_EQ(originalConstraints.initialScale, webViewImpl->pageScaleConstraintsSet().userAgentConstraints().initialScale); |
| + EXPECT_EQ(originalConstraints.minimumScale, webViewImpl->pageScaleConstraintsSet().userAgentConstraints().minimumScale); |
| + EXPECT_EQ(originalConstraints.maximumScale, webViewImpl->pageScaleConstraintsSet().userAgentConstraints().maximumScale); |
| + |
| + // Same behavior for disabling emulation after scale override. |
| + params.visualViewportScale = 3.0; |
| + webViewImpl->enableDeviceEmulation(params); |
| + frameView->layout(); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 3.0, frameView, visualViewport); |
| + EXPECT_EQ(3.0, webViewImpl->pageScaleConstraintsSet().userAgentConstraints().initialScale); |
| + EXPECT_EQ(3.0, webViewImpl->pageScaleConstraintsSet().userAgentConstraints().minimumScale); |
| + EXPECT_EQ(3.0, webViewImpl->pageScaleConstraintsSet().userAgentConstraints().maximumScale); |
| + |
| + webViewImpl->disableDeviceEmulation(); |
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport); |
| + EXPECT_EQ(originalConstraints.initialScale, webViewImpl->pageScaleConstraintsSet().userAgentConstraints().initialScale); |
| + EXPECT_EQ(originalConstraints.minimumScale, webViewImpl->pageScaleConstraintsSet().userAgentConstraints().minimumScale); |
| + EXPECT_EQ(originalConstraints.maximumScale, webViewImpl->pageScaleConstraintsSet().userAgentConstraints().maximumScale); |
| +} |
| + |
| TEST_F(WebViewTest, ExitingDeviceEmulationResetsPageScale) |
| { |
| URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("200-by-300.html")); |