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

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

Issue 16081002: Add SearchOperationTest for drive::file_system::SearchOperation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase 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 26 matching lines...) Expand all
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 1538 matching lines...) Expand 10 before | Expand all | Expand 10 after
1625 google_apis::test_util::CreateCopyResultCallback( 1595 google_apis::test_util::CreateCopyResultCallback(
1626 &error, &file_path, &entry), 1596 &error, &file_path, &entry),
1627 google_apis::GetContentCallback()); 1597 google_apis::GetContentCallback());
1628 google_apis::test_util::RunBlockingPoolTask(); 1598 google_apis::test_util::RunBlockingPoolTask();
1629 1599
1630 EXPECT_EQ(FILE_ERROR_OK, error); 1600 EXPECT_EQ(FILE_ERROR_OK, error);
1631 ASSERT_TRUE(entry); 1601 ASSERT_TRUE(entry);
1632 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); 1602 EXPECT_FALSE(entry->file_specific_info().is_hosted_document());
1633 } 1603 }
1634 1604
1635 TEST_F(FileSystemTest, ContentSearch) {
1636 ASSERT_TRUE(LoadRootFeedDocument());
1637
1638 const SearchResultPair kExpectedResults[] = {
1639 { "drive/root/Directory 1/Sub Directory Folder/Sub Sub Directory Folder",
1640 true },
1641 { "drive/root/Directory 1/Sub Directory Folder", true },
1642 { "drive/root/Directory 1/SubDirectory File 1.txt", false },
1643 { "drive/root/Directory 1", true },
1644 { "drive/root/Directory 2 excludeDir-test", true },
1645 };
1646
1647 SearchCallback callback = base::Bind(
1648 &VerifySearchResult,
1649 &message_loop_,
1650 kExpectedResults, ARRAYSIZE_UNSAFE(kExpectedResults),
1651 GURL());
1652
1653 file_system_->Search("Directory", GURL(), callback);
1654 google_apis::test_util::RunBlockingPoolTask();
1655 }
1656
1657 TEST_F(FileSystemTest, ContentSearchWithNewEntry) {
1658 ASSERT_TRUE(LoadRootFeedDocument());
1659
1660 // Create a new directory in the drive service.
1661 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
1662 scoped_ptr<google_apis::ResourceEntry> resource_entry;
1663 fake_drive_service_->AddNewDirectory(
1664 fake_drive_service_->GetRootResourceId(), // Add to the root directory.
1665 "New Directory 1!",
1666 google_apis::test_util::CreateCopyResultCallback(
1667 &error, &resource_entry));
1668 google_apis::test_util::RunBlockingPoolTask();
1669
1670 // As the result of the first Search(), only entries in the current file
1671 // system snapshot are expected to be returned (i.e. "New Directory 1!"
1672 // shouldn't be included in the search result even though it matches
1673 // "Directory 1".
1674 const SearchResultPair kExpectedResults[] = {
1675 { "drive/root/Directory 1", true }
1676 };
1677
1678 SearchCallback callback = base::Bind(
1679 &VerifySearchResult,
1680 &message_loop_,
1681 kExpectedResults, ARRAYSIZE_UNSAFE(kExpectedResults),
1682 GURL());
1683
1684 file_system_->Search("\"Directory 1\"", GURL(), callback);
1685 google_apis::test_util::RunBlockingPoolTask();
1686 }
1687
1688 TEST_F(FileSystemTest, ContentSearchEmptyResult) {
1689 ASSERT_TRUE(LoadRootFeedDocument());
1690
1691 const SearchResultPair* expected_results = NULL;
1692
1693 SearchCallback callback = base::Bind(
1694 &VerifySearchResult,
1695 &message_loop_,
1696 expected_results,
1697 0u,
1698 GURL());
1699
1700 file_system_->Search("\"no-match query\"", GURL(), callback);
1701 google_apis::test_util::RunBlockingPoolTask();
1702 }
1703
1704 TEST_F(FileSystemTest, GetAvailableSpace) { 1605 TEST_F(FileSystemTest, GetAvailableSpace) {
1705 FileError error = FILE_ERROR_OK; 1606 FileError error = FILE_ERROR_OK;
1706 int64 bytes_total; 1607 int64 bytes_total;
1707 int64 bytes_used; 1608 int64 bytes_used;
1708 file_system_->GetAvailableSpace( 1609 file_system_->GetAvailableSpace(
1709 google_apis::test_util::CreateCopyResultCallback( 1610 google_apis::test_util::CreateCopyResultCallback(
1710 &error, &bytes_total, &bytes_used)); 1611 &error, &bytes_total, &bytes_used));
1711 google_apis::test_util::RunBlockingPoolTask(); 1612 google_apis::test_util::RunBlockingPoolTask();
1712 EXPECT_EQ(GG_LONGLONG(6789012345), bytes_used); 1613 EXPECT_EQ(GG_LONGLONG(6789012345), bytes_used);
1713 EXPECT_EQ(GG_LONGLONG(9876543210), bytes_total); 1614 EXPECT_EQ(GG_LONGLONG(9876543210), bytes_total);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1871 entry->resource_id(), 1772 entry->resource_id(),
1872 entry->file_specific_info().file_md5(), 1773 entry->file_specific_info().file_md5(),
1873 google_apis::test_util::CreateCopyResultCallback(&success, &cache_entry)); 1774 google_apis::test_util::CreateCopyResultCallback(&success, &cache_entry));
1874 google_apis::test_util::RunBlockingPoolTask(); 1775 google_apis::test_util::RunBlockingPoolTask();
1875 1776
1876 EXPECT_TRUE(success); 1777 EXPECT_TRUE(success);
1877 EXPECT_FALSE(cache_entry.is_mounted()); 1778 EXPECT_FALSE(cache_entry.is_mounted());
1878 } 1779 }
1879 1780
1880 } // namespace drive 1781 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_system/search_operation_unittest.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698