Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 PrintHostMsg_DidPrintPage::ID); | 218 PrintHostMsg_DidPrintPage::ID); |
| 218 bool did_print_msg = !!print_msg; | 219 bool did_print_msg = !!print_msg; |
| 219 ASSERT_EQ(printed, did_print_msg); | 220 ASSERT_EQ(printed, did_print_msg); |
| 220 if (printed) { | 221 if (printed) { |
| 221 PrintHostMsg_DidPrintPage::Param post_did_print_page_param; | 222 PrintHostMsg_DidPrintPage::Param post_did_print_page_param; |
| 222 PrintHostMsg_DidPrintPage::Read(print_msg, &post_did_print_page_param); | 223 PrintHostMsg_DidPrintPage::Read(print_msg, &post_did_print_page_param); |
| 223 EXPECT_EQ(0, std::get<0>(post_did_print_page_param).page_number); | 224 EXPECT_EQ(0, std::get<0>(post_did_print_page_param).page_number); |
| 224 } | 225 } |
| 225 } | 226 } |
| 226 | 227 |
| 228 // Verifies whether the pages printed and, if on Windows, that the | |
| 229 // correct page size was returned. | |
| 230 void VerifyPagesPrintedWithSize(bool printed, gfx::Size page_size) { | |
| 231 const IPC::Message* print_msg = | |
| 232 render_thread_->sink().GetUniqueMessageMatching( | |
| 233 PrintHostMsg_DidPrintPage::ID); | |
| 234 bool did_print_msg = !!print_msg; | |
| 235 ASSERT_EQ(printed, did_print_msg); | |
| 236 if (printed) { | |
| 237 PrintHostMsg_DidPrintPage::Param post_did_print_page_param; | |
| 238 PrintHostMsg_DidPrintPage::Read(print_msg, &post_did_print_page_param); | |
| 239 #if defined(OS_WIN) | |
| 240 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
| |
| 241 std::get<0>(post_did_print_page_param).page_size; | |
| 242 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.
| |
| 243 EXPECT_EQ(page_size_received.width(), page_size.width()); | |
| 244 #endif | |
| 245 } | |
| 246 } | |
| 247 | |
| 227 #if BUILDFLAG(ENABLE_BASIC_PRINTING) | 248 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
| 228 void OnPrintPages() { | 249 void OnPrintPages() { |
| 229 GetPrintWebViewHelper()->OnPrintPages(); | 250 GetPrintWebViewHelper()->OnPrintPages(); |
| 230 ProcessPendingMessages(); | 251 ProcessPendingMessages(); |
| 231 } | 252 } |
| 232 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) | 253 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) |
| 233 | 254 |
| 234 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) | 255 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 235 void VerifyPreviewRequest(bool requested) { | 256 void VerifyPreviewRequest(bool requested) { |
| 236 const IPC::Message* print_msg = | 257 const IPC::Message* print_msg = |
| (...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 964 | 985 |
| 965 // Fill in some dummy values. | 986 // Fill in some dummy values. |
| 966 base::DictionaryValue dict; | 987 base::DictionaryValue dict; |
| 967 CreatePrintSettingsDictionary(&dict); | 988 CreatePrintSettingsDictionary(&dict); |
| 968 OnPrintForPrintPreview(dict); | 989 OnPrintForPrintPreview(dict); |
| 969 | 990 |
| 970 VerifyPrintFailed(false); | 991 VerifyPrintFailed(false); |
| 971 VerifyPagesPrinted(true); | 992 VerifyPagesPrinted(true); |
| 972 } | 993 } |
| 973 | 994 |
| 995 // 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.
| |
| 996 // by PrintWebViewHelper is still the real physical page size. See | |
| 997 // crbug.com/686384 | |
| 998 TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintForPrintPreviewWithScaling) { | |
| 999 LoadHTML(kPrintPreviewHTML); | |
| 1000 | |
| 1001 // Fill in some dummy values. | |
| 1002 base::DictionaryValue dict; | |
| 1003 CreatePrintSettingsDictionary(&dict); | |
| 1004 | |
| 1005 // Media size | |
| 1006 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.
| |
| 1007 float deviceMicronsPerUnit = | |
| 1008 (printing::kHundrethsMMPerInch * 10.0f) / printing::kDefaultPdfDpi; | |
| 1009 int height_microns = | |
| 1010 static_cast<int>(page_size_in.height() * deviceMicronsPerUnit); | |
| 1011 int width_microns = | |
| 1012 static_cast<int>(page_size_in.width() * deviceMicronsPerUnit); | |
| 1013 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.
| |
| 1014 mediaSize->SetInteger(kSettingMediaSizeHeightMicrons, height_microns); | |
| 1015 mediaSize->SetInteger(kSettingMediaSizeWidthMicrons, width_microns); | |
| 1016 | |
| 1017 // Non default scaling value | |
| 1018 dict.SetInteger(kSettingScaleFactor, 80); | |
| 1019 dict.Set(kSettingMediaSize, mediaSize); | |
| 1020 | |
| 1021 OnPrintForPrintPreview(dict); | |
| 1022 | |
| 1023 VerifyPrintFailed(false); | |
| 1024 VerifyPagesPrintedWithSize(true, page_size_in); | |
| 1025 } | |
| 1026 | |
| 974 // Tests that printing from print preview fails and receiving error messages | 1027 // Tests that printing from print preview fails and receiving error messages |
| 975 // through that channel all works. | 1028 // through that channel all works. |
| 976 TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintForPrintPreviewFail) { | 1029 TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintForPrintPreviewFail) { |
| 977 LoadHTML(kPrintPreviewHTML); | 1030 LoadHTML(kPrintPreviewHTML); |
| 978 | 1031 |
| 979 // An empty dictionary should fail. | 1032 // An empty dictionary should fail. |
| 980 base::DictionaryValue empty_dict; | 1033 base::DictionaryValue empty_dict; |
| 981 OnPrintForPrintPreview(empty_dict); | 1034 OnPrintForPrintPreview(empty_dict); |
| 982 | 1035 |
| 983 VerifyPagesPrinted(false); | 1036 VerifyPagesPrinted(false); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1062 | 1115 |
| 1063 VerifyPrintFailed(true); | 1116 VerifyPrintFailed(true); |
| 1064 VerifyPagesPrinted(false); | 1117 VerifyPagesPrinted(false); |
| 1065 } | 1118 } |
| 1066 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) | 1119 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) |
| 1067 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) | 1120 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 1068 | 1121 |
| 1069 #endif // !defined(OS_CHROMEOS) | 1122 #endif // !defined(OS_CHROMEOS) |
| 1070 | 1123 |
| 1071 } // namespace printing | 1124 } // namespace printing |
| OLD | NEW |