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 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 .WillRepeatedly( | 431 .WillRepeatedly( |
432 Return(content::DownloadItem::TARGET_DISPOSITION_OVERWRITE)); | 432 Return(content::DownloadItem::TARGET_DISPOSITION_OVERWRITE)); |
433 EXPECT_CALL(manager(), GetDownload(id)) | 433 EXPECT_CALL(manager(), GetDownload(id)) |
434 .WillRepeatedly(Return(&item(index))); | 434 .WillRepeatedly(Return(&item(index))); |
435 EXPECT_CALL(item(index), AddObserver(_)) | 435 EXPECT_CALL(item(index), AddObserver(_)) |
436 .WillOnce(WithArg<0>( | 436 .WillOnce(WithArg<0>( |
437 Invoke(this, &DownloadHistoryTest::SetItemObserver))); | 437 Invoke(this, &DownloadHistoryTest::SetItemObserver))); |
438 EXPECT_CALL(item(index), RemoveObserver(_)); | 438 EXPECT_CALL(item(index), RemoveObserver(_)); |
439 EXPECT_CALL(item(index), IsTemporary()).WillRepeatedly(Return(false)); | 439 EXPECT_CALL(item(index), IsTemporary()).WillRepeatedly(Return(false)); |
440 #if !defined(OS_ANDROID) | 440 #if !defined(OS_ANDROID) |
441 new DownloadedByExtension(&item(index), by_extension_id, by_extension_name); | 441 new extensions::DownloadedByExtension( |
| 442 &item(index), by_extension_id, by_extension_name); |
442 #endif | 443 #endif |
443 | 444 |
444 std::vector<content::DownloadItem*> items; | 445 std::vector<content::DownloadItem*> items; |
445 for (size_t i = 0; i < items_.size(); ++i) { | 446 for (size_t i = 0; i < items_.size(); ++i) { |
446 items.push_back(&item(i)); | 447 items.push_back(&item(i)); |
447 } | 448 } |
448 EXPECT_CALL(*manager_.get(), GetAllDownloads(_)) | 449 EXPECT_CALL(*manager_.get(), GetAllDownloads(_)) |
449 .WillRepeatedly(SetArgPointee<0>(items)); | 450 .WillRepeatedly(SetArgPointee<0>(items)); |
450 } | 451 } |
451 | 452 |
452 private: | 453 private: |
453 base::MessageLoopForUI loop_; | 454 base::MessageLoopForUI loop_; |
454 content::TestBrowserThread ui_thread_; | 455 content::TestBrowserThread ui_thread_; |
455 std::vector<StrictMockDownloadItem*> items_; | 456 std::vector<StrictMockDownloadItem*> items_; |
456 scoped_ptr<content::MockDownloadManager> manager_; | 457 scoped_ptr<content::MockDownloadManager> manager_; |
457 FakeHistoryAdapter* history_; | 458 FakeHistoryAdapter* history_; |
458 scoped_ptr<DownloadHistory> download_history_; | 459 scoped_ptr<DownloadHistory> download_history_; |
459 content::DownloadManager::Observer* manager_observer_; | 460 content::DownloadManager::Observer* manager_observer_; |
460 content::DownloadItem::Observer* item_observer_; | 461 content::DownloadItem::Observer* item_observer_; |
461 size_t download_created_index_; | 462 size_t download_created_index_; |
462 | 463 |
463 DISALLOW_COPY_AND_ASSIGN(DownloadHistoryTest); | 464 DISALLOW_COPY_AND_ASSIGN(DownloadHistoryTest); |
464 }; | 465 }; |
465 | 466 |
466 } // anonymous namespace | 467 } // namespace |
467 | 468 |
468 // Test loading an item from the database, changing it, saving it back, removing | 469 // Test loading an item from the database, changing it, saving it back, removing |
469 // it. | 470 // it. |
470 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Load) { | 471 TEST_F(DownloadHistoryTest, DownloadHistoryTest_Load) { |
471 // Load a download from history, create the item, OnDownloadCreated, | 472 // Load a download from history, create the item, OnDownloadCreated, |
472 // OnDownloadUpdated, OnDownloadRemoved. | 473 // OnDownloadUpdated, OnDownloadRemoved. |
473 history::DownloadRow info; | 474 history::DownloadRow info; |
474 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), | 475 InitBasicItem(FILE_PATH_LITERAL("/foo/bar.pdf"), |
475 "http://example.com/bar.pdf", | 476 "http://example.com/bar.pdf", |
476 "http://example.com/referrer.html", | 477 "http://example.com/referrer.html", |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 item_observer()->OnDownloadUpdated(&item(0)); | 788 item_observer()->OnDownloadUpdated(&item(0)); |
788 | 789 |
789 FinishCreateDownload(); | 790 FinishCreateDownload(); |
790 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 791 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
791 | 792 |
792 // ItemAdded should call OnDownloadUpdated, which should detect that the item | 793 // ItemAdded should call OnDownloadUpdated, which should detect that the item |
793 // changed while it was being added and call UpdateDownload immediately. | 794 // changed while it was being added and call UpdateDownload immediately. |
794 info.opened = true; | 795 info.opened = true; |
795 ExpectDownloadUpdated(info); | 796 ExpectDownloadUpdated(info); |
796 } | 797 } |
OLD | NEW |