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 <map> | 5 #include <map> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "content/renderer/pepper/pepper_device_enumeration_host_helper.h" | 10 #include "content/renderer/pepper/pepper_device_enumeration_host_helper.h" |
11 #include "ppapi/c/pp_errors.h" | 11 #include "ppapi/c/pp_errors.h" |
12 #include "ppapi/host/host_message_context.h" | 12 #include "ppapi/host/host_message_context.h" |
13 #include "ppapi/host/ppapi_host.h" | 13 #include "ppapi/host/ppapi_host.h" |
14 #include "ppapi/host/resource_host.h" | 14 #include "ppapi/host/resource_host.h" |
15 #include "ppapi/proxy/ppapi_message_utils.h" | 15 #include "ppapi/proxy/ppapi_message_utils.h" |
16 #include "ppapi/proxy/ppapi_messages.h" | 16 #include "ppapi/proxy/ppapi_messages.h" |
17 #include "ppapi/proxy/resource_message_params.h" | 17 #include "ppapi/proxy/resource_message_params.h" |
18 #include "ppapi/proxy/resource_message_test_sink.h" | 18 #include "ppapi/proxy/resource_message_test_sink.h" |
19 #include "ppapi/shared_impl/ppapi_permissions.h" | 19 #include "ppapi/shared_impl/ppapi_permissions.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "url/gurl.h" |
21 | 22 |
22 namespace content { | 23 namespace content { |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 class TestDelegate : public PepperDeviceEnumerationHostHelper::Delegate { | 27 class TestDelegate : public PepperDeviceEnumerationHostHelper::Delegate { |
27 public: | 28 public: |
28 TestDelegate() : last_used_id_(0) { | 29 TestDelegate() : last_used_id_(0) { |
29 } | 30 } |
30 | 31 |
31 virtual ~TestDelegate() { | 32 virtual ~TestDelegate() { |
32 CHECK(callbacks_.empty()); | 33 CHECK(callbacks_.empty()); |
33 } | 34 } |
34 | 35 |
35 virtual int EnumerateDevices( | 36 virtual int EnumerateDevices( |
36 PP_DeviceType_Dev /* type */, | 37 PP_DeviceType_Dev /* type */, |
| 38 const GURL& /* document_url */, |
37 const EnumerateDevicesCallback& callback) OVERRIDE { | 39 const EnumerateDevicesCallback& callback) OVERRIDE { |
38 last_used_id_++; | 40 last_used_id_++; |
39 callbacks_[last_used_id_] = callback; | 41 callbacks_[last_used_id_] = callback; |
40 return last_used_id_; | 42 return last_used_id_; |
41 } | 43 } |
42 | 44 |
43 virtual void StopEnumerateDevices(int request_id) OVERRIDE { | 45 virtual void StopEnumerateDevices(int request_id) OVERRIDE { |
44 std::map<int, EnumerateDevicesCallback>::iterator iter = | 46 std::map<int, EnumerateDevicesCallback>::iterator iter = |
45 callbacks_.find(request_id); | 47 callbacks_.find(request_id); |
46 CHECK(iter != callbacks_.end()); | 48 CHECK(iter != callbacks_.end()); |
(...skipping 24 matching lines...) Expand all Loading... |
71 | 73 |
72 DISALLOW_COPY_AND_ASSIGN(TestDelegate); | 74 DISALLOW_COPY_AND_ASSIGN(TestDelegate); |
73 }; | 75 }; |
74 | 76 |
75 class PepperDeviceEnumerationHostHelperTest : public testing::Test { | 77 class PepperDeviceEnumerationHostHelperTest : public testing::Test { |
76 protected: | 78 protected: |
77 PepperDeviceEnumerationHostHelperTest() | 79 PepperDeviceEnumerationHostHelperTest() |
78 : ppapi_host_(&sink_, ppapi::PpapiPermissions()), | 80 : ppapi_host_(&sink_, ppapi::PpapiPermissions()), |
79 resource_host_(&ppapi_host_, 12345, 67890), | 81 resource_host_(&ppapi_host_, 12345, 67890), |
80 device_enumeration_(&resource_host_, &delegate_, | 82 device_enumeration_(&resource_host_, &delegate_, |
81 PP_DEVICETYPE_DEV_AUDIOCAPTURE) { | 83 PP_DEVICETYPE_DEV_AUDIOCAPTURE, |
| 84 GURL("http://example.com")) { |
82 } | 85 } |
83 | 86 |
84 virtual ~PepperDeviceEnumerationHostHelperTest() {} | 87 virtual ~PepperDeviceEnumerationHostHelperTest() {} |
85 | 88 |
86 void SimulateMonitorDeviceChangeReceived(uint32_t callback_id) { | 89 void SimulateMonitorDeviceChangeReceived(uint32_t callback_id) { |
87 PpapiHostMsg_DeviceEnumeration_MonitorDeviceChange msg(callback_id); | 90 PpapiHostMsg_DeviceEnumeration_MonitorDeviceChange msg(callback_id); |
88 ppapi::proxy::ResourceMessageCallParams call_params( | 91 ppapi::proxy::ResourceMessageCallParams call_params( |
89 resource_host_.pp_resource(), 123); | 92 resource_host_.pp_resource(), 123); |
90 ppapi::host::HostMessageContext context(call_params); | 93 ppapi::host::HostMessageContext context(call_params); |
91 int32_t result = PP_ERROR_FAILED; | 94 int32_t result = PP_ERROR_FAILED; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 ppapi::host::HostMessageContext context(call_params); | 227 ppapi::host::HostMessageContext context(call_params); |
225 int32_t result = PP_ERROR_FAILED; | 228 int32_t result = PP_ERROR_FAILED; |
226 ASSERT_TRUE(device_enumeration_.HandleResourceMessage( | 229 ASSERT_TRUE(device_enumeration_.HandleResourceMessage( |
227 msg, &context, &result)); | 230 msg, &context, &result)); |
228 EXPECT_EQ(PP_OK, result); | 231 EXPECT_EQ(PP_OK, result); |
229 | 232 |
230 EXPECT_EQ(0U, delegate_.GetRegisteredCallbackCount()); | 233 EXPECT_EQ(0U, delegate_.GetRegisteredCallbackCount()); |
231 } | 234 } |
232 | 235 |
233 } // namespace content | 236 } // namespace content |
OLD | NEW |