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

Unified Diff: device/bluetooth/bluetooth_adapter_unittest.cc

Issue 1610053005: bluetooth: android: Fix a couple of crashes when adapter is turned on/off. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased on latest master Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/bluetooth_adapter_unittest.cc
diff --git a/device/bluetooth/bluetooth_adapter_unittest.cc b/device/bluetooth/bluetooth_adapter_unittest.cc
index 12351c95739d4594001a780ed285d937fb22c29c..45a52715063081346ddf7ad8df1f440132431b9b 100644
--- a/device/bluetooth/bluetooth_adapter_unittest.cc
+++ b/device/bluetooth/bluetooth_adapter_unittest.cc
@@ -479,6 +479,43 @@ TEST_F(BluetoothTest, DiscoverySession) {
}
#endif // defined(OS_ANDROID)
+// Android only: this test is specific for Android and should not be
+// enabled for other platforms.
+#if defined(OS_ANDROID)
+TEST_F(BluetoothTest, AdapterIllegalStateBeforeStartScan) {
+ if (!PlatformSupportsLowEnergy()) {
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
+ return;
+ }
+ InitWithFakeAdapter();
+ ForceIllegalStateException();
+ StartLowEnergyDiscoverySessionExpectedToFail();
+ EXPECT_EQ(0, callback_count_);
+ EXPECT_EQ(1, error_callback_count_);
+ EXPECT_FALSE(adapter_->IsDiscovering());
+}
+#endif // defined(OS_ANDROID)
+
+// Android only: this test is specific for Android and should not be
+// enabled for other platforms.
+#if defined(OS_ANDROID)
+TEST_F(BluetoothTest, AdapterIllegalStateBeforeStopScan) {
+ if (!PlatformSupportsLowEnergy()) {
+ LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
+ return;
+ }
+ InitWithFakeAdapter();
+ StartLowEnergyDiscoverySession();
+ EXPECT_EQ(1, callback_count_);
+ EXPECT_EQ(0, error_callback_count_);
+ EXPECT_TRUE(adapter_->IsDiscovering());
+ ForceIllegalStateException();
+ discovery_sessions_[0]->Stop(GetCallback(Call::EXPECTED),
+ GetErrorCallback(Call::NOT_EXPECTED));
+ EXPECT_FALSE(adapter_->IsDiscovering());
+}
+#endif // defined(OS_ANDROID)
+
#if defined(OS_ANDROID) || defined(OS_MACOSX)
// Checks that discovery fails (instead of hanging) when permissions are denied.
TEST_F(BluetoothTest, NoPermissions) {
@@ -616,4 +653,52 @@ TEST_F(BluetoothTest, DiscoverMultipleLowEnergyDevices) {
}
#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
+#if defined(OS_ANDROID)
+TEST_F(BluetoothTest, TogglePowerFakeAdapter) {
+ InitWithFakeAdapter();
+ ASSERT_TRUE(adapter_->IsPresent());
+ ASSERT_TRUE(adapter_->IsPowered());
+
+ // Check if power can be turned off.
+ adapter_->SetPowered(false, GetCallback(Call::EXPECTED),
+ GetErrorCallback(Call::NOT_EXPECTED));
+ EXPECT_FALSE(adapter_->IsPowered());
+
+ // Check if power can be turned on again.
+ adapter_->SetPowered(true, GetCallback(Call::EXPECTED),
+ GetErrorCallback(Call::NOT_EXPECTED));
+ EXPECT_TRUE(adapter_->IsPowered());
+}
+#endif // defined(OS_ANDROID)
+
+#if defined(OS_ANDROID)
+TEST_F(BluetoothTest, TogglePowerBeforeScan) {
+ InitWithFakeAdapter();
+ ASSERT_TRUE(adapter_->IsPresent());
+ ASSERT_TRUE(adapter_->IsPowered());
+
+ // Turn off adapter.
+ adapter_->SetPowered(false, GetCallback(Call::EXPECTED),
+ GetErrorCallback(Call::NOT_EXPECTED));
+ ASSERT_FALSE(adapter_->IsPowered());
+
+ // Try to perform a scan.
+ StartLowEnergyDiscoverySessionExpectedToFail();
+
+ // Turn on adapter.
+ adapter_->SetPowered(true, GetCallback(Call::EXPECTED),
+ GetErrorCallback(Call::NOT_EXPECTED));
+ ASSERT_TRUE(adapter_->IsPowered());
+
+ // Try to perform a scan again.
+ ResetEventCounts();
+ StartLowEnergyDiscoverySession();
+ EXPECT_EQ(1, callback_count_);
+ EXPECT_EQ(0, error_callback_count_);
+ EXPECT_TRUE(adapter_->IsDiscovering());
+ ASSERT_EQ((size_t)1, discovery_sessions_.size());
+ EXPECT_TRUE(discovery_sessions_[0]->IsActive());
+}
+#endif // defined(OS_ANDROID)
+
} // namespace device

Powered by Google App Engine
This is Rietveld 408576698