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..599e7d148ce3754eacaaedd8ccbbb891549d62b8 |
--- /dev/null |
+++ b/content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc |
@@ -0,0 +1,111 @@ |
+// 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 == "") |
+ callback.Run(NULL); |
scheib
2015/05/12 20:15:06
We start off with a real adapter, and then can ena
ortuno
2015/05/12 20:49:08
Done.
|
+ else |
+ NOTREACHED(); |
+} |
+ |
+void LayoutTestBluetoothAdapterProvider::GetEmptyAdapter( |
+ const BluetoothAdapterFactory::AdapterCallback& callback) { |
+ adapter_ = 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) { |
+ adapter_ = new NiceMock<MockBluetoothAdapter>(); |
+ ON_CALL(*adapter_, StartDiscoverySession(_, _)) |
+ .WillByDefault(Invoke( |
+ this, |
+ &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession)); |
+ SetupEmptyDevice(); |
+ BluetoothAdapter::ConstDeviceList devices; |
+ 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, "Empty Mock Device name", |
scheib
2015/05/12 20:15:06
Comment the 0x1F00 literal with parameter name.
ortuno
2015/05/12 20:49:08
Done.
|
+ "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 |