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 <memory> | 10 #include <memory> |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 unfinished_work->add_top_host()->set_hostname("evil-manifest.com"); | 234 unfinished_work->add_top_host()->set_hostname("evil-manifest.com"); |
235 unfinished_work->set_start_time(base::Time::Now().ToInternalValue()); | 235 unfinished_work->set_start_time(base::Time::Now().ToInternalValue()); |
236 precache_database_->SaveUnfinishedWork(std::move(unfinished_work)); | 236 precache_database_->SaveUnfinishedWork(std::move(unfinished_work)); |
237 | 237 |
238 EXPECT_FALSE(precache_manager_->IsPrecaching()); | 238 EXPECT_FALSE(precache_manager_->IsPrecaching()); |
239 | 239 |
240 factory_.SetFakeResponse( | 240 factory_.SetFakeResponse( |
241 GURL(kEvilManifestURL), "", | 241 GURL(kEvilManifestURL), "", |
242 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 242 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
243 | 243 |
| 244 ASSERT_TRUE(precache_database_->GetLastPrecacheTimestamp().is_null()); |
| 245 |
244 precache_manager_->StartPrecaching(precache_callback_.GetCallback()); | 246 precache_manager_->StartPrecaching(precache_callback_.GetCallback()); |
245 EXPECT_TRUE(precache_manager_->IsPrecaching()); | 247 EXPECT_TRUE(precache_manager_->IsPrecaching()); |
246 | 248 |
247 base::RunLoop().RunUntilIdle(); // For PrecacheFetcher. | 249 base::RunLoop().RunUntilIdle(); // For PrecacheFetcher. |
248 EXPECT_FALSE(precache_manager_->IsPrecaching()); | 250 EXPECT_FALSE(precache_manager_->IsPrecaching()); |
249 EXPECT_TRUE(precache_callback_.was_on_done_called()); | 251 EXPECT_TRUE(precache_callback_.was_on_done_called()); |
250 | 252 |
| 253 // The LastPrecacheTimestamp has been set. |
| 254 EXPECT_FALSE(precache_database_->GetLastPrecacheTimestamp().is_null()); |
| 255 |
251 std::multiset<GURL> expected_requested_urls; | 256 std::multiset<GURL> expected_requested_urls; |
252 expected_requested_urls.insert(GURL(kConfigURL)); | 257 expected_requested_urls.insert(GURL(kConfigURL)); |
253 expected_requested_urls.insert(GURL(kEvilManifestURL)); | 258 expected_requested_urls.insert(GURL(kEvilManifestURL)); |
254 EXPECT_EQ(expected_requested_urls, url_callback_.requested_urls()); | 259 EXPECT_EQ(expected_requested_urls, url_callback_.requested_urls()); |
255 } | 260 } |
256 | 261 |
257 TEST_F(PrecacheManagerTest, | 262 TEST_F(PrecacheManagerTest, |
258 StartAndCancelPrecachingBeforeUnfinishedWorkRetrieved) { | 263 StartAndCancelPrecachingBeforeUnfinishedWorkRetrieved) { |
259 EXPECT_FALSE(precache_manager_->IsPrecaching()); | 264 EXPECT_FALSE(precache_manager_->IsPrecaching()); |
260 | 265 |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 | 499 |
495 // A fetch for the same URL as the expired precache was served from the cache, | 500 // A fetch for the same URL as the expired precache was served from the cache, |
496 // but it isn't reported as saved bytes because it had expired in the precache | 501 // but it isn't reported as saved bytes because it had expired in the precache |
497 // history. | 502 // history. |
498 precache_manager_->RecordStatsForFetch(GURL("http://old-fetch.com"), GURL(), | 503 precache_manager_->RecordStatsForFetch(GURL("http://old-fetch.com"), GURL(), |
499 base::TimeDelta(), kCurrentTime, 1000, | 504 base::TimeDelta(), kCurrentTime, 1000, |
500 true); | 505 true); |
501 expected_histogram_count_map["Precache.Fetch.TimeToComplete"]++; | 506 expected_histogram_count_map["Precache.Fetch.TimeToComplete"]++; |
502 expected_histogram_count_map["Precache.Latency.NonPrefetch"]++; | 507 expected_histogram_count_map["Precache.Latency.NonPrefetch"]++; |
503 expected_histogram_count_map["Precache.Latency.NonPrefetch.NonTopHosts"]++; | 508 expected_histogram_count_map["Precache.Latency.NonPrefetch.NonTopHosts"]++; |
| 509 expected_histogram_count_map["Precache.TimeSinceLastPrecache"] += 1; |
504 | 510 |
505 base::RunLoop().RunUntilIdle(); | 511 base::RunLoop().RunUntilIdle(); |
506 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), | 512 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), |
507 ContainerEq(expected_histogram_count_map)); | 513 ContainerEq(expected_histogram_count_map)); |
508 | 514 |
509 // The other precaches should not have expired, so the following fetches from | 515 // The other precaches should not have expired, so the following fetches from |
510 // the cache should count as saved bytes. | 516 // the cache should count as saved bytes. |
511 precache_manager_->RecordStatsForFetch(GURL("http://recent-fetch.com"), GURL()
, | 517 precache_manager_->RecordStatsForFetch(GURL("http://recent-fetch.com"), GURL()
, |
512 base::TimeDelta(), kCurrentTime, 1000, | 518 base::TimeDelta(), kCurrentTime, 1000, |
513 true); | 519 true); |
514 precache_manager_->RecordStatsForFetch(GURL("http://yesterday-fetch.com"), | 520 precache_manager_->RecordStatsForFetch(GURL("http://yesterday-fetch.com"), |
515 GURL(), base::TimeDelta(), kCurrentTime, | 521 GURL(), base::TimeDelta(), kCurrentTime, |
516 1000, true); | 522 1000, true); |
517 expected_histogram_count_map["Precache.Latency.NonPrefetch"] += 2; | 523 expected_histogram_count_map["Precache.Latency.NonPrefetch"] += 2; |
518 expected_histogram_count_map["Precache.Latency.NonPrefetch.NonTopHosts"] += 2; | 524 expected_histogram_count_map["Precache.Latency.NonPrefetch.NonTopHosts"] += 2; |
519 expected_histogram_count_map["Precache.Saved"] += 2; | 525 expected_histogram_count_map["Precache.Saved"] += 2; |
| 526 expected_histogram_count_map["Precache.TimeSinceLastPrecache"] += 2; |
520 | 527 |
521 base::RunLoop().RunUntilIdle(); | 528 base::RunLoop().RunUntilIdle(); |
522 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), | 529 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), |
523 ContainerEq(expected_histogram_count_map)); | 530 ContainerEq(expected_histogram_count_map)); |
524 } | 531 } |
525 | 532 |
526 } // namespace | 533 } // namespace |
527 | 534 |
528 } // namespace precache | 535 } // namespace precache |
OLD | NEW |