From 338cf0096006ea5bdefbbe2c0e4042698fde3b9c Mon Sep 17 00:00:00 2001 From: ortuno Date: Wed, 22 Jul 2015 10:59:12 -0700 Subject: [PATCH] bluetooth: Implement MissingCharacteristicAdapter and GetBaseGATTService. Part of the refactoring of the test platform. MissingCharacteristicAdapter is used for test what happens when a characteristic gets removed. Design doc: https://docs.google.com/document/d/1_QsBzcc84SwF7oaBWbO8rBzn39MISQ3w-6QM9hk0L3E/edit?usp=sharing Blink-side patch: http://crrev.com/1242813003 BUG=499552 Review URL: https://codereview.chromium.org/1242403002 Cr-Commit-Position: refs/heads/master@{#339912} --- .../layout_test_bluetooth_adapter_provider.cc | 66 +++++++++++++++------- .../layout_test_bluetooth_adapter_provider.h | 43 +++++++++++--- 2 files changed, 79 insertions(+), 30 deletions(-) diff --git a/content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc b/content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc index 810f69708b07..7b0f79a6ff8b 100644 --- a/content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc +++ b/content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc @@ -111,6 +111,8 @@ LayoutTestBluetoothAdapterProvider::GetBluetoothAdapter( return GetGlucoseHeartRateAdapter(); else if (fake_adapter_name == "MissingServiceGenericAccessAdapter") return GetMissingServiceGenericAccessAdapter(); + else if (fake_adapter_name == "MissingCharacteristicGenericAccessAdapter") + return GetMissingCharacteristicGenericAccessAdapter(); else if (fake_adapter_name == "") return NULL; @@ -222,6 +224,27 @@ LayoutTestBluetoothAdapterProvider::GetMissingServiceGenericAccessAdapter() { } // static +scoped_refptr> +LayoutTestBluetoothAdapterProvider:: + GetMissingCharacteristicGenericAccessAdapter() { + scoped_refptr> adapter(GetEmptyAdapter()); + + scoped_ptr> device( + GetGenericAccessDevice(adapter.get())); + + scoped_ptr> generic_access( + GetBaseGATTService(device.get(), kGenericAccessServiceUUID)); + + // Intentionally NOT adding a characteristic to generic_access service. + + device->AddMockService(generic_access.Pass()); + + adapter->AddMockDevice(device.Pass()); + + return adapter.Pass(); +} + +// static scoped_ptr> LayoutTestBluetoothAdapterProvider::GetBaseDevice( MockBluetoothAdapter* adapter, @@ -324,6 +347,27 @@ LayoutTestBluetoothAdapterProvider::GetGenericAccessDevice( return GetConnectableDeviceNew(adapter, device_name, uuids); } +// static +scoped_ptr> +LayoutTestBluetoothAdapterProvider::GetBaseGATTService( + MockBluetoothDevice* device, + const std::string& uuid) { + scoped_ptr> service( + new NiceMock( + device, uuid /* identifier */, BluetoothUUID(uuid), + true /* is_primary */, false /* is_local */)); + + ON_CALL(*service, GetCharacteristics()) + .WillByDefault(Invoke(service.get(), + &MockBluetoothGattService::GetMockCharacteristics)); + + ON_CALL(*service, GetCharacteristic(_)) + .WillByDefault(Invoke(service.get(), + &MockBluetoothGattService::GetMockCharacteristic)); + + return service.Pass(); +} + // The functions after this haven't been updated to the new design yet. // static @@ -379,7 +423,7 @@ LayoutTestBluetoothAdapterProvider::GetEmptyDevice( ON_CALL(*empty_device, GetUUIDs()).WillByDefault(Return(list)); scoped_ptr> generic_access( - GetGattService(empty_device.get(), kGenericAccessServiceUUID)); + GetBaseGATTService(empty_device.get(), kGenericAccessServiceUUID)); scoped_ptr> device_name_characteristic(GetGattCharacteristic( generic_access.get(), "2A00" /* Device Name */)); @@ -460,26 +504,6 @@ LayoutTestBluetoothAdapterProvider::GetUnconnectableDevice( } // static -scoped_ptr> -LayoutTestBluetoothAdapterProvider::GetGattService(MockBluetoothDevice* device, - const std::string& uuid) { - scoped_ptr> service( - new NiceMock( - device, uuid /* identifier */, BluetoothUUID(uuid), - true /* is_primary */, false /* is_local */)); - - ON_CALL(*service, GetCharacteristics()) - .WillByDefault(Invoke(service.get(), - &MockBluetoothGattService::GetMockCharacteristics)); - - ON_CALL(*service, GetCharacteristic(_)) - .WillByDefault(Invoke(service.get(), - &MockBluetoothGattService::GetMockCharacteristic)); - - return service.Pass(); -} - -// static scoped_ptr> LayoutTestBluetoothAdapterProvider::GetGattCharacteristic( MockBluetoothGattService* service, diff --git a/content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.h b/content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.h index 1f5ad1d74f50..3a5a932a99c4 100644 --- a/content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.h +++ b/content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.h @@ -94,6 +94,15 @@ class LayoutTestBluetoothAdapterProvider { static scoped_refptr> GetMissingServiceGenericAccessAdapter(); + // |MissingCharacteristicGenericAccessAdapter| + // Inherits from EmptyAdapter + // Internal Structure: + // - GenericAccessDevice + // - GenericAccess UUID (0x1800) + // - GenericAccessService + static scoped_refptr> + GetMissingCharacteristicGenericAccessAdapter(); + // Discovery Sessions // |DiscoverySession| @@ -202,6 +211,31 @@ class LayoutTestBluetoothAdapterProvider { device::MockBluetoothAdapter* adapter, const std::string& device_name = "Generic Access Device"); + // Services + + // |BaseGATTService| + // Characteristics Added: + // None. + // Mock Functions: + // - GetCharacteristics: + // Returns a list with all the characteristics added to the service + // - GetCharacteristic: + // Returns a characteristic matching the identifier provided if the + // characteristic was added to the mock. + // - GetIdentifier: + // Returns: uuid + “ Identifier” + // - GetUUID: + // Returns: uuid + // - IsLocal: + // Returns: false + // - IsPrimary: + // Returns: true + // - GetDevice: + // Returns: device + static scoped_ptr> + GetBaseGATTService(device::MockBluetoothDevice* device, + const std::string& uuid); + // The functions after this haven't been updated to the new design yet. // Returns "SingleEmptyDeviceAdapter" fake BluetoothAdapter with the following @@ -265,15 +299,6 @@ class LayoutTestBluetoothAdapterProvider { static scoped_ptr> GetUnconnectableDevice(device::MockBluetoothAdapter* adapter); - // Returns a fake BluetoothGattService with the following characteristics: - // - |GetIdentifier| returns |uuid|. - // - |GetUUID| returns BluetoothUUID(|uuid|). - // - |IsLocal| returns false. - // - |IsPrimary| returns true. - // - |GetDevice| returns |device|. - static scoped_ptr> - GetGattService(device::MockBluetoothDevice* device, const std::string& uuid); - // Returns a fake BluetoothGattCharacteristic with the following // characteristics: // - |GetIdentifier| returns |uuid|. -- 2.11.4.GIT