Commit c58e8f35 authored by Giovanni Ortuño Urquidi's avatar Giovanni Ortuño Urquidi Committed by Commit Bot

bluetooth: Add tests for powering off and removing the adapter while scanning

Also remove some unnecessary functions.

BUG=897996

Change-Id: I413001df24f29c5ccd4e3ed906727fd8152f0906
Reviewed-on: https://chromium-review.googlesource.com/c/1331287Reviewed-by: default avatarOvidio Henriquez <odejesush@chromium.org>
Commit-Queue: Giovanni Ortuño Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607762}
parent 6d6affc7
......@@ -232,11 +232,6 @@ class DEVICE_BLUETOOTH_EXPORT TestBluetoothAdapterClient
return adapter_object_paths_to_call_counts_[object_path].start_discovery;
}
void SimulateStartDiscoveryCompleted(const std::string& object_path_str) {
GetProperties(dbus::ObjectPath(object_path_str))
->discovering.ReplaceValueWithSetValue();
}
void SetNextStopDiscoveryResponse(const std::string& object_path_str,
bool response) {
dbus::ObjectPath object_path(object_path_str);
......@@ -251,11 +246,6 @@ class DEVICE_BLUETOOTH_EXPORT TestBluetoothAdapterClient
return adapter_object_paths_to_call_counts_[object_path].stop_discovery;
}
void SimulateStopDiscoveryCompleted(const std::string& object_path_str) {
GetProperties(dbus::ObjectPath(object_path_str))
->discovering.ReplaceValueWithSetValue();
}
// Helper methods to perform multiple common operations.
// Simultes adding an adapter and it changing its state to powered On.
......@@ -309,8 +299,6 @@ class DEVICE_BLUETOOTH_EXPORT TestBluetoothAdapterClient
std::move(callback).Run(Error(kUnknownAdapterError, "Unknown error"));
return;
}
GetProperties(object_path)->discovering.ReplaceSetValueForTesting(true);
std::move(callback).Run(base::nullopt);
}
......@@ -331,8 +319,6 @@ class DEVICE_BLUETOOTH_EXPORT TestBluetoothAdapterClient
std::move(callback).Run(Error(kUnknownAdapterError, "Unknown error"));
return;
}
GetProperties(object_path)->discovering.ReplaceSetValueForTesting(false);
std::move(callback).Run(base::nullopt);
}
......@@ -1166,8 +1152,8 @@ TEST_F(BluetoothSystemTest, StartScan_Succeeds) {
EXPECT_EQ(ScanStateVector(), on_scan_state_changed_states_);
ResetResults();
test_bluetooth_adapter_client_->SimulateStartDiscoveryCompleted(
kFooObjectPathStr);
test_bluetooth_adapter_client_->SimulateAdapterDiscoveringStateChanged(
kFooObjectPathStr, true);
EXPECT_EQ(mojom::BluetoothSystem::ScanState::kScanning,
GetScanStateAndWait(system));
......@@ -1296,8 +1282,8 @@ TEST_F(BluetoothSystemTest, StopScan_Succeeds) {
test_bluetooth_adapter_client_->SetNextStartDiscoveryResponse(
kFooObjectPathStr, true);
StartScanAndWait(system);
test_bluetooth_adapter_client_->SimulateStartDiscoveryCompleted(
kFooObjectPathStr);
test_bluetooth_adapter_client_->SimulateAdapterDiscoveringStateChanged(
kFooObjectPathStr, true);
EXPECT_EQ(mojom::BluetoothSystem::ScanState::kScanning,
GetScanStateAndWait(system));
ResetResults();
......@@ -1315,8 +1301,8 @@ TEST_F(BluetoothSystemTest, StopScan_Succeeds) {
EXPECT_EQ(ScanStateVector(), on_scan_state_changed_states_);
ResetResults();
test_bluetooth_adapter_client_->SimulateStopDiscoveryCompleted(
kFooObjectPathStr);
test_bluetooth_adapter_client_->SimulateAdapterDiscoveringStateChanged(
kFooObjectPathStr, false);
EXPECT_EQ(mojom::BluetoothSystem::ScanState::kNotScanning,
GetScanStateAndWait(system));
......@@ -1334,8 +1320,8 @@ TEST_F(BluetoothSystemTest, StopScan_Fails) {
test_bluetooth_adapter_client_->SetNextStartDiscoveryResponse(
kFooObjectPathStr, true);
StartScanAndWait(system);
test_bluetooth_adapter_client_->SimulateStartDiscoveryCompleted(
kFooObjectPathStr);
test_bluetooth_adapter_client_->SimulateAdapterDiscoveringStateChanged(
kFooObjectPathStr, true);
EXPECT_EQ(mojom::BluetoothSystem::ScanState::kScanning,
GetScanStateAndWait(system));
ResetResults();
......@@ -1397,8 +1383,8 @@ TEST_F(BluetoothSystemTest, StopScan_FailsDuringPowerOff) {
kFooObjectPathStr, true);
EXPECT_EQ(mojom::BluetoothSystem::StartScanResult::kSuccess,
StartScanAndWait(system));
test_bluetooth_adapter_client_->SimulateStartDiscoveryCompleted(
kFooObjectPathStr);
test_bluetooth_adapter_client_->SimulateAdapterDiscoveringStateChanged(
kFooObjectPathStr, true);
EXPECT_EQ(mojom::BluetoothSystem::ScanState::kScanning,
GetScanStateAndWait(system));
......@@ -1430,4 +1416,57 @@ TEST_F(BluetoothSystemTest, StopScan_FailsDuringPowerOff) {
on_state_changed_states_);
}
// Tests that the scan state is correctly updated if the adapter is removed
// during scanning.
TEST_F(BluetoothSystemTest, Scan_AdapterRemovedWhileScanning) {
test_bluetooth_adapter_client_->SimulatePoweredOnAdapter(kFooObjectPathStr);
auto system = CreateBluetoothSystem();
// Start scanning.
test_bluetooth_adapter_client_->SetNextStartDiscoveryResponse(
kFooObjectPathStr, true);
StartScanAndWait(system);
test_bluetooth_adapter_client_->SimulateAdapterDiscoveringStateChanged(
kFooObjectPathStr, true);
ASSERT_EQ(mojom::BluetoothSystem::ScanState::kScanning,
GetScanStateAndWait(system));
ResetResults();
// Remove the adapter. Scan state should change to kNotScanning.
test_bluetooth_adapter_client_->SimulateAdapterRemoved(kFooObjectPathStr);
EXPECT_EQ(mojom::BluetoothSystem::ScanState::kNotScanning,
GetScanStateAndWait(system));
EXPECT_EQ(ScanStateVector({mojom::BluetoothSystem::ScanState::kNotScanning}),
on_scan_state_changed_states_);
}
// Tests that the scan state is correctly updated if the adapter turns off
// during scanning.
TEST_F(BluetoothSystemTest, Scan_PowerOffWhileScanning) {
test_bluetooth_adapter_client_->SimulatePoweredOnAdapter(kFooObjectPathStr);
auto system = CreateBluetoothSystem();
// Start scanning.
test_bluetooth_adapter_client_->SetNextStartDiscoveryResponse(
kFooObjectPathStr, true);
StartScanAndWait(system);
test_bluetooth_adapter_client_->SimulateAdapterDiscoveringStateChanged(
kFooObjectPathStr, true);
ASSERT_EQ(mojom::BluetoothSystem::ScanState::kScanning,
GetScanStateAndWait(system));
ResetResults();
// Power off the adapter. Scan state should change to kNotScanning.
test_bluetooth_adapter_client_->SimulateAdapterPowerStateChanged(
kFooObjectPathStr, false);
EXPECT_EQ(mojom::BluetoothSystem::ScanState::kNotScanning,
GetScanStateAndWait(system));
EXPECT_EQ(ScanStateVector({mojom::BluetoothSystem::ScanState::kNotScanning}),
on_scan_state_changed_states_);
}
} // namespace device
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment