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" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 service_factory_for_test_.reset( | 122 service_factory_for_test_.reset( |
123 new drive::DriveIntegrationServiceFactory::ScopedFactoryForTest( | 123 new drive::DriveIntegrationServiceFactory::ScopedFactoryForTest( |
124 &create_drive_integration_service_)); | 124 &create_drive_integration_service_)); |
125 } | 125 } |
126 | 126 |
127 // Ensure the fake service's data is fetch in the local file system. This is | 127 // Ensure the fake service's data is fetch in the local file system. This is |
128 // necessary because the fetch starts lazily upon the first read operation. | 128 // necessary because the fetch starts lazily upon the first read operation. |
129 void SetUpOnMainThread() override { | 129 void SetUpOnMainThread() override { |
130 PlatformAppBrowserTest::SetUpOnMainThread(); | 130 PlatformAppBrowserTest::SetUpOnMainThread(); |
131 | 131 |
132 scoped_ptr<drive::ResourceEntry> entry; | 132 std::unique_ptr<drive::ResourceEntry> entry; |
133 drive::FileError error = drive::FILE_ERROR_FAILED; | 133 drive::FileError error = drive::FILE_ERROR_FAILED; |
134 integration_service_->file_system()->GetResourceEntry( | 134 integration_service_->file_system()->GetResourceEntry( |
135 base::FilePath::FromUTF8Unsafe("drive/root"), // whatever | 135 base::FilePath::FromUTF8Unsafe("drive/root"), // whatever |
136 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | 136 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
137 content::RunAllBlockingPoolTasksUntilIdle(); | 137 content::RunAllBlockingPoolTasksUntilIdle(); |
138 ASSERT_EQ(drive::FILE_ERROR_OK, error); | 138 ASSERT_EQ(drive::FILE_ERROR_OK, error); |
139 } | 139 } |
140 | 140 |
141 void TearDown() override { | 141 void TearDown() override { |
142 FileSystemChooseEntryFunction::StopSkippingPickerForTest(); | 142 FileSystemChooseEntryFunction::StopSkippingPickerForTest(); |
(...skipping 28 matching lines...) Expand all Loading... |
171 ASSERT_TRUE(AddTestFile("open_existing2.txt", "Can you see me?", root)); | 171 ASSERT_TRUE(AddTestFile("open_existing2.txt", "Can you see me?", root)); |
172 ASSERT_TRUE(AddTestFile("save_existing.txt", "Can you see me?", root)); | 172 ASSERT_TRUE(AddTestFile("save_existing.txt", "Can you see me?", root)); |
173 const std::string subdir = AddTestDirectory("subdir", root); | 173 const std::string subdir = AddTestDirectory("subdir", root); |
174 ASSERT_FALSE(subdir.empty()); | 174 ASSERT_FALSE(subdir.empty()); |
175 ASSERT_TRUE(AddTestFile("open_existing.txt", "Can you see me?", subdir)); | 175 ASSERT_TRUE(AddTestFile("open_existing.txt", "Can you see me?", subdir)); |
176 } | 176 } |
177 | 177 |
178 bool AddTestFile(const std::string& title, | 178 bool AddTestFile(const std::string& title, |
179 const std::string& data, | 179 const std::string& data, |
180 const std::string& parent_id) { | 180 const std::string& parent_id) { |
181 scoped_ptr<google_apis::FileResource> entry; | 181 std::unique_ptr<google_apis::FileResource> entry; |
182 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; | 182 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; |
183 fake_drive_service_->AddNewFile( | 183 fake_drive_service_->AddNewFile( |
184 "text/plain", data, parent_id, title, false, | 184 "text/plain", data, parent_id, title, false, |
185 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | 185 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
186 content::RunAllPendingInMessageLoop(); | 186 content::RunAllPendingInMessageLoop(); |
187 return error == google_apis::HTTP_CREATED && entry; | 187 return error == google_apis::HTTP_CREATED && entry; |
188 } | 188 } |
189 | 189 |
190 std::string AddTestDirectory(const std::string& title, | 190 std::string AddTestDirectory(const std::string& title, |
191 const std::string& parent_id) { | 191 const std::string& parent_id) { |
192 scoped_ptr<google_apis::FileResource> entry; | 192 std::unique_ptr<google_apis::FileResource> entry; |
193 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; | 193 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; |
194 fake_drive_service_->AddNewDirectory( | 194 fake_drive_service_->AddNewDirectory( |
195 parent_id, title, drive::AddNewDirectoryOptions(), | 195 parent_id, title, drive::AddNewDirectoryOptions(), |
196 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | 196 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
197 content::RunAllPendingInMessageLoop(); | 197 content::RunAllPendingInMessageLoop(); |
198 return error == google_apis::HTTP_CREATED && entry ? entry->file_id() : ""; | 198 return error == google_apis::HTTP_CREATED && entry ? entry->file_id() : ""; |
199 } | 199 } |
200 | 200 |
201 base::ScopedTempDir test_cache_root_; | 201 base::ScopedTempDir test_cache_root_; |
202 drive::FakeDriveService* fake_drive_service_; | 202 drive::FakeDriveService* fake_drive_service_; |
203 drive::DriveIntegrationService* integration_service_; | 203 drive::DriveIntegrationService* integration_service_; |
204 drive::DriveIntegrationServiceFactory::FactoryCallback | 204 drive::DriveIntegrationServiceFactory::FactoryCallback |
205 create_drive_integration_service_; | 205 create_drive_integration_service_; |
206 scoped_ptr<drive::DriveIntegrationServiceFactory::ScopedFactoryForTest> | 206 std::unique_ptr<drive::DriveIntegrationServiceFactory::ScopedFactoryForTest> |
207 service_factory_for_test_; | 207 service_factory_for_test_; |
208 }; | 208 }; |
209 | 209 |
210 // This class contains chrome.filesystem.requestFileSystem API tests. | 210 // This class contains chrome.filesystem.requestFileSystem API tests. |
211 class FileSystemApiTestForRequestFileSystem : public PlatformAppBrowserTest { | 211 class FileSystemApiTestForRequestFileSystem : public PlatformAppBrowserTest { |
212 public: | 212 public: |
213 FileSystemApiTestForRequestFileSystem() : fake_user_manager_(nullptr) {} | 213 FileSystemApiTestForRequestFileSystem() : fake_user_manager_(nullptr) {} |
214 | 214 |
215 void SetUpOnMainThread() override { | 215 void SetUpOnMainThread() override { |
216 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 216 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
(...skipping 14 matching lines...) Expand all Loading... |
231 VolumeManager::Get(browser()->profile()); | 231 VolumeManager::Get(browser()->profile()); |
232 ASSERT_TRUE(volume_manager); | 232 ASSERT_TRUE(volume_manager); |
233 volume_manager->AddVolumeForTesting( | 233 volume_manager->AddVolumeForTesting( |
234 base::FilePath("/a/b/c"), file_manager::VOLUME_TYPE_TESTING, | 234 base::FilePath("/a/b/c"), file_manager::VOLUME_TYPE_TESTING, |
235 chromeos::DEVICE_TYPE_UNKNOWN, false /* read_only */); | 235 chromeos::DEVICE_TYPE_UNKNOWN, false /* read_only */); |
236 } | 236 } |
237 | 237 |
238 protected: | 238 protected: |
239 base::ScopedTempDir temp_dir_; | 239 base::ScopedTempDir temp_dir_; |
240 chromeos::FakeChromeUserManager* fake_user_manager_; | 240 chromeos::FakeChromeUserManager* fake_user_manager_; |
241 scoped_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; | 241 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; |
242 | 242 |
243 // Creates a testing file system in a testing directory. | 243 // Creates a testing file system in a testing directory. |
244 void CreateTestingFileSystem(const std::string& mount_point_name, | 244 void CreateTestingFileSystem(const std::string& mount_point_name, |
245 bool read_only) { | 245 bool read_only) { |
246 const base::FilePath mount_point_path = | 246 const base::FilePath mount_point_path = |
247 temp_dir_.path().Append(mount_point_name); | 247 temp_dir_.path().Append(mount_point_name); |
248 ASSERT_TRUE(base::CreateDirectory(mount_point_path)); | 248 ASSERT_TRUE(base::CreateDirectory(mount_point_path)); |
249 ASSERT_TRUE( | 249 ASSERT_TRUE( |
250 base::CreateDirectory(mount_point_path.Append(kChildDirectory))); | 250 base::CreateDirectory(mount_point_path.Append(kChildDirectory))); |
251 ASSERT_TRUE(content::BrowserContext::GetMountPoints(browser()->profile()) | 251 ASSERT_TRUE(content::BrowserContext::GetMountPoints(browser()->profile()) |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 profile(), extensions::api::file_system::OnVolumeListChanged::kEventName, | 493 profile(), extensions::api::file_system::OnVolumeListChanged::kEventName, |
494 kTestingExtensionId, | 494 kTestingExtensionId, |
495 base::Bind(&FileSystemApiTestForRequestFileSystem::MountFakeVolume, | 495 base::Bind(&FileSystemApiTestForRequestFileSystem::MountFakeVolume, |
496 this)); | 496 this)); |
497 | 497 |
498 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/on_volume_list_changed")) | 498 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/on_volume_list_changed")) |
499 << message_; | 499 << message_; |
500 } | 500 } |
501 | 501 |
502 } // namespace extensions | 502 } // namespace extensions |
OLD | NEW |