| 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" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 namespace predictors { | 35 namespace predictors { |
| 36 | 36 |
| 37 typedef ResourcePrefetchPredictor::URLRequestSummary URLRequestSummary; | 37 typedef ResourcePrefetchPredictor::URLRequestSummary URLRequestSummary; |
| 38 typedef ResourcePrefetchPredictorTables::ResourceRow ResourceRow; | 38 typedef ResourcePrefetchPredictorTables::ResourceRow ResourceRow; |
| 39 typedef std::vector<ResourceRow> ResourceRows; | 39 typedef std::vector<ResourceRow> ResourceRows; |
| 40 typedef ResourcePrefetchPredictorTables::PrefetchData PrefetchData; | 40 typedef ResourcePrefetchPredictorTables::PrefetchData PrefetchData; |
| 41 typedef ResourcePrefetchPredictorTables::PrefetchDataMap PrefetchDataMap; | 41 typedef ResourcePrefetchPredictorTables::PrefetchDataMap PrefetchDataMap; |
| 42 | 42 |
| 43 // For printing failures nicely. | 43 // For printing failures nicely. |
| 44 void PrintTo(const ResourceRow& row, ::std::ostream* os) { | 44 void PrintTo(const ResourceRow& row, ::std::ostream* os) { |
| 45 *os << "[" << row.primary_key << "," << row.resource_url | 45 *os << "[" |
| 46 << "," << row.resource_type << "," << row.number_of_hits | 46 << "," << row.resource_url << "," << row.resource_type << "," |
| 47 << "," << row.number_of_misses << "," << row.consecutive_misses | 47 << row.number_of_hits << "," << row.number_of_misses << "," |
| 48 << "," << row.average_position << "," << row.score << "]"; | 48 << row.consecutive_misses << "," << row.average_position << "," |
| 49 << row.score << "]"; |
| 49 } | 50 } |
| 50 | 51 |
| 51 void PrintTo(const PrefetchData& data, ::std::ostream* os) { | 52 void PrintTo(const PrefetchData& data, ::std::ostream* os) { |
| 52 *os << "[" << data.key_type << "," << data.primary_key | 53 *os << "[" << data.key_type << "," << data.primary_key |
| 53 << "," << data.last_visit.ToInternalValue() << "]\n"; | 54 << "," << data.last_visit.ToInternalValue() << "]\n"; |
| 54 for (ResourceRows::const_iterator it = data.resources.begin(); | 55 for (ResourceRows::const_iterator it = data.resources.begin(); |
| 55 it != data.resources.end(); ++it) { | 56 it != data.resources.end(); ++it) { |
| 56 *os << "\t\t"; | 57 *os << "\t\t"; |
| 57 PrintTo(*it, os); | 58 PrintTo(*it, os); |
| 58 *os << "\n"; | 59 *os << "\n"; |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 | 320 |
| 320 void ResourcePrefetchPredictorTest::TearDown() { | 321 void ResourcePrefetchPredictorTest::TearDown() { |
| 321 predictor_.reset(NULL); | 322 predictor_.reset(NULL); |
| 322 profile_->DestroyHistoryService(); | 323 profile_->DestroyHistoryService(); |
| 323 } | 324 } |
| 324 | 325 |
| 325 void ResourcePrefetchPredictorTest::InitializeSampleData() { | 326 void ResourcePrefetchPredictorTest::InitializeSampleData() { |
| 326 { // Url data. | 327 { // Url data. |
| 327 PrefetchData google(PREFETCH_KEY_TYPE_URL, "http://www.google.com/"); | 328 PrefetchData google(PREFETCH_KEY_TYPE_URL, "http://www.google.com/"); |
| 328 google.last_visit = base::Time::FromInternalValue(1); | 329 google.last_visit = base::Time::FromInternalValue(1); |
| 329 google.resources.push_back( | 330 google.resources.push_back(ResourceRow( |
| 330 ResourceRow(std::string(), "http://google.com/style1.css", | 331 "http://google.com/style1.css", content::RESOURCE_TYPE_STYLESHEET, 3, 2, |
| 331 content::RESOURCE_TYPE_STYLESHEET, 3, 2, 1, 1.0, | 332 1, 1.0, net::MEDIUM, false, false)); |
| 332 net::MEDIUM, false, false)); | 333 google.resources.push_back(ResourceRow("http://google.com/script3.js", |
| 333 google.resources.push_back(ResourceRow(std::string(), | |
| 334 "http://google.com/script3.js", | |
| 335 content::RESOURCE_TYPE_SCRIPT, 4, 0, | 334 content::RESOURCE_TYPE_SCRIPT, 4, 0, |
| 336 1, 2.1, net::MEDIUM, false, false)); | 335 1, 2.1, net::MEDIUM, false, false)); |
| 337 google.resources.push_back(ResourceRow(std::string(), | 336 google.resources.push_back(ResourceRow("http://google.com/script4.js", |
| 338 "http://google.com/script4.js", | |
| 339 content::RESOURCE_TYPE_SCRIPT, 11, 0, | 337 content::RESOURCE_TYPE_SCRIPT, 11, 0, |
| 340 0, 2.1, net::MEDIUM, false, false)); | 338 0, 2.1, net::MEDIUM, false, false)); |
| 339 google.resources.push_back(ResourceRow("http://google.com/image1.png", |
| 340 content::RESOURCE_TYPE_IMAGE, 6, 3, |
| 341 0, 2.2, net::MEDIUM, false, false)); |
| 341 google.resources.push_back(ResourceRow( | 342 google.resources.push_back(ResourceRow( |
| 342 std::string(), "http://google.com/image1.png", | 343 "http://google.com/a.font", content::RESOURCE_TYPE_LAST_TYPE, 2, 0, 0, |
| 343 content::RESOURCE_TYPE_IMAGE, 6, 3, 0, 2.2, net::MEDIUM, false, false)); | 344 5.1, net::MEDIUM, false, false)); |
| 344 google.resources.push_back( | |
| 345 ResourceRow(std::string(), "http://google.com/a.font", | |
| 346 content::RESOURCE_TYPE_LAST_TYPE, 2, 0, 0, 5.1, net::MEDIUM, | |
| 347 false, false)); | |
| 348 | 345 |
| 349 PrefetchData reddit(PREFETCH_KEY_TYPE_URL, "http://www.reddit.com/"); | 346 PrefetchData reddit(PREFETCH_KEY_TYPE_URL, "http://www.reddit.com/"); |
| 350 reddit.last_visit = base::Time::FromInternalValue(2); | 347 reddit.last_visit = base::Time::FromInternalValue(2); |
| 351 reddit.resources.push_back( | 348 reddit.resources.push_back(ResourceRow( |
| 352 ResourceRow(std::string(), "http://reddit-resource.com/script1.js", | 349 "http://reddit-resource.com/script1.js", content::RESOURCE_TYPE_SCRIPT, |
| 353 content::RESOURCE_TYPE_SCRIPT, 4, 0, 1, 1.0, net::MEDIUM, | 350 4, 0, 1, 1.0, net::MEDIUM, false, false)); |
| 354 false, false)); | 351 reddit.resources.push_back(ResourceRow( |
| 355 reddit.resources.push_back( | 352 "http://reddit-resource.com/script2.js", content::RESOURCE_TYPE_SCRIPT, |
| 356 ResourceRow(std::string(), "http://reddit-resource.com/script2.js", | 353 2, 0, 0, 2.1, net::MEDIUM, false, false)); |
| 357 content::RESOURCE_TYPE_SCRIPT, 2, 0, 0, 2.1, net::MEDIUM, | |
| 358 false, false)); | |
| 359 | 354 |
| 360 PrefetchData yahoo(PREFETCH_KEY_TYPE_URL, "http://www.yahoo.com/"); | 355 PrefetchData yahoo(PREFETCH_KEY_TYPE_URL, "http://www.yahoo.com/"); |
| 361 yahoo.last_visit = base::Time::FromInternalValue(3); | 356 yahoo.last_visit = base::Time::FromInternalValue(3); |
| 362 yahoo.resources.push_back(ResourceRow(std::string(), | 357 yahoo.resources.push_back(ResourceRow("http://google.com/image.png", |
| 363 "http://google.com/image.png", | |
| 364 content::RESOURCE_TYPE_IMAGE, 20, 1, | 358 content::RESOURCE_TYPE_IMAGE, 20, 1, |
| 365 0, 10.0, net::MEDIUM, false, false)); | 359 0, 10.0, net::MEDIUM, false, false)); |
| 366 | 360 |
| 367 test_url_data_.clear(); | 361 test_url_data_.clear(); |
| 368 test_url_data_.insert(std::make_pair("http://www.google.com/", google)); | 362 test_url_data_.insert(std::make_pair("http://www.google.com/", google)); |
| 369 test_url_data_.insert(std::make_pair("http://www.reddit.com/", reddit)); | 363 test_url_data_.insert(std::make_pair("http://www.reddit.com/", reddit)); |
| 370 test_url_data_.insert(std::make_pair("http://www.yahoo.com/", yahoo)); | 364 test_url_data_.insert(std::make_pair("http://www.yahoo.com/", yahoo)); |
| 371 } | 365 } |
| 372 | 366 |
| 373 { // Host data. | 367 { // Host data. |
| 374 PrefetchData facebook(PREFETCH_KEY_TYPE_HOST, "www.facebook.com"); | 368 PrefetchData facebook(PREFETCH_KEY_TYPE_HOST, "www.facebook.com"); |
| 375 facebook.last_visit = base::Time::FromInternalValue(4); | 369 facebook.last_visit = base::Time::FromInternalValue(4); |
| 370 facebook.resources.push_back(ResourceRow( |
| 371 "http://www.facebook.com/style.css", content::RESOURCE_TYPE_STYLESHEET, |
| 372 5, 2, 1, 1.1, net::MEDIUM, false, false)); |
| 373 facebook.resources.push_back(ResourceRow( |
| 374 "http://www.facebook.com/script.js", content::RESOURCE_TYPE_SCRIPT, 4, |
| 375 0, 1, 2.1, net::MEDIUM, false, false)); |
| 376 facebook.resources.push_back(ResourceRow( |
| 377 "http://www.facebook.com/image.png", content::RESOURCE_TYPE_IMAGE, 6, 3, |
| 378 0, 2.2, net::MEDIUM, false, false)); |
| 379 facebook.resources.push_back(ResourceRow( |
| 380 "http://www.facebook.com/a.font", content::RESOURCE_TYPE_LAST_TYPE, 2, |
| 381 0, 0, 5.1, net::MEDIUM, false, false)); |
| 376 facebook.resources.push_back( | 382 facebook.resources.push_back( |
| 377 ResourceRow(std::string(), "http://www.facebook.com/style.css", | 383 ResourceRow("http://www.resources.facebook.com/script.js", |
| 378 content::RESOURCE_TYPE_STYLESHEET, 5, 2, 1, 1.1, | 384 content::RESOURCE_TYPE_SCRIPT, 11, 0, 0, 8.5, net::MEDIUM, |
| 379 net::MEDIUM, false, false)); | |
| 380 facebook.resources.push_back( | |
| 381 ResourceRow(std::string(), "http://www.facebook.com/script.js", | |
| 382 content::RESOURCE_TYPE_SCRIPT, 4, 0, 1, 2.1, net::MEDIUM, | |
| 383 false, false)); | 385 false, false)); |
| 384 facebook.resources.push_back(ResourceRow( | |
| 385 std::string(), "http://www.facebook.com/image.png", | |
| 386 content::RESOURCE_TYPE_IMAGE, 6, 3, 0, 2.2, net::MEDIUM, false, false)); | |
| 387 facebook.resources.push_back( | |
| 388 ResourceRow(std::string(), "http://www.facebook.com/a.font", | |
| 389 content::RESOURCE_TYPE_LAST_TYPE, 2, 0, 0, 5.1, net::MEDIUM, | |
| 390 false, false)); | |
| 391 facebook.resources.push_back(ResourceRow( | |
| 392 std::string(), "http://www.resources.facebook.com/script.js", | |
| 393 content::RESOURCE_TYPE_SCRIPT, 11, 0, 0, 8.5, net::MEDIUM, false, | |
| 394 false)); | |
| 395 | 386 |
| 396 PrefetchData yahoo(PREFETCH_KEY_TYPE_HOST, "www.yahoo.com"); | 387 PrefetchData yahoo(PREFETCH_KEY_TYPE_HOST, "www.yahoo.com"); |
| 397 yahoo.last_visit = base::Time::FromInternalValue(5); | 388 yahoo.last_visit = base::Time::FromInternalValue(5); |
| 398 yahoo.resources.push_back(ResourceRow(std::string(), | 389 yahoo.resources.push_back(ResourceRow("http://google.com/image.png", |
| 399 "http://google.com/image.png", | |
| 400 content::RESOURCE_TYPE_IMAGE, 20, 1, | 390 content::RESOURCE_TYPE_IMAGE, 20, 1, |
| 401 0, 10.0, net::MEDIUM, false, false)); | 391 0, 10.0, net::MEDIUM, false, false)); |
| 402 | 392 |
| 403 test_host_data_.clear(); | 393 test_host_data_.clear(); |
| 404 test_host_data_.insert(std::make_pair("www.facebook.com", facebook)); | 394 test_host_data_.insert(std::make_pair("www.facebook.com", facebook)); |
| 405 test_host_data_.insert(std::make_pair("www.yahoo.com", yahoo)); | 395 test_host_data_.insert(std::make_pair("www.yahoo.com", yahoo)); |
| 406 } | 396 } |
| 407 } | 397 } |
| 408 | 398 |
| 409 TEST_F(ResourcePrefetchPredictorTest, LazilyInitializeEmpty) { | 399 TEST_F(ResourcePrefetchPredictorTest, LazilyInitializeEmpty) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 URLRequestSummary resource2 = CreateURLRequestSummary( | 443 URLRequestSummary resource2 = CreateURLRequestSummary( |
| 454 1, 1, "http://www.google.com", "http://google.com/script1.js", | 444 1, 1, "http://www.google.com", "http://google.com/script1.js", |
| 455 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); | 445 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); |
| 456 predictor_->RecordURLResponse(resource2); | 446 predictor_->RecordURLResponse(resource2); |
| 457 URLRequestSummary resource3 = CreateURLRequestSummary( | 447 URLRequestSummary resource3 = CreateURLRequestSummary( |
| 458 1, 1, "http://www.google.com", "http://google.com/script2.js", | 448 1, 1, "http://www.google.com", "http://google.com/script2.js", |
| 459 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); | 449 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); |
| 460 predictor_->RecordURLResponse(resource3); | 450 predictor_->RecordURLResponse(resource3); |
| 461 | 451 |
| 462 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com"); | 452 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com"); |
| 463 host_data.resources.push_back( | |
| 464 ResourceRow(std::string(), "http://google.com/style1.css", | |
| 465 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, net::MEDIUM, | |
| 466 false, false)); | |
| 467 host_data.resources.push_back(ResourceRow( | 453 host_data.resources.push_back(ResourceRow( |
| 468 std::string(), "http://google.com/script1.js", | 454 "http://google.com/style1.css", content::RESOURCE_TYPE_STYLESHEET, 1, 0, |
| 469 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM, false, false)); | 455 0, 1.0, net::MEDIUM, false, false)); |
| 470 host_data.resources.push_back(ResourceRow( | 456 host_data.resources.push_back(ResourceRow("http://google.com/script1.js", |
| 471 std::string(), "http://google.com/script2.js", | 457 content::RESOURCE_TYPE_SCRIPT, 1, 0, |
| 472 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false)); | 458 0, 2.0, net::MEDIUM, false, false)); |
| 459 host_data.resources.push_back(ResourceRow("http://google.com/script2.js", |
| 460 content::RESOURCE_TYPE_SCRIPT, 1, 0, |
| 461 0, 3.0, net::MEDIUM, false, false)); |
| 473 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); | 462 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); |
| 474 | 463 |
| 475 predictor_->OnNavigationComplete(main_frame.navigation_id); | 464 predictor_->OnNavigationComplete(main_frame.navigation_id); |
| 476 profile_->BlockUntilHistoryProcessesPendingRequests(); | 465 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 477 } | 466 } |
| 478 | 467 |
| 479 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDB) { | 468 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDB) { |
| 480 // Single navigation that will be recorded. Will check for duplicate | 469 // Single navigation that will be recorded. Will check for duplicate |
| 481 // resources and also for number of resources saved. | 470 // resources and also for number of resources saved. |
| 482 AddUrlToHistory("http://www.google.com", 4); | 471 AddUrlToHistory("http://www.google.com", 4); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 510 URLRequestSummary resource6 = CreateURLRequestSummary( | 499 URLRequestSummary resource6 = CreateURLRequestSummary( |
| 511 1, 1, "http://www.google.com", "http://google.com/image2.png", | 500 1, 1, "http://www.google.com", "http://google.com/image2.png", |
| 512 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false); | 501 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false); |
| 513 predictor_->RecordURLResponse(resource6); | 502 predictor_->RecordURLResponse(resource6); |
| 514 URLRequestSummary resource7 = CreateURLRequestSummary( | 503 URLRequestSummary resource7 = CreateURLRequestSummary( |
| 515 1, 1, "http://www.google.com", "http://google.com/style2.css", | 504 1, 1, "http://www.google.com", "http://google.com/style2.css", |
| 516 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true); | 505 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true); |
| 517 predictor_->RecordURLResponse(resource7); | 506 predictor_->RecordURLResponse(resource7); |
| 518 | 507 |
| 519 PrefetchData url_data(PREFETCH_KEY_TYPE_URL, "http://www.google.com/"); | 508 PrefetchData url_data(PREFETCH_KEY_TYPE_URL, "http://www.google.com/"); |
| 520 url_data.resources.push_back( | |
| 521 ResourceRow(std::string(), "http://google.com/style1.css", | |
| 522 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, net::MEDIUM, | |
| 523 false, false)); | |
| 524 url_data.resources.push_back(ResourceRow( | 509 url_data.resources.push_back(ResourceRow( |
| 525 std::string(), "http://google.com/script1.js", | 510 "http://google.com/style1.css", content::RESOURCE_TYPE_STYLESHEET, 1, 0, |
| 526 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM, false, false)); | 511 0, 1.0, net::MEDIUM, false, false)); |
| 512 url_data.resources.push_back(ResourceRow("http://google.com/script1.js", |
| 513 content::RESOURCE_TYPE_SCRIPT, 1, 0, |
| 514 0, 2.0, net::MEDIUM, false, false)); |
| 515 url_data.resources.push_back(ResourceRow("http://google.com/script2.js", |
| 516 content::RESOURCE_TYPE_SCRIPT, 1, 0, |
| 517 0, 3.0, net::MEDIUM, false, false)); |
| 527 url_data.resources.push_back(ResourceRow( | 518 url_data.resources.push_back(ResourceRow( |
| 528 std::string(), "http://google.com/script2.js", | 519 "http://google.com/style2.css", content::RESOURCE_TYPE_STYLESHEET, 1, 0, |
| 529 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false)); | 520 0, 7.0, net::MEDIUM, false, false)); |
| 530 url_data.resources.push_back( | |
| 531 ResourceRow(std::string(), "http://google.com/style2.css", | |
| 532 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 7.0, net::MEDIUM, | |
| 533 false, false)); | |
| 534 EXPECT_CALL(*mock_tables_.get(), UpdateData(url_data, empty_host_data_)); | 521 EXPECT_CALL(*mock_tables_.get(), UpdateData(url_data, empty_host_data_)); |
| 535 | 522 |
| 536 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com"); | 523 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com"); |
| 537 host_data.resources = url_data.resources; | 524 host_data.resources = url_data.resources; |
| 538 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); | 525 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); |
| 539 | 526 |
| 540 predictor_->OnNavigationComplete(main_frame.navigation_id); | 527 predictor_->OnNavigationComplete(main_frame.navigation_id); |
| 541 profile_->BlockUntilHistoryProcessesPendingRequests(); | 528 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 542 } | 529 } |
| 543 | 530 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 URLRequestSummary resource6 = CreateURLRequestSummary( | 572 URLRequestSummary resource6 = CreateURLRequestSummary( |
| 586 1, 1, "http://www.google.com", "http://google.com/image2.png", | 573 1, 1, "http://www.google.com", "http://google.com/image2.png", |
| 587 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false); | 574 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false); |
| 588 predictor_->RecordURLResponse(resource6); | 575 predictor_->RecordURLResponse(resource6); |
| 589 URLRequestSummary resource7 = CreateURLRequestSummary( | 576 URLRequestSummary resource7 = CreateURLRequestSummary( |
| 590 1, 1, "http://www.google.com", "http://google.com/style2.css", | 577 1, 1, "http://www.google.com", "http://google.com/style2.css", |
| 591 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true); | 578 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true); |
| 592 predictor_->RecordURLResponse(resource7); | 579 predictor_->RecordURLResponse(resource7); |
| 593 | 580 |
| 594 PrefetchData url_data(PREFETCH_KEY_TYPE_URL, "http://www.google.com/"); | 581 PrefetchData url_data(PREFETCH_KEY_TYPE_URL, "http://www.google.com/"); |
| 595 url_data.resources.push_back( | |
| 596 ResourceRow(std::string(), "http://google.com/style1.css", | |
| 597 content::RESOURCE_TYPE_STYLESHEET, 4, 2, 0, 1.0, net::MEDIUM, | |
| 598 false, false)); | |
| 599 url_data.resources.push_back(ResourceRow( | 582 url_data.resources.push_back(ResourceRow( |
| 600 std::string(), "http://google.com/script1.js", | 583 "http://google.com/style1.css", content::RESOURCE_TYPE_STYLESHEET, 4, 2, |
| 601 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM, false, false)); | 584 0, 1.0, net::MEDIUM, false, false)); |
| 602 url_data.resources.push_back(ResourceRow( | 585 url_data.resources.push_back(ResourceRow("http://google.com/script1.js", |
| 603 std::string(), "http://google.com/script4.js", | 586 content::RESOURCE_TYPE_SCRIPT, 1, 0, |
| 604 content::RESOURCE_TYPE_SCRIPT, 11, 1, 1, 2.1, net::MEDIUM, false, false)); | 587 0, 2.0, net::MEDIUM, false, false)); |
| 605 url_data.resources.push_back(ResourceRow( | 588 url_data.resources.push_back(ResourceRow("http://google.com/script4.js", |
| 606 std::string(), "http://google.com/script2.js", | 589 content::RESOURCE_TYPE_SCRIPT, 11, 1, |
| 607 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false)); | 590 1, 2.1, net::MEDIUM, false, false)); |
| 591 url_data.resources.push_back(ResourceRow("http://google.com/script2.js", |
| 592 content::RESOURCE_TYPE_SCRIPT, 1, 0, |
| 593 0, 3.0, net::MEDIUM, false, false)); |
| 608 EXPECT_CALL(*mock_tables_.get(), UpdateData(url_data, empty_host_data_)); | 594 EXPECT_CALL(*mock_tables_.get(), UpdateData(url_data, empty_host_data_)); |
| 609 | 595 |
| 610 EXPECT_CALL( | 596 EXPECT_CALL( |
| 611 *mock_tables_.get(), | 597 *mock_tables_.get(), |
| 612 DeleteSingleDataPoint("www.facebook.com", PREFETCH_KEY_TYPE_HOST)); | 598 DeleteSingleDataPoint("www.facebook.com", PREFETCH_KEY_TYPE_HOST)); |
| 613 | 599 |
| 614 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com"); | 600 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com"); |
| 615 host_data.resources.push_back( | |
| 616 ResourceRow(std::string(), "http://google.com/style1.css", | |
| 617 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, net::MEDIUM, | |
| 618 false, false)); | |
| 619 host_data.resources.push_back(ResourceRow( | 601 host_data.resources.push_back(ResourceRow( |
| 620 std::string(), "http://google.com/script1.js", | 602 "http://google.com/style1.css", content::RESOURCE_TYPE_STYLESHEET, 1, 0, |
| 621 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM, false, false)); | 603 0, 1.0, net::MEDIUM, false, false)); |
| 604 host_data.resources.push_back(ResourceRow("http://google.com/script1.js", |
| 605 content::RESOURCE_TYPE_SCRIPT, 1, 0, |
| 606 0, 2.0, net::MEDIUM, false, false)); |
| 607 host_data.resources.push_back(ResourceRow("http://google.com/script2.js", |
| 608 content::RESOURCE_TYPE_SCRIPT, 1, 0, |
| 609 0, 3.0, net::MEDIUM, false, false)); |
| 622 host_data.resources.push_back(ResourceRow( | 610 host_data.resources.push_back(ResourceRow( |
| 623 std::string(), "http://google.com/script2.js", | 611 "http://google.com/style2.css", content::RESOURCE_TYPE_STYLESHEET, 1, 0, |
| 624 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false)); | 612 0, 7.0, net::MEDIUM, false, false)); |
| 625 host_data.resources.push_back( | |
| 626 ResourceRow(std::string(), "http://google.com/style2.css", | |
| 627 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 7.0, net::MEDIUM, | |
| 628 false, false)); | |
| 629 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); | 613 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); |
| 630 | 614 |
| 631 predictor_->OnNavigationComplete(main_frame.navigation_id); | 615 predictor_->OnNavigationComplete(main_frame.navigation_id); |
| 632 profile_->BlockUntilHistoryProcessesPendingRequests(); | 616 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 633 } | 617 } |
| 634 | 618 |
| 635 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDBAndDBFull) { | 619 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDBAndDBFull) { |
| 636 // Tests that a URL is deleted before another is added if the cache is full. | 620 // Tests that a URL is deleted before another is added if the cache is full. |
| 637 AddUrlToHistory("http://www.nike.com/", 4); | 621 AddUrlToHistory("http://www.nike.com/", 4); |
| 638 | 622 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 662 predictor_->RecordURLResponse(resource2); | 646 predictor_->RecordURLResponse(resource2); |
| 663 | 647 |
| 664 EXPECT_CALL( | 648 EXPECT_CALL( |
| 665 *mock_tables_.get(), | 649 *mock_tables_.get(), |
| 666 DeleteSingleDataPoint("http://www.google.com/", PREFETCH_KEY_TYPE_URL)); | 650 DeleteSingleDataPoint("http://www.google.com/", PREFETCH_KEY_TYPE_URL)); |
| 667 EXPECT_CALL( | 651 EXPECT_CALL( |
| 668 *mock_tables_.get(), | 652 *mock_tables_.get(), |
| 669 DeleteSingleDataPoint("www.facebook.com", PREFETCH_KEY_TYPE_HOST)); | 653 DeleteSingleDataPoint("www.facebook.com", PREFETCH_KEY_TYPE_HOST)); |
| 670 | 654 |
| 671 PrefetchData url_data(PREFETCH_KEY_TYPE_URL, "http://www.nike.com/"); | 655 PrefetchData url_data(PREFETCH_KEY_TYPE_URL, "http://www.nike.com/"); |
| 672 url_data.resources.push_back( | |
| 673 ResourceRow(std::string(), "http://nike.com/style1.css", | |
| 674 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, net::MEDIUM, | |
| 675 false, false)); | |
| 676 url_data.resources.push_back(ResourceRow( | 656 url_data.resources.push_back(ResourceRow( |
| 677 std::string(), "http://nike.com/image2.png", content::RESOURCE_TYPE_IMAGE, | 657 "http://nike.com/style1.css", content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, |
| 678 1, 0, 0, 2.0, net::MEDIUM, false, false)); | 658 1.0, net::MEDIUM, false, false)); |
| 659 url_data.resources.push_back(ResourceRow("http://nike.com/image2.png", |
| 660 content::RESOURCE_TYPE_IMAGE, 1, 0, |
| 661 0, 2.0, net::MEDIUM, false, false)); |
| 679 EXPECT_CALL(*mock_tables_.get(), UpdateData(url_data, empty_host_data_)); | 662 EXPECT_CALL(*mock_tables_.get(), UpdateData(url_data, empty_host_data_)); |
| 680 | 663 |
| 681 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.nike.com"); | 664 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.nike.com"); |
| 682 host_data.resources = url_data.resources; | 665 host_data.resources = url_data.resources; |
| 683 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); | 666 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); |
| 684 | 667 |
| 685 predictor_->OnNavigationComplete(main_frame.navigation_id); | 668 predictor_->OnNavigationComplete(main_frame.navigation_id); |
| 686 profile_->BlockUntilHistoryProcessesPendingRequests(); | 669 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 687 } | 670 } |
| 688 | 671 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 main_frame.navigation_id.creation_time = base::TimeTicks(); | 855 main_frame.navigation_id.creation_time = base::TimeTicks(); |
| 873 EXPECT_TRUE(main_frame.navigation_id.creation_time.is_null()); | 856 EXPECT_TRUE(main_frame.navigation_id.creation_time.is_null()); |
| 874 | 857 |
| 875 // Now add a subresource. | 858 // Now add a subresource. |
| 876 URLRequestSummary resource1 = CreateURLRequestSummary( | 859 URLRequestSummary resource1 = CreateURLRequestSummary( |
| 877 1, 1, "http://www.google.com", "http://google.com/style1.css", | 860 1, 1, "http://www.google.com", "http://google.com/style1.css", |
| 878 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); | 861 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); |
| 879 predictor_->RecordURLResponse(resource1); | 862 predictor_->RecordURLResponse(resource1); |
| 880 | 863 |
| 881 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com"); | 864 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com"); |
| 882 host_data.resources.push_back( | 865 host_data.resources.push_back(ResourceRow( |
| 883 ResourceRow(std::string(), "http://google.com/style1.css", | 866 "http://google.com/style1.css", content::RESOURCE_TYPE_STYLESHEET, 1, 0, |
| 884 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, net::MEDIUM, | 867 0, 1.0, net::MEDIUM, false, false)); |
| 885 false, false)); | |
| 886 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); | 868 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); |
| 887 | 869 |
| 888 // The page load time will be collected by RPP_HISTOGRAM_MEDIUM_TIMES, which | 870 // The page load time will be collected by RPP_HISTOGRAM_MEDIUM_TIMES, which |
| 889 // has a upper bound of 3 minutes. | 871 // has a upper bound of 3 minutes. |
| 890 base::TimeDelta plt = | 872 base::TimeDelta plt = |
| 891 predictor_->OnNavigationComplete(main_frame.navigation_id); | 873 predictor_->OnNavigationComplete(main_frame.navigation_id); |
| 892 EXPECT_LT(plt, base::TimeDelta::FromSeconds(180)); | 874 EXPECT_LT(plt, base::TimeDelta::FromSeconds(180)); |
| 893 | 875 |
| 894 profile_->BlockUntilHistoryProcessesPendingRequests(); | 876 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 895 } | 877 } |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1118 url_request_job_factory_.set_response_info(response_info); | 1100 url_request_job_factory_.set_response_info(response_info); |
| 1119 std::unique_ptr<net::URLRequest> request_etag = | 1101 std::unique_ptr<net::URLRequest> request_etag = |
| 1120 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, | 1102 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, |
| 1121 content::RESOURCE_TYPE_PREFETCH, 1, 1, true); | 1103 content::RESOURCE_TYPE_PREFETCH, 1, 1, true); |
| 1122 EXPECT_TRUE(URLRequestSummary::SummarizeResponse(*request_etag, &summary)); | 1104 EXPECT_TRUE(URLRequestSummary::SummarizeResponse(*request_etag, &summary)); |
| 1123 EXPECT_TRUE(summary.has_validators); | 1105 EXPECT_TRUE(summary.has_validators); |
| 1124 EXPECT_TRUE(summary.always_revalidate); | 1106 EXPECT_TRUE(summary.always_revalidate); |
| 1125 } | 1107 } |
| 1126 | 1108 |
| 1127 } // namespace predictors | 1109 } // namespace predictors |
| OLD | NEW |