blob: d89ea739c56478c1ed5127388aaa4afff80febec [file] [log] [blame]
[email protected]9f4f3322012-01-18 22:29:561// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]c6d068ff2011-10-14 17:28:232// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CONTENT_TEST_MOCK_RENDER_THREAD_H_
6#define CONTENT_TEST_MOCK_RENDER_THREAD_H_
7#pragma once
8
9#include "base/shared_memory.h"
[email protected]6f8f8b632011-12-05 16:43:5510#include "base/string16.h"
[email protected]c6d068ff2011-10-14 17:28:2311#include "content/public/renderer/render_thread.h"
12#include "ipc/ipc_test_sink.h"
13#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupType.h"
14
15namespace IPC {
16class MessageReplyDeserializer;
17}
18
19namespace content {
20
21// This class is a very simple mock of RenderThread. It simulates an IPC channel
22// which supports only two messages:
23// ViewHostMsg_CreateWidget : sync message sent by the Widget.
24// ViewMsg_Close : async, send to the Widget.
25class MockRenderThread : public content::RenderThread {
26 public:
27 MockRenderThread();
28 virtual ~MockRenderThread();
29
30 // Provides access to the messages that have been received by this thread.
31 IPC::TestSink& sink() { return sink_; }
32
[email protected]6f8f8b632011-12-05 16:43:5533 // Helpers for embedders to know when content IPC messages are received, since
34 // they don't have access to content IPC files.
35 void VerifyRunJavaScriptMessageSend(const string16& expected_alert_message);
36
[email protected]c6d068ff2011-10-14 17:28:2337 // content::RenderThread implementation:
38 virtual bool Send(IPC::Message* msg) OVERRIDE;
39 virtual MessageLoop* GetMessageLoop() OVERRIDE;
40 virtual IPC::SyncChannel* GetChannel() OVERRIDE;
41 virtual std::string GetLocale() OVERRIDE;
[email protected]07bb6332012-01-21 01:07:5742 virtual IPC::SyncMessageFilter* GetSyncMessageFilter() OVERRIDE;
[email protected]c6d068ff2011-10-14 17:28:2343 virtual void AddRoute(int32 routing_id,
44 IPC::Channel::Listener* listener) OVERRIDE;
45 virtual void RemoveRoute(int32 routing_id) OVERRIDE;
[email protected]77fc9b92011-10-15 16:20:3746 virtual int GenerateRoutingID() OVERRIDE;
[email protected]c6d068ff2011-10-14 17:28:2347 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter) OVERRIDE;
48 virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) OVERRIDE;
49 virtual void SetOutgoingMessageFilter(
50 IPC::ChannelProxy::OutgoingMessageFilter* filter) OVERRIDE;
51 virtual void AddObserver(content::RenderProcessObserver* observer) OVERRIDE;
52 virtual void RemoveObserver(
53 content::RenderProcessObserver* observer) OVERRIDE;
54 virtual void SetResourceDispatcherDelegate(
55 content::ResourceDispatcherDelegate* delegate) OVERRIDE;
56 virtual void WidgetHidden() OVERRIDE;
57 virtual void WidgetRestored() OVERRIDE;
58 virtual void EnsureWebKitInitialized() OVERRIDE;
59 virtual void RecordUserMetrics(const std::string& action) OVERRIDE;
60 virtual base::SharedMemoryHandle HostAllocateSharedMemoryBuffer(
61 uint32 buffer_size) OVERRIDE;
62 virtual void RegisterExtension(v8::Extension* extension) OVERRIDE;
63 virtual bool IsRegisteredExtension(
64 const std::string& v8_extension_name) const OVERRIDE;
[email protected]6593ae12011-11-14 12:09:4465 virtual void ScheduleIdleHandler(int64 initial_delay_ms) OVERRIDE;
[email protected]c6d068ff2011-10-14 17:28:2366 virtual void IdleHandler() OVERRIDE;
[email protected]6593ae12011-11-14 12:09:4467 virtual int64 GetIdleNotificationDelayInMs() const OVERRIDE;
68 virtual void SetIdleNotificationDelayInMs(
69 int64 idle_notification_delay_in_ms) OVERRIDE;
[email protected]c6d068ff2011-10-14 17:28:2370#if defined(OS_WIN)
71 virtual void PreCacheFont(const LOGFONT& log_font) OVERRIDE;
72 virtual void ReleaseCachedFonts() OVERRIDE;
73#endif
74
75 //////////////////////////////////////////////////////////////////////////
76 // The following functions are called by the test itself.
77
78 void set_routing_id(int32 id) {
79 routing_id_ = id;
80 }
81
[email protected]9f4f3322012-01-18 22:29:5682 void set_surface_id(int32 id) {
83 surface_id_ = id;
84 }
85
[email protected]c6d068ff2011-10-14 17:28:2386 int32 opener_id() const {
87 return opener_id_;
88 }
89
90 bool has_widget() const {
91 return widget_ ? true : false;
92 }
93
94 // Simulates the Widget receiving a close message. This should result
95 // on releasing the internal reference counts and destroying the internal
96 // state.
97 void SendCloseMessage();
98
99 protected:
100 // This function operates as a regular IPC listener. Subclasses
101 // overriding this should first delegate to this implementation.
102 virtual bool OnMessageReceived(const IPC::Message& msg);
103
104 // The Widget expects to be returned valid route_id.
105 void OnMsgCreateWidget(int opener_id,
106 WebKit::WebPopupType popup_type,
[email protected]9f4f3322012-01-18 22:29:56107 int* route_id,
108 int* surface_id);
[email protected]c6d068ff2011-10-14 17:28:23109
110#if defined(OS_WIN)
111 void OnDuplicateSection(base::SharedMemoryHandle renderer_handle,
112 base::SharedMemoryHandle* browser_handle);
113#endif
114
115 IPC::TestSink sink_;
116
117 // Routing id what will be assigned to the Widget.
118 int32 routing_id_;
119
[email protected]9f4f3322012-01-18 22:29:56120 // Surface id what will be assigned to the Widget.
121 int32 surface_id_;
122
[email protected]c6d068ff2011-10-14 17:28:23123 // Opener id reported by the Widget.
124 int32 opener_id_;
125
126 // We only keep track of one Widget, we learn its pointer when it
127 // adds a new route.
128 IPC::Channel::Listener* widget_;
129
130 // The last known good deserializer for sync messages.
131 scoped_ptr<IPC::MessageReplyDeserializer> reply_deserializer_;
132};
133
134} // namespace content
135
136#endif // CONTENT_TEST_MOCK_RENDER_THREAD_H_