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

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

Issue 1676073002: Implement BluetoothLowEnergyWrapperFake for Bluetooth test fixture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase && address comments Created 4 years, 10 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
« no previous file with comments | « no previous file | device/bluetooth/bluetooth_low_energy_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include <utility> 9 #include <utility>
10 10
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 return; 531 return;
532 } 532 }
533 533
534 StartLowEnergyDiscoverySessionExpectedToFail(); 534 StartLowEnergyDiscoverySessionExpectedToFail();
535 535
536 EXPECT_EQ(0, callback_count_); 536 EXPECT_EQ(0, callback_count_);
537 EXPECT_EQ(1, error_callback_count_); 537 EXPECT_EQ(1, error_callback_count_);
538 } 538 }
539 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) 539 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
540 540
541 #if defined(OS_ANDROID) || defined(OS_MACOSX) 541 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
542 // Discovers a device. 542 // Discovers a device.
543 TEST_F(BluetoothTest, DiscoverLowEnergyDevice) { 543 TEST_F(BluetoothTest, DiscoverLowEnergyDevice) {
544 if (!PlatformSupportsLowEnergy()) { 544 if (!PlatformSupportsLowEnergy()) {
545 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 545 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
546 return; 546 return;
547 } 547 }
548 InitWithFakeAdapter(); 548 InitWithFakeAdapter();
549 TestBluetoothAdapterObserver observer(adapter_); 549 TestBluetoothAdapterObserver observer(adapter_);
550 550
551 // Start discovery and find a device. 551 // Start discovery and find a device.
552 StartLowEnergyDiscoverySession(); 552 StartLowEnergyDiscoverySession();
553 DiscoverLowEnergyDevice(1); 553 DiscoverLowEnergyDevice(1);
554 EXPECT_EQ(1, observer.device_added_count()); 554 EXPECT_EQ(1, observer.device_added_count());
555 BluetoothDevice* device = adapter_->GetDevice(observer.last_device_address()); 555 BluetoothDevice* device = adapter_->GetDevice(observer.last_device_address());
556 EXPECT_TRUE(device); 556 EXPECT_TRUE(device);
557 } 557 }
558 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) 558 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
559 559
560 #if defined(OS_ANDROID) || defined(OS_MACOSX) 560 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
561 // Discovers the same device multiple times. 561 // Discovers the same device multiple times.
562 TEST_F(BluetoothTest, DiscoverLowEnergyDeviceTwice) { 562 TEST_F(BluetoothTest, DiscoverLowEnergyDeviceTwice) {
563 if (!PlatformSupportsLowEnergy()) { 563 if (!PlatformSupportsLowEnergy()) {
564 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 564 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
565 return; 565 return;
566 } 566 }
567 InitWithFakeAdapter(); 567 InitWithFakeAdapter();
568 TestBluetoothAdapterObserver observer(adapter_); 568 TestBluetoothAdapterObserver observer(adapter_);
569 569
570 // Start discovery and find a device. 570 // Start discovery and find a device.
571 StartLowEnergyDiscoverySession(); 571 StartLowEnergyDiscoverySession();
572 DiscoverLowEnergyDevice(1); 572 DiscoverLowEnergyDevice(1);
573 EXPECT_EQ(1, observer.device_added_count()); 573 EXPECT_EQ(1, observer.device_added_count());
574 BluetoothDevice* device = adapter_->GetDevice(observer.last_device_address()); 574 BluetoothDevice* device = adapter_->GetDevice(observer.last_device_address());
575 EXPECT_TRUE(device); 575 EXPECT_TRUE(device);
576 576
577 // Find the same device again. This should not create a new device object. 577 // Find the same device again. This should not create a new device object.
578 observer.Reset(); 578 observer.Reset();
579 DiscoverLowEnergyDevice(1); 579 DiscoverLowEnergyDevice(1);
580 base::RunLoop().RunUntilIdle(); 580 base::RunLoop().RunUntilIdle();
581 EXPECT_EQ(0, observer.device_added_count()); 581 EXPECT_EQ(0, observer.device_added_count());
582 EXPECT_EQ(1u, adapter_->GetDevices().size()); 582 EXPECT_EQ(1u, adapter_->GetDevices().size());
583 } 583 }
584 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) 584 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
585 585
586 #if defined(OS_ANDROID) || defined(OS_MACOSX) 586 #if defined(OS_ANDROID) || defined(OS_MACOSX)
587 // Discovers a device, and then again with new Service UUIDs. 587 // Discovers a device, and then again with new Service UUIDs.
588 TEST_F(BluetoothTest, DiscoverLowEnergyDeviceWithUpdatedUUIDs) { 588 TEST_F(BluetoothTest, DiscoverLowEnergyDeviceWithUpdatedUUIDs) {
589 if (!PlatformSupportsLowEnergy()) { 589 if (!PlatformSupportsLowEnergy()) {
590 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 590 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
591 return; 591 return;
592 } 592 }
593 InitWithFakeAdapter(); 593 InitWithFakeAdapter();
594 TestBluetoothAdapterObserver observer(adapter_); 594 TestBluetoothAdapterObserver observer(adapter_);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 #else 627 #else
628 EXPECT_EQ(0, observer.device_changed_count()); 628 EXPECT_EQ(0, observer.device_changed_count());
629 #endif 629 #endif
630 EXPECT_EQ(1u, adapter_->GetDevices().size()); 630 EXPECT_EQ(1u, adapter_->GetDevices().size());
631 631
632 // Expect all UUIDs: 632 // Expect all UUIDs:
633 EXPECT_EQ(4u, device->GetUUIDs().size()); 633 EXPECT_EQ(4u, device->GetUUIDs().size());
634 } 634 }
635 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) 635 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
636 636
637 #if defined(OS_ANDROID) || defined(OS_MACOSX) 637 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
638 // Discovers multiple devices when addresses vary. 638 // Discovers multiple devices when addresses vary.
639 TEST_F(BluetoothTest, DiscoverMultipleLowEnergyDevices) { 639 TEST_F(BluetoothTest, DiscoverMultipleLowEnergyDevices) {
640 if (!PlatformSupportsLowEnergy()) { 640 if (!PlatformSupportsLowEnergy()) {
641 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 641 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
642 return; 642 return;
643 } 643 }
644 InitWithFakeAdapter(); 644 InitWithFakeAdapter();
645 TestBluetoothAdapterObserver observer(adapter_); 645 TestBluetoothAdapterObserver observer(adapter_);
646 646
647 // Start discovery and find a device. 647 // Start discovery and find a device.
648 StartLowEnergyDiscoverySession(); 648 StartLowEnergyDiscoverySession();
649 DiscoverLowEnergyDevice(1); 649 DiscoverLowEnergyDevice(1);
650 DiscoverLowEnergyDevice(4); 650 DiscoverLowEnergyDevice(4);
651 EXPECT_EQ(2, observer.device_added_count()); 651 EXPECT_EQ(2, observer.device_added_count());
652 EXPECT_EQ(2u, adapter_->GetDevices().size()); 652 EXPECT_EQ(2u, adapter_->GetDevices().size());
653 } 653 }
654 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) 654 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
655 655
656 #if defined(OS_ANDROID) 656 #if defined(OS_ANDROID)
657 TEST_F(BluetoothTest, TogglePowerFakeAdapter) { 657 TEST_F(BluetoothTest, TogglePowerFakeAdapter) {
658 InitWithFakeAdapter(); 658 InitWithFakeAdapter();
659 ASSERT_TRUE(adapter_->IsPresent()); 659 ASSERT_TRUE(adapter_->IsPresent());
660 ASSERT_TRUE(adapter_->IsPowered()); 660 ASSERT_TRUE(adapter_->IsPowered());
661 661
662 // Check if power can be turned off. 662 // Check if power can be turned off.
663 adapter_->SetPowered(false, GetCallback(Call::EXPECTED), 663 adapter_->SetPowered(false, GetCallback(Call::EXPECTED),
664 GetErrorCallback(Call::NOT_EXPECTED)); 664 GetErrorCallback(Call::NOT_EXPECTED));
(...skipping 30 matching lines...) Expand all
695 StartLowEnergyDiscoverySession(); 695 StartLowEnergyDiscoverySession();
696 EXPECT_EQ(1, callback_count_); 696 EXPECT_EQ(1, callback_count_);
697 EXPECT_EQ(0, error_callback_count_); 697 EXPECT_EQ(0, error_callback_count_);
698 EXPECT_TRUE(adapter_->IsDiscovering()); 698 EXPECT_TRUE(adapter_->IsDiscovering());
699 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 699 ASSERT_EQ((size_t)1, discovery_sessions_.size());
700 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); 700 EXPECT_TRUE(discovery_sessions_[0]->IsActive());
701 } 701 }
702 #endif // defined(OS_ANDROID) 702 #endif // defined(OS_ANDROID)
703 703
704 } // namespace device 704 } // namespace device
OLDNEW
« no previous file with comments | « no previous file | device/bluetooth/bluetooth_low_energy_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698