| 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 22 matching lines...) Expand all Loading... |
| 33 params->margin_left = static_cast<int>(0.25 * dpi); | 33 params->margin_left = static_cast<int>(0.25 * dpi); |
| 34 params->margin_top = static_cast<int>(0.25 * dpi); | 34 params->margin_top = static_cast<int>(0.25 * dpi); |
| 35 } else if (margins_type == printing::CUSTOM_MARGINS) { | 35 } else if (margins_type == printing::CUSTOM_MARGINS) { |
| 36 params->content_size.SetSize(static_cast<int>((7.9 * dpi)), | 36 params->content_size.SetSize(static_cast<int>((7.9 * dpi)), |
| 37 static_cast<int>((10.4 * dpi))); | 37 static_cast<int>((10.4 * dpi))); |
| 38 params->margin_left = static_cast<int>(0.30 * dpi); | 38 params->margin_left = static_cast<int>(0.30 * dpi); |
| 39 params->margin_top = static_cast<int>(0.30 * dpi); | 39 params->margin_top = static_cast<int>(0.30 * dpi); |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 | 42 |
| 43 void UpdatePageSizeAndScaling(const gfx::Size& page_size, |
| 44 int scale_factor, |
| 45 PrintMsg_Print_Params* params) { |
| 46 params->page_size = page_size; |
| 47 params->scale_factor = static_cast<double>(scale_factor) / 100.0; |
| 48 } |
| 49 |
| 43 } // namespace | 50 } // namespace |
| 44 | 51 |
| 45 MockPrinterPage::MockPrinterPage(const void* source_data, | 52 MockPrinterPage::MockPrinterPage(const void* source_data, |
| 46 uint32_t source_size, | 53 uint32_t source_size, |
| 47 const printing::Image& image) | 54 const printing::Image& image) |
| 48 : source_size_(source_size), image_(image) { | 55 : source_size_(source_size), image_(image) { |
| 49 // Create copies of the source data | 56 // Create copies of the source data |
| 50 source_data_.reset(new uint8_t[source_size]); | 57 source_data_.reset(new uint8_t[source_size]); |
| 51 if (source_data_.get()) | 58 if (source_data_.get()) |
| 52 memcpy(source_data_.get(), source_data, source_size); | 59 memcpy(source_data_.get(), source_data, source_size); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 settings->params.preview_request_id = preview_request_id_; | 161 settings->params.preview_request_id = preview_request_id_; |
| 155 settings->params.display_header_footer = display_header_footer_; | 162 settings->params.display_header_footer = display_header_footer_; |
| 156 settings->params.title = title_; | 163 settings->params.title = title_; |
| 157 settings->params.url = url_; | 164 settings->params.url = url_; |
| 158 printer_status_ = PRINTER_PRINTING; | 165 printer_status_ = PRINTER_PRINTING; |
| 159 } | 166 } |
| 160 | 167 |
| 161 void MockPrinter::UpdateSettings(int cookie, | 168 void MockPrinter::UpdateSettings(int cookie, |
| 162 PrintMsg_PrintPages_Params* params, | 169 PrintMsg_PrintPages_Params* params, |
| 163 const std::vector<int>& pages, | 170 const std::vector<int>& pages, |
| 164 int margins_type) { | 171 int margins_type, |
| 172 const gfx::Size& page_size, |
| 173 int scale_factor) { |
| 165 if (document_cookie_ == -1) { | 174 if (document_cookie_ == -1) { |
| 166 document_cookie_ = CreateDocumentCookie(); | 175 document_cookie_ = CreateDocumentCookie(); |
| 167 } | 176 } |
| 168 params->Reset(); | 177 params->Reset(); |
| 169 params->pages = pages; | 178 params->pages = pages; |
| 170 SetPrintParams(&(params->params)); | 179 SetPrintParams(&(params->params)); |
| 171 UpdateMargins(margins_type, dpi_, &(params->params)); | 180 UpdateMargins(margins_type, dpi_, &(params->params)); |
| 181 if (!page_size.IsEmpty()) |
| 182 UpdatePageSizeAndScaling(page_size, scale_factor, ¶ms->params); |
| 172 printer_status_ = PRINTER_PRINTING; | 183 printer_status_ = PRINTER_PRINTING; |
| 173 } | 184 } |
| 174 | 185 |
| 175 void MockPrinter::SetPrintedPagesCount(int cookie, int number_pages) { | 186 void MockPrinter::SetPrintedPagesCount(int cookie, int number_pages) { |
| 176 // Verify the input parameter and update the printer status so that the | 187 // Verify the input parameter and update the printer status so that the |
| 177 // RenderViewTest class can verify the this function finishes without errors. | 188 // RenderViewTest class can verify the this function finishes without errors. |
| 178 EXPECT_EQ(document_cookie_, cookie); | 189 EXPECT_EQ(document_cookie_, cookie); |
| 179 EXPECT_EQ(PRINTER_PRINTING, printer_status_); | 190 EXPECT_EQ(PRINTER_PRINTING, printer_status_); |
| 180 EXPECT_EQ(0, number_pages_); | 191 EXPECT_EQ(0, number_pages_); |
| 181 EXPECT_EQ(0, page_number_); | 192 EXPECT_EQ(0, page_number_); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 params->margin_left = margin_left_; | 300 params->margin_left = margin_left_; |
| 290 params->margin_top = margin_top_; | 301 params->margin_top = margin_top_; |
| 291 params->is_first_request = is_first_request_; | 302 params->is_first_request = is_first_request_; |
| 292 params->print_scaling_option = print_scaling_option_; | 303 params->print_scaling_option = print_scaling_option_; |
| 293 params->print_to_pdf = print_to_pdf_; | 304 params->print_to_pdf = print_to_pdf_; |
| 294 params->preview_request_id = preview_request_id_; | 305 params->preview_request_id = preview_request_id_; |
| 295 params->display_header_footer = display_header_footer_; | 306 params->display_header_footer = display_header_footer_; |
| 296 params->title = title_; | 307 params->title = title_; |
| 297 params->url = url_; | 308 params->url = url_; |
| 298 } | 309 } |
| OLD | NEW |