| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/run_loop.h" | 5 #include "base/run_loop.h" |
| 6 #include "build/build_config.h" | 6 #include "build/build_config.h" |
| 7 #include "device/bluetooth/bluetooth_gatt_service.h" | 7 #include "device/bluetooth/bluetooth_gatt_service.h" |
| 8 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" | 8 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" |
| 9 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" | 9 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 device1->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 37 device1->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 38 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 38 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 39 device2->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 39 device2->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 40 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 40 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 41 SimulateGattConnection(device1); | 41 SimulateGattConnection(device1); |
| 42 SimulateGattConnection(device2); | 42 SimulateGattConnection(device2); |
| 43 base::RunLoop().RunUntilIdle(); | 43 base::RunLoop().RunUntilIdle(); |
| 44 | 44 |
| 45 // 2 duplicate UUIDs creating 2 service instances on each device. | 45 // 2 duplicate UUIDs creating 2 service instances on each device. |
| 46 std::vector<std::string> services; | 46 std::vector<std::string> services; |
| 47 std::string uuid = "00000000-0000-1000-8000-00805f9b34fb"; | 47 services.push_back(kTestUUIDGenericAccess); |
| 48 services.push_back(uuid); | 48 services.push_back(kTestUUIDGenericAccess); |
| 49 services.push_back(uuid); | |
| 50 SimulateGattServicesDiscovered(device1, services); | 49 SimulateGattServicesDiscovered(device1, services); |
| 51 SimulateGattServicesDiscovered(device2, services); | 50 SimulateGattServicesDiscovered(device2, services); |
| 52 base::RunLoop().RunUntilIdle(); | 51 base::RunLoop().RunUntilIdle(); |
| 53 BluetoothRemoteGattService* service1 = device1->GetGattServices()[0]; | 52 BluetoothRemoteGattService* service1 = device1->GetGattServices()[0]; |
| 54 BluetoothRemoteGattService* service2 = device1->GetGattServices()[1]; | 53 BluetoothRemoteGattService* service2 = device1->GetGattServices()[1]; |
| 55 BluetoothRemoteGattService* service3 = device2->GetGattServices()[0]; | 54 BluetoothRemoteGattService* service3 = device2->GetGattServices()[0]; |
| 56 BluetoothRemoteGattService* service4 = device2->GetGattServices()[1]; | 55 BluetoothRemoteGattService* service4 = device2->GetGattServices()[1]; |
| 57 | 56 |
| 58 // All IDs are unique, even though they have the same UUID. | 57 // All IDs are unique, even though they have the same UUID. |
| 59 EXPECT_NE(service1->GetIdentifier(), service2->GetIdentifier()); | 58 EXPECT_NE(service1->GetIdentifier(), service2->GetIdentifier()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 75 } | 74 } |
| 76 InitWithFakeAdapter(); | 75 InitWithFakeAdapter(); |
| 77 StartLowEnergyDiscoverySession(); | 76 StartLowEnergyDiscoverySession(); |
| 78 BluetoothDevice* device = SimulateLowEnergyDevice(3); | 77 BluetoothDevice* device = SimulateLowEnergyDevice(3); |
| 79 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 78 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 80 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 79 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 81 SimulateGattConnection(device); | 80 SimulateGattConnection(device); |
| 82 base::RunLoop().RunUntilIdle(); | 81 base::RunLoop().RunUntilIdle(); |
| 83 | 82 |
| 84 // Create multiple instances with the same UUID. | 83 // Create multiple instances with the same UUID. |
| 85 BluetoothUUID uuid("00000000-0000-1000-8000-00805f9b34fb"); | 84 BluetoothUUID uuid(kTestUUIDGenericAccess); |
| 86 std::vector<std::string> services; | 85 std::vector<std::string> services; |
| 87 services.push_back(uuid.canonical_value()); | 86 services.push_back(uuid.canonical_value()); |
| 88 services.push_back(uuid.canonical_value()); | 87 services.push_back(uuid.canonical_value()); |
| 89 SimulateGattServicesDiscovered(device, services); | 88 SimulateGattServicesDiscovered(device, services); |
| 90 base::RunLoop().RunUntilIdle(); | 89 base::RunLoop().RunUntilIdle(); |
| 91 | 90 |
| 92 // Each has the same UUID. | 91 // Each has the same UUID. |
| 93 EXPECT_EQ(uuid, device->GetGattServices()[0]->GetUUID()); | 92 EXPECT_EQ(uuid, device->GetGattServices()[0]->GetUUID()); |
| 94 EXPECT_EQ(uuid, device->GetGattServices()[1]->GetUUID()); | 93 EXPECT_EQ(uuid, device->GetGattServices()[1]->GetUUID()); |
| 95 } | 94 } |
| 96 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 95 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 97 | 96 |
| 98 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 97 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 99 TEST_F(BluetoothRemoteGattServiceTest, GetCharacteristics_FindNone) { | 98 TEST_F(BluetoothRemoteGattServiceTest, GetCharacteristics_FindNone) { |
| 100 if (!PlatformSupportsLowEnergy()) { | 99 if (!PlatformSupportsLowEnergy()) { |
| 101 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 100 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 102 return; | 101 return; |
| 103 } | 102 } |
| 104 InitWithFakeAdapter(); | 103 InitWithFakeAdapter(); |
| 105 StartLowEnergyDiscoverySession(); | 104 StartLowEnergyDiscoverySession(); |
| 106 BluetoothDevice* device = SimulateLowEnergyDevice(3); | 105 BluetoothDevice* device = SimulateLowEnergyDevice(3); |
| 107 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 106 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 108 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 107 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 109 SimulateGattConnection(device); | 108 SimulateGattConnection(device); |
| 110 base::RunLoop().RunUntilIdle(); | 109 base::RunLoop().RunUntilIdle(); |
| 111 | 110 |
| 112 // Simulate a service, with no Characteristics: | 111 // Simulate a service, with no Characteristics: |
| 113 std::vector<std::string> services; | 112 std::vector<std::string> services; |
| 114 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); | 113 services.push_back(kTestUUIDGenericAccess); |
| 115 SimulateGattServicesDiscovered(device, services); | 114 SimulateGattServicesDiscovered(device, services); |
| 116 base::RunLoop().RunUntilIdle(); | 115 base::RunLoop().RunUntilIdle(); |
| 117 BluetoothRemoteGattService* service = device->GetGattServices()[0]; | 116 BluetoothRemoteGattService* service = device->GetGattServices()[0]; |
| 118 | 117 |
| 119 EXPECT_EQ(0u, service->GetCharacteristics().size()); | 118 EXPECT_EQ(0u, service->GetCharacteristics().size()); |
| 120 } | 119 } |
| 121 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 120 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 122 | 121 |
| 123 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 122 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 124 TEST_F(BluetoothRemoteGattServiceTest, | 123 TEST_F(BluetoothRemoteGattServiceTest, |
| 125 GetCharacteristics_and_GetCharacteristic) { | 124 GetCharacteristics_and_GetCharacteristic) { |
| 126 if (!PlatformSupportsLowEnergy()) { | 125 if (!PlatformSupportsLowEnergy()) { |
| 127 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 126 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 128 return; | 127 return; |
| 129 } | 128 } |
| 130 InitWithFakeAdapter(); | 129 InitWithFakeAdapter(); |
| 131 StartLowEnergyDiscoverySession(); | 130 StartLowEnergyDiscoverySession(); |
| 132 BluetoothDevice* device = SimulateLowEnergyDevice(3); | 131 BluetoothDevice* device = SimulateLowEnergyDevice(3); |
| 133 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 132 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 134 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 133 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 135 SimulateGattConnection(device); | 134 SimulateGattConnection(device); |
| 136 base::RunLoop().RunUntilIdle(); | 135 base::RunLoop().RunUntilIdle(); |
| 137 | 136 |
| 138 // Simulate a service, with several Characteristics: | 137 // Simulate a service, with several Characteristics: |
| 139 std::vector<std::string> services; | 138 std::vector<std::string> services; |
| 140 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); | 139 services.push_back(kTestUUIDGenericAccess); |
| 141 SimulateGattServicesDiscovered(device, services); | 140 SimulateGattServicesDiscovered(device, services); |
| 142 base::RunLoop().RunUntilIdle(); | 141 base::RunLoop().RunUntilIdle(); |
| 143 BluetoothRemoteGattService* service = device->GetGattServices()[0]; | 142 BluetoothRemoteGattService* service = device->GetGattServices()[0]; |
| 144 std::string characteristic_uuid1 = "11111111-0000-1000-8000-00805f9b34fb"; | 143 SimulateGattCharacteristic(service, kTestUUIDDeviceName, /* properties */ 0); |
| 145 std::string characteristic_uuid2 = "22222222-0000-1000-8000-00805f9b34fb"; | 144 SimulateGattCharacteristic(service, kTestUUIDAppearance, |
| 146 std::string characteristic_uuid3 = characteristic_uuid2; // Duplicate UUID. | 145 /* properties */ 0); |
| 147 std::string characteristic_uuid4 = "33333333-0000-1000-8000-00805f9b34fb"; | 146 // Duplicate UUID. |
| 148 SimulateGattCharacteristic(service, characteristic_uuid1, /* properties */ 0); | 147 SimulateGattCharacteristic(service, kTestUUIDAppearance, |
| 149 SimulateGattCharacteristic(service, characteristic_uuid2, /* properties */ 0); | 148 /* properties */ 0); |
| 150 SimulateGattCharacteristic(service, characteristic_uuid3, /* properties */ 0); | 149 SimulateGattCharacteristic(service, kTestUUIDReconnectionAddress, |
| 151 SimulateGattCharacteristic(service, characteristic_uuid4, /* properties */ 0); | 150 /* properties */ 0); |
| 152 | 151 |
| 153 // Verify that GetCharacteristic can retrieve characteristics again by ID, | 152 // Verify that GetCharacteristic can retrieve characteristics again by ID, |
| 154 // and that the same Characteristics come back. | 153 // and that the same Characteristics come back. |
| 155 EXPECT_EQ(4u, service->GetCharacteristics().size()); | 154 EXPECT_EQ(4u, service->GetCharacteristics().size()); |
| 156 std::string char_id1 = service->GetCharacteristics()[0]->GetIdentifier(); | 155 std::string char_id1 = service->GetCharacteristics()[0]->GetIdentifier(); |
| 157 std::string char_id2 = service->GetCharacteristics()[1]->GetIdentifier(); | 156 std::string char_id2 = service->GetCharacteristics()[1]->GetIdentifier(); |
| 158 std::string char_id3 = service->GetCharacteristics()[2]->GetIdentifier(); | 157 std::string char_id3 = service->GetCharacteristics()[2]->GetIdentifier(); |
| 159 std::string char_id4 = service->GetCharacteristics()[3]->GetIdentifier(); | 158 std::string char_id4 = service->GetCharacteristics()[3]->GetIdentifier(); |
| 160 BluetoothUUID char_uuid1 = service->GetCharacteristics()[0]->GetUUID(); | 159 BluetoothUUID char_uuid1 = service->GetCharacteristics()[0]->GetUUID(); |
| 161 BluetoothUUID char_uuid2 = service->GetCharacteristics()[1]->GetUUID(); | 160 BluetoothUUID char_uuid2 = service->GetCharacteristics()[1]->GetUUID(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 182 InitWithFakeAdapter(); | 181 InitWithFakeAdapter(); |
| 183 StartLowEnergyDiscoverySession(); | 182 StartLowEnergyDiscoverySession(); |
| 184 BluetoothDevice* device = SimulateLowEnergyDevice(3); | 183 BluetoothDevice* device = SimulateLowEnergyDevice(3); |
| 185 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 184 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 186 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 185 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 187 SimulateGattConnection(device); | 186 SimulateGattConnection(device); |
| 188 base::RunLoop().RunUntilIdle(); | 187 base::RunLoop().RunUntilIdle(); |
| 189 | 188 |
| 190 // Simulate two primary GATT services. | 189 // Simulate two primary GATT services. |
| 191 std::vector<std::string> services; | 190 std::vector<std::string> services; |
| 192 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); | 191 services.push_back(kTestUUIDGenericAccess); |
| 193 services.push_back("01010101-0101-1000-8000-00805f9b34fb"); | 192 services.push_back(kTestUUIDHeartRate); |
| 194 SimulateGattServicesDiscovered(device, services); | 193 SimulateGattServicesDiscovered(device, services); |
| 195 base::RunLoop().RunUntilIdle(); | 194 base::RunLoop().RunUntilIdle(); |
| 196 BluetoothRemoteGattService* service1 = device->GetGattServices()[0]; | 195 BluetoothRemoteGattService* service1 = device->GetGattServices()[0]; |
| 197 BluetoothRemoteGattService* service2 = device->GetGattServices()[1]; | 196 BluetoothRemoteGattService* service2 = device->GetGattServices()[1]; |
| 198 std::string characteristic_uuid1 = "11111111-0000-1000-8000-00805f9b34fb"; | 197 SimulateGattCharacteristic(service1, kTestUUIDDeviceName, |
| 199 std::string characteristic_uuid2 = "22222222-0000-1000-8000-00805f9b34fb"; | |
| 200 SimulateGattCharacteristic(service1, characteristic_uuid1, | |
| 201 /* properties */ 0); | 198 /* properties */ 0); |
| 202 // 2 duplicate UUIDs creating 2 instances. | 199 // 2 duplicate UUIDs creating 2 instances. |
| 203 SimulateGattCharacteristic(service2, characteristic_uuid2, | 200 SimulateGattCharacteristic(service2, kTestUUIDHeartRateMeasurement, |
| 204 /* properties */ 0); | 201 /* properties */ 0); |
| 205 SimulateGattCharacteristic(service2, characteristic_uuid2, | 202 SimulateGattCharacteristic(service2, kTestUUIDHeartRateMeasurement, |
| 206 /* properties */ 0); | 203 /* properties */ 0); |
| 207 | 204 |
| 208 { | 205 { |
| 209 std::vector<BluetoothRemoteGattCharacteristic*> characteristics = | 206 std::vector<BluetoothRemoteGattCharacteristic*> characteristics = |
| 210 service1->GetCharacteristicsByUUID(BluetoothUUID(characteristic_uuid1)); | 207 service1->GetCharacteristicsByUUID(BluetoothUUID(kTestUUIDDeviceName)); |
| 211 EXPECT_EQ(1u, characteristics.size()); | 208 EXPECT_EQ(1u, characteristics.size()); |
| 212 EXPECT_EQ(characteristic_uuid1, | 209 EXPECT_EQ(kTestUUIDDeviceName, |
| 213 characteristics[0]->GetUUID().canonical_value()); | 210 characteristics[0]->GetUUID().canonical_value()); |
| 214 } | 211 } |
| 215 | 212 |
| 216 { | 213 { |
| 217 std::vector<BluetoothRemoteGattCharacteristic*> characteristics = | 214 std::vector<BluetoothRemoteGattCharacteristic*> characteristics = |
| 218 service2->GetCharacteristicsByUUID(BluetoothUUID(characteristic_uuid2)); | 215 service2->GetCharacteristicsByUUID( |
| 216 BluetoothUUID(kTestUUIDHeartRateMeasurement)); |
| 219 EXPECT_EQ(2u, characteristics.size()); | 217 EXPECT_EQ(2u, characteristics.size()); |
| 220 EXPECT_EQ(characteristic_uuid2, | 218 EXPECT_EQ(kTestUUIDHeartRateMeasurement, |
| 221 characteristics[0]->GetUUID().canonical_value()); | 219 characteristics[0]->GetUUID().canonical_value()); |
| 222 EXPECT_EQ(characteristic_uuid2, | 220 EXPECT_EQ(kTestUUIDHeartRateMeasurement, |
| 223 characteristics[1]->GetUUID().canonical_value()); | 221 characteristics[1]->GetUUID().canonical_value()); |
| 224 EXPECT_NE(characteristics[0]->GetIdentifier(), | 222 EXPECT_NE(characteristics[0]->GetIdentifier(), |
| 225 characteristics[1]->GetIdentifier()); | 223 characteristics[1]->GetIdentifier()); |
| 226 } | 224 } |
| 227 | 225 |
| 228 BluetoothUUID characteristic_uuid_not_exist_in_setup( | 226 BluetoothUUID characteristic_uuid_not_exist_in_setup( |
| 229 "33333333-0000-1000-8000-00805f9b34fb"); | 227 "33333333-0000-1000-8000-00805f9b34fb"); |
| 230 EXPECT_TRUE( | 228 EXPECT_TRUE( |
| 231 service1->GetCharacteristicsByUUID(characteristic_uuid_not_exist_in_setup) | 229 service1->GetCharacteristicsByUUID(characteristic_uuid_not_exist_in_setup) |
| 232 .empty()); | 230 .empty()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 247 BluetoothDevice* device = SimulateLowEnergyDevice(3); | 245 BluetoothDevice* device = SimulateLowEnergyDevice(3); |
| 248 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 246 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 249 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 247 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 250 SimulateGattConnection(device); | 248 SimulateGattConnection(device); |
| 251 base::RunLoop().RunUntilIdle(); | 249 base::RunLoop().RunUntilIdle(); |
| 252 | 250 |
| 253 TestBluetoothAdapterObserver observer(adapter_); | 251 TestBluetoothAdapterObserver observer(adapter_); |
| 254 | 252 |
| 255 // Simulate a service, with several Characteristics: | 253 // Simulate a service, with several Characteristics: |
| 256 std::vector<std::string> services; | 254 std::vector<std::string> services; |
| 257 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); | 255 services.push_back(kTestUUIDGenericAccess); |
| 258 SimulateGattServicesDiscovered(device, services); | 256 SimulateGattServicesDiscovered(device, services); |
| 259 base::RunLoop().RunUntilIdle(); | 257 base::RunLoop().RunUntilIdle(); |
| 260 BluetoothRemoteGattService* service = device->GetGattServices()[0]; | 258 BluetoothRemoteGattService* service = device->GetGattServices()[0]; |
| 261 std::string characteristic_uuid1 = "11111111-0000-1000-8000-00805f9b34fb"; | 259 SimulateGattCharacteristic(service, kTestUUIDDeviceName, /* properties */ 0); |
| 262 std::string characteristic_uuid2 = "22222222-0000-1000-8000-00805f9b34fb"; | 260 SimulateGattCharacteristic(service, kTestUUIDAppearance, |
| 263 std::string characteristic_uuid3 = characteristic_uuid2; // Duplicate UUID. | 261 /* properties */ 0); |
| 264 std::string characteristic_uuid4 = "33333333-0000-1000-8000-00805f9b34fb"; | 262 // Duplicate UUID. |
| 265 SimulateGattCharacteristic(service, characteristic_uuid1, /* properties */ 0); | 263 SimulateGattCharacteristic(service, kTestUUIDAppearance, |
| 266 SimulateGattCharacteristic(service, characteristic_uuid2, /* properties */ 0); | 264 /* properties */ 0); |
| 267 SimulateGattCharacteristic(service, characteristic_uuid3, /* properties */ 0); | 265 SimulateGattCharacteristic(service, kTestUUIDReconnectionAddress, |
| 268 SimulateGattCharacteristic(service, characteristic_uuid4, /* properties */ 0); | 266 /* properties */ 0); |
| 269 #if !defined(OS_WIN) | 267 #if !defined(OS_WIN) |
| 270 // TODO(620895) GattCharacteristicAdded has to be implemented for Windows. | 268 // TODO(620895) GattCharacteristicAdded has to be implemented for Windows. |
| 271 EXPECT_EQ(4, observer.gatt_characteristic_added_count()); | 269 EXPECT_EQ(4, observer.gatt_characteristic_added_count()); |
| 272 #endif // !defined(OS_WIN) | 270 #endif // !defined(OS_WIN) |
| 273 | 271 |
| 274 // Simulate remove of characteristics one by one. | 272 // Simulate remove of characteristics one by one. |
| 275 EXPECT_EQ(4u, service->GetCharacteristics().size()); | 273 EXPECT_EQ(4u, service->GetCharacteristics().size()); |
| 276 std::string removed_char = service->GetCharacteristics()[0]->GetIdentifier(); | 274 std::string removed_char = service->GetCharacteristics()[0]->GetIdentifier(); |
| 277 SimulateGattCharacteristicRemoved(service, | 275 SimulateGattCharacteristicRemoved(service, |
| 278 service->GetCharacteristic(removed_char)); | 276 service->GetCharacteristic(removed_char)); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 BluetoothDevice* device = SimulateLowEnergyDevice(3); | 318 BluetoothDevice* device = SimulateLowEnergyDevice(3); |
| 321 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 319 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 322 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 320 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 323 SimulateGattConnection(device); | 321 SimulateGattConnection(device); |
| 324 base::RunLoop().RunUntilIdle(); | 322 base::RunLoop().RunUntilIdle(); |
| 325 | 323 |
| 326 TestBluetoothAdapterObserver observer(adapter_); | 324 TestBluetoothAdapterObserver observer(adapter_); |
| 327 | 325 |
| 328 // Simulate two primary GATT services. | 326 // Simulate two primary GATT services. |
| 329 std::vector<std::string> services; | 327 std::vector<std::string> services; |
| 330 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); | 328 services.push_back(kTestUUIDGenericAccess); |
| 331 services.push_back("01010101-0101-1000-8000-00805f9b34fb"); | 329 services.push_back(kTestUUIDHeartRate); |
| 332 SimulateGattServicesDiscovered(device, services); | 330 SimulateGattServicesDiscovered(device, services); |
| 333 EXPECT_EQ(2u, device->GetGattServices().size()); | 331 EXPECT_EQ(2u, device->GetGattServices().size()); |
| 334 | 332 |
| 335 // Simulate remove of a primary service. | 333 // Simulate remove of a primary service. |
| 336 BluetoothRemoteGattService* service1 = device->GetGattServices()[0]; | 334 BluetoothRemoteGattService* service1 = device->GetGattServices()[0]; |
| 337 BluetoothRemoteGattService* service2 = device->GetGattServices()[1]; | 335 BluetoothRemoteGattService* service2 = device->GetGattServices()[1]; |
| 338 std::string removed_service = service1->GetIdentifier(); | 336 std::string removed_service = service1->GetIdentifier(); |
| 339 SimulateGattServiceRemoved(device->GetGattService(removed_service)); | 337 SimulateGattServiceRemoved(device->GetGattService(removed_service)); |
| 340 EXPECT_EQ(1, observer.gatt_service_removed_count()); | 338 EXPECT_EQ(1, observer.gatt_service_removed_count()); |
| 341 EXPECT_EQ(1u, device->GetGattServices().size()); | 339 EXPECT_EQ(1u, device->GetGattServices().size()); |
| 342 EXPECT_FALSE(device->GetGattService(removed_service)); | 340 EXPECT_FALSE(device->GetGattService(removed_service)); |
| 343 EXPECT_EQ(device->GetGattServices()[0], service2); | 341 EXPECT_EQ(device->GetGattServices()[0], service2); |
| 344 } | 342 } |
| 345 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 343 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
| 346 | 344 |
| 347 } // namespace device | 345 } // namespace device |
| OLD | NEW |