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_cancel_page_number_(-1), | 29 print_preview_cancel_page_number_(-1), |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 !job_settings.GetBoolean(printing::kIsFirstRequest, NULL) || | 246 !job_settings.GetBoolean(printing::kIsFirstRequest, NULL) || |
246 !job_settings.GetString(printing::kSettingDeviceName, &dummy_string) || | 247 !job_settings.GetString(printing::kSettingDeviceName, &dummy_string) || |
247 !job_settings.GetInteger(printing::kSettingDuplexMode, NULL) || | 248 !job_settings.GetInteger(printing::kSettingDuplexMode, NULL) || |
248 !job_settings.GetInteger(printing::kSettingCopies, NULL) || | 249 !job_settings.GetInteger(printing::kSettingCopies, NULL) || |
249 !job_settings.GetString(printing::kPreviewUIAddr, &dummy_string) || | 250 !job_settings.GetString(printing::kPreviewUIAddr, &dummy_string) || |
250 !job_settings.GetInteger(printing::kPreviewRequestID, NULL)) { | 251 !job_settings.GetInteger(printing::kPreviewRequestID, NULL)) { |
251 return; | 252 return; |
252 } | 253 } |
253 | 254 |
254 // Just return the default settings. | 255 // Just return the default settings. |
255 if (printer_.get()) | 256 if (printer_.get()) { |
256 printer_->UpdateSettings(document_cookie, params); | 257 ListValue* page_range_array; |
| 258 printing::PageRanges new_ranges; |
| 259 if (job_settings.GetList(printing::kSettingPageRange, &page_range_array)) { |
| 260 for (size_t index = 0; index < page_range_array->GetSize(); ++index) { |
| 261 DictionaryValue* dict; |
| 262 if (!page_range_array->GetDictionary(index, &dict)) |
| 263 continue; |
| 264 printing::PageRange range; |
| 265 if (!dict->GetInteger(printing::kSettingPageRangeFrom, &range.from) || |
| 266 !dict->GetInteger(printing::kSettingPageRangeTo, &range.to)) { |
| 267 continue; |
| 268 } |
| 269 // Page numbers are 1-based in the dictionary. |
| 270 // Page numbers are 0-based for the printing context. |
| 271 range.from--; |
| 272 range.to--; |
| 273 new_ranges.push_back(range); |
| 274 } |
| 275 } |
| 276 std::vector<int> pages(printing::PageRange::GetPages(new_ranges)); |
| 277 printer_->UpdateSettings(document_cookie, params, pages); |
| 278 } |
257 } | 279 } |
258 | 280 |
259 void MockRenderThread::set_print_dialog_user_response(bool response) { | 281 void MockRenderThread::set_print_dialog_user_response(bool response) { |
260 print_dialog_user_response_ = response; | 282 print_dialog_user_response_ = response; |
261 } | 283 } |
262 | 284 |
263 void MockRenderThread::set_print_preview_cancel_page_number(int page) { | 285 void MockRenderThread::set_print_preview_cancel_page_number(int page) { |
264 print_preview_cancel_page_number_ = page; | 286 print_preview_cancel_page_number_ = page; |
265 } | 287 } |
266 | 288 |
267 int MockRenderThread::print_preview_pages_remaining() { | 289 int MockRenderThread::print_preview_pages_remaining() { |
268 return print_preview_pages_remaining_; | 290 return print_preview_pages_remaining_; |
269 } | 291 } |
OLD | NEW |