| 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 class PrecacheManagerTest : public testing::Test { | 134 class PrecacheManagerTest : public testing::Test { |
| 135 public: | 135 public: |
| 136 PrecacheManagerTest() | 136 PrecacheManagerTest() |
| 137 : precache_manager_(&browser_context_, | 137 : precache_manager_(&browser_context_, |
| 138 nullptr /* sync_service */, | 138 nullptr /* sync_service */, |
| 139 &history_service_), | 139 &history_service_), |
| 140 factory_(nullptr, | 140 factory_(nullptr, |
| 141 base::Bind(&TestURLFetcherCallback::CreateURLFetcher, | 141 base::Bind(&TestURLFetcherCallback::CreateURLFetcher, |
| 142 base::Unretained(&url_callback_))) {} | 142 base::Unretained(&url_callback_))) {} |
| 143 | 143 |
| 144 ~PrecacheManagerTest() { |
| 145 // precache_manager_'s constructor releases a PrecacheDatabase and deletes |
| 146 // it on the DB thread. PrecacheDatabase already has a pending Init call |
| 147 // which will assert in debug builds because the directory passed to it is |
| 148 // deleted. So manually ensure that the task is run before browser_context_ |
| 149 // is destructed. |
| 150 base::MessageLoop::current()->RunUntilIdle(); |
| 151 } |
| 152 |
| 144 protected: | 153 protected: |
| 145 void SetUp() override { | 154 void SetUp() override { |
| 146 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 155 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 147 switches::kPrecacheConfigSettingsURL, kConfigURL); | 156 switches::kPrecacheConfigSettingsURL, kConfigURL); |
| 148 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 157 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 149 switches::kPrecacheManifestURLPrefix, kManifestURLPrefix); | 158 switches::kPrecacheManifestURLPrefix, kManifestURLPrefix); |
| 150 | 159 |
| 151 // Make the fetch of the precache configuration settings fail. Precaching | 160 // Make the fetch of the precache configuration settings fail. Precaching |
| 152 // should still complete normally in this case. | 161 // should still complete normally in this case. |
| 153 factory_.SetFakeResponse(GURL(kConfigURL), "", | 162 factory_.SetFakeResponse(GURL(kConfigURL), "", |
| 154 net::HTTP_INTERNAL_SERVER_ERROR, | 163 net::HTTP_INTERNAL_SERVER_ERROR, |
| 155 net::URLRequestStatus::FAILED); | 164 net::URLRequestStatus::FAILED); |
| 156 } | 165 } |
| 157 | 166 |
| 158 // Must be declared first so that it is destroyed last. | 167 // Must be declared first so that it is destroyed last. |
| 168 content::TestBrowserThreadBundle test_browser_thread_bundle_; |
| 159 content::TestBrowserContext browser_context_; | 169 content::TestBrowserContext browser_context_; |
| 160 content::TestBrowserThreadBundle test_browser_thread_bundle_; | |
| 161 PrecacheManagerUnderTest precache_manager_; | 170 PrecacheManagerUnderTest precache_manager_; |
| 162 TestURLFetcherCallback url_callback_; | 171 TestURLFetcherCallback url_callback_; |
| 163 net::FakeURLFetcherFactory factory_; | 172 net::FakeURLFetcherFactory factory_; |
| 164 TestPrecacheCompletionCallback precache_callback_; | 173 TestPrecacheCompletionCallback precache_callback_; |
| 165 testing::NiceMock<MockHistoryService> history_service_; | 174 testing::NiceMock<MockHistoryService> history_service_; |
| 166 base::HistogramTester histograms_; | 175 base::HistogramTester histograms_; |
| 167 }; | 176 }; |
| 168 | 177 |
| 169 TEST_F(PrecacheManagerTest, StartAndFinishPrecaching) { | 178 TEST_F(PrecacheManagerTest, StartAndFinishPrecaching) { |
| 170 EXPECT_FALSE(precache_manager_.IsPrecaching()); | 179 EXPECT_FALSE(precache_manager_.IsPrecaching()); |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 expected_histogram_count_map["Precache.Saved"] += 2; | 438 expected_histogram_count_map["Precache.Saved"] += 2; |
| 430 | 439 |
| 431 base::MessageLoop::current()->RunUntilIdle(); | 440 base::MessageLoop::current()->RunUntilIdle(); |
| 432 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), | 441 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), |
| 433 ContainerEq(expected_histogram_count_map)); | 442 ContainerEq(expected_histogram_count_map)); |
| 434 } | 443 } |
| 435 | 444 |
| 436 } // namespace | 445 } // namespace |
| 437 | 446 |
| 438 } // namespace precache | 447 } // namespace precache |
| OLD | NEW |