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 "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 | 20 |
21 MockRenderThread::MockRenderThread() | 21 MockRenderThread::MockRenderThread() |
22 : routing_id_(0), | 22 : routing_id_(0), |
23 opener_id_(0), | 23 opener_id_(0), |
24 widget_(NULL), | 24 widget_(NULL), |
25 reply_deserializer_(NULL), | 25 reply_deserializer_(NULL), |
26 printer_(new MockPrinter), | 26 printer_(new MockPrinter), |
27 print_dialog_user_response_(true), | 27 print_dialog_user_response_(true), |
| 28 print_preview_cancel_page_number_(-1), |
28 print_preview_pages_remaining_(0) { | 29 print_preview_pages_remaining_(0) { |
29 } | 30 } |
30 | 31 |
31 MockRenderThread::~MockRenderThread() { | 32 MockRenderThread::~MockRenderThread() { |
32 } | 33 } |
33 | 34 |
34 // Called by the Widget. The routing_id must match the routing id assigned | 35 // Called by the Widget. The routing_id must match the routing id assigned |
35 // to the Widget in reply to ViewHostMsg_CreateWidget message. | 36 // to the Widget in reply to ViewHostMsg_CreateWidget message. |
36 void MockRenderThread::AddRoute(int32 routing_id, | 37 void MockRenderThread::AddRoute(int32 routing_id, |
37 IPC::Channel::Listener* listener) { | 38 IPC::Channel::Listener* listener) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 IPC_MESSAGE_HANDLER(PrintHostMsg_GetDefaultPrintSettings, | 105 IPC_MESSAGE_HANDLER(PrintHostMsg_GetDefaultPrintSettings, |
105 OnGetDefaultPrintSettings) | 106 OnGetDefaultPrintSettings) |
106 IPC_MESSAGE_HANDLER(PrintHostMsg_ScriptedPrint, OnScriptedPrint) | 107 IPC_MESSAGE_HANDLER(PrintHostMsg_ScriptedPrint, OnScriptedPrint) |
107 IPC_MESSAGE_HANDLER(PrintHostMsg_UpdatePrintSettings, OnUpdatePrintSettings) | 108 IPC_MESSAGE_HANDLER(PrintHostMsg_UpdatePrintSettings, OnUpdatePrintSettings) |
108 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPrintedPagesCount, | 109 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPrintedPagesCount, |
109 OnDidGetPrintedPagesCount) | 110 OnDidGetPrintedPagesCount) |
110 IPC_MESSAGE_HANDLER(PrintHostMsg_DidPrintPage, OnDidPrintPage) | 111 IPC_MESSAGE_HANDLER(PrintHostMsg_DidPrintPage, OnDidPrintPage) |
111 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPreviewPageCount, | 112 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPreviewPageCount, |
112 OnDidGetPreviewPageCount) | 113 OnDidGetPreviewPageCount) |
113 IPC_MESSAGE_HANDLER(PrintHostMsg_DidPreviewPage, OnDidPreviewPage) | 114 IPC_MESSAGE_HANDLER(PrintHostMsg_DidPreviewPage, OnDidPreviewPage) |
| 115 IPC_MESSAGE_HANDLER(PrintHostMsg_CheckForCancel, OnCheckForCancel) |
114 #if defined(OS_WIN) | 116 #if defined(OS_WIN) |
115 IPC_MESSAGE_HANDLER(PrintHostMsg_DuplicateSection, OnDuplicateSection) | 117 IPC_MESSAGE_HANDLER(PrintHostMsg_DuplicateSection, OnDuplicateSection) |
116 #endif | 118 #endif |
117 IPC_MESSAGE_HANDLER(ViewHostMsg_AllocateSharedMemoryBuffer, | 119 IPC_MESSAGE_HANDLER(ViewHostMsg_AllocateSharedMemoryBuffer, |
118 OnAllocateSharedMemoryBuffer) | 120 OnAllocateSharedMemoryBuffer) |
119 #if defined(OS_CHROMEOS) | 121 #if defined(OS_CHROMEOS) |
120 IPC_MESSAGE_HANDLER(PrintHostMsg_AllocateTempFileForPrinting, | 122 IPC_MESSAGE_HANDLER(PrintHostMsg_AllocateTempFileForPrinting, |
121 OnAllocateTempFileForPrinting) | 123 OnAllocateTempFileForPrinting) |
122 IPC_MESSAGE_HANDLER(PrintHostMsg_TempFileForPrintingWritten, | 124 IPC_MESSAGE_HANDLER(PrintHostMsg_TempFileForPrintingWritten, |
123 OnTempFileForPrintingWritten) | 125 OnTempFileForPrintingWritten) |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 printer_->PrintPage(params); | 213 printer_->PrintPage(params); |
212 } | 214 } |
213 | 215 |
214 void MockRenderThread::OnDidGetPreviewPageCount( | 216 void MockRenderThread::OnDidGetPreviewPageCount( |
215 const PrintHostMsg_DidGetPreviewPageCount_Params& params) { | 217 const PrintHostMsg_DidGetPreviewPageCount_Params& params) { |
216 print_preview_pages_remaining_ = params.page_count; | 218 print_preview_pages_remaining_ = params.page_count; |
217 } | 219 } |
218 | 220 |
219 void MockRenderThread::OnDidPreviewPage( | 221 void MockRenderThread::OnDidPreviewPage( |
220 const PrintHostMsg_DidPreviewPage_Params& params) { | 222 const PrintHostMsg_DidPreviewPage_Params& params) { |
221 if (params.page_number < printing::FIRST_PAGE_INDEX) | 223 DCHECK(params.page_number >= printing::FIRST_PAGE_INDEX); |
222 return; | |
223 print_preview_pages_remaining_--; | 224 print_preview_pages_remaining_--; |
224 } | 225 } |
225 | 226 |
| 227 void MockRenderThread::OnCheckForCancel(const std::string& preview_ui_addr, |
| 228 int preview_request_id, |
| 229 bool* cancel) { |
| 230 *cancel = |
| 231 (print_preview_pages_remaining_ == print_preview_cancel_page_number_); |
| 232 } |
| 233 |
226 void MockRenderThread::OnUpdatePrintSettings( | 234 void MockRenderThread::OnUpdatePrintSettings( |
227 int document_cookie, | 235 int document_cookie, |
228 const DictionaryValue& job_settings, | 236 const DictionaryValue& job_settings, |
229 PrintMsg_PrintPages_Params* params) { | 237 PrintMsg_PrintPages_Params* params) { |
230 // Check and make sure the required settings are all there. | 238 // Check and make sure the required settings are all there. |
231 // We don't actually care about the values. | 239 // We don't actually care about the values. |
232 std::string dummy_string; | 240 std::string dummy_string; |
233 if (!job_settings.GetBoolean(printing::kSettingLandscape, NULL) || | 241 if (!job_settings.GetBoolean(printing::kSettingLandscape, NULL) || |
234 !job_settings.GetBoolean(printing::kSettingCollate, NULL) || | 242 !job_settings.GetBoolean(printing::kSettingCollate, NULL) || |
235 !job_settings.GetBoolean(printing::kSettingColor, NULL) || | 243 !job_settings.GetBoolean(printing::kSettingColor, NULL) || |
236 !job_settings.GetBoolean(printing::kSettingPrintToPDF, NULL) || | 244 !job_settings.GetBoolean(printing::kSettingPrintToPDF, NULL) || |
237 !job_settings.GetBoolean(printing::kIsFirstRequest, NULL) || | 245 !job_settings.GetBoolean(printing::kIsFirstRequest, NULL) || |
238 !job_settings.GetString(printing::kSettingDeviceName, &dummy_string) || | 246 !job_settings.GetString(printing::kSettingDeviceName, &dummy_string) || |
239 !job_settings.GetInteger(printing::kSettingDuplexMode, NULL) || | 247 !job_settings.GetInteger(printing::kSettingDuplexMode, NULL) || |
240 !job_settings.GetInteger(printing::kSettingCopies, NULL) || | 248 !job_settings.GetInteger(printing::kSettingCopies, NULL) || |
| 249 !job_settings.GetString(printing::kPreviewUIAddr, &dummy_string) || |
241 !job_settings.GetInteger(printing::kPreviewRequestID, NULL)) { | 250 !job_settings.GetInteger(printing::kPreviewRequestID, NULL)) { |
242 return; | 251 return; |
243 } | 252 } |
244 | 253 |
245 // Just return the default settings. | 254 // Just return the default settings. |
246 if (printer_.get()) | 255 if (printer_.get()) |
247 printer_->UpdateSettings(document_cookie, params); | 256 printer_->UpdateSettings(document_cookie, params); |
248 } | 257 } |
249 | 258 |
250 void MockRenderThread::set_print_dialog_user_response(bool response) { | 259 void MockRenderThread::set_print_dialog_user_response(bool response) { |
251 print_dialog_user_response_ = response; | 260 print_dialog_user_response_ = response; |
252 } | 261 } |
253 | 262 |
| 263 void MockRenderThread::set_print_preview_cancel_page_number(int page) { |
| 264 print_preview_cancel_page_number_ = page; |
| 265 } |
| 266 |
254 int MockRenderThread::print_preview_pages_remaining() { | 267 int MockRenderThread::print_preview_pages_remaining() { |
255 return print_preview_pages_remaining_; | 268 return print_preview_pages_remaining_; |
256 } | 269 } |
OLD | NEW |