diff --git a/fastpair/dart/BUILD b/fastpair/dart/BUILD index 6df3e492..e9dc578c 100644 --- a/fastpair/dart/BUILD +++ b/fastpair/dart/BUILD @@ -29,7 +29,8 @@ cc_library( "//fastpair:__subpackages__", ], deps = [ - "//fastpair/scanning/fastpair:scanning", + "//fastpair/common", + "//fastpair/scanning:scanner", "//internal/platform:logging", "//internal/platform/implementation:types", ], diff --git a/fastpair/dart/fast_pair_wrapper_impl.cc b/fastpair/dart/fast_pair_wrapper_impl.cc index f0ebfe98..de235a75 100644 --- a/fastpair/dart/fast_pair_wrapper_impl.cc +++ b/fastpair/dart/fast_pair_wrapper_impl.cc @@ -16,8 +16,10 @@ #include -#include "fastpair/scanning/fastpair/fast_pair_scanner_impl.h" + +#include "fastpair/scanning/scanner_broker_impl.h" #include "internal/platform/logging.h" +#include "fastpair/common/protocol.h" namespace nearby { namespace fastpair { @@ -28,13 +30,13 @@ FastPairWrapperImpl::FastPairWrapperImpl() { FastPairWrapperImpl::~FastPairWrapperImpl() = default; void FastPairWrapperImpl::StartScan() { - scanner_ = std::make_unique(); + scanner_broker_ = std::make_unique(); if (is_scanning_) { NEARBY_LOGS(VERBOSE) << __func__ << ": We're currently scanning. "; return; } is_scanning_ = true; - scanner_->StartScanning(); + scanner_broker_->StartScanning(Protocol::kFastPairInitialPairing); } bool FastPairWrapperImpl::IsScanning() { return is_scanning_; } diff --git a/fastpair/dart/fast_pair_wrapper_impl.h b/fastpair/dart/fast_pair_wrapper_impl.h index 2b18e78c..9589303b 100644 --- a/fastpair/dart/fast_pair_wrapper_impl.h +++ b/fastpair/dart/fast_pair_wrapper_impl.h @@ -19,14 +19,14 @@ #include #include "fastpair/dart/fast_pair_wrapper.h" -#include "fastpair/scanning/fastpair/fast_pair_scanner_impl.h" +#include "fastpair/scanning/scanner_broker.h" namespace nearby { namespace fastpair { class FastPairScannerImpl; -class FastPairWrapperImpl : public FastPairWrapper, public FastPairScannerImpl { +class FastPairWrapperImpl : public FastPairWrapper { public: explicit FastPairWrapperImpl(); ~FastPairWrapperImpl() override; @@ -37,7 +37,7 @@ class FastPairWrapperImpl : public FastPairWrapper, public FastPairScannerImpl { void StartScan() override; private: - std::unique_ptr scanner_; + std::unique_ptr scanner_broker_; // True if we are currently scanning for remote devices. bool is_scanning_ = false; diff --git a/fastpair/scanning/BUILD b/fastpair/scanning/BUILD index 757f100e..bca6d0c3 100644 --- a/fastpair/scanning/BUILD +++ b/fastpair/scanning/BUILD @@ -41,6 +41,23 @@ cc_library( ], ) +cc_library( + name = "mocks", + testonly = 1, + hdrs = [ + "mock_scanner_broker.h", + ], + visibility = [ + "//fastpair:__subpackages__", + ], + deps = [ + ":scanner", + "//fastpair/common", + "//internal/base", + "@com_google_googletest//:gtest_for_library_testonly", + ], +) + cc_test( name = "scanner_broker_impl_test", size = "small", @@ -54,8 +71,10 @@ cc_test( "//fastpair/scanning/fastpair:scanning", "//fastpair/scanning/fastpair:test_support", "//internal/platform:test_util", + "//internal/platform/implementation:types", "//internal/platform/implementation/g3", # build_cleaner: keep "@com_github_protobuf_matchers//protobuf-matchers", + "@com_google_absl//absl/strings", "@com_google_absl//absl/time", "@com_google_googletest//:gtest_main", ], diff --git a/fastpair/scanning/fastpair/BUILD b/fastpair/scanning/fastpair/BUILD index 337391a1..a6e18638 100644 --- a/fastpair/scanning/fastpair/BUILD +++ b/fastpair/scanning/fastpair/BUILD @@ -99,6 +99,7 @@ cc_test( shard_count = 16, deps = [ ":scanning", + ":test_support", "//fastpair/dataparser", "//fastpair/server_access:test_support", "//fastpair/testing", diff --git a/fastpair/scanning/fastpair/fake_fast_pair_scanner.h b/fastpair/scanning/fastpair/fake_fast_pair_scanner.h index 90cd7c95..960bf83f 100644 --- a/fastpair/scanning/fastpair/fake_fast_pair_scanner.h +++ b/fastpair/scanning/fastpair/fake_fast_pair_scanner.h @@ -26,6 +26,7 @@ class FakeFastPairScanner final : public FastPairScanner { FakeFastPairScanner() = default; FakeFastPairScanner(const FakeFastPairScanner&) = delete; FakeFastPairScanner& operator=(const FakeFastPairScanner&) = delete; + ~FakeFastPairScanner() override = default; void AddObserver(Observer* observer) override; void RemoveObserver(Observer* observer) override; @@ -33,8 +34,6 @@ class FakeFastPairScanner final : public FastPairScanner { void NotifyDeviceLost(const BlePeripheral& peripheral); private: - ~FakeFastPairScanner() override = default; - ObserverList observer_; }; diff --git a/fastpair/scanning/fastpair/fast_pair_discoverable_scanner_impl_test.cc b/fastpair/scanning/fastpair/fast_pair_discoverable_scanner_impl_test.cc index c502f534..883ff12f 100644 --- a/fastpair/scanning/fastpair/fast_pair_discoverable_scanner_impl_test.cc +++ b/fastpair/scanning/fastpair/fast_pair_discoverable_scanner_impl_test.cc @@ -23,11 +23,10 @@ #include "protobuf-matchers/protocol-buffer-matchers.h" #include "gtest/gtest.h" #include "absl/synchronization/notification.h" -#include "fastpair/scanning/fastpair/fast_pair_scanner_impl.h" +#include "fastpair/scanning/fastpair/fake_fast_pair_scanner.h" #include "fastpair/server_access/fake_fast_pair_repository.h" #include "fastpair/testing/fast_pair_service_data_creator.h" #include "internal/platform/bluetooth_adapter.h" -#include "internal/platform/medium_environment.h" namespace nearby { namespace fastpair { @@ -79,10 +78,16 @@ class FastPairDiscoverableScannerImplTest : public testing::Test { public: void SetUp() override { SetUpMetadata(); - scanner_ = std::make_shared(); + scanner_ = std::make_shared(); adapter_ = std::make_shared(); } + void TearDown() override { + scanner_.reset(); + adapter_.reset(); + repository_.reset(); + } + void SetUpMetadata() { repository_ = std::make_unique(); proto::Device metadata; @@ -93,7 +98,7 @@ class FastPairDiscoverableScannerImplTest : public testing::Test { // void TearDown() override { discoverable_scanner_.reset(); } protected: - std::shared_ptr scanner_; + std::shared_ptr scanner_; std::unique_ptr repository_; std::shared_ptr adapter_; DeviceCallback found_device_callback_; @@ -117,9 +122,9 @@ TEST_F(FastPairDiscoverableScannerImplTest, ValidModelId) { auto ble_peripheral = std::make_unique(kTestBleDeviceAddress, kValidModelId); - scanner_->OnDeviceFound(BlePeripheral(ble_peripheral.get())); + scanner_->NotifyDeviceFound(BlePeripheral(ble_peripheral.get())); EXPECT_TRUE(found_notification.WaitForNotificationWithTimeout(kWaitTimeout)); - scanner_->OnDeviceLost(BlePeripheral(ble_peripheral.get())); + scanner_->NotifyDeviceLost(BlePeripheral(ble_peripheral.get())); EXPECT_TRUE(lost_notification.WaitForNotificationWithTimeout(kWaitTimeout)); } @@ -136,7 +141,7 @@ TEST_F(FastPairDiscoverableScannerImplTest, InvalidModelId) { auto ble_peripheral = std::make_unique( kTestBleDeviceAddress, kInvalidModelId); - scanner_->OnDeviceFound(BlePeripheral(ble_peripheral.get())); + scanner_->NotifyDeviceFound(BlePeripheral(ble_peripheral.get())); EXPECT_FALSE(found_notification.WaitForNotificationWithTimeout(kWaitTimeout)); } @@ -287,7 +292,7 @@ TEST_F(FastPairDiscoverableScannerImplTest, NearbyShareModelId) { auto ble_peripheral = std::make_unique( kTestBleDeviceAddress, kNearbyShareModelId); - scanner_->OnDeviceFound(BlePeripheral(ble_peripheral.get())); + scanner_->NotifyDeviceFound(BlePeripheral(ble_peripheral.get())); EXPECT_FALSE(found_notification.WaitForNotificationWithTimeout(kWaitTimeout)); } @@ -309,7 +314,7 @@ TEST_F(FastPairDiscoverableScannerImplTest, auto ble_peripheral = std::make_unique(kTestBleDeviceAddress, kValidModelId); - scanner_->OnDeviceLost(BlePeripheral(ble_peripheral.get())); + scanner_->NotifyDeviceLost(BlePeripheral(ble_peripheral.get())); EXPECT_FALSE(lost_notification.WaitForNotificationWithTimeout(kWaitTimeout)); } diff --git a/fastpair/scanning/fastpair/fast_pair_scanner_impl.cc b/fastpair/scanning/fastpair/fast_pair_scanner_impl.cc index 02182fd7..6c36df43 100644 --- a/fastpair/scanning/fastpair/fast_pair_scanner_impl.cc +++ b/fastpair/scanning/fastpair/fast_pair_scanner_impl.cc @@ -55,6 +55,7 @@ FastPairScannerImpl::Factory::~Factory() = default; // FastPairScannerImpl FastPairScannerImpl::FastPairScannerImpl() { task_runner_ = std::make_unique(1); + StartScanning(); } void FastPairScannerImpl::AddObserver(FastPairScanner::Observer* observer) { diff --git a/fastpair/scanning/fastpair/fast_pair_scanner_impl.h b/fastpair/scanning/fastpair/fast_pair_scanner_impl.h index 7249fe90..9162a425 100644 --- a/fastpair/scanning/fastpair/fast_pair_scanner_impl.h +++ b/fastpair/scanning/fastpair/fast_pair_scanner_impl.h @@ -57,9 +57,6 @@ class FastPairScannerImpl : public FastPairScanner { void AddObserver(FastPairScanner::Observer* observer) override; void RemoveObserver(FastPairScanner::Observer* observer) override; - void StartScanning(); - void StopScanning(); - // Fast Pair discovered peripheral callback void OnDeviceFound(const BlePeripheral& peripheral); void OnDeviceLost(const BlePeripheral& peripheral); @@ -72,6 +69,9 @@ class FastPairScannerImpl : public FastPairScanner { Ble& GetBle() { return ble_; } private: + void StartScanning(); + void StopScanning(); + std::unique_ptr task_runner_; // Map of a Bluetooth device address to a set of advertisement data we have diff --git a/fastpair/scanning/fastpair/fast_pair_scanner_impl_test.cc b/fastpair/scanning/fastpair/fast_pair_scanner_impl_test.cc index 6f2b9c99..d0e520a0 100644 --- a/fastpair/scanning/fastpair/fast_pair_scanner_impl_test.cc +++ b/fastpair/scanning/fastpair/fast_pair_scanner_impl_test.cc @@ -22,7 +22,6 @@ #include "gtest/gtest.h" #include "absl/strings/string_view.h" #include "absl/time/time.h" -#include "fastpair/common/constant.h" #include "fastpair/scanning/fastpair/fast_pair_scanner.h" #include "internal/platform/bluetooth_adapter.h" #include "internal/platform/byte_array.h" @@ -35,6 +34,7 @@ namespace { // Below constants are used to construct MockBluetoothDevice for testing. constexpr char kTestBleDeviceAddress[] = "11:12:13:14:15:16"; constexpr char kTestModelId[] = "112233"; +constexpr absl::Duration kTaskWaitTimeout = absl::Milliseconds(200); class FakeBlePeripheral : public api::BlePeripheral { public: @@ -98,13 +98,19 @@ class FastPairScannerObserver : public FastPairScanner::Observer { class FastPairScannerImplTest : public testing::Test { public: void SetUp() override { - scanner_.reset(); + env_.Start(); scanner_ = std::make_shared(); + SystemClock::Sleep(kTaskWaitTimeout); scanner_observer_ = std::make_unique(); scanner_->AddObserver(scanner_observer_.get()); } - void TearDown() override { env_.Stop(); } + void TearDown() override { + scanner_->RemoveObserver(scanner_observer_.get()); + scanner_.reset(); + scanner_observer_.reset(); + env_.Stop(); + } void TriggerOnDeviceFound(absl::string_view address, absl::string_view data) { auto ble_peripheral = std::make_unique(address, data); @@ -122,58 +128,37 @@ class FastPairScannerImplTest : public testing::Test { std::unique_ptr scanner_observer_; }; -TEST_F(FastPairScannerImplTest, FactoryCreatSuccessfully) { - env_.Start(); - std::shared_ptr scanner = - FastPairScannerImpl::Factory::Create(); - EXPECT_TRUE(scanner); - scanner.reset(); - env_.Stop(); -} - TEST_F(FastPairScannerImplTest, StartScanningSuccessfully) { - env_.Start(); - scanner_->StartScanning(); - SystemClock::Sleep(absl::Milliseconds(200)); EXPECT_TRUE(scanner_->GetBle().IsScanning()); // Not StopScanning as FastPairLowPowerDisabled - env_.Stop(); } TEST_F(FastPairScannerImplTest, DeviceFoundNotifiesObservers) { - env_.Start(); TriggerOnDeviceFound(kTestBleDeviceAddress, kTestModelId); EXPECT_TRUE(scanner_observer_->DoesDeviceListContainTestDevice( kTestBleDeviceAddress)); - env_.Stop(); } TEST_F(FastPairScannerImplTest, DeviceLostNotifiesObservers) { - env_.Start(); TriggerOnDeviceFound(kTestBleDeviceAddress, kTestModelId); EXPECT_TRUE(scanner_observer_->DoesDeviceListContainTestDevice( kTestBleDeviceAddress)); TriggerOnDeviceLost(kTestBleDeviceAddress, kTestModelId); EXPECT_FALSE(scanner_observer_->DoesDeviceListContainTestDevice( kTestBleDeviceAddress)); - env_.Stop(); } -TEST_F(FastPairScannerImplTest, DeviceFoundWithNoServiceData) { - env_.Start(); +TEST_F(FastPairScannerImplTest, DeviceFoundWithNoServiceData) {; TriggerOnDeviceFound(kTestBleDeviceAddress, ""); EXPECT_FALSE(scanner_observer_->DoesDeviceListContainTestDevice( kTestBleDeviceAddress)); - env_.Stop(); } TEST_F(FastPairScannerImplTest, RemoveObserver) { - env_.Start(); scanner_->RemoveObserver(scanner_observer_.get()); TriggerOnDeviceFound(kTestBleDeviceAddress, kTestModelId); EXPECT_FALSE(scanner_observer_->DoesDeviceListContainTestDevice( kTestBleDeviceAddress)); - env_.Stop(); } } // namespace diff --git a/fastpair/scanning/mock_scanner_broker.h b/fastpair/scanning/mock_scanner_broker.h new file mode 100644 index 00000000..59a44bef --- /dev/null +++ b/fastpair/scanning/mock_scanner_broker.h @@ -0,0 +1,58 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#ifndef THIRD_PARTY_NEARBY_FASTPAIR_SCANNING_MOCK_SCANNER_BROKER_H_ +#define THIRD_PARTY_NEARBY_FASTPAIR_SCANNING_MOCK_SCANNER_BROKER_H_ + +#include "gmock/gmock.h" +#include "fastpair/scanning/scanner_broker.h" +#include "internal/base/observer_list.h" +#include "fastpair/common/fast_pair_device.h" + +namespace nearby { +namespace fastpair { + +class MockScannerBroker : public ScannerBroker { + public: + MOCK_METHOD(void, StartScanning, (Protocol), (override)); + MOCK_METHOD(void, StopScanning, (Protocol), (override)); + + + void AddObserver(Observer* observer) override { + observers_.AddObserver(observer); + } + + void RemoveObserver(Observer* observer) override { + observers_.RemoveObserver(observer); + } + + void NotifyDeviceFound(const FastPairDevice& device) { + for (auto& observer : observers_){ + observer->OnDeviceFound(device); + } + } + + void NotifyDeviceLost(const FastPairDevice& device) { + for (auto& observer : observers_){ + observer->OnDeviceLost(device); + } + } + + private: + ObserverList observers_; +}; + +} // namespace fastpair +} // namespace nearby + +#endif // THIRD_PARTY_NEARBY_FASTPAIR_SCANNING_MOCK_SCANNER_BROKER_H_ diff --git a/fastpair/scanning/scanner_broker_impl.cc b/fastpair/scanning/scanner_broker_impl.cc index fe685e03..8964531d 100644 --- a/fastpair/scanning/scanner_broker_impl.cc +++ b/fastpair/scanning/scanner_broker_impl.cc @@ -54,10 +54,7 @@ void ScannerBrokerImpl::StartFastPairScanning() { DCHECK(!fast_pair_discoverable_scanner_); DCHECK(adapter_); NEARBY_LOGS(VERBOSE) << "Starting Fast Pair Scanning."; - scanner_impl_ = std::make_shared(); - scanner_impl_->StartScanning(); - scanner_ = std::move(scanner_impl_); - + scanner_ = std::make_shared(); fast_pair_discoverable_scanner_ = FastPairDiscoverableScannerImpl::Factory::Create( scanner_, adapter_, @@ -67,6 +64,7 @@ void ScannerBrokerImpl::StartFastPairScanning() { void ScannerBrokerImpl::StopFastPairScanning() { fast_pair_discoverable_scanner_.reset(); + scanner_.reset(); observers_.Clear(); NEARBY_LOGS(VERBOSE) << __func__ << "Stopping Fast Pair Scanning."; } diff --git a/fastpair/scanning/scanner_broker_impl.h b/fastpair/scanning/scanner_broker_impl.h index 10c986c9..bb40d6b7 100644 --- a/fastpair/scanning/scanner_broker_impl.h +++ b/fastpair/scanning/scanner_broker_impl.h @@ -22,7 +22,6 @@ #include "fastpair/common/fast_pair_device.h" #include "fastpair/scanning/fastpair/fast_pair_discoverable_scanner.h" #include "fastpair/scanning/fastpair/fast_pair_scanner.h" -#include "fastpair/scanning/fastpair/fast_pair_scanner_impl.h" #include "fastpair/scanning/scanner_broker.h" #include "internal/base/observer_list.h" #include "internal/platform/bluetooth_adapter.h" @@ -50,7 +49,6 @@ class ScannerBrokerImpl : public ScannerBroker { std::unique_ptr task_runner_; std::shared_ptr scanner_; - std::shared_ptr scanner_impl_; std::shared_ptr adapter_; std::unique_ptr fast_pair_discoverable_scanner_; ObserverList observers_; diff --git a/fastpair/scanning/scanner_broker_impl_test.cc b/fastpair/scanning/scanner_broker_impl_test.cc index 2a77588d..861d0f1d 100644 --- a/fastpair/scanning/scanner_broker_impl_test.cc +++ b/fastpair/scanning/scanner_broker_impl_test.cc @@ -18,9 +18,8 @@ #include #include -#include "gmock/gmock.h" -#include "protobuf-matchers/protocol-buffer-matchers.h" #include "gtest/gtest.h" +#include "absl/strings/string_view.h" #include "fastpair/common/fast_pair_device.h" #include "fastpair/common/protocol.h" #include "fastpair/scanning/fastpair/fake_fast_pair_discoverable_scanner.h" @@ -29,7 +28,7 @@ #include "fastpair/scanning/fastpair/fast_pair_discoverable_scanner_impl.h" #include "fastpair/scanning/fastpair/fast_pair_scanner.h" #include "fastpair/scanning/fastpair/fast_pair_scanner_impl.h" -#include "internal/platform/medium_environment.h" +#include "internal/platform/implementation/system_clock.h" namespace nearby { namespace fastpair { @@ -37,6 +36,7 @@ namespace { constexpr absl::string_view kTestDeviceAddress("11:12:13:14:15:16"); constexpr absl::string_view kValidModelId("718c17"); +constexpr absl::Duration kTaskWaitTimeout = absl::Milliseconds(200); class FakeFastPairScannerFactory : public FastPairScannerImpl::Factory { public: @@ -74,8 +74,6 @@ class FakeFastPairDiscoverableScannerFactory return fake_fast_pair_discoverable_scanner; } - ~FakeFastPairDiscoverableScannerFactory() override = default; - FakeFastPairDiscoverableScanner* fake_fast_pair_discoverable_scanner() { return fake_fast_pair_discoverable_scanner_; } @@ -91,8 +89,9 @@ class FakeFastPairDiscoverableScannerFactory class ScannerBrokerImplTest : public testing::Test, public ScannerBroker::Observer { public: - ScannerBrokerImplTest() { + void SetUp() override { adapter_ = std::shared_ptr(); + scanner_factory_ = std::make_unique(); FastPairScannerImpl::Factory::SetFactoryForTesting(scanner_factory_.get()); @@ -100,19 +99,21 @@ class ScannerBrokerImplTest : public testing::Test, std::make_unique(); FastPairDiscoverableScannerImpl::Factory::SetFactoryForTesting( discoverable_scanner_factory_.get()); - } - ~ScannerBrokerImplTest() override { - scanner_broker_->RemoveObserver(this); - scanner_broker_.reset(); - adapter_.reset(); - } - - void CreateScannerBroker() { scanner_broker_ = std::make_unique(); scanner_broker_->AddObserver(this); } + void TearDown() override { + scanner_broker_->RemoveObserver(this); + scanner_broker_.reset(); + scanner_factory_.reset(); + discoverable_scanner_factory_.reset(); + FastPairScannerImpl::Factory::SetFactoryForTesting(nullptr); + FastPairDiscoverableScannerImpl::Factory::SetFactoryForTesting(nullptr); + adapter_.reset(); + } + void TriggerDiscoverableDeviceFound() { FastPairDevice device(std::string(kValidModelId), std::string(kTestDeviceAddress), @@ -140,7 +141,6 @@ class ScannerBrokerImplTest : public testing::Test, protected: bool device_found_ = false; bool device_lost_ = false; - MediumEnvironment& env_{MediumEnvironment::Instance()}; std::shared_ptr adapter_; std::unique_ptr scanner_factory_; std::unique_ptr @@ -149,66 +149,55 @@ class ScannerBrokerImplTest : public testing::Test, }; TEST_F(ScannerBrokerImplTest, DiscoverableFound) { - env_.Start(); EXPECT_FALSE(discoverable_scanner_factory_->create_instance()); - CreateScannerBroker(); scanner_broker_->StartScanning(Protocol::kFastPairInitialPairing); - SystemClock::Sleep(absl::Milliseconds(200)); + SystemClock::Sleep(kTaskWaitTimeout); EXPECT_FALSE(device_found_); EXPECT_TRUE(discoverable_scanner_factory_->create_instance()); TriggerDiscoverableDeviceFound(); EXPECT_TRUE(device_found_); - env_.Stop(); } TEST_F(ScannerBrokerImplTest, DiscoverableLost) { - env_.Start(); EXPECT_FALSE(discoverable_scanner_factory_->create_instance()); - CreateScannerBroker(); scanner_broker_->StartScanning(Protocol::kFastPairInitialPairing); - SystemClock::Sleep(absl::Milliseconds(200)); + SystemClock::Sleep(kTaskWaitTimeout); EXPECT_FALSE(device_found_); EXPECT_TRUE(discoverable_scanner_factory_->create_instance()); TriggerDiscoverableDeviceLost(); EXPECT_TRUE(device_lost_); - env_.Stop(); } TEST_F(ScannerBrokerImplTest, RemoveObserver) { - env_.Start(); EXPECT_FALSE(discoverable_scanner_factory_->create_instance()); - CreateScannerBroker(); scanner_broker_->StartScanning(Protocol::kFastPairInitialPairing); - SystemClock::Sleep(absl::Milliseconds(200)); + SystemClock::Sleep(kTaskWaitTimeout); EXPECT_FALSE(device_found_); EXPECT_TRUE(discoverable_scanner_factory_->create_instance()); scanner_broker_->RemoveObserver(this); TriggerDiscoverableDeviceLost(); EXPECT_FALSE(device_lost_); - env_.Stop(); } TEST_F(ScannerBrokerImplTest, StopScanning) { - env_.Start(); - CreateScannerBroker(); EXPECT_FALSE(discoverable_scanner_factory_->create_instance()); scanner_broker_->StartScanning(Protocol::kFastPairInitialPairing); - SystemClock::Sleep(absl::Milliseconds(200)); + SystemClock::Sleep(kTaskWaitTimeout); EXPECT_TRUE(discoverable_scanner_factory_->create_instance()); scanner_broker_->StopScanning(Protocol::kFastPairInitialPairing); - SystemClock::Sleep(absl::Milliseconds(200)); + SystemClock::Sleep(kTaskWaitTimeout); + scanner_broker_->StartScanning(Protocol::kFastPairInitialPairing); - SystemClock::Sleep(absl::Milliseconds(200)); + SystemClock::Sleep(kTaskWaitTimeout); EXPECT_TRUE(discoverable_scanner_factory_->create_instance()); - env_.Stop(); } } // namespace