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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/shell/browser/layout_test/layout_test_bluetooth_adapter_provid er.h"
6
7 #include "device/bluetooth/bluetooth_adapter.h"
8 #include "device/bluetooth/bluetooth_device.h"
9 #include "device/bluetooth/bluetooth_discovery_session.h"
10 #include "device/bluetooth/bluetooth_uuid.h"
11 #include "device/bluetooth/test/mock_bluetooth_adapter.h"
12 #include "device/bluetooth/test/mock_bluetooth_discovery_session.h"
13 #include "testing/gmock/include/gmock/gmock.h"
14
15 using device::BluetoothAdapter;
16 using device::BluetoothAdapterFactory;
17 using device::BluetoothDevice;
18 using device::BluetoothDiscoverySession;
19 using device::BluetoothUUID;
20 using device::MockBluetoothAdapter;
21 using device::MockBluetoothDevice;
22 using device::MockBluetoothDiscoverySession;
23 using testing::Invoke;
24 using testing::Return;
25 using testing::NiceMock;
26 using testing::_;
27
28 namespace content {
29
30 LayoutTestBluetoothAdapterProvider::LayoutTestBluetoothAdapterProvider() {
31 }
32
33 LayoutTestBluetoothAdapterProvider::~LayoutTestBluetoothAdapterProvider() {
34 }
35
36 void LayoutTestBluetoothAdapterProvider::GetBluetoothAdapter(
37 const std::string& fake_adapter_name,
38 const BluetoothAdapterFactory::AdapterCallback& callback) {
39 // TODO(ortuno): Remove RejectRequestDevice once LayoutTests are modified
40 if (fake_adapter_name == "RejectRequestDevice_NotFoundError" ||
41 fake_adapter_name == "EmptyAdapter") {
42 GetEmptyAdapter(callback);
43 }
44 // TODO(ortuno): Remove "Single Empty Device" once LayoutTests are modified
45 else if (fake_adapter_name == "Single Empty Device" ||
46 fake_adapter_name == "SingleEmptyDeviceAdapter") {
47 GetSingleEmptyDeviceAdapter(callback);
48 } else if (fake_adapter_name == "") {
49 if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable())
50 BluetoothAdapterFactory::GetAdapter(callback);
51 } else {
52 NOTREACHED();
53 }
54 }
55
56 void LayoutTestBluetoothAdapterProvider::GetEmptyAdapter(
57 const BluetoothAdapterFactory::AdapterCallback& callback) {
58 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.
59
60 ON_CALL(*adapter_, StartDiscoverySession(_, _))
61 .WillByDefault(Invoke(
62 this,
63 &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession));
64
65 ON_CALL(*adapter_, GetDevices())
66 .WillByDefault(Return(BluetoothAdapter::ConstDeviceList()));
67
68 callback.Run(adapter_);
69 }
70
71 void LayoutTestBluetoothAdapterProvider::GetSingleEmptyDeviceAdapter(
72 const BluetoothAdapterFactory::AdapterCallback& callback) {
73 adapter_ = new NiceMock<MockBluetoothAdapter>();
74
75 ON_CALL(*adapter_, StartDiscoverySession(_, _))
76 .WillByDefault(Invoke(
77 this,
78 &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession));
79
80 BluetoothAdapter::ConstDeviceList devices;
81 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.
82 devices.push_back(empty_device_.get());
83 ON_CALL(*adapter_, GetDevices()).WillByDefault(Return(devices));
84
85 callback.Run(adapter_);
86 }
87 void LayoutTestBluetoothAdapterProvider::SetupEmptyDevice() {
88 empty_device_.reset(new NiceMock<MockBluetoothDevice>(
89 adapter_.get(), 0x1F00 /* Bluetooth Class */, "Empty Mock Device name",
90 "Empty Mock Device instanceID", true, /* Paired */
91 true /* Connected */));
92
93 ON_CALL(*empty_device_, GetVendorIDSource())
94 .WillByDefault(Return(BluetoothDevice::VENDOR_ID_BLUETOOTH));
95 ON_CALL(*empty_device_, GetVendorID()).WillByDefault(Return(0xFFFF));
96 ON_CALL(*empty_device_, GetProductID()).WillByDefault(Return(1));
97 ON_CALL(*empty_device_, GetDeviceID()).WillByDefault(Return(2));
98
99 BluetoothDevice::UUIDList list;
100 list.push_back(BluetoothUUID("1800"));
101 list.push_back(BluetoothUUID("1801"));
102 ON_CALL(*empty_device_, GetUUIDs()).WillByDefault(Return(list));
103 }
104
105 void LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession(
106 const BluetoothAdapter::DiscoverySessionCallback& callback,
107 const BluetoothAdapter::ErrorCallback& error_callback) {
108 NiceMock<MockBluetoothDiscoverySession>* discovery_session =
109 new NiceMock<MockBluetoothDiscoverySession>();
110
111 ON_CALL(*discovery_session, Stop(_, _))
112 .WillByDefault(Invoke(
113 &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySessionStop));
114
115 callback.Run(scoped_ptr<BluetoothDiscoverySession>(discovery_session));
116 }
117
118 void LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySessionStop(
119 const base::Closure& callback,
120 const base::Closure& error_callback) {
121 callback.Run();
122 }
123
124 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698