| 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 26 matching lines...) Expand all Loading... |
| 37 using ::testing::AtLeast; | 37 using ::testing::AtLeast; |
| 38 using ::testing::Eq; | 38 using ::testing::Eq; |
| 39 using ::testing::StrictMock; | 39 using ::testing::StrictMock; |
| 40 using ::testing::_; | 40 using ::testing::_; |
| 41 | 41 |
| 42 namespace drive { | 42 namespace drive { |
| 43 namespace { | 43 namespace { |
| 44 | 44 |
| 45 const int64 kLotsOfSpace = internal::kMinFreeSpace * 10; | 45 const int64 kLotsOfSpace = internal::kMinFreeSpace * 10; |
| 46 | 46 |
| 47 struct SearchResultPair { | |
| 48 const char* path; | |
| 49 const bool is_directory; | |
| 50 }; | |
| 51 | |
| 52 // Callback to FileSystem::Search used in ContentSearch tests. | |
| 53 // Verifies returned vector of results and next feed url. | |
| 54 void VerifySearchResult( | |
| 55 MessageLoop* message_loop, | |
| 56 const SearchResultPair* expected_results, | |
| 57 size_t expected_results_size, | |
| 58 const GURL& expected_next_feed, | |
| 59 FileError error, | |
| 60 const GURL& next_feed, | |
| 61 scoped_ptr<std::vector<SearchResultInfo> > results) { | |
| 62 ASSERT_TRUE(results); | |
| 63 ASSERT_EQ(expected_results_size, results->size()); | |
| 64 | |
| 65 for (size_t i = 0; i < results->size(); i++) { | |
| 66 EXPECT_EQ(base::FilePath(expected_results[i].path), | |
| 67 results->at(i).path); | |
| 68 EXPECT_EQ(expected_results[i].is_directory, | |
| 69 results->at(i).entry.file_info().is_directory()); | |
| 70 } | |
| 71 | |
| 72 EXPECT_EQ(expected_next_feed, next_feed); | |
| 73 | |
| 74 message_loop->Quit(); | |
| 75 } | |
| 76 | |
| 77 // Counts the number of invocation, and if it increased up to |expected_counter| | 47 // Counts the number of invocation, and if it increased up to |expected_counter| |
| 78 // quits the current message loop. | 48 // quits the current message loop. |
| 79 void AsyncInitializationCallback( | 49 void AsyncInitializationCallback( |
| 80 int* counter, int expected_counter, MessageLoop* message_loop, | 50 int* counter, int expected_counter, MessageLoop* message_loop, |
| 81 FileError error, scoped_ptr<ResourceEntry> entry) { | 51 FileError error, scoped_ptr<ResourceEntry> entry) { |
| 82 if (error != FILE_ERROR_OK || !entry) { | 52 if (error != FILE_ERROR_OK || !entry) { |
| 83 // If we hit an error case, quit the message loop immediately. | 53 // If we hit an error case, quit the message loop immediately. |
| 84 // Then the expectation in the test case can find it because the actual | 54 // Then the expectation in the test case can find it because the actual |
| 85 // value of |counter| is different from the expected one. | 55 // value of |counter| is different from the expected one. |
| 86 message_loop->Quit(); | 56 message_loop->Quit(); |
| (...skipping 1551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1638 google_apis::test_util::CreateCopyResultCallback( | 1608 google_apis::test_util::CreateCopyResultCallback( |
| 1639 &error, &file_path, &entry), | 1609 &error, &file_path, &entry), |
| 1640 google_apis::GetContentCallback()); | 1610 google_apis::GetContentCallback()); |
| 1641 google_apis::test_util::RunBlockingPoolTask(); | 1611 google_apis::test_util::RunBlockingPoolTask(); |
| 1642 | 1612 |
| 1643 EXPECT_EQ(FILE_ERROR_OK, error); | 1613 EXPECT_EQ(FILE_ERROR_OK, error); |
| 1644 ASSERT_TRUE(entry); | 1614 ASSERT_TRUE(entry); |
| 1645 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); | 1615 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); |
| 1646 } | 1616 } |
| 1647 | 1617 |
| 1648 TEST_F(FileSystemTest, ContentSearch) { | |
| 1649 ASSERT_TRUE(LoadRootFeedDocument()); | |
| 1650 | |
| 1651 const SearchResultPair kExpectedResults[] = { | |
| 1652 { "drive/root/Directory 1/Sub Directory Folder/Sub Sub Directory Folder", | |
| 1653 true }, | |
| 1654 { "drive/root/Directory 1/Sub Directory Folder", true }, | |
| 1655 { "drive/root/Directory 1/SubDirectory File 1.txt", false }, | |
| 1656 { "drive/root/Directory 1", true }, | |
| 1657 { "drive/root/Directory 2 excludeDir-test", true }, | |
| 1658 }; | |
| 1659 | |
| 1660 SearchCallback callback = base::Bind( | |
| 1661 &VerifySearchResult, | |
| 1662 &message_loop_, | |
| 1663 kExpectedResults, ARRAYSIZE_UNSAFE(kExpectedResults), | |
| 1664 GURL()); | |
| 1665 | |
| 1666 file_system_->Search("Directory", GURL(), callback); | |
| 1667 google_apis::test_util::RunBlockingPoolTask(); | |
| 1668 } | |
| 1669 | |
| 1670 TEST_F(FileSystemTest, ContentSearchWithNewEntry) { | |
| 1671 ASSERT_TRUE(LoadRootFeedDocument()); | |
| 1672 | |
| 1673 // Create a new directory in the drive service. | |
| 1674 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | |
| 1675 scoped_ptr<google_apis::ResourceEntry> resource_entry; | |
| 1676 fake_drive_service_->AddNewDirectory( | |
| 1677 fake_drive_service_->GetRootResourceId(), // Add to the root directory. | |
| 1678 "New Directory 1!", | |
| 1679 google_apis::test_util::CreateCopyResultCallback( | |
| 1680 &error, &resource_entry)); | |
| 1681 google_apis::test_util::RunBlockingPoolTask(); | |
| 1682 | |
| 1683 // As the result of the first Search(), only entries in the current file | |
| 1684 // system snapshot are expected to be returned (i.e. "New Directory 1!" | |
| 1685 // shouldn't be included in the search result even though it matches | |
| 1686 // "Directory 1". | |
| 1687 const SearchResultPair kExpectedResults[] = { | |
| 1688 { "drive/root/Directory 1", true } | |
| 1689 }; | |
| 1690 | |
| 1691 SearchCallback callback = base::Bind( | |
| 1692 &VerifySearchResult, | |
| 1693 &message_loop_, | |
| 1694 kExpectedResults, ARRAYSIZE_UNSAFE(kExpectedResults), | |
| 1695 GURL()); | |
| 1696 | |
| 1697 file_system_->Search("\"Directory 1\"", GURL(), callback); | |
| 1698 google_apis::test_util::RunBlockingPoolTask(); | |
| 1699 } | |
| 1700 | |
| 1701 TEST_F(FileSystemTest, ContentSearchEmptyResult) { | |
| 1702 ASSERT_TRUE(LoadRootFeedDocument()); | |
| 1703 | |
| 1704 const SearchResultPair* expected_results = NULL; | |
| 1705 | |
| 1706 SearchCallback callback = base::Bind( | |
| 1707 &VerifySearchResult, | |
| 1708 &message_loop_, | |
| 1709 expected_results, | |
| 1710 0u, | |
| 1711 GURL()); | |
| 1712 | |
| 1713 file_system_->Search("\"no-match query\"", GURL(), callback); | |
| 1714 google_apis::test_util::RunBlockingPoolTask(); | |
| 1715 } | |
| 1716 | |
| 1717 TEST_F(FileSystemTest, GetAvailableSpace) { | 1618 TEST_F(FileSystemTest, GetAvailableSpace) { |
| 1718 FileError error = FILE_ERROR_OK; | 1619 FileError error = FILE_ERROR_OK; |
| 1719 int64 bytes_total; | 1620 int64 bytes_total; |
| 1720 int64 bytes_used; | 1621 int64 bytes_used; |
| 1721 file_system_->GetAvailableSpace( | 1622 file_system_->GetAvailableSpace( |
| 1722 google_apis::test_util::CreateCopyResultCallback( | 1623 google_apis::test_util::CreateCopyResultCallback( |
| 1723 &error, &bytes_total, &bytes_used)); | 1624 &error, &bytes_total, &bytes_used)); |
| 1724 google_apis::test_util::RunBlockingPoolTask(); | 1625 google_apis::test_util::RunBlockingPoolTask(); |
| 1725 EXPECT_EQ(GG_LONGLONG(6789012345), bytes_used); | 1626 EXPECT_EQ(GG_LONGLONG(6789012345), bytes_used); |
| 1726 EXPECT_EQ(GG_LONGLONG(9876543210), bytes_total); | 1627 EXPECT_EQ(GG_LONGLONG(9876543210), bytes_total); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1884 entry->resource_id(), | 1785 entry->resource_id(), |
| 1885 entry->file_specific_info().file_md5(), | 1786 entry->file_specific_info().file_md5(), |
| 1886 google_apis::test_util::CreateCopyResultCallback(&success, &cache_entry)); | 1787 google_apis::test_util::CreateCopyResultCallback(&success, &cache_entry)); |
| 1887 google_apis::test_util::RunBlockingPoolTask(); | 1788 google_apis::test_util::RunBlockingPoolTask(); |
| 1888 | 1789 |
| 1889 EXPECT_TRUE(success); | 1790 EXPECT_TRUE(success); |
| 1890 EXPECT_FALSE(cache_entry.is_mounted()); | 1791 EXPECT_FALSE(cache_entry.is_mounted()); |
| 1891 } | 1792 } |
| 1892 | 1793 |
| 1893 } // namespace drive | 1794 } // namespace drive |
| OLD | NEW |