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

Side by Side 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, 9 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 | « components/printing/test/print_mock_render_thread.cc ('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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/printing/renderer/print_web_view_helper.h" 5 #include "components/printing/renderer/print_web_view_helper.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <tuple> 10 #include <tuple>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "build/build_config.h" 16 #include "build/build_config.h"
17 #include "components/printing/common/print_messages.h" 17 #include "components/printing/common/print_messages.h"
18 #include "components/printing/test/mock_printer.h" 18 #include "components/printing/test/mock_printer.h"
19 #include "components/printing/test/print_mock_render_thread.h" 19 #include "components/printing/test/print_mock_render_thread.h"
20 #include "components/printing/test/print_test_content_renderer_client.h" 20 #include "components/printing/test/print_test_content_renderer_client.h"
21 #include "content/public/renderer/render_frame.h" 21 #include "content/public/renderer/render_frame.h"
22 #include "content/public/renderer/render_view.h" 22 #include "content/public/renderer/render_view.h"
23 #include "content/public/test/render_view_test.h" 23 #include "content/public/test/render_view_test.h"
24 #include "ipc/ipc_listener.h" 24 #include "ipc/ipc_listener.h"
25 #include "printing/features/features.h" 25 #include "printing/features/features.h"
26 #include "printing/print_job_constants.h" 26 #include "printing/print_job_constants.h"
27 #include "printing/units.h"
27 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
28 #include "third_party/WebKit/public/platform/WebMouseEvent.h" 29 #include "third_party/WebKit/public/platform/WebMouseEvent.h"
29 #include "third_party/WebKit/public/platform/WebString.h" 30 #include "third_party/WebKit/public/platform/WebString.h"
30 #include "third_party/WebKit/public/web/WebLocalFrame.h" 31 #include "third_party/WebKit/public/web/WebLocalFrame.h"
31 #include "third_party/WebKit/public/web/WebRange.h" 32 #include "third_party/WebKit/public/web/WebRange.h"
32 #include "third_party/WebKit/public/web/WebView.h" 33 #include "third_party/WebKit/public/web/WebView.h"
33 34
34 #if defined(OS_WIN) || defined(OS_MACOSX) 35 #if defined(OS_WIN) || defined(OS_MACOSX)
35 #include "base/files/file_util.h" 36 #include "base/files/file_util.h"
36 #include "printing/image.h" 37 #include "printing/image.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 render_thread_->sink().GetUniqueMessageMatching( 204 render_thread_->sink().GetUniqueMessageMatching(
204 PrintHostMsg_DidGetPreviewPageCount::ID); 205 PrintHostMsg_DidGetPreviewPageCount::ID);
205 ASSERT_TRUE(page_cnt_msg); 206 ASSERT_TRUE(page_cnt_msg);
206 PrintHostMsg_DidGetPreviewPageCount::Param post_page_count_param; 207 PrintHostMsg_DidGetPreviewPageCount::Param post_page_count_param;
207 PrintHostMsg_DidGetPreviewPageCount::Read(page_cnt_msg, 208 PrintHostMsg_DidGetPreviewPageCount::Read(page_cnt_msg,
208 &post_page_count_param); 209 &post_page_count_param);
209 EXPECT_EQ(count, std::get<0>(post_page_count_param).page_count); 210 EXPECT_EQ(count, std::get<0>(post_page_count_param).page_count);
210 } 211 }
211 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) 212 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
212 213
214 #if defined(OS_WIN)
215 // Verifies that the correct page size was returned.
216 void VerifyPrintedPageSize(const gfx::Size& page_size) {
217 const IPC::Message* print_msg =
218 render_thread_->sink().GetUniqueMessageMatching(
219 PrintHostMsg_DidPrintPage::ID);
220 PrintHostMsg_DidPrintPage::Param post_did_print_page_param;
221 PrintHostMsg_DidPrintPage::Read(print_msg, &post_did_print_page_param);
222 gfx::Size page_size_received =
223 std::get<0>(post_did_print_page_param).page_size;
224 EXPECT_EQ(page_size, page_size_received);
225 }
226 #endif
227
213 // Verifies whether the pages printed or not. 228 // Verifies whether the pages printed or not.
214 void VerifyPagesPrinted(bool printed) { 229 void VerifyPagesPrinted(bool printed) {
215 const IPC::Message* print_msg = 230 const IPC::Message* print_msg =
216 render_thread_->sink().GetUniqueMessageMatching( 231 render_thread_->sink().GetUniqueMessageMatching(
217 PrintHostMsg_DidPrintPage::ID); 232 PrintHostMsg_DidPrintPage::ID);
218 bool did_print_msg = !!print_msg; 233 bool did_print_msg = !!print_msg;
219 ASSERT_EQ(printed, did_print_msg); 234 ASSERT_EQ(printed, did_print_msg);
220 if (printed) { 235 if (printed) {
221 PrintHostMsg_DidPrintPage::Param post_did_print_page_param; 236 PrintHostMsg_DidPrintPage::Param post_did_print_page_param;
222 PrintHostMsg_DidPrintPage::Read(print_msg, &post_did_print_page_param); 237 PrintHostMsg_DidPrintPage::Read(print_msg, &post_did_print_page_param);
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 979
965 // Fill in some dummy values. 980 // Fill in some dummy values.
966 base::DictionaryValue dict; 981 base::DictionaryValue dict;
967 CreatePrintSettingsDictionary(&dict); 982 CreatePrintSettingsDictionary(&dict);
968 OnPrintForPrintPreview(dict); 983 OnPrintForPrintPreview(dict);
969 984
970 VerifyPrintFailed(false); 985 VerifyPrintFailed(false);
971 VerifyPagesPrinted(true); 986 VerifyPagesPrinted(true);
972 } 987 }
973 988
989 // Tests that when printing non-default scaling values, the page size returned
990 // by PrintWebViewHelper is still the real physical page size. See
991 // crbug.com/686384
992 TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintForPrintPreviewWithScaling) {
993 LoadHTML(kPrintPreviewHTML);
994
995 // Fill in some dummy values.
996 base::DictionaryValue dict;
997 CreatePrintSettingsDictionary(&dict);
998
999 // Media size
1000 gfx::Size page_size_in = gfx::Size(240, 480);
1001 float device_microns_per_unit =
1002 (printing::kHundrethsMMPerInch * 10.0f) / printing::kDefaultPdfDpi;
1003 int height_microns =
1004 static_cast<int>(page_size_in.height() * device_microns_per_unit);
1005 int width_microns =
1006 static_cast<int>(page_size_in.width() * device_microns_per_unit);
1007 auto media_size = base::MakeUnique<base::DictionaryValue>();
1008 media_size->SetInteger(kSettingMediaSizeHeightMicrons, height_microns);
1009 media_size->SetInteger(kSettingMediaSizeWidthMicrons, width_microns);
1010
1011 // Non default scaling value
1012 dict.SetInteger(kSettingScaleFactor, 80);
1013 dict.Set(kSettingMediaSize, media_size.release());
1014
1015 OnPrintForPrintPreview(dict);
1016
1017 VerifyPrintFailed(false);
1018 VerifyPagesPrinted(true);
1019 #if defined(OS_WIN)
1020 VerifyPrintedPageSize(page_size_in);
1021 #endif
1022 }
1023
974 // Tests that printing from print preview fails and receiving error messages 1024 // Tests that printing from print preview fails and receiving error messages
975 // through that channel all works. 1025 // through that channel all works.
976 TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintForPrintPreviewFail) { 1026 TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintForPrintPreviewFail) {
977 LoadHTML(kPrintPreviewHTML); 1027 LoadHTML(kPrintPreviewHTML);
978 1028
979 // An empty dictionary should fail. 1029 // An empty dictionary should fail.
980 base::DictionaryValue empty_dict; 1030 base::DictionaryValue empty_dict;
981 OnPrintForPrintPreview(empty_dict); 1031 OnPrintForPrintPreview(empty_dict);
982 1032
983 VerifyPagesPrinted(false); 1033 VerifyPagesPrinted(false);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 1112
1063 VerifyPrintFailed(true); 1113 VerifyPrintFailed(true);
1064 VerifyPagesPrinted(false); 1114 VerifyPagesPrinted(false);
1065 } 1115 }
1066 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) 1116 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING)
1067 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) 1117 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
1068 1118
1069 #endif // !defined(OS_CHROMEOS) 1119 #endif // !defined(OS_CHROMEOS)
1070 1120
1071 } // namespace printing 1121 } // namespace printing
OLDNEW
« 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