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

Side by Side Diff: device/bluetooth/bluetooth_adapter_devices_chromeos_unittest.cc

Issue 15020009: Bluetooth: remove legacy backend (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chromeos/dbus/mock_bluetooth_adapter_client.h"
6 #include "chromeos/dbus/mock_bluetooth_device_client.h"
7 #include "chromeos/dbus/mock_bluetooth_manager_client.h"
8 #include "chromeos/dbus/mock_dbus_thread_manager.h"
9 #include "dbus/object_path.h"
10 #include "device/bluetooth/bluetooth_adapter.h"
11 #include "device/bluetooth/bluetooth_adapter_chromeos.h"
12 #include "device/bluetooth/bluetooth_adapter_factory.h"
13 #include "device/bluetooth/test/mock_bluetooth_adapter.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 using device::BluetoothAdapter;
17 using device::BluetoothAdapterFactory;
18 using device::BluetoothDevice;
19 using device::MockBluetoothAdapter;
20 using ::testing::_;
21 using ::testing::Mock;
22 using ::testing::Return;
23 using ::testing::SaveArg;
24
25 namespace chromeos {
26
27 class BluetoothAdapterDevicesChromeOSTest : public testing::Test {
28 public:
29 virtual void SetUp() {
30 MockDBusThreadManager* mock_dbus_thread_manager = new MockDBusThreadManager;
31
32 EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus())
33 .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL)));
34 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager);
35
36 mock_manager_client_ =
37 mock_dbus_thread_manager->mock_bluetooth_manager_client();
38 mock_adapter_client_ =
39 mock_dbus_thread_manager->mock_bluetooth_adapter_client();
40 mock_device_client_ =
41 mock_dbus_thread_manager->mock_bluetooth_device_client();
42
43 // Create the default adapter instance;
44 // BluetoothManagerClient::DefaultAdapter will be called once, passing
45 // a callback to obtain the adapter path.
46 BluetoothManagerClient::AdapterCallback adapter_callback;
47 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
48 .WillOnce(SaveArg<0>(&adapter_callback));
49
50 EXPECT_CALL(*mock_manager_client_, AddObserver(_))
51 .Times(1);
52 EXPECT_CALL(*mock_adapter_client_, AddObserver(_))
53 .Times(1);
54
55 BluetoothAdapterFactory::GetAdapter(
56 base::Bind(&BluetoothAdapterDevicesChromeOSTest::SetAdapter,
57 base::Unretained(this)));
58 ASSERT_TRUE(adapter_ != NULL);
59
60 // Call the adapter callback;
61 // BluetoothAdapterClient::GetProperties will be called once to obtain
62 // the property set.
63 MockBluetoothAdapterClient::Properties adapter_properties;
64 adapter_properties.address.ReplaceValue(adapter_address_);
65 adapter_properties.powered.ReplaceValue(true);
66
67 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path_))
68 .WillRepeatedly(Return(&adapter_properties));
69
70 // Add an observer to the adapter; expect the usual set of changes to
71 // an adapter becoming present and then clear to clean up for the test.
72 adapter_->AddObserver(&adapter_observer_);
73
74 EXPECT_CALL(adapter_observer_, AdapterPresentChanged(adapter_.get(), true))
75 .Times(1);
76 EXPECT_CALL(adapter_observer_, AdapterPoweredChanged(adapter_.get(), true))
77 .Times(1);
78
79 adapter_callback.Run(adapter_path_, true);
80
81 Mock::VerifyAndClearExpectations(mock_manager_client_);
82 Mock::VerifyAndClearExpectations(mock_adapter_client_);
83 Mock::VerifyAndClearExpectations(mock_device_client_);
84 Mock::VerifyAndClearExpectations(&adapter_observer_);
85 }
86
87 virtual void TearDown() {
88 BluetoothAdapterChromeOS* adapter_chromeos =
89 static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
90 EXPECT_CALL(*mock_device_client_, RemoveObserver(adapter_chromeos))
91 .Times(1);
92 EXPECT_CALL(*mock_adapter_client_, RemoveObserver(adapter_chromeos))
93 .Times(1);
94 EXPECT_CALL(*mock_manager_client_, RemoveObserver(adapter_chromeos))
95 .Times(1);
96
97 adapter_ = NULL;
98 DBusThreadManager::Shutdown();
99 }
100
101 void SetAdapter(scoped_refptr<device::BluetoothAdapter> adapter) {
102 adapter_ = adapter;
103 }
104
105 protected:
106 MockBluetoothManagerClient* mock_manager_client_;
107 MockBluetoothAdapterClient* mock_adapter_client_;
108 MockBluetoothDeviceClient* mock_device_client_;
109
110 static const dbus::ObjectPath adapter_path_;
111 static const std::string adapter_address_;
112 scoped_refptr<BluetoothAdapter> adapter_;
113
114 MockBluetoothAdapter::Observer adapter_observer_;
115 };
116
117 const dbus::ObjectPath BluetoothAdapterDevicesChromeOSTest::adapter_path_(
118 "/fake/hci0");
119 const std::string BluetoothAdapterDevicesChromeOSTest::adapter_address_ =
120 "CA:FE:4A:C0:FE:FE";
121
122 TEST_F(BluetoothAdapterDevicesChromeOSTest, DeviceRemovedAfterFound) {
123 const dbus::ObjectPath device_path("/fake/hci0/dev_ba_c0_11_00_00_01");
124 const std::string device_address = "BA:C0:11:00:00:01";
125
126 MockBluetoothDeviceClient::Properties device_properties;
127 device_properties.address.ReplaceValue(device_address);
128 device_properties.name.ReplaceValue("Fake Keyboard");
129 device_properties.bluetooth_class.ReplaceValue(0x2540);
130
131 // Inform the adapter that the device has been found;
132 // BluetoothAdapterClient::Observer::DeviceAdded will be called, passing
133 // the device object.
134 BluetoothDevice* device;
135 EXPECT_CALL(adapter_observer_, DeviceAdded(adapter_.get(), _))
136 .Times(1)
137 .WillOnce(SaveArg<1>(&device));
138
139 BluetoothAdapterChromeOS* adapter_chromeos =
140 static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
141 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
142 ->DeviceFound(adapter_path_, device_address, device_properties);
143
144 // Now inform the adapter that the device has been added and assigned an
145 // object path; BluetoothDeviceClient::GetProperties will be called to
146 // obtain the property set; and
147 // BluetoothAdapterClient::Observer::DeviceChanged will be called passing
148 // the same device object as before.
149 EXPECT_CALL(*mock_device_client_, GetProperties(device_path))
150 .WillRepeatedly(Return(&device_properties));
151
152 EXPECT_CALL(adapter_observer_, DeviceChanged(adapter_chromeos, device))
153 .Times(1);
154
155 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
156 ->DeviceCreated(adapter_path_, device_path);
157
158 // Finally remove the device again;
159 // BluetoothAdapterClient::Observer::DeviceRemoved should be not called,
160 // instead BluetoothAdapterClient::Observer::DeviceChanged will be called.
161 EXPECT_CALL(adapter_observer_, DeviceRemoved(adapter_.get(), device))
162 .Times(0);
163 EXPECT_CALL(adapter_observer_, DeviceChanged(adapter_.get(), device))
164 .Times(1);
165
166 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
167 ->DeviceRemoved(adapter_path_, device_path);
168
169 // Verify that the device is still visible, just no longer paired.
170 EXPECT_FALSE(device->IsPaired());
171 }
172
173 } // namespace chromeos
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter_chromeos_unittest.cc ('k') | device/bluetooth/bluetooth_device_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698