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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // is destructed. | 175 // is destructed. |
176 base::RunLoop().RunUntilIdle(); | 176 base::RunLoop().RunUntilIdle(); |
177 } | 177 } |
178 | 178 |
179 protected: | 179 protected: |
180 void SetUp() override { | 180 void SetUp() override { |
181 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 181 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
182 switches::kPrecacheConfigSettingsURL, kConfigURL); | 182 switches::kPrecacheConfigSettingsURL, kConfigURL); |
183 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 183 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
184 switches::kPrecacheManifestURLPrefix, kManifestURLPrefix); | 184 switches::kPrecacheManifestURLPrefix, kManifestURLPrefix); |
185 std::unique_ptr<PrecacheDatabase> precache_database( | |
186 new PrecacheDatabase()); | |
187 precache_database_ = precache_database.get(); | |
188 | 185 |
189 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); | 186 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); |
190 base::FilePath db_path = scoped_temp_dir_.GetPath().Append( | 187 precache_database_ = new PrecacheDatabase; |
191 base::FilePath(FILE_PATH_LITERAL("precache_database"))); | 188 Reset(precache_database_); |
| 189 base::RunLoop().RunUntilIdle(); |
192 | 190 |
193 // Make the fetch of the precache configuration settings fail. Precaching | 191 // Make the fetch of the precache configuration settings fail. Precaching |
194 // should still complete normally in this case. | 192 // should still complete normally in this case. |
195 factory_.SetFakeResponse(GURL(kConfigURL), "", | 193 factory_.SetFakeResponse(GURL(kConfigURL), "", |
196 net::HTTP_INTERNAL_SERVER_ERROR, | 194 net::HTTP_INTERNAL_SERVER_ERROR, |
197 net::URLRequestStatus::FAILED); | 195 net::URLRequestStatus::FAILED); |
| 196 info_.headers = new net::HttpResponseHeaders(""); |
| 197 } |
| 198 |
| 199 // precache_manager_ assumes ownership of precache_database. |
| 200 void Reset(PrecacheDatabase* precache_database) { |
| 201 base::FilePath db_path = scoped_temp_dir_.GetPath().Append( |
| 202 base::FilePath(FILE_PATH_LITERAL("precache_database"))); |
198 precache_manager_.reset(new PrecacheManagerUnderTest( | 203 precache_manager_.reset(new PrecacheManagerUnderTest( |
199 &browser_context_, nullptr /* sync_service */, &history_service_, | 204 &browser_context_, nullptr /* sync_service */, &history_service_, |
200 nullptr /* data_reduction_proxy_settings */, db_path, | 205 nullptr /* data_reduction_proxy_settings */, db_path, |
201 std::move(precache_database))); | 206 base::WrapUnique(precache_database))); |
202 base::RunLoop().RunUntilIdle(); | 207 } |
203 | 208 |
204 info_.headers = new net::HttpResponseHeaders(""); | 209 void Flush() { precache_database_->Flush(); } |
| 210 |
| 211 void RecordStatsForFetch(const GURL& url, |
| 212 const std::string& referrer_host, |
| 213 const base::TimeDelta& latency, |
| 214 const base::Time& fetch_time, |
| 215 const net::HttpResponseInfo& info, |
| 216 int64_t size, |
| 217 base::Time last_precache_time) { |
| 218 precache_manager_->RecordStatsForFetch( |
| 219 url, GURL(referrer_host), latency, fetch_time, info, size, |
| 220 base::Bind(&PrecacheManagerTest::RegisterSyntheticFieldTrial, |
| 221 base::Unretained(this)), |
| 222 last_precache_time); |
205 } | 223 } |
206 | 224 |
207 void RecordStatsForPrecacheFetch(const GURL& url, | 225 void RecordStatsForPrecacheFetch(const GURL& url, |
208 const std::string& referrer_host, | 226 const std::string& referrer_host, |
209 const base::TimeDelta& latency, | 227 const base::TimeDelta& latency, |
210 const base::Time& fetch_time, | 228 const base::Time& fetch_time, |
211 const net::HttpResponseInfo& info, | 229 const net::HttpResponseInfo& info, |
212 int64_t size) { | 230 int64_t size, |
213 precache_manager_->RecordStatsForFetch(url, GURL(referrer_host), latency, | 231 base::Time last_precache_time) { |
214 fetch_time, info, size); | 232 RecordStatsForFetch(url, referrer_host, latency, fetch_time, info, size, |
| 233 last_precache_time); |
215 precache_database_->RecordURLPrefetch(url, referrer_host, fetch_time, | 234 precache_database_->RecordURLPrefetch(url, referrer_host, fetch_time, |
216 info.was_cached, size); | 235 info.was_cached, size); |
217 } | 236 } |
218 | 237 |
| 238 MOCK_METHOD1(RegisterSyntheticFieldTrial, |
| 239 void(base::Time last_precache_time)); |
| 240 |
219 // Must be declared first so that it is destroyed last. | 241 // Must be declared first so that it is destroyed last. |
220 content::TestBrowserThreadBundle test_browser_thread_bundle_; | 242 content::TestBrowserThreadBundle test_browser_thread_bundle_; |
221 base::ScopedTempDir scoped_temp_dir_; | 243 base::ScopedTempDir scoped_temp_dir_; |
222 PrecacheDatabase* precache_database_; | 244 PrecacheDatabase* precache_database_; |
223 content::TestBrowserContext browser_context_; | 245 content::TestBrowserContext browser_context_; |
224 std::unique_ptr<PrecacheManagerUnderTest> precache_manager_; | 246 std::unique_ptr<PrecacheManagerUnderTest> precache_manager_; |
225 TestURLFetcherCallback url_callback_; | 247 TestURLFetcherCallback url_callback_; |
226 net::FakeURLFetcherFactory factory_; | 248 net::FakeURLFetcherFactory factory_; |
227 TestPrecacheCompletionCallback precache_callback_; | 249 TestPrecacheCompletionCallback precache_callback_; |
228 testing::NiceMock<MockHistoryService> history_service_; | 250 testing::NiceMock<MockHistoryService> history_service_; |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 | 470 |
449 std::multiset<GURL> expected_requested_urls; | 471 std::multiset<GURL> expected_requested_urls; |
450 expected_requested_urls.insert(GURL(kConfigURL)); | 472 expected_requested_urls.insert(GURL(kConfigURL)); |
451 EXPECT_EQ(expected_requested_urls, url_callback_.requested_urls()); | 473 EXPECT_EQ(expected_requested_urls, url_callback_.requested_urls()); |
452 } | 474 } |
453 | 475 |
454 // TODO(rajendrant): Add unittests for | 476 // TODO(rajendrant): Add unittests for |
455 // PrecacheUtil::UpdatePrecacheMetricsAndState() for more test coverage. | 477 // PrecacheUtil::UpdatePrecacheMetricsAndState() for more test coverage. |
456 TEST_F(PrecacheManagerTest, RecordStatsForFetchWithSizeZero) { | 478 TEST_F(PrecacheManagerTest, RecordStatsForFetchWithSizeZero) { |
457 // Fetches with size 0 should be ignored. | 479 // Fetches with size 0 should be ignored. |
458 precache_manager_->RecordStatsForFetch(GURL("http://url.com"), GURL(), | 480 RecordStatsForPrecacheFetch(GURL("http://url.com"), "", base::TimeDelta(), |
459 base::TimeDelta(), base::Time(), info_, | 481 base::Time(), info_, 0, base::Time()); |
460 0); | |
461 base::RunLoop().RunUntilIdle(); | 482 base::RunLoop().RunUntilIdle(); |
462 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), IsEmpty()); | 483 histograms_.ExpectTotalCount("Precache.Latency.Prefetch", 0); |
| 484 histograms_.ExpectTotalCount("Precache.Freshness.Prefetch", 0); |
463 } | 485 } |
464 | 486 |
465 TEST_F(PrecacheManagerTest, RecordStatsForFetchWithNonHTTP) { | 487 TEST_F(PrecacheManagerTest, RecordStatsForFetchWithNonHTTP) { |
466 // Fetches for URLs with schemes other than HTTP or HTTPS should be ignored. | 488 // Fetches for URLs with schemes other than HTTP or HTTPS should be ignored. |
467 precache_manager_->RecordStatsForFetch(GURL("ftp://ftp.com"), GURL(), | 489 RecordStatsForPrecacheFetch(GURL("ftp://ftp.com"), "", base::TimeDelta(), |
468 base::TimeDelta(), base::Time(), info_, | 490 base::Time(), info_, 1000, base::Time()); |
469 1000); | |
470 base::RunLoop().RunUntilIdle(); | 491 base::RunLoop().RunUntilIdle(); |
471 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), IsEmpty()); | 492 histograms_.ExpectTotalCount("Precache.Latency.Prefetch", 0); |
| 493 histograms_.ExpectTotalCount("Precache.Freshness.Prefetch", 0); |
472 } | 494 } |
473 | 495 |
474 TEST_F(PrecacheManagerTest, RecordStatsForFetchWithEmptyURL) { | 496 TEST_F(PrecacheManagerTest, RecordStatsForFetchWithEmptyURL) { |
475 // Fetches for empty URLs should be ignored. | 497 // Fetches for empty URLs should be ignored. |
476 precache_manager_->RecordStatsForFetch(GURL(), GURL(), base::TimeDelta(), | 498 RecordStatsForPrecacheFetch(GURL(), "", base::TimeDelta(), base::Time(), |
477 base::Time(), info_, 1000); | 499 info_, 1000, base::Time()); |
478 base::RunLoop().RunUntilIdle(); | 500 base::RunLoop().RunUntilIdle(); |
479 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), IsEmpty()); | 501 histograms_.ExpectTotalCount("Precache.Latency.Prefetch", 0); |
| 502 histograms_.ExpectTotalCount("Precache.Freshness.Prefetch", 0); |
480 } | 503 } |
481 | 504 |
482 TEST_F(PrecacheManagerTest, RecordStatsForFetchDuringPrecaching) { | 505 TEST_F(PrecacheManagerTest, RecordStatsForFetchDuringPrecaching) { |
483 EXPECT_CALL(history_service_, TopHosts(NumTopHosts(), _)) | 506 EXPECT_CALL(history_service_, TopHosts(NumTopHosts(), _)) |
484 .WillOnce(ReturnHosts(history::TopHostsList())); | 507 .WillOnce(ReturnHosts(history::TopHostsList())); |
485 | 508 |
486 precache_manager_->StartPrecaching(precache_callback_.GetCallback()); | 509 precache_manager_->StartPrecaching(precache_callback_.GetCallback()); |
487 | 510 |
488 EXPECT_TRUE(precache_manager_->IsPrecaching()); | 511 EXPECT_TRUE(precache_manager_->IsPrecaching()); |
489 RecordStatsForPrecacheFetch(GURL("http://url.com"), std::string(), | 512 RecordStatsForPrecacheFetch(GURL("http://url.com"), std::string(), |
490 base::TimeDelta(), base::Time(), info_, 1000); | 513 base::TimeDelta(), base::Time(), info_, 1000, |
| 514 base::Time()); |
491 base::RunLoop().RunUntilIdle(); | 515 base::RunLoop().RunUntilIdle(); |
492 precache_manager_->CancelPrecaching(); | 516 precache_manager_->CancelPrecaching(); |
493 | 517 |
494 // For PrecacheFetcher and RecordURLPrecached. | 518 // For PrecacheFetcher and RecordURLPrecached. |
495 base::RunLoop().RunUntilIdle(); | 519 base::RunLoop().RunUntilIdle(); |
496 EXPECT_THAT( | 520 EXPECT_THAT( |
497 histograms_.GetTotalCountsForPrefix("Precache."), | 521 histograms_.GetTotalCountsForPrefix("Precache."), |
498 UnorderedElementsAre(Pair("Precache.CacheStatus.Prefetch", 1), | 522 UnorderedElementsAre(Pair("Precache.CacheStatus.Prefetch", 1), |
499 Pair("Precache.CacheSize.AllEntries", 1), | 523 Pair("Precache.CacheSize.AllEntries", 1), |
500 Pair("Precache.DownloadedPrecacheMotivated", 1), | 524 Pair("Precache.DownloadedPrecacheMotivated", 1), |
501 Pair("Precache.Fetch.PercentCompleted", 1), | 525 Pair("Precache.Fetch.PercentCompleted", 1), |
502 Pair("Precache.Fetch.ResponseBytes.Network", 1), | 526 Pair("Precache.Fetch.ResponseBytes.Network", 1), |
503 Pair("Precache.Fetch.ResponseBytes.Total", 1), | 527 Pair("Precache.Fetch.ResponseBytes.Total", 1), |
504 Pair("Precache.Fetch.TimeToComplete", 1), | 528 Pair("Precache.Fetch.TimeToComplete", 1), |
505 Pair("Precache.Latency.Prefetch", 1), | 529 Pair("Precache.Latency.Prefetch", 1), |
506 Pair("Precache.Freshness.Prefetch", 1))); | 530 Pair("Precache.Freshness.Prefetch", 1))); |
507 } | 531 } |
508 | 532 |
| 533 TEST_F(PrecacheManagerTest, RegistersSyntheticFieldTrial) { |
| 534 base::Time now = base::Time::Now(); |
| 535 |
| 536 EXPECT_CALL(history_service_, TopHosts(NumTopHosts(), _)) |
| 537 .WillOnce(ReturnHosts(history::TopHostsList())); |
| 538 EXPECT_CALL(*this, RegisterSyntheticFieldTrial(now)); |
| 539 |
| 540 precache_manager_->StartPrecaching(precache_callback_.GetCallback()); |
| 541 |
| 542 EXPECT_TRUE(precache_manager_->IsPrecaching()); |
| 543 RecordStatsForPrecacheFetch(GURL("http://url.com"), std::string(), |
| 544 base::TimeDelta(), base::Time(), info_, 1000, |
| 545 now /* last_precache_time */); |
| 546 base::RunLoop().RunUntilIdle(); |
| 547 precache_manager_->CancelPrecaching(); |
| 548 } |
| 549 |
509 TEST_F(PrecacheManagerTest, RecordStatsForFetchHTTP) { | 550 TEST_F(PrecacheManagerTest, RecordStatsForFetchHTTP) { |
510 precache_manager_->RecordStatsForFetch(GURL("http://http-url.com"), GURL(), | 551 RecordStatsForFetch(GURL("http://http-url.com"), "", base::TimeDelta(), |
511 base::TimeDelta(), base::Time(), info_, | 552 base::Time(), info_, 1000, base::Time()); |
512 1000); | |
513 base::RunLoop().RunUntilIdle(); | 553 base::RunLoop().RunUntilIdle(); |
514 | 554 |
515 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), | 555 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), |
516 UnorderedElementsAre( | 556 UnorderedElementsAre( |
517 Pair("Precache.DownloadedNonPrecache", 1), | 557 Pair("Precache.DownloadedNonPrecache", 1), |
518 Pair("Precache.CacheStatus.NonPrefetch", 1), | 558 Pair("Precache.CacheStatus.NonPrefetch", 1), |
519 Pair("Precache.Latency.NonPrefetch", 1), | 559 Pair("Precache.Latency.NonPrefetch", 1), |
520 Pair("Precache.Latency.NonPrefetch.NonTopHosts", 1))); | 560 Pair("Precache.Latency.NonPrefetch.NonTopHosts", 1))); |
521 } | 561 } |
522 | 562 |
523 TEST_F(PrecacheManagerTest, RecordStatsForFetchHTTPS) { | 563 TEST_F(PrecacheManagerTest, RecordStatsForFetchHTTPS) { |
524 precache_manager_->RecordStatsForFetch(GURL("https://https-url.com"), GURL(), | 564 RecordStatsForFetch(GURL("https://https-url.com"), "", base::TimeDelta(), |
525 base::TimeDelta(), base::Time(), info_, | 565 base::Time(), info_, 1000, base::Time()); |
526 1000); | |
527 base::RunLoop().RunUntilIdle(); | 566 base::RunLoop().RunUntilIdle(); |
528 | 567 |
529 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), | 568 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), |
530 UnorderedElementsAre( | 569 UnorderedElementsAre( |
531 Pair("Precache.DownloadedNonPrecache", 1), | 570 Pair("Precache.DownloadedNonPrecache", 1), |
532 Pair("Precache.CacheStatus.NonPrefetch", 1), | 571 Pair("Precache.CacheStatus.NonPrefetch", 1), |
533 Pair("Precache.Latency.NonPrefetch", 1), | 572 Pair("Precache.Latency.NonPrefetch", 1), |
534 Pair("Precache.Latency.NonPrefetch.NonTopHosts", 1))); | 573 Pair("Precache.Latency.NonPrefetch.NonTopHosts", 1))); |
535 } | 574 } |
536 | 575 |
537 TEST_F(PrecacheManagerTest, RecordStatsForFetchInTopHosts) { | 576 TEST_F(PrecacheManagerTest, RecordStatsForFetchInTopHosts) { |
538 EXPECT_CALL(history_service_, | 577 EXPECT_CALL(history_service_, |
539 HostRankIfAvailable(GURL("http://referrer.com"), _)) | 578 HostRankIfAvailable(GURL("http://referrer.com"), _)) |
540 .WillOnce(Invoke( | 579 .WillOnce(Invoke( |
541 [](const GURL& url, const base::Callback<void(int)>& callback) { | 580 [](const GURL& url, const base::Callback<void(int)>& callback) { |
542 callback.Run(0); | 581 callback.Run(0); |
543 })); | 582 })); |
544 precache_manager_->RecordStatsForFetch( | 583 RecordStatsForFetch(GURL("http://http-url.com"), "http://referrer.com", |
545 GURL("http://http-url.com"), GURL("http://referrer.com"), | 584 base::TimeDelta(), base::Time(), info_, 1000, |
546 base::TimeDelta(), base::Time(), info_, 1000); | 585 base::Time()); |
547 base::RunLoop().RunUntilIdle(); | 586 base::RunLoop().RunUntilIdle(); |
548 | 587 |
549 EXPECT_THAT( | 588 EXPECT_THAT( |
550 histograms_.GetTotalCountsForPrefix("Precache."), | 589 histograms_.GetTotalCountsForPrefix("Precache."), |
551 UnorderedElementsAre(Pair("Precache.DownloadedNonPrecache", 1), | 590 UnorderedElementsAre(Pair("Precache.DownloadedNonPrecache", 1), |
552 Pair("Precache.CacheStatus.NonPrefetch", 1), | 591 Pair("Precache.CacheStatus.NonPrefetch", 1), |
553 Pair("Precache.Latency.NonPrefetch", 1), | 592 Pair("Precache.Latency.NonPrefetch", 1), |
554 Pair("Precache.Latency.NonPrefetch.TopHosts", 1))); | 593 Pair("Precache.Latency.NonPrefetch.TopHosts", 1))); |
555 } | 594 } |
556 | 595 |
557 TEST_F(PrecacheManagerTest, DeleteExpiredPrecacheHistory) { | 596 TEST_F(PrecacheManagerTest, DeleteExpiredPrecacheHistory) { |
558 // TODO(twifkak): Split this into multiple tests. | 597 // TODO(twifkak): Split this into multiple tests. |
559 base::HistogramTester::CountsMap expected_histogram_count_map; | 598 base::HistogramTester::CountsMap expected_histogram_count_map; |
560 | 599 |
561 // This test has to use Time::Now() because StartPrecaching uses Time::Now(). | 600 // This test has to use Time::Now() because StartPrecaching uses Time::Now(). |
562 const base::Time kCurrentTime = base::Time::Now(); | 601 const base::Time kCurrentTime = base::Time::Now(); |
563 EXPECT_CALL(history_service_, TopHosts(NumTopHosts(), _)) | 602 EXPECT_CALL(history_service_, TopHosts(NumTopHosts(), _)) |
564 .Times(2) | 603 .Times(2) |
565 .WillRepeatedly(ReturnHosts(history::TopHostsList())); | 604 .WillRepeatedly(ReturnHosts(history::TopHostsList())); |
566 | 605 |
567 precache_manager_->StartPrecaching(precache_callback_.GetCallback()); | 606 precache_manager_->StartPrecaching(precache_callback_.GetCallback()); |
568 EXPECT_TRUE(precache_manager_->IsPrecaching()); | 607 EXPECT_TRUE(precache_manager_->IsPrecaching()); |
569 | 608 |
570 // Precache a bunch of URLs, with different fetch times. | 609 // Precache a bunch of URLs, with different fetch times. |
571 RecordStatsForPrecacheFetch( | 610 RecordStatsForPrecacheFetch( |
572 GURL("http://old-fetch.com"), std::string(), base::TimeDelta(), | 611 GURL("http://old-fetch.com"), std::string(), base::TimeDelta(), |
573 kCurrentTime - base::TimeDelta::FromDays(61), info_, 1000); | 612 kCurrentTime - base::TimeDelta::FromDays(61), info_, 1000, base::Time()); |
574 RecordStatsForPrecacheFetch( | 613 RecordStatsForPrecacheFetch( |
575 GURL("http://recent-fetch.com"), std::string(), base::TimeDelta(), | 614 GURL("http://recent-fetch.com"), std::string(), base::TimeDelta(), |
576 kCurrentTime - base::TimeDelta::FromDays(59), info_, 1000); | 615 kCurrentTime - base::TimeDelta::FromDays(59), info_, 1000, base::Time()); |
577 RecordStatsForPrecacheFetch( | 616 RecordStatsForPrecacheFetch( |
578 GURL("http://yesterday-fetch.com"), std::string(), base::TimeDelta(), | 617 GURL("http://yesterday-fetch.com"), std::string(), base::TimeDelta(), |
579 kCurrentTime - base::TimeDelta::FromDays(1), info_, 1000); | 618 kCurrentTime - base::TimeDelta::FromDays(1), info_, 1000, base::Time()); |
580 expected_histogram_count_map["Precache.CacheStatus.Prefetch"] += 3; | 619 expected_histogram_count_map["Precache.CacheStatus.Prefetch"] += 3; |
581 expected_histogram_count_map["Precache.CacheSize.AllEntries"]++; | 620 expected_histogram_count_map["Precache.CacheSize.AllEntries"]++; |
582 expected_histogram_count_map["Precache.DownloadedPrecacheMotivated"] += 3; | 621 expected_histogram_count_map["Precache.DownloadedPrecacheMotivated"] += 3; |
583 expected_histogram_count_map["Precache.Fetch.PercentCompleted"]++; | 622 expected_histogram_count_map["Precache.Fetch.PercentCompleted"]++; |
584 expected_histogram_count_map["Precache.Fetch.ResponseBytes.Network"]++; | 623 expected_histogram_count_map["Precache.Fetch.ResponseBytes.Network"]++; |
585 expected_histogram_count_map["Precache.Fetch.ResponseBytes.Total"]++; | 624 expected_histogram_count_map["Precache.Fetch.ResponseBytes.Total"]++; |
586 expected_histogram_count_map["Precache.Fetch.TimeToComplete"]++; | 625 expected_histogram_count_map["Precache.Fetch.TimeToComplete"]++; |
587 expected_histogram_count_map["Precache.Latency.Prefetch"] += 3; | 626 expected_histogram_count_map["Precache.Latency.Prefetch"] += 3; |
588 expected_histogram_count_map["Precache.Freshness.Prefetch"] += 3; | 627 expected_histogram_count_map["Precache.Freshness.Prefetch"] += 3; |
589 base::RunLoop().RunUntilIdle(); | 628 base::RunLoop().RunUntilIdle(); |
(...skipping 23 matching lines...) Expand all Loading... |
613 expected_histogram_count_map["Precache.Fetch.ResponseBytes.Network"]++; | 652 expected_histogram_count_map["Precache.Fetch.ResponseBytes.Network"]++; |
614 expected_histogram_count_map["Precache.Fetch.ResponseBytes.Total"]++; | 653 expected_histogram_count_map["Precache.Fetch.ResponseBytes.Total"]++; |
615 // For PrecacheFetcher and RecordURLPrecached. | 654 // For PrecacheFetcher and RecordURLPrecached. |
616 base::RunLoop().RunUntilIdle(); | 655 base::RunLoop().RunUntilIdle(); |
617 EXPECT_FALSE(precache_manager_->IsPrecaching()); | 656 EXPECT_FALSE(precache_manager_->IsPrecaching()); |
618 | 657 |
619 // A fetch for the same URL as the expired precache was served from the cache, | 658 // A fetch for the same URL as the expired precache was served from the cache, |
620 // but it isn't reported as saved bytes because it had expired in the precache | 659 // but it isn't reported as saved bytes because it had expired in the precache |
621 // history. | 660 // history. |
622 info_.was_cached = true; // From now on all fetches are cached. | 661 info_.was_cached = true; // From now on all fetches are cached. |
623 precache_manager_->RecordStatsForFetch(GURL("http://old-fetch.com"), GURL(), | 662 RecordStatsForFetch(GURL("http://old-fetch.com"), "", base::TimeDelta(), |
624 base::TimeDelta(), kCurrentTime, info_, | 663 kCurrentTime, info_, 1000, base::Time()); |
625 1000); | |
626 expected_histogram_count_map["Precache.Fetch.TimeToComplete"]++; | 664 expected_histogram_count_map["Precache.Fetch.TimeToComplete"]++; |
627 expected_histogram_count_map["Precache.CacheStatus.NonPrefetch"]++; | 665 expected_histogram_count_map["Precache.CacheStatus.NonPrefetch"]++; |
628 expected_histogram_count_map["Precache.Latency.NonPrefetch"]++; | 666 expected_histogram_count_map["Precache.Latency.NonPrefetch"]++; |
629 expected_histogram_count_map["Precache.Latency.NonPrefetch.NonTopHosts"]++; | 667 expected_histogram_count_map["Precache.Latency.NonPrefetch.NonTopHosts"]++; |
630 expected_histogram_count_map["Precache.TimeSinceLastPrecache"] += 1; | 668 expected_histogram_count_map["Precache.TimeSinceLastPrecache"] += 1; |
631 | 669 |
632 base::RunLoop().RunUntilIdle(); | 670 base::RunLoop().RunUntilIdle(); |
633 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), | 671 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), |
634 ContainerEq(expected_histogram_count_map)); | 672 ContainerEq(expected_histogram_count_map)); |
635 | 673 |
636 // The other precaches should not have expired, so the following fetches from | 674 // The other precaches should not have expired, so the following fetches from |
637 // the cache should count as saved bytes. | 675 // the cache should count as saved bytes. |
638 precache_manager_->RecordStatsForFetch(GURL("http://recent-fetch.com"), | 676 RecordStatsForFetch(GURL("http://recent-fetch.com"), "", base::TimeDelta(), |
639 GURL(), base::TimeDelta(), | 677 kCurrentTime, info_, 1000, base::Time()); |
640 kCurrentTime, info_, 1000); | 678 RecordStatsForFetch(GURL("http://yesterday-fetch.com"), "", base::TimeDelta(), |
641 precache_manager_->RecordStatsForFetch(GURL("http://yesterday-fetch.com"), | 679 kCurrentTime, info_, 1000, base::Time()); |
642 GURL(), base::TimeDelta(), | |
643 kCurrentTime, info_, 1000); | |
644 expected_histogram_count_map["Precache.CacheStatus.NonPrefetch"] += 2; | 680 expected_histogram_count_map["Precache.CacheStatus.NonPrefetch"] += 2; |
645 expected_histogram_count_map | 681 expected_histogram_count_map |
646 ["Precache.CacheStatus.NonPrefetch.FromPrecache"] += 2; | 682 ["Precache.CacheStatus.NonPrefetch.FromPrecache"] += 2; |
647 expected_histogram_count_map["Precache.Latency.NonPrefetch"] += 2; | 683 expected_histogram_count_map["Precache.Latency.NonPrefetch"] += 2; |
648 expected_histogram_count_map["Precache.Latency.NonPrefetch.NonTopHosts"] += 2; | 684 expected_histogram_count_map["Precache.Latency.NonPrefetch.NonTopHosts"] += 2; |
649 expected_histogram_count_map["Precache.Saved"] += 2; | 685 expected_histogram_count_map["Precache.Saved"] += 2; |
650 expected_histogram_count_map["Precache.TimeSinceLastPrecache"] += 2; | 686 expected_histogram_count_map["Precache.TimeSinceLastPrecache"] += 2; |
651 expected_histogram_count_map["Precache.Saved.Freshness"] = 2; | 687 expected_histogram_count_map["Precache.Saved.Freshness"] = 2; |
652 | 688 |
653 base::RunLoop().RunUntilIdle(); | 689 base::RunLoop().RunUntilIdle(); |
654 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), | 690 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), |
655 ContainerEq(expected_histogram_count_map)); | 691 ContainerEq(expected_histogram_count_map)); |
656 } | 692 } |
657 | 693 |
658 } // namespace precache | 694 } // namespace precache |
OLD | NEW |