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

Unified Diff: device/bluetooth/bluetooth_adapter_android_unittest.cc

Issue 1129683002: bluetooth: Android adapter can be created with and without Bluetooth permission. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bta-jni-
Patch Set: Reland: IsPowered may be false on test infra. Created 5 years, 7 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
« no previous file with comments | « device/bluetooth/bluetooth_adapter_android.cc ('k') | testing/android/native_test/java/AndroidManifest.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/bluetooth_adapter_android_unittest.cc
diff --git a/device/bluetooth/bluetooth_adapter_android_unittest.cc b/device/bluetooth/bluetooth_adapter_android_unittest.cc
index c4d5252e339c7a99f97c059bccfed78af6695902..fcc9516fe8ba42e1f8839ee95d9234ef554cf088 100644
--- a/device/bluetooth/bluetooth_adapter_android_unittest.cc
+++ b/device/bluetooth/bluetooth_adapter_android_unittest.cc
@@ -10,16 +10,47 @@ namespace device {
class BluetoothAdapterAndroidTest : public testing::Test {
protected:
- BluetoothAdapterAndroidTest() {
+ void InitWithPermission() {
adapter_ = BluetoothAdapterAndroid::CreateAdapter().get();
}
+ void InitWithoutPermission() {
+ adapter_ =
+ BluetoothAdapterAndroid::CreateAdapterWithoutPermissionForTesting()
+ .get();
+ }
+
scoped_refptr<BluetoothAdapterAndroid> adapter_;
};
TEST_F(BluetoothAdapterAndroidTest, Construct) {
+ InitWithPermission();
+ ASSERT_TRUE(adapter_.get());
+ EXPECT_TRUE(adapter_->HasBluetoothPermission());
+ if (!adapter_->IsPresent()) {
+ LOG(WARNING) << "Bluetooth adapter not present; skipping unit test.";
+ return;
+ }
+ EXPECT_GT(adapter_->GetAddress().length(), 0u);
+ EXPECT_GT(adapter_->GetName().length(), 0u);
+ EXPECT_TRUE(adapter_->IsPresent());
+ // Don't know on test machines if adapter will be powered or not, but
+ // the call should be safe to make and consistent.
+ EXPECT_EQ(adapter_->IsPowered(), adapter_->IsPowered());
+ EXPECT_FALSE(adapter_->IsDiscoverable());
+ EXPECT_FALSE(adapter_->IsDiscovering());
+}
+
+TEST_F(BluetoothAdapterAndroidTest, ConstructNoPermision) {
+ InitWithoutPermission();
ASSERT_TRUE(adapter_.get());
EXPECT_FALSE(adapter_->HasBluetoothPermission());
+ EXPECT_EQ(adapter_->GetAddress().length(), 0u);
+ EXPECT_EQ(adapter_->GetName().length(), 0u);
+ EXPECT_FALSE(adapter_->IsPresent());
+ EXPECT_FALSE(adapter_->IsPowered());
+ EXPECT_FALSE(adapter_->IsDiscoverable());
+ EXPECT_FALSE(adapter_->IsDiscovering());
}
} // namespace device
« no previous file with comments | « device/bluetooth/bluetooth_adapter_android.cc ('k') | testing/android/native_test/java/AndroidManifest.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698