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

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

Issue 1246913006: Bringing 4 more BluetoothTest.* unit tests to Mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scheibtest
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/memory/ref_counted.h" 6 #include "base/memory/ref_counted.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "device/bluetooth/bluetooth_adapter.h" 8 #include "device/bluetooth/bluetooth_adapter.h"
9 #include "device/bluetooth/bluetooth_device.h" 9 #include "device/bluetooth/bluetooth_device.h"
10 #include "device/bluetooth/bluetooth_discovery_session.h" 10 #include "device/bluetooth/bluetooth_discovery_session.h"
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 465
466 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); 466 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback());
467 base::RunLoop().RunUntilIdle(); 467 base::RunLoop().RunUntilIdle();
468 EXPECT_EQ(1, callback_count_--); 468 EXPECT_EQ(1, callback_count_--);
469 EXPECT_EQ(0, error_callback_count_); 469 EXPECT_EQ(0, error_callback_count_);
470 EXPECT_FALSE(adapter_->IsDiscovering()); 470 EXPECT_FALSE(adapter_->IsDiscovering());
471 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); 471 EXPECT_FALSE(discovery_sessions_[0]->IsActive());
472 } 472 }
473 #endif // defined(OS_ANDROID) 473 #endif // defined(OS_ANDROID)
474 474
475 #if defined(OS_ANDROID) 475 #if defined(OS_ANDROID) || defined(OS_MACOSX)
476 // Discovers a device. 476 // Discovers a device.
477 TEST_F(BluetoothTest, DiscoverDevice) { 477 TEST_F(BluetoothTest, DiscoverLowEnergyDevice) {
478 if (!PlatformSupportsLowEnergy()) {
479 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
480 return;
481 }
478 InitWithFakeAdapter(); 482 InitWithFakeAdapter();
479 TestBluetoothAdapterObserver observer(adapter_); 483 TestBluetoothAdapterObserver observer(adapter_);
480 484
481 // Start discovery and find a device. 485 // Start discovery and find a device.
482 adapter_->StartDiscoverySession(GetDiscoverySessionCallback(), 486 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(
483 GetErrorCallback()); 487 new BluetoothDiscoveryFilter(
488 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE));
489 adapter_->StartDiscoverySessionWithFilter(discovery_filter.Pass(),
490 GetDiscoverySessionCallback(),
491 GetErrorCallback());
484 base::RunLoop().RunUntilIdle(); 492 base::RunLoop().RunUntilIdle();
485 DiscoverLowEnergyDevice(1); 493 DiscoverLowEnergyDevice(1);
486 base::RunLoop().RunUntilIdle(); 494 base::RunLoop().RunUntilIdle();
487 EXPECT_EQ(1, observer.device_added_count()); 495 EXPECT_EQ(1, observer.device_added_count());
488 BluetoothDevice* device = adapter_->GetDevice(observer.last_device_address()); 496 BluetoothDevice* device = adapter_->GetDevice(observer.last_device_address());
489 EXPECT_TRUE(device); 497 EXPECT_TRUE(device);
490 } 498 }
491 #endif // defined(OS_ANDROID) 499 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
492 500
493 #if defined(OS_ANDROID) 501 #if defined(OS_ANDROID) || defined(OS_MACOSX)
494 // Discovers the same device multiple times. 502 // Discovers the same device multiple times.
495 TEST_F(BluetoothTest, DiscoverDeviceTwice) { 503 TEST_F(BluetoothTest, DiscoverLowEnergyDeviceTwice) {
504 if (!PlatformSupportsLowEnergy()) {
505 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
506 return;
507 }
496 InitWithFakeAdapter(); 508 InitWithFakeAdapter();
497 TestBluetoothAdapterObserver observer(adapter_); 509 TestBluetoothAdapterObserver observer(adapter_);
498 510
499 // Start discovery and find a device. 511 // Start discovery and find a device.
500 adapter_->StartDiscoverySession(GetDiscoverySessionCallback(), 512 adapter_->StartDiscoverySession(GetDiscoverySessionCallback(),
501 GetErrorCallback()); 513 GetErrorCallback());
502 base::RunLoop().RunUntilIdle(); 514 base::RunLoop().RunUntilIdle();
503 DiscoverLowEnergyDevice(1); 515 DiscoverLowEnergyDevice(1);
504 base::RunLoop().RunUntilIdle(); 516 base::RunLoop().RunUntilIdle();
505 EXPECT_EQ(1, observer.device_added_count()); 517 EXPECT_EQ(1, observer.device_added_count());
506 BluetoothDevice* device = adapter_->GetDevice(observer.last_device_address()); 518 BluetoothDevice* device = adapter_->GetDevice(observer.last_device_address());
507 EXPECT_TRUE(device); 519 EXPECT_TRUE(device);
508 520
509 // Find the same device again. This should not create a new device object. 521 // Find the same device again. This should not create a new device object.
510 observer.Reset(); 522 observer.Reset();
511 DiscoverLowEnergyDevice(1); 523 DiscoverLowEnergyDevice(1);
512 base::RunLoop().RunUntilIdle(); 524 base::RunLoop().RunUntilIdle();
513 EXPECT_EQ(0, observer.device_added_count()); 525 EXPECT_EQ(0, observer.device_added_count());
514 EXPECT_EQ(0, observer.device_changed_count());
krstnmnlsn 2015/07/22 23:23:17 As previously discussed, it's not clear if / how w
scheib 2015/07/23 18:15:25 Well, in the implementation of Update (and all met
krstnmnlsn 2015/07/23 22:03:29 Yes, and the reason I'm hesitant on it is because
515 EXPECT_EQ(1u, adapter_->GetDevices().size()); 526 EXPECT_EQ(1u, adapter_->GetDevices().size());
516 } 527 }
517 #endif // defined(OS_ANDROID) 528 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
518 529
519 #if defined(OS_ANDROID) 530 #if defined(OS_ANDROID) || defined(OS_MACOSX)
520 // Discovers a device, and then again with new Service UUIDs. 531 // Discovers a device, and then again with new Service UUIDs.
521 TEST_F(BluetoothTest, DiscoverDeviceWithUpdatedUUIDs) { 532 TEST_F(BluetoothTest, DiscoverLowEnergyDeviceWithUpdatedUUIDs) {
533 if (!PlatformSupportsLowEnergy()) {
534 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
535 return;
536 }
522 InitWithFakeAdapter(); 537 InitWithFakeAdapter();
523 TestBluetoothAdapterObserver observer(adapter_); 538 TestBluetoothAdapterObserver observer(adapter_);
524 539
525 // Start discovery and find a device. 540 // Start discovery and find a device.
526 adapter_->StartDiscoverySession(GetDiscoverySessionCallback(), 541 adapter_->StartDiscoverySession(GetDiscoverySessionCallback(),
527 GetErrorCallback()); 542 GetErrorCallback());
528 base::RunLoop().RunUntilIdle(); 543 base::RunLoop().RunUntilIdle();
529 DiscoverLowEnergyDevice(1); 544 DiscoverLowEnergyDevice(1);
530 base::RunLoop().RunUntilIdle(); 545 base::RunLoop().RunUntilIdle();
531 BluetoothDevice* device = observer.last_device(); 546 BluetoothDevice* device = observer.last_device();
532 547
533 // Check the initial UUIDs: 548 // Check the initial UUIDs:
534 EXPECT_TRUE(ContainsValue(device->GetUUIDs(), BluetoothUUID("1800"))); 549 EXPECT_TRUE(ContainsValue(device->GetUUIDs(), BluetoothUUID(kTestUUID1)));
535 EXPECT_FALSE(ContainsValue(device->GetUUIDs(), BluetoothUUID("1802"))); 550 EXPECT_FALSE(ContainsValue(device->GetUUIDs(), BluetoothUUID(kTestUUID3)));
536 551
537 // Discover same device again with updated UUIDs: 552 // Discover same device again with updated UUIDs:
538 observer.Reset(); 553 observer.Reset();
539 DiscoverLowEnergyDevice(2); 554 DiscoverLowEnergyDevice(2);
540 base::RunLoop().RunUntilIdle(); 555 base::RunLoop().RunUntilIdle();
541 EXPECT_EQ(0, observer.device_added_count()); 556 EXPECT_EQ(0, observer.device_added_count());
542 EXPECT_EQ(1, observer.device_changed_count()); 557 EXPECT_EQ(1, observer.device_changed_count());
543 EXPECT_EQ(1u, adapter_->GetDevices().size()); 558 EXPECT_EQ(1u, adapter_->GetDevices().size());
544 EXPECT_EQ(device, observer.last_device()); 559 EXPECT_EQ(device, observer.last_device());
545 560
546 // Expect new UUIDs: 561 // Expect new UUIDs:
547 EXPECT_FALSE(ContainsValue(device->GetUUIDs(), BluetoothUUID("1800"))); 562 EXPECT_FALSE(ContainsValue(device->GetUUIDs(), BluetoothUUID(kTestUUID1)));
548 EXPECT_TRUE(ContainsValue(device->GetUUIDs(), BluetoothUUID("1802"))); 563 EXPECT_TRUE(ContainsValue(device->GetUUIDs(), BluetoothUUID(kTestUUID3)));
549 564
550 // Discover same device again with empty UUIDs: 565 // Discover same device again with empty UUIDs:
551 observer.Reset(); 566 observer.Reset();
552 DiscoverLowEnergyDevice(3); 567 DiscoverLowEnergyDevice(3);
553 base::RunLoop().RunUntilIdle(); 568 base::RunLoop().RunUntilIdle();
554 EXPECT_EQ(0, observer.device_added_count()); 569 EXPECT_EQ(0, observer.device_added_count());
555 EXPECT_EQ(1, observer.device_changed_count()); 570 EXPECT_EQ(1, observer.device_changed_count());
556 EXPECT_EQ(1u, adapter_->GetDevices().size()); 571 EXPECT_EQ(1u, adapter_->GetDevices().size());
557 EXPECT_EQ(device, observer.last_device()); 572 EXPECT_EQ(device, observer.last_device());
558 573
559 // Expect empty UUIDs: 574 // Expect empty UUIDs:
560 EXPECT_EQ(0u, device->GetUUIDs().size()); 575 EXPECT_EQ(0u, device->GetUUIDs().size());
561 } 576 }
562 #endif // defined(OS_ANDROID) 577 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
563 578
564 #if defined(OS_ANDROID) 579 #if defined(OS_ANDROID) || defined(OS_MACOSX)
565 // Discovers multiple devices when addresses vary. 580 // Discovers multiple devices when addresses vary.
566 TEST_F(BluetoothTest, DiscoverMultipleDevices) { 581 TEST_F(BluetoothTest, DiscoverMultipleLowEnergyDevices) {
582 if (!PlatformSupportsLowEnergy()) {
583 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
584 return;
585 }
567 InitWithFakeAdapter(); 586 InitWithFakeAdapter();
568 TestBluetoothAdapterObserver observer(adapter_); 587 TestBluetoothAdapterObserver observer(adapter_);
569 588
570 // Start discovery and find a device. 589 // Start discovery and find a device.
571 adapter_->StartDiscoverySession(GetDiscoverySessionCallback(), 590 adapter_->StartDiscoverySession(GetDiscoverySessionCallback(),
572 GetErrorCallback()); 591 GetErrorCallback());
573 base::RunLoop().RunUntilIdle(); 592 base::RunLoop().RunUntilIdle();
574 DiscoverLowEnergyDevice(1); 593 DiscoverLowEnergyDevice(1);
575 DiscoverLowEnergyDevice(4); 594 DiscoverLowEnergyDevice(4);
576 base::RunLoop().RunUntilIdle(); 595 base::RunLoop().RunUntilIdle();
577 EXPECT_EQ(2, observer.device_added_count()); 596 EXPECT_EQ(2, observer.device_added_count());
578 EXPECT_EQ(2u, adapter_->GetDevices().size()); 597 EXPECT_EQ(2u, adapter_->GetDevices().size());
579 } 598 }
580 #endif // defined(OS_ANDROID) 599 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
581 600
582 } // namespace device 601 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698