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 {
return *this;
}
TestCase& EnableMyFilesVolume() {
enable_myfiles_volume.emplace(true);
return *this;
}
TestCase& DisableDriveFs() {
enable_drivefs.emplace(false);
return *this;
......@@ -83,6 +88,9 @@ struct TestCase {
if (test.enable_drivefs.value_or(false))
name.append("_DriveFs");
if (test.enable_myfiles_volume.value_or(false))
name.append("_MyFilesVolume");
return name;
}
......@@ -91,6 +99,7 @@ struct TestCase {
bool trusted_events = false;
bool tablet_mode = false;
base::Optional<bool> enable_drivefs;
base::Optional<bool> enable_myfiles_volume;
bool with_browser = false;
bool needs_zip = false;
bool offline = false;
......@@ -153,6 +162,11 @@ class FilesAppBrowserTest : public FileManagerBrowserTestBase,
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 {
return GetParam().enable_drivefs.value_or(
FileManagerBrowserTestBase::GetEnableDriveFs());
......@@ -687,12 +701,13 @@ WRAPPED_INSTANTIATE_TEST_CASE_P(
WRAPPED_INSTANTIATE_TEST_CASE_P(
MyFiles, /* my_files.js */
FilesAppBrowserTest,
::testing::Values(TestCase("showMyFiles"),
TestCase("hideSearchButton"),
TestCase("myFilesDisplaysAndOpensEntries"),
TestCase("directoryTreeRefresh"),
TestCase("myFilesFolderRename"),
TestCase("myFilesUpdatesChildren")));
::testing::Values(
TestCase("showMyFiles"),
TestCase("hideSearchButton"),
TestCase("myFilesDisplaysAndOpensEntries"),
TestCase("directoryTreeRefresh"),
TestCase("myFilesFolderRename"),
TestCase("myFilesUpdatesChildren").EnableMyFilesVolume()));
WRAPPED_INSTANTIATE_TEST_CASE_P(
InstallLinuxPackageDialog, /* install_linux_package_dialog.js */
......
......@@ -514,10 +514,12 @@ class LocalTestVolume : public TestVolume {
// Adds this local volume. Returns true on success.
virtual bool Mount(Profile* profile) = 0;
void CreateEntry(const AddEntriesMessage::TestEntryInfo& entry) {
const base::FilePath target_path =
root_path().AppendASCII(entry.target_path);
virtual void CreateEntry(const AddEntriesMessage::TestEntryInfo& entry) {
CreateEntryImpl(entry, 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));
switch (entry.type) {
case AddEntriesMessage::FILE: {
......@@ -540,16 +542,18 @@ class LocalTestVolume : public TestVolume {
NOTREACHED() << "Can't create a computer in a local volume: "
<< target_path.value();
break;
default:
NOTREACHED() << "Unsupported entry type for: " << target_path.value();
}
ASSERT_TRUE(UpdateModifiedTime(entry));
ASSERT_TRUE(UpdateModifiedTime(entry, target_path));
}
private:
// Updates the ModifiedTime of the entry, and its parent directories if
// needed. Returns true on success.
bool UpdateModifiedTime(const AddEntriesMessage::TestEntryInfo& entry) {
const base::FilePath path = root_path().AppendASCII(entry.target_path);
bool UpdateModifiedTime(const AddEntriesMessage::TestEntryInfo& entry,
const base::FilePath& path) {
if (!base::TouchFile(path, entry.last_modified_time,
entry.last_modified_time)) {
return false;
......@@ -561,7 +565,7 @@ class LocalTestVolume : public TestVolume {
const auto& it = entries_.find(path.DirName());
if (it == entries_.end())
return false;
return UpdateModifiedTime(it->second);
return UpdateModifiedTime(it->second, path.DirName());
}
return true;
......@@ -578,13 +582,42 @@ class DownloadsTestVolume : public LocalTestVolume {
DownloadsTestVolume() : LocalTestVolume("Downloads") {}
~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 {
if (!CreateRootDirectory(profile))
return false;
EnsureDownloadsFolderExists();
auto* volume = VolumeManager::Get(profile);
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) {
auto* volume = VolumeManager::Get(profile);
volume->RemoveDownloadsDirectoryForTesting();
......@@ -1151,6 +1184,10 @@ void FileManagerBrowserTestBase::SetUpCommandLine(
} else {
disabled_features.emplace_back(chromeos::features::kDriveFs);
}
if (IsMyFilesVolume())
enabled_features.emplace_back(chromeos::features::kMyFilesVolume);
feature_list_.InitWithFeatures(enabled_features, disabled_features);
extensions::ExtensionApiTest::SetUpCommandLine(command_line);
......@@ -1241,6 +1278,10 @@ bool FileManagerBrowserTestBase::GetTabletMode() const {
return false;
}
bool FileManagerBrowserTestBase::GetEnableMyFilesVolume() const {
return false;
}
bool FileManagerBrowserTestBase::GetEnableDriveFs() const {
return true;
}
......
......@@ -49,6 +49,7 @@ class FileManagerBrowserTestBase : public extensions::ExtensionApiTest {
// Optional overrides for each File Manager test extension type.
virtual bool GetTabletMode() const;
virtual bool GetEnableDriveFs() const;
virtual bool GetEnableMyFilesVolume() const;
virtual bool GetRequiresStartupBrowser() const;
virtual bool GetNeedsZipSupport() const;
virtual bool GetIsOffline() const;
......@@ -71,6 +72,9 @@ class FileManagerBrowserTestBase : public extensions::ExtensionApiTest {
// Returns true if the test requires DriveFS.
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.
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