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" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 }; | 84 }; |
85 | 85 |
86 } // namespace | 86 } // namespace |
87 | 87 |
88 namespace content { | 88 namespace content { |
89 | 89 |
90 // static | 90 // static |
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 if (fake_adapter_name == "EmptyAdapter") | 94 // Old Adapters |
95 return GetEmptyAdapter(); | 95 if (fake_adapter_name == "SingleEmptyDeviceAdapter") |
96 else if (fake_adapter_name == "SingleEmptyDeviceAdapter") | |
97 return GetSingleEmptyDeviceAdapter(); | 96 return GetSingleEmptyDeviceAdapter(); |
98 else if (fake_adapter_name == "ConnectableDeviceAdapter") | 97 else if (fake_adapter_name == "ConnectableDeviceAdapter") |
99 return GetConnectableDeviceAdapter(); | 98 return GetConnectableDeviceAdapter(); |
100 else if (fake_adapter_name == "UnconnectableDeviceAdapter") | 99 else if (fake_adapter_name == "UnconnectableDeviceAdapter") |
101 return GetUnconnectableDeviceAdapter(); | 100 return GetUnconnectableDeviceAdapter(); |
102 else if (fake_adapter_name == "ScanFilterCheckingAdapter") | 101 else if (fake_adapter_name == "ScanFilterCheckingAdapter") |
103 return GetScanFilterCheckingAdapter(); | 102 return GetScanFilterCheckingAdapter(); |
104 else if (fake_adapter_name == "MultiDeviceAdapter") | 103 else if (fake_adapter_name == "MultiDeviceAdapter") |
105 return GetMultiDeviceAdapter(); | 104 return GetMultiDeviceAdapter(); |
| 105 // New adapters |
| 106 else if (fake_adapter_name == "BaseAdapter") |
| 107 return GetBaseAdapter(); |
| 108 else if (fake_adapter_name == "EmptyAdapter") |
| 109 return GetEmptyAdapter(); |
| 110 else if (fake_adapter_name == "FailStartDiscoveryAdapter") |
| 111 return GetFailStartDiscoveryAdapter(); |
106 else if (fake_adapter_name == "") | 112 else if (fake_adapter_name == "") |
107 return NULL; | 113 return NULL; |
108 | 114 |
109 NOTREACHED() << fake_adapter_name; | 115 NOTREACHED() << fake_adapter_name; |
110 return NULL; | 116 return NULL; |
111 } | 117 } |
112 | 118 |
113 // static | 119 // static |
114 scoped_refptr<NiceMock<MockBluetoothAdapter>> | 120 scoped_refptr<NiceMock<MockBluetoothAdapter>> |
115 LayoutTestBluetoothAdapterProvider::GetEmptyAdapter() { | 121 LayoutTestBluetoothAdapterProvider::GetBaseAdapter() { |
116 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter( | 122 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter( |
117 new NiceMock<MockBluetoothAdapter>()); | 123 new NiceMock<MockBluetoothAdapter>()); |
118 | 124 |
119 ON_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _)) | |
120 .WillByDefault(RunCallbackWithResult<1 /* success_callback */>( | |
121 []() { return GetDiscoverySession(); })); | |
122 | |
123 // Using Invoke allows the adapter returned from this method to be futher | 125 // Using Invoke allows the adapter returned from this method to be futher |
124 // modified and have devices added to it. The call to ::GetDevices will | 126 // modified and have devices added to it. The call to ::GetDevices will |
125 // invoke ::GetConstMockDevices, returning all devices added up to that time. | 127 // invoke ::GetConstMockDevices, returning all devices added up to that time. |
126 ON_CALL(*adapter, GetDevices()) | 128 ON_CALL(*adapter, GetDevices()) |
127 .WillByDefault( | 129 .WillByDefault( |
128 Invoke(adapter.get(), &MockBluetoothAdapter::GetConstMockDevices)); | 130 Invoke(adapter.get(), &MockBluetoothAdapter::GetConstMockDevices)); |
129 | 131 |
130 // The call to ::GetDevice will invoke GetMockDevice which returns a device | 132 // The call to ::GetDevice will invoke GetMockDevice which returns a device |
131 // matching the address provided if the device was added to the mock. | 133 // matching the address provided if the device was added to the mock. |
132 ON_CALL(*adapter, GetDevice(_)).WillByDefault(GetMockDevice(adapter.get())); | 134 ON_CALL(*adapter, GetDevice(_)).WillByDefault(GetMockDevice(adapter.get())); |
133 | 135 |
134 return adapter.Pass(); | 136 return adapter.Pass(); |
135 } | 137 } |
136 | 138 |
137 // static | 139 // static |
138 scoped_refptr<NiceMock<MockBluetoothAdapter>> | 140 scoped_refptr<NiceMock<MockBluetoothAdapter>> |
| 141 LayoutTestBluetoothAdapterProvider::GetFailStartDiscoveryAdapter() { |
| 142 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(GetBaseAdapter()); |
| 143 |
| 144 ON_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _)) |
| 145 .WillByDefault(RunCallback<2 /* error_callback */>()); |
| 146 |
| 147 return adapter.Pass(); |
| 148 } |
| 149 |
| 150 // static |
| 151 scoped_refptr<NiceMock<MockBluetoothAdapter>> |
| 152 LayoutTestBluetoothAdapterProvider::GetEmptyAdapter() { |
| 153 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(GetBaseAdapter()); |
| 154 |
| 155 ON_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _)) |
| 156 .WillByDefault(RunCallbackWithResult<1 /* success_callback */>( |
| 157 []() { return GetDiscoverySession(); })); |
| 158 |
| 159 return adapter.Pass(); |
| 160 } |
| 161 |
| 162 // static |
| 163 scoped_ptr<NiceMock<MockBluetoothDiscoverySession>> |
| 164 LayoutTestBluetoothAdapterProvider::GetDiscoverySession() { |
| 165 scoped_ptr<NiceMock<MockBluetoothDiscoverySession>> discovery_session( |
| 166 new NiceMock<MockBluetoothDiscoverySession>()); |
| 167 |
| 168 ON_CALL(*discovery_session, Stop(_, _)) |
| 169 .WillByDefault(RunCallback<0 /* success_callback */>()); |
| 170 |
| 171 return discovery_session.Pass(); |
| 172 } |
| 173 |
| 174 // The functions after this haven't been updated to the new design yet. |
| 175 |
| 176 // static |
| 177 scoped_refptr<NiceMock<MockBluetoothAdapter>> |
139 LayoutTestBluetoothAdapterProvider::GetScanFilterCheckingAdapter() { | 178 LayoutTestBluetoothAdapterProvider::GetScanFilterCheckingAdapter() { |
140 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter( | 179 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter( |
141 new NiceMock<MockBluetoothAdapter>()); | 180 new NiceMock<MockBluetoothAdapter>()); |
142 | 181 |
143 // This fails the test with an error message listing actual and expected UUIDs | 182 // This fails the test with an error message listing actual and expected UUIDs |
144 // if StartDiscoverySessionWithFilter() is called with the wrong argument. | 183 // if StartDiscoverySessionWithFilter() is called with the wrong argument. |
145 EXPECT_CALL( | 184 EXPECT_CALL( |
146 *adapter, | 185 *adapter, |
147 StartDiscoverySessionWithFilterRaw( | 186 StartDiscoverySessionWithFilterRaw( |
148 ResultOf(&GetUUIDs, ElementsAre(BluetoothUUID(kGlucoseServiceUUID), | 187 ResultOf(&GetUUIDs, ElementsAre(BluetoothUUID(kGlucoseServiceUUID), |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 scoped_refptr<NiceMock<MockBluetoothAdapter>> | 260 scoped_refptr<NiceMock<MockBluetoothAdapter>> |
222 LayoutTestBluetoothAdapterProvider::GetUnconnectableDeviceAdapter() { | 261 LayoutTestBluetoothAdapterProvider::GetUnconnectableDeviceAdapter() { |
223 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(GetEmptyAdapter()); | 262 scoped_refptr<NiceMock<MockBluetoothAdapter>> adapter(GetEmptyAdapter()); |
224 | 263 |
225 adapter->AddMockDevice(GetUnconnectableDevice(adapter.get())); | 264 adapter->AddMockDevice(GetUnconnectableDevice(adapter.get())); |
226 | 265 |
227 return adapter.Pass(); | 266 return adapter.Pass(); |
228 } | 267 } |
229 | 268 |
230 // static | 269 // static |
231 scoped_ptr<NiceMock<MockBluetoothDiscoverySession>> | |
232 LayoutTestBluetoothAdapterProvider::GetDiscoverySession() { | |
233 scoped_ptr<NiceMock<MockBluetoothDiscoverySession>> discovery_session( | |
234 new NiceMock<MockBluetoothDiscoverySession>()); | |
235 | |
236 ON_CALL(*discovery_session, Stop(_, _)) | |
237 .WillByDefault(RunCallback<0 /* success_callback */>()); | |
238 | |
239 return discovery_session.Pass(); | |
240 } | |
241 | |
242 // static | |
243 scoped_ptr<NiceMock<MockBluetoothDevice>> | 270 scoped_ptr<NiceMock<MockBluetoothDevice>> |
244 LayoutTestBluetoothAdapterProvider::GetEmptyDevice( | 271 LayoutTestBluetoothAdapterProvider::GetEmptyDevice( |
245 MockBluetoothAdapter* adapter, | 272 MockBluetoothAdapter* adapter, |
246 const std::string& device_name) { | 273 const std::string& device_name) { |
247 scoped_ptr<NiceMock<MockBluetoothDevice>> empty_device( | 274 scoped_ptr<NiceMock<MockBluetoothDevice>> empty_device( |
248 new NiceMock<MockBluetoothDevice>( | 275 new NiceMock<MockBluetoothDevice>( |
249 adapter, 0x1F00 /* Bluetooth Class */, device_name, | 276 adapter, 0x1F00 /* Bluetooth Class */, device_name, |
250 device_name + " instanceID", true /* Paired */, | 277 device_name + " instanceID", true /* Paired */, |
251 true /* Connected */)); | 278 true /* Connected */)); |
252 | 279 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 scoped_ptr<NiceMock<MockBluetoothGattCharacteristic>> | 393 scoped_ptr<NiceMock<MockBluetoothGattCharacteristic>> |
367 LayoutTestBluetoothAdapterProvider::GetGattCharacteristic( | 394 LayoutTestBluetoothAdapterProvider::GetGattCharacteristic( |
368 MockBluetoothGattService* service, | 395 MockBluetoothGattService* service, |
369 const std::string& uuid) { | 396 const std::string& uuid) { |
370 return make_scoped_ptr(new NiceMock<MockBluetoothGattCharacteristic>( | 397 return make_scoped_ptr(new NiceMock<MockBluetoothGattCharacteristic>( |
371 service, uuid /* identifier */, BluetoothUUID(uuid), false /* is_local */, | 398 service, uuid /* identifier */, BluetoothUUID(uuid), false /* is_local */, |
372 NULL /* properties */, NULL /* permissions */)); | 399 NULL /* properties */, NULL /* permissions */)); |
373 } | 400 } |
374 | 401 |
375 } // namespace content | 402 } // namespace content |
OLD | NEW |