OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/quic/quic_connection_helper.h" | 5 #include "net/quic/quic_connection_helper.h" |
6 | 6 |
7 #include "net/quic/test_tools/mock_clock.h" | 7 #include "net/quic/test_tools/mock_clock.h" |
8 #include "net/quic/test_tools/mock_random.h" | 8 #include "net/quic/test_tools/mock_random.h" |
9 #include "net/quic/test_tools/test_task_runner.h" | 9 #include "net/quic/test_tools/test_task_runner.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 namespace net { | 12 namespace net { |
13 namespace test { | 13 namespace test { |
14 namespace { | 14 namespace { |
15 | 15 |
16 class TestDelegate : public QuicAlarm::Delegate { | 16 class TestDelegate : public QuicAlarm::Delegate { |
17 public: | 17 public: |
18 TestDelegate() : fired_(false) {} | 18 TestDelegate() : fired_(false) {} |
19 | 19 |
20 virtual QuicTime OnAlarm() OVERRIDE { | 20 virtual QuicTime OnAlarm() OVERRIDE { |
21 fired_ = true; | 21 fired_ = true; |
22 return QuicTime::Zero(); | 22 return QuicTime::Zero(); |
23 } | 23 } |
24 | 24 |
25 bool fired() const { return fired_; } | 25 bool fired() const { return fired_; } |
26 void Clear() { fired_= false; } | 26 void Clear() { fired_ = false; } |
27 | 27 |
28 private: | 28 private: |
29 bool fired_; | 29 bool fired_; |
30 }; | 30 }; |
31 | 31 |
32 class QuicConnectionHelperTest : public ::testing::Test { | 32 class QuicConnectionHelperTest : public ::testing::Test { |
33 protected: | 33 protected: |
34 QuicConnectionHelperTest() | 34 QuicConnectionHelperTest() |
35 : runner_(new TestTaskRunner(&clock_)), | 35 : runner_(new TestTaskRunner(&clock_)), |
36 helper_(runner_.get(), &clock_, &random_generator_) { | 36 helper_(runner_.get(), &clock_, &random_generator_) {} |
37 } | |
38 | 37 |
39 scoped_refptr<TestTaskRunner> runner_; | 38 scoped_refptr<TestTaskRunner> runner_; |
40 QuicConnectionHelper helper_; | 39 QuicConnectionHelper helper_; |
41 MockClock clock_; | 40 MockClock clock_; |
42 MockRandom random_generator_; | 41 MockRandom random_generator_; |
43 }; | 42 }; |
44 | 43 |
45 TEST_F(QuicConnectionHelperTest, GetClock) { | 44 TEST_F(QuicConnectionHelperTest, GetClock) { |
46 EXPECT_EQ(&clock_, helper_.GetClock()); | 45 EXPECT_EQ(&clock_, helper_.GetClock()); |
47 } | 46 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 // When the latter task is executed, the weak ptr will be invalid and | 136 // When the latter task is executed, the weak ptr will be invalid and |
138 // the alarm will not fire. | 137 // the alarm will not fire. |
139 runner_->RunNextTask(); | 138 runner_->RunNextTask(); |
140 EXPECT_EQ(QuicTime::Zero().Add(delta), clock_.Now()); | 139 EXPECT_EQ(QuicTime::Zero().Add(delta), clock_.Now()); |
141 EXPECT_FALSE(delegate->fired()); | 140 EXPECT_FALSE(delegate->fired()); |
142 } | 141 } |
143 | 142 |
144 } // namespace | 143 } // namespace |
145 } // namespace test | 144 } // namespace test |
146 } // namespace net | 145 } // namespace net |
OLD | NEW |