| 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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 LayoutTestBluetoothAdapterProvider::GetGenericAccessAdapter() { | 333 LayoutTestBluetoothAdapterProvider::GetGenericAccessAdapter() { |
| 334 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 334 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
| 335 | 335 |
| 336 scoped_ptr<NiceMockBluetoothDevice> device( | 336 scoped_ptr<NiceMockBluetoothDevice> device( |
| 337 GetGenericAccessDevice(adapter.get())); | 337 GetGenericAccessDevice(adapter.get())); |
| 338 | 338 |
| 339 scoped_ptr<NiceMockBluetoothGattService> generic_access( | 339 scoped_ptr<NiceMockBluetoothGattService> generic_access( |
| 340 GetBaseGATTService(device.get(), kGenericAccessServiceUUID)); | 340 GetBaseGATTService(device.get(), kGenericAccessServiceUUID)); |
| 341 | 341 |
| 342 scoped_ptr<NiceMockBluetoothGattCharacteristic> device_name( | 342 scoped_ptr<NiceMockBluetoothGattCharacteristic> device_name( |
| 343 GetBaseGATTCharacteristic(generic_access.get(), kDeviceNameUUID)); | 343 GetBaseGATTCharacteristic( |
| 344 generic_access.get(), |
| 345 kDeviceNameUUID, |
| 346 BluetoothGattCharacteristic::PROPERTY_READ | |
| 347 BluetoothGattCharacteristic::PROPERTY_WRITE)); |
| 344 | 348 |
| 345 // Read response. | 349 // Read response. |
| 346 std::string device_name_str = device->GetDeviceName(); | 350 std::string device_name_str = device->GetDeviceName(); |
| 347 std::vector<uint8_t> device_name_value(device_name_str.begin(), | 351 std::vector<uint8_t> device_name_value(device_name_str.begin(), |
| 348 device_name_str.end()); | 352 device_name_str.end()); |
| 349 | 353 |
| 350 ON_CALL(*device_name, ReadRemoteCharacteristic(_, _)) | 354 ON_CALL(*device_name, ReadRemoteCharacteristic(_, _)) |
| 351 .WillByDefault(RunCallback<0>(device_name_value)); | 355 .WillByDefault(RunCallback<0>(device_name_value)); |
| 352 | 356 |
| 353 // Write response. | 357 // Write response. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 369 NiceMockBluetoothAdapter* adapter_ptr = adapter.get(); | 373 NiceMockBluetoothAdapter* adapter_ptr = adapter.get(); |
| 370 | 374 |
| 371 scoped_ptr<NiceMockBluetoothDevice> device(GetHeartRateDevice(adapter.get())); | 375 scoped_ptr<NiceMockBluetoothDevice> device(GetHeartRateDevice(adapter.get())); |
| 372 scoped_ptr<NiceMockBluetoothGattService> heart_rate( | 376 scoped_ptr<NiceMockBluetoothGattService> heart_rate( |
| 373 GetBaseGATTService(device.get(), kHeartRateServiceUUID)); | 377 GetBaseGATTService(device.get(), kHeartRateServiceUUID)); |
| 374 | 378 |
| 375 // TODO(ortuno): Implement the rest of the service's characteristics | 379 // TODO(ortuno): Implement the rest of the service's characteristics |
| 376 // See: http://crbug.com/529975 | 380 // See: http://crbug.com/529975 |
| 377 | 381 |
| 378 // Body Sensor Location Characteristic | 382 // Body Sensor Location Characteristic |
| 383 |
| 379 scoped_ptr<NiceMockBluetoothGattCharacteristic> body_sensor_location( | 384 scoped_ptr<NiceMockBluetoothGattCharacteristic> body_sensor_location( |
| 380 GetBaseGATTCharacteristic(heart_rate.get(), kBodySensorLocation)); | 385 GetBaseGATTCharacteristic( |
| 386 heart_rate.get(), |
| 387 kBodySensorLocation, |
| 388 BluetoothGattCharacteristic::PROPERTY_READ)); |
| 381 BluetoothGattCharacteristic* location_ptr = body_sensor_location.get(); | 389 BluetoothGattCharacteristic* location_ptr = body_sensor_location.get(); |
| 382 | 390 |
| 383 ON_CALL(*body_sensor_location, ReadRemoteCharacteristic(_, _)) | 391 ON_CALL(*body_sensor_location, ReadRemoteCharacteristic(_, _)) |
| 384 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( | 392 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( |
| 385 [adapter_ptr, location_ptr]() { | 393 [adapter_ptr, location_ptr]() { |
| 386 std::vector<uint8_t> location(1 /* size */); | 394 std::vector<uint8_t> location(1 /* size */); |
| 387 location[0] = 1; // Chest | 395 location[0] = 1; // Chest |
| 388 // Read a characteristic has a side effect of | 396 // Read a characteristic has a side effect of |
| 389 // GattCharacteristicValueChanged being called. | 397 // GattCharacteristicValueChanged being called. |
| 390 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, | 398 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, |
| 391 adapter_ptr->GetObservers(), | 399 adapter_ptr->GetObservers(), |
| 392 GattCharacteristicValueChanged( | 400 GattCharacteristicValueChanged( |
| 393 adapter_ptr, location_ptr, location)); | 401 adapter_ptr, location_ptr, location)); |
| 394 return location; | 402 return location; |
| 395 })); | 403 })); |
| 396 | 404 |
| 397 // Heart Rate Measurement Characteristic | 405 // Heart Rate Measurement Characteristic |
| 398 scoped_ptr<NiceMockBluetoothGattCharacteristic> heart_rate_measurement( | 406 scoped_ptr<NiceMockBluetoothGattCharacteristic> heart_rate_measurement( |
| 399 GetBaseGATTCharacteristic(heart_rate.get(), kHeartRateMeasurementUUID)); | 407 GetBaseGATTCharacteristic( |
| 408 heart_rate.get(), |
| 409 kHeartRateMeasurementUUID, |
| 410 BluetoothGattCharacteristic::PROPERTY_NOTIFY)); |
| 400 NiceMockBluetoothGattCharacteristic* measurement_ptr = | 411 NiceMockBluetoothGattCharacteristic* measurement_ptr = |
| 401 heart_rate_measurement.get(); | 412 heart_rate_measurement.get(); |
| 402 | 413 |
| 403 ON_CALL(*heart_rate_measurement, StartNotifySession(_, _)) | 414 ON_CALL(*heart_rate_measurement, StartNotifySession(_, _)) |
| 404 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( | 415 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( |
| 405 [adapter_ptr, measurement_ptr]() { | 416 [adapter_ptr, measurement_ptr]() { |
| 406 scoped_ptr<NiceMockBluetoothGattNotifySession> notify_session( | 417 scoped_ptr<NiceMockBluetoothGattNotifySession> notify_session( |
| 407 GetBaseGATTNotifySession(measurement_ptr->GetIdentifier())); | 418 GetBaseGATTNotifySession(measurement_ptr->GetIdentifier())); |
| 408 | 419 |
| 409 std::vector<uint8_t> rate(1 /* size */); | 420 std::vector<uint8_t> rate(1 /* size */); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 | 636 |
| 626 return service.Pass(); | 637 return service.Pass(); |
| 627 } | 638 } |
| 628 | 639 |
| 629 // Characteristics | 640 // Characteristics |
| 630 | 641 |
| 631 // static | 642 // static |
| 632 scoped_ptr<NiceMockBluetoothGattCharacteristic> | 643 scoped_ptr<NiceMockBluetoothGattCharacteristic> |
| 633 LayoutTestBluetoothAdapterProvider::GetBaseGATTCharacteristic( | 644 LayoutTestBluetoothAdapterProvider::GetBaseGATTCharacteristic( |
| 634 MockBluetoothGattService* service, | 645 MockBluetoothGattService* service, |
| 635 const std::string& uuid) { | 646 const std::string& uuid, |
| 647 BluetoothGattCharacteristic::Properties properties) { |
| 636 return make_scoped_ptr(new NiceMockBluetoothGattCharacteristic( | 648 return make_scoped_ptr(new NiceMockBluetoothGattCharacteristic( |
| 637 service, uuid + " Identifier", BluetoothUUID(uuid), false /* is_local */, | 649 service, uuid + " Identifier", BluetoothUUID(uuid), false /* is_local */, |
| 638 NULL /* properties */, NULL /* permissions */)); | 650 properties, NULL /* permissions */)); |
| 639 } | 651 } |
| 640 | 652 |
| 641 // static | 653 // static |
| 642 scoped_ptr<NiceMockBluetoothGattCharacteristic> | 654 scoped_ptr<NiceMockBluetoothGattCharacteristic> |
| 643 LayoutTestBluetoothAdapterProvider::GetErrorCharacteristic( | 655 LayoutTestBluetoothAdapterProvider::GetErrorCharacteristic( |
| 644 MockBluetoothGattService* service, | 656 MockBluetoothGattService* service, |
| 645 BluetoothGattService::GattErrorCode error_code) { | 657 BluetoothGattService::GattErrorCode error_code) { |
| 646 uint32_t error_alias = error_code + 0xA1; // Error UUIDs start at 0xA1. | 658 uint32_t error_alias = error_code + 0xA1; // Error UUIDs start at 0xA1. |
| 647 scoped_ptr<NiceMockBluetoothGattCharacteristic> characteristic( | 659 scoped_ptr<NiceMockBluetoothGattCharacteristic> characteristic( |
| 648 GetBaseGATTCharacteristic(service, errorUUID(error_alias))); | 660 GetBaseGATTCharacteristic( |
| 661 service, |
| 662 errorUUID(error_alias), |
| 663 BluetoothGattCharacteristic::PROPERTY_READ | |
| 664 BluetoothGattCharacteristic::PROPERTY_WRITE | |
| 665 BluetoothGattCharacteristic::PROPERTY_INDICATE)); |
| 666 |
| 649 | 667 |
| 650 // Read response. | 668 // Read response. |
| 651 ON_CALL(*characteristic, ReadRemoteCharacteristic(_, _)) | 669 ON_CALL(*characteristic, ReadRemoteCharacteristic(_, _)) |
| 652 .WillByDefault(RunCallback<1 /* error_callback */>(error_code)); | 670 .WillByDefault(RunCallback<1 /* error_callback */>(error_code)); |
| 653 | 671 |
| 654 // Write response. | 672 // Write response. |
| 655 ON_CALL(*characteristic, WriteRemoteCharacteristic(_, _, _)) | 673 ON_CALL(*characteristic, WriteRemoteCharacteristic(_, _, _)) |
| 656 .WillByDefault(RunCallback<2 /* error_callback */>(error_code)); | 674 .WillByDefault(RunCallback<2 /* error_callback */>(error_code)); |
| 657 | 675 |
| 658 // StartNotifySession response | 676 // StartNotifySession response |
| (...skipping 29 matching lines...) Expand all Loading... |
| 688 return base::StringPrintf("%08x-97e5-4cd7-b9f1-f5a427670c59", alias); | 706 return base::StringPrintf("%08x-97e5-4cd7-b9f1-f5a427670c59", alias); |
| 689 } | 707 } |
| 690 | 708 |
| 691 // static | 709 // static |
| 692 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { | 710 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { |
| 693 return BluetoothDevice::CanonicalizeAddress( | 711 return BluetoothDevice::CanonicalizeAddress( |
| 694 base::StringPrintf("%012" PRIx64, addr)); | 712 base::StringPrintf("%012" PRIx64, addr)); |
| 695 } | 713 } |
| 696 | 714 |
| 697 } // namespace content | 715 } // namespace content |
| OLD | NEW |