fast_pair_support_utils_unittest.cc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/quick_pair/feature_status_tracker/fast_pair_support_utils.h"
  5. #include "ash/constants/ash_features.h"
  6. #include "ash/quick_pair/feature_status_tracker/fake_bluetooth_adapter.h"
  7. #include "base/memory/scoped_refptr.h"
  8. #include "base/test/scoped_feature_list.h"
  9. #include "testing/gtest/include/gtest/gtest.h"
  10. namespace ash {
  11. namespace quick_pair {
  12. class FastPairSupportUtilsTest : public testing::Test {
  13. public:
  14. void SetUp() override {
  15. adapter_ = base::MakeRefCounted<FakeBluetoothAdapter>();
  16. }
  17. protected:
  18. scoped_refptr<FakeBluetoothAdapter> adapter_;
  19. };
  20. TEST_F(FastPairSupportUtilsTest, HasHardwareSupportForHardwareState) {
  21. EXPECT_TRUE(HasHardwareSupport(adapter_));
  22. adapter_->SetHardwareOffloadingStatus(
  23. device::BluetoothAdapter::LowEnergyScanSessionHardwareOffloadingStatus::
  24. kNotSupported);
  25. EXPECT_FALSE(HasHardwareSupport(adapter_));
  26. adapter_->SetHardwareOffloadingStatus(
  27. device::BluetoothAdapter::LowEnergyScanSessionHardwareOffloadingStatus::
  28. kSupported);
  29. EXPECT_TRUE(HasHardwareSupport(adapter_));
  30. }
  31. TEST_F(FastPairSupportUtilsTest, HasHardwareSupportForFlagState) {
  32. EXPECT_TRUE(HasHardwareSupport(adapter_));
  33. adapter_->SetHardwareOffloadingStatus(
  34. device::BluetoothAdapter::LowEnergyScanSessionHardwareOffloadingStatus::
  35. kNotSupported);
  36. EXPECT_FALSE(HasHardwareSupport(adapter_));
  37. base::test::ScopedFeatureList feature_list{
  38. features::kFastPairSoftwareScanning};
  39. EXPECT_TRUE(HasHardwareSupport(adapter_));
  40. }
  41. TEST_F(FastPairSupportUtilsTest, HasHardwareSupportFalseForAdapterState) {
  42. EXPECT_TRUE(HasHardwareSupport(adapter_));
  43. adapter_->SetBluetoothIsPresent(false);
  44. EXPECT_FALSE(HasHardwareSupport(adapter_));
  45. scoped_refptr<FakeBluetoothAdapter> null_adapter;
  46. EXPECT_FALSE(HasHardwareSupport(null_adapter));
  47. }
  48. } // namespace quick_pair
  49. } // namespace ash