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

Side by Side Diff: chrome/browser/chromeos/drive/file_system/search_operation_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
« no previous file with comments | « no previous file | chrome/browser/chromeos/drive/file_system_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/drive/file_system/search_operation.h"
6
7 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h"
8 #include "chrome/browser/google_apis/fake_drive_service.h"
9 #include "chrome/browser/google_apis/gdata_wapi_parser.h"
10 #include "chrome/browser/google_apis/test_util.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace drive {
14 namespace file_system {
15
16 namespace {
17
18 struct SearchResultPair {
19 const char* path;
20 const bool is_directory;
21 };
22
23 } // namespace
24
25 typedef OperationTestBase SearchOperationTest;
26
27 TEST_F(SearchOperationTest, ContentSearch) {
28 SearchOperation operation(blocking_task_runner(), scheduler(), metadata());
29
30 const SearchResultPair kExpectedResults[] = {
31 { "drive/root/Directory 1/Sub Directory Folder/Sub Sub Directory Folder",
32 true },
33 { "drive/root/Directory 1/Sub Directory Folder", true },
34 { "drive/root/Directory 1/SubDirectory File 1.txt", false },
35 { "drive/root/Directory 1", true },
36 { "drive/root/Directory 2 excludeDir-test", true },
37 };
38
39 FileError error = FILE_ERROR_FAILED;
40 GURL next_feed;
41 scoped_ptr<std::vector<SearchResultInfo> > results;
42
43 operation.Search("Directory", GURL(),
44 google_apis::test_util::CreateCopyResultCallback(
45 &error, &next_feed, &results));
46 google_apis::test_util::RunBlockingPoolTask();
47
48 EXPECT_EQ(FILE_ERROR_OK, error);
49 EXPECT_EQ(GURL(), next_feed);
50 EXPECT_EQ(ARRAYSIZE_UNSAFE(kExpectedResults), results->size());
51 for (size_t i = 0; i < results->size(); i++) {
52 EXPECT_EQ(kExpectedResults[i].path, results->at(i).path.AsUTF8Unsafe());
53 EXPECT_EQ(kExpectedResults[i].is_directory,
54 results->at(i).entry.file_info().is_directory());
55 }
56 }
57
58 TEST_F(SearchOperationTest, ContentSearchWithNewEntry) {
59 SearchOperation operation(blocking_task_runner(), scheduler(), metadata());
60
61 // Create a new directory in the drive service.
62 google_apis::GDataErrorCode gdata_error = google_apis::GDATA_OTHER_ERROR;
63 scoped_ptr<google_apis::ResourceEntry> resource_entry;
64 fake_service()->AddNewDirectory(
65 fake_service()->GetRootResourceId(),
66 "New Directory 1!",
67 google_apis::test_util::CreateCopyResultCallback(
68 &gdata_error, &resource_entry));
69 google_apis::test_util::RunBlockingPoolTask();
70 ASSERT_EQ(google_apis::HTTP_CREATED, gdata_error);
71
72 // As the result of the first Search(), only entries in the current file
73 // system snapshot are expected to be returned (i.e. "New Directory 1!"
74 // shouldn't be included in the search result even though it matches
75 // "Directory 1".
76 const SearchResultPair kExpectedResults[] = {
77 { "drive/root/Directory 1", true }
78 };
79
80 FileError error = FILE_ERROR_FAILED;
81 GURL next_feed;
82 scoped_ptr<std::vector<SearchResultInfo> > results;
83
84 operation.Search("\"Directory 1\"", GURL(),
85 google_apis::test_util::CreateCopyResultCallback(
86 &error, &next_feed, &results));
87 google_apis::test_util::RunBlockingPoolTask();
88
89 EXPECT_EQ(FILE_ERROR_OK, error);
90 EXPECT_EQ(GURL(), next_feed);
91 ASSERT_EQ(1U, results->size());
92 EXPECT_EQ(kExpectedResults[0].path, results->at(0).path.AsUTF8Unsafe());
93 }
94
95 TEST_F(SearchOperationTest, ContentSearchEmptyResult) {
96 SearchOperation operation(blocking_task_runner(), scheduler(), metadata());
97
98 FileError error = FILE_ERROR_FAILED;
99 GURL next_feed;
100 scoped_ptr<std::vector<SearchResultInfo> > results;
101
102 operation.Search("\"no-match query\"", GURL(),
103 google_apis::test_util::CreateCopyResultCallback(
104 &error, &next_feed, &results));
105 google_apis::test_util::RunBlockingPoolTask();
106
107 EXPECT_EQ(FILE_ERROR_OK, error);
108 EXPECT_EQ(GURL(), next_feed);
109 EXPECT_EQ(0U, results->size());
110 }
111
112 } // namespace file_system
113 } // namespace drive
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/drive/file_system_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698