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

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

Issue 2618743006: Use previous target path when resuming a download after crash (Closed)
Patch Set: move the target path logic into if(!is_forced_path) statement Created 3 years, 11 months 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
OLDNEW
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/at_exit.h" 8 #include "base/at_exit.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 1596 matching lines...) Expand 10 before | Expand all | Expand 10 after
1607 EXPECT_CALL(*delegate(), NotifyExtensions(_, _, _)) 1607 EXPECT_CALL(*delegate(), NotifyExtensions(_, _, _))
1608 .Times(test_case.test_type == AUTOMATIC ? 1 : 0); 1608 .Times(test_case.test_type == AUTOMATIC ? 1 : 0);
1609 EXPECT_CALL(*delegate(), ReserveVirtualPath(_, expected_path, false, _, _)); 1609 EXPECT_CALL(*delegate(), ReserveVirtualPath(_, expected_path, false, _, _));
1610 EXPECT_CALL(*delegate(), PromptUserForDownloadPath(_, _, _)) 1610 EXPECT_CALL(*delegate(), PromptUserForDownloadPath(_, _, _))
1611 .Times(0); 1611 .Times(0);
1612 EXPECT_CALL(*delegate(), DetermineLocalPath(_, expected_path, _)); 1612 EXPECT_CALL(*delegate(), DetermineLocalPath(_, expected_path, _));
1613 EXPECT_CALL(*delegate(), CheckDownloadUrl(_, expected_path, _)); 1613 EXPECT_CALL(*delegate(), CheckDownloadUrl(_, expected_path, _));
1614 RunTestCase(test_case, GetPathInDownloadDir(kInitialPath), item.get()); 1614 RunTestCase(test_case, GetPathInDownloadDir(kInitialPath), item.get());
1615 } 1615 }
1616 1616
1617 // Test that resuming a download will use the target file path if it is
1618 // provided.
1619 TEST_F(DownloadTargetDeterminerTest, ResumedWithTagetFilePath) {
1620 const base::FilePath::CharType* kInitialPath =
1621 FILE_PATH_LITERAL("some_path/bar.txt");
1622 const DownloadTestCase kResumedDownload = {
1623 AUTOMATIC,
1624 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
1625 DownloadFileType::NOT_DANGEROUS,
1626 "http://example.com/foo.txt",
1627 "",
1628 FILE_PATH_LITERAL(""),
1629 FILE_PATH_LITERAL("target-foo.txt"),
1630 DownloadItem::TARGET_DISPOSITION_OVERWRITE,
1631 EXPECT_CRDOWNLOAD};
1632
1633 const DownloadTestCase& test_case = kResumedDownload;
1634 base::FilePath expected_path =
1635 GetPathInDownloadDir(test_case.expected_local_path);
1636 std::unique_ptr<content::MockDownloadItem> item(
1637 CreateActiveDownloadItem(0, test_case));
1638 ON_CALL(*item.get(), GetTargetFilePath())
1639 .WillByDefault(ReturnRefOfCopy(expected_path));
1640 EXPECT_CALL(*delegate(), NotifyExtensions(_, _, _)).Times(0);
1641 EXPECT_CALL(*delegate(), ReserveVirtualPath(_, expected_path, false, _, _));
1642 EXPECT_CALL(*delegate(), PromptUserForDownloadPath(_, _, _)).Times(0);
1643 EXPECT_CALL(*delegate(), DetermineLocalPath(_, expected_path, _));
1644 EXPECT_CALL(*delegate(), CheckDownloadUrl(_, expected_path, _));
1645 RunTestCase(test_case, GetPathInDownloadDir(kInitialPath), item.get());
1646 }
1647
1617 // Prompting behavior for resumed downloads is based on the last interrupt 1648 // Prompting behavior for resumed downloads is based on the last interrupt
1618 // reason. If the reason indicates that the target path may not be suitable for 1649 // reason. If the reason indicates that the target path may not be suitable for
1619 // the download (ACCESS_DENIED, NO_SPACE, etc..), then the user should be 1650 // the download (ACCESS_DENIED, NO_SPACE, etc..), then the user should be
1620 // prompted, and not otherwise. These test cases result in prompting since the 1651 // prompted, and not otherwise. These test cases result in prompting since the
1621 // error is set to NO_SPACE. 1652 // error is set to NO_SPACE.
1622 TEST_F(DownloadTargetDeterminerTest, ResumedWithPrompt) { 1653 TEST_F(DownloadTargetDeterminerTest, ResumedWithPrompt) {
1623 // All test cases run with GetPathInDownloadDir(kInitialPath) as the inital 1654 // All test cases run with GetPathInDownloadDir(kInitialPath) as the inital
1624 // path. 1655 // path.
1625 const base::FilePath::CharType* kInitialPath = 1656 const base::FilePath::CharType* kInitialPath =
1626 FILE_PATH_LITERAL("some_path/bar.txt"); 1657 FILE_PATH_LITERAL("some_path/bar.txt");
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
2156 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(browser_plugin.path())) 2187 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(browser_plugin.path()))
2157 .WillRepeatedly(Return(false)); 2188 .WillRepeatedly(Return(false));
2158 target_info = RunDownloadTargetDeterminer( 2189 target_info = RunDownloadTargetDeterminer(
2159 GetPathInDownloadDir(kInitialPath), item.get()); 2190 GetPathInDownloadDir(kInitialPath), item.get());
2160 EXPECT_FALSE(target_info->is_filetype_handled_safely); 2191 EXPECT_FALSE(target_info->is_filetype_handled_safely);
2161 } 2192 }
2162 2193
2163 #endif // BUILDFLAG(ENABLE_PLUGINS) 2194 #endif // BUILDFLAG(ENABLE_PLUGINS)
2164 2195
2165 } // namespace 2196 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698