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

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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 TRAFFIC_ANNOTATION_FOR_TESTS); 254 TRAFFIC_ANNOTATION_FOR_TESTS);
253 request->set_first_party_for_cookies(url); 255 request->set_first_party_for_cookies(url);
254 content::ResourceRequestInfo::AllocateForTesting( 256 content::ResourceRequestInfo::AllocateForTesting(
255 request.get(), resource_type, nullptr, -1, -1, -1, is_main_frame, false, 257 request.get(), resource_type, nullptr, -1, -1, -1, is_main_frame, false,
256 false, true, content::PREVIEWS_OFF); 258 false, true, content::PREVIEWS_OFF);
257 request->Start(); 259 request->Start();
258 return request; 260 return request;
259 } 261 }
260 262
261 void InitializePredictor() { 263 void InitializePredictor() {
262 predictor_->StartInitialization(); 264 loading_predictor_->StartInitialization();
263 base::RunLoop loop; 265 base::RunLoop loop;
264 loop.RunUntilIdle(); // Runs the DB lookup. 266 loop.RunUntilIdle(); // Runs the DB lookup.
265 profile_->BlockUntilHistoryProcessesPendingRequests(); 267 profile_->BlockUntilHistoryProcessesPendingRequests();
266 } 268 }
267 269
268 void ResetPredictor(bool small_db = true) { 270 void ResetPredictor(bool small_db = true) {
269 LoadingPredictorConfig config; 271 LoadingPredictorConfig config;
270 if (small_db) { 272 PopulateTestConfig(&config, small_db);
271 config.max_urls_to_track = 3; 273 loading_predictor_ =
272 config.max_hosts_to_track = 2; 274 base::MakeUnique<LoadingPredictor>(config, profile_.get());
273 config.max_resources_per_entry = 4; 275 predictor_ = loading_predictor_->resource_prefetch_predictor();
274 config.max_consecutive_misses = 2;
275 config.max_redirect_consecutive_misses = 2;
276 config.min_resource_confidence_to_trigger_prefetch = 0.5;
277 }
278 config.is_url_learning_enabled = true;
279 config.is_manifests_enabled = true;
280 config.is_origin_learning_enabled = true;
281
282 config.mode |= LoadingPredictorConfig::LEARNING;
283 predictor_.reset(new ResourcePrefetchPredictor(config, profile_.get()));
284 predictor_->set_mock_tables(mock_tables_); 276 predictor_->set_mock_tables(mock_tables_);
285 } 277 }
286 278
287 void InitializeSampleData(); 279 void InitializeSampleData();
288 void TestRedirectStatusHistogram( 280 void TestRedirectStatusHistogram(
289 const std::string& predictor_initial_key, 281 const std::string& predictor_initial_key,
290 const std::string& predictor_key, 282 const std::string& predictor_key,
291 const std::string& navigation_initial_url, 283 const std::string& navigation_initial_url,
292 const std::string& navigation_url, 284 const std::string& navigation_url,
293 ResourcePrefetchPredictor::RedirectStatus expected_status); 285 ResourcePrefetchPredictor::RedirectStatus expected_status);
294 286
295 content::TestBrowserThreadBundle thread_bundle_; 287 content::TestBrowserThreadBundle thread_bundle_;
296 std::unique_ptr<TestingProfile> profile_; 288 std::unique_ptr<TestingProfile> profile_;
297 net::TestURLRequestContext url_request_context_; 289 net::TestURLRequestContext url_request_context_;
298 290
299 std::unique_ptr<ResourcePrefetchPredictor> predictor_; 291 std::unique_ptr<LoadingPredictor> loading_predictor_;
292 ResourcePrefetchPredictor* predictor_;
300 scoped_refptr<StrictMock<MockResourcePrefetchPredictorTables>> mock_tables_; 293 scoped_refptr<StrictMock<MockResourcePrefetchPredictorTables>> mock_tables_;
301 294
302 PrefetchDataMap test_url_data_; 295 PrefetchDataMap test_url_data_;
303 PrefetchDataMap test_host_data_; 296 PrefetchDataMap test_host_data_;
304 RedirectDataMap test_url_redirect_data_; 297 RedirectDataMap test_url_redirect_data_;
305 RedirectDataMap test_host_redirect_data_; 298 RedirectDataMap test_host_redirect_data_;
306 ManifestDataMap test_manifest_data_; 299 ManifestDataMap test_manifest_data_;
307 OriginDataMap test_origin_data_; 300 OriginDataMap test_origin_data_;
308 301
309 MockURLRequestJobFactory url_request_job_factory_; 302 MockURLRequestJobFactory url_request_job_factory_;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 EXPECT_EQ(*predictor_->url_redirect_data_->data_cache_, 341 EXPECT_EQ(*predictor_->url_redirect_data_->data_cache_,
349 mock_tables_->url_redirect_table_.data_); 342 mock_tables_->url_redirect_table_.data_);
350 EXPECT_EQ(*predictor_->host_resource_data_->data_cache_, 343 EXPECT_EQ(*predictor_->host_resource_data_->data_cache_,
351 mock_tables_->host_resource_table_.data_); 344 mock_tables_->host_resource_table_.data_);
352 EXPECT_EQ(*predictor_->host_redirect_data_->data_cache_, 345 EXPECT_EQ(*predictor_->host_redirect_data_->data_cache_,
353 mock_tables_->host_redirect_table_.data_); 346 mock_tables_->host_redirect_table_.data_);
354 EXPECT_EQ(*predictor_->manifest_data_->data_cache_, 347 EXPECT_EQ(*predictor_->manifest_data_->data_cache_,
355 mock_tables_->manifest_table_.data_); 348 mock_tables_->manifest_table_.data_);
356 EXPECT_EQ(*predictor_->origin_data_->data_cache_, 349 EXPECT_EQ(*predictor_->origin_data_->data_cache_,
357 mock_tables_->origin_table_.data_); 350 mock_tables_->origin_table_.data_);
358 predictor_.reset(NULL); 351 loading_predictor_ = nullptr;
352 predictor_ = nullptr;
359 profile_->DestroyHistoryService(); 353 profile_->DestroyHistoryService();
360 } 354 }
361 355
362 void ResourcePrefetchPredictorTest::InitializeSampleData() { 356 void ResourcePrefetchPredictorTest::InitializeSampleData() {
363 { // Url data. 357 { // Url data.
364 PrefetchData google = CreatePrefetchData("http://www.google.com/", 1); 358 PrefetchData google = CreatePrefetchData("http://www.google.com/", 1);
365 InitializeResourceData(google.add_resources(), 359 InitializeResourceData(google.add_resources(),
366 "http://google.com/style1.css", 360 "http://google.com/style1.css",
367 content::RESOURCE_TYPE_STYLESHEET, 3, 2, 1, 1.0, 361 content::RESOURCE_TYPE_STYLESHEET, 3, 2, 1, 1.0,
368 net::MEDIUM, false, false); 362 net::MEDIUM, false, false);
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 predictor_->RecordURLResponse(resource1); 611 predictor_->RecordURLResponse(resource1);
618 URLRequestSummary resource2 = CreateURLRequestSummary( 612 URLRequestSummary resource2 = CreateURLRequestSummary(
619 1, "https://www.google.com", "https://google.com/script1.js", 613 1, "https://www.google.com", "https://google.com/script1.js",
620 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); 614 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false);
621 predictor_->RecordURLResponse(resource2); 615 predictor_->RecordURLResponse(resource2);
622 URLRequestSummary resource3 = CreateURLRequestSummary( 616 URLRequestSummary resource3 = CreateURLRequestSummary(
623 1, "https://www.google.com", "https://google.com/script2.js", 617 1, "https://www.google.com", "https://google.com/script2.js",
624 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); 618 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false);
625 predictor_->RecordURLResponse(resource3); 619 predictor_->RecordURLResponse(resource3);
626 620
627 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( 621 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer(predictor_);
628 predictor_.get());
629 EXPECT_CALL( 622 EXPECT_CALL(
630 mock_observer, 623 mock_observer,
631 OnNavigationLearned(kVisitCount, 624 OnNavigationLearned(kVisitCount,
632 CreatePageRequestSummary( 625 CreatePageRequestSummary(
633 "https://www.google.com", "http://www.google.com", 626 "https://www.google.com", "http://www.google.com",
634 {resource1, resource2, resource3}))); 627 {resource1, resource2, resource3})));
635 628
636 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); 629 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id);
637 profile_->BlockUntilHistoryProcessesPendingRequests(); 630 profile_->BlockUntilHistoryProcessesPendingRequests();
638 631
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true); 710 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true);
718 redirected.redirect_url = GURL("http://dev.null.google.com/style.css"); 711 redirected.redirect_url = GURL("http://dev.null.google.com/style.css");
719 712
720 predictor_->RecordURLRedirect(redirected); 713 predictor_->RecordURLRedirect(redirected);
721 redirected.is_no_store = true; 714 redirected.is_no_store = true;
722 redirected.request_url = redirected.redirect_url; 715 redirected.request_url = redirected.redirect_url;
723 redirected.redirect_url = GURL(); 716 redirected.redirect_url = GURL();
724 717
725 predictor_->RecordURLResponse(redirected); 718 predictor_->RecordURLResponse(redirected);
726 719
727 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( 720 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer(predictor_);
728 predictor_.get());
729 EXPECT_CALL(mock_observer, 721 EXPECT_CALL(mock_observer,
730 OnNavigationLearned( 722 OnNavigationLearned(
731 kVisitCount, CreatePageRequestSummary("http://www.google.com", 723 kVisitCount, CreatePageRequestSummary("http://www.google.com",
732 "http://www.google.com", 724 "http://www.google.com",
733 resources))); 725 resources)));
734 726
735 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); 727 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id);
736 profile_->BlockUntilHistoryProcessesPendingRequests(); 728 profile_->BlockUntilHistoryProcessesPendingRequests();
737 729
738 PrefetchData url_data = CreatePrefetchData("http://www.google.com/"); 730 PrefetchData url_data = CreatePrefetchData("http://www.google.com/");
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 1, "http://www.google.com", "http://google.com/style2.css", 824 1, "http://www.google.com", "http://google.com/style2.css",
833 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true)); 825 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true));
834 predictor_->RecordURLResponse(resources.back()); 826 predictor_->RecordURLResponse(resources.back());
835 auto no_store = CreateURLRequestSummary( 827 auto no_store = CreateURLRequestSummary(
836 1, "http://www.google.com", 828 1, "http://www.google.com",
837 "http://static.google.com/style2-no-store.css", 829 "http://static.google.com/style2-no-store.css",
838 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true); 830 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true);
839 no_store.is_no_store = true; 831 no_store.is_no_store = true;
840 predictor_->RecordURLResponse(no_store); 832 predictor_->RecordURLResponse(no_store);
841 833
842 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( 834 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer(predictor_);
843 predictor_.get());
844 EXPECT_CALL(mock_observer, 835 EXPECT_CALL(mock_observer,
845 OnNavigationLearned( 836 OnNavigationLearned(
846 kVisitCount, CreatePageRequestSummary("http://www.google.com", 837 kVisitCount, CreatePageRequestSummary("http://www.google.com",
847 "http://www.google.com", 838 "http://www.google.com",
848 resources))); 839 resources)));
849 840
850 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); 841 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id);
851 profile_->BlockUntilHistoryProcessesPendingRequests(); 842 profile_->BlockUntilHistoryProcessesPendingRequests();
852 843
853 PrefetchData url_data = CreatePrefetchData("http://www.google.com/"); 844 PrefetchData url_data = CreatePrefetchData("http://www.google.com/");
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 926
936 URLRequestSummary resource1 = CreateURLRequestSummary( 927 URLRequestSummary resource1 = CreateURLRequestSummary(
937 1, "http://www.nike.com", "http://nike.com/style1.css", 928 1, "http://www.nike.com", "http://nike.com/style1.css",
938 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); 929 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false);
939 predictor_->RecordURLResponse(resource1); 930 predictor_->RecordURLResponse(resource1);
940 URLRequestSummary resource2 = CreateURLRequestSummary( 931 URLRequestSummary resource2 = CreateURLRequestSummary(
941 1, "http://www.nike.com", "http://nike.com/image2.png", 932 1, "http://www.nike.com", "http://nike.com/image2.png",
942 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false); 933 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false);
943 predictor_->RecordURLResponse(resource2); 934 predictor_->RecordURLResponse(resource2);
944 935
945 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( 936 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer(predictor_);
946 predictor_.get());
947 EXPECT_CALL(mock_observer, 937 EXPECT_CALL(mock_observer,
948 OnNavigationLearned( 938 OnNavigationLearned(
949 kVisitCount, CreatePageRequestSummary( 939 kVisitCount, CreatePageRequestSummary(
950 "http://www.nike.com", "http://www.nike.com", 940 "http://www.nike.com", "http://www.nike.com",
951 {resource1, resource2}))); 941 {resource1, resource2})));
952 942
953 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); 943 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id);
954 profile_->BlockUntilHistoryProcessesPendingRequests(); 944 profile_->BlockUntilHistoryProcessesPendingRequests();
955 945
956 PrefetchData url_data = CreatePrefetchData("http://www.nike.com/"); 946 PrefetchData url_data = CreatePrefetchData("http://www.nike.com/");
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); 996 EXPECT_EQ(1U, predictor_->inflight_navigations_.size());
1007 997
1008 URLRequestSummary fb2 = CreateRedirectRequestSummary( 998 URLRequestSummary fb2 = CreateRedirectRequestSummary(
1009 1, "http://fb.com/google", "http://facebook.com/google"); 999 1, "http://fb.com/google", "http://facebook.com/google");
1010 predictor_->RecordURLRedirect(fb2); 1000 predictor_->RecordURLRedirect(fb2);
1011 URLRequestSummary fb3 = CreateRedirectRequestSummary( 1001 URLRequestSummary fb3 = CreateRedirectRequestSummary(
1012 1, "http://facebook.com/google", "https://facebook.com/google"); 1002 1, "http://facebook.com/google", "https://facebook.com/google");
1013 predictor_->RecordURLRedirect(fb3); 1003 predictor_->RecordURLRedirect(fb3);
1014 NavigationID fb_end = CreateNavigationID(1, "https://facebook.com/google"); 1004 NavigationID fb_end = CreateNavigationID(1, "https://facebook.com/google");
1015 1005
1016 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( 1006 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer(predictor_);
1017 predictor_.get());
1018 EXPECT_CALL( 1007 EXPECT_CALL(
1019 mock_observer, 1008 mock_observer,
1020 OnNavigationLearned(kVisitCount, CreatePageRequestSummary( 1009 OnNavigationLearned(kVisitCount, CreatePageRequestSummary(
1021 "https://facebook.com/google", 1010 "https://facebook.com/google",
1022 "http://fb.com/google", 1011 "http://fb.com/google",
1023 std::vector<URLRequestSummary>()))); 1012 std::vector<URLRequestSummary>())));
1024 1013
1025 predictor_->RecordMainFrameLoadComplete(fb_end); 1014 predictor_->RecordMainFrameLoadComplete(fb_end);
1026 profile_->BlockUntilHistoryProcessesPendingRequests(); 1015 profile_->BlockUntilHistoryProcessesPendingRequests();
1027 1016
(...skipping 29 matching lines...) Expand all
1057 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); 1046 EXPECT_EQ(1U, predictor_->inflight_navigations_.size());
1058 1047
1059 URLRequestSummary fb2 = CreateRedirectRequestSummary( 1048 URLRequestSummary fb2 = CreateRedirectRequestSummary(
1060 1, "http://fb.com/google", "http://facebook.com/google"); 1049 1, "http://fb.com/google", "http://facebook.com/google");
1061 predictor_->RecordURLRedirect(fb2); 1050 predictor_->RecordURLRedirect(fb2);
1062 URLRequestSummary fb3 = CreateRedirectRequestSummary( 1051 URLRequestSummary fb3 = CreateRedirectRequestSummary(
1063 1, "http://facebook.com/google", "https://facebook.com/google"); 1052 1, "http://facebook.com/google", "https://facebook.com/google");
1064 predictor_->RecordURLRedirect(fb3); 1053 predictor_->RecordURLRedirect(fb3);
1065 NavigationID fb_end = CreateNavigationID(1, "https://facebook.com/google"); 1054 NavigationID fb_end = CreateNavigationID(1, "https://facebook.com/google");
1066 1055
1067 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( 1056 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer(predictor_);
1068 predictor_.get());
1069 EXPECT_CALL( 1057 EXPECT_CALL(
1070 mock_observer, 1058 mock_observer,
1071 OnNavigationLearned(kVisitCount, CreatePageRequestSummary( 1059 OnNavigationLearned(kVisitCount, CreatePageRequestSummary(
1072 "https://facebook.com/google", 1060 "https://facebook.com/google",
1073 "http://fb.com/google", 1061 "http://fb.com/google",
1074 std::vector<URLRequestSummary>()))); 1062 std::vector<URLRequestSummary>())));
1075 1063
1076 predictor_->RecordMainFrameLoadComplete(fb_end); 1064 predictor_->RecordMainFrameLoadComplete(fb_end);
1077 profile_->BlockUntilHistoryProcessesPendingRequests(); 1065 profile_->BlockUntilHistoryProcessesPendingRequests();
1078 1066
(...skipping 983 matching lines...) Expand 10 before | Expand all | Expand 10 after
2062 } 2050 }
2063 2051
2064 TEST_F(ResourcePrefetchPredictorTest, 2052 TEST_F(ResourcePrefetchPredictorTest,
2065 TestRedirectStatusRedirectCorrectlyPredicted) { 2053 TestRedirectStatusRedirectCorrectlyPredicted) {
2066 TestRedirectStatusHistogram( 2054 TestRedirectStatusHistogram(
2067 "google.com", "www.google.com", "http://google.com?query=cats", 2055 "google.com", "www.google.com", "http://google.com?query=cats",
2068 "http://www.google.com?query=cats", 2056 "http://www.google.com?query=cats",
2069 ResourcePrefetchPredictor::RedirectStatus::REDIRECT_CORRECTLY_PREDICTED); 2057 ResourcePrefetchPredictor::RedirectStatus::REDIRECT_CORRECTLY_PREDICTED);
2070 } 2058 }
2071 2059
2072 TEST_F(ResourcePrefetchPredictorTest, TestPrefetchingDurationHistogram) {
2073 // Prefetching duration for an url without resources in the database
2074 // shouldn't be recorded.
2075 const std::string main_frame_url = "http://google.com/?query=cats";
2076 predictor_->StartPrefetching(GURL(main_frame_url), HintOrigin::EXTERNAL);
2077 predictor_->StopPrefetching(GURL(main_frame_url));
2078 histogram_tester_->ExpectTotalCount(
2079 internal::kResourcePrefetchPredictorPrefetchingDurationHistogram, 0);
2080
2081 // Fill the database to record a duration.
2082 PrefetchData google = CreatePrefetchData("google.com", 1);
2083 InitializeResourceData(
2084 google.add_resources(), "https://cdn.google.com/script.js",
2085 content::RESOURCE_TYPE_SCRIPT, 10, 0, 1, 2.1, net::MEDIUM, false, false);
2086 predictor_->host_resource_data_->UpdateData(google.primary_key(), google);
2087
2088 predictor_->StartPrefetching(GURL(main_frame_url), HintOrigin::EXTERNAL);
2089 predictor_->StopPrefetching(GURL(main_frame_url));
2090 histogram_tester_->ExpectTotalCount(
2091 internal::kResourcePrefetchPredictorPrefetchingDurationHistogram, 1);
2092 }
2093
2094 TEST_F(ResourcePrefetchPredictorTest, TestRecordFirstContentfulPaint) { 2060 TEST_F(ResourcePrefetchPredictorTest, TestRecordFirstContentfulPaint) {
2095 auto res1_time = base::TimeTicks::FromInternalValue(1); 2061 auto res1_time = base::TimeTicks::FromInternalValue(1);
2096 auto res2_time = base::TimeTicks::FromInternalValue(2); 2062 auto res2_time = base::TimeTicks::FromInternalValue(2);
2097 auto fcp_time = base::TimeTicks::FromInternalValue(3); 2063 auto fcp_time = base::TimeTicks::FromInternalValue(3);
2098 auto res3_time = base::TimeTicks::FromInternalValue(4); 2064 auto res3_time = base::TimeTicks::FromInternalValue(4);
2099 2065
2100 URLRequestSummary main_frame = 2066 URLRequestSummary main_frame =
2101 CreateURLRequestSummary(1, "http://www.google.com"); 2067 CreateURLRequestSummary(1, "http://www.google.com");
2102 predictor_->RecordURLRequest(main_frame); 2068 predictor_->RecordURLRequest(main_frame);
2103 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); 2069 EXPECT_EQ(1U, predictor_->inflight_navigations_.size());
(...skipping 30 matching lines...) Expand all
2134 ResourceData* resource3_rd = host_data.add_resources(); 2100 ResourceData* resource3_rd = host_data.add_resources();
2135 InitializeResourceData(resource3_rd, "http://google.com/script2.js", 2101 InitializeResourceData(resource3_rd, "http://google.com/script2.js",
2136 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, 2102 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0,
2137 net::MEDIUM, false, false); 2103 net::MEDIUM, false, false);
2138 resource3_rd->set_before_first_contentful_paint(false); 2104 resource3_rd->set_before_first_contentful_paint(false);
2139 EXPECT_EQ(mock_tables_->host_resource_table_.data_, 2105 EXPECT_EQ(mock_tables_->host_resource_table_.data_,
2140 PrefetchDataMap({{host_data.primary_key(), host_data}})); 2106 PrefetchDataMap({{host_data.primary_key(), host_data}}));
2141 } 2107 }
2142 2108
2143 } // namespace predictors 2109 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698