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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
12 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" | 12 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" |
13 #include "chrome/browser/extensions/extension_system_factory.h" | 13 #include "chrome/browser/extensions/extension_system_factory.h" |
14 #include "chrome/browser/extensions/test_extension_system.h" | 14 #include "chrome/browser/extensions/test_extension_system.h" |
15 #include "chrome/common/extensions/api/bluetooth.h" | 15 #include "chrome/common/extensions/api/bluetooth.h" |
16 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
17 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
18 #include "content/public/test/test_browser_thread.h" | 18 #include "content/public/test/test_browser_thread.h" |
| 19 #include "device/bluetooth/bluetooth_uuid.h" |
19 #include "device/bluetooth/test/mock_bluetooth_adapter.h" | 20 #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
20 #include "device/bluetooth/test/mock_bluetooth_device.h" | 21 #include "device/bluetooth/test/mock_bluetooth_device.h" |
21 #include "device/bluetooth/test/mock_bluetooth_profile.h" | 22 #include "device/bluetooth/test/mock_bluetooth_profile.h" |
22 #include "device/bluetooth/test/mock_bluetooth_socket.h" | 23 #include "device/bluetooth/test/mock_bluetooth_socket.h" |
23 #include "extensions/browser/event_router.h" | 24 #include "extensions/browser/event_router.h" |
24 #include "extensions/common/extension_builder.h" | 25 #include "extensions/common/extension_builder.h" |
25 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 const char kTestExtensionId[] = "test extension id"; | 31 const char kTestExtensionId[] = "test extension id"; |
31 const char kAudioProfileUuid[] = "audio profile uuid"; | 32 const device::BluetoothUUID kAudioProfileUuid("1234"); |
32 const char kHealthProfileUuid[] = "health profile uuid"; | 33 const device::BluetoothUUID kHealthProfileUuid("4321"); |
33 | 34 |
34 class FakeEventRouter : public extensions::EventRouter { | 35 class FakeEventRouter : public extensions::EventRouter { |
35 public: | 36 public: |
36 explicit FakeEventRouter(Profile* profile) : EventRouter(profile, NULL) {} | 37 explicit FakeEventRouter(Profile* profile) : EventRouter(profile, NULL) {} |
37 | 38 |
38 virtual void DispatchEventToExtension( | 39 virtual void DispatchEventToExtension( |
39 const std::string& extension_id, | 40 const std::string& extension_id, |
40 scoped_ptr<extensions::Event> event) OVERRIDE { | 41 scoped_ptr<extensions::Event> event) OVERRIDE { |
41 extension_id_ = extension_id; | 42 extension_id_ = extension_id; |
42 event_ = event.Pass(); | 43 event_ = event.Pass(); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 base::DictionaryValue* socket_value = NULL; | 215 base::DictionaryValue* socket_value = NULL; |
215 ASSERT_TRUE(event_args->GetDictionary(0, &socket_value)); | 216 ASSERT_TRUE(event_args->GetDictionary(0, &socket_value)); |
216 int socket_id; | 217 int socket_id; |
217 ASSERT_TRUE(socket_value->GetInteger("id", &socket_id)); | 218 ASSERT_TRUE(socket_value->GetInteger("id", &socket_id)); |
218 EXPECT_EQ(mock_socket.get(), router_.GetSocket(socket_id).get()); | 219 EXPECT_EQ(mock_socket.get(), router_.GetSocket(socket_id).get()); |
219 | 220 |
220 base::DictionaryValue* profile_value = NULL; | 221 base::DictionaryValue* profile_value = NULL; |
221 ASSERT_TRUE(socket_value->GetDictionary("profile", &profile_value)); | 222 ASSERT_TRUE(socket_value->GetDictionary("profile", &profile_value)); |
222 std::string uuid; | 223 std::string uuid; |
223 ASSERT_TRUE(profile_value->GetString("uuid", &uuid)); | 224 ASSERT_TRUE(profile_value->GetString("uuid", &uuid)); |
224 EXPECT_STREQ(kAudioProfileUuid, uuid.c_str()); | 225 EXPECT_STREQ(kAudioProfileUuid.canonical_value().c_str(), uuid.c_str()); |
225 | 226 |
226 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); | 227 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); |
227 router_.ReleaseSocket(socket_id); | 228 router_.ReleaseSocket(socket_id); |
228 } | 229 } |
229 | 230 |
230 TEST_F(BluetoothEventRouterTest, DoNotDispatchConnectionEvent) { | 231 TEST_F(BluetoothEventRouterTest, DoNotDispatchConnectionEvent) { |
231 FakeExtensionSystem* fake_extension_system = | 232 FakeExtensionSystem* fake_extension_system = |
232 static_cast<FakeExtensionSystem*>(ExtensionSystemFactory::GetInstance()-> | 233 static_cast<FakeExtensionSystem*>(ExtensionSystemFactory::GetInstance()-> |
233 SetTestingFactoryAndUse(test_profile_.get(), | 234 SetTestingFactoryAndUse(test_profile_.get(), |
234 &BuildFakeExtensionSystem)); | 235 &BuildFakeExtensionSystem)); |
235 testing::NiceMock<device::MockBluetoothDevice> mock_device( | 236 testing::NiceMock<device::MockBluetoothDevice> mock_device( |
236 mock_adapter_, 0, "device name", "device address", true, false); | 237 mock_adapter_, 0, "device name", "device address", true, false); |
237 scoped_refptr<testing::NiceMock<device::MockBluetoothSocket> > mock_socket( | 238 scoped_refptr<testing::NiceMock<device::MockBluetoothSocket> > mock_socket( |
238 new testing::NiceMock<device::MockBluetoothSocket>()); | 239 new testing::NiceMock<device::MockBluetoothSocket>()); |
239 | 240 |
240 // Connection event won't be dispatched for non-registered profiles. | 241 // Connection event won't be dispatched for non-registered profiles. |
241 router_.DispatchConnectionEvent("test extension id", | 242 router_.DispatchConnectionEvent("test extension id", |
242 kAudioProfileUuid, | 243 kAudioProfileUuid, |
243 &mock_device, | 244 &mock_device, |
244 mock_socket); | 245 mock_socket); |
245 FakeEventRouter* fake_event_router = | 246 FakeEventRouter* fake_event_router = |
246 static_cast<FakeEventRouter*>(fake_extension_system->event_router()); | 247 static_cast<FakeEventRouter*>(fake_extension_system->event_router()); |
247 EXPECT_TRUE(fake_event_router->event() == NULL); | 248 EXPECT_TRUE(fake_event_router->event() == NULL); |
248 | 249 |
249 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); | 250 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); |
250 } | 251 } |
251 | 252 |
252 } // namespace extensions | 253 } // namespace extensions |
OLD | NEW |