| 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/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 return entry && !entry->labels().is_trashed(); | 72 return entry && !entry->labels().is_trashed(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 // Adds a new directory at |parent_resource_id| with the given name. | 75 // Adds a new directory at |parent_resource_id| with the given name. |
| 76 // Returns true on success. | 76 // Returns true on success. |
| 77 bool AddNewDirectory(const std::string& parent_resource_id, | 77 bool AddNewDirectory(const std::string& parent_resource_id, |
| 78 const std::string& directory_title) { | 78 const std::string& directory_title) { |
| 79 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 79 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 80 scoped_ptr<FileResource> entry; | 80 scoped_ptr<FileResource> entry; |
| 81 fake_service_.AddNewDirectory( | 81 fake_service_.AddNewDirectory( |
| 82 parent_resource_id, | 82 parent_resource_id, directory_title, AddNewDirectoryOptions(), |
| 83 directory_title, | |
| 84 DriveServiceInterface::AddNewDirectoryOptions(), | |
| 85 test_util::CreateCopyResultCallback(&error, &entry)); | 83 test_util::CreateCopyResultCallback(&error, &entry)); |
| 86 base::RunLoop().RunUntilIdle(); | 84 base::RunLoop().RunUntilIdle(); |
| 87 return error == HTTP_CREATED; | 85 return error == HTTP_CREATED; |
| 88 } | 86 } |
| 89 | 87 |
| 90 // Returns true if the resource identified by |resource_id| has a parent | 88 // Returns true if the resource identified by |resource_id| has a parent |
| 91 // identified by |parent_id|. | 89 // identified by |parent_id|. |
| 92 bool HasParent(const std::string& resource_id, const std::string& parent_id) { | 90 bool HasParent(const std::string& resource_id, const std::string& parent_id) { |
| 93 scoped_ptr<FileResource> entry = FindEntry(resource_id); | 91 scoped_ptr<FileResource> entry = FindEntry(resource_id); |
| 94 if (entry) { | 92 if (entry) { |
| (...skipping 1379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1474 } | 1472 } |
| 1475 | 1473 |
| 1476 TEST_F(FakeDriveServiceTest, AddNewDirectory_EmptyParent) { | 1474 TEST_F(FakeDriveServiceTest, AddNewDirectory_EmptyParent) { |
| 1477 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1475 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1478 | 1476 |
| 1479 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1477 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
| 1480 | 1478 |
| 1481 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 1479 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1482 scoped_ptr<FileResource> entry; | 1480 scoped_ptr<FileResource> entry; |
| 1483 fake_service_.AddNewDirectory( | 1481 fake_service_.AddNewDirectory( |
| 1484 std::string(), | 1482 std::string(), "new directory", AddNewDirectoryOptions(), |
| 1485 "new directory", | |
| 1486 DriveServiceInterface::AddNewDirectoryOptions(), | |
| 1487 test_util::CreateCopyResultCallback(&error, &entry)); | 1483 test_util::CreateCopyResultCallback(&error, &entry)); |
| 1488 base::RunLoop().RunUntilIdle(); | 1484 base::RunLoop().RunUntilIdle(); |
| 1489 | 1485 |
| 1490 EXPECT_EQ(HTTP_CREATED, error); | 1486 EXPECT_EQ(HTTP_CREATED, error); |
| 1491 ASSERT_TRUE(entry); | 1487 ASSERT_TRUE(entry); |
| 1492 EXPECT_TRUE(entry->IsDirectory()); | 1488 EXPECT_TRUE(entry->IsDirectory()); |
| 1493 EXPECT_EQ("resource_id_1", entry->file_id()); | 1489 EXPECT_EQ("resource_id_1", entry->file_id()); |
| 1494 EXPECT_EQ("new directory", entry->title()); | 1490 EXPECT_EQ("new directory", entry->title()); |
| 1495 EXPECT_TRUE(HasParent(entry->file_id(), fake_service_.GetRootResourceId())); | 1491 EXPECT_TRUE(HasParent(entry->file_id(), fake_service_.GetRootResourceId())); |
| 1496 // Should be incremented as a new directory was created. | 1492 // Should be incremented as a new directory was created. |
| 1497 EXPECT_EQ(old_largest_change_id + 1, | 1493 EXPECT_EQ(old_largest_change_id + 1, |
| 1498 fake_service_.about_resource().largest_change_id()); | 1494 fake_service_.about_resource().largest_change_id()); |
| 1499 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1495 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
| 1500 } | 1496 } |
| 1501 | 1497 |
| 1502 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToRootDirectory) { | 1498 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToRootDirectory) { |
| 1503 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1499 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1504 | 1500 |
| 1505 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1501 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
| 1506 | 1502 |
| 1507 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 1503 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1508 scoped_ptr<FileResource> entry; | 1504 scoped_ptr<FileResource> entry; |
| 1509 fake_service_.AddNewDirectory( | 1505 fake_service_.AddNewDirectory( |
| 1510 fake_service_.GetRootResourceId(), | 1506 fake_service_.GetRootResourceId(), "new directory", |
| 1511 "new directory", | 1507 AddNewDirectoryOptions(), |
| 1512 DriveServiceInterface::AddNewDirectoryOptions(), | |
| 1513 test_util::CreateCopyResultCallback(&error, &entry)); | 1508 test_util::CreateCopyResultCallback(&error, &entry)); |
| 1514 base::RunLoop().RunUntilIdle(); | 1509 base::RunLoop().RunUntilIdle(); |
| 1515 | 1510 |
| 1516 EXPECT_EQ(HTTP_CREATED, error); | 1511 EXPECT_EQ(HTTP_CREATED, error); |
| 1517 ASSERT_TRUE(entry); | 1512 ASSERT_TRUE(entry); |
| 1518 EXPECT_TRUE(entry->IsDirectory()); | 1513 EXPECT_TRUE(entry->IsDirectory()); |
| 1519 EXPECT_EQ("resource_id_1", entry->file_id()); | 1514 EXPECT_EQ("resource_id_1", entry->file_id()); |
| 1520 EXPECT_EQ("new directory", entry->title()); | 1515 EXPECT_EQ("new directory", entry->title()); |
| 1521 EXPECT_TRUE(HasParent(entry->file_id(), fake_service_.GetRootResourceId())); | 1516 EXPECT_TRUE(HasParent(entry->file_id(), fake_service_.GetRootResourceId())); |
| 1522 // Should be incremented as a new directory was created. | 1517 // Should be incremented as a new directory was created. |
| 1523 EXPECT_EQ(old_largest_change_id + 1, | 1518 EXPECT_EQ(old_largest_change_id + 1, |
| 1524 fake_service_.about_resource().largest_change_id()); | 1519 fake_service_.about_resource().largest_change_id()); |
| 1525 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1520 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
| 1526 } | 1521 } |
| 1527 | 1522 |
| 1528 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToRootDirectoryOnEmptyFileSystem) { | 1523 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToRootDirectoryOnEmptyFileSystem) { |
| 1529 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1524 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
| 1530 | 1525 |
| 1531 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 1526 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1532 scoped_ptr<FileResource> entry; | 1527 scoped_ptr<FileResource> entry; |
| 1533 fake_service_.AddNewDirectory( | 1528 fake_service_.AddNewDirectory( |
| 1534 fake_service_.GetRootResourceId(), | 1529 fake_service_.GetRootResourceId(), "new directory", |
| 1535 "new directory", | 1530 AddNewDirectoryOptions(), |
| 1536 DriveServiceInterface::AddNewDirectoryOptions(), | |
| 1537 test_util::CreateCopyResultCallback(&error, &entry)); | 1531 test_util::CreateCopyResultCallback(&error, &entry)); |
| 1538 base::RunLoop().RunUntilIdle(); | 1532 base::RunLoop().RunUntilIdle(); |
| 1539 | 1533 |
| 1540 EXPECT_EQ(HTTP_CREATED, error); | 1534 EXPECT_EQ(HTTP_CREATED, error); |
| 1541 ASSERT_TRUE(entry); | 1535 ASSERT_TRUE(entry); |
| 1542 EXPECT_TRUE(entry->IsDirectory()); | 1536 EXPECT_TRUE(entry->IsDirectory()); |
| 1543 EXPECT_EQ("resource_id_1", entry->file_id()); | 1537 EXPECT_EQ("resource_id_1", entry->file_id()); |
| 1544 EXPECT_EQ("new directory", entry->title()); | 1538 EXPECT_EQ("new directory", entry->title()); |
| 1545 EXPECT_TRUE(HasParent(entry->file_id(), fake_service_.GetRootResourceId())); | 1539 EXPECT_TRUE(HasParent(entry->file_id(), fake_service_.GetRootResourceId())); |
| 1546 // Should be incremented as a new directory was created. | 1540 // Should be incremented as a new directory was created. |
| 1547 EXPECT_EQ(old_largest_change_id + 1, | 1541 EXPECT_EQ(old_largest_change_id + 1, |
| 1548 fake_service_.about_resource().largest_change_id()); | 1542 fake_service_.about_resource().largest_change_id()); |
| 1549 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1543 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
| 1550 } | 1544 } |
| 1551 | 1545 |
| 1552 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToNonRootDirectory) { | 1546 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToNonRootDirectory) { |
| 1553 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1547 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1554 | 1548 |
| 1555 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1549 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
| 1556 | 1550 |
| 1557 const std::string kParentResourceId = "1_folder_resource_id"; | 1551 const std::string kParentResourceId = "1_folder_resource_id"; |
| 1558 | 1552 |
| 1559 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 1553 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1560 scoped_ptr<FileResource> entry; | 1554 scoped_ptr<FileResource> entry; |
| 1561 fake_service_.AddNewDirectory( | 1555 fake_service_.AddNewDirectory( |
| 1562 kParentResourceId, | 1556 kParentResourceId, "new directory", AddNewDirectoryOptions(), |
| 1563 "new directory", | |
| 1564 DriveServiceInterface::AddNewDirectoryOptions(), | |
| 1565 test_util::CreateCopyResultCallback(&error, &entry)); | 1557 test_util::CreateCopyResultCallback(&error, &entry)); |
| 1566 base::RunLoop().RunUntilIdle(); | 1558 base::RunLoop().RunUntilIdle(); |
| 1567 | 1559 |
| 1568 EXPECT_EQ(HTTP_CREATED, error); | 1560 EXPECT_EQ(HTTP_CREATED, error); |
| 1569 ASSERT_TRUE(entry); | 1561 ASSERT_TRUE(entry); |
| 1570 EXPECT_TRUE(entry->IsDirectory()); | 1562 EXPECT_TRUE(entry->IsDirectory()); |
| 1571 EXPECT_EQ("resource_id_1", entry->file_id()); | 1563 EXPECT_EQ("resource_id_1", entry->file_id()); |
| 1572 EXPECT_EQ("new directory", entry->title()); | 1564 EXPECT_EQ("new directory", entry->title()); |
| 1573 EXPECT_TRUE(HasParent(entry->file_id(), kParentResourceId)); | 1565 EXPECT_TRUE(HasParent(entry->file_id(), kParentResourceId)); |
| 1574 // Should be incremented as a new directory was created. | 1566 // Should be incremented as a new directory was created. |
| 1575 EXPECT_EQ(old_largest_change_id + 1, | 1567 EXPECT_EQ(old_largest_change_id + 1, |
| 1576 fake_service_.about_resource().largest_change_id()); | 1568 fake_service_.about_resource().largest_change_id()); |
| 1577 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1569 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
| 1578 } | 1570 } |
| 1579 | 1571 |
| 1580 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToNonexistingDirectory) { | 1572 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToNonexistingDirectory) { |
| 1581 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1573 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1582 | 1574 |
| 1583 const std::string kParentResourceId = "nonexisting_resource_id"; | 1575 const std::string kParentResourceId = "nonexisting_resource_id"; |
| 1584 | 1576 |
| 1585 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 1577 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1586 scoped_ptr<FileResource> entry; | 1578 scoped_ptr<FileResource> entry; |
| 1587 fake_service_.AddNewDirectory( | 1579 fake_service_.AddNewDirectory( |
| 1588 kParentResourceId, | 1580 kParentResourceId, "new directory", AddNewDirectoryOptions(), |
| 1589 "new directory", | |
| 1590 DriveServiceInterface::AddNewDirectoryOptions(), | |
| 1591 test_util::CreateCopyResultCallback(&error, &entry)); | 1581 test_util::CreateCopyResultCallback(&error, &entry)); |
| 1592 base::RunLoop().RunUntilIdle(); | 1582 base::RunLoop().RunUntilIdle(); |
| 1593 | 1583 |
| 1594 EXPECT_EQ(HTTP_NOT_FOUND, error); | 1584 EXPECT_EQ(HTTP_NOT_FOUND, error); |
| 1595 EXPECT_FALSE(entry); | 1585 EXPECT_FALSE(entry); |
| 1596 } | 1586 } |
| 1597 | 1587 |
| 1598 TEST_F(FakeDriveServiceTest, AddNewDirectory_Offline) { | 1588 TEST_F(FakeDriveServiceTest, AddNewDirectory_Offline) { |
| 1599 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1589 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1600 fake_service_.set_offline(true); | 1590 fake_service_.set_offline(true); |
| 1601 | 1591 |
| 1602 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 1592 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1603 scoped_ptr<FileResource> entry; | 1593 scoped_ptr<FileResource> entry; |
| 1604 fake_service_.AddNewDirectory( | 1594 fake_service_.AddNewDirectory( |
| 1605 fake_service_.GetRootResourceId(), | 1595 fake_service_.GetRootResourceId(), "new directory", |
| 1606 "new directory", | 1596 AddNewDirectoryOptions(), |
| 1607 DriveServiceInterface::AddNewDirectoryOptions(), | |
| 1608 test_util::CreateCopyResultCallback(&error, &entry)); | 1597 test_util::CreateCopyResultCallback(&error, &entry)); |
| 1609 base::RunLoop().RunUntilIdle(); | 1598 base::RunLoop().RunUntilIdle(); |
| 1610 | 1599 |
| 1611 EXPECT_EQ(DRIVE_NO_CONNECTION, error); | 1600 EXPECT_EQ(DRIVE_NO_CONNECTION, error); |
| 1612 EXPECT_FALSE(entry); | 1601 EXPECT_FALSE(entry); |
| 1613 } | 1602 } |
| 1614 | 1603 |
| 1615 TEST_F(FakeDriveServiceTest, InitiateUploadNewFile_Offline) { | 1604 TEST_F(FakeDriveServiceTest, InitiateUploadNewFile_Offline) { |
| 1616 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1605 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1617 fake_service_.set_offline(true); | 1606 fake_service_.set_offline(true); |
| 1618 | 1607 |
| 1619 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 1608 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1620 GURL upload_location; | 1609 GURL upload_location; |
| 1621 fake_service_.InitiateUploadNewFile( | 1610 fake_service_.InitiateUploadNewFile( |
| 1622 "test/foo", 13, "1_folder_resource_id", "new file.foo", | 1611 "test/foo", 13, "1_folder_resource_id", "new file.foo", |
| 1623 FakeDriveService::UploadNewFileOptions(), | 1612 UploadNewFileOptions(), |
| 1624 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1613 test_util::CreateCopyResultCallback(&error, &upload_location)); |
| 1625 base::RunLoop().RunUntilIdle(); | 1614 base::RunLoop().RunUntilIdle(); |
| 1626 | 1615 |
| 1627 EXPECT_EQ(DRIVE_NO_CONNECTION, error); | 1616 EXPECT_EQ(DRIVE_NO_CONNECTION, error); |
| 1628 EXPECT_TRUE(upload_location.is_empty()); | 1617 EXPECT_TRUE(upload_location.is_empty()); |
| 1629 } | 1618 } |
| 1630 | 1619 |
| 1631 TEST_F(FakeDriveServiceTest, InitiateUploadNewFile_NotFound) { | 1620 TEST_F(FakeDriveServiceTest, InitiateUploadNewFile_NotFound) { |
| 1632 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1621 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1633 | 1622 |
| 1634 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 1623 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1635 GURL upload_location; | 1624 GURL upload_location; |
| 1636 fake_service_.InitiateUploadNewFile( | 1625 fake_service_.InitiateUploadNewFile( |
| 1637 "test/foo", 13, "non_existent", "new file.foo", | 1626 "test/foo", 13, "non_existent", "new file.foo", |
| 1638 FakeDriveService::UploadNewFileOptions(), | 1627 UploadNewFileOptions(), |
| 1639 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1628 test_util::CreateCopyResultCallback(&error, &upload_location)); |
| 1640 base::RunLoop().RunUntilIdle(); | 1629 base::RunLoop().RunUntilIdle(); |
| 1641 | 1630 |
| 1642 EXPECT_EQ(HTTP_NOT_FOUND, error); | 1631 EXPECT_EQ(HTTP_NOT_FOUND, error); |
| 1643 EXPECT_TRUE(upload_location.is_empty()); | 1632 EXPECT_TRUE(upload_location.is_empty()); |
| 1644 } | 1633 } |
| 1645 | 1634 |
| 1646 TEST_F(FakeDriveServiceTest, InitiateUploadNewFile) { | 1635 TEST_F(FakeDriveServiceTest, InitiateUploadNewFile) { |
| 1647 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1636 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1648 | 1637 |
| 1649 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 1638 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1650 GURL upload_location; | 1639 GURL upload_location; |
| 1651 fake_service_.InitiateUploadNewFile( | 1640 fake_service_.InitiateUploadNewFile( |
| 1652 "test/foo", 13, "1_folder_resource_id", "new file.foo", | 1641 "test/foo", 13, "1_folder_resource_id", "new file.foo", |
| 1653 FakeDriveService::UploadNewFileOptions(), | 1642 UploadNewFileOptions(), |
| 1654 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1643 test_util::CreateCopyResultCallback(&error, &upload_location)); |
| 1655 base::RunLoop().RunUntilIdle(); | 1644 base::RunLoop().RunUntilIdle(); |
| 1656 | 1645 |
| 1657 EXPECT_EQ(HTTP_SUCCESS, error); | 1646 EXPECT_EQ(HTTP_SUCCESS, error); |
| 1658 EXPECT_FALSE(upload_location.is_empty()); | 1647 EXPECT_FALSE(upload_location.is_empty()); |
| 1659 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link?mode=newfile"), | 1648 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link?mode=newfile"), |
| 1660 upload_location); | 1649 upload_location); |
| 1661 } | 1650 } |
| 1662 | 1651 |
| 1663 TEST_F(FakeDriveServiceTest, InitiateUploadExistingFile_Offline) { | 1652 TEST_F(FakeDriveServiceTest, InitiateUploadExistingFile_Offline) { |
| 1664 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1653 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1665 fake_service_.set_offline(true); | 1654 fake_service_.set_offline(true); |
| 1666 | 1655 |
| 1667 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 1656 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1668 GURL upload_location; | 1657 GURL upload_location; |
| 1669 fake_service_.InitiateUploadExistingFile( | 1658 fake_service_.InitiateUploadExistingFile( |
| 1670 "test/foo", 13, "2_file_resource_id", | 1659 "test/foo", 13, "2_file_resource_id", |
| 1671 FakeDriveService::UploadExistingFileOptions(), | 1660 UploadExistingFileOptions(), |
| 1672 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1661 test_util::CreateCopyResultCallback(&error, &upload_location)); |
| 1673 base::RunLoop().RunUntilIdle(); | 1662 base::RunLoop().RunUntilIdle(); |
| 1674 | 1663 |
| 1675 EXPECT_EQ(DRIVE_NO_CONNECTION, error); | 1664 EXPECT_EQ(DRIVE_NO_CONNECTION, error); |
| 1676 EXPECT_TRUE(upload_location.is_empty()); | 1665 EXPECT_TRUE(upload_location.is_empty()); |
| 1677 } | 1666 } |
| 1678 | 1667 |
| 1679 TEST_F(FakeDriveServiceTest, InitiateUploadExistingFile_Forbidden) { | 1668 TEST_F(FakeDriveServiceTest, InitiateUploadExistingFile_Forbidden) { |
| 1680 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1669 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1681 | 1670 |
| 1682 EXPECT_EQ(HTTP_SUCCESS, fake_service_.SetUserPermission( | 1671 EXPECT_EQ(HTTP_SUCCESS, fake_service_.SetUserPermission( |
| 1683 "2_file_resource_id", google_apis::drive::PERMISSION_ROLE_READER)); | 1672 "2_file_resource_id", google_apis::drive::PERMISSION_ROLE_READER)); |
| 1684 | 1673 |
| 1685 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 1674 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1686 GURL upload_location; | 1675 GURL upload_location; |
| 1687 fake_service_.InitiateUploadExistingFile( | 1676 fake_service_.InitiateUploadExistingFile( |
| 1688 "test/foo", 13, "2_file_resource_id", | 1677 "test/foo", 13, "2_file_resource_id", |
| 1689 FakeDriveService::UploadExistingFileOptions(), | 1678 UploadExistingFileOptions(), |
| 1690 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1679 test_util::CreateCopyResultCallback(&error, &upload_location)); |
| 1691 base::RunLoop().RunUntilIdle(); | 1680 base::RunLoop().RunUntilIdle(); |
| 1692 | 1681 |
| 1693 EXPECT_EQ(HTTP_FORBIDDEN, error); | 1682 EXPECT_EQ(HTTP_FORBIDDEN, error); |
| 1694 EXPECT_TRUE(upload_location.is_empty()); | 1683 EXPECT_TRUE(upload_location.is_empty()); |
| 1695 } | 1684 } |
| 1696 | 1685 |
| 1697 TEST_F(FakeDriveServiceTest, InitiateUploadExistingFile_NotFound) { | 1686 TEST_F(FakeDriveServiceTest, InitiateUploadExistingFile_NotFound) { |
| 1698 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1687 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1699 | 1688 |
| 1700 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 1689 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1701 GURL upload_location; | 1690 GURL upload_location; |
| 1702 fake_service_.InitiateUploadExistingFile( | 1691 fake_service_.InitiateUploadExistingFile( |
| 1703 "test/foo", 13, "non_existent", | 1692 "test/foo", 13, "non_existent", |
| 1704 FakeDriveService::UploadExistingFileOptions(), | 1693 UploadExistingFileOptions(), |
| 1705 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1694 test_util::CreateCopyResultCallback(&error, &upload_location)); |
| 1706 base::RunLoop().RunUntilIdle(); | 1695 base::RunLoop().RunUntilIdle(); |
| 1707 | 1696 |
| 1708 EXPECT_EQ(HTTP_NOT_FOUND, error); | 1697 EXPECT_EQ(HTTP_NOT_FOUND, error); |
| 1709 EXPECT_TRUE(upload_location.is_empty()); | 1698 EXPECT_TRUE(upload_location.is_empty()); |
| 1710 } | 1699 } |
| 1711 | 1700 |
| 1712 TEST_F(FakeDriveServiceTest, InitiateUploadExistingFile_WrongETag) { | 1701 TEST_F(FakeDriveServiceTest, InitiateUploadExistingFile_WrongETag) { |
| 1713 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1702 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1714 | 1703 |
| 1715 FakeDriveService::UploadExistingFileOptions options; | 1704 UploadExistingFileOptions options; |
| 1716 options.etag = "invalid_etag"; | 1705 options.etag = "invalid_etag"; |
| 1717 | 1706 |
| 1718 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 1707 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1719 GURL upload_location; | 1708 GURL upload_location; |
| 1720 fake_service_.InitiateUploadExistingFile( | 1709 fake_service_.InitiateUploadExistingFile( |
| 1721 "text/plain", | 1710 "text/plain", |
| 1722 13, | 1711 13, |
| 1723 "2_file_resource_id", | 1712 "2_file_resource_id", |
| 1724 options, | 1713 options, |
| 1725 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1714 test_util::CreateCopyResultCallback(&error, &upload_location)); |
| 1726 base::RunLoop().RunUntilIdle(); | 1715 base::RunLoop().RunUntilIdle(); |
| 1727 | 1716 |
| 1728 EXPECT_EQ(HTTP_PRECONDITION, error); | 1717 EXPECT_EQ(HTTP_PRECONDITION, error); |
| 1729 EXPECT_TRUE(upload_location.is_empty()); | 1718 EXPECT_TRUE(upload_location.is_empty()); |
| 1730 } | 1719 } |
| 1731 | 1720 |
| 1732 TEST_F(FakeDriveServiceTest, InitiateUpload_ExistingFile) { | 1721 TEST_F(FakeDriveServiceTest, InitiateUpload_ExistingFile) { |
| 1733 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1722 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1734 | 1723 |
| 1735 scoped_ptr<FileResource> entry = FindEntry("2_file_resource_id"); | 1724 scoped_ptr<FileResource> entry = FindEntry("2_file_resource_id"); |
| 1736 ASSERT_TRUE(entry); | 1725 ASSERT_TRUE(entry); |
| 1737 | 1726 |
| 1738 FakeDriveService::UploadExistingFileOptions options; | 1727 UploadExistingFileOptions options; |
| 1739 options.etag = entry->etag(); | 1728 options.etag = entry->etag(); |
| 1740 | 1729 |
| 1741 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 1730 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1742 GURL upload_location; | 1731 GURL upload_location; |
| 1743 fake_service_.InitiateUploadExistingFile( | 1732 fake_service_.InitiateUploadExistingFile( |
| 1744 "text/plain", | 1733 "text/plain", |
| 1745 13, | 1734 13, |
| 1746 "2_file_resource_id", | 1735 "2_file_resource_id", |
| 1747 options, | 1736 options, |
| 1748 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1737 test_util::CreateCopyResultCallback(&error, &upload_location)); |
| 1749 base::RunLoop().RunUntilIdle(); | 1738 base::RunLoop().RunUntilIdle(); |
| 1750 | 1739 |
| 1751 EXPECT_EQ(HTTP_SUCCESS, error); | 1740 EXPECT_EQ(HTTP_SUCCESS, error); |
| 1752 EXPECT_TRUE(upload_location.is_valid()); | 1741 EXPECT_TRUE(upload_location.is_valid()); |
| 1753 } | 1742 } |
| 1754 | 1743 |
| 1755 TEST_F(FakeDriveServiceTest, ResumeUpload_Offline) { | 1744 TEST_F(FakeDriveServiceTest, ResumeUpload_Offline) { |
| 1756 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1745 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1757 | 1746 |
| 1758 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 1747 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1759 GURL upload_location; | 1748 GURL upload_location; |
| 1760 fake_service_.InitiateUploadNewFile( | 1749 fake_service_.InitiateUploadNewFile( |
| 1761 "test/foo", 15, "1_folder_resource_id", "new file.foo", | 1750 "test/foo", 15, "1_folder_resource_id", "new file.foo", |
| 1762 FakeDriveService::UploadNewFileOptions(), | 1751 UploadNewFileOptions(), |
| 1763 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1752 test_util::CreateCopyResultCallback(&error, &upload_location)); |
| 1764 base::RunLoop().RunUntilIdle(); | 1753 base::RunLoop().RunUntilIdle(); |
| 1765 | 1754 |
| 1766 EXPECT_EQ(HTTP_SUCCESS, error); | 1755 EXPECT_EQ(HTTP_SUCCESS, error); |
| 1767 EXPECT_FALSE(upload_location.is_empty()); | 1756 EXPECT_FALSE(upload_location.is_empty()); |
| 1768 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link"), | 1757 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link"), |
| 1769 upload_location); | 1758 upload_location); |
| 1770 | 1759 |
| 1771 fake_service_.set_offline(true); | 1760 fake_service_.set_offline(true); |
| 1772 | 1761 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1784 EXPECT_FALSE(entry.get()); | 1773 EXPECT_FALSE(entry.get()); |
| 1785 } | 1774 } |
| 1786 | 1775 |
| 1787 TEST_F(FakeDriveServiceTest, ResumeUpload_NotFound) { | 1776 TEST_F(FakeDriveServiceTest, ResumeUpload_NotFound) { |
| 1788 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1777 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1789 | 1778 |
| 1790 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 1779 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1791 GURL upload_location; | 1780 GURL upload_location; |
| 1792 fake_service_.InitiateUploadNewFile( | 1781 fake_service_.InitiateUploadNewFile( |
| 1793 "test/foo", 15, "1_folder_resource_id", "new file.foo", | 1782 "test/foo", 15, "1_folder_resource_id", "new file.foo", |
| 1794 FakeDriveService::UploadNewFileOptions(), | 1783 UploadNewFileOptions(), |
| 1795 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1784 test_util::CreateCopyResultCallback(&error, &upload_location)); |
| 1796 base::RunLoop().RunUntilIdle(); | 1785 base::RunLoop().RunUntilIdle(); |
| 1797 | 1786 |
| 1798 ASSERT_EQ(HTTP_SUCCESS, error); | 1787 ASSERT_EQ(HTTP_SUCCESS, error); |
| 1799 | 1788 |
| 1800 UploadRangeResponse response; | 1789 UploadRangeResponse response; |
| 1801 scoped_ptr<FileResource> entry; | 1790 scoped_ptr<FileResource> entry; |
| 1802 fake_service_.ResumeUpload( | 1791 fake_service_.ResumeUpload( |
| 1803 GURL("https://foo.com/"), | 1792 GURL("https://foo.com/"), |
| 1804 0, 13, 15, "test/foo", | 1793 0, 13, 15, "test/foo", |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1817 base::FilePath local_file_path = | 1806 base::FilePath local_file_path = |
| 1818 temp_dir.path().Append(FILE_PATH_LITERAL("File 1.txt")); | 1807 temp_dir.path().Append(FILE_PATH_LITERAL("File 1.txt")); |
| 1819 std::string contents("hogefugapiyo"); | 1808 std::string contents("hogefugapiyo"); |
| 1820 ASSERT_TRUE(test_util::WriteStringToFile(local_file_path, contents)); | 1809 ASSERT_TRUE(test_util::WriteStringToFile(local_file_path, contents)); |
| 1821 | 1810 |
| 1822 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1811 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1823 | 1812 |
| 1824 scoped_ptr<FileResource> entry = FindEntry("2_file_resource_id"); | 1813 scoped_ptr<FileResource> entry = FindEntry("2_file_resource_id"); |
| 1825 ASSERT_TRUE(entry); | 1814 ASSERT_TRUE(entry); |
| 1826 | 1815 |
| 1827 FakeDriveService::UploadExistingFileOptions options; | 1816 UploadExistingFileOptions options; |
| 1828 options.etag = entry->etag(); | 1817 options.etag = entry->etag(); |
| 1829 | 1818 |
| 1830 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 1819 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1831 GURL upload_location; | 1820 GURL upload_location; |
| 1832 fake_service_.InitiateUploadExistingFile( | 1821 fake_service_.InitiateUploadExistingFile( |
| 1833 "text/plain", | 1822 "text/plain", |
| 1834 contents.size(), | 1823 contents.size(), |
| 1835 "2_file_resource_id", | 1824 "2_file_resource_id", |
| 1836 options, | 1825 options, |
| 1837 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1826 test_util::CreateCopyResultCallback(&error, &upload_location)); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1888 temp_dir.path().Append(FILE_PATH_LITERAL("new file.foo")); | 1877 temp_dir.path().Append(FILE_PATH_LITERAL("new file.foo")); |
| 1889 std::string contents("hogefugapiyo"); | 1878 std::string contents("hogefugapiyo"); |
| 1890 ASSERT_TRUE(test_util::WriteStringToFile(local_file_path, contents)); | 1879 ASSERT_TRUE(test_util::WriteStringToFile(local_file_path, contents)); |
| 1891 | 1880 |
| 1892 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1881 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1893 | 1882 |
| 1894 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 1883 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1895 GURL upload_location; | 1884 GURL upload_location; |
| 1896 fake_service_.InitiateUploadNewFile( | 1885 fake_service_.InitiateUploadNewFile( |
| 1897 "test/foo", contents.size(), "1_folder_resource_id", "new file.foo", | 1886 "test/foo", contents.size(), "1_folder_resource_id", "new file.foo", |
| 1898 FakeDriveService::UploadNewFileOptions(), | 1887 UploadNewFileOptions(), |
| 1899 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1888 test_util::CreateCopyResultCallback(&error, &upload_location)); |
| 1900 base::RunLoop().RunUntilIdle(); | 1889 base::RunLoop().RunUntilIdle(); |
| 1901 | 1890 |
| 1902 EXPECT_EQ(HTTP_SUCCESS, error); | 1891 EXPECT_EQ(HTTP_SUCCESS, error); |
| 1903 EXPECT_FALSE(upload_location.is_empty()); | 1892 EXPECT_FALSE(upload_location.is_empty()); |
| 1904 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link"), | 1893 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link"), |
| 1905 upload_location); | 1894 upload_location); |
| 1906 | 1895 |
| 1907 UploadRangeResponse response; | 1896 UploadRangeResponse response; |
| 1908 scoped_ptr<FileResource> entry; | 1897 scoped_ptr<FileResource> entry; |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2183 test_util::CreateCopyResultCallback(&error, &entry)); | 2172 test_util::CreateCopyResultCallback(&error, &entry)); |
| 2184 base::RunLoop().RunUntilIdle(); | 2173 base::RunLoop().RunUntilIdle(); |
| 2185 | 2174 |
| 2186 EXPECT_EQ(DRIVE_NO_CONNECTION, error); | 2175 EXPECT_EQ(DRIVE_NO_CONNECTION, error); |
| 2187 EXPECT_FALSE(entry); | 2176 EXPECT_FALSE(entry); |
| 2188 } | 2177 } |
| 2189 | 2178 |
| 2190 } // namespace | 2179 } // namespace |
| 2191 | 2180 |
| 2192 } // namespace drive | 2181 } // namespace drive |
| OLD | NEW |