| 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/chromeos/drive/file_system.h" | 5 #include "chrome/browser/chromeos/drive/file_system.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 1508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1519 | 1519 |
| 1520 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 1520 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 1521 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root)); | 1521 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root)); |
| 1522 std::string resource_id = entry->resource_id(); | 1522 std::string resource_id = entry->resource_id(); |
| 1523 | 1523 |
| 1524 FileError error = FILE_ERROR_OK; | 1524 FileError error = FILE_ERROR_OK; |
| 1525 base::FilePath file_path; | 1525 base::FilePath file_path; |
| 1526 entry.reset(); | 1526 entry.reset(); |
| 1527 file_system_->GetFileByResourceId( | 1527 file_system_->GetFileByResourceId( |
| 1528 resource_id, | 1528 resource_id, |
| 1529 DriveClientContext(USER_INITIATED), | 1529 ClientContext(USER_INITIATED), |
| 1530 google_apis::test_util::CreateCopyResultCallback( | 1530 google_apis::test_util::CreateCopyResultCallback( |
| 1531 &error, &file_path, &entry), | 1531 &error, &file_path, &entry), |
| 1532 google_apis::GetContentCallback()); | 1532 google_apis::GetContentCallback()); |
| 1533 google_apis::test_util::RunBlockingPoolTask(); | 1533 google_apis::test_util::RunBlockingPoolTask(); |
| 1534 | 1534 |
| 1535 EXPECT_EQ(FILE_ERROR_OK, error); | 1535 EXPECT_EQ(FILE_ERROR_OK, error); |
| 1536 ASSERT_TRUE(entry); | 1536 ASSERT_TRUE(entry); |
| 1537 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); | 1537 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); |
| 1538 } | 1538 } |
| 1539 | 1539 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1637 | 1637 |
| 1638 // The file is obtained from the cache. | 1638 // The file is obtained from the cache. |
| 1639 // Hence the downloading should work even if the drive service is offline. | 1639 // Hence the downloading should work even if the drive service is offline. |
| 1640 fake_drive_service_->set_offline(true); | 1640 fake_drive_service_->set_offline(true); |
| 1641 | 1641 |
| 1642 std::string resource_id = entry->resource_id(); | 1642 std::string resource_id = entry->resource_id(); |
| 1643 base::FilePath file_path; | 1643 base::FilePath file_path; |
| 1644 entry.reset(); | 1644 entry.reset(); |
| 1645 file_system_->GetFileByResourceId( | 1645 file_system_->GetFileByResourceId( |
| 1646 resource_id, | 1646 resource_id, |
| 1647 DriveClientContext(USER_INITIATED), | 1647 ClientContext(USER_INITIATED), |
| 1648 google_apis::test_util::CreateCopyResultCallback( | 1648 google_apis::test_util::CreateCopyResultCallback( |
| 1649 &error, &file_path, &entry), | 1649 &error, &file_path, &entry), |
| 1650 google_apis::GetContentCallback()); | 1650 google_apis::GetContentCallback()); |
| 1651 google_apis::test_util::RunBlockingPoolTask(); | 1651 google_apis::test_util::RunBlockingPoolTask(); |
| 1652 | 1652 |
| 1653 EXPECT_EQ(FILE_ERROR_OK, error); | 1653 EXPECT_EQ(FILE_ERROR_OK, error); |
| 1654 ASSERT_TRUE(entry); | 1654 ASSERT_TRUE(entry); |
| 1655 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); | 1655 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); |
| 1656 } | 1656 } |
| 1657 | 1657 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1709 // number after updating a file. | 1709 // number after updating a file. |
| 1710 scoped_ptr<ResourceEntryVector> root_directory_entries( | 1710 scoped_ptr<ResourceEntryVector> root_directory_entries( |
| 1711 ReadDirectoryByPathSync(base::FilePath::FromUTF8Unsafe("drive/root"))); | 1711 ReadDirectoryByPathSync(base::FilePath::FromUTF8Unsafe("drive/root"))); |
| 1712 ASSERT_TRUE(root_directory_entries); | 1712 ASSERT_TRUE(root_directory_entries); |
| 1713 const int num_files_in_root = CountFiles(*root_directory_entries); | 1713 const int num_files_in_root = CountFiles(*root_directory_entries); |
| 1714 | 1714 |
| 1715 // The callback will be called upon completion of | 1715 // The callback will be called upon completion of |
| 1716 // UpdateFileByResourceId(). | 1716 // UpdateFileByResourceId(). |
| 1717 file_system_->UpdateFileByResourceId( | 1717 file_system_->UpdateFileByResourceId( |
| 1718 kResourceId, | 1718 kResourceId, |
| 1719 DriveClientContext(USER_INITIATED), | 1719 ClientContext(USER_INITIATED), |
| 1720 google_apis::test_util::CreateCopyResultCallback(&error)); | 1720 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1721 google_apis::test_util::RunBlockingPoolTask(); | 1721 google_apis::test_util::RunBlockingPoolTask(); |
| 1722 EXPECT_EQ(FILE_ERROR_OK, error); | 1722 EXPECT_EQ(FILE_ERROR_OK, error); |
| 1723 | 1723 |
| 1724 // Make sure that the number of files did not change (i.e. we updated an | 1724 // Make sure that the number of files did not change (i.e. we updated an |
| 1725 // existing file, rather than adding a new file. The number of files | 1725 // existing file, rather than adding a new file. The number of files |
| 1726 // increases if we don't handle the file update right). | 1726 // increases if we don't handle the file update right). |
| 1727 EXPECT_EQ(num_files_in_root, CountFiles(*root_directory_entries)); | 1727 EXPECT_EQ(num_files_in_root, CountFiles(*root_directory_entries)); |
| 1728 } | 1728 } |
| 1729 | 1729 |
| 1730 TEST_F(FileSystemTest, UpdateFileByResourceId_NonexistentFile) { | 1730 TEST_F(FileSystemTest, UpdateFileByResourceId_NonexistentFile) { |
| 1731 ASSERT_TRUE(LoadRootFeedDocument()); | 1731 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1732 | 1732 |
| 1733 // This is nonexistent in root_feed.json. | 1733 // This is nonexistent in root_feed.json. |
| 1734 const base::FilePath kFilePath( | 1734 const base::FilePath kFilePath( |
| 1735 FILE_PATH_LITERAL("drive/root/Nonexistent.txt")); | 1735 FILE_PATH_LITERAL("drive/root/Nonexistent.txt")); |
| 1736 const std::string kResourceId("file:nonexistent_resource_id"); | 1736 const std::string kResourceId("file:nonexistent_resource_id"); |
| 1737 const std::string kMd5("nonexistent_md5"); | 1737 const std::string kMd5("nonexistent_md5"); |
| 1738 | 1738 |
| 1739 // The callback will be called upon completion of | 1739 // The callback will be called upon completion of |
| 1740 // UpdateFileByResourceId(). | 1740 // UpdateFileByResourceId(). |
| 1741 FileError error = FILE_ERROR_OK; | 1741 FileError error = FILE_ERROR_OK; |
| 1742 file_system_->UpdateFileByResourceId( | 1742 file_system_->UpdateFileByResourceId( |
| 1743 kResourceId, | 1743 kResourceId, |
| 1744 DriveClientContext(USER_INITIATED), | 1744 ClientContext(USER_INITIATED), |
| 1745 google_apis::test_util::CreateCopyResultCallback(&error)); | 1745 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 1746 google_apis::test_util::RunBlockingPoolTask(); | 1746 google_apis::test_util::RunBlockingPoolTask(); |
| 1747 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); | 1747 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); |
| 1748 } | 1748 } |
| 1749 | 1749 |
| 1750 TEST_F(FileSystemTest, ContentSearch) { | 1750 TEST_F(FileSystemTest, ContentSearch) { |
| 1751 ASSERT_TRUE(LoadRootFeedDocument()); | 1751 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1752 | 1752 |
| 1753 const SearchResultPair kExpectedResults[] = { | 1753 const SearchResultPair kExpectedResults[] = { |
| 1754 { "drive/root/Directory 1/Sub Directory Folder/Sub Sub Directory Folder", | 1754 { "drive/root/Directory 1/Sub Directory Folder/Sub Sub Directory Folder", |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1986 entry->resource_id(), | 1986 entry->resource_id(), |
| 1987 entry->file_specific_info().file_md5(), | 1987 entry->file_specific_info().file_md5(), |
| 1988 google_apis::test_util::CreateCopyResultCallback(&success, &cache_entry)); | 1988 google_apis::test_util::CreateCopyResultCallback(&success, &cache_entry)); |
| 1989 google_apis::test_util::RunBlockingPoolTask(); | 1989 google_apis::test_util::RunBlockingPoolTask(); |
| 1990 | 1990 |
| 1991 EXPECT_TRUE(success); | 1991 EXPECT_TRUE(success); |
| 1992 EXPECT_FALSE(cache_entry.is_mounted()); | 1992 EXPECT_FALSE(cache_entry.is_mounted()); |
| 1993 } | 1993 } |
| 1994 | 1994 |
| 1995 } // namespace drive | 1995 } // namespace drive |
| OLD | NEW |