OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/base/socket_performance_watcher.h" |
| 6 |
| 7 #include <stddef.h> |
| 8 |
| 9 #include "base/macros.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/time/time.h" |
| 12 #include "net/base/socket_performance_watcher_factory.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 |
| 15 namespace net { |
| 16 |
| 17 namespace { |
| 18 |
| 19 class TestSocketPerformanceWatcherFactory |
| 20 : public SocketPerformanceWatcherFactory { |
| 21 public: |
| 22 TestSocketPerformanceWatcherFactory() : rtt_notification_received_count_(0) {} |
| 23 |
| 24 ~TestSocketPerformanceWatcherFactory() override {} |
| 25 |
| 26 // SocketPerformanceWatcherFactory implementation: |
| 27 scoped_ptr<SocketPerformanceWatcher> CreateSocketPerformanceWatcher( |
| 28 const Protocol protocol) override { |
| 29 return scoped_ptr<SocketPerformanceWatcher>( |
| 30 new SocketPerformanceWatcher(protocol, this)); |
| 31 } |
| 32 |
| 33 void OnUpdatedRTTAvailable(const Protocol protocol, |
| 34 const base::TimeDelta& rtt) override { |
| 35 rtt_notification_received_count_++; |
| 36 } |
| 37 |
| 38 void OnWatcherReset() override {} |
| 39 |
| 40 size_t rtt_notification_received_count() const { |
| 41 return rtt_notification_received_count_; |
| 42 } |
| 43 |
| 44 private: |
| 45 size_t rtt_notification_received_count_; |
| 46 |
| 47 DISALLOW_COPY_AND_ASSIGN(TestSocketPerformanceWatcherFactory); |
| 48 }; |
| 49 |
| 50 // Tests if SocketPerformanceWatcher computes ShouldNotifyUpdatedRTT() |
| 51 // correctly. |
| 52 // TODO(tbansal): crbug.com/590300: Tighten up this test once |
| 53 // ShouldNotifyUpdatedRTT() is tuned. |
| 54 TEST(SocketPerformanceWatcherTest, TestCanNotifyRTT) { |
| 55 TestSocketPerformanceWatcherFactory socket_performance_watcher_factory; |
| 56 scoped_ptr<SocketPerformanceWatcher> watcher = |
| 57 socket_performance_watcher_factory.CreateSocketPerformanceWatcher( |
| 58 SocketPerformanceWatcherFactory::PROTOCOL_TCP); |
| 59 watcher->OnUpdatedRTTAvailable(base::TimeDelta::FromSeconds(1)); |
| 60 EXPECT_EQ( |
| 61 1u, socket_performance_watcher_factory.rtt_notification_received_count()); |
| 62 EXPECT_FALSE(watcher->ShouldNotifyUpdatedRTT()); |
| 63 watcher->Reset(); |
| 64 EXPECT_TRUE(watcher->ShouldNotifyUpdatedRTT()); |
| 65 } |
| 66 |
| 67 } // namespace |
| 68 |
| 69 } // namespace net |
OLD | NEW |