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

Side by Side Diff: device/bluetooth/bluetooth_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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/memory/scoped_vector.h" 5 #include "base/memory/scoped_vector.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "dbus/object_path.h" 9 #include "dbus/object_path.h"
10 #include "device/bluetooth/bluetooth_adapter.h" 10 #include "device/bluetooth/bluetooth_adapter.h"
11 #include "device/bluetooth/bluetooth_adapter_chromeos.h" 11 #include "device/bluetooth/bluetooth_adapter_bluez.h"
12 #include "device/bluetooth/bluetooth_adapter_factory.h" 12 #include "device/bluetooth/bluetooth_adapter_factory.h"
13 #include "device/bluetooth/bluetooth_device.h" 13 #include "device/bluetooth/bluetooth_device.h"
14 #include "device/bluetooth/bluetooth_device_chromeos.h" 14 #include "device/bluetooth/bluetooth_device_bluez.h"
15 #include "device/bluetooth/bluetooth_discovery_session.h" 15 #include "device/bluetooth/bluetooth_discovery_session.h"
16 #include "device/bluetooth/bluetooth_pairing_chromeos.h" 16 #include "device/bluetooth/bluetooth_pairing_bluez.h"
17 #include "device/bluetooth/dbus/bluez_dbus_manager.h" 17 #include "device/bluetooth/dbus/bluez_dbus_manager.h"
18 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h" 18 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h"
19 #include "device/bluetooth/dbus/fake_bluetooth_agent_manager_client.h" 19 #include "device/bluetooth/dbus/fake_bluetooth_agent_manager_client.h"
20 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" 20 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h"
21 #include "device/bluetooth/dbus/fake_bluetooth_gatt_service_client.h" 21 #include "device/bluetooth/dbus/fake_bluetooth_gatt_service_client.h"
22 #include "device/bluetooth/dbus/fake_bluetooth_input_client.h" 22 #include "device/bluetooth/dbus/fake_bluetooth_input_client.h"
23 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" 23 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h"
24 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
25 #include "third_party/cros_system_api/dbus/service_constants.h" 25 #include "third_party/cros_system_api/dbus/service_constants.h"
26 26
27 using device::BluetoothAdapter; 27 using device::BluetoothAdapter;
28 using device::BluetoothAdapterFactory; 28 using device::BluetoothAdapterFactory;
29 using device::BluetoothAudioSink; 29 using device::BluetoothAudioSink;
30 using device::BluetoothDevice; 30 using device::BluetoothDevice;
31 using device::BluetoothDiscoveryFilter; 31 using device::BluetoothDiscoveryFilter;
32 using device::BluetoothDiscoverySession; 32 using device::BluetoothDiscoverySession;
33 using device::BluetoothUUID; 33 using device::BluetoothUUID;
34 using device::TestBluetoothAdapterObserver; 34 using device::TestBluetoothAdapterObserver;
35 35
36 namespace chromeos { 36 namespace bluez {
37 37
38 namespace { 38 namespace {
39 39
40 // Callback for BluetoothDevice::GetConnectionInfo() that simply saves the 40 // Callback for BluetoothDevice::GetConnectionInfo() that simply saves the
41 // connection info to the bound argument. 41 // connection info to the bound argument.
42 void SaveConnectionInfo(BluetoothDevice::ConnectionInfo* out, 42 void SaveConnectionInfo(BluetoothDevice::ConnectionInfo* out,
43 const BluetoothDevice::ConnectionInfo& conn_info) { 43 const BluetoothDevice::ConnectionInfo& conn_info) {
44 *out = conn_info; 44 *out = conn_info;
45 }; 45 };
46 46
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 // Some tests use a message loop since background processing is simulated; 156 // Some tests use a message loop since background processing is simulated;
157 // break out of those loops. 157 // break out of those loops.
158 void QuitMessageLoop() { 158 void QuitMessageLoop() {
159 if (base::MessageLoop::current() && 159 if (base::MessageLoop::current() &&
160 base::MessageLoop::current()->is_running()) { 160 base::MessageLoop::current()->is_running()) {
161 base::MessageLoop::current()->QuitWhenIdle(); 161 base::MessageLoop::current()->QuitWhenIdle();
162 } 162 }
163 } 163 }
164 }; 164 };
165 165
166 class BluetoothChromeOSTest : public testing::Test { 166 class BluetoothBlueZTest : public testing::Test {
167 public: 167 public:
168 void SetUp() override { 168 void SetUp() override {
169 scoped_ptr<bluez::BluezDBusManagerSetter> dbus_setter = 169 scoped_ptr<bluez::BluezDBusManagerSetter> dbus_setter =
170 bluez::BluezDBusManager::GetSetterForTesting(); 170 bluez::BluezDBusManager::GetSetterForTesting();
171 // We need to initialize BluezDBusManager early to prevent 171 // We need to initialize BluezDBusManager early to prevent
172 // Bluetooth*::Create() methods from picking the real instead of fake 172 // Bluetooth*::Create() methods from picking the real instead of fake
173 // implementations. 173 // implementations.
174 fake_bluetooth_adapter_client_ = new bluez::FakeBluetoothAdapterClient; 174 fake_bluetooth_adapter_client_ = new bluez::FakeBluetoothAdapterClient;
175 dbus_setter->SetBluetoothAdapterClient( 175 dbus_setter->SetBluetoothAdapterClient(
176 scoped_ptr<bluez::BluetoothAdapterClient>( 176 scoped_ptr<bluez::BluetoothAdapterClient>(
(...skipping 15 matching lines...) Expand all
192 fake_bluetooth_adapter_client_->SetSimulationIntervalMs(10); 192 fake_bluetooth_adapter_client_->SetSimulationIntervalMs(10);
193 193
194 callback_count_ = 0; 194 callback_count_ = 0;
195 error_callback_count_ = 0; 195 error_callback_count_ = 0;
196 last_connect_error_ = BluetoothDevice::ERROR_UNKNOWN; 196 last_connect_error_ = BluetoothDevice::ERROR_UNKNOWN;
197 last_client_error_ = ""; 197 last_client_error_ = "";
198 } 198 }
199 199
200 void TearDown() override { 200 void TearDown() override {
201 for (ScopedVector<BluetoothDiscoverySession>::iterator iter = 201 for (ScopedVector<BluetoothDiscoverySession>::iterator iter =
202 discovery_sessions_.begin(); 202 discovery_sessions_.begin();
203 iter != discovery_sessions_.end(); 203 iter != discovery_sessions_.end(); ++iter) {
204 ++iter) {
205 BluetoothDiscoverySession* session = *iter; 204 BluetoothDiscoverySession* session = *iter;
206 if (!session->IsActive()) 205 if (!session->IsActive())
207 continue; 206 continue;
208 callback_count_ = 0; 207 callback_count_ = 0;
209 session->Stop(GetCallback(), GetErrorCallback()); 208 session->Stop(GetCallback(), GetErrorCallback());
210 message_loop_.Run(); 209 message_loop_.Run();
211 ASSERT_EQ(1, callback_count_); 210 ASSERT_EQ(1, callback_count_);
212 } 211 }
213 discovery_sessions_.clear(); 212 discovery_sessions_.clear();
214 adapter_ = nullptr; 213 adapter_ = nullptr;
215 bluez::BluezDBusManager::Shutdown(); 214 bluez::BluezDBusManager::Shutdown();
216 } 215 }
217 216
218 // Generic callbacks 217 // Generic callbacks
219 void Callback() { 218 void Callback() {
220 ++callback_count_; 219 ++callback_count_;
221 QuitMessageLoop(); 220 QuitMessageLoop();
222 } 221 }
223 222
224 base::Closure GetCallback() { 223 base::Closure GetCallback() {
225 return base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)); 224 return base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this));
226 } 225 }
227 226
228 void DiscoverySessionCallback( 227 void DiscoverySessionCallback(
229 scoped_ptr<BluetoothDiscoverySession> discovery_session) { 228 scoped_ptr<BluetoothDiscoverySession> discovery_session) {
230 ++callback_count_; 229 ++callback_count_;
231 discovery_sessions_.push_back(discovery_session.release()); 230 discovery_sessions_.push_back(discovery_session.release());
232 QuitMessageLoop(); 231 QuitMessageLoop();
233 } 232 }
234 233
235 void AudioSinkAcquiredCallback(scoped_refptr<BluetoothAudioSink>) { 234 void AudioSinkAcquiredCallback(scoped_refptr<BluetoothAudioSink>) {
236 ++callback_count_; 235 ++callback_count_;
237 QuitMessageLoop(); 236 QuitMessageLoop();
238 } 237 }
239 238
240 void ProfileRegisteredCallback(BluetoothAdapterProfileChromeOS* profile) { 239 void ProfileRegisteredCallback(BluetoothAdapterProfileBlueZ* profile) {
241 adapter_profile_ = profile; 240 adapter_profile_ = profile;
242 ++callback_count_; 241 ++callback_count_;
243 QuitMessageLoop(); 242 QuitMessageLoop();
244 } 243 }
245 244
246 void ErrorCallback() { 245 void ErrorCallback() {
247 ++error_callback_count_; 246 ++error_callback_count_;
248 QuitMessageLoop(); 247 QuitMessageLoop();
249 } 248 }
250 249
251 void DiscoveryErrorCallback(device::UMABluetoothDiscoverySessionOutcome) { 250 void DiscoveryErrorCallback(device::UMABluetoothDiscoverySessionOutcome) {
252 ErrorCallback(); 251 ErrorCallback();
253 } 252 }
254 253
255 base::Closure GetErrorCallback() { 254 base::Closure GetErrorCallback() {
256 return base::Bind(&BluetoothChromeOSTest::ErrorCallback, 255 return base::Bind(&BluetoothBlueZTest::ErrorCallback,
257 base::Unretained(this)); 256 base::Unretained(this));
258 } 257 }
259 258
260 base::Callback<void(device::UMABluetoothDiscoverySessionOutcome)> 259 base::Callback<void(device::UMABluetoothDiscoverySessionOutcome)>
261 GetDiscoveryErrorCallback() { 260 GetDiscoveryErrorCallback() {
262 return base::Bind(&BluetoothChromeOSTest::DiscoveryErrorCallback, 261 return base::Bind(&BluetoothBlueZTest::DiscoveryErrorCallback,
263 base::Unretained(this)); 262 base::Unretained(this));
264 } 263 }
265 264
266 void DBusErrorCallback(const std::string& error_name, 265 void DBusErrorCallback(const std::string& error_name,
267 const std::string& error_message) { 266 const std::string& error_message) {
268 ++error_callback_count_; 267 ++error_callback_count_;
269 last_client_error_ = error_name; 268 last_client_error_ = error_name;
270 QuitMessageLoop(); 269 QuitMessageLoop();
271 } 270 }
272 271
273 void ConnectErrorCallback(BluetoothDevice::ConnectErrorCode error) { 272 void ConnectErrorCallback(BluetoothDevice::ConnectErrorCode error) {
274 ++error_callback_count_; 273 ++error_callback_count_;
275 last_connect_error_ = error; 274 last_connect_error_ = error;
276 } 275 }
277 276
278 void AudioSinkErrorCallback(BluetoothAudioSink::ErrorCode) { 277 void AudioSinkErrorCallback(BluetoothAudioSink::ErrorCode) {
279 ++error_callback_count_; 278 ++error_callback_count_;
280 QuitMessageLoop(); 279 QuitMessageLoop();
281 } 280 }
282 281
283 void ErrorCompletionCallback(const std::string& error_message) { 282 void ErrorCompletionCallback(const std::string& error_message) {
284 ++error_callback_count_; 283 ++error_callback_count_;
285 QuitMessageLoop(); 284 QuitMessageLoop();
286 } 285 }
287 286
288 // Call to fill the adapter_ member with a BluetoothAdapter instance. 287 // Call to fill the adapter_ member with a BluetoothAdapter instance.
289 void GetAdapter() { 288 void GetAdapter() {
290 adapter_ = new BluetoothAdapterChromeOS(); 289 adapter_ = new BluetoothAdapterBlueZ();
291 ASSERT_TRUE(adapter_.get() != nullptr); 290 ASSERT_TRUE(adapter_.get() != nullptr);
292 ASSERT_TRUE(adapter_->IsInitialized()); 291 ASSERT_TRUE(adapter_->IsInitialized());
293 } 292 }
294 293
295 // Run a discovery phase until the named device is detected, or if the named 294 // Run a discovery phase until the named device is detected, or if the named
296 // device is not created, the discovery process ends without finding it. 295 // device is not created, the discovery process ends without finding it.
297 // 296 //
298 // The correct behavior of discovery is tested by the "Discovery" test case 297 // The correct behavior of discovery is tested by the "Discovery" test case
299 // without using this function. 298 // without using this function.
300 void DiscoverDevice(const std::string& address) { 299 void DiscoverDevice(const std::string& address) {
301 ASSERT_TRUE(adapter_.get() != nullptr); 300 ASSERT_TRUE(adapter_.get() != nullptr);
302 ASSERT_TRUE(base::MessageLoop::current() != nullptr); 301 ASSERT_TRUE(base::MessageLoop::current() != nullptr);
303 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 302 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
304 303
305 TestBluetoothAdapterObserver observer(adapter_); 304 TestBluetoothAdapterObserver observer(adapter_);
306 305
307 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 306 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
308 adapter_->StartDiscoverySession( 307 adapter_->StartDiscoverySession(
309 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 308 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
310 base::Unretained(this)), 309 base::Unretained(this)),
311 GetErrorCallback()); 310 GetErrorCallback());
312 base::MessageLoop::current()->Run(); 311 base::MessageLoop::current()->Run();
313 ASSERT_EQ(2, callback_count_); 312 ASSERT_EQ(2, callback_count_);
314 ASSERT_EQ(0, error_callback_count_); 313 ASSERT_EQ(0, error_callback_count_);
315 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 314 ASSERT_EQ((size_t)1, discovery_sessions_.size());
316 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); 315 ASSERT_TRUE(discovery_sessions_[0]->IsActive());
317 callback_count_ = 0; 316 callback_count_ = 0;
318 317
319 ASSERT_TRUE(adapter_->IsPowered()); 318 ASSERT_TRUE(adapter_->IsPowered());
(...skipping 23 matching lines...) Expand all
343 base::MessageLoop message_loop_; 342 base::MessageLoop message_loop_;
344 bluez::FakeBluetoothAdapterClient* fake_bluetooth_adapter_client_; 343 bluez::FakeBluetoothAdapterClient* fake_bluetooth_adapter_client_;
345 bluez::FakeBluetoothDeviceClient* fake_bluetooth_device_client_; 344 bluez::FakeBluetoothDeviceClient* fake_bluetooth_device_client_;
346 scoped_refptr<BluetoothAdapter> adapter_; 345 scoped_refptr<BluetoothAdapter> adapter_;
347 346
348 int callback_count_; 347 int callback_count_;
349 int error_callback_count_; 348 int error_callback_count_;
350 enum BluetoothDevice::ConnectErrorCode last_connect_error_; 349 enum BluetoothDevice::ConnectErrorCode last_connect_error_;
351 std::string last_client_error_; 350 std::string last_client_error_;
352 ScopedVector<BluetoothDiscoverySession> discovery_sessions_; 351 ScopedVector<BluetoothDiscoverySession> discovery_sessions_;
353 BluetoothAdapterProfileChromeOS* adapter_profile_; 352 BluetoothAdapterProfileBlueZ* adapter_profile_;
354 353
355 private: 354 private:
356 // Some tests use a message loop since background processing is simulated; 355 // Some tests use a message loop since background processing is simulated;
357 // break out of those loops. 356 // break out of those loops.
358 void QuitMessageLoop() { 357 void QuitMessageLoop() {
359 if (base::MessageLoop::current() && 358 if (base::MessageLoop::current() &&
360 base::MessageLoop::current()->is_running()) { 359 base::MessageLoop::current()->is_running()) {
361 base::MessageLoop::current()->QuitWhenIdle(); 360 base::MessageLoop::current()->QuitWhenIdle();
362 } 361 }
363 } 362 }
364 }; 363 };
365 364
366 TEST_F(BluetoothChromeOSTest, AlreadyPresent) { 365 TEST_F(BluetoothBlueZTest, AlreadyPresent) {
367 GetAdapter(); 366 GetAdapter();
368 367
369 // This verifies that the class gets the list of adapters when created; 368 // This verifies that the class gets the list of adapters when created;
370 // and initializes with an existing adapter if there is one. 369 // and initializes with an existing adapter if there is one.
371 EXPECT_TRUE(adapter_->IsPresent()); 370 EXPECT_TRUE(adapter_->IsPresent());
372 EXPECT_FALSE(adapter_->IsPowered()); 371 EXPECT_FALSE(adapter_->IsPowered());
373 EXPECT_EQ(bluez::FakeBluetoothAdapterClient::kAdapterAddress, 372 EXPECT_EQ(bluez::FakeBluetoothAdapterClient::kAdapterAddress,
374 adapter_->GetAddress()); 373 adapter_->GetAddress());
375 EXPECT_FALSE(adapter_->IsDiscovering()); 374 EXPECT_FALSE(adapter_->IsDiscovering());
376 375
377 // There should be 2 devices 376 // There should be 2 devices
378 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 377 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
379 EXPECT_EQ(2U, devices.size()); 378 EXPECT_EQ(2U, devices.size());
380 379
381 // |devices| are not ordered, verify it contains the 2 device addresses. 380 // |devices| are not ordered, verify it contains the 2 device addresses.
382 EXPECT_NE( 381 EXPECT_NE(
383 -1, GetDeviceIndexByAddress( 382 -1, GetDeviceIndexByAddress(
384 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress)); 383 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress));
385 EXPECT_NE( 384 EXPECT_NE(
386 -1, 385 -1,
387 GetDeviceIndexByAddress( 386 GetDeviceIndexByAddress(
388 devices, 387 devices,
389 bluez::FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress)); 388 bluez::FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress));
390 } 389 }
391 390
392 TEST_F(BluetoothChromeOSTest, BecomePresent) { 391 TEST_F(BluetoothBlueZTest, BecomePresent) {
393 fake_bluetooth_adapter_client_->SetVisible(false); 392 fake_bluetooth_adapter_client_->SetVisible(false);
394 GetAdapter(); 393 GetAdapter();
395 ASSERT_FALSE(adapter_->IsPresent()); 394 ASSERT_FALSE(adapter_->IsPresent());
396 395
397 // Install an observer; expect the AdapterPresentChanged to be called 396 // Install an observer; expect the AdapterPresentChanged to be called
398 // with true, and IsPresent() to return true. 397 // with true, and IsPresent() to return true.
399 TestBluetoothAdapterObserver observer(adapter_); 398 TestBluetoothAdapterObserver observer(adapter_);
400 399
401 fake_bluetooth_adapter_client_->SetVisible(true); 400 fake_bluetooth_adapter_client_->SetVisible(true);
402 401
403 EXPECT_EQ(1, observer.present_changed_count()); 402 EXPECT_EQ(1, observer.present_changed_count());
404 EXPECT_TRUE(observer.last_present()); 403 EXPECT_TRUE(observer.last_present());
405 404
406 EXPECT_TRUE(adapter_->IsPresent()); 405 EXPECT_TRUE(adapter_->IsPresent());
407 406
408 // We should have had a device announced. 407 // We should have had a device announced.
409 EXPECT_EQ(2, observer.device_added_count()); 408 EXPECT_EQ(2, observer.device_added_count());
410 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress, 409 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress,
411 observer.last_device_address()); 410 observer.last_device_address());
412 411
413 // Other callbacks shouldn't be called if the values are false. 412 // Other callbacks shouldn't be called if the values are false.
414 EXPECT_EQ(0, observer.powered_changed_count()); 413 EXPECT_EQ(0, observer.powered_changed_count());
415 EXPECT_EQ(0, observer.discovering_changed_count()); 414 EXPECT_EQ(0, observer.discovering_changed_count());
416 EXPECT_FALSE(adapter_->IsPowered()); 415 EXPECT_FALSE(adapter_->IsPowered());
417 EXPECT_FALSE(adapter_->IsDiscovering()); 416 EXPECT_FALSE(adapter_->IsDiscovering());
418 } 417 }
419 418
420 TEST_F(BluetoothChromeOSTest, BecomeNotPresent) { 419 TEST_F(BluetoothBlueZTest, BecomeNotPresent) {
421 GetAdapter(); 420 GetAdapter();
422 ASSERT_TRUE(adapter_->IsPresent()); 421 ASSERT_TRUE(adapter_->IsPresent());
423 422
424 // Install an observer; expect the AdapterPresentChanged to be called 423 // Install an observer; expect the AdapterPresentChanged to be called
425 // with false, and IsPresent() to return false. 424 // with false, and IsPresent() to return false.
426 TestBluetoothAdapterObserver observer(adapter_); 425 TestBluetoothAdapterObserver observer(adapter_);
427 426
428 fake_bluetooth_adapter_client_->SetVisible(false); 427 fake_bluetooth_adapter_client_->SetVisible(false);
429 428
430 EXPECT_EQ(1, observer.present_changed_count()); 429 EXPECT_EQ(1, observer.present_changed_count());
(...skipping 10 matching lines...) Expand all
441 address.compare( 440 address.compare(
442 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress) == 0); 441 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress) == 0);
443 442
444 // Other callbacks shouldn't be called since the values are false. 443 // Other callbacks shouldn't be called since the values are false.
445 EXPECT_EQ(0, observer.powered_changed_count()); 444 EXPECT_EQ(0, observer.powered_changed_count());
446 EXPECT_EQ(0, observer.discovering_changed_count()); 445 EXPECT_EQ(0, observer.discovering_changed_count());
447 EXPECT_FALSE(adapter_->IsPowered()); 446 EXPECT_FALSE(adapter_->IsPowered());
448 EXPECT_FALSE(adapter_->IsDiscovering()); 447 EXPECT_FALSE(adapter_->IsDiscovering());
449 } 448 }
450 449
451 TEST_F(BluetoothChromeOSTest, SecondAdapter) { 450 TEST_F(BluetoothBlueZTest, SecondAdapter) {
452 GetAdapter(); 451 GetAdapter();
453 ASSERT_TRUE(adapter_->IsPresent()); 452 ASSERT_TRUE(adapter_->IsPresent());
454 453
455 // Install an observer, then add a second adapter. Nothing should change, 454 // Install an observer, then add a second adapter. Nothing should change,
456 // we ignore the second adapter. 455 // we ignore the second adapter.
457 TestBluetoothAdapterObserver observer(adapter_); 456 TestBluetoothAdapterObserver observer(adapter_);
458 457
459 fake_bluetooth_adapter_client_->SetSecondVisible(true); 458 fake_bluetooth_adapter_client_->SetSecondVisible(true);
460 459
461 EXPECT_EQ(0, observer.present_changed_count()); 460 EXPECT_EQ(0, observer.present_changed_count());
(...skipping 30 matching lines...) Expand all
492 observer.Reset(); 491 observer.Reset();
493 492
494 // Removing the second adapter shouldn't set anything either. 493 // Removing the second adapter shouldn't set anything either.
495 fake_bluetooth_adapter_client_->SetSecondVisible(false); 494 fake_bluetooth_adapter_client_->SetSecondVisible(false);
496 495
497 EXPECT_EQ(0, observer.device_removed_count()); 496 EXPECT_EQ(0, observer.device_removed_count());
498 EXPECT_EQ(0, observer.powered_changed_count()); 497 EXPECT_EQ(0, observer.powered_changed_count());
499 EXPECT_EQ(0, observer.discovering_changed_count()); 498 EXPECT_EQ(0, observer.discovering_changed_count());
500 } 499 }
501 500
502 TEST_F(BluetoothChromeOSTest, BecomePowered) { 501 TEST_F(BluetoothBlueZTest, BecomePowered) {
503 GetAdapter(); 502 GetAdapter();
504 ASSERT_FALSE(adapter_->IsPowered()); 503 ASSERT_FALSE(adapter_->IsPowered());
505 504
506 // Install an observer; expect the AdapterPoweredChanged to be called 505 // Install an observer; expect the AdapterPoweredChanged to be called
507 // with true, and IsPowered() to return true. 506 // with true, and IsPowered() to return true.
508 TestBluetoothAdapterObserver observer(adapter_); 507 TestBluetoothAdapterObserver observer(adapter_);
509 508
510 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 509 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
511 EXPECT_EQ(1, callback_count_); 510 EXPECT_EQ(1, callback_count_);
512 EXPECT_EQ(0, error_callback_count_); 511 EXPECT_EQ(0, error_callback_count_);
513 512
514 EXPECT_EQ(1, observer.powered_changed_count()); 513 EXPECT_EQ(1, observer.powered_changed_count());
515 EXPECT_TRUE(observer.last_powered()); 514 EXPECT_TRUE(observer.last_powered());
516 515
517 EXPECT_TRUE(adapter_->IsPowered()); 516 EXPECT_TRUE(adapter_->IsPowered());
518 } 517 }
519 518
520 TEST_F(BluetoothChromeOSTest, BecomeNotPowered) { 519 TEST_F(BluetoothBlueZTest, BecomeNotPowered) {
521 GetAdapter(); 520 GetAdapter();
522 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 521 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
523 EXPECT_EQ(1, callback_count_); 522 EXPECT_EQ(1, callback_count_);
524 EXPECT_EQ(0, error_callback_count_); 523 EXPECT_EQ(0, error_callback_count_);
525 callback_count_ = 0; 524 callback_count_ = 0;
526 525
527 ASSERT_TRUE(adapter_->IsPowered()); 526 ASSERT_TRUE(adapter_->IsPowered());
528 527
529 // Install an observer; expect the AdapterPoweredChanged to be called 528 // Install an observer; expect the AdapterPoweredChanged to be called
530 // with false, and IsPowered() to return false. 529 // with false, and IsPowered() to return false.
531 TestBluetoothAdapterObserver observer(adapter_); 530 TestBluetoothAdapterObserver observer(adapter_);
532 531
533 adapter_->SetPowered(false, GetCallback(), GetErrorCallback()); 532 adapter_->SetPowered(false, GetCallback(), GetErrorCallback());
534 EXPECT_EQ(1, callback_count_); 533 EXPECT_EQ(1, callback_count_);
535 EXPECT_EQ(0, error_callback_count_); 534 EXPECT_EQ(0, error_callback_count_);
536 535
537 EXPECT_EQ(1, observer.powered_changed_count()); 536 EXPECT_EQ(1, observer.powered_changed_count());
538 EXPECT_FALSE(observer.last_powered()); 537 EXPECT_FALSE(observer.last_powered());
539 538
540 EXPECT_FALSE(adapter_->IsPowered()); 539 EXPECT_FALSE(adapter_->IsPowered());
541 } 540 }
542 541
543 TEST_F(BluetoothChromeOSTest, SetPoweredWhenNotPresent) { 542 TEST_F(BluetoothBlueZTest, SetPoweredWhenNotPresent) {
544 GetAdapter(); 543 GetAdapter();
545 ASSERT_TRUE(adapter_->IsPresent()); 544 ASSERT_TRUE(adapter_->IsPresent());
546 545
547 // Install an observer; expect the AdapterPresentChanged to be called 546 // Install an observer; expect the AdapterPresentChanged to be called
548 // with false, and IsPresent() to return false. 547 // with false, and IsPresent() to return false.
549 TestBluetoothAdapterObserver observer(adapter_); 548 TestBluetoothAdapterObserver observer(adapter_);
550 549
551 fake_bluetooth_adapter_client_->SetVisible(false); 550 fake_bluetooth_adapter_client_->SetVisible(false);
552 551
553 EXPECT_EQ(1, observer.present_changed_count()); 552 EXPECT_EQ(1, observer.present_changed_count());
554 EXPECT_FALSE(observer.last_present()); 553 EXPECT_FALSE(observer.last_present());
555 554
556 EXPECT_FALSE(adapter_->IsPresent()); 555 EXPECT_FALSE(adapter_->IsPresent());
557 EXPECT_FALSE(adapter_->IsPowered()); 556 EXPECT_FALSE(adapter_->IsPowered());
558 557
559 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 558 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
560 EXPECT_EQ(0, callback_count_); 559 EXPECT_EQ(0, callback_count_);
561 EXPECT_EQ(1, error_callback_count_); 560 EXPECT_EQ(1, error_callback_count_);
562 561
563 EXPECT_EQ(0, observer.powered_changed_count()); 562 EXPECT_EQ(0, observer.powered_changed_count());
564 EXPECT_FALSE(observer.last_powered()); 563 EXPECT_FALSE(observer.last_powered());
565 564
566 EXPECT_FALSE(adapter_->IsPowered()); 565 EXPECT_FALSE(adapter_->IsPowered());
567 } 566 }
568 567
569 TEST_F(BluetoothChromeOSTest, ChangeAdapterName) { 568 TEST_F(BluetoothBlueZTest, ChangeAdapterName) {
570 GetAdapter(); 569 GetAdapter();
571 570
572 static const std::string new_name(".__."); 571 static const std::string new_name(".__.");
573 572
574 adapter_->SetName(new_name, GetCallback(), GetErrorCallback()); 573 adapter_->SetName(new_name, GetCallback(), GetErrorCallback());
575 EXPECT_EQ(1, callback_count_); 574 EXPECT_EQ(1, callback_count_);
576 EXPECT_EQ(0, error_callback_count_); 575 EXPECT_EQ(0, error_callback_count_);
577 576
578 EXPECT_EQ(new_name, adapter_->GetName()); 577 EXPECT_EQ(new_name, adapter_->GetName());
579 } 578 }
580 579
581 TEST_F(BluetoothChromeOSTest, ChangeAdapterNameWhenNotPresent) { 580 TEST_F(BluetoothBlueZTest, ChangeAdapterNameWhenNotPresent) {
582 GetAdapter(); 581 GetAdapter();
583 ASSERT_TRUE(adapter_->IsPresent()); 582 ASSERT_TRUE(adapter_->IsPresent());
584 583
585 // Install an observer; expect the AdapterPresentChanged to be called 584 // Install an observer; expect the AdapterPresentChanged to be called
586 // with false, and IsPresent() to return false. 585 // with false, and IsPresent() to return false.
587 TestBluetoothAdapterObserver observer(adapter_); 586 TestBluetoothAdapterObserver observer(adapter_);
588 587
589 fake_bluetooth_adapter_client_->SetVisible(false); 588 fake_bluetooth_adapter_client_->SetVisible(false);
590 589
591 EXPECT_EQ(1, observer.present_changed_count()); 590 EXPECT_EQ(1, observer.present_changed_count());
592 EXPECT_FALSE(observer.last_present()); 591 EXPECT_FALSE(observer.last_present());
593 592
594 EXPECT_FALSE(adapter_->IsPresent()); 593 EXPECT_FALSE(adapter_->IsPresent());
595 EXPECT_FALSE(adapter_->IsPowered()); 594 EXPECT_FALSE(adapter_->IsPowered());
596 595
597 adapter_->SetName("^o^", GetCallback(), GetErrorCallback()); 596 adapter_->SetName("^o^", GetCallback(), GetErrorCallback());
598 EXPECT_EQ(0, callback_count_); 597 EXPECT_EQ(0, callback_count_);
599 EXPECT_EQ(1, error_callback_count_); 598 EXPECT_EQ(1, error_callback_count_);
600 599
601 EXPECT_EQ("", adapter_->GetName()); 600 EXPECT_EQ("", adapter_->GetName());
602 } 601 }
603 602
604 TEST_F(BluetoothChromeOSTest, BecomeDiscoverable) { 603 TEST_F(BluetoothBlueZTest, BecomeDiscoverable) {
605 GetAdapter(); 604 GetAdapter();
606 ASSERT_FALSE(adapter_->IsDiscoverable()); 605 ASSERT_FALSE(adapter_->IsDiscoverable());
607 606
608 // Install an observer; expect the AdapterDiscoverableChanged to be called 607 // Install an observer; expect the AdapterDiscoverableChanged to be called
609 // with true, and IsDiscoverable() to return true. 608 // with true, and IsDiscoverable() to return true.
610 TestBluetoothAdapterObserver observer(adapter_); 609 TestBluetoothAdapterObserver observer(adapter_);
611 610
612 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback()); 611 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback());
613 EXPECT_EQ(1, callback_count_); 612 EXPECT_EQ(1, callback_count_);
614 EXPECT_EQ(0, error_callback_count_); 613 EXPECT_EQ(0, error_callback_count_);
615 614
616 EXPECT_EQ(1, observer.discoverable_changed_count()); 615 EXPECT_EQ(1, observer.discoverable_changed_count());
617 616
618 EXPECT_TRUE(adapter_->IsDiscoverable()); 617 EXPECT_TRUE(adapter_->IsDiscoverable());
619 } 618 }
620 619
621 TEST_F(BluetoothChromeOSTest, BecomeNotDiscoverable) { 620 TEST_F(BluetoothBlueZTest, BecomeNotDiscoverable) {
622 GetAdapter(); 621 GetAdapter();
623 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback()); 622 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback());
624 EXPECT_EQ(1, callback_count_); 623 EXPECT_EQ(1, callback_count_);
625 EXPECT_EQ(0, error_callback_count_); 624 EXPECT_EQ(0, error_callback_count_);
626 callback_count_ = 0; 625 callback_count_ = 0;
627 626
628 ASSERT_TRUE(adapter_->IsDiscoverable()); 627 ASSERT_TRUE(adapter_->IsDiscoverable());
629 628
630 // Install an observer; expect the AdapterDiscoverableChanged to be called 629 // Install an observer; expect the AdapterDiscoverableChanged to be called
631 // with false, and IsDiscoverable() to return false. 630 // with false, and IsDiscoverable() to return false.
632 TestBluetoothAdapterObserver observer(adapter_); 631 TestBluetoothAdapterObserver observer(adapter_);
633 632
634 adapter_->SetDiscoverable(false, GetCallback(), GetErrorCallback()); 633 adapter_->SetDiscoverable(false, GetCallback(), GetErrorCallback());
635 EXPECT_EQ(1, callback_count_); 634 EXPECT_EQ(1, callback_count_);
636 EXPECT_EQ(0, error_callback_count_); 635 EXPECT_EQ(0, error_callback_count_);
637 636
638 EXPECT_EQ(1, observer.discoverable_changed_count()); 637 EXPECT_EQ(1, observer.discoverable_changed_count());
639 638
640 EXPECT_FALSE(adapter_->IsDiscoverable()); 639 EXPECT_FALSE(adapter_->IsDiscoverable());
641 } 640 }
642 641
643 TEST_F(BluetoothChromeOSTest, SetDiscoverableWhenNotPresent) { 642 TEST_F(BluetoothBlueZTest, SetDiscoverableWhenNotPresent) {
644 GetAdapter(); 643 GetAdapter();
645 ASSERT_TRUE(adapter_->IsPresent()); 644 ASSERT_TRUE(adapter_->IsPresent());
646 ASSERT_FALSE(adapter_->IsDiscoverable()); 645 ASSERT_FALSE(adapter_->IsDiscoverable());
647 646
648 // Install an observer; expect the AdapterDiscoverableChanged to be called 647 // Install an observer; expect the AdapterDiscoverableChanged to be called
649 // with true, and IsDiscoverable() to return true. 648 // with true, and IsDiscoverable() to return true.
650 TestBluetoothAdapterObserver observer(adapter_); 649 TestBluetoothAdapterObserver observer(adapter_);
651 650
652 fake_bluetooth_adapter_client_->SetVisible(false); 651 fake_bluetooth_adapter_client_->SetVisible(false);
653 652
654 EXPECT_EQ(1, observer.present_changed_count()); 653 EXPECT_EQ(1, observer.present_changed_count());
655 EXPECT_FALSE(observer.last_present()); 654 EXPECT_FALSE(observer.last_present());
656 655
657 EXPECT_FALSE(adapter_->IsPresent()); 656 EXPECT_FALSE(adapter_->IsPresent());
658 EXPECT_FALSE(adapter_->IsDiscoverable()); 657 EXPECT_FALSE(adapter_->IsDiscoverable());
659 658
660 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback()); 659 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback());
661 EXPECT_EQ(0, callback_count_); 660 EXPECT_EQ(0, callback_count_);
662 EXPECT_EQ(1, error_callback_count_); 661 EXPECT_EQ(1, error_callback_count_);
663 662
664 EXPECT_EQ(0, observer.discoverable_changed_count()); 663 EXPECT_EQ(0, observer.discoverable_changed_count());
665 664
666 EXPECT_FALSE(adapter_->IsDiscoverable()); 665 EXPECT_FALSE(adapter_->IsDiscoverable());
667 } 666 }
668 667
669 TEST_F(BluetoothChromeOSTest, StopDiscovery) { 668 TEST_F(BluetoothBlueZTest, StopDiscovery) {
670 GetAdapter(); 669 GetAdapter();
671 670
672 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 671 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
673 adapter_->StartDiscoverySession( 672 adapter_->StartDiscoverySession(
674 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 673 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
675 base::Unretained(this)), 674 base::Unretained(this)),
676 GetErrorCallback()); 675 GetErrorCallback());
677 message_loop_.Run(); 676 message_loop_.Run();
678 EXPECT_EQ(2, callback_count_); 677 EXPECT_EQ(2, callback_count_);
679 EXPECT_EQ(0, error_callback_count_); 678 EXPECT_EQ(0, error_callback_count_);
680 callback_count_ = 0; 679 callback_count_ = 0;
681 680
682 ASSERT_TRUE(adapter_->IsPowered()); 681 ASSERT_TRUE(adapter_->IsPowered());
683 ASSERT_TRUE(adapter_->IsDiscovering()); 682 ASSERT_TRUE(adapter_->IsDiscovering());
684 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 683 ASSERT_EQ((size_t)1, discovery_sessions_.size());
(...skipping 13 matching lines...) Expand all
698 EXPECT_FALSE(observer.last_discovering()); 697 EXPECT_FALSE(observer.last_discovering());
699 698
700 EXPECT_FALSE(adapter_->IsDiscovering()); 699 EXPECT_FALSE(adapter_->IsDiscovering());
701 discovery_sessions_.clear(); 700 discovery_sessions_.clear();
702 callback_count_ = 0; 701 callback_count_ = 0;
703 702
704 // Test that the Stop callbacks get called even if the 703 // Test that the Stop callbacks get called even if the
705 // BluetoothDiscoverySession objects gets deleted 704 // BluetoothDiscoverySession objects gets deleted
706 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 705 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
707 adapter_->StartDiscoverySession( 706 adapter_->StartDiscoverySession(
708 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 707 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
709 base::Unretained(this)), 708 base::Unretained(this)),
710 GetErrorCallback()); 709 GetErrorCallback());
711 message_loop_.Run(); 710 message_loop_.Run();
712 EXPECT_EQ(2, callback_count_); 711 EXPECT_EQ(2, callback_count_);
713 EXPECT_EQ(0, error_callback_count_); 712 EXPECT_EQ(0, error_callback_count_);
714 callback_count_ = 0; 713 callback_count_ = 0;
715 ASSERT_TRUE(adapter_->IsPowered()); 714 ASSERT_TRUE(adapter_->IsPowered());
716 ASSERT_TRUE(adapter_->IsDiscovering()); 715 ASSERT_TRUE(adapter_->IsDiscovering());
717 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 716 ASSERT_EQ((size_t)1, discovery_sessions_.size());
718 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); 717 ASSERT_TRUE(discovery_sessions_[0]->IsActive());
719 718
720 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); 719 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback());
721 discovery_sessions_.clear(); 720 discovery_sessions_.clear();
722 721
723 message_loop_.Run(); 722 message_loop_.Run();
724 EXPECT_EQ(1, callback_count_); 723 EXPECT_EQ(1, callback_count_);
725 EXPECT_EQ(0, error_callback_count_); 724 EXPECT_EQ(0, error_callback_count_);
726 } 725 }
727 726
728 TEST_F(BluetoothChromeOSTest, Discovery) { 727 TEST_F(BluetoothBlueZTest, Discovery) {
729 // Test a simulated discovery session. 728 // Test a simulated discovery session.
730 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 729 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
731 GetAdapter(); 730 GetAdapter();
732 731
733 TestBluetoothAdapterObserver observer(adapter_); 732 TestBluetoothAdapterObserver observer(adapter_);
734 733
735 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 734 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
736 adapter_->StartDiscoverySession( 735 adapter_->StartDiscoverySession(
737 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 736 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
738 base::Unretained(this)), 737 base::Unretained(this)),
739 GetErrorCallback()); 738 GetErrorCallback());
740 message_loop_.Run(); 739 message_loop_.Run();
741 EXPECT_EQ(2, callback_count_); 740 EXPECT_EQ(2, callback_count_);
742 EXPECT_EQ(0, error_callback_count_); 741 EXPECT_EQ(0, error_callback_count_);
743 callback_count_ = 0; 742 callback_count_ = 0;
744 743
745 ASSERT_TRUE(adapter_->IsPowered()); 744 ASSERT_TRUE(adapter_->IsPowered());
746 ASSERT_TRUE(adapter_->IsDiscovering()); 745 ASSERT_TRUE(adapter_->IsDiscovering());
747 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 746 ASSERT_EQ((size_t)1, discovery_sessions_.size());
(...skipping 12 matching lines...) Expand all
760 759
761 // Okay, let's run forward until a device is actually removed... 760 // Okay, let's run forward until a device is actually removed...
762 while (!observer.device_removed_count()) 761 while (!observer.device_removed_count())
763 message_loop_.Run(); 762 message_loop_.Run();
764 763
765 EXPECT_EQ(1, observer.device_removed_count()); 764 EXPECT_EQ(1, observer.device_removed_count());
766 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kVanishingDeviceAddress, 765 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kVanishingDeviceAddress,
767 observer.last_device_address()); 766 observer.last_device_address());
768 } 767 }
769 768
770 TEST_F(BluetoothChromeOSTest, PoweredAndDiscovering) { 769 TEST_F(BluetoothBlueZTest, PoweredAndDiscovering) {
771 GetAdapter(); 770 GetAdapter();
772 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 771 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
773 adapter_->StartDiscoverySession( 772 adapter_->StartDiscoverySession(
774 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 773 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
775 base::Unretained(this)), 774 base::Unretained(this)),
776 GetErrorCallback()); 775 GetErrorCallback());
777 message_loop_.Run(); 776 message_loop_.Run();
778 EXPECT_EQ(2, callback_count_); 777 EXPECT_EQ(2, callback_count_);
779 EXPECT_EQ(0, error_callback_count_); 778 EXPECT_EQ(0, error_callback_count_);
780 callback_count_ = 0; 779 callback_count_ = 0;
781 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 780 ASSERT_EQ((size_t)1, discovery_sessions_.size());
782 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); 781 ASSERT_TRUE(discovery_sessions_[0]->IsActive());
783 782
784 // Stop the timers that the simulation uses 783 // Stop the timers that the simulation uses
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 EXPECT_FALSE(observer.last_powered()); 825 EXPECT_FALSE(observer.last_powered());
827 EXPECT_FALSE(adapter_->IsPowered()); 826 EXPECT_FALSE(adapter_->IsPowered());
828 827
829 EXPECT_EQ(1, observer.discovering_changed_count()); 828 EXPECT_EQ(1, observer.discovering_changed_count());
830 EXPECT_FALSE(observer.last_discovering()); 829 EXPECT_FALSE(observer.last_discovering());
831 EXPECT_FALSE(adapter_->IsDiscovering()); 830 EXPECT_FALSE(adapter_->IsDiscovering());
832 } 831 }
833 832
834 // This unit test asserts that the basic reference counting logic works 833 // This unit test asserts that the basic reference counting logic works
835 // correctly for discovery requests done via the BluetoothAdapter. 834 // correctly for discovery requests done via the BluetoothAdapter.
836 TEST_F(BluetoothChromeOSTest, MultipleDiscoverySessions) { 835 TEST_F(BluetoothBlueZTest, MultipleDiscoverySessions) {
837 GetAdapter(); 836 GetAdapter();
838 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 837 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
839 EXPECT_EQ(1, callback_count_); 838 EXPECT_EQ(1, callback_count_);
840 EXPECT_EQ(0, error_callback_count_); 839 EXPECT_EQ(0, error_callback_count_);
841 EXPECT_TRUE(adapter_->IsPowered()); 840 EXPECT_TRUE(adapter_->IsPowered());
842 callback_count_ = 0; 841 callback_count_ = 0;
843 842
844 TestBluetoothAdapterObserver observer(adapter_); 843 TestBluetoothAdapterObserver observer(adapter_);
845 844
846 EXPECT_EQ(0, observer.discovering_changed_count()); 845 EXPECT_EQ(0, observer.discovering_changed_count());
847 EXPECT_FALSE(observer.last_discovering()); 846 EXPECT_FALSE(observer.last_discovering());
848 EXPECT_FALSE(adapter_->IsDiscovering()); 847 EXPECT_FALSE(adapter_->IsDiscovering());
849 848
850 // Request device discovery 3 times. 849 // Request device discovery 3 times.
851 for (int i = 0; i < 3; i++) { 850 for (int i = 0; i < 3; i++) {
852 adapter_->StartDiscoverySession( 851 adapter_->StartDiscoverySession(
853 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 852 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
854 base::Unretained(this)), 853 base::Unretained(this)),
855 GetErrorCallback()); 854 GetErrorCallback());
856 } 855 }
857 // Run only once, as there should have been one D-Bus call. 856 // Run only once, as there should have been one D-Bus call.
858 message_loop_.Run(); 857 message_loop_.Run();
859 858
860 // The observer should have received the discovering changed event exactly 859 // The observer should have received the discovering changed event exactly
861 // once, the success callback should have been called 3 times and the adapter 860 // once, the success callback should have been called 3 times and the adapter
862 // should be discovering. 861 // should be discovering.
863 EXPECT_EQ(1, observer.discovering_changed_count()); 862 EXPECT_EQ(1, observer.discovering_changed_count());
(...skipping 17 matching lines...) Expand all
881 EXPECT_TRUE(observer.last_discovering()); 880 EXPECT_TRUE(observer.last_discovering());
882 EXPECT_TRUE(adapter_->IsDiscovering()); 881 EXPECT_TRUE(adapter_->IsDiscovering());
883 EXPECT_TRUE(adapter_->IsDiscovering()); 882 EXPECT_TRUE(adapter_->IsDiscovering());
884 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); 883 EXPECT_FALSE(discovery_sessions_[0]->IsActive());
885 EXPECT_FALSE(discovery_sessions_[1]->IsActive()); 884 EXPECT_FALSE(discovery_sessions_[1]->IsActive());
886 EXPECT_TRUE(discovery_sessions_[2]->IsActive()); 885 EXPECT_TRUE(discovery_sessions_[2]->IsActive());
887 886
888 // Request device discovery 3 times. 887 // Request device discovery 3 times.
889 for (int i = 0; i < 3; i++) { 888 for (int i = 0; i < 3; i++) {
890 adapter_->StartDiscoverySession( 889 adapter_->StartDiscoverySession(
891 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 890 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
892 base::Unretained(this)), 891 base::Unretained(this)),
893 GetErrorCallback()); 892 GetErrorCallback());
894 } 893 }
895 894
896 // The observer should have received no additional discovering changed events, 895 // The observer should have received no additional discovering changed events,
897 // the success callback should have been called 3 times and the adapter should 896 // the success callback should have been called 3 times and the adapter should
898 // still be discovering. 897 // still be discovering.
899 EXPECT_EQ(1, observer.discovering_changed_count()); 898 EXPECT_EQ(1, observer.discovering_changed_count());
900 EXPECT_EQ(8, callback_count_); 899 EXPECT_EQ(8, callback_count_);
901 EXPECT_EQ(0, error_callback_count_); 900 EXPECT_EQ(0, error_callback_count_);
(...skipping 28 matching lines...) Expand all
930 EXPECT_EQ(2, observer.discovering_changed_count()); 929 EXPECT_EQ(2, observer.discovering_changed_count());
931 EXPECT_EQ(12, callback_count_); 930 EXPECT_EQ(12, callback_count_);
932 EXPECT_EQ(1, error_callback_count_); 931 EXPECT_EQ(1, error_callback_count_);
933 EXPECT_FALSE(observer.last_discovering()); 932 EXPECT_FALSE(observer.last_discovering());
934 EXPECT_FALSE(adapter_->IsDiscovering()); 933 EXPECT_FALSE(adapter_->IsDiscovering());
935 } 934 }
936 935
937 // This unit test asserts that the reference counting logic works correctly in 936 // This unit test asserts that the reference counting logic works correctly in
938 // the cases when the adapter gets reset and D-Bus calls are made outside of 937 // the cases when the adapter gets reset and D-Bus calls are made outside of
939 // the BluetoothAdapter. 938 // the BluetoothAdapter.
940 TEST_F(BluetoothChromeOSTest, 939 TEST_F(BluetoothBlueZTest, UnexpectedChangesDuringMultipleDiscoverySessions) {
941 UnexpectedChangesDuringMultipleDiscoverySessions) {
942 GetAdapter(); 940 GetAdapter();
943 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 941 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
944 EXPECT_EQ(1, callback_count_); 942 EXPECT_EQ(1, callback_count_);
945 EXPECT_EQ(0, error_callback_count_); 943 EXPECT_EQ(0, error_callback_count_);
946 EXPECT_TRUE(adapter_->IsPowered()); 944 EXPECT_TRUE(adapter_->IsPowered());
947 callback_count_ = 0; 945 callback_count_ = 0;
948 946
949 TestBluetoothAdapterObserver observer(adapter_); 947 TestBluetoothAdapterObserver observer(adapter_);
950 948
951 EXPECT_EQ(0, observer.discovering_changed_count()); 949 EXPECT_EQ(0, observer.discovering_changed_count());
952 EXPECT_FALSE(observer.last_discovering()); 950 EXPECT_FALSE(observer.last_discovering());
953 EXPECT_FALSE(adapter_->IsDiscovering()); 951 EXPECT_FALSE(adapter_->IsDiscovering());
954 952
955 // Request device discovery 3 times. 953 // Request device discovery 3 times.
956 for (int i = 0; i < 3; i++) { 954 for (int i = 0; i < 3; i++) {
957 adapter_->StartDiscoverySession( 955 adapter_->StartDiscoverySession(
958 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 956 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
959 base::Unretained(this)), 957 base::Unretained(this)),
960 GetErrorCallback()); 958 GetErrorCallback());
961 } 959 }
962 // Run only once, as there should have been one D-Bus call. 960 // Run only once, as there should have been one D-Bus call.
963 message_loop_.Run(); 961 message_loop_.Run();
964 962
965 // The observer should have received the discovering changed event exactly 963 // The observer should have received the discovering changed event exactly
966 // once, the success callback should have been called 3 times and the adapter 964 // once, the success callback should have been called 3 times and the adapter
967 // should be discovering. 965 // should be discovering.
968 EXPECT_EQ(1, observer.discovering_changed_count()); 966 EXPECT_EQ(1, observer.discovering_changed_count());
(...skipping 16 matching lines...) Expand all
985 // Stop device discovery behind the adapter. The adapter and the observer 983 // Stop device discovery behind the adapter. The adapter and the observer
986 // should be notified of the change and the reference count should be reset. 984 // should be notified of the change and the reference count should be reset.
987 // Even though bluez::FakeBluetoothAdapterClient does its own reference 985 // Even though bluez::FakeBluetoothAdapterClient does its own reference
988 // counting and 986 // counting and
989 // we called 3 BluetoothAdapter::StartDiscoverySession 3 times, the 987 // we called 3 BluetoothAdapter::StartDiscoverySession 3 times, the
990 // bluez::FakeBluetoothAdapterClient's count should be only 1 and a single 988 // bluez::FakeBluetoothAdapterClient's count should be only 1 and a single
991 // call to 989 // call to
992 // bluez::FakeBluetoothAdapterClient::StopDiscovery should work. 990 // bluez::FakeBluetoothAdapterClient::StopDiscovery should work.
993 fake_bluetooth_adapter_client_->StopDiscovery( 991 fake_bluetooth_adapter_client_->StopDiscovery(
994 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 992 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
995 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, 993 GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
996 base::Unretained(this))); 994 base::Unretained(this)));
997 message_loop_.Run(); 995 message_loop_.Run();
998 EXPECT_EQ(2, observer.discovering_changed_count()); 996 EXPECT_EQ(2, observer.discovering_changed_count());
999 EXPECT_EQ(4, callback_count_); 997 EXPECT_EQ(4, callback_count_);
1000 EXPECT_EQ(0, error_callback_count_); 998 EXPECT_EQ(0, error_callback_count_);
1001 EXPECT_FALSE(observer.last_discovering()); 999 EXPECT_FALSE(observer.last_discovering());
1002 EXPECT_FALSE(adapter_->IsDiscovering()); 1000 EXPECT_FALSE(adapter_->IsDiscovering());
1003 1001
1004 // All discovery session instances should have been updated. 1002 // All discovery session instances should have been updated.
1005 for (int i = 0; i < 3; i++) 1003 for (int i = 0; i < 3; i++)
1006 EXPECT_FALSE(discovery_sessions_[i]->IsActive()); 1004 EXPECT_FALSE(discovery_sessions_[i]->IsActive());
1007 discovery_sessions_.clear(); 1005 discovery_sessions_.clear();
1008 1006
1009 // It should be possible to successfully start discovery. 1007 // It should be possible to successfully start discovery.
1010 for (int i = 0; i < 2; i++) { 1008 for (int i = 0; i < 2; i++) {
1011 adapter_->StartDiscoverySession( 1009 adapter_->StartDiscoverySession(
1012 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1010 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1013 base::Unretained(this)), 1011 base::Unretained(this)),
1014 GetErrorCallback()); 1012 GetErrorCallback());
1015 } 1013 }
1016 // Run only once, as there should have been one D-Bus call. 1014 // Run only once, as there should have been one D-Bus call.
1017 message_loop_.Run(); 1015 message_loop_.Run();
1018 EXPECT_EQ(3, observer.discovering_changed_count()); 1016 EXPECT_EQ(3, observer.discovering_changed_count());
1019 EXPECT_EQ(6, callback_count_); 1017 EXPECT_EQ(6, callback_count_);
1020 EXPECT_EQ(0, error_callback_count_); 1018 EXPECT_EQ(0, error_callback_count_);
1021 EXPECT_TRUE(observer.last_discovering()); 1019 EXPECT_TRUE(observer.last_discovering());
1022 EXPECT_TRUE(adapter_->IsDiscovering()); 1020 EXPECT_TRUE(adapter_->IsDiscovering());
(...skipping 27 matching lines...) Expand all
1050 EXPECT_EQ(0, error_callback_count_); 1048 EXPECT_EQ(0, error_callback_count_);
1051 EXPECT_TRUE(observer.last_discovering()); 1049 EXPECT_TRUE(observer.last_discovering());
1052 EXPECT_TRUE(adapter_->IsDiscovering()); 1050 EXPECT_TRUE(adapter_->IsDiscovering());
1053 1051
1054 // Start and stop discovery. At this point, bluez::FakeBluetoothAdapterClient 1052 // Start and stop discovery. At this point, bluez::FakeBluetoothAdapterClient
1055 // has 1053 // has
1056 // a reference count that is equal to 1. Pretend that this was done by an 1054 // a reference count that is equal to 1. Pretend that this was done by an
1057 // application other than us. Starting and stopping discovery will succeed 1055 // application other than us. Starting and stopping discovery will succeed
1058 // but it won't cause the discovery state to change. 1056 // but it won't cause the discovery state to change.
1059 adapter_->StartDiscoverySession( 1057 adapter_->StartDiscoverySession(
1060 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1058 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1061 base::Unretained(this)), 1059 base::Unretained(this)),
1062 GetErrorCallback()); 1060 GetErrorCallback());
1063 message_loop_.Run(); // Run the loop, as there should have been a D-Bus call. 1061 message_loop_.Run(); // Run the loop, as there should have been a D-Bus call.
1064 EXPECT_EQ(5, observer.discovering_changed_count()); 1062 EXPECT_EQ(5, observer.discovering_changed_count());
1065 EXPECT_EQ(7, callback_count_); 1063 EXPECT_EQ(7, callback_count_);
1066 EXPECT_EQ(0, error_callback_count_); 1064 EXPECT_EQ(0, error_callback_count_);
1067 EXPECT_TRUE(observer.last_discovering()); 1065 EXPECT_TRUE(observer.last_discovering());
1068 EXPECT_TRUE(adapter_->IsDiscovering()); 1066 EXPECT_TRUE(adapter_->IsDiscovering());
1069 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 1067 ASSERT_EQ((size_t)1, discovery_sessions_.size());
1070 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); 1068 EXPECT_TRUE(discovery_sessions_[0]->IsActive());
1071 1069
1072 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); 1070 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback());
1073 message_loop_.Run(); // Run the loop, as there should have been a D-Bus call. 1071 message_loop_.Run(); // Run the loop, as there should have been a D-Bus call.
1074 EXPECT_EQ(5, observer.discovering_changed_count()); 1072 EXPECT_EQ(5, observer.discovering_changed_count());
1075 EXPECT_EQ(8, callback_count_); 1073 EXPECT_EQ(8, callback_count_);
1076 EXPECT_EQ(0, error_callback_count_); 1074 EXPECT_EQ(0, error_callback_count_);
1077 EXPECT_TRUE(observer.last_discovering()); 1075 EXPECT_TRUE(observer.last_discovering());
1078 EXPECT_TRUE(adapter_->IsDiscovering()); 1076 EXPECT_TRUE(adapter_->IsDiscovering());
1079 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); 1077 EXPECT_FALSE(discovery_sessions_[0]->IsActive());
1080 discovery_sessions_.clear(); 1078 discovery_sessions_.clear();
1081 1079
1082 // Start discovery again. 1080 // Start discovery again.
1083 adapter_->StartDiscoverySession( 1081 adapter_->StartDiscoverySession(
1084 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1082 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1085 base::Unretained(this)), 1083 base::Unretained(this)),
1086 GetErrorCallback()); 1084 GetErrorCallback());
1087 message_loop_.Run(); // Run the loop, as there should have been a D-Bus call. 1085 message_loop_.Run(); // Run the loop, as there should have been a D-Bus call.
1088 EXPECT_EQ(5, observer.discovering_changed_count()); 1086 EXPECT_EQ(5, observer.discovering_changed_count());
1089 EXPECT_EQ(9, callback_count_); 1087 EXPECT_EQ(9, callback_count_);
1090 EXPECT_EQ(0, error_callback_count_); 1088 EXPECT_EQ(0, error_callback_count_);
1091 EXPECT_TRUE(observer.last_discovering()); 1089 EXPECT_TRUE(observer.last_discovering());
1092 EXPECT_TRUE(adapter_->IsDiscovering()); 1090 EXPECT_TRUE(adapter_->IsDiscovering());
1093 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 1091 ASSERT_EQ((size_t)1, discovery_sessions_.size());
1094 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); 1092 EXPECT_TRUE(discovery_sessions_[0]->IsActive());
1095 1093
1096 // Stop discovery via D-Bus. The fake client's reference count will drop but 1094 // Stop discovery via D-Bus. The fake client's reference count will drop but
1097 // the discovery state won't change since our BluetoothAdapter also just 1095 // the discovery state won't change since our BluetoothAdapter also just
1098 // requested it via D-Bus. 1096 // requested it via D-Bus.
1099 fake_bluetooth_adapter_client_->StopDiscovery( 1097 fake_bluetooth_adapter_client_->StopDiscovery(
1100 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 1098 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
1101 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, 1099 GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
1102 base::Unretained(this))); 1100 base::Unretained(this)));
1103 message_loop_.Run(); 1101 message_loop_.Run();
1104 EXPECT_EQ(5, observer.discovering_changed_count()); 1102 EXPECT_EQ(5, observer.discovering_changed_count());
1105 EXPECT_EQ(10, callback_count_); 1103 EXPECT_EQ(10, callback_count_);
1106 EXPECT_EQ(0, error_callback_count_); 1104 EXPECT_EQ(0, error_callback_count_);
1107 EXPECT_TRUE(observer.last_discovering()); 1105 EXPECT_TRUE(observer.last_discovering());
1108 EXPECT_TRUE(adapter_->IsDiscovering()); 1106 EXPECT_TRUE(adapter_->IsDiscovering());
1109 1107
1110 // Now end the discovery session. This should change the adapter's discovery 1108 // Now end the discovery session. This should change the adapter's discovery
1111 // state. 1109 // state.
1112 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); 1110 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback());
1113 message_loop_.Run(); 1111 message_loop_.Run();
1114 EXPECT_EQ(6, observer.discovering_changed_count()); 1112 EXPECT_EQ(6, observer.discovering_changed_count());
1115 EXPECT_EQ(11, callback_count_); 1113 EXPECT_EQ(11, callback_count_);
1116 EXPECT_EQ(0, error_callback_count_); 1114 EXPECT_EQ(0, error_callback_count_);
1117 EXPECT_FALSE(observer.last_discovering()); 1115 EXPECT_FALSE(observer.last_discovering());
1118 EXPECT_FALSE(adapter_->IsDiscovering()); 1116 EXPECT_FALSE(adapter_->IsDiscovering());
1119 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); 1117 EXPECT_FALSE(discovery_sessions_[0]->IsActive());
1120 } 1118 }
1121 1119
1122 TEST_F(BluetoothChromeOSTest, InvalidatedDiscoverySessions) { 1120 TEST_F(BluetoothBlueZTest, InvalidatedDiscoverySessions) {
1123 GetAdapter(); 1121 GetAdapter();
1124 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 1122 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
1125 EXPECT_EQ(1, callback_count_); 1123 EXPECT_EQ(1, callback_count_);
1126 EXPECT_EQ(0, error_callback_count_); 1124 EXPECT_EQ(0, error_callback_count_);
1127 EXPECT_TRUE(adapter_->IsPowered()); 1125 EXPECT_TRUE(adapter_->IsPowered());
1128 callback_count_ = 0; 1126 callback_count_ = 0;
1129 1127
1130 TestBluetoothAdapterObserver observer(adapter_); 1128 TestBluetoothAdapterObserver observer(adapter_);
1131 1129
1132 EXPECT_EQ(0, observer.discovering_changed_count()); 1130 EXPECT_EQ(0, observer.discovering_changed_count());
1133 EXPECT_FALSE(observer.last_discovering()); 1131 EXPECT_FALSE(observer.last_discovering());
1134 EXPECT_FALSE(adapter_->IsDiscovering()); 1132 EXPECT_FALSE(adapter_->IsDiscovering());
1135 1133
1136 // Request device discovery 3 times. 1134 // Request device discovery 3 times.
1137 for (int i = 0; i < 3; i++) { 1135 for (int i = 0; i < 3; i++) {
1138 adapter_->StartDiscoverySession( 1136 adapter_->StartDiscoverySession(
1139 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1137 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1140 base::Unretained(this)), 1138 base::Unretained(this)),
1141 GetErrorCallback()); 1139 GetErrorCallback());
1142 } 1140 }
1143 // Run only once, as there should have been one D-Bus call. 1141 // Run only once, as there should have been one D-Bus call.
1144 message_loop_.Run(); 1142 message_loop_.Run();
1145 1143
1146 // The observer should have received the discovering changed event exactly 1144 // The observer should have received the discovering changed event exactly
1147 // once, the success callback should have been called 3 times and the adapter 1145 // once, the success callback should have been called 3 times and the adapter
1148 // should be discovering. 1146 // should be discovering.
1149 EXPECT_EQ(1, observer.discovering_changed_count()); 1147 EXPECT_EQ(1, observer.discovering_changed_count());
(...skipping 19 matching lines...) Expand all
1169 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 1167 ASSERT_EQ((size_t)1, discovery_sessions_.size());
1170 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); 1168 EXPECT_TRUE(discovery_sessions_[0]->IsActive());
1171 EXPECT_TRUE(adapter_->IsDiscovering()); 1169 EXPECT_TRUE(adapter_->IsDiscovering());
1172 1170
1173 // Stop device discovery behind the adapter. The one active discovery session 1171 // Stop device discovery behind the adapter. The one active discovery session
1174 // should become inactive, but more importantly, we shouldn't run into any 1172 // should become inactive, but more importantly, we shouldn't run into any
1175 // memory errors as the sessions that we explicitly deleted should get 1173 // memory errors as the sessions that we explicitly deleted should get
1176 // cleaned up. 1174 // cleaned up.
1177 fake_bluetooth_adapter_client_->StopDiscovery( 1175 fake_bluetooth_adapter_client_->StopDiscovery(
1178 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 1176 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
1179 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, 1177 GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
1180 base::Unretained(this))); 1178 base::Unretained(this)));
1181 message_loop_.Run(); 1179 message_loop_.Run();
1182 EXPECT_EQ(2, observer.discovering_changed_count()); 1180 EXPECT_EQ(2, observer.discovering_changed_count());
1183 EXPECT_EQ(4, callback_count_); 1181 EXPECT_EQ(4, callback_count_);
1184 EXPECT_EQ(0, error_callback_count_); 1182 EXPECT_EQ(0, error_callback_count_);
1185 EXPECT_FALSE(observer.last_discovering()); 1183 EXPECT_FALSE(observer.last_discovering());
1186 EXPECT_FALSE(adapter_->IsDiscovering()); 1184 EXPECT_FALSE(adapter_->IsDiscovering());
1187 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); 1185 EXPECT_FALSE(discovery_sessions_[0]->IsActive());
1188 } 1186 }
1189 1187
1190 TEST_F(BluetoothChromeOSTest, QueuedDiscoveryRequests) { 1188 TEST_F(BluetoothBlueZTest, QueuedDiscoveryRequests) {
1191 GetAdapter(); 1189 GetAdapter();
1192 1190
1193 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 1191 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
1194 EXPECT_EQ(1, callback_count_); 1192 EXPECT_EQ(1, callback_count_);
1195 EXPECT_EQ(0, error_callback_count_); 1193 EXPECT_EQ(0, error_callback_count_);
1196 EXPECT_TRUE(adapter_->IsPowered()); 1194 EXPECT_TRUE(adapter_->IsPowered());
1197 callback_count_ = 0; 1195 callback_count_ = 0;
1198 1196
1199 TestBluetoothAdapterObserver observer(adapter_); 1197 TestBluetoothAdapterObserver observer(adapter_);
1200 1198
1201 EXPECT_EQ(0, observer.discovering_changed_count()); 1199 EXPECT_EQ(0, observer.discovering_changed_count());
1202 EXPECT_FALSE(observer.last_discovering()); 1200 EXPECT_FALSE(observer.last_discovering());
1203 EXPECT_FALSE(adapter_->IsDiscovering()); 1201 EXPECT_FALSE(adapter_->IsDiscovering());
1204 1202
1205 // Request to start discovery. The call should be pending. 1203 // Request to start discovery. The call should be pending.
1206 adapter_->StartDiscoverySession( 1204 adapter_->StartDiscoverySession(
1207 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1205 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1208 base::Unretained(this)), 1206 base::Unretained(this)),
1209 GetErrorCallback()); 1207 GetErrorCallback());
1210 EXPECT_EQ(0, callback_count_); 1208 EXPECT_EQ(0, callback_count_);
1211 1209
1212 fake_bluetooth_device_client_->EndDiscoverySimulation( 1210 fake_bluetooth_device_client_->EndDiscoverySimulation(
1213 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath)); 1211 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath));
1214 1212
1215 // The underlying adapter has started discovery, but our call hasn't returned 1213 // The underlying adapter has started discovery, but our call hasn't returned
1216 // yet. 1214 // yet.
1217 EXPECT_EQ(1, observer.discovering_changed_count()); 1215 EXPECT_EQ(1, observer.discovering_changed_count());
1218 EXPECT_TRUE(observer.last_discovering()); 1216 EXPECT_TRUE(observer.last_discovering());
1219 EXPECT_TRUE(adapter_->IsDiscovering()); 1217 EXPECT_TRUE(adapter_->IsDiscovering());
1220 EXPECT_TRUE(discovery_sessions_.empty()); 1218 EXPECT_TRUE(discovery_sessions_.empty());
1221 1219
1222 // Request to start discovery twice. These should get queued and there should 1220 // Request to start discovery twice. These should get queued and there should
1223 // be no change in state. 1221 // be no change in state.
1224 for (int i = 0; i < 2; i++) { 1222 for (int i = 0; i < 2; i++) {
1225 adapter_->StartDiscoverySession( 1223 adapter_->StartDiscoverySession(
1226 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1224 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1227 base::Unretained(this)), 1225 base::Unretained(this)),
1228 GetErrorCallback()); 1226 GetErrorCallback());
1229 } 1227 }
1230 EXPECT_EQ(0, callback_count_); 1228 EXPECT_EQ(0, callback_count_);
1231 EXPECT_EQ(0, error_callback_count_); 1229 EXPECT_EQ(0, error_callback_count_);
1232 EXPECT_EQ(1, observer.discovering_changed_count()); 1230 EXPECT_EQ(1, observer.discovering_changed_count());
1233 EXPECT_TRUE(observer.last_discovering()); 1231 EXPECT_TRUE(observer.last_discovering());
1234 EXPECT_TRUE(adapter_->IsDiscovering()); 1232 EXPECT_TRUE(adapter_->IsDiscovering());
1235 EXPECT_TRUE(discovery_sessions_.empty()); 1233 EXPECT_TRUE(discovery_sessions_.empty());
1236 1234
(...skipping 25 matching lines...) Expand all
1262 discovery_sessions_[2]->Stop(GetCallback(), GetErrorCallback()); 1260 discovery_sessions_[2]->Stop(GetCallback(), GetErrorCallback());
1263 EXPECT_EQ(5, callback_count_); 1261 EXPECT_EQ(5, callback_count_);
1264 EXPECT_EQ(1, error_callback_count_); 1262 EXPECT_EQ(1, error_callback_count_);
1265 EXPECT_EQ(2, observer.discovering_changed_count()); 1263 EXPECT_EQ(2, observer.discovering_changed_count());
1266 EXPECT_FALSE(observer.last_discovering()); 1264 EXPECT_FALSE(observer.last_discovering());
1267 EXPECT_FALSE(adapter_->IsDiscovering()); 1265 EXPECT_FALSE(adapter_->IsDiscovering());
1268 EXPECT_TRUE(discovery_sessions_[2]->IsActive()); 1266 EXPECT_TRUE(discovery_sessions_[2]->IsActive());
1269 1267
1270 // Request to start should get queued. 1268 // Request to start should get queued.
1271 adapter_->StartDiscoverySession( 1269 adapter_->StartDiscoverySession(
1272 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1270 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1273 base::Unretained(this)), 1271 base::Unretained(this)),
1274 GetErrorCallback()); 1272 GetErrorCallback());
1275 EXPECT_EQ(5, callback_count_); 1273 EXPECT_EQ(5, callback_count_);
1276 EXPECT_EQ(1, error_callback_count_); 1274 EXPECT_EQ(1, error_callback_count_);
1277 EXPECT_EQ(2, observer.discovering_changed_count()); 1275 EXPECT_EQ(2, observer.discovering_changed_count());
1278 EXPECT_FALSE(observer.last_discovering()); 1276 EXPECT_FALSE(observer.last_discovering());
1279 EXPECT_FALSE(adapter_->IsDiscovering()); 1277 EXPECT_FALSE(adapter_->IsDiscovering());
1280 ASSERT_EQ((size_t)3, discovery_sessions_.size()); 1278 ASSERT_EQ((size_t)3, discovery_sessions_.size());
1281 1279
1282 // Run the pending request. 1280 // Run the pending request.
(...skipping 11 matching lines...) Expand all
1294 message_loop_.Run(); 1292 message_loop_.Run();
1295 EXPECT_EQ(7, callback_count_); 1293 EXPECT_EQ(7, callback_count_);
1296 EXPECT_EQ(1, error_callback_count_); 1294 EXPECT_EQ(1, error_callback_count_);
1297 EXPECT_EQ(3, observer.discovering_changed_count()); 1295 EXPECT_EQ(3, observer.discovering_changed_count());
1298 EXPECT_TRUE(observer.last_discovering()); 1296 EXPECT_TRUE(observer.last_discovering());
1299 EXPECT_TRUE(adapter_->IsDiscovering()); 1297 EXPECT_TRUE(adapter_->IsDiscovering());
1300 ASSERT_EQ((size_t)4, discovery_sessions_.size()); 1298 ASSERT_EQ((size_t)4, discovery_sessions_.size());
1301 EXPECT_TRUE(discovery_sessions_[3]->IsActive()); 1299 EXPECT_TRUE(discovery_sessions_[3]->IsActive());
1302 } 1300 }
1303 1301
1304 TEST_F(BluetoothChromeOSTest, StartDiscoverySession) { 1302 TEST_F(BluetoothBlueZTest, StartDiscoverySession) {
1305 GetAdapter(); 1303 GetAdapter();
1306 1304
1307 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 1305 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
1308 EXPECT_EQ(1, callback_count_); 1306 EXPECT_EQ(1, callback_count_);
1309 EXPECT_EQ(0, error_callback_count_); 1307 EXPECT_EQ(0, error_callback_count_);
1310 EXPECT_TRUE(adapter_->IsPowered()); 1308 EXPECT_TRUE(adapter_->IsPowered());
1311 callback_count_ = 0; 1309 callback_count_ = 0;
1312 1310
1313 TestBluetoothAdapterObserver observer(adapter_); 1311 TestBluetoothAdapterObserver observer(adapter_);
1314 1312
1315 EXPECT_EQ(0, observer.discovering_changed_count()); 1313 EXPECT_EQ(0, observer.discovering_changed_count());
1316 EXPECT_FALSE(observer.last_discovering()); 1314 EXPECT_FALSE(observer.last_discovering());
1317 EXPECT_FALSE(adapter_->IsDiscovering()); 1315 EXPECT_FALSE(adapter_->IsDiscovering());
1318 EXPECT_TRUE(discovery_sessions_.empty()); 1316 EXPECT_TRUE(discovery_sessions_.empty());
1319 1317
1320 // Request a new discovery session. 1318 // Request a new discovery session.
1321 adapter_->StartDiscoverySession( 1319 adapter_->StartDiscoverySession(
1322 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1320 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1323 base::Unretained(this)), 1321 base::Unretained(this)),
1324 GetErrorCallback()); 1322 GetErrorCallback());
1325 message_loop_.Run(); 1323 message_loop_.Run();
1326 EXPECT_EQ(1, observer.discovering_changed_count()); 1324 EXPECT_EQ(1, observer.discovering_changed_count());
1327 EXPECT_EQ(1, callback_count_); 1325 EXPECT_EQ(1, callback_count_);
1328 EXPECT_EQ(0, error_callback_count_); 1326 EXPECT_EQ(0, error_callback_count_);
1329 EXPECT_TRUE(observer.last_discovering()); 1327 EXPECT_TRUE(observer.last_discovering());
1330 EXPECT_TRUE(adapter_->IsDiscovering()); 1328 EXPECT_TRUE(adapter_->IsDiscovering());
1331 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 1329 ASSERT_EQ((size_t)1, discovery_sessions_.size());
1332 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); 1330 EXPECT_TRUE(discovery_sessions_[0]->IsActive());
1333 1331
1334 // Start another session. A new one should be returned in the callback, which 1332 // Start another session. A new one should be returned in the callback, which
1335 // in turn will destroy the previous session. Adapter should still be 1333 // in turn will destroy the previous session. Adapter should still be
1336 // discovering and the reference count should be 1. 1334 // discovering and the reference count should be 1.
1337 adapter_->StartDiscoverySession( 1335 adapter_->StartDiscoverySession(
1338 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1336 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1339 base::Unretained(this)), 1337 base::Unretained(this)),
1340 GetErrorCallback()); 1338 GetErrorCallback());
1341 message_loop_.Run(); 1339 message_loop_.Run();
1342 EXPECT_EQ(1, observer.discovering_changed_count()); 1340 EXPECT_EQ(1, observer.discovering_changed_count());
1343 EXPECT_EQ(2, callback_count_); 1341 EXPECT_EQ(2, callback_count_);
1344 EXPECT_EQ(0, error_callback_count_); 1342 EXPECT_EQ(0, error_callback_count_);
1345 EXPECT_TRUE(observer.last_discovering()); 1343 EXPECT_TRUE(observer.last_discovering());
1346 EXPECT_TRUE(adapter_->IsDiscovering()); 1344 EXPECT_TRUE(adapter_->IsDiscovering());
1347 ASSERT_EQ((size_t)2, discovery_sessions_.size()); 1345 ASSERT_EQ((size_t)2, discovery_sessions_.size());
1348 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); 1346 EXPECT_TRUE(discovery_sessions_[0]->IsActive());
1349 1347
1350 // Request a new session. 1348 // Request a new session.
1351 adapter_->StartDiscoverySession( 1349 adapter_->StartDiscoverySession(
1352 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1350 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1353 base::Unretained(this)), 1351 base::Unretained(this)),
1354 GetErrorCallback()); 1352 GetErrorCallback());
1355 message_loop_.Run(); 1353 message_loop_.Run();
1356 EXPECT_EQ(1, observer.discovering_changed_count()); 1354 EXPECT_EQ(1, observer.discovering_changed_count());
1357 EXPECT_EQ(3, callback_count_); 1355 EXPECT_EQ(3, callback_count_);
1358 EXPECT_EQ(0, error_callback_count_); 1356 EXPECT_EQ(0, error_callback_count_);
1359 EXPECT_TRUE(observer.last_discovering()); 1357 EXPECT_TRUE(observer.last_discovering());
1360 EXPECT_TRUE(adapter_->IsDiscovering()); 1358 EXPECT_TRUE(adapter_->IsDiscovering());
1361 ASSERT_EQ((size_t)3, discovery_sessions_.size()); 1359 ASSERT_EQ((size_t)3, discovery_sessions_.size());
1362 EXPECT_TRUE(discovery_sessions_[1]->IsActive()); 1360 EXPECT_TRUE(discovery_sessions_[1]->IsActive());
(...skipping 17 matching lines...) Expand all
1380 while (observer.last_discovering()) 1378 while (observer.last_discovering())
1381 message_loop_.RunUntilIdle(); 1379 message_loop_.RunUntilIdle();
1382 1380
1383 EXPECT_EQ(2, observer.discovering_changed_count()); 1381 EXPECT_EQ(2, observer.discovering_changed_count());
1384 EXPECT_EQ(4, callback_count_); 1382 EXPECT_EQ(4, callback_count_);
1385 EXPECT_EQ(0, error_callback_count_); 1383 EXPECT_EQ(0, error_callback_count_);
1386 EXPECT_FALSE(observer.last_discovering()); 1384 EXPECT_FALSE(observer.last_discovering());
1387 EXPECT_FALSE(adapter_->IsDiscovering()); 1385 EXPECT_FALSE(adapter_->IsDiscovering());
1388 } 1386 }
1389 1387
1390 TEST_F(BluetoothChromeOSTest, SetDiscoveryFilterBeforeStartDiscovery) { 1388 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterBeforeStartDiscovery) {
1391 // Test a simulated discovery session. 1389 // Test a simulated discovery session.
1392 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 1390 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
1393 GetAdapter(); 1391 GetAdapter();
1394 1392
1395 TestBluetoothAdapterObserver observer(adapter_); 1393 TestBluetoothAdapterObserver observer(adapter_);
1396 1394
1397 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( 1395 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter(
1398 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 1396 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE);
1399 df->SetRSSI(-60); 1397 df->SetRSSI(-60);
1400 df->AddUUID(BluetoothUUID("1000")); 1398 df->AddUUID(BluetoothUUID("1000"));
1401 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df); 1399 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df);
1402 1400
1403 adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, 1401 adapter_->SetPowered(
1404 base::Unretained(this)), 1402 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1405 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1403 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1406 base::Unretained(this)));
1407 adapter_->StartDiscoverySessionWithFilter( 1404 adapter_->StartDiscoverySessionWithFilter(
1408 discovery_filter.Pass(), 1405 discovery_filter.Pass(),
1409 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1406 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1410 base::Unretained(this)), 1407 base::Unretained(this)),
1411 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1408 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1412 base::Unretained(this)));
1413 message_loop_.Run(); 1409 message_loop_.Run();
1414 EXPECT_EQ(2, callback_count_); 1410 EXPECT_EQ(2, callback_count_);
1415 EXPECT_EQ(0, error_callback_count_); 1411 EXPECT_EQ(0, error_callback_count_);
1416 callback_count_ = 0; 1412 callback_count_ = 0;
1417 1413
1418 ASSERT_TRUE(adapter_->IsPowered()); 1414 ASSERT_TRUE(adapter_->IsPowered());
1419 ASSERT_TRUE(adapter_->IsDiscovering()); 1415 ASSERT_TRUE(adapter_->IsDiscovering());
1420 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 1416 ASSERT_EQ((size_t)1, discovery_sessions_.size());
1421 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); 1417 ASSERT_TRUE(discovery_sessions_[0]->IsActive());
1422 ASSERT_TRUE(df->Equals(*discovery_sessions_[0]->GetDiscoveryFilter())); 1418 ASSERT_TRUE(df->Equals(*discovery_sessions_[0]->GetDiscoveryFilter()));
1423 1419
1424 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1420 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1425 EXPECT_NE(nullptr, filter); 1421 EXPECT_NE(nullptr, filter);
1426 EXPECT_EQ("le", *filter->transport); 1422 EXPECT_EQ("le", *filter->transport);
1427 EXPECT_EQ(-60, *filter->rssi); 1423 EXPECT_EQ(-60, *filter->rssi);
1428 EXPECT_EQ(nullptr, filter->pathloss.get()); 1424 EXPECT_EQ(nullptr, filter->pathloss.get());
1429 std::vector<std::string> uuids = *filter->uuids; 1425 std::vector<std::string> uuids = *filter->uuids;
1430 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); 1426 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000"));
1431 1427
1432 discovery_sessions_[0]->Stop( 1428 discovery_sessions_[0]->Stop(
1433 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), 1429 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1434 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1430 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1435 base::Unretained(this)));
1436 1431
1437 message_loop_.Run(); 1432 message_loop_.Run();
1438 1433
1439 EXPECT_EQ(1, callback_count_); 1434 EXPECT_EQ(1, callback_count_);
1440 EXPECT_EQ(0, error_callback_count_); 1435 EXPECT_EQ(0, error_callback_count_);
1441 1436
1442 ASSERT_TRUE(adapter_->IsPowered()); 1437 ASSERT_TRUE(adapter_->IsPowered());
1443 ASSERT_FALSE(adapter_->IsDiscovering()); 1438 ASSERT_FALSE(adapter_->IsDiscovering());
1444 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 1439 ASSERT_EQ((size_t)1, discovery_sessions_.size());
1445 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); 1440 ASSERT_FALSE(discovery_sessions_[0]->IsActive());
1446 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), 1441 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(),
1447 (BluetoothDiscoveryFilter*)nullptr); 1442 (BluetoothDiscoveryFilter*)nullptr);
1448 1443
1449 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1444 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1450 EXPECT_EQ(nullptr, filter); 1445 EXPECT_EQ(nullptr, filter);
1451 } 1446 }
1452 1447
1453 TEST_F(BluetoothChromeOSTest, SetDiscoveryFilterBeforeStartDiscoveryFail) { 1448 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterBeforeStartDiscoveryFail) {
1454 // Test a simulated discovery session. 1449 // Test a simulated discovery session.
1455 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 1450 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
1456 GetAdapter(); 1451 GetAdapter();
1457 1452
1458 TestBluetoothAdapterObserver observer(adapter_); 1453 TestBluetoothAdapterObserver observer(adapter_);
1459 1454
1460 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( 1455 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter(
1461 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 1456 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE);
1462 df->SetRSSI(-60); 1457 df->SetRSSI(-60);
1463 df->AddUUID(BluetoothUUID("1000")); 1458 df->AddUUID(BluetoothUUID("1000"));
1464 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df); 1459 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df);
1465 1460
1466 adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, 1461 adapter_->SetPowered(
1467 base::Unretained(this)), 1462 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1468 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1463 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1469 base::Unretained(this)));
1470 EXPECT_EQ(1, callback_count_); 1464 EXPECT_EQ(1, callback_count_);
1471 callback_count_ = 0; 1465 callback_count_ = 0;
1472 1466
1473 fake_bluetooth_adapter_client_->MakeSetDiscoveryFilterFail(); 1467 fake_bluetooth_adapter_client_->MakeSetDiscoveryFilterFail();
1474 1468
1475 adapter_->StartDiscoverySessionWithFilter( 1469 adapter_->StartDiscoverySessionWithFilter(
1476 discovery_filter.Pass(), 1470 discovery_filter.Pass(),
1477 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1471 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1478 base::Unretained(this)), 1472 base::Unretained(this)),
1479 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1473 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1480 base::Unretained(this)));
1481 1474
1482 message_loop_.Run(); 1475 message_loop_.Run();
1483 1476
1484 EXPECT_EQ(1, error_callback_count_); 1477 EXPECT_EQ(1, error_callback_count_);
1485 error_callback_count_ = 0; 1478 error_callback_count_ = 0;
1486 1479
1487 ASSERT_TRUE(adapter_->IsPowered()); 1480 ASSERT_TRUE(adapter_->IsPowered());
1488 ASSERT_FALSE(adapter_->IsDiscovering()); 1481 ASSERT_FALSE(adapter_->IsDiscovering());
1489 ASSERT_EQ((size_t)0, discovery_sessions_.size()); 1482 ASSERT_EQ((size_t)0, discovery_sessions_.size());
1490 1483
1491 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1484 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1492 EXPECT_EQ(nullptr, filter); 1485 EXPECT_EQ(nullptr, filter);
1493 } 1486 }
1494 1487
1495 // This test queues two requests to StartDiscovery with pre set filter. This 1488 // This test queues two requests to StartDiscovery with pre set filter. This
1496 // should result in SetDiscoveryFilter, then StartDiscovery, and SetDiscovery 1489 // should result in SetDiscoveryFilter, then StartDiscovery, and SetDiscovery
1497 // DBus calls 1490 // DBus calls
1498 TEST_F(BluetoothChromeOSTest, QueuedSetDiscoveryFilterBeforeStartDiscovery) { 1491 TEST_F(BluetoothBlueZTest, QueuedSetDiscoveryFilterBeforeStartDiscovery) {
1499 // Test a simulated discovery session. 1492 // Test a simulated discovery session.
1500 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 1493 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
1501 GetAdapter(); 1494 GetAdapter();
1502 1495
1503 TestBluetoothAdapterObserver observer(adapter_); 1496 TestBluetoothAdapterObserver observer(adapter_);
1504 1497
1505 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( 1498 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter(
1506 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 1499 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE);
1507 df->SetRSSI(-60); 1500 df->SetRSSI(-60);
1508 df->AddUUID(BluetoothUUID("1000")); 1501 df->AddUUID(BluetoothUUID("1000"));
1509 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df); 1502 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df);
1510 1503
1511 BluetoothDiscoveryFilter* df2 = new BluetoothDiscoveryFilter( 1504 BluetoothDiscoveryFilter* df2 = new BluetoothDiscoveryFilter(
1512 BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC); 1505 BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC);
1513 df2->SetRSSI(-65); 1506 df2->SetRSSI(-65);
1514 df2->AddUUID(BluetoothUUID("1002")); 1507 df2->AddUUID(BluetoothUUID("1002"));
1515 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter2(df2); 1508 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter2(df2);
1516 1509
1517 adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, 1510 adapter_->SetPowered(
1518 base::Unretained(this)), 1511 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1519 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1512 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1520 base::Unretained(this)));
1521 1513
1522 EXPECT_EQ(1, callback_count_); 1514 EXPECT_EQ(1, callback_count_);
1523 EXPECT_EQ(0, error_callback_count_); 1515 EXPECT_EQ(0, error_callback_count_);
1524 callback_count_ = 0; 1516 callback_count_ = 0;
1525 1517
1526 // Queue two requests to start discovery session with filter. 1518 // Queue two requests to start discovery session with filter.
1527 adapter_->StartDiscoverySessionWithFilter( 1519 adapter_->StartDiscoverySessionWithFilter(
1528 discovery_filter.Pass(), 1520 discovery_filter.Pass(),
1529 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1521 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1530 base::Unretained(this)), 1522 base::Unretained(this)),
1531 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1523 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1532 base::Unretained(this)));
1533 1524
1534 adapter_->StartDiscoverySessionWithFilter( 1525 adapter_->StartDiscoverySessionWithFilter(
1535 discovery_filter2.Pass(), 1526 discovery_filter2.Pass(),
1536 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1527 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1537 base::Unretained(this)), 1528 base::Unretained(this)),
1538 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1529 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1539 base::Unretained(this)));
1540 1530
1541 // Run requests, on DBus level there should be call SetDiscoveryFilter, then 1531 // Run requests, on DBus level there should be call SetDiscoveryFilter, then
1542 // StartDiscovery, then SetDiscoveryFilter again. 1532 // StartDiscovery, then SetDiscoveryFilter again.
1543 message_loop_.Run(); 1533 message_loop_.Run();
1544 message_loop_.Run(); 1534 message_loop_.Run();
1545 1535
1546 EXPECT_EQ(2, callback_count_); 1536 EXPECT_EQ(2, callback_count_);
1547 EXPECT_EQ(0, error_callback_count_); 1537 EXPECT_EQ(0, error_callback_count_);
1548 callback_count_ = 0; 1538 callback_count_ = 0;
1549 1539
1550 ASSERT_TRUE(adapter_->IsPowered()); 1540 ASSERT_TRUE(adapter_->IsPowered());
1551 ASSERT_TRUE(adapter_->IsDiscovering()); 1541 ASSERT_TRUE(adapter_->IsDiscovering());
1552 ASSERT_EQ((size_t)2, discovery_sessions_.size()); 1542 ASSERT_EQ((size_t)2, discovery_sessions_.size());
1553 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); 1543 ASSERT_TRUE(discovery_sessions_[0]->IsActive());
1554 ASSERT_TRUE(df->Equals(*discovery_sessions_[0]->GetDiscoveryFilter())); 1544 ASSERT_TRUE(df->Equals(*discovery_sessions_[0]->GetDiscoveryFilter()));
1555 ASSERT_TRUE(discovery_sessions_[1]->IsActive()); 1545 ASSERT_TRUE(discovery_sessions_[1]->IsActive());
1556 ASSERT_TRUE(df2->Equals(*discovery_sessions_[1]->GetDiscoveryFilter())); 1546 ASSERT_TRUE(df2->Equals(*discovery_sessions_[1]->GetDiscoveryFilter()));
1557 1547
1558 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1548 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1559 EXPECT_NE(nullptr, filter); 1549 EXPECT_NE(nullptr, filter);
1560 EXPECT_EQ("auto", *filter->transport); 1550 EXPECT_EQ("auto", *filter->transport);
1561 EXPECT_EQ(-65, *filter->rssi); 1551 EXPECT_EQ(-65, *filter->rssi);
1562 EXPECT_EQ(nullptr, filter->pathloss.get()); 1552 EXPECT_EQ(nullptr, filter->pathloss.get());
1563 auto uuids = *filter->uuids; 1553 auto uuids = *filter->uuids;
1564 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); 1554 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000"));
1565 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1002")); 1555 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1002"));
1566 1556
1567 discovery_sessions_[0]->Stop( 1557 discovery_sessions_[0]->Stop(
1568 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), 1558 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1569 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1559 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1570 base::Unretained(this)));
1571 1560
1572 discovery_sessions_[1]->Stop( 1561 discovery_sessions_[1]->Stop(
1573 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), 1562 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1574 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1563 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1575 base::Unretained(this)));
1576 1564
1577 message_loop_.Run(); 1565 message_loop_.Run();
1578 1566
1579 EXPECT_EQ(2, callback_count_); 1567 EXPECT_EQ(2, callback_count_);
1580 EXPECT_EQ(0, error_callback_count_); 1568 EXPECT_EQ(0, error_callback_count_);
1581 1569
1582 ASSERT_TRUE(adapter_->IsPowered()); 1570 ASSERT_TRUE(adapter_->IsPowered());
1583 ASSERT_FALSE(adapter_->IsDiscovering()); 1571 ASSERT_FALSE(adapter_->IsDiscovering());
1584 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); 1572 ASSERT_FALSE(discovery_sessions_[0]->IsActive());
1585 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), 1573 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(),
1586 (BluetoothDiscoveryFilter*)nullptr); 1574 (BluetoothDiscoveryFilter*)nullptr);
1587 ASSERT_FALSE(discovery_sessions_[1]->IsActive()); 1575 ASSERT_FALSE(discovery_sessions_[1]->IsActive());
1588 ASSERT_EQ(discovery_sessions_[1]->GetDiscoveryFilter(), 1576 ASSERT_EQ(discovery_sessions_[1]->GetDiscoveryFilter(),
1589 (BluetoothDiscoveryFilter*)nullptr); 1577 (BluetoothDiscoveryFilter*)nullptr);
1590 1578
1591 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1579 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1592 EXPECT_EQ(nullptr, filter); 1580 EXPECT_EQ(nullptr, filter);
1593 } 1581 }
1594 1582
1595 // Call StartFilteredDiscovery twice (2nd time while 1st call is still pending). 1583 // Call StartFilteredDiscovery twice (2nd time while 1st call is still pending).
1596 // Make the first SetDiscoveryFilter fail and the second one succeed. It should 1584 // Make the first SetDiscoveryFilter fail and the second one succeed. It should
1597 // end up with one active discovery session. 1585 // end up with one active discovery session.
1598 TEST_F(BluetoothChromeOSTest, 1586 TEST_F(BluetoothBlueZTest, QueuedSetDiscoveryFilterBeforeStartDiscoveryFail) {
1599 QueuedSetDiscoveryFilterBeforeStartDiscoveryFail) {
1600 // Test a simulated discovery session. 1587 // Test a simulated discovery session.
1601 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 1588 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
1602 GetAdapter(); 1589 GetAdapter();
1603 1590
1604 TestBluetoothAdapterObserver observer(adapter_); 1591 TestBluetoothAdapterObserver observer(adapter_);
1605 1592
1606 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( 1593 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter(
1607 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 1594 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE);
1608 df->SetRSSI(-60); 1595 df->SetRSSI(-60);
1609 df->AddUUID(BluetoothUUID("1000")); 1596 df->AddUUID(BluetoothUUID("1000"));
1610 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df); 1597 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df);
1611 1598
1612 BluetoothDiscoveryFilter* df2 = new BluetoothDiscoveryFilter( 1599 BluetoothDiscoveryFilter* df2 = new BluetoothDiscoveryFilter(
1613 BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC); 1600 BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC);
1614 df2->SetRSSI(-65); 1601 df2->SetRSSI(-65);
1615 df2->AddUUID(BluetoothUUID("1002")); 1602 df2->AddUUID(BluetoothUUID("1002"));
1616 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter2(df2); 1603 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter2(df2);
1617 1604
1618 adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, 1605 adapter_->SetPowered(
1619 base::Unretained(this)), 1606 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1620 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1607 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1621 base::Unretained(this)));
1622 1608
1623 EXPECT_EQ(1, callback_count_); 1609 EXPECT_EQ(1, callback_count_);
1624 EXPECT_EQ(0, error_callback_count_); 1610 EXPECT_EQ(0, error_callback_count_);
1625 callback_count_ = 0; 1611 callback_count_ = 0;
1626 1612
1627 fake_bluetooth_adapter_client_->MakeSetDiscoveryFilterFail(); 1613 fake_bluetooth_adapter_client_->MakeSetDiscoveryFilterFail();
1628 1614
1629 // Queue two requests to start discovery session with filter. 1615 // Queue two requests to start discovery session with filter.
1630 adapter_->StartDiscoverySessionWithFilter( 1616 adapter_->StartDiscoverySessionWithFilter(
1631 discovery_filter.Pass(), 1617 discovery_filter.Pass(),
1632 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1618 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1633 base::Unretained(this)), 1619 base::Unretained(this)),
1634 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1620 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1635 base::Unretained(this)));
1636 1621
1637 adapter_->StartDiscoverySessionWithFilter( 1622 adapter_->StartDiscoverySessionWithFilter(
1638 discovery_filter2.Pass(), 1623 discovery_filter2.Pass(),
1639 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1624 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1640 base::Unretained(this)), 1625 base::Unretained(this)),
1641 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1626 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1642 base::Unretained(this)));
1643 1627
1644 message_loop_.Run(); 1628 message_loop_.Run();
1645 1629
1646 // First request to SetDiscoveryFilter should fail, resulting in no session 1630 // First request to SetDiscoveryFilter should fail, resulting in no session
1647 // being created. 1631 // being created.
1648 EXPECT_EQ(0, callback_count_); 1632 EXPECT_EQ(0, callback_count_);
1649 EXPECT_EQ(1, error_callback_count_); 1633 EXPECT_EQ(1, error_callback_count_);
1650 error_callback_count_ = 0; 1634 error_callback_count_ = 0;
1651 1635
1652 ASSERT_TRUE(adapter_->IsPowered()); 1636 ASSERT_TRUE(adapter_->IsPowered());
(...skipping 14 matching lines...) Expand all
1667 1651
1668 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1652 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1669 EXPECT_NE(nullptr, filter); 1653 EXPECT_NE(nullptr, filter);
1670 EXPECT_EQ("bredr", *filter->transport); 1654 EXPECT_EQ("bredr", *filter->transport);
1671 EXPECT_EQ(-65, *filter->rssi); 1655 EXPECT_EQ(-65, *filter->rssi);
1672 EXPECT_EQ(nullptr, filter->pathloss.get()); 1656 EXPECT_EQ(nullptr, filter->pathloss.get());
1673 auto uuids = *filter->uuids; 1657 auto uuids = *filter->uuids;
1674 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1002")); 1658 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1002"));
1675 1659
1676 discovery_sessions_[0]->Stop( 1660 discovery_sessions_[0]->Stop(
1677 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), 1661 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1678 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1662 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1679 base::Unretained(this)));
1680 1663
1681 message_loop_.Run(); 1664 message_loop_.Run();
1682 1665
1683 EXPECT_EQ(1, callback_count_); 1666 EXPECT_EQ(1, callback_count_);
1684 EXPECT_EQ(0, error_callback_count_); 1667 EXPECT_EQ(0, error_callback_count_);
1685 1668
1686 ASSERT_TRUE(adapter_->IsPowered()); 1669 ASSERT_TRUE(adapter_->IsPowered());
1687 ASSERT_FALSE(adapter_->IsDiscovering()); 1670 ASSERT_FALSE(adapter_->IsDiscovering());
1688 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); 1671 ASSERT_FALSE(discovery_sessions_[0]->IsActive());
1689 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), 1672 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(),
1690 (BluetoothDiscoveryFilter*)nullptr); 1673 (BluetoothDiscoveryFilter*)nullptr);
1691 1674
1692 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1675 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1693 EXPECT_EQ(nullptr, filter); 1676 EXPECT_EQ(nullptr, filter);
1694 } 1677 }
1695 1678
1696 TEST_F(BluetoothChromeOSTest, SetDiscoveryFilterAfterStartDiscovery) { 1679 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterAfterStartDiscovery) {
1697 // Test a simulated discovery session. 1680 // Test a simulated discovery session.
1698 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 1681 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
1699 GetAdapter(); 1682 GetAdapter();
1700 1683
1701 TestBluetoothAdapterObserver observer(adapter_); 1684 TestBluetoothAdapterObserver observer(adapter_);
1702 1685
1703 adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, 1686 adapter_->SetPowered(
1704 base::Unretained(this)), 1687 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1705 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1688 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1706 base::Unretained(this)));
1707 adapter_->StartDiscoverySession( 1689 adapter_->StartDiscoverySession(
1708 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1690 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1709 base::Unretained(this)), 1691 base::Unretained(this)),
1710 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1692 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1711 base::Unretained(this)));
1712 message_loop_.Run(); 1693 message_loop_.Run();
1713 EXPECT_EQ(2, callback_count_); 1694 EXPECT_EQ(2, callback_count_);
1714 EXPECT_EQ(0, error_callback_count_); 1695 EXPECT_EQ(0, error_callback_count_);
1715 callback_count_ = 0; 1696 callback_count_ = 0;
1716 1697
1717 ASSERT_TRUE(adapter_->IsPowered()); 1698 ASSERT_TRUE(adapter_->IsPowered());
1718 ASSERT_TRUE(adapter_->IsDiscovering()); 1699 ASSERT_TRUE(adapter_->IsDiscovering());
1719 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 1700 ASSERT_EQ((size_t)1, discovery_sessions_.size());
1720 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); 1701 ASSERT_TRUE(discovery_sessions_[0]->IsActive());
1721 EXPECT_EQ(1, observer.discovering_changed_count()); 1702 EXPECT_EQ(1, observer.discovering_changed_count());
1722 observer.Reset(); 1703 observer.Reset();
1723 1704
1724 auto null_instance = scoped_ptr<BluetoothDiscoveryFilter>(); 1705 auto null_instance = scoped_ptr<BluetoothDiscoveryFilter>();
1725 null_instance.reset(); 1706 null_instance.reset();
1726 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), null_instance.get()); 1707 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), null_instance.get());
1727 1708
1728 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1709 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1729 EXPECT_EQ(nullptr, filter); 1710 EXPECT_EQ(nullptr, filter);
1730 1711
1731 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( 1712 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter(
1732 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 1713 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE);
1733 df->SetRSSI(-60); 1714 df->SetRSSI(-60);
1734 df->AddUUID(BluetoothUUID("1000")); 1715 df->AddUUID(BluetoothUUID("1000"));
1735 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df); 1716 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df);
1736 1717
1737 discovery_sessions_[0]->SetDiscoveryFilter( 1718 discovery_sessions_[0]->SetDiscoveryFilter(
1738 discovery_filter.Pass(), 1719 discovery_filter.Pass(),
1739 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), 1720 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1740 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1721 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1741 base::Unretained(this)));
1742 1722
1743 message_loop_.Run(); 1723 message_loop_.Run();
1744 EXPECT_EQ(1, callback_count_); 1724 EXPECT_EQ(1, callback_count_);
1745 EXPECT_EQ(0, error_callback_count_); 1725 EXPECT_EQ(0, error_callback_count_);
1746 callback_count_ = 0; 1726 callback_count_ = 0;
1747 1727
1748 ASSERT_TRUE(df->Equals(*discovery_sessions_[0]->GetDiscoveryFilter())); 1728 ASSERT_TRUE(df->Equals(*discovery_sessions_[0]->GetDiscoveryFilter()));
1749 1729
1750 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1730 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1751 EXPECT_NE(nullptr, filter); 1731 EXPECT_NE(nullptr, filter);
1752 EXPECT_EQ("le", *filter->transport); 1732 EXPECT_EQ("le", *filter->transport);
1753 EXPECT_EQ(-60, *filter->rssi); 1733 EXPECT_EQ(-60, *filter->rssi);
1754 EXPECT_EQ(nullptr, filter->pathloss.get()); 1734 EXPECT_EQ(nullptr, filter->pathloss.get());
1755 std::vector<std::string> uuids = *filter->uuids; 1735 std::vector<std::string> uuids = *filter->uuids;
1756 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); 1736 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000"));
1757 1737
1758 discovery_sessions_[0]->Stop( 1738 discovery_sessions_[0]->Stop(
1759 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), 1739 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1760 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1740 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1761 base::Unretained(this)));
1762 1741
1763 message_loop_.Run(); 1742 message_loop_.Run();
1764 1743
1765 EXPECT_EQ(1, callback_count_); 1744 EXPECT_EQ(1, callback_count_);
1766 EXPECT_EQ(0, error_callback_count_); 1745 EXPECT_EQ(0, error_callback_count_);
1767 1746
1768 ASSERT_TRUE(adapter_->IsPowered()); 1747 ASSERT_TRUE(adapter_->IsPowered());
1769 ASSERT_FALSE(adapter_->IsDiscovering()); 1748 ASSERT_FALSE(adapter_->IsDiscovering());
1770 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 1749 ASSERT_EQ((size_t)1, discovery_sessions_.size());
1771 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); 1750 ASSERT_FALSE(discovery_sessions_[0]->IsActive());
1772 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(), 1751 ASSERT_EQ(discovery_sessions_[0]->GetDiscoveryFilter(),
1773 (BluetoothDiscoveryFilter*)nullptr); 1752 (BluetoothDiscoveryFilter*)nullptr);
1774 1753
1775 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1754 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1776 EXPECT_EQ(nullptr, filter); 1755 EXPECT_EQ(nullptr, filter);
1777 } 1756 }
1778 1757
1779 // This unit test asserts that the basic reference counting, and filter merging 1758 // This unit test asserts that the basic reference counting, and filter merging
1780 // works correctly for discovery requests done via the BluetoothAdapter. 1759 // works correctly for discovery requests done via the BluetoothAdapter.
1781 TEST_F(BluetoothChromeOSTest, SetDiscoveryFilterBeforeStartDiscoveryMultiple) { 1760 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterBeforeStartDiscoveryMultiple) {
1782 GetAdapter(); 1761 GetAdapter();
1783 adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, 1762 adapter_->SetPowered(
1784 base::Unretained(this)), 1763 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1785 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1764 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1786 base::Unretained(this)));
1787 EXPECT_EQ(1, callback_count_); 1765 EXPECT_EQ(1, callback_count_);
1788 EXPECT_EQ(0, error_callback_count_); 1766 EXPECT_EQ(0, error_callback_count_);
1789 EXPECT_TRUE(adapter_->IsPowered()); 1767 EXPECT_TRUE(adapter_->IsPowered());
1790 callback_count_ = 0; 1768 callback_count_ = 0;
1791 1769
1792 TestBluetoothAdapterObserver observer(adapter_); 1770 TestBluetoothAdapterObserver observer(adapter_);
1793 1771
1794 // Request device discovery with pre-set filter 3 times. 1772 // Request device discovery with pre-set filter 3 times.
1795 for (int i = 0; i < 3; i++) { 1773 for (int i = 0; i < 3; i++) {
1796 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter; 1774 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter;
(...skipping 14 matching lines...) Expand all
1811 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( 1789 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter(
1812 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 1790 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE);
1813 df->SetRSSI(-65); 1791 df->SetRSSI(-65);
1814 df->AddUUID(BluetoothUUID("1020")); 1792 df->AddUUID(BluetoothUUID("1020"));
1815 df->AddUUID(BluetoothUUID("1003")); 1793 df->AddUUID(BluetoothUUID("1003"));
1816 discovery_filter.reset(df); 1794 discovery_filter.reset(df);
1817 } 1795 }
1818 1796
1819 adapter_->StartDiscoverySessionWithFilter( 1797 adapter_->StartDiscoverySessionWithFilter(
1820 discovery_filter.Pass(), 1798 discovery_filter.Pass(),
1821 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1799 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1822 base::Unretained(this)), 1800 base::Unretained(this)),
1823 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1801 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1824 base::Unretained(this)));
1825 1802
1826 message_loop_.Run(); 1803 message_loop_.Run();
1827 1804
1828 if (i == 0) { 1805 if (i == 0) {
1829 EXPECT_EQ(1, observer.discovering_changed_count()); 1806 EXPECT_EQ(1, observer.discovering_changed_count());
1830 observer.Reset(); 1807 observer.Reset();
1831 1808
1832 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1809 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1833 EXPECT_EQ("le", *filter->transport); 1810 EXPECT_EQ("le", *filter->transport);
1834 EXPECT_EQ(-85, *filter->rssi); 1811 EXPECT_EQ(-85, *filter->rssi);
(...skipping 26 matching lines...) Expand all
1861 // be discovering. 1838 // be discovering.
1862 EXPECT_EQ(3, callback_count_); 1839 EXPECT_EQ(3, callback_count_);
1863 EXPECT_EQ(0, error_callback_count_); 1840 EXPECT_EQ(0, error_callback_count_);
1864 EXPECT_TRUE(adapter_->IsDiscovering()); 1841 EXPECT_TRUE(adapter_->IsDiscovering());
1865 ASSERT_EQ((size_t)3, discovery_sessions_.size()); 1842 ASSERT_EQ((size_t)3, discovery_sessions_.size());
1866 1843
1867 callback_count_ = 0; 1844 callback_count_ = 0;
1868 // Request to stop discovery twice. 1845 // Request to stop discovery twice.
1869 for (int i = 0; i < 2; i++) { 1846 for (int i = 0; i < 2; i++) {
1870 discovery_sessions_[i]->Stop( 1847 discovery_sessions_[i]->Stop(
1871 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), 1848 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1872 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1849 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1873 base::Unretained(this)));
1874 message_loop_.Run(); 1850 message_loop_.Run();
1875 1851
1876 if (i == 0) { 1852 if (i == 0) {
1877 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1853 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1878 EXPECT_EQ("le", *filter->transport); 1854 EXPECT_EQ("le", *filter->transport);
1879 EXPECT_EQ(-65, *filter->rssi); 1855 EXPECT_EQ(-65, *filter->rssi);
1880 EXPECT_EQ(nullptr, filter->pathloss.get()); 1856 EXPECT_EQ(nullptr, filter->pathloss.get());
1881 std::vector<std::string> uuids = *filter->uuids; 1857 std::vector<std::string> uuids = *filter->uuids;
1882 EXPECT_EQ(3UL, uuids.size()); 1858 EXPECT_EQ(3UL, uuids.size());
1883 EXPECT_EQ(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); 1859 EXPECT_EQ(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000"));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1937 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( 1913 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter(
1938 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 1914 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE);
1939 df->SetRSSI(-65); 1915 df->SetRSSI(-65);
1940 df->AddUUID(BluetoothUUID("1020")); 1916 df->AddUUID(BluetoothUUID("1020"));
1941 df->AddUUID(BluetoothUUID("1003")); 1917 df->AddUUID(BluetoothUUID("1003"));
1942 discovery_filter.reset(df); 1918 discovery_filter.reset(df);
1943 } 1919 }
1944 1920
1945 adapter_->StartDiscoverySessionWithFilter( 1921 adapter_->StartDiscoverySessionWithFilter(
1946 discovery_filter.Pass(), 1922 discovery_filter.Pass(),
1947 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 1923 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
1948 base::Unretained(this)), 1924 base::Unretained(this)),
1949 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1925 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1950 base::Unretained(this)));
1951 1926
1952 // each result in 1 requests. 1927 // each result in 1 requests.
1953 message_loop_.Run(); 1928 message_loop_.Run();
1954 1929
1955 if (i == 0) { 1930 if (i == 0) {
1956 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1931 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
1957 EXPECT_EQ("le", *filter->transport); 1932 EXPECT_EQ("le", *filter->transport);
1958 EXPECT_EQ(-85, *filter->rssi); 1933 EXPECT_EQ(-85, *filter->rssi);
1959 EXPECT_EQ(nullptr, filter->pathloss.get()); 1934 EXPECT_EQ(nullptr, filter->pathloss.get());
1960 std::vector<std::string> uuids = *filter->uuids; 1935 std::vector<std::string> uuids = *filter->uuids;
(...skipping 17 matching lines...) Expand all
1978 // still be discovering. 1953 // still be discovering.
1979 EXPECT_EQ(3, callback_count_); 1954 EXPECT_EQ(3, callback_count_);
1980 EXPECT_EQ(0, error_callback_count_); 1955 EXPECT_EQ(0, error_callback_count_);
1981 EXPECT_TRUE(adapter_->IsDiscovering()); 1956 EXPECT_TRUE(adapter_->IsDiscovering());
1982 ASSERT_EQ((size_t)6, discovery_sessions_.size()); 1957 ASSERT_EQ((size_t)6, discovery_sessions_.size());
1983 1958
1984 callback_count_ = 0; 1959 callback_count_ = 0;
1985 // Request to stop discovery 4 times. 1960 // Request to stop discovery 4 times.
1986 for (int i = 2; i < 6; i++) { 1961 for (int i = 2; i < 6; i++) {
1987 discovery_sessions_[i]->Stop( 1962 discovery_sessions_[i]->Stop(
1988 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), 1963 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
1989 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1964 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
1990 base::Unretained(this)));
1991 1965
1992 // filter no 2 is same as filter no 5, so removing it shouldn't cause any 1966 // filter no 2 is same as filter no 5, so removing it shouldn't cause any
1993 // filter update 1967 // filter update
1994 if (i != 2 && i != 5) 1968 if (i != 2 && i != 5)
1995 message_loop_.Run(); 1969 message_loop_.Run();
1996 } 1970 }
1997 // Run only once, as there should have been one D-Bus call. 1971 // Run only once, as there should have been one D-Bus call.
1998 message_loop_.Run(); 1972 message_loop_.Run();
1999 1973
2000 // The success callback should have been called 4 times and the adapter should 1974 // The success callback should have been called 4 times and the adapter should
2001 // no longer be discovering. 1975 // no longer be discovering.
2002 EXPECT_EQ(4, callback_count_); 1976 EXPECT_EQ(4, callback_count_);
2003 EXPECT_EQ(0, error_callback_count_); 1977 EXPECT_EQ(0, error_callback_count_);
2004 EXPECT_FALSE(adapter_->IsDiscovering()); 1978 EXPECT_FALSE(adapter_->IsDiscovering());
2005 EXPECT_EQ(1, observer.discovering_changed_count()); 1979 EXPECT_EQ(1, observer.discovering_changed_count());
2006 1980
2007 // All discovery sessions should be inactive. 1981 // All discovery sessions should be inactive.
2008 for (int i = 0; i < 6; i++) 1982 for (int i = 0; i < 6; i++)
2009 EXPECT_FALSE(discovery_sessions_[i]->IsActive()); 1983 EXPECT_FALSE(discovery_sessions_[i]->IsActive());
2010 1984
2011 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 1985 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
2012 EXPECT_EQ(nullptr, filter); 1986 EXPECT_EQ(nullptr, filter);
2013 } 1987 }
2014 1988
2015 // This unit test asserts that filter merging logic works correctly for filtered 1989 // This unit test asserts that filter merging logic works correctly for filtered
2016 // discovery requests done via the BluetoothAdapter. 1990 // discovery requests done via the BluetoothAdapter.
2017 TEST_F(BluetoothChromeOSTest, SetDiscoveryFilterMergingTest) { 1991 TEST_F(BluetoothBlueZTest, SetDiscoveryFilterMergingTest) {
2018 GetAdapter(); 1992 GetAdapter();
2019 adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, 1993 adapter_->SetPowered(
2020 base::Unretained(this)), 1994 true, base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
2021 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 1995 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
2022 base::Unretained(this)));
2023 1996
2024 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter( 1997 BluetoothDiscoveryFilter* df = new BluetoothDiscoveryFilter(
2025 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 1998 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE);
2026 df->SetRSSI(-15); 1999 df->SetRSSI(-15);
2027 df->AddUUID(BluetoothUUID("1000")); 2000 df->AddUUID(BluetoothUUID("1000"));
2028 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df); 2001 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(df);
2029 2002
2030 adapter_->StartDiscoverySessionWithFilter( 2003 adapter_->StartDiscoverySessionWithFilter(
2031 discovery_filter.Pass(), 2004 discovery_filter.Pass(),
2032 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 2005 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
2033 base::Unretained(this)), 2006 base::Unretained(this)),
2034 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 2007 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
2035 base::Unretained(this)));
2036 2008
2037 message_loop_.Run(); 2009 message_loop_.Run();
2038 2010
2039 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 2011 auto filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
2040 EXPECT_EQ("le", *filter->transport); 2012 EXPECT_EQ("le", *filter->transport);
2041 EXPECT_EQ(-15, *filter->rssi); 2013 EXPECT_EQ(-15, *filter->rssi);
2042 EXPECT_EQ(nullptr, filter->pathloss.get()); 2014 EXPECT_EQ(nullptr, filter->pathloss.get());
2043 std::vector<std::string> uuids = *filter->uuids; 2015 std::vector<std::string> uuids = *filter->uuids;
2044 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); 2016 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000"));
2045 2017
2046 df = new BluetoothDiscoveryFilter( 2018 df = new BluetoothDiscoveryFilter(
2047 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE); 2019 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE);
2048 df->SetRSSI(-60); 2020 df->SetRSSI(-60);
2049 df->AddUUID(BluetoothUUID("1020")); 2021 df->AddUUID(BluetoothUUID("1020"));
2050 df->AddUUID(BluetoothUUID("1001")); 2022 df->AddUUID(BluetoothUUID("1001"));
2051 discovery_filter = scoped_ptr<BluetoothDiscoveryFilter>(df); 2023 discovery_filter = scoped_ptr<BluetoothDiscoveryFilter>(df);
2052 2024
2053 adapter_->StartDiscoverySessionWithFilter( 2025 adapter_->StartDiscoverySessionWithFilter(
2054 discovery_filter.Pass(), 2026 discovery_filter.Pass(),
2055 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 2027 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
2056 base::Unretained(this)), 2028 base::Unretained(this)),
2057 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 2029 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
2058 base::Unretained(this)));
2059 2030
2060 message_loop_.Run(); 2031 message_loop_.Run();
2061 2032
2062 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 2033 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
2063 EXPECT_EQ("le", *filter->transport); 2034 EXPECT_EQ("le", *filter->transport);
2064 EXPECT_EQ(-60, *filter->rssi); 2035 EXPECT_EQ(-60, *filter->rssi);
2065 EXPECT_EQ(nullptr, filter->pathloss.get()); 2036 EXPECT_EQ(nullptr, filter->pathloss.get());
2066 uuids = *filter->uuids; 2037 uuids = *filter->uuids;
2067 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); 2038 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000"));
2068 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1001")); 2039 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1001"));
2069 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1020")); 2040 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1020"));
2070 2041
2071 BluetoothDiscoveryFilter* df3 = new BluetoothDiscoveryFilter( 2042 BluetoothDiscoveryFilter* df3 = new BluetoothDiscoveryFilter(
2072 BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC); 2043 BluetoothDiscoveryFilter::Transport::TRANSPORT_CLASSIC);
2073 df3->SetRSSI(-65); 2044 df3->SetRSSI(-65);
2074 df3->AddUUID(BluetoothUUID("1020")); 2045 df3->AddUUID(BluetoothUUID("1020"));
2075 df3->AddUUID(BluetoothUUID("1003")); 2046 df3->AddUUID(BluetoothUUID("1003"));
2076 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter3(df3); 2047 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter3(df3);
2077 2048
2078 adapter_->StartDiscoverySessionWithFilter( 2049 adapter_->StartDiscoverySessionWithFilter(
2079 discovery_filter3.Pass(), 2050 discovery_filter3.Pass(),
2080 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 2051 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
2081 base::Unretained(this)), 2052 base::Unretained(this)),
2082 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 2053 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
2083 base::Unretained(this)));
2084 2054
2085 message_loop_.Run(); 2055 message_loop_.Run();
2086 2056
2087 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 2057 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
2088 EXPECT_EQ("auto", *filter->transport); 2058 EXPECT_EQ("auto", *filter->transport);
2089 EXPECT_EQ(-65, *filter->rssi); 2059 EXPECT_EQ(-65, *filter->rssi);
2090 EXPECT_EQ(nullptr, filter->pathloss.get()); 2060 EXPECT_EQ(nullptr, filter->pathloss.get());
2091 uuids = *filter->uuids; 2061 uuids = *filter->uuids;
2092 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000")); 2062 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1000"));
2093 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1001")); 2063 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1001"));
2094 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1003")); 2064 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1003"));
2095 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1020")); 2065 EXPECT_NE(uuids.end(), std::find(uuids.begin(), uuids.end(), "1020"));
2096 2066
2097 // start additionally classic scan 2067 // start additionally classic scan
2098 adapter_->StartDiscoverySession( 2068 adapter_->StartDiscoverySession(
2099 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 2069 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
2100 base::Unretained(this)), 2070 base::Unretained(this)),
2101 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 2071 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
2102 base::Unretained(this)));
2103 2072
2104 message_loop_.Run(); 2073 message_loop_.Run();
2105 2074
2106 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter(); 2075 filter = fake_bluetooth_adapter_client_->GetDiscoveryFilter();
2107 EXPECT_EQ("auto", *filter->transport); 2076 EXPECT_EQ("auto", *filter->transport);
2108 EXPECT_EQ(nullptr, filter->rssi.get()); 2077 EXPECT_EQ(nullptr, filter->rssi.get());
2109 EXPECT_EQ(nullptr, filter->pathloss.get()); 2078 EXPECT_EQ(nullptr, filter->pathloss.get());
2110 EXPECT_EQ(nullptr, filter->uuids.get()); 2079 EXPECT_EQ(nullptr, filter->uuids.get());
2111 2080
2112 // Request to stop discovery 4 times. 2081 // Request to stop discovery 4 times.
2113 for (int i = 3; i >= 0; i--) { 2082 for (int i = 3; i >= 0; i--) {
2114 discovery_sessions_[i]->Stop( 2083 discovery_sessions_[i]->Stop(
2115 base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this)), 2084 base::Bind(&BluetoothBlueZTest::Callback, base::Unretained(this)),
2116 base::Bind(&BluetoothChromeOSTest::ErrorCallback, 2085 base::Bind(&BluetoothBlueZTest::ErrorCallback, base::Unretained(this)));
2117 base::Unretained(this)));
2118 2086
2119 // Every session stopping would trigger filter update 2087 // Every session stopping would trigger filter update
2120 message_loop_.Run(); 2088 message_loop_.Run();
2121 } 2089 }
2122 } 2090 }
2123 2091
2124 TEST_F(BluetoothChromeOSTest, DeviceProperties) { 2092 TEST_F(BluetoothBlueZTest, DeviceProperties) {
2125 GetAdapter(); 2093 GetAdapter();
2126 2094
2127 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 2095 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
2128 ASSERT_EQ(2U, devices.size()); 2096 ASSERT_EQ(2U, devices.size());
2129 2097
2130 int idx = GetDeviceIndexByAddress( 2098 int idx = GetDeviceIndexByAddress(
2131 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 2099 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
2132 ASSERT_NE(-1, idx); 2100 ASSERT_NE(-1, idx);
2133 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, 2101 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress,
2134 devices[idx]->GetAddress()); 2102 devices[idx]->GetAddress());
(...skipping 14 matching lines...) Expand all
2149 ASSERT_EQ(2U, uuids.size()); 2117 ASSERT_EQ(2U, uuids.size());
2150 EXPECT_EQ(uuids[0], BluetoothUUID("1800")); 2118 EXPECT_EQ(uuids[0], BluetoothUUID("1800"));
2151 EXPECT_EQ(uuids[1], BluetoothUUID("1801")); 2119 EXPECT_EQ(uuids[1], BluetoothUUID("1801"));
2152 2120
2153 EXPECT_EQ(BluetoothDevice::VENDOR_ID_USB, devices[idx]->GetVendorIDSource()); 2121 EXPECT_EQ(BluetoothDevice::VENDOR_ID_USB, devices[idx]->GetVendorIDSource());
2154 EXPECT_EQ(0x05ac, devices[idx]->GetVendorID()); 2122 EXPECT_EQ(0x05ac, devices[idx]->GetVendorID());
2155 EXPECT_EQ(0x030d, devices[idx]->GetProductID()); 2123 EXPECT_EQ(0x030d, devices[idx]->GetProductID());
2156 EXPECT_EQ(0x0306, devices[idx]->GetDeviceID()); 2124 EXPECT_EQ(0x0306, devices[idx]->GetDeviceID());
2157 } 2125 }
2158 2126
2159 TEST_F(BluetoothChromeOSTest, DeviceClassChanged) { 2127 TEST_F(BluetoothBlueZTest, DeviceClassChanged) {
2160 // Simulate a change of class of a device, as sometimes occurs 2128 // Simulate a change of class of a device, as sometimes occurs
2161 // during discovery. 2129 // during discovery.
2162 GetAdapter(); 2130 GetAdapter();
2163 2131
2164 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 2132 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
2165 ASSERT_EQ(2U, devices.size()); 2133 ASSERT_EQ(2U, devices.size());
2166 2134
2167 int idx = GetDeviceIndexByAddress( 2135 int idx = GetDeviceIndexByAddress(
2168 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 2136 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
2169 ASSERT_NE(-1, idx); 2137 ASSERT_NE(-1, idx);
2170 ASSERT_EQ(BluetoothDevice::DEVICE_COMPUTER, devices[idx]->GetDeviceType()); 2138 ASSERT_EQ(BluetoothDevice::DEVICE_COMPUTER, devices[idx]->GetDeviceType());
2171 2139
2172 // Install an observer; expect the DeviceChanged method to be called when 2140 // Install an observer; expect the DeviceChanged method to be called when
2173 // we change the class of the device. 2141 // we change the class of the device.
2174 TestBluetoothAdapterObserver observer(adapter_); 2142 TestBluetoothAdapterObserver observer(adapter_);
2175 2143
2176 bluez::FakeBluetoothDeviceClient::Properties* properties = 2144 bluez::FakeBluetoothDeviceClient::Properties* properties =
2177 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 2145 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
2178 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); 2146 bluez::FakeBluetoothDeviceClient::kPairedDevicePath));
2179 2147
2180 properties->bluetooth_class.ReplaceValue(0x002580); 2148 properties->bluetooth_class.ReplaceValue(0x002580);
2181 2149
2182 EXPECT_EQ(1, observer.device_changed_count()); 2150 EXPECT_EQ(1, observer.device_changed_count());
2183 EXPECT_EQ(devices[idx], observer.last_device()); 2151 EXPECT_EQ(devices[idx], observer.last_device());
2184 2152
2185 EXPECT_EQ(BluetoothDevice::DEVICE_MOUSE, devices[idx]->GetDeviceType()); 2153 EXPECT_EQ(BluetoothDevice::DEVICE_MOUSE, devices[idx]->GetDeviceType());
2186 } 2154 }
2187 2155
2188 TEST_F(BluetoothChromeOSTest, DeviceNameChanged) { 2156 TEST_F(BluetoothBlueZTest, DeviceNameChanged) {
2189 // Simulate a change of name of a device. 2157 // Simulate a change of name of a device.
2190 GetAdapter(); 2158 GetAdapter();
2191 2159
2192 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 2160 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
2193 ASSERT_EQ(2U, devices.size()); 2161 ASSERT_EQ(2U, devices.size());
2194 2162
2195 int idx = GetDeviceIndexByAddress( 2163 int idx = GetDeviceIndexByAddress(
2196 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 2164 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
2197 ASSERT_NE(-1, idx); 2165 ASSERT_NE(-1, idx);
2198 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, 2166 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress,
(...skipping 12 matching lines...) Expand all
2211 2179
2212 static const std::string new_name("New Device Name"); 2180 static const std::string new_name("New Device Name");
2213 properties->alias.ReplaceValue(new_name); 2181 properties->alias.ReplaceValue(new_name);
2214 2182
2215 EXPECT_EQ(1, observer.device_changed_count()); 2183 EXPECT_EQ(1, observer.device_changed_count());
2216 EXPECT_EQ(devices[idx], observer.last_device()); 2184 EXPECT_EQ(devices[idx], observer.last_device());
2217 2185
2218 EXPECT_EQ(base::UTF8ToUTF16(new_name), devices[idx]->GetName()); 2186 EXPECT_EQ(base::UTF8ToUTF16(new_name), devices[idx]->GetName());
2219 } 2187 }
2220 2188
2221 TEST_F(BluetoothChromeOSTest, DeviceAddressChanged) { 2189 TEST_F(BluetoothBlueZTest, DeviceAddressChanged) {
2222 // Simulate a change of address of a device. 2190 // Simulate a change of address of a device.
2223 GetAdapter(); 2191 GetAdapter();
2224 2192
2225 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 2193 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
2226 ASSERT_EQ(2U, devices.size()); 2194 ASSERT_EQ(2U, devices.size());
2227 2195
2228 int idx = GetDeviceIndexByAddress( 2196 int idx = GetDeviceIndexByAddress(
2229 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 2197 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
2230 ASSERT_NE(-1, idx); 2198 ASSERT_NE(-1, idx);
2231 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, 2199 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress,
(...skipping 13 matching lines...) Expand all
2245 static const char* kNewAddress = "D9:1F:FC:11:22:33"; 2213 static const char* kNewAddress = "D9:1F:FC:11:22:33";
2246 properties->address.ReplaceValue(kNewAddress); 2214 properties->address.ReplaceValue(kNewAddress);
2247 2215
2248 EXPECT_EQ(1, observer.device_address_changed_count()); 2216 EXPECT_EQ(1, observer.device_address_changed_count());
2249 EXPECT_EQ(1, observer.device_changed_count()); 2217 EXPECT_EQ(1, observer.device_changed_count());
2250 EXPECT_EQ(devices[idx], observer.last_device()); 2218 EXPECT_EQ(devices[idx], observer.last_device());
2251 2219
2252 EXPECT_EQ(std::string(kNewAddress), devices[idx]->GetAddress()); 2220 EXPECT_EQ(std::string(kNewAddress), devices[idx]->GetAddress());
2253 } 2221 }
2254 2222
2255 TEST_F(BluetoothChromeOSTest, DeviceUuidsChanged) { 2223 TEST_F(BluetoothBlueZTest, DeviceUuidsChanged) {
2256 // Simulate a change of advertised services of a device. 2224 // Simulate a change of advertised services of a device.
2257 GetAdapter(); 2225 GetAdapter();
2258 2226
2259 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 2227 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
2260 ASSERT_EQ(2U, devices.size()); 2228 ASSERT_EQ(2U, devices.size());
2261 2229
2262 int idx = GetDeviceIndexByAddress( 2230 int idx = GetDeviceIndexByAddress(
2263 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 2231 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
2264 ASSERT_NE(-1, idx); 2232 ASSERT_NE(-1, idx);
2265 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, 2233 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress,
(...skipping 27 matching lines...) Expand all
2293 // Fetching the value should give the new one. 2261 // Fetching the value should give the new one.
2294 uuids = devices[idx]->GetUUIDs(); 2262 uuids = devices[idx]->GetUUIDs();
2295 ASSERT_EQ(5U, uuids.size()); 2263 ASSERT_EQ(5U, uuids.size());
2296 EXPECT_EQ(uuids[0], BluetoothUUID("1800")); 2264 EXPECT_EQ(uuids[0], BluetoothUUID("1800"));
2297 EXPECT_EQ(uuids[1], BluetoothUUID("1801")); 2265 EXPECT_EQ(uuids[1], BluetoothUUID("1801"));
2298 EXPECT_EQ(uuids[2], BluetoothUUID("110c")); 2266 EXPECT_EQ(uuids[2], BluetoothUUID("110c"));
2299 EXPECT_EQ(uuids[3], BluetoothUUID("110e")); 2267 EXPECT_EQ(uuids[3], BluetoothUUID("110e"));
2300 EXPECT_EQ(uuids[4], BluetoothUUID("110a")); 2268 EXPECT_EQ(uuids[4], BluetoothUUID("110a"));
2301 } 2269 }
2302 2270
2303 TEST_F(BluetoothChromeOSTest, DeviceInquiryRSSIInvalidated) { 2271 TEST_F(BluetoothBlueZTest, DeviceInquiryRSSIInvalidated) {
2304 // Simulate invalidation of inquiry RSSI of a device, as it occurs 2272 // Simulate invalidation of inquiry RSSI of a device, as it occurs
2305 // when discovery is finished. 2273 // when discovery is finished.
2306 GetAdapter(); 2274 GetAdapter();
2307 2275
2308 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 2276 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
2309 ASSERT_EQ(2U, devices.size()); 2277 ASSERT_EQ(2U, devices.size());
2310 2278
2311 int idx = GetDeviceIndexByAddress( 2279 int idx = GetDeviceIndexByAddress(
2312 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 2280 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
2313 ASSERT_NE(-1, idx); 2281 ASSERT_NE(-1, idx);
(...skipping 16 matching lines...) Expand all
2330 properties->rssi.set_valid(false); 2298 properties->rssi.set_valid(false);
2331 properties->NotifyPropertyChanged(properties->rssi.name()); 2299 properties->NotifyPropertyChanged(properties->rssi.name());
2332 2300
2333 EXPECT_EQ(1, observer.device_changed_count()); 2301 EXPECT_EQ(1, observer.device_changed_count());
2334 EXPECT_EQ(devices[idx], observer.last_device()); 2302 EXPECT_EQ(devices[idx], observer.last_device());
2335 2303
2336 int unknown_power = BluetoothDevice::kUnknownPower; 2304 int unknown_power = BluetoothDevice::kUnknownPower;
2337 EXPECT_EQ(unknown_power, devices[idx]->GetInquiryRSSI()); 2305 EXPECT_EQ(unknown_power, devices[idx]->GetInquiryRSSI());
2338 } 2306 }
2339 2307
2340 TEST_F(BluetoothChromeOSTest, DeviceInquiryTxPowerInvalidated) { 2308 TEST_F(BluetoothBlueZTest, DeviceInquiryTxPowerInvalidated) {
2341 // Simulate invalidation of inquiry TxPower of a device, as it occurs 2309 // Simulate invalidation of inquiry TxPower of a device, as it occurs
2342 // when discovery is finished. 2310 // when discovery is finished.
2343 GetAdapter(); 2311 GetAdapter();
2344 2312
2345 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 2313 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
2346 ASSERT_EQ(2U, devices.size()); 2314 ASSERT_EQ(2U, devices.size());
2347 2315
2348 int idx = GetDeviceIndexByAddress( 2316 int idx = GetDeviceIndexByAddress(
2349 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 2317 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
2350 ASSERT_NE(-1, idx); 2318 ASSERT_NE(-1, idx);
(...skipping 16 matching lines...) Expand all
2367 properties->tx_power.set_valid(false); 2335 properties->tx_power.set_valid(false);
2368 properties->NotifyPropertyChanged(properties->tx_power.name()); 2336 properties->NotifyPropertyChanged(properties->tx_power.name());
2369 2337
2370 EXPECT_EQ(1, observer.device_changed_count()); 2338 EXPECT_EQ(1, observer.device_changed_count());
2371 EXPECT_EQ(devices[idx], observer.last_device()); 2339 EXPECT_EQ(devices[idx], observer.last_device());
2372 2340
2373 int unknown_power = BluetoothDevice::kUnknownPower; 2341 int unknown_power = BluetoothDevice::kUnknownPower;
2374 EXPECT_EQ(unknown_power, devices[idx]->GetInquiryTxPower()); 2342 EXPECT_EQ(unknown_power, devices[idx]->GetInquiryTxPower());
2375 } 2343 }
2376 2344
2377 TEST_F(BluetoothChromeOSTest, ForgetDevice) { 2345 TEST_F(BluetoothBlueZTest, ForgetDevice) {
2378 GetAdapter(); 2346 GetAdapter();
2379 2347
2380 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 2348 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
2381 ASSERT_EQ(2U, devices.size()); 2349 ASSERT_EQ(2U, devices.size());
2382 2350
2383 int idx = GetDeviceIndexByAddress( 2351 int idx = GetDeviceIndexByAddress(
2384 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 2352 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
2385 ASSERT_NE(-1, idx); 2353 ASSERT_NE(-1, idx);
2386 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, 2354 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress,
2387 devices[idx]->GetAddress()); 2355 devices[idx]->GetAddress());
2388 2356
2389 std::string address = devices[idx]->GetAddress(); 2357 std::string address = devices[idx]->GetAddress();
2390 2358
2391 // Install an observer; expect the DeviceRemoved method to be called 2359 // Install an observer; expect the DeviceRemoved method to be called
2392 // with the device we remove. 2360 // with the device we remove.
2393 TestBluetoothAdapterObserver observer(adapter_); 2361 TestBluetoothAdapterObserver observer(adapter_);
2394 2362
2395 devices[idx]->Forget(GetErrorCallback()); 2363 devices[idx]->Forget(GetErrorCallback());
2396 EXPECT_EQ(0, error_callback_count_); 2364 EXPECT_EQ(0, error_callback_count_);
2397 2365
2398 EXPECT_EQ(1, observer.device_removed_count()); 2366 EXPECT_EQ(1, observer.device_removed_count());
2399 EXPECT_EQ(address, observer.last_device_address()); 2367 EXPECT_EQ(address, observer.last_device_address());
2400 2368
2401 // GetDevices shouldn't return the device either. 2369 // GetDevices shouldn't return the device either.
2402 devices = adapter_->GetDevices(); 2370 devices = adapter_->GetDevices();
2403 ASSERT_EQ(1U, devices.size()); 2371 ASSERT_EQ(1U, devices.size());
2404 } 2372 }
2405 2373
2406 TEST_F(BluetoothChromeOSTest, ForgetUnpairedDevice) { 2374 TEST_F(BluetoothBlueZTest, ForgetUnpairedDevice) {
2407 GetAdapter(); 2375 GetAdapter();
2408 DiscoverDevices(); 2376 DiscoverDevices();
2409 2377
2410 BluetoothDevice* device = adapter_->GetDevice( 2378 BluetoothDevice* device = adapter_->GetDevice(
2411 bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress); 2379 bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress);
2412 ASSERT_TRUE(device != nullptr); 2380 ASSERT_TRUE(device != nullptr);
2413 ASSERT_FALSE(device->IsPaired()); 2381 ASSERT_FALSE(device->IsPaired());
2414 2382
2415 // Connect the device so it becomes trusted and remembered. 2383 // Connect the device so it becomes trusted and remembered.
2416 device->Connect(nullptr, GetCallback(), 2384 device->Connect(nullptr, GetCallback(),
2417 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2385 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2418 base::Unretained(this))); 2386 base::Unretained(this)));
2419 2387
2420 ASSERT_EQ(1, callback_count_); 2388 ASSERT_EQ(1, callback_count_);
2421 ASSERT_EQ(0, error_callback_count_); 2389 ASSERT_EQ(0, error_callback_count_);
2422 callback_count_ = 0; 2390 callback_count_ = 0;
2423 2391
2424 ASSERT_TRUE(device->IsConnected()); 2392 ASSERT_TRUE(device->IsConnected());
2425 ASSERT_FALSE(device->IsConnecting()); 2393 ASSERT_FALSE(device->IsConnecting());
2426 2394
2427 // Make sure the trusted property has been set to true. 2395 // Make sure the trusted property has been set to true.
(...skipping 12 matching lines...) Expand all
2440 EXPECT_EQ(1, observer.device_removed_count()); 2408 EXPECT_EQ(1, observer.device_removed_count());
2441 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress, 2409 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress,
2442 observer.last_device_address()); 2410 observer.last_device_address());
2443 2411
2444 // GetDevices shouldn't return the device either. 2412 // GetDevices shouldn't return the device either.
2445 device = adapter_->GetDevice( 2413 device = adapter_->GetDevice(
2446 bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress); 2414 bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress);
2447 EXPECT_FALSE(device != nullptr); 2415 EXPECT_FALSE(device != nullptr);
2448 } 2416 }
2449 2417
2450 TEST_F(BluetoothChromeOSTest, ConnectPairedDevice) { 2418 TEST_F(BluetoothBlueZTest, ConnectPairedDevice) {
2451 GetAdapter(); 2419 GetAdapter();
2452 2420
2453 BluetoothDevice* device = adapter_->GetDevice( 2421 BluetoothDevice* device = adapter_->GetDevice(
2454 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 2422 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
2455 ASSERT_TRUE(device != nullptr); 2423 ASSERT_TRUE(device != nullptr);
2456 ASSERT_TRUE(device->IsPaired()); 2424 ASSERT_TRUE(device->IsPaired());
2457 2425
2458 TestBluetoothAdapterObserver observer(adapter_); 2426 TestBluetoothAdapterObserver observer(adapter_);
2459 2427
2460 // Connect without a pairing delegate; since the device is already Paired 2428 // Connect without a pairing delegate; since the device is already Paired
2461 // this should succeed and the device should become connected. 2429 // this should succeed and the device should become connected.
2462 device->Connect(nullptr, GetCallback(), 2430 device->Connect(nullptr, GetCallback(),
2463 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2431 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2464 base::Unretained(this))); 2432 base::Unretained(this)));
2465 2433
2466 EXPECT_EQ(1, callback_count_); 2434 EXPECT_EQ(1, callback_count_);
2467 EXPECT_EQ(0, error_callback_count_); 2435 EXPECT_EQ(0, error_callback_count_);
2468 2436
2469 // Two changes for connecting, one for connected and one for for trusted 2437 // Two changes for connecting, one for connected and one for for trusted
2470 // after connecting. 2438 // after connecting.
2471 EXPECT_EQ(4, observer.device_changed_count()); 2439 EXPECT_EQ(4, observer.device_changed_count());
2472 EXPECT_EQ(device, observer.last_device()); 2440 EXPECT_EQ(device, observer.last_device());
2473 2441
2474 EXPECT_TRUE(device->IsConnected()); 2442 EXPECT_TRUE(device->IsConnected());
2475 EXPECT_FALSE(device->IsConnecting()); 2443 EXPECT_FALSE(device->IsConnecting());
2476 } 2444 }
2477 2445
2478 TEST_F(BluetoothChromeOSTest, ConnectUnpairableDevice) { 2446 TEST_F(BluetoothBlueZTest, ConnectUnpairableDevice) {
2479 GetAdapter(); 2447 GetAdapter();
2480 DiscoverDevices(); 2448 DiscoverDevices();
2481 2449
2482 BluetoothDevice* device = adapter_->GetDevice( 2450 BluetoothDevice* device = adapter_->GetDevice(
2483 bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress); 2451 bluez::FakeBluetoothDeviceClient::kConnectUnpairableAddress);
2484 ASSERT_TRUE(device != nullptr); 2452 ASSERT_TRUE(device != nullptr);
2485 ASSERT_FALSE(device->IsPaired()); 2453 ASSERT_FALSE(device->IsPaired());
2486 2454
2487 TestBluetoothAdapterObserver observer(adapter_); 2455 TestBluetoothAdapterObserver observer(adapter_);
2488 2456
2489 // Connect without a pairing delegate; since the device does not require 2457 // Connect without a pairing delegate; since the device does not require
2490 // pairing, this should succeed and the device should become connected. 2458 // pairing, this should succeed and the device should become connected.
2491 device->Connect(nullptr, GetCallback(), 2459 device->Connect(nullptr, GetCallback(),
2492 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2460 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2493 base::Unretained(this))); 2461 base::Unretained(this)));
2494 2462
2495 EXPECT_EQ(1, callback_count_); 2463 EXPECT_EQ(1, callback_count_);
2496 EXPECT_EQ(0, error_callback_count_); 2464 EXPECT_EQ(0, error_callback_count_);
2497 2465
2498 // Two changes for connecting, one for connected, one for for trusted after 2466 // Two changes for connecting, one for connected, one for for trusted after
2499 // connection, and one for the reconnect mode (IsConnectable). 2467 // connection, and one for the reconnect mode (IsConnectable).
2500 EXPECT_EQ(5, observer.device_changed_count()); 2468 EXPECT_EQ(5, observer.device_changed_count());
2501 EXPECT_EQ(device, observer.last_device()); 2469 EXPECT_EQ(device, observer.last_device());
2502 2470
2503 EXPECT_TRUE(device->IsConnected()); 2471 EXPECT_TRUE(device->IsConnected());
2504 EXPECT_FALSE(device->IsConnecting()); 2472 EXPECT_FALSE(device->IsConnecting());
2505 2473
2506 // Make sure the trusted property has been set to true. 2474 // Make sure the trusted property has been set to true.
2507 bluez::FakeBluetoothDeviceClient::Properties* properties = 2475 bluez::FakeBluetoothDeviceClient::Properties* properties =
2508 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 2476 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
2509 bluez::FakeBluetoothDeviceClient::kConnectUnpairablePath)); 2477 bluez::FakeBluetoothDeviceClient::kConnectUnpairablePath));
2510 EXPECT_TRUE(properties->trusted.value()); 2478 EXPECT_TRUE(properties->trusted.value());
2511 2479
2512 // Verify is a HID device and is not connectable. 2480 // Verify is a HID device and is not connectable.
2513 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); 2481 BluetoothDevice::UUIDList uuids = device->GetUUIDs();
2514 ASSERT_EQ(1U, uuids.size()); 2482 ASSERT_EQ(1U, uuids.size());
2515 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); 2483 EXPECT_EQ(uuids[0], BluetoothUUID("1124"));
2516 EXPECT_FALSE(device->IsConnectable()); 2484 EXPECT_FALSE(device->IsConnectable());
2517 } 2485 }
2518 2486
2519 TEST_F(BluetoothChromeOSTest, ConnectConnectedDevice) { 2487 TEST_F(BluetoothBlueZTest, ConnectConnectedDevice) {
2520 GetAdapter(); 2488 GetAdapter();
2521 2489
2522 BluetoothDevice* device = adapter_->GetDevice( 2490 BluetoothDevice* device = adapter_->GetDevice(
2523 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 2491 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
2524 ASSERT_TRUE(device != nullptr); 2492 ASSERT_TRUE(device != nullptr);
2525 ASSERT_TRUE(device->IsPaired()); 2493 ASSERT_TRUE(device->IsPaired());
2526 2494
2527 device->Connect(nullptr, GetCallback(), 2495 device->Connect(nullptr, GetCallback(),
2528 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2496 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2529 base::Unretained(this))); 2497 base::Unretained(this)));
2530 2498
2531 ASSERT_EQ(1, callback_count_); 2499 ASSERT_EQ(1, callback_count_);
2532 ASSERT_EQ(0, error_callback_count_); 2500 ASSERT_EQ(0, error_callback_count_);
2533 callback_count_ = 0; 2501 callback_count_ = 0;
2534 2502
2535 ASSERT_TRUE(device->IsConnected()); 2503 ASSERT_TRUE(device->IsConnected());
2536 2504
2537 // Connect again; since the device is already Connected, this shouldn't do 2505 // Connect again; since the device is already Connected, this shouldn't do
2538 // anything to initiate the connection. 2506 // anything to initiate the connection.
2539 TestBluetoothAdapterObserver observer(adapter_); 2507 TestBluetoothAdapterObserver observer(adapter_);
2540 2508
2541 device->Connect(nullptr, GetCallback(), 2509 device->Connect(nullptr, GetCallback(),
2542 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2510 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2543 base::Unretained(this))); 2511 base::Unretained(this)));
2544 2512
2545 EXPECT_EQ(1, callback_count_); 2513 EXPECT_EQ(1, callback_count_);
2546 EXPECT_EQ(0, error_callback_count_); 2514 EXPECT_EQ(0, error_callback_count_);
2547 2515
2548 // The observer will be called because Connecting will toggle true and false, 2516 // The observer will be called because Connecting will toggle true and false,
2549 // and the trusted property will be updated to true. 2517 // and the trusted property will be updated to true.
2550 EXPECT_EQ(3, observer.device_changed_count()); 2518 EXPECT_EQ(3, observer.device_changed_count());
2551 2519
2552 EXPECT_TRUE(device->IsConnected()); 2520 EXPECT_TRUE(device->IsConnected());
2553 EXPECT_FALSE(device->IsConnecting()); 2521 EXPECT_FALSE(device->IsConnecting());
2554 } 2522 }
2555 2523
2556 TEST_F(BluetoothChromeOSTest, ConnectDeviceFails) { 2524 TEST_F(BluetoothBlueZTest, ConnectDeviceFails) {
2557 GetAdapter(); 2525 GetAdapter();
2558 DiscoverDevices(); 2526 DiscoverDevices();
2559 2527
2560 BluetoothDevice* device = adapter_->GetDevice( 2528 BluetoothDevice* device = adapter_->GetDevice(
2561 bluez::FakeBluetoothDeviceClient::kLegacyAutopairAddress); 2529 bluez::FakeBluetoothDeviceClient::kLegacyAutopairAddress);
2562 ASSERT_TRUE(device != nullptr); 2530 ASSERT_TRUE(device != nullptr);
2563 ASSERT_FALSE(device->IsPaired()); 2531 ASSERT_FALSE(device->IsPaired());
2564 2532
2565 TestBluetoothAdapterObserver observer(adapter_); 2533 TestBluetoothAdapterObserver observer(adapter_);
2566 2534
2567 // Connect without a pairing delegate; since the device requires pairing, 2535 // Connect without a pairing delegate; since the device requires pairing,
2568 // this should fail with an error. 2536 // this should fail with an error.
2569 device->Connect(nullptr, GetCallback(), 2537 device->Connect(nullptr, GetCallback(),
2570 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2538 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2571 base::Unretained(this))); 2539 base::Unretained(this)));
2572 2540
2573 EXPECT_EQ(0, callback_count_); 2541 EXPECT_EQ(0, callback_count_);
2574 EXPECT_EQ(1, error_callback_count_); 2542 EXPECT_EQ(1, error_callback_count_);
2575 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_); 2543 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_);
2576 2544
2577 EXPECT_EQ(2, observer.device_changed_count()); 2545 EXPECT_EQ(2, observer.device_changed_count());
2578 2546
2579 EXPECT_FALSE(device->IsConnected()); 2547 EXPECT_FALSE(device->IsConnected());
2580 EXPECT_FALSE(device->IsConnecting()); 2548 EXPECT_FALSE(device->IsConnecting());
2581 } 2549 }
2582 2550
2583 TEST_F(BluetoothChromeOSTest, DisconnectDevice) { 2551 TEST_F(BluetoothBlueZTest, DisconnectDevice) {
2584 GetAdapter(); 2552 GetAdapter();
2585 2553
2586 BluetoothDevice* device = adapter_->GetDevice( 2554 BluetoothDevice* device = adapter_->GetDevice(
2587 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 2555 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
2588 ASSERT_TRUE(device != nullptr); 2556 ASSERT_TRUE(device != nullptr);
2589 ASSERT_TRUE(device->IsPaired()); 2557 ASSERT_TRUE(device->IsPaired());
2590 2558
2591 device->Connect(nullptr, GetCallback(), 2559 device->Connect(nullptr, GetCallback(),
2592 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2560 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2593 base::Unretained(this))); 2561 base::Unretained(this)));
2594 2562
2595 ASSERT_EQ(1, callback_count_); 2563 ASSERT_EQ(1, callback_count_);
2596 ASSERT_EQ(0, error_callback_count_); 2564 ASSERT_EQ(0, error_callback_count_);
2597 callback_count_ = 0; 2565 callback_count_ = 0;
2598 2566
2599 ASSERT_TRUE(device->IsConnected()); 2567 ASSERT_TRUE(device->IsConnected());
2600 ASSERT_FALSE(device->IsConnecting()); 2568 ASSERT_FALSE(device->IsConnecting());
2601 2569
2602 // Disconnect the device, we should see the observer method fire and the 2570 // Disconnect the device, we should see the observer method fire and the
2603 // device get dropped. 2571 // device get dropped.
2604 TestBluetoothAdapterObserver observer(adapter_); 2572 TestBluetoothAdapterObserver observer(adapter_);
2605 2573
2606 device->Disconnect(GetCallback(), GetErrorCallback()); 2574 device->Disconnect(GetCallback(), GetErrorCallback());
2607 2575
2608 EXPECT_EQ(1, callback_count_); 2576 EXPECT_EQ(1, callback_count_);
2609 EXPECT_EQ(0, error_callback_count_); 2577 EXPECT_EQ(0, error_callback_count_);
2610 2578
2611 EXPECT_EQ(1, observer.device_changed_count()); 2579 EXPECT_EQ(1, observer.device_changed_count());
2612 EXPECT_EQ(device, observer.last_device()); 2580 EXPECT_EQ(device, observer.last_device());
2613 2581
2614 EXPECT_FALSE(device->IsConnected()); 2582 EXPECT_FALSE(device->IsConnected());
2615 } 2583 }
2616 2584
2617 TEST_F(BluetoothChromeOSTest, DisconnectUnconnectedDevice) { 2585 TEST_F(BluetoothBlueZTest, DisconnectUnconnectedDevice) {
2618 GetAdapter(); 2586 GetAdapter();
2619 2587
2620 BluetoothDevice* device = adapter_->GetDevice( 2588 BluetoothDevice* device = adapter_->GetDevice(
2621 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 2589 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
2622 ASSERT_TRUE(device != nullptr); 2590 ASSERT_TRUE(device != nullptr);
2623 ASSERT_TRUE(device->IsPaired()); 2591 ASSERT_TRUE(device->IsPaired());
2624 ASSERT_FALSE(device->IsConnected()); 2592 ASSERT_FALSE(device->IsConnected());
2625 2593
2626 // Disconnect the device, we should see the observer method fire and the 2594 // Disconnect the device, we should see the observer method fire and the
2627 // device get dropped. 2595 // device get dropped.
2628 TestBluetoothAdapterObserver observer(adapter_); 2596 TestBluetoothAdapterObserver observer(adapter_);
2629 2597
2630 device->Disconnect(GetCallback(), GetErrorCallback()); 2598 device->Disconnect(GetCallback(), GetErrorCallback());
2631 2599
2632 EXPECT_EQ(0, callback_count_); 2600 EXPECT_EQ(0, callback_count_);
2633 EXPECT_EQ(1, error_callback_count_); 2601 EXPECT_EQ(1, error_callback_count_);
2634 2602
2635 EXPECT_EQ(0, observer.device_changed_count()); 2603 EXPECT_EQ(0, observer.device_changed_count());
2636 2604
2637 EXPECT_FALSE(device->IsConnected()); 2605 EXPECT_FALSE(device->IsConnected());
2638 } 2606 }
2639 2607
2640 TEST_F(BluetoothChromeOSTest, PairTrustedDevice) { 2608 TEST_F(BluetoothBlueZTest, PairTrustedDevice) {
2641 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 2609 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
2642 GetAdapter(); 2610 GetAdapter();
2643 2611
2644 fake_bluetooth_device_client_->CreateDevice( 2612 fake_bluetooth_device_client_->CreateDevice(
2645 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 2613 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
2646 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient:: 2614 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::
2647 kConnectedTrustedNotPairedDevicePath)); 2615 kConnectedTrustedNotPairedDevicePath));
2648 BluetoothDevice* device = 2616 BluetoothDevice* device =
2649 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient:: 2617 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::
2650 kConnectedTrustedNotPairedDeviceAddress); 2618 kConnectedTrustedNotPairedDeviceAddress);
2651 ASSERT_TRUE(device != nullptr); 2619 ASSERT_TRUE(device != nullptr);
2652 2620
2653 // On the DBus level the device is trusted but not paired. But the current 2621 // On the DBus level the device is trusted but not paired. But the current
2654 // implementation of |BluetoothDevice::IsPaired()| returns true in this case. 2622 // implementation of |BluetoothDevice::IsPaired()| returns true in this case.
2655 bluez::FakeBluetoothDeviceClient::Properties* properties = 2623 bluez::FakeBluetoothDeviceClient::Properties* properties =
2656 fake_bluetooth_device_client_->GetProperties( 2624 fake_bluetooth_device_client_->GetProperties(
2657 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient:: 2625 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::
2658 kConnectedTrustedNotPairedDevicePath)); 2626 kConnectedTrustedNotPairedDevicePath));
2659 EXPECT_FALSE(properties->paired.value()); 2627 EXPECT_FALSE(properties->paired.value());
2660 EXPECT_TRUE(properties->trusted.value()); 2628 EXPECT_TRUE(properties->trusted.value());
2661 ASSERT_TRUE(device->IsPaired()); 2629 ASSERT_TRUE(device->IsPaired());
2662 2630
2663 // The |kConnectedTrustedNotPairedDevicePath| requests a passkey confirmation. 2631 // The |kConnectedTrustedNotPairedDevicePath| requests a passkey confirmation.
2664 // Obs.: This is the flow when CrOS triggers pairing with a iOS device. 2632 // Obs.: This is the flow when CrOS triggers pairing with a iOS device.
2665 TestBluetoothAdapterObserver observer(adapter_); 2633 TestBluetoothAdapterObserver observer(adapter_);
2666 TestPairingDelegate pairing_delegate; 2634 TestPairingDelegate pairing_delegate;
2667 adapter_->AddPairingDelegate( 2635 adapter_->AddPairingDelegate(
2668 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); 2636 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
2669 device->Pair(&pairing_delegate, GetCallback(), 2637 device->Pair(&pairing_delegate, GetCallback(),
2670 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2638 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2671 base::Unretained(this))); 2639 base::Unretained(this)));
2672 EXPECT_EQ(1, pairing_delegate.call_count_); 2640 EXPECT_EQ(1, pairing_delegate.call_count_);
2673 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); 2641 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_);
2674 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); 2642 EXPECT_EQ(123456U, pairing_delegate.last_passkey_);
2675 2643
2676 // Confirm the passkey. 2644 // Confirm the passkey.
2677 device->ConfirmPairing(); 2645 device->ConfirmPairing();
2678 message_loop_.Run(); 2646 message_loop_.Run();
2679 EXPECT_EQ(1, callback_count_); 2647 EXPECT_EQ(1, callback_count_);
2680 EXPECT_EQ(0, error_callback_count_); 2648 EXPECT_EQ(0, error_callback_count_);
2681 2649
2682 // Make sure the paired property has been set to true. 2650 // Make sure the paired property has been set to true.
2683 properties = fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 2651 properties = fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
2684 bluez::FakeBluetoothDeviceClient::kConnectedTrustedNotPairedDevicePath)); 2652 bluez::FakeBluetoothDeviceClient::kConnectedTrustedNotPairedDevicePath));
2685 EXPECT_TRUE(properties->paired.value()); 2653 EXPECT_TRUE(properties->paired.value());
2686 } 2654 }
2687 2655
2688 TEST_F(BluetoothChromeOSTest, PairAlreadyPairedDevice) { 2656 TEST_F(BluetoothBlueZTest, PairAlreadyPairedDevice) {
2689 GetAdapter(); 2657 GetAdapter();
2690 2658
2691 fake_bluetooth_device_client_->CreateDevice( 2659 fake_bluetooth_device_client_->CreateDevice(
2692 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 2660 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
2693 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); 2661 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kPairedDevicePath));
2694 BluetoothDevice* device = adapter_->GetDevice( 2662 BluetoothDevice* device = adapter_->GetDevice(
2695 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 2663 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
2696 ASSERT_TRUE(device != nullptr); 2664 ASSERT_TRUE(device != nullptr);
2697 2665
2698 // On the DBus level a device can be trusted but not paired. 2666 // On the DBus level a device can be trusted but not paired.
2699 bluez::FakeBluetoothDeviceClient::Properties* properties = 2667 bluez::FakeBluetoothDeviceClient::Properties* properties =
2700 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 2668 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
2701 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); 2669 bluez::FakeBluetoothDeviceClient::kPairedDevicePath));
2702 EXPECT_TRUE(properties->paired.value()); 2670 EXPECT_TRUE(properties->paired.value());
2703 EXPECT_TRUE(properties->trusted.value()); 2671 EXPECT_TRUE(properties->trusted.value());
2704 ASSERT_TRUE(device->IsPaired()); 2672 ASSERT_TRUE(device->IsPaired());
2705 2673
2706 TestBluetoothAdapterObserver observer(adapter_); 2674 TestBluetoothAdapterObserver observer(adapter_);
2707 TestPairingDelegate pairing_delegate; 2675 TestPairingDelegate pairing_delegate;
2708 adapter_->AddPairingDelegate( 2676 adapter_->AddPairingDelegate(
2709 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); 2677 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
2710 device->Pair(&pairing_delegate, GetCallback(), 2678 device->Pair(&pairing_delegate, GetCallback(),
2711 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2679 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2712 base::Unretained(this))); 2680 base::Unretained(this)));
2713 2681
2714 // For already paired devices a call to |Pair| should succeed without calling 2682 // For already paired devices a call to |Pair| should succeed without calling
2715 // the pairing delegate. 2683 // the pairing delegate.
2716 EXPECT_EQ(0, pairing_delegate.call_count_); 2684 EXPECT_EQ(0, pairing_delegate.call_count_);
2717 EXPECT_EQ(1, callback_count_); 2685 EXPECT_EQ(1, callback_count_);
2718 EXPECT_EQ(0, error_callback_count_); 2686 EXPECT_EQ(0, error_callback_count_);
2719 } 2687 }
2720 2688
2721 TEST_F(BluetoothChromeOSTest, PairLegacyAutopair) { 2689 TEST_F(BluetoothBlueZTest, PairLegacyAutopair) {
2722 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 2690 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
2723 2691
2724 GetAdapter(); 2692 GetAdapter();
2725 DiscoverDevices(); 2693 DiscoverDevices();
2726 2694
2727 // The Legacy Autopair device requires no PIN or Passkey to pair because 2695 // The Legacy Autopair device requires no PIN or Passkey to pair because
2728 // the daemon provides 0000 to the device for us. 2696 // the daemon provides 0000 to the device for us.
2729 BluetoothDevice* device = adapter_->GetDevice( 2697 BluetoothDevice* device = adapter_->GetDevice(
2730 bluez::FakeBluetoothDeviceClient::kLegacyAutopairAddress); 2698 bluez::FakeBluetoothDeviceClient::kLegacyAutopairAddress);
2731 ASSERT_TRUE(device != nullptr); 2699 ASSERT_TRUE(device != nullptr);
2732 ASSERT_FALSE(device->IsPaired()); 2700 ASSERT_FALSE(device->IsPaired());
2733 2701
2734 TestBluetoothAdapterObserver observer(adapter_); 2702 TestBluetoothAdapterObserver observer(adapter_);
2735 2703
2736 TestPairingDelegate pairing_delegate; 2704 TestPairingDelegate pairing_delegate;
2737 device->Connect(&pairing_delegate, GetCallback(), 2705 device->Connect(&pairing_delegate, GetCallback(),
2738 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2706 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2739 base::Unretained(this))); 2707 base::Unretained(this)));
2740 2708
2741 EXPECT_EQ(0, pairing_delegate.call_count_); 2709 EXPECT_EQ(0, pairing_delegate.call_count_);
2742 EXPECT_TRUE(device->IsConnecting()); 2710 EXPECT_TRUE(device->IsConnecting());
2743 2711
2744 message_loop_.Run(); 2712 message_loop_.Run();
2745 2713
2746 EXPECT_EQ(1, callback_count_); 2714 EXPECT_EQ(1, callback_count_);
2747 EXPECT_EQ(0, error_callback_count_); 2715 EXPECT_EQ(0, error_callback_count_);
2748 2716
(...skipping 14 matching lines...) Expand all
2763 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); 2731 EXPECT_EQ(uuids[0], BluetoothUUID("1124"));
2764 EXPECT_TRUE(device->IsConnectable()); 2732 EXPECT_TRUE(device->IsConnectable());
2765 2733
2766 // Make sure the trusted property has been set to true. 2734 // Make sure the trusted property has been set to true.
2767 bluez::FakeBluetoothDeviceClient::Properties* properties = 2735 bluez::FakeBluetoothDeviceClient::Properties* properties =
2768 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 2736 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
2769 bluez::FakeBluetoothDeviceClient::kLegacyAutopairPath)); 2737 bluez::FakeBluetoothDeviceClient::kLegacyAutopairPath));
2770 EXPECT_TRUE(properties->trusted.value()); 2738 EXPECT_TRUE(properties->trusted.value());
2771 } 2739 }
2772 2740
2773 TEST_F(BluetoothChromeOSTest, PairDisplayPinCode) { 2741 TEST_F(BluetoothBlueZTest, PairDisplayPinCode) {
2774 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 2742 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
2775 2743
2776 GetAdapter(); 2744 GetAdapter();
2777 DiscoverDevices(); 2745 DiscoverDevices();
2778 2746
2779 // Requires that we display a randomly generated PIN on the screen. 2747 // Requires that we display a randomly generated PIN on the screen.
2780 BluetoothDevice* device = adapter_->GetDevice( 2748 BluetoothDevice* device = adapter_->GetDevice(
2781 bluez::FakeBluetoothDeviceClient::kDisplayPinCodeAddress); 2749 bluez::FakeBluetoothDeviceClient::kDisplayPinCodeAddress);
2782 ASSERT_TRUE(device != nullptr); 2750 ASSERT_TRUE(device != nullptr);
2783 ASSERT_FALSE(device->IsPaired()); 2751 ASSERT_FALSE(device->IsPaired());
2784 2752
2785 TestBluetoothAdapterObserver observer(adapter_); 2753 TestBluetoothAdapterObserver observer(adapter_);
2786 2754
2787 TestPairingDelegate pairing_delegate; 2755 TestPairingDelegate pairing_delegate;
2788 device->Connect(&pairing_delegate, GetCallback(), 2756 device->Connect(&pairing_delegate, GetCallback(),
2789 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2757 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2790 base::Unretained(this))); 2758 base::Unretained(this)));
2791 2759
2792 EXPECT_EQ(1, pairing_delegate.call_count_); 2760 EXPECT_EQ(1, pairing_delegate.call_count_);
2793 EXPECT_EQ(1, pairing_delegate.display_pincode_count_); 2761 EXPECT_EQ(1, pairing_delegate.display_pincode_count_);
2794 EXPECT_EQ("123456", pairing_delegate.last_pincode_); 2762 EXPECT_EQ("123456", pairing_delegate.last_pincode_);
2795 EXPECT_TRUE(device->IsConnecting()); 2763 EXPECT_TRUE(device->IsConnecting());
2796 2764
2797 message_loop_.Run(); 2765 message_loop_.Run();
2798 2766
2799 EXPECT_EQ(1, callback_count_); 2767 EXPECT_EQ(1, callback_count_);
(...skipping 16 matching lines...) Expand all
2816 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); 2784 EXPECT_EQ(uuids[0], BluetoothUUID("1124"));
2817 EXPECT_TRUE(device->IsConnectable()); 2785 EXPECT_TRUE(device->IsConnectable());
2818 2786
2819 // Make sure the trusted property has been set to true. 2787 // Make sure the trusted property has been set to true.
2820 bluez::FakeBluetoothDeviceClient::Properties* properties = 2788 bluez::FakeBluetoothDeviceClient::Properties* properties =
2821 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 2789 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
2822 bluez::FakeBluetoothDeviceClient::kDisplayPinCodePath)); 2790 bluez::FakeBluetoothDeviceClient::kDisplayPinCodePath));
2823 EXPECT_TRUE(properties->trusted.value()); 2791 EXPECT_TRUE(properties->trusted.value());
2824 } 2792 }
2825 2793
2826 TEST_F(BluetoothChromeOSTest, PairDisplayPasskey) { 2794 TEST_F(BluetoothBlueZTest, PairDisplayPasskey) {
2827 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 2795 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
2828 2796
2829 GetAdapter(); 2797 GetAdapter();
2830 DiscoverDevices(); 2798 DiscoverDevices();
2831 2799
2832 // Requires that we display a randomly generated Passkey on the screen, 2800 // Requires that we display a randomly generated Passkey on the screen,
2833 // and notifies us as it's typed in. 2801 // and notifies us as it's typed in.
2834 BluetoothDevice* device = adapter_->GetDevice( 2802 BluetoothDevice* device = adapter_->GetDevice(
2835 bluez::FakeBluetoothDeviceClient::kDisplayPasskeyAddress); 2803 bluez::FakeBluetoothDeviceClient::kDisplayPasskeyAddress);
2836 ASSERT_TRUE(device != nullptr); 2804 ASSERT_TRUE(device != nullptr);
2837 ASSERT_FALSE(device->IsPaired()); 2805 ASSERT_FALSE(device->IsPaired());
2838 2806
2839 TestBluetoothAdapterObserver observer(adapter_); 2807 TestBluetoothAdapterObserver observer(adapter_);
2840 2808
2841 TestPairingDelegate pairing_delegate; 2809 TestPairingDelegate pairing_delegate;
2842 device->Connect(&pairing_delegate, GetCallback(), 2810 device->Connect(&pairing_delegate, GetCallback(),
2843 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2811 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2844 base::Unretained(this))); 2812 base::Unretained(this)));
2845 2813
2846 // One call for DisplayPasskey() and one for KeysEntered(). 2814 // One call for DisplayPasskey() and one for KeysEntered().
2847 EXPECT_EQ(2, pairing_delegate.call_count_); 2815 EXPECT_EQ(2, pairing_delegate.call_count_);
2848 EXPECT_EQ(1, pairing_delegate.display_passkey_count_); 2816 EXPECT_EQ(1, pairing_delegate.display_passkey_count_);
2849 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); 2817 EXPECT_EQ(123456U, pairing_delegate.last_passkey_);
2850 EXPECT_EQ(1, pairing_delegate.keys_entered_count_); 2818 EXPECT_EQ(1, pairing_delegate.keys_entered_count_);
2851 EXPECT_EQ(0U, pairing_delegate.last_entered_); 2819 EXPECT_EQ(0U, pairing_delegate.last_entered_);
2852 2820
2853 EXPECT_TRUE(device->IsConnecting()); 2821 EXPECT_TRUE(device->IsConnecting());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2891 // And usually not connectable. 2859 // And usually not connectable.
2892 EXPECT_FALSE(device->IsConnectable()); 2860 EXPECT_FALSE(device->IsConnectable());
2893 2861
2894 // Make sure the trusted property has been set to true. 2862 // Make sure the trusted property has been set to true.
2895 bluez::FakeBluetoothDeviceClient::Properties* properties = 2863 bluez::FakeBluetoothDeviceClient::Properties* properties =
2896 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 2864 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
2897 bluez::FakeBluetoothDeviceClient::kDisplayPasskeyPath)); 2865 bluez::FakeBluetoothDeviceClient::kDisplayPasskeyPath));
2898 EXPECT_TRUE(properties->trusted.value()); 2866 EXPECT_TRUE(properties->trusted.value());
2899 } 2867 }
2900 2868
2901 TEST_F(BluetoothChromeOSTest, PairRequestPinCode) { 2869 TEST_F(BluetoothBlueZTest, PairRequestPinCode) {
2902 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 2870 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
2903 2871
2904 GetAdapter(); 2872 GetAdapter();
2905 DiscoverDevices(); 2873 DiscoverDevices();
2906 2874
2907 // Requires that the user enters a PIN for them. 2875 // Requires that the user enters a PIN for them.
2908 BluetoothDevice* device = adapter_->GetDevice( 2876 BluetoothDevice* device = adapter_->GetDevice(
2909 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); 2877 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress);
2910 ASSERT_TRUE(device != nullptr); 2878 ASSERT_TRUE(device != nullptr);
2911 ASSERT_FALSE(device->IsPaired()); 2879 ASSERT_FALSE(device->IsPaired());
2912 2880
2913 TestBluetoothAdapterObserver observer(adapter_); 2881 TestBluetoothAdapterObserver observer(adapter_);
2914 2882
2915 TestPairingDelegate pairing_delegate; 2883 TestPairingDelegate pairing_delegate;
2916 device->Connect(&pairing_delegate, GetCallback(), 2884 device->Connect(&pairing_delegate, GetCallback(),
2917 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2885 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2918 base::Unretained(this))); 2886 base::Unretained(this)));
2919 2887
2920 EXPECT_EQ(1, pairing_delegate.call_count_); 2888 EXPECT_EQ(1, pairing_delegate.call_count_);
2921 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); 2889 EXPECT_EQ(1, pairing_delegate.request_pincode_count_);
2922 EXPECT_TRUE(device->IsConnecting()); 2890 EXPECT_TRUE(device->IsConnecting());
2923 2891
2924 // Set the PIN. 2892 // Set the PIN.
2925 device->SetPinCode("1234"); 2893 device->SetPinCode("1234");
2926 message_loop_.Run(); 2894 message_loop_.Run();
2927 2895
(...skipping 17 matching lines...) Expand all
2945 // Non HID devices are always connectable. 2913 // Non HID devices are always connectable.
2946 EXPECT_TRUE(device->IsConnectable()); 2914 EXPECT_TRUE(device->IsConnectable());
2947 2915
2948 // Make sure the trusted property has been set to true. 2916 // Make sure the trusted property has been set to true.
2949 bluez::FakeBluetoothDeviceClient::Properties* properties = 2917 bluez::FakeBluetoothDeviceClient::Properties* properties =
2950 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 2918 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
2951 bluez::FakeBluetoothDeviceClient::kRequestPinCodePath)); 2919 bluez::FakeBluetoothDeviceClient::kRequestPinCodePath));
2952 EXPECT_TRUE(properties->trusted.value()); 2920 EXPECT_TRUE(properties->trusted.value());
2953 } 2921 }
2954 2922
2955 TEST_F(BluetoothChromeOSTest, PairConfirmPasskey) { 2923 TEST_F(BluetoothBlueZTest, PairConfirmPasskey) {
2956 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 2924 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
2957 2925
2958 GetAdapter(); 2926 GetAdapter();
2959 DiscoverDevices(); 2927 DiscoverDevices();
2960 2928
2961 // Requests that we confirm a displayed passkey. 2929 // Requests that we confirm a displayed passkey.
2962 BluetoothDevice* device = adapter_->GetDevice( 2930 BluetoothDevice* device = adapter_->GetDevice(
2963 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); 2931 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress);
2964 ASSERT_TRUE(device != nullptr); 2932 ASSERT_TRUE(device != nullptr);
2965 ASSERT_FALSE(device->IsPaired()); 2933 ASSERT_FALSE(device->IsPaired());
2966 2934
2967 TestBluetoothAdapterObserver observer(adapter_); 2935 TestBluetoothAdapterObserver observer(adapter_);
2968 2936
2969 TestPairingDelegate pairing_delegate; 2937 TestPairingDelegate pairing_delegate;
2970 device->Connect(&pairing_delegate, GetCallback(), 2938 device->Connect(&pairing_delegate, GetCallback(),
2971 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2939 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
2972 base::Unretained(this))); 2940 base::Unretained(this)));
2973 2941
2974 EXPECT_EQ(1, pairing_delegate.call_count_); 2942 EXPECT_EQ(1, pairing_delegate.call_count_);
2975 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); 2943 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_);
2976 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); 2944 EXPECT_EQ(123456U, pairing_delegate.last_passkey_);
2977 EXPECT_TRUE(device->IsConnecting()); 2945 EXPECT_TRUE(device->IsConnecting());
2978 2946
2979 // Confirm the passkey. 2947 // Confirm the passkey.
2980 device->ConfirmPairing(); 2948 device->ConfirmPairing();
2981 message_loop_.Run(); 2949 message_loop_.Run();
(...skipping 14 matching lines...) Expand all
2996 // Non HID devices are always connectable. 2964 // Non HID devices are always connectable.
2997 EXPECT_TRUE(device->IsConnectable()); 2965 EXPECT_TRUE(device->IsConnectable());
2998 2966
2999 // Make sure the trusted property has been set to true. 2967 // Make sure the trusted property has been set to true.
3000 bluez::FakeBluetoothDeviceClient::Properties* properties = 2968 bluez::FakeBluetoothDeviceClient::Properties* properties =
3001 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 2969 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
3002 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath)); 2970 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath));
3003 EXPECT_TRUE(properties->trusted.value()); 2971 EXPECT_TRUE(properties->trusted.value());
3004 } 2972 }
3005 2973
3006 TEST_F(BluetoothChromeOSTest, PairRequestPasskey) { 2974 TEST_F(BluetoothBlueZTest, PairRequestPasskey) {
3007 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 2975 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3008 2976
3009 GetAdapter(); 2977 GetAdapter();
3010 DiscoverDevices(); 2978 DiscoverDevices();
3011 2979
3012 // Requires that the user enters a Passkey, this would be some kind of 2980 // Requires that the user enters a Passkey, this would be some kind of
3013 // device that has a display, but doesn't use "just works" - maybe a car? 2981 // device that has a display, but doesn't use "just works" - maybe a car?
3014 BluetoothDevice* device = adapter_->GetDevice( 2982 BluetoothDevice* device = adapter_->GetDevice(
3015 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); 2983 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress);
3016 ASSERT_TRUE(device != nullptr); 2984 ASSERT_TRUE(device != nullptr);
3017 ASSERT_FALSE(device->IsPaired()); 2985 ASSERT_FALSE(device->IsPaired());
3018 2986
3019 TestBluetoothAdapterObserver observer(adapter_); 2987 TestBluetoothAdapterObserver observer(adapter_);
3020 2988
3021 TestPairingDelegate pairing_delegate; 2989 TestPairingDelegate pairing_delegate;
3022 device->Connect(&pairing_delegate, GetCallback(), 2990 device->Connect(&pairing_delegate, GetCallback(),
3023 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 2991 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3024 base::Unretained(this))); 2992 base::Unretained(this)));
3025 2993
3026 EXPECT_EQ(1, pairing_delegate.call_count_); 2994 EXPECT_EQ(1, pairing_delegate.call_count_);
3027 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); 2995 EXPECT_EQ(1, pairing_delegate.request_passkey_count_);
3028 EXPECT_TRUE(device->IsConnecting()); 2996 EXPECT_TRUE(device->IsConnecting());
3029 2997
3030 // Set the Passkey. 2998 // Set the Passkey.
3031 device->SetPasskey(1234); 2999 device->SetPasskey(1234);
3032 message_loop_.Run(); 3000 message_loop_.Run();
3033 3001
(...skipping 13 matching lines...) Expand all
3047 // Non HID devices are always connectable. 3015 // Non HID devices are always connectable.
3048 EXPECT_TRUE(device->IsConnectable()); 3016 EXPECT_TRUE(device->IsConnectable());
3049 3017
3050 // Make sure the trusted property has been set to true. 3018 // Make sure the trusted property has been set to true.
3051 bluez::FakeBluetoothDeviceClient::Properties* properties = 3019 bluez::FakeBluetoothDeviceClient::Properties* properties =
3052 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 3020 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
3053 bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); 3021 bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath));
3054 EXPECT_TRUE(properties->trusted.value()); 3022 EXPECT_TRUE(properties->trusted.value());
3055 } 3023 }
3056 3024
3057 TEST_F(BluetoothChromeOSTest, PairJustWorks) { 3025 TEST_F(BluetoothBlueZTest, PairJustWorks) {
3058 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3026 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3059 3027
3060 GetAdapter(); 3028 GetAdapter();
3061 DiscoverDevices(); 3029 DiscoverDevices();
3062 3030
3063 // Uses just-works pairing, since this is an outgoing pairing, no delegate 3031 // Uses just-works pairing, since this is an outgoing pairing, no delegate
3064 // interaction is required. 3032 // interaction is required.
3065 BluetoothDevice* device = 3033 BluetoothDevice* device =
3066 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kJustWorksAddress); 3034 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kJustWorksAddress);
3067 ASSERT_TRUE(device != nullptr); 3035 ASSERT_TRUE(device != nullptr);
3068 ASSERT_FALSE(device->IsPaired()); 3036 ASSERT_FALSE(device->IsPaired());
3069 3037
3070 TestBluetoothAdapterObserver observer(adapter_); 3038 TestBluetoothAdapterObserver observer(adapter_);
3071 3039
3072 TestPairingDelegate pairing_delegate; 3040 TestPairingDelegate pairing_delegate;
3073 device->Connect(&pairing_delegate, GetCallback(), 3041 device->Connect(&pairing_delegate, GetCallback(),
3074 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 3042 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3075 base::Unretained(this))); 3043 base::Unretained(this)));
3076 3044
3077 EXPECT_EQ(0, pairing_delegate.call_count_); 3045 EXPECT_EQ(0, pairing_delegate.call_count_);
3078 3046
3079 message_loop_.Run(); 3047 message_loop_.Run();
3080 3048
3081 EXPECT_EQ(1, callback_count_); 3049 EXPECT_EQ(1, callback_count_);
3082 EXPECT_EQ(0, error_callback_count_); 3050 EXPECT_EQ(0, error_callback_count_);
3083 3051
3084 // Two changes for connecting, one change for connected, one for paired and 3052 // Two changes for connecting, one change for connected, one for paired and
3085 // two for trusted (after pairing and connection). 3053 // two for trusted (after pairing and connection).
3086 EXPECT_EQ(6, observer.device_changed_count()); 3054 EXPECT_EQ(6, observer.device_changed_count());
3087 EXPECT_EQ(device, observer.last_device()); 3055 EXPECT_EQ(device, observer.last_device());
3088 3056
3089 EXPECT_TRUE(device->IsConnected()); 3057 EXPECT_TRUE(device->IsConnected());
3090 EXPECT_FALSE(device->IsConnecting()); 3058 EXPECT_FALSE(device->IsConnecting());
3091 3059
3092 EXPECT_TRUE(device->IsPaired()); 3060 EXPECT_TRUE(device->IsPaired());
3093 3061
3094 // Non HID devices are always connectable. 3062 // Non HID devices are always connectable.
3095 EXPECT_TRUE(device->IsConnectable()); 3063 EXPECT_TRUE(device->IsConnectable());
3096 3064
3097 // Make sure the trusted property has been set to true. 3065 // Make sure the trusted property has been set to true.
3098 bluez::FakeBluetoothDeviceClient::Properties* properties = 3066 bluez::FakeBluetoothDeviceClient::Properties* properties =
3099 fake_bluetooth_device_client_->GetProperties( 3067 fake_bluetooth_device_client_->GetProperties(
3100 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath)); 3068 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath));
3101 EXPECT_TRUE(properties->trusted.value()); 3069 EXPECT_TRUE(properties->trusted.value());
3102 } 3070 }
3103 3071
3104 TEST_F(BluetoothChromeOSTest, PairUnpairableDeviceFails) { 3072 TEST_F(BluetoothBlueZTest, PairUnpairableDeviceFails) {
3105 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3073 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3106 3074
3107 GetAdapter(); 3075 GetAdapter();
3108 DiscoverDevice(bluez::FakeBluetoothDeviceClient::kUnconnectableDeviceAddress); 3076 DiscoverDevice(bluez::FakeBluetoothDeviceClient::kUnconnectableDeviceAddress);
3109 3077
3110 BluetoothDevice* device = adapter_->GetDevice( 3078 BluetoothDevice* device = adapter_->GetDevice(
3111 bluez::FakeBluetoothDeviceClient::kUnpairableDeviceAddress); 3079 bluez::FakeBluetoothDeviceClient::kUnpairableDeviceAddress);
3112 ASSERT_TRUE(device != nullptr); 3080 ASSERT_TRUE(device != nullptr);
3113 ASSERT_FALSE(device->IsPaired()); 3081 ASSERT_FALSE(device->IsPaired());
3114 3082
3115 TestBluetoothAdapterObserver observer(adapter_); 3083 TestBluetoothAdapterObserver observer(adapter_);
3116 3084
3117 TestPairingDelegate pairing_delegate; 3085 TestPairingDelegate pairing_delegate;
3118 device->Connect(&pairing_delegate, GetCallback(), 3086 device->Connect(&pairing_delegate, GetCallback(),
3119 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 3087 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3120 base::Unretained(this))); 3088 base::Unretained(this)));
3121 3089
3122 EXPECT_EQ(0, pairing_delegate.call_count_); 3090 EXPECT_EQ(0, pairing_delegate.call_count_);
3123 EXPECT_TRUE(device->IsConnecting()); 3091 EXPECT_TRUE(device->IsConnecting());
3124 3092
3125 // Run the loop to get the error.. 3093 // Run the loop to get the error..
3126 message_loop_.Run(); 3094 message_loop_.Run();
3127 3095
3128 EXPECT_EQ(0, callback_count_); 3096 EXPECT_EQ(0, callback_count_);
3129 EXPECT_EQ(1, error_callback_count_); 3097 EXPECT_EQ(1, error_callback_count_);
3130 3098
3131 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_); 3099 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_);
3132 3100
3133 EXPECT_FALSE(device->IsConnected()); 3101 EXPECT_FALSE(device->IsConnected());
3134 EXPECT_FALSE(device->IsConnecting()); 3102 EXPECT_FALSE(device->IsConnecting());
3135 EXPECT_FALSE(device->IsPaired()); 3103 EXPECT_FALSE(device->IsPaired());
3136 } 3104 }
3137 3105
3138 TEST_F(BluetoothChromeOSTest, PairingFails) { 3106 TEST_F(BluetoothBlueZTest, PairingFails) {
3139 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3107 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3140 3108
3141 GetAdapter(); 3109 GetAdapter();
3142 DiscoverDevice(bluez::FakeBluetoothDeviceClient::kVanishingDeviceAddress); 3110 DiscoverDevice(bluez::FakeBluetoothDeviceClient::kVanishingDeviceAddress);
3143 3111
3144 // The vanishing device times out during pairing 3112 // The vanishing device times out during pairing
3145 BluetoothDevice* device = adapter_->GetDevice( 3113 BluetoothDevice* device = adapter_->GetDevice(
3146 bluez::FakeBluetoothDeviceClient::kVanishingDeviceAddress); 3114 bluez::FakeBluetoothDeviceClient::kVanishingDeviceAddress);
3147 ASSERT_TRUE(device != nullptr); 3115 ASSERT_TRUE(device != nullptr);
3148 ASSERT_FALSE(device->IsPaired()); 3116 ASSERT_FALSE(device->IsPaired());
3149 3117
3150 TestBluetoothAdapterObserver observer(adapter_); 3118 TestBluetoothAdapterObserver observer(adapter_);
3151 3119
3152 TestPairingDelegate pairing_delegate; 3120 TestPairingDelegate pairing_delegate;
3153 device->Connect(&pairing_delegate, GetCallback(), 3121 device->Connect(&pairing_delegate, GetCallback(),
3154 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 3122 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3155 base::Unretained(this))); 3123 base::Unretained(this)));
3156 3124
3157 EXPECT_EQ(0, pairing_delegate.call_count_); 3125 EXPECT_EQ(0, pairing_delegate.call_count_);
3158 EXPECT_TRUE(device->IsConnecting()); 3126 EXPECT_TRUE(device->IsConnecting());
3159 3127
3160 // Run the loop to get the error.. 3128 // Run the loop to get the error..
3161 message_loop_.Run(); 3129 message_loop_.Run();
3162 3130
3163 EXPECT_EQ(0, callback_count_); 3131 EXPECT_EQ(0, callback_count_);
3164 EXPECT_EQ(1, error_callback_count_); 3132 EXPECT_EQ(1, error_callback_count_);
3165 3133
3166 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_TIMEOUT, last_connect_error_); 3134 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_TIMEOUT, last_connect_error_);
3167 3135
3168 EXPECT_FALSE(device->IsConnected()); 3136 EXPECT_FALSE(device->IsConnected());
3169 EXPECT_FALSE(device->IsConnecting()); 3137 EXPECT_FALSE(device->IsConnecting());
3170 EXPECT_FALSE(device->IsPaired()); 3138 EXPECT_FALSE(device->IsPaired());
3171 } 3139 }
3172 3140
3173 TEST_F(BluetoothChromeOSTest, PairingFailsAtConnection) { 3141 TEST_F(BluetoothBlueZTest, PairingFailsAtConnection) {
3174 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3142 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3175 3143
3176 GetAdapter(); 3144 GetAdapter();
3177 DiscoverDevices(); 3145 DiscoverDevices();
3178 3146
3179 // Everything seems to go according to plan with the unconnectable device; 3147 // Everything seems to go according to plan with the unconnectable device;
3180 // it pairs, but then you can't make connections to it after. 3148 // it pairs, but then you can't make connections to it after.
3181 BluetoothDevice* device = adapter_->GetDevice( 3149 BluetoothDevice* device = adapter_->GetDevice(
3182 bluez::FakeBluetoothDeviceClient::kUnconnectableDeviceAddress); 3150 bluez::FakeBluetoothDeviceClient::kUnconnectableDeviceAddress);
3183 ASSERT_TRUE(device != nullptr); 3151 ASSERT_TRUE(device != nullptr);
3184 ASSERT_FALSE(device->IsPaired()); 3152 ASSERT_FALSE(device->IsPaired());
3185 3153
3186 TestBluetoothAdapterObserver observer(adapter_); 3154 TestBluetoothAdapterObserver observer(adapter_);
3187 3155
3188 TestPairingDelegate pairing_delegate; 3156 TestPairingDelegate pairing_delegate;
3189 device->Connect(&pairing_delegate, GetCallback(), 3157 device->Connect(&pairing_delegate, GetCallback(),
3190 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 3158 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3191 base::Unretained(this))); 3159 base::Unretained(this)));
3192 3160
3193 EXPECT_EQ(0, pairing_delegate.call_count_); 3161 EXPECT_EQ(0, pairing_delegate.call_count_);
3194 EXPECT_TRUE(device->IsConnecting()); 3162 EXPECT_TRUE(device->IsConnecting());
3195 3163
3196 message_loop_.Run(); 3164 message_loop_.Run();
3197 3165
3198 EXPECT_EQ(0, callback_count_); 3166 EXPECT_EQ(0, callback_count_);
3199 EXPECT_EQ(1, error_callback_count_); 3167 EXPECT_EQ(1, error_callback_count_);
3200 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_); 3168 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_);
3201 3169
3202 // Two changes for connecting, one for paired and one for trusted after 3170 // Two changes for connecting, one for paired and one for trusted after
3203 // pairing. The device should not be connected. 3171 // pairing. The device should not be connected.
3204 EXPECT_EQ(4, observer.device_changed_count()); 3172 EXPECT_EQ(4, observer.device_changed_count());
3205 EXPECT_EQ(device, observer.last_device()); 3173 EXPECT_EQ(device, observer.last_device());
3206 3174
3207 EXPECT_FALSE(device->IsConnected()); 3175 EXPECT_FALSE(device->IsConnected());
3208 EXPECT_FALSE(device->IsConnecting()); 3176 EXPECT_FALSE(device->IsConnecting());
3209 3177
3210 EXPECT_TRUE(device->IsPaired()); 3178 EXPECT_TRUE(device->IsPaired());
3211 3179
3212 // Make sure the trusted property has been set to true still (since pairing 3180 // Make sure the trusted property has been set to true still (since pairing
3213 // worked). 3181 // worked).
3214 bluez::FakeBluetoothDeviceClient::Properties* properties = 3182 bluez::FakeBluetoothDeviceClient::Properties* properties =
3215 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 3183 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
3216 bluez::FakeBluetoothDeviceClient::kUnconnectableDevicePath)); 3184 bluez::FakeBluetoothDeviceClient::kUnconnectableDevicePath));
3217 EXPECT_TRUE(properties->trusted.value()); 3185 EXPECT_TRUE(properties->trusted.value());
3218 } 3186 }
3219 3187
3220 TEST_F(BluetoothChromeOSTest, PairingRejectedAtPinCode) { 3188 TEST_F(BluetoothBlueZTest, PairingRejectedAtPinCode) {
3221 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3189 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3222 3190
3223 GetAdapter(); 3191 GetAdapter();
3224 DiscoverDevices(); 3192 DiscoverDevices();
3225 3193
3226 // Reject the pairing after we receive a request for the PIN code. 3194 // Reject the pairing after we receive a request for the PIN code.
3227 BluetoothDevice* device = adapter_->GetDevice( 3195 BluetoothDevice* device = adapter_->GetDevice(
3228 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); 3196 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress);
3229 ASSERT_TRUE(device != nullptr); 3197 ASSERT_TRUE(device != nullptr);
3230 ASSERT_FALSE(device->IsPaired()); 3198 ASSERT_FALSE(device->IsPaired());
3231 3199
3232 TestBluetoothAdapterObserver observer(adapter_); 3200 TestBluetoothAdapterObserver observer(adapter_);
3233 3201
3234 TestPairingDelegate pairing_delegate; 3202 TestPairingDelegate pairing_delegate;
3235 device->Connect(&pairing_delegate, GetCallback(), 3203 device->Connect(&pairing_delegate, GetCallback(),
3236 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 3204 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3237 base::Unretained(this))); 3205 base::Unretained(this)));
3238 3206
3239 EXPECT_EQ(1, pairing_delegate.call_count_); 3207 EXPECT_EQ(1, pairing_delegate.call_count_);
3240 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); 3208 EXPECT_EQ(1, pairing_delegate.request_pincode_count_);
3241 EXPECT_TRUE(device->IsConnecting()); 3209 EXPECT_TRUE(device->IsConnecting());
3242 3210
3243 // Reject the pairing. 3211 // Reject the pairing.
3244 device->RejectPairing(); 3212 device->RejectPairing();
3245 message_loop_.Run(); 3213 message_loop_.Run();
3246 3214
3247 EXPECT_EQ(0, callback_count_); 3215 EXPECT_EQ(0, callback_count_);
3248 EXPECT_EQ(1, error_callback_count_); 3216 EXPECT_EQ(1, error_callback_count_);
3249 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_); 3217 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_);
3250 3218
3251 // Should be no changes except connecting going true and false. 3219 // Should be no changes except connecting going true and false.
3252 EXPECT_EQ(2, observer.device_changed_count()); 3220 EXPECT_EQ(2, observer.device_changed_count());
3253 EXPECT_FALSE(device->IsConnected()); 3221 EXPECT_FALSE(device->IsConnected());
3254 EXPECT_FALSE(device->IsConnecting()); 3222 EXPECT_FALSE(device->IsConnecting());
3255 EXPECT_FALSE(device->IsPaired()); 3223 EXPECT_FALSE(device->IsPaired());
3256 } 3224 }
3257 3225
3258 TEST_F(BluetoothChromeOSTest, PairingCancelledAtPinCode) { 3226 TEST_F(BluetoothBlueZTest, PairingCancelledAtPinCode) {
3259 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3227 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3260 3228
3261 GetAdapter(); 3229 GetAdapter();
3262 DiscoverDevices(); 3230 DiscoverDevices();
3263 3231
3264 // Cancel the pairing after we receive a request for the PIN code. 3232 // Cancel the pairing after we receive a request for the PIN code.
3265 BluetoothDevice* device = adapter_->GetDevice( 3233 BluetoothDevice* device = adapter_->GetDevice(
3266 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); 3234 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress);
3267 ASSERT_TRUE(device != nullptr); 3235 ASSERT_TRUE(device != nullptr);
3268 ASSERT_FALSE(device->IsPaired()); 3236 ASSERT_FALSE(device->IsPaired());
3269 3237
3270 TestBluetoothAdapterObserver observer(adapter_); 3238 TestBluetoothAdapterObserver observer(adapter_);
3271 3239
3272 TestPairingDelegate pairing_delegate; 3240 TestPairingDelegate pairing_delegate;
3273 device->Connect(&pairing_delegate, GetCallback(), 3241 device->Connect(&pairing_delegate, GetCallback(),
3274 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 3242 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3275 base::Unretained(this))); 3243 base::Unretained(this)));
3276 3244
3277 EXPECT_EQ(1, pairing_delegate.call_count_); 3245 EXPECT_EQ(1, pairing_delegate.call_count_);
3278 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); 3246 EXPECT_EQ(1, pairing_delegate.request_pincode_count_);
3279 EXPECT_TRUE(device->IsConnecting()); 3247 EXPECT_TRUE(device->IsConnecting());
3280 3248
3281 // Cancel the pairing. 3249 // Cancel the pairing.
3282 device->CancelPairing(); 3250 device->CancelPairing();
3283 message_loop_.Run(); 3251 message_loop_.Run();
3284 3252
3285 EXPECT_EQ(0, callback_count_); 3253 EXPECT_EQ(0, callback_count_);
3286 EXPECT_EQ(1, error_callback_count_); 3254 EXPECT_EQ(1, error_callback_count_);
3287 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_); 3255 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_);
3288 3256
3289 // Should be no changes except connecting going true and false. 3257 // Should be no changes except connecting going true and false.
3290 EXPECT_EQ(2, observer.device_changed_count()); 3258 EXPECT_EQ(2, observer.device_changed_count());
3291 EXPECT_FALSE(device->IsConnected()); 3259 EXPECT_FALSE(device->IsConnected());
3292 EXPECT_FALSE(device->IsConnecting()); 3260 EXPECT_FALSE(device->IsConnecting());
3293 EXPECT_FALSE(device->IsPaired()); 3261 EXPECT_FALSE(device->IsPaired());
3294 } 3262 }
3295 3263
3296 TEST_F(BluetoothChromeOSTest, PairingRejectedAtPasskey) { 3264 TEST_F(BluetoothBlueZTest, PairingRejectedAtPasskey) {
3297 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3265 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3298 3266
3299 GetAdapter(); 3267 GetAdapter();
3300 DiscoverDevices(); 3268 DiscoverDevices();
3301 3269
3302 // Reject the pairing after we receive a request for the passkey. 3270 // Reject the pairing after we receive a request for the passkey.
3303 BluetoothDevice* device = adapter_->GetDevice( 3271 BluetoothDevice* device = adapter_->GetDevice(
3304 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); 3272 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress);
3305 ASSERT_TRUE(device != nullptr); 3273 ASSERT_TRUE(device != nullptr);
3306 ASSERT_FALSE(device->IsPaired()); 3274 ASSERT_FALSE(device->IsPaired());
3307 3275
3308 TestBluetoothAdapterObserver observer(adapter_); 3276 TestBluetoothAdapterObserver observer(adapter_);
3309 3277
3310 TestPairingDelegate pairing_delegate; 3278 TestPairingDelegate pairing_delegate;
3311 device->Connect(&pairing_delegate, GetCallback(), 3279 device->Connect(&pairing_delegate, GetCallback(),
3312 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 3280 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3313 base::Unretained(this))); 3281 base::Unretained(this)));
3314 3282
3315 EXPECT_EQ(1, pairing_delegate.call_count_); 3283 EXPECT_EQ(1, pairing_delegate.call_count_);
3316 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); 3284 EXPECT_EQ(1, pairing_delegate.request_passkey_count_);
3317 EXPECT_TRUE(device->IsConnecting()); 3285 EXPECT_TRUE(device->IsConnecting());
3318 3286
3319 // Reject the pairing. 3287 // Reject the pairing.
3320 device->RejectPairing(); 3288 device->RejectPairing();
3321 message_loop_.Run(); 3289 message_loop_.Run();
3322 3290
3323 EXPECT_EQ(0, callback_count_); 3291 EXPECT_EQ(0, callback_count_);
3324 EXPECT_EQ(1, error_callback_count_); 3292 EXPECT_EQ(1, error_callback_count_);
3325 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_); 3293 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_);
3326 3294
3327 // Should be no changes except connecting going true and false. 3295 // Should be no changes except connecting going true and false.
3328 EXPECT_EQ(2, observer.device_changed_count()); 3296 EXPECT_EQ(2, observer.device_changed_count());
3329 EXPECT_FALSE(device->IsConnected()); 3297 EXPECT_FALSE(device->IsConnected());
3330 EXPECT_FALSE(device->IsConnecting()); 3298 EXPECT_FALSE(device->IsConnecting());
3331 EXPECT_FALSE(device->IsPaired()); 3299 EXPECT_FALSE(device->IsPaired());
3332 } 3300 }
3333 3301
3334 TEST_F(BluetoothChromeOSTest, PairingCancelledAtPasskey) { 3302 TEST_F(BluetoothBlueZTest, PairingCancelledAtPasskey) {
3335 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3303 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3336 3304
3337 GetAdapter(); 3305 GetAdapter();
3338 DiscoverDevices(); 3306 DiscoverDevices();
3339 3307
3340 // Cancel the pairing after we receive a request for the passkey. 3308 // Cancel the pairing after we receive a request for the passkey.
3341 BluetoothDevice* device = adapter_->GetDevice( 3309 BluetoothDevice* device = adapter_->GetDevice(
3342 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); 3310 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress);
3343 ASSERT_TRUE(device != nullptr); 3311 ASSERT_TRUE(device != nullptr);
3344 ASSERT_FALSE(device->IsPaired()); 3312 ASSERT_FALSE(device->IsPaired());
3345 3313
3346 TestBluetoothAdapterObserver observer(adapter_); 3314 TestBluetoothAdapterObserver observer(adapter_);
3347 3315
3348 TestPairingDelegate pairing_delegate; 3316 TestPairingDelegate pairing_delegate;
3349 device->Connect(&pairing_delegate, GetCallback(), 3317 device->Connect(&pairing_delegate, GetCallback(),
3350 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 3318 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3351 base::Unretained(this))); 3319 base::Unretained(this)));
3352 3320
3353 EXPECT_EQ(1, pairing_delegate.call_count_); 3321 EXPECT_EQ(1, pairing_delegate.call_count_);
3354 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); 3322 EXPECT_EQ(1, pairing_delegate.request_passkey_count_);
3355 EXPECT_TRUE(device->IsConnecting()); 3323 EXPECT_TRUE(device->IsConnecting());
3356 3324
3357 // Cancel the pairing. 3325 // Cancel the pairing.
3358 device->CancelPairing(); 3326 device->CancelPairing();
3359 message_loop_.Run(); 3327 message_loop_.Run();
3360 3328
3361 EXPECT_EQ(0, callback_count_); 3329 EXPECT_EQ(0, callback_count_);
3362 EXPECT_EQ(1, error_callback_count_); 3330 EXPECT_EQ(1, error_callback_count_);
3363 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_); 3331 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_);
3364 3332
3365 // Should be no changes except connecting going true and false. 3333 // Should be no changes except connecting going true and false.
3366 EXPECT_EQ(2, observer.device_changed_count()); 3334 EXPECT_EQ(2, observer.device_changed_count());
3367 EXPECT_FALSE(device->IsConnected()); 3335 EXPECT_FALSE(device->IsConnected());
3368 EXPECT_FALSE(device->IsConnecting()); 3336 EXPECT_FALSE(device->IsConnecting());
3369 EXPECT_FALSE(device->IsPaired()); 3337 EXPECT_FALSE(device->IsPaired());
3370 } 3338 }
3371 3339
3372 TEST_F(BluetoothChromeOSTest, PairingRejectedAtConfirmation) { 3340 TEST_F(BluetoothBlueZTest, PairingRejectedAtConfirmation) {
3373 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3341 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3374 3342
3375 GetAdapter(); 3343 GetAdapter();
3376 DiscoverDevices(); 3344 DiscoverDevices();
3377 3345
3378 // Reject the pairing after we receive a request for passkey confirmation. 3346 // Reject the pairing after we receive a request for passkey confirmation.
3379 BluetoothDevice* device = adapter_->GetDevice( 3347 BluetoothDevice* device = adapter_->GetDevice(
3380 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); 3348 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress);
3381 ASSERT_TRUE(device != nullptr); 3349 ASSERT_TRUE(device != nullptr);
3382 ASSERT_FALSE(device->IsPaired()); 3350 ASSERT_FALSE(device->IsPaired());
3383 3351
3384 TestBluetoothAdapterObserver observer(adapter_); 3352 TestBluetoothAdapterObserver observer(adapter_);
3385 3353
3386 TestPairingDelegate pairing_delegate; 3354 TestPairingDelegate pairing_delegate;
3387 device->Connect(&pairing_delegate, GetCallback(), 3355 device->Connect(&pairing_delegate, GetCallback(),
3388 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 3356 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3389 base::Unretained(this))); 3357 base::Unretained(this)));
3390 3358
3391 EXPECT_EQ(1, pairing_delegate.call_count_); 3359 EXPECT_EQ(1, pairing_delegate.call_count_);
3392 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); 3360 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_);
3393 EXPECT_TRUE(device->IsConnecting()); 3361 EXPECT_TRUE(device->IsConnecting());
3394 3362
3395 // Reject the pairing. 3363 // Reject the pairing.
3396 device->RejectPairing(); 3364 device->RejectPairing();
3397 message_loop_.Run(); 3365 message_loop_.Run();
3398 3366
3399 EXPECT_EQ(0, callback_count_); 3367 EXPECT_EQ(0, callback_count_);
3400 EXPECT_EQ(1, error_callback_count_); 3368 EXPECT_EQ(1, error_callback_count_);
3401 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_); 3369 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_REJECTED, last_connect_error_);
3402 3370
3403 // Should be no changes except connecting going true and false. 3371 // Should be no changes except connecting going true and false.
3404 EXPECT_EQ(2, observer.device_changed_count()); 3372 EXPECT_EQ(2, observer.device_changed_count());
3405 EXPECT_FALSE(device->IsConnected()); 3373 EXPECT_FALSE(device->IsConnected());
3406 EXPECT_FALSE(device->IsConnecting()); 3374 EXPECT_FALSE(device->IsConnecting());
3407 EXPECT_FALSE(device->IsPaired()); 3375 EXPECT_FALSE(device->IsPaired());
3408 } 3376 }
3409 3377
3410 TEST_F(BluetoothChromeOSTest, PairingCancelledAtConfirmation) { 3378 TEST_F(BluetoothBlueZTest, PairingCancelledAtConfirmation) {
3411 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3379 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3412 3380
3413 GetAdapter(); 3381 GetAdapter();
3414 DiscoverDevices(); 3382 DiscoverDevices();
3415 3383
3416 // Cancel the pairing after we receive a request for the passkey. 3384 // Cancel the pairing after we receive a request for the passkey.
3417 BluetoothDevice* device = adapter_->GetDevice( 3385 BluetoothDevice* device = adapter_->GetDevice(
3418 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); 3386 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress);
3419 ASSERT_TRUE(device != nullptr); 3387 ASSERT_TRUE(device != nullptr);
3420 ASSERT_FALSE(device->IsPaired()); 3388 ASSERT_FALSE(device->IsPaired());
3421 3389
3422 TestBluetoothAdapterObserver observer(adapter_); 3390 TestBluetoothAdapterObserver observer(adapter_);
3423 3391
3424 TestPairingDelegate pairing_delegate; 3392 TestPairingDelegate pairing_delegate;
3425 device->Connect(&pairing_delegate, GetCallback(), 3393 device->Connect(&pairing_delegate, GetCallback(),
3426 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 3394 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3427 base::Unretained(this))); 3395 base::Unretained(this)));
3428 3396
3429 EXPECT_EQ(1, pairing_delegate.call_count_); 3397 EXPECT_EQ(1, pairing_delegate.call_count_);
3430 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); 3398 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_);
3431 EXPECT_TRUE(device->IsConnecting()); 3399 EXPECT_TRUE(device->IsConnecting());
3432 3400
3433 // Cancel the pairing. 3401 // Cancel the pairing.
3434 device->CancelPairing(); 3402 device->CancelPairing();
3435 message_loop_.Run(); 3403 message_loop_.Run();
3436 3404
3437 EXPECT_EQ(0, callback_count_); 3405 EXPECT_EQ(0, callback_count_);
3438 EXPECT_EQ(1, error_callback_count_); 3406 EXPECT_EQ(1, error_callback_count_);
3439 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_); 3407 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_);
3440 3408
3441 // Should be no changes except connecting going true and false. 3409 // Should be no changes except connecting going true and false.
3442 EXPECT_EQ(2, observer.device_changed_count()); 3410 EXPECT_EQ(2, observer.device_changed_count());
3443 EXPECT_FALSE(device->IsConnected()); 3411 EXPECT_FALSE(device->IsConnected());
3444 EXPECT_FALSE(device->IsConnecting()); 3412 EXPECT_FALSE(device->IsConnecting());
3445 EXPECT_FALSE(device->IsPaired()); 3413 EXPECT_FALSE(device->IsPaired());
3446 } 3414 }
3447 3415
3448 TEST_F(BluetoothChromeOSTest, PairingCancelledInFlight) { 3416 TEST_F(BluetoothBlueZTest, PairingCancelledInFlight) {
3449 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3417 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3450 3418
3451 GetAdapter(); 3419 GetAdapter();
3452 DiscoverDevices(); 3420 DiscoverDevices();
3453 3421
3454 // Cancel the pairing while we're waiting for the remote host. 3422 // Cancel the pairing while we're waiting for the remote host.
3455 BluetoothDevice* device = adapter_->GetDevice( 3423 BluetoothDevice* device = adapter_->GetDevice(
3456 bluez::FakeBluetoothDeviceClient::kLegacyAutopairAddress); 3424 bluez::FakeBluetoothDeviceClient::kLegacyAutopairAddress);
3457 ASSERT_TRUE(device != nullptr); 3425 ASSERT_TRUE(device != nullptr);
3458 ASSERT_FALSE(device->IsPaired()); 3426 ASSERT_FALSE(device->IsPaired());
3459 3427
3460 TestBluetoothAdapterObserver observer(adapter_); 3428 TestBluetoothAdapterObserver observer(adapter_);
3461 3429
3462 TestPairingDelegate pairing_delegate; 3430 TestPairingDelegate pairing_delegate;
3463 device->Connect(&pairing_delegate, GetCallback(), 3431 device->Connect(&pairing_delegate, GetCallback(),
3464 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 3432 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3465 base::Unretained(this))); 3433 base::Unretained(this)));
3466 3434
3467 EXPECT_EQ(0, pairing_delegate.call_count_); 3435 EXPECT_EQ(0, pairing_delegate.call_count_);
3468 EXPECT_TRUE(device->IsConnecting()); 3436 EXPECT_TRUE(device->IsConnecting());
3469 3437
3470 // Cancel the pairing. 3438 // Cancel the pairing.
3471 device->CancelPairing(); 3439 device->CancelPairing();
3472 message_loop_.Run(); 3440 message_loop_.Run();
3473 3441
3474 EXPECT_EQ(0, callback_count_); 3442 EXPECT_EQ(0, callback_count_);
3475 EXPECT_EQ(1, error_callback_count_); 3443 EXPECT_EQ(1, error_callback_count_);
3476 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_); 3444 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_CANCELED, last_connect_error_);
3477 3445
3478 // Should be no changes except connecting going true and false. 3446 // Should be no changes except connecting going true and false.
3479 EXPECT_EQ(2, observer.device_changed_count()); 3447 EXPECT_EQ(2, observer.device_changed_count());
3480 EXPECT_FALSE(device->IsConnected()); 3448 EXPECT_FALSE(device->IsConnected());
3481 EXPECT_FALSE(device->IsConnecting()); 3449 EXPECT_FALSE(device->IsConnecting());
3482 EXPECT_FALSE(device->IsPaired()); 3450 EXPECT_FALSE(device->IsPaired());
3483 } 3451 }
3484 3452
3485 TEST_F(BluetoothChromeOSTest, IncomingPairRequestPinCode) { 3453 TEST_F(BluetoothBlueZTest, IncomingPairRequestPinCode) {
3486 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3454 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3487 3455
3488 GetAdapter(); 3456 GetAdapter();
3489 3457
3490 TestPairingDelegate pairing_delegate; 3458 TestPairingDelegate pairing_delegate;
3491 adapter_->AddPairingDelegate( 3459 adapter_->AddPairingDelegate(
3492 &pairing_delegate, 3460 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
3493 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
3494 3461
3495 // Requires that we provide a PIN code. 3462 // Requires that we provide a PIN code.
3496 fake_bluetooth_device_client_->CreateDevice( 3463 fake_bluetooth_device_client_->CreateDevice(
3497 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 3464 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
3498 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath)); 3465 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath));
3499 BluetoothDevice* device = adapter_->GetDevice( 3466 BluetoothDevice* device = adapter_->GetDevice(
3500 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); 3467 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress);
3501 ASSERT_TRUE(device != nullptr); 3468 ASSERT_TRUE(device != nullptr);
3502 ASSERT_FALSE(device->IsPaired()); 3469 ASSERT_FALSE(device->IsPaired());
3503 3470
3504 TestBluetoothAdapterObserver observer(adapter_); 3471 TestBluetoothAdapterObserver observer(adapter_);
3505 3472
3506 fake_bluetooth_device_client_->SimulatePairing( 3473 fake_bluetooth_device_client_->SimulatePairing(
3507 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath), 3474 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath),
3508 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, 3475 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
3509 base::Unretained(this))); 3476 base::Unretained(this)));
3510 3477
3511 EXPECT_EQ(1, pairing_delegate.call_count_); 3478 EXPECT_EQ(1, pairing_delegate.call_count_);
3512 EXPECT_EQ(1, pairing_delegate.request_pincode_count_); 3479 EXPECT_EQ(1, pairing_delegate.request_pincode_count_);
3513 3480
3514 // Set the PIN. 3481 // Set the PIN.
3515 device->SetPinCode("1234"); 3482 device->SetPinCode("1234");
3516 message_loop_.Run(); 3483 message_loop_.Run();
3517 3484
3518 EXPECT_EQ(1, callback_count_); 3485 EXPECT_EQ(1, callback_count_);
3519 EXPECT_EQ(0, error_callback_count_); 3486 EXPECT_EQ(0, error_callback_count_);
3520 3487
3521 // One change for paired, and one for trusted. 3488 // One change for paired, and one for trusted.
3522 EXPECT_EQ(2, observer.device_changed_count()); 3489 EXPECT_EQ(2, observer.device_changed_count());
3523 EXPECT_EQ(device, observer.last_device()); 3490 EXPECT_EQ(device, observer.last_device());
3524 3491
3525 EXPECT_TRUE(device->IsPaired()); 3492 EXPECT_TRUE(device->IsPaired());
3526 3493
3527 // Make sure the trusted property has been set to true. 3494 // Make sure the trusted property has been set to true.
3528 bluez::FakeBluetoothDeviceClient::Properties* properties = 3495 bluez::FakeBluetoothDeviceClient::Properties* properties =
3529 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 3496 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
3530 bluez::FakeBluetoothDeviceClient::kRequestPinCodePath)); 3497 bluez::FakeBluetoothDeviceClient::kRequestPinCodePath));
3531 ASSERT_TRUE(properties->trusted.value()); 3498 ASSERT_TRUE(properties->trusted.value());
3532 3499
3533 // No pairing context should remain on the device. 3500 // No pairing context should remain on the device.
3534 BluetoothDeviceChromeOS* device_chromeos = 3501 BluetoothDeviceBlueZ* device_bluez =
3535 static_cast<BluetoothDeviceChromeOS*>(device); 3502 static_cast<BluetoothDeviceBlueZ*>(device);
3536 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); 3503 EXPECT_TRUE(device_bluez->GetPairing() == nullptr);
3537 } 3504 }
3538 3505
3539 TEST_F(BluetoothChromeOSTest, IncomingPairConfirmPasskey) { 3506 TEST_F(BluetoothBlueZTest, IncomingPairConfirmPasskey) {
3540 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3507 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3541 3508
3542 GetAdapter(); 3509 GetAdapter();
3543 3510
3544 TestPairingDelegate pairing_delegate; 3511 TestPairingDelegate pairing_delegate;
3545 adapter_->AddPairingDelegate( 3512 adapter_->AddPairingDelegate(
3546 &pairing_delegate, 3513 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
3547 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
3548 3514
3549 // Requests that we confirm a displayed passkey. 3515 // Requests that we confirm a displayed passkey.
3550 fake_bluetooth_device_client_->CreateDevice( 3516 fake_bluetooth_device_client_->CreateDevice(
3551 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 3517 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
3552 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath)); 3518 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath));
3553 BluetoothDevice* device = adapter_->GetDevice( 3519 BluetoothDevice* device = adapter_->GetDevice(
3554 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); 3520 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress);
3555 ASSERT_TRUE(device != nullptr); 3521 ASSERT_TRUE(device != nullptr);
3556 ASSERT_FALSE(device->IsPaired()); 3522 ASSERT_FALSE(device->IsPaired());
3557 3523
3558 TestBluetoothAdapterObserver observer(adapter_); 3524 TestBluetoothAdapterObserver observer(adapter_);
3559 3525
3560 fake_bluetooth_device_client_->SimulatePairing( 3526 fake_bluetooth_device_client_->SimulatePairing(
3561 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath), 3527 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath),
3562 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, 3528 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
3563 base::Unretained(this))); 3529 base::Unretained(this)));
3564 3530
3565 EXPECT_EQ(1, pairing_delegate.call_count_); 3531 EXPECT_EQ(1, pairing_delegate.call_count_);
3566 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_); 3532 EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_);
3567 EXPECT_EQ(123456U, pairing_delegate.last_passkey_); 3533 EXPECT_EQ(123456U, pairing_delegate.last_passkey_);
3568 3534
3569 // Confirm the passkey. 3535 // Confirm the passkey.
3570 device->ConfirmPairing(); 3536 device->ConfirmPairing();
3571 message_loop_.Run(); 3537 message_loop_.Run();
3572 3538
3573 EXPECT_EQ(1, callback_count_); 3539 EXPECT_EQ(1, callback_count_);
3574 EXPECT_EQ(0, error_callback_count_); 3540 EXPECT_EQ(0, error_callback_count_);
3575 3541
3576 // One change for paired, and one for trusted. 3542 // One change for paired, and one for trusted.
3577 EXPECT_EQ(2, observer.device_changed_count()); 3543 EXPECT_EQ(2, observer.device_changed_count());
3578 EXPECT_EQ(device, observer.last_device()); 3544 EXPECT_EQ(device, observer.last_device());
3579 3545
3580 EXPECT_TRUE(device->IsPaired()); 3546 EXPECT_TRUE(device->IsPaired());
3581 3547
3582 // Make sure the trusted property has been set to true. 3548 // Make sure the trusted property has been set to true.
3583 bluez::FakeBluetoothDeviceClient::Properties* properties = 3549 bluez::FakeBluetoothDeviceClient::Properties* properties =
3584 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 3550 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
3585 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath)); 3551 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath));
3586 ASSERT_TRUE(properties->trusted.value()); 3552 ASSERT_TRUE(properties->trusted.value());
3587 3553
3588 // No pairing context should remain on the device. 3554 // No pairing context should remain on the device.
3589 BluetoothDeviceChromeOS* device_chromeos = 3555 BluetoothDeviceBlueZ* device_bluez =
3590 static_cast<BluetoothDeviceChromeOS*>(device); 3556 static_cast<BluetoothDeviceBlueZ*>(device);
3591 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); 3557 EXPECT_TRUE(device_bluez->GetPairing() == nullptr);
3592 } 3558 }
3593 3559
3594 TEST_F(BluetoothChromeOSTest, IncomingPairRequestPasskey) { 3560 TEST_F(BluetoothBlueZTest, IncomingPairRequestPasskey) {
3595 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3561 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3596 3562
3597 GetAdapter(); 3563 GetAdapter();
3598 3564
3599 TestPairingDelegate pairing_delegate; 3565 TestPairingDelegate pairing_delegate;
3600 adapter_->AddPairingDelegate( 3566 adapter_->AddPairingDelegate(
3601 &pairing_delegate, 3567 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
3602 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
3603 3568
3604 // Requests that we provide a Passkey. 3569 // Requests that we provide a Passkey.
3605 fake_bluetooth_device_client_->CreateDevice( 3570 fake_bluetooth_device_client_->CreateDevice(
3606 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 3571 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
3607 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); 3572 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath));
3608 BluetoothDevice* device = adapter_->GetDevice( 3573 BluetoothDevice* device = adapter_->GetDevice(
3609 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); 3574 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress);
3610 ASSERT_TRUE(device != nullptr); 3575 ASSERT_TRUE(device != nullptr);
3611 ASSERT_FALSE(device->IsPaired()); 3576 ASSERT_FALSE(device->IsPaired());
3612 3577
3613 TestBluetoothAdapterObserver observer(adapter_); 3578 TestBluetoothAdapterObserver observer(adapter_);
3614 3579
3615 fake_bluetooth_device_client_->SimulatePairing( 3580 fake_bluetooth_device_client_->SimulatePairing(
3616 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath), 3581 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath),
3617 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, 3582 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
3618 base::Unretained(this))); 3583 base::Unretained(this)));
3619 3584
3620 EXPECT_EQ(1, pairing_delegate.call_count_); 3585 EXPECT_EQ(1, pairing_delegate.call_count_);
3621 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); 3586 EXPECT_EQ(1, pairing_delegate.request_passkey_count_);
3622 3587
3623 // Set the Passkey. 3588 // Set the Passkey.
3624 device->SetPasskey(1234); 3589 device->SetPasskey(1234);
3625 message_loop_.Run(); 3590 message_loop_.Run();
3626 3591
3627 EXPECT_EQ(1, callback_count_); 3592 EXPECT_EQ(1, callback_count_);
3628 EXPECT_EQ(0, error_callback_count_); 3593 EXPECT_EQ(0, error_callback_count_);
3629 3594
3630 // One change for paired, and one for trusted. 3595 // One change for paired, and one for trusted.
3631 EXPECT_EQ(2, observer.device_changed_count()); 3596 EXPECT_EQ(2, observer.device_changed_count());
3632 EXPECT_EQ(device, observer.last_device()); 3597 EXPECT_EQ(device, observer.last_device());
3633 3598
3634 EXPECT_TRUE(device->IsPaired()); 3599 EXPECT_TRUE(device->IsPaired());
3635 3600
3636 // Make sure the trusted property has been set to true. 3601 // Make sure the trusted property has been set to true.
3637 bluez::FakeBluetoothDeviceClient::Properties* properties = 3602 bluez::FakeBluetoothDeviceClient::Properties* properties =
3638 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 3603 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
3639 bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); 3604 bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath));
3640 ASSERT_TRUE(properties->trusted.value()); 3605 ASSERT_TRUE(properties->trusted.value());
3641 3606
3642 // No pairing context should remain on the device. 3607 // No pairing context should remain on the device.
3643 BluetoothDeviceChromeOS* device_chromeos = 3608 BluetoothDeviceBlueZ* device_bluez =
3644 static_cast<BluetoothDeviceChromeOS*>(device); 3609 static_cast<BluetoothDeviceBlueZ*>(device);
3645 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); 3610 EXPECT_TRUE(device_bluez->GetPairing() == nullptr);
3646 } 3611 }
3647 3612
3648 TEST_F(BluetoothChromeOSTest, IncomingPairJustWorks) { 3613 TEST_F(BluetoothBlueZTest, IncomingPairJustWorks) {
3649 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3614 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3650 3615
3651 GetAdapter(); 3616 GetAdapter();
3652 3617
3653 TestPairingDelegate pairing_delegate; 3618 TestPairingDelegate pairing_delegate;
3654 adapter_->AddPairingDelegate( 3619 adapter_->AddPairingDelegate(
3655 &pairing_delegate, 3620 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
3656 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
3657 3621
3658 // Uses just-works pairing so, sinec this an incoming pairing, require 3622 // Uses just-works pairing so, sinec this an incoming pairing, require
3659 // authorization from the user. 3623 // authorization from the user.
3660 fake_bluetooth_device_client_->CreateDevice( 3624 fake_bluetooth_device_client_->CreateDevice(
3661 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 3625 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
3662 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath)); 3626 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath));
3663 BluetoothDevice* device = 3627 BluetoothDevice* device =
3664 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kJustWorksAddress); 3628 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kJustWorksAddress);
3665 ASSERT_TRUE(device != nullptr); 3629 ASSERT_TRUE(device != nullptr);
3666 ASSERT_FALSE(device->IsPaired()); 3630 ASSERT_FALSE(device->IsPaired());
3667 3631
3668 TestBluetoothAdapterObserver observer(adapter_); 3632 TestBluetoothAdapterObserver observer(adapter_);
3669 3633
3670 fake_bluetooth_device_client_->SimulatePairing( 3634 fake_bluetooth_device_client_->SimulatePairing(
3671 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath), true, 3635 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath), true,
3672 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, 3636 GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
3673 base::Unretained(this))); 3637 base::Unretained(this)));
3674 3638
3675 EXPECT_EQ(1, pairing_delegate.call_count_); 3639 EXPECT_EQ(1, pairing_delegate.call_count_);
3676 EXPECT_EQ(1, pairing_delegate.authorize_pairing_count_); 3640 EXPECT_EQ(1, pairing_delegate.authorize_pairing_count_);
3677 3641
3678 // Confirm the pairing. 3642 // Confirm the pairing.
3679 device->ConfirmPairing(); 3643 device->ConfirmPairing();
3680 message_loop_.Run(); 3644 message_loop_.Run();
3681 3645
3682 EXPECT_EQ(1, callback_count_); 3646 EXPECT_EQ(1, callback_count_);
3683 EXPECT_EQ(0, error_callback_count_); 3647 EXPECT_EQ(0, error_callback_count_);
3684 3648
3685 // One change for paired, and one for trusted. 3649 // One change for paired, and one for trusted.
3686 EXPECT_EQ(2, observer.device_changed_count()); 3650 EXPECT_EQ(2, observer.device_changed_count());
3687 EXPECT_EQ(device, observer.last_device()); 3651 EXPECT_EQ(device, observer.last_device());
3688 3652
3689 EXPECT_TRUE(device->IsPaired()); 3653 EXPECT_TRUE(device->IsPaired());
3690 3654
3691 // Make sure the trusted property has been set to true. 3655 // Make sure the trusted property has been set to true.
3692 bluez::FakeBluetoothDeviceClient::Properties* properties = 3656 bluez::FakeBluetoothDeviceClient::Properties* properties =
3693 fake_bluetooth_device_client_->GetProperties( 3657 fake_bluetooth_device_client_->GetProperties(
3694 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath)); 3658 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath));
3695 ASSERT_TRUE(properties->trusted.value()); 3659 ASSERT_TRUE(properties->trusted.value());
3696 3660
3697 // No pairing context should remain on the device. 3661 // No pairing context should remain on the device.
3698 BluetoothDeviceChromeOS* device_chromeos = 3662 BluetoothDeviceBlueZ* device_bluez =
3699 static_cast<BluetoothDeviceChromeOS*>(device); 3663 static_cast<BluetoothDeviceBlueZ*>(device);
3700 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); 3664 EXPECT_TRUE(device_bluez->GetPairing() == nullptr);
3701 } 3665 }
3702 3666
3703 TEST_F(BluetoothChromeOSTest, IncomingPairRequestPinCodeWithoutDelegate) { 3667 TEST_F(BluetoothBlueZTest, IncomingPairRequestPinCodeWithoutDelegate) {
3704 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3668 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3705 3669
3706 GetAdapter(); 3670 GetAdapter();
3707 3671
3708 // Requires that we provide a PIN Code, without a pairing delegate, 3672 // Requires that we provide a PIN Code, without a pairing delegate,
3709 // that will be rejected. 3673 // that will be rejected.
3710 fake_bluetooth_device_client_->CreateDevice( 3674 fake_bluetooth_device_client_->CreateDevice(
3711 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 3675 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
3712 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath)); 3676 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath));
3713 BluetoothDevice* device = adapter_->GetDevice( 3677 BluetoothDevice* device = adapter_->GetDevice(
3714 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress); 3678 bluez::FakeBluetoothDeviceClient::kRequestPinCodeAddress);
3715 ASSERT_TRUE(device != nullptr); 3679 ASSERT_TRUE(device != nullptr);
3716 ASSERT_FALSE(device->IsPaired()); 3680 ASSERT_FALSE(device->IsPaired());
3717 3681
3718 TestBluetoothAdapterObserver observer(adapter_); 3682 TestBluetoothAdapterObserver observer(adapter_);
3719 3683
3720 fake_bluetooth_device_client_->SimulatePairing( 3684 fake_bluetooth_device_client_->SimulatePairing(
3721 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath), 3685 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPinCodePath),
3722 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, 3686 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
3723 base::Unretained(this))); 3687 base::Unretained(this)));
3724 3688
3725 message_loop_.Run(); 3689 message_loop_.Run();
3726 3690
3727 EXPECT_EQ(0, callback_count_); 3691 EXPECT_EQ(0, callback_count_);
3728 EXPECT_EQ(1, error_callback_count_); 3692 EXPECT_EQ(1, error_callback_count_);
3729 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); 3693 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_);
3730 3694
3731 // No changes should be observer. 3695 // No changes should be observer.
3732 EXPECT_EQ(0, observer.device_changed_count()); 3696 EXPECT_EQ(0, observer.device_changed_count());
3733 3697
3734 EXPECT_FALSE(device->IsPaired()); 3698 EXPECT_FALSE(device->IsPaired());
3735 3699
3736 // No pairing context should remain on the device. 3700 // No pairing context should remain on the device.
3737 BluetoothDeviceChromeOS* device_chromeos = 3701 BluetoothDeviceBlueZ* device_bluez =
3738 static_cast<BluetoothDeviceChromeOS*>(device); 3702 static_cast<BluetoothDeviceBlueZ*>(device);
3739 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); 3703 EXPECT_TRUE(device_bluez->GetPairing() == nullptr);
3740 } 3704 }
3741 3705
3742 TEST_F(BluetoothChromeOSTest, IncomingPairConfirmPasskeyWithoutDelegate) { 3706 TEST_F(BluetoothBlueZTest, IncomingPairConfirmPasskeyWithoutDelegate) {
3743 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3707 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3744 3708
3745 GetAdapter(); 3709 GetAdapter();
3746 3710
3747 // Requests that we confirm a displayed passkey, without a pairing delegate, 3711 // Requests that we confirm a displayed passkey, without a pairing delegate,
3748 // that will be rejected. 3712 // that will be rejected.
3749 fake_bluetooth_device_client_->CreateDevice( 3713 fake_bluetooth_device_client_->CreateDevice(
3750 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 3714 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
3751 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath)); 3715 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath));
3752 BluetoothDevice* device = adapter_->GetDevice( 3716 BluetoothDevice* device = adapter_->GetDevice(
3753 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress); 3717 bluez::FakeBluetoothDeviceClient::kConfirmPasskeyAddress);
3754 ASSERT_TRUE(device != nullptr); 3718 ASSERT_TRUE(device != nullptr);
3755 ASSERT_FALSE(device->IsPaired()); 3719 ASSERT_FALSE(device->IsPaired());
3756 3720
3757 TestBluetoothAdapterObserver observer(adapter_); 3721 TestBluetoothAdapterObserver observer(adapter_);
3758 3722
3759 fake_bluetooth_device_client_->SimulatePairing( 3723 fake_bluetooth_device_client_->SimulatePairing(
3760 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath), 3724 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kConfirmPasskeyPath),
3761 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, 3725 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
3762 base::Unretained(this))); 3726 base::Unretained(this)));
3763 3727
3764 message_loop_.Run(); 3728 message_loop_.Run();
3765 3729
3766 EXPECT_EQ(0, callback_count_); 3730 EXPECT_EQ(0, callback_count_);
3767 EXPECT_EQ(1, error_callback_count_); 3731 EXPECT_EQ(1, error_callback_count_);
3768 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); 3732 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_);
3769 3733
3770 // No changes should be observer. 3734 // No changes should be observer.
3771 EXPECT_EQ(0, observer.device_changed_count()); 3735 EXPECT_EQ(0, observer.device_changed_count());
3772 3736
3773 EXPECT_FALSE(device->IsPaired()); 3737 EXPECT_FALSE(device->IsPaired());
3774 3738
3775 // No pairing context should remain on the device. 3739 // No pairing context should remain on the device.
3776 BluetoothDeviceChromeOS* device_chromeos = 3740 BluetoothDeviceBlueZ* device_bluez =
3777 static_cast<BluetoothDeviceChromeOS*>(device); 3741 static_cast<BluetoothDeviceBlueZ*>(device);
3778 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); 3742 EXPECT_TRUE(device_bluez->GetPairing() == nullptr);
3779 } 3743 }
3780 3744
3781 TEST_F(BluetoothChromeOSTest, IncomingPairRequestPasskeyWithoutDelegate) { 3745 TEST_F(BluetoothBlueZTest, IncomingPairRequestPasskeyWithoutDelegate) {
3782 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3746 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3783 3747
3784 GetAdapter(); 3748 GetAdapter();
3785 3749
3786 // Requests that we provide a displayed passkey, without a pairing delegate, 3750 // Requests that we provide a displayed passkey, without a pairing delegate,
3787 // that will be rejected. 3751 // that will be rejected.
3788 fake_bluetooth_device_client_->CreateDevice( 3752 fake_bluetooth_device_client_->CreateDevice(
3789 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 3753 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
3790 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); 3754 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath));
3791 BluetoothDevice* device = adapter_->GetDevice( 3755 BluetoothDevice* device = adapter_->GetDevice(
3792 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); 3756 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress);
3793 ASSERT_TRUE(device != nullptr); 3757 ASSERT_TRUE(device != nullptr);
3794 ASSERT_FALSE(device->IsPaired()); 3758 ASSERT_FALSE(device->IsPaired());
3795 3759
3796 TestBluetoothAdapterObserver observer(adapter_); 3760 TestBluetoothAdapterObserver observer(adapter_);
3797 3761
3798 fake_bluetooth_device_client_->SimulatePairing( 3762 fake_bluetooth_device_client_->SimulatePairing(
3799 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath), 3763 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath),
3800 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, 3764 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
3801 base::Unretained(this))); 3765 base::Unretained(this)));
3802 3766
3803 message_loop_.Run(); 3767 message_loop_.Run();
3804 3768
3805 EXPECT_EQ(0, callback_count_); 3769 EXPECT_EQ(0, callback_count_);
3806 EXPECT_EQ(1, error_callback_count_); 3770 EXPECT_EQ(1, error_callback_count_);
3807 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); 3771 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_);
3808 3772
3809 // No changes should be observer. 3773 // No changes should be observer.
3810 EXPECT_EQ(0, observer.device_changed_count()); 3774 EXPECT_EQ(0, observer.device_changed_count());
3811 3775
3812 EXPECT_FALSE(device->IsPaired()); 3776 EXPECT_FALSE(device->IsPaired());
3813 3777
3814 // No pairing context should remain on the device. 3778 // No pairing context should remain on the device.
3815 BluetoothDeviceChromeOS* device_chromeos = 3779 BluetoothDeviceBlueZ* device_bluez =
3816 static_cast<BluetoothDeviceChromeOS*>(device); 3780 static_cast<BluetoothDeviceBlueZ*>(device);
3817 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); 3781 EXPECT_TRUE(device_bluez->GetPairing() == nullptr);
3818 } 3782 }
3819 3783
3820 TEST_F(BluetoothChromeOSTest, IncomingPairJustWorksWithoutDelegate) { 3784 TEST_F(BluetoothBlueZTest, IncomingPairJustWorksWithoutDelegate) {
3821 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3785 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3822 3786
3823 GetAdapter(); 3787 GetAdapter();
3824 3788
3825 // Uses just-works pairing and thus requires authorization for incoming 3789 // Uses just-works pairing and thus requires authorization for incoming
3826 // pairings, without a pairing delegate, that will be rejected. 3790 // pairings, without a pairing delegate, that will be rejected.
3827 fake_bluetooth_device_client_->CreateDevice( 3791 fake_bluetooth_device_client_->CreateDevice(
3828 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 3792 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
3829 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath)); 3793 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath));
3830 BluetoothDevice* device = 3794 BluetoothDevice* device =
3831 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kJustWorksAddress); 3795 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kJustWorksAddress);
3832 ASSERT_TRUE(device != nullptr); 3796 ASSERT_TRUE(device != nullptr);
3833 ASSERT_FALSE(device->IsPaired()); 3797 ASSERT_FALSE(device->IsPaired());
3834 3798
3835 TestBluetoothAdapterObserver observer(adapter_); 3799 TestBluetoothAdapterObserver observer(adapter_);
3836 3800
3837 fake_bluetooth_device_client_->SimulatePairing( 3801 fake_bluetooth_device_client_->SimulatePairing(
3838 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath), true, 3802 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kJustWorksPath), true,
3839 GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, 3803 GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
3840 base::Unretained(this))); 3804 base::Unretained(this)));
3841 3805
3842 message_loop_.Run(); 3806 message_loop_.Run();
3843 3807
3844 EXPECT_EQ(0, callback_count_); 3808 EXPECT_EQ(0, callback_count_);
3845 EXPECT_EQ(1, error_callback_count_); 3809 EXPECT_EQ(1, error_callback_count_);
3846 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_); 3810 EXPECT_EQ(bluetooth_device::kErrorAuthenticationRejected, last_client_error_);
3847 3811
3848 // No changes should be observer. 3812 // No changes should be observer.
3849 EXPECT_EQ(0, observer.device_changed_count()); 3813 EXPECT_EQ(0, observer.device_changed_count());
3850 3814
3851 EXPECT_FALSE(device->IsPaired()); 3815 EXPECT_FALSE(device->IsPaired());
3852 3816
3853 // No pairing context should remain on the device. 3817 // No pairing context should remain on the device.
3854 BluetoothDeviceChromeOS* device_chromeos = 3818 BluetoothDeviceBlueZ* device_bluez =
3855 static_cast<BluetoothDeviceChromeOS*>(device); 3819 static_cast<BluetoothDeviceBlueZ*>(device);
3856 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); 3820 EXPECT_TRUE(device_bluez->GetPairing() == nullptr);
3857 } 3821 }
3858 3822
3859 TEST_F(BluetoothChromeOSTest, RemovePairingDelegateDuringPairing) { 3823 TEST_F(BluetoothBlueZTest, RemovePairingDelegateDuringPairing) {
3860 fake_bluetooth_device_client_->SetSimulationIntervalMs(10); 3824 fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
3861 3825
3862 GetAdapter(); 3826 GetAdapter();
3863 3827
3864 TestPairingDelegate pairing_delegate; 3828 TestPairingDelegate pairing_delegate;
3865 adapter_->AddPairingDelegate( 3829 adapter_->AddPairingDelegate(
3866 &pairing_delegate, 3830 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
3867 BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
3868 3831
3869 // Requests that we provide a Passkey. 3832 // Requests that we provide a Passkey.
3870 fake_bluetooth_device_client_->CreateDevice( 3833 fake_bluetooth_device_client_->CreateDevice(
3871 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 3834 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
3872 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath)); 3835 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath));
3873 BluetoothDevice* device = adapter_->GetDevice( 3836 BluetoothDevice* device = adapter_->GetDevice(
3874 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress); 3837 bluez::FakeBluetoothDeviceClient::kRequestPasskeyAddress);
3875 ASSERT_TRUE(device != nullptr); 3838 ASSERT_TRUE(device != nullptr);
3876 ASSERT_FALSE(device->IsPaired()); 3839 ASSERT_FALSE(device->IsPaired());
3877 3840
3878 TestBluetoothAdapterObserver observer(adapter_); 3841 TestBluetoothAdapterObserver observer(adapter_);
3879 3842
3880 fake_bluetooth_device_client_->SimulatePairing( 3843 fake_bluetooth_device_client_->SimulatePairing(
3881 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath), 3844 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kRequestPasskeyPath),
3882 true, GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback, 3845 true, GetCallback(), base::Bind(&BluetoothBlueZTest::DBusErrorCallback,
3883 base::Unretained(this))); 3846 base::Unretained(this)));
3884 3847
3885 EXPECT_EQ(1, pairing_delegate.call_count_); 3848 EXPECT_EQ(1, pairing_delegate.call_count_);
3886 EXPECT_EQ(1, pairing_delegate.request_passkey_count_); 3849 EXPECT_EQ(1, pairing_delegate.request_passkey_count_);
3887 3850
3888 // A pairing context should now be set on the device. 3851 // A pairing context should now be set on the device.
3889 BluetoothDeviceChromeOS* device_chromeos = 3852 BluetoothDeviceBlueZ* device_bluez =
3890 static_cast<BluetoothDeviceChromeOS*>(device); 3853 static_cast<BluetoothDeviceBlueZ*>(device);
3891 ASSERT_TRUE(device_chromeos->GetPairing() != nullptr); 3854 ASSERT_TRUE(device_bluez->GetPairing() != nullptr);
3892 3855
3893 // Removing the pairing delegate should remove that pairing context. 3856 // Removing the pairing delegate should remove that pairing context.
3894 adapter_->RemovePairingDelegate(&pairing_delegate); 3857 adapter_->RemovePairingDelegate(&pairing_delegate);
3895 3858
3896 EXPECT_TRUE(device_chromeos->GetPairing() == nullptr); 3859 EXPECT_TRUE(device_bluez->GetPairing() == nullptr);
3897 3860
3898 // Set the Passkey, this should now have no effect since the pairing has 3861 // Set the Passkey, this should now have no effect since the pairing has
3899 // been, in-effect, cancelled 3862 // been, in-effect, cancelled
3900 device->SetPasskey(1234); 3863 device->SetPasskey(1234);
3901 3864
3902 EXPECT_EQ(0, callback_count_); 3865 EXPECT_EQ(0, callback_count_);
3903 EXPECT_EQ(0, error_callback_count_); 3866 EXPECT_EQ(0, error_callback_count_);
3904 EXPECT_EQ(0, observer.device_changed_count()); 3867 EXPECT_EQ(0, observer.device_changed_count());
3905 3868
3906 EXPECT_FALSE(device->IsPaired()); 3869 EXPECT_FALSE(device->IsPaired());
3907 } 3870 }
3908 3871
3909 TEST_F(BluetoothChromeOSTest, DeviceId) { 3872 TEST_F(BluetoothBlueZTest, DeviceId) {
3910 GetAdapter(); 3873 GetAdapter();
3911 3874
3912 // Use the built-in paired device for this test, grab its Properties 3875 // Use the built-in paired device for this test, grab its Properties
3913 // structure so we can adjust the underlying modalias property. 3876 // structure so we can adjust the underlying modalias property.
3914 BluetoothDevice* device = adapter_->GetDevice( 3877 BluetoothDevice* device = adapter_->GetDevice(
3915 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 3878 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
3916 bluez::FakeBluetoothDeviceClient::Properties* properties = 3879 bluez::FakeBluetoothDeviceClient::Properties* properties =
3917 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 3880 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
3918 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); 3881 bluez::FakeBluetoothDeviceClient::kPairedDevicePath));
3919 3882
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3954 3917
3955 // Unknown vendor specification identifier. 3918 // Unknown vendor specification identifier.
3956 properties->modalias.ReplaceValue("chrome:v00E0p2400d0400"); 3919 properties->modalias.ReplaceValue("chrome:v00E0p2400d0400");
3957 3920
3958 EXPECT_EQ(BluetoothDevice::VENDOR_ID_UNKNOWN, device->GetVendorIDSource()); 3921 EXPECT_EQ(BluetoothDevice::VENDOR_ID_UNKNOWN, device->GetVendorIDSource());
3959 EXPECT_EQ(0, device->GetVendorID()); 3922 EXPECT_EQ(0, device->GetVendorID());
3960 EXPECT_EQ(0, device->GetProductID()); 3923 EXPECT_EQ(0, device->GetProductID());
3961 EXPECT_EQ(0, device->GetDeviceID()); 3924 EXPECT_EQ(0, device->GetDeviceID());
3962 } 3925 }
3963 3926
3964 TEST_F(BluetoothChromeOSTest, GetConnectionInfoForDisconnectedDevice) { 3927 TEST_F(BluetoothBlueZTest, GetConnectionInfoForDisconnectedDevice) {
3965 GetAdapter(); 3928 GetAdapter();
3966 BluetoothDevice* device = adapter_->GetDevice( 3929 BluetoothDevice* device = adapter_->GetDevice(
3967 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 3930 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
3968 3931
3969 // Calling GetConnectionInfo for an unconnected device should return a result 3932 // Calling GetConnectionInfo for an unconnected device should return a result
3970 // in which all fields are filled with BluetoothDevice::kUnknownPower. 3933 // in which all fields are filled with BluetoothDevice::kUnknownPower.
3971 BluetoothDevice::ConnectionInfo conn_info(0, 0, 0); 3934 BluetoothDevice::ConnectionInfo conn_info(0, 0, 0);
3972 device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info)); 3935 device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info));
3973 int unknown_power = BluetoothDevice::kUnknownPower; 3936 int unknown_power = BluetoothDevice::kUnknownPower;
3974 EXPECT_NE(0, unknown_power); 3937 EXPECT_NE(0, unknown_power);
3975 EXPECT_EQ(unknown_power, conn_info.rssi); 3938 EXPECT_EQ(unknown_power, conn_info.rssi);
3976 EXPECT_EQ(unknown_power, conn_info.transmit_power); 3939 EXPECT_EQ(unknown_power, conn_info.transmit_power);
3977 EXPECT_EQ(unknown_power, conn_info.max_transmit_power); 3940 EXPECT_EQ(unknown_power, conn_info.max_transmit_power);
3978 } 3941 }
3979 3942
3980 TEST_F(BluetoothChromeOSTest, GetConnectionInfoForConnectedDevice) { 3943 TEST_F(BluetoothBlueZTest, GetConnectionInfoForConnectedDevice) {
3981 GetAdapter(); 3944 GetAdapter();
3982 BluetoothDevice* device = adapter_->GetDevice( 3945 BluetoothDevice* device = adapter_->GetDevice(
3983 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 3946 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
3984 3947
3985 device->Connect(nullptr, GetCallback(), 3948 device->Connect(nullptr, GetCallback(),
3986 base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback, 3949 base::Bind(&BluetoothBlueZTest::ConnectErrorCallback,
3987 base::Unretained(this))); 3950 base::Unretained(this)));
3988 EXPECT_TRUE(device->IsConnected()); 3951 EXPECT_TRUE(device->IsConnected());
3989 3952
3990 // Calling GetConnectionInfo for a connected device should return valid 3953 // Calling GetConnectionInfo for a connected device should return valid
3991 // results. 3954 // results.
3992 fake_bluetooth_device_client_->UpdateConnectionInfo(-10, 3, 4); 3955 fake_bluetooth_device_client_->UpdateConnectionInfo(-10, 3, 4);
3993 BluetoothDevice::ConnectionInfo conn_info; 3956 BluetoothDevice::ConnectionInfo conn_info;
3994 device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info)); 3957 device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info));
3995 EXPECT_EQ(-10, conn_info.rssi); 3958 EXPECT_EQ(-10, conn_info.rssi);
3996 EXPECT_EQ(3, conn_info.transmit_power); 3959 EXPECT_EQ(3, conn_info.transmit_power);
3997 EXPECT_EQ(4, conn_info.max_transmit_power); 3960 EXPECT_EQ(4, conn_info.max_transmit_power);
3998 } 3961 }
3999 3962
4000 // Verifies Shutdown shuts down the adapter as expected. 3963 // Verifies Shutdown shuts down the adapter as expected.
4001 TEST_F(BluetoothChromeOSTest, Shutdown) { 3964 TEST_F(BluetoothBlueZTest, Shutdown) {
4002 // Set up adapter. Set powered & discoverable, start discovery. 3965 // Set up adapter. Set powered & discoverable, start discovery.
4003 GetAdapter(); 3966 GetAdapter();
4004 adapter_->SetPowered(true, GetCallback(), GetErrorCallback()); 3967 adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
4005 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback()); 3968 adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback());
4006 adapter_->StartDiscoverySession( 3969 adapter_->StartDiscoverySession(
4007 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 3970 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
4008 base::Unretained(this)), 3971 base::Unretained(this)),
4009 GetErrorCallback()); 3972 GetErrorCallback());
4010 base::MessageLoop::current()->Run(); 3973 base::MessageLoop::current()->Run();
4011 ASSERT_EQ(3, callback_count_); 3974 ASSERT_EQ(3, callback_count_);
4012 ASSERT_EQ(0, error_callback_count_); 3975 ASSERT_EQ(0, error_callback_count_);
4013 callback_count_ = 0; 3976 callback_count_ = 0;
4014 3977
4015 TestPairingDelegate pairing_delegate; 3978 TestPairingDelegate pairing_delegate;
4016 adapter_->AddPairingDelegate( 3979 adapter_->AddPairingDelegate(
4017 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); 3980 &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
4018 3981
4019 // Validate running adapter state. 3982 // Validate running adapter state.
4020 EXPECT_NE("", adapter_->GetAddress()); 3983 EXPECT_NE("", adapter_->GetAddress());
4021 EXPECT_NE("", adapter_->GetName()); 3984 EXPECT_NE("", adapter_->GetName());
4022 EXPECT_TRUE(adapter_->IsInitialized()); 3985 EXPECT_TRUE(adapter_->IsInitialized());
4023 EXPECT_TRUE(adapter_->IsPresent()); 3986 EXPECT_TRUE(adapter_->IsPresent());
4024 EXPECT_TRUE(adapter_->IsPowered()); 3987 EXPECT_TRUE(adapter_->IsPowered());
4025 EXPECT_TRUE(adapter_->IsDiscoverable()); 3988 EXPECT_TRUE(adapter_->IsDiscoverable());
4026 EXPECT_TRUE(adapter_->IsDiscovering()); 3989 EXPECT_TRUE(adapter_->IsDiscovering());
4027 EXPECT_EQ(2U, adapter_->GetDevices().size()); 3990 EXPECT_EQ(2U, adapter_->GetDevices().size());
4028 EXPECT_NE(nullptr, 3991 EXPECT_NE(nullptr,
4029 adapter_->GetDevice( 3992 adapter_->GetDevice(
4030 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress)); 3993 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress));
4031 EXPECT_NE(dbus::ObjectPath(""), static_cast<BluetoothAdapterChromeOS*>( 3994 EXPECT_NE(dbus::ObjectPath(""),
4032 adapter_.get())->object_path()); 3995 static_cast<BluetoothAdapterBlueZ*>(adapter_.get())->object_path());
4033 3996
4034 // Shutdown 3997 // Shutdown
4035 adapter_->Shutdown(); 3998 adapter_->Shutdown();
4036 3999
4037 // Validate post shutdown state by calling all BluetoothAdapterChromeOS 4000 // Validate post shutdown state by calling all BluetoothAdapterBlueZ
4038 // members, in declaration order: 4001 // members, in declaration order:
4039 4002
4040 adapter_->Shutdown(); 4003 adapter_->Shutdown();
4041 // DeleteOnCorrectThread omitted as we don't want to delete in this test. 4004 // DeleteOnCorrectThread omitted as we don't want to delete in this test.
4042 { 4005 {
4043 TestBluetoothAdapterObserver observer(adapter_); // Calls AddObserver 4006 TestBluetoothAdapterObserver observer(adapter_); // Calls AddObserver
4044 } // ~TestBluetoothAdapterObserver calls RemoveObserver. 4007 } // ~TestBluetoothAdapterObserver calls RemoveObserver.
4045 EXPECT_EQ("", adapter_->GetAddress()); 4008 EXPECT_EQ("", adapter_->GetAddress());
4046 EXPECT_EQ("", adapter_->GetName()); 4009 EXPECT_EQ("", adapter_->GetName());
4047 4010
(...skipping 15 matching lines...) Expand all
4063 EXPECT_EQ(0, callback_count_); 4026 EXPECT_EQ(0, callback_count_);
4064 EXPECT_EQ(1, error_callback_count_--) << "SetDiscoverable error"; 4027 EXPECT_EQ(1, error_callback_count_--) << "SetDiscoverable error";
4065 4028
4066 EXPECT_FALSE(adapter_->IsDiscovering()); 4029 EXPECT_FALSE(adapter_->IsDiscovering());
4067 // CreateRfcommService will DCHECK after Shutdown(). 4030 // CreateRfcommService will DCHECK after Shutdown().
4068 // CreateL2capService will DCHECK after Shutdown(). 4031 // CreateL2capService will DCHECK after Shutdown().
4069 4032
4070 BluetoothAudioSink::Options audio_sink_options; 4033 BluetoothAudioSink::Options audio_sink_options;
4071 adapter_->RegisterAudioSink( 4034 adapter_->RegisterAudioSink(
4072 audio_sink_options, 4035 audio_sink_options,
4073 base::Bind(&BluetoothChromeOSTest::AudioSinkAcquiredCallback, 4036 base::Bind(&BluetoothBlueZTest::AudioSinkAcquiredCallback,
4074 base::Unretained(this)), 4037 base::Unretained(this)),
4075 base::Bind(&BluetoothChromeOSTest::AudioSinkErrorCallback, 4038 base::Bind(&BluetoothBlueZTest::AudioSinkErrorCallback,
4076 base::Unretained(this))); 4039 base::Unretained(this)));
4077 EXPECT_EQ(0, callback_count_); 4040 EXPECT_EQ(0, callback_count_);
4078 EXPECT_EQ(1, error_callback_count_--) << "RegisterAudioSink error"; 4041 EXPECT_EQ(1, error_callback_count_--) << "RegisterAudioSink error";
4079 4042
4080 BluetoothAdapterChromeOS* adapter_chrome_os = 4043 BluetoothAdapterBlueZ* adapter_chrome_os =
ortuno 2015/11/06 18:15:42 This should probably be renamed to "adapter" or "a
rkc 2015/11/25 00:48:16 Done.
4081 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); 4044 static_cast<BluetoothAdapterBlueZ*>(adapter_.get());
4082 EXPECT_EQ(nullptr, 4045 EXPECT_EQ(nullptr,
4083 adapter_chrome_os->GetDeviceWithPath(dbus::ObjectPath(""))); 4046 adapter_chrome_os->GetDeviceWithPath(dbus::ObjectPath("")));
4084 4047
4085 // Notify methods presume objects exist that are owned by the adapter and 4048 // Notify methods presume objects exist that are owned by the adapter and
4086 // destroyed in Shutdown(). Mocks are not attempted here that won't exist, 4049 // destroyed in Shutdown(). Mocks are not attempted here that won't exist,
4087 // as verified below by EXPECT_EQ(0U, adapter_->GetDevices().size()); 4050 // as verified below by EXPECT_EQ(0U, adapter_->GetDevices().size());
4088 // NotifyDeviceChanged 4051 // NotifyDeviceChanged
4089 // NotifyGattServiceAdded 4052 // NotifyGattServiceAdded
4090 // NotifyGattServiceRemoved 4053 // NotifyGattServiceRemoved
4091 // NotifyGattServiceChanged 4054 // NotifyGattServiceChanged
4092 // NotifyGattDiscoveryComplete 4055 // NotifyGattDiscoveryComplete
4093 // NotifyGattCharacteristicAdded 4056 // NotifyGattCharacteristicAdded
4094 // NotifyGattCharacteristicRemoved 4057 // NotifyGattCharacteristicRemoved
4095 // NotifyGattDescriptorAdded 4058 // NotifyGattDescriptorAdded
4096 // NotifyGattDescriptorRemoved 4059 // NotifyGattDescriptorRemoved
4097 // NotifyGattCharacteristicValueChanged 4060 // NotifyGattCharacteristicValueChanged
4098 // NotifyGattDescriptorValueChanged 4061 // NotifyGattDescriptorValueChanged
4099 4062
4100 EXPECT_EQ(dbus::ObjectPath(""), adapter_chrome_os->object_path()); 4063 EXPECT_EQ(dbus::ObjectPath(""), adapter_chrome_os->object_path());
4101 4064
4102 adapter_profile_ = nullptr; 4065 adapter_profile_ = nullptr;
4103 4066
4104 FakeBluetoothProfileServiceProviderDelegate profile_delegate; 4067 FakeBluetoothProfileServiceProviderDelegate profile_delegate;
4105 adapter_chrome_os->UseProfile( 4068 adapter_chrome_os->UseProfile(
4106 BluetoothUUID(), dbus::ObjectPath(""), 4069 BluetoothUUID(), dbus::ObjectPath(""),
4107 bluez::BluetoothProfileManagerClient::Options(), &profile_delegate, 4070 bluez::BluetoothProfileManagerClient::Options(), &profile_delegate,
4108 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, 4071 base::Bind(&BluetoothBlueZTest::ProfileRegisteredCallback,
4109 base::Unretained(this)), 4072 base::Unretained(this)),
4110 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, 4073 base::Bind(&BluetoothBlueZTest::ErrorCompletionCallback,
4111 base::Unretained(this))); 4074 base::Unretained(this)));
4112 4075
4113 EXPECT_FALSE(adapter_profile_) << "UseProfile error"; 4076 EXPECT_FALSE(adapter_profile_) << "UseProfile error";
4114 EXPECT_EQ(0, callback_count_) << "UseProfile error"; 4077 EXPECT_EQ(0, callback_count_) << "UseProfile error";
4115 EXPECT_EQ(1, error_callback_count_--) << "UseProfile error"; 4078 EXPECT_EQ(1, error_callback_count_--) << "UseProfile error";
4116 4079
4117 // Protected and private methods: 4080 // Protected and private methods:
4118 4081
4119 adapter_chrome_os->RemovePairingDelegateInternal(&pairing_delegate); 4082 adapter_chrome_os->RemovePairingDelegateInternal(&pairing_delegate);
4120 // AdapterAdded() invalid post Shutdown because it calls SetAdapter. 4083 // AdapterAdded() invalid post Shutdown because it calls SetAdapter.
4121 adapter_chrome_os->AdapterRemoved(dbus::ObjectPath("x")); 4084 adapter_chrome_os->AdapterRemoved(dbus::ObjectPath("x"));
4122 adapter_chrome_os->AdapterPropertyChanged(dbus::ObjectPath("x"), ""); 4085 adapter_chrome_os->AdapterPropertyChanged(dbus::ObjectPath("x"), "");
4123 adapter_chrome_os->DeviceAdded(dbus::ObjectPath("")); 4086 adapter_chrome_os->DeviceAdded(dbus::ObjectPath(""));
4124 adapter_chrome_os->DeviceRemoved(dbus::ObjectPath("")); 4087 adapter_chrome_os->DeviceRemoved(dbus::ObjectPath(""));
4125 adapter_chrome_os->DevicePropertyChanged(dbus::ObjectPath(""), ""); 4088 adapter_chrome_os->DevicePropertyChanged(dbus::ObjectPath(""), "");
4126 adapter_chrome_os->InputPropertyChanged(dbus::ObjectPath(""), ""); 4089 adapter_chrome_os->InputPropertyChanged(dbus::ObjectPath(""), "");
4127 // bluez::BluetoothAgentServiceProvider::Delegate omitted, dbus will be 4090 // bluez::BluetoothAgentServiceProvider::Delegate omitted, dbus will be
4128 // shutdown, 4091 // shutdown,
4129 // with the exception of Released. 4092 // with the exception of Released.
4130 adapter_chrome_os->Released(); 4093 adapter_chrome_os->Released();
4131 4094
4132 adapter_chrome_os->OnRegisterAgent(); 4095 adapter_chrome_os->OnRegisterAgent();
4133 adapter_chrome_os->OnRegisterAgentError("", ""); 4096 adapter_chrome_os->OnRegisterAgentError("", "");
4134 adapter_chrome_os->OnRequestDefaultAgent(); 4097 adapter_chrome_os->OnRequestDefaultAgent();
4135 adapter_chrome_os->OnRequestDefaultAgentError("", ""); 4098 adapter_chrome_os->OnRequestDefaultAgentError("", "");
4136 4099
4137 adapter_chrome_os->OnRegisterAudioSink( 4100 adapter_chrome_os->OnRegisterAudioSink(
4138 base::Bind(&BluetoothChromeOSTest::AudioSinkAcquiredCallback, 4101 base::Bind(&BluetoothBlueZTest::AudioSinkAcquiredCallback,
4139 base::Unretained(this)), 4102 base::Unretained(this)),
4140 base::Bind(&BluetoothChromeOSTest::AudioSinkErrorCallback, 4103 base::Bind(&BluetoothBlueZTest::AudioSinkErrorCallback,
4141 base::Unretained(this)), 4104 base::Unretained(this)),
4142 scoped_refptr<device::BluetoothAudioSink>()); 4105 scoped_refptr<device::BluetoothAudioSink>());
4143 EXPECT_EQ(0, callback_count_); 4106 EXPECT_EQ(0, callback_count_);
4144 EXPECT_EQ(1, error_callback_count_--) << "RegisterAudioSink error"; 4107 EXPECT_EQ(1, error_callback_count_--) << "RegisterAudioSink error";
4145 4108
4146 // GetPairing will DCHECK after Shutdown(). 4109 // GetPairing will DCHECK after Shutdown().
4147 // SetAdapter will DCHECK after Shutdown(). 4110 // SetAdapter will DCHECK after Shutdown().
4148 // SetDefaultAdapterName will DCHECK after Shutdown(). 4111 // SetDefaultAdapterName will DCHECK after Shutdown().
4149 // RemoveAdapter will DCHECK after Shutdown(). 4112 // RemoveAdapter will DCHECK after Shutdown().
4150 adapter_chrome_os->PoweredChanged(false); 4113 adapter_chrome_os->PoweredChanged(false);
(...skipping 25 matching lines...) Expand all
4176 // OnStopDiscovery tested in Shutdown_OnStopDiscovery 4139 // OnStopDiscovery tested in Shutdown_OnStopDiscovery
4177 // OnStopDiscoveryError tested in Shutdown_OnStopDiscoveryError 4140 // OnStopDiscoveryError tested in Shutdown_OnStopDiscoveryError
4178 4141
4179 adapter_profile_ = nullptr; 4142 adapter_profile_ = nullptr;
4180 4143
4181 // OnRegisterProfile SetProfileDelegate, OnRegisterProfileError, require 4144 // OnRegisterProfile SetProfileDelegate, OnRegisterProfileError, require
4182 // UseProfile to be set first, do so again here just before calling them. 4145 // UseProfile to be set first, do so again here just before calling them.
4183 adapter_chrome_os->UseProfile( 4146 adapter_chrome_os->UseProfile(
4184 BluetoothUUID(), dbus::ObjectPath(""), 4147 BluetoothUUID(), dbus::ObjectPath(""),
4185 bluez::BluetoothProfileManagerClient::Options(), &profile_delegate, 4148 bluez::BluetoothProfileManagerClient::Options(), &profile_delegate,
4186 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, 4149 base::Bind(&BluetoothBlueZTest::ProfileRegisteredCallback,
4187 base::Unretained(this)), 4150 base::Unretained(this)),
4188 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, 4151 base::Bind(&BluetoothBlueZTest::ErrorCompletionCallback,
4189 base::Unretained(this))); 4152 base::Unretained(this)));
4190 4153
4191 EXPECT_FALSE(adapter_profile_) << "UseProfile error"; 4154 EXPECT_FALSE(adapter_profile_) << "UseProfile error";
4192 EXPECT_EQ(0, callback_count_) << "UseProfile error"; 4155 EXPECT_EQ(0, callback_count_) << "UseProfile error";
4193 EXPECT_EQ(1, error_callback_count_--) << "UseProfile error"; 4156 EXPECT_EQ(1, error_callback_count_--) << "UseProfile error";
4194 4157
4195 adapter_chrome_os->SetProfileDelegate( 4158 adapter_chrome_os->SetProfileDelegate(
4196 BluetoothUUID(), dbus::ObjectPath(""), &profile_delegate, 4159 BluetoothUUID(), dbus::ObjectPath(""), &profile_delegate,
4197 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, 4160 base::Bind(&BluetoothBlueZTest::ProfileRegisteredCallback,
4198 base::Unretained(this)), 4161 base::Unretained(this)),
4199 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, 4162 base::Bind(&BluetoothBlueZTest::ErrorCompletionCallback,
4200 base::Unretained(this))); 4163 base::Unretained(this)));
4201 EXPECT_EQ(0, callback_count_) << "SetProfileDelegate error"; 4164 EXPECT_EQ(0, callback_count_) << "SetProfileDelegate error";
4202 EXPECT_EQ(1, error_callback_count_--) << "SetProfileDelegate error"; 4165 EXPECT_EQ(1, error_callback_count_--) << "SetProfileDelegate error";
4203 4166
4204 adapter_chrome_os->OnRegisterProfileError(BluetoothUUID(), "", ""); 4167 adapter_chrome_os->OnRegisterProfileError(BluetoothUUID(), "", "");
4205 EXPECT_EQ(0, callback_count_) << "OnRegisterProfileError error"; 4168 EXPECT_EQ(0, callback_count_) << "OnRegisterProfileError error";
4206 EXPECT_EQ(0, error_callback_count_) << "OnRegisterProfileError error"; 4169 EXPECT_EQ(0, error_callback_count_) << "OnRegisterProfileError error";
4207 4170
4208 adapter_chrome_os->ProcessQueuedDiscoveryRequests(); 4171 adapter_chrome_os->ProcessQueuedDiscoveryRequests();
4209 4172
4210 // From BluetoothAdapater: 4173 // From BluetoothAdapater:
4211 4174
4212 adapter_->StartDiscoverySession( 4175 adapter_->StartDiscoverySession(
4213 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 4176 base::Bind(&BluetoothBlueZTest::DiscoverySessionCallback,
4214 base::Unretained(this)), 4177 base::Unretained(this)),
4215 GetErrorCallback()); 4178 GetErrorCallback());
4216 EXPECT_EQ(0, callback_count_) << "StartDiscoverySession error"; 4179 EXPECT_EQ(0, callback_count_) << "StartDiscoverySession error";
4217 EXPECT_EQ(1, error_callback_count_--) << "StartDiscoverySession error"; 4180 EXPECT_EQ(1, error_callback_count_--) << "StartDiscoverySession error";
4218 4181
4219 EXPECT_EQ(0U, adapter_->GetDevices().size()); 4182 EXPECT_EQ(0U, adapter_->GetDevices().size());
4220 EXPECT_EQ(nullptr, 4183 EXPECT_EQ(nullptr,
4221 adapter_->GetDevice( 4184 adapter_->GetDevice(
4222 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress)); 4185 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress));
4223 TestPairingDelegate pairing_delegate2; 4186 TestPairingDelegate pairing_delegate2;
4224 adapter_->AddPairingDelegate( 4187 adapter_->AddPairingDelegate(
4225 &pairing_delegate2, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); 4188 &pairing_delegate2, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
4226 adapter_->RemovePairingDelegate(&pairing_delegate2); 4189 adapter_->RemovePairingDelegate(&pairing_delegate2);
4227 } 4190 }
4228 4191
4229 // Verifies post-Shutdown of discovery sessions and OnStartDiscovery. 4192 // Verifies post-Shutdown of discovery sessions and OnStartDiscovery.
4230 TEST_F(BluetoothChromeOSTest, Shutdown_OnStartDiscovery) { 4193 TEST_F(BluetoothBlueZTest, Shutdown_OnStartDiscovery) {
4231 const int kNumberOfDiscoverySessions = 10; 4194 const int kNumberOfDiscoverySessions = 10;
4232 GetAdapter(); 4195 GetAdapter();
4233 BluetoothAdapterChromeOS* adapter_chrome_os = 4196 BluetoothAdapterBlueZ* adapter_chrome_os =
4234 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); 4197 static_cast<BluetoothAdapterBlueZ*>(adapter_.get());
4235 4198
4236 for (int i = 0; i < kNumberOfDiscoverySessions; i++) { 4199 for (int i = 0; i < kNumberOfDiscoverySessions; i++) {
4237 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), 4200 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(),
4238 GetDiscoveryErrorCallback()); 4201 GetDiscoveryErrorCallback());
4239 } 4202 }
4240 adapter_->Shutdown(); 4203 adapter_->Shutdown();
4241 adapter_chrome_os->OnStartDiscovery(GetCallback(), 4204 adapter_chrome_os->OnStartDiscovery(GetCallback(),
4242 GetDiscoveryErrorCallback()); 4205 GetDiscoveryErrorCallback());
4243 4206
4244 EXPECT_EQ(0, callback_count_); 4207 EXPECT_EQ(0, callback_count_);
4245 EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_); 4208 EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_);
4246 } 4209 }
4247 4210
4248 // Verifies post-Shutdown of discovery sessions and OnStartDiscoveryError. 4211 // Verifies post-Shutdown of discovery sessions and OnStartDiscoveryError.
4249 TEST_F(BluetoothChromeOSTest, Shutdown_OnStartDiscoveryError) { 4212 TEST_F(BluetoothBlueZTest, Shutdown_OnStartDiscoveryError) {
4250 const int kNumberOfDiscoverySessions = 10; 4213 const int kNumberOfDiscoverySessions = 10;
4251 GetAdapter(); 4214 GetAdapter();
4252 BluetoothAdapterChromeOS* adapter_chrome_os = 4215 BluetoothAdapterBlueZ* adapter_chrome_os =
4253 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); 4216 static_cast<BluetoothAdapterBlueZ*>(adapter_.get());
4254 4217
4255 for (int i = 0; i < kNumberOfDiscoverySessions; i++) { 4218 for (int i = 0; i < kNumberOfDiscoverySessions; i++) {
4256 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), 4219 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(),
4257 GetDiscoveryErrorCallback()); 4220 GetDiscoveryErrorCallback());
4258 } 4221 }
4259 adapter_->Shutdown(); 4222 adapter_->Shutdown();
4260 adapter_chrome_os->OnStartDiscoveryError(GetCallback(), 4223 adapter_chrome_os->OnStartDiscoveryError(GetCallback(),
4261 GetDiscoveryErrorCallback(), "", ""); 4224 GetDiscoveryErrorCallback(), "", "");
4262 4225
4263 EXPECT_EQ(0, callback_count_); 4226 EXPECT_EQ(0, callback_count_);
4264 EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_); 4227 EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_);
4265 } 4228 }
4266 4229
4267 // Verifies post-Shutdown of discovery sessions and OnStartDiscovery. 4230 // Verifies post-Shutdown of discovery sessions and OnStartDiscovery.
4268 TEST_F(BluetoothChromeOSTest, Shutdown_OnStopDiscovery) { 4231 TEST_F(BluetoothBlueZTest, Shutdown_OnStopDiscovery) {
4269 const int kNumberOfDiscoverySessions = 10; 4232 const int kNumberOfDiscoverySessions = 10;
4270 GetAdapter(); 4233 GetAdapter();
4271 BluetoothAdapterChromeOS* adapter_chrome_os = 4234 BluetoothAdapterBlueZ* adapter_chrome_os =
4272 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); 4235 static_cast<BluetoothAdapterBlueZ*>(adapter_.get());
4273 4236
4274 // In order to queue up discovery sessions before an OnStopDiscovery call 4237 // In order to queue up discovery sessions before an OnStopDiscovery call
4275 // RemoveDiscoverySession must be called, so Add, Start, and Remove: 4238 // RemoveDiscoverySession must be called, so Add, Start, and Remove:
4276 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), 4239 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(),
4277 GetDiscoveryErrorCallback()); 4240 GetDiscoveryErrorCallback());
4278 adapter_chrome_os->OnStartDiscovery(GetCallback(), 4241 adapter_chrome_os->OnStartDiscovery(GetCallback(),
4279 GetDiscoveryErrorCallback()); 4242 GetDiscoveryErrorCallback());
4280 adapter_chrome_os->RemoveDiscoverySession(nullptr, GetCallback(), 4243 adapter_chrome_os->RemoveDiscoverySession(nullptr, GetCallback(),
4281 GetDiscoveryErrorCallback()); 4244 GetDiscoveryErrorCallback());
4282 callback_count_ = 0; 4245 callback_count_ = 0;
4283 error_callback_count_ = 0; 4246 error_callback_count_ = 0;
4284 // Can now queue discovery sessions while waiting for OnStopDiscovery. 4247 // Can now queue discovery sessions while waiting for OnStopDiscovery.
4285 for (int i = 0; i < kNumberOfDiscoverySessions; i++) { 4248 for (int i = 0; i < kNumberOfDiscoverySessions; i++) {
4286 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), 4249 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(),
4287 GetDiscoveryErrorCallback()); 4250 GetDiscoveryErrorCallback());
4288 } 4251 }
4289 adapter_->Shutdown(); 4252 adapter_->Shutdown();
4290 adapter_chrome_os->OnStopDiscovery(GetCallback()); 4253 adapter_chrome_os->OnStopDiscovery(GetCallback());
4291 4254
4292 // 1 successful stopped discovery from RemoveDiscoverySession, and 4255 // 1 successful stopped discovery from RemoveDiscoverySession, and
4293 // kNumberOfDiscoverySessions errors from AddDiscoverySession/OnStopDiscovery. 4256 // kNumberOfDiscoverySessions errors from AddDiscoverySession/OnStopDiscovery.
4294 EXPECT_EQ(1, callback_count_); 4257 EXPECT_EQ(1, callback_count_);
4295 EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_); 4258 EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_);
4296 } 4259 }
4297 4260
4298 // Verifies post-Shutdown of discovery sessions and OnStopDiscoveryError. 4261 // Verifies post-Shutdown of discovery sessions and OnStopDiscoveryError.
4299 TEST_F(BluetoothChromeOSTest, Shutdown_OnStopDiscoveryError) { 4262 TEST_F(BluetoothBlueZTest, Shutdown_OnStopDiscoveryError) {
4300 const int kNumberOfDiscoverySessions = 10; 4263 const int kNumberOfDiscoverySessions = 10;
4301 GetAdapter(); 4264 GetAdapter();
4302 BluetoothAdapterChromeOS* adapter_chrome_os = 4265 BluetoothAdapterBlueZ* adapter_chrome_os =
4303 static_cast<BluetoothAdapterChromeOS*>(adapter_.get()); 4266 static_cast<BluetoothAdapterBlueZ*>(adapter_.get());
4304 4267
4305 // In order to queue up discovery sessions before an OnStopDiscoveryError call 4268 // In order to queue up discovery sessions before an OnStopDiscoveryError call
4306 // RemoveDiscoverySession must be called, so Add, Start, and Remove: 4269 // RemoveDiscoverySession must be called, so Add, Start, and Remove:
4307 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), 4270 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(),
4308 GetDiscoveryErrorCallback()); 4271 GetDiscoveryErrorCallback());
4309 adapter_chrome_os->OnStartDiscovery(GetCallback(), 4272 adapter_chrome_os->OnStartDiscovery(GetCallback(),
4310 GetDiscoveryErrorCallback()); 4273 GetDiscoveryErrorCallback());
4311 adapter_chrome_os->RemoveDiscoverySession(nullptr, GetCallback(), 4274 adapter_chrome_os->RemoveDiscoverySession(nullptr, GetCallback(),
4312 GetDiscoveryErrorCallback()); 4275 GetDiscoveryErrorCallback());
4313 callback_count_ = 0; 4276 callback_count_ = 0;
4314 error_callback_count_ = 0; 4277 error_callback_count_ = 0;
4315 // Can now queue discovery sessions while waiting for OnStopDiscoveryError. 4278 // Can now queue discovery sessions while waiting for OnStopDiscoveryError.
4316 for (int i = 0; i < kNumberOfDiscoverySessions; i++) { 4279 for (int i = 0; i < kNumberOfDiscoverySessions; i++) {
4317 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(), 4280 adapter_chrome_os->AddDiscoverySession(nullptr, GetCallback(),
4318 GetDiscoveryErrorCallback()); 4281 GetDiscoveryErrorCallback());
4319 } 4282 }
4320 adapter_->Shutdown(); 4283 adapter_->Shutdown();
4321 adapter_chrome_os->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", ""); 4284 adapter_chrome_os->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", "");
4322 4285
4323 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, 4286 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError,
4324 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. 4287 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession.
4325 EXPECT_EQ(0, callback_count_); 4288 EXPECT_EQ(0, callback_count_);
4326 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); 4289 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_);
4327 } 4290 }
4328 4291
4329 } // namespace chromeos 4292 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698