| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 InitWithFakeAdapter(); | 111 InitWithFakeAdapter(); |
| 112 StartLowEnergyDiscoverySession(); | 112 StartLowEnergyDiscoverySession(); |
| 113 BluetoothDevice* device = SimulateLowEnergyDevice(3); | 113 BluetoothDevice* device = SimulateLowEnergyDevice(3); |
| 114 ASSERT_TRUE(device); | 114 ASSERT_TRUE(device); |
| 115 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); | 115 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); |
| 116 EXPECT_EQ(0u, uuids.size()); | 116 EXPECT_EQ(0u, uuids.size()); |
| 117 } | 117 } |
| 118 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 118 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 119 | 119 |
| 120 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 120 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 121 // Tests GetUUIDs returns the right UUIDs when device connects and disconnects. |
| 122 TEST_F(BluetoothTest, GetUUIDs) { |
| 123 if (!PlatformSupportsLowEnergy()) { |
| 124 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 125 return; |
| 126 } |
| 127 InitWithFakeAdapter(); |
| 128 StartLowEnergyDiscoverySession(); |
| 129 BluetoothDevice* device = SimulateLowEnergyDevice(1); |
| 130 |
| 131 // Check advertised UUIDs: |
| 132 EXPECT_EQ(2u, device->GetUUIDs().size()); |
| 133 EXPECT_TRUE( |
| 134 ContainsValue(device->GetUUIDs(), BluetoothUUID(kTestUUIDGenericAccess))); |
| 135 EXPECT_TRUE(ContainsValue(device->GetUUIDs(), |
| 136 BluetoothUUID(kTestUUIDGenericAttribute))); |
| 137 |
| 138 // Connect. |
| 139 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 140 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 141 TestBluetoothAdapterObserver observer(adapter_); |
| 142 SimulateGattConnection(device); |
| 143 ASSERT_TRUE(device->IsConnected()); |
| 144 |
| 145 // No UUIDs until services are completely discovered. |
| 146 EXPECT_EQ(0u, device->GetUUIDs().size()); |
| 147 |
| 148 // Discover services. |
| 149 std::vector<std::string> services; |
| 150 services.push_back(BluetoothUUID(kTestUUIDGenericAccess).canonical_value()); |
| 151 SimulateGattServicesDiscovered(device, services); |
| 152 |
| 153 // GetUUIDs should return UUIDs of services in device. |
| 154 EXPECT_EQ(1u, device->GetUUIDs().size()); |
| 155 EXPECT_TRUE( |
| 156 ContainsValue(device->GetUUIDs(), BluetoothUUID(kTestUUIDGenericAccess))); |
| 157 |
| 158 // Disconnect. |
| 159 device->DisconnectGatt(); |
| 160 SimulateGattDisconnection(device); |
| 161 |
| 162 // After disconnection we don't know what UUIDs the device has. |
| 163 EXPECT_EQ(0u, device->GetUUIDs().size()); |
| 164 |
| 165 // Discover the device again with different UUIDs. |
| 166 device = SimulateLowEnergyDevice(2); |
| 167 |
| 168 // Check advertised UUIDs. |
| 169 EXPECT_EQ(2u, device->GetUUIDs().size()); |
| 170 EXPECT_TRUE(ContainsValue(device->GetUUIDs(), |
| 171 BluetoothUUID(kTestUUIDImmediateAlert))); |
| 172 EXPECT_TRUE( |
| 173 ContainsValue(device->GetUUIDs(), BluetoothUUID(kTestUUIDLinkLoss))); |
| 174 } |
| 175 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 176 |
| 177 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 121 // GetName for Device with no name. | 178 // GetName for Device with no name. |
| 122 TEST_F(BluetoothTest, GetName_NullName) { | 179 TEST_F(BluetoothTest, GetName_NullName) { |
| 123 if (!PlatformSupportsLowEnergy()) { | 180 if (!PlatformSupportsLowEnergy()) { |
| 124 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 181 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 125 return; | 182 return; |
| 126 } | 183 } |
| 127 InitWithFakeAdapter(); | 184 InitWithFakeAdapter(); |
| 128 StartLowEnergyDiscoverySession(); | 185 StartLowEnergyDiscoverySession(); |
| 129 BluetoothDevice* device = SimulateLowEnergyDevice(5); | 186 BluetoothDevice* device = SimulateLowEnergyDevice(5); |
| 130 EXPECT_FALSE(device->GetName()); | 187 EXPECT_FALSE(device->GetName()); |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 | 712 |
| 656 BluetoothDevice* device2 = SimulateLowEnergyDevice(6); | 713 BluetoothDevice* device2 = SimulateLowEnergyDevice(6); |
| 657 EXPECT_EQ(BLUETOOTH_TRANSPORT_DUAL, device2->GetType()); | 714 EXPECT_EQ(BLUETOOTH_TRANSPORT_DUAL, device2->GetType()); |
| 658 | 715 |
| 659 BluetoothDevice* device3 = SimulateClassicDevice(); | 716 BluetoothDevice* device3 = SimulateClassicDevice(); |
| 660 EXPECT_EQ(BLUETOOTH_TRANSPORT_CLASSIC, device3->GetType()); | 717 EXPECT_EQ(BLUETOOTH_TRANSPORT_CLASSIC, device3->GetType()); |
| 661 } | 718 } |
| 662 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) | 719 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) |
| 663 | 720 |
| 664 } // namespace device | 721 } // namespace device |
| OLD | NEW |