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

Unified Diff: components/printing/test/print_web_view_helper_browsertest.cc

Issue 2719443003: Reland of Add automated testing to check for page size with scaling (Closed)
Patch Set: Created 3 years, 10 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 | « components/printing/test/print_mock_render_thread.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..ce387743716eb760f925e1ae8b5d3768f6d6b26c 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"
@@ -209,6 +210,20 @@
EXPECT_EQ(count, std::get<0>(post_page_count_param).page_count);
}
#endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
+
+#if defined(OS_WIN)
+ // Verifies that the correct page size was returned.
+ void VerifyPrintedPageSize(const gfx::Size& page_size) {
+ const IPC::Message* print_msg =
+ render_thread_->sink().GetUniqueMessageMatching(
+ PrintHostMsg_DidPrintPage::ID);
+ PrintHostMsg_DidPrintPage::Param post_did_print_page_param;
+ PrintHostMsg_DidPrintPage::Read(print_msg, &post_did_print_page_param);
+ gfx::Size page_size_received =
+ std::get<0>(post_did_print_page_param).page_size;
+ EXPECT_EQ(page_size, page_size_received);
+ }
+#endif
// Verifies whether the pages printed or not.
void VerifyPagesPrinted(bool printed) {
@@ -971,6 +986,41 @@
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);
+#if defined(OS_WIN)
+ VerifyPrintedPageSize(page_size_in);
+#endif
+}
+
// Tests that printing from print preview fails and receiving error messages
// through that channel all works.
TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintForPrintPreviewFail) {
« no previous file with comments | « components/printing/test/print_mock_render_thread.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698