| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" | 7 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" |
| 8 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" | 8 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" |
| 9 #include "chromeos/dbus/fake_bluetooth_device_client.h" | 9 #include "chromeos/dbus/fake_bluetooth_device_client.h" |
| 10 #include "chromeos/dbus/fake_bluetooth_input_client.h" | 10 #include "chromeos/dbus/fake_bluetooth_input_client.h" |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 | 239 |
| 240 fake_bluetooth_adapter_client_->SetSimulationIntervalMs(10); | 240 fake_bluetooth_adapter_client_->SetSimulationIntervalMs(10); |
| 241 | 241 |
| 242 callback_count_ = 0; | 242 callback_count_ = 0; |
| 243 error_callback_count_ = 0; | 243 error_callback_count_ = 0; |
| 244 last_connect_error_ = BluetoothDevice::ERROR_UNKNOWN; | 244 last_connect_error_ = BluetoothDevice::ERROR_UNKNOWN; |
| 245 last_client_error_ = ""; | 245 last_client_error_ = ""; |
| 246 } | 246 } |
| 247 | 247 |
| 248 virtual void TearDown() { | 248 virtual void TearDown() { |
| 249 if (last_discovery_session_.get() && last_discovery_session_->active()) { | 249 if (last_discovery_session_.get() && last_discovery_session_->IsActive()) { |
| 250 callback_count_ = 0; | 250 callback_count_ = 0; |
| 251 last_discovery_session_->Stop( | 251 last_discovery_session_->Stop( |
| 252 base::Bind(&BluetoothChromeOSTest::Callback, | 252 base::Bind(&BluetoothChromeOSTest::Callback, |
| 253 base::Unretained(this)), | 253 base::Unretained(this)), |
| 254 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 254 base::Bind(&BluetoothChromeOSTest::ErrorCallback, |
| 255 base::Unretained(this))); | 255 base::Unretained(this))); |
| 256 message_loop_.Run(); | 256 message_loop_.Run(); |
| 257 ASSERT_EQ(1, callback_count_); | 257 ASSERT_EQ(1, callback_count_); |
| 258 } | 258 } |
| 259 last_discovery_session_.reset(); | 259 last_discovery_session_.reset(); |
| (...skipping 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1316 base::Unretained(this)), | 1316 base::Unretained(this)), |
| 1317 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1317 base::Bind(&BluetoothChromeOSTest::ErrorCallback, |
| 1318 base::Unretained(this))); | 1318 base::Unretained(this))); |
| 1319 message_loop_.Run(); | 1319 message_loop_.Run(); |
| 1320 EXPECT_EQ(1, observer.discovering_changed_count_); | 1320 EXPECT_EQ(1, observer.discovering_changed_count_); |
| 1321 EXPECT_EQ(1, callback_count_); | 1321 EXPECT_EQ(1, callback_count_); |
| 1322 EXPECT_EQ(0, error_callback_count_); | 1322 EXPECT_EQ(0, error_callback_count_); |
| 1323 EXPECT_TRUE(observer.last_discovering_); | 1323 EXPECT_TRUE(observer.last_discovering_); |
| 1324 EXPECT_TRUE(adapter_->IsDiscovering()); | 1324 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1325 EXPECT_TRUE(last_discovery_session_.get()); | 1325 EXPECT_TRUE(last_discovery_session_.get()); |
| 1326 EXPECT_TRUE(last_discovery_session_->active()); | 1326 EXPECT_TRUE(last_discovery_session_->IsActive()); |
| 1327 | 1327 |
| 1328 // Start another session. A new one should be returned in the callback, which | 1328 // Start another session. A new one should be returned in the callback, which |
| 1329 // in turn will destroy the previous session. Adapter should still be | 1329 // in turn will destroy the previous session. Adapter should still be |
| 1330 // discovering and the reference count should be 1. | 1330 // discovering and the reference count should be 1. |
| 1331 adapter_->StartDiscoverySession( | 1331 adapter_->StartDiscoverySession( |
| 1332 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1332 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
| 1333 base::Unretained(this)), | 1333 base::Unretained(this)), |
| 1334 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1334 base::Bind(&BluetoothChromeOSTest::ErrorCallback, |
| 1335 base::Unretained(this))); | 1335 base::Unretained(this))); |
| 1336 message_loop_.Run(); | 1336 message_loop_.Run(); |
| 1337 EXPECT_EQ(1, observer.discovering_changed_count_); | 1337 EXPECT_EQ(1, observer.discovering_changed_count_); |
| 1338 EXPECT_EQ(2, callback_count_); | 1338 EXPECT_EQ(2, callback_count_); |
| 1339 EXPECT_EQ(0, error_callback_count_); | 1339 EXPECT_EQ(0, error_callback_count_); |
| 1340 EXPECT_TRUE(observer.last_discovering_); | 1340 EXPECT_TRUE(observer.last_discovering_); |
| 1341 EXPECT_TRUE(adapter_->IsDiscovering()); | 1341 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1342 EXPECT_TRUE(last_discovery_session_.get()); | 1342 EXPECT_TRUE(last_discovery_session_.get()); |
| 1343 EXPECT_TRUE(last_discovery_session_->active()); | 1343 EXPECT_TRUE(last_discovery_session_->IsActive()); |
| 1344 | 1344 |
| 1345 // Hold on to the current discovery session to prevent it from getting | 1345 // Hold on to the current discovery session to prevent it from getting |
| 1346 // destroyed during the next call to StartDiscoverySession. | 1346 // destroyed during the next call to StartDiscoverySession. |
| 1347 scoped_ptr<BluetoothDiscoverySession> discovery_session = | 1347 scoped_ptr<BluetoothDiscoverySession> discovery_session = |
| 1348 last_discovery_session_.Pass(); | 1348 last_discovery_session_.Pass(); |
| 1349 | 1349 |
| 1350 // Request a new session. | 1350 // Request a new session. |
| 1351 adapter_->StartDiscoverySession( | 1351 adapter_->StartDiscoverySession( |
| 1352 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, | 1352 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
| 1353 base::Unretained(this)), | 1353 base::Unretained(this)), |
| 1354 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1354 base::Bind(&BluetoothChromeOSTest::ErrorCallback, |
| 1355 base::Unretained(this))); | 1355 base::Unretained(this))); |
| 1356 message_loop_.Run(); | 1356 message_loop_.Run(); |
| 1357 EXPECT_EQ(1, observer.discovering_changed_count_); | 1357 EXPECT_EQ(1, observer.discovering_changed_count_); |
| 1358 EXPECT_EQ(3, callback_count_); | 1358 EXPECT_EQ(3, callback_count_); |
| 1359 EXPECT_EQ(0, error_callback_count_); | 1359 EXPECT_EQ(0, error_callback_count_); |
| 1360 EXPECT_TRUE(observer.last_discovering_); | 1360 EXPECT_TRUE(observer.last_discovering_); |
| 1361 EXPECT_TRUE(adapter_->IsDiscovering()); | 1361 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1362 EXPECT_TRUE(last_discovery_session_.get()); | 1362 EXPECT_TRUE(last_discovery_session_.get()); |
| 1363 EXPECT_TRUE(last_discovery_session_->active()); | 1363 EXPECT_TRUE(last_discovery_session_->IsActive()); |
| 1364 EXPECT_NE(last_discovery_session_.get(), discovery_session); | 1364 EXPECT_NE(last_discovery_session_.get(), discovery_session); |
| 1365 | 1365 |
| 1366 // Stop the previous discovery session. The session should end but discovery | 1366 // Stop the previous discovery session. The session should end but discovery |
| 1367 // should continue. | 1367 // should continue. |
| 1368 discovery_session->Stop( | 1368 discovery_session->Stop( |
| 1369 base::Bind(&BluetoothChromeOSTest::Callback, | 1369 base::Bind(&BluetoothChromeOSTest::Callback, |
| 1370 base::Unretained(this)), | 1370 base::Unretained(this)), |
| 1371 base::Bind(&BluetoothChromeOSTest::ErrorCallback, | 1371 base::Bind(&BluetoothChromeOSTest::ErrorCallback, |
| 1372 base::Unretained(this))); | 1372 base::Unretained(this))); |
| 1373 message_loop_.Run(); | 1373 message_loop_.Run(); |
| 1374 EXPECT_EQ(1, observer.discovering_changed_count_); | 1374 EXPECT_EQ(1, observer.discovering_changed_count_); |
| 1375 EXPECT_EQ(4, callback_count_); | 1375 EXPECT_EQ(4, callback_count_); |
| 1376 EXPECT_EQ(0, error_callback_count_); | 1376 EXPECT_EQ(0, error_callback_count_); |
| 1377 EXPECT_TRUE(observer.last_discovering_); | 1377 EXPECT_TRUE(observer.last_discovering_); |
| 1378 EXPECT_TRUE(adapter_->IsDiscovering()); | 1378 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1379 EXPECT_TRUE(last_discovery_session_.get()); | 1379 EXPECT_TRUE(last_discovery_session_.get()); |
| 1380 EXPECT_TRUE(last_discovery_session_->active()); | 1380 EXPECT_TRUE(last_discovery_session_->IsActive()); |
| 1381 EXPECT_FALSE(discovery_session->active()); | 1381 EXPECT_FALSE(discovery_session->IsActive()); |
| 1382 | 1382 |
| 1383 // Delete the current active session. Discovery should eventually stop. | 1383 // Delete the current active session. Discovery should eventually stop. |
| 1384 last_discovery_session_.reset(); | 1384 last_discovery_session_.reset(); |
| 1385 while (observer.last_discovering_) { | 1385 while (observer.last_discovering_) { |
| 1386 message_loop_.RunUntilIdle(); | 1386 message_loop_.RunUntilIdle(); |
| 1387 } | 1387 } |
| 1388 EXPECT_EQ(2, observer.discovering_changed_count_); | 1388 EXPECT_EQ(2, observer.discovering_changed_count_); |
| 1389 EXPECT_EQ(4, callback_count_); | 1389 EXPECT_EQ(4, callback_count_); |
| 1390 EXPECT_EQ(0, error_callback_count_); | 1390 EXPECT_EQ(0, error_callback_count_); |
| 1391 EXPECT_FALSE(observer.last_discovering_); | 1391 EXPECT_FALSE(observer.last_discovering_); |
| (...skipping 1696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3088 device->SetPasskey(1234); | 3088 device->SetPasskey(1234); |
| 3089 | 3089 |
| 3090 EXPECT_EQ(0, callback_count_); | 3090 EXPECT_EQ(0, callback_count_); |
| 3091 EXPECT_EQ(0, error_callback_count_); | 3091 EXPECT_EQ(0, error_callback_count_); |
| 3092 EXPECT_EQ(0, observer.device_changed_count_); | 3092 EXPECT_EQ(0, observer.device_changed_count_); |
| 3093 | 3093 |
| 3094 EXPECT_FALSE(device->IsPaired()); | 3094 EXPECT_FALSE(device->IsPaired()); |
| 3095 } | 3095 } |
| 3096 | 3096 |
| 3097 } // namespace chromeos | 3097 } // namespace chromeos |
| OLD | NEW |