Commit b97feb36 authored by Victor Costan's avatar Victor Costan Committed by Commit Bot

Bookmarks: Switch test to use temporary directory.

BookmarkExpandedStateTrackerTest passes an empty path into
BookmarkModel::Load(), which causes the loader to look for a "Bookmarks"
file in the current directory. Asides from the attached issue, this
means the test behavior may change if the current directory does happen
to have a "Bookmarks" file.

This CL adds a base::ScopedTempDir to the test, making it not depend on
the current directory.

Bug: 1116809
Change-Id: I18db1ffdbdb2ae29aa17fef8920dde1ba8638f6a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2359389
Auto-Submit: Victor Costan <pwnall@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798692}
parent 07bc7b3c
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <memory> #include <memory>
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
...@@ -31,6 +32,7 @@ class BookmarkExpandedStateTrackerTest : public testing::Test { ...@@ -31,6 +32,7 @@ class BookmarkExpandedStateTrackerTest : public testing::Test {
void SetUp() override; void SetUp() override;
void TearDown() override; void TearDown() override;
base::ScopedTempDir scoped_temp_dir_;
base::test::TaskEnvironment task_environment_; base::test::TaskEnvironment task_environment_;
TestingPrefServiceSimple prefs_; TestingPrefServiceSimple prefs_;
std::unique_ptr<BookmarkModel> model_; std::unique_ptr<BookmarkModel> model_;
...@@ -38,15 +40,17 @@ class BookmarkExpandedStateTrackerTest : public testing::Test { ...@@ -38,15 +40,17 @@ class BookmarkExpandedStateTrackerTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(BookmarkExpandedStateTrackerTest); DISALLOW_COPY_AND_ASSIGN(BookmarkExpandedStateTrackerTest);
}; };
BookmarkExpandedStateTrackerTest::BookmarkExpandedStateTrackerTest() {} BookmarkExpandedStateTrackerTest::BookmarkExpandedStateTrackerTest() = default;
BookmarkExpandedStateTrackerTest::~BookmarkExpandedStateTrackerTest() {} BookmarkExpandedStateTrackerTest::~BookmarkExpandedStateTrackerTest() = default;
void BookmarkExpandedStateTrackerTest::SetUp() { void BookmarkExpandedStateTrackerTest::SetUp() {
ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir());
prefs_.registry()->RegisterListPref(prefs::kBookmarkEditorExpandedNodes); prefs_.registry()->RegisterListPref(prefs::kBookmarkEditorExpandedNodes);
prefs_.registry()->RegisterListPref(prefs::kManagedBookmarks); prefs_.registry()->RegisterListPref(prefs::kManagedBookmarks);
model_.reset(new BookmarkModel(std::make_unique<TestBookmarkClient>())); model_ =
model_->Load(&prefs_, base::FilePath()); std::make_unique<BookmarkModel>(std::make_unique<TestBookmarkClient>());
model_->Load(&prefs_, scoped_temp_dir_.GetPath());
test::WaitForBookmarkModelToLoad(model_.get()); test::WaitForBookmarkModelToLoad(model_.get());
} }
......
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