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

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

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

Powered by Google App Engine
This is Rietveld 408576698