OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
7 #include "ppapi/c/pp_errors.h" | 7 #include "ppapi/c/pp_errors.h" |
8 #include "ppapi/proxy/connection.h" | 8 #include "ppapi/proxy/connection.h" |
9 #include "ppapi/proxy/device_enumeration_resource_helper.h" | 9 #include "ppapi/proxy/device_enumeration_resource_helper.h" |
| 10 #include "ppapi/proxy/plugin_message_filter.h" |
10 #include "ppapi/proxy/plugin_resource.h" | 11 #include "ppapi/proxy/plugin_resource.h" |
11 #include "ppapi/proxy/plugin_resource_tracker.h" | 12 #include "ppapi/proxy/plugin_resource_tracker.h" |
12 #include "ppapi/proxy/plugin_var_tracker.h" | 13 #include "ppapi/proxy/plugin_var_tracker.h" |
13 #include "ppapi/proxy/ppapi_message_utils.h" | 14 #include "ppapi/proxy/ppapi_message_utils.h" |
14 #include "ppapi/proxy/ppapi_messages.h" | 15 #include "ppapi/proxy/ppapi_messages.h" |
15 #include "ppapi/proxy/ppapi_proxy_test.h" | 16 #include "ppapi/proxy/ppapi_proxy_test.h" |
16 #include "ppapi/shared_impl/ppb_device_ref_shared.h" | 17 #include "ppapi/shared_impl/ppb_device_ref_shared.h" |
17 #include "ppapi/shared_impl/proxy_lock.h" | 18 #include "ppapi/shared_impl/proxy_lock.h" |
18 #include "ppapi/shared_impl/var.h" | 19 #include "ppapi/shared_impl/var.h" |
19 #include "ppapi/thunk/enter.h" | 20 #include "ppapi/thunk/enter.h" |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 data_item.name = "name_1"; | 252 data_item.name = "name_1"; |
252 data_item.id = "id_1"; | 253 data_item.id = "id_1"; |
253 data.push_back(data_item); | 254 data.push_back(data_item); |
254 data_item.type = PP_DEVICETYPE_DEV_VIDEOCAPTURE; | 255 data_item.type = PP_DEVICETYPE_DEV_VIDEOCAPTURE; |
255 data_item.name = "name_2"; | 256 data_item.name = "name_2"; |
256 data_item.id = "id_2"; | 257 data_item.id = "id_2"; |
257 data.push_back(data_item); | 258 data.push_back(data_item); |
258 | 259 |
259 { | 260 { |
260 ProxyAutoUnlock unlock; | 261 ProxyAutoUnlock unlock; |
261 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived( | 262 PluginMessageFilter::DispatchResourceReplyForTest( |
262 PpapiPluginMsg_ResourceReply( | 263 reply_params, |
263 reply_params, | 264 PpapiPluginMsg_DeviceEnumeration_EnumerateDevicesReply(data)); |
264 PpapiPluginMsg_DeviceEnumeration_EnumerateDevicesReply(data)))); | |
265 } | 265 } |
266 EXPECT_TRUE(callback.called()); | 266 EXPECT_TRUE(callback.called()); |
267 EXPECT_EQ(PP_OK, callback.result()); | 267 EXPECT_EQ(PP_OK, callback.result()); |
268 EXPECT_EQ(2U, output.count()); | 268 EXPECT_EQ(2U, output.count()); |
269 for (size_t i = 0; i < output.count(); ++i) | 269 for (size_t i = 0; i < output.count(); ++i) |
270 EXPECT_TRUE(CompareDeviceRef(&var_tracker(), output.data()[i], data[i])); | 270 EXPECT_TRUE(CompareDeviceRef(&var_tracker(), output.data()[i], data[i])); |
271 } | 271 } |
272 | 272 |
273 TEST_F(DeviceEnumerationResourceHelperTest, MonitorDeviceChange) { | 273 TEST_F(DeviceEnumerationResourceHelperTest, MonitorDeviceChange) { |
274 ProxyAutoLock lock; | 274 ProxyAutoLock lock; |
(...skipping 22 matching lines...) Expand all Loading... |
297 | 297 |
298 ResourceMessageReplyParams reply_params(params.pp_resource(), 0); | 298 ResourceMessageReplyParams reply_params(params.pp_resource(), 0); |
299 reply_params.set_result(PP_OK); | 299 reply_params.set_result(PP_OK); |
300 std::vector<DeviceRefData> data; | 300 std::vector<DeviceRefData> data; |
301 | 301 |
302 helper.SetExpectedResult(data); | 302 helper.SetExpectedResult(data); |
303 | 303 |
304 { | 304 { |
305 ProxyAutoUnlock unlock; | 305 ProxyAutoUnlock unlock; |
306 // Synthesize a response with no device. | 306 // Synthesize a response with no device. |
307 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived( | 307 PluginMessageFilter::DispatchResourceReplyForTest( |
308 PpapiPluginMsg_ResourceReply( | 308 reply_params, |
309 reply_params, | 309 PpapiPluginMsg_DeviceEnumeration_NotifyDeviceChange( |
310 PpapiPluginMsg_DeviceEnumeration_NotifyDeviceChange( | 310 callback_id, data)); |
311 callback_id, data)))); | |
312 } | 311 } |
313 EXPECT_TRUE(helper.called() && helper.same_as_expected()); | 312 EXPECT_TRUE(helper.called() && helper.same_as_expected()); |
314 | 313 |
315 DeviceRefData data_item; | 314 DeviceRefData data_item; |
316 data_item.type = PP_DEVICETYPE_DEV_AUDIOCAPTURE; | 315 data_item.type = PP_DEVICETYPE_DEV_AUDIOCAPTURE; |
317 data_item.name = "name_1"; | 316 data_item.name = "name_1"; |
318 data_item.id = "id_1"; | 317 data_item.id = "id_1"; |
319 data.push_back(data_item); | 318 data.push_back(data_item); |
320 data_item.type = PP_DEVICETYPE_DEV_VIDEOCAPTURE; | 319 data_item.type = PP_DEVICETYPE_DEV_VIDEOCAPTURE; |
321 data_item.name = "name_2"; | 320 data_item.name = "name_2"; |
322 data_item.id = "id_2"; | 321 data_item.id = "id_2"; |
323 data.push_back(data_item); | 322 data.push_back(data_item); |
324 | 323 |
325 helper.SetExpectedResult(data); | 324 helper.SetExpectedResult(data); |
326 | 325 |
327 { | 326 { |
328 ProxyAutoUnlock unlock; | 327 ProxyAutoUnlock unlock; |
329 // Synthesize a response with some devices. | 328 // Synthesize a response with some devices. |
330 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived( | 329 PluginMessageFilter::DispatchResourceReplyForTest( |
331 PpapiPluginMsg_ResourceReply( | 330 reply_params, |
332 reply_params, | 331 PpapiPluginMsg_DeviceEnumeration_NotifyDeviceChange( |
333 PpapiPluginMsg_DeviceEnumeration_NotifyDeviceChange( | 332 callback_id, data)); |
334 callback_id, data)))); | |
335 } | 333 } |
336 EXPECT_TRUE(helper.called() && helper.same_as_expected()); | 334 EXPECT_TRUE(helper.called() && helper.same_as_expected()); |
337 | 335 |
338 TestMonitorDeviceChange helper2(&var_tracker()); | 336 TestMonitorDeviceChange helper2(&var_tracker()); |
339 | 337 |
340 result = device_enumeration.MonitorDeviceChange( | 338 result = device_enumeration.MonitorDeviceChange( |
341 &TestMonitorDeviceChange::MonitorDeviceChangeCallback, &helper2); | 339 &TestMonitorDeviceChange::MonitorDeviceChangeCallback, &helper2); |
342 ASSERT_EQ(PP_OK, result); | 340 ASSERT_EQ(PP_OK, result); |
343 | 341 |
344 // Should have sent another MonitorDeviceChange message. | 342 // Should have sent another MonitorDeviceChange message. |
345 ResourceMessageCallParams params2; | 343 ResourceMessageCallParams params2; |
346 IPC::Message msg2; | 344 IPC::Message msg2; |
347 ASSERT_TRUE(sink().GetFirstResourceCallMatching( | 345 ASSERT_TRUE(sink().GetFirstResourceCallMatching( |
348 PpapiHostMsg_DeviceEnumeration_MonitorDeviceChange::ID, ¶ms2, &msg2)); | 346 PpapiHostMsg_DeviceEnumeration_MonitorDeviceChange::ID, ¶ms2, &msg2)); |
349 sink().ClearMessages(); | 347 sink().ClearMessages(); |
350 | 348 |
351 uint32_t callback_id2 = 0; | 349 uint32_t callback_id2 = 0; |
352 ASSERT_TRUE(UnpackMessage<PpapiHostMsg_DeviceEnumeration_MonitorDeviceChange>( | 350 ASSERT_TRUE(UnpackMessage<PpapiHostMsg_DeviceEnumeration_MonitorDeviceChange>( |
353 msg2, &callback_id2)); | 351 msg2, &callback_id2)); |
354 | 352 |
355 helper.SetExpectedResult(data); | 353 helper.SetExpectedResult(data); |
356 helper2.SetExpectedResult(data); | 354 helper2.SetExpectedResult(data); |
357 { | 355 { |
358 ProxyAutoUnlock unlock; | 356 ProxyAutoUnlock unlock; |
359 // |helper2| should receive the result while |helper| shouldn't. | 357 // |helper2| should receive the result while |helper| shouldn't. |
360 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived( | 358 PluginMessageFilter::DispatchResourceReplyForTest( |
361 PpapiPluginMsg_ResourceReply( | 359 reply_params, |
362 reply_params, | 360 PpapiPluginMsg_DeviceEnumeration_NotifyDeviceChange( |
363 PpapiPluginMsg_DeviceEnumeration_NotifyDeviceChange( | 361 callback_id2, data)); |
364 callback_id2, data)))); | |
365 } | 362 } |
366 EXPECT_TRUE(helper2.called() && helper2.same_as_expected()); | 363 EXPECT_TRUE(helper2.called() && helper2.same_as_expected()); |
367 EXPECT_FALSE(helper.called()); | 364 EXPECT_FALSE(helper.called()); |
368 | 365 |
369 helper.SetExpectedResult(data); | 366 helper.SetExpectedResult(data); |
370 helper2.SetExpectedResult(data); | 367 helper2.SetExpectedResult(data); |
371 { | 368 { |
372 ProxyAutoUnlock unlock; | 369 ProxyAutoUnlock unlock; |
373 // Even if a message with |callback_id| arrives. |helper| shouldn't receive | 370 // Even if a message with |callback_id| arrives. |helper| shouldn't receive |
374 // the result. | 371 // the result. |
375 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived( | 372 PluginMessageFilter::DispatchResourceReplyForTest( |
376 PpapiPluginMsg_ResourceReply( | 373 reply_params, |
377 reply_params, | 374 PpapiPluginMsg_DeviceEnumeration_NotifyDeviceChange( |
378 PpapiPluginMsg_DeviceEnumeration_NotifyDeviceChange( | 375 callback_id, data)); |
379 callback_id, data)))); | |
380 } | 376 } |
381 EXPECT_FALSE(helper2.called()); | 377 EXPECT_FALSE(helper2.called()); |
382 EXPECT_FALSE(helper.called()); | 378 EXPECT_FALSE(helper.called()); |
383 | 379 |
384 result = device_enumeration.MonitorDeviceChange(NULL, NULL); | 380 result = device_enumeration.MonitorDeviceChange(NULL, NULL); |
385 ASSERT_EQ(PP_OK, result); | 381 ASSERT_EQ(PP_OK, result); |
386 | 382 |
387 // Should have sent a StopMonitoringDeviceChange message. | 383 // Should have sent a StopMonitoringDeviceChange message. |
388 ResourceMessageCallParams params3; | 384 ResourceMessageCallParams params3; |
389 IPC::Message msg3; | 385 IPC::Message msg3; |
390 ASSERT_TRUE(sink().GetFirstResourceCallMatching( | 386 ASSERT_TRUE(sink().GetFirstResourceCallMatching( |
391 PpapiHostMsg_DeviceEnumeration_StopMonitoringDeviceChange::ID, | 387 PpapiHostMsg_DeviceEnumeration_StopMonitoringDeviceChange::ID, |
392 ¶ms3, &msg3)); | 388 ¶ms3, &msg3)); |
393 sink().ClearMessages(); | 389 sink().ClearMessages(); |
394 | 390 |
395 helper2.SetExpectedResult(data); | 391 helper2.SetExpectedResult(data); |
396 { | 392 { |
397 ProxyAutoUnlock unlock; | 393 ProxyAutoUnlock unlock; |
398 // |helper2| shouldn't receive any result any more. | 394 // |helper2| shouldn't receive any result any more. |
399 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived( | 395 PluginMessageFilter::DispatchResourceReplyForTest( |
400 PpapiPluginMsg_ResourceReply( | 396 reply_params, |
401 reply_params, | 397 PpapiPluginMsg_DeviceEnumeration_NotifyDeviceChange( |
402 PpapiPluginMsg_DeviceEnumeration_NotifyDeviceChange( | 398 callback_id2, data)); |
403 callback_id2, data)))); | |
404 } | 399 } |
405 EXPECT_FALSE(helper2.called()); | 400 EXPECT_FALSE(helper2.called()); |
406 } | 401 } |
407 | 402 |
408 } // namespace proxy | 403 } // namespace proxy |
409 } // namespace ppapi | 404 } // namespace ppapi |
OLD | NEW |