| 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ
y_api.h" | 6 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ
y_api.h" |
| 7 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ
y_event_router.h" | 7 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ
y_event_router.h" |
| 8 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
| 9 #include "device/bluetooth/test/mock_bluetooth_adapter.h" | 9 #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
| 10 #include "device/bluetooth/test/mock_bluetooth_device.h" | 10 #include "device/bluetooth/test/mock_bluetooth_device.h" |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 ::std::tr1::get<k>(args).Run(p0); | 235 ::std::tr1::get<k>(args).Run(p0); |
| 236 } | 236 } |
| 237 | 237 |
| 238 ACTION_TEMPLATE(InvokeCallbackWithScopedPtrArg, | 238 ACTION_TEMPLATE(InvokeCallbackWithScopedPtrArg, |
| 239 HAS_2_TEMPLATE_PARAMS(int, k, typename, T), | 239 HAS_2_TEMPLATE_PARAMS(int, k, typename, T), |
| 240 AND_1_VALUE_PARAMS(p0)) { | 240 AND_1_VALUE_PARAMS(p0)) { |
| 241 ::std::tr1::get<k>(args).Run(scoped_ptr<T>(p0)); | 241 ::std::tr1::get<k>(args).Run(scoped_ptr<T>(p0)); |
| 242 } | 242 } |
| 243 | 243 |
| 244 BluetoothGattConnection* CreateGattConnection( | 244 BluetoothGattConnection* CreateGattConnection( |
| 245 scoped_refptr<device::BluetoothAdapter> adapter, |
| 245 const std::string& device_address, | 246 const std::string& device_address, |
| 246 bool expect_disconnect) { | 247 bool expect_disconnect) { |
| 247 testing::NiceMock<MockBluetoothGattConnection>* conn = | 248 testing::NiceMock<MockBluetoothGattConnection>* conn = |
| 248 new testing::NiceMock<MockBluetoothGattConnection>(device_address); | 249 new testing::NiceMock<MockBluetoothGattConnection>(adapter, |
| 250 device_address); |
| 249 EXPECT_CALL(*conn, Disconnect()).Times(expect_disconnect ? 1 : 0); | 251 EXPECT_CALL(*conn, Disconnect()).Times(expect_disconnect ? 1 : 0); |
| 250 return conn; | 252 return conn; |
| 251 } | 253 } |
| 252 | 254 |
| 253 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetServices) { | 255 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetServices) { |
| 254 ResultCatcher catcher; | 256 ResultCatcher catcher; |
| 255 catcher.RestrictToBrowserContext(browser()->profile()); | 257 catcher.RestrictToBrowserContext(browser()->profile()); |
| 256 | 258 |
| 257 std::vector<BluetoothGattService*> services; | 259 std::vector<BluetoothGattService*> services; |
| 258 services.push_back(service0_.get()); | 260 services.push_back(service0_.get()); |
| (...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1143 .WillRepeatedly(Return(device1_.get())); | 1145 .WillRepeatedly(Return(device1_.get())); |
| 1144 EXPECT_CALL(*device0_, CreateGattConnection(_, _)) | 1146 EXPECT_CALL(*device0_, CreateGattConnection(_, _)) |
| 1145 .Times(9) | 1147 .Times(9) |
| 1146 .WillOnce(InvokeCallbackArgument<1>(BluetoothDevice::ERROR_FAILED)) | 1148 .WillOnce(InvokeCallbackArgument<1>(BluetoothDevice::ERROR_FAILED)) |
| 1147 .WillOnce(InvokeCallbackArgument<1>(BluetoothDevice::ERROR_INPROGRESS)) | 1149 .WillOnce(InvokeCallbackArgument<1>(BluetoothDevice::ERROR_INPROGRESS)) |
| 1148 .WillOnce(InvokeCallbackArgument<1>(BluetoothDevice::ERROR_AUTH_FAILED)) | 1150 .WillOnce(InvokeCallbackArgument<1>(BluetoothDevice::ERROR_AUTH_FAILED)) |
| 1149 .WillOnce(InvokeCallbackArgument<1>(BluetoothDevice::ERROR_AUTH_REJECTED)) | 1151 .WillOnce(InvokeCallbackArgument<1>(BluetoothDevice::ERROR_AUTH_REJECTED)) |
| 1150 .WillOnce(InvokeCallbackArgument<1>(BluetoothDevice::ERROR_AUTH_CANCELED)) | 1152 .WillOnce(InvokeCallbackArgument<1>(BluetoothDevice::ERROR_AUTH_CANCELED)) |
| 1151 .WillOnce(InvokeCallbackArgument<1>(BluetoothDevice::ERROR_AUTH_TIMEOUT)) | 1153 .WillOnce(InvokeCallbackArgument<1>(BluetoothDevice::ERROR_AUTH_TIMEOUT)) |
| 1152 .WillOnce( | 1154 .WillOnce( |
| 1153 InvokeCallbackArgument<1>(BluetoothDevice::ERROR_UNSUPPORTED_DEVICE)) | 1155 InvokeCallbackArgument<1>(BluetoothDevice::ERROR_UNSUPPORTED_DEVICE)) |
| 1154 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>( | 1156 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>( |
| 1155 CreateGattConnection(kTestLeDeviceAddress0, | 1157 CreateGattConnection(mock_adapter_, kTestLeDeviceAddress0, |
| 1156 true /* expect_disconnect */))) | 1158 true /* expect_disconnect */))) |
| 1157 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>( | 1159 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>( |
| 1158 CreateGattConnection(kTestLeDeviceAddress0, | 1160 CreateGattConnection(mock_adapter_, kTestLeDeviceAddress0, |
| 1159 false /* expect_disconnect */))); | 1161 false /* expect_disconnect */))); |
| 1160 EXPECT_CALL(*device1_, CreateGattConnection(_, _)) | 1162 EXPECT_CALL(*device1_, CreateGattConnection(_, _)) |
| 1161 .Times(1) | 1163 .Times(1) |
| 1162 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>( | 1164 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>( |
| 1163 CreateGattConnection(kTestLeDeviceAddress1, | 1165 CreateGattConnection(mock_adapter_, kTestLeDeviceAddress1, |
| 1164 true /* expect_disconnect */))); | 1166 true /* expect_disconnect */))); |
| 1165 | 1167 |
| 1166 ASSERT_TRUE(LoadExtension( | 1168 ASSERT_TRUE(LoadExtension( |
| 1167 test_data_dir_.AppendASCII("bluetooth_low_energy/gatt_connection"))); | 1169 test_data_dir_.AppendASCII("bluetooth_low_energy/gatt_connection"))); |
| 1168 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 1170 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 1169 } | 1171 } |
| 1170 | 1172 |
| 1171 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ReconnectAfterDisconnected) { | 1173 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ReconnectAfterDisconnected) { |
| 1172 ResultCatcher catcher; | 1174 ResultCatcher catcher; |
| 1173 catcher.RestrictToBrowserContext(browser()->profile()); | 1175 catcher.RestrictToBrowserContext(browser()->profile()); |
| 1174 | 1176 |
| 1175 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress0)) | 1177 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress0)) |
| 1176 .WillRepeatedly(Return(device0_.get())); | 1178 .WillRepeatedly(Return(device0_.get())); |
| 1177 | 1179 |
| 1178 MockBluetoothGattConnection* first_conn = | 1180 MockBluetoothGattConnection* first_conn = |
| 1179 static_cast<MockBluetoothGattConnection*>(CreateGattConnection( | 1181 static_cast<MockBluetoothGattConnection*>(CreateGattConnection( |
| 1180 kTestLeDeviceAddress0, false /* expect_disconnect */)); | 1182 mock_adapter_, kTestLeDeviceAddress0, false /* expect_disconnect */)); |
| 1181 EXPECT_CALL(*first_conn, IsConnected()) | 1183 EXPECT_CALL(*first_conn, IsConnected()) |
| 1182 .Times(2) | 1184 .Times(2) |
| 1183 .WillOnce(Return(true)) | 1185 .WillOnce(Return(true)) |
| 1184 .WillOnce(Return(false)); | 1186 .WillOnce(Return(false)); |
| 1185 | 1187 |
| 1186 EXPECT_CALL(*device0_, CreateGattConnection(_, _)) | 1188 EXPECT_CALL(*device0_, CreateGattConnection(_, _)) |
| 1187 .Times(2) | 1189 .Times(2) |
| 1188 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>( | 1190 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>( |
| 1189 first_conn)) | 1191 first_conn)) |
| 1190 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>( | 1192 .WillOnce(InvokeCallbackWithScopedPtrArg<0, BluetoothGattConnection>( |
| 1191 CreateGattConnection(kTestLeDeviceAddress0, | 1193 CreateGattConnection(mock_adapter_, kTestLeDeviceAddress0, |
| 1192 false /* expect_disconnect */))); | 1194 false /* expect_disconnect */))); |
| 1193 | 1195 |
| 1194 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( | 1196 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( |
| 1195 "bluetooth_low_energy/reconnect_after_disconnected"))); | 1197 "bluetooth_low_energy/reconnect_after_disconnected"))); |
| 1196 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 1198 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 1197 } | 1199 } |
| 1198 | 1200 |
| 1199 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ConnectInProgress) { | 1201 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ConnectInProgress) { |
| 1200 ResultCatcher catcher; | 1202 ResultCatcher catcher; |
| 1201 catcher.RestrictToBrowserContext(browser()->profile()); | 1203 catcher.RestrictToBrowserContext(browser()->profile()); |
| 1202 | 1204 |
| 1203 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress0)) | 1205 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress0)) |
| 1204 .WillRepeatedly(Return(device0_.get())); | 1206 .WillRepeatedly(Return(device0_.get())); |
| 1205 | 1207 |
| 1206 BluetoothDevice::GattConnectionCallback connect_callback; | 1208 BluetoothDevice::GattConnectionCallback connect_callback; |
| 1207 | 1209 |
| 1208 testing::NiceMock<MockBluetoothGattConnection>* conn = | 1210 testing::NiceMock<MockBluetoothGattConnection>* conn = |
| 1209 new testing::NiceMock<MockBluetoothGattConnection>( | 1211 new testing::NiceMock<MockBluetoothGattConnection>(mock_adapter_, |
| 1210 kTestLeDeviceAddress0); | 1212 kTestLeDeviceAddress0); |
| 1211 scoped_ptr<BluetoothGattConnection> conn_ptr(conn); | 1213 scoped_ptr<BluetoothGattConnection> conn_ptr(conn); |
| 1212 EXPECT_CALL(*conn, Disconnect()).Times(1); | 1214 EXPECT_CALL(*conn, Disconnect()).Times(1); |
| 1213 | 1215 |
| 1214 EXPECT_CALL(*device0_, CreateGattConnection(_, _)) | 1216 EXPECT_CALL(*device0_, CreateGattConnection(_, _)) |
| 1215 .Times(1) | 1217 .Times(1) |
| 1216 .WillOnce(SaveArg<0>(&connect_callback)); | 1218 .WillOnce(SaveArg<0>(&connect_callback)); |
| 1217 | 1219 |
| 1218 ExtensionTestMessageListener listener(true); | 1220 ExtensionTestMessageListener listener(true); |
| 1219 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( | 1221 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( |
| 1220 "bluetooth_low_energy/connect_in_progress"))); | 1222 "bluetooth_low_energy/connect_in_progress"))); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1305 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc2_.get()); | 1307 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc2_.get()); |
| 1306 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc1_.get()); | 1308 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc1_.get()); |
| 1307 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get()); | 1309 event_router()->GattCharacteristicRemoved(mock_adapter_, chrc0_.get()); |
| 1308 event_router()->GattServiceRemoved( | 1310 event_router()->GattServiceRemoved( |
| 1309 mock_adapter_, device0_.get(), service1_.get()); | 1311 mock_adapter_, device0_.get(), service1_.get()); |
| 1310 event_router()->GattServiceRemoved( | 1312 event_router()->GattServiceRemoved( |
| 1311 mock_adapter_, device0_.get(), service0_.get()); | 1313 mock_adapter_, device0_.get(), service0_.get()); |
| 1312 } | 1314 } |
| 1313 | 1315 |
| 1314 } // namespace | 1316 } // namespace |
| OLD | NEW |