| 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/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 navigation_id.creation_time = base::TimeTicks::Now(); | 103 navigation_id.creation_time = base::TimeTicks::Now(); |
| 104 return navigation_id; | 104 return navigation_id; |
| 105 } | 105 } |
| 106 | 106 |
| 107 ResourcePrefetchPredictor::URLRequestSummary CreateURLRequestSummary( | 107 ResourcePrefetchPredictor::URLRequestSummary CreateURLRequestSummary( |
| 108 int process_id, | 108 int process_id, |
| 109 int render_frame_id, | 109 int render_frame_id, |
| 110 const std::string& main_frame_url, | 110 const std::string& main_frame_url, |
| 111 const std::string& resource_url, | 111 const std::string& resource_url, |
| 112 content::ResourceType resource_type, | 112 content::ResourceType resource_type, |
| 113 net::RequestPriority priority, |
| 113 const std::string& mime_type, | 114 const std::string& mime_type, |
| 114 bool was_cached) { | 115 bool was_cached) { |
| 115 ResourcePrefetchPredictor::URLRequestSummary summary; | 116 ResourcePrefetchPredictor::URLRequestSummary summary; |
| 116 summary.navigation_id = CreateNavigationID(process_id, render_frame_id, | 117 summary.navigation_id = CreateNavigationID(process_id, render_frame_id, |
| 117 main_frame_url); | 118 main_frame_url); |
| 118 summary.resource_url = GURL(resource_url); | 119 summary.resource_url = GURL(resource_url); |
| 119 summary.resource_type = resource_type; | 120 summary.resource_type = resource_type; |
| 121 summary.priority = priority; |
| 120 summary.mime_type = mime_type; | 122 summary.mime_type = mime_type; |
| 121 summary.was_cached = was_cached; | 123 summary.was_cached = was_cached; |
| 122 return summary; | 124 return summary; |
| 123 } | 125 } |
| 124 | 126 |
| 125 void InitializePredictor() { | 127 void InitializePredictor() { |
| 126 predictor_->StartInitialization(); | 128 predictor_->StartInitialization(); |
| 127 base::RunLoop loop; | 129 base::RunLoop loop; |
| 128 loop.RunUntilIdle(); // Runs the DB lookup. | 130 loop.RunUntilIdle(); // Runs the DB lookup. |
| 129 profile_->BlockUntilHistoryProcessesPendingRequests(); | 131 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 | 207 |
| 206 void ResourcePrefetchPredictorTest::TearDown() { | 208 void ResourcePrefetchPredictorTest::TearDown() { |
| 207 predictor_.reset(NULL); | 209 predictor_.reset(NULL); |
| 208 profile_->DestroyHistoryService(); | 210 profile_->DestroyHistoryService(); |
| 209 } | 211 } |
| 210 | 212 |
| 211 void ResourcePrefetchPredictorTest::InitializeSampleData() { | 213 void ResourcePrefetchPredictorTest::InitializeSampleData() { |
| 212 { // Url data. | 214 { // Url data. |
| 213 PrefetchData google(PREFETCH_KEY_TYPE_URL, "http://www.google.com/"); | 215 PrefetchData google(PREFETCH_KEY_TYPE_URL, "http://www.google.com/"); |
| 214 google.last_visit = base::Time::FromInternalValue(1); | 216 google.last_visit = base::Time::FromInternalValue(1); |
| 215 google.resources.push_back(ResourceRow(std::string(), | 217 google.resources.push_back(ResourceRow( |
| 216 "http://google.com/style1.css", | 218 std::string(), "http://google.com/style1.css", |
| 217 content::RESOURCE_TYPE_STYLESHEET, | 219 content::RESOURCE_TYPE_STYLESHEET, 3, 2, 1, 1.0, net::MEDIUM)); |
| 218 3, | 220 google.resources.push_back( |
| 219 2, | 221 ResourceRow(std::string(), "http://google.com/script3.js", |
| 220 1, | 222 content::RESOURCE_TYPE_SCRIPT, 4, 0, 1, 2.1, net::MEDIUM)); |
| 221 1.0)); | 223 google.resources.push_back( |
| 222 google.resources.push_back(ResourceRow(std::string(), | 224 ResourceRow(std::string(), "http://google.com/script4.js", |
| 223 "http://google.com/script3.js", | 225 content::RESOURCE_TYPE_SCRIPT, 11, 0, 0, 2.1, net::MEDIUM)); |
| 224 content::RESOURCE_TYPE_SCRIPT, | 226 google.resources.push_back( |
| 225 4, | 227 ResourceRow(std::string(), "http://google.com/image1.png", |
| 226 0, | 228 content::RESOURCE_TYPE_IMAGE, 6, 3, 0, 2.2, net::MEDIUM)); |
| 227 1, | 229 google.resources.push_back(ResourceRow( |
| 228 2.1)); | 230 std::string(), "http://google.com/a.font", |
| 229 google.resources.push_back(ResourceRow(std::string(), | 231 content::RESOURCE_TYPE_LAST_TYPE, 2, 0, 0, 5.1, net::MEDIUM)); |
| 230 "http://google.com/script4.js", | |
| 231 content::RESOURCE_TYPE_SCRIPT, | |
| 232 11, | |
| 233 0, | |
| 234 0, | |
| 235 2.1)); | |
| 236 google.resources.push_back(ResourceRow(std::string(), | |
| 237 "http://google.com/image1.png", | |
| 238 content::RESOURCE_TYPE_IMAGE, | |
| 239 6, | |
| 240 3, | |
| 241 0, | |
| 242 2.2)); | |
| 243 google.resources.push_back(ResourceRow(std::string(), | |
| 244 "http://google.com/a.font", | |
| 245 content::RESOURCE_TYPE_LAST_TYPE, | |
| 246 2, | |
| 247 0, | |
| 248 0, | |
| 249 5.1)); | |
| 250 | 232 |
| 251 PrefetchData reddit(PREFETCH_KEY_TYPE_URL, "http://www.reddit.com/"); | 233 PrefetchData reddit(PREFETCH_KEY_TYPE_URL, "http://www.reddit.com/"); |
| 252 reddit.last_visit = base::Time::FromInternalValue(2); | 234 reddit.last_visit = base::Time::FromInternalValue(2); |
| 253 reddit.resources | 235 reddit.resources.push_back( |
| 254 .push_back(ResourceRow(std::string(), | 236 ResourceRow(std::string(), "http://reddit-resource.com/script1.js", |
| 255 "http://reddit-resource.com/script1.js", | 237 content::RESOURCE_TYPE_SCRIPT, 4, 0, 1, 1.0, net::MEDIUM)); |
| 256 content::RESOURCE_TYPE_SCRIPT, | 238 reddit.resources.push_back( |
| 257 4, | 239 ResourceRow(std::string(), "http://reddit-resource.com/script2.js", |
| 258 0, | 240 content::RESOURCE_TYPE_SCRIPT, 2, 0, 0, 2.1, net::MEDIUM)); |
| 259 1, | |
| 260 1.0)); | |
| 261 reddit.resources | |
| 262 .push_back(ResourceRow(std::string(), | |
| 263 "http://reddit-resource.com/script2.js", | |
| 264 content::RESOURCE_TYPE_SCRIPT, | |
| 265 2, | |
| 266 0, | |
| 267 0, | |
| 268 2.1)); | |
| 269 | 241 |
| 270 PrefetchData yahoo(PREFETCH_KEY_TYPE_URL, "http://www.yahoo.com/"); | 242 PrefetchData yahoo(PREFETCH_KEY_TYPE_URL, "http://www.yahoo.com/"); |
| 271 yahoo.last_visit = base::Time::FromInternalValue(3); | 243 yahoo.last_visit = base::Time::FromInternalValue(3); |
| 272 yahoo.resources.push_back(ResourceRow(std::string(), | 244 yahoo.resources.push_back( |
| 273 "http://google.com/image.png", | 245 ResourceRow(std::string(), "http://google.com/image.png", |
| 274 content::RESOURCE_TYPE_IMAGE, | 246 content::RESOURCE_TYPE_IMAGE, 20, 1, 0, 10.0, net::MEDIUM)); |
| 275 20, | |
| 276 1, | |
| 277 0, | |
| 278 10.0)); | |
| 279 | 247 |
| 280 test_url_data_.clear(); | 248 test_url_data_.clear(); |
| 281 test_url_data_.insert(std::make_pair("http://www.google.com/", google)); | 249 test_url_data_.insert(std::make_pair("http://www.google.com/", google)); |
| 282 test_url_data_.insert(std::make_pair("http://www.reddit.com/", reddit)); | 250 test_url_data_.insert(std::make_pair("http://www.reddit.com/", reddit)); |
| 283 test_url_data_.insert(std::make_pair("http://www.yahoo.com/", yahoo)); | 251 test_url_data_.insert(std::make_pair("http://www.yahoo.com/", yahoo)); |
| 284 } | 252 } |
| 285 | 253 |
| 286 { // Host data. | 254 { // Host data. |
| 287 PrefetchData facebook(PREFETCH_KEY_TYPE_HOST, "www.facebook.com"); | 255 PrefetchData facebook(PREFETCH_KEY_TYPE_HOST, "www.facebook.com"); |
| 288 facebook.last_visit = base::Time::FromInternalValue(4); | 256 facebook.last_visit = base::Time::FromInternalValue(4); |
| 289 facebook.resources | 257 facebook.resources.push_back(ResourceRow( |
| 290 .push_back(ResourceRow(std::string(), | 258 std::string(), "http://www.facebook.com/style.css", |
| 291 "http://www.facebook.com/style.css", | 259 content::RESOURCE_TYPE_STYLESHEET, 5, 2, 1, 1.1, net::MEDIUM)); |
| 292 content::RESOURCE_TYPE_STYLESHEET, | 260 facebook.resources.push_back( |
| 293 5, | 261 ResourceRow(std::string(), "http://www.facebook.com/script.js", |
| 294 2, | 262 content::RESOURCE_TYPE_SCRIPT, 4, 0, 1, 2.1, net::MEDIUM)); |
| 295 1, | 263 facebook.resources.push_back( |
| 296 1.1)); | 264 ResourceRow(std::string(), "http://www.facebook.com/image.png", |
| 297 facebook.resources | 265 content::RESOURCE_TYPE_IMAGE, 6, 3, 0, 2.2, net::MEDIUM)); |
| 298 .push_back(ResourceRow(std::string(), | 266 facebook.resources.push_back(ResourceRow( |
| 299 "http://www.facebook.com/script.js", | 267 std::string(), "http://www.facebook.com/a.font", |
| 300 content::RESOURCE_TYPE_SCRIPT, | 268 content::RESOURCE_TYPE_LAST_TYPE, 2, 0, 0, 5.1, net::MEDIUM)); |
| 301 4, | 269 facebook.resources.push_back(ResourceRow( |
| 302 0, | 270 std::string(), "http://www.resources.facebook.com/script.js", |
| 303 1, | 271 content::RESOURCE_TYPE_SCRIPT, 11, 0, 0, 8.5, net::MEDIUM)); |
| 304 2.1)); | |
| 305 facebook.resources | |
| 306 .push_back(ResourceRow(std::string(), | |
| 307 "http://www.facebook.com/image.png", | |
| 308 content::RESOURCE_TYPE_IMAGE, | |
| 309 6, | |
| 310 3, | |
| 311 0, | |
| 312 2.2)); | |
| 313 facebook.resources.push_back(ResourceRow(std::string(), | |
| 314 "http://www.facebook.com/a.font", | |
| 315 content::RESOURCE_TYPE_LAST_TYPE, | |
| 316 2, | |
| 317 0, | |
| 318 0, | |
| 319 5.1)); | |
| 320 facebook.resources | |
| 321 .push_back(ResourceRow(std::string(), | |
| 322 "http://www.resources.facebook.com/script.js", | |
| 323 content::RESOURCE_TYPE_SCRIPT, | |
| 324 11, | |
| 325 0, | |
| 326 0, | |
| 327 8.5)); | |
| 328 | 272 |
| 329 PrefetchData yahoo(PREFETCH_KEY_TYPE_HOST, "www.yahoo.com"); | 273 PrefetchData yahoo(PREFETCH_KEY_TYPE_HOST, "www.yahoo.com"); |
| 330 yahoo.last_visit = base::Time::FromInternalValue(5); | 274 yahoo.last_visit = base::Time::FromInternalValue(5); |
| 331 yahoo.resources.push_back(ResourceRow(std::string(), | 275 yahoo.resources.push_back( |
| 332 "http://google.com/image.png", | 276 ResourceRow(std::string(), "http://google.com/image.png", |
| 333 content::RESOURCE_TYPE_IMAGE, | 277 content::RESOURCE_TYPE_IMAGE, 20, 1, 0, 10.0, net::MEDIUM)); |
| 334 20, | |
| 335 1, | |
| 336 0, | |
| 337 10.0)); | |
| 338 | 278 |
| 339 test_host_data_.clear(); | 279 test_host_data_.clear(); |
| 340 test_host_data_.insert(std::make_pair("www.facebook.com", facebook)); | 280 test_host_data_.insert(std::make_pair("www.facebook.com", facebook)); |
| 341 test_host_data_.insert(std::make_pair("www.yahoo.com", yahoo)); | 281 test_host_data_.insert(std::make_pair("www.yahoo.com", yahoo)); |
| 342 } | 282 } |
| 343 } | 283 } |
| 344 | 284 |
| 345 TEST_F(ResourcePrefetchPredictorTest, LazilyInitializeEmpty) { | 285 TEST_F(ResourcePrefetchPredictorTest, LazilyInitializeEmpty) { |
| 346 // Tests that the predictor initializes correctly without any data. | 286 // Tests that the predictor initializes correctly without any data. |
| 347 EXPECT_TRUE(predictor_->url_table_cache_->empty()); | 287 EXPECT_TRUE(predictor_->url_table_cache_->empty()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 368 EXPECT_TRUE(predictor_->inflight_navigations_.empty()); | 308 EXPECT_TRUE(predictor_->inflight_navigations_.empty()); |
| 369 | 309 |
| 370 EXPECT_EQ(test_url_data_, *predictor_->url_table_cache_); | 310 EXPECT_EQ(test_url_data_, *predictor_->url_table_cache_); |
| 371 EXPECT_EQ(test_host_data_, *predictor_->host_table_cache_); | 311 EXPECT_EQ(test_host_data_, *predictor_->host_table_cache_); |
| 372 } | 312 } |
| 373 | 313 |
| 374 TEST_F(ResourcePrefetchPredictorTest, NavigationNotRecorded) { | 314 TEST_F(ResourcePrefetchPredictorTest, NavigationNotRecorded) { |
| 375 // Single navigation but history count is low, so should not record. | 315 // Single navigation but history count is low, so should not record. |
| 376 AddUrlToHistory("http://www.google.com", 1); | 316 AddUrlToHistory("http://www.google.com", 1); |
| 377 | 317 |
| 378 URLRequestSummary main_frame = | 318 URLRequestSummary main_frame = CreateURLRequestSummary( |
| 379 CreateURLRequestSummary(1, | 319 1, 1, "http://www.google.com", "http://www.google.com", |
| 380 1, | 320 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); |
| 381 "http://www.google.com", | |
| 382 "http://www.google.com", | |
| 383 content::RESOURCE_TYPE_MAIN_FRAME, | |
| 384 std::string(), | |
| 385 false); | |
| 386 predictor_->RecordURLRequest(main_frame); | 321 predictor_->RecordURLRequest(main_frame); |
| 387 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 322 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
| 388 | 323 |
| 389 // Now add a few subresources. | 324 // Now add a few subresources. |
| 390 URLRequestSummary resource1 = CreateURLRequestSummary( | 325 URLRequestSummary resource1 = CreateURLRequestSummary( |
| 391 1, 1, "http://www.google.com", "http://google.com/style1.css", | 326 1, 1, "http://www.google.com", "http://google.com/style1.css", |
| 392 content::RESOURCE_TYPE_STYLESHEET, "text/css", false); | 327 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); |
| 393 predictor_->RecordURLResponse(resource1); | 328 predictor_->RecordURLResponse(resource1); |
| 394 URLRequestSummary resource2 = CreateURLRequestSummary( | 329 URLRequestSummary resource2 = CreateURLRequestSummary( |
| 395 1, 1, "http://www.google.com", "http://google.com/script1.js", | 330 1, 1, "http://www.google.com", "http://google.com/script1.js", |
| 396 content::RESOURCE_TYPE_SCRIPT, "text/javascript", false); | 331 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); |
| 397 predictor_->RecordURLResponse(resource2); | 332 predictor_->RecordURLResponse(resource2); |
| 398 URLRequestSummary resource3 = CreateURLRequestSummary( | 333 URLRequestSummary resource3 = CreateURLRequestSummary( |
| 399 1, 1, "http://www.google.com", "http://google.com/script2.js", | 334 1, 1, "http://www.google.com", "http://google.com/script2.js", |
| 400 content::RESOURCE_TYPE_SCRIPT, "text/javascript", false); | 335 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); |
| 401 predictor_->RecordURLResponse(resource3); | 336 predictor_->RecordURLResponse(resource3); |
| 402 | 337 |
| 403 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com"); | 338 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com"); |
| 404 host_data.resources.push_back(ResourceRow(std::string(), | 339 host_data.resources.push_back(ResourceRow( |
| 405 "http://google.com/style1.css", | 340 std::string(), "http://google.com/style1.css", |
| 406 content::RESOURCE_TYPE_STYLESHEET, | 341 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, net::MEDIUM)); |
| 407 1, | 342 host_data.resources.push_back( |
| 408 0, | 343 ResourceRow(std::string(), "http://google.com/script1.js", |
| 409 0, | 344 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM)); |
| 410 1.0)); | 345 host_data.resources.push_back( |
| 411 host_data.resources.push_back(ResourceRow(std::string(), | 346 ResourceRow(std::string(), "http://google.com/script2.js", |
| 412 "http://google.com/script1.js", | 347 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM)); |
| 413 content::RESOURCE_TYPE_SCRIPT, | |
| 414 1, | |
| 415 0, | |
| 416 0, | |
| 417 2.0)); | |
| 418 host_data.resources.push_back(ResourceRow(std::string(), | |
| 419 "http://google.com/script2.js", | |
| 420 content::RESOURCE_TYPE_SCRIPT, | |
| 421 1, | |
| 422 0, | |
| 423 0, | |
| 424 3.0)); | |
| 425 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); | 348 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); |
| 426 | 349 |
| 427 predictor_->OnNavigationComplete(main_frame.navigation_id); | 350 predictor_->OnNavigationComplete(main_frame.navigation_id); |
| 428 profile_->BlockUntilHistoryProcessesPendingRequests(); | 351 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 429 } | 352 } |
| 430 | 353 |
| 431 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDB) { | 354 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDB) { |
| 432 // Single navigation that will be recorded. Will check for duplicate | 355 // Single navigation that will be recorded. Will check for duplicate |
| 433 // resources and also for number of resources saved. | 356 // resources and also for number of resources saved. |
| 434 AddUrlToHistory("http://www.google.com", 4); | 357 AddUrlToHistory("http://www.google.com", 4); |
| 435 | 358 |
| 436 URLRequestSummary main_frame = | 359 URLRequestSummary main_frame = CreateURLRequestSummary( |
| 437 CreateURLRequestSummary(1, | 360 1, 1, "http://www.google.com", "http://www.google.com", |
| 438 1, | 361 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); |
| 439 "http://www.google.com", | |
| 440 "http://www.google.com", | |
| 441 content::RESOURCE_TYPE_MAIN_FRAME, | |
| 442 std::string(), | |
| 443 false); | |
| 444 predictor_->RecordURLRequest(main_frame); | 362 predictor_->RecordURLRequest(main_frame); |
| 445 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 363 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
| 446 | 364 |
| 447 URLRequestSummary resource1 = CreateURLRequestSummary( | 365 URLRequestSummary resource1 = CreateURLRequestSummary( |
| 448 1, 1, "http://www.google.com", "http://google.com/style1.css", | 366 1, 1, "http://www.google.com", "http://google.com/style1.css", |
| 449 content::RESOURCE_TYPE_STYLESHEET, "text/css", false); | 367 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); |
| 450 predictor_->RecordURLResponse(resource1); | 368 predictor_->RecordURLResponse(resource1); |
| 451 URLRequestSummary resource2 = CreateURLRequestSummary( | 369 URLRequestSummary resource2 = CreateURLRequestSummary( |
| 452 1, 1, "http://www.google.com", "http://google.com/script1.js", | 370 1, 1, "http://www.google.com", "http://google.com/script1.js", |
| 453 content::RESOURCE_TYPE_SCRIPT, "text/javascript", false); | 371 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); |
| 454 predictor_->RecordURLResponse(resource2); | 372 predictor_->RecordURLResponse(resource2); |
| 455 URLRequestSummary resource3 = CreateURLRequestSummary( | 373 URLRequestSummary resource3 = CreateURLRequestSummary( |
| 456 1, 1, "http://www.google.com", "http://google.com/script2.js", | 374 1, 1, "http://www.google.com", "http://google.com/script2.js", |
| 457 content::RESOURCE_TYPE_SCRIPT, "text/javascript", false); | 375 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); |
| 458 predictor_->RecordURLResponse(resource3); | 376 predictor_->RecordURLResponse(resource3); |
| 459 URLRequestSummary resource4 = CreateURLRequestSummary( | 377 URLRequestSummary resource4 = CreateURLRequestSummary( |
| 460 1, 1, "http://www.google.com", "http://google.com/script1.js", | 378 1, 1, "http://www.google.com", "http://google.com/script1.js", |
| 461 content::RESOURCE_TYPE_SCRIPT, "text/javascript", true); | 379 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", true); |
| 462 predictor_->RecordURLResponse(resource4); | 380 predictor_->RecordURLResponse(resource4); |
| 463 URLRequestSummary resource5 = CreateURLRequestSummary( | 381 URLRequestSummary resource5 = CreateURLRequestSummary( |
| 464 1, 1, "http://www.google.com", "http://google.com/image1.png", | 382 1, 1, "http://www.google.com", "http://google.com/image1.png", |
| 465 content::RESOURCE_TYPE_IMAGE, "image/png", false); | 383 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false); |
| 466 predictor_->RecordURLResponse(resource5); | 384 predictor_->RecordURLResponse(resource5); |
| 467 URLRequestSummary resource6 = CreateURLRequestSummary( | 385 URLRequestSummary resource6 = CreateURLRequestSummary( |
| 468 1, 1, "http://www.google.com", "http://google.com/image2.png", | 386 1, 1, "http://www.google.com", "http://google.com/image2.png", |
| 469 content::RESOURCE_TYPE_IMAGE, "image/png", false); | 387 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false); |
| 470 predictor_->RecordURLResponse(resource6); | 388 predictor_->RecordURLResponse(resource6); |
| 471 URLRequestSummary resource7 = CreateURLRequestSummary( | 389 URLRequestSummary resource7 = CreateURLRequestSummary( |
| 472 1, 1, "http://www.google.com", "http://google.com/style2.css", | 390 1, 1, "http://www.google.com", "http://google.com/style2.css", |
| 473 content::RESOURCE_TYPE_STYLESHEET, "text/css", true); | 391 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true); |
| 474 predictor_->RecordURLResponse(resource7); | 392 predictor_->RecordURLResponse(resource7); |
| 475 | 393 |
| 476 PrefetchData url_data(PREFETCH_KEY_TYPE_URL, "http://www.google.com/"); | 394 PrefetchData url_data(PREFETCH_KEY_TYPE_URL, "http://www.google.com/"); |
| 477 url_data.resources.push_back(ResourceRow(std::string(), | 395 url_data.resources.push_back(ResourceRow( |
| 478 "http://google.com/style1.css", | 396 std::string(), "http://google.com/style1.css", |
| 479 content::RESOURCE_TYPE_STYLESHEET, | 397 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, net::MEDIUM)); |
| 480 1, | 398 url_data.resources.push_back( |
| 481 0, | 399 ResourceRow(std::string(), "http://google.com/script1.js", |
| 482 0, | 400 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM)); |
| 483 1.0)); | 401 url_data.resources.push_back( |
| 484 url_data.resources.push_back(ResourceRow(std::string(), | 402 ResourceRow(std::string(), "http://google.com/script2.js", |
| 485 "http://google.com/script1.js", | 403 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM)); |
| 486 content::RESOURCE_TYPE_SCRIPT, | 404 url_data.resources.push_back(ResourceRow( |
| 487 1, | 405 std::string(), "http://google.com/style2.css", |
| 488 0, | 406 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 7.0, net::MEDIUM)); |
| 489 0, | |
| 490 2.0)); | |
| 491 url_data.resources.push_back(ResourceRow(std::string(), | |
| 492 "http://google.com/script2.js", | |
| 493 content::RESOURCE_TYPE_SCRIPT, | |
| 494 1, | |
| 495 0, | |
| 496 0, | |
| 497 3.0)); | |
| 498 url_data.resources.push_back(ResourceRow(std::string(), | |
| 499 "http://google.com/style2.css", | |
| 500 content::RESOURCE_TYPE_STYLESHEET, | |
| 501 1, | |
| 502 0, | |
| 503 0, | |
| 504 7.0)); | |
| 505 EXPECT_CALL(*mock_tables_.get(), UpdateData(url_data, empty_host_data_)); | 407 EXPECT_CALL(*mock_tables_.get(), UpdateData(url_data, empty_host_data_)); |
| 506 | 408 |
| 507 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com"); | 409 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com"); |
| 508 host_data.resources = url_data.resources; | 410 host_data.resources = url_data.resources; |
| 509 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); | 411 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); |
| 510 | 412 |
| 511 predictor_->OnNavigationComplete(main_frame.navigation_id); | 413 predictor_->OnNavigationComplete(main_frame.navigation_id); |
| 512 profile_->BlockUntilHistoryProcessesPendingRequests(); | 414 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 513 } | 415 } |
| 514 | 416 |
| 515 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlInDB) { | 417 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlInDB) { |
| 516 // Tests that navigation is recorded correctly for URL already present in | 418 // Tests that navigation is recorded correctly for URL already present in |
| 517 // the database cache. | 419 // the database cache. |
| 518 AddUrlToHistory("http://www.google.com", 4); | 420 AddUrlToHistory("http://www.google.com", 4); |
| 519 | 421 |
| 520 EXPECT_CALL(*mock_tables_.get(), | 422 EXPECT_CALL(*mock_tables_.get(), |
| 521 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), | 423 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), |
| 522 Pointee(ContainerEq(PrefetchDataMap())))) | 424 Pointee(ContainerEq(PrefetchDataMap())))) |
| 523 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_), | 425 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_), |
| 524 SetArgPointee<1>(test_host_data_))); | 426 SetArgPointee<1>(test_host_data_))); |
| 525 ResetPredictor(); | 427 ResetPredictor(); |
| 526 InitializePredictor(); | 428 InitializePredictor(); |
| 527 EXPECT_EQ(3U, predictor_->url_table_cache_->size()); | 429 EXPECT_EQ(3U, predictor_->url_table_cache_->size()); |
| 528 EXPECT_EQ(2U, predictor_->host_table_cache_->size()); | 430 EXPECT_EQ(2U, predictor_->host_table_cache_->size()); |
| 529 | 431 |
| 530 URLRequestSummary main_frame = | 432 URLRequestSummary main_frame = CreateURLRequestSummary( |
| 531 CreateURLRequestSummary(1, | 433 1, 1, "http://www.google.com", "http://www.google.com", |
| 532 1, | 434 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); |
| 533 "http://www.google.com", | |
| 534 "http://www.google.com", | |
| 535 content::RESOURCE_TYPE_MAIN_FRAME, | |
| 536 std::string(), | |
| 537 false); | |
| 538 predictor_->RecordURLRequest(main_frame); | 435 predictor_->RecordURLRequest(main_frame); |
| 539 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 436 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
| 540 | 437 |
| 541 URLRequestSummary resource1 = CreateURLRequestSummary( | 438 URLRequestSummary resource1 = CreateURLRequestSummary( |
| 542 1, 1, "http://www.google.com", "http://google.com/style1.css", | 439 1, 1, "http://www.google.com", "http://google.com/style1.css", |
| 543 content::RESOURCE_TYPE_STYLESHEET, "text/css", false); | 440 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); |
| 544 predictor_->RecordURLResponse(resource1); | 441 predictor_->RecordURLResponse(resource1); |
| 545 URLRequestSummary resource2 = CreateURLRequestSummary( | 442 URLRequestSummary resource2 = CreateURLRequestSummary( |
| 546 1, 1, "http://www.google.com", "http://google.com/script1.js", | 443 1, 1, "http://www.google.com", "http://google.com/script1.js", |
| 547 content::RESOURCE_TYPE_SCRIPT, "text/javascript", false); | 444 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); |
| 548 predictor_->RecordURLResponse(resource2); | 445 predictor_->RecordURLResponse(resource2); |
| 549 URLRequestSummary resource3 = CreateURLRequestSummary( | 446 URLRequestSummary resource3 = CreateURLRequestSummary( |
| 550 1, 1, "http://www.google.com", "http://google.com/script2.js", | 447 1, 1, "http://www.google.com", "http://google.com/script2.js", |
| 551 content::RESOURCE_TYPE_SCRIPT, "text/javascript", false); | 448 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); |
| 552 predictor_->RecordURLResponse(resource3); | 449 predictor_->RecordURLResponse(resource3); |
| 553 URLRequestSummary resource4 = CreateURLRequestSummary( | 450 URLRequestSummary resource4 = CreateURLRequestSummary( |
| 554 1, 1, "http://www.google.com", "http://google.com/script1.js", | 451 1, 1, "http://www.google.com", "http://google.com/script1.js", |
| 555 content::RESOURCE_TYPE_SCRIPT, "text/javascript", true); | 452 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", true); |
| 556 predictor_->RecordURLResponse(resource4); | 453 predictor_->RecordURLResponse(resource4); |
| 557 URLRequestSummary resource5 = CreateURLRequestSummary( | 454 URLRequestSummary resource5 = CreateURLRequestSummary( |
| 558 1, 1, "http://www.google.com", "http://google.com/image1.png", | 455 1, 1, "http://www.google.com", "http://google.com/image1.png", |
| 559 content::RESOURCE_TYPE_IMAGE, "image/png", false); | 456 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false); |
| 560 predictor_->RecordURLResponse(resource5); | 457 predictor_->RecordURLResponse(resource5); |
| 561 URLRequestSummary resource6 = CreateURLRequestSummary( | 458 URLRequestSummary resource6 = CreateURLRequestSummary( |
| 562 1, 1, "http://www.google.com", "http://google.com/image2.png", | 459 1, 1, "http://www.google.com", "http://google.com/image2.png", |
| 563 content::RESOURCE_TYPE_IMAGE, "image/png", false); | 460 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false); |
| 564 predictor_->RecordURLResponse(resource6); | 461 predictor_->RecordURLResponse(resource6); |
| 565 URLRequestSummary resource7 = CreateURLRequestSummary( | 462 URLRequestSummary resource7 = CreateURLRequestSummary( |
| 566 1, 1, "http://www.google.com", "http://google.com/style2.css", | 463 1, 1, "http://www.google.com", "http://google.com/style2.css", |
| 567 content::RESOURCE_TYPE_STYLESHEET, "text/css", true); | 464 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true); |
| 568 predictor_->RecordURLResponse(resource7); | 465 predictor_->RecordURLResponse(resource7); |
| 569 | 466 |
| 570 PrefetchData url_data(PREFETCH_KEY_TYPE_URL, "http://www.google.com/"); | 467 PrefetchData url_data(PREFETCH_KEY_TYPE_URL, "http://www.google.com/"); |
| 571 url_data.resources.push_back(ResourceRow(std::string(), | 468 url_data.resources.push_back(ResourceRow( |
| 572 "http://google.com/style1.css", | 469 std::string(), "http://google.com/style1.css", |
| 573 content::RESOURCE_TYPE_STYLESHEET, | 470 content::RESOURCE_TYPE_STYLESHEET, 4, 2, 0, 1.0, net::MEDIUM)); |
| 574 4, | 471 url_data.resources.push_back( |
| 575 2, | 472 ResourceRow(std::string(), "http://google.com/script1.js", |
| 576 0, | 473 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM)); |
| 577 1.0)); | 474 url_data.resources.push_back( |
| 578 url_data.resources.push_back(ResourceRow(std::string(), | 475 ResourceRow(std::string(), "http://google.com/script4.js", |
| 579 "http://google.com/script1.js", | 476 content::RESOURCE_TYPE_SCRIPT, 11, 1, 1, 2.1, net::MEDIUM)); |
| 580 content::RESOURCE_TYPE_SCRIPT, | 477 url_data.resources.push_back( |
| 581 1, | 478 ResourceRow(std::string(), "http://google.com/script2.js", |
| 582 0, | 479 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM)); |
| 583 0, | |
| 584 2.0)); | |
| 585 url_data.resources.push_back(ResourceRow(std::string(), | |
| 586 "http://google.com/script4.js", | |
| 587 content::RESOURCE_TYPE_SCRIPT, | |
| 588 11, | |
| 589 1, | |
| 590 1, | |
| 591 2.1)); | |
| 592 url_data.resources.push_back(ResourceRow(std::string(), | |
| 593 "http://google.com/script2.js", | |
| 594 content::RESOURCE_TYPE_SCRIPT, | |
| 595 1, | |
| 596 0, | |
| 597 0, | |
| 598 3.0)); | |
| 599 EXPECT_CALL(*mock_tables_.get(), UpdateData(url_data, empty_host_data_)); | 480 EXPECT_CALL(*mock_tables_.get(), UpdateData(url_data, empty_host_data_)); |
| 600 | 481 |
| 601 EXPECT_CALL( | 482 EXPECT_CALL( |
| 602 *mock_tables_.get(), | 483 *mock_tables_.get(), |
| 603 DeleteSingleDataPoint("www.facebook.com", PREFETCH_KEY_TYPE_HOST)); | 484 DeleteSingleDataPoint("www.facebook.com", PREFETCH_KEY_TYPE_HOST)); |
| 604 | 485 |
| 605 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com"); | 486 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com"); |
| 606 host_data.resources.push_back(ResourceRow(std::string(), | 487 host_data.resources.push_back(ResourceRow( |
| 607 "http://google.com/style1.css", | 488 std::string(), "http://google.com/style1.css", |
| 608 content::RESOURCE_TYPE_STYLESHEET, | 489 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, net::MEDIUM)); |
| 609 1, | 490 host_data.resources.push_back( |
| 610 0, | 491 ResourceRow(std::string(), "http://google.com/script1.js", |
| 611 0, | 492 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM)); |
| 612 1.0)); | 493 host_data.resources.push_back( |
| 613 host_data.resources.push_back(ResourceRow(std::string(), | 494 ResourceRow(std::string(), "http://google.com/script2.js", |
| 614 "http://google.com/script1.js", | 495 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM)); |
| 615 content::RESOURCE_TYPE_SCRIPT, | 496 host_data.resources.push_back(ResourceRow( |
| 616 1, | 497 std::string(), "http://google.com/style2.css", |
| 617 0, | 498 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 7.0, net::MEDIUM)); |
| 618 0, | |
| 619 2.0)); | |
| 620 host_data.resources.push_back(ResourceRow(std::string(), | |
| 621 "http://google.com/script2.js", | |
| 622 content::RESOURCE_TYPE_SCRIPT, | |
| 623 1, | |
| 624 0, | |
| 625 0, | |
| 626 3.0)); | |
| 627 host_data.resources.push_back(ResourceRow(std::string(), | |
| 628 "http://google.com/style2.css", | |
| 629 content::RESOURCE_TYPE_STYLESHEET, | |
| 630 1, | |
| 631 0, | |
| 632 0, | |
| 633 7.0)); | |
| 634 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); | 499 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); |
| 635 | 500 |
| 636 predictor_->OnNavigationComplete(main_frame.navigation_id); | 501 predictor_->OnNavigationComplete(main_frame.navigation_id); |
| 637 profile_->BlockUntilHistoryProcessesPendingRequests(); | 502 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 638 } | 503 } |
| 639 | 504 |
| 640 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDBAndDBFull) { | 505 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDBAndDBFull) { |
| 641 // Tests that a URL is deleted before another is added if the cache is full. | 506 // Tests that a URL is deleted before another is added if the cache is full. |
| 642 AddUrlToHistory("http://www.nike.com/", 4); | 507 AddUrlToHistory("http://www.nike.com/", 4); |
| 643 | 508 |
| 644 EXPECT_CALL(*mock_tables_.get(), | 509 EXPECT_CALL(*mock_tables_.get(), |
| 645 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), | 510 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), |
| 646 Pointee(ContainerEq(PrefetchDataMap())))) | 511 Pointee(ContainerEq(PrefetchDataMap())))) |
| 647 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_), | 512 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_), |
| 648 SetArgPointee<1>(test_host_data_))); | 513 SetArgPointee<1>(test_host_data_))); |
| 649 ResetPredictor(); | 514 ResetPredictor(); |
| 650 InitializePredictor(); | 515 InitializePredictor(); |
| 651 EXPECT_EQ(3U, predictor_->url_table_cache_->size()); | 516 EXPECT_EQ(3U, predictor_->url_table_cache_->size()); |
| 652 EXPECT_EQ(2U, predictor_->host_table_cache_->size()); | 517 EXPECT_EQ(2U, predictor_->host_table_cache_->size()); |
| 653 | 518 |
| 654 URLRequestSummary main_frame = | 519 URLRequestSummary main_frame = CreateURLRequestSummary( |
| 655 CreateURLRequestSummary(1, | 520 1, 1, "http://www.nike.com", "http://www.nike.com", |
| 656 1, | 521 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); |
| 657 "http://www.nike.com", | |
| 658 "http://www.nike.com", | |
| 659 content::RESOURCE_TYPE_MAIN_FRAME, | |
| 660 std::string(), | |
| 661 false); | |
| 662 predictor_->RecordURLRequest(main_frame); | 522 predictor_->RecordURLRequest(main_frame); |
| 663 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 523 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
| 664 | 524 |
| 665 URLRequestSummary resource1 = CreateURLRequestSummary( | 525 URLRequestSummary resource1 = CreateURLRequestSummary( |
| 666 1, 1, "http://www.nike.com", "http://nike.com/style1.css", | 526 1, 1, "http://www.nike.com", "http://nike.com/style1.css", |
| 667 content::RESOURCE_TYPE_STYLESHEET, "text/css", false); | 527 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); |
| 668 predictor_->RecordURLResponse(resource1); | 528 predictor_->RecordURLResponse(resource1); |
| 669 URLRequestSummary resource2 = CreateURLRequestSummary( | 529 URLRequestSummary resource2 = CreateURLRequestSummary( |
| 670 1, 1, "http://www.nike.com", "http://nike.com/image2.png", | 530 1, 1, "http://www.nike.com", "http://nike.com/image2.png", |
| 671 content::RESOURCE_TYPE_IMAGE, "image/png", false); | 531 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false); |
| 672 predictor_->RecordURLResponse(resource2); | 532 predictor_->RecordURLResponse(resource2); |
| 673 | 533 |
| 674 EXPECT_CALL( | 534 EXPECT_CALL( |
| 675 *mock_tables_.get(), | 535 *mock_tables_.get(), |
| 676 DeleteSingleDataPoint("http://www.google.com/", PREFETCH_KEY_TYPE_URL)); | 536 DeleteSingleDataPoint("http://www.google.com/", PREFETCH_KEY_TYPE_URL)); |
| 677 EXPECT_CALL( | 537 EXPECT_CALL( |
| 678 *mock_tables_.get(), | 538 *mock_tables_.get(), |
| 679 DeleteSingleDataPoint("www.facebook.com", PREFETCH_KEY_TYPE_HOST)); | 539 DeleteSingleDataPoint("www.facebook.com", PREFETCH_KEY_TYPE_HOST)); |
| 680 | 540 |
| 681 PrefetchData url_data(PREFETCH_KEY_TYPE_URL, "http://www.nike.com/"); | 541 PrefetchData url_data(PREFETCH_KEY_TYPE_URL, "http://www.nike.com/"); |
| 682 url_data.resources.push_back(ResourceRow(std::string(), | 542 url_data.resources.push_back(ResourceRow( |
| 683 "http://nike.com/style1.css", | 543 std::string(), "http://nike.com/style1.css", |
| 684 content::RESOURCE_TYPE_STYLESHEET, | 544 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, net::MEDIUM)); |
| 685 1, | 545 url_data.resources.push_back( |
| 686 0, | 546 ResourceRow(std::string(), "http://nike.com/image2.png", |
| 687 0, | 547 content::RESOURCE_TYPE_IMAGE, 1, 0, 0, 2.0, net::MEDIUM)); |
| 688 1.0)); | |
| 689 url_data.resources.push_back(ResourceRow(std::string(), | |
| 690 "http://nike.com/image2.png", | |
| 691 content::RESOURCE_TYPE_IMAGE, | |
| 692 1, | |
| 693 0, | |
| 694 0, | |
| 695 2.0)); | |
| 696 EXPECT_CALL(*mock_tables_.get(), UpdateData(url_data, empty_host_data_)); | 548 EXPECT_CALL(*mock_tables_.get(), UpdateData(url_data, empty_host_data_)); |
| 697 | 549 |
| 698 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.nike.com"); | 550 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.nike.com"); |
| 699 host_data.resources = url_data.resources; | 551 host_data.resources = url_data.resources; |
| 700 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); | 552 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); |
| 701 | 553 |
| 702 predictor_->OnNavigationComplete(main_frame.navigation_id); | 554 predictor_->OnNavigationComplete(main_frame.navigation_id); |
| 703 profile_->BlockUntilHistoryProcessesPendingRequests(); | 555 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 704 } | 556 } |
| 705 | 557 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 EXPECT_EQ(1U, predictor_->host_table_cache_->size()); | 604 EXPECT_EQ(1U, predictor_->host_table_cache_->size()); |
| 753 | 605 |
| 754 EXPECT_CALL(*mock_tables_.get(), DeleteAllData()); | 606 EXPECT_CALL(*mock_tables_.get(), DeleteAllData()); |
| 755 | 607 |
| 756 predictor_->DeleteAllUrls(); | 608 predictor_->DeleteAllUrls(); |
| 757 EXPECT_TRUE(predictor_->url_table_cache_->empty()); | 609 EXPECT_TRUE(predictor_->url_table_cache_->empty()); |
| 758 EXPECT_TRUE(predictor_->host_table_cache_->empty()); | 610 EXPECT_TRUE(predictor_->host_table_cache_->empty()); |
| 759 } | 611 } |
| 760 | 612 |
| 761 TEST_F(ResourcePrefetchPredictorTest, OnMainFrameRequest) { | 613 TEST_F(ResourcePrefetchPredictorTest, OnMainFrameRequest) { |
| 762 URLRequestSummary summary1 = | 614 URLRequestSummary summary1 = CreateURLRequestSummary( |
| 763 CreateURLRequestSummary(1, | 615 1, 1, "http://www.google.com", "http://www.google.com", |
| 764 1, | 616 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); |
| 765 "http://www.google.com", | 617 URLRequestSummary summary2 = CreateURLRequestSummary( |
| 766 "http://www.google.com", | 618 1, 2, "http://www.google.com", "http://www.google.com", |
| 767 content::RESOURCE_TYPE_MAIN_FRAME, | 619 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); |
| 768 std::string(), | 620 URLRequestSummary summary3 = CreateURLRequestSummary( |
| 769 false); | 621 2, 1, "http://www.yahoo.com", "http://www.yahoo.com", |
| 770 URLRequestSummary summary2 = | 622 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); |
| 771 CreateURLRequestSummary(1, | |
| 772 2, | |
| 773 "http://www.google.com", | |
| 774 "http://www.google.com", | |
| 775 content::RESOURCE_TYPE_MAIN_FRAME, | |
| 776 std::string(), | |
| 777 false); | |
| 778 URLRequestSummary summary3 = | |
| 779 CreateURLRequestSummary(2, | |
| 780 1, | |
| 781 "http://www.yahoo.com", | |
| 782 "http://www.yahoo.com", | |
| 783 content::RESOURCE_TYPE_MAIN_FRAME, | |
| 784 std::string(), | |
| 785 false); | |
| 786 | 623 |
| 787 predictor_->OnMainFrameRequest(summary1); | 624 predictor_->OnMainFrameRequest(summary1); |
| 788 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 625 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
| 789 predictor_->OnMainFrameRequest(summary2); | 626 predictor_->OnMainFrameRequest(summary2); |
| 790 EXPECT_EQ(2U, predictor_->inflight_navigations_.size()); | 627 EXPECT_EQ(2U, predictor_->inflight_navigations_.size()); |
| 791 predictor_->OnMainFrameRequest(summary3); | 628 predictor_->OnMainFrameRequest(summary3); |
| 792 EXPECT_EQ(3U, predictor_->inflight_navigations_.size()); | 629 EXPECT_EQ(3U, predictor_->inflight_navigations_.size()); |
| 793 | 630 |
| 794 // Insert anther with same navigation id. It should replace. | 631 // Insert anther with same navigation id. It should replace. |
| 795 URLRequestSummary summary4 = | 632 URLRequestSummary summary4 = CreateURLRequestSummary( |
| 796 CreateURLRequestSummary(1, | 633 1, 1, "http://www.nike.com", "http://www.nike.com", |
| 797 1, | 634 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); |
| 798 "http://www.nike.com", | 635 URLRequestSummary summary5 = CreateURLRequestSummary( |
| 799 "http://www.nike.com", | 636 1, 2, "http://www.google.com", "http://www.google.com", |
| 800 content::RESOURCE_TYPE_MAIN_FRAME, | 637 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); |
| 801 std::string(), | |
| 802 false); | |
| 803 URLRequestSummary summary5 = | |
| 804 CreateURLRequestSummary(1, | |
| 805 2, | |
| 806 "http://www.google.com", | |
| 807 "http://www.google.com", | |
| 808 content::RESOURCE_TYPE_MAIN_FRAME, | |
| 809 std::string(), | |
| 810 false); | |
| 811 | 638 |
| 812 predictor_->OnMainFrameRequest(summary4); | 639 predictor_->OnMainFrameRequest(summary4); |
| 813 EXPECT_EQ(3U, predictor_->inflight_navigations_.size()); | 640 EXPECT_EQ(3U, predictor_->inflight_navigations_.size()); |
| 814 | 641 |
| 815 // Change this creation time so that it will go away on the next insert. | 642 // Change this creation time so that it will go away on the next insert. |
| 816 summary5.navigation_id.creation_time = base::TimeTicks::Now() - | 643 summary5.navigation_id.creation_time = base::TimeTicks::Now() - |
| 817 base::TimeDelta::FromDays(1); | 644 base::TimeDelta::FromDays(1); |
| 818 predictor_->OnMainFrameRequest(summary5); | 645 predictor_->OnMainFrameRequest(summary5); |
| 819 EXPECT_EQ(3U, predictor_->inflight_navigations_.size()); | 646 EXPECT_EQ(3U, predictor_->inflight_navigations_.size()); |
| 820 | 647 |
| 821 URLRequestSummary summary6 = | 648 URLRequestSummary summary6 = CreateURLRequestSummary( |
| 822 CreateURLRequestSummary(3, | 649 3, 1, "http://www.shoes.com", "http://www.shoes.com", |
| 823 1, | 650 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); |
| 824 "http://www.shoes.com", | |
| 825 "http://www.shoes.com", | |
| 826 content::RESOURCE_TYPE_MAIN_FRAME, | |
| 827 std::string(), | |
| 828 false); | |
| 829 predictor_->OnMainFrameRequest(summary6); | 651 predictor_->OnMainFrameRequest(summary6); |
| 830 EXPECT_EQ(3U, predictor_->inflight_navigations_.size()); | 652 EXPECT_EQ(3U, predictor_->inflight_navigations_.size()); |
| 831 | 653 |
| 832 EXPECT_TRUE(predictor_->inflight_navigations_.find(summary3.navigation_id) != | 654 EXPECT_TRUE(predictor_->inflight_navigations_.find(summary3.navigation_id) != |
| 833 predictor_->inflight_navigations_.end()); | 655 predictor_->inflight_navigations_.end()); |
| 834 EXPECT_TRUE(predictor_->inflight_navigations_.find(summary4.navigation_id) != | 656 EXPECT_TRUE(predictor_->inflight_navigations_.find(summary4.navigation_id) != |
| 835 predictor_->inflight_navigations_.end()); | 657 predictor_->inflight_navigations_.end()); |
| 836 EXPECT_TRUE(predictor_->inflight_navigations_.find(summary6.navigation_id) != | 658 EXPECT_TRUE(predictor_->inflight_navigations_.find(summary6.navigation_id) != |
| 837 predictor_->inflight_navigations_.end()); | 659 predictor_->inflight_navigations_.end()); |
| 838 } | 660 } |
| 839 | 661 |
| 840 TEST_F(ResourcePrefetchPredictorTest, OnMainFrameRedirect) { | 662 TEST_F(ResourcePrefetchPredictorTest, OnMainFrameRedirect) { |
| 841 URLRequestSummary summary1 = | 663 URLRequestSummary summary1 = CreateURLRequestSummary( |
| 842 CreateURLRequestSummary(1, | 664 1, 1, "http://www.google.com", "http://www.google.com", |
| 843 1, | 665 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); |
| 844 "http://www.google.com", | 666 URLRequestSummary summary2 = CreateURLRequestSummary( |
| 845 "http://www.google.com", | 667 1, 2, "http://www.google.com", "http://www.google.com", |
| 846 content::RESOURCE_TYPE_MAIN_FRAME, | 668 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); |
| 847 std::string(), | 669 URLRequestSummary summary3 = CreateURLRequestSummary( |
| 848 false); | 670 2, 1, "http://www.yahoo.com", "http://www.yahoo.com", |
| 849 URLRequestSummary summary2 = | 671 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); |
| 850 CreateURLRequestSummary(1, | |
| 851 2, | |
| 852 "http://www.google.com", | |
| 853 "http://www.google.com", | |
| 854 content::RESOURCE_TYPE_MAIN_FRAME, | |
| 855 std::string(), | |
| 856 false); | |
| 857 URLRequestSummary summary3 = | |
| 858 CreateURLRequestSummary(2, | |
| 859 1, | |
| 860 "http://www.yahoo.com", | |
| 861 "http://www.yahoo.com", | |
| 862 content::RESOURCE_TYPE_MAIN_FRAME, | |
| 863 std::string(), | |
| 864 false); | |
| 865 | 672 |
| 866 predictor_->OnMainFrameRedirect(summary1); | 673 predictor_->OnMainFrameRedirect(summary1); |
| 867 EXPECT_TRUE(predictor_->inflight_navigations_.empty()); | 674 EXPECT_TRUE(predictor_->inflight_navigations_.empty()); |
| 868 | 675 |
| 869 predictor_->OnMainFrameRequest(summary1); | 676 predictor_->OnMainFrameRequest(summary1); |
| 870 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 677 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
| 871 predictor_->OnMainFrameRequest(summary2); | 678 predictor_->OnMainFrameRequest(summary2); |
| 872 EXPECT_EQ(2U, predictor_->inflight_navigations_.size()); | 679 EXPECT_EQ(2U, predictor_->inflight_navigations_.size()); |
| 873 | 680 |
| 874 predictor_->OnMainFrameRedirect(summary3); | 681 predictor_->OnMainFrameRedirect(summary3); |
| 875 EXPECT_EQ(2U, predictor_->inflight_navigations_.size()); | 682 EXPECT_EQ(2U, predictor_->inflight_navigations_.size()); |
| 876 predictor_->OnMainFrameRedirect(summary1); | 683 predictor_->OnMainFrameRedirect(summary1); |
| 877 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 684 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
| 878 predictor_->OnMainFrameRedirect(summary2); | 685 predictor_->OnMainFrameRedirect(summary2); |
| 879 EXPECT_TRUE(predictor_->inflight_navigations_.empty()); | 686 EXPECT_TRUE(predictor_->inflight_navigations_.empty()); |
| 880 } | 687 } |
| 881 | 688 |
| 882 TEST_F(ResourcePrefetchPredictorTest, OnSubresourceResponse) { | 689 TEST_F(ResourcePrefetchPredictorTest, OnSubresourceResponse) { |
| 883 // If there is no inflight navigation, nothing happens. | 690 // If there is no inflight navigation, nothing happens. |
| 884 URLRequestSummary resource1 = CreateURLRequestSummary( | 691 URLRequestSummary resource1 = CreateURLRequestSummary( |
| 885 1, 1, "http://www.google.com", "http://google.com/style1.css", | 692 1, 1, "http://www.google.com", "http://google.com/style1.css", |
| 886 content::RESOURCE_TYPE_STYLESHEET, "text/css", false); | 693 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); |
| 887 predictor_->OnSubresourceResponse(resource1); | 694 predictor_->OnSubresourceResponse(resource1); |
| 888 EXPECT_TRUE(predictor_->inflight_navigations_.empty()); | 695 EXPECT_TRUE(predictor_->inflight_navigations_.empty()); |
| 889 | 696 |
| 890 // Add an inflight navigation. | 697 // Add an inflight navigation. |
| 891 URLRequestSummary main_frame1 = | 698 URLRequestSummary main_frame1 = CreateURLRequestSummary( |
| 892 CreateURLRequestSummary(1, | 699 1, 1, "http://www.google.com", "http://www.google.com", |
| 893 1, | 700 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); |
| 894 "http://www.google.com", | |
| 895 "http://www.google.com", | |
| 896 content::RESOURCE_TYPE_MAIN_FRAME, | |
| 897 std::string(), | |
| 898 false); | |
| 899 predictor_->OnMainFrameRequest(main_frame1); | 701 predictor_->OnMainFrameRequest(main_frame1); |
| 900 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 702 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
| 901 | 703 |
| 902 // Now add a few subresources. | 704 // Now add a few subresources. |
| 903 URLRequestSummary resource2 = CreateURLRequestSummary( | 705 URLRequestSummary resource2 = CreateURLRequestSummary( |
| 904 1, 1, "http://www.google.com", "http://google.com/script1.js", | 706 1, 1, "http://www.google.com", "http://google.com/script1.js", |
| 905 content::RESOURCE_TYPE_SCRIPT, "text/javascript", false); | 707 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); |
| 906 URLRequestSummary resource3 = CreateURLRequestSummary( | 708 URLRequestSummary resource3 = CreateURLRequestSummary( |
| 907 1, 1, "http://www.google.com", "http://google.com/script2.js", | 709 1, 1, "http://www.google.com", "http://google.com/script2.js", |
| 908 content::RESOURCE_TYPE_SCRIPT, "text/javascript", false); | 710 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); |
| 909 predictor_->OnSubresourceResponse(resource1); | 711 predictor_->OnSubresourceResponse(resource1); |
| 910 predictor_->OnSubresourceResponse(resource2); | 712 predictor_->OnSubresourceResponse(resource2); |
| 911 predictor_->OnSubresourceResponse(resource3); | 713 predictor_->OnSubresourceResponse(resource3); |
| 912 | 714 |
| 913 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 715 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
| 914 EXPECT_EQ(3U, | 716 EXPECT_EQ(3U, |
| 915 predictor_->inflight_navigations_[main_frame1.navigation_id]->size()); | 717 predictor_->inflight_navigations_[main_frame1.navigation_id]->size()); |
| 916 EXPECT_TRUE(URLRequestSummaryAreEqual( | 718 EXPECT_TRUE(URLRequestSummaryAreEqual( |
| 917 resource1, | 719 resource1, |
| 918 predictor_->inflight_navigations_[main_frame1.navigation_id]->at(0))); | 720 predictor_->inflight_navigations_[main_frame1.navigation_id]->at(0))); |
| 919 EXPECT_TRUE(URLRequestSummaryAreEqual( | 721 EXPECT_TRUE(URLRequestSummaryAreEqual( |
| 920 resource2, | 722 resource2, |
| 921 predictor_->inflight_navigations_[main_frame1.navigation_id]->at(1))); | 723 predictor_->inflight_navigations_[main_frame1.navigation_id]->at(1))); |
| 922 EXPECT_TRUE(URLRequestSummaryAreEqual( | 724 EXPECT_TRUE(URLRequestSummaryAreEqual( |
| 923 resource3, | 725 resource3, |
| 924 predictor_->inflight_navigations_[main_frame1.navigation_id]->at(2))); | 726 predictor_->inflight_navigations_[main_frame1.navigation_id]->at(2))); |
| 925 } | 727 } |
| 926 | 728 |
| 927 TEST_F(ResourcePrefetchPredictorTest, GetCorrectPLT) { | 729 TEST_F(ResourcePrefetchPredictorTest, GetCorrectPLT) { |
| 928 // Single navigation but history count is low, so should not record. | 730 // Single navigation but history count is low, so should not record. |
| 929 AddUrlToHistory("http://www.google.com", 1); | 731 AddUrlToHistory("http://www.google.com", 1); |
| 930 | 732 |
| 931 URLRequestSummary main_frame = | 733 URLRequestSummary main_frame = CreateURLRequestSummary( |
| 932 CreateURLRequestSummary(1, | 734 1, 1, "http://www.google.com", "http://www.google.com", |
| 933 1, | 735 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); |
| 934 "http://www.google.com", | |
| 935 "http://www.google.com", | |
| 936 content::RESOURCE_TYPE_MAIN_FRAME, | |
| 937 std::string(), | |
| 938 false); | |
| 939 predictor_->RecordURLRequest(main_frame); | 736 predictor_->RecordURLRequest(main_frame); |
| 940 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 737 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
| 941 | 738 |
| 942 // Reset the creation time in |main_frame.navigation_id|. The correct creation | 739 // Reset the creation time in |main_frame.navigation_id|. The correct creation |
| 943 // time is stored in |inflight_navigations_| and should be used later. | 740 // time is stored in |inflight_navigations_| and should be used later. |
| 944 main_frame.navigation_id.creation_time = base::TimeTicks(); | 741 main_frame.navigation_id.creation_time = base::TimeTicks(); |
| 945 EXPECT_TRUE(main_frame.navigation_id.creation_time.is_null()); | 742 EXPECT_TRUE(main_frame.navigation_id.creation_time.is_null()); |
| 946 | 743 |
| 947 // Now add a subresource. | 744 // Now add a subresource. |
| 948 URLRequestSummary resource1 = CreateURLRequestSummary( | 745 URLRequestSummary resource1 = CreateURLRequestSummary( |
| 949 1, 1, "http://www.google.com", "http://google.com/style1.css", | 746 1, 1, "http://www.google.com", "http://google.com/style1.css", |
| 950 content::RESOURCE_TYPE_STYLESHEET, "text/css", false); | 747 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); |
| 951 predictor_->RecordURLResponse(resource1); | 748 predictor_->RecordURLResponse(resource1); |
| 952 | 749 |
| 953 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com"); | 750 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com"); |
| 954 host_data.resources.push_back(ResourceRow(std::string(), | 751 host_data.resources.push_back(ResourceRow( |
| 955 "http://google.com/style1.css", | 752 std::string(), "http://google.com/style1.css", |
| 956 content::RESOURCE_TYPE_STYLESHEET, | 753 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, net::MEDIUM)); |
| 957 1, | |
| 958 0, | |
| 959 0, | |
| 960 1.0)); | |
| 961 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); | 754 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); |
| 962 | 755 |
| 963 // The page load time will be collected by RPP_HISTOGRAM_MEDIUM_TIMES, which | 756 // The page load time will be collected by RPP_HISTOGRAM_MEDIUM_TIMES, which |
| 964 // has a upper bound of 3 minutes. | 757 // has a upper bound of 3 minutes. |
| 965 base::TimeDelta plt = | 758 base::TimeDelta plt = |
| 966 predictor_->OnNavigationComplete(main_frame.navigation_id); | 759 predictor_->OnNavigationComplete(main_frame.navigation_id); |
| 967 EXPECT_LT(plt, base::TimeDelta::FromSeconds(180)); | 760 EXPECT_LT(plt, base::TimeDelta::FromSeconds(180)); |
| 968 | 761 |
| 969 profile_->BlockUntilHistoryProcessesPendingRequests(); | 762 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 970 } | 763 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 984 content::RESOURCE_TYPE_PREFETCH, "bogus/mime-type")); | 777 content::RESOURCE_TYPE_PREFETCH, "bogus/mime-type")); |
| 985 EXPECT_FALSE(ResourcePrefetchPredictor::IsHandledResourceType( | 778 EXPECT_FALSE(ResourcePrefetchPredictor::IsHandledResourceType( |
| 986 content::RESOURCE_TYPE_PREFETCH, "")); | 779 content::RESOURCE_TYPE_PREFETCH, "")); |
| 987 EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType( | 780 EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType( |
| 988 content::RESOURCE_TYPE_PREFETCH, "application/font-woff")); | 781 content::RESOURCE_TYPE_PREFETCH, "application/font-woff")); |
| 989 EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType( | 782 EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType( |
| 990 content::RESOURCE_TYPE_PREFETCH, "font/woff2")); | 783 content::RESOURCE_TYPE_PREFETCH, "font/woff2")); |
| 991 } | 784 } |
| 992 | 785 |
| 993 } // namespace predictors | 786 } // namespace predictors |
| OLD | NEW |