| 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 762ed806a241d7e9052325acc4b73d88ad2deee0..7cb1bb58be399900144a831076a6798b3c61fefe 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,434 @@ TEST_F(WebViewTest, IsSelectionAnchorFirst)
|
| EXPECT_FALSE(webView->isSelectionAnchorFirst());
|
| }
|
|
|
| +TEST_F(WebViewTest, ScrollAndScaleOverrideMovesAndZoomsViewports)
|
| +{
|
| + 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();
|
| +
|
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport);
|
| +
|
| + // Scroll position override moves layout viewport.
|
| + webViewImpl->setScrollAndScaleOverride(IntPoint(100, 100), DoublePoint(-1, -1), 0);
|
| + EXPECT_FALSE(frameView->layoutPending());
|
| + EXPECT_FALSE(frameView->needsLayout());
|
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 100), DoublePoint(0, 0), 1.0, frameView, visualViewport);
|
| + // Ensure that setting the override only affects the layer's offset, and
|
| + // not its position. The position should not be affected by the overridden
|
| + // minimumScrollPosition - prevents regression against crbug.com/625084.
|
| + EXPECT_POINT_EQ(DoublePoint(0, 0), frameView->layerForScrolling()->position());
|
| + EXPECT_POINT_EQ(DoublePoint(100, 100), static_cast<DoublePoint>(frameView->layerForScrolling()->platformLayer()->scrollPositionDouble()));
|
| +
|
| + webViewImpl->setScrollAndScaleOverride(IntPoint(50, 50), DoublePoint(-1, -1), 0);
|
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(0, 0), 1.0, frameView, visualViewport);
|
| +
|
| + webViewImpl->clearScrollAndScaleOverride();
|
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport);
|
| +
|
| + // Visual viewport scroll position override moves visual viewport.
|
| + webViewImpl->setScrollAndScaleOverride(IntPoint(-1, -1), DoublePoint(50, 50), 0);
|
| + EXPECT_FALSE(frameView->layoutPending());
|
| + EXPECT_FALSE(frameView->needsLayout());
|
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(50, 50), 1.0, frameView, visualViewport);
|
| + // Ensure that setting the override only affects the layer's offset.
|
| + EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport->layerForScrolling()->position());
|
| + EXPECT_POINT_EQ(DoublePoint(50, 50), static_cast<DoublePoint>(visualViewport->layerForScrolling()->platformLayer()->scrollPositionDouble()));
|
| +
|
| + webViewImpl->setScrollAndScaleOverride(IntPoint(-1, -1), DoublePoint(25, 25), 0);
|
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(25, 25), 1.0, frameView, visualViewport);
|
| +
|
| + webViewImpl->clearScrollAndScaleOverride();
|
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport);
|
| +
|
| + // Page scale override zooms into page.
|
| + webViewImpl->setScrollAndScaleOverride(IntPoint(-1, -1), DoublePoint(-1, -1), 2);
|
| + // Scale override is enforced via constraints, which require a layout.
|
| + EXPECT_TRUE(frameView->layoutPending());
|
| + EXPECT_TRUE(frameView->needsLayout());
|
| + webViewImpl->updateAllLifecyclePhases();
|
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 2.0, frameView, visualViewport);
|
| +
|
| + webViewImpl->setScrollAndScaleOverride(IntPoint(-1, -1), DoublePoint(-1, -1), 1.5);
|
| + EXPECT_TRUE(frameView->layoutPending());
|
| + EXPECT_TRUE(frameView->needsLayout());
|
| + webViewImpl->updateAllLifecyclePhases();
|
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.5, frameView, visualViewport);
|
| +
|
| + webViewImpl->clearScrollAndScaleOverride();
|
| + EXPECT_TRUE(frameView->layoutPending());
|
| + EXPECT_TRUE(frameView->needsLayout());
|
| + webViewImpl->updateAllLifecyclePhases();
|
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport);
|
| +
|
| + // Combined override of all factors repositions and scales viewports.
|
| + webViewImpl->setScrollAndScaleOverride(IntPoint(100, 100), DoublePoint(50, 50), 2);
|
| + EXPECT_TRUE(frameView->layoutPending());
|
| + EXPECT_TRUE(frameView->needsLayout());
|
| + webViewImpl->updateAllLifecyclePhases();
|
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 100), DoublePoint(50, 50), 2.0, frameView, visualViewport);
|
| +
|
| + webViewImpl->setScrollAndScaleOverride(IntPoint(50, 50), DoublePoint(25, 25), 1.5);
|
| + EXPECT_TRUE(frameView->layoutPending());
|
| + EXPECT_TRUE(frameView->needsLayout());
|
| + webViewImpl->updateAllLifecyclePhases();
|
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(25, 25), 1.5, frameView, visualViewport);
|
| +
|
| + webViewImpl->clearScrollAndScaleOverride();
|
| + EXPECT_TRUE(frameView->layoutPending());
|
| + EXPECT_TRUE(frameView->needsLayout());
|
| + webViewImpl->updateAllLifecyclePhases();
|
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport);
|
| +}
|
| +
|
| +TEST_F(WebViewTest, ScrollAndScaleOverrideFixesScaleAndScrollPositions)
|
| +{
|
| + 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();
|
| +
|
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport);
|
| +
|
| + // Empty overrides allow scrolling and zooming.
|
| + webViewImpl->setScrollAndScaleOverride(IntPoint(-1, -1), DoublePoint(-1, -1), 0);
|
| + 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->clearScrollAndScaleOverride();
|
| + 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.
|
| + webViewImpl->setScrollAndScaleOverride(IntPoint(50, 50), DoublePoint(-1, -1), 0);
|
| + 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->clearScrollAndScaleOverride();
|
| + 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.
|
| + webViewImpl->setScrollAndScaleOverride(IntPoint(-1, -1), DoublePoint(25, 25), 0);
|
| + 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->clearScrollAndScaleOverride();
|
| + 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.
|
| + webViewImpl->setScrollAndScaleOverride(IntPoint(-1, 50), DoublePoint(-1, -1), 0);
|
| + 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);
|
| +
|
| + webViewImpl->setScrollAndScaleOverride(IntPoint(50, -1), DoublePoint(-1, -1), 0);
|
| + 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->clearScrollAndScaleOverride();
|
| + 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.
|
| + webViewImpl->setScrollAndScaleOverride(IntPoint(-1, -1), DoublePoint(-1, 25), 0);
|
| + 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);
|
| +
|
| + webViewImpl->setScrollAndScaleOverride(IntPoint(-1, -1), DoublePoint(25, -1), 0);
|
| + 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->clearScrollAndScaleOverride();
|
| + 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.
|
| + webViewImpl->setScrollAndScaleOverride(IntPoint(-1, -1), DoublePoint(-1, -1), 1.5);
|
| + webViewImpl->updateAllLifecyclePhases();
|
| + 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->clearScrollAndScaleOverride();
|
| + webViewImpl->updateAllLifecyclePhases();
|
| + 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.
|
| + webViewImpl->setScrollAndScaleOverride(IntPoint(50, 50), DoublePoint(25, 25), 0);
|
| + 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->clearScrollAndScaleOverride();
|
| + 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.
|
| + webViewImpl->setScrollAndScaleOverride(IntPoint(50, 50), DoublePoint(25, 25), 1.5);
|
| + webViewImpl->updateAllLifecyclePhases();
|
| + 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->clearScrollAndScaleOverride();
|
| + webViewImpl->updateAllLifecyclePhases();
|
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport);
|
| +}
|
| +
|
| +TEST_F(WebViewTest, ScrollOverrideIsClamped)
|
| +{
|
| + 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();
|
| +
|
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport);
|
| +
|
| + // Scroll position override is clamped to maximum.
|
| + webViewImpl->setScrollAndScaleOverride(IntPoint(1000, 1000), DoublePoint(-1, -1), 0);
|
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 150), DoublePoint(0, 0), 1.0, frameView, visualViewport);
|
| +
|
| + webViewImpl->clearScrollAndScaleOverride();
|
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport);
|
| +
|
| + // Viewport scroll position override is clamped to maximum.
|
| + webViewImpl->setScrollAndScaleOverride(IntPoint(-1, -1), DoublePoint(1000, 1000), 0);
|
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(50, 75), 1.0, frameView, visualViewport);
|
| +
|
| + webViewImpl->clearScrollAndScaleOverride();
|
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView, visualViewport);
|
| +}
|
| +
|
| +TEST_F(WebViewTest, ScrollAndScaleOverrideDisablesAndRestoresThreadedScrolling)
|
| +{
|
| + 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();
|
| +
|
| + EXPECT_TRUE(webViewImpl->page()->settings().threadedScrollingEnabled());
|
| +
|
| + // Setting scroll override disables threaded scrolling and sets main thread
|
| + // scrolling reasons.
|
| + webViewImpl->setScrollAndScaleOverride(IntPoint(0, 0), DoublePoint(0, 0), 0);
|
| + 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->clearScrollAndScaleOverride();
|
| + 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.
|
| + webViewImpl->setScrollAndScaleOverride(IntPoint(0, 0), DoublePoint(0, 0), 0);
|
| + webViewImpl->setScrollAndScaleOverride(IntPoint(100, 100), DoublePoint(0, 0), 0);
|
| + EXPECT_FALSE(webViewImpl->page()->settings().threadedScrollingEnabled());
|
| + webViewImpl->updateAllLifecyclePhases();
|
| + EXPECT_TRUE(frameView->layerForScrolling()->platformLayer()->shouldScrollOnMainThread());
|
| + EXPECT_TRUE(visualViewport->layerForScrolling()->platformLayer()->shouldScrollOnMainThread());
|
| +
|
| + webViewImpl->clearScrollAndScaleOverride();
|
| + EXPECT_TRUE(webViewImpl->page()->settings().threadedScrollingEnabled());
|
| + webViewImpl->updateAllLifecyclePhases();
|
| + EXPECT_FALSE(frameView->layerForScrolling()->platformLayer()->shouldScrollOnMainThread());
|
| + EXPECT_FALSE(visualViewport->layerForScrolling()->platformLayer()->shouldScrollOnMainThread());
|
| +}
|
| +
|
| +TEST_F(WebViewTest, ScaleOverrideDoesNotAffectMainFrameSize)
|
| +{
|
| + 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();
|
| +
|
| + 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();
|
| + webViewImpl->setScrollAndScaleOverride(IntPoint(-1, -1), DoublePoint(-1, -1), 2.0);
|
| + webViewImpl->updateAllLifecyclePhases();
|
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 2.0, frameView, visualViewport);
|
| + EXPECT_SIZE_EQ(expectedSize, webViewImpl->mainFrameSize());
|
| +
|
| + // Main frame size resizes correctly.
|
| + WebSize viewSize = webViewImpl->size();
|
| + webViewImpl->resize(WebSize(viewSize.width * 2, viewSize.height * 2));
|
| + EXPECT_SIZE_EQ(IntSize(expectedSize.width() * 2, expectedSize.height() * 2), webViewImpl->mainFrameSize());
|
| + webViewImpl->resize(viewSize);
|
| +
|
| + webViewImpl->clearScrollAndScaleOverride();
|
| + webViewImpl->updateAllLifecyclePhases();
|
| + 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);
|
| + webViewImpl->updateAllLifecyclePhases();
|
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 0.25, frameView, visualViewport);
|
| + expectedSize = webViewImpl->mainFrameSize();
|
| + webViewImpl->setScrollAndScaleOverride(IntPoint(-1, -1), DoublePoint(-1, -1), 2.0);
|
| + webViewImpl->updateAllLifecyclePhases();
|
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 2.0, frameView, visualViewport);
|
| + EXPECT_SIZE_EQ(expectedSize, webViewImpl->mainFrameSize());
|
| +
|
| + viewSize = webViewImpl->size();
|
| + webViewImpl->resize(WebSize(viewSize.width * 2, viewSize.height * 2));
|
| + EXPECT_SIZE_EQ(IntSize(expectedSize.width() * 2, expectedSize.height() * 2), webViewImpl->mainFrameSize());
|
| + webViewImpl->resize(viewSize);
|
| +
|
| + webViewImpl->clearScrollAndScaleOverride();
|
| + webViewImpl->updateAllLifecyclePhases();
|
| + EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 0.25, frameView, visualViewport);
|
| + EXPECT_SIZE_EQ(expectedSize, webViewImpl->mainFrameSize());
|
| +}
|
| +
|
| +TEST_F(WebViewTest, ScaleOverrideSetsAndRestoresPageScaleConstraints)
|
| +{
|
| + 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);
|
| + webViewImpl->updateAllLifecyclePhases();
|
| + 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.
|
| + webViewImpl->setScrollAndScaleOverride(IntPoint(-1, -1), DoublePoint(-1, -1), 3.0);
|
| + webViewImpl->updateAllLifecyclePhases();
|
| + 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->setScrollAndScaleOverride(IntPoint(-1, -1), DoublePoint(-1, -1), 0);
|
| + webViewImpl->updateAllLifecyclePhases();
|
| + 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.
|
| + webViewImpl->setScrollAndScaleOverride(IntPoint(-1, -1), DoublePoint(-1, -1), 3.0);
|
| + webViewImpl->updateAllLifecyclePhases();
|
| + 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->clearScrollAndScaleOverride();
|
| + webViewImpl->updateAllLifecyclePhases();
|
| + 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"));
|
|
|