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 @@
#include <string>
#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
......@@ -257,8 +256,6 @@ class ChromeDownloadManagerDelegateTest
void GetNextId(uint32_t next_id) { download_ids_.emplace_back(next_id); }
private:
// Resets the global cached DefaultDownloadDirectory instance.
base::ShadowingAtExitManager at_exit_manager_;
base::ScopedPathOverride download_dir_override_{
chrome::DIR_DEFAULT_DOWNLOADS};
sync_preferences::TestingPrefServiceSyncable* pref_service_;
......@@ -273,6 +270,7 @@ ChromeDownloadManagerDelegateTest::ChromeDownloadManagerDelegateTest()
}
void ChromeDownloadManagerDelegateTest::SetUp() {
DownloadPrefs::ReinitializeDefaultDownloadDirectoryForTesting();
ChromeRenderViewHostTestHarness::SetUp();
CHECK(profile());
......
......@@ -13,9 +13,9 @@
#include "base/bind_helpers.h"
#include "base/feature_list.h"
#include "base/files/file_util.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/no_destructor.h"
#include "base/path_service.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
......@@ -86,10 +86,7 @@ class DefaultDownloadDirectory {
public:
const base::FilePath& path() const { return path_; }
private:
friend struct base::LazyInstanceTraitsBase<DefaultDownloadDirectory>;
DefaultDownloadDirectory() {
void Initialize() {
if (!base::PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &path_)) {
NOTREACHED();
}
......@@ -102,13 +99,20 @@ class DefaultDownloadDirectory {
}
}
private:
friend class base::NoDestructor<DefaultDownloadDirectory>;
DefaultDownloadDirectory() { Initialize(); }
base::FilePath path_;
DISALLOW_COPY_AND_ASSIGN(DefaultDownloadDirectory);
};
base::LazyInstance<DefaultDownloadDirectory>::DestructorAtExit
g_default_download_directory = LAZY_INSTANCE_INITIALIZER;
DefaultDownloadDirectory& GetDefaultDownloadDirectorySingleton() {
static base::NoDestructor<DefaultDownloadDirectory> instance;
return *instance;
}
} // namespace
......@@ -262,9 +266,14 @@ base::FilePath DownloadPrefs::GetDefaultDownloadDirectoryForProfile() const {
#endif
}
// static
void DownloadPrefs::ReinitializeDefaultDownloadDirectoryForTesting() {
GetDefaultDownloadDirectorySingleton().Initialize();
}
// static
const base::FilePath& DownloadPrefs::GetDefaultDownloadDirectory() {
return g_default_download_directory.Get().path();
return GetDefaultDownloadDirectorySingleton().path();
}
// static
......
......@@ -43,6 +43,8 @@ class DownloadPrefs {
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
static void ReinitializeDefaultDownloadDirectoryForTesting();
// Returns the default download directory.
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