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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 bool IsInControlGroup() const override { return control_group_; } | 140 bool IsInControlGroup() const override { return control_group_; } |
141 bool IsPrecachingAllowed() const override { return true; } | 141 bool IsPrecachingAllowed() const override { return true; } |
142 void SetInControlGroup(bool in_control_group) { | 142 void SetInControlGroup(bool in_control_group) { |
143 control_group_ = in_control_group; | 143 control_group_ = in_control_group; |
144 } | 144 } |
145 | 145 |
146 private: | 146 private: |
147 bool control_group_; | 147 bool control_group_; |
148 }; | 148 }; |
149 | 149 |
| 150 } // namespace |
| 151 |
150 class PrecacheManagerTest : public testing::Test { | 152 class PrecacheManagerTest : public testing::Test { |
151 public: | 153 public: |
152 PrecacheManagerTest() | 154 PrecacheManagerTest() |
153 : factory_(nullptr, | 155 : factory_(nullptr, |
154 base::Bind(&TestURLFetcherCallback::CreateURLFetcher, | 156 base::Bind(&TestURLFetcherCallback::CreateURLFetcher, |
155 base::Unretained(&url_callback_))) {} | 157 base::Unretained(&url_callback_))) {} |
156 | 158 |
157 ~PrecacheManagerTest() { | 159 ~PrecacheManagerTest() { |
158 // precache_manager_'s constructor releases a PrecacheDatabase and deletes | 160 // precache_manager_'s constructor releases a PrecacheDatabase and deletes |
159 // it on the DB thread. PrecacheDatabase already has a pending Init call | 161 // it on the DB thread. PrecacheDatabase already has a pending Init call |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 | 337 |
336 base::RunLoop().RunUntilIdle(); // For PrecacheFetcher. | 338 base::RunLoop().RunUntilIdle(); // For PrecacheFetcher. |
337 EXPECT_FALSE(precache_manager_->IsPrecaching()); | 339 EXPECT_FALSE(precache_manager_->IsPrecaching()); |
338 EXPECT_FALSE(precache_callback_.was_on_done_called()); | 340 EXPECT_FALSE(precache_callback_.was_on_done_called()); |
339 | 341 |
340 std::multiset<GURL> expected_requested_urls; | 342 std::multiset<GURL> expected_requested_urls; |
341 expected_requested_urls.insert(GURL(kConfigURL)); | 343 expected_requested_urls.insert(GURL(kConfigURL)); |
342 EXPECT_EQ(expected_requested_urls, url_callback_.requested_urls()); | 344 EXPECT_EQ(expected_requested_urls, url_callback_.requested_urls()); |
343 } | 345 } |
344 | 346 |
| 347 // TODO(rajendrant): Add unittests for |
| 348 // PrecacheUtil::UpdatePrecacheMetricsAndState() for more test coverage. |
345 TEST_F(PrecacheManagerTest, RecordStatsForFetchWithSizeZero) { | 349 TEST_F(PrecacheManagerTest, RecordStatsForFetchWithSizeZero) { |
346 // Fetches with size 0 should be ignored. | 350 // Fetches with size 0 should be ignored. |
347 precache_manager_->RecordStatsForFetch(GURL("http://url.com"), GURL(), | 351 precache_manager_->RecordStatsForFetch(GURL("http://url.com"), GURL(), |
348 base::TimeDelta(), base::Time(), 0, | 352 base::TimeDelta(), base::Time(), 0, |
349 false); | 353 false); |
350 base::RunLoop().RunUntilIdle(); | 354 base::RunLoop().RunUntilIdle(); |
351 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), IsEmpty()); | 355 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), IsEmpty()); |
352 } | 356 } |
353 | 357 |
354 TEST_F(PrecacheManagerTest, RecordStatsForFetchWithNonHTTP) { | 358 TEST_F(PrecacheManagerTest, RecordStatsForFetchWithNonHTTP) { |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 1000, true); | 520 1000, true); |
517 expected_histogram_count_map["Precache.Latency.NonPrefetch"] += 2; | 521 expected_histogram_count_map["Precache.Latency.NonPrefetch"] += 2; |
518 expected_histogram_count_map["Precache.Latency.NonPrefetch.NonTopHosts"] += 2; | 522 expected_histogram_count_map["Precache.Latency.NonPrefetch.NonTopHosts"] += 2; |
519 expected_histogram_count_map["Precache.Saved"] += 2; | 523 expected_histogram_count_map["Precache.Saved"] += 2; |
520 | 524 |
521 base::RunLoop().RunUntilIdle(); | 525 base::RunLoop().RunUntilIdle(); |
522 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), | 526 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), |
523 ContainerEq(expected_histogram_count_map)); | 527 ContainerEq(expected_histogram_count_map)); |
524 } | 528 } |
525 | 529 |
526 } // namespace | |
527 | |
528 } // namespace precache | 530 } // namespace precache |
OLD | NEW |