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