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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/memory/ptr_util.h" |
13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
17 #include "base/thread_task_runner_handle.h" | 18 #include "base/thread_task_runner_handle.h" |
18 #include "device/bluetooth/bluetooth_adapter.h" | 19 #include "device/bluetooth/bluetooth_adapter.h" |
19 #include "device/bluetooth/bluetooth_device.h" | 20 #include "device/bluetooth/bluetooth_device.h" |
20 #include "device/bluetooth/bluetooth_discovery_session.h" | 21 #include "device/bluetooth/bluetooth_discovery_session.h" |
21 #include "device/bluetooth/bluetooth_uuid.h" | 22 #include "device/bluetooth/bluetooth_uuid.h" |
22 #include "device/bluetooth/test/mock_bluetooth_adapter.h" | 23 #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
(...skipping 294 matching lines...) Loading... |
317 []() { return GetDiscoverySession(); })); | 318 []() { return GetDiscoverySession(); })); |
318 | 319 |
319 return adapter; | 320 return adapter; |
320 } | 321 } |
321 | 322 |
322 // static | 323 // static |
323 scoped_refptr<NiceMockBluetoothAdapter> | 324 scoped_refptr<NiceMockBluetoothAdapter> |
324 LayoutTestBluetoothAdapterProvider::GetPowerValueAdapter(int8_t tx_power, | 325 LayoutTestBluetoothAdapterProvider::GetPowerValueAdapter(int8_t tx_power, |
325 int8_t rssi) { | 326 int8_t rssi) { |
326 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 327 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
327 scoped_ptr<NiceMockBluetoothDevice> device(GetHeartRateDevice(adapter.get())); | 328 std::unique_ptr<NiceMockBluetoothDevice> device( |
| 329 GetHeartRateDevice(adapter.get())); |
328 | 330 |
329 ON_CALL(*device, GetInquiryTxPower()).WillByDefault(Return(tx_power)); | 331 ON_CALL(*device, GetInquiryTxPower()).WillByDefault(Return(tx_power)); |
330 ON_CALL(*device, GetInquiryRSSI()).WillByDefault(Return(rssi)); | 332 ON_CALL(*device, GetInquiryRSSI()).WillByDefault(Return(rssi)); |
331 | 333 |
332 adapter->AddMockDevice(std::move(device)); | 334 adapter->AddMockDevice(std::move(device)); |
333 | 335 |
334 return adapter; | 336 return adapter; |
335 } | 337 } |
336 | 338 |
337 // static | 339 // static |
(...skipping 27 matching lines...) Loading... |
365 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 367 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
366 | 368 |
367 adapter->AddMockDevice(GetBaseDevice(adapter.get(), "❤❤❤❤❤❤❤❤❤")); | 369 adapter->AddMockDevice(GetBaseDevice(adapter.get(), "❤❤❤❤❤❤❤❤❤")); |
368 | 370 |
369 return adapter; | 371 return adapter; |
370 } | 372 } |
371 | 373 |
372 // Adds a device to |adapter| and notifies all observers about that new device. | 374 // Adds a device to |adapter| and notifies all observers about that new device. |
373 // Mocks can call this asynchronously to cause changes in the middle of a test. | 375 // Mocks can call this asynchronously to cause changes in the middle of a test. |
374 static void AddDevice(scoped_refptr<NiceMockBluetoothAdapter> adapter, | 376 static void AddDevice(scoped_refptr<NiceMockBluetoothAdapter> adapter, |
375 scoped_ptr<NiceMockBluetoothDevice> new_device) { | 377 std::unique_ptr<NiceMockBluetoothDevice> new_device) { |
376 NiceMockBluetoothDevice* new_device_ptr = new_device.get(); | 378 NiceMockBluetoothDevice* new_device_ptr = new_device.get(); |
377 adapter->AddMockDevice(std::move(new_device)); | 379 adapter->AddMockDevice(std::move(new_device)); |
378 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, adapter->GetObservers(), | 380 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, adapter->GetObservers(), |
379 DeviceAdded(adapter.get(), new_device_ptr)); | 381 DeviceAdded(adapter.get(), new_device_ptr)); |
380 } | 382 } |
381 | 383 |
382 // static | 384 // static |
383 scoped_refptr<NiceMockBluetoothAdapter> | 385 scoped_refptr<NiceMockBluetoothAdapter> |
384 LayoutTestBluetoothAdapterProvider::GetSecondDiscoveryFindsHeartRateAdapter() { | 386 LayoutTestBluetoothAdapterProvider::GetSecondDiscoveryFindsHeartRateAdapter() { |
385 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetPoweredAdapter()); | 387 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetPoweredAdapter()); |
(...skipping 25 matching lines...) Loading... |
411 adapter->AddMockDevice(GetHeartRateDevice(adapter.get())); | 413 adapter->AddMockDevice(GetHeartRateDevice(adapter.get())); |
412 | 414 |
413 return adapter; | 415 return adapter; |
414 } | 416 } |
415 | 417 |
416 // static | 418 // static |
417 scoped_refptr<NiceMockBluetoothAdapter> | 419 scoped_refptr<NiceMockBluetoothAdapter> |
418 LayoutTestBluetoothAdapterProvider::GetMissingCharacteristicHeartRateAdapter() { | 420 LayoutTestBluetoothAdapterProvider::GetMissingCharacteristicHeartRateAdapter() { |
419 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 421 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
420 | 422 |
421 scoped_ptr<NiceMockBluetoothDevice> device(GetHeartRateDevice(adapter.get())); | 423 std::unique_ptr<NiceMockBluetoothDevice> device( |
| 424 GetHeartRateDevice(adapter.get())); |
422 | 425 |
423 scoped_ptr<NiceMockBluetoothGattService> generic_access( | 426 std::unique_ptr<NiceMockBluetoothGattService> generic_access( |
424 GetBaseGATTService(device.get(), kGenericAccessServiceUUID)); | 427 GetBaseGATTService(device.get(), kGenericAccessServiceUUID)); |
425 scoped_ptr<NiceMockBluetoothGattService> heart_rate( | 428 std::unique_ptr<NiceMockBluetoothGattService> heart_rate( |
426 GetBaseGATTService(device.get(), kHeartRateServiceUUID)); | 429 GetBaseGATTService(device.get(), kHeartRateServiceUUID)); |
427 | 430 |
428 // Intentionally NOT adding a characteristic to heart_rate service. | 431 // Intentionally NOT adding a characteristic to heart_rate service. |
429 | 432 |
430 device->AddMockService(std::move(generic_access)); | 433 device->AddMockService(std::move(generic_access)); |
431 device->AddMockService(std::move(heart_rate)); | 434 device->AddMockService(std::move(heart_rate)); |
432 adapter->AddMockDevice(std::move(device)); | 435 adapter->AddMockDevice(std::move(device)); |
433 | 436 |
434 return adapter; | 437 return adapter; |
435 } | 438 } |
436 | 439 |
437 // static | 440 // static |
438 scoped_refptr<NiceMockBluetoothAdapter> | 441 scoped_refptr<NiceMockBluetoothAdapter> |
439 LayoutTestBluetoothAdapterProvider::GetDelayedServicesDiscoveryAdapter() { | 442 LayoutTestBluetoothAdapterProvider::GetDelayedServicesDiscoveryAdapter() { |
440 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 443 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
441 scoped_ptr<NiceMockBluetoothDevice> device(GetHeartRateDevice(adapter.get())); | 444 std::unique_ptr<NiceMockBluetoothDevice> device( |
| 445 GetHeartRateDevice(adapter.get())); |
442 | 446 |
443 MockBluetoothAdapter* adapter_ptr = adapter.get(); | 447 MockBluetoothAdapter* adapter_ptr = adapter.get(); |
444 MockBluetoothDevice* device_ptr = device.get(); | 448 MockBluetoothDevice* device_ptr = device.get(); |
445 | 449 |
446 // Override the previous mock implementation of CreateGattConnection that | 450 // Override the previous mock implementation of CreateGattConnection that |
447 // this a NotifyServicesDiscovered task. Instead thsi adapter will not post | 451 // this a NotifyServicesDiscovered task. Instead thsi adapter will not post |
448 // that task until GetGattServices is called. | 452 // that task until GetGattServices is called. |
449 ON_CALL(*device, CreateGattConnection(_, _)) | 453 ON_CALL(*device, CreateGattConnection(_, _)) |
450 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( | 454 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( |
451 [adapter_ptr, device_ptr]() { | 455 [adapter_ptr, device_ptr]() { |
452 return make_scoped_ptr(new NiceMockBluetoothGattConnection( | 456 return base::WrapUnique(new NiceMockBluetoothGattConnection( |
453 adapter_ptr, device_ptr->GetAddress())); | 457 adapter_ptr, device_ptr->GetAddress())); |
454 })); | 458 })); |
455 | 459 |
456 ON_CALL(*device, GetGattServices()) | 460 ON_CALL(*device, GetGattServices()) |
457 .WillByDefault(Invoke([adapter_ptr, device_ptr] { | 461 .WillByDefault(Invoke([adapter_ptr, device_ptr] { |
458 std::vector<BluetoothGattService*> services = | 462 std::vector<BluetoothGattService*> services = |
459 device_ptr->GetMockServices(); | 463 device_ptr->GetMockServices(); |
460 | 464 |
461 if (services.size() > 0) { | 465 if (services.size() > 0) { |
462 return services; | 466 return services; |
463 } | 467 } |
464 | 468 |
465 scoped_ptr<NiceMockBluetoothGattService> heart_rate( | 469 std::unique_ptr<NiceMockBluetoothGattService> heart_rate( |
466 GetBaseGATTService(device_ptr, kHeartRateServiceUUID)); | 470 GetBaseGATTService(device_ptr, kHeartRateServiceUUID)); |
467 | 471 |
468 device_ptr->AddMockService(std::move(heart_rate)); | 472 device_ptr->AddMockService(std::move(heart_rate)); |
469 base::ThreadTaskRunnerHandle::Get()->PostTask( | 473 base::ThreadTaskRunnerHandle::Get()->PostTask( |
470 FROM_HERE, base::Bind(&NotifyServicesDiscovered, | 474 FROM_HERE, base::Bind(&NotifyServicesDiscovered, |
471 base::RetainedRef(adapter_ptr), device_ptr)); | 475 base::RetainedRef(adapter_ptr), device_ptr)); |
472 | 476 |
473 DCHECK(services.size() == 0); | 477 DCHECK(services.size() == 0); |
474 return services; | 478 return services; |
475 })); | 479 })); |
476 | 480 |
477 adapter->AddMockDevice(std::move(device)); | 481 adapter->AddMockDevice(std::move(device)); |
478 | 482 |
479 return adapter; | 483 return adapter; |
480 } | 484 } |
481 | 485 |
482 // static | 486 // static |
483 scoped_refptr<NiceMockBluetoothAdapter> | 487 scoped_refptr<NiceMockBluetoothAdapter> |
484 LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() { | 488 LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() { |
485 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 489 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
486 scoped_ptr<NiceMockBluetoothDevice> device(GetHeartRateDevice(adapter.get())); | 490 std::unique_ptr<NiceMockBluetoothDevice> device( |
| 491 GetHeartRateDevice(adapter.get())); |
487 | 492 |
488 // TODO(ortuno): Implement the rest of the service's characteristics | 493 // TODO(ortuno): Implement the rest of the service's characteristics |
489 // See: http://crbug.com/529975 | 494 // See: http://crbug.com/529975 |
490 | 495 |
491 device->AddMockService(GetGenericAccessService(device.get())); | 496 device->AddMockService(GetGenericAccessService(device.get())); |
492 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); | 497 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); |
493 adapter->AddMockDevice(std::move(device)); | 498 adapter->AddMockDevice(std::move(device)); |
494 | 499 |
495 return adapter; | 500 return adapter; |
496 } | 501 } |
497 | 502 |
498 // static | 503 // static |
499 scoped_refptr<NiceMockBluetoothAdapter> | 504 scoped_refptr<NiceMockBluetoothAdapter> |
500 LayoutTestBluetoothAdapterProvider::GetBlacklistTestAdapter() { | 505 LayoutTestBluetoothAdapterProvider::GetBlacklistTestAdapter() { |
501 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 506 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
502 | 507 |
503 BluetoothDevice::UUIDList uuids; | 508 BluetoothDevice::UUIDList uuids; |
504 uuids.push_back(BluetoothUUID(kBlacklistTestServiceUUID)); | 509 uuids.push_back(BluetoothUUID(kBlacklistTestServiceUUID)); |
505 uuids.push_back(BluetoothUUID(kDeviceInformationServiceUUID)); | 510 uuids.push_back(BluetoothUUID(kDeviceInformationServiceUUID)); |
506 uuids.push_back(BluetoothUUID(kGenericAccessServiceUUID)); | 511 uuids.push_back(BluetoothUUID(kGenericAccessServiceUUID)); |
507 uuids.push_back(BluetoothUUID(kHeartRateServiceUUID)); | 512 uuids.push_back(BluetoothUUID(kHeartRateServiceUUID)); |
508 uuids.push_back(BluetoothUUID(kHumanInterfaceDeviceServiceUUID)); | 513 uuids.push_back(BluetoothUUID(kHumanInterfaceDeviceServiceUUID)); |
509 | 514 |
510 scoped_ptr<NiceMockBluetoothDevice> device( | 515 std::unique_ptr<NiceMockBluetoothDevice> device( |
511 GetConnectableDevice(adapter.get(), "Blacklist Test Device", uuids)); | 516 GetConnectableDevice(adapter.get(), "Blacklist Test Device", uuids)); |
512 | 517 |
513 device->AddMockService(GetBlacklistTestService(device.get())); | 518 device->AddMockService(GetBlacklistTestService(device.get())); |
514 device->AddMockService(GetDeviceInformationService(device.get())); | 519 device->AddMockService(GetDeviceInformationService(device.get())); |
515 device->AddMockService(GetGenericAccessService(device.get())); | 520 device->AddMockService(GetGenericAccessService(device.get())); |
516 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); | 521 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); |
517 device->AddMockService( | 522 device->AddMockService( |
518 GetBaseGATTService(device.get(), kHumanInterfaceDeviceServiceUUID)); | 523 GetBaseGATTService(device.get(), kHumanInterfaceDeviceServiceUUID)); |
519 adapter->AddMockDevice(std::move(device)); | 524 adapter->AddMockDevice(std::move(device)); |
520 | 525 |
(...skipping 17 matching lines...) Loading... |
538 // static | 543 // static |
539 scoped_refptr<NiceMockBluetoothAdapter> | 544 scoped_refptr<NiceMockBluetoothAdapter> |
540 LayoutTestBluetoothAdapterProvider::GetFailingGATTOperationsAdapter() { | 545 LayoutTestBluetoothAdapterProvider::GetFailingGATTOperationsAdapter() { |
541 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 546 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
542 | 547 |
543 const std::string errorsServiceUUID = errorUUID(0xA0); | 548 const std::string errorsServiceUUID = errorUUID(0xA0); |
544 | 549 |
545 BluetoothDevice::UUIDList uuids; | 550 BluetoothDevice::UUIDList uuids; |
546 uuids.push_back(BluetoothUUID(errorsServiceUUID)); | 551 uuids.push_back(BluetoothUUID(errorsServiceUUID)); |
547 | 552 |
548 scoped_ptr<NiceMockBluetoothDevice> device( | 553 std::unique_ptr<NiceMockBluetoothDevice> device( |
549 GetConnectableDevice(adapter.get(), "Errors Device", uuids)); | 554 GetConnectableDevice(adapter.get(), "Errors Device", uuids)); |
550 | 555 |
551 scoped_ptr<NiceMockBluetoothGattService> service( | 556 std::unique_ptr<NiceMockBluetoothGattService> service( |
552 GetBaseGATTService(device.get(), errorsServiceUUID)); | 557 GetBaseGATTService(device.get(), errorsServiceUUID)); |
553 | 558 |
554 for (int error = BluetoothGattService::GATT_ERROR_UNKNOWN; | 559 for (int error = BluetoothGattService::GATT_ERROR_UNKNOWN; |
555 error <= BluetoothGattService::GATT_ERROR_NOT_SUPPORTED; error++) { | 560 error <= BluetoothGattService::GATT_ERROR_NOT_SUPPORTED; error++) { |
556 service->AddMockCharacteristic(GetErrorCharacteristic( | 561 service->AddMockCharacteristic(GetErrorCharacteristic( |
557 service.get(), | 562 service.get(), |
558 static_cast<BluetoothGattService::GattErrorCode>(error))); | 563 static_cast<BluetoothGattService::GattErrorCode>(error))); |
559 } | 564 } |
560 | 565 |
561 device->AddMockService(std::move(service)); | 566 device->AddMockService(std::move(service)); |
562 adapter->AddMockDevice(std::move(device)); | 567 adapter->AddMockDevice(std::move(device)); |
563 | 568 |
564 return adapter; | 569 return adapter; |
565 } | 570 } |
566 | 571 |
567 // Discovery Sessions | 572 // Discovery Sessions |
568 | 573 |
569 // static | 574 // static |
570 scoped_ptr<NiceMockBluetoothDiscoverySession> | 575 std::unique_ptr<NiceMockBluetoothDiscoverySession> |
571 LayoutTestBluetoothAdapterProvider::GetDiscoverySession() { | 576 LayoutTestBluetoothAdapterProvider::GetDiscoverySession() { |
572 scoped_ptr<NiceMockBluetoothDiscoverySession> discovery_session( | 577 std::unique_ptr<NiceMockBluetoothDiscoverySession> discovery_session( |
573 new NiceMockBluetoothDiscoverySession()); | 578 new NiceMockBluetoothDiscoverySession()); |
574 | 579 |
575 ON_CALL(*discovery_session, Stop(_, _)) | 580 ON_CALL(*discovery_session, Stop(_, _)) |
576 .WillByDefault(RunCallback<0 /* success_callback */>()); | 581 .WillByDefault(RunCallback<0 /* success_callback */>()); |
577 | 582 |
578 return discovery_session; | 583 return discovery_session; |
579 } | 584 } |
580 | 585 |
581 // Devices | 586 // Devices |
582 | 587 |
583 // static | 588 // static |
584 scoped_ptr<NiceMockBluetoothDevice> | 589 std::unique_ptr<NiceMockBluetoothDevice> |
585 LayoutTestBluetoothAdapterProvider::GetBaseDevice( | 590 LayoutTestBluetoothAdapterProvider::GetBaseDevice( |
586 MockBluetoothAdapter* adapter, | 591 MockBluetoothAdapter* adapter, |
587 const std::string& device_name, | 592 const std::string& device_name, |
588 device::BluetoothDevice::UUIDList uuids, | 593 device::BluetoothDevice::UUIDList uuids, |
589 const std::string& address) { | 594 const std::string& address) { |
590 scoped_ptr<NiceMockBluetoothDevice> device(new NiceMockBluetoothDevice( | 595 std::unique_ptr<NiceMockBluetoothDevice> device(new NiceMockBluetoothDevice( |
591 adapter, 0x1F00 /* Bluetooth class */, device_name, address, | 596 adapter, 0x1F00 /* Bluetooth class */, device_name, address, |
592 true /* paired */, true /* connected */)); | 597 true /* paired */, true /* connected */)); |
593 | 598 |
594 ON_CALL(*device, GetUUIDs()).WillByDefault(Return(uuids)); | 599 ON_CALL(*device, GetUUIDs()).WillByDefault(Return(uuids)); |
595 | 600 |
596 // Using Invoke allows the device returned from this method to be futher | 601 // Using Invoke allows the device returned from this method to be futher |
597 // modified and have more services added to it. The call to ::GetGattServices | 602 // modified and have more services added to it. The call to ::GetGattServices |
598 // will invoke ::GetMockServices, returning all services added up to that | 603 // will invoke ::GetMockServices, returning all services added up to that |
599 // time. | 604 // time. |
600 ON_CALL(*device, GetGattServices()) | 605 ON_CALL(*device, GetGattServices()) |
601 .WillByDefault( | 606 .WillByDefault( |
602 Invoke(device.get(), &MockBluetoothDevice::GetMockServices)); | 607 Invoke(device.get(), &MockBluetoothDevice::GetMockServices)); |
603 // The call to BluetoothDevice::GetGattService will invoke ::GetMockService | 608 // The call to BluetoothDevice::GetGattService will invoke ::GetMockService |
604 // which returns a service matching the identifier provided if the service | 609 // which returns a service matching the identifier provided if the service |
605 // was added to the mock. | 610 // was added to the mock. |
606 ON_CALL(*device, GetGattService(_)) | 611 ON_CALL(*device, GetGattService(_)) |
607 .WillByDefault( | 612 .WillByDefault( |
608 Invoke(device.get(), &MockBluetoothDevice::GetMockService)); | 613 Invoke(device.get(), &MockBluetoothDevice::GetMockService)); |
609 | 614 |
610 ON_CALL(*device, GetVendorIDSource()) | 615 ON_CALL(*device, GetVendorIDSource()) |
611 .WillByDefault(Return(BluetoothDevice::VENDOR_ID_BLUETOOTH)); | 616 .WillByDefault(Return(BluetoothDevice::VENDOR_ID_BLUETOOTH)); |
612 ON_CALL(*device, GetVendorID()).WillByDefault(Return(0xFFFF)); | 617 ON_CALL(*device, GetVendorID()).WillByDefault(Return(0xFFFF)); |
613 ON_CALL(*device, GetProductID()).WillByDefault(Return(1)); | 618 ON_CALL(*device, GetProductID()).WillByDefault(Return(1)); |
614 ON_CALL(*device, GetDeviceID()).WillByDefault(Return(2)); | 619 ON_CALL(*device, GetDeviceID()).WillByDefault(Return(2)); |
615 | 620 |
616 return device; | 621 return device; |
617 } | 622 } |
618 | 623 |
619 // static | 624 // static |
620 scoped_ptr<NiceMockBluetoothDevice> | 625 std::unique_ptr<NiceMockBluetoothDevice> |
621 LayoutTestBluetoothAdapterProvider::GetBatteryDevice( | 626 LayoutTestBluetoothAdapterProvider::GetBatteryDevice( |
622 MockBluetoothAdapter* adapter) { | 627 MockBluetoothAdapter* adapter) { |
623 BluetoothDevice::UUIDList uuids; | 628 BluetoothDevice::UUIDList uuids; |
624 uuids.push_back(BluetoothUUID(kBatteryServiceUUID)); | 629 uuids.push_back(BluetoothUUID(kBatteryServiceUUID)); |
625 | 630 |
626 return GetBaseDevice(adapter, "Battery Device", uuids, makeMACAddress(0x1)); | 631 return GetBaseDevice(adapter, "Battery Device", uuids, makeMACAddress(0x1)); |
627 } | 632 } |
628 | 633 |
629 // static | 634 // static |
630 scoped_ptr<NiceMockBluetoothDevice> | 635 std::unique_ptr<NiceMockBluetoothDevice> |
631 LayoutTestBluetoothAdapterProvider::GetGlucoseDevice( | 636 LayoutTestBluetoothAdapterProvider::GetGlucoseDevice( |
632 MockBluetoothAdapter* adapter) { | 637 MockBluetoothAdapter* adapter) { |
633 BluetoothDevice::UUIDList uuids; | 638 BluetoothDevice::UUIDList uuids; |
634 uuids.push_back(BluetoothUUID(kGenericAccessServiceUUID)); | 639 uuids.push_back(BluetoothUUID(kGenericAccessServiceUUID)); |
635 uuids.push_back(BluetoothUUID(kGlucoseServiceUUID)); | 640 uuids.push_back(BluetoothUUID(kGlucoseServiceUUID)); |
636 uuids.push_back(BluetoothUUID(kTxPowerServiceUUID)); | 641 uuids.push_back(BluetoothUUID(kTxPowerServiceUUID)); |
637 | 642 |
638 return GetBaseDevice(adapter, "Glucose Device", uuids, makeMACAddress(0x2)); | 643 return GetBaseDevice(adapter, "Glucose Device", uuids, makeMACAddress(0x2)); |
639 } | 644 } |
640 | 645 |
641 // static | 646 // static |
642 scoped_ptr<NiceMockBluetoothDevice> | 647 std::unique_ptr<NiceMockBluetoothDevice> |
643 LayoutTestBluetoothAdapterProvider::GetConnectableDevice( | 648 LayoutTestBluetoothAdapterProvider::GetConnectableDevice( |
644 device::MockBluetoothAdapter* adapter, | 649 device::MockBluetoothAdapter* adapter, |
645 const std::string& device_name, | 650 const std::string& device_name, |
646 BluetoothDevice::UUIDList uuids, | 651 BluetoothDevice::UUIDList uuids, |
647 const std::string& address) { | 652 const std::string& address) { |
648 scoped_ptr<NiceMockBluetoothDevice> device( | 653 std::unique_ptr<NiceMockBluetoothDevice> device( |
649 GetBaseDevice(adapter, device_name, uuids, address)); | 654 GetBaseDevice(adapter, device_name, uuids, address)); |
650 | 655 |
651 MockBluetoothDevice* device_ptr = device.get(); | 656 MockBluetoothDevice* device_ptr = device.get(); |
652 | 657 |
653 ON_CALL(*device, CreateGattConnection(_, _)) | 658 ON_CALL(*device, CreateGattConnection(_, _)) |
654 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( | 659 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( |
655 [adapter, device_ptr]() { | 660 [adapter, device_ptr]() { |
656 base::ThreadTaskRunnerHandle::Get()->PostTask( | 661 base::ThreadTaskRunnerHandle::Get()->PostTask( |
657 FROM_HERE, base::Bind(&NotifyServicesDiscovered, | 662 FROM_HERE, base::Bind(&NotifyServicesDiscovered, |
658 base::RetainedRef(adapter), device_ptr)); | 663 base::RetainedRef(adapter), device_ptr)); |
659 return make_scoped_ptr(new NiceMockBluetoothGattConnection( | 664 return base::WrapUnique(new NiceMockBluetoothGattConnection( |
660 adapter, device_ptr->GetAddress())); | 665 adapter, device_ptr->GetAddress())); |
661 })); | 666 })); |
662 | 667 |
663 return device; | 668 return device; |
664 } | 669 } |
665 | 670 |
666 // static | 671 // static |
667 scoped_ptr<NiceMockBluetoothDevice> | 672 std::unique_ptr<NiceMockBluetoothDevice> |
668 LayoutTestBluetoothAdapterProvider::GetUnconnectableDevice( | 673 LayoutTestBluetoothAdapterProvider::GetUnconnectableDevice( |
669 MockBluetoothAdapter* adapter, | 674 MockBluetoothAdapter* adapter, |
670 BluetoothDevice::ConnectErrorCode error_code, | 675 BluetoothDevice::ConnectErrorCode error_code, |
671 const std::string& device_name) { | 676 const std::string& device_name) { |
672 BluetoothDevice::UUIDList uuids; | 677 BluetoothDevice::UUIDList uuids; |
673 uuids.push_back(BluetoothUUID(errorUUID(error_code))); | 678 uuids.push_back(BluetoothUUID(errorUUID(error_code))); |
674 | 679 |
675 scoped_ptr<NiceMockBluetoothDevice> device( | 680 std::unique_ptr<NiceMockBluetoothDevice> device( |
676 GetBaseDevice(adapter, device_name, uuids, makeMACAddress(error_code))); | 681 GetBaseDevice(adapter, device_name, uuids, makeMACAddress(error_code))); |
677 | 682 |
678 ON_CALL(*device, CreateGattConnection(_, _)) | 683 ON_CALL(*device, CreateGattConnection(_, _)) |
679 .WillByDefault(RunCallback<1 /* error_callback */>(error_code)); | 684 .WillByDefault(RunCallback<1 /* error_callback */>(error_code)); |
680 | 685 |
681 return device; | 686 return device; |
682 } | 687 } |
683 | 688 |
684 // static | 689 // static |
685 scoped_ptr<NiceMockBluetoothDevice> | 690 std::unique_ptr<NiceMockBluetoothDevice> |
686 LayoutTestBluetoothAdapterProvider::GetHeartRateDevice( | 691 LayoutTestBluetoothAdapterProvider::GetHeartRateDevice( |
687 MockBluetoothAdapter* adapter) { | 692 MockBluetoothAdapter* adapter) { |
688 BluetoothDevice::UUIDList uuids; | 693 BluetoothDevice::UUIDList uuids; |
689 uuids.push_back(BluetoothUUID(kGenericAccessServiceUUID)); | 694 uuids.push_back(BluetoothUUID(kGenericAccessServiceUUID)); |
690 uuids.push_back(BluetoothUUID(kHeartRateServiceUUID)); | 695 uuids.push_back(BluetoothUUID(kHeartRateServiceUUID)); |
691 | 696 |
692 return GetConnectableDevice(adapter, "Heart Rate Device", uuids); | 697 return GetConnectableDevice(adapter, "Heart Rate Device", uuids); |
693 } | 698 } |
694 | 699 |
695 // Services | 700 // Services |
696 | 701 |
697 // static | 702 // static |
698 scoped_ptr<NiceMockBluetoothGattService> | 703 std::unique_ptr<NiceMockBluetoothGattService> |
699 LayoutTestBluetoothAdapterProvider::GetBaseGATTService( | 704 LayoutTestBluetoothAdapterProvider::GetBaseGATTService( |
700 MockBluetoothDevice* device, | 705 MockBluetoothDevice* device, |
701 const std::string& uuid) { | 706 const std::string& uuid) { |
702 scoped_ptr<NiceMockBluetoothGattService> service( | 707 std::unique_ptr<NiceMockBluetoothGattService> service( |
703 new NiceMockBluetoothGattService( | 708 new NiceMockBluetoothGattService( |
704 device, uuid /* identifier */, BluetoothUUID(uuid), | 709 device, uuid /* identifier */, BluetoothUUID(uuid), |
705 true /* is_primary */, false /* is_local */)); | 710 true /* is_primary */, false /* is_local */)); |
706 | 711 |
707 ON_CALL(*service, GetCharacteristics()) | 712 ON_CALL(*service, GetCharacteristics()) |
708 .WillByDefault(Invoke(service.get(), | 713 .WillByDefault(Invoke(service.get(), |
709 &MockBluetoothGattService::GetMockCharacteristics)); | 714 &MockBluetoothGattService::GetMockCharacteristics)); |
710 | 715 |
711 ON_CALL(*service, GetCharacteristic(_)) | 716 ON_CALL(*service, GetCharacteristic(_)) |
712 .WillByDefault(Invoke(service.get(), | 717 .WillByDefault(Invoke(service.get(), |
713 &MockBluetoothGattService::GetMockCharacteristic)); | 718 &MockBluetoothGattService::GetMockCharacteristic)); |
714 | 719 |
715 return service; | 720 return service; |
716 } | 721 } |
717 | 722 |
718 // static | 723 // static |
719 scoped_ptr<NiceMockBluetoothGattService> | 724 std::unique_ptr<NiceMockBluetoothGattService> |
720 LayoutTestBluetoothAdapterProvider::GetBlacklistTestService( | 725 LayoutTestBluetoothAdapterProvider::GetBlacklistTestService( |
721 device::MockBluetoothDevice* device) { | 726 device::MockBluetoothDevice* device) { |
722 scoped_ptr<NiceMockBluetoothGattService> blacklist_test_service( | 727 std::unique_ptr<NiceMockBluetoothGattService> blacklist_test_service( |
723 GetBaseGATTService(device, kBlacklistTestServiceUUID)); | 728 GetBaseGATTService(device, kBlacklistTestServiceUUID)); |
724 | 729 |
725 scoped_ptr<NiceMockBluetoothGattCharacteristic> | 730 std::unique_ptr<NiceMockBluetoothGattCharacteristic> |
726 blacklist_exclude_reads_characteristic(GetBaseGATTCharacteristic( | 731 blacklist_exclude_reads_characteristic(GetBaseGATTCharacteristic( |
727 "Excluded Reads Characteristic", blacklist_test_service.get(), | 732 "Excluded Reads Characteristic", blacklist_test_service.get(), |
728 kBlacklistExcludeReadsCharacteristicUUID, | 733 kBlacklistExcludeReadsCharacteristicUUID, |
729 BluetoothGattCharacteristic::PROPERTY_READ | | 734 BluetoothGattCharacteristic::PROPERTY_READ | |
730 BluetoothGattCharacteristic::PROPERTY_WRITE)); | 735 BluetoothGattCharacteristic::PROPERTY_WRITE)); |
731 | 736 |
732 // Crash if ReadRemoteCharacteristic called. Not using GoogleMock's Expect | 737 // Crash if ReadRemoteCharacteristic called. Not using GoogleMock's Expect |
733 // because this is used in layout tests that may not report a mock expectation | 738 // because this is used in layout tests that may not report a mock expectation |
734 // error correctly as a layout test failure. | 739 // error correctly as a layout test failure. |
735 ON_CALL(*blacklist_exclude_reads_characteristic, | 740 ON_CALL(*blacklist_exclude_reads_characteristic, |
736 ReadRemoteCharacteristic(_, _)) | 741 ReadRemoteCharacteristic(_, _)) |
737 .WillByDefault( | 742 .WillByDefault( |
738 Invoke([](const BluetoothGattCharacteristic::ValueCallback&, | 743 Invoke([](const BluetoothGattCharacteristic::ValueCallback&, |
739 const BluetoothGattCharacteristic::ErrorCallback&) { | 744 const BluetoothGattCharacteristic::ErrorCallback&) { |
740 NOTREACHED(); | 745 NOTREACHED(); |
741 })); | 746 })); |
742 | 747 |
743 // Write response. | 748 // Write response. |
744 ON_CALL(*blacklist_exclude_reads_characteristic, | 749 ON_CALL(*blacklist_exclude_reads_characteristic, |
745 WriteRemoteCharacteristic(_, _, _)) | 750 WriteRemoteCharacteristic(_, _, _)) |
746 .WillByDefault(RunCallback<1 /* success callback */>()); | 751 .WillByDefault(RunCallback<1 /* success callback */>()); |
747 | 752 |
748 blacklist_test_service->AddMockCharacteristic( | 753 blacklist_test_service->AddMockCharacteristic( |
749 std::move(blacklist_exclude_reads_characteristic)); | 754 std::move(blacklist_exclude_reads_characteristic)); |
750 | 755 |
751 return blacklist_test_service; | 756 return blacklist_test_service; |
752 } | 757 } |
753 | 758 |
754 // static | 759 // static |
755 scoped_ptr<NiceMockBluetoothGattService> | 760 std::unique_ptr<NiceMockBluetoothGattService> |
756 LayoutTestBluetoothAdapterProvider::GetDeviceInformationService( | 761 LayoutTestBluetoothAdapterProvider::GetDeviceInformationService( |
757 device::MockBluetoothDevice* device) { | 762 device::MockBluetoothDevice* device) { |
758 scoped_ptr<NiceMockBluetoothGattService> device_information( | 763 std::unique_ptr<NiceMockBluetoothGattService> device_information( |
759 GetBaseGATTService(device, kDeviceInformationServiceUUID)); | 764 GetBaseGATTService(device, kDeviceInformationServiceUUID)); |
760 | 765 |
761 scoped_ptr<NiceMockBluetoothGattCharacteristic> serial_number_string( | 766 std::unique_ptr<NiceMockBluetoothGattCharacteristic> serial_number_string( |
762 GetBaseGATTCharacteristic( | 767 GetBaseGATTCharacteristic( |
763 "Serial Number String", device_information.get(), | 768 "Serial Number String", device_information.get(), |
764 kSerialNumberStringUUID, BluetoothGattCharacteristic::PROPERTY_READ)); | 769 kSerialNumberStringUUID, BluetoothGattCharacteristic::PROPERTY_READ)); |
765 | 770 |
766 // Crash if ReadRemoteCharacteristic called. Not using GoogleMock's Expect | 771 // Crash if ReadRemoteCharacteristic called. Not using GoogleMock's Expect |
767 // because this is used in layout tests that may not report a mock expectation | 772 // because this is used in layout tests that may not report a mock expectation |
768 // error correctly as a layout test failure. | 773 // error correctly as a layout test failure. |
769 ON_CALL(*serial_number_string, ReadRemoteCharacteristic(_, _)) | 774 ON_CALL(*serial_number_string, ReadRemoteCharacteristic(_, _)) |
770 .WillByDefault( | 775 .WillByDefault( |
771 Invoke([](const BluetoothGattCharacteristic::ValueCallback&, | 776 Invoke([](const BluetoothGattCharacteristic::ValueCallback&, |
772 const BluetoothGattCharacteristic::ErrorCallback&) { | 777 const BluetoothGattCharacteristic::ErrorCallback&) { |
773 NOTREACHED(); | 778 NOTREACHED(); |
774 })); | 779 })); |
775 | 780 |
776 device_information->AddMockCharacteristic(std::move(serial_number_string)); | 781 device_information->AddMockCharacteristic(std::move(serial_number_string)); |
777 | 782 |
778 return device_information; | 783 return device_information; |
779 } | 784 } |
780 | 785 |
781 // static | 786 // static |
782 scoped_ptr<NiceMockBluetoothGattService> | 787 std::unique_ptr<NiceMockBluetoothGattService> |
783 LayoutTestBluetoothAdapterProvider::GetGenericAccessService( | 788 LayoutTestBluetoothAdapterProvider::GetGenericAccessService( |
784 device::MockBluetoothDevice* device) { | 789 device::MockBluetoothDevice* device) { |
785 scoped_ptr<NiceMockBluetoothGattService> generic_access( | 790 std::unique_ptr<NiceMockBluetoothGattService> generic_access( |
786 GetBaseGATTService(device, kGenericAccessServiceUUID)); | 791 GetBaseGATTService(device, kGenericAccessServiceUUID)); |
787 | 792 |
788 { // Device Name: | 793 { // Device Name: |
789 scoped_ptr<NiceMockBluetoothGattCharacteristic> device_name( | 794 std::unique_ptr<NiceMockBluetoothGattCharacteristic> device_name( |
790 GetBaseGATTCharacteristic( | 795 GetBaseGATTCharacteristic( |
791 "Device Name", generic_access.get(), kDeviceNameUUID, | 796 "Device Name", generic_access.get(), kDeviceNameUUID, |
792 BluetoothGattCharacteristic::PROPERTY_READ | | 797 BluetoothGattCharacteristic::PROPERTY_READ | |
793 BluetoothGattCharacteristic::PROPERTY_WRITE)); | 798 BluetoothGattCharacteristic::PROPERTY_WRITE)); |
794 | 799 |
795 // Read response. | 800 // Read response. |
796 std::string device_name_str = device->GetDeviceName(); | 801 std::string device_name_str = device->GetDeviceName(); |
797 std::vector<uint8_t> device_name_value(device_name_str.begin(), | 802 std::vector<uint8_t> device_name_value(device_name_str.begin(), |
798 device_name_str.end()); | 803 device_name_str.end()); |
799 | 804 |
800 ON_CALL(*device_name, ReadRemoteCharacteristic(_, _)) | 805 ON_CALL(*device_name, ReadRemoteCharacteristic(_, _)) |
801 .WillByDefault(RunCallback<0>(device_name_value)); | 806 .WillByDefault(RunCallback<0>(device_name_value)); |
802 | 807 |
803 // Write response. | 808 // Write response. |
804 ON_CALL(*device_name, WriteRemoteCharacteristic(_, _, _)) | 809 ON_CALL(*device_name, WriteRemoteCharacteristic(_, _, _)) |
805 .WillByDefault(RunCallback<1 /* success callback */>()); | 810 .WillByDefault(RunCallback<1 /* success callback */>()); |
806 | 811 |
807 generic_access->AddMockCharacteristic(std::move(device_name)); | 812 generic_access->AddMockCharacteristic(std::move(device_name)); |
808 } | 813 } |
809 | 814 |
810 { // Peripheral Privacy Flag: | 815 { // Peripheral Privacy Flag: |
811 scoped_ptr<NiceMockBluetoothGattCharacteristic> peripheral_privacy_flag( | 816 std::unique_ptr<NiceMockBluetoothGattCharacteristic> |
812 GetBaseGATTCharacteristic( | 817 peripheral_privacy_flag(GetBaseGATTCharacteristic( |
813 "Peripheral Privacy Flag", generic_access.get(), | 818 "Peripheral Privacy Flag", generic_access.get(), |
814 kPeripheralPrivacyFlagUUID, | 819 kPeripheralPrivacyFlagUUID, |
815 BluetoothGattCharacteristic::PROPERTY_READ | | 820 BluetoothGattCharacteristic::PROPERTY_READ | |
816 BluetoothGattCharacteristic::PROPERTY_WRITE)); | 821 BluetoothGattCharacteristic::PROPERTY_WRITE)); |
817 | 822 |
818 // Read response. | 823 // Read response. |
819 std::vector<uint8_t> value(1); | 824 std::vector<uint8_t> value(1); |
820 value[0] = false; | 825 value[0] = false; |
821 | 826 |
822 ON_CALL(*peripheral_privacy_flag, ReadRemoteCharacteristic(_, _)) | 827 ON_CALL(*peripheral_privacy_flag, ReadRemoteCharacteristic(_, _)) |
823 .WillByDefault(RunCallback<0>(value)); | 828 .WillByDefault(RunCallback<0>(value)); |
824 | 829 |
825 // Crash if WriteRemoteCharacteristic called. Not using GoogleMock's Expect | 830 // Crash if WriteRemoteCharacteristic called. Not using GoogleMock's Expect |
826 // because this is used in layout tests that may not report a mock | 831 // because this is used in layout tests that may not report a mock |
827 // expectation error correctly as a layout test failure. | 832 // expectation error correctly as a layout test failure. |
828 ON_CALL(*peripheral_privacy_flag, WriteRemoteCharacteristic(_, _, _)) | 833 ON_CALL(*peripheral_privacy_flag, WriteRemoteCharacteristic(_, _, _)) |
829 .WillByDefault( | 834 .WillByDefault( |
830 Invoke([](const std::vector<uint8_t>&, const base::Closure&, | 835 Invoke([](const std::vector<uint8_t>&, const base::Closure&, |
831 const BluetoothGattCharacteristic::ErrorCallback&) { | 836 const BluetoothGattCharacteristic::ErrorCallback&) { |
832 NOTREACHED(); | 837 NOTREACHED(); |
833 })); | 838 })); |
834 | 839 |
835 generic_access->AddMockCharacteristic(std::move(peripheral_privacy_flag)); | 840 generic_access->AddMockCharacteristic(std::move(peripheral_privacy_flag)); |
836 } | 841 } |
837 | 842 |
838 return generic_access; | 843 return generic_access; |
839 } | 844 } |
840 | 845 |
841 // static | 846 // static |
842 scoped_ptr<NiceMockBluetoothGattService> | 847 std::unique_ptr<NiceMockBluetoothGattService> |
843 LayoutTestBluetoothAdapterProvider::GetHeartRateService( | 848 LayoutTestBluetoothAdapterProvider::GetHeartRateService( |
844 MockBluetoothAdapter* adapter, | 849 MockBluetoothAdapter* adapter, |
845 MockBluetoothDevice* device) { | 850 MockBluetoothDevice* device) { |
846 scoped_ptr<NiceMockBluetoothGattService> heart_rate( | 851 std::unique_ptr<NiceMockBluetoothGattService> heart_rate( |
847 GetBaseGATTService(device, kHeartRateServiceUUID)); | 852 GetBaseGATTService(device, kHeartRateServiceUUID)); |
848 | 853 |
849 // Heart Rate Measurement | 854 // Heart Rate Measurement |
850 scoped_ptr<NiceMockBluetoothGattCharacteristic> heart_rate_measurement( | 855 std::unique_ptr<NiceMockBluetoothGattCharacteristic> heart_rate_measurement( |
851 GetBaseGATTCharacteristic("Heart Rate Measurement", heart_rate.get(), | 856 GetBaseGATTCharacteristic("Heart Rate Measurement", heart_rate.get(), |
852 kHeartRateMeasurementUUID, | 857 kHeartRateMeasurementUUID, |
853 BluetoothGattCharacteristic::PROPERTY_NOTIFY)); | 858 BluetoothGattCharacteristic::PROPERTY_NOTIFY)); |
854 NiceMockBluetoothGattCharacteristic* measurement_ptr = | 859 NiceMockBluetoothGattCharacteristic* measurement_ptr = |
855 heart_rate_measurement.get(); | 860 heart_rate_measurement.get(); |
856 | 861 |
857 ON_CALL(*heart_rate_measurement, StartNotifySession(_, _)) | 862 ON_CALL(*heart_rate_measurement, StartNotifySession(_, _)) |
858 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( | 863 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( |
859 [adapter, measurement_ptr]() { | 864 [adapter, measurement_ptr]() { |
860 scoped_ptr<NiceMockBluetoothGattNotifySession> notify_session( | 865 std::unique_ptr<NiceMockBluetoothGattNotifySession> notify_session( |
861 GetBaseGATTNotifySession(measurement_ptr->GetIdentifier())); | 866 GetBaseGATTNotifySession(measurement_ptr->GetIdentifier())); |
862 | 867 |
863 std::vector<uint8_t> rate(1 /* size */); | 868 std::vector<uint8_t> rate(1 /* size */); |
864 rate[0] = 60; | 869 rate[0] = 60; |
865 | 870 |
866 notify_session->StartTestNotifications(adapter, measurement_ptr, | 871 notify_session->StartTestNotifications(adapter, measurement_ptr, |
867 rate); | 872 rate); |
868 | 873 |
869 return notify_session; | 874 return notify_session; |
870 })); | 875 })); |
871 | 876 |
872 // Body Sensor Location Characteristic (Chest) | 877 // Body Sensor Location Characteristic (Chest) |
873 scoped_ptr<NiceMockBluetoothGattCharacteristic> body_sensor_location_chest( | 878 std::unique_ptr<NiceMockBluetoothGattCharacteristic> |
874 GetBaseGATTCharacteristic("Body Sensor Location Chest", heart_rate.get(), | 879 body_sensor_location_chest(GetBaseGATTCharacteristic( |
875 kBodySensorLocation, | 880 "Body Sensor Location Chest", heart_rate.get(), kBodySensorLocation, |
876 BluetoothGattCharacteristic::PROPERTY_READ)); | 881 BluetoothGattCharacteristic::PROPERTY_READ)); |
877 BluetoothGattCharacteristic* location_chest_ptr = | 882 BluetoothGattCharacteristic* location_chest_ptr = |
878 body_sensor_location_chest.get(); | 883 body_sensor_location_chest.get(); |
879 | 884 |
880 ON_CALL(*body_sensor_location_chest, ReadRemoteCharacteristic(_, _)) | 885 ON_CALL(*body_sensor_location_chest, ReadRemoteCharacteristic(_, _)) |
881 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( | 886 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( |
882 [adapter, location_chest_ptr]() { | 887 [adapter, location_chest_ptr]() { |
883 std::vector<uint8_t> location(1 /* size */); | 888 std::vector<uint8_t> location(1 /* size */); |
884 location[0] = 1; // Chest | 889 location[0] = 1; // Chest |
885 // Read a characteristic has a side effect of | 890 // Read a characteristic has a side effect of |
886 // GattCharacteristicValueChanged being called. | 891 // GattCharacteristicValueChanged being called. |
887 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, | 892 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, |
888 adapter->GetObservers(), | 893 adapter->GetObservers(), |
889 GattCharacteristicValueChanged( | 894 GattCharacteristicValueChanged( |
890 adapter, location_chest_ptr, location)); | 895 adapter, location_chest_ptr, location)); |
891 return location; | 896 return location; |
892 })); | 897 })); |
893 | 898 |
894 // Body Sensor Location Characteristic (Wrist) | 899 // Body Sensor Location Characteristic (Wrist) |
895 scoped_ptr<NiceMockBluetoothGattCharacteristic> body_sensor_location_wrist( | 900 std::unique_ptr<NiceMockBluetoothGattCharacteristic> |
896 GetBaseGATTCharacteristic("Body Sensor Location Wrist", heart_rate.get(), | 901 body_sensor_location_wrist(GetBaseGATTCharacteristic( |
897 kBodySensorLocation, | 902 "Body Sensor Location Wrist", heart_rate.get(), kBodySensorLocation, |
898 BluetoothGattCharacteristic::PROPERTY_READ)); | 903 BluetoothGattCharacteristic::PROPERTY_READ)); |
899 BluetoothGattCharacteristic* location_wrist_ptr = | 904 BluetoothGattCharacteristic* location_wrist_ptr = |
900 body_sensor_location_wrist.get(); | 905 body_sensor_location_wrist.get(); |
901 | 906 |
902 ON_CALL(*body_sensor_location_wrist, ReadRemoteCharacteristic(_, _)) | 907 ON_CALL(*body_sensor_location_wrist, ReadRemoteCharacteristic(_, _)) |
903 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( | 908 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( |
904 [adapter, location_wrist_ptr]() { | 909 [adapter, location_wrist_ptr]() { |
905 std::vector<uint8_t> location(1 /* size */); | 910 std::vector<uint8_t> location(1 /* size */); |
906 location[0] = 2; // Wrist | 911 location[0] = 2; // Wrist |
907 // Read a characteristic has a side effect of | 912 // Read a characteristic has a side effect of |
908 // GattCharacteristicValueChanged being called. | 913 // GattCharacteristicValueChanged being called. |
909 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, | 914 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, |
910 adapter->GetObservers(), | 915 adapter->GetObservers(), |
911 GattCharacteristicValueChanged( | 916 GattCharacteristicValueChanged( |
912 adapter, location_wrist_ptr, location)); | 917 adapter, location_wrist_ptr, location)); |
913 return location; | 918 return location; |
914 })); | 919 })); |
915 | 920 |
916 heart_rate->AddMockCharacteristic(std::move(heart_rate_measurement)); | 921 heart_rate->AddMockCharacteristic(std::move(heart_rate_measurement)); |
917 heart_rate->AddMockCharacteristic(std::move(body_sensor_location_chest)); | 922 heart_rate->AddMockCharacteristic(std::move(body_sensor_location_chest)); |
918 heart_rate->AddMockCharacteristic(std::move(body_sensor_location_wrist)); | 923 heart_rate->AddMockCharacteristic(std::move(body_sensor_location_wrist)); |
919 | 924 |
920 return heart_rate; | 925 return heart_rate; |
921 } | 926 } |
922 | 927 |
923 // Characteristics | 928 // Characteristics |
924 | 929 |
925 // static | 930 // static |
926 scoped_ptr<NiceMockBluetoothGattCharacteristic> | 931 std::unique_ptr<NiceMockBluetoothGattCharacteristic> |
927 LayoutTestBluetoothAdapterProvider::GetBaseGATTCharacteristic( | 932 LayoutTestBluetoothAdapterProvider::GetBaseGATTCharacteristic( |
928 const std::string& identifier, | 933 const std::string& identifier, |
929 MockBluetoothGattService* service, | 934 MockBluetoothGattService* service, |
930 const std::string& uuid, | 935 const std::string& uuid, |
931 BluetoothGattCharacteristic::Properties properties) { | 936 BluetoothGattCharacteristic::Properties properties) { |
932 return make_scoped_ptr(new NiceMockBluetoothGattCharacteristic( | 937 return base::WrapUnique(new NiceMockBluetoothGattCharacteristic( |
933 service, identifier, BluetoothUUID(uuid), false /* is_local */, | 938 service, identifier, BluetoothUUID(uuid), false /* is_local */, |
934 properties, NULL /* permissions */)); | 939 properties, NULL /* permissions */)); |
935 } | 940 } |
936 | 941 |
937 // static | 942 // static |
938 scoped_ptr<NiceMockBluetoothGattCharacteristic> | 943 std::unique_ptr<NiceMockBluetoothGattCharacteristic> |
939 LayoutTestBluetoothAdapterProvider::GetErrorCharacteristic( | 944 LayoutTestBluetoothAdapterProvider::GetErrorCharacteristic( |
940 MockBluetoothGattService* service, | 945 MockBluetoothGattService* service, |
941 BluetoothGattService::GattErrorCode error_code) { | 946 BluetoothGattService::GattErrorCode error_code) { |
942 uint32_t error_alias = error_code + 0xA1; // Error UUIDs start at 0xA1. | 947 uint32_t error_alias = error_code + 0xA1; // Error UUIDs start at 0xA1. |
943 scoped_ptr<NiceMockBluetoothGattCharacteristic> characteristic( | 948 std::unique_ptr<NiceMockBluetoothGattCharacteristic> characteristic( |
944 GetBaseGATTCharacteristic( | 949 GetBaseGATTCharacteristic( |
945 // Use the UUID to generate unique identifiers. | 950 // Use the UUID to generate unique identifiers. |
946 "Error Characteristic " + errorUUID(error_alias), service, | 951 "Error Characteristic " + errorUUID(error_alias), service, |
947 errorUUID(error_alias), | 952 errorUUID(error_alias), |
948 BluetoothGattCharacteristic::PROPERTY_READ | | 953 BluetoothGattCharacteristic::PROPERTY_READ | |
949 BluetoothGattCharacteristic::PROPERTY_WRITE | | 954 BluetoothGattCharacteristic::PROPERTY_WRITE | |
950 BluetoothGattCharacteristic::PROPERTY_INDICATE)); | 955 BluetoothGattCharacteristic::PROPERTY_INDICATE)); |
951 | 956 |
952 // Read response. | 957 // Read response. |
953 ON_CALL(*characteristic, ReadRemoteCharacteristic(_, _)) | 958 ON_CALL(*characteristic, ReadRemoteCharacteristic(_, _)) |
954 .WillByDefault(RunCallback<1 /* error_callback */>(error_code)); | 959 .WillByDefault(RunCallback<1 /* error_callback */>(error_code)); |
955 | 960 |
956 // Write response. | 961 // Write response. |
957 ON_CALL(*characteristic, WriteRemoteCharacteristic(_, _, _)) | 962 ON_CALL(*characteristic, WriteRemoteCharacteristic(_, _, _)) |
958 .WillByDefault(RunCallback<2 /* error_callback */>(error_code)); | 963 .WillByDefault(RunCallback<2 /* error_callback */>(error_code)); |
959 | 964 |
960 // StartNotifySession response | 965 // StartNotifySession response |
961 ON_CALL(*characteristic, StartNotifySession(_, _)) | 966 ON_CALL(*characteristic, StartNotifySession(_, _)) |
962 .WillByDefault(RunCallback<1 /* error_callback */>(error_code)); | 967 .WillByDefault(RunCallback<1 /* error_callback */>(error_code)); |
963 | 968 |
964 return characteristic; | 969 return characteristic; |
965 } | 970 } |
966 | 971 |
967 // Notify sessions | 972 // Notify sessions |
968 | 973 |
969 // static | 974 // static |
970 scoped_ptr<NiceMockBluetoothGattNotifySession> | 975 std::unique_ptr<NiceMockBluetoothGattNotifySession> |
971 LayoutTestBluetoothAdapterProvider::GetBaseGATTNotifySession( | 976 LayoutTestBluetoothAdapterProvider::GetBaseGATTNotifySession( |
972 const std::string& characteristic_identifier) { | 977 const std::string& characteristic_identifier) { |
973 scoped_ptr<NiceMockBluetoothGattNotifySession> session( | 978 std::unique_ptr<NiceMockBluetoothGattNotifySession> session( |
974 new NiceMockBluetoothGattNotifySession(characteristic_identifier)); | 979 new NiceMockBluetoothGattNotifySession(characteristic_identifier)); |
975 | 980 |
976 ON_CALL(*session, Stop(_)) | 981 ON_CALL(*session, Stop(_)) |
977 .WillByDefault(testing::DoAll( | 982 .WillByDefault(testing::DoAll( |
978 InvokeWithoutArgs( | 983 InvokeWithoutArgs( |
979 session.get(), | 984 session.get(), |
980 &MockBluetoothGattNotifySession::StopTestNotifications), | 985 &MockBluetoothGattNotifySession::StopTestNotifications), |
981 RunCallback<0>())); | 986 RunCallback<0>())); |
982 | 987 |
983 return session; | 988 return session; |
(...skipping 51 matching lines...) Loading... |
1035 return BluetoothUUID(); | 1040 return BluetoothUUID(); |
1036 } | 1041 } |
1037 | 1042 |
1038 // static | 1043 // static |
1039 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { | 1044 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { |
1040 return BluetoothDevice::CanonicalizeAddress( | 1045 return BluetoothDevice::CanonicalizeAddress( |
1041 base::StringPrintf("%012" PRIx64, addr)); | 1046 base::StringPrintf("%012" PRIx64, addr)); |
1042 } | 1047 } |
1043 | 1048 |
1044 } // namespace content | 1049 } // namespace content |
OLD | NEW |