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

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

Issue 1247553002: bluetooth: Implement FailingConnectionsAdapter. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-tests-small-5
Patch Set: 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
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 24 matching lines...) Expand all
35 using testing::WithArgs; 35 using testing::WithArgs;
36 using testing::_; 36 using testing::_;
37 37
38 namespace { 38 namespace {
39 // Bluetooth UUIDs suitable to pass to BluetoothUUID(). 39 // Bluetooth UUIDs suitable to pass to BluetoothUUID().
40 const char kBatteryServiceUUID[] = "180f"; 40 const char kBatteryServiceUUID[] = "180f";
41 const char kGenericAccessServiceUUID[] = "1800"; 41 const char kGenericAccessServiceUUID[] = "1800";
42 const char kGenericAttributeServiceUUID[] = "1801"; 42 const char kGenericAttributeServiceUUID[] = "1801";
43 const char kGlucoseServiceUUID[] = "1808"; 43 const char kGlucoseServiceUUID[] = "1808";
44 const char kHeartRateServiceUUID[] = "180d"; 44 const char kHeartRateServiceUUID[] = "180d";
45 // UUID prefix for devices that return connection errors.
46 const char kPrefixConnectionErrorUUID[] = "0000000";
47 // Base Errors UUID. It's used so that we can filter devices and characteristics
48 // that return errors. See UnconnectableDevice and ErrorsDevice.
49 const char kBaseErrorUUID[] = "-97e5-4cd7-b9f1-f5a427670c59";
50 const char kAddressPrefix[] = "00:00:00:00:0";
45 51
46 // Invokes Run() on the k-th argument of the function with no arguments. 52 // Invokes Run() on the k-th argument of the function with no arguments.
47 ACTION_TEMPLATE(RunCallback, 53 ACTION_TEMPLATE(RunCallback,
48 HAS_1_TEMPLATE_PARAMS(int, k), 54 HAS_1_TEMPLATE_PARAMS(int, k),
49 AND_0_VALUE_PARAMS()) { 55 AND_0_VALUE_PARAMS()) {
50 return ::testing::get<k>(args).Run(); 56 return ::testing::get<k>(args).Run();
51 } 57 }
52 58
53 // Invokes Run() on the k-th argument of the function with 1 argument. 59 // Invokes Run() on the k-th argument of the function with 1 argument.
54 ACTION_TEMPLATE(RunCallback, 60 ACTION_TEMPLATE(RunCallback,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 else if (fake_adapter_name == "EmptyAdapter") 112 else if (fake_adapter_name == "EmptyAdapter")
107 return GetEmptyAdapter(); 113 return GetEmptyAdapter();
108 else if (fake_adapter_name == "FailStartDiscoveryAdapter") 114 else if (fake_adapter_name == "FailStartDiscoveryAdapter")
109 return GetFailStartDiscoveryAdapter(); 115 return GetFailStartDiscoveryAdapter();
110 else if (fake_adapter_name == "GlucoseHeartRateAdapter") 116 else if (fake_adapter_name == "GlucoseHeartRateAdapter")
111 return GetGlucoseHeartRateAdapter(); 117 return GetGlucoseHeartRateAdapter();
112 else if (fake_adapter_name == "MissingServiceGenericAccessAdapter") 118 else if (fake_adapter_name == "MissingServiceGenericAccessAdapter")
113 return GetMissingServiceGenericAccessAdapter(); 119 return GetMissingServiceGenericAccessAdapter();
114 else if (fake_adapter_name == "MissingCharacteristicGenericAccessAdapter") 120 else if (fake_adapter_name == "MissingCharacteristicGenericAccessAdapter")
115 return GetMissingCharacteristicGenericAccessAdapter(); 121 return GetMissingCharacteristicGenericAccessAdapter();
122 else if (fake_adapter_name == "FailingConnectionsAdapter")
123 return GetFailingConnectionsAdapter();
116 else if (fake_adapter_name == "") 124 else if (fake_adapter_name == "")
117 return NULL; 125 return NULL;
118 126
119 NOTREACHED() << fake_adapter_name; 127 NOTREACHED() << fake_adapter_name;
120 return NULL; 128 return NULL;
121 } 129 }
122 130
123 // static 131 // static
124 scoped_refptr<NiceMock<MockBluetoothAdapter>> 132 scoped_refptr<NiceMock<MockBluetoothAdapter>>
125 LayoutTestBluetoothAdapterProvider::GetBaseAdapter() { 133 LayoutTestBluetoothAdapterProvider::GetBaseAdapter() {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 245
238 // Intentionally NOT adding a characteristic to generic_access service. 246 // Intentionally NOT adding a characteristic to generic_access service.
239 247
240 device->AddMockService(generic_access.Pass()); 248 device->AddMockService(generic_access.Pass());
241 249
242 adapter->AddMockDevice(device.Pass()); 250 adapter->AddMockDevice(device.Pass());
243 251
244 return adapter.Pass(); 252 return adapter.Pass();
245 } 253 }
246 254
255 scoped_refptr<NiceMock<MockBluetoothAdapter>>
256 LayoutTestBluetoothAdapterProvider::GetFailingConnectionsAdapter() {
257 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(GetEmptyAdapter());
258
259 for (int error = BluetoothDevice::ERROR_UNKNOWN;
ortuno 2015/07/21 21:32:43 Is this a good way of doing it? I've heard that yo
Jeffrey Yasskin 2015/07/21 23:08:58 This is fine. If the relevant enum had a COUNT mem
260 error <= BluetoothDevice::ERROR_UNSUPPORTED_DEVICE; error++) {
261 adapter->AddMockDevice(GetUnconnectableDevice(
262 adapter.get(), static_cast<BluetoothDevice::ConnectErrorCode>(error)));
263 }
264 return adapter.Pass();
265 }
266
247 // static 267 // static
248 scoped_ptr<NiceMock<MockBluetoothDevice>> 268 scoped_ptr<NiceMock<MockBluetoothDevice>>
249 LayoutTestBluetoothAdapterProvider::GetBaseDevice( 269 LayoutTestBluetoothAdapterProvider::GetBaseDevice(
250 MockBluetoothAdapter* adapter, 270 MockBluetoothAdapter* adapter,
251 const std::string& device_name, 271 const std::string& device_name,
252 device::BluetoothDevice::UUIDList uuids, 272 device::BluetoothDevice::UUIDList uuids,
253 const std::string& address) { 273 const std::string& address) {
254 scoped_ptr<NiceMock<MockBluetoothDevice>> device( 274 scoped_ptr<NiceMock<MockBluetoothDevice>> device(
255 new NiceMock<MockBluetoothDevice>(adapter, 0x1F00 /* Bluetooth class */, 275 new NiceMock<MockBluetoothDevice>(adapter, 0x1F00 /* Bluetooth class */,
256 device_name, address, true /* paired */, 276 device_name, address, true /* paired */,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 RunCallbackWithResult<0 /* success_callback */>([device_ptr]() { 351 RunCallbackWithResult<0 /* success_callback */>([device_ptr]() {
332 return make_scoped_ptr(new NiceMock<MockBluetoothGattConnection>( 352 return make_scoped_ptr(new NiceMock<MockBluetoothGattConnection>(
333 device_ptr->GetAddress())); 353 device_ptr->GetAddress()));
334 })); 354 }));
335 355
336 return device.Pass(); 356 return device.Pass();
337 } 357 }
338 358
339 // static 359 // static
340 scoped_ptr<testing::NiceMock<device::MockBluetoothDevice>> 360 scoped_ptr<testing::NiceMock<device::MockBluetoothDevice>>
361 LayoutTestBluetoothAdapterProvider::GetUnconnectableDevice(
362 MockBluetoothAdapter* adapter,
363 BluetoothDevice::ConnectErrorCode error_code,
364 const std::string& device_name) {
365 BluetoothDevice::UUIDList uuids;
366 uuids.push_back(BluetoothUUID(kPrefixConnectionErrorUUID +
Jeffrey Yasskin 2015/07/21 23:08:58 I think this should use StringPrintf("%08x-97e5-4c
ortuno 2015/07/22 01:06:20 Done.
367 std::to_string(error_code) + kBaseErrorUUID));
368
369 scoped_ptr<testing::NiceMock<MockBluetoothDevice>> device(
370 GetBaseDevice(adapter, device_name, uuids,
371 kAddressPrefix + std::to_string(error_code)));
Jeffrey Yasskin 2015/07/21 23:08:58 Similarly, a format string instead of string conca
ortuno 2015/07/22 01:06:20 Done.
372
373 ON_CALL(*device, CreateGattConnection(_, _))
374 .WillByDefault(RunCallback<1 /* error_callback */>(error_code));
375
376 return device.Pass();
377 }
378
379 // static
380 scoped_ptr<testing::NiceMock<device::MockBluetoothDevice>>
341 LayoutTestBluetoothAdapterProvider::GetGenericAccessDevice( 381 LayoutTestBluetoothAdapterProvider::GetGenericAccessDevice(
342 MockBluetoothAdapter* adapter, 382 MockBluetoothAdapter* adapter,
343 const std::string& device_name) { 383 const std::string& device_name) {
344 BluetoothDevice::UUIDList uuids; 384 BluetoothDevice::UUIDList uuids;
345 uuids.push_back(BluetoothUUID(kGenericAccessServiceUUID)); 385 uuids.push_back(BluetoothUUID(kGenericAccessServiceUUID));
346 386
347 return GetConnectableDeviceNew(adapter, device_name, uuids); 387 return GetConnectableDeviceNew(adapter, device_name, uuids);
348 } 388 }
349 389
350 // static 390 // static
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 scoped_ptr<NiceMock<MockBluetoothGattCharacteristic>> 547 scoped_ptr<NiceMock<MockBluetoothGattCharacteristic>>
508 LayoutTestBluetoothAdapterProvider::GetGattCharacteristic( 548 LayoutTestBluetoothAdapterProvider::GetGattCharacteristic(
509 MockBluetoothGattService* service, 549 MockBluetoothGattService* service,
510 const std::string& uuid) { 550 const std::string& uuid) {
511 return make_scoped_ptr(new NiceMock<MockBluetoothGattCharacteristic>( 551 return make_scoped_ptr(new NiceMock<MockBluetoothGattCharacteristic>(
512 service, uuid /* identifier */, BluetoothUUID(uuid), false /* is_local */, 552 service, uuid /* identifier */, BluetoothUUID(uuid), false /* is_local */,
513 NULL /* properties */, NULL /* permissions */)); 553 NULL /* properties */, NULL /* permissions */));
514 } 554 }
515 555
516 } // namespace content 556 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698