| 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 "content/shell/browser/layout_test/layout_test_bluetooth_adapter_provid
er.h" | 5 #include "content/shell/browser/layout_test/layout_test_bluetooth_adapter_provid
er.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 // modified and have devices added to it. The call to ::GetDevices will | 209 // modified and have devices added to it. The call to ::GetDevices will |
| 210 // invoke ::GetConstMockDevices, returning all devices added up to that time. | 210 // invoke ::GetConstMockDevices, returning all devices added up to that time. |
| 211 ON_CALL(*adapter, GetDevices()) | 211 ON_CALL(*adapter, GetDevices()) |
| 212 .WillByDefault( | 212 .WillByDefault( |
| 213 Invoke(adapter.get(), &MockBluetoothAdapter::GetConstMockDevices)); | 213 Invoke(adapter.get(), &MockBluetoothAdapter::GetConstMockDevices)); |
| 214 | 214 |
| 215 // The call to ::GetDevice will invoke GetMockDevice which returns a device | 215 // The call to ::GetDevice will invoke GetMockDevice which returns a device |
| 216 // matching the address provided if the device was added to the mock. | 216 // matching the address provided if the device was added to the mock. |
| 217 ON_CALL(*adapter, GetDevice(_)).WillByDefault(GetMockDevice(adapter.get())); | 217 ON_CALL(*adapter, GetDevice(_)).WillByDefault(GetMockDevice(adapter.get())); |
| 218 | 218 |
| 219 return adapter.Pass(); | 219 return adapter; |
| 220 } | 220 } |
| 221 | 221 |
| 222 // static | 222 // static |
| 223 scoped_refptr<NiceMockBluetoothAdapter> | 223 scoped_refptr<NiceMockBluetoothAdapter> |
| 224 LayoutTestBluetoothAdapterProvider::GetPresentAdapter() { | 224 LayoutTestBluetoothAdapterProvider::GetPresentAdapter() { |
| 225 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetBaseAdapter()); | 225 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetBaseAdapter()); |
| 226 ON_CALL(*adapter, IsPresent()).WillByDefault(Return(true)); | 226 ON_CALL(*adapter, IsPresent()).WillByDefault(Return(true)); |
| 227 | 227 |
| 228 return adapter.Pass(); | 228 return adapter; |
| 229 } | 229 } |
| 230 | 230 |
| 231 // static | 231 // static |
| 232 scoped_refptr<NiceMockBluetoothAdapter> | 232 scoped_refptr<NiceMockBluetoothAdapter> |
| 233 LayoutTestBluetoothAdapterProvider::GetNotPresentAdapter() { | 233 LayoutTestBluetoothAdapterProvider::GetNotPresentAdapter() { |
| 234 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetBaseAdapter()); | 234 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetBaseAdapter()); |
| 235 ON_CALL(*adapter, IsPresent()).WillByDefault(Return(false)); | 235 ON_CALL(*adapter, IsPresent()).WillByDefault(Return(false)); |
| 236 | 236 |
| 237 return adapter.Pass(); | 237 return adapter; |
| 238 } | 238 } |
| 239 | 239 |
| 240 // static | 240 // static |
| 241 scoped_refptr<NiceMockBluetoothAdapter> | 241 scoped_refptr<NiceMockBluetoothAdapter> |
| 242 LayoutTestBluetoothAdapterProvider::GetPoweredAdapter() { | 242 LayoutTestBluetoothAdapterProvider::GetPoweredAdapter() { |
| 243 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetPresentAdapter()); | 243 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetPresentAdapter()); |
| 244 ON_CALL(*adapter, IsPowered()).WillByDefault(Return(true)); | 244 ON_CALL(*adapter, IsPowered()).WillByDefault(Return(true)); |
| 245 | 245 |
| 246 return adapter.Pass(); | 246 return adapter; |
| 247 } | 247 } |
| 248 | 248 |
| 249 // static | 249 // static |
| 250 scoped_refptr<NiceMockBluetoothAdapter> | 250 scoped_refptr<NiceMockBluetoothAdapter> |
| 251 LayoutTestBluetoothAdapterProvider::GetNotPoweredAdapter() { | 251 LayoutTestBluetoothAdapterProvider::GetNotPoweredAdapter() { |
| 252 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetPresentAdapter()); | 252 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetPresentAdapter()); |
| 253 ON_CALL(*adapter, IsPowered()).WillByDefault(Return(false)); | 253 ON_CALL(*adapter, IsPowered()).WillByDefault(Return(false)); |
| 254 | 254 |
| 255 return adapter.Pass(); | 255 return adapter; |
| 256 } | 256 } |
| 257 | 257 |
| 258 // static | 258 // static |
| 259 scoped_refptr<NiceMockBluetoothAdapter> | 259 scoped_refptr<NiceMockBluetoothAdapter> |
| 260 LayoutTestBluetoothAdapterProvider::GetScanFilterCheckingAdapter() { | 260 LayoutTestBluetoothAdapterProvider::GetScanFilterCheckingAdapter() { |
| 261 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetPoweredAdapter()); | 261 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetPoweredAdapter()); |
| 262 | 262 |
| 263 // This fails the test with an error message listing actual and expected UUIDs | 263 // This fails the test with an error message listing actual and expected UUIDs |
| 264 // if StartDiscoverySessionWithFilter() is called with the wrong argument. | 264 // if StartDiscoverySessionWithFilter() is called with the wrong argument. |
| 265 EXPECT_CALL( | 265 EXPECT_CALL( |
| 266 *adapter, | 266 *adapter, |
| 267 StartDiscoverySessionWithFilterRaw( | 267 StartDiscoverySessionWithFilterRaw( |
| 268 ResultOf(&GetUUIDs, ElementsAre(BluetoothUUID(kGlucoseServiceUUID), | 268 ResultOf(&GetUUIDs, ElementsAre(BluetoothUUID(kGlucoseServiceUUID), |
| 269 BluetoothUUID(kHeartRateServiceUUID), | 269 BluetoothUUID(kHeartRateServiceUUID), |
| 270 BluetoothUUID(kBatteryServiceUUID))), | 270 BluetoothUUID(kBatteryServiceUUID))), |
| 271 _, _)) | 271 _, _)) |
| 272 .WillRepeatedly(RunCallbackWithResult<1 /* success_callback */>( | 272 .WillRepeatedly(RunCallbackWithResult<1 /* success_callback */>( |
| 273 []() { return GetDiscoverySession(); })); | 273 []() { return GetDiscoverySession(); })); |
| 274 | 274 |
| 275 // Any unexpected call results in the failure callback. | 275 // Any unexpected call results in the failure callback. |
| 276 ON_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _)) | 276 ON_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _)) |
| 277 .WillByDefault(RunCallback<2 /* error_callback */>()); | 277 .WillByDefault(RunCallback<2 /* error_callback */>()); |
| 278 | 278 |
| 279 // We need to add a device otherwise requestDevice would reject. | 279 // We need to add a device otherwise requestDevice would reject. |
| 280 adapter->AddMockDevice(GetBatteryDevice(adapter.get())); | 280 adapter->AddMockDevice(GetBatteryDevice(adapter.get())); |
| 281 | 281 |
| 282 return adapter.Pass(); | 282 return adapter; |
| 283 } | 283 } |
| 284 | 284 |
| 285 // static | 285 // static |
| 286 scoped_refptr<NiceMockBluetoothAdapter> | 286 scoped_refptr<NiceMockBluetoothAdapter> |
| 287 LayoutTestBluetoothAdapterProvider::GetFailStartDiscoveryAdapter() { | 287 LayoutTestBluetoothAdapterProvider::GetFailStartDiscoveryAdapter() { |
| 288 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetPoweredAdapter()); | 288 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetPoweredAdapter()); |
| 289 | 289 |
| 290 ON_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _)) | 290 ON_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _)) |
| 291 .WillByDefault(RunCallback<2 /* error_callback */>()); | 291 .WillByDefault(RunCallback<2 /* error_callback */>()); |
| 292 | 292 |
| 293 return adapter.Pass(); | 293 return adapter; |
| 294 } | 294 } |
| 295 | 295 |
| 296 // static | 296 // static |
| 297 scoped_refptr<NiceMockBluetoothAdapter> | 297 scoped_refptr<NiceMockBluetoothAdapter> |
| 298 LayoutTestBluetoothAdapterProvider::GetEmptyAdapter() { | 298 LayoutTestBluetoothAdapterProvider::GetEmptyAdapter() { |
| 299 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetPoweredAdapter()); | 299 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetPoweredAdapter()); |
| 300 | 300 |
| 301 ON_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _)) | 301 ON_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _)) |
| 302 .WillByDefault(RunCallbackWithResult<1 /* success_callback */>( | 302 .WillByDefault(RunCallbackWithResult<1 /* success_callback */>( |
| 303 []() { return GetDiscoverySession(); })); | 303 []() { return GetDiscoverySession(); })); |
| 304 | 304 |
| 305 return adapter.Pass(); | 305 return adapter; |
| 306 } | 306 } |
| 307 | 307 |
| 308 // static | 308 // static |
| 309 scoped_refptr<NiceMockBluetoothAdapter> | 309 scoped_refptr<NiceMockBluetoothAdapter> |
| 310 LayoutTestBluetoothAdapterProvider::GetPowerValueAdapter(int8_t tx_power, | 310 LayoutTestBluetoothAdapterProvider::GetPowerValueAdapter(int8_t tx_power, |
| 311 int8_t rssi) { | 311 int8_t rssi) { |
| 312 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 312 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
| 313 scoped_ptr<NiceMockBluetoothDevice> device(GetHeartRateDevice(adapter.get())); | 313 scoped_ptr<NiceMockBluetoothDevice> device(GetHeartRateDevice(adapter.get())); |
| 314 | 314 |
| 315 ON_CALL(*device, GetInquiryTxPower()).WillByDefault(Return(tx_power)); | 315 ON_CALL(*device, GetInquiryTxPower()).WillByDefault(Return(tx_power)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 335 } | 335 } |
| 336 | 336 |
| 337 // static | 337 // static |
| 338 scoped_refptr<NiceMockBluetoothAdapter> | 338 scoped_refptr<NiceMockBluetoothAdapter> |
| 339 LayoutTestBluetoothAdapterProvider::GetGlucoseHeartRateAdapter() { | 339 LayoutTestBluetoothAdapterProvider::GetGlucoseHeartRateAdapter() { |
| 340 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 340 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
| 341 | 341 |
| 342 adapter->AddMockDevice(GetHeartRateDevice(adapter.get())); | 342 adapter->AddMockDevice(GetHeartRateDevice(adapter.get())); |
| 343 adapter->AddMockDevice(GetGlucoseDevice(adapter.get())); | 343 adapter->AddMockDevice(GetGlucoseDevice(adapter.get())); |
| 344 | 344 |
| 345 return adapter.Pass(); | 345 return adapter; |
| 346 } | 346 } |
| 347 | 347 |
| 348 // static | 348 // static |
| 349 scoped_refptr<NiceMockBluetoothAdapter> | 349 scoped_refptr<NiceMockBluetoothAdapter> |
| 350 LayoutTestBluetoothAdapterProvider::GetUnicodeDeviceAdapter() { | 350 LayoutTestBluetoothAdapterProvider::GetUnicodeDeviceAdapter() { |
| 351 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 351 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
| 352 | 352 |
| 353 adapter->AddMockDevice(GetBaseDevice(adapter.get(), "❤❤❤❤❤❤❤❤❤")); | 353 adapter->AddMockDevice(GetBaseDevice(adapter.get(), "❤❤❤❤❤❤❤❤❤")); |
| 354 | 354 |
| 355 return adapter.Pass(); | 355 return adapter; |
| 356 } | 356 } |
| 357 | 357 |
| 358 // Adds a device to |adapter| and notifies all observers about that new device. | 358 // Adds a device to |adapter| and notifies all observers about that new device. |
| 359 // Mocks can call this asynchronously to cause changes in the middle of a test. | 359 // Mocks can call this asynchronously to cause changes in the middle of a test. |
| 360 static void AddDevice(scoped_refptr<NiceMockBluetoothAdapter> adapter, | 360 static void AddDevice(scoped_refptr<NiceMockBluetoothAdapter> adapter, |
| 361 scoped_ptr<NiceMockBluetoothDevice> new_device) { | 361 scoped_ptr<NiceMockBluetoothDevice> new_device) { |
| 362 NiceMockBluetoothDevice* new_device_ptr = new_device.get(); | 362 NiceMockBluetoothDevice* new_device_ptr = new_device.get(); |
| 363 adapter->AddMockDevice(new_device.Pass()); | 363 adapter->AddMockDevice(new_device.Pass()); |
| 364 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, adapter->GetObservers(), | 364 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, adapter->GetObservers(), |
| 365 DeviceAdded(adapter.get(), new_device_ptr)); | 365 DeviceAdded(adapter.get(), new_device_ptr)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 389 return adapter; | 389 return adapter; |
| 390 } | 390 } |
| 391 | 391 |
| 392 // static | 392 // static |
| 393 scoped_refptr<NiceMockBluetoothAdapter> | 393 scoped_refptr<NiceMockBluetoothAdapter> |
| 394 LayoutTestBluetoothAdapterProvider::GetMissingServiceHeartRateAdapter() { | 394 LayoutTestBluetoothAdapterProvider::GetMissingServiceHeartRateAdapter() { |
| 395 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 395 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
| 396 | 396 |
| 397 adapter->AddMockDevice(GetHeartRateDevice(adapter.get())); | 397 adapter->AddMockDevice(GetHeartRateDevice(adapter.get())); |
| 398 | 398 |
| 399 return adapter.Pass(); | 399 return adapter; |
| 400 } | 400 } |
| 401 | 401 |
| 402 // static | 402 // static |
| 403 scoped_refptr<NiceMockBluetoothAdapter> | 403 scoped_refptr<NiceMockBluetoothAdapter> |
| 404 LayoutTestBluetoothAdapterProvider::GetMissingCharacteristicHeartRateAdapter() { | 404 LayoutTestBluetoothAdapterProvider::GetMissingCharacteristicHeartRateAdapter() { |
| 405 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 405 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
| 406 | 406 |
| 407 scoped_ptr<NiceMockBluetoothDevice> device(GetHeartRateDevice(adapter.get())); | 407 scoped_ptr<NiceMockBluetoothDevice> device(GetHeartRateDevice(adapter.get())); |
| 408 | 408 |
| 409 scoped_ptr<NiceMockBluetoothGattService> generic_access( | 409 scoped_ptr<NiceMockBluetoothGattService> generic_access( |
| 410 GetBaseGATTService(device.get(), kGenericAccessServiceUUID)); | 410 GetBaseGATTService(device.get(), kGenericAccessServiceUUID)); |
| 411 scoped_ptr<NiceMockBluetoothGattService> heart_rate( | 411 scoped_ptr<NiceMockBluetoothGattService> heart_rate( |
| 412 GetBaseGATTService(device.get(), kHeartRateServiceUUID)); | 412 GetBaseGATTService(device.get(), kHeartRateServiceUUID)); |
| 413 | 413 |
| 414 // Intentionally NOT adding a characteristic to heart_rate service. | 414 // Intentionally NOT adding a characteristic to heart_rate service. |
| 415 | 415 |
| 416 device->AddMockService(generic_access.Pass()); | 416 device->AddMockService(generic_access.Pass()); |
| 417 device->AddMockService(heart_rate.Pass()); | 417 device->AddMockService(heart_rate.Pass()); |
| 418 adapter->AddMockDevice(device.Pass()); | 418 adapter->AddMockDevice(device.Pass()); |
| 419 | 419 |
| 420 return adapter.Pass(); | 420 return adapter; |
| 421 } | 421 } |
| 422 | 422 |
| 423 // static | 423 // static |
| 424 scoped_refptr<NiceMockBluetoothAdapter> | 424 scoped_refptr<NiceMockBluetoothAdapter> |
| 425 LayoutTestBluetoothAdapterProvider::GetDelayedServicesDiscoveryAdapter() { | 425 LayoutTestBluetoothAdapterProvider::GetDelayedServicesDiscoveryAdapter() { |
| 426 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 426 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
| 427 scoped_ptr<NiceMockBluetoothDevice> device(GetHeartRateDevice(adapter.get())); | 427 scoped_ptr<NiceMockBluetoothDevice> device(GetHeartRateDevice(adapter.get())); |
| 428 | 428 |
| 429 MockBluetoothAdapter* adapter_ptr = adapter.get(); | 429 MockBluetoothAdapter* adapter_ptr = adapter.get(); |
| 430 MockBluetoothDevice* device_ptr = device.get(); | 430 MockBluetoothDevice* device_ptr = device.get(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 455 base::ThreadTaskRunnerHandle::Get()->PostTask( | 455 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 456 FROM_HERE, base::Bind(&NotifyServicesDiscovered, | 456 FROM_HERE, base::Bind(&NotifyServicesDiscovered, |
| 457 make_scoped_refptr(adapter_ptr), device_ptr)); | 457 make_scoped_refptr(adapter_ptr), device_ptr)); |
| 458 | 458 |
| 459 DCHECK(services.size() == 0); | 459 DCHECK(services.size() == 0); |
| 460 return services; | 460 return services; |
| 461 })); | 461 })); |
| 462 | 462 |
| 463 adapter->AddMockDevice(device.Pass()); | 463 adapter->AddMockDevice(device.Pass()); |
| 464 | 464 |
| 465 return adapter.Pass(); | 465 return adapter; |
| 466 } | 466 } |
| 467 | 467 |
| 468 // static | 468 // static |
| 469 scoped_refptr<NiceMockBluetoothAdapter> | 469 scoped_refptr<NiceMockBluetoothAdapter> |
| 470 LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() { | 470 LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() { |
| 471 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 471 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
| 472 scoped_ptr<NiceMockBluetoothDevice> device(GetHeartRateDevice(adapter.get())); | 472 scoped_ptr<NiceMockBluetoothDevice> device(GetHeartRateDevice(adapter.get())); |
| 473 | 473 |
| 474 // TODO(ortuno): Implement the rest of the service's characteristics | 474 // TODO(ortuno): Implement the rest of the service's characteristics |
| 475 // See: http://crbug.com/529975 | 475 // See: http://crbug.com/529975 |
| 476 | 476 |
| 477 device->AddMockService(GetGenericAccessService(adapter.get(), device.get())); | 477 device->AddMockService(GetGenericAccessService(adapter.get(), device.get())); |
| 478 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); | 478 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); |
| 479 adapter->AddMockDevice(device.Pass()); | 479 adapter->AddMockDevice(device.Pass()); |
| 480 | 480 |
| 481 return adapter; | 481 return adapter; |
| 482 } | 482 } |
| 483 | 483 |
| 484 // static | 484 // static |
| 485 scoped_refptr<NiceMockBluetoothAdapter> | 485 scoped_refptr<NiceMockBluetoothAdapter> |
| 486 LayoutTestBluetoothAdapterProvider::GetFailingConnectionsAdapter() { | 486 LayoutTestBluetoothAdapterProvider::GetFailingConnectionsAdapter() { |
| 487 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 487 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
| 488 | 488 |
| 489 for (int error = BluetoothDevice::ERROR_UNKNOWN; | 489 for (int error = BluetoothDevice::ERROR_UNKNOWN; |
| 490 error <= BluetoothDevice::ERROR_UNSUPPORTED_DEVICE; error++) { | 490 error <= BluetoothDevice::ERROR_UNSUPPORTED_DEVICE; error++) { |
| 491 adapter->AddMockDevice(GetUnconnectableDevice( | 491 adapter->AddMockDevice(GetUnconnectableDevice( |
| 492 adapter.get(), static_cast<BluetoothDevice::ConnectErrorCode>(error))); | 492 adapter.get(), static_cast<BluetoothDevice::ConnectErrorCode>(error))); |
| 493 } | 493 } |
| 494 | 494 |
| 495 return adapter.Pass(); | 495 return adapter; |
| 496 } | 496 } |
| 497 | 497 |
| 498 // static | 498 // static |
| 499 scoped_refptr<NiceMockBluetoothAdapter> | 499 scoped_refptr<NiceMockBluetoothAdapter> |
| 500 LayoutTestBluetoothAdapterProvider::GetFailingGATTOperationsAdapter() { | 500 LayoutTestBluetoothAdapterProvider::GetFailingGATTOperationsAdapter() { |
| 501 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 501 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
| 502 | 502 |
| 503 const std::string errorsServiceUUID = errorUUID(0xA0); | 503 const std::string errorsServiceUUID = errorUUID(0xA0); |
| 504 | 504 |
| 505 BluetoothDevice::UUIDList uuids; | 505 BluetoothDevice::UUIDList uuids; |
| 506 uuids.push_back(BluetoothUUID(errorsServiceUUID)); | 506 uuids.push_back(BluetoothUUID(errorsServiceUUID)); |
| 507 | 507 |
| 508 scoped_ptr<NiceMockBluetoothDevice> device( | 508 scoped_ptr<NiceMockBluetoothDevice> device( |
| 509 GetConnectableDevice(adapter.get(), "Errors Device", uuids)); | 509 GetConnectableDevice(adapter.get(), "Errors Device", uuids)); |
| 510 | 510 |
| 511 scoped_ptr<NiceMockBluetoothGattService> service( | 511 scoped_ptr<NiceMockBluetoothGattService> service( |
| 512 GetBaseGATTService(device.get(), errorsServiceUUID)); | 512 GetBaseGATTService(device.get(), errorsServiceUUID)); |
| 513 | 513 |
| 514 for (int error = BluetoothGattService::GATT_ERROR_UNKNOWN; | 514 for (int error = BluetoothGattService::GATT_ERROR_UNKNOWN; |
| 515 error <= BluetoothGattService::GATT_ERROR_NOT_SUPPORTED; error++) { | 515 error <= BluetoothGattService::GATT_ERROR_NOT_SUPPORTED; error++) { |
| 516 service->AddMockCharacteristic(GetErrorCharacteristic( | 516 service->AddMockCharacteristic(GetErrorCharacteristic( |
| 517 service.get(), | 517 service.get(), |
| 518 static_cast<BluetoothGattService::GattErrorCode>(error))); | 518 static_cast<BluetoothGattService::GattErrorCode>(error))); |
| 519 } | 519 } |
| 520 | 520 |
| 521 device->AddMockService(service.Pass()); | 521 device->AddMockService(service.Pass()); |
| 522 adapter->AddMockDevice(device.Pass()); | 522 adapter->AddMockDevice(device.Pass()); |
| 523 | 523 |
| 524 return adapter.Pass(); | 524 return adapter; |
| 525 } | 525 } |
| 526 | 526 |
| 527 // Discovery Sessions | 527 // Discovery Sessions |
| 528 | 528 |
| 529 // static | 529 // static |
| 530 scoped_ptr<NiceMockBluetoothDiscoverySession> | 530 scoped_ptr<NiceMockBluetoothDiscoverySession> |
| 531 LayoutTestBluetoothAdapterProvider::GetDiscoverySession() { | 531 LayoutTestBluetoothAdapterProvider::GetDiscoverySession() { |
| 532 scoped_ptr<NiceMockBluetoothDiscoverySession> discovery_session( | 532 scoped_ptr<NiceMockBluetoothDiscoverySession> discovery_session( |
| 533 new NiceMockBluetoothDiscoverySession()); | 533 new NiceMockBluetoothDiscoverySession()); |
| 534 | 534 |
| 535 ON_CALL(*discovery_session, Stop(_, _)) | 535 ON_CALL(*discovery_session, Stop(_, _)) |
| 536 .WillByDefault(RunCallback<0 /* success_callback */>()); | 536 .WillByDefault(RunCallback<0 /* success_callback */>()); |
| 537 | 537 |
| 538 return discovery_session.Pass(); | 538 return discovery_session; |
| 539 } | 539 } |
| 540 | 540 |
| 541 // Devices | 541 // Devices |
| 542 | 542 |
| 543 // static | 543 // static |
| 544 scoped_ptr<NiceMockBluetoothDevice> | 544 scoped_ptr<NiceMockBluetoothDevice> |
| 545 LayoutTestBluetoothAdapterProvider::GetBaseDevice( | 545 LayoutTestBluetoothAdapterProvider::GetBaseDevice( |
| 546 MockBluetoothAdapter* adapter, | 546 MockBluetoothAdapter* adapter, |
| 547 const std::string& device_name, | 547 const std::string& device_name, |
| 548 device::BluetoothDevice::UUIDList uuids, | 548 device::BluetoothDevice::UUIDList uuids, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 566 ON_CALL(*device, GetGattService(_)) | 566 ON_CALL(*device, GetGattService(_)) |
| 567 .WillByDefault( | 567 .WillByDefault( |
| 568 Invoke(device.get(), &MockBluetoothDevice::GetMockService)); | 568 Invoke(device.get(), &MockBluetoothDevice::GetMockService)); |
| 569 | 569 |
| 570 ON_CALL(*device, GetVendorIDSource()) | 570 ON_CALL(*device, GetVendorIDSource()) |
| 571 .WillByDefault(Return(BluetoothDevice::VENDOR_ID_BLUETOOTH)); | 571 .WillByDefault(Return(BluetoothDevice::VENDOR_ID_BLUETOOTH)); |
| 572 ON_CALL(*device, GetVendorID()).WillByDefault(Return(0xFFFF)); | 572 ON_CALL(*device, GetVendorID()).WillByDefault(Return(0xFFFF)); |
| 573 ON_CALL(*device, GetProductID()).WillByDefault(Return(1)); | 573 ON_CALL(*device, GetProductID()).WillByDefault(Return(1)); |
| 574 ON_CALL(*device, GetDeviceID()).WillByDefault(Return(2)); | 574 ON_CALL(*device, GetDeviceID()).WillByDefault(Return(2)); |
| 575 | 575 |
| 576 return device.Pass(); | 576 return device; |
| 577 } | 577 } |
| 578 | 578 |
| 579 // static | 579 // static |
| 580 scoped_ptr<NiceMockBluetoothDevice> | 580 scoped_ptr<NiceMockBluetoothDevice> |
| 581 LayoutTestBluetoothAdapterProvider::GetBatteryDevice( | 581 LayoutTestBluetoothAdapterProvider::GetBatteryDevice( |
| 582 MockBluetoothAdapter* adapter) { | 582 MockBluetoothAdapter* adapter) { |
| 583 BluetoothDevice::UUIDList uuids; | 583 BluetoothDevice::UUIDList uuids; |
| 584 uuids.push_back(BluetoothUUID(kBatteryServiceUUID)); | 584 uuids.push_back(BluetoothUUID(kBatteryServiceUUID)); |
| 585 | 585 |
| 586 return GetBaseDevice(adapter, "Battery Device", uuids, makeMACAddress(0x1)); | 586 return GetBaseDevice(adapter, "Battery Device", uuids, makeMACAddress(0x1)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 612 ON_CALL(*device, CreateGattConnection(_, _)) | 612 ON_CALL(*device, CreateGattConnection(_, _)) |
| 613 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( | 613 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( |
| 614 [adapter, device_ptr]() { | 614 [adapter, device_ptr]() { |
| 615 base::ThreadTaskRunnerHandle::Get()->PostTask( | 615 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 616 FROM_HERE, base::Bind(&NotifyServicesDiscovered, | 616 FROM_HERE, base::Bind(&NotifyServicesDiscovered, |
| 617 make_scoped_refptr(adapter), device_ptr)); | 617 make_scoped_refptr(adapter), device_ptr)); |
| 618 return make_scoped_ptr(new NiceMockBluetoothGattConnection( | 618 return make_scoped_ptr(new NiceMockBluetoothGattConnection( |
| 619 adapter, device_ptr->GetAddress())); | 619 adapter, device_ptr->GetAddress())); |
| 620 })); | 620 })); |
| 621 | 621 |
| 622 return device.Pass(); | 622 return device; |
| 623 } | 623 } |
| 624 | 624 |
| 625 // static | 625 // static |
| 626 scoped_ptr<NiceMockBluetoothDevice> | 626 scoped_ptr<NiceMockBluetoothDevice> |
| 627 LayoutTestBluetoothAdapterProvider::GetUnconnectableDevice( | 627 LayoutTestBluetoothAdapterProvider::GetUnconnectableDevice( |
| 628 MockBluetoothAdapter* adapter, | 628 MockBluetoothAdapter* adapter, |
| 629 BluetoothDevice::ConnectErrorCode error_code, | 629 BluetoothDevice::ConnectErrorCode error_code, |
| 630 const std::string& device_name) { | 630 const std::string& device_name) { |
| 631 BluetoothDevice::UUIDList uuids; | 631 BluetoothDevice::UUIDList uuids; |
| 632 uuids.push_back(BluetoothUUID(errorUUID(error_code))); | 632 uuids.push_back(BluetoothUUID(errorUUID(error_code))); |
| 633 | 633 |
| 634 scoped_ptr<NiceMockBluetoothDevice> device( | 634 scoped_ptr<NiceMockBluetoothDevice> device( |
| 635 GetBaseDevice(adapter, device_name, uuids, makeMACAddress(error_code))); | 635 GetBaseDevice(adapter, device_name, uuids, makeMACAddress(error_code))); |
| 636 | 636 |
| 637 ON_CALL(*device, CreateGattConnection(_, _)) | 637 ON_CALL(*device, CreateGattConnection(_, _)) |
| 638 .WillByDefault(RunCallback<1 /* error_callback */>(error_code)); | 638 .WillByDefault(RunCallback<1 /* error_callback */>(error_code)); |
| 639 | 639 |
| 640 return device.Pass(); | 640 return device; |
| 641 } | 641 } |
| 642 | 642 |
| 643 // static | 643 // static |
| 644 scoped_ptr<NiceMockBluetoothDevice> | 644 scoped_ptr<NiceMockBluetoothDevice> |
| 645 LayoutTestBluetoothAdapterProvider::GetHeartRateDevice( | 645 LayoutTestBluetoothAdapterProvider::GetHeartRateDevice( |
| 646 MockBluetoothAdapter* adapter) { | 646 MockBluetoothAdapter* adapter) { |
| 647 BluetoothDevice::UUIDList uuids; | 647 BluetoothDevice::UUIDList uuids; |
| 648 uuids.push_back(BluetoothUUID(kHeartRateServiceUUID)); | 648 uuids.push_back(BluetoothUUID(kHeartRateServiceUUID)); |
| 649 | 649 |
| 650 return GetConnectableDevice(adapter, "Heart Rate Device", uuids); | 650 return GetConnectableDevice(adapter, "Heart Rate Device", uuids); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 663 true /* is_primary */, false /* is_local */)); | 663 true /* is_primary */, false /* is_local */)); |
| 664 | 664 |
| 665 ON_CALL(*service, GetCharacteristics()) | 665 ON_CALL(*service, GetCharacteristics()) |
| 666 .WillByDefault(Invoke(service.get(), | 666 .WillByDefault(Invoke(service.get(), |
| 667 &MockBluetoothGattService::GetMockCharacteristics)); | 667 &MockBluetoothGattService::GetMockCharacteristics)); |
| 668 | 668 |
| 669 ON_CALL(*service, GetCharacteristic(_)) | 669 ON_CALL(*service, GetCharacteristic(_)) |
| 670 .WillByDefault(Invoke(service.get(), | 670 .WillByDefault(Invoke(service.get(), |
| 671 &MockBluetoothGattService::GetMockCharacteristic)); | 671 &MockBluetoothGattService::GetMockCharacteristic)); |
| 672 | 672 |
| 673 return service.Pass(); | 673 return service; |
| 674 } | 674 } |
| 675 | 675 |
| 676 // static | 676 // static |
| 677 scoped_ptr<NiceMockBluetoothGattService> | 677 scoped_ptr<NiceMockBluetoothGattService> |
| 678 LayoutTestBluetoothAdapterProvider::GetGenericAccessService( | 678 LayoutTestBluetoothAdapterProvider::GetGenericAccessService( |
| 679 MockBluetoothAdapter* adapter, | 679 MockBluetoothAdapter* adapter, |
| 680 MockBluetoothDevice* device) { | 680 MockBluetoothDevice* device) { |
| 681 scoped_ptr<NiceMockBluetoothGattService> generic_access( | 681 scoped_ptr<NiceMockBluetoothGattService> generic_access( |
| 682 GetBaseGATTService(device, kGenericAccessServiceUUID)); | 682 GetBaseGATTService(device, kGenericAccessServiceUUID)); |
| 683 | 683 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 [adapter, measurement_ptr]() { | 724 [adapter, measurement_ptr]() { |
| 725 scoped_ptr<NiceMockBluetoothGattNotifySession> notify_session( | 725 scoped_ptr<NiceMockBluetoothGattNotifySession> notify_session( |
| 726 GetBaseGATTNotifySession(measurement_ptr->GetIdentifier())); | 726 GetBaseGATTNotifySession(measurement_ptr->GetIdentifier())); |
| 727 | 727 |
| 728 std::vector<uint8_t> rate(1 /* size */); | 728 std::vector<uint8_t> rate(1 /* size */); |
| 729 rate[0] = 60; | 729 rate[0] = 60; |
| 730 | 730 |
| 731 notify_session->StartTestNotifications(adapter, measurement_ptr, | 731 notify_session->StartTestNotifications(adapter, measurement_ptr, |
| 732 rate); | 732 rate); |
| 733 | 733 |
| 734 return notify_session.Pass(); | 734 return notify_session; |
| 735 })); | 735 })); |
| 736 | 736 |
| 737 // Body Sensor Location Characteristic | 737 // Body Sensor Location Characteristic |
| 738 scoped_ptr<NiceMockBluetoothGattCharacteristic> body_sensor_location( | 738 scoped_ptr<NiceMockBluetoothGattCharacteristic> body_sensor_location( |
| 739 GetBaseGATTCharacteristic(heart_rate.get(), kBodySensorLocation, | 739 GetBaseGATTCharacteristic(heart_rate.get(), kBodySensorLocation, |
| 740 BluetoothGattCharacteristic::PROPERTY_READ)); | 740 BluetoothGattCharacteristic::PROPERTY_READ)); |
| 741 BluetoothGattCharacteristic* location_ptr = body_sensor_location.get(); | 741 BluetoothGattCharacteristic* location_ptr = body_sensor_location.get(); |
| 742 | 742 |
| 743 ON_CALL(*body_sensor_location, ReadRemoteCharacteristic(_, _)) | 743 ON_CALL(*body_sensor_location, ReadRemoteCharacteristic(_, _)) |
| 744 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( | 744 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 793 .WillByDefault(RunCallback<1 /* error_callback */>(error_code)); | 793 .WillByDefault(RunCallback<1 /* error_callback */>(error_code)); |
| 794 | 794 |
| 795 // Write response. | 795 // Write response. |
| 796 ON_CALL(*characteristic, WriteRemoteCharacteristic(_, _, _)) | 796 ON_CALL(*characteristic, WriteRemoteCharacteristic(_, _, _)) |
| 797 .WillByDefault(RunCallback<2 /* error_callback */>(error_code)); | 797 .WillByDefault(RunCallback<2 /* error_callback */>(error_code)); |
| 798 | 798 |
| 799 // StartNotifySession response | 799 // StartNotifySession response |
| 800 ON_CALL(*characteristic, StartNotifySession(_, _)) | 800 ON_CALL(*characteristic, StartNotifySession(_, _)) |
| 801 .WillByDefault(RunCallback<1 /* error_callback */>(error_code)); | 801 .WillByDefault(RunCallback<1 /* error_callback */>(error_code)); |
| 802 | 802 |
| 803 return characteristic.Pass(); | 803 return characteristic; |
| 804 } | 804 } |
| 805 | 805 |
| 806 // Notify sessions | 806 // Notify sessions |
| 807 | 807 |
| 808 // static | 808 // static |
| 809 scoped_ptr<NiceMockBluetoothGattNotifySession> | 809 scoped_ptr<NiceMockBluetoothGattNotifySession> |
| 810 LayoutTestBluetoothAdapterProvider::GetBaseGATTNotifySession( | 810 LayoutTestBluetoothAdapterProvider::GetBaseGATTNotifySession( |
| 811 const std::string& characteristic_identifier) { | 811 const std::string& characteristic_identifier) { |
| 812 scoped_ptr<NiceMockBluetoothGattNotifySession> session( | 812 scoped_ptr<NiceMockBluetoothGattNotifySession> session( |
| 813 new NiceMockBluetoothGattNotifySession(characteristic_identifier)); | 813 new NiceMockBluetoothGattNotifySession(characteristic_identifier)); |
| 814 | 814 |
| 815 ON_CALL(*session, Stop(_)) | 815 ON_CALL(*session, Stop(_)) |
| 816 .WillByDefault(testing::DoAll( | 816 .WillByDefault(testing::DoAll( |
| 817 InvokeWithoutArgs( | 817 InvokeWithoutArgs( |
| 818 session.get(), | 818 session.get(), |
| 819 &MockBluetoothGattNotifySession::StopTestNotifications), | 819 &MockBluetoothGattNotifySession::StopTestNotifications), |
| 820 RunCallback<0>())); | 820 RunCallback<0>())); |
| 821 | 821 |
| 822 return session.Pass(); | 822 return session; |
| 823 } | 823 } |
| 824 | 824 |
| 825 // Helper functions | 825 // Helper functions |
| 826 | 826 |
| 827 // static | 827 // static |
| 828 std::string LayoutTestBluetoothAdapterProvider::errorUUID(uint32_t alias) { | 828 std::string LayoutTestBluetoothAdapterProvider::errorUUID(uint32_t alias) { |
| 829 return base::StringPrintf("%08x-97e5-4cd7-b9f1-f5a427670c59", alias); | 829 return base::StringPrintf("%08x-97e5-4cd7-b9f1-f5a427670c59", alias); |
| 830 } | 830 } |
| 831 | 831 |
| 832 // static | 832 // static |
| 833 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { | 833 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { |
| 834 return BluetoothDevice::CanonicalizeAddress( | 834 return BluetoothDevice::CanonicalizeAddress( |
| 835 base::StringPrintf("%012" PRIx64, addr)); | 835 base::StringPrintf("%012" PRIx64, addr)); |
| 836 } | 836 } |
| 837 | 837 |
| 838 } // namespace content | 838 } // namespace content |
| OLD | NEW |