OLD | NEW |
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 <set> | 5 #include <set> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "chrome/browser/download/download_history.h" | 10 #include "chrome/browser/download/download_history.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 using testing::Return; | 22 using testing::Return; |
23 using testing::ReturnRef; | 23 using testing::ReturnRef; |
24 using testing::SetArgPointee; | 24 using testing::SetArgPointee; |
25 using testing::WithArg; | 25 using testing::WithArg; |
26 using testing::_; | 26 using testing::_; |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 void CheckInfoEqual(const history::DownloadRow& left, | 30 void CheckInfoEqual(const history::DownloadRow& left, |
31 const history::DownloadRow& right) { | 31 const history::DownloadRow& right) { |
32 EXPECT_EQ(left.path.value(), right.path.value()); | 32 EXPECT_EQ(left.current_path.value(), right.current_path.value()); |
33 EXPECT_EQ(left.url.spec(), right.url.spec()); | 33 EXPECT_EQ(left.target_path.value(), right.target_path.value()); |
| 34 EXPECT_EQ(left.url_chain.size(), right.url_chain.size()); |
| 35 for (unsigned int i = 0; |
| 36 i < left.url_chain.size() && i < right.url_chain.size(); |
| 37 ++i) { |
| 38 EXPECT_EQ(left.url_chain[i].spec(), right.url_chain[i].spec()); |
| 39 } |
34 EXPECT_EQ(left.referrer_url.spec(), right.referrer_url.spec()); | 40 EXPECT_EQ(left.referrer_url.spec(), right.referrer_url.spec()); |
35 EXPECT_EQ(left.start_time.ToTimeT(), right.start_time.ToTimeT()); | 41 EXPECT_EQ(left.start_time.ToTimeT(), right.start_time.ToTimeT()); |
36 EXPECT_EQ(left.end_time.ToTimeT(), right.end_time.ToTimeT()); | 42 EXPECT_EQ(left.end_time.ToTimeT(), right.end_time.ToTimeT()); |
37 EXPECT_EQ(left.received_bytes, right.received_bytes); | 43 EXPECT_EQ(left.received_bytes, right.received_bytes); |
38 EXPECT_EQ(left.total_bytes, right.total_bytes); | 44 EXPECT_EQ(left.total_bytes, right.total_bytes); |
39 EXPECT_EQ(left.state, right.state); | 45 EXPECT_EQ(left.state, right.state); |
40 EXPECT_EQ(left.db_handle, right.db_handle); | 46 EXPECT_EQ(left.db_handle, right.db_handle); |
41 EXPECT_EQ(left.opened, right.opened); | 47 EXPECT_EQ(left.opened, right.opened); |
42 } | 48 } |
43 | 49 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 } | 234 } |
229 | 235 |
230 void ExpectWillQueryDownloads(scoped_ptr<InfoVector> infos) { | 236 void ExpectWillQueryDownloads(scoped_ptr<InfoVector> infos) { |
231 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 237 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
232 CHECK(infos.get()); | 238 CHECK(infos.get()); |
233 EXPECT_CALL(manager(), AddObserver(_)).WillOnce(WithArg<0>(Invoke( | 239 EXPECT_CALL(manager(), AddObserver(_)).WillOnce(WithArg<0>(Invoke( |
234 this, &DownloadHistoryTest::SetManagerObserver))); | 240 this, &DownloadHistoryTest::SetManagerObserver))); |
235 EXPECT_CALL(manager(), RemoveObserver(_)); | 241 EXPECT_CALL(manager(), RemoveObserver(_)); |
236 download_created_index_ = 0; | 242 download_created_index_ = 0; |
237 for (size_t index = 0; index < infos->size(); ++index) { | 243 for (size_t index = 0; index < infos->size(); ++index) { |
238 EXPECT_CALL(manager(), CreateDownloadItem( | 244 EXPECT_CALL(manager(), MockCreateDownloadItem( |
239 infos->at(index).path, | 245 infos->at(index).target_path, |
240 infos->at(index).url, | 246 infos->at(index).url_chain, |
241 infos->at(index).referrer_url, | 247 infos->at(index).referrer_url, |
242 infos->at(index).start_time, | 248 infos->at(index).start_time, |
243 infos->at(index).end_time, | 249 infos->at(index).end_time, |
244 infos->at(index).received_bytes, | 250 infos->at(index).received_bytes, |
245 infos->at(index).total_bytes, | 251 infos->at(index).total_bytes, |
246 infos->at(index).state, | 252 infos->at(index).state, |
| 253 infos->at(index).interrupt_reason, |
247 infos->at(index).opened)) | 254 infos->at(index).opened)) |
248 .WillOnce(DoAll( | 255 .WillOnce(DoAll( |
249 InvokeWithoutArgs( | 256 InvokeWithoutArgs( |
250 this, &DownloadHistoryTest::CallOnDownloadCreatedInOrder), | 257 this, &DownloadHistoryTest::CallOnDownloadCreatedInOrder), |
251 Return(&item(index)))); | 258 Return(&item(index)))); |
252 } | 259 } |
253 EXPECT_CALL(manager(), CheckForHistoryFilesRemoval()); | 260 EXPECT_CALL(manager(), CheckForHistoryFilesRemoval()); |
254 history_ = new FakeHistoryAdapter(); | 261 history_ = new FakeHistoryAdapter(); |
255 history_->ExpectWillQueryDownloads(infos.Pass()); | 262 history_->ExpectWillQueryDownloads(infos.Pass()); |
256 EXPECT_CALL(*manager_.get(), GetAllDownloads(_)).WillRepeatedly(Return()); | 263 EXPECT_CALL(*manager_.get(), GetAllDownloads(_)).WillRepeatedly(Return()); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 void ExpectNoDownloadsRemoved() { | 318 void ExpectNoDownloadsRemoved() { |
312 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 319 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
313 history_->ExpectNoDownloadsRemoved(); | 320 history_->ExpectNoDownloadsRemoved(); |
314 } | 321 } |
315 | 322 |
316 void ExpectDownloadsRemoved(const HandleSet& handles) { | 323 void ExpectDownloadsRemoved(const HandleSet& handles) { |
317 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 324 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
318 history_->ExpectDownloadsRemoved(handles); | 325 history_->ExpectDownloadsRemoved(handles); |
319 } | 326 } |
320 | 327 |
| 328 // Caller is responsibile for making sure reference arguments lifetime is |
| 329 // greater than the lifetime of the NiceMockDownloadItem() created by this |
| 330 // routine. |
321 void InitItem( | 331 void InitItem( |
322 int32 id, | 332 int32 id, |
323 const FilePath& path, | 333 const FilePath& current_path, |
324 const GURL& url, | 334 const FilePath& target_path, |
| 335 const std::vector<GURL>& url_chain, |
325 const GURL& referrer, | 336 const GURL& referrer, |
326 const base::Time& start_time, | 337 const base::Time& start_time, |
327 const base::Time& end_time, | 338 const base::Time& end_time, |
328 int64 received_bytes, | 339 int64 received_bytes, |
329 int64 total_bytes, | 340 int64 total_bytes, |
330 content::DownloadItem::DownloadState state, | 341 content::DownloadItem::DownloadState state, |
| 342 content::DownloadInterruptReason interrupt_reason, |
331 int64 db_handle, | 343 int64 db_handle, |
332 bool opened, | 344 bool opened, |
333 history::DownloadRow* info) { | 345 history::DownloadRow* info) { |
334 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 346 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
335 int32 index = items_.size(); | 347 int32 index = items_.size(); |
336 NiceMockDownloadItem* mock_item = new NiceMockDownloadItem(); | 348 NiceMockDownloadItem* mock_item = new NiceMockDownloadItem(); |
337 items_.push_back(mock_item); | 349 items_.push_back(mock_item); |
338 | 350 |
339 info->path = path; | 351 info->current_path = current_path; |
340 info->url = url; | 352 info->target_path = target_path; |
| 353 info->url_chain = url_chain; |
341 info->referrer_url = referrer; | 354 info->referrer_url = referrer; |
342 info->start_time = start_time; | 355 info->start_time = start_time; |
343 info->end_time = end_time; | 356 info->end_time = end_time; |
344 info->received_bytes = received_bytes; | 357 info->received_bytes = received_bytes; |
345 info->total_bytes = total_bytes; | 358 info->total_bytes = total_bytes; |
346 info->state = state; | 359 info->state = state; |
| 360 info->interrupt_reason = interrupt_reason; |
347 info->db_handle = db_handle; | 361 info->db_handle = db_handle; |
348 info->opened = opened; | 362 info->opened = opened; |
349 | 363 |
350 EXPECT_CALL(item(index), GetId()).WillRepeatedly(Return(id)); | 364 EXPECT_CALL(item(index), GetId()).WillRepeatedly(Return(id)); |
351 EXPECT_CALL(item(index), GetFullPath()).WillRepeatedly(ReturnRef(path)); | 365 EXPECT_CALL(item(index), |
352 EXPECT_CALL(item(index), GetURL()).WillRepeatedly(ReturnRef(url)); | 366 GetFullPath()).WillRepeatedly(ReturnRef(current_path)); |
| 367 EXPECT_CALL(item(index), |
| 368 GetTargetFilePath()).WillRepeatedly(ReturnRef(target_path)); |
| 369 DCHECK_LE(1u, url_chain.size()); |
| 370 EXPECT_CALL(item(index), GetURL()).WillRepeatedly(ReturnRef(url_chain[0])); |
| 371 EXPECT_CALL(item(index), |
| 372 GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); |
353 EXPECT_CALL(item(index), GetMimeType()).WillRepeatedly(Return( | 373 EXPECT_CALL(item(index), GetMimeType()).WillRepeatedly(Return( |
354 "application/octet-stream")); | 374 "application/octet-stream")); |
355 EXPECT_CALL(item(index), GetReferrerUrl()).WillRepeatedly(ReturnRef( | 375 EXPECT_CALL(item(index), GetReferrerUrl()).WillRepeatedly(ReturnRef( |
356 referrer)); | 376 referrer)); |
357 EXPECT_CALL(item(index), GetStartTime()).WillRepeatedly(Return(start_time)); | 377 EXPECT_CALL(item(index), GetStartTime()).WillRepeatedly(Return(start_time)); |
358 EXPECT_CALL(item(index), GetEndTime()).WillRepeatedly(Return(end_time)); | 378 EXPECT_CALL(item(index), GetEndTime()).WillRepeatedly(Return(end_time)); |
359 EXPECT_CALL(item(index), GetReceivedBytes()) | 379 EXPECT_CALL(item(index), GetReceivedBytes()) |
360 .WillRepeatedly(Return(received_bytes)); | 380 .WillRepeatedly(Return(received_bytes)); |
361 EXPECT_CALL(item(index), GetTotalBytes()).WillRepeatedly(Return( | 381 EXPECT_CALL(item(index), GetTotalBytes()).WillRepeatedly(Return( |
362 total_bytes)); | 382 total_bytes)); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 | 416 |
397 // Test loading an item from the database, changing it, saving it back, removing | 417 // Test loading an item from the database, changing it, saving it back, removing |
398 // it. | 418 // it. |
399 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Load) { | 419 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Load) { |
400 // Load a download from history, create the item, OnDownloadCreated, | 420 // Load a download from history, create the item, OnDownloadCreated, |
401 // OnDownloadUpdated, OnDownloadRemoved. | 421 // OnDownloadUpdated, OnDownloadRemoved. |
402 history::DownloadRow info; | 422 history::DownloadRow info; |
403 FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf")); | 423 FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf")); |
404 GURL url("http://example.com/bar.pdf"); | 424 GURL url("http://example.com/bar.pdf"); |
405 GURL referrer("http://example.com/referrer.html"); | 425 GURL referrer("http://example.com/referrer.html"); |
| 426 std::vector<GURL> url_chain; |
| 427 url_chain.push_back(url); |
406 InitItem(base::RandInt(0, 1 << 20), | 428 InitItem(base::RandInt(0, 1 << 20), |
407 path, | 429 path, |
408 url, | 430 path, |
| 431 url_chain, |
409 referrer, | 432 referrer, |
410 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), | 433 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), |
411 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), | 434 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), |
412 100, | 435 100, |
413 100, | 436 100, |
414 content::DownloadItem::COMPLETE, | 437 content::DownloadItem::COMPLETE, |
| 438 content::DOWNLOAD_INTERRUPT_REASON_NONE, |
415 base::RandInt(0, 1 << 20), | 439 base::RandInt(0, 1 << 20), |
416 false, | 440 false, |
417 &info); | 441 &info); |
418 { | 442 { |
419 scoped_ptr<InfoVector> infos(new InfoVector()); | 443 scoped_ptr<InfoVector> infos(new InfoVector()); |
420 infos->push_back(info); | 444 infos->push_back(info); |
421 ExpectWillQueryDownloads(infos.Pass()); | 445 ExpectWillQueryDownloads(infos.Pass()); |
422 ExpectNoDownloadCreated(); | 446 ExpectNoDownloadCreated(); |
423 } | 447 } |
424 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 448 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
(...skipping 16 matching lines...) Expand all Loading... |
441 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Create) { | 465 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Create) { |
442 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, | 466 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, |
443 // OnDownloadRemoved. | 467 // OnDownloadRemoved. |
444 ExpectWillQueryDownloads(scoped_ptr<InfoVector>(new InfoVector())); | 468 ExpectWillQueryDownloads(scoped_ptr<InfoVector>(new InfoVector())); |
445 | 469 |
446 // Note that db_handle must be -1 at first because it isn't in the db yet. | 470 // Note that db_handle must be -1 at first because it isn't in the db yet. |
447 history::DownloadRow info; | 471 history::DownloadRow info; |
448 FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf")); | 472 FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf")); |
449 GURL url("http://example.com/bar.pdf"); | 473 GURL url("http://example.com/bar.pdf"); |
450 GURL referrer("http://example.com/referrer.html"); | 474 GURL referrer("http://example.com/referrer.html"); |
| 475 std::vector<GURL> url_chain; |
| 476 url_chain.push_back(url); |
451 InitItem(base::RandInt(0, 1 << 20), | 477 InitItem(base::RandInt(0, 1 << 20), |
452 path, | 478 path, |
453 url, | 479 path, |
| 480 url_chain, |
454 referrer, | 481 referrer, |
455 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), | 482 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), |
456 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), | 483 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), |
457 100, | 484 100, |
458 100, | 485 100, |
459 content::DownloadItem::COMPLETE, | 486 content::DownloadItem::COMPLETE, |
| 487 content::DOWNLOAD_INTERRUPT_REASON_NONE, |
460 -1, | 488 -1, |
461 false, | 489 false, |
462 &info); | 490 &info); |
463 | 491 |
464 // Pretend the manager just created |item|. | 492 // Pretend the manager just created |item|. |
465 CallOnDownloadCreated(0); | 493 CallOnDownloadCreated(0); |
466 // CreateDownload() always gets db_handle=-1. | 494 // CreateDownload() always gets db_handle=-1. |
467 ExpectDownloadCreated(info); | 495 ExpectDownloadCreated(info); |
468 info.db_handle = 0; | 496 info.db_handle = 0; |
469 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 497 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
(...skipping 18 matching lines...) Expand all Loading... |
488 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Temporary) { | 516 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Temporary) { |
489 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, | 517 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, |
490 // OnDownloadRemoved. | 518 // OnDownloadRemoved. |
491 ExpectWillQueryDownloads(scoped_ptr<InfoVector>(new InfoVector())); | 519 ExpectWillQueryDownloads(scoped_ptr<InfoVector>(new InfoVector())); |
492 | 520 |
493 // Note that db_handle must be -1 at first because it isn't in the db yet. | 521 // Note that db_handle must be -1 at first because it isn't in the db yet. |
494 history::DownloadRow info; | 522 history::DownloadRow info; |
495 FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf")); | 523 FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf")); |
496 GURL url("http://example.com/bar.pdf"); | 524 GURL url("http://example.com/bar.pdf"); |
497 GURL referrer("http://example.com/referrer.html"); | 525 GURL referrer("http://example.com/referrer.html"); |
| 526 std::vector<GURL> url_chain; |
| 527 url_chain.push_back(url); |
498 InitItem(base::RandInt(0, 1 << 20), | 528 InitItem(base::RandInt(0, 1 << 20), |
499 path, | 529 path, |
500 url, | 530 path, |
| 531 url_chain, |
501 referrer, | 532 referrer, |
502 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), | 533 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), |
503 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), | 534 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), |
504 100, | 535 100, |
505 100, | 536 100, |
506 content::DownloadItem::COMPLETE, | 537 content::DownloadItem::COMPLETE, |
| 538 content::DOWNLOAD_INTERRUPT_REASON_NONE, |
507 -1, | 539 -1, |
508 false, | 540 false, |
509 &info); | 541 &info); |
510 | 542 |
511 // Pretend the manager just created |item|. | 543 // Pretend the manager just created |item|. |
512 CallOnDownloadCreated(0); | 544 CallOnDownloadCreated(0); |
513 // CreateDownload() always gets db_handle=-1. | 545 // CreateDownload() always gets db_handle=-1. |
514 ExpectDownloadCreated(info); | 546 ExpectDownloadCreated(info); |
515 info.db_handle = 0; | 547 info.db_handle = 0; |
516 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 548 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 // Test removing downloads while they're still being added. | 581 // Test removing downloads while they're still being added. |
550 TEST_F(DownloadHistoryTest, | 582 TEST_F(DownloadHistoryTest, |
551 DownloadHistoryTest_RemoveWhileAdding) { | 583 DownloadHistoryTest_RemoveWhileAdding) { |
552 ExpectWillQueryDownloads(scoped_ptr<InfoVector>(new InfoVector())); | 584 ExpectWillQueryDownloads(scoped_ptr<InfoVector>(new InfoVector())); |
553 | 585 |
554 // Note that db_handle must be -1 at first because it isn't in the db yet. | 586 // Note that db_handle must be -1 at first because it isn't in the db yet. |
555 history::DownloadRow info; | 587 history::DownloadRow info; |
556 FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf")); | 588 FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf")); |
557 GURL url("http://example.com/bar.pdf"); | 589 GURL url("http://example.com/bar.pdf"); |
558 GURL referrer("http://example.com/referrer.html"); | 590 GURL referrer("http://example.com/referrer.html"); |
| 591 std::vector<GURL> url_chain; |
| 592 url_chain.push_back(url); |
559 InitItem(base::RandInt(0, 1 << 20), | 593 InitItem(base::RandInt(0, 1 << 20), |
560 path, | 594 path, |
561 url, | 595 path, |
| 596 url_chain, |
562 referrer, | 597 referrer, |
563 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), | 598 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), |
564 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), | 599 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), |
565 100, | 600 100, |
566 100, | 601 100, |
567 content::DownloadItem::COMPLETE, | 602 content::DownloadItem::COMPLETE, |
| 603 content::DOWNLOAD_INTERRUPT_REASON_NONE, |
568 -1, | 604 -1, |
569 false, | 605 false, |
570 &info); | 606 &info); |
571 | 607 |
572 // Instruct CreateDownload() to not callback to DownloadHistory immediately, | 608 // Instruct CreateDownload() to not callback to DownloadHistory immediately, |
573 // but to wait for FinishCreateDownload(). | 609 // but to wait for FinishCreateDownload(). |
574 set_slow_create_download(true); | 610 set_slow_create_download(true); |
575 | 611 |
576 // Pretend the manager just created |item|. | 612 // Pretend the manager just created |item|. |
577 CallOnDownloadCreated(0); | 613 CallOnDownloadCreated(0); |
(...skipping 22 matching lines...) Expand all Loading... |
600 } | 636 } |
601 | 637 |
602 // Test loading multiple items from the database and removing them all. | 638 // Test loading multiple items from the database and removing them all. |
603 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Multiple) { | 639 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Multiple) { |
604 // Load a download from history, create the item, OnDownloadCreated, | 640 // Load a download from history, create the item, OnDownloadCreated, |
605 // OnDownloadUpdated, OnDownloadRemoved. | 641 // OnDownloadUpdated, OnDownloadRemoved. |
606 history::DownloadRow info0, info1; | 642 history::DownloadRow info0, info1; |
607 FilePath path0(FILE_PATH_LITERAL("/foo/bar.pdf")); | 643 FilePath path0(FILE_PATH_LITERAL("/foo/bar.pdf")); |
608 GURL url0("http://example.com/bar.pdf"); | 644 GURL url0("http://example.com/bar.pdf"); |
609 GURL referrer0("http://example.com/referrer.html"); | 645 GURL referrer0("http://example.com/referrer.html"); |
| 646 std::vector<GURL> url0_chain; |
| 647 url0_chain.push_back(url0); |
610 InitItem(base::RandInt(0, 1 << 10), | 648 InitItem(base::RandInt(0, 1 << 10), |
611 path0, | 649 path0, |
612 url0, | 650 path0, |
| 651 url0_chain, |
613 referrer0, | 652 referrer0, |
614 (base::Time::Now() - base::TimeDelta::FromMinutes(11)), | 653 (base::Time::Now() - base::TimeDelta::FromMinutes(11)), |
615 (base::Time::Now() - base::TimeDelta::FromMinutes(2)), | 654 (base::Time::Now() - base::TimeDelta::FromMinutes(2)), |
616 100, | 655 100, |
617 100, | 656 100, |
618 content::DownloadItem::COMPLETE, | 657 content::DownloadItem::COMPLETE, |
| 658 content::DOWNLOAD_INTERRUPT_REASON_NONE, |
619 base::RandInt(0, 1 << 10), | 659 base::RandInt(0, 1 << 10), |
620 false, | 660 false, |
621 &info0); | 661 &info0); |
622 FilePath path1(FILE_PATH_LITERAL("/foo/qux.pdf")); | 662 FilePath path1(FILE_PATH_LITERAL("/foo/qux.pdf")); |
623 GURL url1("http://example.com/qux.pdf"); | 663 GURL url1("http://example.com/qux.pdf"); |
624 GURL referrer1("http://example.com/referrer.html"); | 664 GURL referrer1("http://example.com/referrer.html"); |
| 665 std::vector<GURL> url1_chain; |
| 666 url1_chain.push_back(url0); |
625 InitItem(item(0).GetId() + base::RandInt(1, 1 << 10), | 667 InitItem(item(0).GetId() + base::RandInt(1, 1 << 10), |
626 path1, | 668 path1, |
627 url1, | 669 path1, |
| 670 url1_chain, |
628 referrer1, | 671 referrer1, |
629 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), | 672 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), |
630 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), | 673 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), |
631 200, | 674 200, |
632 200, | 675 200, |
633 content::DownloadItem::COMPLETE, | 676 content::DownloadItem::COMPLETE, |
| 677 content::DOWNLOAD_INTERRUPT_REASON_NONE, |
634 info0.db_handle + base::RandInt(1, 1 << 10), | 678 info0.db_handle + base::RandInt(1, 1 << 10), |
635 false, | 679 false, |
636 &info1); | 680 &info1); |
637 { | 681 { |
638 scoped_ptr<InfoVector> infos(new InfoVector()); | 682 scoped_ptr<InfoVector> infos(new InfoVector()); |
639 infos->push_back(info0); | 683 infos->push_back(info0); |
640 infos->push_back(info1); | 684 infos->push_back(info1); |
641 ExpectWillQueryDownloads(infos.Pass()); | 685 ExpectWillQueryDownloads(infos.Pass()); |
642 ExpectNoDownloadCreated(); | 686 ExpectNoDownloadCreated(); |
643 } | 687 } |
(...skipping 14 matching lines...) Expand all Loading... |
658 TEST_F(DownloadHistoryTest, DownloadHistoryTest_CreateFailed) { | 702 TEST_F(DownloadHistoryTest, DownloadHistoryTest_CreateFailed) { |
659 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, | 703 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, |
660 // OnDownloadRemoved. | 704 // OnDownloadRemoved. |
661 ExpectWillQueryDownloads(scoped_ptr<InfoVector>(new InfoVector())); | 705 ExpectWillQueryDownloads(scoped_ptr<InfoVector>(new InfoVector())); |
662 | 706 |
663 // Note that db_handle must be -1 at first because it isn't in the db yet. | 707 // Note that db_handle must be -1 at first because it isn't in the db yet. |
664 history::DownloadRow info; | 708 history::DownloadRow info; |
665 FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf")); | 709 FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf")); |
666 GURL url("http://example.com/bar.pdf"); | 710 GURL url("http://example.com/bar.pdf"); |
667 GURL referrer("http://example.com/referrer.html"); | 711 GURL referrer("http://example.com/referrer.html"); |
| 712 std::vector<GURL> url_chain; |
| 713 url_chain.push_back(url); |
668 InitItem(base::RandInt(0, 1 << 20), | 714 InitItem(base::RandInt(0, 1 << 20), |
669 path, | 715 path, |
670 url, | 716 path, |
| 717 url_chain, |
671 referrer, | 718 referrer, |
672 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), | 719 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), |
673 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), | 720 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), |
674 100, | 721 100, |
675 100, | 722 100, |
676 content::DownloadItem::COMPLETE, | 723 content::DownloadItem::COMPLETE, |
| 724 content::DOWNLOAD_INTERRUPT_REASON_NONE, |
677 -1, | 725 -1, |
678 false, | 726 false, |
679 &info); | 727 &info); |
680 | 728 |
681 FailCreateDownload(); | 729 FailCreateDownload(); |
682 // Pretend the manager just created |item|. | 730 // Pretend the manager just created |item|. |
683 CallOnDownloadCreated(0); | 731 CallOnDownloadCreated(0); |
684 // CreateDownload() always gets db_handle=-1. | 732 // CreateDownload() always gets db_handle=-1. |
685 ExpectDownloadCreated(info); | 733 ExpectDownloadCreated(info); |
686 EXPECT_FALSE(DownloadHistory::IsPersisted(&item(0))); | 734 EXPECT_FALSE(DownloadHistory::IsPersisted(&item(0))); |
687 | 735 |
688 EXPECT_CALL(item(0), GetReceivedBytes()).WillRepeatedly(Return(100)); | 736 EXPECT_CALL(item(0), GetReceivedBytes()).WillRepeatedly(Return(100)); |
689 item_observer()->OnDownloadUpdated(&item(0)); | 737 item_observer()->OnDownloadUpdated(&item(0)); |
690 info.received_bytes = 100; | 738 info.received_bytes = 100; |
691 ExpectDownloadCreated(info); | 739 ExpectDownloadCreated(info); |
692 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 740 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
693 } | 741 } |
694 | 742 |
695 TEST_F(DownloadHistoryTest, | 743 TEST_F(DownloadHistoryTest, |
696 DownloadHistoryTest_UpdateWhileAdding) { | 744 DownloadHistoryTest_UpdateWhileAdding) { |
697 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, | 745 // Create a fresh item not from history, OnDownloadCreated, OnDownloadUpdated, |
698 // OnDownloadRemoved. | 746 // OnDownloadRemoved. |
699 ExpectWillQueryDownloads(scoped_ptr<InfoVector>(new InfoVector())); | 747 ExpectWillQueryDownloads(scoped_ptr<InfoVector>(new InfoVector())); |
700 | 748 |
701 // Note that db_handle must be -1 at first because it isn't in the db yet. | 749 // Note that db_handle must be -1 at first because it isn't in the db yet. |
702 history::DownloadRow info; | 750 history::DownloadRow info; |
703 FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf")); | 751 FilePath path(FILE_PATH_LITERAL("/foo/bar.pdf")); |
704 GURL url("http://example.com/bar.pdf"); | 752 GURL url("http://example.com/bar.pdf"); |
705 GURL referrer("http://example.com/referrer.html"); | 753 GURL referrer("http://example.com/referrer.html"); |
| 754 std::vector<GURL> url_chain; |
| 755 url_chain.push_back(url); |
706 InitItem(base::RandInt(0, 1 << 20), | 756 InitItem(base::RandInt(0, 1 << 20), |
707 path, | 757 path, |
708 url, | 758 path, |
| 759 url_chain, |
709 referrer, | 760 referrer, |
710 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), | 761 (base::Time::Now() - base::TimeDelta::FromMinutes(10)), |
711 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), | 762 (base::Time::Now() - base::TimeDelta::FromMinutes(1)), |
712 100, | 763 100, |
713 100, | 764 100, |
714 content::DownloadItem::COMPLETE, | 765 content::DownloadItem::COMPLETE, |
| 766 content::DOWNLOAD_INTERRUPT_REASON_NONE, |
715 -1, | 767 -1, |
716 false, | 768 false, |
717 &info); | 769 &info); |
718 | 770 |
719 // Instruct CreateDownload() to not callback to DownloadHistory immediately, | 771 // Instruct CreateDownload() to not callback to DownloadHistory immediately, |
720 // but to wait for FinishCreateDownload(). | 772 // but to wait for FinishCreateDownload(). |
721 set_slow_create_download(true); | 773 set_slow_create_download(true); |
722 | 774 |
723 // Pretend the manager just created |item|. | 775 // Pretend the manager just created |item|. |
724 CallOnDownloadCreated(0); | 776 CallOnDownloadCreated(0); |
725 // CreateDownload() always gets db_handle=-1. | 777 // CreateDownload() always gets db_handle=-1. |
726 ExpectDownloadCreated(info); | 778 ExpectDownloadCreated(info); |
727 info.db_handle = 0; | 779 info.db_handle = 0; |
728 EXPECT_FALSE(DownloadHistory::IsPersisted(&item(0))); | 780 EXPECT_FALSE(DownloadHistory::IsPersisted(&item(0))); |
729 | 781 |
730 // Pretend that something changed on the item. | 782 // Pretend that something changed on the item. |
731 EXPECT_CALL(item(0), GetOpened()).WillRepeatedly(Return(true)); | 783 EXPECT_CALL(item(0), GetOpened()).WillRepeatedly(Return(true)); |
732 item_observer()->OnDownloadUpdated(&item(0)); | 784 item_observer()->OnDownloadUpdated(&item(0)); |
733 | 785 |
734 FinishCreateDownload(); | 786 FinishCreateDownload(); |
735 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 787 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
736 | 788 |
737 // ItemAdded should call OnDownloadUpdated, which should detect that the item | 789 // ItemAdded should call OnDownloadUpdated, which should detect that the item |
738 // changed while it was being added and call UpdateDownload immediately. | 790 // changed while it was being added and call UpdateDownload immediately. |
739 info.opened = true; | 791 info.opened = true; |
740 ExpectDownloadUpdated(info); | 792 ExpectDownloadUpdated(info); |
741 } | 793 } |
OLD | NEW |