| 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 340521631ad19f081804fb958e67acbb0ae14ad8..74ec6acea358b93196c28400955260b74b869a15 100644
|
| --- a/third_party/WebKit/Source/web/tests/WebViewTest.cpp
|
| +++ b/third_party/WebKit/Source/web/tests/WebViewTest.cpp
|
| @@ -57,16 +57,19 @@
|
| #include "core/timing/PerformanceCompositeTiming.h"
|
| #include "platform/KeyboardCodes.h"
|
| #include "platform/UserGestureIndicator.h"
|
| +#include "platform/geometry/IntRect.h"
|
| #include "platform/geometry/IntSize.h"
|
| #include "platform/graphics/Color.h"
|
| #include "platform/graphics/GraphicsContext.h"
|
| #include "platform/graphics/paint/SkPictureBuilder.h"
|
| +#include "platform/scroll/ScrollTypes.h"
|
| #include "platform/testing/URLTestHelpers.h"
|
| #include "platform/testing/UnitTestHelpers.h"
|
| #include "public/platform/Platform.h"
|
| #include "public/platform/WebDisplayMode.h"
|
| #include "public/platform/WebDragData.h"
|
| #include "public/platform/WebDragOperation.h"
|
| +#include "public/platform/WebFloatRect.h"
|
| #include "public/platform/WebMockClipboard.h"
|
| #include "public/platform/WebSize.h"
|
| #include "public/platform/WebThread.h"
|
| @@ -91,6 +94,7 @@
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "third_party/skia/include/core/SkBitmap.h"
|
| #include "third_party/skia/include/core/SkCanvas.h"
|
| +#include "web/DevToolsEmulator.h"
|
| #include "web/WebLocalFrameImpl.h"
|
| #include "web/WebSettingsImpl.h"
|
| #include "web/WebViewImpl.h"
|
| @@ -3286,4 +3290,101 @@ TEST_F(WebViewTest, NestedLoadDeferrals)
|
| EXPECT_FALSE(webView->page()->defersLoading());
|
| }
|
|
|
| +TEST_F(WebViewTest, SetAndClearVisualTransformOverride)
|
| +{
|
| + 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));
|
| + FrameView* frameView = webViewImpl->mainFrameImpl()->frame()->view();
|
| + VisualViewport* visualViewport = &webViewImpl->page()->frameHost().visualViewport();
|
| +
|
| + TransformationMatrix expectedMatrix;
|
| + expectedMatrix.makeIdentity();
|
| + EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting());
|
| + EXPECT_EQ(IntRect(0, 0, 100, 150), frameView->visibleContentRectForPainting());
|
| + EXPECT_TRUE(visualViewport->containerLayer()->masksToBounds());
|
| +
|
| + // Override applies transform, sets visibleContentRect, and disables
|
| + // visual viewport clipping.
|
| + webViewImpl->devToolsEmulator()->setVisualTransformOverride(WebFloatRect(50, 55, 100, 110), 2.f);
|
| + expectedMatrix.makeIdentity().scale(2.f).translate(-50, -55);
|
| + EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting());
|
| + EXPECT_EQ(IntRect(50, 55, 100, 110), frameView->visibleContentRectForPainting());
|
| + EXPECT_FALSE(visualViewport->containerLayer()->masksToBounds());
|
| +
|
| + // Setting new override discards previous one.
|
| + webViewImpl->devToolsEmulator()->setVisualTransformOverride(WebFloatRect(5.4f, 10.5f, 50.4f, 55.5f), 1.5);
|
| + expectedMatrix.makeIdentity().scale(1.5f).translate(-5.4f, -10.5f);
|
| + EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting());
|
| + EXPECT_EQ(IntRect(5, 10, 51, 56), frameView->visibleContentRectForPainting());
|
| + EXPECT_FALSE(visualViewport->containerLayer()->masksToBounds());
|
| +
|
| + // Clearing override restores original transform, visibleContentRect and
|
| + // visual viewport clipping.
|
| + webViewImpl->devToolsEmulator()->clearVisualTransformOverride();
|
| + expectedMatrix.makeIdentity();
|
| + EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting());
|
| + EXPECT_EQ(IntRect(0, 0, 100, 150), frameView->visibleContentRectForPainting());
|
| + EXPECT_TRUE(visualViewport->containerLayer()->masksToBounds());
|
| +}
|
| +
|
| +TEST_F(WebViewTest, VisualTransformOverrideIntegratesDeviceMetricsOffsetAndScale)
|
| +{
|
| + 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));
|
| +
|
| + TransformationMatrix expectedMatrix;
|
| + expectedMatrix.makeIdentity();
|
| + EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting());
|
| +
|
| + WebDeviceEmulationParams emulationParams;
|
| + emulationParams.offset = WebFloatPoint(50, 50);
|
| + emulationParams.scale = 2.f;
|
| + webViewImpl->enableDeviceEmulation(emulationParams);
|
| + expectedMatrix.makeIdentity().translate(50, 50).scale(2.f);
|
| + EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting());
|
| +
|
| + // Device metrics offset and scale are applied before visual transform.
|
| + webViewImpl->devToolsEmulator()->setVisualTransformOverride(WebFloatRect(5, 10, 100, 110), 1.5f);
|
| + expectedMatrix.makeIdentity().scale(1.5f).translate(-5, -10).translate(50, 50).scale(2.f);
|
| + EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting());
|
| +}
|
| +
|
| +TEST_F(WebViewTest, VisualTransformOverrideAdaptsToScaleAndScroll)
|
| +{
|
| + 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));
|
| + FrameView* frameView = webViewImpl->mainFrameImpl()->frame()->view();
|
| +
|
| + TransformationMatrix expectedMatrix;
|
| + expectedMatrix.makeIdentity();
|
| + EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting());
|
| +
|
| + // Initial transform takes current page scale and scroll position into
|
| + // account.
|
| + webViewImpl->setPageScaleFactor(1.5f);
|
| + frameView->setScrollPosition(DoublePoint(100, 150), ProgrammaticScroll, ScrollBehaviorInstant);
|
| + webViewImpl->devToolsEmulator()->setVisualTransformOverride(WebFloatRect(50, 55, 100, 110), 2.f);
|
| + expectedMatrix.makeIdentity().scale(2.f).translate(-50, -55).translate(100, 150).scale(1. / 1.5f);
|
| + EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting());
|
| + // Scroll and scale are irrelevant for visibleContentRect.
|
| + EXPECT_EQ(IntRect(50, 55, 100, 110), frameView->visibleContentRectForPainting());
|
| +
|
| + // Transform adapts to scroll changes.
|
| + frameView->setScrollPosition(DoublePoint(50, 55), ProgrammaticScroll, ScrollBehaviorInstant);
|
| + expectedMatrix.makeIdentity().scale(2.f).translate(-50, -55).translate(50, 55).scale(1. / 1.5f);
|
| + EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting());
|
| + // visibleContentRect doesn't change.
|
| + EXPECT_EQ(IntRect(50, 55, 100, 110), frameView->visibleContentRectForPainting());
|
| +
|
| + // Transform adapts to page scale changes.
|
| + webViewImpl->setPageScaleFactor(2.f);
|
| + expectedMatrix.makeIdentity().scale(2.f).translate(-50, -55).translate(50, 55).scale(1. / 2.f);
|
| + EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting());
|
| + // visibleContentRect doesn't change.
|
| + EXPECT_EQ(IntRect(50, 55, 100, 110), frameView->visibleContentRectForPainting());
|
| +}
|
| +
|
| } // namespace blink
|
|
|