Commit 1ac34692 authored by Austin Tankiang's avatar Austin Tankiang Committed by Commit Bot

Remove DriveService dependency from apitests

Bug: 1003238
Change-Id: I0d9241a98c12470a95a772a5d9d59da33a3aae65
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1888615Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Commit-Queue: Austin Tankiang <austinct@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710650}
parent 8f89167c
......@@ -13,7 +13,6 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/drive/drive_integration_service.h"
#include "chrome/browser/chromeos/drive/drivefs_test_support.h"
#include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/chromeos/file_manager/mount_test_util.h"
#include "chrome/browser/chromeos/file_manager/volume_manager.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
......@@ -27,16 +26,13 @@
#include "chrome/common/chrome_paths.h"
#include "chromeos/constants/chromeos_features.h"
#include "chromeos/constants/chromeos_switches.h"
#include "components/drive/service/fake_drive_service.h"
#include "components/session_manager/core/session_manager.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/notification_service.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/notification_types.h"
#include "extensions/test/result_catcher.h"
#include "google_apis/drive/drive_api_parser.h"
#include "google_apis/drive/test_util.h"
#include "google_apis/drive/time_util.h"
#include "storage/browser/file_system/external_mount_points.h"
#include "ui/shell_dialogs/select_file_dialog_factory.h"
#include "ui/shell_dialogs/select_file_policy.h"
......@@ -50,8 +46,6 @@
// - restricted (kFileSystemTypeRestrictedLocalNative): a *read-only* local file
// system which can only be accessed by extensions that have full access to
// external file systems (i.e. extensions with fileManagerPrivate permission).
// - drive (kFileSystemTypeDrive): a file system that provides access to Google
// Drive.
//
// The tests cover following scenarios:
// - Performing file system operations on external file systems from an
......@@ -225,83 +219,6 @@ bool InitializeLocalFileSystem(std::string mount_point_name,
return true;
}
void IgnoreDriveEntryResult(google_apis::DriveApiErrorCode error,
std::unique_ptr<google_apis::FileResource> entry) {}
void UpdateDriveEntryTime(drive::FakeDriveService* fake_drive_service,
const std::string& resource_id,
const std::string& last_modified,
const std::string& last_viewed_by_me) {
base::Time last_modified_time, last_viewed_by_me_time;
ASSERT_TRUE(google_apis::util::GetTimeFromString(last_modified,
&last_modified_time) &&
google_apis::util::GetTimeFromString(last_viewed_by_me,
&last_viewed_by_me_time));
fake_drive_service->UpdateResource(resource_id,
std::string(), // parent_resource_id
std::string(), // title
last_modified_time, last_viewed_by_me_time,
google_apis::drive::Properties(),
base::Bind(&IgnoreDriveEntryResult));
}
void AddFileToDriveService(drive::FakeDriveService* fake_drive_service,
const std::string& mime_type,
const std::string& content,
const std::string& parent_resource_id,
const std::string& title,
const std::string& last_modified,
const std::string& last_viewed_by_me) {
fake_drive_service->AddNewFileWithResourceId(
title, mime_type, content, parent_resource_id, title,
false, // shared_with_me
base::Bind(&IgnoreDriveEntryResult));
UpdateDriveEntryTime(fake_drive_service, title, last_modified,
last_viewed_by_me);
}
void AddDirectoryToDriveService(drive::FakeDriveService* fake_drive_service,
const std::string& parent_resource_id,
const std::string& title,
const std::string& last_modified,
const std::string& last_viewed_by_me) {
fake_drive_service->AddNewDirectoryWithResourceId(
title, parent_resource_id, title, drive::AddNewDirectoryOptions(),
base::Bind(&IgnoreDriveEntryResult));
UpdateDriveEntryTime(fake_drive_service, title, last_modified,
last_viewed_by_me);
}
// Sets up the drive service state.
// The hierarchy is the same as for the local file system.
drive::FakeDriveService* CreateDriveService() {
drive::FakeDriveService* service = new drive::FakeDriveService;
AddDirectoryToDriveService(service, service->GetRootResourceId(), "test_dir",
"2012-01-02T00:00:00.000Z",
"2012-01-02T00:00:01.000Z");
AddDirectoryToDriveService(service, "test_dir", "empty_dir",
"2011-11-02T04:00:00.000Z",
"2011-11-02T04:00:00.000Z");
AddDirectoryToDriveService(service, "test_dir", "subdir",
"2011-04-01T18:34:08.234Z",
"2012-01-02T00:00:01.000Z");
AddFileToDriveService(service, "application/vnd.mozilla.xul+xml",
kTestFileContent, "test_dir", "test_file.xul",
"2011-12-14T00:40:47.330Z", "2012-01-02T00:00:00.000Z");
AddFileToDriveService(service, "test/ro", kTestFileContent, "test_dir",
"test_file.xul.foo", "2012-01-01T10:00:30.000Z",
"2012-01-01T00:00:00.000Z");
AddFileToDriveService(service, "image/tiff", kTestFileContent, "test_dir",
"test_file.tiff", "2011-04-03T11:11:10.000Z",
"2012-01-02T00:00:00.000Z");
AddFileToDriveService(service, "test/rw", kTestFileContent, "test_dir",
"test_file.tiff.foo", "2011-12-14T00:40:47.330Z",
"2010-01-02T00:00:00.000Z");
AddFileToDriveService(service, "test/rw", "", "test_dir", "empty_file.foo",
"2011-12-14T00:40:47.330Z", "2011-12-14T00:40:47.330Z");
return service;
}
// Helper class to wait for a background page to load or close again.
class BackgroundObserver {
public:
......@@ -512,7 +429,6 @@ class DriveFileSystemExtensionApiTest : public FileSystemExtensionApiTestBase {
base::Unretained(this));
service_factory_for_test_ =
std::make_unique<DriveIntegrationServiceFactory::ScopedFactoryForTest>(
&create_drive_integration_service_);
}
......@@ -540,21 +456,18 @@ class DriveFileSystemExtensionApiTest : public FileSystemExtensionApiTestBase {
// DriveFileSystemExtensionApiTest doesn't expect that several user profiles
// could exist simultaneously.
DCHECK(!fake_drive_service_);
fake_drive_service_ = CreateDriveService();
base::FilePath drivefs_mount_point;
InitializeLocalFileSystem("drive-user/root", &drivefs_root_,
&drivefs_mount_point);
fake_drivefs_helper_ = std::make_unique<drive::FakeDriveFsHelper>(
profile, drivefs_mount_point.DirName());
return new drive::DriveIntegrationService(
profile, nullptr, fake_drive_service_, "", test_cache_root_.GetPath(),
nullptr, fake_drivefs_helper_->CreateFakeDriveFsListenerFactory());
profile, nullptr, nullptr, "", test_cache_root_.GetPath(), nullptr,
fake_drivefs_helper_->CreateFakeDriveFsListenerFactory());
}
base::ScopedTempDir test_cache_root_;
base::ScopedTempDir drivefs_root_;
drive::FakeDriveService* fake_drive_service_ = nullptr;
std::unique_ptr<drive::FakeDriveFsHelper> fake_drivefs_helper_;
DriveIntegrationServiceFactory::FactoryCallback
create_drive_integration_service_;
......@@ -644,11 +557,10 @@ class MultiProfileDriveFileSystemExtensionApiTest :
CHECK(google_apis::test_util::WriteStringToFile(
test_dir.AppendASCII("hosted_doc.gdoc"), kTestFileContent));
drive::FakeDriveService* const service = CreateDriveService();
const auto& drivefs_helper = fake_drivefs_helpers_[profile] =
std::make_unique<drive::FakeDriveFsHelper>(profile, drivefs_dir);
return new drive::DriveIntegrationService(
profile, nullptr, service, std::string(), cache_dir, nullptr,
profile, nullptr, nullptr, std::string(), cache_dir, nullptr,
drivefs_helper->CreateFakeDriveFsListenerFactory());
}
......@@ -685,7 +597,6 @@ class LocalAndDriveFileSystemExtensionApiTest
base::Unretained(this));
service_factory_for_test_ =
std::make_unique<DriveIntegrationServiceFactory::ScopedFactoryForTest>(
&create_drive_integration_service_);
}
......@@ -714,16 +625,14 @@ class LocalAndDriveFileSystemExtensionApiTest
// LocalAndDriveFileSystemExtensionApiTest doesn't expect that several user
// profiles could exist simultaneously.
DCHECK(!fake_drive_service_);
fake_drive_service_ = CreateDriveService();
base::FilePath drivefs_mount_point;
InitializeLocalFileSystem("drive-user/root", &drivefs_root_,
&drivefs_mount_point);
fake_drivefs_helper_ = std::make_unique<drive::FakeDriveFsHelper>(
profile, drivefs_mount_point.DirName());
return new drive::DriveIntegrationService(
profile, nullptr, fake_drive_service_, "", test_cache_root_.GetPath(),
nullptr, fake_drivefs_helper_->CreateFakeDriveFsListenerFactory());
profile, nullptr, nullptr, "", test_cache_root_.GetPath(), nullptr,
fake_drivefs_helper_->CreateFakeDriveFsListenerFactory());
}
private:
......@@ -734,7 +643,6 @@ class LocalAndDriveFileSystemExtensionApiTest
// For drive volume.
base::ScopedTempDir test_cache_root_;
base::ScopedTempDir drivefs_root_;
drive::FakeDriveService* fake_drive_service_ = nullptr;
std::unique_ptr<drive::FakeDriveFsHelper> fake_drivefs_helper_;
DriveIntegrationServiceFactory::FactoryCallback
create_drive_integration_service_;
......
......@@ -14,7 +14,6 @@
#include "chrome/browser/apps/platform_apps/app_browsertest_util.h"
#include "chrome/browser/chromeos/drive/drive_integration_service.h"
#include "chrome/browser/chromeos/drive/drivefs_test_support.h"
#include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/chromeos/file_manager/volume_manager.h"
#include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
......@@ -22,17 +21,12 @@
#include "chrome/browser/extensions/component_loader.h"
#include "chrome/common/chrome_paths.h"
#include "chromeos/constants/chromeos_features.h"
#include "components/drive/chromeos/file_system_interface.h"
#include "components/drive/service/fake_drive_service.h"
#include "components/user_manager/scoped_user_manager.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/api/file_system/file_system_api.h"
#include "extensions/browser/event_router.h"
#include "extensions/common/api/file_system.h"
#include "extensions/common/switches.h"
#include "google_apis/drive/base_requests.h"
#include "google_apis/drive/drive_api_parser.h"
#include "google_apis/drive/test_util.h"
#include "storage/browser/file_system/external_mount_points.h"
#include "ui/base/ui_base_types.h"
......@@ -55,9 +49,6 @@ const char kChildDirectory[] = "child-dir";
// ID of a testing extension.
const char kTestingExtensionId[] = "pkplfbidichfdicaijlchgnapepdginl";
void IgnoreDriveEntryResult(google_apis::DriveApiErrorCode error,
std::unique_ptr<google_apis::FileResource> entry) {}
} // namespace
// Skips the user consent dialog for chrome.fileSystem.requestFileSystem() and
......@@ -165,9 +156,6 @@ class FileSystemApiTestForDrive : public PlatformAppBrowserTest {
// FileSystemApiTestForDrive doesn't expect that several user profiles could
// exist simultaneously.
DCHECK(!fake_drive_service_);
fake_drive_service_ = new drive::FakeDriveService;
CHECK(drivefs_root_.CreateUniqueTempDir());
drivefs_mount_point_ = drivefs_root_.GetPath().Append("drive-user");
fake_drivefs_helper_ = std::make_unique<drive::FakeDriveFsHelper>(
......@@ -176,50 +164,33 @@ class FileSystemApiTestForDrive : public PlatformAppBrowserTest {
SetUpTestFileHierarchy();
integration_service_ = new drive::DriveIntegrationService(
profile, nullptr, fake_drive_service_, "", test_cache_root_.GetPath(),
nullptr, fake_drivefs_helper_->CreateFakeDriveFsListenerFactory());
profile, nullptr, nullptr, "", test_cache_root_.GetPath(), nullptr,
fake_drivefs_helper_->CreateFakeDriveFsListenerFactory());
return integration_service_;
}
void SetUpTestFileHierarchy() {
CHECK(base::CreateDirectory(drivefs_mount_point_.Append("root")));
const std::string root = fake_drive_service_->GetRootResourceId();
AddTestFile("open_existing.txt", "Can you see me?", root);
AddTestFile("open_existing1.txt", "Can you see me?", root);
AddTestFile("open_existing2.txt", "Can you see me?", root);
AddTestFile("save_existing.txt", "Can you see me?", root);
const char kSubdirResourceId[] = "subdir_resource_id";
AddTestDirectory(kSubdirResourceId, "subdir", root);
AddTestFile("open_existing.txt", "Can you see me?", kSubdirResourceId);
}
void AddTestFile(const std::string& title,
const std::string& data,
const std::string& parent_id) {
fake_drive_service_->AddNewFile("text/plain", data, parent_id, title, false,
base::Bind(&IgnoreDriveEntryResult));
base::FilePath parent_path = drivefs_mount_point_.Append("root");
if (parent_id == "subdir_resource_id") {
parent_path = parent_path.Append("subdir");
}
CHECK(base::WriteFile(parent_path.Append(title), data.data(), data.size()));
}
void AddTestDirectory(const std::string& resource_id,
const std::string& title,
const std::string& parent_id) {
fake_drive_service_->AddNewDirectoryWithResourceId(
resource_id, parent_id, title, drive::AddNewDirectoryOptions(),
base::Bind(&IgnoreDriveEntryResult));
CHECK(base::CreateDirectory(
drivefs_mount_point_.Append("root").Append(title)));
const base::FilePath root = drivefs_mount_point_.Append("root");
CHECK(base::CreateDirectory(root));
std::string data = "Can you see me?";
CHECK(base::WriteFile(root.Append("open_existing.txt"), data.data(),
data.size()));
CHECK(base::WriteFile(root.Append("open_existing1.txt"), data.data(),
data.size()));
CHECK(base::WriteFile(root.Append("open_existing2.txt"), data.data(),
data.size()));
CHECK(base::WriteFile(root.Append("save_existing.txt"), data.data(),
data.size()));
CHECK(base::CreateDirectory(root.Append("subdir")));
CHECK(base::WriteFile(root.Append("subdir").Append("open_existing.txt"),
data.data(), data.size()));
}
base::ScopedTempDir test_cache_root_;
base::ScopedTempDir drivefs_root_;
base::FilePath drivefs_mount_point_;
drive::FakeDriveService* fake_drive_service_ = nullptr;
std::unique_ptr<drive::FakeDriveFsHelper> fake_drivefs_helper_;
drive::DriveIntegrationService* integration_service_ = nullptr;
drive::DriveIntegrationServiceFactory::FactoryCallback
......
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