Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(454)

Side by Side Diff: chrome/browser/chromeos/drive/file_system_unittest.cc

Issue 15989002: Add UpdateOperationTest for drive::file_system::UpdateOperationTest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase + Reflect review comment Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 results->at(i).path); 67 results->at(i).path);
68 EXPECT_EQ(expected_results[i].is_directory, 68 EXPECT_EQ(expected_results[i].is_directory,
69 results->at(i).entry.file_info().is_directory()); 69 results->at(i).entry.file_info().is_directory());
70 } 70 }
71 71
72 EXPECT_EQ(expected_next_feed, next_feed); 72 EXPECT_EQ(expected_next_feed, next_feed);
73 73
74 message_loop->Quit(); 74 message_loop->Quit();
75 } 75 }
76 76
77 // Counts the number of files (not directories) in |entries|.
78 int CountFiles(const ResourceEntryVector& entries) {
79 int num_files = 0;
80 for (size_t i = 0; i < entries.size(); ++i) {
81 if (!entries[i].file_info().is_directory())
82 ++num_files;
83 }
84 return num_files;
85 }
86
87 // Counts the number of invocation, and if it increased up to |expected_counter| 77 // Counts the number of invocation, and if it increased up to |expected_counter|
88 // quits the current message loop. 78 // quits the current message loop.
89 void AsyncInitializationCallback( 79 void AsyncInitializationCallback(
90 int* counter, int expected_counter, MessageLoop* message_loop, 80 int* counter, int expected_counter, MessageLoop* message_loop,
91 FileError error, scoped_ptr<ResourceEntry> entry) { 81 FileError error, scoped_ptr<ResourceEntry> entry) {
92 if (error != FILE_ERROR_OK || !entry) { 82 if (error != FILE_ERROR_OK || !entry) {
93 // If we hit an error case, quit the message loop immediately. 83 // If we hit an error case, quit the message loop immediately.
94 // Then the expectation in the test case can find it because the actual 84 // Then the expectation in the test case can find it because the actual
95 // value of |counter| is different from the expected one. 85 // value of |counter| is different from the expected one.
96 message_loop->Quit(); 86 message_loop->Quit();
(...skipping 1551 matching lines...) Expand 10 before | Expand all | Expand 10 after
1648 google_apis::test_util::CreateCopyResultCallback( 1638 google_apis::test_util::CreateCopyResultCallback(
1649 &error, &file_path, &entry), 1639 &error, &file_path, &entry),
1650 google_apis::GetContentCallback()); 1640 google_apis::GetContentCallback());
1651 google_apis::test_util::RunBlockingPoolTask(); 1641 google_apis::test_util::RunBlockingPoolTask();
1652 1642
1653 EXPECT_EQ(FILE_ERROR_OK, error); 1643 EXPECT_EQ(FILE_ERROR_OK, error);
1654 ASSERT_TRUE(entry); 1644 ASSERT_TRUE(entry);
1655 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); 1645 EXPECT_FALSE(entry->file_specific_info().is_hosted_document());
1656 } 1646 }
1657 1647
1658 TEST_F(FileSystemTest, UpdateFileByResourceId_PersistentFile) {
1659 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
1660
1661 ASSERT_TRUE(LoadRootFeedDocument());
1662
1663 // This is a file defined in root_feed.json.
1664 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1665 const std::string kResourceId("file:2_file_resource_id");
1666 const std::string kMd5("3b4382ebefec6e743578c76bbd0575ce");
1667
1668 // Pin the file so it'll be store in "persistent" directory.
1669 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(kResourceId, kMd5)).Times(1);
1670 FileError error = FILE_ERROR_OK;
1671 cache_->PinOnUIThread(
1672 kResourceId, kMd5,
1673 google_apis::test_util::CreateCopyResultCallback(&error));
1674 google_apis::test_util::RunBlockingPoolTask();
1675 EXPECT_EQ(FILE_ERROR_OK, error);
1676
1677 // First store a file to cache.
1678 cache_->StoreOnUIThread(
1679 kResourceId,
1680 kMd5,
1681 // Anything works.
1682 google_apis::test_util::GetTestFilePath("chromeos/gdata/root_feed.json"),
1683 internal::FileCache::FILE_OPERATION_COPY,
1684 google_apis::test_util::CreateCopyResultCallback(&error));
1685 google_apis::test_util::RunBlockingPoolTask();
1686 EXPECT_EQ(FILE_ERROR_OK, error);
1687
1688 // Add the dirty bit.
1689 cache_->MarkDirtyOnUIThread(
1690 kResourceId, kMd5,
1691 google_apis::test_util::CreateCopyResultCallback(&error));
1692 google_apis::test_util::RunBlockingPoolTask();
1693 EXPECT_EQ(FILE_ERROR_OK, error);
1694
1695 // Commit the dirty bit.
1696 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(kResourceId)).Times(1);
1697 cache_->CommitDirtyOnUIThread(
1698 kResourceId, kMd5,
1699 google_apis::test_util::CreateCopyResultCallback(&error));
1700 google_apis::test_util::RunBlockingPoolTask();
1701 EXPECT_EQ(FILE_ERROR_OK, error);
1702
1703 // We'll notify the directory change to the observer upon completion.
1704 EXPECT_CALL(*mock_directory_observer_,
1705 OnDirectoryChanged(Eq(util::GetDriveMyDriveRootPath())))
1706 .Times(1);
1707
1708 // Check the number of files in the root directory. We'll compare the
1709 // number after updating a file.
1710 scoped_ptr<ResourceEntryVector> root_directory_entries(
1711 ReadDirectoryByPathSync(base::FilePath::FromUTF8Unsafe("drive/root")));
1712 ASSERT_TRUE(root_directory_entries);
1713 const int num_files_in_root = CountFiles(*root_directory_entries);
1714
1715 // The callback will be called upon completion of
1716 // UpdateFileByResourceId().
1717 file_system_->UpdateFileByResourceId(
1718 kResourceId,
1719 DriveClientContext(USER_INITIATED),
1720 google_apis::test_util::CreateCopyResultCallback(&error));
1721 google_apis::test_util::RunBlockingPoolTask();
1722 EXPECT_EQ(FILE_ERROR_OK, error);
1723
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
1726 // increases if we don't handle the file update right).
1727 EXPECT_EQ(num_files_in_root, CountFiles(*root_directory_entries));
1728 }
1729
1730 TEST_F(FileSystemTest, UpdateFileByResourceId_NonexistentFile) {
1731 ASSERT_TRUE(LoadRootFeedDocument());
1732
1733 // This is nonexistent in root_feed.json.
1734 const base::FilePath kFilePath(
1735 FILE_PATH_LITERAL("drive/root/Nonexistent.txt"));
1736 const std::string kResourceId("file:nonexistent_resource_id");
1737 const std::string kMd5("nonexistent_md5");
1738
1739 // The callback will be called upon completion of
1740 // UpdateFileByResourceId().
1741 FileError error = FILE_ERROR_OK;
1742 file_system_->UpdateFileByResourceId(
1743 kResourceId,
1744 DriveClientContext(USER_INITIATED),
1745 google_apis::test_util::CreateCopyResultCallback(&error));
1746 google_apis::test_util::RunBlockingPoolTask();
1747 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error);
1748 }
1749
1750 TEST_F(FileSystemTest, ContentSearch) { 1648 TEST_F(FileSystemTest, ContentSearch) {
1751 ASSERT_TRUE(LoadRootFeedDocument()); 1649 ASSERT_TRUE(LoadRootFeedDocument());
1752 1650
1753 const SearchResultPair kExpectedResults[] = { 1651 const SearchResultPair kExpectedResults[] = {
1754 { "drive/root/Directory 1/Sub Directory Folder/Sub Sub Directory Folder", 1652 { "drive/root/Directory 1/Sub Directory Folder/Sub Sub Directory Folder",
1755 true }, 1653 true },
1756 { "drive/root/Directory 1/Sub Directory Folder", true }, 1654 { "drive/root/Directory 1/Sub Directory Folder", true },
1757 { "drive/root/Directory 1/SubDirectory File 1.txt", false }, 1655 { "drive/root/Directory 1/SubDirectory File 1.txt", false },
1758 { "drive/root/Directory 1", true }, 1656 { "drive/root/Directory 1", true },
1759 { "drive/root/Directory 2 excludeDir-test", true }, 1657 { "drive/root/Directory 2 excludeDir-test", true },
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
1986 entry->resource_id(), 1884 entry->resource_id(),
1987 entry->file_specific_info().file_md5(), 1885 entry->file_specific_info().file_md5(),
1988 google_apis::test_util::CreateCopyResultCallback(&success, &cache_entry)); 1886 google_apis::test_util::CreateCopyResultCallback(&success, &cache_entry));
1989 google_apis::test_util::RunBlockingPoolTask(); 1887 google_apis::test_util::RunBlockingPoolTask();
1990 1888
1991 EXPECT_TRUE(success); 1889 EXPECT_TRUE(success);
1992 EXPECT_FALSE(cache_entry.is_mounted()); 1890 EXPECT_FALSE(cache_entry.is_mounted());
1993 } 1891 }
1994 1892
1995 } // namespace drive 1893 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698