blob: fffb20cbc7d04e0a063fed358c515b6157e4716e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ppapi/proxy/ppapi_proxy_test.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/proxy/ppapi_messages.h"
namespace pp {
namespace proxy {
namespace {
ProxyTestBase* current_test = NULL;
const void* MockGetInterface(const char* name) {
if (!current_test) {
NOTREACHED();
return NULL;
}
return current_test->GetInterface(name);
}
int32_t MockInitModule(PP_Module, Dispatcher::GetInterfaceFunc) {
return PP_OK;
}
void MockShutdownModuleFunc() {
}
} // namespace
// ProxyTestBase ---------------------------------------------------------------
ProxyTestBase::ProxyTestBase() : pp_module_(0x98765), pp_instance_(0x12345) {
DCHECK(!current_test);
current_test = this;
}
ProxyTestBase::~ProxyTestBase() {
DCHECK(current_test == this);
current_test = NULL;
}
const void* ProxyTestBase::GetInterface(const char* name) {
return registered_interfaces_[name];
}
void ProxyTestBase::RegisterTestInterface(const char* name,
const void* interface) {
registered_interfaces_[name] = interface;
}
bool ProxyTestBase::SupportsInterface(const char* name) {
sink().ClearMessages();
// IPC doesn't actually write to this when we send a message manually
// not actually using IPC.
bool unused_result = false;
PpapiMsg_SupportsInterface msg(name, &unused_result);
GetDispatcher()->OnMessageReceived(msg);
const IPC::Message* reply_msg =
sink().GetUniqueMessageMatching(IPC_REPLY_ID);
EXPECT_TRUE(reply_msg);
if (!reply_msg)
return false;
TupleTypes<PpapiMsg_SupportsInterface::ReplyParam>::ValueTuple reply_data;
EXPECT_TRUE(PpapiMsg_SupportsInterface::ReadReplyParam(
reply_msg, &reply_data));
sink().ClearMessages();
return reply_data.a;
}
// PluginProxyTest -------------------------------------------------------------
PluginProxyTest::PluginProxyTest() {
}
PluginProxyTest::~PluginProxyTest() {
}
Dispatcher* PluginProxyTest::GetDispatcher() {
return plugin_dispatcher_.get();
}
void PluginProxyTest::SetUp() {
// These must be first since the dispatcher set-up uses them.
PluginResourceTracker::SetInstanceForTest(&resource_tracker_);
PluginVarTracker::SetInstanceForTest(&var_tracker_);
plugin_dispatcher_.reset(new PluginDispatcher(
base::Process::Current().handle(),
&MockGetInterface));
plugin_dispatcher_->InitWithTestSink(&sink());
plugin_dispatcher_->DidCreateInstance(pp_instance());
}
void PluginProxyTest::TearDown() {
plugin_dispatcher_->DidDestroyInstance(pp_instance());
plugin_dispatcher_.reset();
PluginVarTracker::SetInstanceForTest(NULL);
PluginResourceTracker::SetInstanceForTest(NULL);
}
// HostProxyTest ---------------------------------------------------------------
HostProxyTest::HostProxyTest() {
}
HostProxyTest::~HostProxyTest() {
}
Dispatcher* HostProxyTest::GetDispatcher() {
return host_dispatcher_.get();
}
void HostProxyTest::SetUp() {
host_dispatcher_.reset(new HostDispatcher(
base::Process::Current().handle(),
pp_module(),
&MockGetInterface));
host_dispatcher_->InitWithTestSink(&sink());
HostDispatcher::SetForInstance(pp_instance(), host_dispatcher_.get());
}
void HostProxyTest::TearDown() {
HostDispatcher::RemoveForInstance(pp_instance());
host_dispatcher_.reset();
}
} // namespace proxy
} // namespace pp
|