OLD | NEW |
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_device.h" | 5 #include "device/bluetooth/bluetooth_device.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 ASSERT_TRUE(device); | 102 ASSERT_TRUE(device); |
103 // Bluetooth class information for BLE device is not available on Windows. | 103 // Bluetooth class information for BLE device is not available on Windows. |
104 #ifndef OS_WIN | 104 #ifndef OS_WIN |
105 EXPECT_EQ(0x1F00u, device->GetBluetoothClass()); | 105 EXPECT_EQ(0x1F00u, device->GetBluetoothClass()); |
106 #endif | 106 #endif |
107 EXPECT_EQ(kTestDeviceAddress1, device->GetAddress()); | 107 EXPECT_EQ(kTestDeviceAddress1, device->GetAddress()); |
108 EXPECT_EQ(BluetoothDevice::VENDOR_ID_UNKNOWN, device->GetVendorIDSource()); | 108 EXPECT_EQ(BluetoothDevice::VENDOR_ID_UNKNOWN, device->GetVendorIDSource()); |
109 EXPECT_EQ(0, device->GetVendorID()); | 109 EXPECT_EQ(0, device->GetVendorID()); |
110 EXPECT_EQ(0, device->GetProductID()); | 110 EXPECT_EQ(0, device->GetProductID()); |
111 EXPECT_EQ(0, device->GetDeviceID()); | 111 EXPECT_EQ(0, device->GetDeviceID()); |
112 EXPECT_EQ(base::UTF8ToUTF16(kTestDeviceName), device->GetNameForDisplay()); | 112 // There is no advertised name in Windows. |
| 113 // TODO(crbug.com/629456): Enable on macOS. |
| 114 #if defined(OS_ANDROID) |
| 115 EXPECT_EQ(base::UTF8ToUTF16(kTestDeviceAdvertisedName), |
| 116 device->GetNameForDisplay()); |
| 117 #else |
| 118 EXPECT_EQ(base::UTF8ToUTF16(kTestDeviceGapName), device->GetNameForDisplay()); |
| 119 #endif // defined(OS_ANDROID) |
113 EXPECT_FALSE(device->IsPaired()); | 120 EXPECT_FALSE(device->IsPaired()); |
114 UUIDSet uuids = device->GetUUIDs(); | 121 UUIDSet uuids = device->GetUUIDs(); |
115 EXPECT_TRUE(base::ContainsKey(uuids, BluetoothUUID(kTestUUIDGenericAccess))); | 122 EXPECT_TRUE(base::ContainsKey(uuids, BluetoothUUID(kTestUUIDGenericAccess))); |
116 EXPECT_TRUE( | 123 EXPECT_TRUE( |
117 base::ContainsKey(uuids, BluetoothUUID(kTestUUIDGenericAttribute))); | 124 base::ContainsKey(uuids, BluetoothUUID(kTestUUIDGenericAttribute))); |
118 } | 125 } |
119 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 126 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
120 | 127 |
121 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 128 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
122 // Device with no advertised Service UUIDs. | 129 // Device with no advertised Service UUIDs. |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 // does require this step. | 695 // does require this step. |
689 #if !defined(OS_CHROMEOS) | 696 #if !defined(OS_CHROMEOS) |
690 StartLowEnergyDiscoverySession(); | 697 StartLowEnergyDiscoverySession(); |
691 #endif | 698 #endif |
692 | 699 |
693 BluetoothDevice* device = SimulateLowEnergyDevice(5); | 700 BluetoothDevice* device = SimulateLowEnergyDevice(5); |
694 EXPECT_FALSE(device->GetName()); | 701 EXPECT_FALSE(device->GetName()); |
695 } | 702 } |
696 #endif // defined(OS_ANDROID) || defined(OS_CHROMEOS) || defined(OS_MACOSX) | 703 #endif // defined(OS_ANDROID) || defined(OS_CHROMEOS) || defined(OS_MACOSX) |
697 | 704 |
| 705 #if defined(OS_ANDROID) |
| 706 TEST_F(BluetoothTest, GetName_NonConnectedNonAdvertising) { |
| 707 if (!PlatformSupportsLowEnergy()) { |
| 708 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 709 return; |
| 710 } |
| 711 InitWithFakeAdapter(); |
| 712 StartLowEnergyDiscoverySession(); |
| 713 BluetoothDevice* device = SimulateLowEnergyDevice(1); |
| 714 |
| 715 discovery_sessions_[0]->Stop(GetCallback(Call::EXPECTED), |
| 716 GetErrorCallback(Call::NOT_EXPECTED)); |
| 717 ASSERT_FALSE(adapter_->IsDiscovering()); |
| 718 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); |
| 719 |
| 720 EXPECT_EQ(kTestDeviceGapName, device->GetName().value()); |
| 721 } |
| 722 #endif // defined(OS_ANDROID) |
| 723 |
| 724 #if defined(OS_ANDROID) |
| 725 TEST_F(BluetoothTest, GetName_ConnectedNonAdvertising) { |
| 726 if (!PlatformSupportsLowEnergy()) { |
| 727 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 728 return; |
| 729 } |
| 730 InitWithFakeAdapter(); |
| 731 StartLowEnergyDiscoverySession(); |
| 732 BluetoothDevice* device = SimulateLowEnergyDevice(1); |
| 733 |
| 734 discovery_sessions_[0]->Stop(GetCallback(Call::EXPECTED), |
| 735 GetErrorCallback(Call::NOT_EXPECTED)); |
| 736 ASSERT_FALSE(adapter_->IsDiscovering()); |
| 737 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); |
| 738 |
| 739 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 740 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 741 SimulateGattConnection(device); |
| 742 ASSERT_TRUE(device->IsGattConnected()); |
| 743 |
| 744 EXPECT_EQ(kTestDeviceGapName, device->GetName().value()); |
| 745 } |
| 746 #endif // defined(OS_ANDROID) |
| 747 |
| 748 #if defined(OS_ANDROID) |
| 749 TEST_F(BluetoothTest, GetName_NonConnectedAdvertising) { |
| 750 if (!PlatformSupportsLowEnergy()) { |
| 751 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 752 return; |
| 753 } |
| 754 InitWithFakeAdapter(); |
| 755 StartLowEnergyDiscoverySession(); |
| 756 BluetoothDevice* device = SimulateLowEnergyDevice(1); |
| 757 |
| 758 EXPECT_EQ(kTestDeviceAdvertisedName, device->GetName().value()); |
| 759 } |
| 760 #endif // defined(OS_ANDROID) |
| 761 |
| 762 #if defined(OS_ANDROID) |
| 763 TEST_F(BluetoothTest, GetName_ConnectedAdvertising) { |
| 764 if (!PlatformSupportsLowEnergy()) { |
| 765 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 766 return; |
| 767 } |
| 768 InitWithFakeAdapter(); |
| 769 StartLowEnergyDiscoverySession(); |
| 770 BluetoothDevice* device = SimulateLowEnergyDevice(1); |
| 771 |
| 772 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 773 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 774 SimulateGattConnection(device); |
| 775 ASSERT_TRUE(device->IsGattConnected()); |
| 776 |
| 777 EXPECT_EQ(kTestDeviceGapName, device->GetName().value()); |
| 778 } |
| 779 #endif // defined(OS_ANDROID) |
| 780 |
698 // TODO(506415): Test GetNameForDisplay with a device with no name. | 781 // TODO(506415): Test GetNameForDisplay with a device with no name. |
699 // BluetoothDevice::GetAddressWithLocalizedDeviceTypeName() will run, which | 782 // BluetoothDevice::GetAddressWithLocalizedDeviceTypeName() will run, which |
700 // requires string resources to be loaded. For that, something like | 783 // requires string resources to be loaded. For that, something like |
701 // InitSharedInstance must be run. See unittest files that call that. It will | 784 // InitSharedInstance must be run. See unittest files that call that. It will |
702 // also require build configuration to generate string resources into a .pak | 785 // also require build configuration to generate string resources into a .pak |
703 // file. | 786 // file. |
704 | 787 |
705 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 788 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
706 // Basic CreateGattConnection test. | 789 // Basic CreateGattConnection test. |
707 TEST_F(BluetoothTest, CreateGattConnection) { | 790 TEST_F(BluetoothTest, CreateGattConnection) { |
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1330 | 1413 |
1331 BluetoothDevice* device2 = SimulateLowEnergyDevice(6); | 1414 BluetoothDevice* device2 = SimulateLowEnergyDevice(6); |
1332 EXPECT_EQ(BLUETOOTH_TRANSPORT_DUAL, device2->GetType()); | 1415 EXPECT_EQ(BLUETOOTH_TRANSPORT_DUAL, device2->GetType()); |
1333 | 1416 |
1334 BluetoothDevice* device3 = SimulateClassicDevice(); | 1417 BluetoothDevice* device3 = SimulateClassicDevice(); |
1335 EXPECT_EQ(BLUETOOTH_TRANSPORT_CLASSIC, device3->GetType()); | 1418 EXPECT_EQ(BLUETOOTH_TRANSPORT_CLASSIC, device3->GetType()); |
1336 } | 1419 } |
1337 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) | 1420 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) |
1338 | 1421 |
1339 } // namespace device | 1422 } // namespace device |
OLD | NEW |