Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: chrome/renderer/mock_render_thread.h

Issue 8230034: Split most of RenderViewTest and associated classes into content. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Mac build breaks. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/mock_keyboard_driver_win.cc ('k') | chrome/renderer/mock_render_thread.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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_MOCK_RENDER_THREAD_H_
6 #define CHROME_RENDERER_MOCK_RENDER_THREAD_H_
7 #pragma once
8
9 #include <string>
10
11 #include "base/compiler_specific.h"
12 #include "base/shared_memory.h"
13 #include "chrome/common/extensions/extension_set.h"
14 #include "chrome/renderer/mock_printer.h"
15 #include "content/public/renderer/render_thread.h"
16 #include "ipc/ipc_test_sink.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupType.h"
18
19 namespace IPC {
20 class MessageReplyDeserializer;
21 }
22
23 namespace base {
24 class DictionaryValue;
25 }
26
27 struct PrintHostMsg_DidGetPreviewPageCount_Params;
28 struct PrintHostMsg_DidPreviewPage_Params;
29 struct PrintHostMsg_ScriptedPrint_Params;
30 struct PrintMsg_PrintPages_Params;
31 struct PrintMsg_Print_Params;
32
33 // This class is very simple mock of RenderThread. It simulates an IPC channel
34 // which supports only two messages:
35 // ViewHostMsg_CreateWidget : sync message sent by the Widget.
36 // ViewMsg_Close : async, send to the Widget.
37 class MockRenderThread : public content::RenderThread {
38 public:
39 MockRenderThread();
40 virtual ~MockRenderThread();
41
42 // Provides access to the messages that have been received by this thread.
43 IPC::TestSink& sink() { return sink_; }
44
45 // content::RenderThread implementation:
46 virtual bool Send(IPC::Message* msg) OVERRIDE;
47 virtual MessageLoop* GetMessageLoop() OVERRIDE;
48 virtual IPC::SyncChannel* GetChannel() OVERRIDE;
49 virtual std::string GetLocale() OVERRIDE;
50 virtual void AddRoute(int32 routing_id,
51 IPC::Channel::Listener* listener) OVERRIDE;
52 virtual void RemoveRoute(int32 routing_id) OVERRIDE;
53 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter) OVERRIDE;
54 virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) OVERRIDE;
55 virtual void SetOutgoingMessageFilter(
56 IPC::ChannelProxy::OutgoingMessageFilter* filter) OVERRIDE;
57 virtual void AddObserver(content::RenderProcessObserver* observer) OVERRIDE;
58 virtual void RemoveObserver(
59 content::RenderProcessObserver* observer) OVERRIDE;
60 virtual void SetResourceDispatcherDelegate(
61 content::ResourceDispatcherDelegate* delegate) OVERRIDE;
62 virtual void WidgetHidden() OVERRIDE;
63 virtual void WidgetRestored() OVERRIDE;
64 virtual void EnsureWebKitInitialized() OVERRIDE;
65 virtual void RecordUserMetrics(const std::string& action) OVERRIDE;
66 virtual base::SharedMemoryHandle HostAllocateSharedMemoryBuffer(
67 uint32 buffer_size) OVERRIDE;
68 virtual void RegisterExtension(v8::Extension* extension) OVERRIDE;
69 virtual bool IsRegisteredExtension(
70 const std::string& v8_extension_name) const OVERRIDE;
71 virtual void ScheduleIdleHandler(double initial_delay_s) OVERRIDE;
72 virtual void IdleHandler() OVERRIDE;
73 virtual double GetIdleNotificationDelayInS() const OVERRIDE;
74 virtual void SetIdleNotificationDelayInS(
75 double idle_notification_delay_in_s) OVERRIDE;
76 #if defined(OS_WIN)
77 virtual void PreCacheFont(const LOGFONT& log_font) OVERRIDE;
78 virtual void ReleaseCachedFonts() OVERRIDE;
79 #endif
80
81 //////////////////////////////////////////////////////////////////////////
82 // The following functions are called by the test itself.
83
84 void set_routing_id(int32 id) {
85 routing_id_ = id;
86 }
87
88 int32 opener_id() const {
89 return opener_id_;
90 }
91
92 bool has_widget() const {
93 return widget_ ? true : false;
94 }
95
96 // Simulates the Widget receiving a close message. This should result
97 // on releasing the internal reference counts and destroying the internal
98 // state.
99 void SendCloseMessage();
100
101 // Returns the pseudo-printer instance.
102 MockPrinter* printer() const { return printer_.get(); }
103
104 // Call with |response| set to true if the user wants to print.
105 // False if the user decides to cancel.
106 void set_print_dialog_user_response(bool response);
107
108 // Cancel print preview when print preview has |page| remaining pages.
109 void set_print_preview_cancel_page_number(int page);
110
111 // Get the number of pages to generate for print preview.
112 int print_preview_pages_remaining();
113
114 private:
115 // This function operates as a regular IPC listener.
116 bool OnMessageReceived(const IPC::Message& msg);
117
118 // The Widget expects to be returned valid route_id.
119 void OnMsgCreateWidget(int opener_id,
120 WebKit::WebPopupType popup_type,
121 int* route_id);
122
123 // The callee expects to be returned a valid channel_id.
124 void OnMsgOpenChannelToExtension(
125 int routing_id, const std::string& extension_id,
126 const std::string& source_extension_id,
127 const std::string& target_extension_id, int* port_id);
128
129 #if defined(OS_WIN)
130 void OnDuplicateSection(base::SharedMemoryHandle renderer_handle,
131 base::SharedMemoryHandle* browser_handle);
132 #endif
133
134 #if defined(OS_CHROMEOS)
135 void OnAllocateTempFileForPrinting(base::FileDescriptor* renderer_fd,
136 int* browser_fd);
137 void OnTempFileForPrintingWritten(int browser_fd);
138 #endif
139
140 // PrintWebViewHelper expects default print settings.
141 void OnGetDefaultPrintSettings(PrintMsg_Print_Params* setting);
142
143 // PrintWebViewHelper expects final print settings from the user.
144 void OnScriptedPrint(const PrintHostMsg_ScriptedPrint_Params& params,
145 PrintMsg_PrintPages_Params* settings);
146
147 void OnDidGetPrintedPagesCount(int cookie, int number_pages);
148 void OnDidPrintPage(const PrintHostMsg_DidPrintPage_Params& params);
149 void OnDidGetPreviewPageCount(
150 const PrintHostMsg_DidGetPreviewPageCount_Params& params);
151 void OnDidPreviewPage(const PrintHostMsg_DidPreviewPage_Params& params);
152 void OnCheckForCancel(const std::string& preview_ui_addr,
153 int preview_request_id,
154 bool* cancel);
155
156
157 // For print preview, PrintWebViewHelper will update settings.
158 void OnUpdatePrintSettings(int document_cookie,
159 const base::DictionaryValue& job_settings,
160 PrintMsg_PrintPages_Params* params);
161
162 IPC::TestSink sink_;
163
164 // Routing id what will be assigned to the Widget.
165 int32 routing_id_;
166
167 // Opener id reported by the Widget.
168 int32 opener_id_;
169
170 // We only keep track of one Widget, we learn its pointer when it
171 // adds a new route.
172 IPC::Channel::Listener* widget_;
173
174 // The last known good deserializer for sync messages.
175 scoped_ptr<IPC::MessageReplyDeserializer> reply_deserializer_;
176
177 // A mock printer device used for printing tests.
178 scoped_ptr<MockPrinter> printer_;
179
180 // True to simulate user clicking print. False to cancel.
181 bool print_dialog_user_response_;
182
183 // Simulates cancelling print preview if |print_preview_pages_remaining_|
184 // equals this.
185 int print_preview_cancel_page_number_;
186
187 // Number of pages to generate for print preview.
188 int print_preview_pages_remaining_;
189 };
190
191 #endif // CHROME_RENDERER_MOCK_RENDER_THREAD_H_
OLDNEW
« no previous file with comments | « chrome/renderer/mock_keyboard_driver_win.cc ('k') | chrome/renderer/mock_render_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698