Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Unified Diff: third_party/WebKit/Source/web/tests/WebViewTest.cpp

Issue 2643903002: Fix viewport unit sizes when printing. (Closed)
Patch Set: Fix comment Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/frame/FrameView.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..5ceb8a0af3a7fcb129e091edcb8fa8c6dc1c0e98 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; }"
+ " #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;
+
+ // The expected layout size comes from the calculation done in
+ // 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());
}
« no previous file with comments | « third_party/WebKit/Source/core/frame/FrameView.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698