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/basictypes.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/shared_memory.h" | 9 #include "base/shared_memory.h" |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 page_size_ = params.page_size; | 80 page_size_ = params.page_size; |
81 printable_size_ = params.printable_size; | 81 printable_size_ = params.printable_size; |
82 margin_left_ = params.margin_left; | 82 margin_left_ = params.margin_left; |
83 margin_top_ = params.margin_top; | 83 margin_top_ = params.margin_top; |
84 display_header_footer_ = params.display_header_footer; | 84 display_header_footer_ = params.display_header_footer; |
85 date_ = params.date; | 85 date_ = params.date; |
86 title_ = params.title; | 86 title_ = params.title; |
87 url_ = params.url; | 87 url_ = params.url; |
88 } | 88 } |
89 | 89 |
| 90 void MockPrinter::UseInvalidSettings() { |
| 91 use_invalid_settings_ = true; |
| 92 PrintMsg_Print_Params empty_param; |
| 93 SetDefaultPrintSettings(empty_param); |
| 94 } |
| 95 |
90 void MockPrinter::ScriptedPrint(int cookie, | 96 void MockPrinter::ScriptedPrint(int cookie, |
91 int expected_pages_count, | 97 int expected_pages_count, |
92 bool has_selection, | 98 bool has_selection, |
93 PrintMsg_PrintPages_Params* settings) { | 99 PrintMsg_PrintPages_Params* settings) { |
94 // Verify the input parameters. | 100 // Verify the input parameters. |
95 EXPECT_EQ(document_cookie_, cookie); | 101 EXPECT_EQ(document_cookie_, cookie); |
96 | 102 |
97 settings->Reset(); | 103 settings->Reset(); |
98 | 104 |
99 settings->params.dpi = dpi_; | 105 settings->params.dpi = dpi_; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 bool MockPrinter::SaveBitmap( | 235 bool MockPrinter::SaveBitmap( |
230 unsigned int page, const FilePath& filepath) const { | 236 unsigned int page, const FilePath& filepath) const { |
231 if (printer_status_ != PRINTER_READY || page >= pages_.size()) | 237 if (printer_status_ != PRINTER_READY || page >= pages_.size()) |
232 return false; | 238 return false; |
233 | 239 |
234 pages_[page]->image().SaveToPng(filepath); | 240 pages_[page]->image().SaveToPng(filepath); |
235 return true; | 241 return true; |
236 } | 242 } |
237 | 243 |
238 int MockPrinter::CreateDocumentCookie() { | 244 int MockPrinter::CreateDocumentCookie() { |
239 return ++current_document_cookie_; | 245 return use_invalid_settings_ ? 0 : ++current_document_cookie_; |
240 } | 246 } |
241 | 247 |
242 void MockPrinter::SetPrintParams(PrintMsg_Print_Params* params) { | 248 void MockPrinter::SetPrintParams(PrintMsg_Print_Params* params) { |
243 params->dpi = dpi_; | 249 params->dpi = dpi_; |
244 params->max_shrink = max_shrink_; | 250 params->max_shrink = max_shrink_; |
245 params->min_shrink = min_shrink_; | 251 params->min_shrink = min_shrink_; |
246 params->desired_dpi = desired_dpi_; | 252 params->desired_dpi = desired_dpi_; |
247 params->selection_only = selection_only_; | 253 params->selection_only = selection_only_; |
248 params->document_cookie = document_cookie_; | 254 params->document_cookie = document_cookie_; |
249 params->page_size = page_size_; | 255 params->page_size = page_size_; |
250 params->printable_size = printable_size_; | 256 params->printable_size = printable_size_; |
251 params->margin_left = margin_left_; | 257 params->margin_left = margin_left_; |
252 params->margin_top = margin_top_; | 258 params->margin_top = margin_top_; |
253 params->is_first_request = is_first_request_; | 259 params->is_first_request = is_first_request_; |
254 params->preview_request_id = preview_request_id_; | 260 params->preview_request_id = preview_request_id_; |
255 params->display_header_footer = display_header_footer_; | 261 params->display_header_footer = display_header_footer_; |
256 params->date = date_; | 262 params->date = date_; |
257 params->title = title_; | 263 params->title = title_; |
258 params->url = url_; | 264 params->url = url_; |
259 } | 265 } |
OLD | NEW |