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

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: Changed new'ed variables to scoped_ptr. 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 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(
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(adapter->GetMockDevices()));
68
69 callback.Run(adapter.Pass());
70 }
71
72 void LayoutTestBluetoothAdapterProvider::GetSingleEmptyDeviceAdapter(
73 const BluetoothAdapterFactory::AdapterCallback& callback) {
74 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(
75 new NiceMock<MockBluetoothAdapter>());
76
77 ON_CALL(*adapter, StartDiscoverySession(_, _))
78 .WillByDefault(Invoke(
79 this,
80 &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession));
81
82 adapter->AddMockDevice(GetEmptyDevice(adapter.get()));
83
84 ON_CALL(*adapter, GetDevices())
85 .WillByDefault(Return(adapter->GetMockDevices()));
86
87 callback.Run(adapter.Pass());
88 }
89
90 scoped_ptr<NiceMock<MockBluetoothDevice>>
91 LayoutTestBluetoothAdapterProvider::GetEmptyDevice(
92 MockBluetoothAdapter* adapter) {
93 scoped_ptr<NiceMock<MockBluetoothDevice>> empty_device(
94 new NiceMock<MockBluetoothDevice>(
95 adapter, 0x1F00 /* Bluetooth Class */, "Empty Mock Device name",
96 "Empty Mock Device instanceID", true /* Paired */,
97 true /* Connected */));
98
99 ON_CALL(*empty_device, GetVendorIDSource())
100 .WillByDefault(Return(BluetoothDevice::VENDOR_ID_BLUETOOTH));
101 ON_CALL(*empty_device, GetVendorID()).WillByDefault(Return(0xFFFF));
102 ON_CALL(*empty_device, GetProductID()).WillByDefault(Return(1));
103 ON_CALL(*empty_device, GetDeviceID()).WillByDefault(Return(2));
104
105 BluetoothDevice::UUIDList list;
106 list.push_back(BluetoothUUID("1800"));
107 list.push_back(BluetoothUUID("1801"));
108 ON_CALL(*empty_device, GetUUIDs()).WillByDefault(Return(list));
109 return empty_device.Pass();
110 }
111
112 void LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession(
113 const BluetoothAdapter::DiscoverySessionCallback& callback,
114 const BluetoothAdapter::ErrorCallback& error_callback) {
115 scoped_ptr<NiceMock<MockBluetoothDiscoverySession>> discovery_session(
116 new NiceMock<MockBluetoothDiscoverySession>());
117
118 ON_CALL(*discovery_session, Stop(_, _))
119 .WillByDefault(Invoke(
120 &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySessionStop));
121
122 callback.Run(discovery_session.Pass());
123 }
124
125 void LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySessionStop(
126 const base::Closure& callback,
127 const base::Closure& error_callback) {
128 callback.Run();
129 }
130
131 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698