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 7929d8fa3fbaa57806c46da6e1ada59c298b7280..d911b4fffccd054e24371773a90b4088ab3dc78e 100644 |
| --- a/third_party/WebKit/Source/web/tests/WebViewTest.cpp |
| +++ b/third_party/WebKit/Source/web/tests/WebViewTest.cpp |
| @@ -4335,7 +4335,10 @@ TEST_P(WebViewTest, ResizeForPrintingViewportUnits) { |
| WebURL baseURL = URLTestHelpers::toKURL("http://example.com/"); |
| FrameTestHelpers::loadHTMLString(webView->mainFrame(), |
| - "<style>#vw { width: 100vw }</style>" |
| + "<style>" |
| + " body { margin: 0px; }" |
|
rune
2017/01/19 08:59:24
This one's here to avoid #vw overflowing the page,
bokan
2017/01/19 16:26:35
It's to make the calculation more straightforwardl
|
| + " #vw { width: 100vw; height: 100vh; }" |
| + "</style>" |
| "<div id=vw></div>", |
| baseURL); |
| @@ -4345,16 +4348,36 @@ TEST_P(WebViewTest, ResizeForPrintingViewportUnits) { |
| EXPECT_EQ(800, vwElement->offsetWidth()); |
| + FloatSize pageSize(300, 360); |
| + |
| WebPrintParams printParams; |
| - printParams.printContentArea.width = 500; |
| - printParams.printContentArea.height = 500; |
| + printParams.printContentArea.width = pageSize.width(); |
| + printParams.printContentArea.height = pageSize.height(); |
| + |
| + // This needs to match printingMinimumShrinkFactor in PrintContext.cpp. The |
| + // layout is scaled by this factor for printing. |
| + constexpr float minimumShrinkFactor = 1.333f; |
|
rune
2017/01/19 08:59:24
Would be nice to have a common constant. But then
bokan
2017/01/19 16:26:35
Acknowledged.
|
| + |
| + // The expcted layout size comes from the calculation done in |
|
rune
2017/01/19 08:59:24
expcted -> expected
bokan
2017/01/19 16:26:35
Done.
|
| + // resizePageRectsKeepingRatio which is used from PrintContext::begin to |
| + // scale the page size. |
| + const float ratio = pageSize.height() / (float)pageSize.width(); |
| + const int expectedWidth = floor(pageSize.width() * minimumShrinkFactor); |
| + const int expectedHeight = floor(expectedWidth * ratio); |
| frame->printBegin(printParams, WebNode()); |
| - webView->resize(WebSize(500, 500)); |
| - EXPECT_EQ(500, vwElement->offsetWidth()); |
| + |
| + EXPECT_EQ(expectedWidth, vwElement->offsetWidth()); |
| + EXPECT_EQ(expectedHeight, vwElement->offsetHeight()); |
| + |
| + webView->resize(flooredIntSize(pageSize)); |
| + |
| + EXPECT_EQ(expectedWidth, vwElement->offsetWidth()); |
| + EXPECT_EQ(expectedHeight, vwElement->offsetHeight()); |
| webView->resize(WebSize(800, 600)); |
| frame->printEnd(); |
| + |
| EXPECT_EQ(800, vwElement->offsetWidth()); |
| } |