Commit 96350f90 authored by Sorin Jianu's avatar Sorin Jianu Committed by Commit Bot

Changed from unique_ptr<base::RunLoop> to RunLoop.

This should be a mechanical change in a unit test. I refactored
some odd looking code due to unique_ptr<base::RunLoop>.

This CL gets rid of unique_ptr and confusing ownership semantics.

Change-Id: I90386d09ffed6de242acb47d35ba2156a43c0da9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2104451Reviewed-by: default avatarJoshua Pawlicki <waffles@chromium.org>
Commit-Queue: Sorin Jianu <sorin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#750550}
parent 4b266fb5
...@@ -179,7 +179,7 @@ TEST_F(LocalExtensionCacheTest, KeepHashed) { ...@@ -179,7 +179,7 @@ TEST_F(LocalExtensionCacheTest, KeepHashed) {
bool initialized = false; bool initialized = false;
cache.Init(true, base::Bind(&SimpleCallback, &initialized)); cache.Init(true, base::Bind(&SimpleCallback, &initialized));
// Add three identical extensions with different hash sums // Add three identical extensions with different hash sums.
const base::Time time = base::Time::Now() - base::TimeDelta::FromDays(1); const base::Time time = base::Time::Now() - base::TimeDelta::FromDays(1);
base::FilePath file, file1, file2; base::FilePath file, file1, file2;
CreateExtensionFile(cache_dir, kTestExtensionId1, "1.0", 100, time, &file); CreateExtensionFile(cache_dir, kTestExtensionId1, "1.0", 100, time, &file);
...@@ -216,7 +216,7 @@ TEST_F(LocalExtensionCacheTest, KeepLatest) { ...@@ -216,7 +216,7 @@ TEST_F(LocalExtensionCacheTest, KeepLatest) {
bool initialized = false; bool initialized = false;
cache.Init(true, base::Bind(&SimpleCallback, &initialized)); cache.Init(true, base::Bind(&SimpleCallback, &initialized));
// All extension files are hashed, but have different versions // All extension files are hashed, but have different versions.
const base::Time time = base::Time::Now() - base::TimeDelta::FromDays(1); const base::Time time = base::Time::Now() - base::TimeDelta::FromDays(1);
base::FilePath file1, file21, file22; base::FilePath file1, file21, file22;
const std::string hash1 = CreateSignedExtensionFile( const std::string hash1 = CreateSignedExtensionFile(
...@@ -229,13 +229,13 @@ TEST_F(LocalExtensionCacheTest, KeepLatest) { ...@@ -229,13 +229,13 @@ TEST_F(LocalExtensionCacheTest, KeepLatest) {
content::RunAllTasksUntilIdle(); content::RunAllTasksUntilIdle();
ASSERT_TRUE(initialized); ASSERT_TRUE(initialized);
// Older version should be removed // Older version should be removed.
EXPECT_FALSE(base::PathExists(file1)); EXPECT_FALSE(base::PathExists(file1));
// Both newer hashed versions should stay // Both newer hashed versions should stay.
EXPECT_TRUE(base::PathExists(file21)); EXPECT_TRUE(base::PathExists(file21));
EXPECT_TRUE(base::PathExists(file22)); EXPECT_TRUE(base::PathExists(file22));
// We should be able to lookup only the latest version queries // We should be able to lookup only the latest version queries.
EXPECT_FALSE(cache.GetExtension(kTestExtensionId1, hash1, NULL, NULL)); EXPECT_FALSE(cache.GetExtension(kTestExtensionId1, hash1, NULL, NULL));
EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash21, NULL, NULL)); EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash21, NULL, NULL));
EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash22, NULL, NULL)); EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash22, NULL, NULL));
...@@ -252,7 +252,7 @@ TEST_F(LocalExtensionCacheTest, Complex) { ...@@ -252,7 +252,7 @@ TEST_F(LocalExtensionCacheTest, Complex) {
bool initialized = false; bool initialized = false;
cache.Init(true, base::Bind(&SimpleCallback, &initialized)); cache.Init(true, base::Bind(&SimpleCallback, &initialized));
// Like in KeepHashed test, but with two different versions // Like in KeepHashed test, but with two different versions.
const base::Time time = base::Time::Now() - base::TimeDelta::FromDays(1); const base::Time time = base::Time::Now() - base::TimeDelta::FromDays(1);
base::FilePath file1, file11, file12, file2, file21, file22; base::FilePath file1, file11, file12, file2, file21, file22;
CreateExtensionFile(cache_dir, kTestExtensionId1, "1.0", 100, time, &file1); CreateExtensionFile(cache_dir, kTestExtensionId1, "1.0", 100, time, &file1);
...@@ -269,17 +269,17 @@ TEST_F(LocalExtensionCacheTest, Complex) { ...@@ -269,17 +269,17 @@ TEST_F(LocalExtensionCacheTest, Complex) {
content::RunAllTasksUntilIdle(); content::RunAllTasksUntilIdle();
ASSERT_TRUE(initialized); ASSERT_TRUE(initialized);
// Older and unhashed versions should be removed // Older and unhashed versions should be removed.
EXPECT_FALSE(base::PathExists(file1)); EXPECT_FALSE(base::PathExists(file1));
EXPECT_FALSE(base::PathExists(file11)); EXPECT_FALSE(base::PathExists(file11));
EXPECT_FALSE(base::PathExists(file12)); EXPECT_FALSE(base::PathExists(file12));
EXPECT_FALSE(base::PathExists(file2)); EXPECT_FALSE(base::PathExists(file2));
// Newest hashed versions should stay // Newest hashed versions should stay.
EXPECT_TRUE(base::PathExists(file21)); EXPECT_TRUE(base::PathExists(file21));
EXPECT_TRUE(base::PathExists(file22)); EXPECT_TRUE(base::PathExists(file22));
// We should be able to lookup only the latest version queries, both with and // We should be able to lookup only the latest version queries, both with and
// without hash // without hash.
std::string version; std::string version;
EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, "", NULL, &version)); EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, "", NULL, &version));
EXPECT_EQ(version, "2.0"); EXPECT_EQ(version, "2.0");
...@@ -289,23 +289,18 @@ TEST_F(LocalExtensionCacheTest, Complex) { ...@@ -289,23 +289,18 @@ TEST_F(LocalExtensionCacheTest, Complex) {
EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash22, NULL, NULL)); EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash22, NULL, NULL));
} }
static void OnPutExtension(std::unique_ptr<base::RunLoop>* run_loop, static void PutExtensionAndWait(LocalExtensionCache* cache,
const base::FilePath& file_path,
bool file_ownership_passed) {
ASSERT_TRUE(*run_loop);
(*run_loop)->Quit();
}
static void PutExtensionAndWait(LocalExtensionCache& cache,
const std::string& id, const std::string& id,
const std::string& expected_hash, const std::string& expected_hash,
const base::FilePath& path, const base::FilePath& path,
const std::string& version) { const std::string& version) {
std::unique_ptr<base::RunLoop> run_loop; base::RunLoop run_loop;
run_loop.reset(new base::RunLoop); cache->PutExtension(
cache.PutExtension(id, expected_hash, path, version, id, expected_hash, path, version,
base::Bind(&OnPutExtension, &run_loop)); base::BindRepeating([](base::RunLoop* run_loop, const base::FilePath&,
run_loop->Run(); bool) { run_loop->Quit(); },
&run_loop));
run_loop.Run();
} }
TEST_F(LocalExtensionCacheTest, PutExtensionCases) { TEST_F(LocalExtensionCacheTest, PutExtensionCases) {
...@@ -339,53 +334,53 @@ TEST_F(LocalExtensionCacheTest, PutExtensionCases) { ...@@ -339,53 +334,53 @@ TEST_F(LocalExtensionCacheTest, PutExtensionCases) {
const base::FilePath temp_path = temp_dir.GetPath(); const base::FilePath temp_path = temp_dir.GetPath();
std::string version; std::string version;
// Right now we have two files for the first extension // Right now we have two files for the first extension.
EXPECT_TRUE(base::PathExists(file11)); EXPECT_TRUE(base::PathExists(file11));
EXPECT_TRUE(base::PathExists(file12)); EXPECT_TRUE(base::PathExists(file12));
EXPECT_TRUE(base::PathExists(file2)); EXPECT_TRUE(base::PathExists(file2));
EXPECT_TRUE(base::PathExists(file3)); EXPECT_TRUE(base::PathExists(file3));
// 1. Cache contains an older version // 1. Cache contains an older version.
base::FilePath temp1; base::FilePath temp1;
CreateExtensionFile(temp_path, kTestExtensionId1, "3.0", 110, time, &temp1); CreateExtensionFile(temp_path, kTestExtensionId1, "3.0", 110, time, &temp1);
PutExtensionAndWait(cache, kTestExtensionId1, "", temp1, "3.0"); PutExtensionAndWait(&cache, kTestExtensionId1, "", temp1, "3.0");
// New file added // New file added.
const base::FilePath unhashed = const base::FilePath unhashed =
GetExtensionFileName(cache_dir, kTestExtensionId1, "3.0", ""); GetExtensionFileName(cache_dir, kTestExtensionId1, "3.0", "");
EXPECT_TRUE(base::PathExists(unhashed)); EXPECT_TRUE(base::PathExists(unhashed));
// Old files removed from cache (kept in the directory though) // Old files removed from cache (kept in the directory though).
EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash11, NULL, &version)); EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash11, NULL, &version));
EXPECT_EQ(version, "3.0"); EXPECT_EQ(version, "3.0");
EXPECT_TRUE(base::DeleteFile(temp1, false)); EXPECT_TRUE(base::DeleteFile(temp1, false));
// 2. Cache contains a newer version // 2. Cache contains a newer version.
base::FilePath temp2; base::FilePath temp2;
CreateExtensionFile(temp_path, kTestExtensionId1, "2.0", 120, time, &temp2); CreateExtensionFile(temp_path, kTestExtensionId1, "2.0", 120, time, &temp2);
PutExtensionAndWait(cache, kTestExtensionId1, "", temp2, "2.0"); PutExtensionAndWait(&cache, kTestExtensionId1, "", temp2, "2.0");
// New file skipped // New file skipped.
EXPECT_FALSE(base::PathExists( EXPECT_FALSE(base::PathExists(
GetExtensionFileName(cache_dir, kTestExtensionId1, "2.0", ""))); GetExtensionFileName(cache_dir, kTestExtensionId1, "2.0", "")));
// Old file kept // Old file kept.
EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, "", NULL, &version)); EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, "", NULL, &version));
EXPECT_EQ(version, "3.0"); EXPECT_EQ(version, "3.0");
EXPECT_TRUE(base::DeleteFile(temp2, false)); EXPECT_TRUE(base::DeleteFile(temp2, false));
// 3. Cache contains the same version without hash, our file is unhashed // 3. Cache contains the same version without hash, our file is unhashed.
base::FilePath temp3; base::FilePath temp3;
CreateExtensionFile(temp_path, kTestExtensionId1, "3.0", 130, time, &temp3); CreateExtensionFile(temp_path, kTestExtensionId1, "3.0", 130, time, &temp3);
PutExtensionAndWait(cache, kTestExtensionId1, "", temp3, "3.0"); PutExtensionAndWait(&cache, kTestExtensionId1, "", temp3, "3.0");
// New file skipped, old file kept // New file skipped, old file kept
EXPECT_EQ(base::File(unhashed, base::File::FLAG_READ | base::File::FLAG_OPEN) EXPECT_EQ(base::File(unhashed, base::File::FLAG_READ | base::File::FLAG_OPEN)
.GetLength(), .GetLength(),
110); 110);
EXPECT_TRUE(base::DeleteFile(temp3, false)); EXPECT_TRUE(base::DeleteFile(temp3, false));
// 4. Cache contains the same version without hash, our file is hashed // 4. Cache contains the same version without hash, our file is hashed.
base::FilePath temp4; base::FilePath temp4;
const std::string hash3 = CreateSignedExtensionFile( const std::string hash3 = CreateSignedExtensionFile(
temp_path, kTestExtensionId1, "3.0", 140, time, &temp4); temp_path, kTestExtensionId1, "3.0", 140, time, &temp4);
PutExtensionAndWait(cache, kTestExtensionId1, hash3, temp4, "3.0"); PutExtensionAndWait(&cache, kTestExtensionId1, hash3, temp4, "3.0");
// New file added // New file added.
const base::FilePath hashed = const base::FilePath hashed =
GetExtensionFileName(cache_dir, kTestExtensionId1, "3.0", hash3); GetExtensionFileName(cache_dir, kTestExtensionId1, "3.0", hash3);
EXPECT_TRUE(base::PathExists(hashed)); EXPECT_TRUE(base::PathExists(hashed));
...@@ -397,37 +392,37 @@ TEST_F(LocalExtensionCacheTest, PutExtensionCases) { ...@@ -397,37 +392,37 @@ TEST_F(LocalExtensionCacheTest, PutExtensionCases) {
EXPECT_TRUE(base::DeleteFile(temp4, false)); EXPECT_TRUE(base::DeleteFile(temp4, false));
EXPECT_TRUE(base::DeleteFile(unhashed, false)); EXPECT_TRUE(base::DeleteFile(unhashed, false));
// 5. Cache contains the same version with hash, our file is unhashed // 5. Cache contains the same version with hash, our file is unhashed.
base::FilePath temp5; base::FilePath temp5;
CreateExtensionFile(temp_path, kTestExtensionId1, "3.0", 150, time, &temp5); CreateExtensionFile(temp_path, kTestExtensionId1, "3.0", 150, time, &temp5);
PutExtensionAndWait(cache, kTestExtensionId1, "", temp5, "3.0"); PutExtensionAndWait(&cache, kTestExtensionId1, "", temp5, "3.0");
// New file skipped // New file skipped.
EXPECT_FALSE(base::PathExists(unhashed)); EXPECT_FALSE(base::PathExists(unhashed));
// Old file kept // Old file kept.
EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash3, NULL, NULL)); EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash3, NULL, NULL));
EXPECT_TRUE(base::DeleteFile(temp5, false)); EXPECT_TRUE(base::DeleteFile(temp5, false));
// 6. Cache contains the same version with hash, our file has the "same" hash // 6. Cache contains the same version with hash, our file has the "same" hash.
base::FilePath temp6; base::FilePath temp6;
CreateExtensionFile(temp_path, kTestExtensionId1, "3.0", 160, time, &temp6); CreateExtensionFile(temp_path, kTestExtensionId1, "3.0", 160, time, &temp6);
PutExtensionAndWait(cache, kTestExtensionId1, hash3, temp6, "3.0"); PutExtensionAndWait(&cache, kTestExtensionId1, hash3, temp6, "3.0");
// New file skipped, old file kept // New file skipped, old file kept
EXPECT_EQ(base::File(hashed, base::File::FLAG_READ | base::File::FLAG_OPEN) EXPECT_EQ(base::File(hashed, base::File::FLAG_READ | base::File::FLAG_OPEN)
.GetLength(), .GetLength(),
140); 140);
EXPECT_TRUE(base::DeleteFile(temp6, false)); EXPECT_TRUE(base::DeleteFile(temp6, false));
// 7. Cache contains the same version with hash, our file is different // 7. Cache contains the same version with hash, our file is different.
base::FilePath temp7; base::FilePath temp7;
const std::string hash4 = CreateSignedExtensionFile( const std::string hash4 = CreateSignedExtensionFile(
temp_path, kTestExtensionId1, "3.0", 170, time, &temp7); temp_path, kTestExtensionId1, "3.0", 170, time, &temp7);
PutExtensionAndWait(cache, kTestExtensionId1, hash4, temp7, "3.0"); PutExtensionAndWait(&cache, kTestExtensionId1, hash4, temp7, "3.0");
// New file addded // New file added.
const base::FilePath hashed2 = const base::FilePath hashed2 =
GetExtensionFileName(cache_dir, kTestExtensionId1, "3.0", hash4); GetExtensionFileName(cache_dir, kTestExtensionId1, "3.0", hash4);
EXPECT_TRUE(base::PathExists(hashed2)); EXPECT_TRUE(base::PathExists(hashed2));
EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash4, NULL, NULL)); EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash4, NULL, NULL));
// Old file kept // Old file kept.
EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash3, NULL, NULL)); EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash3, NULL, NULL));
EXPECT_TRUE(base::DeleteFile(temp7, false)); EXPECT_TRUE(base::DeleteFile(temp7, false));
} }
......
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