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..d8d1493d23e514d8015d636af550705973c54461 |
| --- /dev/null |
| +++ b/content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc |
| @@ -0,0 +1,101 @@ |
| +// 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_discovery_session.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| + |
|
scheib
2015/05/12 01:16:28
Add using statements to simplify code below, such
ortuno
2015/05/12 19:33:20
Done.
|
| +namespace content { |
| + |
| +const uint32 kUnspecifiedDeviceClass = |
| + 0x1F00; // bluetooth.org/en-us/specification/assigned-numbers/baseband |
| + |
| +LayoutTestBluetoothAdapterProvider::LayoutTestBluetoothAdapterProvider() |
| + : uuid1(new BluetoothUUID("1800")), uuid2(new BluetoothUUID("1801")) { |
| +} |
| +LayoutTestBluetoothAdapterProvider::~LayoutTestBluetoothAdapterProvider() { |
|
scheib
2015/05/11 20:19:26
Insert blank line above.
ortuno
2015/05/12 19:33:19
Done.
|
| +} |
| + |
| +void LayoutTestBluetoothAdapterProvider::GetBluetoothAdapter( |
| + const BluetoothAdapterFactory::AdapterCallback& callback, |
| + const std::string& adapter) { |
| + // TODO(ortuno): Remove RejectRequestDevice once LayoutTests are modified |
| + if (adapter == "RejectRequestDevice_NotFoundError" || |
| + adapter == "EmptyAdapter") |
| + GetEmptyAdapter(callback); |
| + // TODO(ortuno): Remove "Single Empty Device" once LayoutTests are modified |
| + else if (adapter == "Single Empty Device" || |
| + adapter == "SingleEmptyDeviceAdapter") |
| + GetSingleEmptyDeviceAdapter(callback); |
| + else if (adapter == "") { |
| + if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) |
| + BluetoothAdapterFactory::GetAdapter(callback); |
| + } else |
| + NOTREACHED(); |
|
scheib
2015/05/12 01:16:28
"if one part of an if-else statement uses curly br
ortuno
2015/05/12 19:33:19
Done.
|
| +} |
| + |
| +void LayoutTestBluetoothAdapterProvider::GetEmptyAdapter( |
| + const BluetoothAdapterFactory::AdapterCallback& callback) { |
| + testing::NiceMock<MockBluetoothAdapter>* mock_adapter_ = |
|
scheib
2015/05/12 01:16:28
Let's keep a scoped_refptr in this class to the ad
ortuno
2015/05/12 19:33:20
Done.
Jeffrey Yasskin
2015/05/12 22:37:49
We shouldn't stash single-function-call objects in
scheib
2015/05/13 04:11:05
The reason I discussed with ortuno in person was t
Jeffrey Yasskin
2015/05/13 19:40:50
Yeah, even if it increases the size of a line or t
|
| + new testing::NiceMock<MockBluetoothAdapter>(); |
| + ON_CALL(*mock_adapter_, StartDiscoverySession(testing::_, testing::_)) |
| + .WillByDefault( |
| + testing::Invoke(this, &LayoutTestBluetoothAdapterProvider:: |
|
scheib
2015/05/12 01:16:28
The LayoutTestBluetoothAdapterProvider:: is redund
ortuno
2015/05/12 19:33:19
It is not :(
|
| + SuccessfulDiscoverySessionCallback)); |
| + ON_CALL(*mock_adapter_, GetDevices()) |
| + .WillByDefault(testing::Return(BluetoothAdapter::ConstDeviceList())); |
| + callback.Run(scoped_refptr<BluetoothAdapter>(mock_adapter_)); |
|
scheib
2015/05/12 01:16:27
These should then be able to collapse to just call
ortuno
2015/05/12 19:33:19
Done.
|
| +} |
| + |
| +void LayoutTestBluetoothAdapterProvider::GetSingleEmptyDeviceAdapter( |
| + const BluetoothAdapterFactory::AdapterCallback& callback) { |
| + testing::NiceMock<MockBluetoothAdapter>* mock_adapter_ = |
| + new testing::NiceMock<MockBluetoothAdapter>(); |
| + ON_CALL(*mock_adapter_, StartDiscoverySession(testing::_, testing::_)) |
| + .WillByDefault( |
| + testing::Invoke(this, &LayoutTestBluetoothAdapterProvider:: |
| + SuccessfulDiscoverySessionCallback)); |
| + SetUpMockEmptyDevice(mock_adapter_); |
| + BluetoothAdapter::ConstDeviceList devices; |
| + devices.push_back(empty_device_.get()); |
| + ON_CALL(*mock_adapter_, GetDevices()).WillByDefault(testing::Return(devices)); |
| + callback.Run(scoped_refptr<BluetoothAdapter>(mock_adapter_)); |
| +} |
| +void LayoutTestBluetoothAdapterProvider::SetUpMockEmptyDevice( |
| + MockBluetoothAdapter* adapter) { |
| + testing::NiceMock<MockBluetoothDevice>* empty_device = |
| + new testing::NiceMock<MockBluetoothDevice>( |
| + adapter, kUnspecifiedDeviceClass, "Empty Mock Device name", |
| + "Empty Mock Device instanceID", true, /* Paired */ |
| + true /* Connected */); |
| + ON_CALL(*empty_device, GetVendorIDSource()) |
| + .WillByDefault(testing::Return(BluetoothDevice::VENDOR_ID_BLUETOOTH)); |
| + ON_CALL(*empty_device, GetVendorID()).WillByDefault(testing::Return(0xFFFF)); |
| + ON_CALL(*empty_device, GetProductID()).WillByDefault(testing::Return(1)); |
| + ON_CALL(*empty_device, GetDeviceID()).WillByDefault(testing::Return(2)); |
| + BluetoothDevice::UUIDList list; |
| + list.push_back(*uuid1.get()); |
| + list.push_back(*uuid2.get()); |
| + ON_CALL(*empty_device, GetUUIDs()).WillByDefault(testing::Return(list)); |
| + empty_device_.reset(empty_device); |
|
scheib
2015/05/12 01:16:28
Just set the device member at the top of this meth
ortuno
2015/05/12 19:33:20
Done.
|
| +} |
| + |
| +void LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySessionCallback( |
| + const BluetoothAdapter::DiscoverySessionCallback& callback, |
| + const BluetoothAdapter::ErrorCallback& error_callback) { |
| + testing::NiceMock<MockBluetoothDiscoverySession>* discovery_session = |
| + new testing::NiceMock<MockBluetoothDiscoverySession>(); |
| + ON_CALL(*discovery_session, Stop(testing::_, testing::_)) |
| + .WillByDefault(testing::Invoke(SuccessfulStopDiscoverySessionCallback)); |
| + callback.Run(scoped_ptr<BluetoothDiscoverySession>(discovery_session)); |
| +} |
| + |
| +void LayoutTestBluetoothAdapterProvider::SuccessfulStopDiscoverySessionCallback( |
| + const base::Closure& callback, |
| + const base::Closure& error_callback) { |
| + callback.Run(); |
| +} |
| + |
| +} // namespace content |