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" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 | 21 |
21 MockRenderThread::MockRenderThread() | 22 MockRenderThread::MockRenderThread() |
22 : routing_id_(0), | 23 : routing_id_(0), |
23 opener_id_(0), | 24 opener_id_(0), |
24 widget_(NULL), | 25 widget_(NULL), |
25 reply_deserializer_(NULL), | 26 reply_deserializer_(NULL), |
26 printer_(new MockPrinter), | 27 printer_(new MockPrinter), |
27 print_dialog_user_response_(true), | 28 print_dialog_user_response_(true), |
28 print_preview_pages_remaining_(0) { | 29 print_preview_pages_remaining_(0) { |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 !job_settings.GetBoolean(printing::kSettingPrintToPDF, NULL) || | 237 !job_settings.GetBoolean(printing::kSettingPrintToPDF, NULL) || |
237 !job_settings.GetBoolean(printing::kIsFirstRequest, NULL) || | 238 !job_settings.GetBoolean(printing::kIsFirstRequest, NULL) || |
238 !job_settings.GetString(printing::kSettingDeviceName, &dummy_string) || | 239 !job_settings.GetString(printing::kSettingDeviceName, &dummy_string) || |
239 !job_settings.GetInteger(printing::kSettingDuplexMode, NULL) || | 240 !job_settings.GetInteger(printing::kSettingDuplexMode, NULL) || |
240 !job_settings.GetInteger(printing::kSettingCopies, NULL) || | 241 !job_settings.GetInteger(printing::kSettingCopies, NULL) || |
241 !job_settings.GetInteger(printing::kPreviewRequestID, NULL)) { | 242 !job_settings.GetInteger(printing::kPreviewRequestID, NULL)) { |
242 return; | 243 return; |
243 } | 244 } |
244 | 245 |
245 // Just return the default settings. | 246 // Just return the default settings. |
246 if (printer_.get()) | 247 if (printer_.get()) { |
247 printer_->UpdateSettings(document_cookie, params); | 248 ListValue* page_range_array; |
| 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 } |
248 } | 270 } |
249 | 271 |
250 void MockRenderThread::set_print_dialog_user_response(bool response) { | 272 void MockRenderThread::set_print_dialog_user_response(bool response) { |
251 print_dialog_user_response_ = response; | 273 print_dialog_user_response_ = response; |
252 } | 274 } |
253 | 275 |
254 int MockRenderThread::print_preview_pages_remaining() { | 276 int MockRenderThread::print_preview_pages_remaining() { |
255 return print_preview_pages_remaining_; | 277 return print_preview_pages_remaining_; |
256 } | 278 } |
OLD | NEW |