Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1042)

Side by Side Diff: chrome/browser/predictors/resource_prefetch_predictor_unittest.cc

Issue 2887133003: predictors: Refactor resource_prefetch_predictor triggering. (Closed)
Patch Set: . Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/test/histogram_tester.h" 14 #include "base/test/histogram_tester.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "chrome/browser/history/history_service_factory.h" 16 #include "chrome/browser/history/history_service_factory.h"
17 #include "chrome/browser/predictors/loading_predictor.h"
17 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" 18 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h"
18 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h" 19 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h"
20 #include "chrome/browser/predictors/resource_prefetcher_manager.h"
19 #include "chrome/test/base/testing_profile.h" 21 #include "chrome/test/base/testing_profile.h"
20 #include "components/history/core/browser/history_service.h" 22 #include "components/history/core/browser/history_service.h"
21 #include "components/history/core/browser/history_types.h" 23 #include "components/history/core/browser/history_types.h"
22 #include "components/sessions/core/session_id.h" 24 #include "components/sessions/core/session_id.h"
23 #include "content/public/browser/resource_request_info.h" 25 #include "content/public/browser/resource_request_info.h"
24 #include "content/public/test/test_browser_thread_bundle.h" 26 #include "content/public/test/test_browser_thread_bundle.h"
25 #include "net/http/http_response_headers.h" 27 #include "net/http/http_response_headers.h"
26 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" 28 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
27 #include "net/url_request/url_request_context.h" 29 #include "net/url_request/url_request_context.h"
28 #include "net/url_request/url_request_job.h" 30 #include "net/url_request/url_request_job.h"
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 TRAFFIC_ANNOTATION_FOR_TESTS); 220 TRAFFIC_ANNOTATION_FOR_TESTS);
219 request->set_first_party_for_cookies(url); 221 request->set_first_party_for_cookies(url);
220 content::ResourceRequestInfo::AllocateForTesting( 222 content::ResourceRequestInfo::AllocateForTesting(
221 request.get(), resource_type, nullptr, -1, -1, -1, is_main_frame, false, 223 request.get(), resource_type, nullptr, -1, -1, -1, is_main_frame, false,
222 false, true, content::PREVIEWS_OFF); 224 false, true, content::PREVIEWS_OFF);
223 request->Start(); 225 request->Start();
224 return request; 226 return request;
225 } 227 }
226 228
227 void InitializePredictor() { 229 void InitializePredictor() {
228 predictor_->StartInitialization(); 230 loading_predictor_->StartInitialization();
229 base::RunLoop loop; 231 base::RunLoop loop;
230 loop.RunUntilIdle(); // Runs the DB lookup. 232 loop.RunUntilIdle(); // Runs the DB lookup.
231 profile_->BlockUntilHistoryProcessesPendingRequests(); 233 profile_->BlockUntilHistoryProcessesPendingRequests();
232 } 234 }
233 235
234 void ResetPredictor() { 236 void ResetPredictor() {
235 LoadingPredictorConfig config; 237 LoadingPredictorConfig config;
236 config.max_urls_to_track = 3; 238 PopulateTestConfig(&config);
237 config.max_hosts_to_track = 2;
238 config.min_url_visit_count = 2;
239 config.max_resources_per_entry = 4;
240 config.max_consecutive_misses = 2;
241 config.max_redirect_consecutive_misses = 2;
242 config.min_resource_confidence_to_trigger_prefetch = 0.5;
243 config.is_url_learning_enabled = true;
244 config.is_manifests_enabled = true;
245 config.is_origin_learning_enabled = true;
246 239
247 config.mode |= LoadingPredictorConfig::LEARNING; 240 loading_predictor_ =
248 predictor_.reset(new ResourcePrefetchPredictor(config, profile_.get())); 241 base::MakeUnique<LoadingPredictor>(config, profile_.get());
242 predictor_ = loading_predictor_->resource_prefetch_predictor();
249 predictor_->set_mock_tables(mock_tables_); 243 predictor_->set_mock_tables(mock_tables_);
250 } 244 }
251 245
252 void InitializeSampleData(); 246 void InitializeSampleData();
253 void TestRedirectStatusHistogram( 247 void TestRedirectStatusHistogram(
254 const std::string& predictor_initial_key, 248 const std::string& predictor_initial_key,
255 const std::string& predictor_key, 249 const std::string& predictor_key,
256 const std::string& navigation_initial_url, 250 const std::string& navigation_initial_url,
257 const std::string& navigation_url, 251 const std::string& navigation_url,
258 ResourcePrefetchPredictor::RedirectStatus expected_status); 252 ResourcePrefetchPredictor::RedirectStatus expected_status);
259 253
260 content::TestBrowserThreadBundle thread_bundle_; 254 content::TestBrowserThreadBundle thread_bundle_;
261 std::unique_ptr<TestingProfile> profile_; 255 std::unique_ptr<TestingProfile> profile_;
262 net::TestURLRequestContext url_request_context_; 256 net::TestURLRequestContext url_request_context_;
263 257
264 std::unique_ptr<ResourcePrefetchPredictor> predictor_; 258 std::unique_ptr<LoadingPredictor> loading_predictor_;
259 ResourcePrefetchPredictor* predictor_;
265 scoped_refptr<StrictMock<MockResourcePrefetchPredictorTables>> mock_tables_; 260 scoped_refptr<StrictMock<MockResourcePrefetchPredictorTables>> mock_tables_;
266 261
267 PrefetchDataMap test_url_data_; 262 PrefetchDataMap test_url_data_;
268 PrefetchDataMap test_host_data_; 263 PrefetchDataMap test_host_data_;
269 RedirectDataMap test_url_redirect_data_; 264 RedirectDataMap test_url_redirect_data_;
270 RedirectDataMap test_host_redirect_data_; 265 RedirectDataMap test_host_redirect_data_;
271 ManifestDataMap test_manifest_data_; 266 ManifestDataMap test_manifest_data_;
272 OriginDataMap test_origin_data_; 267 OriginDataMap test_origin_data_;
273 268
274 MockURLRequestJobFactory url_request_job_factory_; 269 MockURLRequestJobFactory url_request_job_factory_;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 EXPECT_TRUE(predictor_->inflight_navigations_.empty()); 304 EXPECT_TRUE(predictor_->inflight_navigations_.empty());
310 EXPECT_EQ(predictor_->initialization_state_, 305 EXPECT_EQ(predictor_->initialization_state_,
311 ResourcePrefetchPredictor::INITIALIZED); 306 ResourcePrefetchPredictor::INITIALIZED);
312 307
313 url_request_context_.set_job_factory(&url_request_job_factory_); 308 url_request_context_.set_job_factory(&url_request_job_factory_);
314 309
315 histogram_tester_.reset(new base::HistogramTester()); 310 histogram_tester_.reset(new base::HistogramTester());
316 } 311 }
317 312
318 void ResourcePrefetchPredictorTest::TearDown() { 313 void ResourcePrefetchPredictorTest::TearDown() {
319 predictor_.reset(NULL); 314 loading_predictor_ = nullptr;
320 profile_->DestroyHistoryService(); 315 profile_->DestroyHistoryService();
321 } 316 }
322 317
323 void ResourcePrefetchPredictorTest::InitializeSampleData() { 318 void ResourcePrefetchPredictorTest::InitializeSampleData() {
324 { // Url data. 319 { // Url data.
325 PrefetchData google = CreatePrefetchData("http://www.google.com/", 1); 320 PrefetchData google = CreatePrefetchData("http://www.google.com/", 1);
326 InitializeResourceData(google.add_resources(), 321 InitializeResourceData(google.add_resources(),
327 "http://google.com/style1.css", 322 "http://google.com/style1.css",
328 content::RESOURCE_TYPE_STYLESHEET, 3, 2, 1, 1.0, 323 content::RESOURCE_TYPE_STYLESHEET, 3, 2, 1, 1.0,
329 net::MEDIUM, false, false); 324 net::MEDIUM, false, false);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 const std::string& navigation_initial_url, 468 const std::string& navigation_initial_url,
474 const std::string& navigation_url, 469 const std::string& navigation_url,
475 ResourcePrefetchPredictor::RedirectStatus expected_status) { 470 ResourcePrefetchPredictor::RedirectStatus expected_status) {
476 // Database initialization. 471 // Database initialization.
477 const std::string& script_url = "https://cdn.google.com/script.js"; 472 const std::string& script_url = "https://cdn.google.com/script.js";
478 PrefetchData google = CreatePrefetchData(predictor_key, 1); 473 PrefetchData google = CreatePrefetchData(predictor_key, 1);
479 // We need at least one resource for prediction. 474 // We need at least one resource for prediction.
480 InitializeResourceData(google.add_resources(), script_url, 475 InitializeResourceData(google.add_resources(), script_url,
481 content::RESOURCE_TYPE_SCRIPT, 10, 0, 1, 2.1, 476 content::RESOURCE_TYPE_SCRIPT, 10, 0, 1, 2.1,
482 net::MEDIUM, false, false); 477 net::MEDIUM, false, false);
483 predictor_->host_table_cache_->insert( 478 predictor_->host_table_cache_->emplace(google.primary_key(), google);
484 std::make_pair(google.primary_key(), google));
485 479
486 if (predictor_initial_key != predictor_key) { 480 if (predictor_initial_key != predictor_key) {
487 RedirectData redirect = CreateRedirectData(predictor_initial_key, 1); 481 RedirectData redirect = CreateRedirectData(predictor_initial_key, 1);
488 InitializeRedirectStat(redirect.add_redirect_endpoints(), predictor_key, 10, 482 InitializeRedirectStat(redirect.add_redirect_endpoints(), predictor_key, 10,
489 0, 0); 483 0, 0);
490 predictor_->host_redirect_table_cache_->insert( 484 predictor_->host_redirect_table_cache_->emplace(redirect.primary_key(),
491 std::make_pair(redirect.primary_key(), redirect)); 485 redirect);
492 } 486 }
493 487
494 // Navigation simulation. 488 // Navigation simulation.
495 using testing::_; 489 using testing::_;
496 EXPECT_CALL(*mock_tables_.get(), UpdateResourceData(_, _)); 490 EXPECT_CALL(*mock_tables_.get(), UpdateResourceData(_, _));
497 EXPECT_CALL(*mock_tables_.get(), UpdateRedirectData(_, _)); 491 EXPECT_CALL(*mock_tables_.get(), UpdateRedirectData(_, _));
498 EXPECT_CALL(*mock_tables_.get(), UpdateOriginData(_)); 492 EXPECT_CALL(*mock_tables_.get(), UpdateOriginData(_));
499 URLRequestSummary initial = 493 URLRequestSummary initial =
500 CreateURLRequestSummary(1, navigation_initial_url); 494 CreateURLRequestSummary(1, navigation_initial_url);
501 predictor_->RecordURLRequest(initial); 495 predictor_->RecordURLRequest(initial);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 predictor_->RecordURLResponse(resource1); 592 predictor_->RecordURLResponse(resource1);
599 URLRequestSummary resource2 = CreateURLRequestSummary( 593 URLRequestSummary resource2 = CreateURLRequestSummary(
600 1, "https://www.google.com", "https://google.com/script1.js", 594 1, "https://www.google.com", "https://google.com/script1.js",
601 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); 595 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false);
602 predictor_->RecordURLResponse(resource2); 596 predictor_->RecordURLResponse(resource2);
603 URLRequestSummary resource3 = CreateURLRequestSummary( 597 URLRequestSummary resource3 = CreateURLRequestSummary(
604 1, "https://www.google.com", "https://google.com/script2.js", 598 1, "https://www.google.com", "https://google.com/script2.js",
605 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); 599 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false);
606 predictor_->RecordURLResponse(resource3); 600 predictor_->RecordURLResponse(resource3);
607 601
608 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( 602 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer(predictor_);
609 predictor_.get());
610 EXPECT_CALL( 603 EXPECT_CALL(
611 mock_observer, 604 mock_observer,
612 OnNavigationLearned(kVisitCount, 605 OnNavigationLearned(kVisitCount,
613 CreatePageRequestSummary( 606 CreatePageRequestSummary(
614 "https://www.google.com", "http://www.google.com", 607 "https://www.google.com", "http://www.google.com",
615 {resource1, resource2, resource3}))); 608 {resource1, resource2, resource3})));
616 609
617 PrefetchData host_data = CreatePrefetchData("www.google.com"); 610 PrefetchData host_data = CreatePrefetchData("www.google.com");
618 InitializeResourceData(host_data.add_resources(), 611 InitializeResourceData(host_data.add_resources(),
619 "https://google.com/style1.css", 612 "https://google.com/style1.css",
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true); 689 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true);
697 redirected.redirect_url = GURL("http://dev.null.google.com/style.css"); 690 redirected.redirect_url = GURL("http://dev.null.google.com/style.css");
698 691
699 predictor_->RecordURLRedirect(redirected); 692 predictor_->RecordURLRedirect(redirected);
700 redirected.is_no_store = true; 693 redirected.is_no_store = true;
701 redirected.request_url = redirected.redirect_url; 694 redirected.request_url = redirected.redirect_url;
702 redirected.redirect_url = GURL(); 695 redirected.redirect_url = GURL();
703 696
704 predictor_->RecordURLResponse(redirected); 697 predictor_->RecordURLResponse(redirected);
705 698
706 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( 699 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer(predictor_);
707 predictor_.get());
708 EXPECT_CALL(mock_observer, 700 EXPECT_CALL(mock_observer,
709 OnNavigationLearned( 701 OnNavigationLearned(
710 kVisitCount, CreatePageRequestSummary("http://www.google.com", 702 kVisitCount, CreatePageRequestSummary("http://www.google.com",
711 "http://www.google.com", 703 "http://www.google.com",
712 resources))); 704 resources)));
713 705
714 PrefetchData url_data = CreatePrefetchData("http://www.google.com/"); 706 PrefetchData url_data = CreatePrefetchData("http://www.google.com/");
715 InitializeResourceData(url_data.add_resources(), 707 InitializeResourceData(url_data.add_resources(),
716 "http://google.com/style1.css", 708 "http://google.com/style1.css",
717 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, 709 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0,
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 1, "http://www.google.com", "http://google.com/style2.css", 808 1, "http://www.google.com", "http://google.com/style2.css",
817 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true)); 809 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true));
818 predictor_->RecordURLResponse(resources.back()); 810 predictor_->RecordURLResponse(resources.back());
819 auto no_store = CreateURLRequestSummary( 811 auto no_store = CreateURLRequestSummary(
820 1, "http://www.google.com", 812 1, "http://www.google.com",
821 "http://static.google.com/style2-no-store.css", 813 "http://static.google.com/style2-no-store.css",
822 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true); 814 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true);
823 no_store.is_no_store = true; 815 no_store.is_no_store = true;
824 predictor_->RecordURLResponse(no_store); 816 predictor_->RecordURLResponse(no_store);
825 817
826 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( 818 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer(predictor_);
827 predictor_.get());
828 EXPECT_CALL(mock_observer, 819 EXPECT_CALL(mock_observer,
829 OnNavigationLearned( 820 OnNavigationLearned(
830 kVisitCount, CreatePageRequestSummary("http://www.google.com", 821 kVisitCount, CreatePageRequestSummary("http://www.google.com",
831 "http://www.google.com", 822 "http://www.google.com",
832 resources))); 823 resources)));
833 824
834 PrefetchData url_data = CreatePrefetchData("http://www.google.com/"); 825 PrefetchData url_data = CreatePrefetchData("http://www.google.com/");
835 InitializeResourceData(url_data.add_resources(), 826 InitializeResourceData(url_data.add_resources(),
836 "http://google.com/style1.css", 827 "http://google.com/style1.css",
837 content::RESOURCE_TYPE_STYLESHEET, 4, 2, 0, 1.0, 828 content::RESOURCE_TYPE_STYLESHEET, 4, 2, 0, 1.0,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 913
923 URLRequestSummary resource1 = CreateURLRequestSummary( 914 URLRequestSummary resource1 = CreateURLRequestSummary(
924 1, "http://www.nike.com", "http://nike.com/style1.css", 915 1, "http://www.nike.com", "http://nike.com/style1.css",
925 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); 916 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false);
926 predictor_->RecordURLResponse(resource1); 917 predictor_->RecordURLResponse(resource1);
927 URLRequestSummary resource2 = CreateURLRequestSummary( 918 URLRequestSummary resource2 = CreateURLRequestSummary(
928 1, "http://www.nike.com", "http://nike.com/image2.png", 919 1, "http://www.nike.com", "http://nike.com/image2.png",
929 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false); 920 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false);
930 predictor_->RecordURLResponse(resource2); 921 predictor_->RecordURLResponse(resource2);
931 922
932 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( 923 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer(predictor_);
933 predictor_.get());
934 EXPECT_CALL(mock_observer, 924 EXPECT_CALL(mock_observer,
935 OnNavigationLearned( 925 OnNavigationLearned(
936 kVisitCount, CreatePageRequestSummary( 926 kVisitCount, CreatePageRequestSummary(
937 "http://www.nike.com", "http://www.nike.com", 927 "http://www.nike.com", "http://www.nike.com",
938 {resource1, resource2}))); 928 {resource1, resource2})));
939 929
940 EXPECT_CALL(*mock_tables_.get(), 930 EXPECT_CALL(*mock_tables_.get(),
941 DeleteSingleResourceDataPoint("http://www.google.com/", 931 DeleteSingleResourceDataPoint("http://www.google.com/",
942 PREFETCH_KEY_TYPE_URL)); 932 PREFETCH_KEY_TYPE_URL));
943 EXPECT_CALL(*mock_tables_.get(), 933 EXPECT_CALL(*mock_tables_.get(),
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); 978 EXPECT_EQ(1U, predictor_->inflight_navigations_.size());
989 979
990 URLRequestSummary fb2 = CreateRedirectRequestSummary( 980 URLRequestSummary fb2 = CreateRedirectRequestSummary(
991 1, "http://fb.com/google", "http://facebook.com/google"); 981 1, "http://fb.com/google", "http://facebook.com/google");
992 predictor_->RecordURLRedirect(fb2); 982 predictor_->RecordURLRedirect(fb2);
993 URLRequestSummary fb3 = CreateRedirectRequestSummary( 983 URLRequestSummary fb3 = CreateRedirectRequestSummary(
994 1, "http://facebook.com/google", "https://facebook.com/google"); 984 1, "http://facebook.com/google", "https://facebook.com/google");
995 predictor_->RecordURLRedirect(fb3); 985 predictor_->RecordURLRedirect(fb3);
996 NavigationID fb_end = CreateNavigationID(1, "https://facebook.com/google"); 986 NavigationID fb_end = CreateNavigationID(1, "https://facebook.com/google");
997 987
998 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( 988 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer(predictor_);
999 predictor_.get());
1000 EXPECT_CALL( 989 EXPECT_CALL(
1001 mock_observer, 990 mock_observer,
1002 OnNavigationLearned(kVisitCount, CreatePageRequestSummary( 991 OnNavigationLearned(kVisitCount, CreatePageRequestSummary(
1003 "https://facebook.com/google", 992 "https://facebook.com/google",
1004 "http://fb.com/google", 993 "http://fb.com/google",
1005 std::vector<URLRequestSummary>()))); 994 std::vector<URLRequestSummary>())));
1006 995
1007 // Since the navigation hasn't resources, corresponding entry 996 // Since the navigation hasn't resources, corresponding entry
1008 // in resource table will be deleted. 997 // in resource table will be deleted.
1009 EXPECT_CALL(*mock_tables_.get(), 998 EXPECT_CALL(*mock_tables_.get(),
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); 1042 EXPECT_EQ(1U, predictor_->inflight_navigations_.size());
1054 1043
1055 URLRequestSummary fb2 = CreateRedirectRequestSummary( 1044 URLRequestSummary fb2 = CreateRedirectRequestSummary(
1056 1, "http://fb.com/google", "http://facebook.com/google"); 1045 1, "http://fb.com/google", "http://facebook.com/google");
1057 predictor_->RecordURLRedirect(fb2); 1046 predictor_->RecordURLRedirect(fb2);
1058 URLRequestSummary fb3 = CreateRedirectRequestSummary( 1047 URLRequestSummary fb3 = CreateRedirectRequestSummary(
1059 1, "http://facebook.com/google", "https://facebook.com/google"); 1048 1, "http://facebook.com/google", "https://facebook.com/google");
1060 predictor_->RecordURLRedirect(fb3); 1049 predictor_->RecordURLRedirect(fb3);
1061 NavigationID fb_end = CreateNavigationID(1, "https://facebook.com/google"); 1050 NavigationID fb_end = CreateNavigationID(1, "https://facebook.com/google");
1062 1051
1063 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( 1052 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer(predictor_);
1064 predictor_.get());
1065 EXPECT_CALL( 1053 EXPECT_CALL(
1066 mock_observer, 1054 mock_observer,
1067 OnNavigationLearned(kVisitCount, CreatePageRequestSummary( 1055 OnNavigationLearned(kVisitCount, CreatePageRequestSummary(
1068 "https://facebook.com/google", 1056 "https://facebook.com/google",
1069 "http://fb.com/google", 1057 "http://fb.com/google",
1070 std::vector<URLRequestSummary>()))); 1058 std::vector<URLRequestSummary>())));
1071 1059
1072 // Oldest entries in tables will be superseded and deleted. 1060 // Oldest entries in tables will be superseded and deleted.
1073 EXPECT_CALL(*mock_tables_.get(), 1061 EXPECT_CALL(*mock_tables_.get(),
1074 DeleteSingleRedirectDataPoint("bbc.com", PREFETCH_KEY_TYPE_HOST)); 1062 DeleteSingleRedirectDataPoint("bbc.com", PREFETCH_KEY_TYPE_HOST));
(...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after
2089 } 2077 }
2090 2078
2091 TEST_F(ResourcePrefetchPredictorTest, 2079 TEST_F(ResourcePrefetchPredictorTest,
2092 TestRedirectStatusRedirectCorrectlyPredicted) { 2080 TestRedirectStatusRedirectCorrectlyPredicted) {
2093 TestRedirectStatusHistogram( 2081 TestRedirectStatusHistogram(
2094 "google.com", "www.google.com", "http://google.com?query=cats", 2082 "google.com", "www.google.com", "http://google.com?query=cats",
2095 "http://www.google.com?query=cats", 2083 "http://www.google.com?query=cats",
2096 ResourcePrefetchPredictor::RedirectStatus::REDIRECT_CORRECTLY_PREDICTED); 2084 ResourcePrefetchPredictor::RedirectStatus::REDIRECT_CORRECTLY_PREDICTED);
2097 } 2085 }
2098 2086
2099 TEST_F(ResourcePrefetchPredictorTest, TestPrefetchingDurationHistogram) {
2100 // Prefetching duration for an url without resources in the database
2101 // shouldn't be recorded.
2102 const std::string main_frame_url = "http://google.com/?query=cats";
2103 predictor_->StartPrefetching(GURL(main_frame_url), HintOrigin::EXTERNAL);
2104 predictor_->StopPrefetching(GURL(main_frame_url));
2105 histogram_tester_->ExpectTotalCount(
2106 internal::kResourcePrefetchPredictorPrefetchingDurationHistogram, 0);
2107
2108 // Fill the database to record a duration.
2109 PrefetchData google = CreatePrefetchData("google.com", 1);
2110 InitializeResourceData(
2111 google.add_resources(), "https://cdn.google.com/script.js",
2112 content::RESOURCE_TYPE_SCRIPT, 10, 0, 1, 2.1, net::MEDIUM, false, false);
2113 predictor_->host_table_cache_->insert(
2114 std::make_pair(google.primary_key(), google));
2115
2116 predictor_->StartPrefetching(GURL(main_frame_url), HintOrigin::EXTERNAL);
2117 predictor_->StopPrefetching(GURL(main_frame_url));
2118 histogram_tester_->ExpectTotalCount(
2119 internal::kResourcePrefetchPredictorPrefetchingDurationHistogram, 1);
2120 }
2121
2122 TEST_F(ResourcePrefetchPredictorTest, TestRecordFirstContentfulPaint) { 2087 TEST_F(ResourcePrefetchPredictorTest, TestRecordFirstContentfulPaint) {
2123 using testing::_; 2088 using testing::_;
2124 EXPECT_CALL(*mock_tables_.get(), UpdateRedirectData(_, _)); 2089 EXPECT_CALL(*mock_tables_.get(), UpdateRedirectData(_, _));
2125 EXPECT_CALL(*mock_tables_.get(), UpdateOriginData(_)); 2090 EXPECT_CALL(*mock_tables_.get(), UpdateOriginData(_));
2126 2091
2127 auto res1_time = base::TimeTicks::FromInternalValue(1); 2092 auto res1_time = base::TimeTicks::FromInternalValue(1);
2128 auto res2_time = base::TimeTicks::FromInternalValue(2); 2093 auto res2_time = base::TimeTicks::FromInternalValue(2);
2129 auto fcp_time = base::TimeTicks::FromInternalValue(3); 2094 auto fcp_time = base::TimeTicks::FromInternalValue(3);
2130 auto res3_time = base::TimeTicks::FromInternalValue(4); 2095 auto res3_time = base::TimeTicks::FromInternalValue(4);
2131 2096
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2166 net::MEDIUM, false, false); 2131 net::MEDIUM, false, false);
2167 resource3_rd->set_before_first_contentful_paint(false); 2132 resource3_rd->set_before_first_contentful_paint(false);
2168 EXPECT_CALL(*mock_tables_.get(), 2133 EXPECT_CALL(*mock_tables_.get(),
2169 UpdateResourceData(host_data, PREFETCH_KEY_TYPE_HOST)); 2134 UpdateResourceData(host_data, PREFETCH_KEY_TYPE_HOST));
2170 2135
2171 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); 2136 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id);
2172 profile_->BlockUntilHistoryProcessesPendingRequests(); 2137 profile_->BlockUntilHistoryProcessesPendingRequests();
2173 } 2138 }
2174 2139
2175 } // namespace predictors 2140 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698