Chromium Code Reviews| Index: net/base/socket_performance_watcher_unittest.cc |
| diff --git a/net/base/socket_performance_watcher_unittest.cc b/net/base/socket_performance_watcher_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a70a34a72d03c0606ad77d5cb123a8d4f27d9ee3 |
| --- /dev/null |
| +++ b/net/base/socket_performance_watcher_unittest.cc |
| @@ -0,0 +1,68 @@ |
| +// Copyright 2016 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/base/socket_performance_watcher.h" |
| + |
| +#include <stddef.h> |
| + |
| +#include "base/macros.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/time/time.h" |
| +#include "net/base/socket_performance_watcher_factory.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace net { |
| + |
| +namespace { |
| + |
| +class TestSocketPerformanceWatcherFactory |
| + : public SocketPerformanceWatcherFactory { |
| + public: |
| + TestSocketPerformanceWatcherFactory() : rtt_notification_received_count_(0) {} |
| + |
| + ~TestSocketPerformanceWatcherFactory() override {} |
| + |
| + // SocketPerformanceWatcherFactory implementation: |
| + scoped_ptr<SocketPerformanceWatcher> CreateSocketPerformanceWatcher( |
| + const Protocol protocol) override { |
| + return scoped_ptr<SocketPerformanceWatcher>( |
| + new SocketPerformanceWatcher(protocol, this)); |
| + } |
| + |
| + void OnUpdatedRTTAvailable(const Protocol protocol, |
| + const base::TimeDelta& rtt) override { |
| + rtt_notification_received_count_++; |
| + } |
| + |
| + void OnWatcherReset() override {} |
| + |
| + size_t rtt_notification_received_count() const { |
| + return rtt_notification_received_count_; |
| + } |
| + |
| + private: |
| + size_t rtt_notification_received_count_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TestSocketPerformanceWatcherFactory); |
| +}; |
| + |
| +// Tests if SocketPerformanceWatcher computes CanNotifyRTT() correctly. |
|
Ryan Sleevi
2016/03/04 01:38:38
Out of date comment (CanNotifyRTT)
tbansal1
2016/03/04 02:37:54
Done.
|
| +// TODO(tbansal): crbug.com/590300: Tighten up this test once CanNotifyRTT() is |
| +// tuned. |
| +TEST(SocketPerformanceWatcherTest, TestCanNotifyRTT) { |
| + TestSocketPerformanceWatcherFactory socket_performance_watcher_factory; |
| + scoped_ptr<SocketPerformanceWatcher> watcher = |
| + socket_performance_watcher_factory.CreateSocketPerformanceWatcher( |
| + SocketPerformanceWatcherFactory::PROTOCOL_TCP); |
| + watcher->OnUpdatedRTTAvailable(base::TimeDelta::FromSeconds(1)); |
| + EXPECT_EQ( |
| + 1u, socket_performance_watcher_factory.rtt_notification_received_count()); |
| + EXPECT_FALSE(watcher->ShouldNotifyUpdatedRTT()); |
| + watcher->Reset(); |
| + EXPECT_TRUE(watcher->ShouldNotifyUpdatedRTT()); |
| +} |
| + |
| +} // namespace |
| + |
| +} // namespace net |