Chromium Code Reviews| 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 "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" |
| 11 #include "device/bluetooth/test/mock_bluetooth_adapter.h" | 11 #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
| 12 #include "device/bluetooth/test/mock_bluetooth_discovery_session.h" | 12 #include "device/bluetooth/test/mock_bluetooth_discovery_session.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 14 | 14 |
| 15 using device::BluetoothAdapter; | 15 using device::BluetoothAdapter; |
| 16 using device::BluetoothAdapterFactory; | 16 using device::BluetoothAdapterFactory; |
| 17 using device::BluetoothDevice; | 17 using device::BluetoothDevice; |
| 18 using device::BluetoothDiscoverySession; | 18 using device::BluetoothDiscoverySession; |
| 19 using device::BluetoothUUID; | 19 using device::BluetoothUUID; |
| 20 using device::MockBluetoothAdapter; | 20 using device::MockBluetoothAdapter; |
| 21 using device::MockBluetoothDevice; | 21 using device::MockBluetoothDevice; |
| 22 using device::MockBluetoothDiscoverySession; | 22 using device::MockBluetoothDiscoverySession; |
| 23 using testing::Invoke; | 23 using testing::Invoke; |
| 24 using testing::Return; | 24 using testing::Return; |
| 25 using testing::NiceMock; | 25 using testing::NiceMock; |
| 26 using testing::_; | 26 using testing::_; |
| 27 | 27 |
| 28 namespace { | |
| 29 // Invokes Run() on the k-th argument of the function with no arguments. | |
| 30 ACTION_TEMPLATE(RunCallback, | |
| 31 HAS_1_TEMPLATE_PARAMS(int, k), | |
| 32 AND_0_VALUE_PARAMS()) { | |
| 33 return ::std::tr1::get<k>(args).Run(); | |
| 34 } | |
| 35 | |
| 36 // Function for when the value passed to the callback needs to be a scoped_ptr. | |
| 37 // Invokes Run() on the k-th argument of the function with value wrapped in | |
| 38 // scoped_ptr<T> | |
| 39 ACTION_TEMPLATE(RunCallbackScoped, | |
| 40 HAS_2_TEMPLATE_PARAMS(int, k, typename, T), | |
| 41 AND_1_VALUE_PARAMS(value)) { | |
| 42 return ::std::tr1::get<k>(args).Run(scoped_ptr<T>(value)); | |
| 43 } | |
| 44 | |
| 45 } | |
| 46 | |
| 28 namespace content { | 47 namespace content { |
| 29 | 48 |
| 30 // static | 49 // static |
| 31 scoped_refptr<BluetoothAdapter> | 50 scoped_refptr<BluetoothAdapter> |
| 32 LayoutTestBluetoothAdapterProvider::GetBluetoothAdapter( | 51 LayoutTestBluetoothAdapterProvider::GetBluetoothAdapter( |
| 33 const std::string& fake_adapter_name) { | 52 const std::string& fake_adapter_name) { |
| 34 // TODO(ortuno): Remove RejectRequestDevice once LayoutTests are modified | 53 // TODO(ortuno): Remove RejectRequestDevice once LayoutTests are modified |
| 35 if (fake_adapter_name == "RejectRequestDevice_NotFoundError" || | 54 if (fake_adapter_name == "RejectRequestDevice_NotFoundError" || |
| 36 fake_adapter_name == "EmptyAdapter") { | 55 fake_adapter_name == "EmptyAdapter") { |
| 37 return GetEmptyAdapter(); | 56 return GetEmptyAdapter(); |
| 38 } | 57 } |
| 39 // TODO(ortuno): Remove "Single Empty Device" once LayoutTests are modified | 58 // TODO(ortuno): Remove "Single Empty Device" once LayoutTests are modified |
| 40 else if (fake_adapter_name == "Single Empty Device" || | 59 else if (fake_adapter_name == "Single Empty Device" || |
| 41 fake_adapter_name == "SingleEmptyDeviceAdapter") { | 60 fake_adapter_name == "SingleEmptyDeviceAdapter") { |
| 42 return GetSingleEmptyDeviceAdapter(); | 61 return GetSingleEmptyDeviceAdapter(); |
| 43 } else if (fake_adapter_name == "") { | 62 } else if (fake_adapter_name == "") { |
| 44 return NULL; | 63 return NULL; |
| 45 } | 64 } |
| 46 NOTREACHED(); | 65 NOTREACHED(); |
| 47 return NULL; | 66 return NULL; |
| 48 } | 67 } |
| 49 | 68 |
| 50 // static | 69 // static |
| 51 scoped_refptr<NiceMock<MockBluetoothAdapter>> | 70 scoped_refptr<NiceMock<MockBluetoothAdapter>> |
| 52 LayoutTestBluetoothAdapterProvider::GetEmptyAdapter() { | 71 LayoutTestBluetoothAdapterProvider::GetEmptyAdapter() { |
| 53 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter( | 72 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter( |
| 54 new NiceMock<MockBluetoothAdapter>()); | 73 new NiceMock<MockBluetoothAdapter>()); |
| 55 | 74 |
| 56 ON_CALL(*adapter, StartDiscoverySession(_, _)) | 75 scoped_ptr<NiceMock<MockBluetoothDiscoverySession>> discovery_session( |
| 57 .WillByDefault(Invoke( | 76 GetDiscoverySession()); |
| 58 &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession)); | 77 |
| 78 EXPECT_CALL(*adapter, StartDiscoverySession(_, _)) | |
| 79 .WillOnce(RunCallbackScoped<0 /* success_callback */, | |
| 80 BluetoothDiscoverySession>( | |
|
Jeffrey Yasskin
2015/05/19 20:47:49
Run `git cl format` to fix the indentation here.
| |
| 81 discovery_session.release())); | |
| 59 | 82 |
| 60 ON_CALL(*adapter, GetDevices()) | 83 ON_CALL(*adapter, GetDevices()) |
| 61 .WillByDefault(Return(adapter->GetMockDevices())); | 84 .WillByDefault( |
| 85 Invoke(adapter.get(), &MockBluetoothAdapter::GetMockDevices)); | |
| 62 | 86 |
| 63 return adapter.Pass(); | 87 return adapter.Pass(); |
| 64 } | 88 } |
| 65 | 89 |
| 66 // static | 90 // static |
| 67 scoped_refptr<NiceMock<MockBluetoothAdapter>> | 91 scoped_refptr<NiceMock<MockBluetoothAdapter>> |
| 68 LayoutTestBluetoothAdapterProvider::GetSingleEmptyDeviceAdapter() { | 92 LayoutTestBluetoothAdapterProvider::GetSingleEmptyDeviceAdapter() { |
| 69 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter( | 93 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(GetEmptyAdapter()); |
| 70 new NiceMock<MockBluetoothAdapter>()); | |
| 71 | |
| 72 ON_CALL(*adapter, StartDiscoverySession(_, _)) | |
| 73 .WillByDefault(Invoke( | |
| 74 &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession)); | |
| 75 | 94 |
| 76 adapter->AddMockDevice(GetEmptyDevice(adapter.get())); | 95 adapter->AddMockDevice(GetEmptyDevice(adapter.get())); |
| 77 | 96 |
| 78 ON_CALL(*adapter, GetDevices()) | |
| 79 .WillByDefault(Return(adapter->GetMockDevices())); | |
| 80 | |
| 81 return adapter.Pass(); | 97 return adapter.Pass(); |
| 82 } | 98 } |
| 83 | 99 |
| 84 // static | 100 // static |
| 85 scoped_ptr<NiceMock<MockBluetoothDevice>> | 101 scoped_ptr<NiceMock<MockBluetoothDevice>> |
| 86 LayoutTestBluetoothAdapterProvider::GetEmptyDevice( | 102 LayoutTestBluetoothAdapterProvider::GetEmptyDevice( |
| 87 MockBluetoothAdapter* adapter) { | 103 MockBluetoothAdapter* adapter) { |
| 88 scoped_ptr<NiceMock<MockBluetoothDevice>> empty_device( | 104 scoped_ptr<NiceMock<MockBluetoothDevice>> empty_device( |
| 89 new NiceMock<MockBluetoothDevice>( | 105 new NiceMock<MockBluetoothDevice>( |
| 90 adapter, 0x1F00 /* Bluetooth Class */, "Empty Mock Device name", | 106 adapter, 0x1F00 /* Bluetooth Class */, "Empty Mock Device name", |
| 91 "Empty Mock Device instanceID", true /* Paired */, | 107 "Empty Mock Device instanceID", true /* Paired */, |
| 92 true /* Connected */)); | 108 true /* Connected */)); |
| 93 | 109 |
| 94 ON_CALL(*empty_device, GetVendorIDSource()) | 110 ON_CALL(*empty_device, GetVendorIDSource()) |
| 95 .WillByDefault(Return(BluetoothDevice::VENDOR_ID_BLUETOOTH)); | 111 .WillByDefault(Return(BluetoothDevice::VENDOR_ID_BLUETOOTH)); |
| 96 ON_CALL(*empty_device, GetVendorID()).WillByDefault(Return(0xFFFF)); | 112 ON_CALL(*empty_device, GetVendorID()).WillByDefault(Return(0xFFFF)); |
| 97 ON_CALL(*empty_device, GetProductID()).WillByDefault(Return(1)); | 113 ON_CALL(*empty_device, GetProductID()).WillByDefault(Return(1)); |
| 98 ON_CALL(*empty_device, GetDeviceID()).WillByDefault(Return(2)); | 114 ON_CALL(*empty_device, GetDeviceID()).WillByDefault(Return(2)); |
| 99 | 115 |
| 100 BluetoothDevice::UUIDList list; | 116 BluetoothDevice::UUIDList list; |
| 101 list.push_back(BluetoothUUID("1800")); | 117 list.push_back(BluetoothUUID("1800")); |
| 102 list.push_back(BluetoothUUID("1801")); | 118 list.push_back(BluetoothUUID("1801")); |
| 103 ON_CALL(*empty_device, GetUUIDs()).WillByDefault(Return(list)); | 119 ON_CALL(*empty_device, GetUUIDs()).WillByDefault(Return(list)); |
| 104 return empty_device.Pass(); | 120 return empty_device.Pass(); |
| 105 } | 121 } |
| 106 | 122 |
| 107 // static | 123 // static |
| 108 void LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySession( | 124 scoped_ptr<NiceMock<MockBluetoothDiscoverySession>> |
| 109 const BluetoothAdapter::DiscoverySessionCallback& callback, | 125 LayoutTestBluetoothAdapterProvider::GetDiscoverySession() { |
| 110 const BluetoothAdapter::ErrorCallback& error_callback) { | |
| 111 scoped_ptr<NiceMock<MockBluetoothDiscoverySession>> discovery_session( | 126 scoped_ptr<NiceMock<MockBluetoothDiscoverySession>> discovery_session( |
| 112 new NiceMock<MockBluetoothDiscoverySession>()); | 127 new NiceMock<MockBluetoothDiscoverySession>()); |
| 113 | 128 |
| 114 ON_CALL(*discovery_session, Stop(_, _)) | 129 ON_CALL(*discovery_session, Stop(_, _)) |
| 115 .WillByDefault(Invoke( | 130 .WillByDefault(RunCallback<0 /* success_callback */>()); |
| 116 &LayoutTestBluetoothAdapterProvider::SuccessfulDiscoverySessionStop)); | |
| 117 | 131 |
| 118 callback.Run(discovery_session.Pass()); | 132 return 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 } | 133 } |
| 127 | 134 |
| 128 } // namespace content | 135 } // namespace content |
| OLD | NEW |