Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / file_system / search_operation_unittest.cc
blob79a7296d0bd295dabf41f18f4792cc41d1324be1
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.
5 #include "chrome/browser/chromeos/drive/file_system/search_operation.h"
7 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h"
8 #include "chrome/browser/drive/fake_drive_service.h"
9 #include "google_apis/drive/gdata_wapi_parser.h"
10 #include "google_apis/drive/test_util.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace drive {
14 namespace file_system {
16 typedef OperationTestBase SearchOperationTest;
18 TEST_F(SearchOperationTest, ContentSearch) {
19 SearchOperation operation(blocking_task_runner(), scheduler(), metadata());
21 std::set<std::string> expected_results;
22 expected_results.insert(
23 "drive/root/Directory 1/Sub Directory Folder/Sub Sub Directory Folder");
24 expected_results.insert("drive/root/Directory 1/Sub Directory Folder");
25 expected_results.insert("drive/root/Directory 1/SubDirectory File 1.txt");
26 expected_results.insert("drive/root/Directory 1");
27 expected_results.insert("drive/root/Directory 2 excludeDir-test");
29 FileError error = FILE_ERROR_FAILED;
30 GURL next_link;
31 scoped_ptr<std::vector<SearchResultInfo> > results;
33 operation.Search("Directory", GURL(),
34 google_apis::test_util::CreateCopyResultCallback(
35 &error, &next_link, &results));
36 test_util::RunBlockingPoolTask();
38 EXPECT_EQ(FILE_ERROR_OK, error);
39 EXPECT_TRUE(next_link.is_empty());
40 EXPECT_EQ(expected_results.size(), results->size());
41 for (size_t i = 0; i < results->size(); i++) {
42 EXPECT_TRUE(expected_results.count(results->at(i).path.AsUTF8Unsafe()))
43 << results->at(i).path.AsUTF8Unsafe();
47 TEST_F(SearchOperationTest, ContentSearchWithNewEntry) {
48 SearchOperation operation(blocking_task_runner(), scheduler(), metadata());
50 // Create a new directory in the drive service.
51 google_apis::GDataErrorCode gdata_error = google_apis::GDATA_OTHER_ERROR;
52 scoped_ptr<google_apis::ResourceEntry> resource_entry;
53 fake_service()->AddNewDirectory(
54 fake_service()->GetRootResourceId(),
55 "New Directory 1!",
56 google_apis::test_util::CreateCopyResultCallback(
57 &gdata_error, &resource_entry));
58 test_util::RunBlockingPoolTask();
59 ASSERT_EQ(google_apis::HTTP_CREATED, gdata_error);
61 // As the result of the first Search(), only entries in the current file
62 // system snapshot are expected to be returned in the "right" path. New
63 // entries like "New Directory 1!" is temporarily added to "drive/other".
64 std::set<std::string> expected_results;
65 expected_results.insert("drive/root/Directory 1");
66 expected_results.insert("drive/other/New Directory 1!");
68 FileError error = FILE_ERROR_FAILED;
69 GURL next_link;
70 scoped_ptr<std::vector<SearchResultInfo> > results;
72 operation.Search("\"Directory 1\"", GURL(),
73 google_apis::test_util::CreateCopyResultCallback(
74 &error, &next_link, &results));
75 test_util::RunBlockingPoolTask();
77 EXPECT_EQ(FILE_ERROR_OK, error);
78 EXPECT_TRUE(next_link.is_empty());
79 ASSERT_EQ(expected_results.size(), results->size());
80 for (size_t i = 0; i < results->size(); i++) {
81 EXPECT_TRUE(expected_results.count(results->at(i).path.AsUTF8Unsafe()))
82 << results->at(i).path.AsUTF8Unsafe();
85 // Load the change from FakeDriveService.
86 ASSERT_EQ(FILE_ERROR_OK, CheckForUpdates());
88 // Now the new entry must be reported to be in the right directory.
89 expected_results.clear();
90 expected_results.insert("drive/root/Directory 1");
91 expected_results.insert("drive/root/New Directory 1!");
92 error = FILE_ERROR_FAILED;
93 operation.Search("\"Directory 1\"", GURL(),
94 google_apis::test_util::CreateCopyResultCallback(
95 &error, &next_link, &results));
96 test_util::RunBlockingPoolTask();
98 EXPECT_EQ(FILE_ERROR_OK, error);
99 EXPECT_TRUE(next_link.is_empty());
100 ASSERT_EQ(expected_results.size(), results->size());
101 for (size_t i = 0; i < results->size(); i++) {
102 EXPECT_TRUE(expected_results.count(results->at(i).path.AsUTF8Unsafe()))
103 << results->at(i).path.AsUTF8Unsafe();
107 TEST_F(SearchOperationTest, ContentSearchEmptyResult) {
108 SearchOperation operation(blocking_task_runner(), scheduler(), metadata());
110 FileError error = FILE_ERROR_FAILED;
111 GURL next_link;
112 scoped_ptr<std::vector<SearchResultInfo> > results;
114 operation.Search("\"no-match query\"", GURL(),
115 google_apis::test_util::CreateCopyResultCallback(
116 &error, &next_link, &results));
117 test_util::RunBlockingPoolTask();
119 EXPECT_EQ(FILE_ERROR_OK, error);
120 EXPECT_TRUE(next_link.is_empty());
121 EXPECT_EQ(0U, results->size());
124 } // namespace file_system
125 } // namespace drive