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_render_thread.h" | 5 #include "chrome/renderer/mock_render_thread.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
11 #include "chrome/common/extensions/extension_messages.h" | 11 #include "chrome/common/extensions/extension_messages.h" |
12 #include "chrome/common/print_messages.h" | 12 #include "chrome/common/print_messages.h" |
13 #include "chrome/common/render_messages.h" | 13 #include "chrome/common/render_messages.h" |
14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
15 #include "content/common/view_messages.h" | 15 #include "content/common/view_messages.h" |
16 #include "ipc/ipc_message_utils.h" | 16 #include "ipc/ipc_message_utils.h" |
17 #include "ipc/ipc_sync_message.h" | 17 #include "ipc/ipc_sync_message.h" |
18 #include "printing/print_job_constants.h" | 18 #include "printing/print_job_constants.h" |
19 #include "printing/page_range.h" | |
20 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
21 | 20 |
22 MockRenderThread::MockRenderThread() | 21 MockRenderThread::MockRenderThread() |
23 : routing_id_(0), | 22 : routing_id_(0), |
24 opener_id_(0), | 23 opener_id_(0), |
25 widget_(NULL), | 24 widget_(NULL), |
26 reply_deserializer_(NULL), | 25 reply_deserializer_(NULL), |
27 printer_(new MockPrinter), | 26 printer_(new MockPrinter), |
28 print_dialog_user_response_(true), | 27 print_dialog_user_response_(true), |
29 print_preview_pages_remaining_(0) { | 28 print_preview_pages_remaining_(0) { |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 } | 206 } |
208 | 207 |
209 void MockRenderThread::OnDidPrintPage( | 208 void MockRenderThread::OnDidPrintPage( |
210 const PrintHostMsg_DidPrintPage_Params& params) { | 209 const PrintHostMsg_DidPrintPage_Params& params) { |
211 if (printer_.get()) | 210 if (printer_.get()) |
212 printer_->PrintPage(params); | 211 printer_->PrintPage(params); |
213 } | 212 } |
214 | 213 |
215 void MockRenderThread::OnDidGetPreviewPageCount(int document_cookie, | 214 void MockRenderThread::OnDidGetPreviewPageCount(int document_cookie, |
216 int number_pages, | 215 int number_pages, |
217 bool is_modifiable, | 216 bool is_modifiable) { |
218 bool clear_preview_data) { | |
219 print_preview_pages_remaining_ = number_pages; | 217 print_preview_pages_remaining_ = number_pages; |
220 } | 218 } |
221 | 219 |
222 void MockRenderThread::OnDidPreviewPage( | 220 void MockRenderThread::OnDidPreviewPage( |
223 const PrintHostMsg_DidPreviewPage_Params& params) { | 221 const PrintHostMsg_DidPreviewPage_Params& params) { |
224 if (params.page_number < printing::FIRST_PAGE_INDEX) | 222 if (params.page_number < printing::FIRST_PAGE_INDEX) |
225 return; | 223 return; |
226 print_preview_pages_remaining_--; | 224 print_preview_pages_remaining_--; |
227 } | 225 } |
228 | 226 |
229 void MockRenderThread::OnUpdatePrintSettings( | 227 void MockRenderThread::OnUpdatePrintSettings( |
230 int document_cookie, | 228 int document_cookie, |
231 const DictionaryValue& job_settings, | 229 const DictionaryValue& job_settings, |
232 PrintMsg_PrintPages_Params* params) { | 230 PrintMsg_PrintPages_Params* params) { |
233 // Check and make sure the required settings are all there. | 231 // Check and make sure the required settings are all there. |
234 // We don't actually care about the values. | 232 // We don't actually care about the values. |
235 std::string dummy_string; | 233 std::string dummy_string; |
236 if (!job_settings.GetBoolean(printing::kSettingLandscape, NULL) || | 234 if (!job_settings.GetBoolean(printing::kSettingLandscape, NULL) || |
237 !job_settings.GetBoolean(printing::kSettingCollate, NULL) || | 235 !job_settings.GetBoolean(printing::kSettingCollate, NULL) || |
238 !job_settings.GetBoolean(printing::kSettingColor, NULL) || | 236 !job_settings.GetBoolean(printing::kSettingColor, NULL) || |
239 !job_settings.GetBoolean(printing::kSettingPrintToPDF, NULL) || | 237 !job_settings.GetBoolean(printing::kSettingPrintToPDF, NULL) || |
240 !job_settings.GetString(printing::kSettingDeviceName, &dummy_string) || | 238 !job_settings.GetString(printing::kSettingDeviceName, &dummy_string) || |
241 !job_settings.GetInteger(printing::kSettingDuplexMode, NULL) || | 239 !job_settings.GetInteger(printing::kSettingDuplexMode, NULL) || |
242 !job_settings.GetInteger(printing::kSettingCopies, NULL)) { | 240 !job_settings.GetInteger(printing::kSettingCopies, NULL)) { |
243 return; | 241 return; |
244 } | 242 } |
245 | 243 |
246 // Just return the default settings. | 244 // Just return the default settings. |
247 if (printer_.get()) { | 245 if (printer_.get()) |
248 ListValue* page_range_array = new ListValue(); | 246 printer_->UpdateSettings(document_cookie, params); |
249 printing::PageRanges new_ranges; | |
250 if (job_settings.GetList(printing::kSettingPageRange, &page_range_array)) { | |
251 for (size_t index = 0; index < page_range_array->GetSize(); ++index) { | |
252 DictionaryValue* dict; | |
253 if (!page_range_array->GetDictionary(index, &dict)) | |
254 continue; | |
255 printing::PageRange range; | |
256 if (!dict->GetInteger(printing::kSettingPageRangeFrom, &range.from) || | |
257 !dict->GetInteger(printing::kSettingPageRangeTo, &range.to)) { | |
258 continue; | |
259 } | |
260 // Page numbers are 1-based in the dictionary. | |
261 // Page numbers are 0-based for the printing context. | |
262 range.from--; | |
263 range.to--; | |
264 new_ranges.push_back(range); | |
265 } | |
266 } | |
267 std::vector<int> pages(printing::PageRange::GetPages(new_ranges)); | |
268 printer_->UpdateSettings(document_cookie, params, pages); | |
269 } | |
270 } | 247 } |
271 | 248 |
272 void MockRenderThread::set_print_dialog_user_response(bool response) { | 249 void MockRenderThread::set_print_dialog_user_response(bool response) { |
273 print_dialog_user_response_ = response; | 250 print_dialog_user_response_ = response; |
274 } | 251 } |
275 | 252 |
276 int MockRenderThread::print_preview_pages_remaining() { | 253 int MockRenderThread::print_preview_pages_remaining() { |
277 return print_preview_pages_remaining_; | 254 return print_preview_pages_remaining_; |
278 } | 255 } |
OLD | NEW |