Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: trunk/src/chrome/browser/extensions/api/bluetooth/bluetooth_event_router_unittest.cc

Issue 224763003: Revert 261566 "device/bluetooth: Rename device::bluetooth_utils:..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
20 #include "device/bluetooth/test/mock_bluetooth_adapter.h" 19 #include "device/bluetooth/test/mock_bluetooth_adapter.h"
21 #include "device/bluetooth/test/mock_bluetooth_device.h" 20 #include "device/bluetooth/test/mock_bluetooth_device.h"
22 #include "device/bluetooth/test/mock_bluetooth_profile.h" 21 #include "device/bluetooth/test/mock_bluetooth_profile.h"
23 #include "device/bluetooth/test/mock_bluetooth_socket.h" 22 #include "device/bluetooth/test/mock_bluetooth_socket.h"
24 #include "extensions/browser/event_router.h" 23 #include "extensions/browser/event_router.h"
25 #include "extensions/common/extension_builder.h" 24 #include "extensions/common/extension_builder.h"
26 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
28 27
29 namespace { 28 namespace {
30 29
31 const char kTestExtensionId[] = "test extension id"; 30 const char kTestExtensionId[] = "test extension id";
32 const device::BluetoothUUID kAudioProfileUuid("1234"); 31 const char kAudioProfileUuid[] = "audio profile uuid";
33 const device::BluetoothUUID kHealthProfileUuid("4321"); 32 const char kHealthProfileUuid[] = "health profile uuid";
34 33
35 class FakeEventRouter : public extensions::EventRouter { 34 class FakeEventRouter : public extensions::EventRouter {
36 public: 35 public:
37 explicit FakeEventRouter(Profile* profile) : EventRouter(profile, NULL) {} 36 explicit FakeEventRouter(Profile* profile) : EventRouter(profile, NULL) {}
38 37
39 virtual void DispatchEventToExtension( 38 virtual void DispatchEventToExtension(
40 const std::string& extension_id, 39 const std::string& extension_id,
41 scoped_ptr<extensions::Event> event) OVERRIDE { 40 scoped_ptr<extensions::Event> event) OVERRIDE {
42 extension_id_ = extension_id; 41 extension_id_ = extension_id;
43 event_ = event.Pass(); 42 event_ = event.Pass();
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 base::DictionaryValue* socket_value = NULL; 214 base::DictionaryValue* socket_value = NULL;
216 ASSERT_TRUE(event_args->GetDictionary(0, &socket_value)); 215 ASSERT_TRUE(event_args->GetDictionary(0, &socket_value));
217 int socket_id; 216 int socket_id;
218 ASSERT_TRUE(socket_value->GetInteger("id", &socket_id)); 217 ASSERT_TRUE(socket_value->GetInteger("id", &socket_id));
219 EXPECT_EQ(mock_socket.get(), router_.GetSocket(socket_id).get()); 218 EXPECT_EQ(mock_socket.get(), router_.GetSocket(socket_id).get());
220 219
221 base::DictionaryValue* profile_value = NULL; 220 base::DictionaryValue* profile_value = NULL;
222 ASSERT_TRUE(socket_value->GetDictionary("profile", &profile_value)); 221 ASSERT_TRUE(socket_value->GetDictionary("profile", &profile_value));
223 std::string uuid; 222 std::string uuid;
224 ASSERT_TRUE(profile_value->GetString("uuid", &uuid)); 223 ASSERT_TRUE(profile_value->GetString("uuid", &uuid));
225 EXPECT_STREQ(kAudioProfileUuid.canonical_value().c_str(), uuid.c_str()); 224 EXPECT_STREQ(kAudioProfileUuid, uuid.c_str());
226 225
227 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); 226 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1);
228 router_.ReleaseSocket(socket_id); 227 router_.ReleaseSocket(socket_id);
229 } 228 }
230 229
231 TEST_F(BluetoothEventRouterTest, DoNotDispatchConnectionEvent) { 230 TEST_F(BluetoothEventRouterTest, DoNotDispatchConnectionEvent) {
232 FakeExtensionSystem* fake_extension_system = 231 FakeExtensionSystem* fake_extension_system =
233 static_cast<FakeExtensionSystem*>(ExtensionSystemFactory::GetInstance()-> 232 static_cast<FakeExtensionSystem*>(ExtensionSystemFactory::GetInstance()->
234 SetTestingFactoryAndUse(test_profile_.get(), 233 SetTestingFactoryAndUse(test_profile_.get(),
235 &BuildFakeExtensionSystem)); 234 &BuildFakeExtensionSystem));
236 testing::NiceMock<device::MockBluetoothDevice> mock_device( 235 testing::NiceMock<device::MockBluetoothDevice> mock_device(
237 mock_adapter_, 0, "device name", "device address", true, false); 236 mock_adapter_, 0, "device name", "device address", true, false);
238 scoped_refptr<testing::NiceMock<device::MockBluetoothSocket> > mock_socket( 237 scoped_refptr<testing::NiceMock<device::MockBluetoothSocket> > mock_socket(
239 new testing::NiceMock<device::MockBluetoothSocket>()); 238 new testing::NiceMock<device::MockBluetoothSocket>());
240 239
241 // Connection event won't be dispatched for non-registered profiles. 240 // Connection event won't be dispatched for non-registered profiles.
242 router_.DispatchConnectionEvent("test extension id", 241 router_.DispatchConnectionEvent("test extension id",
243 kAudioProfileUuid, 242 kAudioProfileUuid,
244 &mock_device, 243 &mock_device,
245 mock_socket); 244 mock_socket);
246 FakeEventRouter* fake_event_router = 245 FakeEventRouter* fake_event_router =
247 static_cast<FakeEventRouter*>(fake_extension_system->event_router()); 246 static_cast<FakeEventRouter*>(fake_extension_system->event_router());
248 EXPECT_TRUE(fake_event_router->event() == NULL); 247 EXPECT_TRUE(fake_event_router->event() == NULL);
249 248
250 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); 249 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1);
251 } 250 }
252 251
253 } // namespace extensions 252 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698