[email protected] | c6d068ff | 2011-10-14 17:28:23 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_RENDERER_CHROME_MOCK_RENDER_THREAD_H_ |
| 6 | #define CHROME_RENDERER_CHROME_MOCK_RENDER_THREAD_H_ |
[email protected] | c6d068ff | 2011-10-14 17:28:23 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "base/compiler_specific.h" |
[email protected] | 08a932d5 | 2012-06-03 21:42:12 | [diff] [blame] | 11 | #include "content/public/test/mock_render_thread.h" |
[email protected] | c6d068ff | 2011-10-14 17:28:23 | [diff] [blame] | 12 | |
| 13 | namespace base { |
| 14 | class DictionaryValue; |
| 15 | } |
| 16 | |
[email protected] | 116d096 | 2012-08-24 23:22:28 | [diff] [blame] | 17 | class MockPrinter; |
[email protected] | 686914f | 2013-04-25 04:54:58 | [diff] [blame] | 18 | struct ExtensionMsg_ExternalConnectionInfo; |
[email protected] | c6d068ff | 2011-10-14 17:28:23 | [diff] [blame] | 19 | struct PrintHostMsg_DidGetPreviewPageCount_Params; |
| 20 | struct PrintHostMsg_DidPreviewPage_Params; |
[email protected] | 116d096 | 2012-08-24 23:22:28 | [diff] [blame] | 21 | struct PrintHostMsg_DidPrintPage_Params; |
[email protected] | c6d068ff | 2011-10-14 17:28:23 | [diff] [blame] | 22 | struct PrintHostMsg_ScriptedPrint_Params; |
| 23 | struct PrintMsg_PrintPages_Params; |
| 24 | struct PrintMsg_Print_Params; |
| 25 | |
| 26 | // Extends content::MockRenderThread to know about printing and |
| 27 | // extension messages. |
| 28 | class ChromeMockRenderThread : public content::MockRenderThread { |
| 29 | public: |
| 30 | ChromeMockRenderThread(); |
| 31 | virtual ~ChromeMockRenderThread(); |
| 32 | |
[email protected] | c9a49a5 | 2013-10-25 02:20:53 | [diff] [blame^] | 33 | // content::RenderThread overrides. |
| 34 | virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() |
| 35 | OVERRIDE; |
| 36 | |
[email protected] | c6d068ff | 2011-10-14 17:28:23 | [diff] [blame] | 37 | ////////////////////////////////////////////////////////////////////////// |
| 38 | // The following functions are called by the test itself. |
| 39 | |
[email protected] | c9a49a5 | 2013-10-25 02:20:53 | [diff] [blame^] | 40 | // Set IO message loop proxy. |
| 41 | void set_io_message_loop_proxy( |
| 42 | const scoped_refptr<base::MessageLoopProxy>& proxy); |
| 43 | |
[email protected] | 1e54c1c | 2013-08-12 17:16:05 | [diff] [blame] | 44 | #if defined(ENABLE_PRINTING) |
[email protected] | c6d068ff | 2011-10-14 17:28:23 | [diff] [blame] | 45 | // Returns the pseudo-printer instance. |
[email protected] | 116d096 | 2012-08-24 23:22:28 | [diff] [blame] | 46 | MockPrinter* printer(); |
[email protected] | c6d068ff | 2011-10-14 17:28:23 | [diff] [blame] | 47 | |
| 48 | // Call with |response| set to true if the user wants to print. |
| 49 | // False if the user decides to cancel. |
| 50 | void set_print_dialog_user_response(bool response); |
| 51 | |
| 52 | // Cancel print preview when print preview has |page| remaining pages. |
| 53 | void set_print_preview_cancel_page_number(int page); |
| 54 | |
| 55 | // Get the number of pages to generate for print preview. |
[email protected] | 116d096 | 2012-08-24 23:22:28 | [diff] [blame] | 56 | int print_preview_pages_remaining() const; |
[email protected] | 1e54c1c | 2013-08-12 17:16:05 | [diff] [blame] | 57 | #endif |
[email protected] | c6d068ff | 2011-10-14 17:28:23 | [diff] [blame] | 58 | |
| 59 | private: |
| 60 | // Overrides base class implementation to add custom handling for |
| 61 | // print and extensions. |
[email protected] | 5341642 | 2011-11-21 16:53:54 | [diff] [blame] | 62 | virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
[email protected] | c6d068ff | 2011-10-14 17:28:23 | [diff] [blame] | 63 | |
| 64 | // The callee expects to be returned a valid channel_id. |
[email protected] | 3d9ec505 | 2013-01-02 22:05:25 | [diff] [blame] | 65 | void OnOpenChannelToExtension(int routing_id, |
[email protected] | 686914f | 2013-04-25 04:54:58 | [diff] [blame] | 66 | const ExtensionMsg_ExternalConnectionInfo& info, |
| 67 | const std::string& channel_name, |
[email protected] | 8ad95b7 | 2013-10-16 02:54:11 | [diff] [blame] | 68 | bool include_tls_channel_id, |
[email protected] | 3d9ec505 | 2013-01-02 22:05:25 | [diff] [blame] | 69 | int* port_id); |
[email protected] | c6d068ff | 2011-10-14 17:28:23 | [diff] [blame] | 70 | |
[email protected] | 1e54c1c | 2013-08-12 17:16:05 | [diff] [blame] | 71 | #if defined(ENABLE_PRINTING) |
[email protected] | b25f003 | 2013-08-19 22:26:25 | [diff] [blame] | 72 | #if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
| 73 | void OnAllocateTempFileForPrinting(int render_view_id, |
| 74 | base::FileDescriptor* renderer_fd, |
[email protected] | c6d068ff | 2011-10-14 17:28:23 | [diff] [blame] | 75 | int* browser_fd); |
[email protected] | b5b79d7 | 2012-05-24 19:42:28 | [diff] [blame] | 76 | void OnTempFileForPrintingWritten(int render_view_id, int browser_fd); |
[email protected] | c6d068ff | 2011-10-14 17:28:23 | [diff] [blame] | 77 | #endif |
| 78 | |
| 79 | // PrintWebViewHelper expects default print settings. |
| 80 | void OnGetDefaultPrintSettings(PrintMsg_Print_Params* setting); |
| 81 | |
| 82 | // PrintWebViewHelper expects final print settings from the user. |
| 83 | void OnScriptedPrint(const PrintHostMsg_ScriptedPrint_Params& params, |
| 84 | PrintMsg_PrintPages_Params* settings); |
| 85 | |
| 86 | void OnDidGetPrintedPagesCount(int cookie, int number_pages); |
| 87 | void OnDidPrintPage(const PrintHostMsg_DidPrintPage_Params& params); |
| 88 | void OnDidGetPreviewPageCount( |
| 89 | const PrintHostMsg_DidGetPreviewPageCount_Params& params); |
| 90 | void OnDidPreviewPage(const PrintHostMsg_DidPreviewPage_Params& params); |
[email protected] | 116d096 | 2012-08-24 23:22:28 | [diff] [blame] | 91 | void OnCheckForCancel(int32 preview_ui_id, |
[email protected] | c6d068ff | 2011-10-14 17:28:23 | [diff] [blame] | 92 | int preview_request_id, |
| 93 | bool* cancel); |
| 94 | |
| 95 | |
| 96 | // For print preview, PrintWebViewHelper will update settings. |
| 97 | void OnUpdatePrintSettings(int document_cookie, |
| 98 | const base::DictionaryValue& job_settings, |
| 99 | PrintMsg_PrintPages_Params* params); |
| 100 | |
| 101 | // A mock printer device used for printing tests. |
| 102 | scoped_ptr<MockPrinter> printer_; |
| 103 | |
| 104 | // True to simulate user clicking print. False to cancel. |
| 105 | bool print_dialog_user_response_; |
| 106 | |
| 107 | // Simulates cancelling print preview if |print_preview_pages_remaining_| |
| 108 | // equals this. |
| 109 | int print_preview_cancel_page_number_; |
| 110 | |
| 111 | // Number of pages to generate for print preview. |
| 112 | int print_preview_pages_remaining_; |
[email protected] | 1e54c1c | 2013-08-12 17:16:05 | [diff] [blame] | 113 | #endif |
| 114 | |
[email protected] | c9a49a5 | 2013-10-25 02:20:53 | [diff] [blame^] | 115 | scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; |
| 116 | |
[email protected] | 1e54c1c | 2013-08-12 17:16:05 | [diff] [blame] | 117 | DISALLOW_COPY_AND_ASSIGN(ChromeMockRenderThread); |
[email protected] | c6d068ff | 2011-10-14 17:28:23 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | #endif // CHROME_RENDERER_CHROME_MOCK_RENDER_THREAD_H_ |