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

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

Issue 2188373002: DO NOT SUBMIT bluetooth-fuzzer: Draft fuzzer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-catch-and-connect
Patch Set: Created 4 years, 4 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 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 adapter->AddMockDevice(std::move(device)); 494 adapter->AddMockDevice(std::move(device));
495 495
496 return adapter; 496 return adapter;
497 } 497 }
498 498
499 // static 499 // static
500 scoped_refptr<NiceMockBluetoothAdapter> 500 scoped_refptr<NiceMockBluetoothAdapter>
501 LayoutTestBluetoothAdapterProvider::GetDisconnectingHeartRateAdapter() { 501 LayoutTestBluetoothAdapterProvider::GetDisconnectingHeartRateAdapter() {
502 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); 502 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter());
503 NiceMockBluetoothAdapter* adapter_ptr = adapter.get(); 503 NiceMockBluetoothAdapter* adapter_ptr = adapter.get();
504
505 BluetoothDevice::UUIDList uuids;
506 uuids.push_back(BluetoothUUID(kGenericAccessServiceUUID));
507 uuids.push_back(BluetoothUUID(kHeartRateServiceUUID));
508 uuids.push_back(BluetoothUUID(kRequestDisconnectionServiceUUID));
509
504 std::unique_ptr<NiceMockBluetoothDevice> device( 510 std::unique_ptr<NiceMockBluetoothDevice> device(
505 GetHeartRateDevice(adapter.get())); 511 GetConnectableDevice(adapter.get(), "Disconnecting Device", uuids));
512
506 NiceMockBluetoothDevice* device_ptr = device.get(); 513 NiceMockBluetoothDevice* device_ptr = device.get();
507 514
508 // TODO(ortuno): Implement the rest of the service's characteristics 515 // TODO(ortuno): Implement the rest of the service's characteristics
509 // See: http://crbug.com/529975 516 // See: http://crbug.com/529975
510 517
511 device->AddMockService(GetGenericAccessService(device.get())); 518 device->AddMockService(GetGenericAccessService(device.get()));
512 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); 519 device->AddMockService(GetHeartRateService(adapter.get(), device.get()));
513 520
514 // Set up a service and a characteristic to disconnect the device when it's 521 // Set up a service and a characteristic to disconnect the device when it's
515 // written to. 522 // written to.
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 BluetoothRemoteGattCharacteristic::PROPERTY_READ | 869 BluetoothRemoteGattCharacteristic::PROPERTY_READ |
863 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); 870 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
864 871
865 // Read response. 872 // Read response.
866 std::vector<uint8_t> value(1); 873 std::vector<uint8_t> value(1);
867 value[0] = false; 874 value[0] = false;
868 875
869 ON_CALL(*peripheral_privacy_flag, ReadRemoteCharacteristic(_, _)) 876 ON_CALL(*peripheral_privacy_flag, ReadRemoteCharacteristic(_, _))
870 .WillByDefault(RunCallback<0>(value)); 877 .WillByDefault(RunCallback<0>(value));
871 878
872 // Crash if WriteRemoteCharacteristic called. Not using GoogleMock's Expect
873 // because this is used in layout tests that may not report a mock
874 // expectation error correctly as a layout test failure.
875 ON_CALL(*peripheral_privacy_flag, WriteRemoteCharacteristic(_, _, _))
876 .WillByDefault(
877 Invoke([](const std::vector<uint8_t>&, const base::Closure&,
878 const BluetoothRemoteGattCharacteristic::ErrorCallback&) {
879 NOTREACHED();
880 }));
881
882 generic_access->AddMockCharacteristic(std::move(peripheral_privacy_flag)); 879 generic_access->AddMockCharacteristic(std::move(peripheral_privacy_flag));
883 } 880 }
884 881
885 return generic_access; 882 return generic_access;
886 } 883 }
887 884
888 // static 885 // static
889 std::unique_ptr<NiceMockBluetoothGattService> 886 std::unique_ptr<NiceMockBluetoothGattService>
890 LayoutTestBluetoothAdapterProvider::GetHeartRateService( 887 LayoutTestBluetoothAdapterProvider::GetHeartRateService(
891 MockBluetoothAdapter* adapter, 888 MockBluetoothAdapter* adapter,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 966
970 // Characteristics 967 // Characteristics
971 968
972 // static 969 // static
973 std::unique_ptr<NiceMockBluetoothGattCharacteristic> 970 std::unique_ptr<NiceMockBluetoothGattCharacteristic>
974 LayoutTestBluetoothAdapterProvider::GetBaseGATTCharacteristic( 971 LayoutTestBluetoothAdapterProvider::GetBaseGATTCharacteristic(
975 const std::string& identifier, 972 const std::string& identifier,
976 MockBluetoothGattService* service, 973 MockBluetoothGattService* service,
977 const std::string& uuid, 974 const std::string& uuid,
978 BluetoothRemoteGattCharacteristic::Properties properties) { 975 BluetoothRemoteGattCharacteristic::Properties properties) {
979 return base::WrapUnique(new NiceMockBluetoothGattCharacteristic( 976 std::unique_ptr<NiceMockBluetoothGattCharacteristic> characteristic(
980 service, identifier, BluetoothUUID(uuid), false /* is_local */, 977 new NiceMockBluetoothGattCharacteristic(
981 properties, NULL /* permissions */)); 978 service, identifier, BluetoothUUID(uuid), false /* is_local */,
979 properties, NULL /* permissions */));
980
981 device::BluetoothGattService::GattErrorCode default_error =
982 device::BluetoothGattService::GATT_ERROR_NOT_SUPPORTED;
983
984 // Default Write response.
985 ON_CALL(*characteristic, WriteRemoteCharacteristic(_, _, _))
986 .WillByDefault(RunCallback<2>(default_error));
987
988 // Read response.
989 ON_CALL(*characteristic, ReadRemoteCharacteristic(_, _))
990 .WillByDefault(RunCallback<1>(default_error));
991
992 ON_CALL(*characteristic, StartNotifySession(_, _))
993 .WillByDefault(RunCallback<1>(default_error));
994
995 return characteristic;
982 } 996 }
983 997
984 // static 998 // static
985 std::unique_ptr<NiceMockBluetoothGattCharacteristic> 999 std::unique_ptr<NiceMockBluetoothGattCharacteristic>
986 LayoutTestBluetoothAdapterProvider::GetErrorCharacteristic( 1000 LayoutTestBluetoothAdapterProvider::GetErrorCharacteristic(
987 MockBluetoothGattService* service, 1001 MockBluetoothGattService* service,
988 BluetoothRemoteGattService::GattErrorCode error_code) { 1002 BluetoothRemoteGattService::GattErrorCode error_code) {
989 uint32_t error_alias = error_code + 0xA1; // Error UUIDs start at 0xA1. 1003 uint32_t error_alias = error_code + 0xA1; // Error UUIDs start at 0xA1.
990 std::unique_ptr<NiceMockBluetoothGattCharacteristic> characteristic( 1004 std::unique_ptr<NiceMockBluetoothGattCharacteristic> characteristic(
991 GetBaseGATTCharacteristic( 1005 GetBaseGATTCharacteristic(
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 return BluetoothUUID(); 1096 return BluetoothUUID();
1083 } 1097 }
1084 1098
1085 // static 1099 // static
1086 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { 1100 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) {
1087 return BluetoothDevice::CanonicalizeAddress( 1101 return BluetoothDevice::CanonicalizeAddress(
1088 base::StringPrintf("%012" PRIx64, addr)); 1102 base::StringPrintf("%012" PRIx64, addr));
1089 } 1103 }
1090 1104
1091 } // namespace content 1105 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698