OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/nqe/network_quality_observation.h" | 5 #include "net/nqe/observation_buffer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/test/simple_test_tick_clock.h" | |
13 #include "base/time/time.h" | 15 #include "base/time/time.h" |
14 #include "net/nqe/network_quality_observation_source.h" | 16 #include "net/nqe/network_quality_observation_source.h" |
RyanSturm
2016/09/26 18:44:55
#include "net/nqe/network_quality_observation.h"
tbansal1
2016/09/28 16:42:32
Done.
| |
15 #include "net/nqe/observation_buffer.h" | |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 namespace net { | 19 namespace net { |
19 | 20 |
20 namespace nqe { | 21 namespace nqe { |
21 | 22 |
23 namespace internal { | |
RyanSturm
2016/09/26 18:44:55
nit: Why did you move to internal? Is that really
tbansal1
2016/09/28 16:42:31
It avoids the need to prefix internal:: to some of
| |
24 | |
22 namespace { | 25 namespace { |
23 | 26 |
27 // Verify that the buffer size is never exceeded. | |
28 TEST(NetworkQualityObservationBufferTest, BoundedBuffer) { | |
29 ObservationBuffer<int32_t> observation_buffer(1.0); | |
30 const base::TimeTicks now = | |
31 base::TimeTicks() + base::TimeDelta::FromSeconds(1); | |
32 for (int i = 1; i <= 1000; ++i) { | |
33 observation_buffer.AddObservation( | |
34 Observation<int32_t>(i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_TCP)); | |
35 // The number of entries should be at most the maximum buffer size. | |
36 EXPECT_GE(300u, observation_buffer.Size()); | |
37 } | |
38 } | |
39 | |
40 // Verify that the percentiles are correctly computed when different | |
RyanSturm
2016/09/26 18:44:55
"correctly" seems to imply that the values are dec
tbansal1
2016/09/28 16:42:32
Done.
| |
41 // observations have different weights. | |
42 TEST(NetworkQualityObservationBufferTest, GetPercentileWithWeights) { | |
43 std::unique_ptr<base::SimpleTestTickClock> tick_clock( | |
44 new base::SimpleTestTickClock()); | |
45 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); | |
46 | |
47 ObservationBuffer<int32_t> observation_buffer(0.005); | |
48 observation_buffer.SetTickClockForTesting(std::move(tick_clock)); | |
49 const base::TimeTicks now = tick_clock_ptr->NowTicks(); | |
50 for (int i = 1; i <= 100; ++i) { | |
51 observation_buffer.AddObservation( | |
52 Observation<int32_t>(i, now + base::TimeDelta::FromSeconds(i), | |
53 NETWORK_QUALITY_OBSERVATION_SOURCE_TCP)); | |
54 } | |
55 EXPECT_EQ(100U, observation_buffer.Size()); | |
56 | |
57 tick_clock_ptr->Advance(base::TimeDelta::FromSeconds(100)); | |
RyanSturm
2016/09/26 18:44:55
Can you call Advance in the for loop above and ins
tbansal1
2016/09/28 16:42:31
Done.
| |
58 for (int i = 1; i <= 100; ++i) { | |
59 // Verify that i'th percentile is more than i-1'th percentile. | |
60 int32_t result_i; | |
61 EXPECT_TRUE(observation_buffer.GetPercentile( | |
62 now, &result_i, i, std::vector<NetworkQualityObservationSource>())); | |
63 | |
64 int32_t result_i_1; | |
65 EXPECT_TRUE(observation_buffer.GetPercentile( | |
66 now, &result_i_1, i - 1, | |
67 std::vector<NetworkQualityObservationSource>())); | |
68 | |
69 EXPECT_LE(result_i_1, result_i); | |
70 } | |
71 } | |
72 | |
24 // Verifies that the percentiles are correctly computed. All observations have | 73 // Verifies that the percentiles are correctly computed. All observations have |
25 // the same timestamp. | 74 // the same timestamp. |
26 TEST(NetworkQualityObservationTest, PercentileSameTimestamps) { | 75 TEST(NetworkQualityObservationBufferTest, PercentileSameTimestamps) { |
27 internal::ObservationBuffer<int32_t> int_buffer(0.5); | 76 ObservationBuffer<int32_t> int_buffer(0.5); |
28 internal::ObservationBuffer<base::TimeDelta> time_delta_buffer(0.5); | 77 ObservationBuffer<base::TimeDelta> time_delta_buffer(0.5); |
29 ASSERT_EQ(0u, int_buffer.Size()); | 78 ASSERT_EQ(0u, int_buffer.Size()); |
30 ASSERT_LT(0u, int_buffer.Capacity()); | 79 ASSERT_LT(0u, int_buffer.Capacity()); |
31 ASSERT_EQ(0u, time_delta_buffer.Size()); | 80 ASSERT_EQ(0u, time_delta_buffer.Size()); |
32 ASSERT_LT(0u, time_delta_buffer.Capacity()); | 81 ASSERT_LT(0u, time_delta_buffer.Capacity()); |
33 | 82 |
34 const base::TimeTicks now = base::TimeTicks::Now(); | 83 const base::TimeTicks now = base::TimeTicks::Now(); |
35 | 84 |
36 int32_t result; | 85 int32_t result; |
37 base::TimeDelta time_delta_result; | 86 base::TimeDelta time_delta_result; |
38 | 87 |
39 // Percentiles should be unavailable when no observations are available. | 88 // Percentiles should be unavailable when no observations are available. |
40 EXPECT_FALSE( | 89 EXPECT_FALSE( |
41 int_buffer.GetPercentile(base::TimeTicks(), &result, 50, | 90 int_buffer.GetPercentile(base::TimeTicks(), &result, 50, |
42 std::vector<NetworkQualityObservationSource>())); | 91 std::vector<NetworkQualityObservationSource>())); |
43 EXPECT_FALSE(time_delta_buffer.GetPercentile( | 92 EXPECT_FALSE(time_delta_buffer.GetPercentile( |
44 base::TimeTicks(), &time_delta_result, 50, | 93 base::TimeTicks(), &time_delta_result, 50, |
45 std::vector<NetworkQualityObservationSource>())); | 94 std::vector<NetworkQualityObservationSource>())); |
46 | 95 |
47 // Insert samples from {1,2,3,..., 100}. First insert odd samples, then even | 96 // Insert samples from {1,2,3,..., 100}. First insert odd samples, then even |
48 // samples. This helps in verifying that the order of samples does not matter. | 97 // samples. This helps in verifying that the order of samples does not matter. |
49 for (int i = 1; i <= 99; i += 2) { | 98 for (int i = 1; i <= 99; i += 2) { |
50 int_buffer.AddObservation(internal::Observation<int32_t>( | 99 int_buffer.AddObservation(Observation<int32_t>( |
51 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 100 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
52 time_delta_buffer.AddObservation(internal::Observation<base::TimeDelta>( | 101 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( |
53 base::TimeDelta::FromMilliseconds(i), now, | 102 base::TimeDelta::FromMilliseconds(i), now, |
54 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 103 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
55 EXPECT_TRUE(int_buffer.GetPercentile( | 104 EXPECT_TRUE(int_buffer.GetPercentile( |
56 base::TimeTicks(), &result, 50, | 105 base::TimeTicks(), &result, 50, |
57 std::vector<NetworkQualityObservationSource>())); | 106 std::vector<NetworkQualityObservationSource>())); |
58 ASSERT_EQ(static_cast<size_t>(i / 2 + 1), int_buffer.Size()); | 107 ASSERT_EQ(static_cast<size_t>(i / 2 + 1), int_buffer.Size()); |
59 EXPECT_TRUE(time_delta_buffer.GetPercentile( | 108 EXPECT_TRUE(time_delta_buffer.GetPercentile( |
60 base::TimeTicks(), &time_delta_result, 50, | 109 base::TimeTicks(), &time_delta_result, 50, |
61 std::vector<NetworkQualityObservationSource>())); | 110 std::vector<NetworkQualityObservationSource>())); |
62 ASSERT_EQ(static_cast<size_t>(i / 2 + 1), time_delta_buffer.Size()); | 111 ASSERT_EQ(static_cast<size_t>(i / 2 + 1), time_delta_buffer.Size()); |
63 } | 112 } |
64 | 113 |
65 for (int i = 2; i <= 100; i += 2) { | 114 for (int i = 2; i <= 100; i += 2) { |
66 int_buffer.AddObservation(internal::Observation<int32_t>( | 115 int_buffer.AddObservation(Observation<int32_t>( |
67 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 116 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
68 time_delta_buffer.AddObservation(internal::Observation<base::TimeDelta>( | 117 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( |
69 base::TimeDelta::FromMilliseconds(i), now, | 118 base::TimeDelta::FromMilliseconds(i), now, |
70 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 119 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
71 EXPECT_TRUE(int_buffer.GetPercentile( | 120 EXPECT_TRUE(int_buffer.GetPercentile( |
72 base::TimeTicks(), &result, 50, | 121 base::TimeTicks(), &result, 50, |
73 std::vector<NetworkQualityObservationSource>())); | 122 std::vector<NetworkQualityObservationSource>())); |
74 ASSERT_EQ(static_cast<size_t>(i / 2 + 50), int_buffer.Size()); | 123 ASSERT_EQ(static_cast<size_t>(i / 2 + 50), int_buffer.Size()); |
75 EXPECT_TRUE(time_delta_buffer.GetPercentile( | 124 EXPECT_TRUE(time_delta_buffer.GetPercentile( |
76 base::TimeTicks(), &time_delta_result, 50, | 125 base::TimeTicks(), &time_delta_result, 50, |
77 std::vector<NetworkQualityObservationSource>())); | 126 std::vector<NetworkQualityObservationSource>())); |
78 ASSERT_EQ(static_cast<size_t>(i / 2 + 50), time_delta_buffer.Size()); | 127 ASSERT_EQ(static_cast<size_t>(i / 2 + 50), time_delta_buffer.Size()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 std::vector<NetworkQualityObservationSource>())); | 160 std::vector<NetworkQualityObservationSource>())); |
112 EXPECT_FALSE(time_delta_buffer.GetPercentile( | 161 EXPECT_FALSE(time_delta_buffer.GetPercentile( |
113 base::TimeTicks(), &time_delta_result, 50, | 162 base::TimeTicks(), &time_delta_result, 50, |
114 std::vector<NetworkQualityObservationSource>())); | 163 std::vector<NetworkQualityObservationSource>())); |
115 } | 164 } |
116 | 165 |
117 // Verifies that the percentiles are correctly computed. Observations have | 166 // Verifies that the percentiles are correctly computed. Observations have |
118 // different timestamps with half the observations being very old and the rest | 167 // different timestamps with half the observations being very old and the rest |
119 // of them being very recent. Percentiles should factor in recent observations | 168 // of them being very recent. Percentiles should factor in recent observations |
120 // much more heavily than older samples. | 169 // much more heavily than older samples. |
121 TEST(NetworkQualityObservationTest, PercentileDifferentTimestamps) { | 170 TEST(NetworkQualityObservationBufferTest, PercentileDifferentTimestamps) { |
122 internal::ObservationBuffer<int32_t> int_buffer(0.5); | 171 ObservationBuffer<int32_t> int_buffer(0.5); |
123 internal::ObservationBuffer<base::TimeDelta> time_delta_buffer(0.5); | 172 ObservationBuffer<base::TimeDelta> time_delta_buffer(0.5); |
124 const base::TimeTicks now = base::TimeTicks::Now(); | 173 const base::TimeTicks now = base::TimeTicks::Now(); |
125 const base::TimeTicks very_old = now - base::TimeDelta::FromDays(365); | 174 const base::TimeTicks very_old = now - base::TimeDelta::FromDays(365); |
126 | 175 |
127 int32_t result; | 176 int32_t result; |
128 base::TimeDelta time_delta_result; | 177 base::TimeDelta time_delta_result; |
129 | 178 |
130 // Network quality should be unavailable when no observations are available. | 179 // Network quality should be unavailable when no observations are available. |
131 EXPECT_FALSE( | 180 EXPECT_FALSE( |
132 int_buffer.GetPercentile(base::TimeTicks(), &result, 50, | 181 int_buffer.GetPercentile(base::TimeTicks(), &result, 50, |
133 std::vector<NetworkQualityObservationSource>())); | 182 std::vector<NetworkQualityObservationSource>())); |
134 EXPECT_FALSE(time_delta_buffer.GetPercentile( | 183 EXPECT_FALSE(time_delta_buffer.GetPercentile( |
135 base::TimeTicks(), &time_delta_result, 50, | 184 base::TimeTicks(), &time_delta_result, 50, |
136 std::vector<NetworkQualityObservationSource>())); | 185 std::vector<NetworkQualityObservationSource>())); |
137 | 186 |
138 // First 50 samples have very old timestamp. | 187 // First 50 samples have very old timestamp. |
139 for (int i = 1; i <= 50; ++i) { | 188 for (int i = 1; i <= 50; ++i) { |
140 int_buffer.AddObservation(internal::Observation<int32_t>( | 189 int_buffer.AddObservation(Observation<int32_t>( |
141 i, very_old, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 190 i, very_old, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
142 time_delta_buffer.AddObservation(internal::Observation<base::TimeDelta>( | 191 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( |
143 base::TimeDelta::FromMilliseconds(i), very_old, | 192 base::TimeDelta::FromMilliseconds(i), very_old, |
144 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 193 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
145 } | 194 } |
146 | 195 |
147 // Next 50 (i.e., from 51 to 100) have recent timestamp. | 196 // Next 50 (i.e., from 51 to 100) have recent timestamp. |
148 for (int i = 51; i <= 100; ++i) { | 197 for (int i = 51; i <= 100; ++i) { |
149 int_buffer.AddObservation(internal::Observation<int32_t>( | 198 int_buffer.AddObservation(Observation<int32_t>( |
150 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 199 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
151 time_delta_buffer.AddObservation(internal::Observation<base::TimeDelta>( | 200 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( |
152 base::TimeDelta::FromMilliseconds(i), now, | 201 base::TimeDelta::FromMilliseconds(i), now, |
153 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 202 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
154 } | 203 } |
155 | 204 |
156 // Older samples have very little weight. So, all percentiles are >= 51 | 205 // Older samples have very little weight. So, all percentiles are >= 51 |
157 // (lowest value among recent observations). | 206 // (lowest value among recent observations). |
158 for (int i = 1; i < 100; ++i) { | 207 for (int i = 1; i < 100; ++i) { |
159 // Checks if the difference between the two integers is less than 1. This is | 208 // Checks if the difference between the two integers is less than 1. This is |
160 // required because computed percentiles may be slightly different from | 209 // required because computed percentiles may be slightly different from |
161 // what is expected due to floating point computation errors and integer | 210 // what is expected due to floating point computation errors and integer |
(...skipping 12 matching lines...) Expand all Loading... | |
174 EXPECT_FALSE(int_buffer.GetPercentile( | 223 EXPECT_FALSE(int_buffer.GetPercentile( |
175 now + base::TimeDelta::FromSeconds(1), &result, 50, | 224 now + base::TimeDelta::FromSeconds(1), &result, 50, |
176 std::vector<NetworkQualityObservationSource>())); | 225 std::vector<NetworkQualityObservationSource>())); |
177 EXPECT_FALSE(time_delta_buffer.GetPercentile( | 226 EXPECT_FALSE(time_delta_buffer.GetPercentile( |
178 now + base::TimeDelta::FromSeconds(1), &time_delta_result, 50, | 227 now + base::TimeDelta::FromSeconds(1), &time_delta_result, 50, |
179 std::vector<NetworkQualityObservationSource>())); | 228 std::vector<NetworkQualityObservationSource>())); |
180 } | 229 } |
181 | 230 |
182 // Verifies that the percentiles are correctly computed when some of the | 231 // Verifies that the percentiles are correctly computed when some of the |
183 // observation sources are disallowed. All observations have the same timestamp. | 232 // observation sources are disallowed. All observations have the same timestamp. |
184 TEST(NetworkQualityObservationTest, DisallowedObservationSources) { | 233 TEST(NetworkQualityObservationBufferTest, DisallowedObservationSources) { |
185 internal::ObservationBuffer<int32_t> int_buffer(0.5); | 234 ObservationBuffer<int32_t> int_buffer(0.5); |
186 internal::ObservationBuffer<base::TimeDelta> time_delta_buffer(0.5); | 235 ObservationBuffer<base::TimeDelta> time_delta_buffer(0.5); |
187 const base::TimeTicks now = base::TimeTicks::Now(); | 236 const base::TimeTicks now = base::TimeTicks::Now(); |
188 | 237 |
189 int32_t result; | 238 int32_t result; |
190 base::TimeDelta time_delta_result; | 239 base::TimeDelta time_delta_result; |
191 | 240 |
192 // Network quality should be unavailable when no observations are available. | 241 // Network quality should be unavailable when no observations are available. |
193 EXPECT_FALSE( | 242 EXPECT_FALSE( |
194 int_buffer.GetPercentile(base::TimeTicks(), &result, 50, | 243 int_buffer.GetPercentile(base::TimeTicks(), &result, 50, |
195 std::vector<NetworkQualityObservationSource>())); | 244 std::vector<NetworkQualityObservationSource>())); |
196 EXPECT_FALSE(time_delta_buffer.GetPercentile( | 245 EXPECT_FALSE(time_delta_buffer.GetPercentile( |
197 base::TimeTicks(), &time_delta_result, 50, | 246 base::TimeTicks(), &time_delta_result, 50, |
198 std::vector<NetworkQualityObservationSource>())); | 247 std::vector<NetworkQualityObservationSource>())); |
199 | 248 |
200 // Insert samples from {1,2,3,..., 100}. First insert odd samples, then even | 249 // Insert samples from {1,2,3,..., 100}. First insert odd samples, then even |
201 // samples. This helps in verifying that the order of samples does not matter. | 250 // samples. This helps in verifying that the order of samples does not matter. |
202 for (int i = 1; i <= 99; i += 2) { | 251 for (int i = 1; i <= 99; i += 2) { |
203 int_buffer.AddObservation(internal::Observation<int32_t>( | 252 int_buffer.AddObservation(Observation<int32_t>( |
204 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 253 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
205 time_delta_buffer.AddObservation(internal::Observation<base::TimeDelta>( | 254 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( |
206 base::TimeDelta::FromMilliseconds(i), now, | 255 base::TimeDelta::FromMilliseconds(i), now, |
207 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 256 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
208 } | 257 } |
209 | 258 |
210 // Add samples for TCP and QUIC observations which should not be taken into | 259 // Add samples for TCP and QUIC observations which should not be taken into |
211 // account when computing the percentile. | 260 // account when computing the percentile. |
212 for (int i = 1; i <= 99; i += 2) { | 261 for (int i = 1; i <= 99; i += 2) { |
213 int_buffer.AddObservation(internal::Observation<int32_t>( | 262 int_buffer.AddObservation(Observation<int32_t>( |
214 10000, now, NETWORK_QUALITY_OBSERVATION_SOURCE_TCP)); | 263 10000, now, NETWORK_QUALITY_OBSERVATION_SOURCE_TCP)); |
215 int_buffer.AddObservation(internal::Observation<int32_t>( | 264 int_buffer.AddObservation(Observation<int32_t>( |
216 10000, now, NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC)); | 265 10000, now, NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC)); |
217 time_delta_buffer.AddObservation(internal::Observation<base::TimeDelta>( | 266 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( |
218 base::TimeDelta::FromMilliseconds(10000), now, | 267 base::TimeDelta::FromMilliseconds(10000), now, |
219 NETWORK_QUALITY_OBSERVATION_SOURCE_TCP)); | 268 NETWORK_QUALITY_OBSERVATION_SOURCE_TCP)); |
220 time_delta_buffer.AddObservation(internal::Observation<base::TimeDelta>( | 269 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( |
221 base::TimeDelta::FromMilliseconds(10000), now, | 270 base::TimeDelta::FromMilliseconds(10000), now, |
222 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC)); | 271 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC)); |
223 } | 272 } |
224 | 273 |
225 for (int i = 2; i <= 100; i += 2) { | 274 for (int i = 2; i <= 100; i += 2) { |
226 int_buffer.AddObservation(internal::Observation<int32_t>( | 275 int_buffer.AddObservation(Observation<int32_t>( |
227 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 276 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
228 time_delta_buffer.AddObservation(internal::Observation<base::TimeDelta>( | 277 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( |
229 base::TimeDelta::FromMilliseconds(i), now, | 278 base::TimeDelta::FromMilliseconds(i), now, |
230 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 279 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
231 } | 280 } |
232 | 281 |
233 std::vector<NetworkQualityObservationSource> disallowed_observation_sources; | 282 std::vector<NetworkQualityObservationSource> disallowed_observation_sources; |
234 disallowed_observation_sources.push_back( | 283 disallowed_observation_sources.push_back( |
235 NETWORK_QUALITY_OBSERVATION_SOURCE_TCP); | 284 NETWORK_QUALITY_OBSERVATION_SOURCE_TCP); |
236 disallowed_observation_sources.push_back( | 285 disallowed_observation_sources.push_back( |
237 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC); | 286 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC); |
238 | 287 |
(...skipping 23 matching lines...) Expand all Loading... | |
262 EXPECT_TRUE(int_buffer.GetPercentile(base::TimeTicks(), &result, i, | 311 EXPECT_TRUE(int_buffer.GetPercentile(base::TimeTicks(), &result, i, |
263 disallowed_observation_sources)); | 312 disallowed_observation_sources)); |
264 EXPECT_NEAR(result, 10000, 1); | 313 EXPECT_NEAR(result, 10000, 1); |
265 EXPECT_TRUE( | 314 EXPECT_TRUE( |
266 time_delta_buffer.GetPercentile(base::TimeTicks(), &time_delta_result, | 315 time_delta_buffer.GetPercentile(base::TimeTicks(), &time_delta_result, |
267 i, disallowed_observation_sources)); | 316 i, disallowed_observation_sources)); |
268 EXPECT_NEAR(time_delta_result.InMilliseconds(), 10000, 1); | 317 EXPECT_NEAR(time_delta_result.InMilliseconds(), 10000, 1); |
269 } | 318 } |
270 } | 319 } |
271 | 320 |
272 TEST(NetworkQualityObservationTest, TestGetMedianRTTSince) { | 321 TEST(NetworkQualityObservationBufferTest, TestGetMedianRTTSince) { |
273 internal::ObservationBuffer<int32_t> int_buffer(0.5); | 322 ObservationBuffer<int32_t> int_buffer(0.5); |
274 internal::ObservationBuffer<base::TimeDelta> time_delta_buffer(0.5); | 323 ObservationBuffer<base::TimeDelta> time_delta_buffer(0.5); |
275 base::TimeTicks now = base::TimeTicks::Now(); | 324 base::TimeTicks now = base::TimeTicks::Now(); |
276 base::TimeTicks old = now - base::TimeDelta::FromMilliseconds(1); | 325 base::TimeTicks old = now - base::TimeDelta::FromMilliseconds(1); |
277 ASSERT_NE(old, now); | 326 ASSERT_NE(old, now); |
278 | 327 |
279 // First sample has very old timestamp. | 328 // First sample has very old timestamp. |
280 int_buffer.AddObservation(internal::Observation<int32_t>( | 329 int_buffer.AddObservation(Observation<int32_t>( |
281 1, old, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 330 1, old, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
282 time_delta_buffer.AddObservation(internal::Observation<base::TimeDelta>( | 331 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( |
283 base::TimeDelta::FromMilliseconds(1), old, | 332 base::TimeDelta::FromMilliseconds(1), old, |
284 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 333 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
285 | 334 |
286 int_buffer.AddObservation(internal::Observation<int32_t>( | 335 int_buffer.AddObservation(Observation<int32_t>( |
287 100, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 336 100, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
288 time_delta_buffer.AddObservation(internal::Observation<base::TimeDelta>( | 337 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( |
289 base::TimeDelta::FromMilliseconds(100), now, | 338 base::TimeDelta::FromMilliseconds(100), now, |
290 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); | 339 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
291 | 340 |
292 const struct { | 341 const struct { |
293 base::TimeTicks start_timestamp; | 342 base::TimeTicks start_timestamp; |
294 bool expect_network_quality_available; | 343 bool expect_network_quality_available; |
295 base::TimeDelta expected_url_request_rtt; | 344 base::TimeDelta expected_url_request_rtt; |
296 int32_t expected_downstream_throughput; | 345 int32_t expected_downstream_throughput; |
297 } tests[] = { | 346 } tests[] = { |
298 {now + base::TimeDelta::FromSeconds(10), false, | 347 {now + base::TimeDelta::FromSeconds(10), false, |
(...skipping 21 matching lines...) Expand all Loading... | |
320 if (test.expect_network_quality_available) { | 369 if (test.expect_network_quality_available) { |
321 EXPECT_EQ(test.expected_url_request_rtt, url_request_rtt); | 370 EXPECT_EQ(test.expected_url_request_rtt, url_request_rtt); |
322 EXPECT_EQ(test.expected_downstream_throughput, | 371 EXPECT_EQ(test.expected_downstream_throughput, |
323 downstream_throughput_kbps); | 372 downstream_throughput_kbps); |
324 } | 373 } |
325 } | 374 } |
326 } | 375 } |
327 | 376 |
328 } // namespace | 377 } // namespace |
329 | 378 |
379 } // namespace internal | |
380 | |
330 } // namespace nqe | 381 } // namespace nqe |
331 | 382 |
332 } // namespace net | 383 } // namespace net |
OLD | NEW |