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

Side by Side Diff: chrome/browser/download/download_history_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698