| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/message_loop/message_loop.h" | |
| 15 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
| 16 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 17 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 18 #include "base/test/test_file_util.h" | 17 #include "base/test/test_file_util.h" |
| 19 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 20 #include "chrome/browser/download/download_path_reservation_tracker.h" | 19 #include "chrome/browser/download/download_path_reservation_tracker.h" |
| 21 #include "chrome/browser/download/download_target_determiner.h" | 20 #include "chrome/browser/download/download_target_determiner.h" |
| 22 #include "content/public/test/mock_download_item.h" | 21 #include "content/public/test/mock_download_item.h" |
| 23 #include "content/public/test/test_browser_thread.h" | 22 #include "content/public/test/test_browser_thread_bundle.h" |
| 24 #include "net/base/filename_util.h" | 23 #include "net/base/filename_util.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 26 |
| 28 using content::BrowserThread; | |
| 29 using content::DownloadItem; | 27 using content::DownloadItem; |
| 30 using content::MockDownloadItem; | 28 using content::MockDownloadItem; |
| 31 using testing::AnyNumber; | 29 using testing::AnyNumber; |
| 32 using testing::Return; | 30 using testing::Return; |
| 33 using testing::ReturnRef; | 31 using testing::ReturnRef; |
| 34 using testing::ReturnRefOfCopy; | 32 using testing::ReturnRefOfCopy; |
| 35 | 33 |
| 36 namespace { | 34 namespace { |
| 37 | 35 |
| 38 class DownloadPathReservationTrackerTest : public testing::Test { | 36 class DownloadPathReservationTrackerTest : public testing::Test { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 62 default_download_path_ = path; | 60 default_download_path_ = path; |
| 63 } | 61 } |
| 64 // Creates a name of form 'a'*repeat + suffix | 62 // Creates a name of form 'a'*repeat + suffix |
| 65 base::FilePath GetLongNamePathInDownloadsDirectory( | 63 base::FilePath GetLongNamePathInDownloadsDirectory( |
| 66 size_t repeat, | 64 size_t repeat, |
| 67 const base::FilePath::CharType* suffix); | 65 const base::FilePath::CharType* suffix); |
| 68 | 66 |
| 69 protected: | 67 protected: |
| 70 base::ScopedTempDir test_download_dir_; | 68 base::ScopedTempDir test_download_dir_; |
| 71 base::FilePath default_download_path_; | 69 base::FilePath default_download_path_; |
| 72 base::MessageLoopForUI message_loop_; | 70 content::TestBrowserThreadBundle test_browser_thread_bundle_; |
| 73 content::TestBrowserThread ui_thread_; | |
| 74 content::TestBrowserThread file_thread_; | |
| 75 | 71 |
| 76 private: | 72 private: |
| 77 void TestReservedPathCallback(base::FilePath* return_path, | 73 void TestReservedPathCallback(base::FilePath* return_path, |
| 78 PathValidationResult* return_result, | 74 PathValidationResult* return_result, |
| 79 const base::Closure& quit_closure, | 75 const base::Closure& quit_closure, |
| 80 PathValidationResult result, | 76 PathValidationResult result, |
| 81 const base::FilePath& path); | 77 const base::FilePath& path); |
| 82 }; | 78 }; |
| 83 | 79 |
| 84 DownloadPathReservationTrackerTest::DownloadPathReservationTrackerTest() | 80 DownloadPathReservationTrackerTest::DownloadPathReservationTrackerTest() = |
| 85 : ui_thread_(BrowserThread::UI, &message_loop_), | 81 default; |
| 86 file_thread_(BrowserThread::FILE, &message_loop_) { | |
| 87 } | |
| 88 | 82 |
| 89 void DownloadPathReservationTrackerTest::SetUp() { | 83 void DownloadPathReservationTrackerTest::SetUp() { |
| 90 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir()); | 84 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir()); |
| 91 set_default_download_path(test_download_dir_.GetPath()); | 85 set_default_download_path(test_download_dir_.GetPath()); |
| 92 } | 86 } |
| 93 | 87 |
| 94 void DownloadPathReservationTrackerTest::TearDown() { | 88 void DownloadPathReservationTrackerTest::TearDown() { |
| 95 base::RunLoop().RunUntilIdle(); | 89 base::RunLoop().RunUntilIdle(); |
| 96 } | 90 } |
| 97 | 91 |
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 DownloadPathReservationTracker::OVERWRITE; | 670 DownloadPathReservationTracker::OVERWRITE; |
| 677 bool create_directory = false; | 671 bool create_directory = false; |
| 678 CallGetReservedPath(item.get(), path, create_directory, conflict_action, | 672 CallGetReservedPath(item.get(), path, create_directory, conflict_action, |
| 679 &reserved_path, &result); | 673 &reserved_path, &result); |
| 680 // We cannot truncate a path with very long extension. | 674 // We cannot truncate a path with very long extension. |
| 681 EXPECT_EQ(PathValidationResult::NAME_TOO_LONG, result); | 675 EXPECT_EQ(PathValidationResult::NAME_TOO_LONG, result); |
| 682 SetDownloadItemState(item.get(), DownloadItem::COMPLETE); | 676 SetDownloadItemState(item.get(), DownloadItem::COMPLETE); |
| 683 } | 677 } |
| 684 | 678 |
| 685 #endif // Platforms that support filename truncation. | 679 #endif // Platforms that support filename truncation. |
| OLD | NEW |