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 d7498f94b31474e3f761fd9045bfae3f56f11f4a..2b2b769d2b7c2b09964234891e4a452927a9b3a5 100644 |
--- a/third_party/WebKit/Source/web/tests/WebViewTest.cpp |
+++ b/third_party/WebKit/Source/web/tests/WebViewTest.cpp |
@@ -46,6 +46,7 @@ |
#include "core/html/HTMLInputElement.h" |
#include "core/html/HTMLTextAreaElement.h" |
#include "core/layout/api/LayoutViewItem.h" |
+#include "core/layout/compositing/PaintLayerCompositor.h" |
#include "core/loader/DocumentLoader.h" |
#include "core/loader/FrameLoadRequest.h" |
#include "core/page/Page.h" |
@@ -4256,4 +4257,89 @@ TEST_F(WebViewTest, ViewportOverrideAdaptsToScaleAndScroll) { |
*devToolsEmulator->visibleContentRectForPainting()); |
} |
+static void configureAndroidCompositing(WebSettings* settings) { |
+ settings->setAcceleratedCompositingEnabled(true); |
+ settings->setPreferCompositingToLCDTextEnabled(true); |
+ settings->setViewportMetaEnabled(true); |
+ settings->setViewportEnabled(true); |
+ settings->setMainFrameResizesAreOrientationChanges(true); |
+ settings->setShrinksViewportContentToFit(true); |
+} |
+ |
+TEST_F(WebViewTest, ResizeCompositedAndFixedBackground) { |
flackr
2016/10/31 18:17:55
We should test with/without root layer scrolls rig
bokan
2016/11/01 20:27:58
Good point, I've moved this to VisualViewportTest
|
+ bool originalInertTopControls = |
+ RuntimeEnabledFeatures::inertTopControlsEnabled(); |
+ RuntimeEnabledFeatures::setInertTopControlsEnabled(true); |
+ |
+ std::unique_ptr<FrameTestHelpers::TestWebViewClient> |
+ fakeCompositingWebViewClient = |
+ wrapUnique(new FrameTestHelpers::TestWebViewClient()); |
+ FrameTestHelpers::WebViewHelper webViewHelper; |
+ WebViewImpl* webViewImpl = webViewHelper.initialize( |
+ true, nullptr, fakeCompositingWebViewClient.get(), nullptr, |
+ &configureAndroidCompositing); |
+ |
+ int pageWidth = 640; |
+ int pageHeight = 480; |
+ float browserControlsHeight = 50.0f; |
+ int smallestHeight = pageHeight - browserControlsHeight; |
+ |
+ webViewImpl->resizeWithBrowserControls(WebSize(pageWidth, pageHeight), |
+ browserControlsHeight, false); |
+ |
+ URLTestHelpers::registerMockedURLLoad(toKURL("http://example.com/foo.png"), |
+ "white-1x1.png"); |
+ WebURL baseURL = URLTestHelpers::toKURL("http://example.com/"); |
+ FrameTestHelpers::loadHTMLString(webViewImpl->mainFrame(), |
+ "<!DOCTYPE html>" |
+ "<style>" |
+ " body {" |
+ " background: url('foo.png');" |
+ " background-attachment: fixed;" |
+ " background-size: cover;" |
+ " background-repeat: no-repeat;" |
+ " }" |
+ " div { height:1000px; width: 200px; }" |
+ "</style>" |
+ "<div></div>", |
+ baseURL); |
+ webViewImpl->updateAllLifecyclePhases(); |
+ |
+ Document* document = |
+ toLocalFrame(webViewImpl->page()->mainFrame())->document(); |
+ PaintLayerCompositor* compositor = document->layoutView()->compositor(); |
+ |
+ ASSERT_TRUE(compositor->needsFixedRootBackgroundLayer( |
+ document->layoutView()->layer())); |
+ ASSERT_TRUE(compositor->fixedRootBackgroundLayer()); |
+ |
+ ASSERT_EQ(pageWidth, compositor->fixedRootBackgroundLayer()->size().width()); |
+ ASSERT_EQ(pageHeight, |
+ compositor->fixedRootBackgroundLayer()->size().height()); |
+ ASSERT_EQ(pageWidth, document->view()->layoutSize().width()); |
+ ASSERT_EQ(smallestHeight, document->view()->layoutSize().height()); |
+ |
+ webViewImpl->resizeWithBrowserControls(WebSize(pageWidth, smallestHeight), |
+ browserControlsHeight, true); |
+ |
+ // The layout size should not have changed. |
+ ASSERT_EQ(pageWidth, document->view()->layoutSize().width()); |
+ ASSERT_EQ(smallestHeight, document->view()->layoutSize().height()); |
+ |
+ // The background layer's size should have changed though. |
+ EXPECT_EQ(pageWidth, compositor->fixedRootBackgroundLayer()->size().width()); |
+ EXPECT_EQ(smallestHeight, |
+ compositor->fixedRootBackgroundLayer()->size().height()); |
flackr
2016/10/31 18:17:55
Is the invalidation tested?
bokan
2016/11/01 20:27:58
I figured out how to test invalidations. Added a s
|
+ |
+ webViewImpl->resizeWithBrowserControls(WebSize(pageWidth, pageHeight), |
+ browserControlsHeight, true); |
+ |
+ // The background layer's size should change again. |
+ EXPECT_EQ(pageWidth, compositor->fixedRootBackgroundLayer()->size().width()); |
+ EXPECT_EQ(pageHeight, |
+ compositor->fixedRootBackgroundLayer()->size().height()); |
+ |
+ RuntimeEnabledFeatures::setInertTopControlsEnabled(originalInertTopControls); |
+} |
+ |
} // namespace blink |