Commit eca5e5cf authored by vabr's avatar vabr Committed by Commit bot

Change ScopedTempDir::path() to GetPath() in chrome/browser/chromeos/file_manager

This CL also changes TestVolume::CreateRootDirectory to handle that GetPath()
(unlike path()) cannot be called before initialising the ScopedTempDir. Because
CreateRootDirectory apparently can be called multiple times from
FakeTestVolume, it needs to handle that and not initialise the directory twice.
On the other hand, the directory cannot be initialised from anywhere else, so
this CL made this clear by adding a Boolean member root_initialized_ which is
updated and checked by CreateRootDirectory. Using the Boolean member, unlike
just handling the fact that the directory has been already initialised (this
information is still possible to retrieve via Take()+Set()), makes it clearer
that the assumption is the directory only being initialised where also
root_initialized_ is set.

R=achuith@chromium.org
BUG=640599

Review-Url: https://codereview.chromium.org/2345473002
Cr-Commit-Position: refs/heads/master@{#418797}
parent 96eff78d
...@@ -184,16 +184,20 @@ class TestVolume { ...@@ -184,16 +184,20 @@ class TestVolume {
virtual ~TestVolume() {} virtual ~TestVolume() {}
bool CreateRootDirectory(const Profile* profile) { bool CreateRootDirectory(const Profile* profile) {
const base::FilePath path = profile->GetPath().Append(name_); if (root_initialized_)
return root_.path() == path || root_.Set(path); return true;
root_initialized_ = root_.Set(profile->GetPath().Append(name_));
return root_initialized_;
} }
const std::string& name() { return name_; } const std::string& name() const { return name_; }
const base::FilePath root_path() { return root_.path(); } const base::FilePath& root_path() const { return root_.GetPath(); }
private: private:
std::string name_; std::string name_;
base::ScopedTempDir root_; base::ScopedTempDir root_;
bool root_initialized_ = false;
}; };
// Listener to obtain the test relative messages synchronously. // Listener to obtain the test relative messages synchronously.
......
...@@ -125,10 +125,9 @@ TEST_F(FileManagerFileWatcherTest, WatchLocalFile) { ...@@ -125,10 +125,9 @@ TEST_F(FileManagerFileWatcherTest, WatchLocalFile) {
bool on_change_error = false; bool on_change_error = false;
base::RunLoop run_loop; base::RunLoop run_loop;
file_watcher->WatchLocalFile( file_watcher->WatchLocalFile(
temp_dir.path(), temp_dir.GetPath(),
CreateQuitCallback( CreateQuitCallback(
&run_loop, &run_loop, CreateCopyResultCallback(&changed_path, &on_change_error)),
CreateCopyResultCallback(&changed_path, &on_change_error)),
CreateCopyResultCallback(&watcher_created)); CreateCopyResultCallback(&watcher_created));
// Spin the message loop so the base::FilePathWatcher is created. // Spin the message loop so the base::FilePathWatcher is created.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -137,11 +136,12 @@ TEST_F(FileManagerFileWatcherTest, WatchLocalFile) { ...@@ -137,11 +136,12 @@ TEST_F(FileManagerFileWatcherTest, WatchLocalFile) {
// Create a temporary file in the temporary directory. The file watcher // Create a temporary file in the temporary directory. The file watcher
// should detect the change in the directory. // should detect the change in the directory.
base::FilePath temp_file_path; base::FilePath temp_file_path;
ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &temp_file_path)); ASSERT_TRUE(
base::CreateTemporaryFileInDir(temp_dir.GetPath(), &temp_file_path));
// Wait until the directory change is notified. // Wait until the directory change is notified.
run_loop.Run(); run_loop.Run();
ASSERT_FALSE(on_change_error); ASSERT_FALSE(on_change_error);
ASSERT_EQ(temp_dir.path().value(), changed_path.value()); ASSERT_EQ(temp_dir.GetPath().value(), changed_path.value());
// This is ugly, but FileWatcher should be deleted explicitly here, and // This is ugly, but FileWatcher should be deleted explicitly here, and
// spin the message loop so the base::FilePathWatcher is deleted. // spin the message loop so the base::FilePathWatcher is deleted.
......
...@@ -55,7 +55,7 @@ TEST(FileManagerFileAPIUtilTest, ...@@ -55,7 +55,7 @@ TEST(FileManagerFileAPIUtilTest,
base::ScopedTempDir drive_cache_dir; base::ScopedTempDir drive_cache_dir;
ASSERT_TRUE(drive_cache_dir.CreateUniqueTempDir()); ASSERT_TRUE(drive_cache_dir.CreateUniqueTempDir());
drive::DriveIntegrationServiceFactory::FactoryCallback factory_callback( drive::DriveIntegrationServiceFactory::FactoryCallback factory_callback(
base::Bind(&CreateDriveIntegrationService, drive_cache_dir.path())); base::Bind(&CreateDriveIntegrationService, drive_cache_dir.GetPath()));
drive::DriveIntegrationServiceFactory::ScopedFactoryForTest drive::DriveIntegrationServiceFactory::ScopedFactoryForTest
integration_service_factory_scope(&factory_callback); integration_service_factory_scope(&factory_callback);
......
...@@ -34,11 +34,11 @@ class ZipFileCreatorTest : public InProcessBrowserTest { ...@@ -34,11 +34,11 @@ class ZipFileCreatorTest : public InProcessBrowserTest {
} }
base::FilePath zip_archive_path() const { base::FilePath zip_archive_path() const {
return dir_.path().AppendASCII("test.zip"); return dir_.GetPath().AppendASCII("test.zip");
} }
base::FilePath zip_base_dir() const { base::FilePath zip_base_dir() const {
return dir_.path().AppendASCII("files"); return dir_.GetPath().AppendASCII("files");
} }
protected: protected:
...@@ -110,7 +110,7 @@ IN_PROC_BROWSER_TEST_F(ZipFileCreatorTest, SomeFilesZip) { ...@@ -110,7 +110,7 @@ IN_PROC_BROWSER_TEST_F(ZipFileCreatorTest, SomeFilesZip) {
EXPECT_FALSE(entry->is_directory()); EXPECT_FALSE(entry->is_directory());
EXPECT_EQ(kRandomDataSize, entry->original_size()); EXPECT_EQ(kRandomDataSize, entry->original_size());
const base::FilePath out = dir_.path().AppendASCII("archived_content"); const base::FilePath out = dir_.GetPath().AppendASCII("archived_content");
EXPECT_TRUE(reader.ExtractCurrentEntryToFilePath(out)); EXPECT_TRUE(reader.ExtractCurrentEntryToFilePath(out));
EXPECT_TRUE(base::ContentsEqual(zip_base_dir().Append(kFile2), out)); EXPECT_TRUE(base::ContentsEqual(zip_base_dir().Append(kFile2), out));
} else { } else {
......
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