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/google_apis/fake_drive_service.h" | 5 #include "chrome/browser/google_apis/fake_drive_service.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1013 GDataErrorCode error = GDATA_OTHER_ERROR; | 1013 GDataErrorCode error = GDATA_OTHER_ERROR; |
1014 scoped_ptr<ResourceEntry> resource_entry; | 1014 scoped_ptr<ResourceEntry> resource_entry; |
1015 fake_service_.AddNewDirectory( | 1015 fake_service_.AddNewDirectory( |
1016 fake_service_.GetRootResourceId(), | 1016 fake_service_.GetRootResourceId(), |
1017 "new directory", | 1017 "new directory", |
1018 test_util::CreateCopyResultCallback(&error, &resource_entry)); | 1018 test_util::CreateCopyResultCallback(&error, &resource_entry)); |
1019 message_loop_.RunUntilIdle(); | 1019 message_loop_.RunUntilIdle(); |
1020 | 1020 |
1021 EXPECT_EQ(HTTP_CREATED, error); | 1021 EXPECT_EQ(HTTP_CREATED, error); |
1022 ASSERT_TRUE(resource_entry); | 1022 ASSERT_TRUE(resource_entry); |
1023 EXPECT_TRUE(resource_entry->is_folder()); | |
1023 EXPECT_EQ("resource_id_1", resource_entry->resource_id()); | 1024 EXPECT_EQ("resource_id_1", resource_entry->resource_id()); |
1024 EXPECT_EQ("new directory", resource_entry->title()); | 1025 EXPECT_EQ("new directory", resource_entry->title()); |
1025 EXPECT_TRUE(HasParent(resource_entry->resource_id(), | 1026 EXPECT_TRUE(HasParent(resource_entry->resource_id(), |
1026 fake_service_.GetRootResourceId())); | 1027 fake_service_.GetRootResourceId())); |
1027 // Should be incremented as a new directory was created. | 1028 // Should be incremented as a new directory was created. |
1028 EXPECT_EQ(old_largest_change_id + 1, fake_service_.largest_changestamp()); | 1029 EXPECT_EQ(old_largest_change_id + 1, fake_service_.largest_changestamp()); |
1029 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1030 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
1030 } | 1031 } |
1031 | 1032 |
1032 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToRootDirectoryOnEmptyFileSystem) { | 1033 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToRootDirectoryOnEmptyFileSystem) { |
1033 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | 1034 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( |
1034 "chromeos/gdata/empty_feed.json")); | 1035 "chromeos/gdata/empty_feed.json")); |
1035 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi( | 1036 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi( |
1036 "chromeos/gdata/account_metadata.json")); | 1037 "chromeos/gdata/account_metadata.json")); |
1037 | 1038 |
1038 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1039 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
1039 | 1040 |
1040 GDataErrorCode error = GDATA_OTHER_ERROR; | 1041 GDataErrorCode error = GDATA_OTHER_ERROR; |
1041 scoped_ptr<ResourceEntry> resource_entry; | 1042 scoped_ptr<ResourceEntry> resource_entry; |
1042 fake_service_.AddNewDirectory( | 1043 fake_service_.AddNewDirectory( |
1043 fake_service_.GetRootResourceId(), | 1044 fake_service_.GetRootResourceId(), |
1044 "new directory", | 1045 "new directory", |
1045 test_util::CreateCopyResultCallback(&error, &resource_entry)); | 1046 test_util::CreateCopyResultCallback(&error, &resource_entry)); |
1046 message_loop_.RunUntilIdle(); | 1047 message_loop_.RunUntilIdle(); |
1047 | 1048 |
1048 EXPECT_EQ(HTTP_CREATED, error); | 1049 EXPECT_EQ(HTTP_CREATED, error); |
1049 ASSERT_TRUE(resource_entry); | 1050 ASSERT_TRUE(resource_entry); |
1051 EXPECT_TRUE(resource_entry->is_folder()); | |
1050 EXPECT_EQ("resource_id_1", resource_entry->resource_id()); | 1052 EXPECT_EQ("resource_id_1", resource_entry->resource_id()); |
1051 EXPECT_EQ("new directory", resource_entry->title()); | 1053 EXPECT_EQ("new directory", resource_entry->title()); |
1052 EXPECT_TRUE(HasParent(resource_entry->resource_id(), | 1054 EXPECT_TRUE(HasParent(resource_entry->resource_id(), |
1053 fake_service_.GetRootResourceId())); | 1055 fake_service_.GetRootResourceId())); |
1054 // Should be incremented as a new directory was created. | 1056 // Should be incremented as a new directory was created. |
1055 EXPECT_EQ(old_largest_change_id + 1, fake_service_.largest_changestamp()); | 1057 EXPECT_EQ(old_largest_change_id + 1, fake_service_.largest_changestamp()); |
1056 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1058 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
1057 } | 1059 } |
1058 | 1060 |
1059 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToNonRootDirectory) { | 1061 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToNonRootDirectory) { |
1060 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | 1062 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( |
1061 "chromeos/gdata/root_feed.json")); | 1063 "chromeos/gdata/root_feed.json")); |
1062 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi( | 1064 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi( |
1063 "chromeos/gdata/account_metadata.json")); | 1065 "chromeos/gdata/account_metadata.json")); |
1064 | 1066 |
1065 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1067 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
1066 | 1068 |
1067 const std::string kParentResourceId = "folder:1_folder_resource_id"; | 1069 const std::string kParentResourceId = "folder:1_folder_resource_id"; |
1068 | 1070 |
1069 GDataErrorCode error = GDATA_OTHER_ERROR; | 1071 GDataErrorCode error = GDATA_OTHER_ERROR; |
1070 scoped_ptr<ResourceEntry> resource_entry; | 1072 scoped_ptr<ResourceEntry> resource_entry; |
1071 fake_service_.AddNewDirectory( | 1073 fake_service_.AddNewDirectory( |
1072 kParentResourceId, | 1074 kParentResourceId, |
1073 "new directory", | 1075 "new directory", |
1074 test_util::CreateCopyResultCallback(&error, &resource_entry)); | 1076 test_util::CreateCopyResultCallback(&error, &resource_entry)); |
1075 message_loop_.RunUntilIdle(); | 1077 message_loop_.RunUntilIdle(); |
1076 | 1078 |
1077 EXPECT_EQ(HTTP_CREATED, error); | 1079 EXPECT_EQ(HTTP_CREATED, error); |
1078 ASSERT_TRUE(resource_entry); | 1080 ASSERT_TRUE(resource_entry); |
1081 EXPECT_TRUE(resource_entry->is_folder()); | |
1079 EXPECT_EQ("resource_id_1", resource_entry->resource_id()); | 1082 EXPECT_EQ("resource_id_1", resource_entry->resource_id()); |
1080 EXPECT_EQ("new directory", resource_entry->title()); | 1083 EXPECT_EQ("new directory", resource_entry->title()); |
1081 EXPECT_TRUE(HasParent(resource_entry->resource_id(), kParentResourceId)); | 1084 EXPECT_TRUE(HasParent(resource_entry->resource_id(), kParentResourceId)); |
1082 // Should be incremented as a new directory was created. | 1085 // Should be incremented as a new directory was created. |
1083 EXPECT_EQ(old_largest_change_id + 1, fake_service_.largest_changestamp()); | 1086 EXPECT_EQ(old_largest_change_id + 1, fake_service_.largest_changestamp()); |
1084 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1087 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
1085 } | 1088 } |
1086 | 1089 |
1087 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToNonexistingDirectory) { | 1090 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToNonexistingDirectory) { |
1088 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | 1091 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1414 scoped_refptr<net::IOBuffer>(), | 1417 scoped_refptr<net::IOBuffer>(), |
1415 test_util::CreateCopyResultCallback(&response, &entry)); | 1418 test_util::CreateCopyResultCallback(&response, &entry)); |
1416 message_loop_.RunUntilIdle(); | 1419 message_loop_.RunUntilIdle(); |
1417 | 1420 |
1418 EXPECT_EQ(HTTP_CREATED, response.code); | 1421 EXPECT_EQ(HTTP_CREATED, response.code); |
1419 EXPECT_TRUE(entry.get()); | 1422 EXPECT_TRUE(entry.get()); |
1420 EXPECT_EQ(15L, entry->file_size()); | 1423 EXPECT_EQ(15L, entry->file_size()); |
1421 EXPECT_TRUE(Exists(entry->resource_id())); | 1424 EXPECT_TRUE(Exists(entry->resource_id())); |
1422 } | 1425 } |
1423 | 1426 |
1427 TEST_F(FakeDriveServiceTest, AddNewFile_ToRootDirectory) { | |
1428 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | |
1429 "chromeos/gdata/root_feed.json")); | |
1430 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi( | |
1431 "chromeos/gdata/account_metadata.json")); | |
1432 | |
1433 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | |
1434 | |
1435 const std::string kContentType = "text/plain"; | |
1436 const int64 kContentSize = 123; | |
1437 const std::string kTitle = "new file"; | |
1438 | |
1439 GDataErrorCode error = GDATA_OTHER_ERROR; | |
1440 scoped_ptr<ResourceEntry> resource_entry; | |
1441 fake_service_.AddNewFile( | |
1442 kContentType, | |
1443 kContentSize, | |
1444 fake_service_.GetRootResourceId(), | |
1445 kTitle, | |
1446 test_util::CreateCopyResultCallback(&error, &resource_entry)); | |
1447 message_loop_.RunUntilIdle(); | |
1448 | |
1449 EXPECT_EQ(HTTP_CREATED, error); | |
1450 ASSERT_TRUE(resource_entry); | |
1451 EXPECT_TRUE(resource_entry->is_file()); | |
1452 EXPECT_EQ(kContentType, resource_entry->content_mime_type()); | |
1453 EXPECT_EQ(kContentSize, resource_entry->file_size()); | |
1454 EXPECT_EQ("resource_id_1", resource_entry->resource_id()); | |
1455 EXPECT_EQ(kTitle, resource_entry->title()); | |
1456 EXPECT_TRUE(HasParent(resource_entry->resource_id(), | |
1457 fake_service_.GetRootResourceId())); | |
1458 // Should be incremented as a new directory was created. | |
1459 EXPECT_EQ(old_largest_change_id + 1, fake_service_.largest_changestamp()); | |
1460 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | |
1461 } | |
1462 | |
1463 TEST_F(FakeDriveServiceTest, AddNewFile_ToRootDirectoryOnEmptyFileSystem) { | |
1464 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | |
1465 "chromeos/gdata/empty_feed.json")); | |
1466 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi( | |
1467 "chromeos/gdata/account_metadata.json")); | |
1468 | |
1469 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | |
1470 | |
1471 const std::string kContentType = "text/plain"; | |
1472 const int64 kContentSize = 123; | |
1473 const std::string kTitle = "new file"; | |
1474 | |
1475 GDataErrorCode error = GDATA_OTHER_ERROR; | |
1476 scoped_ptr<ResourceEntry> resource_entry; | |
1477 fake_service_.AddNewFile( | |
1478 kContentType, | |
1479 kContentSize, | |
1480 fake_service_.GetRootResourceId(), | |
1481 kTitle, | |
1482 test_util::CreateCopyResultCallback(&error, &resource_entry)); | |
1483 message_loop_.RunUntilIdle(); | |
1484 | |
1485 EXPECT_EQ(HTTP_CREATED, error); | |
1486 ASSERT_TRUE(resource_entry); | |
1487 EXPECT_TRUE(resource_entry->is_file()); | |
1488 EXPECT_EQ(kContentType, resource_entry->content_mime_type()); | |
1489 EXPECT_EQ(kContentSize, resource_entry->file_size()); | |
1490 EXPECT_EQ("resource_id_1", resource_entry->resource_id()); | |
1491 EXPECT_EQ(kTitle, resource_entry->title()); | |
1492 EXPECT_TRUE(HasParent(resource_entry->resource_id(), | |
1493 fake_service_.GetRootResourceId())); | |
1494 // Should be incremented as a new directory was created. | |
1495 EXPECT_EQ(old_largest_change_id + 1, fake_service_.largest_changestamp()); | |
1496 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | |
1497 } | |
1498 | |
1499 TEST_F(FakeDriveServiceTest, AddNewFile_ToNonRootDirectory) { | |
1500 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | |
1501 "chromeos/gdata/root_feed.json")); | |
1502 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi( | |
1503 "chromeos/gdata/account_metadata.json")); | |
1504 | |
1505 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | |
1506 | |
1507 const std::string kContentType = "text/plain"; | |
1508 const int64 kContentSize = 123; | |
1509 const std::string kTitle = "new file"; | |
1510 const std::string kParentResourceId = "folder:1_folder_resource_id"; | |
1511 | |
1512 GDataErrorCode error = GDATA_OTHER_ERROR; | |
1513 scoped_ptr<ResourceEntry> resource_entry; | |
1514 fake_service_.AddNewFile( | |
1515 kContentType, | |
1516 kContentSize, | |
1517 kParentResourceId, | |
1518 kTitle, | |
1519 test_util::CreateCopyResultCallback(&error, &resource_entry)); | |
1520 message_loop_.RunUntilIdle(); | |
1521 | |
1522 EXPECT_EQ(HTTP_CREATED, error); | |
1523 ASSERT_TRUE(resource_entry); | |
1524 EXPECT_TRUE(resource_entry->is_file()); | |
1525 EXPECT_EQ(kContentType, resource_entry->content_mime_type()); | |
1526 EXPECT_EQ(kContentSize, resource_entry->file_size()); | |
1527 EXPECT_EQ("resource_id_1", resource_entry->resource_id()); | |
1528 EXPECT_EQ(kTitle, resource_entry->title()); | |
1529 EXPECT_TRUE(HasParent(resource_entry->resource_id(), kParentResourceId)); | |
1530 // Should be incremented as a new directory was created. | |
1531 EXPECT_EQ(old_largest_change_id + 1, fake_service_.largest_changestamp()); | |
1532 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | |
1533 } | |
1534 | |
1535 TEST_F(FakeDriveServiceTest, AddNewFile_ToNonexistingDirectory) { | |
1536 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | |
1537 "chromeos/gdata/root_feed.json")); | |
1538 | |
1539 const std::string kContentType = "text/plain"; | |
1540 const int64 kContentSize = 123; | |
1541 const std::string kTitle = "new file"; | |
1542 const std::string kParentResourceId = "folder:nonexisting_resource_id"; | |
1543 | |
1544 GDataErrorCode error = GDATA_OTHER_ERROR; | |
1545 scoped_ptr<ResourceEntry> resource_entry; | |
1546 fake_service_.AddNewFile( | |
1547 kContentType, | |
1548 kContentSize, | |
1549 kParentResourceId, | |
1550 kTitle, | |
1551 test_util::CreateCopyResultCallback(&error, &resource_entry)); | |
1552 message_loop_.RunUntilIdle(); | |
1553 | |
1554 EXPECT_EQ(HTTP_NOT_FOUND, error); | |
1555 EXPECT_FALSE(resource_entry); | |
1556 } | |
1557 | |
1558 TEST_F(FakeDriveServiceTest, AddNewFile_Offline) { | |
1559 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | |
1560 "chromeos/gdata/root_feed.json")); | |
1561 fake_service_.set_offline(true); | |
1562 | |
1563 const std::string kContentType = "text/plain"; | |
1564 const int64 kContentSize = 123; | |
1565 const std::string kTitle = "new file"; | |
1566 | |
1567 GDataErrorCode error = GDATA_OTHER_ERROR; | |
1568 scoped_ptr<ResourceEntry> resource_entry; | |
1569 fake_service_.AddNewFile( | |
1570 kContentType, | |
1571 kContentSize, | |
1572 fake_service_.GetRootResourceId(), | |
1573 kTitle, | |
1574 test_util::CreateCopyResultCallback(&error, &resource_entry)); | |
1575 message_loop_.RunUntilIdle(); | |
1576 | |
1577 EXPECT_EQ(GDATA_NO_CONNECTION, error); | |
1578 EXPECT_FALSE(resource_entry); | |
1579 } | |
1580 | |
1581 TEST_F(FakeDriveServiceTest, SetLastModifiedTime_ExistingFile) { | |
1582 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | |
1583 "chromeos/gdata/root_feed.json")); | |
1584 | |
1585 const std::string kResourceId = "file:2_file_resource_id"; | |
1586 base::Time time; | |
1587 ASSERT_TRUE(base::Time::FromString("1 April 2013 12:34:56", &time)); | |
1588 | |
1589 GDataErrorCode error = GDATA_OTHER_ERROR; | |
1590 scoped_ptr<ResourceEntry> resource_entry; | |
1591 fake_service_.SetLastModifiedTime( | |
1592 kResourceId, | |
1593 time, | |
1594 test_util::CreateCopyResultCallback(&error, &resource_entry)); | |
1595 message_loop_.RunUntilIdle(); | |
1596 | |
1597 EXPECT_EQ(HTTP_CREATED, error); | |
kinaba
2013/04/03 08:17:33
HTTP_SUCCESS?
satorux1
2013/04/03 08:33:32
Done.
| |
1598 ASSERT_TRUE(resource_entry); | |
1599 EXPECT_EQ(time, resource_entry->updated_time()); | |
1600 } | |
1601 | |
1602 TEST_F(FakeDriveServiceTest, SetLastModifiedTime_NonexistingFile) { | |
1603 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | |
1604 "chromeos/gdata/root_feed.json")); | |
1605 | |
1606 const std::string kResourceId = "file:nonexisting_resource_id"; | |
1607 base::Time time; | |
1608 ASSERT_TRUE(base::Time::FromString("1 April 2013 12:34:56", &time)); | |
1609 | |
1610 GDataErrorCode error = GDATA_OTHER_ERROR; | |
1611 scoped_ptr<ResourceEntry> resource_entry; | |
1612 fake_service_.SetLastModifiedTime( | |
1613 kResourceId, | |
1614 time, | |
1615 test_util::CreateCopyResultCallback(&error, &resource_entry)); | |
1616 message_loop_.RunUntilIdle(); | |
1617 | |
1618 EXPECT_EQ(HTTP_NOT_FOUND, error); | |
1619 EXPECT_FALSE(resource_entry); | |
1620 } | |
1621 | |
1622 TEST_F(FakeDriveServiceTest, SetLastModifiedTime_Offline) { | |
1623 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | |
1624 "chromeos/gdata/root_feed.json")); | |
1625 fake_service_.set_offline(true); | |
1626 | |
1627 const std::string kResourceId = "file:2_file_resource_id"; | |
1628 base::Time time; | |
1629 ASSERT_TRUE(base::Time::FromString("1 April 2013 12:34:56", &time)); | |
1630 | |
1631 GDataErrorCode error = GDATA_OTHER_ERROR; | |
1632 scoped_ptr<ResourceEntry> resource_entry; | |
1633 fake_service_.SetLastModifiedTime( | |
1634 kResourceId, | |
1635 time, | |
1636 test_util::CreateCopyResultCallback(&error, &resource_entry)); | |
1637 message_loop_.RunUntilIdle(); | |
1638 | |
1639 EXPECT_EQ(GDATA_NO_CONNECTION, error); | |
1640 EXPECT_FALSE(resource_entry); | |
1641 } | |
1642 | |
1424 } // namespace | 1643 } // namespace |
1425 | 1644 |
1426 } // namespace google_apis | 1645 } // namespace google_apis |
OLD | NEW |