blob: 0c083a7f7256b83e875f8ff5a7871e7b3f253428 [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;
42 virtual void AddRoute(int32 routing_id,
43 IPC::Channel::Listener* listener) OVERRIDE;
44 virtual void RemoveRoute(int32 routing_id) OVERRIDE;
[email protected]77fc9b92011-10-15 16:20:3745 virtual int GenerateRoutingID() OVERRIDE;
[email protected]c6d068ff2011-10-14 17:28:2346 virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter) OVERRIDE;
47 virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) OVERRIDE;
48 virtual void SetOutgoingMessageFilter(
49 IPC::ChannelProxy::OutgoingMessageFilter* filter) OVERRIDE;
50 virtual void AddObserver(content::RenderProcessObserver* observer) OVERRIDE;
51 virtual void RemoveObserver(
52 content::RenderProcessObserver* observer) OVERRIDE;
53 virtual void SetResourceDispatcherDelegate(
54 content::ResourceDispatcherDelegate* delegate) OVERRIDE;
55 virtual void WidgetHidden() OVERRIDE;
56 virtual void WidgetRestored() OVERRIDE;
57 virtual void EnsureWebKitInitialized() OVERRIDE;
58 virtual void RecordUserMetrics(const std::string& action) OVERRIDE;
59 virtual base::SharedMemoryHandle HostAllocateSharedMemoryBuffer(
60 uint32 buffer_size) OVERRIDE;
61 virtual void RegisterExtension(v8::Extension* extension) OVERRIDE;
62 virtual bool IsRegisteredExtension(
63 const std::string& v8_extension_name) const OVERRIDE;
[email protected]6593ae12011-11-14 12:09:4464 virtual void ScheduleIdleHandler(int64 initial_delay_ms) OVERRIDE;
[email protected]c6d068ff2011-10-14 17:28:2365 virtual void IdleHandler() OVERRIDE;
[email protected]6593ae12011-11-14 12:09:4466 virtual int64 GetIdleNotificationDelayInMs() const OVERRIDE;
67 virtual void SetIdleNotificationDelayInMs(
68 int64 idle_notification_delay_in_ms) OVERRIDE;
[email protected]c6d068ff2011-10-14 17:28:2369#if defined(OS_WIN)
70 virtual void PreCacheFont(const LOGFONT& log_font) OVERRIDE;
71 virtual void ReleaseCachedFonts() OVERRIDE;
72#endif
73
74 //////////////////////////////////////////////////////////////////////////
75 // The following functions are called by the test itself.
76
77 void set_routing_id(int32 id) {
78 routing_id_ = id;
79 }
80
[email protected]9f4f3322012-01-18 22:29:5681 void set_surface_id(int32 id) {
82 surface_id_ = id;
83 }
84
[email protected]c6d068ff2011-10-14 17:28:2385 int32 opener_id() const {
86 return opener_id_;
87 }
88
89 bool has_widget() const {
90 return widget_ ? true : false;
91 }
92
93 // Simulates the Widget receiving a close message. This should result
94 // on releasing the internal reference counts and destroying the internal
95 // state.
96 void SendCloseMessage();
97
98 protected:
99 // This function operates as a regular IPC listener. Subclasses
100 // overriding this should first delegate to this implementation.
101 virtual bool OnMessageReceived(const IPC::Message& msg);
102
103 // The Widget expects to be returned valid route_id.
104 void OnMsgCreateWidget(int opener_id,
105 WebKit::WebPopupType popup_type,
[email protected]9f4f3322012-01-18 22:29:56106 int* route_id,
107 int* surface_id);
[email protected]c6d068ff2011-10-14 17:28:23108
109#if defined(OS_WIN)
110 void OnDuplicateSection(base::SharedMemoryHandle renderer_handle,
111 base::SharedMemoryHandle* browser_handle);
112#endif
113
114 IPC::TestSink sink_;
115
116 // Routing id what will be assigned to the Widget.
117 int32 routing_id_;
118
[email protected]9f4f3322012-01-18 22:29:56119 // Surface id what will be assigned to the Widget.
120 int32 surface_id_;
121
[email protected]c6d068ff2011-10-14 17:28:23122 // Opener id reported by the Widget.
123 int32 opener_id_;
124
125 // We only keep track of one Widget, we learn its pointer when it
126 // adds a new route.
127 IPC::Channel::Listener* widget_;
128
129 // The last known good deserializer for sync messages.
130 scoped_ptr<IPC::MessageReplyDeserializer> reply_deserializer_;
131};
132
133} // namespace content
134
135#endif // CONTENT_TEST_MOCK_RENDER_THREAD_H_