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/file_util.h" | 8 #include "base/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" |
12 #include "chrome/browser/sync_file_system/sync_file_system_test_util.h" | 13 #include "chrome/browser/sync_file_system/sync_file_system_test_util.h" |
13 #include "chrome/browser/sync_file_system/sync_status_code.h" | 14 #include "chrome/browser/sync_file_system/sync_status_code.h" |
14 #include "google_apis/drive/drive_api_parser.h" | 15 #include "google_apis/drive/drive_api_parser.h" |
15 #include "google_apis/drive/gdata_wapi_parser.h" | 16 #include "google_apis/drive/gdata_wapi_parser.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "webkit/browser/fileapi/file_system_url.h" | 18 #include "webkit/browser/fileapi/file_system_url.h" |
18 | 19 |
19 #define FPL(path) FILE_PATH_LITERAL(path) | 20 #define FPL(path) FILE_PATH_LITERAL(path) |
20 | 21 |
21 using google_apis::AboutResource; | 22 using google_apis::AboutResource; |
| 23 using google_apis::FileList; |
| 24 using google_apis::FileResource; |
22 using google_apis::GDataErrorCode; | 25 using google_apis::GDataErrorCode; |
23 using google_apis::ResourceEntry; | 26 using google_apis::ResourceEntry; |
24 using google_apis::ResourceList; | |
25 | 27 |
26 namespace sync_file_system { | 28 namespace sync_file_system { |
27 namespace drive_backend { | 29 namespace drive_backend { |
28 | 30 |
29 namespace { | 31 namespace { |
30 | 32 |
31 void UploadResultCallback(GDataErrorCode* error_out, | 33 void UploadResultCallback(GDataErrorCode* error_out, |
32 scoped_ptr<ResourceEntry>* entry_out, | 34 scoped_ptr<ResourceEntry>* entry_out, |
33 GDataErrorCode error, | 35 GDataErrorCode error, |
34 const GURL& upload_location, | 36 const GURL& upload_location, |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 fake_drive_service_->RemoveResourceFromDirectory( | 204 fake_drive_service_->RemoveResourceFromDirectory( |
203 parent_folder_id, file_id, | 205 parent_folder_id, file_id, |
204 CreateResultReceiver(&error)); | 206 CreateResultReceiver(&error)); |
205 base::RunLoop().RunUntilIdle(); | 207 base::RunLoop().RunUntilIdle(); |
206 return error; | 208 return error; |
207 } | 209 } |
208 | 210 |
209 GDataErrorCode FakeDriveServiceHelper::GetSyncRootFolderID( | 211 GDataErrorCode FakeDriveServiceHelper::GetSyncRootFolderID( |
210 std::string* sync_root_folder_id) { | 212 std::string* sync_root_folder_id) { |
211 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 213 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
212 scoped_ptr<ResourceList> resource_list; | 214 scoped_ptr<FileList> resource_list; |
213 fake_drive_service_->SearchByTitle( | 215 fake_drive_service_->SearchByTitle( |
214 sync_root_folder_title_, std::string(), | 216 sync_root_folder_title_, std::string(), |
215 CreateResultReceiver(&error, &resource_list)); | 217 CreateResultReceiver(&error, &resource_list)); |
216 base::RunLoop().RunUntilIdle(); | 218 base::RunLoop().RunUntilIdle(); |
217 if (error != google_apis::HTTP_SUCCESS) | 219 if (error != google_apis::HTTP_SUCCESS) |
218 return error; | 220 return error; |
219 | 221 |
220 const ScopedVector<ResourceEntry>& entries = resource_list->entries(); | 222 const ScopedVector<FileResource>& items = resource_list->items(); |
221 for (ScopedVector<ResourceEntry>::const_iterator itr = entries.begin(); | 223 for (ScopedVector<FileResource>::const_iterator itr = items.begin(); |
222 itr != entries.end(); ++itr) { | 224 itr != items.end(); ++itr) { |
223 const ResourceEntry& entry = **itr; | 225 const FileResource& item = **itr; |
224 if (!entry.GetLinkByType(google_apis::Link::LINK_PARENT)) { | 226 if (item.parents().empty()) { |
225 *sync_root_folder_id = entry.resource_id(); | 227 *sync_root_folder_id = item.file_id(); |
226 return google_apis::HTTP_SUCCESS; | 228 return google_apis::HTTP_SUCCESS; |
227 } | 229 } |
228 } | 230 } |
229 return google_apis::HTTP_NOT_FOUND; | 231 return google_apis::HTTP_NOT_FOUND; |
230 } | 232 } |
231 | 233 |
232 GDataErrorCode FakeDriveServiceHelper::ListFilesInFolder( | 234 GDataErrorCode FakeDriveServiceHelper::ListFilesInFolder( |
233 const std::string& folder_id, | 235 const std::string& folder_id, |
234 ScopedVector<ResourceEntry>* entries) { | 236 ScopedVector<ResourceEntry>* entries) { |
235 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 237 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
236 scoped_ptr<ResourceList> list; | 238 scoped_ptr<FileList> list; |
237 fake_drive_service_->GetResourceListInDirectory( | 239 fake_drive_service_->GetFileListInDirectory( |
238 folder_id, | 240 folder_id, |
239 CreateResultReceiver(&error, &list)); | 241 CreateResultReceiver(&error, &list)); |
240 base::RunLoop().RunUntilIdle(); | 242 base::RunLoop().RunUntilIdle(); |
241 if (error != google_apis::HTTP_SUCCESS) | 243 if (error != google_apis::HTTP_SUCCESS) |
242 return error; | 244 return error; |
243 | 245 |
244 return CompleteListing(list.Pass(), entries); | 246 return CompleteListing(list.Pass(), entries); |
245 } | 247 } |
246 | 248 |
247 GDataErrorCode FakeDriveServiceHelper::SearchByTitle( | 249 GDataErrorCode FakeDriveServiceHelper::SearchByTitle( |
248 const std::string& folder_id, | 250 const std::string& folder_id, |
249 const std::string& title, | 251 const std::string& title, |
250 ScopedVector<ResourceEntry>* entries) { | 252 ScopedVector<ResourceEntry>* entries) { |
251 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 253 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
252 scoped_ptr<ResourceList> list; | 254 scoped_ptr<FileList> list; |
253 fake_drive_service_->SearchByTitle( | 255 fake_drive_service_->SearchByTitle( |
254 title, folder_id, | 256 title, folder_id, |
255 CreateResultReceiver(&error, &list)); | 257 CreateResultReceiver(&error, &list)); |
256 base::RunLoop().RunUntilIdle(); | 258 base::RunLoop().RunUntilIdle(); |
257 if (error != google_apis::HTTP_SUCCESS) | 259 if (error != google_apis::HTTP_SUCCESS) |
258 return error; | 260 return error; |
259 | 261 |
260 return CompleteListing(list.Pass(), entries); | 262 return CompleteListing(list.Pass(), entries); |
261 } | 263 } |
262 | 264 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 GDataErrorCode FakeDriveServiceHelper::GetAboutResource( | 302 GDataErrorCode FakeDriveServiceHelper::GetAboutResource( |
301 scoped_ptr<AboutResource>* about_resource) { | 303 scoped_ptr<AboutResource>* about_resource) { |
302 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 304 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
303 fake_drive_service_->GetAboutResource( | 305 fake_drive_service_->GetAboutResource( |
304 CreateResultReceiver(&error, about_resource)); | 306 CreateResultReceiver(&error, about_resource)); |
305 base::RunLoop().RunUntilIdle(); | 307 base::RunLoop().RunUntilIdle(); |
306 return error; | 308 return error; |
307 } | 309 } |
308 | 310 |
309 GDataErrorCode FakeDriveServiceHelper::CompleteListing( | 311 GDataErrorCode FakeDriveServiceHelper::CompleteListing( |
310 scoped_ptr<ResourceList> list, | 312 scoped_ptr<FileList> list, |
311 ScopedVector<ResourceEntry>* entries) { | 313 ScopedVector<ResourceEntry>* entries) { |
312 while (true) { | 314 while (true) { |
313 entries->reserve(entries->size() + list->entries().size()); | 315 entries->reserve(entries->size() + list->items().size()); |
314 for (ScopedVector<ResourceEntry>::iterator itr = | 316 for (ScopedVector<FileResource>::const_iterator itr = |
315 list->mutable_entries()->begin(); | 317 list->items().begin(); itr != list->items().end(); ++itr) { |
316 itr != list->mutable_entries()->end(); ++itr) { | 318 entries->push_back( |
317 entries->push_back(*itr); | 319 drive::util::ConvertFileResourceToResourceEntry(**itr).release()); |
318 *itr = NULL; | |
319 } | 320 } |
320 | 321 |
321 GURL next_feed; | 322 GURL next_feed = list->next_link(); |
322 if (!list->GetNextFeedURL(&next_feed)) | 323 if (next_feed.is_empty()) |
323 return google_apis::HTTP_SUCCESS; | 324 return google_apis::HTTP_SUCCESS; |
324 | 325 |
325 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 326 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
326 list.reset(); | 327 list.reset(); |
327 fake_drive_service_->GetRemainingFileList( | 328 fake_drive_service_->GetRemainingFileList( |
328 next_feed, | 329 next_feed, |
329 CreateResultReceiver(&error, &list)); | 330 CreateResultReceiver(&error, &list)); |
330 base::RunLoop().RunUntilIdle(); | 331 base::RunLoop().RunUntilIdle(); |
331 if (error != google_apis::HTTP_SUCCESS) | 332 if (error != google_apis::HTTP_SUCCESS) |
332 return error; | 333 return error; |
(...skipping 10 matching lines...) Expand all Loading... |
343 const std::string& content) { | 344 const std::string& content) { |
344 base::FilePath temp_file; | 345 base::FilePath temp_file; |
345 EXPECT_TRUE(base::CreateTemporaryFileInDir(temp_dir_, &temp_file)); | 346 EXPECT_TRUE(base::CreateTemporaryFileInDir(temp_dir_, &temp_file)); |
346 EXPECT_EQ(static_cast<int>(content.size()), | 347 EXPECT_EQ(static_cast<int>(content.size()), |
347 base::WriteFile(temp_file, content.data(), content.size())); | 348 base::WriteFile(temp_file, content.data(), content.size())); |
348 return temp_file; | 349 return temp_file; |
349 } | 350 } |
350 | 351 |
351 } // namespace drive_backend | 352 } // namespace drive_backend |
352 } // namespace sync_file_system | 353 } // namespace sync_file_system |
OLD | NEW |