| OLD | NEW |
| 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 "base/strings/stringprintf.h" |
| 7 #include "device/bluetooth/bluetooth_adapter.h" | 8 #include "device/bluetooth/bluetooth_adapter.h" |
| 8 #include "device/bluetooth/bluetooth_device.h" | 9 #include "device/bluetooth/bluetooth_device.h" |
| 9 #include "device/bluetooth/bluetooth_discovery_session.h" | 10 #include "device/bluetooth/bluetooth_discovery_session.h" |
| 10 #include "device/bluetooth/bluetooth_uuid.h" | 11 #include "device/bluetooth/bluetooth_uuid.h" |
| 11 #include "device/bluetooth/test/mock_bluetooth_adapter.h" | 12 #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
| 12 #include "device/bluetooth/test/mock_bluetooth_discovery_session.h" | 13 #include "device/bluetooth/test/mock_bluetooth_discovery_session.h" |
| 13 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h" | 14 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 15 | 16 |
| 16 using device::BluetoothAdapter; | 17 using device::BluetoothAdapter; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 else if (fake_adapter_name == "EmptyAdapter") | 107 else if (fake_adapter_name == "EmptyAdapter") |
| 107 return GetEmptyAdapter(); | 108 return GetEmptyAdapter(); |
| 108 else if (fake_adapter_name == "FailStartDiscoveryAdapter") | 109 else if (fake_adapter_name == "FailStartDiscoveryAdapter") |
| 109 return GetFailStartDiscoveryAdapter(); | 110 return GetFailStartDiscoveryAdapter(); |
| 110 else if (fake_adapter_name == "GlucoseHeartRateAdapter") | 111 else if (fake_adapter_name == "GlucoseHeartRateAdapter") |
| 111 return GetGlucoseHeartRateAdapter(); | 112 return GetGlucoseHeartRateAdapter(); |
| 112 else if (fake_adapter_name == "MissingServiceGenericAccessAdapter") | 113 else if (fake_adapter_name == "MissingServiceGenericAccessAdapter") |
| 113 return GetMissingServiceGenericAccessAdapter(); | 114 return GetMissingServiceGenericAccessAdapter(); |
| 114 else if (fake_adapter_name == "MissingCharacteristicGenericAccessAdapter") | 115 else if (fake_adapter_name == "MissingCharacteristicGenericAccessAdapter") |
| 115 return GetMissingCharacteristicGenericAccessAdapter(); | 116 return GetMissingCharacteristicGenericAccessAdapter(); |
| 117 else if (fake_adapter_name == "FailingConnectionsAdapter") |
| 118 return GetFailingConnectionsAdapter(); |
| 116 else if (fake_adapter_name == "") | 119 else if (fake_adapter_name == "") |
| 117 return NULL; | 120 return NULL; |
| 118 | 121 |
| 119 NOTREACHED() << fake_adapter_name; | 122 NOTREACHED() << fake_adapter_name; |
| 120 return NULL; | 123 return NULL; |
| 121 } | 124 } |
| 122 | 125 |
| 123 // static | 126 // static |
| 124 scoped_refptr<NiceMock<MockBluetoothAdapter>> | 127 scoped_refptr<NiceMock<MockBluetoothAdapter>> |
| 125 LayoutTestBluetoothAdapterProvider::GetBaseAdapter() { | 128 LayoutTestBluetoothAdapterProvider::GetBaseAdapter() { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 | 240 |
| 238 // Intentionally NOT adding a characteristic to generic_access service. | 241 // Intentionally NOT adding a characteristic to generic_access service. |
| 239 | 242 |
| 240 device->AddMockService(generic_access.Pass()); | 243 device->AddMockService(generic_access.Pass()); |
| 241 | 244 |
| 242 adapter->AddMockDevice(device.Pass()); | 245 adapter->AddMockDevice(device.Pass()); |
| 243 | 246 |
| 244 return adapter.Pass(); | 247 return adapter.Pass(); |
| 245 } | 248 } |
| 246 | 249 |
| 250 scoped_refptr<NiceMock<MockBluetoothAdapter>> |
| 251 LayoutTestBluetoothAdapterProvider::GetFailingConnectionsAdapter() { |
| 252 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(GetEmptyAdapter()); |
| 253 |
| 254 for (int error = BluetoothDevice::ERROR_UNKNOWN; |
| 255 error <= BluetoothDevice::ERROR_UNSUPPORTED_DEVICE; error++) { |
| 256 adapter->AddMockDevice(GetUnconnectableDevice( |
| 257 adapter.get(), static_cast<BluetoothDevice::ConnectErrorCode>(error))); |
| 258 } |
| 259 return adapter.Pass(); |
| 260 } |
| 261 |
| 247 // static | 262 // static |
| 248 scoped_ptr<NiceMock<MockBluetoothDevice>> | 263 scoped_ptr<NiceMock<MockBluetoothDevice>> |
| 249 LayoutTestBluetoothAdapterProvider::GetBaseDevice( | 264 LayoutTestBluetoothAdapterProvider::GetBaseDevice( |
| 250 MockBluetoothAdapter* adapter, | 265 MockBluetoothAdapter* adapter, |
| 251 const std::string& device_name, | 266 const std::string& device_name, |
| 252 device::BluetoothDevice::UUIDList uuids, | 267 device::BluetoothDevice::UUIDList uuids, |
| 253 const std::string& address) { | 268 const std::string& address) { |
| 254 scoped_ptr<NiceMock<MockBluetoothDevice>> device( | 269 scoped_ptr<NiceMock<MockBluetoothDevice>> device( |
| 255 new NiceMock<MockBluetoothDevice>(adapter, 0x1F00 /* Bluetooth class */, | 270 new NiceMock<MockBluetoothDevice>(adapter, 0x1F00 /* Bluetooth class */, |
| 256 device_name, address, true /* paired */, | 271 device_name, address, true /* paired */, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 RunCallbackWithResult<0 /* success_callback */>([device_ptr]() { | 346 RunCallbackWithResult<0 /* success_callback */>([device_ptr]() { |
| 332 return make_scoped_ptr(new NiceMock<MockBluetoothGattConnection>( | 347 return make_scoped_ptr(new NiceMock<MockBluetoothGattConnection>( |
| 333 device_ptr->GetAddress())); | 348 device_ptr->GetAddress())); |
| 334 })); | 349 })); |
| 335 | 350 |
| 336 return device.Pass(); | 351 return device.Pass(); |
| 337 } | 352 } |
| 338 | 353 |
| 339 // static | 354 // static |
| 340 scoped_ptr<testing::NiceMock<device::MockBluetoothDevice>> | 355 scoped_ptr<testing::NiceMock<device::MockBluetoothDevice>> |
| 356 LayoutTestBluetoothAdapterProvider::GetUnconnectableDevice( |
| 357 MockBluetoothAdapter* adapter, |
| 358 BluetoothDevice::ConnectErrorCode error_code, |
| 359 const std::string& device_name) { |
| 360 BluetoothDevice::UUIDList uuids; |
| 361 uuids.push_back(BluetoothUUID(errorUUID(error_code))); |
| 362 |
| 363 scoped_ptr<testing::NiceMock<MockBluetoothDevice>> device( |
| 364 GetBaseDevice(adapter, device_name, uuids, canonicalAddress(error_code))); |
| 365 |
| 366 ON_CALL(*device, CreateGattConnection(_, _)) |
| 367 .WillByDefault(RunCallback<1 /* error_callback */>(error_code)); |
| 368 |
| 369 return device.Pass(); |
| 370 } |
| 371 |
| 372 // static |
| 373 scoped_ptr<testing::NiceMock<device::MockBluetoothDevice>> |
| 341 LayoutTestBluetoothAdapterProvider::GetGenericAccessDevice( | 374 LayoutTestBluetoothAdapterProvider::GetGenericAccessDevice( |
| 342 MockBluetoothAdapter* adapter, | 375 MockBluetoothAdapter* adapter, |
| 343 const std::string& device_name) { | 376 const std::string& device_name) { |
| 344 BluetoothDevice::UUIDList uuids; | 377 BluetoothDevice::UUIDList uuids; |
| 345 uuids.push_back(BluetoothUUID(kGenericAccessServiceUUID)); | 378 uuids.push_back(BluetoothUUID(kGenericAccessServiceUUID)); |
| 346 | 379 |
| 347 return GetConnectableDeviceNew(adapter, device_name, uuids); | 380 return GetConnectableDeviceNew(adapter, device_name, uuids); |
| 348 } | 381 } |
| 349 | 382 |
| 350 // static | 383 // static |
| (...skipping 10 matching lines...) Expand all Loading... |
| 361 .WillByDefault(Invoke(service.get(), | 394 .WillByDefault(Invoke(service.get(), |
| 362 &MockBluetoothGattService::GetMockCharacteristics)); | 395 &MockBluetoothGattService::GetMockCharacteristics)); |
| 363 | 396 |
| 364 ON_CALL(*service, GetCharacteristic(_)) | 397 ON_CALL(*service, GetCharacteristic(_)) |
| 365 .WillByDefault(Invoke(service.get(), | 398 .WillByDefault(Invoke(service.get(), |
| 366 &MockBluetoothGattService::GetMockCharacteristic)); | 399 &MockBluetoothGattService::GetMockCharacteristic)); |
| 367 | 400 |
| 368 return service.Pass(); | 401 return service.Pass(); |
| 369 } | 402 } |
| 370 | 403 |
| 404 // static |
| 405 std::string LayoutTestBluetoothAdapterProvider::errorUUID(uint32_t alias) { |
| 406 return base::StringPrintf("%08x-97e5-4cd7-b9f1-f5a427670c59", alias); |
| 407 } |
| 408 |
| 409 // static |
| 410 std::string LayoutTestBluetoothAdapterProvider::canonicalAddress(int addr) { |
| 411 return BluetoothDevice::CanonicalizeAddress( |
| 412 base::StringPrintf("%012x", addr)); |
| 413 } |
| 414 |
| 371 // The functions after this haven't been updated to the new design yet. | 415 // The functions after this haven't been updated to the new design yet. |
| 372 | 416 |
| 373 // static | 417 // static |
| 374 scoped_refptr<NiceMock<MockBluetoothAdapter>> | 418 scoped_refptr<NiceMock<MockBluetoothAdapter>> |
| 375 LayoutTestBluetoothAdapterProvider::GetSingleEmptyDeviceAdapter() { | 419 LayoutTestBluetoothAdapterProvider::GetSingleEmptyDeviceAdapter() { |
| 376 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(GetEmptyAdapter()); | 420 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(GetEmptyAdapter()); |
| 377 | 421 |
| 378 adapter->AddMockDevice(GetEmptyDevice(adapter.get())); | 422 adapter->AddMockDevice(GetEmptyDevice(adapter.get())); |
| 379 | 423 |
| 380 return adapter.Pass(); | 424 return adapter.Pass(); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 scoped_ptr<NiceMock<MockBluetoothGattCharacteristic>> | 551 scoped_ptr<NiceMock<MockBluetoothGattCharacteristic>> |
| 508 LayoutTestBluetoothAdapterProvider::GetGattCharacteristic( | 552 LayoutTestBluetoothAdapterProvider::GetGattCharacteristic( |
| 509 MockBluetoothGattService* service, | 553 MockBluetoothGattService* service, |
| 510 const std::string& uuid) { | 554 const std::string& uuid) { |
| 511 return make_scoped_ptr(new NiceMock<MockBluetoothGattCharacteristic>( | 555 return make_scoped_ptr(new NiceMock<MockBluetoothGattCharacteristic>( |
| 512 service, uuid /* identifier */, BluetoothUUID(uuid), false /* is_local */, | 556 service, uuid /* identifier */, BluetoothUUID(uuid), false /* is_local */, |
| 513 NULL /* properties */, NULL /* permissions */)); | 557 NULL /* properties */, NULL /* permissions */)); |
| 514 } | 558 } |
| 515 | 559 |
| 516 } // namespace content | 560 } // namespace content |
| OLD | NEW |