OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/synchronization/waitable_event.h" | 5 #include "base/synchronization/waitable_event.h" |
6 #include "ipc/ipc_message_utils.h" | 6 #include "ipc/ipc_message_utils.h" |
7 #include "ppapi/c/dev/ppb_fullscreen_dev.h" | 7 #include "ppapi/c/dev/ppb_fullscreen_dev.h" |
8 #include "ppapi/c/pp_var.h" | 8 #include "ppapi/c/pp_var.h" |
9 #include "ppapi/c/ppb_core.h" | 9 #include "ppapi/c/ppb_core.h" |
10 #include "ppapi/c/ppb_url_loader.h" | 10 #include "ppapi/c/ppb_url_loader.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 received_instance = 0; | 88 received_instance = 0; |
89 received_argc = 0; | 89 received_argc = 0; |
90 received_argn.clear(); | 90 received_argn.clear(); |
91 received_argv.clear(); | 91 received_argv.clear(); |
92 memset(&received_position, 0, sizeof(received_position)); | 92 memset(&received_position, 0, sizeof(received_position)); |
93 memset(&received_clip, 0, sizeof(received_clip)); | 93 memset(&received_clip, 0, sizeof(received_clip)); |
94 received_has_focus = PP_FALSE; | 94 received_has_focus = PP_FALSE; |
95 memset(&received_event, 0, sizeof(received_event)); | 95 memset(&received_event, 0, sizeof(received_event)); |
96 } | 96 } |
97 | 97 |
98 PPP_Instance_0_4 ppp_instance_0_4 = { | |
99 &DidCreate, | |
100 &DidDestroy, | |
101 &DidChangeView, | |
102 &DidChangeFocus, | |
103 &HandleInputEvent, | |
104 &HandleDocumentLoad, | |
105 &GetInstanceObject | |
106 }; | |
107 | |
108 PPP_Instance_0_5 ppp_instance_0_5 = { | 98 PPP_Instance_0_5 ppp_instance_0_5 = { |
109 &DidCreate, | 99 &DidCreate, |
110 &DidDestroy, | 100 &DidDestroy, |
111 &DidChangeView, | 101 &DidChangeView, |
112 &DidChangeFocus, | 102 &DidChangeFocus, |
113 &HandleInputEvent, | 103 &HandleInputEvent, |
114 &HandleDocumentLoad | 104 &HandleDocumentLoad |
115 }; | 105 }; |
116 | 106 |
117 // PPP_Instance_Proxy::DidChangeView relies on PPB_FullscreenDev being | 107 // PPP_Instance_Proxy::DidChangeView relies on PPB_FullscreenDev being |
118 // available with a valid implementation of IsFullScreen, so we mock it. | 108 // available with a valid implementation of IsFullScreen, so we mock it. |
119 PP_Bool IsFullscreen(PP_Instance instance) { | 109 PP_Bool IsFullscreen(PP_Instance instance) { |
120 return PP_FALSE; | 110 return PP_FALSE; |
121 } | 111 } |
122 PPB_Fullscreen_Dev ppb_fullscreen_dev = { &IsFullscreen }; | 112 PPB_Fullscreen_Dev ppb_fullscreen_dev = { &IsFullscreen }; |
123 | 113 |
124 } // namespace | 114 } // namespace |
125 | 115 |
126 class PPP_Instance_ProxyTest : public TwoWayTest { | 116 class PPP_Instance_ProxyTest : public TwoWayTest { |
127 public: | 117 public: |
128 PPP_Instance_ProxyTest() | 118 PPP_Instance_ProxyTest() |
129 : TwoWayTest(TwoWayTest::TEST_PPP_INTERFACE) { | 119 : TwoWayTest(TwoWayTest::TEST_PPP_INTERFACE) { |
130 } | 120 } |
131 }; | 121 }; |
132 | 122 |
133 TEST_F(PPP_Instance_ProxyTest, PPPInstance0_4) { | |
134 plugin().RegisterTestInterface(PPP_INSTANCE_INTERFACE_0_4, &ppp_instance_0_4); | |
135 host().RegisterTestInterface(PPB_FULLSCREEN_DEV_INTERFACE, | |
136 &ppb_fullscreen_dev); | |
137 | |
138 // Try requesting the 0.5 version, like the browser does. This should come | |
139 // back NULL, since we're not registering 0.5. But this ensures that the | |
140 // behavior through the proxy code reflects more closely what happens for a | |
141 // real plug-in. | |
142 const void* interface = | |
143 host().host_dispatcher()->GetProxiedInterface(PPP_INSTANCE_INTERFACE_0_5); | |
144 EXPECT_EQ(NULL, interface); | |
145 | |
146 // Grab the host-side proxy for the 0.4 interface. | |
147 const PPP_Instance_0_4* ppp_instance = static_cast<const PPP_Instance_0_4*>( | |
148 host().host_dispatcher()->GetProxiedInterface( | |
149 PPP_INSTANCE_INTERFACE_0_4)); | |
150 | |
151 // Call each function in turn, make sure we get the expected values and | |
152 // returns. | |
153 // | |
154 // We don't test DidDestroy, because it has the side-effect of removing the | |
155 // PP_Instance from the PluginDispatcher, which will cause a failure later | |
156 // when the test is torn down. | |
157 PP_Instance expected_instance = pp_instance(); | |
158 std::vector<std::string> expected_argn, expected_argv; | |
159 expected_argn.push_back("Hello"); | |
160 expected_argn.push_back("world."); | |
161 expected_argv.push_back("elloHay"); | |
162 expected_argv.push_back("orldway."); | |
163 std::vector<const char*> argn_to_pass, argv_to_pass; | |
164 CHECK(expected_argn.size() == expected_argv.size()); | |
165 for (size_t i = 0; i < expected_argn.size(); ++i) { | |
166 argn_to_pass.push_back(expected_argn[i].c_str()); | |
167 argv_to_pass.push_back(expected_argv[i].c_str()); | |
168 } | |
169 uint32_t expected_argc = expected_argn.size(); | |
170 bool_to_return = PP_TRUE; | |
171 ResetReceived(); | |
172 EXPECT_EQ(bool_to_return, ppp_instance->DidCreate(expected_instance, | |
173 expected_argc, | |
174 &argn_to_pass[0], | |
175 &argv_to_pass[0])); | |
176 EXPECT_EQ(received_instance, expected_instance); | |
177 EXPECT_EQ(received_argc, expected_argc); | |
178 EXPECT_EQ(received_argn, expected_argn); | |
179 EXPECT_EQ(received_argv, expected_argv); | |
180 | |
181 PP_Rect expected_position = { {1, 2}, {3, 4} }; | |
182 PP_Rect expected_clip = { {5, 6}, {7, 8} }; | |
183 ResetReceived(); | |
184 ppp_instance->DidChangeView(expected_instance, &expected_position, | |
185 &expected_clip); | |
186 did_change_view_called.Wait(); | |
187 EXPECT_EQ(received_instance, expected_instance); | |
188 // If I define operator== for PP_Rect, it has to come before gtest's template | |
189 // definitions in the translation unit, or else it's not found. So instead of | |
190 // defining operator== before the #include that brings in gtest, I compare the | |
191 // individual parts. | |
192 EXPECT_EQ(received_position.point.x, expected_position.point.x); | |
193 EXPECT_EQ(received_position.point.y, expected_position.point.y); | |
194 EXPECT_EQ(received_position.size.width, expected_position.size.width); | |
195 EXPECT_EQ(received_position.size.height, expected_position.size.height); | |
196 EXPECT_EQ(received_clip.point.x, expected_clip.point.x); | |
197 EXPECT_EQ(received_clip.point.y, expected_clip.point.y); | |
198 EXPECT_EQ(received_clip.size.width, expected_clip.size.width); | |
199 EXPECT_EQ(received_clip.size.height, expected_clip.size.height); | |
200 | |
201 PP_Bool expected_has_focus = PP_TRUE; | |
202 ResetReceived(); | |
203 ppp_instance->DidChangeFocus(expected_instance, expected_has_focus); | |
204 did_change_focus_called.Wait(); | |
205 EXPECT_EQ(received_instance, expected_instance); | |
206 EXPECT_EQ(received_has_focus, expected_has_focus); | |
207 | |
208 PP_InputEvent expected_event = { PP_INPUTEVENT_TYPE_KEYDOWN, // type | |
209 0, // padding | |
210 1.0, // time_stamp | |
211 { { 2, 3 } } }; // u (as PP_InputEvent_Key) | |
212 ResetReceived(); | |
213 EXPECT_EQ(bool_to_return, | |
214 ppp_instance->HandleInputEvent(expected_instance, &expected_event)); | |
215 EXPECT_EQ(received_instance, expected_instance); | |
216 ASSERT_EQ(received_event.type, expected_event.type); | |
217 // Ignore padding; it's okay if it's not serialized. | |
218 EXPECT_EQ(received_event.time_stamp, expected_event.time_stamp); | |
219 EXPECT_EQ(received_event.u.key.modifier, expected_event.u.key.modifier); | |
220 EXPECT_EQ(received_event.u.key.key_code, expected_event.u.key.key_code); | |
221 | |
222 // TODO(dmichael): Need to mock out a resource Tracker to be able to test | |
223 // HandleResourceLoad. It also requires | |
224 // PPB_Core.AddRefResource and for PPB_URLLoader to be | |
225 // registered. | |
226 | |
227 var_to_return = PP_MakeInt32(100); | |
228 ResetReceived(); | |
229 PP_Var result(ppp_instance->GetInstanceObject(expected_instance)); | |
230 ASSERT_EQ(var_to_return.type, result.type); | |
231 EXPECT_EQ(var_to_return.value.as_int, result.value.as_int); | |
232 EXPECT_EQ(received_instance, expected_instance); | |
233 } | |
234 | |
235 TEST_F(PPP_Instance_ProxyTest, PPPInstance0_5) { | 123 TEST_F(PPP_Instance_ProxyTest, PPPInstance0_5) { |
236 plugin().RegisterTestInterface(PPP_INSTANCE_INTERFACE_0_5, &ppp_instance_0_5); | 124 plugin().RegisterTestInterface(PPP_INSTANCE_INTERFACE_0_5, &ppp_instance_0_5); |
237 host().RegisterTestInterface(PPB_FULLSCREEN_DEV_INTERFACE, | 125 host().RegisterTestInterface(PPB_FULLSCREEN_DEV_INTERFACE, |
238 &ppb_fullscreen_dev); | 126 &ppb_fullscreen_dev); |
239 | 127 |
240 // Grab the host-side proxy for the 0.5 interface. | 128 // Grab the host-side proxy for the 0.5 interface. |
241 const PPP_Instance_0_5* ppp_instance = static_cast<const PPP_Instance_0_5*>( | 129 const PPP_Instance_0_5* ppp_instance = static_cast<const PPP_Instance_0_5*>( |
242 host().host_dispatcher()->GetProxiedInterface( | 130 host().host_dispatcher()->GetProxiedInterface( |
243 PPP_INSTANCE_INTERFACE_0_5)); | 131 PPP_INSTANCE_INTERFACE_0_5)); |
244 | 132 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 | 199 |
312 // TODO(dmichael): Need to mock out a resource Tracker to be able to test | 200 // TODO(dmichael): Need to mock out a resource Tracker to be able to test |
313 // HandleResourceLoad. It also requires | 201 // HandleResourceLoad. It also requires |
314 // PPB_Core.AddRefResource and for PPB_URLLoader to be | 202 // PPB_Core.AddRefResource and for PPB_URLLoader to be |
315 // registered. | 203 // registered. |
316 } | 204 } |
317 | 205 |
318 } // namespace proxy | 206 } // namespace proxy |
319 } // namespace pp | 207 } // namespace pp |
320 | 208 |
OLD | NEW |