OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/renderer/mock_printer.h" | 5 #include "chrome/renderer/mock_printer.h" |
6 | 6 |
7 #include "base/basictypes.h" | |
7 #include "base/file_util.h" | 8 #include "base/file_util.h" |
8 #include "base/shared_memory.h" | 9 #include "base/shared_memory.h" |
10 #include "base/string16.h" | |
11 #include "base/utf_string_conversions.h" | |
9 #include "chrome/common/print_messages.h" | 12 #include "chrome/common/print_messages.h" |
10 #include "ipc/ipc_message_utils.h" | 13 #include "ipc/ipc_message_utils.h" |
11 #include "printing/metafile_impl.h" | 14 #include "printing/metafile_impl.h" |
12 #include "printing/units.h" | 15 #include "printing/units.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
14 | 17 |
18 PrintMsg_Print_Params_Clone::PrintMsg_Print_Params_Clone() | |
19 : page_size_(), | |
20 printable_size_(), | |
21 margin_top_(0), | |
22 margin_left_(0), | |
23 dpi_(0), | |
24 min_shrink_(0), | |
25 max_shrink_(0), | |
26 desired_dpi_(0), | |
27 document_cookie_(0), | |
28 selection_only_(0), | |
29 supports_alpha_blend_(0), | |
30 preview_request_id_(0), | |
31 is_first_request_(0), | |
32 display_header_footer_(0), | |
33 date_(), | |
34 title_(), | |
35 url_() { | |
36 } | |
37 | |
38 PrintMsg_Print_Params_Clone::~PrintMsg_Print_Params_Clone(){} | |
39 | |
40 void PrintMsg_Print_Params_Clone::ResetParams(PrintMsg_Print_Params* params) { | |
41 params->dpi = dpi_; | |
42 params->max_shrink = max_shrink_; | |
43 params->min_shrink = min_shrink_; | |
44 params->desired_dpi = desired_dpi_; | |
45 params->selection_only = selection_only_; | |
46 params->document_cookie = document_cookie_; | |
47 params->page_size = page_size_; | |
48 params->printable_size = printable_size_; | |
49 params->margin_left = margin_left_; | |
50 params->margin_top = margin_top_; | |
51 params->is_first_request = is_first_request_; | |
52 params->preview_request_id = preview_request_id_; | |
53 params->display_header_footer = display_header_footer_; | |
54 params->date = date_; | |
55 params->title = title_; | |
56 params->url = url_; | |
57 | |
58 assert(sizeof(PrintMsg_Print_Params_Clone) == sizeof(PrintMsg_Print_Params)); | |
vandebo (ex-Chrome)
2011/08/16 17:47:46
Use COMPILE_ASSERT so that the problem is caught a
Aayush Kumar
2011/08/16 20:32:52
Done.
| |
59 } | |
60 | |
61 PrintMsg_PrintPages_Params_Clone::PrintMsg_PrintPages_Params_Clone() | |
62 : pages_(0) { | |
63 } | |
64 | |
65 PrintMsg_PrintPages_Params_Clone::~PrintMsg_PrintPages_Params_Clone(){} | |
66 | |
67 void PrintMsg_PrintPages_Params_Clone::ResetParams( | |
68 PrintMsg_PrintPages_Params* params) { | |
69 params_.ResetParams(¶ms->params); | |
70 params->pages = pages_; | |
kmadhusu
2011/08/16 18:08:34
On Release version, MSVS crashes the application i
Aayush Kumar
2011/08/16 20:32:52
Done.
| |
71 | |
72 assert(sizeof(PrintMsg_PrintPages_Params_Clone) == | |
vandebo (ex-Chrome)
2011/08/16 17:47:46
and here
Aayush Kumar
2011/08/16 20:32:52
Done.
| |
73 sizeof(PrintMsg_PrintPages_Params_Clone)); | |
74 } | |
75 | |
15 MockPrinterPage::MockPrinterPage(const void* source_data, | 76 MockPrinterPage::MockPrinterPage(const void* source_data, |
16 uint32 source_size, | 77 uint32 source_size, |
17 const printing::Image& image) | 78 const printing::Image& image) |
18 : source_size_(source_size), | 79 : source_size_(source_size), |
19 image_(image) { | 80 image_(image) { |
20 // Create copies of the source data | 81 // Create copies of the source data |
21 source_data_.reset(new uint8[source_size]); | 82 source_data_.reset(new uint8[source_size]); |
22 if (source_data_.get()) | 83 if (source_data_.get()) |
23 memcpy(source_data_.get(), source_data, source_size); | 84 memcpy(source_data_.get(), source_data, source_size); |
24 } | 85 } |
25 | 86 |
26 MockPrinterPage::~MockPrinterPage() {} | 87 MockPrinterPage::~MockPrinterPage() {} |
27 | 88 |
28 MockPrinter::MockPrinter() | 89 MockPrinter::MockPrinter() |
29 : dpi_(printing::kPointsPerInch), | 90 : dpi_(printing::kPointsPerInch), |
30 max_shrink_(2.0), | 91 max_shrink_(2.0), |
31 min_shrink_(1.25), | 92 min_shrink_(1.25), |
32 desired_dpi_(printing::kPointsPerInch), | 93 desired_dpi_(printing::kPointsPerInch), |
33 selection_only_(false), | 94 selection_only_(false), |
34 document_cookie_(-1), | 95 document_cookie_(-1), |
35 current_document_cookie_(0), | 96 current_document_cookie_(0), |
36 printer_status_(PRINTER_READY), | 97 printer_status_(PRINTER_READY), |
37 number_pages_(0), | 98 number_pages_(0), |
38 page_number_(0), | 99 page_number_(0), |
39 is_first_request_(true), | 100 is_first_request_(true), |
40 preview_request_id_(0) { | 101 preview_request_id_(0), |
102 display_header_footer_(false), | |
103 date_(ASCIIToUTF16("date")), | |
104 title_(ASCIIToUTF16("title")), | |
105 url_(ASCIIToUTF16("url")) { | |
41 page_size_.SetSize(static_cast<int>(8.5 * dpi_), | 106 page_size_.SetSize(static_cast<int>(8.5 * dpi_), |
42 static_cast<int>(11.0 * dpi_)); | 107 static_cast<int>(11.0 * dpi_)); |
43 printable_size_.SetSize(static_cast<int>((7.5 * dpi_)), | 108 printable_size_.SetSize(static_cast<int>((7.5 * dpi_)), |
44 static_cast<int>((10.0 * dpi_))); | 109 static_cast<int>((10.0 * dpi_))); |
45 margin_left_ = margin_top_ = static_cast<int>(0.5 * dpi_); | 110 margin_left_ = margin_top_ = static_cast<int>(0.5 * dpi_); |
46 } | 111 } |
47 | 112 |
48 MockPrinter::~MockPrinter() { | 113 MockPrinter::~MockPrinter() { |
49 } | 114 } |
50 | 115 |
51 void MockPrinter::ResetPrinter() { | 116 void MockPrinter::ResetPrinter() { |
52 printer_status_ = PRINTER_READY; | 117 printer_status_ = PRINTER_READY; |
53 document_cookie_ = -1; | 118 document_cookie_ = -1; |
54 } | 119 } |
55 | 120 |
56 void MockPrinter::GetDefaultPrintSettings(PrintMsg_Print_Params* params) { | 121 void MockPrinter::GetDefaultPrintSettings(PrintMsg_Print_Params* params) { |
57 // Verify this printer is not processing a job. | 122 // Verify this printer is not processing a job. |
58 // Sorry, this mock printer is very fragile. | 123 // Sorry, this mock printer is very fragile. |
59 EXPECT_EQ(-1, document_cookie_); | 124 EXPECT_EQ(-1, document_cookie_); |
60 | 125 |
61 // Assign a unit document cookie and set the print settings. | 126 // Assign a unit document cookie and set the print settings. |
62 document_cookie_ = CreateDocumentCookie(); | 127 document_cookie_ = CreateDocumentCookie(); |
63 memset(params, 0, sizeof(PrintMsg_Print_Params)); | 128 PrintMsg_Print_Params_Clone params_clone; |
129 params_clone.ResetParams(params); | |
64 SetPrintParams(params); | 130 SetPrintParams(params); |
65 } | 131 } |
66 | 132 |
67 void MockPrinter::SetDefaultPrintSettings(const PrintMsg_Print_Params& params) { | 133 void MockPrinter::SetDefaultPrintSettings(const PrintMsg_Print_Params& params) { |
68 dpi_ = params.dpi; | 134 dpi_ = params.dpi; |
69 max_shrink_ = params.max_shrink; | 135 max_shrink_ = params.max_shrink; |
70 min_shrink_ = params.min_shrink; | 136 min_shrink_ = params.min_shrink; |
71 desired_dpi_ = params.desired_dpi; | 137 desired_dpi_ = params.desired_dpi; |
72 selection_only_ = params.selection_only; | 138 selection_only_ = params.selection_only; |
73 page_size_ = params.page_size; | 139 page_size_ = params.page_size; |
74 printable_size_ = params.printable_size; | 140 printable_size_ = params.printable_size; |
75 margin_left_ = params.margin_left; | 141 margin_left_ = params.margin_left; |
76 margin_top_ = params.margin_top; | 142 margin_top_ = params.margin_top; |
143 display_header_footer_ = params.display_header_footer; | |
144 date_ = params.date; | |
145 title_ = params.title; | |
146 url_ = params.url; | |
77 } | 147 } |
78 | 148 |
79 void MockPrinter::ScriptedPrint(int cookie, | 149 void MockPrinter::ScriptedPrint(int cookie, |
80 int expected_pages_count, | 150 int expected_pages_count, |
81 bool has_selection, | 151 bool has_selection, |
82 PrintMsg_PrintPages_Params* settings) { | 152 PrintMsg_PrintPages_Params* settings) { |
83 // Verify the input parameters. | 153 // Verify the input parameters. |
84 EXPECT_EQ(document_cookie_, cookie); | 154 EXPECT_EQ(document_cookie_, cookie); |
85 | 155 |
86 memset(settings, 0, sizeof(PrintMsg_PrintPages_Params)); | 156 PrintMsg_PrintPages_Params_Clone params_clone; |
157 params_clone.ResetParams(settings); | |
158 | |
87 settings->params.dpi = dpi_; | 159 settings->params.dpi = dpi_; |
88 settings->params.max_shrink = max_shrink_; | 160 settings->params.max_shrink = max_shrink_; |
89 settings->params.min_shrink = min_shrink_; | 161 settings->params.min_shrink = min_shrink_; |
90 settings->params.desired_dpi = desired_dpi_; | 162 settings->params.desired_dpi = desired_dpi_; |
91 settings->params.selection_only = selection_only_; | 163 settings->params.selection_only = selection_only_; |
92 settings->params.document_cookie = document_cookie_; | 164 settings->params.document_cookie = document_cookie_; |
93 settings->params.page_size = page_size_; | 165 settings->params.page_size = page_size_; |
94 settings->params.printable_size = printable_size_; | 166 settings->params.printable_size = printable_size_; |
95 settings->params.is_first_request = is_first_request_; | 167 settings->params.is_first_request = is_first_request_; |
96 settings->params.preview_request_id = preview_request_id_; | 168 settings->params.preview_request_id = preview_request_id_; |
169 settings->params.display_header_footer = display_header_footer_; | |
170 settings->params.date = date_; | |
171 settings->params.title = title_; | |
172 settings->params.url = url_; | |
97 printer_status_ = PRINTER_PRINTING; | 173 printer_status_ = PRINTER_PRINTING; |
98 } | 174 } |
99 | 175 |
100 void MockPrinter::UpdateSettings(int cookie, | 176 void MockPrinter::UpdateSettings(int cookie, |
101 PrintMsg_PrintPages_Params* params) { | 177 PrintMsg_PrintPages_Params* params) { |
102 EXPECT_EQ(document_cookie_, cookie); | 178 EXPECT_EQ(document_cookie_, cookie); |
103 | 179 |
104 memset(params, 0, sizeof(PrintMsg_PrintPages_Params)); | 180 PrintMsg_PrintPages_Params_Clone params_clone; |
181 params_clone.ResetParams(params); | |
105 SetPrintParams(&(params->params)); | 182 SetPrintParams(&(params->params)); |
106 printer_status_ = PRINTER_PRINTING; | 183 printer_status_ = PRINTER_PRINTING; |
107 } | 184 } |
108 | 185 |
109 void MockPrinter::SetPrintedPagesCount(int cookie, int number_pages) { | 186 void MockPrinter::SetPrintedPagesCount(int cookie, int number_pages) { |
110 // Verify the input parameter and update the printer status so that the | 187 // Verify the input parameter and update the printer status so that the |
111 // RenderViewTest class can verify the this function finishes without errors. | 188 // RenderViewTest class can verify the this function finishes without errors. |
112 EXPECT_EQ(document_cookie_, cookie); | 189 EXPECT_EQ(document_cookie_, cookie); |
113 EXPECT_EQ(PRINTER_PRINTING, printer_status_); | 190 EXPECT_EQ(PRINTER_PRINTING, printer_status_); |
114 EXPECT_EQ(0, number_pages_); | 191 EXPECT_EQ(0, number_pages_); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 params->min_shrink = min_shrink_; | 306 params->min_shrink = min_shrink_; |
230 params->desired_dpi = desired_dpi_; | 307 params->desired_dpi = desired_dpi_; |
231 params->selection_only = selection_only_; | 308 params->selection_only = selection_only_; |
232 params->document_cookie = document_cookie_; | 309 params->document_cookie = document_cookie_; |
233 params->page_size = page_size_; | 310 params->page_size = page_size_; |
234 params->printable_size = printable_size_; | 311 params->printable_size = printable_size_; |
235 params->margin_left = margin_left_; | 312 params->margin_left = margin_left_; |
236 params->margin_top = margin_top_; | 313 params->margin_top = margin_top_; |
237 params->is_first_request = is_first_request_; | 314 params->is_first_request = is_first_request_; |
238 params->preview_request_id = preview_request_id_; | 315 params->preview_request_id = preview_request_id_; |
316 params->display_header_footer = display_header_footer_; | |
317 params->date = date_; | |
318 params->title = title_; | |
319 params->url = url_; | |
239 } | 320 } |
OLD | NEW |