| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
| 6 #include "device/bluetooth/bluetooth_adapter_android.h" | 6 #include "device/bluetooth/bluetooth_adapter_android.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 namespace device { | 9 namespace device { |
| 10 | 10 |
| 11 class BluetoothAdapterAndroidTest : public testing::Test { | 11 class BluetoothAdapterAndroidTest : public testing::Test { |
| 12 protected: | 12 protected: |
| 13 void InitWithPermission() { | 13 void InitWithPermission() { |
| 14 adapter_ = BluetoothAdapterAndroid::CreateAdapter().get(); | 14 adapter_ = BluetoothAdapterAndroid::CreateAdapter().get(); |
| 15 } | 15 } |
| 16 | 16 |
| 17 void InitWithoutPermission() { | 17 void InitWithoutPermission() { |
| 18 adapter_ = | 18 adapter_ = |
| 19 BluetoothAdapterAndroid::CreateAdapterWithoutPermissionForTesting() | 19 BluetoothAdapterAndroid::CreateAdapterWithoutPermissionForTesting() |
| 20 .get(); | 20 .get(); |
| 21 } | 21 } |
| 22 | 22 |
| 23 scoped_refptr<BluetoothAdapterAndroid> adapter_; | 23 scoped_refptr<BluetoothAdapterAndroid> adapter_; |
| 24 }; | 24 }; |
| 25 | 25 |
| 26 TEST_F(BluetoothAdapterAndroidTest, Construct) { | 26 TEST_F(BluetoothAdapterAndroidTest, Construct) { |
| 27 InitWithPermission(); | 27 InitWithPermission(); |
| 28 ASSERT_TRUE(adapter_.get()); | 28 ASSERT_TRUE(adapter_.get()); |
| 29 EXPECT_TRUE(adapter_->HasBluetoothPermission()); | 29 EXPECT_TRUE(adapter_->HasBluetoothCapability()); |
| 30 if (!adapter_->IsPresent()) { | 30 if (!adapter_->IsPresent()) { |
| 31 LOG(WARNING) << "Bluetooth adapter not present; skipping unit test."; | 31 LOG(WARNING) << "Bluetooth adapter not present; skipping unit test."; |
| 32 return; | 32 return; |
| 33 } | 33 } |
| 34 EXPECT_GT(adapter_->GetAddress().length(), 0u); | 34 EXPECT_GT(adapter_->GetAddress().length(), 0u); |
| 35 EXPECT_GT(adapter_->GetName().length(), 0u); | 35 EXPECT_GT(adapter_->GetName().length(), 0u); |
| 36 EXPECT_TRUE(adapter_->IsPresent()); | 36 EXPECT_TRUE(adapter_->IsPresent()); |
| 37 // Don't know on test machines if adapter will be powered or not, but | 37 // Don't know on test machines if adapter will be powered or not, but |
| 38 // the call should be safe to make and consistent. | 38 // the call should be safe to make and consistent. |
| 39 EXPECT_EQ(adapter_->IsPowered(), adapter_->IsPowered()); | 39 EXPECT_EQ(adapter_->IsPowered(), adapter_->IsPowered()); |
| 40 EXPECT_FALSE(adapter_->IsDiscoverable()); | 40 EXPECT_FALSE(adapter_->IsDiscoverable()); |
| 41 EXPECT_FALSE(adapter_->IsDiscovering()); | 41 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 42 } | 42 } |
| 43 | 43 |
| 44 TEST_F(BluetoothAdapterAndroidTest, ConstructNoPermision) { | 44 TEST_F(BluetoothAdapterAndroidTest, ConstructNoPermision) { |
| 45 InitWithoutPermission(); | 45 InitWithoutPermission(); |
| 46 ASSERT_TRUE(adapter_.get()); | 46 ASSERT_TRUE(adapter_.get()); |
| 47 EXPECT_FALSE(adapter_->HasBluetoothPermission()); | 47 EXPECT_FALSE(adapter_->HasBluetoothCapability()); |
| 48 EXPECT_EQ(adapter_->GetAddress().length(), 0u); | 48 EXPECT_EQ(adapter_->GetAddress().length(), 0u); |
| 49 EXPECT_EQ(adapter_->GetName().length(), 0u); | 49 EXPECT_EQ(adapter_->GetName().length(), 0u); |
| 50 EXPECT_FALSE(adapter_->IsPresent()); | 50 EXPECT_FALSE(adapter_->IsPresent()); |
| 51 EXPECT_FALSE(adapter_->IsPowered()); | 51 EXPECT_FALSE(adapter_->IsPowered()); |
| 52 EXPECT_FALSE(adapter_->IsDiscoverable()); | 52 EXPECT_FALSE(adapter_->IsDiscoverable()); |
| 53 EXPECT_FALSE(adapter_->IsDiscovering()); | 53 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 54 } | 54 } |
| 55 | 55 |
| 56 } // namespace device | 56 } // namespace device |
| OLD | NEW |