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

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

Issue 2205693003: bluetooth: Replace old advertised uuids (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Fix mac Created 4 years, 4 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>
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 observer.Reset(); 614 observer.Reset();
615 SimulateLowEnergyDevice(1); 615 SimulateLowEnergyDevice(1);
616 base::RunLoop().RunUntilIdle(); 616 base::RunLoop().RunUntilIdle();
617 EXPECT_EQ(0, observer.device_added_count()); 617 EXPECT_EQ(0, observer.device_added_count());
618 EXPECT_EQ(1u, adapter_->GetDevices().size()); 618 EXPECT_EQ(1u, adapter_->GetDevices().size());
619 } 619 }
620 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) 620 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
621 621
622 #if defined(OS_ANDROID) || defined(OS_MACOSX) 622 #if defined(OS_ANDROID) || defined(OS_MACOSX)
623 // Discovers a device, and then again with new Service UUIDs. 623 // Discovers a device, and then again with new Service UUIDs.
624 TEST_F(BluetoothTest, DiscoverLowEnergyDeviceWithUpdatedUUIDs) { 624 TEST_F(BluetoothTest, DiscoverLowEnergyDeviceWithUpdatedUUIDs) {
scheib 2016/08/05 18:49:31 Let's add another test that discovering the same d
ortuno 2016/08/05 23:00:16 I think that should also result in DeviceChanged.
625 if (!PlatformSupportsLowEnergy()) { 625 if (!PlatformSupportsLowEnergy()) {
626 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 626 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
627 return; 627 return;
628 } 628 }
629 InitWithFakeAdapter(); 629 InitWithFakeAdapter();
630 TestBluetoothAdapterObserver observer(adapter_); 630 TestBluetoothAdapterObserver observer(adapter_);
631 631
632 // Start discovery and find a device. 632 // Start discovery and find a device.
633 StartLowEnergyDiscoverySession(); 633 StartLowEnergyDiscoverySession();
634 BluetoothDevice* device = SimulateLowEnergyDevice(1); 634 BluetoothDevice* device = SimulateLowEnergyDevice(1);
635 635
636 // Check the initial UUIDs: 636 // Check the initial UUIDs:
637 EXPECT_TRUE( 637 EXPECT_TRUE(
638 ContainsValue(device->GetUUIDs(), BluetoothUUID(kTestUUIDGenericAccess))); 638 ContainsValue(device->GetUUIDs(), BluetoothUUID(kTestUUIDGenericAccess)));
639 EXPECT_FALSE(ContainsValue(device->GetUUIDs(), 639 EXPECT_FALSE(ContainsValue(device->GetUUIDs(),
640 BluetoothUUID(kTestUUIDImmediateAlert))); 640 BluetoothUUID(kTestUUIDImmediateAlert)));
641 641
642 // Discover same device again with updated UUIDs: 642 // Discover same device again with updated UUIDs:
643 observer.Reset(); 643 observer.Reset();
644 SimulateLowEnergyDevice(2); 644 SimulateLowEnergyDevice(2);
645 EXPECT_EQ(0, observer.device_added_count()); 645 EXPECT_EQ(0, observer.device_added_count());
646 EXPECT_EQ(1, observer.device_changed_count()); 646 EXPECT_EQ(1, observer.device_changed_count());
647 EXPECT_EQ(1u, adapter_->GetDevices().size()); 647 EXPECT_EQ(1u, adapter_->GetDevices().size());
648 EXPECT_EQ(device, observer.last_device()); 648 EXPECT_EQ(device, observer.last_device());
649 649
650 // Expect new AND old UUIDs: 650 // Expect only new UUIDs:
651 EXPECT_TRUE( 651 EXPECT_FALSE(
652 ContainsValue(device->GetUUIDs(), BluetoothUUID(kTestUUIDGenericAccess))); 652 ContainsValue(device->GetUUIDs(), BluetoothUUID(kTestUUIDGenericAccess)));
653 EXPECT_TRUE(ContainsValue(device->GetUUIDs(), 653 EXPECT_TRUE(ContainsValue(device->GetUUIDs(),
654 BluetoothUUID(kTestUUIDImmediateAlert))); 654 BluetoothUUID(kTestUUIDImmediateAlert)));
655 655
656 // Discover same device again with empty UUIDs: 656 // Discover same device again with empty UUIDs:
657 observer.Reset(); 657 observer.Reset();
658 SimulateLowEnergyDevice(3); 658 SimulateLowEnergyDevice(3);
659 EXPECT_EQ(0, observer.device_added_count()); 659 EXPECT_EQ(0, observer.device_added_count());
660 #if defined(OS_MACOSX)
661 // TODO(scheib): Call DeviceChanged only if UUIDs change. crbug.com/547106
662 EXPECT_EQ(1, observer.device_changed_count()); 660 EXPECT_EQ(1, observer.device_changed_count());
663 #else
664 EXPECT_EQ(0, observer.device_changed_count());
665 #endif
666 EXPECT_EQ(1u, adapter_->GetDevices().size()); 661 EXPECT_EQ(1u, adapter_->GetDevices().size());
667 662
668 // Expect all UUIDs: 663 // Expect no UUIDs:
669 EXPECT_EQ(4u, device->GetUUIDs().size()); 664 EXPECT_EQ(0u, device->GetUUIDs().size());
670 } 665 }
671 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) 666 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
672 667
673 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) 668 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
674 // Discovers multiple devices when addresses vary. 669 // Discovers multiple devices when addresses vary.
675 TEST_F(BluetoothTest, DiscoverMultipleLowEnergyDevices) { 670 TEST_F(BluetoothTest, DiscoverMultipleLowEnergyDevices) {
676 if (!PlatformSupportsLowEnergy()) { 671 if (!PlatformSupportsLowEnergy()) {
677 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 672 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
678 return; 673 return;
679 } 674 }
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 GetConnectErrorCallback(Call::NOT_EXPECTED)); 861 GetConnectErrorCallback(Call::NOT_EXPECTED));
867 SimulateGattConnection(device); 862 SimulateGattConnection(device);
868 EXPECT_EQ(1u, adapter_->GetDevices().size()); 863 EXPECT_EQ(1u, adapter_->GetDevices().size());
869 RemoveTimedOutDevices(); 864 RemoveTimedOutDevices();
870 EXPECT_EQ(0, observer.device_removed_count()); 865 EXPECT_EQ(0, observer.device_removed_count());
871 EXPECT_EQ(1u, adapter_->GetDevices().size()); 866 EXPECT_EQ(1u, adapter_->GetDevices().size());
872 } 867 }
873 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) 868 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
874 869
875 } // namespace device 870 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698