| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/file_system/file_system_api.h" | 5 #include "chrome/browser/extensions/api/file_system/file_system_api.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "chrome/browser/apps/app_browsertest_util.h" | 14 #include "chrome/browser/apps/app_browsertest_util.h" |
| 15 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 15 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
| 16 #include "chrome/browser/chromeos/drive/file_system_util.h" | 16 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 17 #include "chrome/browser/chromeos/file_manager/volume_manager.h" | 17 #include "chrome/browser/chromeos/file_manager/volume_manager.h" |
| 18 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 18 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
| 19 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 19 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 20 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 20 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 21 #include "chrome/browser/extensions/component_loader.h" | 21 #include "chrome/browser/extensions/component_loader.h" |
| 22 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
| 23 #include "chrome/common/extensions/api/file_system.h" | 23 #include "chrome/common/extensions/api/file_system.h" |
| 24 #include "components/drive/chromeos/file_system_interface.h" | 24 #include "components/drive/chromeos/file_system_interface.h" |
| 25 #include "components/drive/service/fake_drive_service.h" | 25 #include "components/drive/service/fake_drive_service.h" |
| 26 #include "content/public/test/test_utils.h" | 26 #include "content/public/test/test_utils.h" |
| 27 #include "extensions/browser/event_router.h" | 27 #include "extensions/browser/event_router.h" |
| 28 #include "google_apis/drive/base_requests.h" |
| 28 #include "google_apis/drive/drive_api_parser.h" | 29 #include "google_apis/drive/drive_api_parser.h" |
| 29 #include "google_apis/drive/test_util.h" | 30 #include "google_apis/drive/test_util.h" |
| 30 #include "storage/browser/fileapi/external_mount_points.h" | 31 #include "storage/browser/fileapi/external_mount_points.h" |
| 31 #include "ui/base/ui_base_types.h" | 32 #include "ui/base/ui_base_types.h" |
| 32 | 33 |
| 33 using file_manager::VolumeManager; | 34 using file_manager::VolumeManager; |
| 34 | 35 |
| 35 namespace extensions { | 36 namespace extensions { |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| 38 // Mount point names for chrome.fileSystem.requestFileSystem() tests. | 39 // Mount point names for chrome.fileSystem.requestFileSystem() tests. |
| 39 const char kWritableMountPointName[] = "writable"; | 40 const char kWritableMountPointName[] = "writable"; |
| 40 const char kReadOnlyMountPointName[] = "read-only"; | 41 const char kReadOnlyMountPointName[] = "read-only"; |
| 41 | 42 |
| 42 // Child directory created in each of the mount points. | 43 // Child directory created in each of the mount points. |
| 43 const char kChildDirectory[] = "child-dir"; | 44 const char kChildDirectory[] = "child-dir"; |
| 44 | 45 |
| 45 // ID of a testing extension. | 46 // ID of a testing extension. |
| 46 const char kTestingExtensionId[] = "pkplfbidichfdicaijlchgnapepdginl"; | 47 const char kTestingExtensionId[] = "pkplfbidichfdicaijlchgnapepdginl"; |
| 47 | 48 |
| 49 void IgnoreDriveEntryResult(google_apis::DriveApiErrorCode error, |
| 50 std::unique_ptr<google_apis::FileResource> entry) {} |
| 51 |
| 48 } // namespace | 52 } // namespace |
| 49 | 53 |
| 50 // Skips the user consent dialog for chrome.fileSystem.requestFileSystem() and | 54 // Skips the user consent dialog for chrome.fileSystem.requestFileSystem() and |
| 51 // simulates clicking of the specified dialog button. | 55 // simulates clicking of the specified dialog button. |
| 52 class ScopedSkipRequestFileSystemDialog { | 56 class ScopedSkipRequestFileSystemDialog { |
| 53 public: | 57 public: |
| 54 explicit ScopedSkipRequestFileSystemDialog(ui::DialogButton button) { | 58 explicit ScopedSkipRequestFileSystemDialog(ui::DialogButton button) { |
| 55 file_system_api::ConsentProviderDelegate::SetAutoDialogButtonForTest( | 59 file_system_api::ConsentProviderDelegate::SetAutoDialogButtonForTest( |
| 56 button); | 60 button); |
| 57 } | 61 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 base::Closure callback_; | 100 base::Closure callback_; |
| 97 EventRouter* const event_router_; | 101 EventRouter* const event_router_; |
| 98 | 102 |
| 99 DISALLOW_COPY_AND_ASSIGN(ScopedAddListenerObserver); | 103 DISALLOW_COPY_AND_ASSIGN(ScopedAddListenerObserver); |
| 100 }; | 104 }; |
| 101 | 105 |
| 102 // This class contains chrome.filesystem API test specific to Chrome OS, namely, | 106 // This class contains chrome.filesystem API test specific to Chrome OS, namely, |
| 103 // the integrated Google Drive support. | 107 // the integrated Google Drive support. |
| 104 class FileSystemApiTestForDrive : public PlatformAppBrowserTest { | 108 class FileSystemApiTestForDrive : public PlatformAppBrowserTest { |
| 105 public: | 109 public: |
| 106 FileSystemApiTestForDrive() | 110 FileSystemApiTestForDrive() {} |
| 107 : fake_drive_service_(NULL), | |
| 108 integration_service_(NULL) { | |
| 109 } | |
| 110 | 111 |
| 111 // Sets up fake Drive service for tests (this has to be injected before the | 112 // Sets up fake Drive service for tests (this has to be injected before the |
| 112 // real DriveIntegrationService instance is created.) | 113 // real DriveIntegrationService instance is created.) |
| 113 void SetUpInProcessBrowserTestFixture() override { | 114 void SetUpInProcessBrowserTestFixture() override { |
| 114 PlatformAppBrowserTest::SetUpInProcessBrowserTestFixture(); | 115 PlatformAppBrowserTest::SetUpInProcessBrowserTestFixture(); |
| 115 extensions::ComponentLoader::EnableBackgroundExtensionsForTesting(); | 116 extensions::ComponentLoader::EnableBackgroundExtensionsForTesting(); |
| 116 | 117 |
| 117 ASSERT_TRUE(test_cache_root_.CreateUniqueTempDir()); | 118 ASSERT_TRUE(test_cache_root_.CreateUniqueTempDir()); |
| 118 | 119 |
| 119 create_drive_integration_service_ = | 120 create_drive_integration_service_ = |
| (...skipping 21 matching lines...) Expand all Loading... |
| 141 void TearDown() override { | 142 void TearDown() override { |
| 142 FileSystemChooseEntryFunction::StopSkippingPickerForTest(); | 143 FileSystemChooseEntryFunction::StopSkippingPickerForTest(); |
| 143 PlatformAppBrowserTest::TearDown(); | 144 PlatformAppBrowserTest::TearDown(); |
| 144 }; | 145 }; |
| 145 | 146 |
| 146 private: | 147 private: |
| 147 drive::DriveIntegrationService* CreateDriveIntegrationService( | 148 drive::DriveIntegrationService* CreateDriveIntegrationService( |
| 148 Profile* profile) { | 149 Profile* profile) { |
| 149 // Ignore signin profile. | 150 // Ignore signin profile. |
| 150 if (profile->GetPath() == chromeos::ProfileHelper::GetSigninProfileDir()) | 151 if (profile->GetPath() == chromeos::ProfileHelper::GetSigninProfileDir()) |
| 151 return NULL; | 152 return nullptr; |
| 152 | 153 |
| 153 // FileSystemApiTestForDrive doesn't expect that several user profiles could | 154 // FileSystemApiTestForDrive doesn't expect that several user profiles could |
| 154 // exist simultaneously. | 155 // exist simultaneously. |
| 155 DCHECK(fake_drive_service_ == NULL); | 156 DCHECK(!fake_drive_service_); |
| 156 fake_drive_service_ = new drive::FakeDriveService; | 157 fake_drive_service_ = new drive::FakeDriveService; |
| 157 fake_drive_service_->LoadAppListForDriveApi("drive/applist.json"); | 158 fake_drive_service_->LoadAppListForDriveApi("drive/applist.json"); |
| 158 | 159 |
| 159 SetUpTestFileHierarchy(); | 160 SetUpTestFileHierarchy(); |
| 160 | 161 |
| 161 integration_service_ = new drive::DriveIntegrationService( | 162 integration_service_ = new drive::DriveIntegrationService( |
| 162 profile, NULL, fake_drive_service_, std::string(), | 163 profile, nullptr, fake_drive_service_, std::string(), |
| 163 test_cache_root_.GetPath(), NULL); | 164 test_cache_root_.GetPath(), nullptr); |
| 164 return integration_service_; | 165 return integration_service_; |
| 165 } | 166 } |
| 166 | 167 |
| 167 void SetUpTestFileHierarchy() { | 168 void SetUpTestFileHierarchy() { |
| 168 const std::string root = fake_drive_service_->GetRootResourceId(); | 169 const std::string root = fake_drive_service_->GetRootResourceId(); |
| 169 ASSERT_TRUE(AddTestFile("open_existing.txt", "Can you see me?", root)); | 170 AddTestFile("open_existing.txt", "Can you see me?", root); |
| 170 ASSERT_TRUE(AddTestFile("open_existing1.txt", "Can you see me?", root)); | 171 AddTestFile("open_existing1.txt", "Can you see me?", root); |
| 171 ASSERT_TRUE(AddTestFile("open_existing2.txt", "Can you see me?", root)); | 172 AddTestFile("open_existing2.txt", "Can you see me?", root); |
| 172 ASSERT_TRUE(AddTestFile("save_existing.txt", "Can you see me?", root)); | 173 AddTestFile("save_existing.txt", "Can you see me?", root); |
| 173 const std::string subdir = AddTestDirectory("subdir", root); | 174 |
| 174 ASSERT_FALSE(subdir.empty()); | 175 const char kSubdirResourceId[] = "subdir_resource_id"; |
| 175 ASSERT_TRUE(AddTestFile("open_existing.txt", "Can you see me?", subdir)); | 176 AddTestDirectory(kSubdirResourceId, "subdir", root); |
| 177 AddTestFile("open_existing.txt", "Can you see me?", kSubdirResourceId); |
| 176 } | 178 } |
| 177 | 179 |
| 178 bool AddTestFile(const std::string& title, | 180 void AddTestFile(const std::string& title, |
| 179 const std::string& data, | 181 const std::string& data, |
| 180 const std::string& parent_id) { | 182 const std::string& parent_id) { |
| 181 std::unique_ptr<google_apis::FileResource> entry; | 183 fake_drive_service_->AddNewFile("text/plain", data, parent_id, title, false, |
| 182 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; | 184 base::Bind(&IgnoreDriveEntryResult)); |
| 183 fake_drive_service_->AddNewFile( | |
| 184 "text/plain", data, parent_id, title, false, | |
| 185 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | |
| 186 content::RunAllPendingInMessageLoop(); | |
| 187 return error == google_apis::HTTP_CREATED && entry; | |
| 188 } | 185 } |
| 189 | 186 |
| 190 std::string AddTestDirectory(const std::string& title, | 187 void AddTestDirectory(const std::string& resource_id, |
| 191 const std::string& parent_id) { | 188 const std::string& title, |
| 192 std::unique_ptr<google_apis::FileResource> entry; | 189 const std::string& parent_id) { |
| 193 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; | 190 fake_drive_service_->AddNewDirectoryWithResourceId( |
| 194 fake_drive_service_->AddNewDirectory( | 191 resource_id, parent_id, title, drive::AddNewDirectoryOptions(), |
| 195 parent_id, title, drive::AddNewDirectoryOptions(), | 192 base::Bind(&IgnoreDriveEntryResult)); |
| 196 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | |
| 197 content::RunAllPendingInMessageLoop(); | |
| 198 return error == google_apis::HTTP_CREATED && entry ? entry->file_id() : ""; | |
| 199 } | 193 } |
| 200 | 194 |
| 201 base::ScopedTempDir test_cache_root_; | 195 base::ScopedTempDir test_cache_root_; |
| 202 drive::FakeDriveService* fake_drive_service_; | 196 drive::FakeDriveService* fake_drive_service_ = nullptr; |
| 203 drive::DriveIntegrationService* integration_service_; | 197 drive::DriveIntegrationService* integration_service_ = nullptr; |
| 204 drive::DriveIntegrationServiceFactory::FactoryCallback | 198 drive::DriveIntegrationServiceFactory::FactoryCallback |
| 205 create_drive_integration_service_; | 199 create_drive_integration_service_; |
| 206 std::unique_ptr<drive::DriveIntegrationServiceFactory::ScopedFactoryForTest> | 200 std::unique_ptr<drive::DriveIntegrationServiceFactory::ScopedFactoryForTest> |
| 207 service_factory_for_test_; | 201 service_factory_for_test_; |
| 208 }; | 202 }; |
| 209 | 203 |
| 210 // This class contains chrome.filesystem.requestFileSystem API tests. | 204 // This class contains chrome.filesystem.requestFileSystem API tests. |
| 211 class FileSystemApiTestForRequestFileSystem : public PlatformAppBrowserTest { | 205 class FileSystemApiTestForRequestFileSystem : public PlatformAppBrowserTest { |
| 212 public: | 206 public: |
| 213 FileSystemApiTestForRequestFileSystem() : fake_user_manager_(nullptr) {} | 207 FileSystemApiTestForRequestFileSystem() : fake_user_manager_(nullptr) {} |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 profile(), extensions::api::file_system::OnVolumeListChanged::kEventName, | 487 profile(), extensions::api::file_system::OnVolumeListChanged::kEventName, |
| 494 kTestingExtensionId, | 488 kTestingExtensionId, |
| 495 base::Bind(&FileSystemApiTestForRequestFileSystem::MountFakeVolume, | 489 base::Bind(&FileSystemApiTestForRequestFileSystem::MountFakeVolume, |
| 496 base::Unretained(this))); | 490 base::Unretained(this))); |
| 497 | 491 |
| 498 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/on_volume_list_changed")) | 492 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/on_volume_list_changed")) |
| 499 << message_; | 493 << message_; |
| 500 } | 494 } |
| 501 | 495 |
| 502 } // namespace extensions | 496 } // namespace extensions |
| OLD | NEW |