| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/drive/fake_drive_service.h" | 5 #include "chrome/browser/drive/fake_drive_service.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 fake_service_.GetResourceEntry( | 52 fake_service_.GetResourceEntry( |
| 53 resource_id, | 53 resource_id, |
| 54 test_util::CreateCopyResultCallback(&error, &resource_entry)); | 54 test_util::CreateCopyResultCallback(&error, &resource_entry)); |
| 55 base::RunLoop().RunUntilIdle(); | 55 base::RunLoop().RunUntilIdle(); |
| 56 return resource_entry.Pass(); | 56 return resource_entry.Pass(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 // Returns true if the resource identified by |resource_id| exists. | 59 // Returns true if the resource identified by |resource_id| exists. |
| 60 bool Exists(const std::string& resource_id) { | 60 bool Exists(const std::string& resource_id) { |
| 61 scoped_ptr<ResourceEntry> resource_entry = FindEntry(resource_id); | 61 scoped_ptr<ResourceEntry> resource_entry = FindEntry(resource_id); |
| 62 return resource_entry; | 62 return resource_entry && !resource_entry->deleted(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 // Adds a new directory at |parent_resource_id| with the given name. | 65 // Adds a new directory at |parent_resource_id| with the given name. |
| 66 // Returns true on success. | 66 // Returns true on success. |
| 67 bool AddNewDirectory(const std::string& parent_resource_id, | 67 bool AddNewDirectory(const std::string& parent_resource_id, |
| 68 const std::string& directory_name) { | 68 const std::string& directory_name) { |
| 69 GDataErrorCode error = GDATA_OTHER_ERROR; | 69 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 70 scoped_ptr<ResourceEntry> resource_entry; | 70 scoped_ptr<ResourceEntry> resource_entry; |
| 71 fake_service_.AddNewDirectory( | 71 fake_service_.AddNewDirectory( |
| 72 parent_resource_id, | 72 parent_resource_id, |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 scoped_ptr<ResourceList> resource_list; | 265 scoped_ptr<ResourceList> resource_list; |
| 266 fake_service_.Search( | 266 fake_service_.Search( |
| 267 "Directory 1", // search_query | 267 "Directory 1", // search_query |
| 268 test_util::CreateCopyResultCallback(&error, &resource_list)); | 268 test_util::CreateCopyResultCallback(&error, &resource_list)); |
| 269 base::RunLoop().RunUntilIdle(); | 269 base::RunLoop().RunUntilIdle(); |
| 270 | 270 |
| 271 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 271 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
| 272 EXPECT_FALSE(resource_list); | 272 EXPECT_FALSE(resource_list); |
| 273 } | 273 } |
| 274 | 274 |
| 275 TEST_F(FakeDriveServiceTest, Search_Deleted) { |
| 276 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( |
| 277 "chromeos/gdata/root_feed.json")); |
| 278 |
| 279 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 280 fake_service_.DeleteResource("file:2_file_resource_id", |
| 281 std::string(), // etag |
| 282 test_util::CreateCopyResultCallback(&error)); |
| 283 base::RunLoop().RunUntilIdle(); |
| 284 EXPECT_EQ(HTTP_SUCCESS, error); |
| 285 |
| 286 error = GDATA_OTHER_ERROR; |
| 287 scoped_ptr<ResourceList> resource_list; |
| 288 fake_service_.Search( |
| 289 "File", // search_query |
| 290 test_util::CreateCopyResultCallback(&error, &resource_list)); |
| 291 base::RunLoop().RunUntilIdle(); |
| 292 |
| 293 EXPECT_EQ(HTTP_SUCCESS, error); |
| 294 ASSERT_TRUE(resource_list); |
| 295 // Do some sanity check. There are 4 entries that contain "File" in their |
| 296 // titles and one of them is deleted. |
| 297 EXPECT_EQ(3U, resource_list->entries().size()); |
| 298 } |
| 299 |
| 275 TEST_F(FakeDriveServiceTest, SearchByTitle) { | 300 TEST_F(FakeDriveServiceTest, SearchByTitle) { |
| 276 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | 301 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( |
| 277 "chromeos/gdata/root_feed.json")); | 302 "chromeos/gdata/root_feed.json")); |
| 278 | 303 |
| 279 GDataErrorCode error = GDATA_OTHER_ERROR; | 304 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 280 scoped_ptr<ResourceList> resource_list; | 305 scoped_ptr<ResourceList> resource_list; |
| 281 fake_service_.SearchByTitle( | 306 fake_service_.SearchByTitle( |
| 282 "1.txt", // title | 307 "1.txt", // title |
| 283 fake_service_.GetRootResourceId(), // directory_resource_id | 308 fake_service_.GetRootResourceId(), // directory_resource_id |
| 284 test_util::CreateCopyResultCallback(&error, &resource_list)); | 309 test_util::CreateCopyResultCallback(&error, &resource_list)); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 scoped_ptr<ResourceList> resource_list; | 413 scoped_ptr<ResourceList> resource_list; |
| 389 fake_service_.GetChangeList( | 414 fake_service_.GetChangeList( |
| 390 654321, // start_changestamp | 415 654321, // start_changestamp |
| 391 test_util::CreateCopyResultCallback(&error, &resource_list)); | 416 test_util::CreateCopyResultCallback(&error, &resource_list)); |
| 392 base::RunLoop().RunUntilIdle(); | 417 base::RunLoop().RunUntilIdle(); |
| 393 | 418 |
| 394 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 419 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
| 395 EXPECT_FALSE(resource_list); | 420 EXPECT_FALSE(resource_list); |
| 396 } | 421 } |
| 397 | 422 |
| 423 TEST_F(FakeDriveServiceTest, GetChangeList_DeletedEntry) { |
| 424 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( |
| 425 "chromeos/gdata/root_feed.json")); |
| 426 // Load the account_metadata.json as well to add the largest changestamp |
| 427 // (654321) to the existing entries. |
| 428 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi( |
| 429 "chromeos/gdata/account_metadata.json")); |
| 430 // Add a new directory in the root directory. The new directory will have |
| 431 // the changestamp of 654322. |
| 432 ASSERT_TRUE(Exists("file:2_file_resource_id")); |
| 433 |
| 434 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 435 fake_service_.DeleteResource("file:2_file_resource_id", |
| 436 std::string(), // etag |
| 437 test_util::CreateCopyResultCallback(&error)); |
| 438 base::RunLoop().RunUntilIdle(); |
| 439 ASSERT_EQ(HTTP_SUCCESS, error); |
| 440 ASSERT_FALSE(Exists("file:2_file_resource_id")); |
| 441 |
| 442 // Get the resource list newer than 654321. |
| 443 error = GDATA_OTHER_ERROR; |
| 444 scoped_ptr<ResourceList> resource_list; |
| 445 fake_service_.GetChangeList( |
| 446 654321 + 1, // start_changestamp |
| 447 test_util::CreateCopyResultCallback(&error, &resource_list)); |
| 448 base::RunLoop().RunUntilIdle(); |
| 449 |
| 450 EXPECT_EQ(HTTP_SUCCESS, error); |
| 451 ASSERT_TRUE(resource_list); |
| 452 // The result should only contain the newly created directory. |
| 453 ASSERT_EQ(1U, resource_list->entries().size()); |
| 454 const ResourceEntry& entry = *resource_list->entries()[0]; |
| 455 EXPECT_EQ("file:2_file_resource_id", entry.resource_id()); |
| 456 EXPECT_TRUE(entry.deleted()); |
| 457 EXPECT_EQ(1, fake_service_.change_list_load_count()); |
| 458 } |
| 459 |
| 398 TEST_F(FakeDriveServiceTest, ContinueGetResourceList_GetAllResourceList) { | 460 TEST_F(FakeDriveServiceTest, ContinueGetResourceList_GetAllResourceList) { |
| 399 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | 461 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( |
| 400 "chromeos/gdata/root_feed.json")); | 462 "chromeos/gdata/root_feed.json")); |
| 401 fake_service_.set_default_max_results(6); | 463 fake_service_.set_default_max_results(6); |
| 402 | 464 |
| 403 GDataErrorCode error = GDATA_OTHER_ERROR; | 465 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 404 scoped_ptr<ResourceList> resource_list; | 466 scoped_ptr<ResourceList> resource_list; |
| 405 fake_service_.GetAllResourceList( | 467 fake_service_.GetAllResourceList( |
| 406 test_util::CreateCopyResultCallback(&error, &resource_list)); | 468 test_util::CreateCopyResultCallback(&error, &resource_list)); |
| 407 base::RunLoop().RunUntilIdle(); | 469 base::RunLoop().RunUntilIdle(); |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 | 809 |
| 748 GDataErrorCode error = GDATA_OTHER_ERROR; | 810 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 749 fake_service_.DeleteResource("file:2_file_resource_id", | 811 fake_service_.DeleteResource("file:2_file_resource_id", |
| 750 std::string(), // etag | 812 std::string(), // etag |
| 751 test_util::CreateCopyResultCallback(&error)); | 813 test_util::CreateCopyResultCallback(&error)); |
| 752 base::RunLoop().RunUntilIdle(); | 814 base::RunLoop().RunUntilIdle(); |
| 753 | 815 |
| 754 EXPECT_EQ(HTTP_SUCCESS, error); | 816 EXPECT_EQ(HTTP_SUCCESS, error); |
| 755 // Resource "file:2_file_resource_id" should be gone now. | 817 // Resource "file:2_file_resource_id" should be gone now. |
| 756 EXPECT_FALSE(Exists("file:2_file_resource_id")); | 818 EXPECT_FALSE(Exists("file:2_file_resource_id")); |
| 819 |
| 820 error = GDATA_OTHER_ERROR; |
| 821 fake_service_.DeleteResource("file:2_file_resource_id", |
| 822 std::string(), // etag |
| 823 test_util::CreateCopyResultCallback(&error)); |
| 824 base::RunLoop().RunUntilIdle(); |
| 825 EXPECT_EQ(HTTP_NOT_FOUND, error); |
| 826 EXPECT_FALSE(Exists("file:2_file_resource_id")); |
| 757 } | 827 } |
| 758 | 828 |
| 759 TEST_F(FakeDriveServiceTest, DeleteResource_NonexistingFile) { | 829 TEST_F(FakeDriveServiceTest, DeleteResource_NonexistingFile) { |
| 760 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | 830 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( |
| 761 "chromeos/gdata/root_feed.json")); | 831 "chromeos/gdata/root_feed.json")); |
| 762 | 832 |
| 763 GDataErrorCode error = GDATA_OTHER_ERROR; | 833 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 764 fake_service_.DeleteResource("file:nonexisting_resource_id", | 834 fake_service_.DeleteResource("file:nonexisting_resource_id", |
| 765 std::string(), // etag | 835 std::string(), // etag |
| 766 test_util::CreateCopyResultCallback(&error)); | 836 test_util::CreateCopyResultCallback(&error)); |
| (...skipping 1326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2093 test_util::CreateCopyResultCallback(&error, &resource_entry)); | 2163 test_util::CreateCopyResultCallback(&error, &resource_entry)); |
| 2094 base::RunLoop().RunUntilIdle(); | 2164 base::RunLoop().RunUntilIdle(); |
| 2095 | 2165 |
| 2096 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 2166 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
| 2097 EXPECT_FALSE(resource_entry); | 2167 EXPECT_FALSE(resource_entry); |
| 2098 } | 2168 } |
| 2099 | 2169 |
| 2100 } // namespace | 2170 } // namespace |
| 2101 | 2171 |
| 2102 } // namespace drive | 2172 } // namespace drive |
| OLD | NEW |