Commit e899dc99 authored by Robbie McElrath's avatar Robbie McElrath Committed by Commit Bot

Fix timeout in ChromeDownloadManagerDelegateTest.LastSavePath.

See https://crbug.com/879348 for a description of the issue. This CL
adds a DownloadPrefs::ReinitializeDefaultDownloadDirectoryForTesting()
method to force the global DefaultDownloadDirectory instance to
reinitialize itself to take into account any test configurations.

Bug: 879348
Change-Id: I4a2340fad5f1396196e6746073857d3a09bfa7c1
Reviewed-on: https://chromium-review.googlesource.com/1197724Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Commit-Queue: Robbie McElrath <rmcelrath@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589291}
parent 5240a440
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include <string> #include <string>
#include "base/at_exit.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
...@@ -257,8 +256,6 @@ class ChromeDownloadManagerDelegateTest ...@@ -257,8 +256,6 @@ class ChromeDownloadManagerDelegateTest
void GetNextId(uint32_t next_id) { download_ids_.emplace_back(next_id); } void GetNextId(uint32_t next_id) { download_ids_.emplace_back(next_id); }
private: private:
// Resets the global cached DefaultDownloadDirectory instance.
base::ShadowingAtExitManager at_exit_manager_;
base::ScopedPathOverride download_dir_override_{ base::ScopedPathOverride download_dir_override_{
chrome::DIR_DEFAULT_DOWNLOADS}; chrome::DIR_DEFAULT_DOWNLOADS};
sync_preferences::TestingPrefServiceSyncable* pref_service_; sync_preferences::TestingPrefServiceSyncable* pref_service_;
...@@ -273,6 +270,7 @@ ChromeDownloadManagerDelegateTest::ChromeDownloadManagerDelegateTest() ...@@ -273,6 +270,7 @@ ChromeDownloadManagerDelegateTest::ChromeDownloadManagerDelegateTest()
} }
void ChromeDownloadManagerDelegateTest::SetUp() { void ChromeDownloadManagerDelegateTest::SetUp() {
DownloadPrefs::ReinitializeDefaultDownloadDirectoryForTesting();
ChromeRenderViewHostTestHarness::SetUp(); ChromeRenderViewHostTestHarness::SetUp();
CHECK(profile()); CHECK(profile());
......
...@@ -13,9 +13,9 @@ ...@@ -13,9 +13,9 @@
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/lazy_instance.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/no_destructor.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/strings/string_split.h" #include "base/strings/string_split.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
...@@ -86,10 +86,7 @@ class DefaultDownloadDirectory { ...@@ -86,10 +86,7 @@ class DefaultDownloadDirectory {
public: public:
const base::FilePath& path() const { return path_; } const base::FilePath& path() const { return path_; }
private: void Initialize() {
friend struct base::LazyInstanceTraitsBase<DefaultDownloadDirectory>;
DefaultDownloadDirectory() {
if (!base::PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &path_)) { if (!base::PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &path_)) {
NOTREACHED(); NOTREACHED();
} }
...@@ -102,13 +99,20 @@ class DefaultDownloadDirectory { ...@@ -102,13 +99,20 @@ class DefaultDownloadDirectory {
} }
} }
private:
friend class base::NoDestructor<DefaultDownloadDirectory>;
DefaultDownloadDirectory() { Initialize(); }
base::FilePath path_; base::FilePath path_;
DISALLOW_COPY_AND_ASSIGN(DefaultDownloadDirectory); DISALLOW_COPY_AND_ASSIGN(DefaultDownloadDirectory);
}; };
base::LazyInstance<DefaultDownloadDirectory>::DestructorAtExit DefaultDownloadDirectory& GetDefaultDownloadDirectorySingleton() {
g_default_download_directory = LAZY_INSTANCE_INITIALIZER; static base::NoDestructor<DefaultDownloadDirectory> instance;
return *instance;
}
} // namespace } // namespace
...@@ -262,9 +266,14 @@ base::FilePath DownloadPrefs::GetDefaultDownloadDirectoryForProfile() const { ...@@ -262,9 +266,14 @@ base::FilePath DownloadPrefs::GetDefaultDownloadDirectoryForProfile() const {
#endif #endif
} }
// static
void DownloadPrefs::ReinitializeDefaultDownloadDirectoryForTesting() {
GetDefaultDownloadDirectorySingleton().Initialize();
}
// static // static
const base::FilePath& DownloadPrefs::GetDefaultDownloadDirectory() { const base::FilePath& DownloadPrefs::GetDefaultDownloadDirectory() {
return g_default_download_directory.Get().path(); return GetDefaultDownloadDirectorySingleton().path();
} }
// static // static
......
...@@ -43,6 +43,8 @@ class DownloadPrefs { ...@@ -43,6 +43,8 @@ class DownloadPrefs {
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
static void ReinitializeDefaultDownloadDirectoryForTesting();
// Returns the default download directory. // Returns the default download directory.
static const base::FilePath& GetDefaultDownloadDirectory(); static const base::FilePath& GetDefaultDownloadDirectory();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment