| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/precache/content/precache_manager.h" | 5 #include "components/precache/content/precache_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 | 301 |
| 302 precache_manager_.CancelPrecaching(); | 302 precache_manager_.CancelPrecaching(); |
| 303 | 303 |
| 304 // For PrecacheFetcher and RecordURLPrecached. | 304 // For PrecacheFetcher and RecordURLPrecached. |
| 305 base::MessageLoop::current()->RunUntilIdle(); | 305 base::MessageLoop::current()->RunUntilIdle(); |
| 306 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), | 306 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), |
| 307 ElementsAre(Pair("Precache.DownloadedPrecacheMotivated", 1), | 307 ElementsAre(Pair("Precache.DownloadedPrecacheMotivated", 1), |
| 308 Pair("Precache.Fetch.PercentCompleted", 1), | 308 Pair("Precache.Fetch.PercentCompleted", 1), |
| 309 Pair("Precache.Fetch.ResponseBytes.Network", 1), | 309 Pair("Precache.Fetch.ResponseBytes.Network", 1), |
| 310 Pair("Precache.Fetch.ResponseBytes.Total", 1), | 310 Pair("Precache.Fetch.ResponseBytes.Total", 1), |
| 311 Pair("Precache.Fetch.TimeToComplete", 1), |
| 311 Pair("Precache.Latency.Prefetch", 1))); | 312 Pair("Precache.Latency.Prefetch", 1))); |
| 312 } | 313 } |
| 313 | 314 |
| 314 TEST_F(PrecacheManagerTest, RecordStatsForFetchHTTP) { | 315 TEST_F(PrecacheManagerTest, RecordStatsForFetchHTTP) { |
| 315 precache_manager_.RecordStatsForFetch(GURL("http://http-url.com"), GURL(), | 316 precache_manager_.RecordStatsForFetch(GURL("http://http-url.com"), GURL(), |
| 316 base::TimeDelta(), base::Time(), 1000, | 317 base::TimeDelta(), base::Time(), 1000, |
| 317 false); | 318 false); |
| 318 base::MessageLoop::current()->RunUntilIdle(); | 319 base::MessageLoop::current()->RunUntilIdle(); |
| 319 | 320 |
| 320 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), | 321 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 precache_manager_.RecordStatsForFetch( | 374 precache_manager_.RecordStatsForFetch( |
| 374 GURL("http://recent-fetch.com"), GURL(), base::TimeDelta(), | 375 GURL("http://recent-fetch.com"), GURL(), base::TimeDelta(), |
| 375 kCurrentTime - base::TimeDelta::FromDays(59), 1000, false); | 376 kCurrentTime - base::TimeDelta::FromDays(59), 1000, false); |
| 376 precache_manager_.RecordStatsForFetch( | 377 precache_manager_.RecordStatsForFetch( |
| 377 GURL("http://yesterday-fetch.com"), GURL(), base::TimeDelta(), | 378 GURL("http://yesterday-fetch.com"), GURL(), base::TimeDelta(), |
| 378 kCurrentTime - base::TimeDelta::FromDays(1), 1000, false); | 379 kCurrentTime - base::TimeDelta::FromDays(1), 1000, false); |
| 379 expected_histogram_count_map["Precache.DownloadedPrecacheMotivated"] += 3; | 380 expected_histogram_count_map["Precache.DownloadedPrecacheMotivated"] += 3; |
| 380 expected_histogram_count_map["Precache.Fetch.PercentCompleted"]++; | 381 expected_histogram_count_map["Precache.Fetch.PercentCompleted"]++; |
| 381 expected_histogram_count_map["Precache.Fetch.ResponseBytes.Network"]++; | 382 expected_histogram_count_map["Precache.Fetch.ResponseBytes.Network"]++; |
| 382 expected_histogram_count_map["Precache.Fetch.ResponseBytes.Total"]++; | 383 expected_histogram_count_map["Precache.Fetch.ResponseBytes.Total"]++; |
| 384 expected_histogram_count_map["Precache.Fetch.TimeToComplete"]++; |
| 383 expected_histogram_count_map["Precache.Latency.Prefetch"] += 3; | 385 expected_histogram_count_map["Precache.Latency.Prefetch"] += 3; |
| 384 | 386 |
| 385 precache_manager_.CancelPrecaching(); | 387 precache_manager_.CancelPrecaching(); |
| 386 // For PrecacheFetcher and RecordURLPrecached. | 388 // For PrecacheFetcher and RecordURLPrecached. |
| 387 base::MessageLoop::current()->RunUntilIdle(); | 389 base::MessageLoop::current()->RunUntilIdle(); |
| 388 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), | 390 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), |
| 389 ContainerEq(expected_histogram_count_map)); | 391 ContainerEq(expected_histogram_count_map)); |
| 390 | 392 |
| 391 // The expired precache will be deleted during precaching this time. | 393 // The expired precache will be deleted during precaching this time. |
| 392 precache_manager_.StartPrecaching(precache_callback_.GetCallback()); | 394 precache_manager_.StartPrecaching(precache_callback_.GetCallback()); |
| 393 EXPECT_TRUE(precache_manager_.IsPrecaching()); | 395 EXPECT_TRUE(precache_manager_.IsPrecaching()); |
| 394 expected_histogram_count_map["Precache.Fetch.PercentCompleted"]++; | 396 expected_histogram_count_map["Precache.Fetch.PercentCompleted"]++; |
| 395 expected_histogram_count_map["Precache.Fetch.ResponseBytes.Network"]++; | 397 expected_histogram_count_map["Precache.Fetch.ResponseBytes.Network"]++; |
| 396 expected_histogram_count_map["Precache.Fetch.ResponseBytes.Total"]++; | 398 expected_histogram_count_map["Precache.Fetch.ResponseBytes.Total"]++; |
| 397 | 399 |
| 398 precache_manager_.CancelPrecaching(); | 400 precache_manager_.CancelPrecaching(); |
| 399 // For PrecacheFetcher and RecordURLPrecached. | 401 // For PrecacheFetcher and RecordURLPrecached. |
| 400 base::MessageLoop::current()->RunUntilIdle(); | 402 base::MessageLoop::current()->RunUntilIdle(); |
| 401 EXPECT_FALSE(precache_manager_.IsPrecaching()); | 403 EXPECT_FALSE(precache_manager_.IsPrecaching()); |
| 402 | 404 |
| 403 // A fetch for the same URL as the expired precache was served from the cache, | 405 // A fetch for the same URL as the expired precache was served from the cache, |
| 404 // but it isn't reported as saved bytes because it had expired in the precache | 406 // but it isn't reported as saved bytes because it had expired in the precache |
| 405 // history. | 407 // history. |
| 406 precache_manager_.RecordStatsForFetch(GURL("http://old-fetch.com"), GURL(), | 408 precache_manager_.RecordStatsForFetch(GURL("http://old-fetch.com"), GURL(), |
| 407 base::TimeDelta(), kCurrentTime, 1000, | 409 base::TimeDelta(), kCurrentTime, 1000, |
| 408 true); | 410 true); |
| 411 expected_histogram_count_map["Precache.Fetch.TimeToComplete"]++; |
| 409 expected_histogram_count_map["Precache.Latency.NonPrefetch"]++; | 412 expected_histogram_count_map["Precache.Latency.NonPrefetch"]++; |
| 410 expected_histogram_count_map["Precache.Latency.NonPrefetch.NonTopHosts"]++; | 413 expected_histogram_count_map["Precache.Latency.NonPrefetch.NonTopHosts"]++; |
| 411 | 414 |
| 412 base::MessageLoop::current()->RunUntilIdle(); | 415 base::MessageLoop::current()->RunUntilIdle(); |
| 413 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), | 416 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), |
| 414 ContainerEq(expected_histogram_count_map)); | 417 ContainerEq(expected_histogram_count_map)); |
| 415 | 418 |
| 416 // The other precaches should not have expired, so the following fetches from | 419 // The other precaches should not have expired, so the following fetches from |
| 417 // the cache should count as saved bytes. | 420 // the cache should count as saved bytes. |
| 418 precache_manager_.RecordStatsForFetch(GURL("http://recent-fetch.com"), GURL(), | 421 precache_manager_.RecordStatsForFetch(GURL("http://recent-fetch.com"), GURL(), |
| 419 base::TimeDelta(), kCurrentTime, 1000, | 422 base::TimeDelta(), kCurrentTime, 1000, |
| 420 true); | 423 true); |
| 421 precache_manager_.RecordStatsForFetch(GURL("http://yesterday-fetch.com"), | 424 precache_manager_.RecordStatsForFetch(GURL("http://yesterday-fetch.com"), |
| 422 GURL(), base::TimeDelta(), kCurrentTime, | 425 GURL(), base::TimeDelta(), kCurrentTime, |
| 423 1000, true); | 426 1000, true); |
| 424 expected_histogram_count_map["Precache.Latency.NonPrefetch"] += 2; | 427 expected_histogram_count_map["Precache.Latency.NonPrefetch"] += 2; |
| 425 expected_histogram_count_map["Precache.Latency.NonPrefetch.NonTopHosts"] += 2; | 428 expected_histogram_count_map["Precache.Latency.NonPrefetch.NonTopHosts"] += 2; |
| 426 expected_histogram_count_map["Precache.Saved"] += 2; | 429 expected_histogram_count_map["Precache.Saved"] += 2; |
| 427 | 430 |
| 428 base::MessageLoop::current()->RunUntilIdle(); | 431 base::MessageLoop::current()->RunUntilIdle(); |
| 429 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), | 432 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), |
| 430 ContainerEq(expected_histogram_count_map)); | 433 ContainerEq(expected_histogram_count_map)); |
| 431 } | 434 } |
| 432 | 435 |
| 433 } // namespace | 436 } // namespace |
| 434 | 437 |
| 435 } // namespace precache | 438 } // namespace precache |
| OLD | NEW |