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

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

Issue 8372073: Merge 8401001 r107836 into branch 912: Fix history importing by delaying DownloadManager creation. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/912/src/
Patch Set: Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <string> 5 #include <string>
6 #include <set> 6 #include <set>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/i18n/number_formatting.h" 10 #include "base/i18n/number_formatting.h"
11 #include "base/i18n/rtl.h" 11 #include "base/i18n/rtl.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/string16.h" 14 #include "base/string16.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "chrome/browser/download/chrome_download_manager_delegate.h" 18 #include "chrome/browser/download/chrome_download_manager_delegate.h"
19 #include "chrome/browser/download/download_item_model.h" 19 #include "chrome/browser/download/download_item_model.h"
20 #include "chrome/browser/download/download_prefs.h" 20 #include "chrome/browser/download/download_prefs.h"
21 #include "chrome/browser/download/download_util.h" 21 #include "chrome/browser/download/download_util.h"
22 #include "chrome/browser/prefs/pref_service.h" 22 #include "chrome/browser/prefs/pref_service.h"
23 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
24 #include "chrome/test/base/testing_profile.h" 24 #include "chrome/test/base/testing_profile.h"
25 #include "content/browser/browser_thread.h" 25 #include "content/browser/browser_thread.h"
26 #include "content/browser/download/download_create_info.h" 26 #include "content/browser/download/download_create_info.h"
27 #include "content/browser/download/download_file.h" 27 #include "content/browser/download/download_file.h"
28 #include "content/browser/download/download_file_manager.h" 28 #include "content/browser/download/download_file_manager.h"
29 #include "content/browser/download/download_id_factory.h"
29 #include "content/browser/download/download_item.h" 30 #include "content/browser/download/download_item.h"
30 #include "content/browser/download/download_manager.h" 31 #include "content/browser/download/download_manager.h"
31 #include "content/browser/download/download_status_updater.h" 32 #include "content/browser/download/download_status_updater.h"
32 #include "content/browser/download/interrupt_reasons.h" 33 #include "content/browser/download/interrupt_reasons.h"
33 #include "content/browser/download/mock_download_manager.h" 34 #include "content/browser/download/mock_download_manager.h"
34 #include "grit/generated_resources.h" 35 #include "grit/generated_resources.h"
35 #include "net/base/io_buffer.h" 36 #include "net/base/io_buffer.h"
36 #include "net/base/mock_file_stream.h" 37 #include "net/base/mock_file_stream.h"
37 #include "testing/gmock/include/gmock/gmock.h" 38 #include "testing/gmock/include/gmock/gmock.h"
38 #include "testing/gmock_mutant.h" 39 #include "testing/gmock_mutant.h"
39 #include "testing/gtest/include/gtest/gtest.h" 40 #include "testing/gtest/include/gtest/gtest.h"
40 #include "ui/base/l10n/l10n_util.h" 41 #include "ui/base/l10n/l10n_util.h"
41 #include "ui/base/text/bytes_formatting.h" 42 #include "ui/base/text/bytes_formatting.h"
42 43
44 DownloadId::Domain kValidIdDomain = "valid DownloadId::Domain";
45
43 class DownloadManagerTest : public testing::Test { 46 class DownloadManagerTest : public testing::Test {
44 public: 47 public:
45 static const char* kTestData; 48 static const char* kTestData;
46 static const size_t kTestDataLen; 49 static const size_t kTestDataLen;
47 50
48 DownloadManagerTest() 51 DownloadManagerTest()
49 : profile_(new TestingProfile()), 52 : profile_(new TestingProfile()),
50 download_manager_delegate_(new ChromeDownloadManagerDelegate( 53 download_manager_delegate_(new ChromeDownloadManagerDelegate(
51 profile_.get())), 54 profile_.get())),
55 id_factory_(new DownloadIdFactory(kValidIdDomain)),
52 download_manager_(new MockDownloadManager( 56 download_manager_(new MockDownloadManager(
53 download_manager_delegate_, &download_status_updater_)), 57 download_manager_delegate_,
58 id_factory_.get(),
59 &download_status_updater_)),
54 ui_thread_(BrowserThread::UI, &message_loop_), 60 ui_thread_(BrowserThread::UI, &message_loop_),
55 file_thread_(BrowserThread::FILE, &message_loop_) { 61 file_thread_(BrowserThread::FILE, &message_loop_) {
56 download_manager_->Init(profile_.get()); 62 download_manager_->Init(profile_.get());
57 download_manager_delegate_->SetDownloadManager(download_manager_); 63 download_manager_delegate_->SetDownloadManager(download_manager_);
58 } 64 }
59 65
60 ~DownloadManagerTest() { 66 ~DownloadManagerTest() {
61 download_manager_->Shutdown(); 67 download_manager_->Shutdown();
62 // profile_ must outlive download_manager_, so we explicitly delete 68 // profile_ must outlive download_manager_, so we explicitly delete
63 // download_manager_ first. 69 // download_manager_ first.
64 download_manager_ = NULL; 70 download_manager_ = NULL;
65 download_manager_delegate_ = NULL; 71 download_manager_delegate_ = NULL;
66 profile_.reset(NULL); 72 profile_.reset(NULL);
67 message_loop_.RunAllPending(); 73 message_loop_.RunAllPending();
68 } 74 }
69 75
70 void AddDownloadToFileManager(int id, DownloadFile* download_file) { 76 void AddDownloadToFileManager(int id, DownloadFile* download_file) {
71 file_manager()->downloads_[DownloadId(download_manager_.get(), id)] = 77 file_manager()->downloads_[DownloadId(kValidIdDomain, id)] =
72 download_file; 78 download_file;
73 } 79 }
74 80
75 void OnResponseCompleted(int32 download_id, int64 size, 81 void OnResponseCompleted(int32 download_id, int64 size,
76 const std::string& hash) { 82 const std::string& hash) {
77 download_manager_->OnResponseCompleted(download_id, size, hash); 83 download_manager_->OnResponseCompleted(download_id, size, hash);
78 } 84 }
79 85
80 void FileSelected(const FilePath& path, void* params) { 86 void FileSelected(const FilePath& path, void* params) {
81 download_manager_->FileSelected(path, params); 87 download_manager_->FileSelected(path, params);
(...skipping 13 matching lines...) Expand all
95 { 101 {
96 base::AutoLock auto_lock(download_buffer_.lock); 102 base::AutoLock auto_lock(download_buffer_.lock);
97 103
98 download_buffer_.contents.push_back( 104 download_buffer_.contents.push_back(
99 std::make_pair(io_buffer, length)); 105 std::make_pair(io_buffer, length));
100 } 106 }
101 107
102 BrowserThread::PostTask( 108 BrowserThread::PostTask(
103 BrowserThread::FILE, FROM_HERE, 109 BrowserThread::FILE, FROM_HERE,
104 base::Bind(&DownloadFileManager::UpdateDownload, file_manager_.get(), 110 base::Bind(&DownloadFileManager::UpdateDownload, file_manager_.get(),
105 DownloadId(download_manager_.get(), id), &download_buffer_)); 111 DownloadId(kValidIdDomain, id), &download_buffer_));
106 112
107 message_loop_.RunAllPending(); 113 message_loop_.RunAllPending();
108 } 114 }
109 115
110 void OnDownloadInterrupted(int32 download_id, int64 size, 116 void OnDownloadInterrupted(int32 download_id, int64 size,
111 InterruptReason reason) { 117 InterruptReason reason) {
112 download_manager_->OnDownloadInterrupted(download_id, size, reason); 118 download_manager_->OnDownloadInterrupted(download_id, size, reason);
113 } 119 }
114 120
115 // Get the download item with ID |id|. 121 // Get the download item with ID |id|.
116 DownloadItem* GetActiveDownloadItem(int32 id) { 122 DownloadItem* GetActiveDownloadItem(int32 id) {
117 if (ContainsKey(download_manager_->active_downloads_, id)) 123 if (ContainsKey(download_manager_->active_downloads_, id))
118 return download_manager_->active_downloads_[id]; 124 return download_manager_->active_downloads_[id];
119 return NULL; 125 return NULL;
120 } 126 }
121 127
122 protected: 128 protected:
123 DownloadStatusUpdater download_status_updater_; 129 DownloadStatusUpdater download_status_updater_;
124 scoped_ptr<TestingProfile> profile_; 130 scoped_ptr<TestingProfile> profile_;
125 scoped_refptr<ChromeDownloadManagerDelegate> download_manager_delegate_; 131 scoped_refptr<ChromeDownloadManagerDelegate> download_manager_delegate_;
132 scoped_refptr<DownloadIdFactory> id_factory_;
126 scoped_refptr<DownloadManager> download_manager_; 133 scoped_refptr<DownloadManager> download_manager_;
127 scoped_refptr<DownloadFileManager> file_manager_; 134 scoped_refptr<DownloadFileManager> file_manager_;
128 MessageLoopForUI message_loop_; 135 MessageLoopForUI message_loop_;
129 BrowserThread ui_thread_; 136 BrowserThread ui_thread_;
130 BrowserThread file_thread_; 137 BrowserThread file_thread_;
131 DownloadBuffer download_buffer_; 138 DownloadBuffer download_buffer_;
132 139
133 DownloadFileManager* file_manager() { 140 DownloadFileManager* file_manager() {
134 if (!file_manager_) { 141 if (!file_manager_) {
135 file_manager_ = new DownloadFileManager(NULL); 142 file_manager_ = new DownloadFileManager(NULL);
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 384
378 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kStartDownloadCases); ++i) { 385 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kStartDownloadCases); ++i) {
379 prefs->SetBoolean(prefs::kPromptForDownload, 386 prefs->SetBoolean(prefs::kPromptForDownload,
380 kStartDownloadCases[i].prompt_for_download); 387 kStartDownloadCases[i].prompt_for_download);
381 388
382 SelectFileObserver observer(download_manager_); 389 SelectFileObserver observer(download_manager_);
383 // Normally, the download system takes ownership of info, and is 390 // Normally, the download system takes ownership of info, and is
384 // responsible for deleting it. In these unit tests, however, we 391 // responsible for deleting it. In these unit tests, however, we
385 // don't call the function that deletes it, so we do so ourselves. 392 // don't call the function that deletes it, so we do so ourselves.
386 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); 393 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo);
387 info->download_id = static_cast<int>(i); 394 info->download_id = DownloadId(kValidIdDomain, static_cast<int>(i));
388 info->prompt_user_for_save_location = kStartDownloadCases[i].save_as; 395 info->prompt_user_for_save_location = kStartDownloadCases[i].save_as;
389 info->url_chain.push_back(GURL(kStartDownloadCases[i].url)); 396 info->url_chain.push_back(GURL(kStartDownloadCases[i].url));
390 info->mime_type = kStartDownloadCases[i].mime_type; 397 info->mime_type = kStartDownloadCases[i].mime_type;
391 download_manager_->CreateDownloadItem(info.get()); 398 download_manager_->CreateDownloadItem(info.get());
392 399
393 DownloadFile* download_file( 400 DownloadFile* download_file(
394 new DownloadFile(info.get(), download_manager_)); 401 new DownloadFile(info.get(), download_manager_));
395 AddDownloadToFileManager(info->download_id, download_file); 402 AddDownloadToFileManager(info->download_id.local(), download_file);
396 download_file->Initialize(false); 403 download_file->Initialize(false);
397 download_manager_->StartDownload(info->download_id); 404 download_manager_->StartDownload(info->download_id.local());
398 message_loop_.RunAllPending(); 405 message_loop_.RunAllPending();
399 406
400 // SelectFileObserver will have recorded any attempt to open the 407 // SelectFileObserver will have recorded any attempt to open the
401 // select file dialog. 408 // select file dialog.
402 // Note that DownloadManager::FileSelectionCanceled() is never called. 409 // Note that DownloadManager::FileSelectionCanceled() is never called.
403 EXPECT_EQ(kStartDownloadCases[i].expected_save_as, 410 EXPECT_EQ(kStartDownloadCases[i].expected_save_as,
404 observer.ShowedFileDialogForId(i)); 411 observer.ShowedFileDialogForId(i));
405 } 412 }
406 } 413 }
407 414
408 TEST_F(DownloadManagerTest, DownloadRenameTest) { 415 TEST_F(DownloadManagerTest, DownloadRenameTest) {
409 using ::testing::_; 416 using ::testing::_;
410 using ::testing::CreateFunctor; 417 using ::testing::CreateFunctor;
411 using ::testing::Invoke; 418 using ::testing::Invoke;
412 using ::testing::Return; 419 using ::testing::Return;
413 420
414 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDownloadRenameCases); ++i) { 421 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDownloadRenameCases); ++i) {
415 // Normally, the download system takes ownership of info, and is 422 // Normally, the download system takes ownership of info, and is
416 // responsible for deleting it. In these unit tests, however, we 423 // responsible for deleting it. In these unit tests, however, we
417 // don't call the function that deletes it, so we do so ourselves. 424 // don't call the function that deletes it, so we do so ourselves.
418 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); 425 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo);
419 info->download_id = static_cast<int>(i); 426 info->download_id = DownloadId(kValidIdDomain, static_cast<int>(i));
420 info->prompt_user_for_save_location = false; 427 info->prompt_user_for_save_location = false;
421 info->url_chain.push_back(GURL()); 428 info->url_chain.push_back(GURL());
422 const FilePath new_path(kDownloadRenameCases[i].suggested_path); 429 const FilePath new_path(kDownloadRenameCases[i].suggested_path);
423 430
424 MockDownloadFile* download_file( 431 MockDownloadFile* download_file(
425 new MockDownloadFile(info.get(), download_manager_)); 432 new MockDownloadFile(info.get(), download_manager_));
426 AddDownloadToFileManager(info->download_id, download_file); 433 AddDownloadToFileManager(info->download_id.local(), download_file);
427 434
428 // |download_file| is owned by DownloadFileManager. 435 // |download_file| is owned by DownloadFileManager.
429 ::testing::Mock::AllowLeak(download_file); 436 ::testing::Mock::AllowLeak(download_file);
430 EXPECT_CALL(*download_file, Destructed()).Times(1); 437 EXPECT_CALL(*download_file, Destructed()).Times(1);
431 438
432 if (kDownloadRenameCases[i].expected_rename_count == 1) { 439 if (kDownloadRenameCases[i].expected_rename_count == 1) {
433 EXPECT_CALL(*download_file, Rename(new_path)).WillOnce(Return(net::OK)); 440 EXPECT_CALL(*download_file, Rename(new_path)).WillOnce(Return(net::OK));
434 } else { 441 } else {
435 ASSERT_EQ(2, kDownloadRenameCases[i].expected_rename_count); 442 ASSERT_EQ(2, kDownloadRenameCases[i].expected_rename_count);
436 FilePath crdownload(download_util::GetCrDownloadPath(new_path)); 443 FilePath crdownload(download_util::GetCrDownloadPath(new_path));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 TEST_F(DownloadManagerTest, DownloadInterruptTest) { 479 TEST_F(DownloadManagerTest, DownloadInterruptTest) {
473 using ::testing::_; 480 using ::testing::_;
474 using ::testing::CreateFunctor; 481 using ::testing::CreateFunctor;
475 using ::testing::Invoke; 482 using ::testing::Invoke;
476 using ::testing::Return; 483 using ::testing::Return;
477 484
478 // Normally, the download system takes ownership of info, and is 485 // Normally, the download system takes ownership of info, and is
479 // responsible for deleting it. In these unit tests, however, we 486 // responsible for deleting it. In these unit tests, however, we
480 // don't call the function that deletes it, so we do so ourselves. 487 // don't call the function that deletes it, so we do so ourselves.
481 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); 488 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo);
482 info->download_id = static_cast<int>(0); 489 info->download_id = DownloadId(kValidIdDomain, static_cast<int>(0));
483 info->prompt_user_for_save_location = false; 490 info->prompt_user_for_save_location = false;
484 info->url_chain.push_back(GURL()); 491 info->url_chain.push_back(GURL());
485 info->total_bytes = static_cast<int64>(kTestDataLen); 492 info->total_bytes = static_cast<int64>(kTestDataLen);
486 const FilePath new_path(FILE_PATH_LITERAL("foo.zip")); 493 const FilePath new_path(FILE_PATH_LITERAL("foo.zip"));
487 const FilePath cr_path(download_util::GetCrDownloadPath(new_path)); 494 const FilePath cr_path(download_util::GetCrDownloadPath(new_path));
488 495
489 MockDownloadFile* download_file( 496 MockDownloadFile* download_file(
490 new MockDownloadFile(info.get(), download_manager_)); 497 new MockDownloadFile(info.get(), download_manager_));
491 AddDownloadToFileManager(info->download_id, download_file); 498 AddDownloadToFileManager(info->download_id.local(), download_file);
492 499
493 // |download_file| is owned by DownloadFileManager. 500 // |download_file| is owned by DownloadFileManager.
494 ::testing::Mock::AllowLeak(download_file); 501 ::testing::Mock::AllowLeak(download_file);
495 EXPECT_CALL(*download_file, Destructed()).Times(1); 502 EXPECT_CALL(*download_file, Destructed()).Times(1);
496 503
497 EXPECT_CALL(*download_file, Rename(cr_path)).WillOnce(Return(net::OK)); 504 EXPECT_CALL(*download_file, Rename(cr_path)).WillOnce(Return(net::OK));
498 505
499 download_manager_->CreateDownloadItem(info.get()); 506 download_manager_->CreateDownloadItem(info.get());
500 507
501 DownloadItem* download = GetActiveDownloadItem(0); 508 DownloadItem* download = GetActiveDownloadItem(0);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 net::testing::MockFileStream* mock_stream = new net::testing::MockFileStream; 570 net::testing::MockFileStream* mock_stream = new net::testing::MockFileStream;
564 ASSERT_EQ(0, mock_stream->Open( 571 ASSERT_EQ(0, mock_stream->Open(
565 path, 572 path,
566 base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_WRITE)); 573 base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_WRITE));
567 574
568 // Normally, the download system takes ownership of info, and is 575 // Normally, the download system takes ownership of info, and is
569 // responsible for deleting it. In these unit tests, however, we 576 // responsible for deleting it. In these unit tests, however, we
570 // don't call the function that deletes it, so we do so ourselves. 577 // don't call the function that deletes it, so we do so ourselves.
571 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); 578 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo);
572 int32 id = 0; 579 int32 id = 0;
573 info->download_id = id; 580 info->download_id = DownloadId(kValidIdDomain, id);
574 info->prompt_user_for_save_location = false; 581 info->prompt_user_for_save_location = false;
575 info->url_chain.push_back(GURL()); 582 info->url_chain.push_back(GURL());
576 info->total_bytes = static_cast<int64>(kTestDataLen * 3); 583 info->total_bytes = static_cast<int64>(kTestDataLen * 3);
577 info->save_info.file_path = path; 584 info->save_info.file_path = path;
578 585
579 // Create a download file that we can insert errors into. 586 // Create a download file that we can insert errors into.
580 DownloadFileWithMockStream* download_file(new DownloadFileWithMockStream( 587 DownloadFileWithMockStream* download_file(new DownloadFileWithMockStream(
581 info.get(), download_manager_, mock_stream)); 588 info.get(), download_manager_, mock_stream));
582 AddDownloadToFileManager(id, download_file); 589 AddDownloadToFileManager(id, download_file);
583 590
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 TEST_F(DownloadManagerTest, DownloadCancelTest) { 648 TEST_F(DownloadManagerTest, DownloadCancelTest) {
642 using ::testing::_; 649 using ::testing::_;
643 using ::testing::CreateFunctor; 650 using ::testing::CreateFunctor;
644 using ::testing::Invoke; 651 using ::testing::Invoke;
645 using ::testing::Return; 652 using ::testing::Return;
646 653
647 // Normally, the download system takes ownership of info, and is 654 // Normally, the download system takes ownership of info, and is
648 // responsible for deleting it. In these unit tests, however, we 655 // responsible for deleting it. In these unit tests, however, we
649 // don't call the function that deletes it, so we do so ourselves. 656 // don't call the function that deletes it, so we do so ourselves.
650 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); 657 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo);
651 info->download_id = static_cast<int>(0); 658 info->download_id = DownloadId(kValidIdDomain, static_cast<int>(0));
652 info->prompt_user_for_save_location = false; 659 info->prompt_user_for_save_location = false;
653 info->url_chain.push_back(GURL()); 660 info->url_chain.push_back(GURL());
654 const FilePath new_path(FILE_PATH_LITERAL("foo.zip")); 661 const FilePath new_path(FILE_PATH_LITERAL("foo.zip"));
655 const FilePath cr_path(download_util::GetCrDownloadPath(new_path)); 662 const FilePath cr_path(download_util::GetCrDownloadPath(new_path));
656 663
657 MockDownloadFile* download_file( 664 MockDownloadFile* download_file(
658 new MockDownloadFile(info.get(), download_manager_)); 665 new MockDownloadFile(info.get(), download_manager_));
659 AddDownloadToFileManager(info->download_id, download_file); 666 AddDownloadToFileManager(info->download_id.local(), download_file);
660 667
661 // |download_file| is owned by DownloadFileManager. 668 // |download_file| is owned by DownloadFileManager.
662 ::testing::Mock::AllowLeak(download_file); 669 ::testing::Mock::AllowLeak(download_file);
663 EXPECT_CALL(*download_file, Destructed()).Times(1); 670 EXPECT_CALL(*download_file, Destructed()).Times(1);
664 671
665 EXPECT_CALL(*download_file, Rename(cr_path)).WillOnce(Return(net::OK)); 672 EXPECT_CALL(*download_file, Rename(cr_path)).WillOnce(Return(net::OK));
666 673
667 download_manager_->CreateDownloadItem(info.get()); 674 download_manager_->CreateDownloadItem(info.get());
668 675
669 DownloadItem* download = GetActiveDownloadItem(0); 676 DownloadItem* download = GetActiveDownloadItem(0);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 // which we will override. 732 // which we will override.
726 int uniquifier = DownloadFile::GetUniquePathNumber(new_path); 733 int uniquifier = DownloadFile::GetUniquePathNumber(new_path);
727 FilePath unique_new_path = new_path; 734 FilePath unique_new_path = new_path;
728 EXPECT_NE(0, uniquifier); 735 EXPECT_NE(0, uniquifier);
729 DownloadFile::AppendNumberToPath(&unique_new_path, uniquifier); 736 DownloadFile::AppendNumberToPath(&unique_new_path, uniquifier);
730 737
731 // Normally, the download system takes ownership of info, and is 738 // Normally, the download system takes ownership of info, and is
732 // responsible for deleting it. In these unit tests, however, we 739 // responsible for deleting it. In these unit tests, however, we
733 // don't call the function that deletes it, so we do so ourselves. 740 // don't call the function that deletes it, so we do so ourselves.
734 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); 741 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo);
735 info->download_id = static_cast<int>(0); 742 info->download_id = DownloadId(kValidIdDomain, static_cast<int>(0));
736 info->prompt_user_for_save_location = true; 743 info->prompt_user_for_save_location = true;
737 info->url_chain.push_back(GURL()); 744 info->url_chain.push_back(GURL());
738 745
739 download_manager_->CreateDownloadItem(info.get()); 746 download_manager_->CreateDownloadItem(info.get());
740 747
741 DownloadItem* download = GetActiveDownloadItem(0); 748 DownloadItem* download = GetActiveDownloadItem(0);
742 ASSERT_TRUE(download != NULL); 749 ASSERT_TRUE(download != NULL);
743 scoped_ptr<DownloadItemModel> download_item_model( 750 scoped_ptr<DownloadItemModel> download_item_model(
744 new DownloadItemModel(download)); 751 new DownloadItemModel(download));
745 752
746 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->state()); 753 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->state());
747 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); 754 scoped_ptr<ItemObserver> observer(new ItemObserver(download));
748 755
749 // Create and initialize the download file. We're bypassing the first part 756 // Create and initialize the download file. We're bypassing the first part
750 // of the download process and skipping to the part after the final file 757 // of the download process and skipping to the part after the final file
751 // name has been chosen, so we need to initialize the download file 758 // name has been chosen, so we need to initialize the download file
752 // properly. 759 // properly.
753 DownloadFile* download_file( 760 DownloadFile* download_file(
754 new DownloadFile(info.get(), download_manager_)); 761 new DownloadFile(info.get(), download_manager_));
755 download_file->Rename(cr_path); 762 download_file->Rename(cr_path);
756 // This creates the .crdownload version of the file. 763 // This creates the .crdownload version of the file.
757 download_file->Initialize(false); 764 download_file->Initialize(false);
758 // |download_file| is owned by DownloadFileManager. 765 // |download_file| is owned by DownloadFileManager.
759 AddDownloadToFileManager(info->download_id, download_file); 766 AddDownloadToFileManager(info->download_id.local(), download_file);
760 767
761 ContinueDownloadWithPath(download, new_path); 768 ContinueDownloadWithPath(download, new_path);
762 message_loop_.RunAllPending(); 769 message_loop_.RunAllPending();
763 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); 770 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL);
764 771
765 download_file->AppendDataToFile(kTestData, kTestDataLen); 772 download_file->AppendDataToFile(kTestData, kTestDataLen);
766 773
767 // Finish the download. 774 // Finish the download.
768 OnResponseCompleted(0, kTestDataLen, ""); 775 OnResponseCompleted(0, kTestDataLen, "");
769 message_loop_.RunAllPending(); 776 message_loop_.RunAllPending();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 808
802 // File names we're using. 809 // File names we're using.
803 const FilePath new_path(temp_dir_.path().AppendASCII("foo.txt")); 810 const FilePath new_path(temp_dir_.path().AppendASCII("foo.txt"));
804 const FilePath cr_path(download_util::GetCrDownloadPath(new_path)); 811 const FilePath cr_path(download_util::GetCrDownloadPath(new_path));
805 EXPECT_FALSE(file_util::PathExists(new_path)); 812 EXPECT_FALSE(file_util::PathExists(new_path));
806 813
807 // Normally, the download system takes ownership of info, and is 814 // Normally, the download system takes ownership of info, and is
808 // responsible for deleting it. In these unit tests, however, we 815 // responsible for deleting it. In these unit tests, however, we
809 // don't call the function that deletes it, so we do so ourselves. 816 // don't call the function that deletes it, so we do so ourselves.
810 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); 817 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo);
811 info->download_id = static_cast<int>(0); 818 info->download_id = DownloadId(kValidIdDomain, static_cast<int>(0));
812 info->prompt_user_for_save_location = true; 819 info->prompt_user_for_save_location = true;
813 info->url_chain.push_back(GURL()); 820 info->url_chain.push_back(GURL());
814 821
815 download_manager_->CreateDownloadItem(info.get()); 822 download_manager_->CreateDownloadItem(info.get());
816 823
817 DownloadItem* download = GetActiveDownloadItem(0); 824 DownloadItem* download = GetActiveDownloadItem(0);
818 ASSERT_TRUE(download != NULL); 825 ASSERT_TRUE(download != NULL);
819 scoped_ptr<DownloadItemModel> download_item_model( 826 scoped_ptr<DownloadItemModel> download_item_model(
820 new DownloadItemModel(download)); 827 new DownloadItemModel(download));
821 828
822 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->state()); 829 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->state());
823 scoped_ptr<ItemObserver> observer(new ItemObserver(download)); 830 scoped_ptr<ItemObserver> observer(new ItemObserver(download));
824 831
825 // Create and initialize the download file. We're bypassing the first part 832 // Create and initialize the download file. We're bypassing the first part
826 // of the download process and skipping to the part after the final file 833 // of the download process and skipping to the part after the final file
827 // name has been chosen, so we need to initialize the download file 834 // name has been chosen, so we need to initialize the download file
828 // properly. 835 // properly.
829 DownloadFile* download_file( 836 DownloadFile* download_file(
830 new DownloadFile(info.get(), download_manager_)); 837 new DownloadFile(info.get(), download_manager_));
831 download_file->Rename(cr_path); 838 download_file->Rename(cr_path);
832 // This creates the .crdownload version of the file. 839 // This creates the .crdownload version of the file.
833 download_file->Initialize(false); 840 download_file->Initialize(false);
834 // |download_file| is owned by DownloadFileManager. 841 // |download_file| is owned by DownloadFileManager.
835 AddDownloadToFileManager(info->download_id, download_file); 842 AddDownloadToFileManager(info->download_id.local(), download_file);
836 843
837 ContinueDownloadWithPath(download, new_path); 844 ContinueDownloadWithPath(download, new_path);
838 message_loop_.RunAllPending(); 845 message_loop_.RunAllPending();
839 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL); 846 EXPECT_TRUE(GetActiveDownloadItem(0) != NULL);
840 847
841 download_file->AppendDataToFile(kTestData, kTestDataLen); 848 download_file->AppendDataToFile(kTestData, kTestDataLen);
842 849
843 // Finish the download. 850 // Finish the download.
844 OnResponseCompleted(0, kTestDataLen, ""); 851 OnResponseCompleted(0, kTestDataLen, "");
845 message_loop_.RunAllPending(); 852 message_loop_.RunAllPending();
(...skipping 27 matching lines...) Expand all
873 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); 880 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING));
874 EXPECT_TRUE(observer->was_updated()); 881 EXPECT_TRUE(observer->was_updated());
875 EXPECT_FALSE(observer->was_opened()); 882 EXPECT_FALSE(observer->was_opened());
876 EXPECT_TRUE(download->file_externally_removed()); 883 EXPECT_TRUE(download->file_externally_removed());
877 EXPECT_EQ(DownloadItem::COMPLETE, download->state()); 884 EXPECT_EQ(DownloadItem::COMPLETE, download->state());
878 EXPECT_EQ(download_item_model->GetStatusText(), 885 EXPECT_EQ(download_item_model->GetStatusText(),
879 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED)); 886 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED));
880 887
881 EXPECT_FALSE(file_util::PathExists(new_path)); 888 EXPECT_FALSE(file_util::PathExists(new_path));
882 } 889 }
OLDNEW
« no previous file with comments | « chrome/browser/download/chrome_download_manager_delegate.cc ('k') | chrome/browser/download/download_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698