OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "components/scheduler/child/virtual_time_tqm_delegate.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | |
9 | |
10 namespace scheduler { | |
11 | |
12 class VirtualTimeTqmDelegateTest : public testing::Test { | |
13 public: | |
14 VirtualTimeTqmDelegateTest() {} | |
15 | |
16 ~VirtualTimeTqmDelegateTest() override {} | |
17 | |
18 void SetUp() override { | |
19 message_loop_.reset(new base::MessageLoop()); | |
20 initial_time_ = base::TimeTicks() + base::TimeDelta::FromSeconds(100); | |
21 virtual_time_tqm_delegate_ = | |
22 VirtualTimeTqmDelegate::Create(message_loop_.get(), initial_time_); | |
23 } | |
24 | |
25 base::TimeTicks initial_time_; | |
26 scoped_ptr<base::MessageLoop> message_loop_; | |
27 | |
28 scoped_refptr<VirtualTimeTqmDelegate> virtual_time_tqm_delegate_; | |
29 }; | |
30 | |
31 namespace { | |
32 void TestFunc(bool* run) { | |
33 *run = true; | |
34 } | |
35 } | |
36 | |
37 TEST_F(VirtualTimeTqmDelegateTest, OnNoMoreImmediateWork_TimersFastForward) { | |
38 bool was_run = false; | |
39 virtual_time_tqm_delegate_->PostDelayedTask(FROM_HERE, | |
40 base::Bind(TestFunc, &was_run), | |
41 base::TimeDelta::FromSeconds(1)); | |
42 | |
43 EXPECT_EQ(initial_time_, virtual_time_tqm_delegate_->NowTicks()); | |
44 | |
45 virtual_time_tqm_delegate_->OnNoMoreImmediateWork(); | |
46 | |
47 EXPECT_EQ(initial_time_ + base::TimeDelta::FromSeconds(1), | |
48 virtual_time_tqm_delegate_->NowTicks()); | |
49 | |
50 message_loop_->RunUntilIdle(); | |
51 EXPECT_TRUE(was_run); | |
52 } | |
53 | |
54 } // namespace scheduler | |
OLD | NEW |