| Index: chrome/browser/download/download_browsertest.cc
|
| diff --git a/chrome/browser/download/download_browsertest.cc b/chrome/browser/download/download_browsertest.cc
|
| index a6dab6d92c55cdc993a20f6e8f75e45f53698239..d5168de208d11ba356b53f09be57f0a0e393fcd1 100644
|
| --- a/chrome/browser/download/download_browsertest.cc
|
| +++ b/chrome/browser/download/download_browsertest.cc
|
| @@ -31,6 +31,7 @@
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "base/sys_info.h"
|
| #include "base/test/test_file_util.h"
|
| +#include "base/threading/thread_restrictions.h"
|
| #include "build/build_config.h"
|
| #include "chrome/app/chrome_command_ids.h"
|
| #include "chrome/browser/browser_process.h"
|
| @@ -503,6 +504,7 @@ class DownloadTest : public InProcessBrowserTest {
|
| if (!browser)
|
| return false;
|
|
|
| + base::ThreadRestrictions::ScopedAllowIO allow_io;
|
| if (!downloads_directory_.CreateUniqueTempDir())
|
| return false;
|
|
|
| @@ -631,6 +633,7 @@ class DownloadTest : public InProcessBrowserTest {
|
| bool CheckDownloadFullPaths(Browser* browser,
|
| const base::FilePath& downloaded_file,
|
| const base::FilePath& origin_file) {
|
| + base::ThreadRestrictions::ScopedAllowIO allow_io;
|
| bool origin_file_exists = base::PathExists(origin_file);
|
| EXPECT_TRUE(origin_file_exists) << origin_file.value();
|
| if (!origin_file_exists)
|
| @@ -697,6 +700,7 @@ class DownloadTest : public InProcessBrowserTest {
|
| SizeTestType type,
|
| const std::string& partial_indication,
|
| const std::string& total_indication) {
|
| + base::ThreadRestrictions::ScopedAllowIO allow_io;
|
| EXPECT_TRUE(type == SIZE_TEST_TYPE_UNKNOWN || type == SIZE_TEST_TYPE_KNOWN);
|
| if (type != SIZE_TEST_TYPE_KNOWN && type != SIZE_TEST_TYPE_UNKNOWN)
|
| return false;
|
| @@ -792,6 +796,7 @@ class DownloadTest : public InProcessBrowserTest {
|
| const int64_t file_size) {
|
| std::string file_contents;
|
|
|
| + base::ThreadRestrictions::ScopedAllowIO allow_io;
|
| bool read = base::ReadFileToString(path, &file_contents);
|
| EXPECT_TRUE(read) << "Failed reading file: " << path.value() << std::endl;
|
| if (!read)
|
| @@ -927,6 +932,7 @@ class DownloadTest : public InProcessBrowserTest {
|
|
|
| if (item->GetState() == content::DownloadItem::COMPLETE) {
|
| // Clean up the file, in case it ended up in the My Documents folder.
|
| + base::ThreadRestrictions::ScopedAllowIO allow_io;
|
| base::FilePath destination_folder = GetDownloadDirectory(browser());
|
| base::FilePath my_downloaded_file = item->GetTargetFilePath();
|
| EXPECT_TRUE(base::PathExists(my_downloaded_file));
|
| @@ -1200,6 +1206,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, Quarantine_DependsOnLocalConfig) {
|
| EXPECT_EQ(1, browser()->tab_strip_model()->count());
|
| base::FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
|
| base::FilePath downloaded_file(DestinationFile(browser(), file));
|
| + base::ThreadRestrictions::ScopedAllowIO allow_io;
|
| EXPECT_TRUE(content::IsFileQuarantined(downloaded_file, url, GURL()));
|
| CheckDownload(browser(), file, file);
|
| }
|
| @@ -1281,6 +1288,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) {
|
| ui_test_utils::NavigateToURL(browser(), url);
|
|
|
| // Check that we did not download the web page.
|
| + base::ThreadRestrictions::ScopedAllowIO allow_io;
|
| EXPECT_FALSE(base::PathExists(file_path));
|
|
|
| // Check state.
|
| @@ -1380,6 +1388,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadResourceThrottleCancels) {
|
| // Check that we did not download the file.
|
| base::FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
|
| base::FilePath file_path(DestinationFile(browser(), file));
|
| + base::ThreadRestrictions::ScopedAllowIO allow_io;
|
| EXPECT_FALSE(base::PathExists(file_path));
|
|
|
| // Check state.
|
| @@ -1478,6 +1487,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_IncognitoRegular) {
|
| // later.
|
| base::FilePath origin(OriginFile(base::FilePath(FILE_PATH_LITERAL(
|
| "downloads/a_zip_file.zip"))));
|
| + base::ThreadRestrictions::ScopedAllowIO allow_io;
|
| ASSERT_TRUE(base::PathExists(origin));
|
| int64_t origin_file_size = 0;
|
| EXPECT_TRUE(base::GetFileSize(origin, &origin_file_size));
|
| @@ -1982,6 +1992,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) {
|
| // Confirm the downloaded data exists.
|
| base::FilePath downloaded_file = GetDownloadDirectory(browser());
|
| downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png"));
|
| + base::ThreadRestrictions::ScopedAllowIO allow_io;
|
| EXPECT_TRUE(base::PathExists(downloaded_file));
|
| }
|
|
|
| @@ -2204,6 +2215,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) {
|
| browser()->tab_strip_model()->GetActiveWebContents();
|
| ASSERT_TRUE(web_contents);
|
|
|
| + base::ThreadRestrictions::ScopedAllowIO allow_io;
|
| base::FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
|
| base::ScopedTempDir other_directory;
|
| ASSERT_TRUE(other_directory.CreateUniqueTempDir());
|
| @@ -2240,6 +2252,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, TransientDownload) {
|
| browser()->tab_strip_model()->GetActiveWebContents();
|
| ASSERT_TRUE(web_contents);
|
|
|
| + base::ThreadRestrictions::ScopedAllowIO allow_io;
|
| base::FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
|
| base::ScopedTempDir other_directory;
|
| ASSERT_TRUE(other_directory.CreateUniqueTempDir());
|
| @@ -2931,6 +2944,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_Renaming) {
|
| content::DownloadManager* manager = DownloadManagerForBrowser(browser());
|
| base::FilePath origin_file(OriginFile(base::FilePath(FILE_PATH_LITERAL(
|
| "downloads/a_zip_file.zip"))));
|
| + base::ThreadRestrictions::ScopedAllowIO allow_io;
|
| ASSERT_TRUE(base::PathExists(origin_file));
|
| std::string origin_contents;
|
| ASSERT_TRUE(base::ReadFileToString(origin_file, &origin_contents));
|
| @@ -2948,6 +2962,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_Renaming) {
|
| (index == 0 ? std::string(".zip") :
|
| base::StringPrintf(" (%d).zip", index)),
|
| target_path.BaseName().AsUTF8Unsafe());
|
| + base::ThreadRestrictions::ScopedAllowIO allow_io;
|
| ASSERT_TRUE(base::PathExists(target_path));
|
| ASSERT_TRUE(VerifyFile(target_path, origin_contents,
|
| origin_contents.size()));
|
| @@ -2987,6 +3002,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, MAYBE_DownloadTest_CrazyFilenames) {
|
| };
|
|
|
| std::vector<DownloadItem*> download_items;
|
| + base::ThreadRestrictions::ScopedAllowIO allow_io;
|
| base::FilePath origin_directory =
|
| GetDownloadDirectory(browser()).Append(FILE_PATH_LITERAL("origin"));
|
| ASSERT_TRUE(base::CreateDirectory(origin_directory));
|
| @@ -3084,23 +3100,27 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, MAYBE_DownloadTest_PercentComplete) {
|
| base::FilePath file_path(
|
| GetDownloadDirectory(browser()).AppendASCII("source").AppendASCII(
|
| "DownloadTest_BigZip.zip"));
|
| - ASSERT_TRUE(CreateDirectory(file_path.DirName()));
|
| - base::File file(file_path, base::File::FLAG_CREATE | base::File::FLAG_WRITE);
|
| - ASSERT_TRUE(file.IsValid());
|
| int64_t size = 1 << 25;
|
| - EXPECT_EQ(1, file.Write(size, "a", 1));
|
| - file.Close();
|
| + {
|
| + base::ThreadRestrictions::ScopedAllowIO allow_io;
|
| + ASSERT_TRUE(CreateDirectory(file_path.DirName()));
|
| + base::File file(file_path,
|
| + base::File::FLAG_CREATE | base::File::FLAG_WRITE);
|
| + ASSERT_TRUE(file.IsValid());
|
| + EXPECT_EQ(1, file.Write(size, "a", 1));
|
| + file.Close();
|
|
|
| #if defined(OS_POSIX)
|
| - // Make it readable by chronos on chromeos
|
| - base::SetPosixFilePermissions(file_path, 0755);
|
| + // Make it readable by chronos on chromeos
|
| + base::SetPosixFilePermissions(file_path, 0755);
|
| #endif
|
|
|
| - // Ensure that we have enough disk space.
|
| - int64_t free_space =
|
| - base::SysInfo::AmountOfFreeDiskSpace(GetDownloadDirectory(browser()));
|
| - ASSERT_LE(size, free_space) << "Not enough disk space to download. Got "
|
| - << free_space;
|
| + // Ensure that we have enough disk space.
|
| + int64_t free_space =
|
| + base::SysInfo::AmountOfFreeDiskSpace(GetDownloadDirectory(browser()));
|
| + ASSERT_LE(size, free_space)
|
| + << "Not enough disk space to download. Got " << free_space;
|
| + }
|
| GURL file_url(net::FilePathToFileURL(file_path));
|
| std::unique_ptr<content::DownloadTestObserver> progress_waiter(
|
| CreateInProgressWaiter(browser(), 1));
|
| @@ -3124,6 +3144,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, MAYBE_DownloadTest_PercentComplete) {
|
| ASSERT_EQ(100, download_items[0]->PercentComplete());
|
|
|
| // Check that the file downloaded correctly.
|
| + base::ThreadRestrictions::ScopedAllowIO allow_io;
|
| ASSERT_TRUE(base::PathExists(download_items[0]->GetTargetFilePath()));
|
| int64_t downloaded_size = 0;
|
| ASSERT_TRUE(base::GetFileSize(
|
| @@ -3534,6 +3555,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, FeedbackServiceKeepDownload) {
|
| GetDownloads(browser(), &updated_downloads);
|
| ASSERT_EQ(std::size_t(1), updated_downloads.size());
|
| ASSERT_FALSE(updated_downloads[0]->IsDangerous());
|
| + base::ThreadRestrictions::ScopedAllowIO allow_io;
|
| ASSERT_TRUE(PathExists(updated_downloads[0]->GetTargetFilePath()));
|
| updated_downloads[0]->Cancel(true);
|
| }
|
|
|