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

Side by Side Diff: chrome/browser/chromeos/drive/file_system/search_operation_unittest.cc

Issue 16142003: Report all Drive search results even if resource metadata is not fully loaded. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 7 years, 6 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 | « chrome/browser/chromeos/drive/file_system/search_operation.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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/search_operation.h" 5 #include "chrome/browser/chromeos/drive/file_system/search_operation.h"
6 6
7 #include "chrome/browser/chromeos/drive/change_list_loader.h"
7 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" 8 #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/fake_drive_service.h"
9 #include "chrome/browser/google_apis/gdata_wapi_parser.h" 10 #include "chrome/browser/google_apis/gdata_wapi_parser.h"
10 #include "chrome/browser/google_apis/test_util.h" 11 #include "chrome/browser/google_apis/test_util.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 namespace drive { 14 namespace drive {
14 namespace file_system { 15 namespace file_system {
15 16
16 namespace { 17 namespace {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 scoped_ptr<google_apis::ResourceEntry> resource_entry; 64 scoped_ptr<google_apis::ResourceEntry> resource_entry;
64 fake_service()->AddNewDirectory( 65 fake_service()->AddNewDirectory(
65 fake_service()->GetRootResourceId(), 66 fake_service()->GetRootResourceId(),
66 "New Directory 1!", 67 "New Directory 1!",
67 google_apis::test_util::CreateCopyResultCallback( 68 google_apis::test_util::CreateCopyResultCallback(
68 &gdata_error, &resource_entry)); 69 &gdata_error, &resource_entry));
69 google_apis::test_util::RunBlockingPoolTask(); 70 google_apis::test_util::RunBlockingPoolTask();
70 ASSERT_EQ(google_apis::HTTP_CREATED, gdata_error); 71 ASSERT_EQ(google_apis::HTTP_CREATED, gdata_error);
71 72
72 // As the result of the first Search(), only entries in the current file 73 // 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 // system snapshot are expected to be returned in the "right" path. New
74 // shouldn't be included in the search result even though it matches 75 // entries like "New Directory 1!" is temporarily added to "drive/other".
75 // "Directory 1". 76 const SearchResultPair kExpectedResultsBeforeLoad[] = {
76 const SearchResultPair kExpectedResults[] = { 77 { "drive/root/Directory 1", true },
77 { "drive/root/Directory 1", true } 78 { "drive/other/New Directory 1!", true },
78 }; 79 };
79 80
80 FileError error = FILE_ERROR_FAILED; 81 FileError error = FILE_ERROR_FAILED;
81 GURL next_feed; 82 GURL next_feed;
82 scoped_ptr<std::vector<SearchResultInfo> > results; 83 scoped_ptr<std::vector<SearchResultInfo> > results;
83 84
84 operation.Search("\"Directory 1\"", GURL(), 85 operation.Search("\"Directory 1\"", GURL(),
85 google_apis::test_util::CreateCopyResultCallback( 86 google_apis::test_util::CreateCopyResultCallback(
86 &error, &next_feed, &results)); 87 &error, &next_feed, &results));
87 google_apis::test_util::RunBlockingPoolTask(); 88 google_apis::test_util::RunBlockingPoolTask();
88 89
89 EXPECT_EQ(FILE_ERROR_OK, error); 90 EXPECT_EQ(FILE_ERROR_OK, error);
90 EXPECT_EQ(GURL(), next_feed); 91 EXPECT_EQ(GURL(), next_feed);
91 ASSERT_EQ(1U, results->size()); 92 ASSERT_EQ(ARRAYSIZE_UNSAFE(kExpectedResultsBeforeLoad), results->size());
92 EXPECT_EQ(kExpectedResults[0].path, results->at(0).path.AsUTF8Unsafe()); 93 for (size_t i = 0; i < results->size(); i++) {
94 EXPECT_EQ(kExpectedResultsBeforeLoad[i].path,
95 results->at(i).path.AsUTF8Unsafe());
96 EXPECT_EQ(kExpectedResultsBeforeLoad[i].is_directory,
97 results->at(i).entry.file_info().is_directory());
98 }
99
100 // Load the change from FakeDriveService.
101 internal::ChangeListLoader change_list_loader(
102 blocking_task_runner(), metadata(), scheduler());
103 change_list_loader.CheckForUpdates(
104 google_apis::test_util::CreateCopyResultCallback(&error));
105 google_apis::test_util::RunBlockingPoolTask();
106
107 // Now the new entry must be reported to be in the right directory.
108 const SearchResultPair kExpectedResultsAfterLoad[] = {
109 { "drive/root/Directory 1", true },
110 { "drive/root/New Directory 1!", true },
111 };
112 error = FILE_ERROR_FAILED;
113 operation.Search("\"Directory 1\"", GURL(),
114 google_apis::test_util::CreateCopyResultCallback(
115 &error, &next_feed, &results));
116 google_apis::test_util::RunBlockingPoolTask();
117
118 EXPECT_EQ(FILE_ERROR_OK, error);
119 EXPECT_EQ(GURL(), next_feed);
120 ASSERT_EQ(ARRAYSIZE_UNSAFE(kExpectedResultsAfterLoad), results->size());
121 for (size_t i = 0; i < results->size(); i++) {
122 EXPECT_EQ(kExpectedResultsAfterLoad[i].path,
123 results->at(i).path.AsUTF8Unsafe());
124 EXPECT_EQ(kExpectedResultsAfterLoad[i].is_directory,
125 results->at(i).entry.file_info().is_directory());
126 }
93 } 127 }
94 128
95 TEST_F(SearchOperationTest, ContentSearchEmptyResult) { 129 TEST_F(SearchOperationTest, ContentSearchEmptyResult) {
96 SearchOperation operation(blocking_task_runner(), scheduler(), metadata()); 130 SearchOperation operation(blocking_task_runner(), scheduler(), metadata());
97 131
98 FileError error = FILE_ERROR_FAILED; 132 FileError error = FILE_ERROR_FAILED;
99 GURL next_feed; 133 GURL next_feed;
100 scoped_ptr<std::vector<SearchResultInfo> > results; 134 scoped_ptr<std::vector<SearchResultInfo> > results;
101 135
102 operation.Search("\"no-match query\"", GURL(), 136 operation.Search("\"no-match query\"", GURL(),
103 google_apis::test_util::CreateCopyResultCallback( 137 google_apis::test_util::CreateCopyResultCallback(
104 &error, &next_feed, &results)); 138 &error, &next_feed, &results));
105 google_apis::test_util::RunBlockingPoolTask(); 139 google_apis::test_util::RunBlockingPoolTask();
106 140
107 EXPECT_EQ(FILE_ERROR_OK, error); 141 EXPECT_EQ(FILE_ERROR_OK, error);
108 EXPECT_EQ(GURL(), next_feed); 142 EXPECT_EQ(GURL(), next_feed);
109 EXPECT_EQ(0U, results->size()); 143 EXPECT_EQ(0U, results->size());
110 } 144 }
111 145
112 } // namespace file_system 146 } // namespace file_system
113 } // namespace drive 147 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_system/search_operation.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698