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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..072e7a048ee1d6bfcef5d8b51cc6a5c15b839748 |
| --- /dev/null |
| +++ b/content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc |
| @@ -0,0 +1,132 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.h" |
| + |
| +#include "device/bluetooth/bluetooth_adapter.h" |
| +#include "device/bluetooth/bluetooth_device.h" |
| +#include "device/bluetooth/bluetooth_discovery_session.h" |
| +#include "device/bluetooth/bluetooth_uuid.h" |
| +#include "device/bluetooth/test/mock_bluetooth_adapter.h" |
| +#include "device/bluetooth/test/mock_bluetooth_discovery_session.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| + |
| +using device::BluetoothAdapter; |
| +using device::BluetoothAdapterFactory; |
| +using device::BluetoothDevice; |
| +using device::BluetoothDiscoverySession; |
| +using device::BluetoothUUID; |
| +using device::MockBluetoothAdapter; |
| +using device::MockBluetoothDevice; |
| +using device::MockBluetoothDiscoverySession; |
| +using testing::Invoke; |
| +using testing::Return; |
| +using testing::NiceMock; |
| +using testing::_; |
| + |
| +namespace content { |
| + |
| +LayoutTestBluetoothAdapterProvider::LayoutTestBluetoothAdapterProvider() { |
| +} |
| + |
| +LayoutTestBluetoothAdapterProvider::~LayoutTestBluetoothAdapterProvider() { |
| +} |
| + |
| +void LayoutTestBluetoothAdapterProvider::GetBluetoothAdapter( |
| + const std::string& fake_adapter_name, |
| + const BluetoothAdapterFactory::AdapterCallback& callback) { |
| + // TODO(ortuno): Remove RejectRequestDevice once LayoutTests are modified |
| + if (fake_adapter_name == "RejectRequestDevice_NotFoundError" || |
| + fake_adapter_name == "EmptyAdapter") { |
| + GetEmptyAdapter(callback); |
| + } |
| + // TODO(ortuno): Remove "Single Empty Device" once LayoutTests are modified |
| + else if (fake_adapter_name == "Single Empty Device" || |
| + fake_adapter_name == "SingleEmptyDeviceAdapter") { |
| + GetSingleEmptyDeviceAdapter(callback); |
| + } else if (fake_adapter_name == "") { |
| + if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) |
| + BluetoothAdapterFactory::GetAdapter(callback); |
| + } else { |
| + NOTREACHED(); |
| + } |
| +} |
| + |
| +void LayoutTestBluetoothAdapterProvider::GetEmptyAdapter( |
| + const BluetoothAdapterFactory::AdapterCallback& callback) { |
| + NiceMock<MockBluetoothAdapter>* adapter = |
|
Jeffrey Yasskin
2015/05/13 19:40:50
You should almost always catch a new'ed pointer in
ortuno
2015/05/13 20:59:31
Done.
|
| + new NiceMock<MockBluetoothAdapter>(); |
| + |
| + ON_CALL(*adapter, StartDiscoverySession(_, _)) |
| + .WillByDefault(Invoke( |
| + this, |
| + &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession)); |
| + |
| + ON_CALL(*adapter, GetDevices()) |
| + .WillByDefault(Return(BluetoothAdapter::ConstDeviceList())); |
| + |
| + callback.Run(adapter); |
| +} |
| + |
| +void LayoutTestBluetoothAdapterProvider::GetSingleEmptyDeviceAdapter( |
| + const BluetoothAdapterFactory::AdapterCallback& callback) { |
| + NiceMock<MockBluetoothAdapter>* adapter = |
| + new NiceMock<MockBluetoothAdapter>(); |
| + |
| + ON_CALL(*adapter, StartDiscoverySession(_, _)) |
| + .WillByDefault(Invoke( |
| + this, |
| + &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession)); |
| + |
| + std::vector<MockBluetoothDevice*> devices; |
|
Jeffrey Yasskin
2015/05/13 19:40:51
Similarly here, the vector<> should hold scoped_pt
ortuno
2015/05/13 20:59:30
Changed MockBluetoothAdapter to accept a single de
|
| + devices.push_back(GetEmptyDevice(adapter)); |
| + adapter->SetMockDevices(devices); |
|
Jeffrey Yasskin
2015/05/13 19:40:51
I'd probably have this accept one device at a time
ortuno
2015/05/13 20:59:31
Done.
|
| + ON_CALL(*adapter, GetDevices()) |
| + .WillByDefault(Return(adapter->GetMockDevices())); |
| + |
| + callback.Run(adapter); |
| +} |
| + |
| +NiceMock<MockBluetoothDevice>* |
|
Jeffrey Yasskin
2015/05/13 19:40:51
Return a scoped_ptr<NiceMock<MockBluetoothDevice>>
ortuno
2015/05/13 20:59:30
Done.
|
| +LayoutTestBluetoothAdapterProvider::GetEmptyDevice( |
| + MockBluetoothAdapter* adapter) { |
| + NiceMock<MockBluetoothDevice>* empty_device = |
| + new NiceMock<MockBluetoothDevice>( |
| + adapter, 0x1F00 /* Bluetooth Class */, "Empty Mock Device name", |
| + "Empty Mock Device instanceID", true, /* Paired */ |
| + true /* Connected */); |
| + |
| + ON_CALL(*empty_device, GetVendorIDSource()) |
| + .WillByDefault(Return(BluetoothDevice::VENDOR_ID_BLUETOOTH)); |
| + ON_CALL(*empty_device, GetVendorID()).WillByDefault(Return(0xFFFF)); |
| + ON_CALL(*empty_device, GetProductID()).WillByDefault(Return(1)); |
| + ON_CALL(*empty_device, GetDeviceID()).WillByDefault(Return(2)); |
| + |
| + BluetoothDevice::UUIDList list; |
| + list.push_back(BluetoothUUID("1800")); |
| + list.push_back(BluetoothUUID("1801")); |
| + ON_CALL(*empty_device, GetUUIDs()).WillByDefault(Return(list)); |
| + return empty_device; |
| +} |
| + |
| +void LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession( |
| + const BluetoothAdapter::DiscoverySessionCallback& callback, |
| + const BluetoothAdapter::ErrorCallback& error_callback) { |
| + NiceMock<MockBluetoothDiscoverySession>* discovery_session = |
| + new NiceMock<MockBluetoothDiscoverySession>(); |
| + |
| + ON_CALL(*discovery_session, Stop(_, _)) |
| + .WillByDefault(Invoke( |
| + &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySessionStop)); |
| + |
| + callback.Run(scoped_ptr<BluetoothDiscoverySession>(discovery_session)); |
| +} |
| + |
| +void LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySessionStop( |
| + const base::Closure& callback, |
| + const base::Closure& error_callback) { |
| + callback.Run(); |
| +} |
| + |
| +} // namespace content |