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

Side by Side Diff: components/printing/test/print_web_view_helper_browsertest.cc

Issue 2718513003: Revert 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"
28 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
29 #include "third_party/WebKit/public/platform/WebMouseEvent.h" 28 #include "third_party/WebKit/public/platform/WebMouseEvent.h"
30 #include "third_party/WebKit/public/platform/WebString.h" 29 #include "third_party/WebKit/public/platform/WebString.h"
31 #include "third_party/WebKit/public/web/WebLocalFrame.h" 30 #include "third_party/WebKit/public/web/WebLocalFrame.h"
32 #include "third_party/WebKit/public/web/WebRange.h" 31 #include "third_party/WebKit/public/web/WebRange.h"
33 #include "third_party/WebKit/public/web/WebView.h" 32 #include "third_party/WebKit/public/web/WebView.h"
34 33
35 #if defined(OS_WIN) || defined(OS_MACOSX) 34 #if defined(OS_WIN) || defined(OS_MACOSX)
36 #include "base/files/file_util.h" 35 #include "base/files/file_util.h"
37 #include "printing/image.h" 36 #include "printing/image.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 render_thread_->sink().GetUniqueMessageMatching( 203 render_thread_->sink().GetUniqueMessageMatching(
205 PrintHostMsg_DidGetPreviewPageCount::ID); 204 PrintHostMsg_DidGetPreviewPageCount::ID);
206 ASSERT_TRUE(page_cnt_msg); 205 ASSERT_TRUE(page_cnt_msg);
207 PrintHostMsg_DidGetPreviewPageCount::Param post_page_count_param; 206 PrintHostMsg_DidGetPreviewPageCount::Param post_page_count_param;
208 PrintHostMsg_DidGetPreviewPageCount::Read(page_cnt_msg, 207 PrintHostMsg_DidGetPreviewPageCount::Read(page_cnt_msg,
209 &post_page_count_param); 208 &post_page_count_param);
210 EXPECT_EQ(count, std::get<0>(post_page_count_param).page_count); 209 EXPECT_EQ(count, std::get<0>(post_page_count_param).page_count);
211 } 210 }
212 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) 211 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
213 212
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
228 // Verifies whether the pages printed or not. 213 // Verifies whether the pages printed or not.
229 void VerifyPagesPrinted(bool printed) { 214 void VerifyPagesPrinted(bool printed) {
230 const IPC::Message* print_msg = 215 const IPC::Message* print_msg =
231 render_thread_->sink().GetUniqueMessageMatching( 216 render_thread_->sink().GetUniqueMessageMatching(
232 PrintHostMsg_DidPrintPage::ID); 217 PrintHostMsg_DidPrintPage::ID);
233 bool did_print_msg = !!print_msg; 218 bool did_print_msg = !!print_msg;
234 ASSERT_EQ(printed, did_print_msg); 219 ASSERT_EQ(printed, did_print_msg);
235 if (printed) { 220 if (printed) {
236 PrintHostMsg_DidPrintPage::Param post_did_print_page_param; 221 PrintHostMsg_DidPrintPage::Param post_did_print_page_param;
237 PrintHostMsg_DidPrintPage::Read(print_msg, &post_did_print_page_param); 222 PrintHostMsg_DidPrintPage::Read(print_msg, &post_did_print_page_param);
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 964
980 // Fill in some dummy values. 965 // Fill in some dummy values.
981 base::DictionaryValue dict; 966 base::DictionaryValue dict;
982 CreatePrintSettingsDictionary(&dict); 967 CreatePrintSettingsDictionary(&dict);
983 OnPrintForPrintPreview(dict); 968 OnPrintForPrintPreview(dict);
984 969
985 VerifyPrintFailed(false); 970 VerifyPrintFailed(false);
986 VerifyPagesPrinted(true); 971 VerifyPagesPrinted(true);
987 } 972 }
988 973
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
1024 // Tests that printing from print preview fails and receiving error messages 974 // Tests that printing from print preview fails and receiving error messages
1025 // through that channel all works. 975 // through that channel all works.
1026 TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintForPrintPreviewFail) { 976 TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintForPrintPreviewFail) {
1027 LoadHTML(kPrintPreviewHTML); 977 LoadHTML(kPrintPreviewHTML);
1028 978
1029 // An empty dictionary should fail. 979 // An empty dictionary should fail.
1030 base::DictionaryValue empty_dict; 980 base::DictionaryValue empty_dict;
1031 OnPrintForPrintPreview(empty_dict); 981 OnPrintForPrintPreview(empty_dict);
1032 982
1033 VerifyPagesPrinted(false); 983 VerifyPagesPrinted(false);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 1062
1113 VerifyPrintFailed(true); 1063 VerifyPrintFailed(true);
1114 VerifyPagesPrinted(false); 1064 VerifyPagesPrinted(false);
1115 } 1065 }
1116 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) 1066 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING)
1117 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) 1067 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
1118 1068
1119 #endif // !defined(OS_CHROMEOS) 1069 #endif // !defined(OS_CHROMEOS)
1120 1070
1121 } // namespace printing 1071 } // 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