Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(434)

Side by Side Diff: net/quic/quic_connection_helper_test.cc

Issue 471313002: Add an Update method on QuicAlarm which contains a granularity. Also (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Final_0814_2
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 // The latter task is still posted. 134 // The latter task is still posted.
135 ASSERT_EQ(1u, runner_->GetPostedTasks().size()); 135 ASSERT_EQ(1u, runner_->GetPostedTasks().size());
136 136
137 // When the latter task is executed, the weak ptr will be invalid and 137 // When the latter task is executed, the weak ptr will be invalid and
138 // the alarm will not fire. 138 // the alarm will not fire.
139 runner_->RunNextTask(); 139 runner_->RunNextTask();
140 EXPECT_EQ(QuicTime::Zero().Add(delta), clock_.Now()); 140 EXPECT_EQ(QuicTime::Zero().Add(delta), clock_.Now());
141 EXPECT_FALSE(delegate->fired()); 141 EXPECT_FALSE(delegate->fired());
142 } 142 }
143 143
144 TEST_F(QuicConnectionHelperTest, CreateAlarmAndUpdate) {
145 TestDelegate* delegate = new TestDelegate();
146 scoped_ptr<QuicAlarm> alarm(helper_.CreateAlarm(delegate));
147
148 const QuicClock* clock = helper_.GetClock();
149 QuicTime start = clock->Now();
150 QuicTime::Delta delta = QuicTime::Delta::FromMicroseconds(1);
151 alarm->Set(clock->Now().Add(delta));
152 QuicTime::Delta new_delta = QuicTime::Delta::FromMicroseconds(3);
153 alarm->Update(clock->Now().Add(new_delta),
154 QuicTime::Delta::FromMicroseconds(1));
155
156 // The alarm task should still be posted.
157 ASSERT_EQ(1u, runner_->GetPostedTasks().size());
158 EXPECT_EQ(base::TimeDelta::FromMicroseconds(delta.ToMicroseconds()),
159 runner_->GetPostedTasks()[0].delay);
160
161 runner_->RunNextTask();
162 EXPECT_EQ(QuicTime::Zero().Add(delta), clock->Now());
163 EXPECT_FALSE(delegate->fired());
164
165 // Move the alarm forward 1us and ensure it doesn't move forward.
166 alarm->Update(clock->Now().Add(new_delta),
167 QuicTime::Delta::FromMicroseconds(2));
168
169 ASSERT_EQ(1u, runner_->GetPostedTasks().size());
170 EXPECT_EQ(
171 base::TimeDelta::FromMicroseconds(
172 new_delta.Subtract(delta).ToMicroseconds()),
173 runner_->GetPostedTasks()[0].delay);
174 runner_->RunNextTask();
175 EXPECT_EQ(start.Add(new_delta), clock->Now());
176 EXPECT_TRUE(delegate->fired());
177
178 // Set the alarm via an update call.
179 new_delta = QuicTime::Delta::FromMicroseconds(5);
180 alarm->Update(clock->Now().Add(new_delta),
181 QuicTime::Delta::FromMicroseconds(1));
182 EXPECT_TRUE(alarm->IsSet());
183
184 // Update it with an uninitialized time and ensure it's cancelled.
185 alarm->Update(QuicTime::Zero(), QuicTime::Delta::FromMicroseconds(1));
186 EXPECT_FALSE(alarm->IsSet());
187 }
188
144 } // namespace 189 } // namespace
145 } // namespace test 190 } // namespace test
146 } // namespace net 191 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698