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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/frame/FrameView.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 4317 matching lines...) Expand 10 before | Expand all | Expand 10 after
4328 EXPECT_EQ(IntRect(50, 55, 50, 75), 4328 EXPECT_EQ(IntRect(50, 55, 50, 75),
4329 *devToolsEmulator->visibleContentRectForPainting()); 4329 *devToolsEmulator->visibleContentRectForPainting());
4330 } 4330 }
4331 4331
4332 TEST_P(WebViewTest, ResizeForPrintingViewportUnits) { 4332 TEST_P(WebViewTest, ResizeForPrintingViewportUnits) {
4333 WebViewImpl* webView = m_webViewHelper.initialize(); 4333 WebViewImpl* webView = m_webViewHelper.initialize();
4334 webView->resize(WebSize(800, 600)); 4334 webView->resize(WebSize(800, 600));
4335 4335
4336 WebURL baseURL = URLTestHelpers::toKURL("http://example.com/"); 4336 WebURL baseURL = URLTestHelpers::toKURL("http://example.com/");
4337 FrameTestHelpers::loadHTMLString(webView->mainFrame(), 4337 FrameTestHelpers::loadHTMLString(webView->mainFrame(),
4338 "<style>#vw { width: 100vw }</style>" 4338 "<style>"
4339 " body { margin: 0px; }"
4340 " #vw { width: 100vw; height: 100vh; }"
4341 "</style>"
4339 "<div id=vw></div>", 4342 "<div id=vw></div>",
4340 baseURL); 4343 baseURL);
4341 4344
4342 WebLocalFrameImpl* frame = webView->mainFrameImpl(); 4345 WebLocalFrameImpl* frame = webView->mainFrameImpl();
4343 Document* document = frame->frame()->document(); 4346 Document* document = frame->frame()->document();
4344 Element* vwElement = document->getElementById("vw"); 4347 Element* vwElement = document->getElementById("vw");
4345 4348
4346 EXPECT_EQ(800, vwElement->offsetWidth()); 4349 EXPECT_EQ(800, vwElement->offsetWidth());
4347 4350
4351 FloatSize pageSize(300, 360);
4352
4348 WebPrintParams printParams; 4353 WebPrintParams printParams;
4349 printParams.printContentArea.width = 500; 4354 printParams.printContentArea.width = pageSize.width();
4350 printParams.printContentArea.height = 500; 4355 printParams.printContentArea.height = pageSize.height();
4356
4357 // This needs to match printingMinimumShrinkFactor in PrintContext.cpp. The
4358 // layout is scaled by this factor for printing.
4359 constexpr float minimumShrinkFactor = 1.333f;
4360
4361 // The expected layout size comes from the calculation done in
4362 // resizePageRectsKeepingRatio which is used from PrintContext::begin to
4363 // scale the page size.
4364 const float ratio = pageSize.height() / (float)pageSize.width();
4365 const int expectedWidth = floor(pageSize.width() * minimumShrinkFactor);
4366 const int expectedHeight = floor(expectedWidth * ratio);
4351 4367
4352 frame->printBegin(printParams, WebNode()); 4368 frame->printBegin(printParams, WebNode());
4353 webView->resize(WebSize(500, 500)); 4369
4354 EXPECT_EQ(500, vwElement->offsetWidth()); 4370 EXPECT_EQ(expectedWidth, vwElement->offsetWidth());
4371 EXPECT_EQ(expectedHeight, vwElement->offsetHeight());
4372
4373 webView->resize(flooredIntSize(pageSize));
4374
4375 EXPECT_EQ(expectedWidth, vwElement->offsetWidth());
4376 EXPECT_EQ(expectedHeight, vwElement->offsetHeight());
4355 4377
4356 webView->resize(WebSize(800, 600)); 4378 webView->resize(WebSize(800, 600));
4357 frame->printEnd(); 4379 frame->printEnd();
4380
4358 EXPECT_EQ(800, vwElement->offsetWidth()); 4381 EXPECT_EQ(800, vwElement->offsetWidth());
4359 } 4382 }
4360 4383
4361 } // namespace blink 4384 } // namespace blink
OLDNEW
« 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