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 <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 } | 114 } |
115 | 115 |
116 bool was_on_done_called() const { | 116 bool was_on_done_called() const { |
117 return was_on_done_called_; | 117 return was_on_done_called_; |
118 } | 118 } |
119 | 119 |
120 private: | 120 private: |
121 bool was_on_done_called_; | 121 bool was_on_done_called_; |
122 }; | 122 }; |
123 | 123 |
| 124 class PrecacheManagerUnderTest : public PrecacheManager { |
| 125 public: |
| 126 PrecacheManagerUnderTest(content::BrowserContext* browser_context, |
| 127 const sync_driver::SyncService* const sync_service) |
| 128 : PrecacheManager(browser_context, sync_service) {} |
| 129 bool ShouldRun() const override { return true; } |
| 130 bool WouldRun() const override { return true; } |
| 131 }; |
| 132 |
124 class PrecacheManagerTest : public testing::Test { | 133 class PrecacheManagerTest : public testing::Test { |
125 public: | 134 public: |
126 PrecacheManagerTest() | 135 PrecacheManagerTest() |
127 : precache_manager_(&browser_context_, nullptr /* sync_service */), | 136 : precache_manager_(&browser_context_, nullptr /* sync_service */), |
128 factory_(nullptr, | 137 factory_(nullptr, |
129 base::Bind(&TestURLFetcherCallback::CreateURLFetcher, | 138 base::Bind(&TestURLFetcherCallback::CreateURLFetcher, |
130 base::Unretained(&url_callback_))) {} | 139 base::Unretained(&url_callback_))) {} |
131 | 140 |
132 protected: | 141 protected: |
133 void SetUp() override { | 142 void SetUp() override { |
134 base::StatisticsRecorder::Initialize(); | 143 base::StatisticsRecorder::Initialize(); |
135 | 144 |
136 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 145 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
137 switches::kPrecacheConfigSettingsURL, kConfigURL); | 146 switches::kPrecacheConfigSettingsURL, kConfigURL); |
138 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 147 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
139 switches::kPrecacheManifestURLPrefix, kManifestURLPrefix); | 148 switches::kPrecacheManifestURLPrefix, kManifestURLPrefix); |
140 | 149 |
141 // Make the fetch of the precache configuration settings fail. Precaching | 150 // Make the fetch of the precache configuration settings fail. Precaching |
142 // should still complete normally in this case. | 151 // should still complete normally in this case. |
143 factory_.SetFakeResponse(GURL(kConfigURL), "", | 152 factory_.SetFakeResponse(GURL(kConfigURL), "", |
144 net::HTTP_INTERNAL_SERVER_ERROR, | 153 net::HTTP_INTERNAL_SERVER_ERROR, |
145 net::URLRequestStatus::FAILED); | 154 net::URLRequestStatus::FAILED); |
146 } | 155 } |
147 | 156 |
148 content::TestBrowserThreadBundle test_browser_thread_bundle_; | 157 content::TestBrowserThreadBundle test_browser_thread_bundle_; |
149 content::TestBrowserContext browser_context_; | 158 content::TestBrowserContext browser_context_; |
150 PrecacheManager precache_manager_; | 159 PrecacheManagerUnderTest precache_manager_; |
151 TestURLFetcherCallback url_callback_; | 160 TestURLFetcherCallback url_callback_; |
152 net::FakeURLFetcherFactory factory_; | 161 net::FakeURLFetcherFactory factory_; |
153 TestPrecacheCompletionCallback precache_callback_; | 162 TestPrecacheCompletionCallback precache_callback_; |
154 }; | 163 }; |
155 | 164 |
156 TEST_F(PrecacheManagerTest, StartAndFinishPrecaching) { | 165 TEST_F(PrecacheManagerTest, StartAndFinishPrecaching) { |
157 EXPECT_FALSE(precache_manager_.IsPrecaching()); | 166 EXPECT_FALSE(precache_manager_.IsPrecaching()); |
158 | 167 |
159 MockHistoryService history_service; | 168 MockHistoryService history_service; |
160 MockHistoryService::TopHostsCallback top_hosts_callback; | 169 MockHistoryService::TopHostsCallback top_hosts_callback; |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 kCurrentTime, 1000, true); | 370 kCurrentTime, 1000, true); |
362 expected_histogram_count_map["Precache.Saved"] += 2; | 371 expected_histogram_count_map["Precache.Saved"] += 2; |
363 | 372 |
364 base::MessageLoop::current()->RunUntilIdle(); | 373 base::MessageLoop::current()->RunUntilIdle(); |
365 EXPECT_EQ(expected_histogram_count_map, GetHistogramCountMap()); | 374 EXPECT_EQ(expected_histogram_count_map, GetHistogramCountMap()); |
366 } | 375 } |
367 | 376 |
368 } // namespace | 377 } // namespace |
369 | 378 |
370 } // namespace precache | 379 } // namespace precache |
OLD | NEW |