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/memory/scoped_vector.h" | 5 #include "base/memory/scoped_vector.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chromeos/dbus/dbus_thread_manager.h" | 8 #include "chromeos/dbus/dbus_thread_manager.h" |
9 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" | 9 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" |
10 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" | 10 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" |
(...skipping 3294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3305 // Calling GetConnectionInfo for a connected device should return valid | 3305 // Calling GetConnectionInfo for a connected device should return valid |
3306 // results. | 3306 // results. |
3307 fake_bluetooth_device_client_->UpdateConnectionInfo(-10, 3, 4); | 3307 fake_bluetooth_device_client_->UpdateConnectionInfo(-10, 3, 4); |
3308 BluetoothDevice::ConnectionInfo conn_info; | 3308 BluetoothDevice::ConnectionInfo conn_info; |
3309 device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info)); | 3309 device->GetConnectionInfo(base::Bind(&SaveConnectionInfo, &conn_info)); |
3310 EXPECT_EQ(-10, conn_info.rssi); | 3310 EXPECT_EQ(-10, conn_info.rssi); |
3311 EXPECT_EQ(3, conn_info.transmit_power); | 3311 EXPECT_EQ(3, conn_info.transmit_power); |
3312 EXPECT_EQ(4, conn_info.max_transmit_power); | 3312 EXPECT_EQ(4, conn_info.max_transmit_power); |
3313 } | 3313 } |
3314 | 3314 |
| 3315 // Verifies Shutdown shuts down the adapter as expected. |
| 3316 TEST_F(BluetoothChromeOSTest, Shutdown) { |
| 3317 // Set up and adapter, power, discoverable, start discovery. |
| 3318 GetAdapter(); |
| 3319 adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, |
| 3320 base::Unretained(this)), |
| 3321 base::Bind(&BluetoothChromeOSTest::ErrorCallback, |
| 3322 base::Unretained(this))); |
| 3323 adapter_->SetDiscoverable(true, base::Bind(&BluetoothChromeOSTest::Callback, |
| 3324 base::Unretained(this)), |
| 3325 base::Bind(&BluetoothChromeOSTest::ErrorCallback, |
| 3326 base::Unretained(this))); |
| 3327 adapter_->StartDiscoverySession( |
| 3328 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
| 3329 base::Unretained(this)), |
| 3330 base::Bind(&BluetoothChromeOSTest::ErrorCallback, |
| 3331 base::Unretained(this))); |
| 3332 base::MessageLoop::current()->Run(); |
| 3333 ASSERT_EQ(3, callback_count_); |
| 3334 ASSERT_EQ(0, error_callback_count_); |
| 3335 callback_count_ = 0; |
| 3336 |
| 3337 // Validate running adapter state. |
| 3338 EXPECT_NE("", adapter_->GetAddress()); |
| 3339 EXPECT_NE("", adapter_->GetName()); |
| 3340 EXPECT_TRUE(adapter_->IsInitialized()); |
| 3341 EXPECT_TRUE(adapter_->IsPresent()); |
| 3342 EXPECT_TRUE(adapter_->IsPowered()); |
| 3343 EXPECT_TRUE(adapter_->IsDiscoverable()); |
| 3344 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 3345 EXPECT_EQ(1U, adapter_->GetDevices().size()); |
| 3346 EXPECT_NE(nullptr, adapter_->GetDevice( |
| 3347 FakeBluetoothDeviceClient::kPairedDeviceAddress)); |
| 3348 EXPECT_NE(dbus::ObjectPath(""), static_cast<BluetoothAdapterChromeOS*>( |
| 3349 adapter_.get())->object_path()); |
| 3350 |
| 3351 // Shutdown |
| 3352 static_cast<BluetoothAdapterChromeOS*>(adapter_.get())->Shutdown(); |
| 3353 |
| 3354 // Validate post shutdown state. |
| 3355 EXPECT_EQ("", adapter_->GetAddress()); |
| 3356 EXPECT_EQ("", adapter_->GetName()); |
| 3357 EXPECT_TRUE(adapter_->IsInitialized()); |
| 3358 EXPECT_FALSE(adapter_->IsPresent()); |
| 3359 EXPECT_FALSE(adapter_->IsPowered()); |
| 3360 EXPECT_FALSE(adapter_->IsDiscoverable()); |
| 3361 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 3362 EXPECT_EQ(0U, adapter_->GetDevices().size()); |
| 3363 EXPECT_EQ(nullptr, adapter_->GetDevice( |
| 3364 FakeBluetoothDeviceClient::kPairedDeviceAddress)); |
| 3365 EXPECT_EQ(dbus::ObjectPath(""), static_cast<BluetoothAdapterChromeOS*>( |
| 3366 adapter_.get())->object_path()); |
| 3367 |
| 3368 adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback, |
| 3369 base::Unretained(this)), |
| 3370 base::Bind(&BluetoothChromeOSTest::ErrorCallback, |
| 3371 base::Unretained(this))); |
| 3372 adapter_->SetDiscoverable(true, base::Bind(&BluetoothChromeOSTest::Callback, |
| 3373 base::Unretained(this)), |
| 3374 base::Bind(&BluetoothChromeOSTest::ErrorCallback, |
| 3375 base::Unretained(this))); |
| 3376 adapter_->StartDiscoverySession( |
| 3377 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, |
| 3378 base::Unretained(this)), |
| 3379 base::Bind(&BluetoothChromeOSTest::ErrorCallback, |
| 3380 base::Unretained(this))); |
| 3381 ASSERT_EQ(0, callback_count_); |
| 3382 ASSERT_EQ(3, error_callback_count_); |
| 3383 } |
| 3384 |
3315 } // namespace chromeos | 3385 } // namespace chromeos |
OLD | NEW |