Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: device/bluetooth/bluetooth_device_unittest.cc

Issue 2783733002: Bluetooth: Add service data unit tests for chromeos (Closed)
Patch Set: comments and rebase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 return; 160 return;
161 } 161 }
162 InitWithFakeAdapter(); 162 InitWithFakeAdapter();
163 StartLowEnergyDiscoverySession(); 163 StartLowEnergyDiscoverySession();
164 BluetoothDevice* device = SimulateLowEnergyDevice(3); 164 BluetoothDevice* device = SimulateLowEnergyDevice(3);
165 ASSERT_TRUE(device); 165 ASSERT_TRUE(device);
166 UUIDSet uuids = device->GetUUIDs(); 166 UUIDSet uuids = device->GetUUIDs();
167 EXPECT_EQ(0u, uuids.size()); 167 EXPECT_EQ(0u, uuids.size());
168 } 168 }
169 169
170 #if defined(OS_MACOSX) 170 #if defined(OS_MACOSX) || defined(OS_CHROMEOS) || defined(OS_LINUX)
171 // TODO(ortuno): Enable on Android once it supports Service Data. 171 // TODO(ortuno): Enable on Android once it supports Service Data.
172 // http://crbug.com/639408 172 // http://crbug.com/639408
173 TEST_F(BluetoothTest, GetServiceDataUUIDs_GetServiceDataForUUID) { 173 TEST_F(BluetoothTest, GetServiceDataUUIDs_GetServiceDataForUUID) {
174 if (!PlatformSupportsLowEnergy()) { 174 if (!PlatformSupportsLowEnergy()) {
175 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 175 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
176 return; 176 return;
177 } 177 }
178 InitWithFakeAdapter(); 178 InitWithFakeAdapter();
179
180 #if !defined(OS_LINUX) && !defined(OS_CHROMEOS)
181 // TODO(crbug.com/706043): Remove #if once StartLowEnergyDiscoverySession is
182 // implemented for bluez.
179 StartLowEnergyDiscoverySession(); 183 StartLowEnergyDiscoverySession();
184 #endif // !defined(OS_LINUX) && !defined(OS_CHROMEOS)
185
186 // Receive Advertisement with empty service data.
187 BluetoothDevice* device1 = SimulateLowEnergyDevice(4);
188 EXPECT_TRUE(device1->GetServiceData().empty());
189 EXPECT_TRUE(device1->GetServiceDataUUIDs().empty());
180 190
181 // Receive Advertisement with service data. 191 // Receive Advertisement with service data.
182 BluetoothDevice* device = SimulateLowEnergyDevice(1); 192 BluetoothDevice* device2 = SimulateLowEnergyDevice(1);
183 193
184 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {1}}}), 194 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {1}}}),
185 device->GetServiceData()); 195 device2->GetServiceData());
186 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate)}), 196 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate)}),
187 device->GetServiceDataUUIDs()); 197 device2->GetServiceDataUUIDs());
188 EXPECT_EQ(std::vector<uint8_t>({1}), 198 EXPECT_EQ(std::vector<uint8_t>({1}),
189 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); 199 *device2->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate)));
190 200
191 // Receive Advertisement with no service data. 201 // Receive Advertisement with no service data.
192 SimulateLowEnergyDevice(3); 202 SimulateLowEnergyDevice(3);
193 203
194 EXPECT_TRUE(device->GetServiceData().empty()); 204 // TODO(crbug.com/707039): Remove #if once the BlueZ caching behavior is
195 EXPECT_TRUE(device->GetServiceDataUUIDs().empty()); 205 // changed.
206 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
207 // On ChromeOS and Linux, BlueZ persists all service data meaning if
208 // a device stops advertising service data for a UUID, BlueZ will
209 // still return the cached value for that UUID.
210 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {1}}}),
211 device2->GetServiceData());
212 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate)}),
213 device2->GetServiceDataUUIDs());
214 EXPECT_EQ(std::vector<uint8_t>({1}),
215 *device2->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate)));
216 #else
217 EXPECT_TRUE(device2->GetServiceData().empty());
218 EXPECT_TRUE(device2->GetServiceDataUUIDs().empty());
196 EXPECT_EQ(nullptr, 219 EXPECT_EQ(nullptr,
197 device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); 220 device2->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate)));
221 #endif
198 222
199 // Receive Advertisement with new service data. 223 // Receive Advertisement with new service data.
200 SimulateLowEnergyDevice(2); 224 SimulateLowEnergyDevice(2);
201 225
202 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {2}}, 226 EXPECT_EQ(ServiceDataMap(
203 {BluetoothUUID(kTestUUIDImmediateAlert), {0}}}), 227 {{BluetoothUUID(kTestUUIDHeartRate), std::vector<uint8_t>({})},
204 device->GetServiceData()); 228 {BluetoothUUID(kTestUUIDImmediateAlert), {0, 2}}}),
229 device2->GetServiceData());
205 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate), 230 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate),
206 BluetoothUUID(kTestUUIDImmediateAlert)}), 231 BluetoothUUID(kTestUUIDImmediateAlert)}),
207 device->GetServiceDataUUIDs()); 232 device2->GetServiceDataUUIDs());
208 EXPECT_EQ(std::vector<uint8_t>({2}), 233 EXPECT_EQ(std::vector<uint8_t>({}),
209 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); 234 *device2->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate)));
210 EXPECT_EQ( 235 EXPECT_EQ(
211 std::vector<uint8_t>({0}), 236 std::vector<uint8_t>({0, 2}),
212 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDImmediateAlert))); 237 *device2->GetServiceDataForUUID(BluetoothUUID(kTestUUIDImmediateAlert)));
213 238
239 #if !defined(OS_LINUX) && !defined(OS_CHROMEOS)
240 // TODO(crbug.com/706043): Remove #if once StartLowEnergyDiscoverySession is
241 // implemented for bluez.
214 // Stop discovery. 242 // Stop discovery.
215 discovery_sessions_[0]->Stop(GetCallback(Call::EXPECTED), 243 discovery_sessions_[0]->Stop(GetCallback(Call::EXPECTED),
216 GetErrorCallback(Call::NOT_EXPECTED)); 244 GetErrorCallback(Call::NOT_EXPECTED));
217 ASSERT_FALSE(adapter_->IsDiscovering()); 245 ASSERT_FALSE(adapter_->IsDiscovering());
218 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); 246 ASSERT_FALSE(discovery_sessions_[0]->IsActive());
219 247
220 EXPECT_TRUE(device->GetServiceData().empty()); 248 EXPECT_TRUE(device2->GetServiceData().empty());
221 EXPECT_TRUE(device->GetServiceDataUUIDs().empty()); 249 EXPECT_TRUE(device2->GetServiceDataUUIDs().empty());
222 EXPECT_EQ(nullptr, 250 EXPECT_EQ(nullptr,
223 device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); 251 device2->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate)));
224 EXPECT_EQ(nullptr, device->GetServiceDataForUUID( 252 EXPECT_EQ(nullptr, device2->GetServiceDataForUUID(
225 BluetoothUUID(kTestUUIDImmediateAlert))); 253 BluetoothUUID(kTestUUIDImmediateAlert)));
254 #endif // !defined(OS_LINUX) && !defined(OS_CHROMEOS)
226 } 255 }
227 #endif // defined(OS_MACOSX) 256 #endif // defined(OS_MACOSX) || defined(OS_CHROMEOS) || defined(OS_LINUX)
228 257
229 #if defined(OS_ANDROID) || defined(OS_MACOSX) 258 #if defined(OS_ANDROID) || defined(OS_MACOSX)
230 // Tests that the Advertisement Data fields are correctly updated during 259 // Tests that the Advertisement Data fields are correctly updated during
231 // discovery. 260 // discovery.
232 TEST_F(BluetoothTest, AdvertisementData_Discovery) { 261 TEST_F(BluetoothTest, AdvertisementData_Discovery) {
233 if (!PlatformSupportsLowEnergy()) { 262 if (!PlatformSupportsLowEnergy()) {
234 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 263 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
235 return; 264 return;
236 } 265 }
237 InitWithFakeAdapter(); 266 InitWithFakeAdapter();
(...skipping 1375 matching lines...) Expand 10 before | Expand all | Expand 10 after
1613 .empty()); 1642 .empty());
1614 EXPECT_TRUE(device_ 1643 EXPECT_TRUE(device_
1615 ->GetCharacteristicsByUUID( 1644 ->GetCharacteristicsByUUID(
1616 service_instance_id2, 1645 service_instance_id2,
1617 BluetoothUUID(characteristic_uuid_not_exist_in_setup)) 1646 BluetoothUUID(characteristic_uuid_not_exist_in_setup))
1618 .empty()); 1647 .empty());
1619 } 1648 }
1620 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) 1649 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
1621 1650
1622 } // namespace device 1651 } // namespace device
OLDNEW
« no previous file with comments | « no previous file | device/bluetooth/bluez/bluetooth_bluez_unittest.cc » ('j') | device/bluetooth/test/bluetooth_test_mac.mm » ('J')

Powered by Google App Engine
This is Rietveld 408576698