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..f834bb3c93ceb9560e822cc24530b0150a8ffcde |
| --- /dev/null |
| +++ b/content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc |
| @@ -0,0 +1,124 @@ |
| +// 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) { |
| + adapter_ = new NiceMock<MockBluetoothAdapter>(); |
|
Jeffrey Yasskin
2015/05/12 22:17:54
Why do you stash the adapter in the Provider? It s
ortuno
2015/05/13 17:14:49
Done.
|
| + |
| + 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) { |
| + adapter_ = new NiceMock<MockBluetoothAdapter>(); |
| + |
| + ON_CALL(*adapter_, StartDiscoverySession(_, _)) |
| + .WillByDefault(Invoke( |
| + this, |
| + &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession)); |
| + |
| + BluetoothAdapter::ConstDeviceList devices; |
| + SetupEmptyDevice(); |
|
Jeffrey Yasskin
2015/05/12 22:17:54
Definitely pass the adapter into this function as
ortuno
2015/05/13 17:14:49
Done.
|
| + devices.push_back(empty_device_.get()); |
| + ON_CALL(*adapter_, GetDevices()).WillByDefault(Return(devices)); |
| + |
| + callback.Run(adapter_); |
| +} |
| +void LayoutTestBluetoothAdapterProvider::SetupEmptyDevice() { |
| + empty_device_.reset(new NiceMock<MockBluetoothDevice>( |
| + adapter_.get(), 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)); |
| +} |
| + |
| +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 |