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

Side by Side Diff: content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc

Issue 1697873002: bluetooth: Test Web Bluetooth getCharacteristic calls against blacklist. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bt-blacklist-integration-
Patch Set: addressed ortuno's comments Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 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"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 typedef testing::NiceMock<MockBluetoothGattCharacteristic> 52 typedef testing::NiceMock<MockBluetoothGattCharacteristic>
53 NiceMockBluetoothGattCharacteristic; 53 NiceMockBluetoothGattCharacteristic;
54 typedef testing::NiceMock<MockBluetoothGattConnection> 54 typedef testing::NiceMock<MockBluetoothGattConnection>
55 NiceMockBluetoothGattConnection; 55 NiceMockBluetoothGattConnection;
56 typedef testing::NiceMock<MockBluetoothGattService> 56 typedef testing::NiceMock<MockBluetoothGattService>
57 NiceMockBluetoothGattService; 57 NiceMockBluetoothGattService;
58 typedef testing::NiceMock<MockBluetoothGattNotifySession> 58 typedef testing::NiceMock<MockBluetoothGattNotifySession>
59 NiceMockBluetoothGattNotifySession; 59 NiceMockBluetoothGattNotifySession;
60 60
61 namespace { 61 namespace {
62 // Bluetooth UUIDs suitable to pass to BluetoothUUID(). 62 // Bluetooth UUIDs suitable to pass to BluetoothUUID():
63 // Services:
63 const char kBatteryServiceUUID[] = "180f"; 64 const char kBatteryServiceUUID[] = "180f";
65 const char kDeviceInformationServiceUUID[] = "180a";
64 const char kGenericAccessServiceUUID[] = "1800"; 66 const char kGenericAccessServiceUUID[] = "1800";
65 const char kGlucoseServiceUUID[] = "1808"; 67 const char kGlucoseServiceUUID[] = "1808";
66 const char kHeartRateServiceUUID[] = "180d"; 68 const char kHeartRateServiceUUID[] = "180d";
67 const char kHumanInterfaceDeviceServiceUUID[] = "1812"; 69 const char kHumanInterfaceDeviceServiceUUID[] = "1812";
68 const char kTxPowerServiceUUID[] = "1804"; 70 const char kTxPowerServiceUUID[] = "1804";
69 const char kHeartRateMeasurementUUID[] = "2a37"; 71 // Characteristics:
70 const char kBodySensorLocation[] = "2a38"; 72 const char kBodySensorLocation[] = "2a38";
71 const char kDeviceNameUUID[] = "2a00"; 73 const char kDeviceNameUUID[] = "2a00";
74 const char kHeartRateMeasurementUUID[] = "2a37";
75 const char kSerialNumberStringUUID[] = "2a25";
72 76
73 const int kDefaultTxPower = -10; // TxPower of a device broadcasting at 0.1mW. 77 const int kDefaultTxPower = -10; // TxPower of a device broadcasting at 0.1mW.
74 const int kDefaultRssi = -51; // RSSI at 1m from a device broadcasting at 78 const int kDefaultRssi = -51; // RSSI at 1m from a device broadcasting at
75 // 0.1mW. 79 // 0.1mW.
76 80
77 // Invokes Run() on the k-th argument of the function with no arguments. 81 // Invokes Run() on the k-th argument of the function with no arguments.
78 ACTION_TEMPLATE(RunCallback, 82 ACTION_TEMPLATE(RunCallback,
79 HAS_1_TEMPLATE_PARAMS(int, k), 83 HAS_1_TEMPLATE_PARAMS(int, k),
80 AND_0_VALUE_PARAMS()) { 84 AND_0_VALUE_PARAMS()) {
81 return ::testing::get<k>(args).Run(); 85 return ::testing::get<k>(args).Run();
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 477
474 // static 478 // static
475 scoped_refptr<NiceMockBluetoothAdapter> 479 scoped_refptr<NiceMockBluetoothAdapter>
476 LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() { 480 LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() {
477 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); 481 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter());
478 scoped_ptr<NiceMockBluetoothDevice> device(GetHeartRateDevice(adapter.get())); 482 scoped_ptr<NiceMockBluetoothDevice> device(GetHeartRateDevice(adapter.get()));
479 483
480 // TODO(ortuno): Implement the rest of the service's characteristics 484 // TODO(ortuno): Implement the rest of the service's characteristics
481 // See: http://crbug.com/529975 485 // See: http://crbug.com/529975
482 486
483 device->AddMockService(GetGenericAccessService(adapter.get(), device.get())); 487 device->AddMockService(GetGenericAccessService(device.get()));
484 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); 488 device->AddMockService(GetHeartRateService(adapter.get(), device.get()));
485 adapter->AddMockDevice(std::move(device)); 489 adapter->AddMockDevice(std::move(device));
486 490
487 return adapter; 491 return adapter;
488 } 492 }
489 493
490 // static 494 // static
491 scoped_refptr<NiceMockBluetoothAdapter> 495 scoped_refptr<NiceMockBluetoothAdapter>
492 LayoutTestBluetoothAdapterProvider::GetHeartRateAndHIDAdapter() { 496 LayoutTestBluetoothAdapterProvider::GetHeartRateAndHIDAdapter() {
493 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); 497 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter());
494 498
495 BluetoothDevice::UUIDList uuids; 499 BluetoothDevice::UUIDList uuids;
496 uuids.push_back(BluetoothUUID(kGenericAccessServiceUUID)); 500 uuids.push_back(BluetoothUUID(kGenericAccessServiceUUID));
497 uuids.push_back(BluetoothUUID(kHeartRateServiceUUID)); 501 uuids.push_back(BluetoothUUID(kHeartRateServiceUUID));
498 uuids.push_back(BluetoothUUID(kHumanInterfaceDeviceServiceUUID)); 502 uuids.push_back(BluetoothUUID(kHumanInterfaceDeviceServiceUUID));
499 503
500 scoped_ptr<NiceMockBluetoothDevice> device( 504 scoped_ptr<NiceMockBluetoothDevice> device(
501 GetConnectableDevice(adapter.get(), "Heart Rate And HID Device", uuids)); 505 GetConnectableDevice(adapter.get(), "Heart Rate And HID Device", uuids));
502 506
503 device->AddMockService(GetGenericAccessService(adapter.get(), device.get())); 507 device->AddMockService(GetDeviceInformationService(device.get()));
508 device->AddMockService(GetGenericAccessService(device.get()));
504 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); 509 device->AddMockService(GetHeartRateService(adapter.get(), device.get()));
505 device->AddMockService( 510 device->AddMockService(
506 GetBaseGATTService(device.get(), kHumanInterfaceDeviceServiceUUID)); 511 GetBaseGATTService(device.get(), kHumanInterfaceDeviceServiceUUID));
507 adapter->AddMockDevice(std::move(device)); 512 adapter->AddMockDevice(std::move(device));
508 513
509 return adapter; 514 return adapter;
510 } 515 }
511 516
512 // static 517 // static
513 scoped_refptr<NiceMockBluetoothAdapter> 518 scoped_refptr<NiceMockBluetoothAdapter>
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 703
699 ON_CALL(*service, GetCharacteristic(_)) 704 ON_CALL(*service, GetCharacteristic(_))
700 .WillByDefault(Invoke(service.get(), 705 .WillByDefault(Invoke(service.get(),
701 &MockBluetoothGattService::GetMockCharacteristic)); 706 &MockBluetoothGattService::GetMockCharacteristic));
702 707
703 return service; 708 return service;
704 } 709 }
705 710
706 // static 711 // static
707 scoped_ptr<NiceMockBluetoothGattService> 712 scoped_ptr<NiceMockBluetoothGattService>
713 LayoutTestBluetoothAdapterProvider::GetDeviceInformationService(
714 device::MockBluetoothDevice* device) {
715 scoped_ptr<NiceMockBluetoothGattService> device_information(
716 GetBaseGATTService(device, kDeviceInformationServiceUUID));
717
718 scoped_ptr<NiceMockBluetoothGattCharacteristic> serial_number_string(
719 GetBaseGATTCharacteristic(device_information.get(),
720 kSerialNumberStringUUID,
721 BluetoothGattCharacteristic::PROPERTY_READ));
722
723 EXPECT_CALL(*serial_number_string, ReadRemoteCharacteristic(_, _)).Times(0);
ortuno 2016/02/24 23:08:17 I think you should just CHECK. I've had cases in w
scheib 2016/02/24 23:38:52 Done.
724
725 device_information->AddMockCharacteristic(std::move(serial_number_string));
726
727 return device_information;
728 }
729
730 // static
731 scoped_ptr<NiceMockBluetoothGattService>
708 LayoutTestBluetoothAdapterProvider::GetGenericAccessService( 732 LayoutTestBluetoothAdapterProvider::GetGenericAccessService(
709 MockBluetoothAdapter* adapter, 733 device::MockBluetoothDevice* device) {
710 MockBluetoothDevice* device) {
711 scoped_ptr<NiceMockBluetoothGattService> generic_access( 734 scoped_ptr<NiceMockBluetoothGattService> generic_access(
712 GetBaseGATTService(device, kGenericAccessServiceUUID)); 735 GetBaseGATTService(device, kGenericAccessServiceUUID));
713 736
714 scoped_ptr<NiceMockBluetoothGattCharacteristic> device_name( 737 scoped_ptr<NiceMockBluetoothGattCharacteristic> device_name(
715 GetBaseGATTCharacteristic( 738 GetBaseGATTCharacteristic(
716 generic_access.get(), kDeviceNameUUID, 739 generic_access.get(), kDeviceNameUUID,
717 BluetoothGattCharacteristic::PROPERTY_READ | 740 BluetoothGattCharacteristic::PROPERTY_READ |
718 BluetoothGattCharacteristic::PROPERTY_WRITE)); 741 BluetoothGattCharacteristic::PROPERTY_WRITE));
719 742
720 // Read response. 743 // Read response.
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 return BluetoothUUID(); 927 return BluetoothUUID();
905 } 928 }
906 929
907 // static 930 // static
908 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { 931 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) {
909 return BluetoothDevice::CanonicalizeAddress( 932 return BluetoothDevice::CanonicalizeAddress(
910 base::StringPrintf("%012" PRIx64, addr)); 933 base::StringPrintf("%012" PRIx64, addr));
911 } 934 }
912 935
913 } // namespace content 936 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698