Skip to content

Commit

Permalink
Fix file leaks in BrowserThemePackTest.
Browse files Browse the repository at this point in the history
ScopedTempDir must outlive any files held open within it.

R=pkasting@chromium.org


Bug: 546640
Change-Id: I6b933846cc2578c6526aea8c11b251a26929846b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1895655
Commit-Queue: Greg Thompson <grt@chromium.org>
Auto-Submit: Greg Thompson <grt@chromium.org>
Reviewed-by: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711996}
  • Loading branch information
GregTho authored and Commit Bot committed Nov 2, 2019
1 parent 80941bc commit 48db91f
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions chrome/browser/themes/browser_theme_pack_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ class BrowserThemePackTest : public ::testing::Test {

const BrowserThemePack& theme_pack() const { return *theme_pack_; }

base::FilePath GetTemporaryPakFile(base::FilePath::StringPieceType name) {
if (dir_.IsValid() || dir_.CreateUniqueTempDir())
return dir_.GetPath().Append(name);
ADD_FAILURE() << "Couldn't create temp dir";
return base::FilePath();
}

private:
using ScopedSetSupportedScaleFactors =
std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors>;
Expand All @@ -114,6 +121,7 @@ class BrowserThemePackTest : public ::testing::Test {

ScopedSetSupportedScaleFactors scoped_set_supported_scale_factors_;

base::ScopedTempDir dir_;
content::BrowserTaskEnvironment task_environment_;
scoped_refptr<BrowserThemePack> theme_pack_;
};
Expand Down Expand Up @@ -729,9 +737,8 @@ TEST_F(BrowserThemePackTest, TestNonExistantImages) {
// the extension data, but for now, exists so valgrind can test some of the
// tricky memory stuff that BrowserThemePack does.
TEST_F(BrowserThemePackTest, CanBuildAndReadPack) {
base::ScopedTempDir dir;
ASSERT_TRUE(dir.CreateUniqueTempDir());
base::FilePath file = dir.GetPath().AppendASCII("data.pak");
base::FilePath file = GetTemporaryPakFile(FILE_PATH_LITERAL("data.pak"));
ASSERT_FALSE(file.empty());

// Part 1: Build the pack from an extension.
{
Expand All @@ -754,9 +761,9 @@ TEST_F(BrowserThemePackTest, CanBuildAndReadPack) {
}

TEST_F(BrowserThemePackTest, HiDpiThemeTest) {
base::ScopedTempDir dir;
ASSERT_TRUE(dir.CreateUniqueTempDir());
base::FilePath file = dir.GetPath().AppendASCII("theme_data.pak");
base::FilePath file =
GetTemporaryPakFile(FILE_PATH_LITERAL("theme_data.pak"));
ASSERT_FALSE(file.empty());

// Part 1: Build the pack from an extension.
{
Expand Down

0 comments on commit 48db91f

Please sign in to comment.