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