Commit 349b1232 authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

Add MyFilesVolume feature to browser tests

Add ability to run integration tests with MyFilesVolume feature
enabled.

Change Files app base BrowserTest class to:

1. create folder Downloads when the flag MyFilesVolume is enabled, so
it emulates the same condition that happens in the device.

2. |DownloadsTestVolume.CreateEntry| method to prefix entries with
"Downloads" so they are all created inside the sub-folder downloads.
This is needed to make the test logic compatible with the flag
MyFilesVolume enabled or disabled. Since MyFiles becomes the root
volume when it's enabled, entries would be created in MyFiles. This
should be cleaned up once MyFilesVolume is fully rolled out.

MyFiles/FilesAppBrowserTest.Test/myFilesUpdatesChildren_MyFilesVolume

Test: --gtest_filter="
Bug: 873539
Change-Id: I1464b7fa6f30f16cd7ddaa5900b11e95fafd9208
Reviewed-on: https://chromium-review.googlesource.com/c/1334989Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608251}
parent ad0bdf7c
...@@ -46,6 +46,11 @@ struct TestCase { ...@@ -46,6 +46,11 @@ struct TestCase {
return *this; return *this;
} }
TestCase& EnableMyFilesVolume() {
enable_myfiles_volume.emplace(true);
return *this;
}
TestCase& DisableDriveFs() { TestCase& DisableDriveFs() {
enable_drivefs.emplace(false); enable_drivefs.emplace(false);
return *this; return *this;
...@@ -83,6 +88,9 @@ struct TestCase { ...@@ -83,6 +88,9 @@ struct TestCase {
if (test.enable_drivefs.value_or(false)) if (test.enable_drivefs.value_or(false))
name.append("_DriveFs"); name.append("_DriveFs");
if (test.enable_myfiles_volume.value_or(false))
name.append("_MyFilesVolume");
return name; return name;
} }
...@@ -91,6 +99,7 @@ struct TestCase { ...@@ -91,6 +99,7 @@ struct TestCase {
bool trusted_events = false; bool trusted_events = false;
bool tablet_mode = false; bool tablet_mode = false;
base::Optional<bool> enable_drivefs; base::Optional<bool> enable_drivefs;
base::Optional<bool> enable_myfiles_volume;
bool with_browser = false; bool with_browser = false;
bool needs_zip = false; bool needs_zip = false;
bool offline = false; bool offline = false;
...@@ -153,6 +162,11 @@ class FilesAppBrowserTest : public FileManagerBrowserTestBase, ...@@ -153,6 +162,11 @@ class FilesAppBrowserTest : public FileManagerBrowserTestBase,
bool GetTabletMode() const override { return GetParam().tablet_mode; } bool GetTabletMode() const override { return GetParam().tablet_mode; }
bool GetEnableMyFilesVolume() const override {
return GetParam().enable_myfiles_volume.value_or(
FileManagerBrowserTestBase::GetEnableMyFilesVolume());
}
bool GetEnableDriveFs() const override { bool GetEnableDriveFs() const override {
return GetParam().enable_drivefs.value_or( return GetParam().enable_drivefs.value_or(
FileManagerBrowserTestBase::GetEnableDriveFs()); FileManagerBrowserTestBase::GetEnableDriveFs());
...@@ -687,12 +701,13 @@ WRAPPED_INSTANTIATE_TEST_CASE_P( ...@@ -687,12 +701,13 @@ WRAPPED_INSTANTIATE_TEST_CASE_P(
WRAPPED_INSTANTIATE_TEST_CASE_P( WRAPPED_INSTANTIATE_TEST_CASE_P(
MyFiles, /* my_files.js */ MyFiles, /* my_files.js */
FilesAppBrowserTest, FilesAppBrowserTest,
::testing::Values(TestCase("showMyFiles"), ::testing::Values(
TestCase("showMyFiles"),
TestCase("hideSearchButton"), TestCase("hideSearchButton"),
TestCase("myFilesDisplaysAndOpensEntries"), TestCase("myFilesDisplaysAndOpensEntries"),
TestCase("directoryTreeRefresh"), TestCase("directoryTreeRefresh"),
TestCase("myFilesFolderRename"), TestCase("myFilesFolderRename"),
TestCase("myFilesUpdatesChildren"))); TestCase("myFilesUpdatesChildren").EnableMyFilesVolume()));
WRAPPED_INSTANTIATE_TEST_CASE_P( WRAPPED_INSTANTIATE_TEST_CASE_P(
InstallLinuxPackageDialog, /* install_linux_package_dialog.js */ InstallLinuxPackageDialog, /* install_linux_package_dialog.js */
......
...@@ -514,10 +514,12 @@ class LocalTestVolume : public TestVolume { ...@@ -514,10 +514,12 @@ class LocalTestVolume : public TestVolume {
// Adds this local volume. Returns true on success. // Adds this local volume. Returns true on success.
virtual bool Mount(Profile* profile) = 0; virtual bool Mount(Profile* profile) = 0;
void CreateEntry(const AddEntriesMessage::TestEntryInfo& entry) { virtual void CreateEntry(const AddEntriesMessage::TestEntryInfo& entry) {
const base::FilePath target_path = CreateEntryImpl(entry, root_path().AppendASCII(entry.target_path));
root_path().AppendASCII(entry.target_path); }
void CreateEntryImpl(const AddEntriesMessage::TestEntryInfo& entry,
const base::FilePath& target_path) {
entries_.insert(std::make_pair(target_path, entry)); entries_.insert(std::make_pair(target_path, entry));
switch (entry.type) { switch (entry.type) {
case AddEntriesMessage::FILE: { case AddEntriesMessage::FILE: {
...@@ -540,16 +542,18 @@ class LocalTestVolume : public TestVolume { ...@@ -540,16 +542,18 @@ class LocalTestVolume : public TestVolume {
NOTREACHED() << "Can't create a computer in a local volume: " NOTREACHED() << "Can't create a computer in a local volume: "
<< target_path.value(); << target_path.value();
break; break;
default:
NOTREACHED() << "Unsupported entry type for: " << target_path.value();
} }
ASSERT_TRUE(UpdateModifiedTime(entry)); ASSERT_TRUE(UpdateModifiedTime(entry, target_path));
} }
private: private:
// Updates the ModifiedTime of the entry, and its parent directories if // Updates the ModifiedTime of the entry, and its parent directories if
// needed. Returns true on success. // needed. Returns true on success.
bool UpdateModifiedTime(const AddEntriesMessage::TestEntryInfo& entry) { bool UpdateModifiedTime(const AddEntriesMessage::TestEntryInfo& entry,
const base::FilePath path = root_path().AppendASCII(entry.target_path); const base::FilePath& path) {
if (!base::TouchFile(path, entry.last_modified_time, if (!base::TouchFile(path, entry.last_modified_time,
entry.last_modified_time)) { entry.last_modified_time)) {
return false; return false;
...@@ -561,7 +565,7 @@ class LocalTestVolume : public TestVolume { ...@@ -561,7 +565,7 @@ class LocalTestVolume : public TestVolume {
const auto& it = entries_.find(path.DirName()); const auto& it = entries_.find(path.DirName());
if (it == entries_.end()) if (it == entries_.end())
return false; return false;
return UpdateModifiedTime(it->second); return UpdateModifiedTime(it->second, path.DirName());
} }
return true; return true;
...@@ -578,13 +582,42 @@ class DownloadsTestVolume : public LocalTestVolume { ...@@ -578,13 +582,42 @@ class DownloadsTestVolume : public LocalTestVolume {
DownloadsTestVolume() : LocalTestVolume("Downloads") {} DownloadsTestVolume() : LocalTestVolume("Downloads") {}
~DownloadsTestVolume() override = default; ~DownloadsTestVolume() override = default;
void EnsureDownloadsFolderExists() {
if (!base::FeatureList::IsEnabled(chromeos::features::kMyFilesVolume))
return;
// When MyFiles is the volume create the Downloads folder under it.
auto downloads_folder = root_path().Append("Downloads");
if (!base::PathExists(downloads_folder)) {
CreateEntryImpl(AddEntriesMessage::TestEntryInfo(
AddEntriesMessage::DIRECTORY, "", "Downloads"),
downloads_folder);
}
}
// Forces the content to be created inside MyFiles/Downloads when MyFiles is
// the Volume, so tests are compatible with volume being MyFiles or Downloads.
// TODO(lucmult): Remove this special case once MyFiles volume has been
// rolled out.
base::FilePath base_path() const {
if (base::FeatureList::IsEnabled(chromeos::features::kMyFilesVolume))
return root_path().Append("Downloads");
return root_path();
}
bool Mount(Profile* profile) override { bool Mount(Profile* profile) override {
if (!CreateRootDirectory(profile)) if (!CreateRootDirectory(profile))
return false; return false;
EnsureDownloadsFolderExists();
auto* volume = VolumeManager::Get(profile); auto* volume = VolumeManager::Get(profile);
return volume->RegisterDownloadsDirectoryForTesting(root_path()); return volume->RegisterDownloadsDirectoryForTesting(root_path());
} }
void CreateEntry(const AddEntriesMessage::TestEntryInfo& entry) override {
base::FilePath target_path = base_path().Append(entry.target_path);
CreateEntryImpl(entry, target_path);
}
void Unmount(Profile* profile) { void Unmount(Profile* profile) {
auto* volume = VolumeManager::Get(profile); auto* volume = VolumeManager::Get(profile);
volume->RemoveDownloadsDirectoryForTesting(); volume->RemoveDownloadsDirectoryForTesting();
...@@ -1151,6 +1184,10 @@ void FileManagerBrowserTestBase::SetUpCommandLine( ...@@ -1151,6 +1184,10 @@ void FileManagerBrowserTestBase::SetUpCommandLine(
} else { } else {
disabled_features.emplace_back(chromeos::features::kDriveFs); disabled_features.emplace_back(chromeos::features::kDriveFs);
} }
if (IsMyFilesVolume())
enabled_features.emplace_back(chromeos::features::kMyFilesVolume);
feature_list_.InitWithFeatures(enabled_features, disabled_features); feature_list_.InitWithFeatures(enabled_features, disabled_features);
extensions::ExtensionApiTest::SetUpCommandLine(command_line); extensions::ExtensionApiTest::SetUpCommandLine(command_line);
...@@ -1241,6 +1278,10 @@ bool FileManagerBrowserTestBase::GetTabletMode() const { ...@@ -1241,6 +1278,10 @@ bool FileManagerBrowserTestBase::GetTabletMode() const {
return false; return false;
} }
bool FileManagerBrowserTestBase::GetEnableMyFilesVolume() const {
return false;
}
bool FileManagerBrowserTestBase::GetEnableDriveFs() const { bool FileManagerBrowserTestBase::GetEnableDriveFs() const {
return true; return true;
} }
......
...@@ -49,6 +49,7 @@ class FileManagerBrowserTestBase : public extensions::ExtensionApiTest { ...@@ -49,6 +49,7 @@ class FileManagerBrowserTestBase : public extensions::ExtensionApiTest {
// Optional overrides for each File Manager test extension type. // Optional overrides for each File Manager test extension type.
virtual bool GetTabletMode() const; virtual bool GetTabletMode() const;
virtual bool GetEnableDriveFs() const; virtual bool GetEnableDriveFs() const;
virtual bool GetEnableMyFilesVolume() const;
virtual bool GetRequiresStartupBrowser() const; virtual bool GetRequiresStartupBrowser() const;
virtual bool GetNeedsZipSupport() const; virtual bool GetNeedsZipSupport() const;
virtual bool GetIsOffline() const; virtual bool GetIsOffline() const;
...@@ -71,6 +72,9 @@ class FileManagerBrowserTestBase : public extensions::ExtensionApiTest { ...@@ -71,6 +72,9 @@ class FileManagerBrowserTestBase : public extensions::ExtensionApiTest {
// Returns true if the test requires DriveFS. // Returns true if the test requires DriveFS.
bool IsDriveFsTest() const { return GetEnableDriveFs(); } bool IsDriveFsTest() const { return GetEnableDriveFs(); }
// Returns true if the test MyFilesVolume feature is enabled.
bool IsMyFilesVolume() const { return GetEnableMyFilesVolume(); }
// Returns true if the test requires zip/unzip support. // Returns true if the test requires zip/unzip support.
bool IsZipTest() const { return GetNeedsZipSupport(); } bool IsZipTest() const { return GetNeedsZipSupport(); }
......
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