Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_apitest.cc

Issue 1287753002: bluetooth: Remove callback from BluetoothGattConnection::Disconnect (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/extension_apitest.h" 6 #include "chrome/browser/extensions/extension_apitest.h"
7 #include "device/bluetooth/test/mock_bluetooth_adapter.h" 7 #include "device/bluetooth/test/mock_bluetooth_adapter.h"
8 #include "device/bluetooth/test/mock_bluetooth_device.h" 8 #include "device/bluetooth/test/mock_bluetooth_device.h"
9 #include "device/bluetooth/test/mock_bluetooth_gatt_characteristic.h" 9 #include "device/bluetooth/test/mock_bluetooth_gatt_characteristic.h"
10 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h" 10 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h"
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 const std::string& device_address, 245 const std::string& device_address,
246 bool expect_disconnect) { 246 bool expect_disconnect) {
247 testing::NiceMock<MockBluetoothGattConnection>* conn = 247 testing::NiceMock<MockBluetoothGattConnection>* conn =
248 new testing::NiceMock<MockBluetoothGattConnection>(device_address); 248 new testing::NiceMock<MockBluetoothGattConnection>(device_address);
249 249 EXPECT_CALL(*conn, Disconnect()).Times(expect_disconnect ? 1 : 0);
250 if (expect_disconnect) {
251 EXPECT_CALL(*conn, Disconnect(_))
252 .Times(1)
253 .WillOnce(InvokeCallbackArgument<0>());
254 } else {
255 EXPECT_CALL(*conn, Disconnect(_)).Times(0);
256 }
257
258 return conn; 250 return conn;
259 } 251 }
260 252
261 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetServices) { 253 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, GetServices) {
262 ResultCatcher catcher; 254 ResultCatcher catcher;
263 catcher.RestrictToBrowserContext(browser()->profile()); 255 catcher.RestrictToBrowserContext(browser()->profile());
264 256
265 std::vector<BluetoothGattService*> services; 257 std::vector<BluetoothGattService*> services;
266 services.push_back(service0_.get()); 258 services.push_back(service0_.get());
267 services.push_back(service1_.get()); 259 services.push_back(service1_.get());
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 } 1197 }
1206 1198
1207 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ConnectInProgress) { 1199 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, ConnectInProgress) {
1208 ResultCatcher catcher; 1200 ResultCatcher catcher;
1209 catcher.RestrictToBrowserContext(browser()->profile()); 1201 catcher.RestrictToBrowserContext(browser()->profile());
1210 1202
1211 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress0)) 1203 EXPECT_CALL(*mock_adapter_, GetDevice(kTestLeDeviceAddress0))
1212 .WillRepeatedly(Return(device0_.get())); 1204 .WillRepeatedly(Return(device0_.get()));
1213 1205
1214 BluetoothDevice::GattConnectionCallback connect_callback; 1206 BluetoothDevice::GattConnectionCallback connect_callback;
1215 base::Closure disconnect_callback;
1216 1207
1217 testing::NiceMock<MockBluetoothGattConnection>* conn = 1208 testing::NiceMock<MockBluetoothGattConnection>* conn =
1218 new testing::NiceMock<MockBluetoothGattConnection>( 1209 new testing::NiceMock<MockBluetoothGattConnection>(
1219 kTestLeDeviceAddress0); 1210 kTestLeDeviceAddress0);
1220 scoped_ptr<BluetoothGattConnection> conn_ptr(conn); 1211 scoped_ptr<BluetoothGattConnection> conn_ptr(conn);
1221 EXPECT_CALL(*conn, Disconnect(_)) 1212 EXPECT_CALL(*conn, Disconnect()).Times(1);
1222 .Times(1)
1223 .WillOnce(SaveArg<0>(&disconnect_callback));
1224 1213
1225 EXPECT_CALL(*device0_, CreateGattConnection(_, _)) 1214 EXPECT_CALL(*device0_, CreateGattConnection(_, _))
1226 .Times(1) 1215 .Times(1)
1227 .WillOnce(SaveArg<0>(&connect_callback)); 1216 .WillOnce(SaveArg<0>(&connect_callback));
1228 1217
1229 ExtensionTestMessageListener listener(true); 1218 ExtensionTestMessageListener listener(true);
1230 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( 1219 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
1231 "bluetooth_low_energy/connect_in_progress"))); 1220 "bluetooth_low_energy/connect_in_progress")));
1232 1221
1233 EXPECT_TRUE(listener.WaitUntilSatisfied()); 1222 EXPECT_TRUE(listener.WaitUntilSatisfied());
1234 ASSERT_EQ("ready", listener.message()) << listener.message(); 1223 ASSERT_EQ("After 2nd connect fails due to 1st connect being in progress.",
1224 listener.message())
1225 << listener.message();
1226 listener.Reset();
1227
1235 connect_callback.Run(conn_ptr.Pass()); 1228 connect_callback.Run(conn_ptr.Pass());
1236
1237 listener.Reset();
1238 EXPECT_TRUE(listener.WaitUntilSatisfied()); 1229 EXPECT_TRUE(listener.WaitUntilSatisfied());
1239 ASSERT_EQ("ready", listener.message()) << listener.message(); 1230 ASSERT_EQ("After 2nd call to disconnect.", listener.message())
1240 disconnect_callback.Run(); 1231 << listener.message();
1241 1232
1242 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 1233 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
1243 } 1234 }
1244 1235
1245 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, StartStopNotifications) { 1236 IN_PROC_BROWSER_TEST_F(BluetoothLowEnergyApiTest, StartStopNotifications) {
1246 ResultCatcher catcher; 1237 ResultCatcher catcher;
1247 catcher.RestrictToBrowserContext(browser()->profile()); 1238 catcher.RestrictToBrowserContext(browser()->profile());
1248 1239
1249 event_router()->GattServiceAdded( 1240 event_router()->GattServiceAdded(
1250 mock_adapter_, device0_.get(), service0_.get()); 1241 mock_adapter_, device0_.get(), service0_.get());
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 catcher.RestrictToBrowserContext(browser()->profile()); 1322 catcher.RestrictToBrowserContext(browser()->profile());
1332 1323
1333 // Run the test. 1324 // Run the test.
1334 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( 1325 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
1335 "bluetooth_low_energy/register_advertisement"))); 1326 "bluetooth_low_energy/register_advertisement")));
1336 1327
1337 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 1328 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
1338 } 1329 }
1339 1330
1340 } // namespace 1331 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698