Chromium Code Reviews| Index: content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc |
| 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 3c3dda085ed562654e58879c000ca5d54eca2361..e14940e231d6efda9538fc8d0e8145a7964e1e7b 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 |
| @@ -23,6 +23,7 @@ using device::BluetoothUUID; |
| using device::MockBluetoothAdapter; |
| using device::MockBluetoothDevice; |
| using device::MockBluetoothDiscoverySession; |
| +using device::MockBluetoothGattCharacteristic; |
| using device::MockBluetoothGattConnection; |
| using device::MockBluetoothGattService; |
| using testing::Between; |
| @@ -64,8 +65,20 @@ ACTION_P(GetMockDevice, adapter) { |
| } |
| return NULL; |
| } |
| + |
| +// Function to iterate over the device's services and return the one |
| +// that matches the identifier. |
| +ACTION_P(GetMockService, device) { |
| + std::string identifier = arg0; |
| + for (BluetoothGattService* service : device->GetMockServices()) { |
| + if (service->GetIdentifier() == identifier) |
| + return service; |
| + } |
| + return NULL; |
| } |
| +} // namespace |
| + |
| namespace content { |
| // static |
| @@ -174,10 +187,18 @@ LayoutTestBluetoothAdapterProvider::GetEmptyDevice( |
| list.push_back(BluetoothUUID("1801")); |
| ON_CALL(*empty_device, GetUUIDs()).WillByDefault(Return(list)); |
| - empty_device->AddMockService( |
| + scoped_ptr<NiceMock<MockBluetoothGattService>> generic_access( |
| GetMockService(empty_device.get(), "1800" /* Generic Access */)); |
| - empty_device->AddMockService( |
| + generic_access->AddMockCharacteristic( |
| + GetMockCharacteristic(generic_access.get(), "2A00" /* Device Name */)); |
| + |
| + scoped_ptr<NiceMock<MockBluetoothGattService>> generic_attribute( |
| GetMockService(empty_device.get(), "1801" /* Generic Attribute */)); |
| + generic_attribute->AddMockCharacteristic(GetMockCharacteristic( |
| + generic_attribute.get(), "2A05" /* Service Changed */)); |
| + |
| + empty_device->AddMockService(generic_access.Pass()); |
| + empty_device->AddMockService(generic_attribute.Pass()); |
| // Using Invoke allows the device returned from this method to be futher |
| // modified and have more services added to it. The call to ::GetGattServices |
| @@ -187,6 +208,12 @@ LayoutTestBluetoothAdapterProvider::GetEmptyDevice( |
| .WillByDefault( |
| Invoke(empty_device.get(), &MockBluetoothDevice::GetMockServices)); |
| + // The call to BluetoothDevice::GetService will invoke ::GetMockService |
| + // which returns a service matching the identifier provided if the service |
| + // was added to the mock. |
| + ON_CALL(*empty_device, GetGattService(_)) |
| + .WillByDefault(::GetMockService(empty_device.get())); |
|
Jeffrey Yasskin
2015/06/02 22:12:29
I'm unhappy with the name collision between the ::
ortuno
2015/06/03 20:27:23
What about changing LayoutTestBluetoothAdapterProv
Jeffrey Yasskin
2015/06/03 22:56:24
Sure.
|
| + |
| return empty_device.Pass(); |
| } |
| @@ -225,9 +252,25 @@ LayoutTestBluetoothAdapterProvider::GetUnconnectableDevice( |
| scoped_ptr<NiceMock<MockBluetoothGattService>> |
| LayoutTestBluetoothAdapterProvider::GetMockService(MockBluetoothDevice* device, |
| const std::string& uuid) { |
| - return make_scoped_ptr(new NiceMock<MockBluetoothGattService>( |
| - device, uuid /* identifier */, BluetoothUUID(uuid), true /* is_primary */, |
| - false /* is_local */)); |
| + scoped_ptr<NiceMock<MockBluetoothGattService>> service( |
| + new NiceMock<MockBluetoothGattService>( |
| + device, uuid /* identifier */, BluetoothUUID(uuid), |
| + true /* is_primary */, false /* is_local */)); |
| + |
| + ON_CALL(*service, GetCharacteristics()) |
| + .WillByDefault(Invoke(service.get(), |
| + &MockBluetoothGattService::GetMockCharacteristics)); |
| + return service.Pass(); |
| +} |
| + |
| +// static |
| +scoped_ptr<NiceMock<MockBluetoothGattCharacteristic>> |
| +LayoutTestBluetoothAdapterProvider::GetMockCharacteristic( |
| + MockBluetoothGattService* service, |
| + const std::string& uuid) { |
| + return make_scoped_ptr(new NiceMock<MockBluetoothGattCharacteristic>( |
| + service, uuid /* identifier */, BluetoothUUID(uuid), false /* is_local */, |
| + NULL /* properties */, NULL /* permissions */)); |
| } |
| } // namespace content |