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

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

Issue 2697683004: Add automated testing to check for page size with scaling (Closed)
Patch Set: Fix git cl format issue 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
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..c6001bb26901ec1f4a19d88c1efce3e7e816d7e2 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"
@@ -224,6 +225,26 @@ class PrintWebViewHelperTestBase : public content::RenderViewTest {
}
}
+ // Verifies whether the pages printed and, if on Windows, that the
+ // correct page size was returned.
+ void VerifyPagesPrintedWithSize(bool printed, gfx::Size page_size) {
+ const IPC::Message* print_msg =
+ render_thread_->sink().GetUniqueMessageMatching(
+ PrintHostMsg_DidPrintPage::ID);
+ bool did_print_msg = !!print_msg;
+ ASSERT_EQ(printed, did_print_msg);
+ if (printed) {
+ PrintHostMsg_DidPrintPage::Param post_did_print_page_param;
+ PrintHostMsg_DidPrintPage::Read(print_msg, &post_did_print_page_param);
+#if defined(OS_WIN)
+ gfx::Size page_size_received =
Lei Zhang 2017/02/22 21:21:38 Can this be a separate VerifyPrintedPageSize() fun
rbpotter 2017/02/23 22:27:11 Done.
Lei Zhang 2017/02/23 23:13:54 Looking at the code again, did patch set 3 get wri
+ std::get<0>(post_did_print_page_param).page_size;
+ EXPECT_EQ(page_size_received.height(), page_size.height());
Lei Zhang 2017/02/22 21:21:38 EXPECT_EQ(expected, actual) -> the arguments passe
rbpotter 2017/02/23 22:27:14 Done.
+ EXPECT_EQ(page_size_received.width(), page_size.width());
+#endif
+ }
+ }
+
#if BUILDFLAG(ENABLE_BASIC_PRINTING)
void OnPrintPages() {
GetPrintWebViewHelper()->OnPrintPages();
@@ -971,6 +992,38 @@ TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintForPrintPreview) {
VerifyPagesPrinted(true);
}
+// Tests that when printing non default scaling values the page size returned
Lei Zhang 2017/02/22 21:21:38 non-default comma after values
rbpotter 2017/02/23 22:27:14 Done.
+// 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, 240);
Lei Zhang 2017/02/22 21:21:38 Maybe pick different values for width/height?
rbpotter 2017/02/23 22:27:13 Done.
+ float deviceMicronsPerUnit =
+ (printing::kHundrethsMMPerInch * 10.0f) / printing::kDefaultPdfDpi;
+ int height_microns =
+ static_cast<int>(page_size_in.height() * deviceMicronsPerUnit);
+ int width_microns =
+ static_cast<int>(page_size_in.width() * deviceMicronsPerUnit);
+ base::DictionaryValue* mediaSize = new base::DictionaryValue;
Lei Zhang 2017/02/22 21:21:38 auto dict = base::MakeUnique<base::DictionaryValue
rbpotter 2017/02/23 22:27:13 Done.
+ mediaSize->SetInteger(kSettingMediaSizeHeightMicrons, height_microns);
+ mediaSize->SetInteger(kSettingMediaSizeWidthMicrons, width_microns);
+
+ // Non default scaling value
+ dict.SetInteger(kSettingScaleFactor, 80);
+ dict.Set(kSettingMediaSize, mediaSize);
+
+ OnPrintForPrintPreview(dict);
+
+ VerifyPrintFailed(false);
+ VerifyPagesPrintedWithSize(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) {

Powered by Google App Engine
This is Rietveld 408576698