Update V8 to version 4.7.1.
[chromium-blink-merge.git] / components / component_updater / timer_unittest.cc
blob2c80e84d2a2acb7ac8d0dcd919844a4acfb629f5
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.
5 #include <string>
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"
13 using std::string;
15 namespace component_updater {
17 class ComponentUpdaterTimerTest : public testing::Test {
18 public:
19 ComponentUpdaterTimerTest() {}
20 ~ComponentUpdaterTimerTest() override {}
22 private:
23 base::MessageLoopForUI message_loop_;
26 TEST_F(ComponentUpdaterTimerTest, Start) {
27 class TimerClientFake {
28 public:
29 TimerClientFake(int max_count, const base::Closure& quit_closure)
30 : max_count_(max_count), quit_closure_(quit_closure), count_(0) {}
32 void OnTimerEvent() {
33 ++count_;
34 if (count_ >= max_count_)
35 quit_closure_.Run();
38 int count() const { return count_; }
40 private:
41 const int max_count_;
42 const base::Closure quit_closure_;
44 int count_;
47 base::RunLoop run_loop;
48 TimerClientFake timer_client_fake(3, run_loop.QuitClosure());
49 EXPECT_EQ(0, timer_client_fake.count());
51 Timer timer;
52 const base::TimeDelta delay(base::TimeDelta::FromMilliseconds(1));
53 timer.Start(delay, delay, base::Bind(&TimerClientFake::OnTimerEvent,
54 base::Unretained(&timer_client_fake)));
55 run_loop.Run();
56 timer.Stop();
58 EXPECT_EQ(3, timer_client_fake.count());
61 } // namespace component_updater