| 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 "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/test/test_file_util.h" | 15 #include "base/test/test_file_util.h" |
| 16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 #include "chrome/browser/download/download_path_reservation_tracker.h" | 17 #include "chrome/browser/download/download_path_reservation_tracker.h" |
| 18 #include "chrome/browser/download/download_target_determiner.h" | 18 #include "chrome/browser/download/download_target_determiner.h" |
| 19 #include "chrome/common/features.h" |
| 19 #include "content/public/test/mock_download_item.h" | 20 #include "content/public/test/mock_download_item.h" |
| 20 #include "content/public/test/test_browser_thread.h" | 21 #include "content/public/test/test_browser_thread.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 24 |
| 24 using content::BrowserThread; | 25 using content::BrowserThread; |
| 25 using content::DownloadItem; | 26 using content::DownloadItem; |
| 26 using content::MockDownloadItem; | 27 using content::MockDownloadItem; |
| 27 using testing::AnyNumber; | 28 using testing::AnyNumber; |
| 28 using testing::Return; | 29 using testing::Return; |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 bool create_directory = false; | 495 bool create_directory = false; |
| 495 CallGetReservedPath( | 496 CallGetReservedPath( |
| 496 item.get(), | 497 item.get(), |
| 497 path, | 498 path, |
| 498 create_directory, | 499 create_directory, |
| 499 conflict_action, | 500 conflict_action, |
| 500 &reserved_path, | 501 &reserved_path, |
| 501 &verified); | 502 &verified); |
| 502 // Verification fails. | 503 // Verification fails. |
| 503 EXPECT_FALSE(verified); | 504 EXPECT_FALSE(verified); |
| 505 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 506 EXPECT_TRUE(reserved_path.empty()); |
| 507 #else |
| 504 EXPECT_EQ(path.BaseName().value(), reserved_path.BaseName().value()); | 508 EXPECT_EQ(path.BaseName().value(), reserved_path.BaseName().value()); |
| 509 #endif |
| 505 } | 510 } |
| 506 SetDownloadItemState(item.get(), DownloadItem::COMPLETE); | 511 SetDownloadItemState(item.get(), DownloadItem::COMPLETE); |
| 507 } | 512 } |
| 508 | 513 |
| 509 // If the default download directory doesn't exist, then it should be | 514 // If the default download directory doesn't exist, then it should be |
| 510 // created. But only if we are actually going to create the download path there. | 515 // created. But only if we are actually going to create the download path there. |
| 511 TEST_F(DownloadPathReservationTrackerTest, CreateDefaultDownloadPath) { | 516 TEST_F(DownloadPathReservationTrackerTest, CreateDefaultDownloadPath) { |
| 512 base::FilePath path( | 517 base::FilePath path( |
| 513 GetPathInDownloadsDirectory(FILE_PATH_LITERAL("foo/foo.txt"))); | 518 GetPathInDownloadsDirectory(FILE_PATH_LITERAL("foo/foo.txt"))); |
| 514 base::FilePath dir(path.DirName()); | 519 base::FilePath dir(path.DirName()); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 create_directory, | 708 create_directory, |
| 704 conflict_action, | 709 conflict_action, |
| 705 &reserved_path, | 710 &reserved_path, |
| 706 &verified); | 711 &verified); |
| 707 // We cannot truncate a path with very long extension. | 712 // We cannot truncate a path with very long extension. |
| 708 EXPECT_FALSE(verified); | 713 EXPECT_FALSE(verified); |
| 709 SetDownloadItemState(item.get(), DownloadItem::COMPLETE); | 714 SetDownloadItemState(item.get(), DownloadItem::COMPLETE); |
| 710 } | 715 } |
| 711 | 716 |
| 712 #endif // Platforms that support filename truncation. | 717 #endif // Platforms that support filename truncation. |
| OLD | NEW |