| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 EXPECT_EQ(0x1F00u, device->GetBluetoothClass()); | 89 EXPECT_EQ(0x1F00u, device->GetBluetoothClass()); |
| 90 #endif | 90 #endif |
| 91 EXPECT_EQ(kTestDeviceAddress1, device->GetAddress()); | 91 EXPECT_EQ(kTestDeviceAddress1, device->GetAddress()); |
| 92 EXPECT_EQ(BluetoothDevice::VENDOR_ID_UNKNOWN, device->GetVendorIDSource()); | 92 EXPECT_EQ(BluetoothDevice::VENDOR_ID_UNKNOWN, device->GetVendorIDSource()); |
| 93 EXPECT_EQ(0, device->GetVendorID()); | 93 EXPECT_EQ(0, device->GetVendorID()); |
| 94 EXPECT_EQ(0, device->GetProductID()); | 94 EXPECT_EQ(0, device->GetProductID()); |
| 95 EXPECT_EQ(0, device->GetDeviceID()); | 95 EXPECT_EQ(0, device->GetDeviceID()); |
| 96 EXPECT_EQ(base::UTF8ToUTF16(kTestDeviceName), device->GetNameForDisplay()); | 96 EXPECT_EQ(base::UTF8ToUTF16(kTestDeviceName), device->GetNameForDisplay()); |
| 97 EXPECT_FALSE(device->IsPaired()); | 97 EXPECT_FALSE(device->IsPaired()); |
| 98 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); | 98 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); |
| 99 EXPECT_TRUE(ContainsValue(uuids, BluetoothUUID(kTestUUIDGenericAccess))); | 99 EXPECT_TRUE( |
| 100 EXPECT_TRUE(ContainsValue(uuids, BluetoothUUID(kTestUUIDGenericAttribute))); | 100 base::ContainsValue(uuids, BluetoothUUID(kTestUUIDGenericAccess))); |
| 101 EXPECT_TRUE( |
| 102 base::ContainsValue(uuids, BluetoothUUID(kTestUUIDGenericAttribute))); |
| 101 } | 103 } |
| 102 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 104 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 103 | 105 |
| 104 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 106 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 105 // Device with no advertised Service UUIDs. | 107 // Device with no advertised Service UUIDs. |
| 106 TEST_F(BluetoothTest, LowEnergyDeviceNoUUIDs) { | 108 TEST_F(BluetoothTest, LowEnergyDeviceNoUUIDs) { |
| 107 if (!PlatformSupportsLowEnergy()) { | 109 if (!PlatformSupportsLowEnergy()) { |
| 108 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 110 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 109 return; | 111 return; |
| 110 } | 112 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 123 if (!PlatformSupportsLowEnergy()) { | 125 if (!PlatformSupportsLowEnergy()) { |
| 124 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 126 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 125 return; | 127 return; |
| 126 } | 128 } |
| 127 InitWithFakeAdapter(); | 129 InitWithFakeAdapter(); |
| 128 StartLowEnergyDiscoverySession(); | 130 StartLowEnergyDiscoverySession(); |
| 129 BluetoothDevice* device = SimulateLowEnergyDevice(1); | 131 BluetoothDevice* device = SimulateLowEnergyDevice(1); |
| 130 | 132 |
| 131 // Check advertised UUIDs: | 133 // Check advertised UUIDs: |
| 132 EXPECT_EQ(2u, device->GetUUIDs().size()); | 134 EXPECT_EQ(2u, device->GetUUIDs().size()); |
| 133 EXPECT_TRUE( | 135 EXPECT_TRUE(base::ContainsValue(device->GetUUIDs(), |
| 134 ContainsValue(device->GetUUIDs(), BluetoothUUID(kTestUUIDGenericAccess))); | 136 BluetoothUUID(kTestUUIDGenericAccess))); |
| 135 EXPECT_TRUE(ContainsValue(device->GetUUIDs(), | 137 EXPECT_TRUE(base::ContainsValue(device->GetUUIDs(), |
| 136 BluetoothUUID(kTestUUIDGenericAttribute))); | 138 BluetoothUUID(kTestUUIDGenericAttribute))); |
| 137 | 139 |
| 138 // Connect. | 140 // Connect. |
| 139 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 141 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 140 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 142 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 141 TestBluetoothAdapterObserver observer(adapter_); | 143 TestBluetoothAdapterObserver observer(adapter_); |
| 142 SimulateGattConnection(device); | 144 SimulateGattConnection(device); |
| 143 ASSERT_TRUE(device->IsConnected()); | 145 ASSERT_TRUE(device->IsConnected()); |
| 144 | 146 |
| 145 // No UUIDs until services are completely discovered. | 147 // No UUIDs until services are completely discovered. |
| 146 EXPECT_EQ(0u, device->GetUUIDs().size()); | 148 EXPECT_EQ(0u, device->GetUUIDs().size()); |
| 147 | 149 |
| 148 // Discover services. | 150 // Discover services. |
| 149 std::vector<std::string> services; | 151 std::vector<std::string> services; |
| 150 services.push_back(BluetoothUUID(kTestUUIDGenericAccess).canonical_value()); | 152 services.push_back(BluetoothUUID(kTestUUIDGenericAccess).canonical_value()); |
| 151 SimulateGattServicesDiscovered(device, services); | 153 SimulateGattServicesDiscovered(device, services); |
| 152 | 154 |
| 153 // GetUUIDs should return UUIDs of services in device. | 155 // GetUUIDs should return UUIDs of services in device. |
| 154 EXPECT_EQ(1u, device->GetUUIDs().size()); | 156 EXPECT_EQ(1u, device->GetUUIDs().size()); |
| 155 EXPECT_TRUE( | 157 EXPECT_TRUE(base::ContainsValue(device->GetUUIDs(), |
| 156 ContainsValue(device->GetUUIDs(), BluetoothUUID(kTestUUIDGenericAccess))); | 158 BluetoothUUID(kTestUUIDGenericAccess))); |
| 157 | 159 |
| 158 #if defined(OS_MACOSX) | 160 #if defined(OS_MACOSX) |
| 159 // Android and Windows don't yet support service changed events. | 161 // Android and Windows don't yet support service changed events. |
| 160 // http://crbug.com/548280 | 162 // http://crbug.com/548280 |
| 161 // http://crbug.com/579202 | 163 // http://crbug.com/579202 |
| 162 SimulateGattServicesChanged(device); | 164 SimulateGattServicesChanged(device); |
| 163 | 165 |
| 164 // After service changed event we don't know what UUIDs the device has. | 166 // After service changed event we don't know what UUIDs the device has. |
| 165 ASSERT_FALSE(device->IsGattServicesDiscoveryComplete()); | 167 ASSERT_FALSE(device->IsGattServicesDiscoveryComplete()); |
| 166 EXPECT_EQ(0u, device->GetUUIDs().size()); | 168 EXPECT_EQ(0u, device->GetUUIDs().size()); |
| 167 | 169 |
| 168 SimulateGattServicesDiscovered(device, {} /* services */); | 170 SimulateGattServicesDiscovered(device, {} /* services */); |
| 169 | 171 |
| 170 // GetUUIDs should return UUIDs of services in device. | 172 // GetUUIDs should return UUIDs of services in device. |
| 171 EXPECT_EQ(1u, device->GetUUIDs().size()); | 173 EXPECT_EQ(1u, device->GetUUIDs().size()); |
| 172 EXPECT_TRUE( | 174 EXPECT_TRUE(base::ContainsValue(device->GetUUIDs(), |
| 173 ContainsValue(device->GetUUIDs(), BluetoothUUID(kTestUUIDGenericAccess))); | 175 BluetoothUUID(kTestUUIDGenericAccess))); |
| 174 #endif // defined(OS_MACOSX) | 176 #endif // defined(OS_MACOSX) |
| 175 | 177 |
| 176 // Disconnect. | 178 // Disconnect. |
| 177 device->DisconnectGatt(); | 179 device->DisconnectGatt(); |
| 178 SimulateGattDisconnection(device); | 180 SimulateGattDisconnection(device); |
| 179 | 181 |
| 180 // After disconnection we don't know what UUIDs the device has. | 182 // After disconnection we don't know what UUIDs the device has. |
| 181 EXPECT_EQ(0u, device->GetUUIDs().size()); | 183 EXPECT_EQ(0u, device->GetUUIDs().size()); |
| 182 | 184 |
| 183 // Discover the device again with different UUIDs. | 185 // Discover the device again with different UUIDs. |
| 184 device = SimulateLowEnergyDevice(2); | 186 device = SimulateLowEnergyDevice(2); |
| 185 | 187 |
| 186 // Check advertised UUIDs. | 188 // Check advertised UUIDs. |
| 187 EXPECT_EQ(2u, device->GetUUIDs().size()); | 189 EXPECT_EQ(2u, device->GetUUIDs().size()); |
| 188 EXPECT_TRUE(ContainsValue(device->GetUUIDs(), | 190 EXPECT_TRUE(base::ContainsValue(device->GetUUIDs(), |
| 189 BluetoothUUID(kTestUUIDImmediateAlert))); | 191 BluetoothUUID(kTestUUIDImmediateAlert))); |
| 190 EXPECT_TRUE( | 192 EXPECT_TRUE(base::ContainsValue(device->GetUUIDs(), |
| 191 ContainsValue(device->GetUUIDs(), BluetoothUUID(kTestUUIDLinkLoss))); | 193 BluetoothUUID(kTestUUIDLinkLoss))); |
| 192 } | 194 } |
| 193 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 195 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 194 | 196 |
| 195 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 197 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 196 // GetName for Device with no name. | 198 // GetName for Device with no name. |
| 197 TEST_F(BluetoothTest, GetName_NullName) { | 199 TEST_F(BluetoothTest, GetName_NullName) { |
| 198 if (!PlatformSupportsLowEnergy()) { | 200 if (!PlatformSupportsLowEnergy()) { |
| 199 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 201 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 200 return; | 202 return; |
| 201 } | 203 } |
| (...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 | 843 |
| 842 BluetoothDevice* device2 = SimulateLowEnergyDevice(6); | 844 BluetoothDevice* device2 = SimulateLowEnergyDevice(6); |
| 843 EXPECT_EQ(BLUETOOTH_TRANSPORT_DUAL, device2->GetType()); | 845 EXPECT_EQ(BLUETOOTH_TRANSPORT_DUAL, device2->GetType()); |
| 844 | 846 |
| 845 BluetoothDevice* device3 = SimulateClassicDevice(); | 847 BluetoothDevice* device3 = SimulateClassicDevice(); |
| 846 EXPECT_EQ(BLUETOOTH_TRANSPORT_CLASSIC, device3->GetType()); | 848 EXPECT_EQ(BLUETOOTH_TRANSPORT_CLASSIC, device3->GetType()); |
| 847 } | 849 } |
| 848 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) | 850 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) |
| 849 | 851 |
| 850 } // namespace device | 852 } // namespace device |
| OLD | NEW |