OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/p2p/quic/quicconnectionhelper.h" | 11 #include "webrtc/p2p/quic/quicconnectionhelper.h" |
12 | 12 |
13 #include "net/quic/quic_time.h" | 13 #include "net/quic/quic_time.h" |
14 #include "webrtc/base/gunit.h" | 14 #include "webrtc/base/gunit.h" |
| 15 #include "webrtc/base/scoped_ptr.h" |
15 | 16 |
16 using cricket::QuicAlarm; | 17 using cricket::QuicAlarm; |
17 using cricket::QuicConnectionHelper; | 18 using cricket::QuicConnectionHelper; |
18 | 19 |
19 using net::QuicClock; | 20 using net::QuicClock; |
20 using net::QuicTime; | 21 using net::QuicTime; |
21 using net::QuicWallTime; | 22 using net::QuicWallTime; |
22 | 23 |
23 // Clock that can be set to arbitrary times. | 24 // Clock that can be set to arbitrary times. |
24 class MockClock : public QuicClock { | 25 class MockClock : public QuicClock { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 void Clear() { fired_ = false; } | 61 void Clear() { fired_ = false; } |
61 | 62 |
62 private: | 63 private: |
63 bool fired_; | 64 bool fired_; |
64 }; | 65 }; |
65 | 66 |
66 class QuicAlarmTest : public ::testing::Test { | 67 class QuicAlarmTest : public ::testing::Test { |
67 public: | 68 public: |
68 QuicAlarmTest() | 69 QuicAlarmTest() |
69 : delegate_(new MockAlarmDelegate()), | 70 : delegate_(new MockAlarmDelegate()), |
70 alarm_(new QuicAlarm(&clock_, rtc::Thread::Current(), delegate_)) {} | 71 alarm_(new QuicAlarm( |
| 72 &clock_, |
| 73 rtc::Thread::Current(), |
| 74 net::QuicArenaScopedPtr<net::QuicAlarm::Delegate>(delegate_))) {} |
71 | 75 |
72 // Make the alarm fire after the given microseconds (us). Negative values | 76 // Make the alarm fire after the given microseconds (us). Negative values |
73 // imply the alarm should fire immediately. | 77 // imply the alarm should fire immediately. |
74 void SetTime(int us) { | 78 void SetTime(int us) { |
75 QuicTime::Delta delta = QuicTime::Delta::FromMicroseconds(us); | 79 QuicTime::Delta delta = QuicTime::Delta::FromMicroseconds(us); |
76 alarm_->Set(clock_.Now().Add(delta)); | 80 alarm_->Set(clock_.Now().Add(delta)); |
77 } | 81 } |
78 | 82 |
79 // Make rtc::Thread::Current() process the next message. | 83 // Make rtc::Thread::Current() process the next message. |
80 void ProcessNextMessage() { rtc::Thread::Current()->ProcessMessages(0); } | 84 void ProcessNextMessage() { rtc::Thread::Current()->ProcessMessages(0); } |
81 | 85 |
82 protected: | 86 protected: |
83 // Handles event that alarm fires. | 87 // Handles event that alarm fires. |
84 MockAlarmDelegate* delegate_; | 88 MockAlarmDelegate* delegate_; |
85 // Used for setting clock time relative to alarm. | 89 // Used for setting clock time relative to alarm. |
86 MockClock clock_; | 90 MockClock clock_; |
87 | 91 |
88 scoped_ptr<QuicAlarm> alarm_; | 92 rtc::scoped_ptr<QuicAlarm> alarm_; |
89 }; | 93 }; |
90 | 94 |
91 // Test that the alarm is fired. | 95 // Test that the alarm is fired. |
92 TEST_F(QuicAlarmTest, FireAlarm) { | 96 TEST_F(QuicAlarmTest, FireAlarm) { |
93 SetTime(-1); | 97 SetTime(-1); |
94 ProcessNextMessage(); | 98 ProcessNextMessage(); |
95 ASSERT_TRUE(delegate_->fired()); | 99 ASSERT_TRUE(delegate_->fired()); |
96 ASSERT_EQ(QuicTime::Zero(), alarm_->deadline()); | 100 ASSERT_EQ(QuicTime::Zero(), alarm_->deadline()); |
97 } | 101 } |
98 | 102 |
(...skipping 15 matching lines...) Expand all Loading... |
114 ASSERT_FALSE(delegate_->fired()); | 118 ASSERT_FALSE(delegate_->fired()); |
115 } | 119 } |
116 | 120 |
117 // Test that timing for posting task is accurate. | 121 // Test that timing for posting task is accurate. |
118 TEST_F(QuicAlarmTest, AlarmGetDelay) { | 122 TEST_F(QuicAlarmTest, AlarmGetDelay) { |
119 SetTime(1000000); | 123 SetTime(1000000); |
120 EXPECT_EQ(1000, alarm_->GetDelay()); | 124 EXPECT_EQ(1000, alarm_->GetDelay()); |
121 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(300000)); | 125 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(300000)); |
122 EXPECT_EQ(700, alarm_->GetDelay()); | 126 EXPECT_EQ(700, alarm_->GetDelay()); |
123 } | 127 } |
OLD | NEW |