| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 printer_status_(PRINTER_READY), | 62 printer_status_(PRINTER_READY), |
| 63 number_pages_(0), | 63 number_pages_(0), |
| 64 page_number_(0), | 64 page_number_(0), |
| 65 is_first_request_(true), | 65 is_first_request_(true), |
| 66 print_to_pdf_(false), | 66 print_to_pdf_(false), |
| 67 preview_request_id_(0), | 67 preview_request_id_(0), |
| 68 display_header_footer_(false), | 68 display_header_footer_(false), |
| 69 date_(ASCIIToUTF16("date")), | 69 date_(ASCIIToUTF16("date")), |
| 70 title_(ASCIIToUTF16("title")), | 70 title_(ASCIIToUTF16("title")), |
| 71 url_(ASCIIToUTF16("url")), | 71 url_(ASCIIToUTF16("url")), |
| 72 scripted_print_allowed_(true), |
| 72 use_invalid_settings_(false) { | 73 use_invalid_settings_(false) { |
| 73 page_size_.SetSize(static_cast<int>(8.5 * dpi_), | 74 page_size_.SetSize(static_cast<int>(8.5 * dpi_), |
| 74 static_cast<int>(11.0 * dpi_)); | 75 static_cast<int>(11.0 * dpi_)); |
| 75 content_size_.SetSize(static_cast<int>((7.5 * dpi_)), | 76 content_size_.SetSize(static_cast<int>((7.5 * dpi_)), |
| 76 static_cast<int>((10.0 * dpi_))); | 77 static_cast<int>((10.0 * dpi_))); |
| 77 margin_left_ = margin_top_ = static_cast<int>(0.5 * dpi_); | 78 margin_left_ = margin_top_ = static_cast<int>(0.5 * dpi_); |
| 78 printable_area_.SetRect(static_cast<int>(0.25 * dpi_), | 79 printable_area_.SetRect(static_cast<int>(0.25 * dpi_), |
| 79 static_cast<int>(0.25 *dpi_), | 80 static_cast<int>(0.25 *dpi_), |
| 80 static_cast<int>(8 * dpi_), | 81 static_cast<int>(8 * dpi_), |
| 81 static_cast<int>(10.5 * dpi_)); | 82 static_cast<int>(10.5 * dpi_)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 93 // Verify this printer is not processing a job. | 94 // Verify this printer is not processing a job. |
| 94 // Sorry, this mock printer is very fragile. | 95 // Sorry, this mock printer is very fragile. |
| 95 EXPECT_EQ(-1, document_cookie_); | 96 EXPECT_EQ(-1, document_cookie_); |
| 96 | 97 |
| 97 // Assign a unit document cookie and set the print settings. | 98 // Assign a unit document cookie and set the print settings. |
| 98 document_cookie_ = CreateDocumentCookie(); | 99 document_cookie_ = CreateDocumentCookie(); |
| 99 params->Reset(); | 100 params->Reset(); |
| 100 SetPrintParams(params); | 101 SetPrintParams(params); |
| 101 } | 102 } |
| 102 | 103 |
| 104 void MockPrinter::OnCheckScriptedPrintAllowed(bool* allowed) { |
| 105 *allowed = scripted_print_allowed_; |
| 106 } |
| 107 |
| 103 void MockPrinter::SetDefaultPrintSettings(const PrintMsg_Print_Params& params) { | 108 void MockPrinter::SetDefaultPrintSettings(const PrintMsg_Print_Params& params) { |
| 104 dpi_ = params.dpi; | 109 dpi_ = params.dpi; |
| 105 max_shrink_ = params.max_shrink; | 110 max_shrink_ = params.max_shrink; |
| 106 min_shrink_ = params.min_shrink; | 111 min_shrink_ = params.min_shrink; |
| 107 desired_dpi_ = params.desired_dpi; | 112 desired_dpi_ = params.desired_dpi; |
| 108 selection_only_ = params.selection_only; | 113 selection_only_ = params.selection_only; |
| 109 page_size_ = params.page_size; | 114 page_size_ = params.page_size; |
| 110 content_size_ = params.content_size; | 115 content_size_ = params.content_size; |
| 111 printable_area_ = params.printable_area; | 116 printable_area_ = params.printable_area; |
| 112 margin_left_ = params.margin_left; | 117 margin_left_ = params.margin_left; |
| 113 margin_top_ = params.margin_top; | 118 margin_top_ = params.margin_top; |
| 114 display_header_footer_ = params.display_header_footer; | 119 display_header_footer_ = params.display_header_footer; |
| 115 date_ = params.date; | 120 date_ = params.date; |
| 116 title_ = params.title; | 121 title_ = params.title; |
| 117 url_ = params.url; | 122 url_ = params.url; |
| 118 } | 123 } |
| 119 | 124 |
| 120 void MockPrinter::UseInvalidSettings() { | 125 void MockPrinter::UseInvalidSettings() { |
| 121 use_invalid_settings_ = true; | 126 use_invalid_settings_ = true; |
| 122 PrintMsg_Print_Params empty_param; | 127 PrintMsg_Print_Params empty_param; |
| 123 SetDefaultPrintSettings(empty_param); | 128 SetDefaultPrintSettings(empty_param); |
| 124 } | 129 } |
| 125 | 130 |
| 131 void MockPrinter::SetScriptedPrintAllowed(bool allowed) { |
| 132 scripted_print_allowed_ = allowed; |
| 133 } |
| 134 |
| 126 void MockPrinter::UseInvalidPageSize() { | 135 void MockPrinter::UseInvalidPageSize() { |
| 127 page_size_.SetSize(0, 0); | 136 page_size_.SetSize(0, 0); |
| 128 } | 137 } |
| 129 | 138 |
| 130 void MockPrinter::UseInvalidContentSize() { | 139 void MockPrinter::UseInvalidContentSize() { |
| 131 content_size_.SetSize(0, 0); | 140 content_size_.SetSize(0, 0); |
| 132 } | 141 } |
| 133 | 142 |
| 134 void MockPrinter::ScriptedPrint(int cookie, | 143 void MockPrinter::ScriptedPrint(int cookie, |
| 135 int expected_pages_count, | 144 int expected_pages_count, |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 params->margin_left = margin_left_; | 312 params->margin_left = margin_left_; |
| 304 params->margin_top = margin_top_; | 313 params->margin_top = margin_top_; |
| 305 params->is_first_request = is_first_request_; | 314 params->is_first_request = is_first_request_; |
| 306 params->print_to_pdf = print_to_pdf_; | 315 params->print_to_pdf = print_to_pdf_; |
| 307 params->preview_request_id = preview_request_id_; | 316 params->preview_request_id = preview_request_id_; |
| 308 params->display_header_footer = display_header_footer_; | 317 params->display_header_footer = display_header_footer_; |
| 309 params->date = date_; | 318 params->date = date_; |
| 310 params->title = title_; | 319 params->title = title_; |
| 311 params->url = url_; | 320 params->url = url_; |
| 312 } | 321 } |
| OLD | NEW |