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

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: Fix API tests failing 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 // static
31 scoped_refptr<BluetoothAdapter>
32 LayoutTestBluetoothAdapterProvider::GetBluetoothAdapter(
33 const std::string& fake_adapter_name) {
34 // TODO(ortuno): Remove RejectRequestDevice once LayoutTests are modified
35 if (fake_adapter_name == "RejectRequestDevice_NotFoundError" ||
36 fake_adapter_name == "EmptyAdapter") {
37 return GetEmptyAdapter();
38 }
39 // TODO(ortuno): Remove "Single Empty Device" once LayoutTests are modified
40 else if (fake_adapter_name == "Single Empty Device" ||
41 fake_adapter_name == "SingleEmptyDeviceAdapter") {
42 return GetSingleEmptyDeviceAdapter();
43 } else if (fake_adapter_name == "") {
44 return NULL;
45 }
46 NOTREACHED();
47 return NULL;
48 }
49
50 // static
51 scoped_refptr<NiceMock<MockBluetoothAdapter>>
52 LayoutTestBluetoothAdapterProvider::GetEmptyAdapter() {
53 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(
54 new NiceMock<MockBluetoothAdapter>());
55
56 ON_CALL(*adapter, StartDiscoverySession(_, _))
57 .WillByDefault(Invoke(
58 &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession));
59
60 ON_CALL(*adapter, GetDevices())
61 .WillByDefault(Return(adapter->GetConstMockDevices()));
62
63 return adapter.Pass();
64 }
65
66 // static
67 scoped_refptr<NiceMock<MockBluetoothAdapter>>
68 LayoutTestBluetoothAdapterProvider::GetSingleEmptyDeviceAdapter() {
69 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(
70 new NiceMock<MockBluetoothAdapter>());
71
72 ON_CALL(*adapter, StartDiscoverySession(_, _))
73 .WillByDefault(Invoke(
74 &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession));
75
76 adapter->AddMockDevice(GetEmptyDevice(adapter.get()));
77
78 ON_CALL(*adapter, GetDevices())
79 .WillByDefault(Return(adapter->GetConstMockDevices()));
80
81 return adapter.Pass();
82 }
83
84 // static
85 scoped_ptr<NiceMock<MockBluetoothDevice>>
86 LayoutTestBluetoothAdapterProvider::GetEmptyDevice(
87 MockBluetoothAdapter* adapter) {
88 scoped_ptr<NiceMock<MockBluetoothDevice>> empty_device(
89 new NiceMock<MockBluetoothDevice>(
90 adapter, 0x1F00 /* Bluetooth Class */, "Empty Mock Device name",
91 "Empty Mock Device instanceID", true /* Paired */,
92 true /* Connected */));
93
94 ON_CALL(*empty_device, GetVendorIDSource())
95 .WillByDefault(Return(BluetoothDevice::VENDOR_ID_BLUETOOTH));
96 ON_CALL(*empty_device, GetVendorID()).WillByDefault(Return(0xFFFF));
97 ON_CALL(*empty_device, GetProductID()).WillByDefault(Return(1));
98 ON_CALL(*empty_device, GetDeviceID()).WillByDefault(Return(2));
99
100 BluetoothDevice::UUIDList list;
101 list.push_back(BluetoothUUID("1800"));
102 list.push_back(BluetoothUUID("1801"));
103 ON_CALL(*empty_device, GetUUIDs()).WillByDefault(Return(list));
104 return empty_device.Pass();
105 }
106
107 // static
108 void LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession(
109 const BluetoothAdapter::DiscoverySessionCallback& callback,
110 const BluetoothAdapter::ErrorCallback& error_callback) {
111 scoped_ptr<NiceMock<MockBluetoothDiscoverySession>> discovery_session(
112 new NiceMock<MockBluetoothDiscoverySession>());
113
114 ON_CALL(*discovery_session, Stop(_, _))
115 .WillByDefault(Invoke(
116 &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySessionStop));
117
118 callback.Run(discovery_session.Pass());
119 }
120
121 // static
122 void LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySessionStop(
123 const base::Closure& callback,
124 const base::Closure& error_callback) {
125 callback.Run();
126 }
127
128 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698