| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/predictors/resource_prefetch_predictor.h" | 5 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
| 6 | 6 |
| 7 #include <iostream> | 7 #include <iostream> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/message_loop/message_loop.h" | |
| 14 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 15 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 16 #include "chrome/browser/history/history_service_factory.h" | 15 #include "chrome/browser/history/history_service_factory.h" |
| 17 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" | 16 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" |
| 18 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h" | 17 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h" |
| 19 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
| 20 #include "components/history/core/browser/history_service.h" | 19 #include "components/history/core/browser/history_service.h" |
| 21 #include "components/history/core/browser/history_types.h" | 20 #include "components/history/core/browser/history_types.h" |
| 22 #include "content/public/browser/resource_request_info.h" | 21 #include "content/public/browser/resource_request_info.h" |
| 23 #include "content/public/test/test_browser_thread.h" | 22 #include "content/public/test/test_browser_thread_bundle.h" |
| 24 #include "net/http/http_response_headers.h" | 23 #include "net/http/http_response_headers.h" |
| 25 #include "net/url_request/url_request_context.h" | 24 #include "net/url_request/url_request_context.h" |
| 26 #include "net/url_request/url_request_job.h" | 25 #include "net/url_request/url_request_job.h" |
| 27 #include "net/url_request/url_request_test_util.h" | 26 #include "net/url_request/url_request_test_util.h" |
| 28 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 29 |
| 31 using testing::ContainerEq; | 30 using testing::ContainerEq; |
| 32 using testing::Pointee; | 31 using testing::Pointee; |
| 33 using testing::SetArgPointee; | 32 using testing::SetArgPointee; |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 | 261 |
| 263 // TODO(shishir): Enable the prefetching mode in the tests. | 262 // TODO(shishir): Enable the prefetching mode in the tests. |
| 264 config.mode |= ResourcePrefetchPredictorConfig::URL_LEARNING; | 263 config.mode |= ResourcePrefetchPredictorConfig::URL_LEARNING; |
| 265 config.mode |= ResourcePrefetchPredictorConfig::HOST_LEARNING; | 264 config.mode |= ResourcePrefetchPredictorConfig::HOST_LEARNING; |
| 266 predictor_.reset(new ResourcePrefetchPredictor(config, profile_.get())); | 265 predictor_.reset(new ResourcePrefetchPredictor(config, profile_.get())); |
| 267 predictor_->set_mock_tables(mock_tables_); | 266 predictor_->set_mock_tables(mock_tables_); |
| 268 } | 267 } |
| 269 | 268 |
| 270 void InitializeSampleData(); | 269 void InitializeSampleData(); |
| 271 | 270 |
| 272 base::MessageLoop loop_; | 271 content::TestBrowserThreadBundle thread_bundle_; |
| 273 content::TestBrowserThread ui_thread_; | |
| 274 content::TestBrowserThread db_thread_; | |
| 275 std::unique_ptr<TestingProfile> profile_; | 272 std::unique_ptr<TestingProfile> profile_; |
| 276 net::TestURLRequestContext url_request_context_; | 273 net::TestURLRequestContext url_request_context_; |
| 277 | 274 |
| 278 std::unique_ptr<ResourcePrefetchPredictor> predictor_; | 275 std::unique_ptr<ResourcePrefetchPredictor> predictor_; |
| 279 scoped_refptr<StrictMock<MockResourcePrefetchPredictorTables> > mock_tables_; | 276 scoped_refptr<StrictMock<MockResourcePrefetchPredictorTables> > mock_tables_; |
| 280 | 277 |
| 281 PrefetchDataMap test_url_data_; | 278 PrefetchDataMap test_url_data_; |
| 282 PrefetchDataMap test_host_data_; | 279 PrefetchDataMap test_host_data_; |
| 283 RedirectDataMap test_url_redirect_data_; | 280 RedirectDataMap test_url_redirect_data_; |
| 284 RedirectDataMap test_host_redirect_data_; | 281 RedirectDataMap test_host_redirect_data_; |
| 285 PrefetchData empty_resource_data_; | 282 PrefetchData empty_resource_data_; |
| 286 RedirectData empty_redirect_data_; | 283 RedirectData empty_redirect_data_; |
| 287 | 284 |
| 288 MockURLRequestJobFactory url_request_job_factory_; | 285 MockURLRequestJobFactory url_request_job_factory_; |
| 289 EmptyURLRequestDelegate url_request_delegate_; | 286 EmptyURLRequestDelegate url_request_delegate_; |
| 290 }; | 287 }; |
| 291 | 288 |
| 292 ResourcePrefetchPredictorTest::ResourcePrefetchPredictorTest() | 289 ResourcePrefetchPredictorTest::ResourcePrefetchPredictorTest() |
| 293 : loop_(base::MessageLoop::TYPE_DEFAULT), | 290 : thread_bundle_(), |
| 294 ui_thread_(content::BrowserThread::UI, &loop_), | |
| 295 db_thread_(content::BrowserThread::DB, &loop_), | |
| 296 profile_(new TestingProfile()), | 291 profile_(new TestingProfile()), |
| 297 mock_tables_(new StrictMock<MockResourcePrefetchPredictorTables>()), | 292 mock_tables_(new StrictMock<MockResourcePrefetchPredictorTables>()), |
| 298 empty_resource_data_(), | 293 empty_resource_data_(), |
| 299 empty_redirect_data_() {} | 294 empty_redirect_data_() {} |
| 300 | 295 |
| 301 ResourcePrefetchPredictorTest::~ResourcePrefetchPredictorTest() { | 296 ResourcePrefetchPredictorTest::~ResourcePrefetchPredictorTest() { |
| 302 profile_.reset(NULL); | 297 profile_.reset(NULL); |
| 303 base::RunLoop().RunUntilIdle(); | 298 base::RunLoop().RunUntilIdle(); |
| 304 } | 299 } |
| 305 | 300 |
| (...skipping 1191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1497 net::MEDIUM, false, false); | 1492 net::MEDIUM, false, false); |
| 1498 predictor_->url_table_cache_->insert( | 1493 predictor_->url_table_cache_->insert( |
| 1499 std::make_pair(www_google_url.primary_key(), www_google_url)); | 1494 std::make_pair(www_google_url.primary_key(), www_google_url)); |
| 1500 | 1495 |
| 1501 urls.clear(); | 1496 urls.clear(); |
| 1502 EXPECT_TRUE(predictor_->GetPrefetchData(main_frame_url, &urls)); | 1497 EXPECT_TRUE(predictor_->GetPrefetchData(main_frame_url, &urls)); |
| 1503 EXPECT_THAT(urls, UnorderedElementsAre(GURL(font_url))); | 1498 EXPECT_THAT(urls, UnorderedElementsAre(GURL(font_url))); |
| 1504 } | 1499 } |
| 1505 | 1500 |
| 1506 } // namespace predictors | 1501 } // namespace predictors |
| OLD | NEW |