summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/api
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 /chrome/browser/extensions/api
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
Diffstat (limited to 'chrome/browser/extensions/api')
-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
3 files changed, 89 insertions, 4 deletions
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