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

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

Issue 1415573014: Reland "Add Linux support for the Bluetooth API" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: build fix. Created 5 years, 1 month 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "device/bluetooth/bluetooth_adapter.h" 7 #include "device/bluetooth/bluetooth_adapter.h"
8 #include "device/bluetooth/bluetooth_adapter_chromeos.h" 8 #include "device/bluetooth/bluetooth_adapter_bluez.h"
9 #include "device/bluetooth/bluetooth_adapter_factory.h" 9 #include "device/bluetooth/bluetooth_adapter_factory.h"
10 #include "device/bluetooth/bluetooth_adapter_profile_chromeos.h" 10 #include "device/bluetooth/bluetooth_adapter_profile_bluez.h"
11 #include "device/bluetooth/bluetooth_uuid.h" 11 #include "device/bluetooth/bluetooth_uuid.h"
12 #include "device/bluetooth/dbus/bluetooth_profile_service_provider.h" 12 #include "device/bluetooth/dbus/bluetooth_profile_service_provider.h"
13 #include "device/bluetooth/dbus/bluez_dbus_manager.h" 13 #include "device/bluetooth/dbus/bluez_dbus_manager.h"
14 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h" 14 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h"
15 #include "device/bluetooth/dbus/fake_bluetooth_agent_manager_client.h" 15 #include "device/bluetooth/dbus/fake_bluetooth_agent_manager_client.h"
16 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" 16 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h"
17 #include "device/bluetooth/dbus/fake_bluetooth_profile_manager_client.h" 17 #include "device/bluetooth/dbus/fake_bluetooth_profile_manager_client.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 using device::BluetoothAdapter; 20 using device::BluetoothAdapter;
21 using device::BluetoothUUID; 21 using device::BluetoothUUID;
22 22
23 namespace chromeos { 23 namespace bluez {
24 24
25 class BluetoothAdapterProfileChromeOSTest : public testing::Test { 25 class BluetoothAdapterProfileBlueZTest : public testing::Test {
26 public: 26 public:
27 BluetoothAdapterProfileChromeOSTest() 27 BluetoothAdapterProfileBlueZTest()
28 : success_callback_count_(0), 28 : success_callback_count_(0),
29 error_callback_count_(0), 29 error_callback_count_(0),
30 fake_delegate_paired_( 30 fake_delegate_paired_(
31 bluez::FakeBluetoothDeviceClient::kPairedDevicePath), 31 bluez::FakeBluetoothDeviceClient::kPairedDevicePath),
32 fake_delegate_autopair_( 32 fake_delegate_autopair_(
33 bluez::FakeBluetoothDeviceClient::kLegacyAutopairPath), 33 bluez::FakeBluetoothDeviceClient::kLegacyAutopairPath),
34 fake_delegate_listen_(""), 34 fake_delegate_listen_(""),
35 profile_user_ptr_(nullptr) {} 35 profile_user_ptr_(nullptr) {}
36 36
37 void SetUp() override { 37 void SetUp() override {
38 scoped_ptr<bluez::BluezDBusManagerSetter> dbus_setter = 38 scoped_ptr<bluez::BluezDBusManagerSetter> dbus_setter =
39 bluez::BluezDBusManager::GetSetterForTesting(); 39 bluez::BluezDBusManager::GetSetterForTesting();
40 40
41 dbus_setter->SetBluetoothAdapterClient( 41 dbus_setter->SetBluetoothAdapterClient(
42 scoped_ptr<bluez::BluetoothAdapterClient>( 42 scoped_ptr<bluez::BluetoothAdapterClient>(
43 new bluez::FakeBluetoothAdapterClient)); 43 new bluez::FakeBluetoothAdapterClient));
44 dbus_setter->SetBluetoothAgentManagerClient( 44 dbus_setter->SetBluetoothAgentManagerClient(
45 scoped_ptr<bluez::BluetoothAgentManagerClient>( 45 scoped_ptr<bluez::BluetoothAgentManagerClient>(
46 new bluez::FakeBluetoothAgentManagerClient)); 46 new bluez::FakeBluetoothAgentManagerClient));
47 dbus_setter->SetBluetoothDeviceClient( 47 dbus_setter->SetBluetoothDeviceClient(
48 scoped_ptr<bluez::BluetoothDeviceClient>( 48 scoped_ptr<bluez::BluetoothDeviceClient>(
49 new bluez::FakeBluetoothDeviceClient)); 49 new bluez::FakeBluetoothDeviceClient));
50 dbus_setter->SetBluetoothProfileManagerClient( 50 dbus_setter->SetBluetoothProfileManagerClient(
51 scoped_ptr<bluez::BluetoothProfileManagerClient>( 51 scoped_ptr<bluez::BluetoothProfileManagerClient>(
52 new bluez::FakeBluetoothProfileManagerClient)); 52 new bluez::FakeBluetoothProfileManagerClient));
53 53
54 // Grab a pointer to the adapter. 54 // Grab a pointer to the adapter.
55 device::BluetoothAdapterFactory::GetAdapter( 55 device::BluetoothAdapterFactory::GetAdapter(
56 base::Bind(&BluetoothAdapterProfileChromeOSTest::AdapterCallback, 56 base::Bind(&BluetoothAdapterProfileBlueZTest::AdapterCallback,
57 base::Unretained(this))); 57 base::Unretained(this)));
58 ASSERT_TRUE(adapter_.get() != nullptr); 58 ASSERT_TRUE(adapter_.get() != nullptr);
59 ASSERT_TRUE(adapter_->IsInitialized()); 59 ASSERT_TRUE(adapter_->IsInitialized());
60 ASSERT_TRUE(adapter_->IsPresent()); 60 ASSERT_TRUE(adapter_->IsPresent());
61 61
62 // Turn on the adapter. 62 // Turn on the adapter.
63 adapter_->SetPowered(true, base::Bind(&base::DoNothing), 63 adapter_->SetPowered(true, base::Bind(&base::DoNothing),
64 base::Bind(&base::DoNothing)); 64 base::Bind(&base::DoNothing));
65 ASSERT_TRUE(adapter_->IsPowered()); 65 ASSERT_TRUE(adapter_->IsPowered());
66 } 66 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 void Cancel() override { 108 void Cancel() override {
109 // noop 109 // noop
110 } 110 }
111 111
112 unsigned int connections_; 112 unsigned int connections_;
113 unsigned int disconnections_; 113 unsigned int disconnections_;
114 dbus::ObjectPath device_path_; 114 dbus::ObjectPath device_path_;
115 }; 115 };
116 116
117 void ProfileSuccessCallback( 117 void ProfileSuccessCallback(
118 scoped_ptr<BluetoothAdapterProfileChromeOS> profile) { 118 scoped_ptr<BluetoothAdapterProfileBlueZ> profile) {
119 profile_.swap(profile); 119 profile_.swap(profile);
120 ++success_callback_count_; 120 ++success_callback_count_;
121 } 121 }
122 122
123 void ProfileUserSuccessCallback(BluetoothAdapterProfileChromeOS* profile) { 123 void ProfileUserSuccessCallback(BluetoothAdapterProfileBlueZ* profile) {
124 profile_user_ptr_ = profile; 124 profile_user_ptr_ = profile;
125 ++success_callback_count_; 125 ++success_callback_count_;
126 } 126 }
127 127
128 void MatchedProfileCallback(BluetoothAdapterProfileChromeOS* profile) { 128 void MatchedProfileCallback(BluetoothAdapterProfileBlueZ* profile) {
129 ASSERT_EQ(profile_user_ptr_, profile); 129 ASSERT_EQ(profile_user_ptr_, profile);
130 ++success_callback_count_; 130 ++success_callback_count_;
131 } 131 }
132 132
133 void DBusConnectSuccessCallback() { ++success_callback_count_; } 133 void DBusConnectSuccessCallback() { ++success_callback_count_; }
134 134
135 void DBusErrorCallback(const std::string& error_name, 135 void DBusErrorCallback(const std::string& error_name,
136 const std::string& error_message) { 136 const std::string& error_message) {
137 ++error_callback_count_; 137 ++error_callback_count_;
138 } 138 }
139 139
140 void BasicErrorCallback(const std::string& error_message) { 140 void BasicErrorCallback(const std::string& error_message) {
141 ++error_callback_count_; 141 ++error_callback_count_;
142 } 142 }
143 143
144 protected: 144 protected:
145 base::MessageLoop message_loop_; 145 base::MessageLoop message_loop_;
146 146
147 scoped_refptr<BluetoothAdapter> adapter_; 147 scoped_refptr<BluetoothAdapter> adapter_;
148 148
149 unsigned int success_callback_count_; 149 unsigned int success_callback_count_;
150 unsigned int error_callback_count_; 150 unsigned int error_callback_count_;
151 151
152 FakeDelegate fake_delegate_paired_; 152 FakeDelegate fake_delegate_paired_;
153 FakeDelegate fake_delegate_autopair_; 153 FakeDelegate fake_delegate_autopair_;
154 FakeDelegate fake_delegate_listen_; 154 FakeDelegate fake_delegate_listen_;
155 155
156 scoped_ptr<BluetoothAdapterProfileChromeOS> profile_; 156 scoped_ptr<BluetoothAdapterProfileBlueZ> profile_;
157 157
158 // unowned pointer as expected to be used by clients of 158 // unowned pointer as expected to be used by clients of
159 // BluetoothAdapterChromeOS::UseProfile like BluetoothSocketChromeOS 159 // BluetoothAdapterBlueZ::UseProfile like BluetoothSocketBlueZ
160 BluetoothAdapterProfileChromeOS* profile_user_ptr_; 160 BluetoothAdapterProfileBlueZ* profile_user_ptr_;
161 }; 161 };
162 162
163 TEST_F(BluetoothAdapterProfileChromeOSTest, DelegateCount) { 163 TEST_F(BluetoothAdapterProfileBlueZTest, DelegateCount) {
164 BluetoothUUID uuid(bluez::FakeBluetoothProfileManagerClient::kRfcommUuid); 164 BluetoothUUID uuid(bluez::FakeBluetoothProfileManagerClient::kRfcommUuid);
165 bluez::BluetoothProfileManagerClient::Options options; 165 bluez::BluetoothProfileManagerClient::Options options;
166 166
167 options.require_authentication.reset(new bool(false)); 167 options.require_authentication.reset(new bool(false));
168 168
169 BluetoothAdapterProfileChromeOS::Register( 169 BluetoothAdapterProfileBlueZ::Register(
170 uuid, options, 170 uuid, options,
171 base::Bind(&BluetoothAdapterProfileChromeOSTest::ProfileSuccessCallback, 171 base::Bind(&BluetoothAdapterProfileBlueZTest::ProfileSuccessCallback,
172 base::Unretained(this)), 172 base::Unretained(this)),
173 base::Bind(&BluetoothAdapterProfileChromeOSTest::DBusErrorCallback, 173 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusErrorCallback,
174 base::Unretained(this))); 174 base::Unretained(this)));
175 175
176 message_loop_.RunUntilIdle(); 176 message_loop_.RunUntilIdle();
177 177
178 EXPECT_TRUE(profile_); 178 EXPECT_TRUE(profile_);
179 EXPECT_EQ(1U, success_callback_count_); 179 EXPECT_EQ(1U, success_callback_count_);
180 EXPECT_EQ(0U, error_callback_count_); 180 EXPECT_EQ(0U, error_callback_count_);
181 181
182 EXPECT_EQ(0U, profile_->DelegateCount()); 182 EXPECT_EQ(0U, profile_->DelegateCount());
183 183
184 profile_->SetDelegate(fake_delegate_paired_.device_path_, 184 profile_->SetDelegate(fake_delegate_paired_.device_path_,
185 &fake_delegate_paired_); 185 &fake_delegate_paired_);
186 186
187 EXPECT_EQ(1U, profile_->DelegateCount()); 187 EXPECT_EQ(1U, profile_->DelegateCount());
188 188
189 profile_->RemoveDelegate(fake_delegate_autopair_.device_path_, 189 profile_->RemoveDelegate(fake_delegate_autopair_.device_path_,
190 base::Bind(&base::DoNothing)); 190 base::Bind(&base::DoNothing));
191 191
192 EXPECT_EQ(1U, profile_->DelegateCount()); 192 EXPECT_EQ(1U, profile_->DelegateCount());
193 193
194 profile_->RemoveDelegate(fake_delegate_paired_.device_path_, 194 profile_->RemoveDelegate(fake_delegate_paired_.device_path_,
195 base::Bind(&base::DoNothing)); 195 base::Bind(&base::DoNothing));
196 196
197 EXPECT_EQ(0U, profile_->DelegateCount()); 197 EXPECT_EQ(0U, profile_->DelegateCount());
198 } 198 }
199 199
200 TEST_F(BluetoothAdapterProfileChromeOSTest, BlackHole) { 200 TEST_F(BluetoothAdapterProfileBlueZTest, BlackHole) {
201 BluetoothUUID uuid(bluez::FakeBluetoothProfileManagerClient::kRfcommUuid); 201 BluetoothUUID uuid(bluez::FakeBluetoothProfileManagerClient::kRfcommUuid);
202 bluez::BluetoothProfileManagerClient::Options options; 202 bluez::BluetoothProfileManagerClient::Options options;
203 203
204 options.require_authentication.reset(new bool(false)); 204 options.require_authentication.reset(new bool(false));
205 205
206 BluetoothAdapterProfileChromeOS::Register( 206 BluetoothAdapterProfileBlueZ::Register(
207 uuid, options, 207 uuid, options,
208 base::Bind(&BluetoothAdapterProfileChromeOSTest::ProfileSuccessCallback, 208 base::Bind(&BluetoothAdapterProfileBlueZTest::ProfileSuccessCallback,
209 base::Unretained(this)), 209 base::Unretained(this)),
210 base::Bind(&BluetoothAdapterProfileChromeOSTest::DBusErrorCallback, 210 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusErrorCallback,
211 base::Unretained(this))); 211 base::Unretained(this)));
212 212
213 message_loop_.RunUntilIdle(); 213 message_loop_.RunUntilIdle();
214 214
215 EXPECT_TRUE(profile_); 215 EXPECT_TRUE(profile_);
216 EXPECT_EQ(1U, success_callback_count_); 216 EXPECT_EQ(1U, success_callback_count_);
217 EXPECT_EQ(0U, error_callback_count_); 217 EXPECT_EQ(0U, error_callback_count_);
218 218
219 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->ConnectProfile( 219 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->ConnectProfile(
220 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kPairedDevicePath), 220 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kPairedDevicePath),
221 bluez::FakeBluetoothProfileManagerClient::kRfcommUuid, 221 bluez::FakeBluetoothProfileManagerClient::kRfcommUuid,
222 base::Bind( 222 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusConnectSuccessCallback,
223 &BluetoothAdapterProfileChromeOSTest::DBusConnectSuccessCallback, 223 base::Unretained(this)),
224 base::Unretained(this)), 224 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusErrorCallback,
225 base::Bind(&BluetoothAdapterProfileChromeOSTest::DBusErrorCallback,
226 base::Unretained(this))); 225 base::Unretained(this)));
227 226
228 message_loop_.RunUntilIdle(); 227 message_loop_.RunUntilIdle();
229 228
230 EXPECT_EQ(1U, success_callback_count_); 229 EXPECT_EQ(1U, success_callback_count_);
231 EXPECT_EQ(1U, error_callback_count_); 230 EXPECT_EQ(1U, error_callback_count_);
232 231
233 EXPECT_EQ(0U, fake_delegate_paired_.connections_); 232 EXPECT_EQ(0U, fake_delegate_paired_.connections_);
234 } 233 }
235 234
236 TEST_F(BluetoothAdapterProfileChromeOSTest, Routing) { 235 TEST_F(BluetoothAdapterProfileBlueZTest, Routing) {
237 BluetoothUUID uuid(bluez::FakeBluetoothProfileManagerClient::kRfcommUuid); 236 BluetoothUUID uuid(bluez::FakeBluetoothProfileManagerClient::kRfcommUuid);
238 bluez::BluetoothProfileManagerClient::Options options; 237 bluez::BluetoothProfileManagerClient::Options options;
239 238
240 options.require_authentication.reset(new bool(false)); 239 options.require_authentication.reset(new bool(false));
241 240
242 BluetoothAdapterProfileChromeOS::Register( 241 BluetoothAdapterProfileBlueZ::Register(
243 uuid, options, 242 uuid, options,
244 base::Bind(&BluetoothAdapterProfileChromeOSTest::ProfileSuccessCallback, 243 base::Bind(&BluetoothAdapterProfileBlueZTest::ProfileSuccessCallback,
245 base::Unretained(this)), 244 base::Unretained(this)),
246 base::Bind(&BluetoothAdapterProfileChromeOSTest::DBusErrorCallback, 245 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusErrorCallback,
247 base::Unretained(this))); 246 base::Unretained(this)));
248 247
249 message_loop_.RunUntilIdle(); 248 message_loop_.RunUntilIdle();
250 249
251 ASSERT_TRUE(profile_); 250 ASSERT_TRUE(profile_);
252 ASSERT_EQ(1U, success_callback_count_); 251 ASSERT_EQ(1U, success_callback_count_);
253 ASSERT_EQ(0U, error_callback_count_); 252 ASSERT_EQ(0U, error_callback_count_);
254 253
255 profile_->SetDelegate(fake_delegate_paired_.device_path_, 254 profile_->SetDelegate(fake_delegate_paired_.device_path_,
256 &fake_delegate_paired_); 255 &fake_delegate_paired_);
257 profile_->SetDelegate(fake_delegate_autopair_.device_path_, 256 profile_->SetDelegate(fake_delegate_autopair_.device_path_,
258 &fake_delegate_autopair_); 257 &fake_delegate_autopair_);
259 profile_->SetDelegate(fake_delegate_listen_.device_path_, 258 profile_->SetDelegate(fake_delegate_listen_.device_path_,
260 &fake_delegate_listen_); 259 &fake_delegate_listen_);
261 260
262 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->ConnectProfile( 261 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->ConnectProfile(
263 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kPairedDevicePath), 262 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kPairedDevicePath),
264 bluez::FakeBluetoothProfileManagerClient::kRfcommUuid, 263 bluez::FakeBluetoothProfileManagerClient::kRfcommUuid,
265 base::Bind( 264 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusConnectSuccessCallback,
266 &BluetoothAdapterProfileChromeOSTest::DBusConnectSuccessCallback, 265 base::Unretained(this)),
267 base::Unretained(this)), 266 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusErrorCallback,
268 base::Bind(&BluetoothAdapterProfileChromeOSTest::DBusErrorCallback,
269 base::Unretained(this))); 267 base::Unretained(this)));
270 268
271 message_loop_.RunUntilIdle(); 269 message_loop_.RunUntilIdle();
272 270
273 EXPECT_EQ(2U, success_callback_count_); 271 EXPECT_EQ(2U, success_callback_count_);
274 EXPECT_EQ(0U, error_callback_count_); 272 EXPECT_EQ(0U, error_callback_count_);
275 273
276 EXPECT_EQ(1U, fake_delegate_paired_.connections_); 274 EXPECT_EQ(1U, fake_delegate_paired_.connections_);
277 275
278 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->ConnectProfile( 276 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->ConnectProfile(
279 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLegacyAutopairPath), 277 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLegacyAutopairPath),
280 bluez::FakeBluetoothProfileManagerClient::kRfcommUuid, 278 bluez::FakeBluetoothProfileManagerClient::kRfcommUuid,
281 base::Bind( 279 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusConnectSuccessCallback,
282 &BluetoothAdapterProfileChromeOSTest::DBusConnectSuccessCallback, 280 base::Unretained(this)),
283 base::Unretained(this)), 281 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusErrorCallback,
284 base::Bind(&BluetoothAdapterProfileChromeOSTest::DBusErrorCallback,
285 base::Unretained(this))); 282 base::Unretained(this)));
286 283
287 message_loop_.RunUntilIdle(); 284 message_loop_.RunUntilIdle();
288 285
289 EXPECT_EQ(3U, success_callback_count_); 286 EXPECT_EQ(3U, success_callback_count_);
290 EXPECT_EQ(0U, error_callback_count_); 287 EXPECT_EQ(0U, error_callback_count_);
291 288
292 EXPECT_EQ(1U, fake_delegate_autopair_.connections_); 289 EXPECT_EQ(1U, fake_delegate_autopair_.connections_);
293 290
294 // Incoming connections look the same from BlueZ. 291 // Incoming connections look the same from BlueZ.
295 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->ConnectProfile( 292 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->ConnectProfile(
296 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kDisplayPinCodePath), 293 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kDisplayPinCodePath),
297 bluez::FakeBluetoothProfileManagerClient::kRfcommUuid, 294 bluez::FakeBluetoothProfileManagerClient::kRfcommUuid,
298 base::Bind( 295 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusConnectSuccessCallback,
299 &BluetoothAdapterProfileChromeOSTest::DBusConnectSuccessCallback, 296 base::Unretained(this)),
300 base::Unretained(this)), 297 base::Bind(&BluetoothAdapterProfileBlueZTest::DBusErrorCallback,
301 base::Bind(&BluetoothAdapterProfileChromeOSTest::DBusErrorCallback,
302 base::Unretained(this))); 298 base::Unretained(this)));
303 299
304 message_loop_.RunUntilIdle(); 300 message_loop_.RunUntilIdle();
305 301
306 EXPECT_EQ(4U, success_callback_count_); 302 EXPECT_EQ(4U, success_callback_count_);
307 EXPECT_EQ(0U, error_callback_count_); 303 EXPECT_EQ(0U, error_callback_count_);
308 304
309 EXPECT_EQ(1U, fake_delegate_listen_.connections_); 305 EXPECT_EQ(1U, fake_delegate_listen_.connections_);
310 } 306 }
311 307
312 TEST_F(BluetoothAdapterProfileChromeOSTest, SimultaneousRegister) { 308 TEST_F(BluetoothAdapterProfileBlueZTest, SimultaneousRegister) {
313 BluetoothUUID uuid(bluez::FakeBluetoothProfileManagerClient::kRfcommUuid); 309 BluetoothUUID uuid(bluez::FakeBluetoothProfileManagerClient::kRfcommUuid);
314 bluez::BluetoothProfileManagerClient::Options options; 310 bluez::BluetoothProfileManagerClient::Options options;
315 BluetoothAdapterChromeOS* adapter = 311 BluetoothAdapterBlueZ* adapter =
316 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); 312 static_cast<BluetoothAdapterBlueZ*>(adapter_.get());
317 313
318 options.require_authentication.reset(new bool(false)); 314 options.require_authentication.reset(new bool(false));
319 315
320 success_callback_count_ = 0; 316 success_callback_count_ = 0;
321 error_callback_count_ = 0; 317 error_callback_count_ = 0;
322 318
323 adapter->UseProfile( 319 adapter->UseProfile(
324 uuid, fake_delegate_paired_.device_path_, options, &fake_delegate_paired_, 320 uuid, fake_delegate_paired_.device_path_, options, &fake_delegate_paired_,
325 base::Bind( 321 base::Bind(&BluetoothAdapterProfileBlueZTest::ProfileUserSuccessCallback,
326 &BluetoothAdapterProfileChromeOSTest::ProfileUserSuccessCallback, 322 base::Unretained(this)),
327 base::Unretained(this)), 323 base::Bind(&BluetoothAdapterProfileBlueZTest::BasicErrorCallback,
328 base::Bind(&BluetoothAdapterProfileChromeOSTest::BasicErrorCallback,
329 base::Unretained(this))); 324 base::Unretained(this)));
330 325
331 adapter->UseProfile( 326 adapter->UseProfile(
332 uuid, fake_delegate_autopair_.device_path_, options, 327 uuid, fake_delegate_autopair_.device_path_, options,
333 &fake_delegate_autopair_, 328 &fake_delegate_autopair_,
334 base::Bind(&BluetoothAdapterProfileChromeOSTest::MatchedProfileCallback, 329 base::Bind(&BluetoothAdapterProfileBlueZTest::MatchedProfileCallback,
335 base::Unretained(this)), 330 base::Unretained(this)),
336 base::Bind(&BluetoothAdapterProfileChromeOSTest::BasicErrorCallback, 331 base::Bind(&BluetoothAdapterProfileBlueZTest::BasicErrorCallback,
337 base::Unretained(this))); 332 base::Unretained(this)));
338 333
339 message_loop_.RunUntilIdle(); 334 message_loop_.RunUntilIdle();
340 335
341 EXPECT_TRUE(profile_user_ptr_); 336 EXPECT_TRUE(profile_user_ptr_);
342 EXPECT_EQ(2U, success_callback_count_); 337 EXPECT_EQ(2U, success_callback_count_);
343 EXPECT_EQ(0U, error_callback_count_); 338 EXPECT_EQ(0U, error_callback_count_);
344 339
345 adapter->ReleaseProfile(fake_delegate_paired_.device_path_, 340 adapter->ReleaseProfile(fake_delegate_paired_.device_path_,
346 profile_user_ptr_); 341 profile_user_ptr_);
347 adapter->ReleaseProfile(fake_delegate_autopair_.device_path_, 342 adapter->ReleaseProfile(fake_delegate_autopair_.device_path_,
348 profile_user_ptr_); 343 profile_user_ptr_);
349 344
350 message_loop_.RunUntilIdle(); 345 message_loop_.RunUntilIdle();
351 } 346 }
352 347
353 TEST_F(BluetoothAdapterProfileChromeOSTest, SimultaneousRegisterFail) { 348 TEST_F(BluetoothAdapterProfileBlueZTest, SimultaneousRegisterFail) {
354 BluetoothUUID uuid( 349 BluetoothUUID uuid(
355 bluez::FakeBluetoothProfileManagerClient::kUnregisterableUuid); 350 bluez::FakeBluetoothProfileManagerClient::kUnregisterableUuid);
356 bluez::BluetoothProfileManagerClient::Options options; 351 bluez::BluetoothProfileManagerClient::Options options;
357 BluetoothAdapterChromeOS* adapter = 352 BluetoothAdapterBlueZ* adapter =
358 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); 353 static_cast<BluetoothAdapterBlueZ*>(adapter_.get());
359 354
360 options.require_authentication.reset(new bool(false)); 355 options.require_authentication.reset(new bool(false));
361 356
362 success_callback_count_ = 0; 357 success_callback_count_ = 0;
363 error_callback_count_ = 0; 358 error_callback_count_ = 0;
364 359
365 adapter->UseProfile( 360 adapter->UseProfile(
366 uuid, fake_delegate_paired_.device_path_, options, &fake_delegate_paired_, 361 uuid, fake_delegate_paired_.device_path_, options, &fake_delegate_paired_,
367 base::Bind( 362 base::Bind(&BluetoothAdapterProfileBlueZTest::ProfileUserSuccessCallback,
368 &BluetoothAdapterProfileChromeOSTest::ProfileUserSuccessCallback, 363 base::Unretained(this)),
369 base::Unretained(this)), 364 base::Bind(&BluetoothAdapterProfileBlueZTest::BasicErrorCallback,
370 base::Bind(&BluetoothAdapterProfileChromeOSTest::BasicErrorCallback,
371 base::Unretained(this))); 365 base::Unretained(this)));
372 366
373 adapter->UseProfile( 367 adapter->UseProfile(
374 uuid, fake_delegate_autopair_.device_path_, options, 368 uuid, fake_delegate_autopair_.device_path_, options,
375 &fake_delegate_autopair_, 369 &fake_delegate_autopair_,
376 base::Bind(&BluetoothAdapterProfileChromeOSTest::MatchedProfileCallback, 370 base::Bind(&BluetoothAdapterProfileBlueZTest::MatchedProfileCallback,
377 base::Unretained(this)), 371 base::Unretained(this)),
378 base::Bind(&BluetoothAdapterProfileChromeOSTest::BasicErrorCallback, 372 base::Bind(&BluetoothAdapterProfileBlueZTest::BasicErrorCallback,
379 base::Unretained(this))); 373 base::Unretained(this)));
380 374
381 message_loop_.RunUntilIdle(); 375 message_loop_.RunUntilIdle();
382 376
383 EXPECT_FALSE(profile_user_ptr_); 377 EXPECT_FALSE(profile_user_ptr_);
384 EXPECT_EQ(0U, success_callback_count_); 378 EXPECT_EQ(0U, success_callback_count_);
385 EXPECT_EQ(2U, error_callback_count_); 379 EXPECT_EQ(2U, error_callback_count_);
386 } 380 }
387 381
388 } // namespace chromeos 382 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698