| 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..f7c01fadbb51bbcb3c91722954149b46c12e891a
|
| --- /dev/null
|
| +++ b/net/base/socket_performance_watcher_unittest.cc
|
| @@ -0,0 +1,69 @@
|
| +// 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 ShouldNotifyUpdatedRTT()
|
| +// correctly.
|
| +// TODO(tbansal): crbug.com/590300: Tighten up this test once
|
| +// ShouldNotifyUpdatedRTT() 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
|
|
|