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

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

Issue 1884033002: Implement BluetoothTestBlueZ and enable some LE tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
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 "device/bluetooth/bluetooth_adapter.h" 5 #include "device/bluetooth/bluetooth_adapter.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "build/build_config.h" 16 #include "build/build_config.h"
17 #include "device/bluetooth/bluetooth_device.h" 17 #include "device/bluetooth/bluetooth_device.h"
18 #include "device/bluetooth/bluetooth_discovery_session.h" 18 #include "device/bluetooth/bluetooth_discovery_session.h"
19 #include "device/bluetooth/test/bluetooth_test.h" 19 #include "device/bluetooth/test/bluetooth_test.h"
20 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" 20 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 22
23 #if defined(OS_ANDROID) 23 #if defined(OS_ANDROID)
24 #include "device/bluetooth/test/bluetooth_test_android.h" 24 #include "device/bluetooth/test/bluetooth_test_android.h"
25 #elif defined(OS_MACOSX) 25 #elif defined(OS_MACOSX)
26 #include "device/bluetooth/test/bluetooth_test_mac.h" 26 #include "device/bluetooth/test/bluetooth_test_mac.h"
27 #elif defined(OS_WIN) 27 #elif defined(OS_WIN)
28 #include "device/bluetooth/test/bluetooth_test_win.h" 28 #include "device/bluetooth/test/bluetooth_test_win.h"
29 #elif defined(OS_CHROMEOS) || defined(OS_LINUX)
30 #include "device/bluetooth/test/bluetooth_test_bluez.h"
29 #endif 31 #endif
30 32
31 using device::BluetoothDevice; 33 using device::BluetoothDevice;
32 34
33 namespace device { 35 namespace device {
34 36
35 class TestBluetoothAdapter : public BluetoothAdapter { 37 class TestBluetoothAdapter : public BluetoothAdapter {
36 public: 38 public:
37 TestBluetoothAdapter() { 39 TestBluetoothAdapter() {
38 } 40 }
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 return; 542 return;
541 } 543 }
542 544
543 StartLowEnergyDiscoverySessionExpectedToFail(); 545 StartLowEnergyDiscoverySessionExpectedToFail();
544 546
545 EXPECT_EQ(0, callback_count_); 547 EXPECT_EQ(0, callback_count_);
546 EXPECT_EQ(1, error_callback_count_); 548 EXPECT_EQ(1, error_callback_count_);
547 } 549 }
548 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) 550 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
549 551
550 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
551 // Discovers a device. 552 // Discovers a device.
552 TEST_F(BluetoothTest, DiscoverLowEnergyDevice) { 553 TEST_F(BluetoothTest, DiscoverLowEnergyDevice) {
553 if (!PlatformSupportsLowEnergy()) { 554 if (!PlatformSupportsLowEnergy()) {
554 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 555 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
555 return; 556 return;
556 } 557 }
557 InitWithFakeAdapter(); 558 InitWithFakeAdapter();
558 TestBluetoothAdapterObserver observer(adapter_); 559 TestBluetoothAdapterObserver observer(adapter_);
559 560
560 // Start discovery and find a device. 561 // Start discovery and find a device.
561 StartLowEnergyDiscoverySession(); 562 StartLowEnergyDiscoverySession();
562 DiscoverLowEnergyDevice(1); 563 DiscoverLowEnergyDevice(1);
563 EXPECT_EQ(1, observer.device_added_count()); 564 EXPECT_EQ(1, observer.device_added_count());
564 BluetoothDevice* device = adapter_->GetDevice(observer.last_device_address()); 565 BluetoothDevice* device = adapter_->GetDevice(observer.last_device_address());
565 EXPECT_TRUE(device); 566 EXPECT_TRUE(device);
566 } 567 }
567 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
568 568
569 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
570 // Discovers the same device multiple times. 569 // Discovers the same device multiple times.
571 TEST_F(BluetoothTest, DiscoverLowEnergyDeviceTwice) { 570 TEST_F(BluetoothTest, DiscoverLowEnergyDeviceTwice) {
572 if (!PlatformSupportsLowEnergy()) { 571 if (!PlatformSupportsLowEnergy()) {
573 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 572 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
574 return; 573 return;
575 } 574 }
576 InitWithFakeAdapter(); 575 InitWithFakeAdapter();
577 TestBluetoothAdapterObserver observer(adapter_); 576 TestBluetoothAdapterObserver observer(adapter_);
578 577
579 // Start discovery and find a device. 578 // Start discovery and find a device.
580 StartLowEnergyDiscoverySession(); 579 StartLowEnergyDiscoverySession();
581 DiscoverLowEnergyDevice(1); 580 DiscoverLowEnergyDevice(1);
582 EXPECT_EQ(1, observer.device_added_count()); 581 EXPECT_EQ(1, observer.device_added_count());
583 BluetoothDevice* device = adapter_->GetDevice(observer.last_device_address()); 582 BluetoothDevice* device = adapter_->GetDevice(observer.last_device_address());
584 EXPECT_TRUE(device); 583 EXPECT_TRUE(device);
585 584
586 // Find the same device again. This should not create a new device object. 585 // Find the same device again. This should not create a new device object.
587 observer.Reset(); 586 observer.Reset();
588 DiscoverLowEnergyDevice(1); 587 DiscoverLowEnergyDevice(1);
589 base::RunLoop().RunUntilIdle(); 588 base::RunLoop().RunUntilIdle();
590 EXPECT_EQ(0, observer.device_added_count()); 589 EXPECT_EQ(0, observer.device_added_count());
591 EXPECT_EQ(1u, adapter_->GetDevices().size()); 590 EXPECT_EQ(1u, adapter_->GetDevices().size());
592 } 591 }
593 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
594 592
595 #if defined(OS_ANDROID) || defined(OS_MACOSX) 593 #if defined(OS_ANDROID) || defined(OS_MACOSX)
596 // Discovers a device, and then again with new Service UUIDs. 594 // Discovers a device, and then again with new Service UUIDs.
597 TEST_F(BluetoothTest, DiscoverLowEnergyDeviceWithUpdatedUUIDs) { 595 TEST_F(BluetoothTest, DiscoverLowEnergyDeviceWithUpdatedUUIDs) {
598 if (!PlatformSupportsLowEnergy()) { 596 if (!PlatformSupportsLowEnergy()) {
599 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 597 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
600 return; 598 return;
601 } 599 }
602 InitWithFakeAdapter(); 600 InitWithFakeAdapter();
603 TestBluetoothAdapterObserver observer(adapter_); 601 TestBluetoothAdapterObserver observer(adapter_);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 #else 634 #else
637 EXPECT_EQ(0, observer.device_changed_count()); 635 EXPECT_EQ(0, observer.device_changed_count());
638 #endif 636 #endif
639 EXPECT_EQ(1u, adapter_->GetDevices().size()); 637 EXPECT_EQ(1u, adapter_->GetDevices().size());
640 638
641 // Expect all UUIDs: 639 // Expect all UUIDs:
642 EXPECT_EQ(4u, device->GetUUIDs().size()); 640 EXPECT_EQ(4u, device->GetUUIDs().size());
643 } 641 }
644 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) 642 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
645 643
646 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
647 // Discovers multiple devices when addresses vary. 644 // Discovers multiple devices when addresses vary.
648 TEST_F(BluetoothTest, DiscoverMultipleLowEnergyDevices) { 645 TEST_F(BluetoothTest, DiscoverMultipleLowEnergyDevices) {
649 if (!PlatformSupportsLowEnergy()) { 646 if (!PlatformSupportsLowEnergy()) {
650 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 647 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
651 return; 648 return;
652 } 649 }
653 InitWithFakeAdapter(); 650 InitWithFakeAdapter();
654 TestBluetoothAdapterObserver observer(adapter_); 651 TestBluetoothAdapterObserver observer(adapter_);
655 652
656 // Start discovery and find a device. 653 // Start discovery and find a device.
657 StartLowEnergyDiscoverySession(); 654 StartLowEnergyDiscoverySession();
658 DiscoverLowEnergyDevice(1); 655 DiscoverLowEnergyDevice(1);
659 DiscoverLowEnergyDevice(4); 656 DiscoverLowEnergyDevice(4);
660 EXPECT_EQ(2, observer.device_added_count()); 657 EXPECT_EQ(2, observer.device_added_count());
661 EXPECT_EQ(2u, adapter_->GetDevices().size()); 658 EXPECT_EQ(2u, adapter_->GetDevices().size());
662 } 659 }
663 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
664 660
665 #if defined(OS_ANDROID) 661 #if defined(OS_ANDROID)
666 TEST_F(BluetoothTest, TogglePowerFakeAdapter) { 662 TEST_F(BluetoothTest, TogglePowerFakeAdapter) {
667 InitWithFakeAdapter(); 663 InitWithFakeAdapter();
668 TestBluetoothAdapterObserver observer(adapter_); 664 TestBluetoothAdapterObserver observer(adapter_);
669 665
670 ASSERT_TRUE(adapter_->IsPresent()); 666 ASSERT_TRUE(adapter_->IsPresent());
671 ASSERT_TRUE(adapter_->IsPowered()); 667 ASSERT_TRUE(adapter_->IsPowered());
672 EXPECT_EQ(0, observer.powered_changed_count()); 668 EXPECT_EQ(0, observer.powered_changed_count());
673 669
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 StartLowEnergyDiscoverySession(); 710 StartLowEnergyDiscoverySession();
715 EXPECT_EQ(1, callback_count_); 711 EXPECT_EQ(1, callback_count_);
716 EXPECT_EQ(0, error_callback_count_); 712 EXPECT_EQ(0, error_callback_count_);
717 EXPECT_TRUE(adapter_->IsDiscovering()); 713 EXPECT_TRUE(adapter_->IsDiscovering());
718 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 714 ASSERT_EQ((size_t)1, discovery_sessions_.size());
719 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); 715 EXPECT_TRUE(discovery_sessions_[0]->IsActive());
720 } 716 }
721 #endif // defined(OS_ANDROID) 717 #endif // defined(OS_ANDROID)
722 718
723 } // namespace device 719 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter_bluez.h ('k') | device/bluetooth/dbus/fake_bluetooth_device_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698