| 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" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/common/print_messages.h" | 12 #include "chrome/common/print_messages.h" |
| 13 #include "ipc/ipc_message_utils.h" | 13 #include "ipc/ipc_message_utils.h" |
| 14 #include "printing/metafile_impl.h" | 14 #include "printing/metafile_impl.h" |
| 15 #include "printing/units.h" | 15 #include "printing/units.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 PrintMsg_Print_Params_Clone::PrintMsg_Print_Params_Clone() | |
| 19 : page_size_(), | |
| 20 printable_size_(), | |
| 21 margin_top_(0), | |
| 22 margin_left_(0), | |
| 23 dpi_(0), | |
| 24 min_shrink_(0), | |
| 25 max_shrink_(0), | |
| 26 desired_dpi_(0), | |
| 27 document_cookie_(0), | |
| 28 selection_only_(0), | |
| 29 supports_alpha_blend_(0), | |
| 30 preview_request_id_(0), | |
| 31 is_first_request_(0), | |
| 32 display_header_footer_(0), | |
| 33 date_(), | |
| 34 title_(), | |
| 35 url_() { | |
| 36 } | |
| 37 | |
| 38 PrintMsg_Print_Params_Clone::~PrintMsg_Print_Params_Clone(){} | |
| 39 | |
| 40 void PrintMsg_Print_Params_Clone::ResetParams(PrintMsg_Print_Params* params) { | |
| 41 params->dpi = dpi_; | |
| 42 params->max_shrink = max_shrink_; | |
| 43 params->min_shrink = min_shrink_; | |
| 44 params->desired_dpi = desired_dpi_; | |
| 45 params->selection_only = selection_only_; | |
| 46 params->document_cookie = document_cookie_; | |
| 47 params->page_size = page_size_; | |
| 48 params->printable_size = printable_size_; | |
| 49 params->margin_left = margin_left_; | |
| 50 params->margin_top = margin_top_; | |
| 51 params->is_first_request = is_first_request_; | |
| 52 params->preview_request_id = preview_request_id_; | |
| 53 params->display_header_footer = display_header_footer_; | |
| 54 params->date = date_; | |
| 55 params->title = title_; | |
| 56 params->url = url_; | |
| 57 | |
| 58 COMPILE_ASSERT(sizeof(PrintMsg_Print_Params_Clone) == | |
| 59 sizeof(PrintMsg_Print_Params), | |
| 60 PrintMsg_Print_Params); | |
| 61 } | |
| 62 | |
| 63 PrintMsg_PrintPages_Params_Clone::PrintMsg_PrintPages_Params_Clone() | |
| 64 : pages_(0) { | |
| 65 } | |
| 66 | |
| 67 PrintMsg_PrintPages_Params_Clone::~PrintMsg_PrintPages_Params_Clone(){} | |
| 68 | |
| 69 void PrintMsg_PrintPages_Params_Clone::ResetParams( | |
| 70 PrintMsg_PrintPages_Params* params) { | |
| 71 params_.ResetParams(¶ms->params); | |
| 72 params->pages = pages_; | |
| 73 | |
| 74 COMPILE_ASSERT(sizeof(PrintMsg_PrintPages_Params_Clone) == | |
| 75 sizeof(PrintMsg_PrintPages_Params_Clone), | |
| 76 PrintMsg_PrintPages_Params); | |
| 77 } | |
| 78 | |
| 79 MockPrinterPage::MockPrinterPage(const void* source_data, | 18 MockPrinterPage::MockPrinterPage(const void* source_data, |
| 80 uint32 source_size, | 19 uint32 source_size, |
| 81 const printing::Image& image) | 20 const printing::Image& image) |
| 82 : source_size_(source_size), | 21 : source_size_(source_size), |
| 83 image_(image) { | 22 image_(image) { |
| 84 // Create copies of the source data | 23 // Create copies of the source data |
| 85 source_data_.reset(new uint8[source_size]); | 24 source_data_.reset(new uint8[source_size]); |
| 86 if (source_data_.get()) | 25 if (source_data_.get()) |
| 87 memcpy(source_data_.get(), source_data, source_size); | 26 memcpy(source_data_.get(), source_data, source_size); |
| 88 } | 27 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 document_cookie_ = -1; | 60 document_cookie_ = -1; |
| 122 } | 61 } |
| 123 | 62 |
| 124 void MockPrinter::GetDefaultPrintSettings(PrintMsg_Print_Params* params) { | 63 void MockPrinter::GetDefaultPrintSettings(PrintMsg_Print_Params* params) { |
| 125 // Verify this printer is not processing a job. | 64 // Verify this printer is not processing a job. |
| 126 // Sorry, this mock printer is very fragile. | 65 // Sorry, this mock printer is very fragile. |
| 127 EXPECT_EQ(-1, document_cookie_); | 66 EXPECT_EQ(-1, document_cookie_); |
| 128 | 67 |
| 129 // Assign a unit document cookie and set the print settings. | 68 // Assign a unit document cookie and set the print settings. |
| 130 document_cookie_ = CreateDocumentCookie(); | 69 document_cookie_ = CreateDocumentCookie(); |
| 131 PrintMsg_Print_Params_Clone params_clone; | 70 params->Reset(); |
| 132 params_clone.ResetParams(params); | |
| 133 SetPrintParams(params); | 71 SetPrintParams(params); |
| 134 } | 72 } |
| 135 | 73 |
| 136 void MockPrinter::SetDefaultPrintSettings(const PrintMsg_Print_Params& params) { | 74 void MockPrinter::SetDefaultPrintSettings(const PrintMsg_Print_Params& params) { |
| 137 dpi_ = params.dpi; | 75 dpi_ = params.dpi; |
| 138 max_shrink_ = params.max_shrink; | 76 max_shrink_ = params.max_shrink; |
| 139 min_shrink_ = params.min_shrink; | 77 min_shrink_ = params.min_shrink; |
| 140 desired_dpi_ = params.desired_dpi; | 78 desired_dpi_ = params.desired_dpi; |
| 141 selection_only_ = params.selection_only; | 79 selection_only_ = params.selection_only; |
| 142 page_size_ = params.page_size; | 80 page_size_ = params.page_size; |
| 143 printable_size_ = params.printable_size; | 81 printable_size_ = params.printable_size; |
| 144 margin_left_ = params.margin_left; | 82 margin_left_ = params.margin_left; |
| 145 margin_top_ = params.margin_top; | 83 margin_top_ = params.margin_top; |
| 146 display_header_footer_ = params.display_header_footer; | 84 display_header_footer_ = params.display_header_footer; |
| 147 date_ = params.date; | 85 date_ = params.date; |
| 148 title_ = params.title; | 86 title_ = params.title; |
| 149 url_ = params.url; | 87 url_ = params.url; |
| 150 } | 88 } |
| 151 | 89 |
| 152 void MockPrinter::ScriptedPrint(int cookie, | 90 void MockPrinter::ScriptedPrint(int cookie, |
| 153 int expected_pages_count, | 91 int expected_pages_count, |
| 154 bool has_selection, | 92 bool has_selection, |
| 155 PrintMsg_PrintPages_Params* settings) { | 93 PrintMsg_PrintPages_Params* settings) { |
| 156 // Verify the input parameters. | 94 // Verify the input parameters. |
| 157 EXPECT_EQ(document_cookie_, cookie); | 95 EXPECT_EQ(document_cookie_, cookie); |
| 158 | 96 |
| 159 PrintMsg_PrintPages_Params_Clone params_clone; | 97 settings->Reset(); |
| 160 params_clone.ResetParams(settings); | |
| 161 | 98 |
| 162 settings->params.dpi = dpi_; | 99 settings->params.dpi = dpi_; |
| 163 settings->params.max_shrink = max_shrink_; | 100 settings->params.max_shrink = max_shrink_; |
| 164 settings->params.min_shrink = min_shrink_; | 101 settings->params.min_shrink = min_shrink_; |
| 165 settings->params.desired_dpi = desired_dpi_; | 102 settings->params.desired_dpi = desired_dpi_; |
| 166 settings->params.selection_only = selection_only_; | 103 settings->params.selection_only = selection_only_; |
| 167 settings->params.document_cookie = document_cookie_; | 104 settings->params.document_cookie = document_cookie_; |
| 168 settings->params.page_size = page_size_; | 105 settings->params.page_size = page_size_; |
| 169 settings->params.printable_size = printable_size_; | 106 settings->params.printable_size = printable_size_; |
| 170 settings->params.is_first_request = is_first_request_; | 107 settings->params.is_first_request = is_first_request_; |
| 171 settings->params.preview_request_id = preview_request_id_; | 108 settings->params.preview_request_id = preview_request_id_; |
| 172 settings->params.display_header_footer = display_header_footer_; | 109 settings->params.display_header_footer = display_header_footer_; |
| 173 settings->params.date = date_; | 110 settings->params.date = date_; |
| 174 settings->params.title = title_; | 111 settings->params.title = title_; |
| 175 settings->params.url = url_; | 112 settings->params.url = url_; |
| 176 printer_status_ = PRINTER_PRINTING; | 113 printer_status_ = PRINTER_PRINTING; |
| 177 } | 114 } |
| 178 | 115 |
| 179 void MockPrinter::UpdateSettings(int cookie, | 116 void MockPrinter::UpdateSettings(int cookie, |
| 180 PrintMsg_PrintPages_Params* params) { | 117 PrintMsg_PrintPages_Params* params) { |
| 181 EXPECT_EQ(document_cookie_, cookie); | 118 EXPECT_EQ(document_cookie_, cookie); |
| 182 | 119 |
| 183 PrintMsg_PrintPages_Params_Clone params_clone; | 120 params->Reset(); |
| 184 params_clone.ResetParams(params); | |
| 185 SetPrintParams(&(params->params)); | 121 SetPrintParams(&(params->params)); |
| 186 printer_status_ = PRINTER_PRINTING; | 122 printer_status_ = PRINTER_PRINTING; |
| 187 } | 123 } |
| 188 | 124 |
| 189 void MockPrinter::SetPrintedPagesCount(int cookie, int number_pages) { | 125 void MockPrinter::SetPrintedPagesCount(int cookie, int number_pages) { |
| 190 // Verify the input parameter and update the printer status so that the | 126 // Verify the input parameter and update the printer status so that the |
| 191 // RenderViewTest class can verify the this function finishes without errors. | 127 // RenderViewTest class can verify the this function finishes without errors. |
| 192 EXPECT_EQ(document_cookie_, cookie); | 128 EXPECT_EQ(document_cookie_, cookie); |
| 193 EXPECT_EQ(PRINTER_PRINTING, printer_status_); | 129 EXPECT_EQ(PRINTER_PRINTING, printer_status_); |
| 194 EXPECT_EQ(0, number_pages_); | 130 EXPECT_EQ(0, number_pages_); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 params->printable_size = printable_size_; | 250 params->printable_size = printable_size_; |
| 315 params->margin_left = margin_left_; | 251 params->margin_left = margin_left_; |
| 316 params->margin_top = margin_top_; | 252 params->margin_top = margin_top_; |
| 317 params->is_first_request = is_first_request_; | 253 params->is_first_request = is_first_request_; |
| 318 params->preview_request_id = preview_request_id_; | 254 params->preview_request_id = preview_request_id_; |
| 319 params->display_header_footer = display_header_footer_; | 255 params->display_header_footer = display_header_footer_; |
| 320 params->date = date_; | 256 params->date = date_; |
| 321 params->title = title_; | 257 params->title = title_; |
| 322 params->url = url_; | 258 params->url = url_; |
| 323 } | 259 } |
| OLD | NEW |