| 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 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "chrome/browser/history/history_service_factory.h" | 15 #include "chrome/browser/history/history_service_factory.h" |
| 16 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" | 16 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" |
| 17 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h" |
| 17 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
| 18 #include "components/history/core/browser/history_service.h" | 19 #include "components/history/core/browser/history_service.h" |
| 19 #include "components/history/core/browser/history_types.h" | 20 #include "components/history/core/browser/history_types.h" |
| 20 #include "content/public/browser/resource_request_info.h" | 21 #include "content/public/browser/resource_request_info.h" |
| 21 #include "content/public/test/test_browser_thread.h" | 22 #include "content/public/test/test_browser_thread.h" |
| 22 #include "net/http/http_response_headers.h" | 23 #include "net/http/http_response_headers.h" |
| 23 #include "net/url_request/url_request_context.h" | 24 #include "net/url_request/url_request_context.h" |
| 24 #include "net/url_request/url_request_job.h" | 25 #include "net/url_request/url_request_job.h" |
| 25 #include "net/url_request/url_request_test_util.h" | 26 #include "net/url_request/url_request_test_util.h" |
| 26 #include "net/url_request/url_request_test_util.h" | 27 #include "net/url_request/url_request_test_util.h" |
| 27 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 29 | 30 |
| 30 using testing::ContainerEq; | 31 using testing::ContainerEq; |
| 31 using testing::Pointee; | 32 using testing::Pointee; |
| 32 using testing::SetArgPointee; | 33 using testing::SetArgPointee; |
| 33 using testing::StrictMock; | 34 using testing::StrictMock; |
| 34 | 35 |
| 35 namespace predictors { | 36 namespace predictors { |
| 36 | 37 |
| 37 typedef ResourcePrefetchPredictor::URLRequestSummary URLRequestSummary; | 38 typedef ResourcePrefetchPredictor::URLRequestSummary URLRequestSummary; |
| 38 typedef ResourcePrefetchPredictorTables::ResourceRow ResourceRow; | |
| 39 typedef std::vector<ResourceRow> ResourceRows; | |
| 40 typedef ResourcePrefetchPredictorTables::PrefetchData PrefetchData; | 39 typedef ResourcePrefetchPredictorTables::PrefetchData PrefetchData; |
| 41 typedef ResourcePrefetchPredictorTables::PrefetchDataMap PrefetchDataMap; | 40 typedef ResourcePrefetchPredictorTables::PrefetchDataMap PrefetchDataMap; |
| 42 | 41 |
| 43 // For printing failures nicely. | |
| 44 void PrintTo(const ResourceRow& row, ::std::ostream* os) { | |
| 45 *os << "[" | |
| 46 << "," << row.resource_url << "," << row.resource_type << "," | |
| 47 << row.number_of_hits << "," << row.number_of_misses << "," | |
| 48 << row.consecutive_misses << "," << row.average_position << "," | |
| 49 << row.score << "]"; | |
| 50 } | |
| 51 | |
| 52 void PrintTo(const PrefetchData& data, ::std::ostream* os) { | |
| 53 *os << "[" << data.key_type << "," << data.primary_key | |
| 54 << "," << data.last_visit.ToInternalValue() << "]\n"; | |
| 55 for (ResourceRows::const_iterator it = data.resources.begin(); | |
| 56 it != data.resources.end(); ++it) { | |
| 57 *os << "\t\t"; | |
| 58 PrintTo(*it, os); | |
| 59 *os << "\n"; | |
| 60 } | |
| 61 } | |
| 62 | |
| 63 scoped_refptr<net::HttpResponseHeaders> MakeResponseHeaders( | 42 scoped_refptr<net::HttpResponseHeaders> MakeResponseHeaders( |
| 64 const char* headers) { | 43 const char* headers) { |
| 65 return make_scoped_refptr(new net::HttpResponseHeaders( | 44 return make_scoped_refptr(new net::HttpResponseHeaders( |
| 66 net::HttpUtil::AssembleRawHeaders(headers, strlen(headers)))); | 45 net::HttpUtil::AssembleRawHeaders(headers, strlen(headers)))); |
| 67 } | 46 } |
| 68 | 47 |
| 69 class EmptyURLRequestDelegate : public net::URLRequest::Delegate { | 48 class EmptyURLRequestDelegate : public net::URLRequest::Delegate { |
| 70 void OnResponseStarted(net::URLRequest* request) override {} | 49 void OnResponseStarted(net::URLRequest* request) override {} |
| 71 void OnReadCompleted(net::URLRequest* request, int bytes_read) override {} | 50 void OnReadCompleted(net::URLRequest* request, int bytes_read) override {} |
| 72 }; | 51 }; |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 | 299 |
| 321 void ResourcePrefetchPredictorTest::TearDown() { | 300 void ResourcePrefetchPredictorTest::TearDown() { |
| 322 predictor_.reset(NULL); | 301 predictor_.reset(NULL); |
| 323 profile_->DestroyHistoryService(); | 302 profile_->DestroyHistoryService(); |
| 324 } | 303 } |
| 325 | 304 |
| 326 void ResourcePrefetchPredictorTest::InitializeSampleData() { | 305 void ResourcePrefetchPredictorTest::InitializeSampleData() { |
| 327 { // Url data. | 306 { // Url data. |
| 328 PrefetchData google(PREFETCH_KEY_TYPE_URL, "http://www.google.com/"); | 307 PrefetchData google(PREFETCH_KEY_TYPE_URL, "http://www.google.com/"); |
| 329 google.last_visit = base::Time::FromInternalValue(1); | 308 google.last_visit = base::Time::FromInternalValue(1); |
| 330 google.resources.push_back(ResourceRow( | 309 google.resources.push_back(CreateResourceData( |
| 331 "http://google.com/style1.css", content::RESOURCE_TYPE_STYLESHEET, 3, 2, | 310 "http://google.com/style1.css", content::RESOURCE_TYPE_STYLESHEET, 3, 2, |
| 332 1, 1.0, net::MEDIUM, false, false)); | 311 1, 1.0, net::MEDIUM, false, false)); |
| 333 google.resources.push_back(ResourceRow("http://google.com/script3.js", | 312 google.resources.push_back(CreateResourceData( |
| 334 content::RESOURCE_TYPE_SCRIPT, 4, 0, | 313 "http://google.com/script3.js", content::RESOURCE_TYPE_SCRIPT, 4, 0, 1, |
| 335 1, 2.1, net::MEDIUM, false, false)); | 314 2.1, net::MEDIUM, false, false)); |
| 336 google.resources.push_back(ResourceRow("http://google.com/script4.js", | 315 google.resources.push_back(CreateResourceData( |
| 337 content::RESOURCE_TYPE_SCRIPT, 11, 0, | 316 "http://google.com/script4.js", content::RESOURCE_TYPE_SCRIPT, 11, 0, 0, |
| 338 0, 2.1, net::MEDIUM, false, false)); | 317 2.1, net::MEDIUM, false, false)); |
| 339 google.resources.push_back(ResourceRow("http://google.com/image1.png", | 318 google.resources.push_back(CreateResourceData( |
| 340 content::RESOURCE_TYPE_IMAGE, 6, 3, | 319 "http://google.com/image1.png", content::RESOURCE_TYPE_IMAGE, 6, 3, 0, |
| 341 0, 2.2, net::MEDIUM, false, false)); | 320 2.2, net::MEDIUM, false, false)); |
| 342 google.resources.push_back(ResourceRow( | 321 google.resources.push_back(CreateResourceData( |
| 343 "http://google.com/a.font", content::RESOURCE_TYPE_LAST_TYPE, 2, 0, 0, | 322 "http://google.com/a.font", content::RESOURCE_TYPE_LAST_TYPE, 2, 0, 0, |
| 344 5.1, net::MEDIUM, false, false)); | 323 5.1, net::MEDIUM, false, false)); |
| 345 | 324 |
| 346 PrefetchData reddit(PREFETCH_KEY_TYPE_URL, "http://www.reddit.com/"); | 325 PrefetchData reddit(PREFETCH_KEY_TYPE_URL, "http://www.reddit.com/"); |
| 347 reddit.last_visit = base::Time::FromInternalValue(2); | 326 reddit.last_visit = base::Time::FromInternalValue(2); |
| 348 reddit.resources.push_back(ResourceRow( | 327 reddit.resources.push_back(CreateResourceData( |
| 349 "http://reddit-resource.com/script1.js", content::RESOURCE_TYPE_SCRIPT, | 328 "http://reddit-resource.com/script1.js", content::RESOURCE_TYPE_SCRIPT, |
| 350 4, 0, 1, 1.0, net::MEDIUM, false, false)); | 329 4, 0, 1, 1.0, net::MEDIUM, false, false)); |
| 351 reddit.resources.push_back(ResourceRow( | 330 reddit.resources.push_back(CreateResourceData( |
| 352 "http://reddit-resource.com/script2.js", content::RESOURCE_TYPE_SCRIPT, | 331 "http://reddit-resource.com/script2.js", content::RESOURCE_TYPE_SCRIPT, |
| 353 2, 0, 0, 2.1, net::MEDIUM, false, false)); | 332 2, 0, 0, 2.1, net::MEDIUM, false, false)); |
| 354 | 333 |
| 355 PrefetchData yahoo(PREFETCH_KEY_TYPE_URL, "http://www.yahoo.com/"); | 334 PrefetchData yahoo(PREFETCH_KEY_TYPE_URL, "http://www.yahoo.com/"); |
| 356 yahoo.last_visit = base::Time::FromInternalValue(3); | 335 yahoo.last_visit = base::Time::FromInternalValue(3); |
| 357 yahoo.resources.push_back(ResourceRow("http://google.com/image.png", | 336 yahoo.resources.push_back(CreateResourceData( |
| 358 content::RESOURCE_TYPE_IMAGE, 20, 1, | 337 "http://google.com/image.png", content::RESOURCE_TYPE_IMAGE, 20, 1, 0, |
| 359 0, 10.0, net::MEDIUM, false, false)); | 338 10.0, net::MEDIUM, false, false)); |
| 360 | 339 |
| 361 test_url_data_.clear(); | 340 test_url_data_.clear(); |
| 362 test_url_data_.insert(std::make_pair("http://www.google.com/", google)); | 341 test_url_data_.insert(std::make_pair("http://www.google.com/", google)); |
| 363 test_url_data_.insert(std::make_pair("http://www.reddit.com/", reddit)); | 342 test_url_data_.insert(std::make_pair("http://www.reddit.com/", reddit)); |
| 364 test_url_data_.insert(std::make_pair("http://www.yahoo.com/", yahoo)); | 343 test_url_data_.insert(std::make_pair("http://www.yahoo.com/", yahoo)); |
| 365 } | 344 } |
| 366 | 345 |
| 367 { // Host data. | 346 { // Host data. |
| 368 PrefetchData facebook(PREFETCH_KEY_TYPE_HOST, "www.facebook.com"); | 347 PrefetchData facebook(PREFETCH_KEY_TYPE_HOST, "www.facebook.com"); |
| 369 facebook.last_visit = base::Time::FromInternalValue(4); | 348 facebook.last_visit = base::Time::FromInternalValue(4); |
| 370 facebook.resources.push_back(ResourceRow( | 349 facebook.resources.push_back(CreateResourceData( |
| 371 "http://www.facebook.com/style.css", content::RESOURCE_TYPE_STYLESHEET, | 350 "http://www.facebook.com/style.css", content::RESOURCE_TYPE_STYLESHEET, |
| 372 5, 2, 1, 1.1, net::MEDIUM, false, false)); | 351 5, 2, 1, 1.1, net::MEDIUM, false, false)); |
| 373 facebook.resources.push_back(ResourceRow( | 352 facebook.resources.push_back(CreateResourceData( |
| 374 "http://www.facebook.com/script.js", content::RESOURCE_TYPE_SCRIPT, 4, | 353 "http://www.facebook.com/script.js", content::RESOURCE_TYPE_SCRIPT, 4, |
| 375 0, 1, 2.1, net::MEDIUM, false, false)); | 354 0, 1, 2.1, net::MEDIUM, false, false)); |
| 376 facebook.resources.push_back(ResourceRow( | 355 facebook.resources.push_back(CreateResourceData( |
| 377 "http://www.facebook.com/image.png", content::RESOURCE_TYPE_IMAGE, 6, 3, | 356 "http://www.facebook.com/image.png", content::RESOURCE_TYPE_IMAGE, 6, 3, |
| 378 0, 2.2, net::MEDIUM, false, false)); | 357 0, 2.2, net::MEDIUM, false, false)); |
| 379 facebook.resources.push_back(ResourceRow( | 358 facebook.resources.push_back(CreateResourceData( |
| 380 "http://www.facebook.com/a.font", content::RESOURCE_TYPE_LAST_TYPE, 2, | 359 "http://www.facebook.com/a.font", content::RESOURCE_TYPE_LAST_TYPE, 2, |
| 381 0, 0, 5.1, net::MEDIUM, false, false)); | 360 0, 0, 5.1, net::MEDIUM, false, false)); |
| 382 facebook.resources.push_back( | 361 facebook.resources.push_back( |
| 383 ResourceRow("http://www.resources.facebook.com/script.js", | 362 CreateResourceData("http://www.resources.facebook.com/script.js", |
| 384 content::RESOURCE_TYPE_SCRIPT, 11, 0, 0, 8.5, net::MEDIUM, | 363 content::RESOURCE_TYPE_SCRIPT, 11, 0, 0, 8.5, |
| 385 false, false)); | 364 net::MEDIUM, false, false)); |
| 386 | 365 |
| 387 PrefetchData yahoo(PREFETCH_KEY_TYPE_HOST, "www.yahoo.com"); | 366 PrefetchData yahoo(PREFETCH_KEY_TYPE_HOST, "www.yahoo.com"); |
| 388 yahoo.last_visit = base::Time::FromInternalValue(5); | 367 yahoo.last_visit = base::Time::FromInternalValue(5); |
| 389 yahoo.resources.push_back(ResourceRow("http://google.com/image.png", | 368 yahoo.resources.push_back(CreateResourceData( |
| 390 content::RESOURCE_TYPE_IMAGE, 20, 1, | 369 "http://google.com/image.png", content::RESOURCE_TYPE_IMAGE, 20, 1, 0, |
| 391 0, 10.0, net::MEDIUM, false, false)); | 370 10.0, net::MEDIUM, false, false)); |
| 392 | 371 |
| 393 test_host_data_.clear(); | 372 test_host_data_.clear(); |
| 394 test_host_data_.insert(std::make_pair("www.facebook.com", facebook)); | 373 test_host_data_.insert(std::make_pair("www.facebook.com", facebook)); |
| 395 test_host_data_.insert(std::make_pair("www.yahoo.com", yahoo)); | 374 test_host_data_.insert(std::make_pair("www.yahoo.com", yahoo)); |
| 396 } | 375 } |
| 397 } | 376 } |
| 398 | 377 |
| 399 TEST_F(ResourcePrefetchPredictorTest, LazilyInitializeEmpty) { | 378 TEST_F(ResourcePrefetchPredictorTest, LazilyInitializeEmpty) { |
| 400 // Tests that the predictor initializes correctly without any data. | 379 // Tests that the predictor initializes correctly without any data. |
| 401 EXPECT_TRUE(predictor_->url_table_cache_->empty()); | 380 EXPECT_TRUE(predictor_->url_table_cache_->empty()); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 URLRequestSummary resource2 = CreateURLRequestSummary( | 422 URLRequestSummary resource2 = CreateURLRequestSummary( |
| 444 1, 1, "http://www.google.com", "http://google.com/script1.js", | 423 1, 1, "http://www.google.com", "http://google.com/script1.js", |
| 445 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); | 424 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); |
| 446 predictor_->RecordURLResponse(resource2); | 425 predictor_->RecordURLResponse(resource2); |
| 447 URLRequestSummary resource3 = CreateURLRequestSummary( | 426 URLRequestSummary resource3 = CreateURLRequestSummary( |
| 448 1, 1, "http://www.google.com", "http://google.com/script2.js", | 427 1, 1, "http://www.google.com", "http://google.com/script2.js", |
| 449 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); | 428 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); |
| 450 predictor_->RecordURLResponse(resource3); | 429 predictor_->RecordURLResponse(resource3); |
| 451 | 430 |
| 452 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com"); | 431 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com"); |
| 453 host_data.resources.push_back(ResourceRow( | 432 host_data.resources.push_back(CreateResourceData( |
| 454 "http://google.com/style1.css", content::RESOURCE_TYPE_STYLESHEET, 1, 0, | 433 "http://google.com/style1.css", content::RESOURCE_TYPE_STYLESHEET, 1, 0, |
| 455 0, 1.0, net::MEDIUM, false, false)); | 434 0, 1.0, net::MEDIUM, false, false)); |
| 456 host_data.resources.push_back(ResourceRow("http://google.com/script1.js", | 435 host_data.resources.push_back(CreateResourceData( |
| 457 content::RESOURCE_TYPE_SCRIPT, 1, 0, | 436 "http://google.com/script1.js", content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, |
| 458 0, 2.0, net::MEDIUM, false, false)); | 437 2.0, net::MEDIUM, false, false)); |
| 459 host_data.resources.push_back(ResourceRow("http://google.com/script2.js", | 438 host_data.resources.push_back(CreateResourceData( |
| 460 content::RESOURCE_TYPE_SCRIPT, 1, 0, | 439 "http://google.com/script2.js", content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, |
| 461 0, 3.0, net::MEDIUM, false, false)); | 440 3.0, net::MEDIUM, false, false)); |
| 462 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); | 441 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); |
| 463 | 442 |
| 464 predictor_->OnNavigationComplete(main_frame.navigation_id); | 443 predictor_->OnNavigationComplete(main_frame.navigation_id); |
| 465 profile_->BlockUntilHistoryProcessesPendingRequests(); | 444 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 466 } | 445 } |
| 467 | 446 |
| 468 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDB) { | 447 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDB) { |
| 469 // Single navigation that will be recorded. Will check for duplicate | 448 // Single navigation that will be recorded. Will check for duplicate |
| 470 // resources and also for number of resources saved. | 449 // resources and also for number of resources saved. |
| 471 AddUrlToHistory("http://www.google.com", 4); | 450 AddUrlToHistory("http://www.google.com", 4); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 499 URLRequestSummary resource6 = CreateURLRequestSummary( | 478 URLRequestSummary resource6 = CreateURLRequestSummary( |
| 500 1, 1, "http://www.google.com", "http://google.com/image2.png", | 479 1, 1, "http://www.google.com", "http://google.com/image2.png", |
| 501 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false); | 480 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false); |
| 502 predictor_->RecordURLResponse(resource6); | 481 predictor_->RecordURLResponse(resource6); |
| 503 URLRequestSummary resource7 = CreateURLRequestSummary( | 482 URLRequestSummary resource7 = CreateURLRequestSummary( |
| 504 1, 1, "http://www.google.com", "http://google.com/style2.css", | 483 1, 1, "http://www.google.com", "http://google.com/style2.css", |
| 505 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true); | 484 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true); |
| 506 predictor_->RecordURLResponse(resource7); | 485 predictor_->RecordURLResponse(resource7); |
| 507 | 486 |
| 508 PrefetchData url_data(PREFETCH_KEY_TYPE_URL, "http://www.google.com/"); | 487 PrefetchData url_data(PREFETCH_KEY_TYPE_URL, "http://www.google.com/"); |
| 509 url_data.resources.push_back(ResourceRow( | 488 url_data.resources.push_back(CreateResourceData( |
| 510 "http://google.com/style1.css", content::RESOURCE_TYPE_STYLESHEET, 1, 0, | 489 "http://google.com/style1.css", content::RESOURCE_TYPE_STYLESHEET, 1, 0, |
| 511 0, 1.0, net::MEDIUM, false, false)); | 490 0, 1.0, net::MEDIUM, false, false)); |
| 512 url_data.resources.push_back(ResourceRow("http://google.com/script1.js", | 491 url_data.resources.push_back(CreateResourceData( |
| 513 content::RESOURCE_TYPE_SCRIPT, 1, 0, | 492 "http://google.com/script1.js", content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, |
| 514 0, 2.0, net::MEDIUM, false, false)); | 493 2.0, net::MEDIUM, false, false)); |
| 515 url_data.resources.push_back(ResourceRow("http://google.com/script2.js", | 494 url_data.resources.push_back(CreateResourceData( |
| 516 content::RESOURCE_TYPE_SCRIPT, 1, 0, | 495 "http://google.com/script2.js", content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, |
| 517 0, 3.0, net::MEDIUM, false, false)); | 496 3.0, net::MEDIUM, false, false)); |
| 518 url_data.resources.push_back(ResourceRow( | 497 url_data.resources.push_back(CreateResourceData( |
| 519 "http://google.com/style2.css", content::RESOURCE_TYPE_STYLESHEET, 1, 0, | 498 "http://google.com/style2.css", content::RESOURCE_TYPE_STYLESHEET, 1, 0, |
| 520 0, 7.0, net::MEDIUM, false, false)); | 499 0, 7.0, net::MEDIUM, false, false)); |
| 521 EXPECT_CALL(*mock_tables_.get(), UpdateData(url_data, empty_host_data_)); | 500 EXPECT_CALL(*mock_tables_.get(), UpdateData(url_data, empty_host_data_)); |
| 522 | 501 |
| 523 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com"); | 502 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com"); |
| 524 host_data.resources = url_data.resources; | 503 host_data.resources = url_data.resources; |
| 525 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); | 504 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); |
| 526 | 505 |
| 527 predictor_->OnNavigationComplete(main_frame.navigation_id); | 506 predictor_->OnNavigationComplete(main_frame.navigation_id); |
| 528 profile_->BlockUntilHistoryProcessesPendingRequests(); | 507 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 URLRequestSummary resource6 = CreateURLRequestSummary( | 551 URLRequestSummary resource6 = CreateURLRequestSummary( |
| 573 1, 1, "http://www.google.com", "http://google.com/image2.png", | 552 1, 1, "http://www.google.com", "http://google.com/image2.png", |
| 574 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false); | 553 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false); |
| 575 predictor_->RecordURLResponse(resource6); | 554 predictor_->RecordURLResponse(resource6); |
| 576 URLRequestSummary resource7 = CreateURLRequestSummary( | 555 URLRequestSummary resource7 = CreateURLRequestSummary( |
| 577 1, 1, "http://www.google.com", "http://google.com/style2.css", | 556 1, 1, "http://www.google.com", "http://google.com/style2.css", |
| 578 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true); | 557 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true); |
| 579 predictor_->RecordURLResponse(resource7); | 558 predictor_->RecordURLResponse(resource7); |
| 580 | 559 |
| 581 PrefetchData url_data(PREFETCH_KEY_TYPE_URL, "http://www.google.com/"); | 560 PrefetchData url_data(PREFETCH_KEY_TYPE_URL, "http://www.google.com/"); |
| 582 url_data.resources.push_back(ResourceRow( | 561 url_data.resources.push_back(CreateResourceData( |
| 583 "http://google.com/style1.css", content::RESOURCE_TYPE_STYLESHEET, 4, 2, | 562 "http://google.com/style1.css", content::RESOURCE_TYPE_STYLESHEET, 4, 2, |
| 584 0, 1.0, net::MEDIUM, false, false)); | 563 0, 1.0, net::MEDIUM, false, false)); |
| 585 url_data.resources.push_back(ResourceRow("http://google.com/script1.js", | 564 url_data.resources.push_back(CreateResourceData( |
| 586 content::RESOURCE_TYPE_SCRIPT, 1, 0, | 565 "http://google.com/script1.js", content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, |
| 587 0, 2.0, net::MEDIUM, false, false)); | 566 2.0, net::MEDIUM, false, false)); |
| 588 url_data.resources.push_back(ResourceRow("http://google.com/script4.js", | 567 url_data.resources.push_back(CreateResourceData( |
| 589 content::RESOURCE_TYPE_SCRIPT, 11, 1, | 568 "http://google.com/script4.js", content::RESOURCE_TYPE_SCRIPT, 11, 1, 1, |
| 590 1, 2.1, net::MEDIUM, false, false)); | 569 2.1, net::MEDIUM, false, false)); |
| 591 url_data.resources.push_back(ResourceRow("http://google.com/script2.js", | 570 url_data.resources.push_back(CreateResourceData( |
| 592 content::RESOURCE_TYPE_SCRIPT, 1, 0, | 571 "http://google.com/script2.js", content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, |
| 593 0, 3.0, net::MEDIUM, false, false)); | 572 3.0, net::MEDIUM, false, false)); |
| 594 EXPECT_CALL(*mock_tables_.get(), UpdateData(url_data, empty_host_data_)); | 573 EXPECT_CALL(*mock_tables_.get(), UpdateData(url_data, empty_host_data_)); |
| 595 | 574 |
| 596 EXPECT_CALL( | 575 EXPECT_CALL( |
| 597 *mock_tables_.get(), | 576 *mock_tables_.get(), |
| 598 DeleteSingleDataPoint("www.facebook.com", PREFETCH_KEY_TYPE_HOST)); | 577 DeleteSingleDataPoint("www.facebook.com", PREFETCH_KEY_TYPE_HOST)); |
| 599 | 578 |
| 600 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com"); | 579 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com"); |
| 601 host_data.resources.push_back(ResourceRow( | 580 host_data.resources.push_back(CreateResourceData( |
| 602 "http://google.com/style1.css", content::RESOURCE_TYPE_STYLESHEET, 1, 0, | 581 "http://google.com/style1.css", content::RESOURCE_TYPE_STYLESHEET, 1, 0, |
| 603 0, 1.0, net::MEDIUM, false, false)); | 582 0, 1.0, net::MEDIUM, false, false)); |
| 604 host_data.resources.push_back(ResourceRow("http://google.com/script1.js", | 583 host_data.resources.push_back(CreateResourceData( |
| 605 content::RESOURCE_TYPE_SCRIPT, 1, 0, | 584 "http://google.com/script1.js", content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, |
| 606 0, 2.0, net::MEDIUM, false, false)); | 585 2.0, net::MEDIUM, false, false)); |
| 607 host_data.resources.push_back(ResourceRow("http://google.com/script2.js", | 586 host_data.resources.push_back(CreateResourceData( |
| 608 content::RESOURCE_TYPE_SCRIPT, 1, 0, | 587 "http://google.com/script2.js", content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, |
| 609 0, 3.0, net::MEDIUM, false, false)); | 588 3.0, net::MEDIUM, false, false)); |
| 610 host_data.resources.push_back(ResourceRow( | 589 host_data.resources.push_back(CreateResourceData( |
| 611 "http://google.com/style2.css", content::RESOURCE_TYPE_STYLESHEET, 1, 0, | 590 "http://google.com/style2.css", content::RESOURCE_TYPE_STYLESHEET, 1, 0, |
| 612 0, 7.0, net::MEDIUM, false, false)); | 591 0, 7.0, net::MEDIUM, false, false)); |
| 613 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); | 592 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); |
| 614 | 593 |
| 615 predictor_->OnNavigationComplete(main_frame.navigation_id); | 594 predictor_->OnNavigationComplete(main_frame.navigation_id); |
| 616 profile_->BlockUntilHistoryProcessesPendingRequests(); | 595 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 617 } | 596 } |
| 618 | 597 |
| 619 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDBAndDBFull) { | 598 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDBAndDBFull) { |
| 620 // Tests that a URL is deleted before another is added if the cache is full. | 599 // Tests that a URL is deleted before another is added if the cache is full. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 646 predictor_->RecordURLResponse(resource2); | 625 predictor_->RecordURLResponse(resource2); |
| 647 | 626 |
| 648 EXPECT_CALL( | 627 EXPECT_CALL( |
| 649 *mock_tables_.get(), | 628 *mock_tables_.get(), |
| 650 DeleteSingleDataPoint("http://www.google.com/", PREFETCH_KEY_TYPE_URL)); | 629 DeleteSingleDataPoint("http://www.google.com/", PREFETCH_KEY_TYPE_URL)); |
| 651 EXPECT_CALL( | 630 EXPECT_CALL( |
| 652 *mock_tables_.get(), | 631 *mock_tables_.get(), |
| 653 DeleteSingleDataPoint("www.facebook.com", PREFETCH_KEY_TYPE_HOST)); | 632 DeleteSingleDataPoint("www.facebook.com", PREFETCH_KEY_TYPE_HOST)); |
| 654 | 633 |
| 655 PrefetchData url_data(PREFETCH_KEY_TYPE_URL, "http://www.nike.com/"); | 634 PrefetchData url_data(PREFETCH_KEY_TYPE_URL, "http://www.nike.com/"); |
| 656 url_data.resources.push_back(ResourceRow( | 635 url_data.resources.push_back(CreateResourceData( |
| 657 "http://nike.com/style1.css", content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, | 636 "http://nike.com/style1.css", content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, |
| 658 1.0, net::MEDIUM, false, false)); | 637 1.0, net::MEDIUM, false, false)); |
| 659 url_data.resources.push_back(ResourceRow("http://nike.com/image2.png", | 638 url_data.resources.push_back(CreateResourceData( |
| 660 content::RESOURCE_TYPE_IMAGE, 1, 0, | 639 "http://nike.com/image2.png", content::RESOURCE_TYPE_IMAGE, 1, 0, 0, 2.0, |
| 661 0, 2.0, net::MEDIUM, false, false)); | 640 net::MEDIUM, false, false)); |
| 662 EXPECT_CALL(*mock_tables_.get(), UpdateData(url_data, empty_host_data_)); | 641 EXPECT_CALL(*mock_tables_.get(), UpdateData(url_data, empty_host_data_)); |
| 663 | 642 |
| 664 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.nike.com"); | 643 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.nike.com"); |
| 665 host_data.resources = url_data.resources; | 644 host_data.resources = url_data.resources; |
| 666 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); | 645 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); |
| 667 | 646 |
| 668 predictor_->OnNavigationComplete(main_frame.navigation_id); | 647 predictor_->OnNavigationComplete(main_frame.navigation_id); |
| 669 profile_->BlockUntilHistoryProcessesPendingRequests(); | 648 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 670 } | 649 } |
| 671 | 650 |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1064 url_request_job_factory_.set_response_info(response_info); | 1043 url_request_job_factory_.set_response_info(response_info); |
| 1065 std::unique_ptr<net::URLRequest> request_etag = | 1044 std::unique_ptr<net::URLRequest> request_etag = |
| 1066 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, | 1045 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, |
| 1067 content::RESOURCE_TYPE_PREFETCH, 1, 1, true); | 1046 content::RESOURCE_TYPE_PREFETCH, 1, 1, true); |
| 1068 EXPECT_TRUE(URLRequestSummary::SummarizeResponse(*request_etag, &summary)); | 1047 EXPECT_TRUE(URLRequestSummary::SummarizeResponse(*request_etag, &summary)); |
| 1069 EXPECT_TRUE(summary.has_validators); | 1048 EXPECT_TRUE(summary.has_validators); |
| 1070 EXPECT_TRUE(summary.always_revalidate); | 1049 EXPECT_TRUE(summary.always_revalidate); |
| 1071 } | 1050 } |
| 1072 | 1051 |
| 1073 } // namespace predictors | 1052 } // namespace predictors |
| OLD | NEW |