| 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/sync_file_system/drive_backend/fake_drive_service_helpe
r.h" | 5 #include "chrome/browser/sync_file_system/drive_backend/fake_drive_service_helpe
r.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/threading/sequenced_worker_pool.h" | 11 #include "base/threading/sequenced_worker_pool.h" |
| 12 #include "chrome/browser/drive/drive_api_util.h" | |
| 13 #include "chrome/browser/sync_file_system/sync_file_system_test_util.h" | 12 #include "chrome/browser/sync_file_system/sync_file_system_test_util.h" |
| 14 #include "chrome/browser/sync_file_system/sync_status_code.h" | 13 #include "chrome/browser/sync_file_system/sync_status_code.h" |
| 15 #include "google_apis/drive/drive_api_parser.h" | 14 #include "google_apis/drive/drive_api_parser.h" |
| 16 #include "storage/browser/fileapi/file_system_url.h" | 15 #include "storage/browser/fileapi/file_system_url.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 17 |
| 19 #define FPL(path) FILE_PATH_LITERAL(path) | 18 #define FPL(path) FILE_PATH_LITERAL(path) |
| 20 | 19 |
| 21 using google_apis::AboutResource; | 20 using google_apis::AboutResource; |
| 22 using google_apis::FileList; | 21 using google_apis::FileList; |
| 23 using google_apis::FileResource; | 22 using google_apis::FileResource; |
| 24 using google_apis::GDataErrorCode; | 23 using google_apis::GDataErrorCode; |
| 25 using google_apis::ResourceEntry; | |
| 26 | 24 |
| 27 namespace sync_file_system { | 25 namespace sync_file_system { |
| 28 namespace drive_backend { | 26 namespace drive_backend { |
| 29 | 27 |
| 30 namespace { | 28 namespace { |
| 31 | 29 |
| 32 void UploadResultCallback(GDataErrorCode* error_out, | 30 void UploadResultCallback(GDataErrorCode* error_out, |
| 33 scoped_ptr<FileResource>* entry_out, | 31 scoped_ptr<FileResource>* entry_out, |
| 34 GDataErrorCode error, | 32 GDataErrorCode error, |
| 35 const GURL& upload_location, | 33 const GURL& upload_location, |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 if (item.parents().empty()) { | 224 if (item.parents().empty()) { |
| 227 *sync_root_folder_id = item.file_id(); | 225 *sync_root_folder_id = item.file_id(); |
| 228 return google_apis::HTTP_SUCCESS; | 226 return google_apis::HTTP_SUCCESS; |
| 229 } | 227 } |
| 230 } | 228 } |
| 231 return google_apis::HTTP_NOT_FOUND; | 229 return google_apis::HTTP_NOT_FOUND; |
| 232 } | 230 } |
| 233 | 231 |
| 234 GDataErrorCode FakeDriveServiceHelper::ListFilesInFolder( | 232 GDataErrorCode FakeDriveServiceHelper::ListFilesInFolder( |
| 235 const std::string& folder_id, | 233 const std::string& folder_id, |
| 236 ScopedVector<ResourceEntry>* entries) { | 234 ScopedVector<FileResource>* entries) { |
| 237 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 235 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
| 238 scoped_ptr<FileList> list; | 236 scoped_ptr<FileList> list; |
| 239 fake_drive_service_->GetFileListInDirectory( | 237 fake_drive_service_->GetFileListInDirectory( |
| 240 folder_id, | 238 folder_id, |
| 241 CreateResultReceiver(&error, &list)); | 239 CreateResultReceiver(&error, &list)); |
| 242 base::RunLoop().RunUntilIdle(); | 240 base::RunLoop().RunUntilIdle(); |
| 243 if (error != google_apis::HTTP_SUCCESS) | 241 if (error != google_apis::HTTP_SUCCESS) |
| 244 return error; | 242 return error; |
| 245 | 243 |
| 246 return CompleteListing(list.Pass(), entries); | 244 return CompleteListing(list.Pass(), entries); |
| 247 } | 245 } |
| 248 | 246 |
| 249 GDataErrorCode FakeDriveServiceHelper::SearchByTitle( | 247 GDataErrorCode FakeDriveServiceHelper::SearchByTitle( |
| 250 const std::string& folder_id, | 248 const std::string& folder_id, |
| 251 const std::string& title, | 249 const std::string& title, |
| 252 ScopedVector<ResourceEntry>* entries) { | 250 ScopedVector<FileResource>* entries) { |
| 253 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 251 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
| 254 scoped_ptr<FileList> list; | 252 scoped_ptr<FileList> list; |
| 255 fake_drive_service_->SearchByTitle( | 253 fake_drive_service_->SearchByTitle( |
| 256 title, folder_id, | 254 title, folder_id, |
| 257 CreateResultReceiver(&error, &list)); | 255 CreateResultReceiver(&error, &list)); |
| 258 base::RunLoop().RunUntilIdle(); | 256 base::RunLoop().RunUntilIdle(); |
| 259 if (error != google_apis::HTTP_SUCCESS) | 257 if (error != google_apis::HTTP_SUCCESS) |
| 260 return error; | 258 return error; |
| 261 | 259 |
| 262 return CompleteListing(list.Pass(), entries); | 260 return CompleteListing(list.Pass(), entries); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 scoped_ptr<AboutResource>* about_resource) { | 301 scoped_ptr<AboutResource>* about_resource) { |
| 304 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 302 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
| 305 fake_drive_service_->GetAboutResource( | 303 fake_drive_service_->GetAboutResource( |
| 306 CreateResultReceiver(&error, about_resource)); | 304 CreateResultReceiver(&error, about_resource)); |
| 307 base::RunLoop().RunUntilIdle(); | 305 base::RunLoop().RunUntilIdle(); |
| 308 return error; | 306 return error; |
| 309 } | 307 } |
| 310 | 308 |
| 311 GDataErrorCode FakeDriveServiceHelper::CompleteListing( | 309 GDataErrorCode FakeDriveServiceHelper::CompleteListing( |
| 312 scoped_ptr<FileList> list, | 310 scoped_ptr<FileList> list, |
| 313 ScopedVector<ResourceEntry>* entries) { | 311 ScopedVector<FileResource>* entries) { |
| 314 while (true) { | 312 while (true) { |
| 315 entries->reserve(entries->size() + list->items().size()); | 313 entries->reserve(entries->size() + list->items().size()); |
| 316 for (ScopedVector<FileResource>::const_iterator itr = | 314 std::vector<FileResource*> tmp; |
| 317 list->items().begin(); itr != list->items().end(); ++itr) { | 315 list->mutable_items()->release(&tmp); |
| 318 entries->push_back( | 316 for (std::vector<FileResource*>::const_iterator itr = |
| 319 drive::util::ConvertFileResourceToResourceEntry(**itr).release()); | 317 tmp.begin(); itr != tmp.end(); ++itr) { |
| 318 entries->push_back(*itr); |
| 320 } | 319 } |
| 321 | 320 |
| 322 GURL next_feed = list->next_link(); | 321 GURL next_feed = list->next_link(); |
| 323 if (next_feed.is_empty()) | 322 if (next_feed.is_empty()) |
| 324 return google_apis::HTTP_SUCCESS; | 323 return google_apis::HTTP_SUCCESS; |
| 325 | 324 |
| 326 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 325 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
| 327 list.reset(); | 326 list.reset(); |
| 328 fake_drive_service_->GetRemainingFileList( | 327 fake_drive_service_->GetRemainingFileList( |
| 329 next_feed, | 328 next_feed, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 344 const std::string& content) { | 343 const std::string& content) { |
| 345 base::FilePath temp_file; | 344 base::FilePath temp_file; |
| 346 EXPECT_TRUE(base::CreateTemporaryFileInDir(temp_dir_, &temp_file)); | 345 EXPECT_TRUE(base::CreateTemporaryFileInDir(temp_dir_, &temp_file)); |
| 347 EXPECT_EQ(static_cast<int>(content.size()), | 346 EXPECT_EQ(static_cast<int>(content.size()), |
| 348 base::WriteFile(temp_file, content.data(), content.size())); | 347 base::WriteFile(temp_file, content.data(), content.size())); |
| 349 return temp_file; | 348 return temp_file; |
| 350 } | 349 } |
| 351 | 350 |
| 352 } // namespace drive_backend | 351 } // namespace drive_backend |
| 353 } // namespace sync_file_system | 352 } // namespace sync_file_system |
| OLD | NEW |