Commit 0e9ae106 authored by Olivier Li's avatar Olivier Li Committed by Commit Bot

Set browser state builder dir to avoid file leaks in ios tests in /ios/chrome/browser/ui/bookmarks

This cl is generated with 'git cl split'

This CL was uploaded by git cl split.

R=sczs@chromium.org

Bug: 546640
Change-Id: I8ea59ea0816ab8f2cee1eb5a377d8b16ce41a220
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1991757
Commit-Queue: Oliver Li <olivierli@chromium.org>
Auto-Submit: Oliver Li <olivierli@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#730164}
parent b3326abc
...@@ -17,6 +17,10 @@ class BookmarkNode; ...@@ -17,6 +17,10 @@ class BookmarkNode;
class ManagedBookmarkService; class ManagedBookmarkService;
} // namespace bookmarks } // namespace bookmarks
namespace base {
class ScopedTempDir;
} // namespace base
class TestChromeBrowserState; class TestChromeBrowserState;
// Provides common bookmark testing infrastructure. // Provides common bookmark testing infrastructure.
...@@ -35,6 +39,11 @@ class BookmarkIOSUnitTest : public PlatformTest { ...@@ -35,6 +39,11 @@ class BookmarkIOSUnitTest : public PlatformTest {
NSString* title); NSString* title);
void ChangeTitle(NSString* title, const bookmarks::BookmarkNode* node); void ChangeTitle(NSString* title, const bookmarks::BookmarkNode* node);
// A state directory that outlives |task_environment_| is needed because
// CreateHistoryService/CreateBookmarkModel use the directory to host
// databases. See https://crbug.com/546640 for more details.
std::unique_ptr<base::ScopedTempDir> state_dir_;
web::WebTaskEnvironment task_environment_; web::WebTaskEnvironment task_environment_;
std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
bookmarks::BookmarkModel* _bookmarkModel; bookmarks::BookmarkModel* _bookmarkModel;
......
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "ios/chrome/browser/ui/bookmarks/bookmark_ios_unittest.h" #include "ios/chrome/browser/ui/bookmarks/bookmark_ios_unittest.h"
#include <memory>
#include "base/files/scoped_temp_dir.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "components/bookmarks/browser/bookmark_model.h" #include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/test/bookmark_test_helpers.h" #include "components/bookmarks/test/bookmark_test_helpers.h"
...@@ -23,6 +25,11 @@ BookmarkIOSUnitTest::~BookmarkIOSUnitTest() {} ...@@ -23,6 +25,11 @@ BookmarkIOSUnitTest::~BookmarkIOSUnitTest() {}
void BookmarkIOSUnitTest::SetUp() { void BookmarkIOSUnitTest::SetUp() {
// Get a BookmarkModel from the test ChromeBrowserState. // Get a BookmarkModel from the test ChromeBrowserState.
TestChromeBrowserState::Builder test_cbs_builder; TestChromeBrowserState::Builder test_cbs_builder;
state_dir_ = std::make_unique<base::ScopedTempDir>();
ASSERT_TRUE(state_dir_->CreateUniqueTempDir());
test_cbs_builder.SetPath(state_dir_->GetPath());
chrome_browser_state_ = test_cbs_builder.Build(); chrome_browser_state_ = test_cbs_builder.Build();
chrome_browser_state_->CreateBookmarkModel(true); chrome_browser_state_->CreateBookmarkModel(true);
......
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