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

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

Issue 2453653002: Separate out observation sources as either HTTP layer or transport layer (Closed)
Patch Set: Addressed bengr comments Created 4 years, 1 month 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/network_quality_observation_source.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/observation_buffer.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 <memory>
10 #include <utility> 10 #include <utility>
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 EXPECT_FALSE( 103 EXPECT_FALSE(
104 int_buffer.GetPercentile(base::TimeTicks(), &result, 50, 104 int_buffer.GetPercentile(base::TimeTicks(), &result, 50,
105 std::vector<NetworkQualityObservationSource>())); 105 std::vector<NetworkQualityObservationSource>()));
106 EXPECT_FALSE(time_delta_buffer.GetPercentile( 106 EXPECT_FALSE(time_delta_buffer.GetPercentile(
107 base::TimeTicks(), &time_delta_result, 50, 107 base::TimeTicks(), &time_delta_result, 50,
108 std::vector<NetworkQualityObservationSource>())); 108 std::vector<NetworkQualityObservationSource>()));
109 109
110 // Insert samples from {1,2,3,..., 100}. First insert odd samples, then even 110 // Insert samples from {1,2,3,..., 100}. First insert odd samples, then even
111 // samples. This helps in verifying that the order of samples does not matter. 111 // samples. This helps in verifying that the order of samples does not matter.
112 for (int i = 1; i <= 99; i += 2) { 112 for (int i = 1; i <= 99; i += 2) {
113 int_buffer.AddObservation(Observation<int32_t>( 113 int_buffer.AddObservation(
114 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 114 Observation<int32_t>(i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
115 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( 115 time_delta_buffer.AddObservation(
116 base::TimeDelta::FromMilliseconds(i), now, 116 Observation<base::TimeDelta>(base::TimeDelta::FromMilliseconds(i), now,
117 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 117 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
118 EXPECT_TRUE(int_buffer.GetPercentile( 118 EXPECT_TRUE(int_buffer.GetPercentile(
119 base::TimeTicks(), &result, 50, 119 base::TimeTicks(), &result, 50,
120 std::vector<NetworkQualityObservationSource>())); 120 std::vector<NetworkQualityObservationSource>()));
121 ASSERT_EQ(static_cast<size_t>(i / 2 + 1), int_buffer.Size()); 121 ASSERT_EQ(static_cast<size_t>(i / 2 + 1), int_buffer.Size());
122 EXPECT_TRUE(time_delta_buffer.GetPercentile( 122 EXPECT_TRUE(time_delta_buffer.GetPercentile(
123 base::TimeTicks(), &time_delta_result, 50, 123 base::TimeTicks(), &time_delta_result, 50,
124 std::vector<NetworkQualityObservationSource>())); 124 std::vector<NetworkQualityObservationSource>()));
125 ASSERT_EQ(static_cast<size_t>(i / 2 + 1), time_delta_buffer.Size()); 125 ASSERT_EQ(static_cast<size_t>(i / 2 + 1), time_delta_buffer.Size());
126 } 126 }
127 127
128 for (int i = 2; i <= 100; i += 2) { 128 for (int i = 2; i <= 100; i += 2) {
129 int_buffer.AddObservation(Observation<int32_t>( 129 int_buffer.AddObservation(
130 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 130 Observation<int32_t>(i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
131 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( 131 time_delta_buffer.AddObservation(
132 base::TimeDelta::FromMilliseconds(i), now, 132 Observation<base::TimeDelta>(base::TimeDelta::FromMilliseconds(i), now,
133 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 133 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
134 EXPECT_TRUE(int_buffer.GetPercentile( 134 EXPECT_TRUE(int_buffer.GetPercentile(
135 base::TimeTicks(), &result, 50, 135 base::TimeTicks(), &result, 50,
136 std::vector<NetworkQualityObservationSource>())); 136 std::vector<NetworkQualityObservationSource>()));
137 ASSERT_EQ(static_cast<size_t>(i / 2 + 50), int_buffer.Size()); 137 ASSERT_EQ(static_cast<size_t>(i / 2 + 50), int_buffer.Size());
138 EXPECT_TRUE(time_delta_buffer.GetPercentile( 138 EXPECT_TRUE(time_delta_buffer.GetPercentile(
139 base::TimeTicks(), &time_delta_result, 50, 139 base::TimeTicks(), &time_delta_result, 50,
140 std::vector<NetworkQualityObservationSource>())); 140 std::vector<NetworkQualityObservationSource>()));
141 ASSERT_EQ(static_cast<size_t>(i / 2 + 50), time_delta_buffer.Size()); 141 ASSERT_EQ(static_cast<size_t>(i / 2 + 50), time_delta_buffer.Size());
142 } 142 }
143 143
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 EXPECT_FALSE( 194 EXPECT_FALSE(
195 int_buffer.GetPercentile(base::TimeTicks(), &result, 50, 195 int_buffer.GetPercentile(base::TimeTicks(), &result, 50,
196 std::vector<NetworkQualityObservationSource>())); 196 std::vector<NetworkQualityObservationSource>()));
197 EXPECT_FALSE(time_delta_buffer.GetPercentile( 197 EXPECT_FALSE(time_delta_buffer.GetPercentile(
198 base::TimeTicks(), &time_delta_result, 50, 198 base::TimeTicks(), &time_delta_result, 50,
199 std::vector<NetworkQualityObservationSource>())); 199 std::vector<NetworkQualityObservationSource>()));
200 200
201 // First 50 samples have very old timestamps. 201 // First 50 samples have very old timestamps.
202 for (int i = 1; i <= 50; ++i) { 202 for (int i = 1; i <= 50; ++i) {
203 int_buffer.AddObservation(Observation<int32_t>( 203 int_buffer.AddObservation(Observation<int32_t>(
204 i, very_old, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 204 i, very_old, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
205 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( 205 time_delta_buffer.AddObservation(Observation<base::TimeDelta>(
206 base::TimeDelta::FromMilliseconds(i), very_old, 206 base::TimeDelta::FromMilliseconds(i), very_old,
207 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 207 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
208 } 208 }
209 209
210 // Next 50 (i.e., from 51 to 100) have recent timestamps. 210 // Next 50 (i.e., from 51 to 100) have recent timestamps.
211 for (int i = 51; i <= 100; ++i) { 211 for (int i = 51; i <= 100; ++i) {
212 int_buffer.AddObservation(Observation<int32_t>( 212 int_buffer.AddObservation(
213 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 213 Observation<int32_t>(i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
214 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( 214 time_delta_buffer.AddObservation(
215 base::TimeDelta::FromMilliseconds(i), now, 215 Observation<base::TimeDelta>(base::TimeDelta::FromMilliseconds(i), now,
216 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 216 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
217 } 217 }
218 218
219 // Older samples have very little weight. So, all percentiles are >= 51 219 // Older samples have very little weight. So, all percentiles are >= 51
220 // (lowest value among recent observations). 220 // (lowest value among recent observations).
221 for (int i = 1; i < 100; ++i) { 221 for (int i = 1; i < 100; ++i) {
222 // Checks if the difference between the two integers is less than 1. This is 222 // Checks if the difference between the two integers is less than 1. This is
223 // required because computed percentiles may be slightly different from 223 // required because computed percentiles may be slightly different from
224 // what is expected due to floating point computation errors and integer 224 // what is expected due to floating point computation errors and integer
225 // rounding off errors. 225 // rounding off errors.
226 EXPECT_TRUE(int_buffer.GetPercentile( 226 EXPECT_TRUE(int_buffer.GetPercentile(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 base::TimeTicks(), std::vector<NetworkQualityObservationSource>(), 262 base::TimeTicks(), std::vector<NetworkQualityObservationSource>(),
263 &time_delta_result)); 263 &time_delta_result));
264 EXPECT_FALSE(int_buffer.GetUnweightedAverage( 264 EXPECT_FALSE(int_buffer.GetUnweightedAverage(
265 base::TimeTicks(), std::vector<NetworkQualityObservationSource>(), 265 base::TimeTicks(), std::vector<NetworkQualityObservationSource>(),
266 &int_result)); 266 &int_result));
267 267
268 // The first 50 samples have very old timestamps. 268 // The first 50 samples have very old timestamps.
269 for (int i = 1; i <= 50; ++i) { 269 for (int i = 1; i <= 50; ++i) {
270 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( 270 time_delta_buffer.AddObservation(Observation<base::TimeDelta>(
271 base::TimeDelta::FromMilliseconds(i), very_old, 271 base::TimeDelta::FromMilliseconds(i), very_old,
272 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 272 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
273 int_buffer.AddObservation(Observation<int32_t>( 273 int_buffer.AddObservation(Observation<int32_t>(
274 i, very_old, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 274 i, very_old, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
275 } 275 }
276 276
277 // The next 50 (i.e., from 51 to 100) samples have recent timestamps. 277 // The next 50 (i.e., from 51 to 100) samples have recent timestamps.
278 for (int i = 51; i <= 100; ++i) { 278 for (int i = 51; i <= 100; ++i) {
279 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( 279 time_delta_buffer.AddObservation(
280 base::TimeDelta::FromMilliseconds(i), now, 280 Observation<base::TimeDelta>(base::TimeDelta::FromMilliseconds(i), now,
281 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 281 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
282 int_buffer.AddObservation(Observation<int32_t>( 282 int_buffer.AddObservation(
283 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 283 Observation<int32_t>(i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
284 } 284 }
285 285
286 // All samples have equal weight. So, the unweighted average is the average of 286 // All samples have equal weight. So, the unweighted average is the average of
287 // all samples. 287 // all samples.
288 EXPECT_TRUE(time_delta_buffer.GetUnweightedAverage( 288 EXPECT_TRUE(time_delta_buffer.GetUnweightedAverage(
289 very_old, std::vector<NetworkQualityObservationSource>(), 289 very_old, std::vector<NetworkQualityObservationSource>(),
290 &time_delta_result)); 290 &time_delta_result));
291 EXPECT_NEAR(time_delta_result.InMilliseconds(), (1 + 100) / 2, 1); 291 EXPECT_NEAR(time_delta_result.InMilliseconds(), (1 + 100) / 2, 1);
292 292
293 EXPECT_TRUE(int_buffer.GetUnweightedAverage( 293 EXPECT_TRUE(int_buffer.GetUnweightedAverage(
(...skipping 22 matching lines...) Expand all
316 base::TimeTicks(), std::vector<NetworkQualityObservationSource>(), 316 base::TimeTicks(), std::vector<NetworkQualityObservationSource>(),
317 &time_delta_result)); 317 &time_delta_result));
318 EXPECT_FALSE(int_buffer.GetWeightedAverage( 318 EXPECT_FALSE(int_buffer.GetWeightedAverage(
319 base::TimeTicks(), std::vector<NetworkQualityObservationSource>(), 319 base::TimeTicks(), std::vector<NetworkQualityObservationSource>(),
320 &int_result)); 320 &int_result));
321 321
322 // The first 50 samples have very old timestamps. 322 // The first 50 samples have very old timestamps.
323 for (int i = 1; i <= 50; ++i) { 323 for (int i = 1; i <= 50; ++i) {
324 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( 324 time_delta_buffer.AddObservation(Observation<base::TimeDelta>(
325 base::TimeDelta::FromMilliseconds(i), very_old, 325 base::TimeDelta::FromMilliseconds(i), very_old,
326 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 326 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
327 int_buffer.AddObservation(Observation<int32_t>( 327 int_buffer.AddObservation(Observation<int32_t>(
328 i, very_old, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 328 i, very_old, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
329 } 329 }
330 330
331 // The next 50 (i.e., from 51 to 100) samples have recent timestamps. 331 // The next 50 (i.e., from 51 to 100) samples have recent timestamps.
332 for (int i = 51; i <= 100; ++i) { 332 for (int i = 51; i <= 100; ++i) {
333 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( 333 time_delta_buffer.AddObservation(
334 base::TimeDelta::FromMilliseconds(i), now, 334 Observation<base::TimeDelta>(base::TimeDelta::FromMilliseconds(i), now,
335 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 335 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
336 int_buffer.AddObservation(Observation<int32_t>( 336 int_buffer.AddObservation(
337 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 337 Observation<int32_t>(i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
338 } 338 }
339 339
340 // The older samples have very little weight, and so the weighted average must 340 // The older samples have very little weight, and so the weighted average must
341 // be approximately equal to the average of all recent samples. 341 // be approximately equal to the average of all recent samples.
342 EXPECT_TRUE(time_delta_buffer.GetWeightedAverage( 342 EXPECT_TRUE(time_delta_buffer.GetWeightedAverage(
343 very_old, std::vector<NetworkQualityObservationSource>(), 343 very_old, std::vector<NetworkQualityObservationSource>(),
344 &time_delta_result)); 344 &time_delta_result));
345 EXPECT_NEAR(time_delta_result.InMilliseconds(), (51 + 100) / 2, 1); 345 EXPECT_NEAR(time_delta_result.InMilliseconds(), (51 + 100) / 2, 1);
346 346
347 EXPECT_TRUE(int_buffer.GetWeightedAverage( 347 EXPECT_TRUE(int_buffer.GetWeightedAverage(
(...skipping 23 matching lines...) Expand all
371 EXPECT_FALSE( 371 EXPECT_FALSE(
372 int_buffer.GetPercentile(base::TimeTicks(), &result, 50, 372 int_buffer.GetPercentile(base::TimeTicks(), &result, 50,
373 std::vector<NetworkQualityObservationSource>())); 373 std::vector<NetworkQualityObservationSource>()));
374 EXPECT_FALSE(time_delta_buffer.GetPercentile( 374 EXPECT_FALSE(time_delta_buffer.GetPercentile(
375 base::TimeTicks(), &time_delta_result, 50, 375 base::TimeTicks(), &time_delta_result, 50,
376 std::vector<NetworkQualityObservationSource>())); 376 std::vector<NetworkQualityObservationSource>()));
377 377
378 // Insert samples from {1,2,3,..., 100}. First insert odd samples, then even 378 // Insert samples from {1,2,3,..., 100}. First insert odd samples, then even
379 // samples. This helps in verifying that the order of samples does not matter. 379 // samples. This helps in verifying that the order of samples does not matter.
380 for (int i = 1; i <= 99; i += 2) { 380 for (int i = 1; i <= 99; i += 2) {
381 int_buffer.AddObservation(Observation<int32_t>( 381 int_buffer.AddObservation(
382 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 382 Observation<int32_t>(i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
383 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( 383 time_delta_buffer.AddObservation(
384 base::TimeDelta::FromMilliseconds(i), now, 384 Observation<base::TimeDelta>(base::TimeDelta::FromMilliseconds(i), now,
385 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 385 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
386 } 386 }
387 387
388 // Add samples for TCP and QUIC observations which should not be taken into 388 // Add samples for TCP and QUIC observations which should not be taken into
389 // account when computing the percentile. 389 // account when computing the percentile.
390 for (int i = 1; i <= 99; i += 2) { 390 for (int i = 1; i <= 99; i += 2) {
391 int_buffer.AddObservation(Observation<int32_t>( 391 int_buffer.AddObservation(Observation<int32_t>(
392 10000, now, NETWORK_QUALITY_OBSERVATION_SOURCE_TCP)); 392 10000, now, NETWORK_QUALITY_OBSERVATION_SOURCE_TCP));
393 int_buffer.AddObservation(Observation<int32_t>( 393 int_buffer.AddObservation(Observation<int32_t>(
394 10000, now, NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC)); 394 10000, now, NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC));
395 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( 395 time_delta_buffer.AddObservation(Observation<base::TimeDelta>(
396 base::TimeDelta::FromMilliseconds(10000), now, 396 base::TimeDelta::FromMilliseconds(10000), now,
397 NETWORK_QUALITY_OBSERVATION_SOURCE_TCP)); 397 NETWORK_QUALITY_OBSERVATION_SOURCE_TCP));
398 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( 398 time_delta_buffer.AddObservation(Observation<base::TimeDelta>(
399 base::TimeDelta::FromMilliseconds(10000), now, 399 base::TimeDelta::FromMilliseconds(10000), now,
400 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC)); 400 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC));
401 } 401 }
402 402
403 for (int i = 2; i <= 100; i += 2) { 403 for (int i = 2; i <= 100; i += 2) {
404 int_buffer.AddObservation(Observation<int32_t>( 404 int_buffer.AddObservation(
405 i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 405 Observation<int32_t>(i, now, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
406 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( 406 time_delta_buffer.AddObservation(
407 base::TimeDelta::FromMilliseconds(i), now, 407 Observation<base::TimeDelta>(base::TimeDelta::FromMilliseconds(i), now,
408 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 408 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
409 } 409 }
410 410
411 std::vector<NetworkQualityObservationSource> disallowed_observation_sources; 411 std::vector<NetworkQualityObservationSource> disallowed_observation_sources;
412 disallowed_observation_sources.push_back( 412 disallowed_observation_sources.push_back(
413 NETWORK_QUALITY_OBSERVATION_SOURCE_TCP); 413 NETWORK_QUALITY_OBSERVATION_SOURCE_TCP);
414 disallowed_observation_sources.push_back( 414 disallowed_observation_sources.push_back(
415 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC); 415 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC);
416 416
417 for (int i = 0; i <= 100; ++i) { 417 for (int i = 0; i <= 100; ++i) {
418 // Checks if the difference between the two integers is less than 1. This is 418 // Checks if the difference between the two integers is less than 1. This is
419 // required because computed percentiles may be slightly different from 419 // required because computed percentiles may be slightly different from
420 // what is expected due to floating point computation errors and integer 420 // what is expected due to floating point computation errors and integer
421 // rounding off errors. 421 // rounding off errors.
422 EXPECT_TRUE(int_buffer.GetPercentile(base::TimeTicks(), &result, i, 422 EXPECT_TRUE(int_buffer.GetPercentile(base::TimeTicks(), &result, i,
423 disallowed_observation_sources)); 423 disallowed_observation_sources));
424 EXPECT_NEAR(result, i, 1); 424 EXPECT_NEAR(result, i, 1);
425 EXPECT_TRUE( 425 EXPECT_TRUE(
426 time_delta_buffer.GetPercentile(base::TimeTicks(), &time_delta_result, 426 time_delta_buffer.GetPercentile(base::TimeTicks(), &time_delta_result,
427 i, disallowed_observation_sources)); 427 i, disallowed_observation_sources));
428 EXPECT_NEAR(time_delta_result.InMilliseconds(), i, 1); 428 EXPECT_NEAR(time_delta_result.InMilliseconds(), i, 1);
429 } 429 }
430 430
431 // Now check the percentile value for TCP and QUIC observations. 431 // Now check the percentile value for TCP and QUIC observations.
432 disallowed_observation_sources.clear(); 432 disallowed_observation_sources.clear();
433 disallowed_observation_sources.push_back( 433 disallowed_observation_sources.push_back(
434 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST); 434 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP);
435 for (int i = 0; i <= 100; ++i) { 435 for (int i = 0; i <= 100; ++i) {
436 // Checks if the difference between the two integers is less than 1. This is 436 // Checks if the difference between the two integers is less than 1. This is
437 // required because computed percentiles may be slightly different from 437 // required because computed percentiles may be slightly different from
438 // what is expected due to floating point computation errors and integer 438 // what is expected due to floating point computation errors and integer
439 // rounding off errors. 439 // rounding off errors.
440 EXPECT_TRUE(int_buffer.GetPercentile(base::TimeTicks(), &result, i, 440 EXPECT_TRUE(int_buffer.GetPercentile(base::TimeTicks(), &result, i,
441 disallowed_observation_sources)); 441 disallowed_observation_sources));
442 EXPECT_NEAR(result, 10000, 1); 442 EXPECT_NEAR(result, 10000, 1);
443 EXPECT_TRUE( 443 EXPECT_TRUE(
444 time_delta_buffer.GetPercentile(base::TimeTicks(), &time_delta_result, 444 time_delta_buffer.GetPercentile(base::TimeTicks(), &time_delta_result,
445 i, disallowed_observation_sources)); 445 i, disallowed_observation_sources));
446 EXPECT_NEAR(time_delta_result.InMilliseconds(), 10000, 1); 446 EXPECT_NEAR(time_delta_result.InMilliseconds(), 10000, 1);
447 } 447 }
448 } 448 }
449 449
450 TEST(NetworkQualityObservationBufferTest, TestGetMedianRTTSince) { 450 TEST(NetworkQualityObservationBufferTest, TestGetMedianRTTSince) {
451 ObservationBuffer<int32_t> int_buffer(0.5); 451 ObservationBuffer<int32_t> int_buffer(0.5);
452 ObservationBuffer<base::TimeDelta> time_delta_buffer(0.5); 452 ObservationBuffer<base::TimeDelta> time_delta_buffer(0.5);
453 base::TimeTicks now = base::TimeTicks::Now(); 453 base::TimeTicks now = base::TimeTicks::Now();
454 base::TimeTicks old = now - base::TimeDelta::FromMilliseconds(1); 454 base::TimeTicks old = now - base::TimeDelta::FromMilliseconds(1);
455 ASSERT_NE(old, now); 455 ASSERT_NE(old, now);
456 456
457 // First sample has very old timestamp. 457 // First sample has very old timestamp.
458 int_buffer.AddObservation(Observation<int32_t>( 458 int_buffer.AddObservation(
459 1, old, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 459 Observation<int32_t>(1, old, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
460 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( 460 time_delta_buffer.AddObservation(
461 base::TimeDelta::FromMilliseconds(1), old, 461 Observation<base::TimeDelta>(base::TimeDelta::FromMilliseconds(1), old,
462 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 462 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
463 463
464 int_buffer.AddObservation(Observation<int32_t>( 464 int_buffer.AddObservation(
465 100, now, NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 465 Observation<int32_t>(100, now, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
466 time_delta_buffer.AddObservation(Observation<base::TimeDelta>( 466 time_delta_buffer.AddObservation(
467 base::TimeDelta::FromMilliseconds(100), now, 467 Observation<base::TimeDelta>(base::TimeDelta::FromMilliseconds(100), now,
468 NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); 468 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
469 469
470 const struct { 470 const struct {
471 base::TimeTicks start_timestamp; 471 base::TimeTicks start_timestamp;
472 bool expect_network_quality_available; 472 bool expect_network_quality_available;
473 base::TimeDelta expected_url_request_rtt; 473 base::TimeDelta expected_url_request_rtt;
474 int32_t expected_downstream_throughput; 474 int32_t expected_downstream_throughput;
475 } tests[] = { 475 } tests[] = {
476 {now + base::TimeDelta::FromSeconds(10), false, 476 {now + base::TimeDelta::FromSeconds(10), false,
477 base::TimeDelta::FromMilliseconds(0), 0}, 477 base::TimeDelta::FromMilliseconds(0), 0},
478 {now, true, base::TimeDelta::FromMilliseconds(100), 100}, 478 {now, true, base::TimeDelta::FromMilliseconds(100), 100},
(...skipping 24 matching lines...) Expand all
503 } 503 }
504 } 504 }
505 505
506 } // namespace 506 } // namespace
507 507
508 } // namespace internal 508 } // namespace internal
509 509
510 } // namespace nqe 510 } // namespace nqe
511 511
512 } // namespace net 512 } // namespace net
OLDNEW
« no previous file with comments | « net/nqe/network_quality_observation_source.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698