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

Side by Side Diff: net/base/socket_performance_watcher_unittest.cc

Issue 1831383002: Add SocketWatcherFactory as a helper class to NQE (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased, removed cyclic dependency between SPWF and SPW 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 unified diff | Download patch
OLDNEW
(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/bind.h"
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/time/time.h"
14 #include "net/base/socket_performance_watcher_factory.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace net {
18
19 namespace {
20
21 class TestSocketPerformanceWatcherFactory
22 : public SocketPerformanceWatcherFactory {
23 public:
24 TestSocketPerformanceWatcherFactory()
25 : rtt_notification_received_count_(0), weak_ptr_factory_(this) {}
26
27 ~TestSocketPerformanceWatcherFactory() override {}
28
29 // SocketPerformanceWatcherFactory implementation:
30 scoped_ptr<SocketPerformanceWatcher> CreateSocketPerformanceWatcher(
31 const Protocol protocol) override {
32 return scoped_ptr<SocketPerformanceWatcher>(new SocketPerformanceWatcher(
33 protocol,
34 base::Bind(&TestSocketPerformanceWatcherFactory::OnUpdatedRTTAvailable,
35 weak_ptr_factory_.GetWeakPtr()),
36 base::Bind(&TestSocketPerformanceWatcherFactory::OnWatcherReset,
37 weak_ptr_factory_.GetWeakPtr())));
38 }
39
40 void OnUpdatedRTTAvailable(const Protocol protocol,
41 const base::TimeDelta& rtt) override {
42 rtt_notification_received_count_++;
43 }
44
45 void OnWatcherReset() override {}
46
47 size_t rtt_notification_received_count() const {
48 return rtt_notification_received_count_;
49 }
50
51 private:
52 size_t rtt_notification_received_count_;
53
54 base::WeakPtrFactory<TestSocketPerformanceWatcherFactory> weak_ptr_factory_;
55
56 DISALLOW_COPY_AND_ASSIGN(TestSocketPerformanceWatcherFactory);
57 };
58
59 // Tests if SocketPerformanceWatcher computes ShouldNotifyUpdatedRTT()
60 // correctly.
61 // TODO(tbansal): crbug.com/590300: Tighten up this test once
62 // ShouldNotifyUpdatedRTT() is tuned.
63 TEST(SocketPerformanceWatcherTest, TestCanNotifyRTT) {
64 TestSocketPerformanceWatcherFactory socket_performance_watcher_factory;
65 scoped_ptr<SocketPerformanceWatcher> watcher =
66 socket_performance_watcher_factory.CreateSocketPerformanceWatcher(
67 SocketPerformanceWatcherFactory::PROTOCOL_TCP);
68 watcher->OnUpdatedRTTAvailable(base::TimeDelta::FromSeconds(1));
69 EXPECT_EQ(
70 1u, socket_performance_watcher_factory.rtt_notification_received_count());
71 EXPECT_FALSE(watcher->ShouldNotifyUpdatedRTT());
72 watcher->Reset();
73 EXPECT_TRUE(watcher->ShouldNotifyUpdatedRTT());
74 }
75
76 } // namespace
77
78 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698