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

Side by Side Diff: content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc

Issue 1230023010: bluetooth: Refactor MultiDeviceAdapter, ScanFilterCheckingAdapter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-tests-small-1
Patch Set: Fix adapter name. Created 5 years, 5 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
« no previous file with comments | « content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/shell/browser/layout_test/layout_test_bluetooth_adapter_provid er.h" 5 #include "content/shell/browser/layout_test/layout_test_bluetooth_adapter_provid er.h"
6 6
7 #include "device/bluetooth/bluetooth_adapter.h" 7 #include "device/bluetooth/bluetooth_adapter.h"
8 #include "device/bluetooth/bluetooth_device.h" 8 #include "device/bluetooth/bluetooth_device.h"
9 #include "device/bluetooth/bluetooth_discovery_session.h" 9 #include "device/bluetooth/bluetooth_discovery_session.h"
10 #include "device/bluetooth/bluetooth_uuid.h" 10 #include "device/bluetooth/bluetooth_uuid.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 scoped_refptr<BluetoothAdapter> 91 scoped_refptr<BluetoothAdapter>
92 LayoutTestBluetoothAdapterProvider::GetBluetoothAdapter( 92 LayoutTestBluetoothAdapterProvider::GetBluetoothAdapter(
93 const std::string& fake_adapter_name) { 93 const std::string& fake_adapter_name) {
94 // Old Adapters 94 // Old Adapters
95 if (fake_adapter_name == "SingleEmptyDeviceAdapter") 95 if (fake_adapter_name == "SingleEmptyDeviceAdapter")
96 return GetSingleEmptyDeviceAdapter(); 96 return GetSingleEmptyDeviceAdapter();
97 else if (fake_adapter_name == "ConnectableDeviceAdapter") 97 else if (fake_adapter_name == "ConnectableDeviceAdapter")
98 return GetConnectableDeviceAdapter(); 98 return GetConnectableDeviceAdapter();
99 else if (fake_adapter_name == "UnconnectableDeviceAdapter") 99 else if (fake_adapter_name == "UnconnectableDeviceAdapter")
100 return GetUnconnectableDeviceAdapter(); 100 return GetUnconnectableDeviceAdapter();
101 else if (fake_adapter_name == "ScanFilterCheckingAdapter")
102 return GetScanFilterCheckingAdapter();
103 else if (fake_adapter_name == "MultiDeviceAdapter")
104 return GetMultiDeviceAdapter();
105 // New adapters 101 // New adapters
106 else if (fake_adapter_name == "BaseAdapter") 102 else if (fake_adapter_name == "BaseAdapter")
107 return GetBaseAdapter(); 103 return GetBaseAdapter();
104 else if (fake_adapter_name == "ScanFilterCheckingAdapter")
105 return GetScanFilterCheckingAdapter();
108 else if (fake_adapter_name == "EmptyAdapter") 106 else if (fake_adapter_name == "EmptyAdapter")
109 return GetEmptyAdapter(); 107 return GetEmptyAdapter();
110 else if (fake_adapter_name == "FailStartDiscoveryAdapter") 108 else if (fake_adapter_name == "FailStartDiscoveryAdapter")
111 return GetFailStartDiscoveryAdapter(); 109 return GetFailStartDiscoveryAdapter();
110 // TODO(ortuno): Remove MultiDeviceAdapter in follow up patch.
111 else if (fake_adapter_name == "MultiDeviceAdapter" ||
112 fake_adapter_name == "GlucoseHeartRateAdapter")
113 return GetGlucoseHeartRateAdapter();
112 else if (fake_adapter_name == "") 114 else if (fake_adapter_name == "")
113 return NULL; 115 return NULL;
114 116
115 NOTREACHED() << fake_adapter_name; 117 NOTREACHED() << fake_adapter_name;
116 return NULL; 118 return NULL;
117 } 119 }
118 120
119 // static 121 // static
120 scoped_refptr<NiceMock<MockBluetoothAdapter>> 122 scoped_refptr<NiceMock<MockBluetoothAdapter>>
121 LayoutTestBluetoothAdapterProvider::GetBaseAdapter() { 123 LayoutTestBluetoothAdapterProvider::GetBaseAdapter() {
122 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter( 124 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(
123 new NiceMock<MockBluetoothAdapter>()); 125 new NiceMock<MockBluetoothAdapter>());
124 126
125 // Using Invoke allows the adapter returned from this method to be futher 127 // Using Invoke allows the adapter returned from this method to be futher
126 // modified and have devices added to it. The call to ::GetDevices will 128 // modified and have devices added to it. The call to ::GetDevices will
127 // invoke ::GetConstMockDevices, returning all devices added up to that time. 129 // invoke ::GetConstMockDevices, returning all devices added up to that time.
128 ON_CALL(*adapter, GetDevices()) 130 ON_CALL(*adapter, GetDevices())
129 .WillByDefault( 131 .WillByDefault(
130 Invoke(adapter.get(), &MockBluetoothAdapter::GetConstMockDevices)); 132 Invoke(adapter.get(), &MockBluetoothAdapter::GetConstMockDevices));
131 133
132 // The call to ::GetDevice will invoke GetMockDevice which returns a device 134 // The call to ::GetDevice will invoke GetMockDevice which returns a device
133 // matching the address provided if the device was added to the mock. 135 // matching the address provided if the device was added to the mock.
134 ON_CALL(*adapter, GetDevice(_)).WillByDefault(GetMockDevice(adapter.get())); 136 ON_CALL(*adapter, GetDevice(_)).WillByDefault(GetMockDevice(adapter.get()));
135 137
136 return adapter.Pass(); 138 return adapter.Pass();
137 } 139 }
138 140
139 // static 141 // static
140 scoped_refptr<NiceMock<MockBluetoothAdapter>> 142 scoped_refptr<NiceMock<MockBluetoothAdapter>>
143 LayoutTestBluetoothAdapterProvider::GetScanFilterCheckingAdapter() {
144 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(GetBaseAdapter());
145
146 // This fails the test with an error message listing actual and expected UUIDs
147 // if StartDiscoverySessionWithFilter() is called with the wrong argument.
148 EXPECT_CALL(
149 *adapter,
150 StartDiscoverySessionWithFilterRaw(
151 ResultOf(&GetUUIDs, ElementsAre(BluetoothUUID(kGlucoseServiceUUID),
152 BluetoothUUID(kHeartRateServiceUUID),
153 BluetoothUUID(kBatteryServiceUUID))),
154 _, _))
155 .WillRepeatedly(RunCallbackWithResult<1 /* success_callback */>(
156 []() { return GetDiscoverySession(); }));
157
158 // Any unexpected call results in the failure callback.
159 ON_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _))
160 .WillByDefault(RunCallback<2 /* error_callback */>());
161
162 // We need to add a device otherwise requestDevice would reject.
163 adapter->AddMockDevice(GetBatteryDevice(adapter.get()));
164
165 return adapter.Pass();
166 }
167
168 // static
169 scoped_refptr<NiceMock<MockBluetoothAdapter>>
141 LayoutTestBluetoothAdapterProvider::GetFailStartDiscoveryAdapter() { 170 LayoutTestBluetoothAdapterProvider::GetFailStartDiscoveryAdapter() {
142 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(GetBaseAdapter()); 171 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(GetBaseAdapter());
143 172
144 ON_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _)) 173 ON_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _))
145 .WillByDefault(RunCallback<2 /* error_callback */>()); 174 .WillByDefault(RunCallback<2 /* error_callback */>());
146 175
147 return adapter.Pass(); 176 return adapter.Pass();
148 } 177 }
149 178
150 // static 179 // static
(...skipping 13 matching lines...) Expand all
164 LayoutTestBluetoothAdapterProvider::GetDiscoverySession() { 193 LayoutTestBluetoothAdapterProvider::GetDiscoverySession() {
165 scoped_ptr<NiceMock<MockBluetoothDiscoverySession>> discovery_session( 194 scoped_ptr<NiceMock<MockBluetoothDiscoverySession>> discovery_session(
166 new NiceMock<MockBluetoothDiscoverySession>()); 195 new NiceMock<MockBluetoothDiscoverySession>());
167 196
168 ON_CALL(*discovery_session, Stop(_, _)) 197 ON_CALL(*discovery_session, Stop(_, _))
169 .WillByDefault(RunCallback<0 /* success_callback */>()); 198 .WillByDefault(RunCallback<0 /* success_callback */>());
170 199
171 return discovery_session.Pass(); 200 return discovery_session.Pass();
172 } 201 }
173 202
174 // The functions after this haven't been updated to the new design yet.
175
176 // static 203 // static
177 scoped_refptr<NiceMock<MockBluetoothAdapter>> 204 scoped_refptr<NiceMock<MockBluetoothAdapter>>
178 LayoutTestBluetoothAdapterProvider::GetScanFilterCheckingAdapter() { 205 LayoutTestBluetoothAdapterProvider::GetGlucoseHeartRateAdapter() {
179 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter( 206 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(GetEmptyAdapter());
180 new NiceMock<MockBluetoothAdapter>());
181 207
182 // This fails the test with an error message listing actual and expected UUIDs 208 adapter->AddMockDevice(GetHeartRateDevice(adapter.get()));
183 // if StartDiscoverySessionWithFilter() is called with the wrong argument. 209 adapter->AddMockDevice(GetGlucoseDevice(adapter.get()));
184 EXPECT_CALL(
185 *adapter,
186 StartDiscoverySessionWithFilterRaw(
187 ResultOf(&GetUUIDs, ElementsAre(BluetoothUUID(kGlucoseServiceUUID),
188 BluetoothUUID(kHeartRateServiceUUID),
189 BluetoothUUID(kBatteryServiceUUID))),
190 _, _))
191 .WillRepeatedly(RunCallbackWithResult<1 /* success_callback */>(
192 []() { return GetDiscoverySession(); }));
193
194 // Any unexpected call results in the failure callback.
195 ON_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _))
196 .WillByDefault(RunCallback<2 /* failure_callback */>());
197
198 scoped_ptr<NiceMock<MockBluetoothDevice>> battery_device =
199 GetEmptyDevice(adapter.get(), "Battery Device");
200 BluetoothDevice::UUIDList battery_uuid_list;
201 battery_uuid_list.push_back(BluetoothUUID(kBatteryServiceUUID));
202 ON_CALL(*battery_device, GetUUIDs()).WillByDefault(Return(battery_uuid_list));
203 adapter->AddMockDevice(battery_device.Pass());
204
205 // This adapter isn't modified further, so we just return a hard-coded list.
206 ON_CALL(*adapter, GetDevices())
207 .WillByDefault(Return(adapter->GetConstMockDevices()));
208 210
209 return adapter.Pass(); 211 return adapter.Pass();
210 } 212 }
211 213
212 // static 214 // static
215 scoped_ptr<NiceMock<MockBluetoothDevice>>
216 LayoutTestBluetoothAdapterProvider::GetBaseDevice(
217 MockBluetoothAdapter* adapter,
218 const std::string& device_name,
219 device::BluetoothDevice::UUIDList uuids,
220 const std::string& address) {
221 scoped_ptr<NiceMock<MockBluetoothDevice>> device(
222 new NiceMock<MockBluetoothDevice>(adapter, 0x1F00 /* Bluetooth class */,
223 device_name, address, true /* paired */,
224 true /* connected */));
225
226 ON_CALL(*device, GetUUIDs()).WillByDefault(Return(uuids));
227
228 // Using Invoke allows the device returned from this method to be futher
229 // modified and have more services added to it. The call to ::GetGattServices
230 // will invoke ::GetMockServices, returning all services added up to that
231 // time.
232 ON_CALL(*device, GetGattServices())
233 .WillByDefault(
234 Invoke(device.get(), &MockBluetoothDevice::GetMockServices));
235
236 // The call to BluetoothDevice::GetGattService will invoke ::GetMockService
237 // which returns a service matching the identifier provided if the service
238 // was added to the mock.
239 ON_CALL(*device, GetGattService(_))
240 .WillByDefault(
241 Invoke(device.get(), &MockBluetoothDevice::GetMockService));
242
243 ON_CALL(*device, GetVendorIDSource())
244 .WillByDefault(Return(BluetoothDevice::VENDOR_ID_BLUETOOTH));
245 ON_CALL(*device, GetVendorID()).WillByDefault(Return(0xFFFF));
246 ON_CALL(*device, GetProductID()).WillByDefault(Return(1));
247 ON_CALL(*device, GetDeviceID()).WillByDefault(Return(2));
248
249 return device.Pass();
250 }
251
252 // static
253 scoped_ptr<testing::NiceMock<device::MockBluetoothDevice>>
254 LayoutTestBluetoothAdapterProvider::GetBatteryDevice(
255 MockBluetoothAdapter* adapter) {
256 BluetoothDevice::UUIDList uuids;
257 uuids.push_back(BluetoothUUID(kGenericAccessServiceUUID));
258 uuids.push_back(BluetoothUUID(kBatteryServiceUUID));
259
260 return GetBaseDevice(adapter, "Battery Device", uuids, "00:00:00:00:01");
261 }
262
263 // static
264 scoped_ptr<testing::NiceMock<device::MockBluetoothDevice>>
265 LayoutTestBluetoothAdapterProvider::GetGlucoseDevice(
266 MockBluetoothAdapter* adapter) {
267 BluetoothDevice::UUIDList uuids;
268 uuids.push_back(BluetoothUUID(kGenericAccessServiceUUID));
269 uuids.push_back(BluetoothUUID(kGlucoseServiceUUID));
270
271 return GetBaseDevice(adapter, "Glucose Device", uuids, "00:00:00:00:02");
272 }
273
274 // static
275 scoped_ptr<testing::NiceMock<device::MockBluetoothDevice>>
276 LayoutTestBluetoothAdapterProvider::GetHeartRateDevice(
277 MockBluetoothAdapter* adapter) {
278 BluetoothDevice::UUIDList uuids;
279 uuids.push_back(BluetoothUUID(kGenericAccessServiceUUID));
280 uuids.push_back(BluetoothUUID(kHeartRateServiceUUID));
281
282 return GetBaseDevice(adapter, "Heart Rate Device", uuids, "00:00:00:00:03");
283 }
284
285 // The functions after this haven't been updated to the new design yet.
286
287 // static
213 scoped_refptr<NiceMock<MockBluetoothAdapter>> 288 scoped_refptr<NiceMock<MockBluetoothAdapter>>
214 LayoutTestBluetoothAdapterProvider::GetSingleEmptyDeviceAdapter() { 289 LayoutTestBluetoothAdapterProvider::GetSingleEmptyDeviceAdapter() {
215 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(GetEmptyAdapter()); 290 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(GetEmptyAdapter());
216 291
217 adapter->AddMockDevice(GetEmptyDevice(adapter.get())); 292 adapter->AddMockDevice(GetEmptyDevice(adapter.get()));
218 293
219 return adapter.Pass(); 294 return adapter.Pass();
220 } 295 }
221
222 // static
223 scoped_refptr<NiceMock<MockBluetoothAdapter>>
224 LayoutTestBluetoothAdapterProvider::GetMultiDeviceAdapter() {
225 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(GetEmptyAdapter());
226
227 scoped_ptr<NiceMock<MockBluetoothDevice>> heart_rate_device =
228 GetEmptyDevice(adapter.get(), "Heart Rate Device");
229 BluetoothDevice::UUIDList heart_rate_uuid_list;
230 heart_rate_uuid_list.push_back(BluetoothUUID(kHeartRateServiceUUID));
231 heart_rate_uuid_list.push_back(BluetoothUUID(kGenericAccessServiceUUID));
232 heart_rate_uuid_list.push_back(BluetoothUUID(kGenericAttributeServiceUUID));
233 ON_CALL(*heart_rate_device, GetUUIDs())
234 .WillByDefault(Return(heart_rate_uuid_list));
235 adapter->AddMockDevice(heart_rate_device.Pass());
236
237 scoped_ptr<NiceMock<MockBluetoothDevice>> glucose_device =
238 GetEmptyDevice(adapter.get(), "Glucose Device");
239 BluetoothDevice::UUIDList glucose_uuid_list;
240 glucose_uuid_list.push_back(BluetoothUUID(kGlucoseServiceUUID));
241 glucose_uuid_list.push_back(BluetoothUUID(kGenericAccessServiceUUID));
242 glucose_uuid_list.push_back(BluetoothUUID(kGenericAttributeServiceUUID));
243 ON_CALL(*glucose_device, GetUUIDs()).WillByDefault(Return(glucose_uuid_list));
244 adapter->AddMockDevice(glucose_device.Pass());
245
246 return adapter.Pass();
247 }
248 296
249 // static 297 // static
250 scoped_refptr<NiceMock<MockBluetoothAdapter>> 298 scoped_refptr<NiceMock<MockBluetoothAdapter>>
251 LayoutTestBluetoothAdapterProvider::GetConnectableDeviceAdapter() { 299 LayoutTestBluetoothAdapterProvider::GetConnectableDeviceAdapter() {
252 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(GetEmptyAdapter()); 300 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(GetEmptyAdapter());
253 301
254 adapter->AddMockDevice(GetConnectableDevice(adapter.get())); 302 adapter->AddMockDevice(GetConnectableDevice(adapter.get()));
255 303
256 return adapter.Pass(); 304 return adapter.Pass();
257 } 305 }
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 scoped_ptr<NiceMock<MockBluetoothGattCharacteristic>> 441 scoped_ptr<NiceMock<MockBluetoothGattCharacteristic>>
394 LayoutTestBluetoothAdapterProvider::GetGattCharacteristic( 442 LayoutTestBluetoothAdapterProvider::GetGattCharacteristic(
395 MockBluetoothGattService* service, 443 MockBluetoothGattService* service,
396 const std::string& uuid) { 444 const std::string& uuid) {
397 return make_scoped_ptr(new NiceMock<MockBluetoothGattCharacteristic>( 445 return make_scoped_ptr(new NiceMock<MockBluetoothGattCharacteristic>(
398 service, uuid /* identifier */, BluetoothUUID(uuid), false /* is_local */, 446 service, uuid /* identifier */, BluetoothUUID(uuid), false /* is_local */,
399 NULL /* properties */, NULL /* permissions */)); 447 NULL /* properties */, NULL /* permissions */));
400 } 448 }
401 449
402 } // namespace content 450 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698