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

Unified Diff: net/tools/quic/quic_epoll_alarm_factory_test.cc

Issue 1908103002: Landing Recent QUIC changes until 4/15/2016 17:20 UTC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/tools/quic/quic_epoll_alarm_factory.cc ('k') | net/tools/quic/quic_epoll_connection_helper.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/tools/quic/quic_epoll_alarm_factory_test.cc
diff --git a/net/tools/quic/quic_epoll_alarm_factory_test.cc b/net/tools/quic/quic_epoll_alarm_factory_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..33f74434dd6b8998b8b4e182e4815357b5d44c4b
--- /dev/null
+++ b/net/tools/quic/quic_epoll_alarm_factory_test.cc
@@ -0,0 +1,126 @@
+// Copyright (c) 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/tools/quic/quic_epoll_alarm_factory.h"
+#include "net/tools/quic/test_tools/mock_epoll_server.h"
+#include "testing/base/public/gmock.h"
+#include "testing/base/public/gunit.h"
+
+namespace net {
+namespace test {
+namespace {
+
+// The boolean parameter denotes whether or not to use an arena.
+class QuicEpollAlarmFactoryTest : public ::testing::TestWithParam<bool> {
+ protected:
+ QuicEpollAlarmFactoryTest()
+ : clock_(&epoll_server_), alarm_factory_(&epoll_server_) {}
+
+ QuicConnectionArena* GetArenaParam() {
+ return GetParam() ? &arena_ : nullptr;
+ }
+
+ const QuicEpollClock clock_;
+ QuicEpollAlarmFactory alarm_factory_;
+ test::MockEpollServer epoll_server_;
+ QuicConnectionArena arena_;
+};
+
+TEST_P(QuicEpollAlarmFactoryTest, CreateAlarm) {
+ QuicArenaScopedPtr<TestDelegate> delegate =
+ QuicArenaScopedPtr<TestDelegate>(new TestDelegate());
+ QuicArenaScopedPtr<QuicAlarm> alarm(
+ alarm_factory_.CreateAlarm(std::move(delegate), GetArenaParam()));
+
+ QuicTime start = clock_.Now();
+ QuicTime::Delta delta = QuicTime::Delta::FromMicroseconds(1);
+ alarm->Set(start.Add(delta));
+
+ epoll_server_.AdvanceByAndWaitForEventsAndExecuteCallbacks(
+ delta.ToMicroseconds());
+ EXPECT_EQ(start.Add(delta), clock_.Now());
+}
+
+TEST_P(QuicEpollAlarmFactoryTest, CreateAlarmAndCancel) {
+ QuicArenaScopedPtr<TestDelegate> delegate =
+ QuicArenaScopedPtr<TestDelegate>(new TestDelegate());
+ TestDelegate* unowned_delegate = delegate.get();
+ QuicArenaScopedPtr<QuicAlarm> alarm(
+ alarm_factory_.CreateAlarm(std::move(delegate), GetArenaParam()));
+
+ QuicTime start = clock_.Now();
+ QuicTime::Delta delta = QuicTime::Delta::FromMicroseconds(1);
+ alarm->Set(start.Add(delta));
+ alarm->Cancel();
+
+ epoll_server_.AdvanceByExactlyAndCallCallbacks(delta.ToMicroseconds());
+ EXPECT_EQ(start.Add(delta), clock_.Now());
+ EXPECT_FALSE(unowned_delegate->fired());
+}
+
+TEST_P(QuicEpollAlarmFactoryTest, CreateAlarmAndReset) {
+ QuicArenaScopedPtr<TestDelegate> delegate =
+ QuicArenaScopedPtr<TestDelegate>(new TestDelegate());
+ TestDelegate* unowned_delegate = delegate.get();
+ QuicArenaScopedPtr<QuicAlarm> alarm(
+ alarm_factory_.CreateAlarm(std::move(delegate), GetArenaParam()));
+
+ QuicTime start = clock_.Now();
+ QuicTime::Delta delta = QuicTime::Delta::FromMicroseconds(1);
+ alarm->Set(clock_.Now().Add(delta));
+ alarm->Cancel();
+ QuicTime::Delta new_delta = QuicTime::Delta::FromMicroseconds(3);
+ alarm->Set(clock_.Now().Add(new_delta));
+
+ epoll_server_.AdvanceByExactlyAndCallCallbacks(delta.ToMicroseconds());
+ EXPECT_EQ(start.Add(delta), clock_.Now());
+ EXPECT_FALSE(unowned_delegate->fired());
+
+ epoll_server_.AdvanceByExactlyAndCallCallbacks(
+ new_delta.Subtract(delta).ToMicroseconds());
+ EXPECT_EQ(start.Add(new_delta), clock_.Now());
+ EXPECT_TRUE(unowned_delegate->fired());
+}
+
+TEST_P(QuicEpollAlarmFactoryTest, CreateAlarmAndUpdate) {
+ QuicArenaScopedPtr<TestDelegate> delegate =
+ QuicArenaScopedPtr<TestDelegate>(new TestDelegate());
+ TestDelegate* unowned_delegate = delegate.get();
+ QuicArenaScopedPtr<QuicAlarm> alarm(
+ alarm_factory_.CreateAlarm(std::move(delegate), GetArenaParam()));
+
+ QuicTime start = clock_.Now();
+ QuicTime::Delta delta = QuicTime::Delta::FromMicroseconds(1);
+ alarm->Set(clock_.Now().Add(delta));
+ QuicTime::Delta new_delta = QuicTime::Delta::FromMicroseconds(3);
+ alarm->Update(clock_.Now().Add(new_delta),
+ QuicTime::Delta::FromMicroseconds(1));
+
+ epoll_server_.AdvanceByExactlyAndCallCallbacks(delta.ToMicroseconds());
+ EXPECT_EQ(start.Add(delta), clock_.Now());
+ EXPECT_FALSE(unowned_delegate->fired());
+
+ // Move the alarm forward 1us and ensure it doesn't move forward.
+ alarm->Update(clock_.Now().Add(new_delta),
+ QuicTime::Delta::FromMicroseconds(2));
+
+ epoll_server_.AdvanceByExactlyAndCallCallbacks(
+ new_delta.Subtract(delta).ToMicroseconds());
+ EXPECT_EQ(start.Add(new_delta), clock_.Now());
+ EXPECT_TRUE(unowned_delegate->fired());
+
+ // Set the alarm via an update call.
+ new_delta = QuicTime::Delta::FromMicroseconds(5);
+ alarm->Update(clock_.Now().Add(new_delta),
+ QuicTime::Delta::FromMicroseconds(1));
+ EXPECT_TRUE(alarm->IsSet());
+
+ // Update it with an uninitialized time and ensure it's cancelled.
+ alarm->Update(QuicTime::Zero(), QuicTime::Delta::FromMicroseconds(1));
+ EXPECT_FALSE(alarm->IsSet());
+}
+
+} // namespace
+} // namespace test
+} // namespace net
« no previous file with comments | « net/tools/quic/quic_epoll_alarm_factory.cc ('k') | net/tools/quic/quic_epoll_connection_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698