This source file includes following definitions.
- InitializeLocalFileSystem
- page_closed_
- WaitUntilLoaded
- WaitUntilClosed
- SetUp
- SetUpOnMainThread
- RunFileSystemExtensionApiTest
- InitTestFileSystem
- AddTestMountPoint
- InitTestFileSystem
- AddTestMountPoint
- InitTestFileSystem
- AddTestMountPoint
- CreateDriveIntegrationService
- SetUpOnMainThread
- InitTestFileSystem
- AddTestMountPoint
- CreateDriveIntegrationService
- AddTestHostedDocuments
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include "base/bind.h"
#include "base/file_util.h"
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/drive/drive_integration_service.h"
#include "chrome/browser/chromeos/drive/test_util.h"
#include "chrome/browser/chromeos/file_manager/drive_test_util.h"
#include "chrome/browser/chromeos/file_manager/volume_manager.h"
#include "chrome/browser/drive/fake_drive_service.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_constants.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/notification_service.h"
#include "content/public/test/test_utils.h"
#include "google_apis/drive/test_util.h"
#include "webkit/browser/fileapi/external_mount_points.h"
using drive::DriveIntegrationServiceFactory;
using extensions::Extension;
namespace file_manager {
namespace {
const char kLocalMountPointName[] = "local";
const char kRestrictedMountPointName[] = "restricted";
const char kTestFileContent[] = "This is some test content.";
const char kTestRootFeed[] =
"gdata/remote_file_system_apitest_root_feed.json";
bool InitializeLocalFileSystem(std::string mount_point_name,
base::ScopedTempDir* tmp_dir,
base::FilePath* mount_point_dir) {
if (!tmp_dir->CreateUniqueTempDir())
return false;
*mount_point_dir = tmp_dir->path().AppendASCII(mount_point_name);
if (!base::CreateDirectory(*mount_point_dir))
return false;
base::FilePath test_dir = mount_point_dir->AppendASCII("test_dir");
if (!base::CreateDirectory(test_dir))
return false;
base::FilePath test_subdir = test_dir.AppendASCII("empty_test_dir");
if (!base::CreateDirectory(test_subdir))
return false;
test_subdir = test_dir.AppendASCII("subdir");
if (!base::CreateDirectory(test_subdir))
return false;
base::FilePath test_file = test_dir.AppendASCII("test_file.xul");
if (!google_apis::test_util::WriteStringToFile(test_file, kTestFileContent))
return false;
test_file = test_dir.AppendASCII("test_file.xul.foo");
if (!google_apis::test_util::WriteStringToFile(test_file, kTestFileContent))
return false;
test_file = test_dir.AppendASCII("test_file.tiff");
if (!google_apis::test_util::WriteStringToFile(test_file, kTestFileContent))
return false;
test_file = test_dir.AppendASCII("test_file.tiff.foo");
if (!google_apis::test_util::WriteStringToFile(test_file, kTestFileContent))
return false;
test_file = test_dir.AppendASCII("empty_test_file.foo");
if (!google_apis::test_util::WriteStringToFile(test_file, ""))
return false;
return true;
}
class BackgroundObserver {
public:
BackgroundObserver()
: page_created_(chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY,
content::NotificationService::AllSources()),
page_closed_(chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
content::NotificationService::AllSources()) {
}
void WaitUntilLoaded() {
page_created_.Wait();
}
void WaitUntilClosed() {
page_closed_.Wait();
}
private:
content::WindowedNotificationObserver page_created_;
content::WindowedNotificationObserver page_closed_;
};
class FileSystemExtensionApiTestBase : public ExtensionApiTest {
public:
enum Flags {
FLAGS_NONE = 0,
FLAGS_USE_FILE_HANDLER = 1 << 1,
FLAGS_LAZY_FILE_HANDLER = 1 << 2
};
FileSystemExtensionApiTestBase() {}
virtual ~FileSystemExtensionApiTestBase() {}
virtual void SetUp() OVERRIDE {
InitTestFileSystem();
ExtensionApiTest::SetUp();
}
virtual void SetUpOnMainThread() OVERRIDE {
AddTestMountPoint();
ExtensionApiTest::SetUpOnMainThread();
}
bool RunFileSystemExtensionApiTest(
const std::string& filebrowser_path,
const base::FilePath::CharType* filebrowser_manifest,
const std::string& filehandler_path,
int flags) {
if (flags & FLAGS_USE_FILE_HANDLER) {
if (filehandler_path.empty()) {
message_ = "Missing file handler path.";
return false;
}
BackgroundObserver page_complete;
const Extension* file_handler =
LoadExtension(test_data_dir_.AppendASCII(filehandler_path));
if (!file_handler)
return false;
if (flags & FLAGS_LAZY_FILE_HANDLER) {
page_complete.WaitUntilClosed();
} else {
page_complete.WaitUntilLoaded();
}
}
ResultCatcher catcher;
const Extension* file_browser = LoadExtensionAsComponentWithManifest(
test_data_dir_.AppendASCII(filebrowser_path),
filebrowser_manifest);
if (!file_browser)
return false;
if (!catcher.GetNextResult()) {
message_ = catcher.message();
return false;
}
return true;
}
protected:
virtual void InitTestFileSystem() = 0;
virtual void AddTestMountPoint() = 0;
};
class LocalFileSystemExtensionApiTest : public FileSystemExtensionApiTestBase {
public:
LocalFileSystemExtensionApiTest() {}
virtual ~LocalFileSystemExtensionApiTest() {}
virtual void InitTestFileSystem() OVERRIDE {
ASSERT_TRUE(InitializeLocalFileSystem(
kLocalMountPointName, &tmp_dir_, &mount_point_dir_))
<< "Failed to initialize file system.";
}
virtual void AddTestMountPoint() OVERRIDE {
EXPECT_TRUE(content::BrowserContext::GetMountPoints(browser()->profile())->
RegisterFileSystem(kLocalMountPointName,
fileapi::kFileSystemTypeNativeLocal,
fileapi::FileSystemMountOption(),
mount_point_dir_));
VolumeManager::Get(browser()->profile())->AddVolumeInfoForTesting(
mount_point_dir_, VOLUME_TYPE_TESTING, chromeos::DEVICE_TYPE_UNKNOWN);
}
private:
base::ScopedTempDir tmp_dir_;
base::FilePath mount_point_dir_;
};
class RestrictedFileSystemExtensionApiTest
: public FileSystemExtensionApiTestBase {
public:
RestrictedFileSystemExtensionApiTest() {}
virtual ~RestrictedFileSystemExtensionApiTest() {}
virtual void InitTestFileSystem() OVERRIDE {
ASSERT_TRUE(InitializeLocalFileSystem(
kRestrictedMountPointName, &tmp_dir_, &mount_point_dir_))
<< "Failed to initialize file system.";
}
virtual void AddTestMountPoint() OVERRIDE {
EXPECT_TRUE(content::BrowserContext::GetMountPoints(browser()->profile())->
RegisterFileSystem(kRestrictedMountPointName,
fileapi::kFileSystemTypeRestrictedNativeLocal,
fileapi::FileSystemMountOption(),
mount_point_dir_));
VolumeManager::Get(browser()->profile())->AddVolumeInfoForTesting(
mount_point_dir_, VOLUME_TYPE_TESTING, chromeos::DEVICE_TYPE_UNKNOWN);
}
private:
base::ScopedTempDir tmp_dir_;
base::FilePath mount_point_dir_;
};
class DriveFileSystemExtensionApiTest : public FileSystemExtensionApiTestBase {
public:
DriveFileSystemExtensionApiTest() : fake_drive_service_(NULL) {}
virtual ~DriveFileSystemExtensionApiTest() {}
virtual void InitTestFileSystem() OVERRIDE {
ASSERT_TRUE(test_cache_root_.CreateUniqueTempDir());
create_drive_integration_service_ = base::Bind(
&DriveFileSystemExtensionApiTest::CreateDriveIntegrationService,
base::Unretained(this));
service_factory_for_test_.reset(
new DriveIntegrationServiceFactory::ScopedFactoryForTest(
&create_drive_integration_service_));
}
virtual void AddTestMountPoint() OVERRIDE {
test_util::WaitUntilDriveMountPointIsAdded(browser()->profile());
}
protected:
drive::DriveIntegrationService* CreateDriveIntegrationService(
Profile* profile) {
fake_drive_service_ = new drive::FakeDriveService;
fake_drive_service_->LoadResourceListForWapi(kTestRootFeed);
fake_drive_service_->LoadAppListForDriveApi("drive/applist.json");
return new drive::DriveIntegrationService(
profile, NULL,
fake_drive_service_, "drive", test_cache_root_.path(), NULL);
}
base::ScopedTempDir test_cache_root_;
drive::FakeDriveService* fake_drive_service_;
DriveIntegrationServiceFactory::FactoryCallback
create_drive_integration_service_;
scoped_ptr<DriveIntegrationServiceFactory::ScopedFactoryForTest>
service_factory_for_test_;
};
class MultiProfileDriveFileSystemExtensionApiTest :
public FileSystemExtensionApiTestBase {
public:
MultiProfileDriveFileSystemExtensionApiTest() : second_profile(NULL) {}
virtual void SetUpOnMainThread() OVERRIDE {
base::FilePath profile_dir;
base::CreateNewTempDirectory(base::FilePath::StringType(), &profile_dir);
profile_dir = profile_dir.AppendASCII(
std::string(chrome::kProfileDirPrefix) + "fileBrowserApiTestProfile2");
second_profile =
g_browser_process->profile_manager()->GetProfile(profile_dir);
FileSystemExtensionApiTestBase::SetUpOnMainThread();
}
virtual void InitTestFileSystem() OVERRIDE {
create_drive_integration_service_ = base::Bind(
&MultiProfileDriveFileSystemExtensionApiTest::
CreateDriveIntegrationService,
base::Unretained(this));
service_factory_for_test_.reset(
new DriveIntegrationServiceFactory::ScopedFactoryForTest(
&create_drive_integration_service_));
}
virtual void AddTestMountPoint() OVERRIDE {
test_util::WaitUntilDriveMountPointIsAdded(browser()->profile());
test_util::WaitUntilDriveMountPointIsAdded(second_profile);
}
protected:
drive::DriveIntegrationService* CreateDriveIntegrationService(
Profile* profile) {
base::FilePath cache_dir;
base::CreateNewTempDirectory(base::FilePath::StringType(), &cache_dir);
drive::FakeDriveService* const fake_drive_service =
new drive::FakeDriveService;
fake_drive_service->LoadResourceListForWapi(kTestRootFeed);
fake_drive_service->LoadAppListForDriveApi("drive/applist.json");
return new drive::DriveIntegrationService(
profile, NULL, fake_drive_service, std::string(), cache_dir, NULL);
}
bool AddTestHostedDocuments() {
const char kResourceId[] = "document:unique-id-for-multiprofile-copy-test";
drive::FakeDriveService* const main_service =
static_cast<drive::FakeDriveService*>(
drive::util::GetDriveServiceByProfile(browser()->profile()));
drive::FakeDriveService* const sub_service =
static_cast<drive::FakeDriveService*>(
drive::util::GetDriveServiceByProfile(second_profile));
google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
scoped_ptr<google_apis::ResourceEntry> entry;
sub_service->AddNewFileWithResourceId(
kResourceId,
"application/vnd.google-apps.document", "",
"folder:1_folder_resource_id", "hosted_doc", true,
google_apis::test_util::CreateCopyResultCallback(&error, &entry));
drive::test_util::RunBlockingPoolTask();
if (error != google_apis::HTTP_CREATED)
return false;
error = google_apis::GDATA_OTHER_ERROR;
main_service->AddNewFileWithResourceId(
kResourceId,
"application/vnd.google-apps.document", "", "", "hosted_doc", true,
google_apis::test_util::CreateCopyResultCallback(&error, &entry));
drive::test_util::RunBlockingPoolTask();
return (error == google_apis::HTTP_CREATED);
}
DriveIntegrationServiceFactory::FactoryCallback
create_drive_integration_service_;
scoped_ptr<DriveIntegrationServiceFactory::ScopedFactoryForTest>
service_factory_for_test_;
Profile* second_profile;
};
IN_PROC_BROWSER_TEST_F(LocalFileSystemExtensionApiTest, FileSystemOperations) {
EXPECT_TRUE(RunFileSystemExtensionApiTest(
"file_browser/filesystem_operations_test",
FILE_PATH_LITERAL("manifest.json"),
"",
FLAGS_NONE)) << message_;
}
IN_PROC_BROWSER_TEST_F(LocalFileSystemExtensionApiTest, FileWatch) {
EXPECT_TRUE(RunFileSystemExtensionApiTest(
"file_browser/file_watcher_test",
FILE_PATH_LITERAL("manifest.json"),
"",
FLAGS_NONE)) << message_;
}
IN_PROC_BROWSER_TEST_F(LocalFileSystemExtensionApiTest, FileBrowserHandlers) {
EXPECT_TRUE(RunFileSystemExtensionApiTest(
"file_browser/handler_test_runner",
FILE_PATH_LITERAL("manifest.json"),
"file_browser/file_browser_handler",
FLAGS_USE_FILE_HANDLER)) << message_;
}
IN_PROC_BROWSER_TEST_F(LocalFileSystemExtensionApiTest,
FileBrowserHandlersLazy) {
EXPECT_TRUE(RunFileSystemExtensionApiTest(
"file_browser/handler_test_runner",
FILE_PATH_LITERAL("manifest.json"),
"file_browser/file_browser_handler_lazy",
FLAGS_USE_FILE_HANDLER | FLAGS_LAZY_FILE_HANDLER)) << message_;
}
IN_PROC_BROWSER_TEST_F(LocalFileSystemExtensionApiTest, AppFileHandler) {
EXPECT_TRUE(RunFileSystemExtensionApiTest(
"file_browser/handler_test_runner",
FILE_PATH_LITERAL("manifest.json"),
"file_browser/app_file_handler",
FLAGS_USE_FILE_HANDLER)) << message_;
}
IN_PROC_BROWSER_TEST_F(RestrictedFileSystemExtensionApiTest,
FileSystemOperations) {
EXPECT_TRUE(RunFileSystemExtensionApiTest(
"file_browser/filesystem_operations_test",
FILE_PATH_LITERAL("manifest.json"),
"",
FLAGS_NONE)) << message_;
}
IN_PROC_BROWSER_TEST_F(DriveFileSystemExtensionApiTest, FileSystemOperations) {
EXPECT_TRUE(RunFileSystemExtensionApiTest(
"file_browser/filesystem_operations_test",
FILE_PATH_LITERAL("manifest.json"),
"",
FLAGS_NONE)) << message_;
}
IN_PROC_BROWSER_TEST_F(DriveFileSystemExtensionApiTest, FileWatch) {
EXPECT_TRUE(RunFileSystemExtensionApiTest(
"file_browser/file_watcher_test",
FILE_PATH_LITERAL("manifest.json"),
"",
FLAGS_NONE)) << message_;
}
IN_PROC_BROWSER_TEST_F(DriveFileSystemExtensionApiTest, FileBrowserHandlers) {
EXPECT_TRUE(RunFileSystemExtensionApiTest(
"file_browser/handler_test_runner",
FILE_PATH_LITERAL("manifest.json"),
"file_browser/file_browser_handler",
FLAGS_USE_FILE_HANDLER)) << message_;
}
IN_PROC_BROWSER_TEST_F(DriveFileSystemExtensionApiTest, Search) {
fake_drive_service_->set_default_max_results(1);
EXPECT_TRUE(RunFileSystemExtensionApiTest(
"file_browser/drive_search_test",
FILE_PATH_LITERAL("manifest.json"),
"",
FLAGS_NONE)) << message_;
}
IN_PROC_BROWSER_TEST_F(DriveFileSystemExtensionApiTest, AppFileHandler) {
EXPECT_TRUE(RunFileSystemExtensionApiTest(
"file_browser/handler_test_runner",
FILE_PATH_LITERAL("manifest.json"),
"file_browser/app_file_handler",
FLAGS_USE_FILE_HANDLER)) << message_;
}
IN_PROC_BROWSER_TEST_F(MultiProfileDriveFileSystemExtensionApiTest,
CrossProfileCopy) {
ASSERT_TRUE(AddTestHostedDocuments());
EXPECT_TRUE(RunFileSystemExtensionApiTest(
"file_browser/multi_profile_copy",
FILE_PATH_LITERAL("manifest.json"),
"",
FLAGS_NONE)) << message_;
}
}
}