Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_adapter_mac.h" | 5 #include "device/bluetooth/bluetooth_adapter_mac.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/strings/sys_string_conversions.h" | |
| 11 #include "base/test/test_simple_task_runner.h" | 12 #include "base/test/test_simple_task_runner.h" |
| 12 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 13 #include "device/bluetooth/bluetooth_adapter.h" | 14 #include "device/bluetooth/bluetooth_adapter.h" |
| 14 #include "device/bluetooth/bluetooth_common.h" | 15 #include "device/bluetooth/bluetooth_common.h" |
| 15 #include "device/bluetooth/bluetooth_discovery_session.h" | 16 #include "device/bluetooth/bluetooth_discovery_session.h" |
| 16 #include "device/bluetooth/bluetooth_discovery_session_outcome.h" | 17 #include "device/bluetooth/bluetooth_discovery_session_outcome.h" |
| 17 #include "device/bluetooth/bluetooth_low_energy_device_mac.h" | 18 #include "device/bluetooth/bluetooth_low_energy_device_mac.h" |
| 18 #include "device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h" | 19 #include "device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h" |
| 19 #include "device/bluetooth/test/mock_bluetooth_central_manager_mac.h" | 20 #include "device/bluetooth/test/mock_bluetooth_central_manager_mac.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "third_party/ocmock/OCMock/OCMock.h" | 22 #include "third_party/ocmock/OCMock/OCMock.h" |
| 22 | 23 |
| 23 #if defined(OS_IOS) | 24 #if defined(OS_IOS) |
| 24 #import <CoreBluetooth/CoreBluetooth.h> | 25 #import <CoreBluetooth/CoreBluetooth.h> |
| 25 #else // !defined(OS_IOS) | 26 #else // !defined(OS_IOS) |
| 26 #import <IOBluetooth/IOBluetooth.h> | 27 #import <IOBluetooth/IOBluetooth.h> |
| 27 #endif // defined(OS_IOS) | 28 #endif // defined(OS_IOS) |
| 28 | 29 |
| 29 #import <Foundation/Foundation.h> | 30 #import <Foundation/Foundation.h> |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 // |kTestHashAddress| is the hash corresponding to identifier |kTestNSUUID|. | 33 // |kTestHashAddress| is the hash corresponding to identifier |kTestNSUUID|. |
| 33 const char* const kTestNSUUID = "00000000-1111-2222-3333-444444444444"; | 34 const char* const kTestNSUUID = "00000000-1111-2222-3333-444444444444"; |
| 35 NSString* const kTestNSStringUUIDHeartRate = | |
| 36 @"0000180d-0000-1000-8000-00805f9b34fb"; | |
| 37 NSString* const kTestNSStringUUIDGlucose = | |
| 38 @"00001808-0000-1000-8000-00805f9b34fb"; | |
| 39 const char* kTestStringUUIDHeartRate = "0000180d-0000-1000-8000-00805f9b34fb"; | |
|
Jeffrey Yasskin
2016/08/23 21:37:04
Use either "const char* const kTestString" or "con
| |
| 40 const char* kTestStringUUIDGlucose = "00001808-0000-1000-8000-00805f9b34fb"; | |
| 34 const std::string kTestHashAddress = "D1:6F:E3:22:FD:5B"; | 41 const std::string kTestHashAddress = "D1:6F:E3:22:FD:5B"; |
| 35 const int kTestRssi = 0; | 42 const int kTestRssi = 0; |
| 36 } // namespace | 43 } // namespace |
| 37 | 44 |
| 38 namespace device { | 45 namespace device { |
| 39 | 46 |
| 40 class BluetoothAdapterMacTest : public testing::Test { | 47 class BluetoothAdapterMacTest : public testing::Test { |
| 41 public: | 48 public: |
| 42 BluetoothAdapterMacTest() | 49 BluetoothAdapterMacTest() |
| 43 : ui_task_runner_(new base::TestSimpleTaskRunner()), | 50 : ui_task_runner_(new base::TestSimpleTaskRunner()), |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 void RemoveDiscoverySession(BluetoothDiscoveryFilter* discovery_filter) { | 127 void RemoveDiscoverySession(BluetoothDiscoveryFilter* discovery_filter) { |
| 121 adapter_mac_->RemoveDiscoverySession( | 128 adapter_mac_->RemoveDiscoverySession( |
| 122 discovery_filter, | 129 discovery_filter, |
| 123 base::Bind(&BluetoothAdapterMacTest::Callback, base::Unretained(this)), | 130 base::Bind(&BluetoothAdapterMacTest::Callback, base::Unretained(this)), |
| 124 base::Bind(&BluetoothAdapterMacTest::DiscoveryErrorCallback, | 131 base::Bind(&BluetoothAdapterMacTest::DiscoveryErrorCallback, |
| 125 base::Unretained(this))); | 132 base::Unretained(this))); |
| 126 } | 133 } |
| 127 | 134 |
| 128 int NumDiscoverySessions() { return adapter_mac_->num_discovery_sessions_; } | 135 int NumDiscoverySessions() { return adapter_mac_->num_discovery_sessions_; } |
| 129 | 136 |
| 137 void ResetEventCounts() { | |
| 138 callback_count_ = 0; | |
| 139 error_callback_count_ = 0; | |
| 140 [mock_central_manager_ resetEventCounts]; | |
| 141 } | |
| 142 | |
| 130 // Generic callbacks. | 143 // Generic callbacks. |
| 131 void Callback() { ++callback_count_; } | 144 void Callback() { ++callback_count_; } |
| 132 void ErrorCallback() { ++error_callback_count_; } | 145 void ErrorCallback() { ++error_callback_count_; } |
| 133 void DiscoveryErrorCallback(UMABluetoothDiscoverySessionOutcome) { | 146 void DiscoveryErrorCallback(UMABluetoothDiscoverySessionOutcome) { |
| 134 ++error_callback_count_; | 147 ++error_callback_count_; |
| 135 } | 148 } |
| 136 | 149 |
| 137 protected: | 150 protected: |
| 138 scoped_refptr<base::TestSimpleTaskRunner> ui_task_runner_; | 151 scoped_refptr<base::TestSimpleTaskRunner> ui_task_runner_; |
| 139 scoped_refptr<BluetoothAdapter> adapter_; | 152 scoped_refptr<BluetoothAdapter> adapter_; |
| 140 BluetoothAdapterMac* adapter_mac_; | 153 BluetoothAdapterMac* adapter_mac_; |
| 141 | 154 |
| 142 // Owned by |adapter_mac_|. | 155 // Owned by |adapter_mac_|. |
| 143 base::scoped_nsobject<MockCentralManager> mock_central_manager_; | 156 base::scoped_nsobject<MockCentralManager> mock_central_manager_; |
| 144 | 157 |
| 145 int callback_count_; | 158 int callback_count_; |
| 146 int error_callback_count_; | 159 int error_callback_count_; |
| 147 }; | 160 }; |
| 148 | 161 |
| 149 TEST_F(BluetoothAdapterMacTest, Poll) { | 162 TEST_F(BluetoothAdapterMacTest, Poll) { |
| 150 PollAdapter(); | 163 PollAdapter(); |
| 151 EXPECT_FALSE(ui_task_runner_->GetPendingTasks().empty()); | 164 EXPECT_FALSE(ui_task_runner_->GetPendingTasks().empty()); |
| 152 } | 165 } |
| 153 | 166 |
| 154 TEST_F(BluetoothAdapterMacTest, AddDiscoverySessionWithLowEnergyFilter) { | 167 TEST_F(BluetoothAdapterMacTest, AddDiscoverySession_LowEnergyFilter) { |
| 155 if (!SetMockCentralManager(CBCentralManagerStatePoweredOn)) | 168 if (!SetMockCentralManager(CBCentralManagerStatePoweredOn)) |
| 156 return; | 169 return; |
| 157 EXPECT_EQ(0, [mock_central_manager_ scanForPeripheralsCallCount]); | 170 EXPECT_EQ(0, [mock_central_manager_ scanForPeripheralsCallCount]); |
| 158 EXPECT_EQ(0, NumDiscoverySessions()); | 171 EXPECT_EQ(0, NumDiscoverySessions()); |
| 159 | 172 |
| 160 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter( | 173 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter( |
| 161 new BluetoothDiscoveryFilter(BLUETOOTH_TRANSPORT_LE)); | 174 new BluetoothDiscoveryFilter(BLUETOOTH_TRANSPORT_LE)); |
| 162 AddDiscoverySession(discovery_filter.get()); | 175 discovery_filter->AddUUID(BluetoothUUID(kTestStringUUIDHeartRate)); |
| 163 EXPECT_EQ(1, callback_count_); | 176 discovery_filter->AddUUID(BluetoothUUID(kTestStringUUIDGlucose)); |
| 164 EXPECT_EQ(0, error_callback_count_); | 177 AddDiscoverySession(discovery_filter.get()); |
| 165 EXPECT_EQ(1, NumDiscoverySessions()); | 178 EXPECT_EQ(1, callback_count_); |
| 179 EXPECT_EQ(0, error_callback_count_); | |
| 180 EXPECT_EQ(1, NumDiscoverySessions()); | |
| 181 | |
| 182 NSSet* expected_uuids = [NSSet setWithArray:@[ | |
| 183 [CBUUID UUIDWithString:kTestNSStringUUIDHeartRate], | |
| 184 [CBUUID UUIDWithString:kTestNSStringUUIDGlucose] | |
| 185 ]]; | |
| 186 NSSet* actual_uuids = [NSSet setWithArray:[mock_central_manager_ scan_uuids]]; | |
| 187 | |
| 188 EXPECT_TRUE([actual_uuids isEqualToSet:expected_uuids]); | |
| 166 | 189 |
| 167 // Check that adding a discovery session resulted in | 190 // Check that adding a discovery session resulted in |
| 168 // scanForPeripheralsWithServices being called on the Central Manager. | 191 // scanForPeripheralsWithServices being called on the Central Manager. |
| 169 EXPECT_EQ(1, [mock_central_manager_ scanForPeripheralsCallCount]); | 192 EXPECT_EQ(1, [mock_central_manager_ scanForPeripheralsCallCount]); |
| 170 } | 193 } |
| 171 | 194 |
| 172 // TODO(krstnmnlsn): Test changing the filter when adding the second discovery | 195 TEST_F(BluetoothAdapterMacTest, AddDiscoverySession_TwiceWithNewUUIDs) { |
| 173 // session (once we have that ability). | 196 if (!SetMockCentralManager(CBCentralManagerStatePoweredOn)) |
| 174 TEST_F(BluetoothAdapterMacTest, AddSecondDiscoverySessionWithLowEnergyFilter) { | 197 return; |
| 175 if (!SetMockCentralManager(CBCentralManagerStatePoweredOn)) | 198 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter1( |
| 176 return; | 199 new BluetoothDiscoveryFilter(BLUETOOTH_TRANSPORT_LE)); |
| 177 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter( | 200 discovery_filter1->AddUUID(BluetoothUUID(kTestStringUUIDHeartRate)); |
| 178 new BluetoothDiscoveryFilter(BLUETOOTH_TRANSPORT_LE)); | 201 AddDiscoverySession(discovery_filter1.get()); |
| 179 AddDiscoverySession(discovery_filter.get()); | 202 EXPECT_EQ(1, callback_count_); |
| 180 EXPECT_EQ(1, callback_count_); | 203 EXPECT_EQ(0, error_callback_count_); |
| 181 EXPECT_EQ(0, error_callback_count_); | 204 EXPECT_EQ(1, NumDiscoverySessions()); |
| 182 EXPECT_EQ(1, NumDiscoverySessions()); | 205 NSSet* expected_uuids1 = [NSSet |
| 206 setWithArray:@[ [CBUUID UUIDWithString:kTestNSStringUUIDHeartRate] ]]; | |
| 207 NSSet* actual_uuids1 = | |
| 208 [NSSet setWithArray:[mock_central_manager_ scan_uuids]]; | |
| 209 EXPECT_TRUE([actual_uuids1 isEqualToSet:expected_uuids1]); | |
| 183 | 210 |
| 184 // We replaced the success callback handed to AddDiscoverySession, so | 211 // We replaced the success callback handed to AddDiscoverySession, so |
| 185 // |adapter_mac_| should remain in a discovering state indefinitely. | 212 // |adapter_mac_| should remain in a discovering state indefinitely. |
| 186 EXPECT_TRUE(adapter_mac_->IsDiscovering()); | 213 EXPECT_TRUE(adapter_mac_->IsDiscovering()); |
| 187 | 214 |
| 188 AddDiscoverySession(discovery_filter.get()); | 215 // Add another session with different UUIDs. |
| 189 EXPECT_EQ(2, [mock_central_manager_ scanForPeripheralsCallCount]); | 216 ResetEventCounts(); |
| 190 EXPECT_EQ(2, callback_count_); | 217 |
| 191 EXPECT_EQ(0, error_callback_count_); | 218 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter2( |
| 192 EXPECT_EQ(2, NumDiscoverySessions()); | 219 new BluetoothDiscoveryFilter(BLUETOOTH_TRANSPORT_LE)); |
| 193 } | 220 discovery_filter2->AddUUID(BluetoothUUID(kTestStringUUIDGlucose)); |
| 194 | 221 AddDiscoverySession(discovery_filter2.get()); |
| 195 TEST_F(BluetoothAdapterMacTest, RemoveDiscoverySessionWithLowEnergyFilter) { | 222 // Since the new filter had new UUIDs we update the scan. |
| 196 if (!SetMockCentralManager(CBCentralManagerStatePoweredOn)) | 223 EXPECT_EQ(1, [mock_central_manager_ scanForPeripheralsCallCount]); |
| 197 return; | 224 |
| 198 EXPECT_EQ(0, [mock_central_manager_ scanForPeripheralsCallCount]); | 225 NSSet* expected_uuids2 = [NSSet setWithArray:@[ |
| 199 | 226 [CBUUID UUIDWithString:kTestNSStringUUIDHeartRate], |
| 200 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter( | 227 [CBUUID UUIDWithString:kTestNSStringUUIDGlucose] |
| 201 new BluetoothDiscoveryFilter(BLUETOOTH_TRANSPORT_LE)); | 228 ]]; |
| 202 AddDiscoverySession(discovery_filter.get()); | 229 NSSet* actual_uuids2 = |
| 203 EXPECT_EQ(1, callback_count_); | 230 [NSSet setWithArray:[mock_central_manager_ scan_uuids]]; |
| 204 EXPECT_EQ(0, error_callback_count_); | 231 |
| 205 EXPECT_EQ(1, NumDiscoverySessions()); | 232 EXPECT_TRUE([actual_uuids2 isEqualToSet:expected_uuids2]); |
| 206 | 233 |
| 207 EXPECT_EQ(0, [mock_central_manager_ stopScanCallCount]); | 234 EXPECT_EQ(1, callback_count_); |
| 235 EXPECT_EQ(0, error_callback_count_); | |
| 236 EXPECT_EQ(2, NumDiscoverySessions()); | |
| 237 } | |
| 238 | |
| 239 TEST_F(BluetoothAdapterMacTest, AddDiscoverySession_TwiceWithSameUUIDs) { | |
| 240 if (!SetMockCentralManager(CBCentralManagerStatePoweredOn)) | |
| 241 return; | |
| 242 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter( | |
| 243 new BluetoothDiscoveryFilter(BLUETOOTH_TRANSPORT_LE)); | |
| 244 discovery_filter->AddUUID(BluetoothUUID(kTestStringUUIDHeartRate)); | |
| 245 AddDiscoverySession(discovery_filter.get()); | |
| 246 EXPECT_EQ(1, callback_count_); | |
| 247 EXPECT_EQ(0, error_callback_count_); | |
| 248 EXPECT_EQ(1, NumDiscoverySessions()); | |
| 249 NSSet* expected_uuids = [NSSet | |
| 250 setWithArray:@[ [CBUUID UUIDWithString:kTestNSStringUUIDHeartRate] ]]; | |
| 251 NSSet* actual_uuids = [NSSet setWithArray:[mock_central_manager_ scan_uuids]]; | |
| 252 EXPECT_TRUE([actual_uuids isEqualToSet:expected_uuids]); | |
| 253 | |
| 254 // We replaced the success callback handed to AddDiscoverySession, so | |
| 255 // |adapter_mac_| should remain in a discovering state indefinitely. | |
| 256 EXPECT_TRUE(adapter_mac_->IsDiscovering()); | |
| 257 | |
| 258 // Add another session with the same UUIDs. | |
| 259 ResetEventCounts(); | |
| 260 | |
| 261 AddDiscoverySession(discovery_filter.get()); | |
| 262 // Since the new filter had no new UUIDs no need to update the scan. | |
| 263 EXPECT_EQ(0, [mock_central_manager_ scanForPeripheralsCallCount]); | |
| 264 actual_uuids = [NSSet setWithArray:[mock_central_manager_ scan_uuids]]; | |
| 265 EXPECT_TRUE([actual_uuids isEqualToSet:expected_uuids]); | |
| 266 | |
| 267 EXPECT_EQ(1, callback_count_); | |
| 268 EXPECT_EQ(0, error_callback_count_); | |
| 269 EXPECT_EQ(2, NumDiscoverySessions()); | |
| 270 } | |
| 271 | |
| 272 TEST_F(BluetoothAdapterMacTest, RemoveDiscoverySession_WithLowEnergyFilter) { | |
| 273 if (!SetMockCentralManager(CBCentralManagerStatePoweredOn)) | |
| 274 return; | |
| 275 EXPECT_EQ(0, [mock_central_manager_ scanForPeripheralsCallCount]); | |
| 276 | |
| 277 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter( | |
| 278 new BluetoothDiscoveryFilter(BLUETOOTH_TRANSPORT_LE)); | |
| 279 AddDiscoverySession(discovery_filter.get()); | |
| 280 EXPECT_EQ(1, callback_count_); | |
| 281 EXPECT_EQ(0, error_callback_count_); | |
| 282 EXPECT_EQ(1, NumDiscoverySessions()); | |
| 283 | |
| 284 ResetEventCounts(); | |
| 208 RemoveDiscoverySession(discovery_filter.get()); | 285 RemoveDiscoverySession(discovery_filter.get()); |
| 209 EXPECT_EQ(2, callback_count_); | 286 EXPECT_EQ(1, callback_count_); |
| 210 EXPECT_EQ(0, error_callback_count_); | 287 EXPECT_EQ(0, error_callback_count_); |
| 211 EXPECT_EQ(0, NumDiscoverySessions()); | 288 EXPECT_EQ(0, NumDiscoverySessions()); |
| 212 | 289 |
| 213 // Check that removing the discovery session resulted in stopScan being called | 290 // Check that removing the discovery session resulted in stopScan being called |
| 214 // on the Central Manager. | 291 // on the Central Manager. |
| 215 EXPECT_EQ(1, [mock_central_manager_ stopScanCallCount]); | 292 EXPECT_EQ(1, [mock_central_manager_ stopScanCallCount]); |
| 216 } | 293 } |
| 217 | 294 |
| 295 TEST_F(BluetoothAdapterMacTest, RemoveDiscoverySession_ForDifferentUUID) { | |
| 296 if (!SetMockCentralManager(CBCentralManagerStatePoweredOn)) | |
| 297 return; | |
| 298 // Create filters. | |
| 299 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter1( | |
| 300 new BluetoothDiscoveryFilter(BLUETOOTH_TRANSPORT_LE)); | |
| 301 discovery_filter1->AddUUID(BluetoothUUID(kTestStringUUIDHeartRate)); | |
| 302 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter2( | |
| 303 new BluetoothDiscoveryFilter(BLUETOOTH_TRANSPORT_LE)); | |
| 304 discovery_filter2->AddUUID(BluetoothUUID(kTestStringUUIDGlucose)); | |
| 305 | |
| 306 AddDiscoverySession(discovery_filter1.get()); | |
| 307 AddDiscoverySession(discovery_filter2.get()); | |
| 308 | |
| 309 EXPECT_EQ(2, [mock_central_manager_ scanForPeripheralsCallCount]); | |
| 310 EXPECT_TRUE(adapter_mac_->IsDiscovering()); | |
| 311 EXPECT_EQ(2, callback_count_); | |
| 312 EXPECT_EQ(0, error_callback_count_); | |
| 313 EXPECT_EQ(2, NumDiscoverySessions()); | |
| 314 | |
| 315 NSSet* expected_uuids1 = [NSSet setWithArray:@[ | |
| 316 [CBUUID UUIDWithString:kTestNSStringUUIDHeartRate], | |
| 317 [CBUUID UUIDWithString:kTestNSStringUUIDGlucose] | |
| 318 ]]; | |
| 319 NSSet* actual_uuids1 = | |
| 320 [NSSet setWithArray:[mock_central_manager_ scan_uuids]]; | |
| 321 | |
| 322 EXPECT_TRUE([actual_uuids1 isEqualToSet:expected_uuids1]); | |
| 323 | |
| 324 // Remove one discovery session. | |
| 325 ResetEventCounts(); | |
| 326 | |
| 327 RemoveDiscoverySession(discovery_filter1.get()); | |
| 328 EXPECT_EQ(1, callback_count_); | |
| 329 EXPECT_EQ(0, error_callback_count_); | |
| 330 EXPECT_EQ(1, NumDiscoverySessions()); | |
| 331 EXPECT_EQ(0, [mock_central_manager_ stopScanCallCount]); | |
| 332 EXPECT_EQ(1, [mock_central_manager_ scanForPeripheralsCallCount]); | |
| 333 | |
| 334 // Since we removed the session that scanned for kTestStringUUIDHeartRate, | |
| 335 // we expect to only be scanning for kTestStringUUIDGlucose. | |
| 336 NSSet* expected_uuids2 = [NSSet | |
| 337 setWithArray:@[ [CBUUID UUIDWithString:kTestNSStringUUIDGlucose] ]]; | |
| 338 NSSet* actual_uuids2 = | |
| 339 [NSSet setWithArray:[mock_central_manager_ scan_uuids]]; | |
| 340 | |
| 341 EXPECT_TRUE([actual_uuids2 isEqualToSet:expected_uuids2]); | |
| 342 | |
| 343 // Remove last discovery session. | |
| 344 ResetEventCounts(); | |
| 345 | |
| 346 RemoveDiscoverySession(discovery_filter2.get()); | |
| 347 EXPECT_EQ(1, callback_count_); | |
| 348 EXPECT_EQ(0, error_callback_count_); | |
| 349 EXPECT_EQ(0, NumDiscoverySessions()); | |
| 350 EXPECT_EQ(1, [mock_central_manager_ stopScanCallCount]); | |
| 351 EXPECT_EQ(0, [mock_central_manager_ scanForPeripheralsCallCount]); | |
| 352 } | |
| 353 | |
| 354 TEST_F(BluetoothAdapterMacTest, RemoveDiscoverySession_ForSameUUID) { | |
| 355 // Tests that removing a filter that has a UUID that another filter has | |
| 356 // does not change scan. | |
| 357 if (!SetMockCentralManager(CBCentralManagerStatePoweredOn)) | |
| 358 return; | |
| 359 EXPECT_EQ(0, [mock_central_manager_ scanForPeripheralsCallCount]); | |
| 360 | |
| 361 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter( | |
| 362 new BluetoothDiscoveryFilter(BLUETOOTH_TRANSPORT_LE)); | |
| 363 discovery_filter->AddUUID(BluetoothUUID(kTestStringUUIDHeartRate)); | |
| 364 AddDiscoverySession(discovery_filter.get()); | |
| 365 // Add discovery session with same filters. | |
| 366 AddDiscoverySession(discovery_filter.get()); | |
| 367 EXPECT_EQ(2, callback_count_); | |
| 368 EXPECT_EQ(0, error_callback_count_); | |
| 369 EXPECT_EQ(2, NumDiscoverySessions()); | |
| 370 | |
| 371 // Remove one discovery sesssion. We should not have called stop | |
|
Jeffrey Yasskin
2016/08/23 21:37:04
Is "have called" the right tense here? It looks li
Jeffrey Yasskin
2016/08/23 21:37:04
sp: sesssion
| |
| 372 // because the other filter still scans for the same UUID. | |
| 373 ResetEventCounts(); | |
| 374 | |
| 375 RemoveDiscoverySession(discovery_filter.get()); | |
| 376 EXPECT_EQ(1, callback_count_); | |
| 377 EXPECT_EQ(0, error_callback_count_); | |
| 378 EXPECT_EQ(1, NumDiscoverySessions()); | |
| 379 | |
| 380 EXPECT_EQ(0, [mock_central_manager_ scanForPeripheralsCallCount]); | |
| 381 EXPECT_EQ(0, [mock_central_manager_ stopScanCallCount]); | |
| 382 | |
| 383 // Remove last discovery sesssion. | |
| 384 ResetEventCounts(); | |
| 385 | |
| 386 RemoveDiscoverySession(discovery_filter.get()); | |
| 387 EXPECT_EQ(1, callback_count_); | |
| 388 EXPECT_EQ(0, error_callback_count_); | |
| 389 EXPECT_EQ(0, NumDiscoverySessions()); | |
| 390 | |
| 391 EXPECT_EQ(1, [mock_central_manager_ stopScanCallCount]); | |
| 392 } | |
| 393 | |
| 218 TEST_F(BluetoothAdapterMacTest, RemoveDiscoverySessionWithLowEnergyFilterFail) { | 394 TEST_F(BluetoothAdapterMacTest, RemoveDiscoverySessionWithLowEnergyFilterFail) { |
| 219 if (!SetMockCentralManager(CBCentralManagerStatePoweredOn)) | 395 if (!SetMockCentralManager(CBCentralManagerStatePoweredOn)) |
| 220 return; | 396 return; |
| 221 EXPECT_EQ(0, [mock_central_manager_ scanForPeripheralsCallCount]); | 397 EXPECT_EQ(0, [mock_central_manager_ scanForPeripheralsCallCount]); |
| 222 EXPECT_EQ(0, [mock_central_manager_ stopScanCallCount]); | 398 EXPECT_EQ(0, [mock_central_manager_ stopScanCallCount]); |
| 223 EXPECT_EQ(0, NumDiscoverySessions()); | 399 EXPECT_EQ(0, NumDiscoverySessions()); |
| 224 | 400 |
| 225 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter( | 401 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter( |
| 226 new BluetoothDiscoveryFilter(BLUETOOTH_TRANSPORT_LE)); | 402 new BluetoothDiscoveryFilter(BLUETOOTH_TRANSPORT_LE)); |
| 227 RemoveDiscoverySession(discovery_filter.get()); | 403 RemoveDiscoverySession(discovery_filter.get()); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 253 base::scoped_nsobject<NSDictionary> advertisement_data(AdvertisementData()); | 429 base::scoped_nsobject<NSDictionary> advertisement_data(AdvertisementData()); |
| 254 | 430 |
| 255 EXPECT_EQ(0, NumDevices()); | 431 EXPECT_EQ(0, NumDevices()); |
| 256 EXPECT_FALSE(DevicePresent(mock_peripheral)); | 432 EXPECT_FALSE(DevicePresent(mock_peripheral)); |
| 257 LowEnergyDeviceUpdated(mock_peripheral, advertisement_data, kTestRssi); | 433 LowEnergyDeviceUpdated(mock_peripheral, advertisement_data, kTestRssi); |
| 258 EXPECT_EQ(1, NumDevices()); | 434 EXPECT_EQ(1, NumDevices()); |
| 259 EXPECT_TRUE(DevicePresent(mock_peripheral)); | 435 EXPECT_TRUE(DevicePresent(mock_peripheral)); |
| 260 } | 436 } |
| 261 | 437 |
| 262 } // namespace device | 438 } // namespace device |
| OLD | NEW |