Commit 17c30a6b authored by Austin Tankiang's avatar Austin Tankiang Committed by Commit Bot

Remove DriveTestVolume in file manager browsertests

With the removal of the legacy drive client, DriveFsTestVolume can be
used instead.

Bug: 1003238
Change-Id: I57e99412c4a22c6bfa2d831f3506dc48309fa489
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1885865
Commit-Queue: Austin Tankiang <austinct@chromium.org>
Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710584}
parent 7c2df7e3
...@@ -970,186 +970,12 @@ class RemovableTestVolume : public FakeTestVolume { ...@@ -970,186 +970,12 @@ class RemovableTestVolume : public FakeTestVolume {
DISALLOW_COPY_AND_ASSIGN(RemovableTestVolume); DISALLOW_COPY_AND_ASSIGN(RemovableTestVolume);
}; };
// DriveTestVolume: test volume for Google Drive. // DriveFsTestVolume: test volume for Google Drive using DriveFS.
class DriveTestVolume : public TestVolume { class DriveFsTestVolume : public TestVolume {
public: public:
DriveTestVolume() : TestVolume("drive") {} explicit DriveFsTestVolume(Profile* original_profile)
~DriveTestVolume() override = default; : TestVolume("drive"), original_profile_(original_profile) {}
~DriveFsTestVolume() override = default;
virtual void CreateEntry(const AddEntriesMessage::TestEntryInfo& entry) {
const base::FilePath path =
base::FilePath::FromUTF8Unsafe(entry.target_path);
const std::string target_name = path.BaseName().AsUTF8Unsafe();
// Obtain the parent entry.
drive::FileError error = drive::FILE_ERROR_OK;
std::unique_ptr<drive::ResourceEntry> parent_entry(
new drive::ResourceEntry);
if (!entry.team_drive_name.empty()) {
integration_service_->file_system()->GetResourceEntry(
drive::util::GetDriveTeamDrivesRootPath()
.Append(entry.team_drive_name)
.Append(path)
.DirName(),
google_apis::test_util::CreateCopyResultCallback(&error,
&parent_entry));
} else {
integration_service_->file_system()->GetResourceEntry(
drive::util::GetDriveMyDriveRootPath().Append(path).DirName(),
google_apis::test_util::CreateCopyResultCallback(&error,
&parent_entry));
}
content::RunAllTasksUntilIdle();
ASSERT_EQ(drive::FILE_ERROR_OK, error);
ASSERT_TRUE(parent_entry);
// Create the capabilities object.
google_apis::FileResourceCapabilities file_capabilities;
file_capabilities.set_can_copy(entry.capabilities.can_copy);
file_capabilities.set_can_delete(entry.capabilities.can_delete);
file_capabilities.set_can_rename(entry.capabilities.can_rename);
file_capabilities.set_can_add_children(entry.capabilities.can_add_children);
file_capabilities.set_can_share(entry.capabilities.can_share);
google_apis::TeamDriveCapabilities team_drive_capabilities;
team_drive_capabilities.set_can_copy(entry.capabilities.can_copy);
team_drive_capabilities.set_can_delete_team_drive(
entry.capabilities.can_delete);
team_drive_capabilities.set_can_rename_team_drive(
entry.capabilities.can_rename);
team_drive_capabilities.set_can_add_children(
entry.capabilities.can_add_children);
team_drive_capabilities.set_can_share(entry.capabilities.can_share);
// Add the file or directory entry.
switch (entry.type) {
case AddEntriesMessage::FILE:
CreateFile(entry.source_file_name, parent_entry->resource_id(),
target_name, entry.mime_type,
entry.shared_option == AddEntriesMessage::SHARED ||
entry.shared_option == AddEntriesMessage::SHARED_WITH_ME,
entry.last_modified_time, file_capabilities);
break;
case AddEntriesMessage::DIRECTORY:
CreateDirectory(
parent_entry->resource_id(), target_name, entry.last_modified_time,
entry.shared_option == AddEntriesMessage::SHARED ||
entry.shared_option == AddEntriesMessage::SHARED_WITH_ME,
file_capabilities);
break;
case AddEntriesMessage::LINK:
NOTREACHED() << "Can't create a link in a drive test volume: "
<< entry.computer_name;
break;
case AddEntriesMessage::TEAM_DRIVE:
CreateTeamDrive(entry.team_drive_name, team_drive_capabilities);
break;
case AddEntriesMessage::COMPUTER:
NOTREACHED() << "Can't create a computer in a drive test volume: "
<< entry.computer_name;
break;
}
// Any file or directory created above, will only appear in Drive after
// CheckForUpdates() has completed.
CheckForUpdates();
content::RunAllTasksUntilIdle();
}
// Creates a new Team Drive with ID |name| and name |name|, and sets the
// capabilities to |capabilities|.
void CreateTeamDrive(const std::string& name,
google_apis::TeamDriveCapabilities capabilities) {
fake_drive_service_->AddTeamDrive(name, name);
fake_drive_service_->SetTeamDriveCapabilities(name, capabilities);
}
// Creates an empty directory with the given |name| and |modification_time|.
void CreateDirectory(
const std::string& parent_id,
const std::string& target_name,
const base::Time& modification_time,
bool shared_with_me,
const google_apis::FileResourceCapabilities& capabilities) {
google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR;
std::unique_ptr<google_apis::FileResource> entry;
fake_drive_service_->AddNewDirectory(
parent_id, target_name, drive::AddNewDirectoryOptions(),
google_apis::test_util::CreateCopyResultCallback(&error, &entry));
base::RunLoop().RunUntilIdle();
ASSERT_EQ(google_apis::HTTP_CREATED, error);
ASSERT_TRUE(entry);
fake_drive_service_->SetLastModifiedTime(
entry->file_id(), modification_time,
google_apis::test_util::CreateCopyResultCallback(&error, &entry));
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(error == google_apis::HTTP_SUCCESS);
ASSERT_TRUE(entry);
fake_drive_service_->SetFileCapabilities(
entry->file_id(), capabilities,
google_apis::test_util::CreateCopyResultCallback(&error, &entry));
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(error == google_apis::HTTP_SUCCESS);
ASSERT_TRUE(entry);
if (shared_with_me) {
ASSERT_EQ(google_apis::HTTP_SUCCESS,
fake_drive_service_->SetFileAsSharedWithMe(entry->file_id()));
}
}
// Creates a test file with the given spec.
// Serves |test_file_name| file. Pass an empty string for an empty file.
void CreateFile(const std::string& source_file_name,
const std::string& parent_id,
const std::string& target_name,
const std::string& mime_type,
bool shared_with_me,
const base::Time& modification_time,
const google_apis::FileResourceCapabilities& capabilities) {
google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR;
std::string content_data;
if (!source_file_name.empty()) {
base::FilePath source_path =
TestVolume::GetTestDataFilePath(source_file_name);
ASSERT_TRUE(base::ReadFileToString(source_path, &content_data));
}
std::unique_ptr<google_apis::FileResource> entry;
fake_drive_service_->AddNewFile(
mime_type, content_data, parent_id, target_name, shared_with_me,
google_apis::test_util::CreateCopyResultCallback(&error, &entry));
base::RunLoop().RunUntilIdle();
ASSERT_EQ(google_apis::HTTP_CREATED, error);
ASSERT_TRUE(entry);
fake_drive_service_->SetLastModifiedTime(
entry->file_id(), modification_time,
google_apis::test_util::CreateCopyResultCallback(&error, &entry));
base::RunLoop().RunUntilIdle();
ASSERT_EQ(google_apis::HTTP_SUCCESS, error);
ASSERT_TRUE(entry);
fake_drive_service_->SetFileCapabilities(
entry->file_id(), capabilities,
google_apis::test_util::CreateCopyResultCallback(&error, &entry));
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(error == google_apis::HTTP_SUCCESS);
ASSERT_TRUE(entry);
}
// Notifies FileSystem that the contents in FakeDriveService have changed,
// hence the new contents should be fetched.
void CheckForUpdates() {
if (integration_service_ && integration_service_->file_system()) {
integration_service_->file_system()->CheckForUpdates();
}
}
drive::DriveIntegrationService* CreateDriveIntegrationService( drive::DriveIntegrationService* CreateDriveIntegrationService(
Profile* profile) { Profile* profile) {
...@@ -1159,13 +985,10 @@ class DriveTestVolume : public TestVolume { ...@@ -1159,13 +985,10 @@ class DriveTestVolume : public TestVolume {
EXPECT_FALSE(profile_); EXPECT_FALSE(profile_);
profile_ = profile; profile_ = profile;
EXPECT_FALSE(fake_drive_service_);
fake_drive_service_ = new drive::FakeDriveService;
EXPECT_FALSE(integration_service_); EXPECT_FALSE(integration_service_);
integration_service_ = new drive::DriveIntegrationService( integration_service_ = new drive::DriveIntegrationService(
profile, nullptr, fake_drive_service_, std::string(), profile, nullptr, nullptr, std::string(), root_path().Append("v1"),
root_path().Append("v1"), nullptr, CreateDriveFsBootstrapListener()); nullptr, CreateDriveFsBootstrapListener());
return integration_service_; return integration_service_;
} }
...@@ -1184,30 +1007,7 @@ class DriveTestVolume : public TestVolume { ...@@ -1184,30 +1007,7 @@ class DriveTestVolume : public TestVolume {
void Unmount() { integration_service_->SetEnabled(false); } void Unmount() { integration_service_->SetEnabled(false); }
private: void CreateEntry(const AddEntriesMessage::TestEntryInfo& entry) {
virtual base::RepeatingCallback<
std::unique_ptr<drivefs::DriveFsBootstrapListener>()>
CreateDriveFsBootstrapListener() {
return {};
}
// Profile associated with this volume: not owned.
Profile* profile_ = nullptr;
// Fake drive service used for testing: not owned.
drive::FakeDriveService* fake_drive_service_ = nullptr;
// Integration service used for testing: not owned.
drive::DriveIntegrationService* integration_service_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(DriveTestVolume);
};
// DriveFsTestVolume: test volume for Google Drive using DriveFS.
class DriveFsTestVolume : public DriveTestVolume {
public:
explicit DriveFsTestVolume(Profile* profile) : profile_(profile) {}
~DriveFsTestVolume() override = default;
void CreateEntry(const AddEntriesMessage::TestEntryInfo& entry) override {
const base::FilePath target_path = GetTargetPathForTestEntry(entry); const base::FilePath target_path = GetTargetPathForTestEntry(entry);
entries_.insert(std::make_pair(target_path, entry)); entries_.insert(std::make_pair(target_path, entry));
...@@ -1264,14 +1064,14 @@ class DriveFsTestVolume : public DriveTestVolume { ...@@ -1264,14 +1064,14 @@ class DriveFsTestVolume : public DriveTestVolume {
private: private:
base::RepeatingCallback<std::unique_ptr<drivefs::DriveFsBootstrapListener>()> base::RepeatingCallback<std::unique_ptr<drivefs::DriveFsBootstrapListener>()>
CreateDriveFsBootstrapListener() override { CreateDriveFsBootstrapListener() {
CHECK(base::CreateDirectory(GetMyDrivePath())); CHECK(base::CreateDirectory(GetMyDrivePath()));
CHECK(base::CreateDirectory(GetTeamDriveGrandRoot())); CHECK(base::CreateDirectory(GetTeamDriveGrandRoot()));
CHECK(base::CreateDirectory(GetComputerGrandRoot())); CHECK(base::CreateDirectory(GetComputerGrandRoot()));
if (!fake_drivefs_helper_) { if (!fake_drivefs_helper_) {
fake_drivefs_helper_ = fake_drivefs_helper_ = std::make_unique<drive::FakeDriveFsHelper>(
std::make_unique<drive::FakeDriveFsHelper>(profile_, mount_path()); original_profile_, mount_path());
} }
return fake_drivefs_helper_->CreateFakeDriveFsListenerFactory(); return fake_drivefs_helper_->CreateFakeDriveFsListenerFactory();
...@@ -1357,7 +1157,12 @@ class DriveFsTestVolume : public DriveTestVolume { ...@@ -1357,7 +1157,12 @@ class DriveFsTestVolume : public DriveTestVolume {
return GetComputerGrandRoot().Append(computer_name); return GetComputerGrandRoot().Append(computer_name);
} }
Profile* const profile_; // Profile associated with this volume: not owned.
Profile* profile_ = nullptr;
// Integration service used for testing: not owned.
drive::DriveIntegrationService* integration_service_ = nullptr;
Profile* const original_profile_;
std::map<base::FilePath, const AddEntriesMessage::TestEntryInfo> entries_; std::map<base::FilePath, const AddEntriesMessage::TestEntryInfo> entries_;
std::unique_ptr<drive::FakeDriveFsHelper> fake_drivefs_helper_; std::unique_ptr<drive::FakeDriveFsHelper> fake_drivefs_helper_;
......
...@@ -30,7 +30,7 @@ namespace file_manager { ...@@ -30,7 +30,7 @@ namespace file_manager {
enum GuestMode { NOT_IN_GUEST_MODE, IN_GUEST_MODE, IN_INCOGNITO }; enum GuestMode { NOT_IN_GUEST_MODE, IN_GUEST_MODE, IN_INCOGNITO };
class DriveTestVolume; class DriveFsTestVolume;
class FakeTestVolume; class FakeTestVolume;
class DownloadsTestVolume; class DownloadsTestVolume;
class CrostiniTestVolume; class CrostiniTestVolume;
...@@ -149,8 +149,8 @@ class FileManagerBrowserTestBase : public extensions::ExtensionApiTest { ...@@ -149,8 +149,8 @@ class FileManagerBrowserTestBase : public extensions::ExtensionApiTest {
std::unique_ptr<DownloadsTestVolume> local_volume_; std::unique_ptr<DownloadsTestVolume> local_volume_;
std::unique_ptr<CrostiniTestVolume> crostini_volume_; std::unique_ptr<CrostiniTestVolume> crostini_volume_;
std::unique_ptr<AndroidFilesTestVolume> android_files_volume_; std::unique_ptr<AndroidFilesTestVolume> android_files_volume_;
std::map<Profile*, std::unique_ptr<DriveTestVolume>> drive_volumes_; std::map<Profile*, std::unique_ptr<DriveFsTestVolume>> drive_volumes_;
DriveTestVolume* drive_volume_ = nullptr; DriveFsTestVolume* drive_volume_ = nullptr;
std::unique_ptr<FakeTestVolume> usb_volume_; std::unique_ptr<FakeTestVolume> usb_volume_;
std::unique_ptr<FakeTestVolume> mtp_volume_; std::unique_ptr<FakeTestVolume> mtp_volume_;
std::unique_ptr<RemovableTestVolume> partition_1_; std::unique_ptr<RemovableTestVolume> partition_1_;
......
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