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.
5 #ifndef CHROME_RENDERER_CHROME_MOCK_RENDER_THREAD_H_
6 #define CHROME_RENDERER_CHROME_MOCK_RENDER_THREAD_H_
10 #include "base/compiler_specific.h"
11 #include "content/public/test/mock_render_thread.h"
14 class DictionaryValue
;
18 struct ExtensionMsg_ExternalConnectionInfo
;
19 struct PrintHostMsg_DidGetPreviewPageCount_Params
;
20 struct PrintHostMsg_DidPreviewPage_Params
;
21 struct PrintHostMsg_DidPrintPage_Params
;
22 struct PrintHostMsg_ScriptedPrint_Params
;
23 struct PrintMsg_PrintPages_Params
;
24 struct PrintMsg_Print_Params
;
26 // Extends content::MockRenderThread to know about printing and
27 // extension messages.
28 class ChromeMockRenderThread
: public content::MockRenderThread
{
30 ChromeMockRenderThread();
31 ~ChromeMockRenderThread() override
;
33 // content::RenderThread overrides.
34 scoped_refptr
<base::MessageLoopProxy
> GetIOMessageLoopProxy() override
;
36 //////////////////////////////////////////////////////////////////////////
37 // The following functions are called by the test itself.
39 // Set IO message loop proxy.
40 void set_io_message_loop_proxy(
41 const scoped_refptr
<base::MessageLoopProxy
>& proxy
);
43 #if defined(ENABLE_PRINTING)
44 // Returns the pseudo-printer instance.
45 MockPrinter
* printer();
47 // Call with |response| set to true if the user wants to print.
48 // False if the user decides to cancel.
49 void set_print_dialog_user_response(bool response
);
51 // Cancel print preview when print preview has |page| remaining pages.
52 void set_print_preview_cancel_page_number(int page
);
54 // Get the number of pages to generate for print preview.
55 int print_preview_pages_remaining() const;
59 // Overrides base class implementation to add custom handling for
60 // print and extensions.
61 bool OnMessageReceived(const IPC::Message
& msg
) override
;
63 #if defined(ENABLE_EXTENSIONS)
64 // The callee expects to be returned a valid channel_id.
65 void OnOpenChannelToExtension(int routing_id
,
66 const ExtensionMsg_ExternalConnectionInfo
& info
,
67 const std::string
& channel_name
,
68 bool include_tls_channel_id
,
72 #if defined(ENABLE_PRINTING)
73 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
74 void OnAllocateTempFileForPrinting(int render_view_id
,
75 base::FileDescriptor
* renderer_fd
,
77 void OnTempFileForPrintingWritten(int render_view_id
, int browser_fd
);
80 // PrintWebViewHelper expects default print settings.
81 void OnGetDefaultPrintSettings(PrintMsg_Print_Params
* setting
);
83 // PrintWebViewHelper expects final print settings from the user.
84 void OnScriptedPrint(const PrintHostMsg_ScriptedPrint_Params
& params
,
85 PrintMsg_PrintPages_Params
* settings
);
87 void OnDidGetPrintedPagesCount(int cookie
, int number_pages
);
88 void OnDidPrintPage(const PrintHostMsg_DidPrintPage_Params
& params
);
89 void OnDidGetPreviewPageCount(
90 const PrintHostMsg_DidGetPreviewPageCount_Params
& params
);
91 void OnDidPreviewPage(const PrintHostMsg_DidPreviewPage_Params
& params
);
92 void OnCheckForCancel(int32 preview_ui_id
,
93 int preview_request_id
,
97 // For print preview, PrintWebViewHelper will update settings.
98 void OnUpdatePrintSettings(int document_cookie
,
99 const base::DictionaryValue
& job_settings
,
100 PrintMsg_PrintPages_Params
* params
,
103 // A mock printer device used for printing tests.
104 scoped_ptr
<MockPrinter
> printer_
;
106 // True to simulate user clicking print. False to cancel.
107 bool print_dialog_user_response_
;
109 // Simulates cancelling print preview if |print_preview_pages_remaining_|
111 int print_preview_cancel_page_number_
;
113 // Number of pages to generate for print preview.
114 int print_preview_pages_remaining_
;
117 scoped_refptr
<base::MessageLoopProxy
> io_message_loop_proxy_
;
119 DISALLOW_COPY_AND_ASSIGN(ChromeMockRenderThread
);
122 #endif // CHROME_RENDERER_CHROME_MOCK_RENDER_THREAD_H_