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 26 matching lines...) Expand all Loading... |
37 document_cookie_(-1), | 37 document_cookie_(-1), |
38 current_document_cookie_(0), | 38 current_document_cookie_(0), |
39 printer_status_(PRINTER_READY), | 39 printer_status_(PRINTER_READY), |
40 number_pages_(0), | 40 number_pages_(0), |
41 page_number_(0), | 41 page_number_(0), |
42 is_first_request_(true), | 42 is_first_request_(true), |
43 preview_request_id_(0), | 43 preview_request_id_(0), |
44 display_header_footer_(false), | 44 display_header_footer_(false), |
45 date_(ASCIIToUTF16("date")), | 45 date_(ASCIIToUTF16("date")), |
46 title_(ASCIIToUTF16("title")), | 46 title_(ASCIIToUTF16("title")), |
47 url_(ASCIIToUTF16("url")) { | 47 url_(ASCIIToUTF16("url")), |
| 48 use_invalid_settings_(false) { |
48 page_size_.SetSize(static_cast<int>(8.5 * dpi_), | 49 page_size_.SetSize(static_cast<int>(8.5 * dpi_), |
49 static_cast<int>(11.0 * dpi_)); | 50 static_cast<int>(11.0 * dpi_)); |
50 printable_size_.SetSize(static_cast<int>((7.5 * dpi_)), | 51 printable_size_.SetSize(static_cast<int>((7.5 * dpi_)), |
51 static_cast<int>((10.0 * dpi_))); | 52 static_cast<int>((10.0 * dpi_))); |
52 margin_left_ = margin_top_ = static_cast<int>(0.5 * dpi_); | 53 margin_left_ = margin_top_ = static_cast<int>(0.5 * dpi_); |
53 } | 54 } |
54 | 55 |
55 MockPrinter::~MockPrinter() { | 56 MockPrinter::~MockPrinter() { |
56 } | 57 } |
57 | 58 |
(...skipping 22 matching lines...) Expand all Loading... |
80 page_size_ = params.page_size; | 81 page_size_ = params.page_size; |
81 printable_size_ = params.printable_size; | 82 printable_size_ = params.printable_size; |
82 margin_left_ = params.margin_left; | 83 margin_left_ = params.margin_left; |
83 margin_top_ = params.margin_top; | 84 margin_top_ = params.margin_top; |
84 display_header_footer_ = params.display_header_footer; | 85 display_header_footer_ = params.display_header_footer; |
85 date_ = params.date; | 86 date_ = params.date; |
86 title_ = params.title; | 87 title_ = params.title; |
87 url_ = params.url; | 88 url_ = params.url; |
88 } | 89 } |
89 | 90 |
| 91 void MockPrinter::UseInvalidSettings() { |
| 92 use_invalid_settings_ = true; |
| 93 PrintMsg_Print_Params empty_param; |
| 94 SetDefaultPrintSettings(empty_param); |
| 95 } |
| 96 |
90 void MockPrinter::ScriptedPrint(int cookie, | 97 void MockPrinter::ScriptedPrint(int cookie, |
91 int expected_pages_count, | 98 int expected_pages_count, |
92 bool has_selection, | 99 bool has_selection, |
93 PrintMsg_PrintPages_Params* settings) { | 100 PrintMsg_PrintPages_Params* settings) { |
94 // Verify the input parameters. | 101 // Verify the input parameters. |
95 EXPECT_EQ(document_cookie_, cookie); | 102 EXPECT_EQ(document_cookie_, cookie); |
96 | 103 |
97 settings->Reset(); | 104 settings->Reset(); |
98 | 105 |
99 settings->params.dpi = dpi_; | 106 settings->params.dpi = dpi_; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 bool MockPrinter::SaveBitmap( | 238 bool MockPrinter::SaveBitmap( |
232 unsigned int page, const FilePath& filepath) const { | 239 unsigned int page, const FilePath& filepath) const { |
233 if (printer_status_ != PRINTER_READY || page >= pages_.size()) | 240 if (printer_status_ != PRINTER_READY || page >= pages_.size()) |
234 return false; | 241 return false; |
235 | 242 |
236 pages_[page]->image().SaveToPng(filepath); | 243 pages_[page]->image().SaveToPng(filepath); |
237 return true; | 244 return true; |
238 } | 245 } |
239 | 246 |
240 int MockPrinter::CreateDocumentCookie() { | 247 int MockPrinter::CreateDocumentCookie() { |
241 return ++current_document_cookie_; | 248 return use_invalid_settings_ ? 0 : ++current_document_cookie_; |
242 } | 249 } |
243 | 250 |
244 void MockPrinter::SetPrintParams(PrintMsg_Print_Params* params) { | 251 void MockPrinter::SetPrintParams(PrintMsg_Print_Params* params) { |
245 params->dpi = dpi_; | 252 params->dpi = dpi_; |
246 params->max_shrink = max_shrink_; | 253 params->max_shrink = max_shrink_; |
247 params->min_shrink = min_shrink_; | 254 params->min_shrink = min_shrink_; |
248 params->desired_dpi = desired_dpi_; | 255 params->desired_dpi = desired_dpi_; |
249 params->selection_only = selection_only_; | 256 params->selection_only = selection_only_; |
250 params->document_cookie = document_cookie_; | 257 params->document_cookie = document_cookie_; |
251 params->page_size = page_size_; | 258 params->page_size = page_size_; |
252 params->printable_size = printable_size_; | 259 params->printable_size = printable_size_; |
253 params->margin_left = margin_left_; | 260 params->margin_left = margin_left_; |
254 params->margin_top = margin_top_; | 261 params->margin_top = margin_top_; |
255 params->is_first_request = is_first_request_; | 262 params->is_first_request = is_first_request_; |
256 params->preview_request_id = preview_request_id_; | 263 params->preview_request_id = preview_request_id_; |
257 params->display_header_footer = display_header_footer_; | 264 params->display_header_footer = display_header_footer_; |
258 params->date = date_; | 265 params->date = date_; |
259 params->title = title_; | 266 params->title = title_; |
260 params->url = url_; | 267 params->url = url_; |
261 } | 268 } |
OLD | NEW |