Chromium Code Reviews| Index: components/printing/test/print_web_view_helper_browsertest.cc |
| diff --git a/components/printing/test/print_web_view_helper_browsertest.cc b/components/printing/test/print_web_view_helper_browsertest.cc |
| index 279ae825f41acee18f4b86ca53c553085a9ae2ba..515a4e762ef1dfc1bf0e9510c7046a344073cc63 100644 |
| --- a/components/printing/test/print_web_view_helper_browsertest.cc |
| +++ b/components/printing/test/print_web_view_helper_browsertest.cc |
| @@ -24,6 +24,7 @@ |
| #include "ipc/ipc_listener.h" |
| #include "printing/features/features.h" |
| #include "printing/print_job_constants.h" |
| +#include "printing/units.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "third_party/WebKit/public/platform/WebMouseEvent.h" |
| #include "third_party/WebKit/public/platform/WebString.h" |
| @@ -210,8 +211,20 @@ class PrintWebViewHelperTestBase : public content::RenderViewTest { |
| } |
| #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| +#if defined(OS_WIN) |
| + // Verifies that the correct page size was returned. |
| + void VerifyPrintedPageSize( |
| + gfx::Size page_size, |
|
Lei Zhang
2017/02/23 23:13:54
One more pass by const ref.
rbpotter
2017/02/24 00:34:27
Done.
|
| + PrintHostMsg_DidPrintPage::Param post_did_print_page_param) { |
|
Lei Zhang
2017/02/23 23:13:54
Make that 2?
rbpotter
2017/02/24 00:34:28
Done.
|
| + gfx::Size page_size_received = |
| + std::get<0>(post_did_print_page_param).page_size; |
| + EXPECT_EQ(page_size.height(), page_size_received.height()); |
|
Lei Zhang
2017/02/23 23:13:54
Fun fact, gfx::Size integrates well with gtest. As
rbpotter
2017/02/24 00:34:27
Done.
|
| + EXPECT_EQ(page_size.width(), page_size_received.width()); |
| + } |
| +#endif |
| + |
| // Verifies whether the pages printed or not. |
| - void VerifyPagesPrinted(bool printed) { |
| + void VerifyPagesPrinted(bool printed, gfx::Size page_size = gfx::Size(0, 0)) { |
| const IPC::Message* print_msg = |
| render_thread_->sink().GetUniqueMessageMatching( |
| PrintHostMsg_DidPrintPage::ID); |
| @@ -221,6 +234,10 @@ class PrintWebViewHelperTestBase : public content::RenderViewTest { |
| PrintHostMsg_DidPrintPage::Param post_did_print_page_param; |
| PrintHostMsg_DidPrintPage::Read(print_msg, &post_did_print_page_param); |
| EXPECT_EQ(0, std::get<0>(post_did_print_page_param).page_number); |
| +#if defined(OS_WIN) |
| + if (!page_size.IsEmpty()) |
| + VerifyPrintedPageSize(page_size, post_did_print_page_param); |
| +#endif |
| } |
| } |
| @@ -971,6 +988,38 @@ TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintForPrintPreview) { |
| VerifyPagesPrinted(true); |
| } |
| +// Tests that when printing non-default scaling values, the page size returned |
| +// by PrintWebViewHelper is still the real physical page size. See |
| +// crbug.com/686384 |
| +TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintForPrintPreviewWithScaling) { |
| + LoadHTML(kPrintPreviewHTML); |
| + |
| + // Fill in some dummy values. |
| + base::DictionaryValue dict; |
| + CreatePrintSettingsDictionary(&dict); |
| + |
| + // Media size |
| + gfx::Size page_size_in = gfx::Size(240, 480); |
| + float device_microns_per_unit = |
| + (printing::kHundrethsMMPerInch * 10.0f) / printing::kDefaultPdfDpi; |
| + int height_microns = |
| + static_cast<int>(page_size_in.height() * device_microns_per_unit); |
| + int width_microns = |
| + static_cast<int>(page_size_in.width() * device_microns_per_unit); |
| + auto media_size = base::MakeUnique<base::DictionaryValue>(); |
| + media_size->SetInteger(kSettingMediaSizeHeightMicrons, height_microns); |
| + media_size->SetInteger(kSettingMediaSizeWidthMicrons, width_microns); |
| + |
| + // Non default scaling value |
| + dict.SetInteger(kSettingScaleFactor, 80); |
| + dict.Set(kSettingMediaSize, media_size.release()); |
| + |
| + OnPrintForPrintPreview(dict); |
| + |
| + VerifyPrintFailed(false); |
| + VerifyPagesPrinted(true, page_size_in); |
| +} |
| + |
| // Tests that printing from print preview fails and receiving error messages |
| // through that channel all works. |
| TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintForPrintPreviewFail) { |