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

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: Ready for review! 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
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 ResourceDispatcher* GetResourceDispatcher() OVERRIDE;
50 virtual std::string GetLocale() OVERRIDE;
51 virtual void AddRoute(int32 routing_id,
52 IPC::Channel::Listener* listener) OVERRIDE;
53 virtual void RemoveRoute(int32 routing_id) OVERRIDE;
54 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter) OVERRIDE;
55 virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) OVERRIDE;
56 virtual void SetOutgoingMessageFilter(
57 IPC::ChannelProxy::OutgoingMessageFilter* filter) OVERRIDE;
58 virtual void AddObserver(content::RenderProcessObserver* observer) OVERRIDE;
59 virtual void RemoveObserver(
60 content::RenderProcessObserver* observer) OVERRIDE;
61 virtual void WidgetHidden() OVERRIDE;
62 virtual void WidgetRestored() OVERRIDE;
63 virtual void EnsureWebKitInitialized() OVERRIDE;
64 virtual void RecordUserMetrics(const std::string& action) OVERRIDE;
65 virtual base::SharedMemoryHandle HostAllocateSharedMemoryBuffer(
66 uint32 buffer_size) OVERRIDE;
67 virtual void RegisterExtension(v8::Extension* extension) OVERRIDE;
68 virtual bool IsRegisteredExtension(
69 const std::string& v8_extension_name) const OVERRIDE;
70 virtual void ScheduleIdleHandler(double initial_delay_s) OVERRIDE;
71 virtual void IdleHandler() OVERRIDE;
72 virtual double GetIdleNotificationDelayInS() const OVERRIDE;
73 virtual void SetIdleNotificationDelayInS(
74 double idle_notification_delay_in_s) OVERRIDE;
75 #if defined(OS_WIN)
76 virtual void PreCacheFont(const LOGFONT& log_font) OVERRIDE;
77 virtual void ReleaseCachedFonts() OVERRIDE;
78 #endif
79
80 //////////////////////////////////////////////////////////////////////////
81 // The following functions are called by the test itself.
82
83 void set_routing_id(int32 id) {
84 routing_id_ = id;
85 }
86
87 int32 opener_id() const {
88 return opener_id_;
89 }
90
91 bool has_widget() const {
92 return widget_ ? true : false;
93 }
94
95 // Simulates the Widget receiving a close message. This should result
96 // on releasing the internal reference counts and destroying the internal
97 // state.
98 void SendCloseMessage();
99
100 // Returns the pseudo-printer instance.
101 MockPrinter* printer() const { return printer_.get(); }
102
103 // Call with |response| set to true if the user wants to print.
104 // False if the user decides to cancel.
105 void set_print_dialog_user_response(bool response);
106
107 // Cancel print preview when print preview has |page| remaining pages.
108 void set_print_preview_cancel_page_number(int page);
109
110 // Get the number of pages to generate for print preview.
111 int print_preview_pages_remaining();
112
113 private:
114 // This function operates as a regular IPC listener.
115 bool OnMessageReceived(const IPC::Message& msg);
116
117 // The Widget expects to be returned valid route_id.
118 void OnMsgCreateWidget(int opener_id,
119 WebKit::WebPopupType popup_type,
120 int* route_id);
121
122 // The callee expects to be returned a valid channel_id.
123 void OnMsgOpenChannelToExtension(
124 int routing_id, const std::string& extension_id,
125 const std::string& source_extension_id,
126 const std::string& target_extension_id, int* port_id);
127
128 #if defined(OS_WIN)
129 void OnDuplicateSection(base::SharedMemoryHandle renderer_handle,
130 base::SharedMemoryHandle* browser_handle);
131 #endif
132
133 #if defined(OS_CHROMEOS)
134 void OnAllocateTempFileForPrinting(base::FileDescriptor* renderer_fd,
135 int* browser_fd);
136 void OnTempFileForPrintingWritten(int browser_fd);
137 #endif
138
139 // PrintWebViewHelper expects default print settings.
140 void OnGetDefaultPrintSettings(PrintMsg_Print_Params* setting);
141
142 // PrintWebViewHelper expects final print settings from the user.
143 void OnScriptedPrint(const PrintHostMsg_ScriptedPrint_Params& params,
144 PrintMsg_PrintPages_Params* settings);
145
146 void OnDidGetPrintedPagesCount(int cookie, int number_pages);
147 void OnDidPrintPage(const PrintHostMsg_DidPrintPage_Params& params);
148 void OnDidGetPreviewPageCount(
149 const PrintHostMsg_DidGetPreviewPageCount_Params& params);
150 void OnDidPreviewPage(const PrintHostMsg_DidPreviewPage_Params& params);
151 void OnCheckForCancel(const std::string& preview_ui_addr,
152 int preview_request_id,
153 bool* cancel);
154
155
156 // For print preview, PrintWebViewHelper will update settings.
157 void OnUpdatePrintSettings(int document_cookie,
158 const base::DictionaryValue& job_settings,
159 PrintMsg_PrintPages_Params* params);
160
161 IPC::TestSink sink_;
162
163 // Routing id what will be assigned to the Widget.
164 int32 routing_id_;
165
166 // Opener id reported by the Widget.
167 int32 opener_id_;
168
169 // We only keep track of one Widget, we learn its pointer when it
170 // adds a new route.
171 IPC::Channel::Listener* widget_;
172
173 // The last known good deserializer for sync messages.
174 scoped_ptr<IPC::MessageReplyDeserializer> reply_deserializer_;
175
176 // A mock printer device used for printing tests.
177 scoped_ptr<MockPrinter> printer_;
178
179 // True to simulate user clicking print. False to cancel.
180 bool print_dialog_user_response_;
181
182 // Simulates cancelling print preview if |print_preview_pages_remaining_|
183 // equals this.
184 int print_preview_cancel_page_number_;
185
186 // Number of pages to generate for print preview.
187 int print_preview_pages_remaining_;
188 };
189
190 #endif // CHROME_RENDERER_MOCK_RENDER_THREAD_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698