1 // Copyright 2015 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 #include "base/functional/bind.h"
9 #include "base/run_loop.h"
10 #include "base/test/task_environment.h"
11 #include "base/time/time.h"
12 #include "components/component_updater/timer.h"
13 #include "testing/gtest/include/gtest/gtest.h"
15 namespace component_updater {
17 class ComponentUpdaterTimerTest : public testing::Test {
19 ComponentUpdaterTimerTest()
21 base::test::SingleThreadTaskEnvironment::MainThreadType::UI) {}
22 ~ComponentUpdaterTimerTest() override = default;
25 base::test::SingleThreadTaskEnvironment task_environment_;
28 TEST_F(ComponentUpdaterTimerTest, Start) {
29 class TimerClientMock {
31 TimerClientMock(int max_count, base::OnceClosure quit_closure)
32 : max_count_(max_count),
33 quit_closure_(std::move(quit_closure)),
38 if (count_ >= max_count_)
39 std::move(quit_closure_).Run();
42 int count() const { return count_; }
46 base::OnceClosure quit_closure_;
51 base::RunLoop run_loop;
52 TimerClientMock timer_client_fake(3, run_loop.QuitClosure());
53 EXPECT_EQ(0, timer_client_fake.count());
56 const base::TimeDelta delay(base::Milliseconds(1));
57 timer.Start(delay, delay,
58 base::BindRepeating(&TimerClientMock::OnTimerEvent,
59 base::Unretained(&timer_client_fake)));
63 EXPECT_EQ(3, timer_client_fake.count());
66 } // namespace component_updater