[M120 Migration][VD] Enable direct rendering for TVPlus
[platform/framework/web/chromium-efl.git] / components / component_updater / timer_unittest.cc
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.
4
5 #include <string>
6 #include <utility>
7
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"
14
15 namespace component_updater {
16
17 class ComponentUpdaterTimerTest : public testing::Test {
18  public:
19   ComponentUpdaterTimerTest()
20       : task_environment_(
21             base::test::SingleThreadTaskEnvironment::MainThreadType::UI) {}
22   ~ComponentUpdaterTimerTest() override = default;
23
24  private:
25   base::test::SingleThreadTaskEnvironment task_environment_;
26 };
27
28 TEST_F(ComponentUpdaterTimerTest, Start) {
29   class TimerClientMock {
30    public:
31     TimerClientMock(int max_count, base::OnceClosure quit_closure)
32         : max_count_(max_count),
33           quit_closure_(std::move(quit_closure)),
34           count_(0) {}
35
36     void OnTimerEvent() {
37       ++count_;
38       if (count_ >= max_count_)
39         std::move(quit_closure_).Run();
40     }
41
42     int count() const { return count_; }
43
44    private:
45     const int max_count_;
46     base::OnceClosure quit_closure_;
47
48     int count_;
49   };
50
51   base::RunLoop run_loop;
52   TimerClientMock timer_client_fake(3, run_loop.QuitClosure());
53   EXPECT_EQ(0, timer_client_fake.count());
54
55   Timer timer;
56   const base::TimeDelta delay(base::Milliseconds(1));
57   timer.Start(delay, delay,
58               base::BindRepeating(&TimerClientMock::OnTimerEvent,
59                                   base::Unretained(&timer_client_fake)));
60   run_loop.Run();
61   timer.Stop();
62
63   EXPECT_EQ(3, timer_client_fake.count());
64 }
65
66 }  // namespace component_updater