OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/test/mock_printer.h" | 5 #include "components/printing/test/mock_printer.h" |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 source_data_.reset(new uint8_t[source_size]); | 57 source_data_.reset(new uint8_t[source_size]); |
58 if (source_data_.get()) | 58 if (source_data_.get()) |
59 memcpy(source_data_.get(), source_data, source_size); | 59 memcpy(source_data_.get(), source_data, source_size); |
60 } | 60 } |
61 | 61 |
62 MockPrinterPage::~MockPrinterPage() { | 62 MockPrinterPage::~MockPrinterPage() { |
63 } | 63 } |
64 | 64 |
65 MockPrinter::MockPrinter() | 65 MockPrinter::MockPrinter() |
66 : dpi_(printing::kPointsPerInch), | 66 : dpi_(printing::kPointsPerInch), |
67 desired_dpi_(printing::kPointsPerInch), | |
68 selection_only_(false), | 67 selection_only_(false), |
69 should_print_backgrounds_(false), | 68 should_print_backgrounds_(false), |
70 document_cookie_(-1), | 69 document_cookie_(-1), |
71 current_document_cookie_(0), | 70 current_document_cookie_(0), |
72 printer_status_(PRINTER_READY), | 71 printer_status_(PRINTER_READY), |
73 number_pages_(0), | 72 number_pages_(0), |
74 page_number_(0), | 73 page_number_(0), |
75 is_first_request_(true), | 74 is_first_request_(true), |
76 print_to_pdf_(false), | 75 print_to_pdf_(false), |
77 preview_request_id_(0), | 76 preview_request_id_(0), |
(...skipping 26 matching lines...) Expand all Loading... |
104 EXPECT_EQ(-1, document_cookie_); | 103 EXPECT_EQ(-1, document_cookie_); |
105 | 104 |
106 // Assign a unit document cookie and set the print settings. | 105 // Assign a unit document cookie and set the print settings. |
107 document_cookie_ = CreateDocumentCookie(); | 106 document_cookie_ = CreateDocumentCookie(); |
108 params->Reset(); | 107 params->Reset(); |
109 SetPrintParams(params); | 108 SetPrintParams(params); |
110 } | 109 } |
111 | 110 |
112 void MockPrinter::SetDefaultPrintSettings(const PrintMsg_Print_Params& params) { | 111 void MockPrinter::SetDefaultPrintSettings(const PrintMsg_Print_Params& params) { |
113 dpi_ = params.dpi; | 112 dpi_ = params.dpi; |
114 desired_dpi_ = params.desired_dpi; | |
115 selection_only_ = params.selection_only; | 113 selection_only_ = params.selection_only; |
116 should_print_backgrounds_ = params.should_print_backgrounds; | 114 should_print_backgrounds_ = params.should_print_backgrounds; |
117 page_size_ = params.page_size; | 115 page_size_ = params.page_size; |
118 content_size_ = params.content_size; | 116 content_size_ = params.content_size; |
119 printable_area_ = params.printable_area; | 117 printable_area_ = params.printable_area; |
120 margin_left_ = params.margin_left; | 118 margin_left_ = params.margin_left; |
121 margin_top_ = params.margin_top; | 119 margin_top_ = params.margin_top; |
122 display_header_footer_ = params.display_header_footer; | 120 display_header_footer_ = params.display_header_footer; |
123 title_ = params.title; | 121 title_ = params.title; |
124 url_ = params.url; | 122 url_ = params.url; |
(...skipping 16 matching lines...) Expand all Loading... |
141 void MockPrinter::ScriptedPrint(int cookie, | 139 void MockPrinter::ScriptedPrint(int cookie, |
142 int expected_pages_count, | 140 int expected_pages_count, |
143 bool has_selection, | 141 bool has_selection, |
144 PrintMsg_PrintPages_Params* settings) { | 142 PrintMsg_PrintPages_Params* settings) { |
145 // Verify the input parameters. | 143 // Verify the input parameters. |
146 EXPECT_EQ(document_cookie_, cookie); | 144 EXPECT_EQ(document_cookie_, cookie); |
147 | 145 |
148 settings->Reset(); | 146 settings->Reset(); |
149 | 147 |
150 settings->params.dpi = dpi_; | 148 settings->params.dpi = dpi_; |
151 settings->params.desired_dpi = desired_dpi_; | |
152 settings->params.selection_only = selection_only_; | 149 settings->params.selection_only = selection_only_; |
153 settings->params.should_print_backgrounds = should_print_backgrounds_; | 150 settings->params.should_print_backgrounds = should_print_backgrounds_; |
154 settings->params.document_cookie = document_cookie_; | 151 settings->params.document_cookie = document_cookie_; |
155 settings->params.page_size = page_size_; | 152 settings->params.page_size = page_size_; |
156 settings->params.content_size = content_size_; | 153 settings->params.content_size = content_size_; |
157 settings->params.printable_area = printable_area_; | 154 settings->params.printable_area = printable_area_; |
158 settings->params.is_first_request = is_first_request_; | 155 settings->params.is_first_request = is_first_request_; |
159 settings->params.print_scaling_option = print_scaling_option_; | 156 settings->params.print_scaling_option = print_scaling_option_; |
160 settings->params.print_to_pdf = print_to_pdf_; | 157 settings->params.print_to_pdf = print_to_pdf_; |
161 settings->params.preview_request_id = preview_request_id_; | 158 settings->params.preview_request_id = preview_request_id_; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 pages_[page]->image().SaveToPng(filepath); | 280 pages_[page]->image().SaveToPng(filepath); |
284 return true; | 281 return true; |
285 } | 282 } |
286 | 283 |
287 int MockPrinter::CreateDocumentCookie() { | 284 int MockPrinter::CreateDocumentCookie() { |
288 return use_invalid_settings_ ? 0 : ++current_document_cookie_; | 285 return use_invalid_settings_ ? 0 : ++current_document_cookie_; |
289 } | 286 } |
290 | 287 |
291 void MockPrinter::SetPrintParams(PrintMsg_Print_Params* params) { | 288 void MockPrinter::SetPrintParams(PrintMsg_Print_Params* params) { |
292 params->dpi = dpi_; | 289 params->dpi = dpi_; |
293 params->desired_dpi = desired_dpi_; | |
294 params->selection_only = selection_only_; | 290 params->selection_only = selection_only_; |
295 params->should_print_backgrounds = should_print_backgrounds_; | 291 params->should_print_backgrounds = should_print_backgrounds_; |
296 params->document_cookie = document_cookie_; | 292 params->document_cookie = document_cookie_; |
297 params->page_size = page_size_; | 293 params->page_size = page_size_; |
298 params->content_size = content_size_; | 294 params->content_size = content_size_; |
299 params->printable_area = printable_area_; | 295 params->printable_area = printable_area_; |
300 params->margin_left = margin_left_; | 296 params->margin_left = margin_left_; |
301 params->margin_top = margin_top_; | 297 params->margin_top = margin_top_; |
302 params->is_first_request = is_first_request_; | 298 params->is_first_request = is_first_request_; |
303 params->print_scaling_option = print_scaling_option_; | 299 params->print_scaling_option = print_scaling_option_; |
304 params->print_to_pdf = print_to_pdf_; | 300 params->print_to_pdf = print_to_pdf_; |
305 params->preview_request_id = preview_request_id_; | 301 params->preview_request_id = preview_request_id_; |
306 params->display_header_footer = display_header_footer_; | 302 params->display_header_footer = display_header_footer_; |
307 params->title = title_; | 303 params->title = title_; |
308 params->url = url_; | 304 params->url = url_; |
309 } | 305 } |
OLD | NEW |