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

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: 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(base::FilePath(kExpectedResults[i].path),
hashimoto 2013/05/27 03:15:51 Shouldn't this be FromUTF8Unsafe()? Also, how abou
kinaba 2013/05/27 03:35:17 Sounds good. Done.
53 results->at(i).path);
54 EXPECT_EQ(kExpectedResults[i].is_directory,
55 results->at(i).entry.file_info().is_directory());
56 }
57 }
58
59 TEST_F(SearchOperationTest, ContentSearchWithNewEntry) {
60 SearchOperation operation(blocking_task_runner(), scheduler(), metadata());
61
62 // Create a new directory in the drive service.
63 google_apis::GDataErrorCode gdata_error = google_apis::GDATA_OTHER_ERROR;
64 scoped_ptr<google_apis::ResourceEntry> resource_entry;
65 fake_service()->AddNewDirectory(
66 fake_service()->GetRootResourceId(),
67 "New Directory 1!",
68 google_apis::test_util::CreateCopyResultCallback(
69 &gdata_error, &resource_entry));
70 google_apis::test_util::RunBlockingPoolTask();
71 ASSERT_EQ(google_apis::HTTP_CREATED, gdata_error);
72
73 // As the result of the first Search(), only entries in the current file
74 // system snapshot are expected to be returned (i.e. "New Directory 1!"
75 // shouldn't be included in the search result even though it matches
76 // "Directory 1".
77 const SearchResultPair kExpectedResults[] = {
78 { "drive/root/Directory 1", true }
79 };
80
81 FileError error = FILE_ERROR_FAILED;
82 GURL next_feed;
83 scoped_ptr<std::vector<SearchResultInfo> > results;
84
85 operation.Search("\"Directory 1\"", GURL(),
86 google_apis::test_util::CreateCopyResultCallback(
87 &error, &next_feed, &results));
88 google_apis::test_util::RunBlockingPoolTask();
89
90 EXPECT_EQ(FILE_ERROR_OK, error);
91 EXPECT_EQ(GURL(), next_feed);
92 ASSERT_EQ(1U, results->size());
93 EXPECT_EQ(base::FilePath(kExpectedResults[0].path), results->at(0).path);
hashimoto 2013/05/27 03:15:51 ditto.
kinaba 2013/05/27 03:35:17 Done.
94 }
95
96 TEST_F(SearchOperationTest, ContentSearchEmptyResult) {
97 SearchOperation operation(blocking_task_runner(), scheduler(), metadata());
98
99 FileError error = FILE_ERROR_FAILED;
100 GURL next_feed;
101 scoped_ptr<std::vector<SearchResultInfo> > results;
102
103 operation.Search("\"no-match query\"", GURL(),
104 google_apis::test_util::CreateCopyResultCallback(
105 &error, &next_feed, &results));
106 google_apis::test_util::RunBlockingPoolTask();
107
108 EXPECT_EQ(FILE_ERROR_OK, error);
109 EXPECT_EQ(GURL(), next_feed);
110 EXPECT_EQ(0U, results->size());
111 }
112
113 } // namespace file_system
114 } // 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