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

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: Remove member variables. 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 NiceMock<MockBluetoothAdapter>* adapter =
Jeffrey Yasskin 2015/05/13 19:40:50 You should almost always catch a new'ed pointer in
ortuno 2015/05/13 20:59:31 Done.
59 new NiceMock<MockBluetoothAdapter>();
60
61 ON_CALL(*adapter, StartDiscoverySession(_, _))
62 .WillByDefault(Invoke(
63 this,
64 &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession));
65
66 ON_CALL(*adapter, GetDevices())
67 .WillByDefault(Return(BluetoothAdapter::ConstDeviceList()));
68
69 callback.Run(adapter);
70 }
71
72 void LayoutTestBluetoothAdapterProvider::GetSingleEmptyDeviceAdapter(
73 const BluetoothAdapterFactory::AdapterCallback& callback) {
74 NiceMock<MockBluetoothAdapter>* adapter =
75 new NiceMock<MockBluetoothAdapter>();
76
77 ON_CALL(*adapter, StartDiscoverySession(_, _))
78 .WillByDefault(Invoke(
79 this,
80 &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession));
81
82 std::vector<MockBluetoothDevice*> devices;
Jeffrey Yasskin 2015/05/13 19:40:51 Similarly here, the vector<> should hold scoped_pt
ortuno 2015/05/13 20:59:30 Changed MockBluetoothAdapter to accept a single de
83 devices.push_back(GetEmptyDevice(adapter));
84 adapter->SetMockDevices(devices);
Jeffrey Yasskin 2015/05/13 19:40:51 I'd probably have this accept one device at a time
ortuno 2015/05/13 20:59:31 Done.
85 ON_CALL(*adapter, GetDevices())
86 .WillByDefault(Return(adapter->GetMockDevices()));
87
88 callback.Run(adapter);
89 }
90
91 NiceMock<MockBluetoothDevice>*
Jeffrey Yasskin 2015/05/13 19:40:51 Return a scoped_ptr<NiceMock<MockBluetoothDevice>>
ortuno 2015/05/13 20:59:30 Done.
92 LayoutTestBluetoothAdapterProvider::GetEmptyDevice(
93 MockBluetoothAdapter* adapter) {
94 NiceMock<MockBluetoothDevice>* empty_device =
95 new NiceMock<MockBluetoothDevice>(
96 adapter, 0x1F00 /* Bluetooth Class */, "Empty Mock Device name",
97 "Empty Mock Device instanceID", true, /* Paired */
98 true /* Connected */);
99
100 ON_CALL(*empty_device, GetVendorIDSource())
101 .WillByDefault(Return(BluetoothDevice::VENDOR_ID_BLUETOOTH));
102 ON_CALL(*empty_device, GetVendorID()).WillByDefault(Return(0xFFFF));
103 ON_CALL(*empty_device, GetProductID()).WillByDefault(Return(1));
104 ON_CALL(*empty_device, GetDeviceID()).WillByDefault(Return(2));
105
106 BluetoothDevice::UUIDList list;
107 list.push_back(BluetoothUUID("1800"));
108 list.push_back(BluetoothUUID("1801"));
109 ON_CALL(*empty_device, GetUUIDs()).WillByDefault(Return(list));
110 return empty_device;
111 }
112
113 void LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession(
114 const BluetoothAdapter::DiscoverySessionCallback& callback,
115 const BluetoothAdapter::ErrorCallback& error_callback) {
116 NiceMock<MockBluetoothDiscoverySession>* discovery_session =
117 new NiceMock<MockBluetoothDiscoverySession>();
118
119 ON_CALL(*discovery_session, Stop(_, _))
120 .WillByDefault(Invoke(
121 &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySessionStop));
122
123 callback.Run(scoped_ptr<BluetoothDiscoverySession>(discovery_session));
124 }
125
126 void LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySessionStop(
127 const base::Closure& callback,
128 const base::Closure& error_callback) {
129 callback.Run();
130 }
131
132 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698