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

Side by Side Diff: net/nqe/event_creator_unittest.cc

Issue 2724403004: NQE: Add net log event if the metric changes substantially (Closed)
Patch Set: ryansturm comments Created 3 years, 9 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
« no previous file with comments | « net/nqe/event_creator.cc ('k') | net/nqe/network_quality_estimator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 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/nqe/event_creator.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "base/time/time.h"
9 #include "net/log/net_log_with_source.h"
10 #include "net/log/test_net_log.h"
11 #include "net/log/test_net_log_entry.h"
12 #include "net/nqe/effective_connection_type.h"
13 #include "net/nqe/network_quality.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 namespace net {
17
18 namespace nqe {
19
20 namespace internal {
21
22 namespace {
23
24 // Returns the number of entries in |net_log| that have type set to
25 // |NetLogEventType::NETWORK_QUALITY_CHANGED|.
26 int GetNetworkQualityChangedEntriesCount(BoundTestNetLog* net_log) {
27 TestNetLogEntry::List entries;
28 net_log->GetEntries(&entries);
29
30 int count = 0;
31 for (const auto& entry : entries) {
32 if (entry.type == NetLogEventType::NETWORK_QUALITY_CHANGED)
33 ++count;
34 }
35 return count;
36 }
37
38 // Verify that the net log events are recorded correctly.
39 TEST(NetworkQualityEstimatorEventCreatorTest, Notified) {
40 // std::unique_ptr<BoundTestNetLog>
41 // net_log(base::MakeUnique<BoundTestNetLog>());
42 BoundTestNetLog net_log;
43
44 EventCreator event_creator(net_log.bound());
45
46 NetworkQuality network_quality_100(base::TimeDelta::FromMilliseconds(100),
47 base::TimeDelta::FromMilliseconds(100),
48 100);
49
50 event_creator.MaybeAddNetworkQualityChangedEventToNetLog(
51 EFFECTIVE_CONNECTION_TYPE_2G, network_quality_100);
52 EXPECT_EQ(1, GetNetworkQualityChangedEntriesCount(&net_log));
53
54 // No new entry should be created since the network quality has not changed.
55 event_creator.MaybeAddNetworkQualityChangedEventToNetLog(
56 EFFECTIVE_CONNECTION_TYPE_2G, network_quality_100);
57 EXPECT_EQ(1, GetNetworkQualityChangedEntriesCount(&net_log));
58
59 // A new entry should be created since effective connection type has changed.
60 event_creator.MaybeAddNetworkQualityChangedEventToNetLog(
61 EFFECTIVE_CONNECTION_TYPE_3G, network_quality_100);
62 EXPECT_EQ(2, GetNetworkQualityChangedEntriesCount(&net_log));
63
64 // A new entry should not be created since HTTP RTT has not changed
65 // meaningfully.
66 NetworkQuality network_quality_http_rtt_110(
67 base::TimeDelta::FromMilliseconds(110),
68 base::TimeDelta::FromMilliseconds(100), 100);
69 event_creator.MaybeAddNetworkQualityChangedEventToNetLog(
70 EFFECTIVE_CONNECTION_TYPE_3G, network_quality_http_rtt_110);
71 EXPECT_EQ(2, GetNetworkQualityChangedEntriesCount(&net_log));
72
73 // A new entry should be created since HTTP RTT has changed meaningfully.
74 NetworkQuality network_quality_http_rtt_300(
75 base::TimeDelta::FromMilliseconds(300),
76 base::TimeDelta::FromMilliseconds(100), 100);
77 event_creator.MaybeAddNetworkQualityChangedEventToNetLog(
78 EFFECTIVE_CONNECTION_TYPE_3G, network_quality_http_rtt_300);
79 EXPECT_EQ(3, GetNetworkQualityChangedEntriesCount(&net_log));
80
81 // A new entry should be created since transport RTT has changed meaningfully.
82 NetworkQuality network_quality_transport_rtt_300(
83 base::TimeDelta::FromMilliseconds(300),
84 base::TimeDelta::FromMilliseconds(300), 100);
85 event_creator.MaybeAddNetworkQualityChangedEventToNetLog(
86 EFFECTIVE_CONNECTION_TYPE_3G, network_quality_transport_rtt_300);
87 EXPECT_EQ(4, GetNetworkQualityChangedEntriesCount(&net_log));
88
89 // A new entry should be created since bandwidth has changed meaningfully.
90 NetworkQuality network_quality_kbps_300(
91 base::TimeDelta::FromMilliseconds(300),
92 base::TimeDelta::FromMilliseconds(300), 300);
93 event_creator.MaybeAddNetworkQualityChangedEventToNetLog(
94 EFFECTIVE_CONNECTION_TYPE_3G, network_quality_kbps_300);
95 EXPECT_EQ(5, GetNetworkQualityChangedEntriesCount(&net_log));
96
97 // A new entry should not be created since network quality has not changed
98 // meaningfully.
99 event_creator.MaybeAddNetworkQualityChangedEventToNetLog(
100 EFFECTIVE_CONNECTION_TYPE_3G, network_quality_kbps_300);
101 EXPECT_EQ(5, GetNetworkQualityChangedEntriesCount(&net_log));
102
103 // A new entry should be created since bandwidth has changed meaningfully.
104 NetworkQuality network_quality_kbps_2000(
105 base::TimeDelta::FromMilliseconds(300),
106 base::TimeDelta::FromMilliseconds(300), 2000);
107 event_creator.MaybeAddNetworkQualityChangedEventToNetLog(
108 EFFECTIVE_CONNECTION_TYPE_3G, network_quality_kbps_2000);
109 EXPECT_EQ(6, GetNetworkQualityChangedEntriesCount(&net_log));
110
111 // A new entry should not be created since bandwidth has not changed by more
112 // than 20%.
113 NetworkQuality network_quality_kbps_2200(
114 base::TimeDelta::FromMilliseconds(300),
115 base::TimeDelta::FromMilliseconds(300), 2200);
116 event_creator.MaybeAddNetworkQualityChangedEventToNetLog(
117 EFFECTIVE_CONNECTION_TYPE_3G, network_quality_kbps_2200);
118 EXPECT_EQ(6, GetNetworkQualityChangedEntriesCount(&net_log));
119 }
120
121 } // namespace
122
123 } // namespace internal
124
125 } // namespace nqe
126
127 } // namespace net
OLDNEW
« no previous file with comments | « net/nqe/event_creator.cc ('k') | net/nqe/network_quality_estimator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698