Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(756)

Unified Diff: content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc

Issue 1132943002: bluetooth: Move mock creation out of BluetoothDispatcherHost to LayoutTestBluetoothAdapterProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-testing-layout-tests
Patch Set: Address scheib comments Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698