OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stdint.h> | 5 #include <stdint.h> |
| 6 |
| 7 #include <memory> |
6 #include <utility> | 8 #include <utility> |
7 | 9 |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ
y_api.h" | 10 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ
y_api.h" |
10 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ
y_event_router.h" | 11 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ
y_event_router.h" |
11 #include "chrome/browser/extensions/extension_apitest.h" | 12 #include "chrome/browser/extensions/extension_apitest.h" |
12 #include "device/bluetooth/test/mock_bluetooth_adapter.h" | 13 #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
13 #include "device/bluetooth/test/mock_bluetooth_device.h" | 14 #include "device/bluetooth/test/mock_bluetooth_device.h" |
14 #include "device/bluetooth/test/mock_bluetooth_gatt_characteristic.h" | 15 #include "device/bluetooth/test/mock_bluetooth_gatt_characteristic.h" |
15 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h" | 16 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h" |
16 #include "device/bluetooth/test/mock_bluetooth_gatt_descriptor.h" | 17 #include "device/bluetooth/test/mock_bluetooth_gatt_descriptor.h" |
17 #include "device/bluetooth/test/mock_bluetooth_gatt_notify_session.h" | 18 #include "device/bluetooth/test/mock_bluetooth_gatt_notify_session.h" |
18 #include "device/bluetooth/test/mock_bluetooth_gatt_service.h" | 19 #include "device/bluetooth/test/mock_bluetooth_gatt_service.h" |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 ON_CALL(*desc1_, GetValue()).WillByDefault(ReturnRefOfCopy(default_value)); | 207 ON_CALL(*desc1_, GetValue()).WillByDefault(ReturnRefOfCopy(default_value)); |
207 } | 208 } |
208 | 209 |
209 protected: | 210 protected: |
210 BluetoothLowEnergyEventRouter* event_router() { | 211 BluetoothLowEnergyEventRouter* event_router() { |
211 return extensions::BluetoothLowEnergyAPI::Get(browser()->profile()) | 212 return extensions::BluetoothLowEnergyAPI::Get(browser()->profile()) |
212 ->event_router(); | 213 ->event_router(); |
213 } | 214 } |
214 | 215 |
215 testing::StrictMock<MockBluetoothAdapter>* mock_adapter_; | 216 testing::StrictMock<MockBluetoothAdapter>* mock_adapter_; |
216 scoped_ptr<testing::NiceMock<MockBluetoothDevice> > device0_; | 217 std::unique_ptr<testing::NiceMock<MockBluetoothDevice>> device0_; |
217 scoped_ptr<testing::NiceMock<MockBluetoothDevice> > device1_; | 218 std::unique_ptr<testing::NiceMock<MockBluetoothDevice>> device1_; |
218 scoped_ptr<testing::NiceMock<MockBluetoothGattService> > service0_; | 219 std::unique_ptr<testing::NiceMock<MockBluetoothGattService>> service0_; |
219 scoped_ptr<testing::NiceMock<MockBluetoothGattService> > service1_; | 220 std::unique_ptr<testing::NiceMock<MockBluetoothGattService>> service1_; |
220 scoped_ptr<testing::NiceMock<MockBluetoothGattCharacteristic> > chrc0_; | 221 std::unique_ptr<testing::NiceMock<MockBluetoothGattCharacteristic>> chrc0_; |
221 scoped_ptr<testing::NiceMock<MockBluetoothGattCharacteristic> > chrc1_; | 222 std::unique_ptr<testing::NiceMock<MockBluetoothGattCharacteristic>> chrc1_; |
222 scoped_ptr<testing::NiceMock<MockBluetoothGattCharacteristic> > chrc2_; | 223 std::unique_ptr<testing::NiceMock<MockBluetoothGattCharacteristic>> chrc2_; |
223 scoped_ptr<testing::NiceMock<MockBluetoothGattDescriptor> > desc0_; | 224 std::unique_ptr<testing::NiceMock<MockBluetoothGattDescriptor>> desc0_; |
224 scoped_ptr<testing::NiceMock<MockBluetoothGattDescriptor> > desc1_; | 225 std::unique_ptr<testing::NiceMock<MockBluetoothGattDescriptor>> desc1_; |
225 | 226 |
226 private: | 227 private: |
227 scoped_refptr<extensions::Extension> empty_extension_; | 228 scoped_refptr<extensions::Extension> empty_extension_; |
228 }; | 229 }; |
229 | 230 |
230 ACTION_TEMPLATE(InvokeCallbackArgument, | 231 ACTION_TEMPLATE(InvokeCallbackArgument, |
231 HAS_1_TEMPLATE_PARAMS(int, k), | 232 HAS_1_TEMPLATE_PARAMS(int, k), |
232 AND_0_VALUE_PARAMS()) { | 233 AND_0_VALUE_PARAMS()) { |
233 ::std::tr1::get<k>(args).Run(); | 234 ::std::tr1::get<k>(args).Run(); |
234 } | 235 } |
235 | 236 |
236 ACTION_TEMPLATE(InvokeCallbackArgument, | 237 ACTION_TEMPLATE(InvokeCallbackArgument, |
237 HAS_1_TEMPLATE_PARAMS(int, k), | 238 HAS_1_TEMPLATE_PARAMS(int, k), |
238 AND_1_VALUE_PARAMS(p0)) { | 239 AND_1_VALUE_PARAMS(p0)) { |
239 ::std::tr1::get<k>(args).Run(p0); | 240 ::std::tr1::get<k>(args).Run(p0); |
240 } | 241 } |
241 | 242 |
242 ACTION_TEMPLATE(InvokeCallbackWithScopedPtrArg, | 243 ACTION_TEMPLATE(InvokeCallbackWithScopedPtrArg, |
243 HAS_2_TEMPLATE_PARAMS(int, k, typename, T), | 244 HAS_2_TEMPLATE_PARAMS(int, k, typename, T), |
244 AND_1_VALUE_PARAMS(p0)) { | 245 AND_1_VALUE_PARAMS(p0)) { |
245 ::std::tr1::get<k>(args).Run(scoped_ptr<T>(p0)); | 246 ::std::tr1::get<k>(args).Run(std::unique_ptr<T>(p0)); |
246 } | 247 } |
247 | 248 |
248 BluetoothGattConnection* CreateGattConnection( | 249 BluetoothGattConnection* CreateGattConnection( |
249 scoped_refptr<device::BluetoothAdapter> adapter, | 250 scoped_refptr<device::BluetoothAdapter> adapter, |
250 const std::string& device_address, | 251 const std::string& device_address, |
251 bool expect_disconnect) { | 252 bool expect_disconnect) { |
252 testing::NiceMock<MockBluetoothGattConnection>* conn = | 253 testing::NiceMock<MockBluetoothGattConnection>* conn = |
253 new testing::NiceMock<MockBluetoothGattConnection>(adapter, | 254 new testing::NiceMock<MockBluetoothGattConnection>(adapter, |
254 device_address); | 255 device_address); |
255 EXPECT_CALL(*conn, Disconnect()).Times(expect_disconnect ? 1 : 0); | 256 EXPECT_CALL(*conn, Disconnect()).Times(expect_disconnect ? 1 : 0); |
(...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1224 catcher.RestrictToBrowserContext(browser()->profile()); | 1225 catcher.RestrictToBrowserContext(browser()->profile()); |
1225 | 1226 |
1226 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress0)) | 1227 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress0)) |
1227 .WillRepeatedly(Return(device0_.get())); | 1228 .WillRepeatedly(Return(device0_.get())); |
1228 | 1229 |
1229 BluetoothDevice::GattConnectionCallback connect_callback; | 1230 BluetoothDevice::GattConnectionCallback connect_callback; |
1230 | 1231 |
1231 testing::NiceMock<MockBluetoothGattConnection>* conn = | 1232 testing::NiceMock<MockBluetoothGattConnection>* conn = |
1232 new testing::NiceMock<MockBluetoothGattConnection>(mock_adapter_, | 1233 new testing::NiceMock<MockBluetoothGattConnection>(mock_adapter_, |
1233 kTestLeDeviceAddress0); | 1234 kTestLeDeviceAddress0); |
1234 scoped_ptr<BluetoothGattConnection> conn_ptr(conn); | 1235 std::unique_ptr<BluetoothGattConnection> conn_ptr(conn); |
1235 EXPECT_CALL(*conn, Disconnect()).Times(1); | 1236 EXPECT_CALL(*conn, Disconnect()).Times(1); |
1236 | 1237 |
1237 EXPECT_CALL(*device0_, CreateGattConnection(_, _)) | 1238 EXPECT_CALL(*device0_, CreateGattConnection(_, _)) |
1238 .Times(1) | 1239 .Times(1) |
1239 .WillOnce(SaveArg<0>(&connect_callback)); | 1240 .WillOnce(SaveArg<0>(&connect_callback)); |
1240 | 1241 |
1241 ExtensionTestMessageListener listener(true); | 1242 ExtensionTestMessageListener listener(true); |
1242 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( | 1243 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( |
1243 "bluetooth_low_energy/connect_in_progress"))); | 1244 "bluetooth_low_energy/connect_in_progress"))); |
1244 | 1245 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1362 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 1363 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
1363 | 1364 |
1364 listener.Reply("go"); | 1365 listener.Reply("go"); |
1365 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 1366 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
1366 | 1367 |
1367 event_router()->GattServiceRemoved(mock_adapter_, device0_.get(), | 1368 event_router()->GattServiceRemoved(mock_adapter_, device0_.get(), |
1368 service0_.get()); | 1369 service0_.get()); |
1369 } | 1370 } |
1370 | 1371 |
1371 } // namespace | 1372 } // namespace |
OLD | NEW |