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