| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | |
| 8 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/test/scoped_task_environment.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "components/component_updater/timer.h" | 10 #include "components/component_updater/timer.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 using std::string; | 13 using std::string; |
| 14 | 14 |
| 15 namespace component_updater { | 15 namespace component_updater { |
| 16 | 16 |
| 17 class ComponentUpdaterTimerTest : public testing::Test { | 17 class ComponentUpdaterTimerTest : public testing::Test { |
| 18 public: | 18 public: |
| 19 ComponentUpdaterTimerTest() {} | 19 ComponentUpdaterTimerTest() |
| 20 : scoped_task_environment_( |
| 21 base::test::ScopedTaskEnvironment::MainThreadType::UI) {} |
| 20 ~ComponentUpdaterTimerTest() override {} | 22 ~ComponentUpdaterTimerTest() override {} |
| 21 | 23 |
| 22 private: | 24 private: |
| 23 base::MessageLoopForUI message_loop_; | 25 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 24 }; | 26 }; |
| 25 | 27 |
| 26 TEST_F(ComponentUpdaterTimerTest, Start) { | 28 TEST_F(ComponentUpdaterTimerTest, Start) { |
| 27 class TimerClientFake { | 29 class TimerClientFake { |
| 28 public: | 30 public: |
| 29 TimerClientFake(int max_count, const base::Closure& quit_closure) | 31 TimerClientFake(int max_count, const base::Closure& quit_closure) |
| 30 : max_count_(max_count), quit_closure_(quit_closure), count_(0) {} | 32 : max_count_(max_count), quit_closure_(quit_closure), count_(0) {} |
| 31 | 33 |
| 32 void OnTimerEvent() { | 34 void OnTimerEvent() { |
| 33 ++count_; | 35 ++count_; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 52 const base::TimeDelta delay(base::TimeDelta::FromMilliseconds(1)); | 54 const base::TimeDelta delay(base::TimeDelta::FromMilliseconds(1)); |
| 53 timer.Start(delay, delay, base::Bind(&TimerClientFake::OnTimerEvent, | 55 timer.Start(delay, delay, base::Bind(&TimerClientFake::OnTimerEvent, |
| 54 base::Unretained(&timer_client_fake))); | 56 base::Unretained(&timer_client_fake))); |
| 55 run_loop.Run(); | 57 run_loop.Run(); |
| 56 timer.Stop(); | 58 timer.Stop(); |
| 57 | 59 |
| 58 EXPECT_EQ(3, timer_client_fake.count()); | 60 EXPECT_EQ(3, timer_client_fake.count()); |
| 59 } | 61 } |
| 60 | 62 |
| 61 } // namespace component_updater | 63 } // namespace component_updater |
| OLD | NEW |