| 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 #ifndef CHROME_RENDERER_CHROME_MOCK_RENDER_THREAD_H_ | 5 #ifndef CHROME_RENDERER_CHROME_MOCK_RENDER_THREAD_H_ |
| 6 #define CHROME_RENDERER_CHROME_MOCK_RENDER_THREAD_H_ | 6 #define CHROME_RENDERER_CHROME_MOCK_RENDER_THREAD_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "chrome/common/extensions/extension_set.h" | |
| 12 #include "chrome/renderer/mock_printer.h" | |
| 13 #include "content/public/test/mock_render_thread.h" | 11 #include "content/public/test/mock_render_thread.h" |
| 14 | 12 |
| 15 namespace base { | 13 namespace base { |
| 16 class DictionaryValue; | 14 class DictionaryValue; |
| 17 } | 15 } |
| 18 | 16 |
| 17 class MockPrinter; |
| 19 struct PrintHostMsg_DidGetPreviewPageCount_Params; | 18 struct PrintHostMsg_DidGetPreviewPageCount_Params; |
| 20 struct PrintHostMsg_DidPreviewPage_Params; | 19 struct PrintHostMsg_DidPreviewPage_Params; |
| 20 struct PrintHostMsg_DidPrintPage_Params; |
| 21 struct PrintHostMsg_ScriptedPrint_Params; | 21 struct PrintHostMsg_ScriptedPrint_Params; |
| 22 struct PrintMsg_PrintPages_Params; | 22 struct PrintMsg_PrintPages_Params; |
| 23 struct PrintMsg_Print_Params; | 23 struct PrintMsg_Print_Params; |
| 24 | 24 |
| 25 // Extends content::MockRenderThread to know about printing and | 25 // Extends content::MockRenderThread to know about printing and |
| 26 // extension messages. | 26 // extension messages. |
| 27 class ChromeMockRenderThread : public content::MockRenderThread { | 27 class ChromeMockRenderThread : public content::MockRenderThread { |
| 28 public: | 28 public: |
| 29 ChromeMockRenderThread(); | 29 ChromeMockRenderThread(); |
| 30 virtual ~ChromeMockRenderThread(); | 30 virtual ~ChromeMockRenderThread(); |
| 31 | 31 |
| 32 ////////////////////////////////////////////////////////////////////////// | 32 ////////////////////////////////////////////////////////////////////////// |
| 33 // The following functions are called by the test itself. | 33 // The following functions are called by the test itself. |
| 34 | 34 |
| 35 // Returns the pseudo-printer instance. | 35 // Returns the pseudo-printer instance. |
| 36 MockPrinter* printer() const { return printer_.get(); } | 36 MockPrinter* printer(); |
| 37 | 37 |
| 38 // Call with |response| set to true if the user wants to print. | 38 // Call with |response| set to true if the user wants to print. |
| 39 // False if the user decides to cancel. | 39 // False if the user decides to cancel. |
| 40 void set_print_dialog_user_response(bool response); | 40 void set_print_dialog_user_response(bool response); |
| 41 | 41 |
| 42 // Cancel print preview when print preview has |page| remaining pages. | 42 // Cancel print preview when print preview has |page| remaining pages. |
| 43 void set_print_preview_cancel_page_number(int page); | 43 void set_print_preview_cancel_page_number(int page); |
| 44 | 44 |
| 45 // Get the number of pages to generate for print preview. | 45 // Get the number of pages to generate for print preview. |
| 46 int print_preview_pages_remaining(); | 46 int print_preview_pages_remaining() const; |
| 47 | 47 |
| 48 private: | 48 private: |
| 49 // Overrides base class implementation to add custom handling for | 49 // Overrides base class implementation to add custom handling for |
| 50 // print and extensions. | 50 // print and extensions. |
| 51 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | 51 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
| 52 | 52 |
| 53 // The callee expects to be returned a valid channel_id. | 53 // The callee expects to be returned a valid channel_id. |
| 54 void OnMsgOpenChannelToExtension( | 54 void OnMsgOpenChannelToExtension(int routing_id, |
| 55 int routing_id, const std::string& extension_id, | 55 const std::string& extension_id, |
| 56 const std::string& source_extension_id, | 56 const std::string& source_extension_id, |
| 57 const std::string& target_extension_id, int* port_id); | 57 const std::string& target_extension_id, |
| 58 int* port_id); |
| 58 | 59 |
| 59 #if defined(OS_CHROMEOS) | 60 #if defined(OS_CHROMEOS) |
| 60 void OnAllocateTempFileForPrinting(base::FileDescriptor* renderer_fd, | 61 void OnAllocateTempFileForPrinting(base::FileDescriptor* renderer_fd, |
| 61 int* browser_fd); | 62 int* browser_fd); |
| 62 void OnTempFileForPrintingWritten(int render_view_id, int browser_fd); | 63 void OnTempFileForPrintingWritten(int render_view_id, int browser_fd); |
| 63 #endif | 64 #endif |
| 64 | 65 |
| 65 // PrintWebViewHelper expects default print settings. | 66 // PrintWebViewHelper expects default print settings. |
| 66 void OnGetDefaultPrintSettings(PrintMsg_Print_Params* setting); | 67 void OnGetDefaultPrintSettings(PrintMsg_Print_Params* setting); |
| 67 | 68 |
| 68 // PrintWebViewHelper expects final print settings from the user. | 69 // PrintWebViewHelper expects final print settings from the user. |
| 69 void OnScriptedPrint(const PrintHostMsg_ScriptedPrint_Params& params, | 70 void OnScriptedPrint(const PrintHostMsg_ScriptedPrint_Params& params, |
| 70 PrintMsg_PrintPages_Params* settings); | 71 PrintMsg_PrintPages_Params* settings); |
| 71 | 72 |
| 72 void OnDidGetPrintedPagesCount(int cookie, int number_pages); | 73 void OnDidGetPrintedPagesCount(int cookie, int number_pages); |
| 73 void OnDidPrintPage(const PrintHostMsg_DidPrintPage_Params& params); | 74 void OnDidPrintPage(const PrintHostMsg_DidPrintPage_Params& params); |
| 74 void OnDidGetPreviewPageCount( | 75 void OnDidGetPreviewPageCount( |
| 75 const PrintHostMsg_DidGetPreviewPageCount_Params& params); | 76 const PrintHostMsg_DidGetPreviewPageCount_Params& params); |
| 76 void OnDidPreviewPage(const PrintHostMsg_DidPreviewPage_Params& params); | 77 void OnDidPreviewPage(const PrintHostMsg_DidPreviewPage_Params& params); |
| 77 void OnCheckForCancel(const std::string& preview_ui_addr, | 78 void OnCheckForCancel(int32 preview_ui_id, |
| 78 int preview_request_id, | 79 int preview_request_id, |
| 79 bool* cancel); | 80 bool* cancel); |
| 80 | 81 |
| 81 | 82 |
| 82 // For print preview, PrintWebViewHelper will update settings. | 83 // For print preview, PrintWebViewHelper will update settings. |
| 83 void OnUpdatePrintSettings(int document_cookie, | 84 void OnUpdatePrintSettings(int document_cookie, |
| 84 const base::DictionaryValue& job_settings, | 85 const base::DictionaryValue& job_settings, |
| 85 PrintMsg_PrintPages_Params* params); | 86 PrintMsg_PrintPages_Params* params); |
| 86 | 87 |
| 87 // A mock printer device used for printing tests. | 88 // A mock printer device used for printing tests. |
| 88 scoped_ptr<MockPrinter> printer_; | 89 scoped_ptr<MockPrinter> printer_; |
| 89 | 90 |
| 90 // True to simulate user clicking print. False to cancel. | 91 // True to simulate user clicking print. False to cancel. |
| 91 bool print_dialog_user_response_; | 92 bool print_dialog_user_response_; |
| 92 | 93 |
| 93 // Simulates cancelling print preview if |print_preview_pages_remaining_| | 94 // Simulates cancelling print preview if |print_preview_pages_remaining_| |
| 94 // equals this. | 95 // equals this. |
| 95 int print_preview_cancel_page_number_; | 96 int print_preview_cancel_page_number_; |
| 96 | 97 |
| 97 // Number of pages to generate for print preview. | 98 // Number of pages to generate for print preview. |
| 98 int print_preview_pages_remaining_; | 99 int print_preview_pages_remaining_; |
| 99 }; | 100 }; |
| 100 | 101 |
| 101 #endif // CHROME_RENDERER_CHROME_MOCK_RENDER_THREAD_H_ | 102 #endif // CHROME_RENDERER_CHROME_MOCK_RENDER_THREAD_H_ |
| OLD | NEW |