diff options
author | yoshiki iguchi <yoshiki@chromium.org> | 2016-01-05 20:07:52 +0900 |
---|---|---|
committer | yoshiki iguchi <yoshiki@chromium.org> | 2016-01-05 11:09:25 +0000 |
commit | e56d5f319b46db04fd48f60429e1406301f770ce (patch) | |
tree | 7aa3aa2c96276caa84d9f691e7eb265668d988a8 | |
parent | 017eb2857a73fd46c8ffc30edb50067db3ee037f (diff) | |
download | chromium_src-e56d5f319b46db04fd48f60429e1406301f770ce.zip chromium_src-e56d5f319b46db04fd48f60429e1406301f770ce.tar.gz chromium_src-e56d5f319b46db04fd48f60429e1406301f770ce.tar.bz2 |
[DownloadNotification Test] Use temporary download directory
This patch has the tests use a temporary download directory so that the download directory won't be full with downloaded files and the flakiness on trybots should be fixed.
And this patch also re-enable the tests except SimultaneousIncognitoAndNormalDownloads, which was flakiness due to downloaded files in the download directory.
This fix had been committed once (crrev.com/f01a43dd6f) but reverted (crrev.com/c96cd8bc15) due to SimultaneousIncognitoAndNormalDownloads failure. But this failure is caused by an other reason. I'll fix it and re-enable separately.
BUG=560329
TEST=browser_tests pass both on trybots and locally
TBR=asanka@chromium.org, tapted@chromium.org
Review URL: https://codereview.chromium.org/1490233006
BUG=570518 # for merging to M48 branch
Cr-Commit-Position: refs/heads/master@{#362906}
(cherry picked from commit 6adbf2e61e7a6a3dae0c72d5dcf946a6535c13df)
Review URL: https://codereview.chromium.org/1553383002 .
Cr-Commit-Position: refs/branch-heads/2564@{#471}
Cr-Branched-From: 1283eca15bd9f772387f75241576cde7bdec7f54-refs/heads/master@{#359700}
-rw-r--r-- | chrome/browser/download/notification/download_notification_browsertest.cc | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/chrome/browser/download/notification/download_notification_browsertest.cc b/chrome/browser/download/notification/download_notification_browsertest.cc index 7c260ef..ab3b5ad 100644 --- a/chrome/browser/download/notification/download_notification_browsertest.cc +++ b/chrome/browser/download/notification/download_notification_browsertest.cc @@ -5,6 +5,7 @@ #include "base/command_line.h" #include "base/message_loop/message_loop.h" #include "base/path_service.h" +#include "base/prefs/pref_service.h" #include "base/run_loop.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/chromeos/profiles/profile_helper.h" @@ -18,6 +19,7 @@ #include "chrome/browser/ui/browser_commands.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/pref_names.h" #include "chrome/grit/chromium_strings.h" #include "chrome/grit/generated_resources.h" #include "chrome/test/base/in_process_browser_test.h" @@ -284,11 +286,43 @@ class DownloadNotificationTestBase : public InProcessBrowserTest { base::Bind(&net::URLRequestSlowDownloadJob::AddUrlHandler)); GetMessageCenter()->DisableTimersForTest(); + + // Set up the temporary download folder. + ASSERT_TRUE(CreateAndSetDownloadsDirectory(browser())); + } + + protected: + // Must be called after browser creation. Creates a temporary + // directory for downloads that is auto-deleted on destruction. + // Returning false indicates a failure of the function, and should be asserted + // in the caller. + bool CreateAndSetDownloadsDirectory(Browser* browser) { + if (!browser) + return false; + + if (!downloads_directory_.path().empty()) + return true; // already created + + if (!downloads_directory_.CreateUniqueTempDir()) + return false; + + browser->profile()->GetPrefs()->SetFilePath( + prefs::kDownloadDefaultDirectory, + downloads_directory_.path()); + browser->profile()->GetPrefs()->SetFilePath( + prefs::kSaveFileDefaultDirectory, + downloads_directory_.path()); + + return true; } content::DownloadManager* GetDownloadManager(Browser* browser) { return content::BrowserContext::GetDownloadManager(browser->profile()); } + + private: + // Location of the downloads directory for these tests + base::ScopedTempDir downloads_directory_; }; ////////////////////////////////////////////////// @@ -322,6 +356,8 @@ class DownloadNotificationTest : public DownloadNotificationTestBase { incognito_browser_ = CreateIncognitoBrowser(); Profile* incognito_profile = incognito_browser_->profile(); + ASSERT_TRUE(CreateAndSetDownloadsDirectory(incognito_browser_)); + scoped_ptr<TestChromeDownloadManagerDelegate> incognito_test_delegate; incognito_test_delegate.reset( new TestChromeDownloadManagerDelegate(incognito_profile)); |