| OLD | NEW |
| 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 <set> | 5 #include <set> |
| 6 #include <string> | 6 #include <string> |
| 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" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include "content/browser/download/mock_download_manager.h" | 36 #include "content/browser/download/mock_download_manager.h" |
| 37 #include "content/test/test_browser_thread.h" | 37 #include "content/test/test_browser_thread.h" |
| 38 #include "grit/generated_resources.h" | 38 #include "grit/generated_resources.h" |
| 39 #include "net/base/io_buffer.h" | 39 #include "net/base/io_buffer.h" |
| 40 #include "testing/gmock/include/gmock/gmock.h" | 40 #include "testing/gmock/include/gmock/gmock.h" |
| 41 #include "testing/gmock_mutant.h" | 41 #include "testing/gmock_mutant.h" |
| 42 #include "testing/gtest/include/gtest/gtest.h" | 42 #include "testing/gtest/include/gtest/gtest.h" |
| 43 #include "ui/base/l10n/l10n_util.h" | 43 #include "ui/base/l10n/l10n_util.h" |
| 44 #include "ui/base/text/bytes_formatting.h" | 44 #include "ui/base/text/bytes_formatting.h" |
| 45 | 45 |
| 46 #if defined(USE_AURA) && defined(OS_WIN) |
| 47 // http://crbug.com/105200 |
| 48 #define MAYBE_StartDownload DISABLED_StartDownload |
| 49 #define MAYBE_DownloadOverwriteTest DISABLED_DownloadOverwriteTest |
| 50 #define MAYBE_DownloadRemoveTest DISABLED_DownloadRemoveTest |
| 51 #else |
| 52 #define MAYBE_StartDownload StartDownload |
| 53 #define MAYBE_DownloadOverwriteTest DownloadOverwriteTest |
| 54 #define MAYBE_DownloadRemoveTest DownloadRemoveTest |
| 55 #endif |
| 56 |
| 46 using content::BrowserThread; | 57 using content::BrowserThread; |
| 47 | 58 |
| 48 DownloadId::Domain kValidIdDomain = "valid DownloadId::Domain"; | 59 DownloadId::Domain kValidIdDomain = "valid DownloadId::Domain"; |
| 49 | 60 |
| 50 class DownloadManagerTest : public testing::Test { | 61 class DownloadManagerTest : public testing::Test { |
| 51 public: | 62 public: |
| 52 static const char* kTestData; | 63 static const char* kTestData; |
| 53 static const size_t kTestDataLen; | 64 static const size_t kTestDataLen; |
| 54 | 65 |
| 55 DownloadManagerTest() | 66 DownloadManagerTest() |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 } | 352 } |
| 342 | 353 |
| 343 DownloadItem* tracked_; | 354 DownloadItem* tracked_; |
| 344 int states_hit_; | 355 int states_hit_; |
| 345 bool was_updated_; | 356 bool was_updated_; |
| 346 bool was_opened_; | 357 bool was_opened_; |
| 347 }; | 358 }; |
| 348 | 359 |
| 349 } // namespace | 360 } // namespace |
| 350 | 361 |
| 351 TEST_F(DownloadManagerTest, StartDownload) { | 362 TEST_F(DownloadManagerTest, MAYBE_StartDownload) { |
| 352 content::TestBrowserThread io_thread(BrowserThread::IO, &message_loop_); | 363 content::TestBrowserThread io_thread(BrowserThread::IO, &message_loop_); |
| 353 PrefService* prefs = profile_->GetPrefs(); | 364 PrefService* prefs = profile_->GetPrefs(); |
| 354 prefs->SetFilePath(prefs::kDownloadDefaultDirectory, FilePath()); | 365 prefs->SetFilePath(prefs::kDownloadDefaultDirectory, FilePath()); |
| 355 DownloadPrefs* download_prefs = | 366 DownloadPrefs* download_prefs = |
| 356 DownloadPrefs::FromDownloadManager(download_manager_); | 367 DownloadPrefs::FromDownloadManager(download_manager_); |
| 357 download_prefs->EnableAutoOpenBasedOnExtension( | 368 download_prefs->EnableAutoOpenBasedOnExtension( |
| 358 FilePath(FILE_PATH_LITERAL("example.pdf"))); | 369 FilePath(FILE_PATH_LITERAL("example.pdf"))); |
| 359 | 370 |
| 360 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kStartDownloadCases); ++i) { | 371 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kStartDownloadCases); ++i) { |
| 361 prefs->SetBoolean(prefs::kPromptForDownload, | 372 prefs->SetBoolean(prefs::kPromptForDownload, |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 EXPECT_FALSE(observer->was_opened()); | 685 EXPECT_FALSE(observer->was_opened()); |
| 675 EXPECT_FALSE(download->GetFileExternallyRemoved()); | 686 EXPECT_FALSE(download->GetFileExternallyRemoved()); |
| 676 EXPECT_EQ(DownloadItem::CANCELLED, download->GetState()); | 687 EXPECT_EQ(DownloadItem::CANCELLED, download->GetState()); |
| 677 EXPECT_EQ(download_item_model->GetStatusText(), | 688 EXPECT_EQ(download_item_model->GetStatusText(), |
| 678 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_CANCELED)); | 689 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_CANCELED)); |
| 679 | 690 |
| 680 EXPECT_FALSE(file_util::PathExists(new_path)); | 691 EXPECT_FALSE(file_util::PathExists(new_path)); |
| 681 EXPECT_FALSE(file_util::PathExists(cr_path)); | 692 EXPECT_FALSE(file_util::PathExists(cr_path)); |
| 682 } | 693 } |
| 683 | 694 |
| 684 TEST_F(DownloadManagerTest, DownloadOverwriteTest) { | 695 TEST_F(DownloadManagerTest, MAYBE_DownloadOverwriteTest) { |
| 685 using ::testing::_; | 696 using ::testing::_; |
| 686 using ::testing::CreateFunctor; | 697 using ::testing::CreateFunctor; |
| 687 using ::testing::Invoke; | 698 using ::testing::Invoke; |
| 688 using ::testing::Return; | 699 using ::testing::Return; |
| 689 | 700 |
| 690 // Create a temporary directory. | 701 // Create a temporary directory. |
| 691 ScopedTempDir temp_dir_; | 702 ScopedTempDir temp_dir_; |
| 692 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 703 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 693 | 704 |
| 694 // File names we're using. | 705 // File names we're using. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 EXPECT_EQ(download_item_model->GetStatusText(), ASCIIToUTF16("")); | 775 EXPECT_EQ(download_item_model->GetStatusText(), ASCIIToUTF16("")); |
| 765 | 776 |
| 766 EXPECT_TRUE(file_util::PathExists(new_path)); | 777 EXPECT_TRUE(file_util::PathExists(new_path)); |
| 767 EXPECT_FALSE(file_util::PathExists(cr_path)); | 778 EXPECT_FALSE(file_util::PathExists(cr_path)); |
| 768 EXPECT_FALSE(file_util::PathExists(unique_new_path)); | 779 EXPECT_FALSE(file_util::PathExists(unique_new_path)); |
| 769 std::string file_contents; | 780 std::string file_contents; |
| 770 EXPECT_TRUE(file_util::ReadFileToString(new_path, &file_contents)); | 781 EXPECT_TRUE(file_util::ReadFileToString(new_path, &file_contents)); |
| 771 EXPECT_EQ(std::string(kTestData), file_contents); | 782 EXPECT_EQ(std::string(kTestData), file_contents); |
| 772 } | 783 } |
| 773 | 784 |
| 774 TEST_F(DownloadManagerTest, DownloadRemoveTest) { | 785 TEST_F(DownloadManagerTest, MAYBE_DownloadRemoveTest) { |
| 775 using ::testing::_; | 786 using ::testing::_; |
| 776 using ::testing::CreateFunctor; | 787 using ::testing::CreateFunctor; |
| 777 using ::testing::Invoke; | 788 using ::testing::Invoke; |
| 778 using ::testing::Return; | 789 using ::testing::Return; |
| 779 | 790 |
| 780 // Create a temporary directory. | 791 // Create a temporary directory. |
| 781 ScopedTempDir temp_dir_; | 792 ScopedTempDir temp_dir_; |
| 782 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 793 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 783 | 794 |
| 784 // File names we're using. | 795 // File names we're using. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); | 867 EXPECT_FALSE(observer->hit_state(DownloadItem::REMOVING)); |
| 857 EXPECT_TRUE(observer->was_updated()); | 868 EXPECT_TRUE(observer->was_updated()); |
| 858 EXPECT_FALSE(observer->was_opened()); | 869 EXPECT_FALSE(observer->was_opened()); |
| 859 EXPECT_TRUE(download->GetFileExternallyRemoved()); | 870 EXPECT_TRUE(download->GetFileExternallyRemoved()); |
| 860 EXPECT_EQ(DownloadItem::COMPLETE, download->GetState()); | 871 EXPECT_EQ(DownloadItem::COMPLETE, download->GetState()); |
| 861 EXPECT_EQ(download_item_model->GetStatusText(), | 872 EXPECT_EQ(download_item_model->GetStatusText(), |
| 862 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED)); | 873 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED)); |
| 863 | 874 |
| 864 EXPECT_FALSE(file_util::PathExists(new_path)); | 875 EXPECT_FALSE(file_util::PathExists(new_path)); |
| 865 } | 876 } |
| OLD | NEW |