quick_pair_process_shutdown_controller_unittest.cc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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/services/quick_pair/quick_pair_process_shutdown_controller.h"
  5. #include "base/memory/weak_ptr.h"
  6. #include "base/run_loop.h"
  7. #include "base/test/task_environment.h"
  8. #include "testing/gtest/include/gtest/gtest.h"
  9. namespace ash {
  10. namespace quick_pair {
  11. class QuickPairProcessShutdownControllerTest : public testing::Test {
  12. public:
  13. void SetUp() override {
  14. shutdown_controller_ =
  15. std::make_unique<QuickPairProcessShutdownController>();
  16. }
  17. void TearDown() override { shutdown_controller_.reset(); }
  18. void Start() {
  19. shutdown_controller_->Start(
  20. base::BindOnce(&QuickPairProcessShutdownControllerTest::OnStart,
  21. weak_ptr_factory_.GetWeakPtr()));
  22. }
  23. void OnStart() { start_ = true; }
  24. protected:
  25. bool start_ = false;
  26. base::test::SingleThreadTaskEnvironment task_environment_{
  27. base::test::TaskEnvironment::TimeSource::MOCK_TIME};
  28. std::unique_ptr<QuickPairProcessShutdownController> shutdown_controller_;
  29. base::WeakPtrFactory<QuickPairProcessShutdownControllerTest>
  30. weak_ptr_factory_{this};
  31. };
  32. TEST_F(QuickPairProcessShutdownControllerTest, Start) {
  33. EXPECT_FALSE(start_);
  34. Start();
  35. task_environment_.FastForwardBy(base::Seconds(5));
  36. base::RunLoop().RunUntilIdle();
  37. EXPECT_TRUE(start_);
  38. }
  39. TEST_F(QuickPairProcessShutdownControllerTest, Stop) {
  40. EXPECT_FALSE(start_);
  41. Start();
  42. shutdown_controller_->Stop();
  43. base::RunLoop().RunUntilIdle();
  44. EXPECT_FALSE(start_);
  45. }
  46. } // namespace quick_pair
  47. } // namespace ash