Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / renderer / chrome_mock_render_thread.h
blobb17ef4da304235edbd26e298d18e473e5c4ceca1
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_
8 #include <string>
10 #include "base/compiler_specific.h"
11 #include "content/public/test/mock_render_thread.h"
13 namespace base {
14 class DictionaryValue;
17 class MockPrinter;
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 {
29 public:
30 ChromeMockRenderThread();
31 virtual ~ChromeMockRenderThread();
33 // content::RenderThread overrides.
34 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy()
35 override;
37 //////////////////////////////////////////////////////////////////////////
38 // The following functions are called by the test itself.
40 // Set IO message loop proxy.
41 void set_io_message_loop_proxy(
42 const scoped_refptr<base::MessageLoopProxy>& proxy);
44 #if defined(ENABLE_PRINTING)
45 // Returns the pseudo-printer instance.
46 MockPrinter* printer();
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);
52 // Cancel print preview when print preview has |page| remaining pages.
53 void set_print_preview_cancel_page_number(int page);
55 // Get the number of pages to generate for print preview.
56 int print_preview_pages_remaining() const;
57 #endif
59 private:
60 // Overrides base class implementation to add custom handling for
61 // print and extensions.
62 virtual bool OnMessageReceived(const IPC::Message& msg) override;
64 #if defined(ENABLE_EXTENSIONS)
65 // The callee expects to be returned a valid channel_id.
66 void OnOpenChannelToExtension(int routing_id,
67 const ExtensionMsg_ExternalConnectionInfo& info,
68 const std::string& channel_name,
69 bool include_tls_channel_id,
70 int* port_id);
71 #endif
73 #if defined(ENABLE_PRINTING)
74 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
75 void OnAllocateTempFileForPrinting(int render_view_id,
76 base::FileDescriptor* renderer_fd,
77 int* browser_fd);
78 void OnTempFileForPrintingWritten(int render_view_id, int browser_fd);
79 #endif
81 // PrintWebViewHelper expects default print settings.
82 void OnGetDefaultPrintSettings(PrintMsg_Print_Params* setting);
84 // PrintWebViewHelper expects final print settings from the user.
85 void OnScriptedPrint(const PrintHostMsg_ScriptedPrint_Params& params,
86 PrintMsg_PrintPages_Params* settings);
88 void OnDidGetPrintedPagesCount(int cookie, int number_pages);
89 void OnDidPrintPage(const PrintHostMsg_DidPrintPage_Params& params);
90 void OnDidGetPreviewPageCount(
91 const PrintHostMsg_DidGetPreviewPageCount_Params& params);
92 void OnDidPreviewPage(const PrintHostMsg_DidPreviewPage_Params& params);
93 void OnCheckForCancel(int32 preview_ui_id,
94 int preview_request_id,
95 bool* cancel);
98 // For print preview, PrintWebViewHelper will update settings.
99 void OnUpdatePrintSettings(int document_cookie,
100 const base::DictionaryValue& job_settings,
101 PrintMsg_PrintPages_Params* params,
102 bool* canceled);
104 // A mock printer device used for printing tests.
105 scoped_ptr<MockPrinter> printer_;
107 // True to simulate user clicking print. False to cancel.
108 bool print_dialog_user_response_;
110 // Simulates cancelling print preview if |print_preview_pages_remaining_|
111 // equals this.
112 int print_preview_cancel_page_number_;
114 // Number of pages to generate for print preview.
115 int print_preview_pages_remaining_;
116 #endif
118 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
120 DISALLOW_COPY_AND_ASSIGN(ChromeMockRenderThread);
123 #endif // CHROME_RENDERER_CHROME_MOCK_RENDER_THREAD_H_