| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 10 #include "net/quic/crypto/quic_decrypter.h" | 10 #include "net/quic/crypto/quic_decrypter.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 class TestDelegate : public QuicAlarm::Delegate { | 31 class TestDelegate : public QuicAlarm::Delegate { |
| 32 public: | 32 public: |
| 33 TestDelegate() : fired_(false) {} | 33 TestDelegate() : fired_(false) {} |
| 34 | 34 |
| 35 virtual QuicTime OnAlarm() OVERRIDE { | 35 virtual QuicTime OnAlarm() OVERRIDE { |
| 36 fired_ = true; | 36 fired_ = true; |
| 37 return QuicTime::Zero(); | 37 return QuicTime::Zero(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 bool fired() const { return fired_; } | 40 bool fired() const { return fired_; } |
| 41 void Clear() { fired_= false; } |
| 41 | 42 |
| 42 private: | 43 private: |
| 43 bool fired_; | 44 bool fired_; |
| 44 }; | 45 }; |
| 45 | 46 |
| 46 class TestConnection : public QuicConnection { | 47 class TestConnection : public QuicConnection { |
| 47 public: | 48 public: |
| 48 TestConnection(QuicGuid guid, | 49 TestConnection(QuicGuid guid, |
| 49 IPEndPoint address, | 50 IPEndPoint address, |
| 50 QuicConnectionHelper* helper) | 51 QuicConnectionHelper* helper) |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 EXPECT_FALSE(delegate->fired()); | 301 EXPECT_FALSE(delegate->fired()); |
| 301 | 302 |
| 302 // The alarm task should be posted again. | 303 // The alarm task should be posted again. |
| 303 ASSERT_EQ(2u, runner_->GetPostedTasks().size()); | 304 ASSERT_EQ(2u, runner_->GetPostedTasks().size()); |
| 304 | 305 |
| 305 runner_->RunNextTask(); | 306 runner_->RunNextTask(); |
| 306 EXPECT_EQ(QuicTime::Zero().Add(new_delta), clock_.Now()); | 307 EXPECT_EQ(QuicTime::Zero().Add(new_delta), clock_.Now()); |
| 307 EXPECT_TRUE(delegate->fired()); | 308 EXPECT_TRUE(delegate->fired()); |
| 308 } | 309 } |
| 309 | 310 |
| 311 TEST_F(QuicConnectionHelperTest, CreateAlarmAndResetEarlier) { |
| 312 TestDelegate* delegate = new TestDelegate(); |
| 313 scoped_ptr<QuicAlarm> alarm(helper_->CreateAlarm(delegate)); |
| 314 |
| 315 QuicTime::Delta delta = QuicTime::Delta::FromMicroseconds(3); |
| 316 alarm->Set(clock_.Now().Add(delta)); |
| 317 alarm->Cancel(); |
| 318 QuicTime::Delta new_delta = QuicTime::Delta::FromMicroseconds(1); |
| 319 alarm->Set(clock_.Now().Add(new_delta)); |
| 320 |
| 321 // Both alarm tasks will be posted. |
| 322 ASSERT_EQ(3u, runner_->GetPostedTasks().size()); |
| 323 |
| 324 // The earlier task will execute and will fire the alarm. |
| 325 runner_->RunNextTask(); |
| 326 EXPECT_EQ(QuicTime::Zero().Add(new_delta), clock_.Now()); |
| 327 EXPECT_TRUE(delegate->fired()); |
| 328 delegate->Clear(); |
| 329 |
| 330 // The latter task is still posted. |
| 331 ASSERT_EQ(2u, runner_->GetPostedTasks().size()); |
| 332 |
| 333 // When the latter task is executed, the weak ptr will be invalid and |
| 334 // the alarm will not fire. |
| 335 runner_->RunNextTask(); |
| 336 EXPECT_EQ(QuicTime::Zero().Add(delta), clock_.Now()); |
| 337 EXPECT_FALSE(delegate->fired()); |
| 338 } |
| 339 |
| 310 TEST_F(QuicConnectionHelperTest, TestRTORetransmission) { | 340 TEST_F(QuicConnectionHelperTest, TestRTORetransmission) { |
| 311 AddWrite(SYNCHRONOUS, ConstructDataPacket(1)); | 341 AddWrite(SYNCHRONOUS, ConstructDataPacket(1)); |
| 312 AddWrite(SYNCHRONOUS, ConstructDataPacket(2)); | 342 AddWrite(SYNCHRONOUS, ConstructDataPacket(2)); |
| 313 Initialize(); | 343 Initialize(); |
| 314 | 344 |
| 315 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly( | 345 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly( |
| 316 Return(QuicTime::Delta::Zero())); | 346 Return(QuicTime::Delta::Zero())); |
| 317 | 347 |
| 318 QuicTime::Delta kDefaultRetransmissionTime = | 348 QuicTime::Delta kDefaultRetransmissionTime = |
| 319 QuicTime::Delta::FromMilliseconds(500); | 349 QuicTime::Delta::FromMilliseconds(500); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 Return(QuicTime::Delta::Zero())); | 523 Return(QuicTime::Delta::Zero())); |
| 494 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(Return(true)); | 524 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(Return(true)); |
| 495 EXPECT_CALL(visitor_, HasPendingHandshake()).Times(AnyNumber()); | 525 EXPECT_CALL(visitor_, HasPendingHandshake()).Times(AnyNumber()); |
| 496 runner_->RunNextTask(); | 526 runner_->RunNextTask(); |
| 497 EXPECT_EQ(0u, connection_->NumQueuedPackets()); | 527 EXPECT_EQ(0u, connection_->NumQueuedPackets()); |
| 498 EXPECT_TRUE(AtEof()); | 528 EXPECT_TRUE(AtEof()); |
| 499 } | 529 } |
| 500 | 530 |
| 501 } // namespace test | 531 } // namespace test |
| 502 } // namespace net | 532 } // namespace net |
| OLD | NEW |