summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-17 06:58:03 +0000
committerkinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-17 06:58:03 +0000
commit42b6c357ea6af9fb4c144ef937ffb0c7a907dbe2 (patch)
treec3609f91481be4711f5f53c1c6dbc009520e94eb
parent334d0b9f4fd414ae255303dca31403e97e0e8146 (diff)
downloadchromium_src-42b6c357ea6af9fb4c144ef937ffb0c7a907dbe2.zip
chromium_src-42b6c357ea6af9fb4c144ef937ffb0c7a907dbe2.tar.gz
chromium_src-42b6c357ea6af9fb4c144ef937ffb0c7a907dbe2.tar.bz2
Make chrome.fileSystem.chooseEntry work on Google Drive directories.
BUG=323097 TEST=added auto tests, and manually tested by samples apps for the API Review URL: https://codereview.chromium.org/137343008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245453 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/drive/file_system_util.cc23
-rw-r--r--chrome/browser/chromeos/drive/file_system_util.h6
-rw-r--r--chrome/browser/drive/fake_drive_service.cc3
-rw-r--r--chrome/browser/drive/fake_drive_service_unittest.cc8
-rw-r--r--chrome/browser/extensions/api/file_handlers/app_file_handler_util.cc24
-rw-r--r--chrome/browser/extensions/api/file_system/file_system_api.cc10
-rw-r--r--chrome/browser/extensions/api/file_system/file_system_apitest_chromeos.cc59
7 files changed, 123 insertions, 10 deletions
diff --git a/chrome/browser/chromeos/drive/file_system_util.cc b/chrome/browser/chromeos/drive/file_system_util.cc
index d539871..46eb9fa 100644
--- a/chrome/browser/chromeos/drive/file_system_util.cc
+++ b/chrome/browser/chromeos/drive/file_system_util.cc
@@ -109,6 +109,15 @@ DriveIntegrationService* GetIntegrationServiceByProfile(Profile* profile) {
return service;
}
+void CheckDirectoryExistsAfterGetResourceEntry(
+ const FileOperationCallback& callback,
+ FileError error,
+ scoped_ptr<ResourceEntry> entry) {
+ if (error == FILE_ERROR_OK && !entry->file_info().is_directory())
+ error = FILE_ERROR_NOT_A_DIRECTORY;
+ callback.Run(error);
+}
+
} // namespace
const base::FilePath& GetDriveGrandRootPath() {
@@ -343,6 +352,20 @@ void EnsureDirectoryExists(Profile* profile,
}
}
+void CheckDirectoryExists(Profile* profile,
+ const base::FilePath& directory,
+ const FileOperationCallback& callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(!callback.is_null());
+
+ FileSystemInterface* file_system = GetFileSystemByProfile(profile);
+ DCHECK(file_system);
+
+ file_system->GetResourceEntry(
+ ExtractDrivePath(directory),
+ base::Bind(&CheckDirectoryExistsAfterGetResourceEntry, callback));
+}
+
void EmptyFileOperationCallback(FileError error) {
}
diff --git a/chrome/browser/chromeos/drive/file_system_util.h b/chrome/browser/chromeos/drive/file_system_util.h
index 104a4eb..0fa527b 100644
--- a/chrome/browser/chromeos/drive/file_system_util.h
+++ b/chrome/browser/chromeos/drive/file_system_util.h
@@ -153,6 +153,12 @@ void PrepareWritableFileAndRun(Profile* profile,
const base::FilePath& path,
const PrepareWritableFileCallback& callback);
+// Checks whether a directory exists at the given Drive path |directory|.
+// Must be called from UI thread. The result will be called back to |callback|.
+void CheckDirectoryExists(Profile* profile,
+ const base::FilePath& directory,
+ const FileOperationCallback& callback);
+
// Ensures the existence of |directory| of '/special/drive/foo'. This will
// create |directory| and its ancestors if they don't exist. |callback| is
// invoked after making sure that |directory| exists. |callback| should
diff --git a/chrome/browser/drive/fake_drive_service.cc b/chrome/browser/drive/fake_drive_service.cc
index 6995f28..ffb53ae 100644
--- a/chrome/browser/drive/fake_drive_service.cc
+++ b/chrome/browser/drive/fake_drive_service.cc
@@ -781,8 +781,7 @@ CancelCallback FakeDriveService::CopyResource(
resource_id == current_resource_id) {
// Make a copy and set the new resource ID and the new title.
scoped_ptr<base::DictionaryValue> copied_entry(entry->DeepCopy());
- copied_entry->SetString("gd$resourceId.$t",
- resource_id + "_copied");
+ copied_entry->SetString("gd$resourceId.$t", GetNewResourceId());
copied_entry->SetString("title.$t", new_title);
// Reset parent directory.
diff --git a/chrome/browser/drive/fake_drive_service_unittest.cc b/chrome/browser/drive/fake_drive_service_unittest.cc
index aea6b03..5421a20 100644
--- a/chrome/browser/drive/fake_drive_service_unittest.cc
+++ b/chrome/browser/drive/fake_drive_service_unittest.cc
@@ -1118,7 +1118,7 @@ TEST_F(FakeDriveServiceTest, CopyResource) {
EXPECT_EQ(HTTP_SUCCESS, error);
ASSERT_TRUE(resource_entry);
// The copied entry should have the new resource ID and the title.
- EXPECT_EQ(kResourceId + "_copied", resource_entry->resource_id());
+ EXPECT_NE(kResourceId, resource_entry->resource_id());
EXPECT_EQ("new title", resource_entry->title());
EXPECT_EQ(base::Time::FromUTCExploded(kModifiedDate),
resource_entry->updated_time());
@@ -1168,7 +1168,7 @@ TEST_F(FakeDriveServiceTest, CopyResource_EmptyParentResourceId) {
EXPECT_EQ(HTTP_SUCCESS, error);
ASSERT_TRUE(resource_entry);
// The copied entry should have the new resource ID and the title.
- EXPECT_EQ(kResourceId + "_copied", resource_entry->resource_id());
+ EXPECT_NE(kResourceId, resource_entry->resource_id());
EXPECT_EQ("new title", resource_entry->title());
EXPECT_TRUE(HasParent(kResourceId, fake_service_.GetRootResourceId()));
// Should be incremented as a new hosted document was created.
@@ -1222,7 +1222,7 @@ TEST_F(FakeDriveServiceTest, UpdateResource) {
EXPECT_EQ(HTTP_SUCCESS, error);
ASSERT_TRUE(resource_entry);
- // The copied entry should have the new resource ID and the title.
+ // The updated entry should have the new title.
EXPECT_EQ(kResourceId, resource_entry->resource_id());
EXPECT_EQ("new title", resource_entry->title());
EXPECT_EQ(base::Time::FromUTCExploded(kModifiedDate),
@@ -1280,7 +1280,7 @@ TEST_F(FakeDriveServiceTest, UpdateResource_EmptyParentResourceId) {
EXPECT_EQ(HTTP_SUCCESS, error);
ASSERT_TRUE(resource_entry);
- // The copied entry should have the new resource ID and the title.
+ // The updated entry should have the new title.
EXPECT_EQ(kResourceId, resource_entry->resource_id());
EXPECT_EQ("new title", resource_entry->title());
EXPECT_TRUE(HasParent(kResourceId, "fake_root"));
diff --git a/chrome/browser/extensions/api/file_handlers/app_file_handler_util.cc b/chrome/browser/extensions/api/file_handlers/app_file_handler_util.cc
index d8e3480..3fa01da 100644
--- a/chrome/browser/extensions/api/file_handlers/app_file_handler_util.cc
+++ b/chrome/browser/extensions/api/file_handlers/app_file_handler_util.cc
@@ -124,6 +124,8 @@ class WritableFileChecker
void CheckRemoteWritableFile(const base::FilePath& remote_path,
drive::FileError error,
const base::FilePath& local_path);
+ void RemoteCheckDone(const base::FilePath& remote_path,
+ drive::FileError error);
#endif
const std::vector<base::FilePath> paths_;
@@ -156,10 +158,18 @@ void WritableFileChecker::Check() {
it != paths_.end();
++it) {
DCHECK(drive::util::IsUnderDriveMountPoint(*it));
- drive::util::PrepareWritableFileAndRun(
- profile_,
- *it,
- base::Bind(&WritableFileChecker::CheckRemoteWritableFile, this, *it));
+ if (is_directory_) {
+ drive::util::CheckDirectoryExists(
+ profile_,
+ *it,
+ base::Bind(&WritableFileChecker::RemoteCheckDone, this, *it));
+ } else {
+ drive::util::PrepareWritableFileAndRun(
+ profile_,
+ *it,
+ base::Bind(&WritableFileChecker::CheckRemoteWritableFile, this,
+ *it));
+ }
}
return;
}
@@ -215,6 +225,12 @@ void WritableFileChecker::CheckRemoteWritableFile(
const base::FilePath& remote_path,
drive::FileError error,
const base::FilePath& /* local_path */) {
+ RemoteCheckDone(remote_path, error);
+}
+
+void WritableFileChecker::RemoteCheckDone(
+ const base::FilePath& remote_path,
+ drive::FileError error) {
if (error == drive::FILE_ERROR_OK) {
content::BrowserThread::PostTask(
content::BrowserThread::UI,
diff --git a/chrome/browser/extensions/api/file_system/file_system_api.cc b/chrome/browser/extensions/api/file_system/file_system_api.cc
index 0e9c267..6ad9a61f 100644
--- a/chrome/browser/extensions/api/file_system/file_system_api.cc
+++ b/chrome/browser/extensions/api/file_system/file_system_api.cc
@@ -49,6 +49,10 @@
#include "base/mac/foundation_util.h"
#endif
+#if defined(OS_CHROMEOS)
+#include "chrome/browser/chromeos/drive/file_system_util.h"
+#endif
+
using apps::SavedFileEntry;
using apps::SavedFilesService;
using apps::ShellWindow;
@@ -698,7 +702,13 @@ void FileSystemChooseEntryFunction::ConfirmDirectoryAccessOnFileThread(
const std::vector<base::FilePath>& paths,
content::WebContents* web_contents) {
DCHECK_EQ(paths.size(), 1u);
+#if defined(OS_CHROMEOS)
+ const base::FilePath path =
+ drive::util::IsUnderDriveMountPoint(paths[0]) ? paths[0] :
+ base::MakeAbsoluteFilePath(paths[0]);
+#else
const base::FilePath path = base::MakeAbsoluteFilePath(paths[0]);
+#endif
if (path.empty()) {
content::BrowserThread::PostTask(
content::BrowserThread::UI,
diff --git a/chrome/browser/extensions/api/file_system/file_system_apitest_chromeos.cc b/chrome/browser/extensions/api/file_system/file_system_apitest_chromeos.cc
index 16abe55..400b27e 100644
--- a/chrome/browser/extensions/api/file_system/file_system_apitest_chromeos.cc
+++ b/chrome/browser/extensions/api/file_system/file_system_apitest_chromeos.cc
@@ -77,6 +77,9 @@ class FileSystemApiTestForDrive : public PlatformAppBrowserTest {
void SetUpTestFileHierarchy() {
const std::string root = fake_drive_service_->GetRootResourceId();
ASSERT_TRUE(AddTestFile("open_existing.txt", "Can you see me?", root));
+ const std::string subdir = AddTestDirectory("subdir", root);
+ ASSERT_FALSE(subdir.empty());
+ ASSERT_TRUE(AddTestFile("open_existing.txt", "Can you see me?", subdir));
}
bool AddTestFile(const std::string& title,
@@ -92,6 +95,19 @@ class FileSystemApiTestForDrive : public PlatformAppBrowserTest {
return error == google_apis::HTTP_CREATED && resource_entry;
}
+ std::string AddTestDirectory(const std::string& title,
+ const std::string& parent_id) {
+ scoped_ptr<google_apis::ResourceEntry> resource_entry;
+ google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
+ fake_drive_service_->AddNewDirectory(
+ parent_id, title,
+ google_apis::test_util::CreateCopyResultCallback(&error,
+ &resource_entry));
+ content::RunAllPendingInMessageLoop();
+ return error == google_apis::HTTP_CREATED && resource_entry ?
+ resource_entry->resource_id() : "";
+ }
+
base::ScopedTempDir test_cache_root_;
drive::FakeDriveService* fake_drive_service_;
drive::DriveIntegrationService* integration_service_;
@@ -121,4 +137,47 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTestForDrive,
"api_test/file_system/open_existing_with_write")) << message_;
}
+IN_PROC_BROWSER_TEST_F(FileSystemApiTestForDrive,
+ FileSystemApiOpenDirectoryTest) {
+ base::FilePath test_directory =
+ drive::util::GetDriveMountPointPath().AppendASCII("root/subdir");
+ FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
+ &test_directory);
+ ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory"))
+ << message_;
+}
+
+IN_PROC_BROWSER_TEST_F(FileSystemApiTestForDrive,
+ FileSystemApiOpenDirectoryWithWriteTest) {
+ base::FilePath test_directory =
+ drive::util::GetDriveMountPointPath().AppendASCII("root/subdir");
+ FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
+ &test_directory);
+ ASSERT_TRUE(
+ RunPlatformAppTest("api_test/file_system/open_directory_with_write"))
+ << message_;
+}
+
+IN_PROC_BROWSER_TEST_F(FileSystemApiTestForDrive,
+ FileSystemApiOpenDirectoryWithoutPermissionTest) {
+ base::FilePath test_directory =
+ drive::util::GetDriveMountPointPath().AppendASCII("root/subdir");
+ FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
+ &test_directory);
+ ASSERT_TRUE(RunPlatformAppTest(
+ "api_test/file_system/open_directory_without_permission"))
+ << message_;
+}
+
+IN_PROC_BROWSER_TEST_F(FileSystemApiTestForDrive,
+ FileSystemApiOpenDirectoryWithOnlyWritePermissionTest) {
+ base::FilePath test_directory =
+ drive::util::GetDriveMountPointPath().AppendASCII("root/subdir");
+ FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
+ &test_directory);
+ ASSERT_TRUE(RunPlatformAppTest(
+ "api_test/file_system/open_directory_with_only_write"))
+ << message_;
+}
+
} // namespace extensions