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

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

Issue 2268283005: predictors: Refactor the resource_prefetch_predictor database handling. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 4 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 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
36 using chrome_browser_predictors::ResourceData;
37
35 namespace predictors { 38 namespace predictors {
36 39
37 typedef ResourcePrefetchPredictor::URLRequestSummary URLRequestSummary; 40 typedef ResourcePrefetchPredictor::URLRequestSummary URLRequestSummary;
38 typedef ResourcePrefetchPredictorTables::ResourceRow ResourceRow;
39 typedef std::vector<ResourceRow> ResourceRows;
40 typedef ResourcePrefetchPredictorTables::PrefetchData PrefetchData; 41 typedef ResourcePrefetchPredictorTables::PrefetchData PrefetchData;
41 typedef ResourcePrefetchPredictorTables::PrefetchDataMap PrefetchDataMap; 42 typedef ResourcePrefetchPredictorTables::PrefetchDataMap PrefetchDataMap;
42 43
43 // For printing failures nicely.
44 void PrintTo(const ResourceRow& row, ::std::ostream* os) {
45 *os << "[" << row.primary_key << "," << row.resource_url
46 << "," << row.resource_type << "," << row.number_of_hits
47 << "," << row.number_of_misses << "," << row.consecutive_misses
48 << "," << row.average_position << "," << row.score << "]";
49 }
50
51 void PrintTo(const PrefetchData& data, ::std::ostream* os) {
52 *os << "[" << data.key_type << "," << data.primary_key
53 << "," << data.last_visit.ToInternalValue() << "]\n";
54 for (ResourceRows::const_iterator it = data.resources.begin();
55 it != data.resources.end(); ++it) {
56 *os << "\t\t";
57 PrintTo(*it, os);
58 *os << "\n";
59 }
60 }
61
62 scoped_refptr<net::HttpResponseHeaders> MakeResponseHeaders( 44 scoped_refptr<net::HttpResponseHeaders> MakeResponseHeaders(
63 const char* headers) { 45 const char* headers) {
64 return make_scoped_refptr(new net::HttpResponseHeaders( 46 return make_scoped_refptr(new net::HttpResponseHeaders(
65 net::HttpUtil::AssembleRawHeaders(headers, strlen(headers)))); 47 net::HttpUtil::AssembleRawHeaders(headers, strlen(headers))));
66 } 48 }
67 49
68 class EmptyURLRequestDelegate : public net::URLRequest::Delegate { 50 class EmptyURLRequestDelegate : public net::URLRequest::Delegate {
69 void OnResponseStarted(net::URLRequest* request) override {} 51 void OnResponseStarted(net::URLRequest* request) override {}
70 void OnReadCompleted(net::URLRequest* request, int bytes_read) override {} 52 void OnReadCompleted(net::URLRequest* request, int bytes_read) override {}
71 }; 53 };
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 301
320 void ResourcePrefetchPredictorTest::TearDown() { 302 void ResourcePrefetchPredictorTest::TearDown() {
321 predictor_.reset(NULL); 303 predictor_.reset(NULL);
322 profile_->DestroyHistoryService(); 304 profile_->DestroyHistoryService();
323 } 305 }
324 306
325 void ResourcePrefetchPredictorTest::InitializeSampleData() { 307 void ResourcePrefetchPredictorTest::InitializeSampleData() {
326 { // Url data. 308 { // Url data.
327 PrefetchData google(PREFETCH_KEY_TYPE_URL, "http://www.google.com/"); 309 PrefetchData google(PREFETCH_KEY_TYPE_URL, "http://www.google.com/");
328 google.last_visit = base::Time::FromInternalValue(1); 310 google.last_visit = base::Time::FromInternalValue(1);
329 google.resources.push_back( 311 google.resources.push_back(MakeResourceData(
330 ResourceRow(std::string(), "http://google.com/style1.css", 312 "http://google.com/style1.css", content::RESOURCE_TYPE_STYLESHEET, 3, 2,
331 content::RESOURCE_TYPE_STYLESHEET, 3, 2, 1, 1.0, 313 1, 1.0, net::MEDIUM, false, false));
332 net::MEDIUM, false, false)); 314 google.resources.push_back(MakeResourceData(
333 google.resources.push_back(ResourceRow(std::string(), 315 "http://google.com/script3.js", content::RESOURCE_TYPE_SCRIPT, 4, 0, 1,
334 "http://google.com/script3.js", 316 2.1, net::MEDIUM, false, false));
335 content::RESOURCE_TYPE_SCRIPT, 4, 0, 317 google.resources.push_back(MakeResourceData(
336 1, 2.1, net::MEDIUM, false, false)); 318 "http://google.com/script4.js", content::RESOURCE_TYPE_SCRIPT, 11, 0, 0,
337 google.resources.push_back(ResourceRow(std::string(), 319 2.1, net::MEDIUM, false, false));
338 "http://google.com/script4.js", 320 google.resources.push_back(MakeResourceData(
339 content::RESOURCE_TYPE_SCRIPT, 11, 0, 321 "http://google.com/image1.png", content::RESOURCE_TYPE_IMAGE, 6, 3, 0,
340 0, 2.1, net::MEDIUM, false, false)); 322 2.2, net::MEDIUM, false, false));
341 google.resources.push_back(ResourceRow( 323 google.resources.push_back(MakeResourceData(
342 std::string(), "http://google.com/image1.png", 324 "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)); 325 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 326
349 PrefetchData reddit(PREFETCH_KEY_TYPE_URL, "http://www.reddit.com/"); 327 PrefetchData reddit(PREFETCH_KEY_TYPE_URL, "http://www.reddit.com/");
350 reddit.last_visit = base::Time::FromInternalValue(2); 328 reddit.last_visit = base::Time::FromInternalValue(2);
351 reddit.resources.push_back( 329 reddit.resources.push_back(MakeResourceData(
352 ResourceRow(std::string(), "http://reddit-resource.com/script1.js", 330 "http://reddit-resource.com/script1.js", content::RESOURCE_TYPE_SCRIPT,
353 content::RESOURCE_TYPE_SCRIPT, 4, 0, 1, 1.0, net::MEDIUM, 331 4, 0, 1, 1.0, net::MEDIUM, false, false));
354 false, false)); 332 reddit.resources.push_back(MakeResourceData(
355 reddit.resources.push_back( 333 "http://reddit-resource.com/script2.js", content::RESOURCE_TYPE_SCRIPT,
356 ResourceRow(std::string(), "http://reddit-resource.com/script2.js", 334 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 335
360 PrefetchData yahoo(PREFETCH_KEY_TYPE_URL, "http://www.yahoo.com/"); 336 PrefetchData yahoo(PREFETCH_KEY_TYPE_URL, "http://www.yahoo.com/");
361 yahoo.last_visit = base::Time::FromInternalValue(3); 337 yahoo.last_visit = base::Time::FromInternalValue(3);
362 yahoo.resources.push_back(ResourceRow(std::string(), 338 yahoo.resources.push_back(MakeResourceData(
363 "http://google.com/image.png", 339 "http://google.com/image.png", content::RESOURCE_TYPE_IMAGE, 20, 1, 0,
364 content::RESOURCE_TYPE_IMAGE, 20, 1, 340 10.0, net::MEDIUM, false, false));
365 0, 10.0, net::MEDIUM, false, false));
366 341
367 test_url_data_.clear(); 342 test_url_data_.clear();
368 test_url_data_.insert(std::make_pair("http://www.google.com/", google)); 343 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)); 344 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)); 345 test_url_data_.insert(std::make_pair("http://www.yahoo.com/", yahoo));
371 } 346 }
372 347
373 { // Host data. 348 { // Host data.
374 PrefetchData facebook(PREFETCH_KEY_TYPE_HOST, "www.facebook.com"); 349 PrefetchData facebook(PREFETCH_KEY_TYPE_HOST, "www.facebook.com");
375 facebook.last_visit = base::Time::FromInternalValue(4); 350 facebook.last_visit = base::Time::FromInternalValue(4);
351 facebook.resources.push_back(MakeResourceData(
352 "http://www.facebook.com/style.css", content::RESOURCE_TYPE_STYLESHEET,
353 5, 2, 1, 1.1, net::MEDIUM, false, false));
354 facebook.resources.push_back(MakeResourceData(
355 "http://www.facebook.com/script.js", content::RESOURCE_TYPE_SCRIPT, 4,
356 0, 1, 2.1, net::MEDIUM, false, false));
357 facebook.resources.push_back(MakeResourceData(
358 "http://www.facebook.com/image.png", content::RESOURCE_TYPE_IMAGE, 6, 3,
359 0, 2.2, net::MEDIUM, false, false));
360 facebook.resources.push_back(MakeResourceData(
361 "http://www.facebook.com/a.font", content::RESOURCE_TYPE_LAST_TYPE, 2,
362 0, 0, 5.1, net::MEDIUM, false, false));
376 facebook.resources.push_back( 363 facebook.resources.push_back(
377 ResourceRow(std::string(), "http://www.facebook.com/style.css", 364 MakeResourceData("http://www.resources.facebook.com/script.js",
378 content::RESOURCE_TYPE_STYLESHEET, 5, 2, 1, 1.1, 365 content::RESOURCE_TYPE_SCRIPT, 11, 0, 0, 8.5,
379 net::MEDIUM, false, false)); 366 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));
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 367
396 PrefetchData yahoo(PREFETCH_KEY_TYPE_HOST, "www.yahoo.com"); 368 PrefetchData yahoo(PREFETCH_KEY_TYPE_HOST, "www.yahoo.com");
397 yahoo.last_visit = base::Time::FromInternalValue(5); 369 yahoo.last_visit = base::Time::FromInternalValue(5);
398 yahoo.resources.push_back(ResourceRow(std::string(), 370 yahoo.resources.push_back(MakeResourceData(
399 "http://google.com/image.png", 371 "http://google.com/image.png", content::RESOURCE_TYPE_IMAGE, 20, 1, 0,
400 content::RESOURCE_TYPE_IMAGE, 20, 1, 372 10.0, net::MEDIUM, false, false));
401 0, 10.0, net::MEDIUM, false, false));
402 373
403 test_host_data_.clear(); 374 test_host_data_.clear();
404 test_host_data_.insert(std::make_pair("www.facebook.com", facebook)); 375 test_host_data_.insert(std::make_pair("www.facebook.com", facebook));
405 test_host_data_.insert(std::make_pair("www.yahoo.com", yahoo)); 376 test_host_data_.insert(std::make_pair("www.yahoo.com", yahoo));
406 } 377 }
407 } 378 }
408 379
409 TEST_F(ResourcePrefetchPredictorTest, LazilyInitializeEmpty) { 380 TEST_F(ResourcePrefetchPredictorTest, LazilyInitializeEmpty) {
410 // Tests that the predictor initializes correctly without any data. 381 // Tests that the predictor initializes correctly without any data.
411 EXPECT_TRUE(predictor_->url_table_cache_->empty()); 382 EXPECT_TRUE(predictor_->url_table_cache_->empty());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 URLRequestSummary resource2 = CreateURLRequestSummary( 424 URLRequestSummary resource2 = CreateURLRequestSummary(
454 1, 1, "http://www.google.com", "http://google.com/script1.js", 425 1, 1, "http://www.google.com", "http://google.com/script1.js",
455 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); 426 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false);
456 predictor_->RecordURLResponse(resource2); 427 predictor_->RecordURLResponse(resource2);
457 URLRequestSummary resource3 = CreateURLRequestSummary( 428 URLRequestSummary resource3 = CreateURLRequestSummary(
458 1, 1, "http://www.google.com", "http://google.com/script2.js", 429 1, 1, "http://www.google.com", "http://google.com/script2.js",
459 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); 430 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false);
460 predictor_->RecordURLResponse(resource3); 431 predictor_->RecordURLResponse(resource3);
461 432
462 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com"); 433 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com");
463 host_data.resources.push_back( 434 host_data.resources.push_back(MakeResourceData(
464 ResourceRow(std::string(), "http://google.com/style1.css", 435 "http://google.com/style1.css", content::RESOURCE_TYPE_STYLESHEET, 1, 0,
465 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, net::MEDIUM, 436 0, 1.0, net::MEDIUM, false, false));
466 false, false)); 437 host_data.resources.push_back(MakeResourceData(
467 host_data.resources.push_back(ResourceRow( 438 "http://google.com/script1.js", content::RESOURCE_TYPE_SCRIPT, 1, 0, 0,
468 std::string(), "http://google.com/script1.js", 439 2.0, net::MEDIUM, false, false));
469 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM, false, false)); 440 host_data.resources.push_back(MakeResourceData(
470 host_data.resources.push_back(ResourceRow( 441 "http://google.com/script2.js", content::RESOURCE_TYPE_SCRIPT, 1, 0, 0,
471 std::string(), "http://google.com/script2.js", 442 3.0, net::MEDIUM, false, false));
472 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false));
473 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); 443 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data));
474 444
475 predictor_->OnNavigationComplete(main_frame.navigation_id); 445 predictor_->OnNavigationComplete(main_frame.navigation_id);
476 profile_->BlockUntilHistoryProcessesPendingRequests(); 446 profile_->BlockUntilHistoryProcessesPendingRequests();
477 } 447 }
478 448
479 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDB) { 449 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDB) {
480 // Single navigation that will be recorded. Will check for duplicate 450 // Single navigation that will be recorded. Will check for duplicate
481 // resources and also for number of resources saved. 451 // resources and also for number of resources saved.
482 AddUrlToHistory("http://www.google.com", 4); 452 AddUrlToHistory("http://www.google.com", 4);
(...skipping 27 matching lines...) Expand all
510 URLRequestSummary resource6 = CreateURLRequestSummary( 480 URLRequestSummary resource6 = CreateURLRequestSummary(
511 1, 1, "http://www.google.com", "http://google.com/image2.png", 481 1, 1, "http://www.google.com", "http://google.com/image2.png",
512 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false); 482 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false);
513 predictor_->RecordURLResponse(resource6); 483 predictor_->RecordURLResponse(resource6);
514 URLRequestSummary resource7 = CreateURLRequestSummary( 484 URLRequestSummary resource7 = CreateURLRequestSummary(
515 1, 1, "http://www.google.com", "http://google.com/style2.css", 485 1, 1, "http://www.google.com", "http://google.com/style2.css",
516 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true); 486 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true);
517 predictor_->RecordURLResponse(resource7); 487 predictor_->RecordURLResponse(resource7);
518 488
519 PrefetchData url_data(PREFETCH_KEY_TYPE_URL, "http://www.google.com/"); 489 PrefetchData url_data(PREFETCH_KEY_TYPE_URL, "http://www.google.com/");
520 url_data.resources.push_back( 490 url_data.resources.push_back(MakeResourceData(
521 ResourceRow(std::string(), "http://google.com/style1.css", 491 "http://google.com/style1.css", content::RESOURCE_TYPE_STYLESHEET, 1, 0,
522 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, net::MEDIUM, 492 0, 1.0, net::MEDIUM, false, false));
523 false, false)); 493 url_data.resources.push_back(MakeResourceData(
524 url_data.resources.push_back(ResourceRow( 494 "http://google.com/script1.js", content::RESOURCE_TYPE_SCRIPT, 1, 0, 0,
525 std::string(), "http://google.com/script1.js", 495 2.0, net::MEDIUM, false, false));
526 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM, false, false)); 496 url_data.resources.push_back(MakeResourceData(
527 url_data.resources.push_back(ResourceRow( 497 "http://google.com/script2.js", content::RESOURCE_TYPE_SCRIPT, 1, 0, 0,
528 std::string(), "http://google.com/script2.js", 498 3.0, net::MEDIUM, false, false));
529 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false)); 499 url_data.resources.push_back(MakeResourceData(
530 url_data.resources.push_back( 500 "http://google.com/style2.css", content::RESOURCE_TYPE_STYLESHEET, 1, 0,
531 ResourceRow(std::string(), "http://google.com/style2.css", 501 0, 7.0, net::MEDIUM, false, false));
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_)); 502 EXPECT_CALL(*mock_tables_.get(), UpdateData(url_data, empty_host_data_));
535 503
536 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com"); 504 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com");
537 host_data.resources = url_data.resources; 505 host_data.resources = url_data.resources;
538 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); 506 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data));
539 507
540 predictor_->OnNavigationComplete(main_frame.navigation_id); 508 predictor_->OnNavigationComplete(main_frame.navigation_id);
541 profile_->BlockUntilHistoryProcessesPendingRequests(); 509 profile_->BlockUntilHistoryProcessesPendingRequests();
542 } 510 }
543 511
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 URLRequestSummary resource6 = CreateURLRequestSummary( 553 URLRequestSummary resource6 = CreateURLRequestSummary(
586 1, 1, "http://www.google.com", "http://google.com/image2.png", 554 1, 1, "http://www.google.com", "http://google.com/image2.png",
587 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false); 555 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false);
588 predictor_->RecordURLResponse(resource6); 556 predictor_->RecordURLResponse(resource6);
589 URLRequestSummary resource7 = CreateURLRequestSummary( 557 URLRequestSummary resource7 = CreateURLRequestSummary(
590 1, 1, "http://www.google.com", "http://google.com/style2.css", 558 1, 1, "http://www.google.com", "http://google.com/style2.css",
591 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true); 559 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true);
592 predictor_->RecordURLResponse(resource7); 560 predictor_->RecordURLResponse(resource7);
593 561
594 PrefetchData url_data(PREFETCH_KEY_TYPE_URL, "http://www.google.com/"); 562 PrefetchData url_data(PREFETCH_KEY_TYPE_URL, "http://www.google.com/");
595 url_data.resources.push_back( 563 url_data.resources.push_back(MakeResourceData(
596 ResourceRow(std::string(), "http://google.com/style1.css", 564 "http://google.com/style1.css", content::RESOURCE_TYPE_STYLESHEET, 4, 2,
597 content::RESOURCE_TYPE_STYLESHEET, 4, 2, 0, 1.0, net::MEDIUM, 565 0, 1.0, net::MEDIUM, false, false));
598 false, false)); 566 url_data.resources.push_back(MakeResourceData(
599 url_data.resources.push_back(ResourceRow( 567 "http://google.com/script1.js", content::RESOURCE_TYPE_SCRIPT, 1, 0, 0,
600 std::string(), "http://google.com/script1.js", 568 2.0, net::MEDIUM, false, false));
601 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM, false, false)); 569 url_data.resources.push_back(MakeResourceData(
602 url_data.resources.push_back(ResourceRow( 570 "http://google.com/script4.js", content::RESOURCE_TYPE_SCRIPT, 11, 1, 1,
603 std::string(), "http://google.com/script4.js", 571 2.1, net::MEDIUM, false, false));
604 content::RESOURCE_TYPE_SCRIPT, 11, 1, 1, 2.1, net::MEDIUM, false, false)); 572 url_data.resources.push_back(MakeResourceData(
605 url_data.resources.push_back(ResourceRow( 573 "http://google.com/script2.js", content::RESOURCE_TYPE_SCRIPT, 1, 0, 0,
606 std::string(), "http://google.com/script2.js", 574 3.0, net::MEDIUM, false, false));
607 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false));
608 EXPECT_CALL(*mock_tables_.get(), UpdateData(url_data, empty_host_data_)); 575 EXPECT_CALL(*mock_tables_.get(), UpdateData(url_data, empty_host_data_));
609 576
610 EXPECT_CALL( 577 EXPECT_CALL(
611 *mock_tables_.get(), 578 *mock_tables_.get(),
612 DeleteSingleDataPoint("www.facebook.com", PREFETCH_KEY_TYPE_HOST)); 579 DeleteSingleDataPoint("www.facebook.com", PREFETCH_KEY_TYPE_HOST));
613 580
614 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com"); 581 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com");
615 host_data.resources.push_back( 582 host_data.resources.push_back(MakeResourceData(
616 ResourceRow(std::string(), "http://google.com/style1.css", 583 "http://google.com/style1.css", content::RESOURCE_TYPE_STYLESHEET, 1, 0,
617 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, net::MEDIUM, 584 0, 1.0, net::MEDIUM, false, false));
618 false, false)); 585 host_data.resources.push_back(MakeResourceData(
619 host_data.resources.push_back(ResourceRow( 586 "http://google.com/script1.js", content::RESOURCE_TYPE_SCRIPT, 1, 0, 0,
620 std::string(), "http://google.com/script1.js", 587 2.0, net::MEDIUM, false, false));
621 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM, false, false)); 588 host_data.resources.push_back(MakeResourceData(
622 host_data.resources.push_back(ResourceRow( 589 "http://google.com/script2.js", content::RESOURCE_TYPE_SCRIPT, 1, 0, 0,
623 std::string(), "http://google.com/script2.js", 590 3.0, net::MEDIUM, false, false));
624 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false)); 591 host_data.resources.push_back(MakeResourceData(
625 host_data.resources.push_back( 592 "http://google.com/style2.css", content::RESOURCE_TYPE_STYLESHEET, 1, 0,
626 ResourceRow(std::string(), "http://google.com/style2.css", 593 0, 7.0, net::MEDIUM, false, false));
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)); 594 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data));
630 595
631 predictor_->OnNavigationComplete(main_frame.navigation_id); 596 predictor_->OnNavigationComplete(main_frame.navigation_id);
632 profile_->BlockUntilHistoryProcessesPendingRequests(); 597 profile_->BlockUntilHistoryProcessesPendingRequests();
633 } 598 }
634 599
635 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDBAndDBFull) { 600 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDBAndDBFull) {
636 // Tests that a URL is deleted before another is added if the cache is full. 601 // Tests that a URL is deleted before another is added if the cache is full.
637 AddUrlToHistory("http://www.nike.com/", 4); 602 AddUrlToHistory("http://www.nike.com/", 4);
638 603
(...skipping 23 matching lines...) Expand all
662 predictor_->RecordURLResponse(resource2); 627 predictor_->RecordURLResponse(resource2);
663 628
664 EXPECT_CALL( 629 EXPECT_CALL(
665 *mock_tables_.get(), 630 *mock_tables_.get(),
666 DeleteSingleDataPoint("http://www.google.com/", PREFETCH_KEY_TYPE_URL)); 631 DeleteSingleDataPoint("http://www.google.com/", PREFETCH_KEY_TYPE_URL));
667 EXPECT_CALL( 632 EXPECT_CALL(
668 *mock_tables_.get(), 633 *mock_tables_.get(),
669 DeleteSingleDataPoint("www.facebook.com", PREFETCH_KEY_TYPE_HOST)); 634 DeleteSingleDataPoint("www.facebook.com", PREFETCH_KEY_TYPE_HOST));
670 635
671 PrefetchData url_data(PREFETCH_KEY_TYPE_URL, "http://www.nike.com/"); 636 PrefetchData url_data(PREFETCH_KEY_TYPE_URL, "http://www.nike.com/");
672 url_data.resources.push_back( 637 url_data.resources.push_back(MakeResourceData(
673 ResourceRow(std::string(), "http://nike.com/style1.css", 638 "http://nike.com/style1.css", content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0,
674 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, net::MEDIUM, 639 1.0, net::MEDIUM, false, false));
675 false, false)); 640 url_data.resources.push_back(MakeResourceData(
676 url_data.resources.push_back(ResourceRow( 641 "http://nike.com/image2.png", content::RESOURCE_TYPE_IMAGE, 1, 0, 0, 2.0,
677 std::string(), "http://nike.com/image2.png", content::RESOURCE_TYPE_IMAGE, 642 net::MEDIUM, false, false));
678 1, 0, 0, 2.0, net::MEDIUM, false, false));
679 EXPECT_CALL(*mock_tables_.get(), UpdateData(url_data, empty_host_data_)); 643 EXPECT_CALL(*mock_tables_.get(), UpdateData(url_data, empty_host_data_));
680 644
681 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.nike.com"); 645 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.nike.com");
682 host_data.resources = url_data.resources; 646 host_data.resources = url_data.resources;
683 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); 647 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data));
684 648
685 predictor_->OnNavigationComplete(main_frame.navigation_id); 649 predictor_->OnNavigationComplete(main_frame.navigation_id);
686 profile_->BlockUntilHistoryProcessesPendingRequests(); 650 profile_->BlockUntilHistoryProcessesPendingRequests();
687 } 651 }
688 652
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 main_frame.navigation_id.creation_time = base::TimeTicks(); 836 main_frame.navigation_id.creation_time = base::TimeTicks();
873 EXPECT_TRUE(main_frame.navigation_id.creation_time.is_null()); 837 EXPECT_TRUE(main_frame.navigation_id.creation_time.is_null());
874 838
875 // Now add a subresource. 839 // Now add a subresource.
876 URLRequestSummary resource1 = CreateURLRequestSummary( 840 URLRequestSummary resource1 = CreateURLRequestSummary(
877 1, 1, "http://www.google.com", "http://google.com/style1.css", 841 1, 1, "http://www.google.com", "http://google.com/style1.css",
878 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); 842 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false);
879 predictor_->RecordURLResponse(resource1); 843 predictor_->RecordURLResponse(resource1);
880 844
881 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com"); 845 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com");
882 host_data.resources.push_back( 846 host_data.resources.push_back(MakeResourceData(
883 ResourceRow(std::string(), "http://google.com/style1.css", 847 "http://google.com/style1.css", content::RESOURCE_TYPE_STYLESHEET, 1, 0,
884 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, net::MEDIUM, 848 0, 1.0, net::MEDIUM, false, false));
885 false, false));
886 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); 849 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data));
887 850
888 // The page load time will be collected by RPP_HISTOGRAM_MEDIUM_TIMES, which 851 // The page load time will be collected by RPP_HISTOGRAM_MEDIUM_TIMES, which
889 // has a upper bound of 3 minutes. 852 // has a upper bound of 3 minutes.
890 base::TimeDelta plt = 853 base::TimeDelta plt =
891 predictor_->OnNavigationComplete(main_frame.navigation_id); 854 predictor_->OnNavigationComplete(main_frame.navigation_id);
892 EXPECT_LT(plt, base::TimeDelta::FromSeconds(180)); 855 EXPECT_LT(plt, base::TimeDelta::FromSeconds(180));
893 856
894 profile_->BlockUntilHistoryProcessesPendingRequests(); 857 profile_->BlockUntilHistoryProcessesPendingRequests();
895 } 858 }
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 url_request_job_factory_.set_response_info(response_info); 1081 url_request_job_factory_.set_response_info(response_info);
1119 std::unique_ptr<net::URLRequest> request_etag = 1082 std::unique_ptr<net::URLRequest> request_etag =
1120 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, 1083 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM,
1121 content::RESOURCE_TYPE_PREFETCH, 1, 1, true); 1084 content::RESOURCE_TYPE_PREFETCH, 1, 1, true);
1122 EXPECT_TRUE(URLRequestSummary::SummarizeResponse(*request_etag, &summary)); 1085 EXPECT_TRUE(URLRequestSummary::SummarizeResponse(*request_etag, &summary));
1123 EXPECT_TRUE(summary.has_validators); 1086 EXPECT_TRUE(summary.has_validators);
1124 EXPECT_TRUE(summary.always_revalidate); 1087 EXPECT_TRUE(summary.always_revalidate);
1125 } 1088 }
1126 1089
1127 } // namespace predictors 1090 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698