1 // Copyright 2015 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.
7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h"
9 #include "base/time/time.h"
10 #include "components/component_updater/timer.h"
11 #include "testing/gtest/include/gtest/gtest.h"
15 namespace component_updater
{
17 class ComponentUpdaterTimerTest
: public testing::Test
{
19 ComponentUpdaterTimerTest() {}
20 ~ComponentUpdaterTimerTest() override
{}
23 base::MessageLoopForUI message_loop_
;
26 TEST_F(ComponentUpdaterTimerTest
, Start
) {
27 class TimerClientFake
{
29 TimerClientFake(int max_count
, const base::Closure
& quit_closure
)
30 : max_count_(max_count
), quit_closure_(quit_closure
), count_(0) {}
34 if (count_
>= max_count_
)
38 int count() const { return count_
; }
42 const base::Closure quit_closure_
;
47 base::RunLoop run_loop
;
48 TimerClientFake
timer_client_fake(3, run_loop
.QuitClosure());
49 EXPECT_EQ(0, timer_client_fake
.count());
52 const base::TimeDelta
delay(base::TimeDelta::FromMilliseconds(1));
53 timer
.Start(delay
, delay
, base::Bind(&TimerClientFake::OnTimerEvent
,
54 base::Unretained(&timer_client_fake
)));
58 EXPECT_EQ(3, timer_client_fake
.count());
61 } // namespace component_updater