Commit 191ab5f2 authored by Greg Thompson's avatar Greg Thompson Committed by Commit Bot

Fix temp dir cleanup in components_unittests.

The ScopedTempDir must outlive anything that holds file(s) open within
it; otherwise, it is unable to delete itself.

BUG=546640

Change-Id: I09d5fe93f6ed0620087b9360a6922ff919221e0b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1891191Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Reviewed-by: default avatarJosh Karlin <jkarlin@chromium.org>
Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Reviewed-by: default avatarJared Saul <jsaul@google.com>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Commit-Queue: Greg Thompson <grt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711236}
parent 6d00e32f
......@@ -60,7 +60,7 @@ class StrikeDatabaseTest : public ::testing::Test {
StrikeDatabaseTest() {}
void SetUp() override {
EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
db_provider_ = std::make_unique<leveldb_proto::ProtoDatabaseProvider>(
temp_dir_.GetPath());
......@@ -129,10 +129,10 @@ class StrikeDatabaseTest : public ::testing::Test {
protected:
base::HistogramTester* GetHistogramTester() { return &histogram_tester_; }
base::ScopedTempDir temp_dir_;
base::test::TaskEnvironment task_environment_;
std::unique_ptr<leveldb_proto::ProtoDatabaseProvider> db_provider_;
std::unique_ptr<TestStrikeDatabase> strike_database_;
base::ScopedTempDir temp_dir_;
private:
base::HistogramTester histogram_tester_;
......
......@@ -164,11 +164,6 @@ class ProtoDatabaseImplTest : public testing::Test {
kDefaultClientName, shared_db_temp_dir_->GetPath()));
}
void TearDown() override {
temp_dir_.reset();
shared_db_temp_dir_.reset();
}
void SetUpExperimentParams(std::map<std::string, std::string> params) {
scoped_feature_list_.InitAndEnableFeatureWithParameters(
kProtoDBSharedMigration, params);
......@@ -394,6 +389,7 @@ class ProtoDatabaseImplTest : public testing::Test {
private:
std::unique_ptr<base::ScopedTempDir> temp_dir_;
std::unique_ptr<base::ScopedTempDir> shared_db_temp_dir_;
base::test::TaskEnvironment task_environment_;
base::test::ScopedFeatureList scoped_feature_list_;
......@@ -401,7 +397,6 @@ class ProtoDatabaseImplTest : public testing::Test {
std::unique_ptr<base::Thread> test_thread_;
std::unique_ptr<base::Thread> shared_db_thread_;
scoped_refptr<SharedProtoDatabase> shared_db_;
std::unique_ptr<base::ScopedTempDir> shared_db_temp_dir_;
};
using ProtoDatabaseImplTestConfig = testing::Types<TestProto, ClientStruct>;
......
......@@ -23,20 +23,14 @@ namespace leveldb_proto {
class SharedProtoDatabaseClientTest : public testing::Test {
public:
void SetUp() override {
temp_dir_.reset(new base::ScopedTempDir());
ASSERT_TRUE(temp_dir_->CreateUniqueTempDir());
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
db_ = base::WrapRefCounted(
new SharedProtoDatabase("client", temp_dir_->GetPath()));
}
void TearDown() override {
db_->database_task_runner_for_testing()->DeleteSoon(FROM_HERE,
std::move(temp_dir_));
new SharedProtoDatabase("client", temp_dir_.GetPath()));
}
protected:
scoped_refptr<SharedProtoDatabase> db() { return db_; }
base::ScopedTempDir* temp_dir() { return temp_dir_.get(); }
base::ScopedTempDir* temp_dir() { return &temp_dir_; }
LevelDB* GetLevelDB() const { return db_->GetLevelDBForTesting(); }
......@@ -288,10 +282,9 @@ class SharedProtoDatabaseClientTest : public testing::Test {
}
private:
base::ScopedTempDir temp_dir_;
base::test::TaskEnvironment task_environment_;
scoped_refptr<SharedProtoDatabase> db_;
std::unique_ptr<base::ScopedTempDir> temp_dir_;
};
TEST_F(SharedProtoDatabaseClientTest, InitSuccess) {
......
......@@ -169,8 +169,9 @@ class InMemoryURLIndexTest : public testing::Test {
void ExpectPrivateDataEqual(const URLIndexPrivateData& expected,
const URLIndexPrivateData& actual);
base::test::TaskEnvironment task_environment_;
base::ScopedTempDir history_dir_;
base::ScopedTempDir temp_dir_;
base::test::TaskEnvironment task_environment_;
std::unique_ptr<history::HistoryService> history_service_;
history::HistoryDatabase* history_database_ = nullptr;
std::unique_ptr<TemplateURLService> template_url_service_;
......@@ -229,9 +230,9 @@ bool InMemoryURLIndexTest::DeleteURL(const GURL& url) {
void InMemoryURLIndexTest::SetUp() {
// We cannot access the database until the backend has been loaded.
if (history_dir_.CreateUniqueTempDir())
history_service_ =
history::CreateHistoryService(history_dir_.GetPath(), true);
ASSERT_TRUE(history_dir_.CreateUniqueTempDir());
history_service_ =
history::CreateHistoryService(history_dir_.GetPath(), true);
ASSERT_TRUE(history_service_);
BlockUntilInMemoryURLIndexIsRefreshed(url_index_.get());
......@@ -1228,9 +1229,8 @@ TEST_F(InMemoryURLIndexTest, DISABLED_CacheSaveRestore) {
}
TEST_F(InMemoryURLIndexTest, RebuildFromHistoryIfCacheOld) {
base::ScopedTempDir temp_directory;
ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
set_history_dir(temp_directory.GetPath());
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
set_history_dir(temp_dir_.GetPath());
URLIndexPrivateData& private_data(*GetPrivateData());
......@@ -1302,6 +1302,8 @@ TEST_F(InMemoryURLIndexTest, RebuildFromHistoryIfCacheOld) {
// Compare the captured and restored for equality.
ExpectPrivateDataEqual(*old_data, new_data);
set_history_dir(base::FilePath());
}
TEST_F(InMemoryURLIndexTest, CalculateWordStartsOffsets) {
......@@ -1433,8 +1435,8 @@ class InMemoryURLIndexCacheTest : public testing::Test {
void set_history_dir(const base::FilePath& dir_path);
bool GetCacheFilePath(base::FilePath* file_path) const;
base::test::TaskEnvironment task_environment_;
base::ScopedTempDir temp_dir_;
base::test::TaskEnvironment task_environment_;
std::unique_ptr<InMemoryURLIndex> url_index_;
};
......
......@@ -183,11 +183,11 @@ class JsonPrefStoreTest
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
}
base::test::TaskEnvironment task_environment_;
// The path to temporary directory used to contain the test operations.
base::ScopedTempDir temp_dir_;
base::test::TaskEnvironment task_environment_;
DISALLOW_COPY_AND_ASSIGN(JsonPrefStoreTest);
};
......
......@@ -85,6 +85,8 @@ class SubresourceFilterRulesetPublisherImplTest : public ::testing::Test {
content::TestBrowserContext* browser_context() { return &browser_context_; }
base::FilePath temp_dir() const { return scoped_temp_dir_.GetPath(); }
base::FilePath scoped_temp_file() const {
return scoped_temp_dir_.GetPath().AppendASCII("data");
}
......@@ -155,11 +157,8 @@ TEST_F(SubresourceFilterRulesetPublisherImplTest,
// Regression test for crbug.com/817308. Test verifies that ruleset is
// published on browser startup via exactly one PostTask.
// Create a temporary directory for the indexed ruleset data.
base::ScopedTempDir scoped_temp_dir;
ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir());
const base::FilePath base_dir =
scoped_temp_dir.GetPath().AppendASCII("Rules").AppendASCII("Indexed");
temp_dir().AppendASCII("Rules").AppendASCII("Indexed");
// Create a testing ruleset.
testing::TestRulesetPair ruleset;
......
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