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