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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 source_data_.reset(new uint8_t[source_size]); | 50 source_data_.reset(new uint8_t[source_size]); |
51 if (source_data_.get()) | 51 if (source_data_.get()) |
52 memcpy(source_data_.get(), source_data, source_size); | 52 memcpy(source_data_.get(), source_data, source_size); |
53 } | 53 } |
54 | 54 |
55 MockPrinterPage::~MockPrinterPage() { | 55 MockPrinterPage::~MockPrinterPage() { |
56 } | 56 } |
57 | 57 |
58 MockPrinter::MockPrinter() | 58 MockPrinter::MockPrinter() |
59 : dpi_(printing::kPointsPerInch), | 59 : dpi_(printing::kPointsPerInch), |
| 60 max_shrink_(2.0), |
| 61 min_shrink_(1.25), |
60 desired_dpi_(printing::kPointsPerInch), | 62 desired_dpi_(printing::kPointsPerInch), |
61 selection_only_(false), | 63 selection_only_(false), |
62 should_print_backgrounds_(false), | 64 should_print_backgrounds_(false), |
63 document_cookie_(-1), | 65 document_cookie_(-1), |
64 current_document_cookie_(0), | 66 current_document_cookie_(0), |
65 printer_status_(PRINTER_READY), | 67 printer_status_(PRINTER_READY), |
66 number_pages_(0), | 68 number_pages_(0), |
67 page_number_(0), | 69 page_number_(0), |
68 is_first_request_(true), | 70 is_first_request_(true), |
69 print_to_pdf_(false), | 71 print_to_pdf_(false), |
(...skipping 27 matching lines...) Expand all Loading... |
97 EXPECT_EQ(-1, document_cookie_); | 99 EXPECT_EQ(-1, document_cookie_); |
98 | 100 |
99 // Assign a unit document cookie and set the print settings. | 101 // Assign a unit document cookie and set the print settings. |
100 document_cookie_ = CreateDocumentCookie(); | 102 document_cookie_ = CreateDocumentCookie(); |
101 params->Reset(); | 103 params->Reset(); |
102 SetPrintParams(params); | 104 SetPrintParams(params); |
103 } | 105 } |
104 | 106 |
105 void MockPrinter::SetDefaultPrintSettings(const PrintMsg_Print_Params& params) { | 107 void MockPrinter::SetDefaultPrintSettings(const PrintMsg_Print_Params& params) { |
106 dpi_ = params.dpi; | 108 dpi_ = params.dpi; |
| 109 max_shrink_ = params.max_shrink; |
| 110 min_shrink_ = params.min_shrink; |
107 desired_dpi_ = params.desired_dpi; | 111 desired_dpi_ = params.desired_dpi; |
108 selection_only_ = params.selection_only; | 112 selection_only_ = params.selection_only; |
109 should_print_backgrounds_ = params.should_print_backgrounds; | 113 should_print_backgrounds_ = params.should_print_backgrounds; |
110 page_size_ = params.page_size; | 114 page_size_ = params.page_size; |
111 content_size_ = params.content_size; | 115 content_size_ = params.content_size; |
112 printable_area_ = params.printable_area; | 116 printable_area_ = params.printable_area; |
113 margin_left_ = params.margin_left; | 117 margin_left_ = params.margin_left; |
114 margin_top_ = params.margin_top; | 118 margin_top_ = params.margin_top; |
115 display_header_footer_ = params.display_header_footer; | 119 display_header_footer_ = params.display_header_footer; |
116 title_ = params.title; | 120 title_ = params.title; |
(...skipping 17 matching lines...) Expand all Loading... |
134 void MockPrinter::ScriptedPrint(int cookie, | 138 void MockPrinter::ScriptedPrint(int cookie, |
135 int expected_pages_count, | 139 int expected_pages_count, |
136 bool has_selection, | 140 bool has_selection, |
137 PrintMsg_PrintPages_Params* settings) { | 141 PrintMsg_PrintPages_Params* settings) { |
138 // Verify the input parameters. | 142 // Verify the input parameters. |
139 EXPECT_EQ(document_cookie_, cookie); | 143 EXPECT_EQ(document_cookie_, cookie); |
140 | 144 |
141 settings->Reset(); | 145 settings->Reset(); |
142 | 146 |
143 settings->params.dpi = dpi_; | 147 settings->params.dpi = dpi_; |
| 148 settings->params.max_shrink = max_shrink_; |
| 149 settings->params.min_shrink = min_shrink_; |
144 settings->params.desired_dpi = desired_dpi_; | 150 settings->params.desired_dpi = desired_dpi_; |
145 settings->params.selection_only = selection_only_; | 151 settings->params.selection_only = selection_only_; |
146 settings->params.should_print_backgrounds = should_print_backgrounds_; | 152 settings->params.should_print_backgrounds = should_print_backgrounds_; |
147 settings->params.document_cookie = document_cookie_; | 153 settings->params.document_cookie = document_cookie_; |
148 settings->params.page_size = page_size_; | 154 settings->params.page_size = page_size_; |
149 settings->params.content_size = content_size_; | 155 settings->params.content_size = content_size_; |
150 settings->params.printable_area = printable_area_; | 156 settings->params.printable_area = printable_area_; |
151 settings->params.is_first_request = is_first_request_; | 157 settings->params.is_first_request = is_first_request_; |
152 settings->params.print_scaling_option = print_scaling_option_; | 158 settings->params.print_scaling_option = print_scaling_option_; |
153 settings->params.print_to_pdf = print_to_pdf_; | 159 settings->params.print_to_pdf = print_to_pdf_; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 pages_[page]->image().SaveToPng(filepath); | 279 pages_[page]->image().SaveToPng(filepath); |
274 return true; | 280 return true; |
275 } | 281 } |
276 | 282 |
277 int MockPrinter::CreateDocumentCookie() { | 283 int MockPrinter::CreateDocumentCookie() { |
278 return use_invalid_settings_ ? 0 : ++current_document_cookie_; | 284 return use_invalid_settings_ ? 0 : ++current_document_cookie_; |
279 } | 285 } |
280 | 286 |
281 void MockPrinter::SetPrintParams(PrintMsg_Print_Params* params) { | 287 void MockPrinter::SetPrintParams(PrintMsg_Print_Params* params) { |
282 params->dpi = dpi_; | 288 params->dpi = dpi_; |
| 289 params->max_shrink = max_shrink_; |
| 290 params->min_shrink = min_shrink_; |
283 params->desired_dpi = desired_dpi_; | 291 params->desired_dpi = desired_dpi_; |
284 params->selection_only = selection_only_; | 292 params->selection_only = selection_only_; |
285 params->should_print_backgrounds = should_print_backgrounds_; | 293 params->should_print_backgrounds = should_print_backgrounds_; |
286 params->document_cookie = document_cookie_; | 294 params->document_cookie = document_cookie_; |
287 params->page_size = page_size_; | 295 params->page_size = page_size_; |
288 params->content_size = content_size_; | 296 params->content_size = content_size_; |
289 params->printable_area = printable_area_; | 297 params->printable_area = printable_area_; |
290 params->margin_left = margin_left_; | 298 params->margin_left = margin_left_; |
291 params->margin_top = margin_top_; | 299 params->margin_top = margin_top_; |
292 params->is_first_request = is_first_request_; | 300 params->is_first_request = is_first_request_; |
293 params->print_scaling_option = print_scaling_option_; | 301 params->print_scaling_option = print_scaling_option_; |
294 params->print_to_pdf = print_to_pdf_; | 302 params->print_to_pdf = print_to_pdf_; |
295 params->preview_request_id = preview_request_id_; | 303 params->preview_request_id = preview_request_id_; |
296 params->display_header_footer = display_header_footer_; | 304 params->display_header_footer = display_header_footer_; |
297 params->title = title_; | 305 params->title = title_; |
298 params->url = url_; | 306 params->url = url_; |
299 } | 307 } |
OLD | NEW |