| 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 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/location.h" | 16 #include "base/location.h" |
| 17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 18 #include "base/test/histogram_tester.h" | 18 #include "base/test/histogram_tester.h" |
| 19 #include "base/thread_task_runner_handle.h" | 19 #include "base/thread_task_runner_handle.h" |
| 20 #include "components/history/core/browser/history_constants.h" | 20 #include "components/history/core/browser/history_constants.h" |
| 21 #include "components/history/core/browser/history_service.h" | 21 #include "components/history/core/browser/history_service.h" |
| 22 #include "components/history/core/browser/history_types.h" | 22 #include "components/history/core/browser/history_types.h" |
| 23 #include "components/precache/core/precache_switches.h" | 23 #include "components/precache/core/precache_switches.h" |
| 24 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/test/test_browser_context.h" | 25 #include "content/public/test/test_browser_context.h" |
| 25 #include "content/public/test/test_browser_thread_bundle.h" | 26 #include "content/public/test/test_browser_thread_bundle.h" |
| 26 #include "net/http/http_status_code.h" | 27 #include "net/http/http_status_code.h" |
| 27 #include "net/url_request/test_url_fetcher_factory.h" | 28 #include "net/url_request/test_url_fetcher_factory.h" |
| 28 #include "net/url_request/url_request_status.h" | 29 #include "net/url_request/url_request_status.h" |
| 29 #include "net/url_request/url_request_test_util.h" | 30 #include "net/url_request/url_request_test_util.h" |
| 30 #include "testing/gmock/include/gmock/gmock.h" | 31 #include "testing/gmock/include/gmock/gmock.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| 32 #include "url/gurl.h" | 33 #include "url/gurl.h" |
| 33 | 34 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 140 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 140 switches::kPrecacheManifestURLPrefix, kManifestURLPrefix); | 141 switches::kPrecacheManifestURLPrefix, kManifestURLPrefix); |
| 141 | 142 |
| 142 // Make the fetch of the precache configuration settings fail. Precaching | 143 // Make the fetch of the precache configuration settings fail. Precaching |
| 143 // should still complete normally in this case. | 144 // should still complete normally in this case. |
| 144 factory_.SetFakeResponse(GURL(kConfigURL), "", | 145 factory_.SetFakeResponse(GURL(kConfigURL), "", |
| 145 net::HTTP_INTERNAL_SERVER_ERROR, | 146 net::HTTP_INTERNAL_SERVER_ERROR, |
| 146 net::URLRequestStatus::FAILED); | 147 net::URLRequestStatus::FAILED); |
| 147 } | 148 } |
| 148 | 149 |
| 150 // Must be declared first so that it is destroyed last. |
| 151 content::TestBrowserContext browser_context_; |
| 149 content::TestBrowserThreadBundle test_browser_thread_bundle_; | 152 content::TestBrowserThreadBundle test_browser_thread_bundle_; |
| 150 content::TestBrowserContext browser_context_; | |
| 151 PrecacheManagerUnderTest precache_manager_; | 153 PrecacheManagerUnderTest precache_manager_; |
| 152 TestURLFetcherCallback url_callback_; | 154 TestURLFetcherCallback url_callback_; |
| 153 net::FakeURLFetcherFactory factory_; | 155 net::FakeURLFetcherFactory factory_; |
| 154 TestPrecacheCompletionCallback precache_callback_; | 156 TestPrecacheCompletionCallback precache_callback_; |
| 155 testing::NiceMock<MockHistoryService> history_service_; | 157 testing::NiceMock<MockHistoryService> history_service_; |
| 156 base::HistogramTester histograms_; | 158 base::HistogramTester histograms_; |
| 157 }; | 159 }; |
| 158 | 160 |
| 159 TEST_F(PrecacheManagerTest, StartAndFinishPrecaching) { | 161 TEST_F(PrecacheManagerTest, StartAndFinishPrecaching) { |
| 160 EXPECT_FALSE(precache_manager_.IsPrecaching()); | 162 EXPECT_FALSE(precache_manager_.IsPrecaching()); |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 expected_histogram_count_map["Precache.Saved"] += 2; | 398 expected_histogram_count_map["Precache.Saved"] += 2; |
| 397 | 399 |
| 398 base::MessageLoop::current()->RunUntilIdle(); | 400 base::MessageLoop::current()->RunUntilIdle(); |
| 399 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), | 401 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), |
| 400 ContainerEq(expected_histogram_count_map)); | 402 ContainerEq(expected_histogram_count_map)); |
| 401 } | 403 } |
| 402 | 404 |
| 403 } // namespace | 405 } // namespace |
| 404 | 406 |
| 405 } // namespace precache | 407 } // namespace precache |
| OLD | NEW |