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

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

Issue 1124813003: [chrome/browser/chromeos/drive] Avoid use of MessageLoopProxy by use of TTRH (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/search_metadata.h" 5 #include "chrome/browser/chromeos/drive/search_metadata.h"
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/i18n/string_search.h" 9 #include "base/i18n/string_search.h"
10 #include "base/message_loop/message_loop_proxy.h"
11 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/thread_task_runner_handle.h"
13 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h" 14 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h"
14 #include "chrome/browser/chromeos/drive/file_cache.h" 15 #include "chrome/browser/chromeos/drive/file_cache.h"
15 #include "chrome/browser/chromeos/drive/file_system_util.h" 16 #include "chrome/browser/chromeos/drive/file_system_util.h"
16 #include "chrome/browser/chromeos/drive/test_util.h" 17 #include "chrome/browser/chromeos/drive/test_util.h"
17 #include "chrome/browser/drive/drive_api_util.h" 18 #include "chrome/browser/drive/drive_api_util.h"
18 #include "content/public/test/test_browser_thread_bundle.h" 19 #include "content/public/test/test_browser_thread_bundle.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 21
21 namespace drive { 22 namespace drive {
22 namespace internal { 23 namespace internal {
(...skipping 15 matching lines...) Expand all
38 39
39 } // namespace 40 } // namespace
40 41
41 class SearchMetadataTest : public testing::Test { 42 class SearchMetadataTest : public testing::Test {
42 protected: 43 protected:
43 void SetUp() override { 44 void SetUp() override {
44 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 45 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
45 fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter); 46 fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter);
46 47
47 metadata_storage_.reset(new ResourceMetadataStorage( 48 metadata_storage_.reset(new ResourceMetadataStorage(
48 temp_dir_.path(), base::MessageLoopProxy::current().get())); 49 temp_dir_.path(), base::ThreadTaskRunnerHandle::Get()));
49 ASSERT_TRUE(metadata_storage_->Initialize()); 50 ASSERT_TRUE(metadata_storage_->Initialize());
50 51
51 cache_.reset(new FileCache(metadata_storage_.get(), 52 cache_.reset(new FileCache(metadata_storage_.get(), temp_dir_.path(),
52 temp_dir_.path(), 53 base::ThreadTaskRunnerHandle::Get(),
53 base::MessageLoopProxy::current().get(),
54 fake_free_disk_space_getter_.get())); 54 fake_free_disk_space_getter_.get()));
55 ASSERT_TRUE(cache_->Initialize()); 55 ASSERT_TRUE(cache_->Initialize());
56 56
57 resource_metadata_.reset( 57 resource_metadata_.reset(
58 new ResourceMetadata(metadata_storage_.get(), 58 new ResourceMetadata(metadata_storage_.get(), cache_.get(),
59 cache_.get(), 59 base::ThreadTaskRunnerHandle::Get()));
60 base::MessageLoopProxy::current()));
61 ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->Initialize()); 60 ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->Initialize());
62 61
63 AddEntriesToMetadata(); 62 AddEntriesToMetadata();
64 } 63 }
65 64
66 void AddEntriesToMetadata() { 65 void AddEntriesToMetadata() {
67 base::FilePath temp_file; 66 base::FilePath temp_file;
68 EXPECT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &temp_file)); 67 EXPECT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &temp_file));
69 const std::string temp_file_md5 = "md5"; 68 const std::string temp_file_md5 = "md5";
70 69
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 scoped_ptr<ResourceMetadata, test_util::DestroyHelperForTests> 155 scoped_ptr<ResourceMetadata, test_util::DestroyHelperForTests>
157 resource_metadata_; 156 resource_metadata_;
158 scoped_ptr<FileCache, test_util::DestroyHelperForTests> cache_; 157 scoped_ptr<FileCache, test_util::DestroyHelperForTests> cache_;
159 }; 158 };
160 159
161 TEST_F(SearchMetadataTest, SearchMetadata_ZeroMatches) { 160 TEST_F(SearchMetadataTest, SearchMetadata_ZeroMatches) {
162 FileError error = FILE_ERROR_FAILED; 161 FileError error = FILE_ERROR_FAILED;
163 scoped_ptr<MetadataSearchResultVector> result; 162 scoped_ptr<MetadataSearchResultVector> result;
164 163
165 SearchMetadata( 164 SearchMetadata(
166 base::MessageLoopProxy::current(), resource_metadata_.get(), 165 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(),
167 "NonExistent", base::Bind(&MatchesType, SEARCH_METADATA_ALL), 166 "NonExistent", base::Bind(&MatchesType, SEARCH_METADATA_ALL),
168 kDefaultAtMostNumMatches, 167 kDefaultAtMostNumMatches,
169 google_apis::test_util::CreateCopyResultCallback(&error, &result)); 168 google_apis::test_util::CreateCopyResultCallback(&error, &result));
170 base::RunLoop().RunUntilIdle(); 169 base::RunLoop().RunUntilIdle();
171 EXPECT_EQ(FILE_ERROR_OK, error); 170 EXPECT_EQ(FILE_ERROR_OK, error);
172 ASSERT_TRUE(result); 171 ASSERT_TRUE(result);
173 ASSERT_EQ(0U, result->size()); 172 ASSERT_EQ(0U, result->size());
174 } 173 }
175 174
176 TEST_F(SearchMetadataTest, SearchMetadata_RegularFile) { 175 TEST_F(SearchMetadataTest, SearchMetadata_RegularFile) {
177 FileError error = FILE_ERROR_FAILED; 176 FileError error = FILE_ERROR_FAILED;
178 scoped_ptr<MetadataSearchResultVector> result; 177 scoped_ptr<MetadataSearchResultVector> result;
179 178
180 SearchMetadata( 179 SearchMetadata(
181 base::MessageLoopProxy::current(), resource_metadata_.get(), 180 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(),
182 "SubDirectory File 1.txt", base::Bind(&MatchesType, SEARCH_METADATA_ALL), 181 "SubDirectory File 1.txt", base::Bind(&MatchesType, SEARCH_METADATA_ALL),
183 kDefaultAtMostNumMatches, 182 kDefaultAtMostNumMatches,
184 google_apis::test_util::CreateCopyResultCallback(&error, &result)); 183 google_apis::test_util::CreateCopyResultCallback(&error, &result));
185 base::RunLoop().RunUntilIdle(); 184 base::RunLoop().RunUntilIdle();
186 EXPECT_EQ(FILE_ERROR_OK, error); 185 EXPECT_EQ(FILE_ERROR_OK, error);
187 ASSERT_TRUE(result); 186 ASSERT_TRUE(result);
188 ASSERT_EQ(1U, result->size()); 187 ASSERT_EQ(1U, result->size());
189 EXPECT_EQ("drive/root/Directory 1/SubDirectory File 1.txt", 188 EXPECT_EQ("drive/root/Directory 1/SubDirectory File 1.txt",
190 result->at(0).path.AsUTF8Unsafe()); 189 result->at(0).path.AsUTF8Unsafe());
191 } 190 }
192 191
193 // This test checks if |FindAndHighlightWrapper| does case-insensitive search. 192 // This test checks if |FindAndHighlightWrapper| does case-insensitive search.
194 // Tricker test cases for |FindAndHighlightWrapper| can be found below. 193 // Tricker test cases for |FindAndHighlightWrapper| can be found below.
195 TEST_F(SearchMetadataTest, SearchMetadata_CaseInsensitiveSearch) { 194 TEST_F(SearchMetadataTest, SearchMetadata_CaseInsensitiveSearch) {
196 FileError error = FILE_ERROR_FAILED; 195 FileError error = FILE_ERROR_FAILED;
197 scoped_ptr<MetadataSearchResultVector> result; 196 scoped_ptr<MetadataSearchResultVector> result;
198 197
199 // The query is all in lower case. 198 // The query is all in lower case.
200 SearchMetadata( 199 SearchMetadata(
201 base::MessageLoopProxy::current(), resource_metadata_.get(), 200 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(),
202 "subdirectory file 1.txt", base::Bind(&MatchesType, SEARCH_METADATA_ALL), 201 "subdirectory file 1.txt", base::Bind(&MatchesType, SEARCH_METADATA_ALL),
203 kDefaultAtMostNumMatches, 202 kDefaultAtMostNumMatches,
204 google_apis::test_util::CreateCopyResultCallback(&error, &result)); 203 google_apis::test_util::CreateCopyResultCallback(&error, &result));
205 base::RunLoop().RunUntilIdle(); 204 base::RunLoop().RunUntilIdle();
206 EXPECT_EQ(FILE_ERROR_OK, error); 205 EXPECT_EQ(FILE_ERROR_OK, error);
207 ASSERT_TRUE(result); 206 ASSERT_TRUE(result);
208 ASSERT_EQ(1U, result->size()); 207 ASSERT_EQ(1U, result->size());
209 EXPECT_EQ("drive/root/Directory 1/SubDirectory File 1.txt", 208 EXPECT_EQ("drive/root/Directory 1/SubDirectory File 1.txt",
210 result->at(0).path.AsUTF8Unsafe()); 209 result->at(0).path.AsUTF8Unsafe());
211 } 210 }
212 211
213 TEST_F(SearchMetadataTest, SearchMetadata_RegularFiles) { 212 TEST_F(SearchMetadataTest, SearchMetadata_RegularFiles) {
214 FileError error = FILE_ERROR_FAILED; 213 FileError error = FILE_ERROR_FAILED;
215 scoped_ptr<MetadataSearchResultVector> result; 214 scoped_ptr<MetadataSearchResultVector> result;
216 215
217 SearchMetadata( 216 SearchMetadata(
218 base::MessageLoopProxy::current(), resource_metadata_.get(), "SubDir", 217 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(), "SubDir",
219 base::Bind(&MatchesType, SEARCH_METADATA_ALL), kDefaultAtMostNumMatches, 218 base::Bind(&MatchesType, SEARCH_METADATA_ALL), kDefaultAtMostNumMatches,
220 google_apis::test_util::CreateCopyResultCallback(&error, &result)); 219 google_apis::test_util::CreateCopyResultCallback(&error, &result));
221 base::RunLoop().RunUntilIdle(); 220 base::RunLoop().RunUntilIdle();
222 EXPECT_EQ(FILE_ERROR_OK, error); 221 EXPECT_EQ(FILE_ERROR_OK, error);
223 ASSERT_TRUE(result); 222 ASSERT_TRUE(result);
224 ASSERT_EQ(2U, result->size()); 223 ASSERT_EQ(2U, result->size());
225 224
226 // All base names should contain "File". The results should be sorted by the 225 // All base names should contain "File". The results should be sorted by the
227 // last accessed time in descending order. 226 // last accessed time in descending order.
228 EXPECT_EQ("drive/root/Slash \xE2\x88\x95 in directory/Slash SubDir File.txt", 227 EXPECT_EQ("drive/root/Slash \xE2\x88\x95 in directory/Slash SubDir File.txt",
229 result->at(0).path.AsUTF8Unsafe()); 228 result->at(0).path.AsUTF8Unsafe());
230 EXPECT_EQ("drive/root/Directory 1/SubDirectory File 1.txt", 229 EXPECT_EQ("drive/root/Directory 1/SubDirectory File 1.txt",
231 result->at(1).path.AsUTF8Unsafe()); 230 result->at(1).path.AsUTF8Unsafe());
232 } 231 }
233 232
234 TEST_F(SearchMetadataTest, SearchMetadata_AtMostOneFile) { 233 TEST_F(SearchMetadataTest, SearchMetadata_AtMostOneFile) {
235 FileError error = FILE_ERROR_FAILED; 234 FileError error = FILE_ERROR_FAILED;
236 scoped_ptr<MetadataSearchResultVector> result; 235 scoped_ptr<MetadataSearchResultVector> result;
237 236
238 // There are two files matching "SubDir" but only one file should be 237 // There are two files matching "SubDir" but only one file should be
239 // returned. 238 // returned.
240 SearchMetadata( 239 SearchMetadata(
241 base::MessageLoopProxy::current(), resource_metadata_.get(), "SubDir", 240 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(), "SubDir",
242 base::Bind(&MatchesType, SEARCH_METADATA_ALL), 241 base::Bind(&MatchesType, SEARCH_METADATA_ALL),
243 1, // at_most_num_matches 242 1, // at_most_num_matches
244 google_apis::test_util::CreateCopyResultCallback(&error, &result)); 243 google_apis::test_util::CreateCopyResultCallback(&error, &result));
245 base::RunLoop().RunUntilIdle(); 244 base::RunLoop().RunUntilIdle();
246 EXPECT_EQ(FILE_ERROR_OK, error); 245 EXPECT_EQ(FILE_ERROR_OK, error);
247 ASSERT_TRUE(result); 246 ASSERT_TRUE(result);
248 ASSERT_EQ(1U, result->size()); 247 ASSERT_EQ(1U, result->size());
249 EXPECT_EQ("drive/root/Slash \xE2\x88\x95 in directory/Slash SubDir File.txt", 248 EXPECT_EQ("drive/root/Slash \xE2\x88\x95 in directory/Slash SubDir File.txt",
250 result->at(0).path.AsUTF8Unsafe()); 249 result->at(0).path.AsUTF8Unsafe());
251 } 250 }
252 251
253 TEST_F(SearchMetadataTest, SearchMetadata_Directory) { 252 TEST_F(SearchMetadataTest, SearchMetadata_Directory) {
254 FileError error = FILE_ERROR_FAILED; 253 FileError error = FILE_ERROR_FAILED;
255 scoped_ptr<MetadataSearchResultVector> result; 254 scoped_ptr<MetadataSearchResultVector> result;
256 255
257 SearchMetadata( 256 SearchMetadata(
258 base::MessageLoopProxy::current(), resource_metadata_.get(), 257 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(),
259 "Directory 1", base::Bind(&MatchesType, SEARCH_METADATA_ALL), 258 "Directory 1", base::Bind(&MatchesType, SEARCH_METADATA_ALL),
260 kDefaultAtMostNumMatches, 259 kDefaultAtMostNumMatches,
261 google_apis::test_util::CreateCopyResultCallback(&error, &result)); 260 google_apis::test_util::CreateCopyResultCallback(&error, &result));
262 base::RunLoop().RunUntilIdle(); 261 base::RunLoop().RunUntilIdle();
263 EXPECT_EQ(FILE_ERROR_OK, error); 262 EXPECT_EQ(FILE_ERROR_OK, error);
264 ASSERT_TRUE(result); 263 ASSERT_TRUE(result);
265 ASSERT_EQ(1U, result->size()); 264 ASSERT_EQ(1U, result->size());
266 EXPECT_EQ("drive/root/Directory 1", result->at(0).path.AsUTF8Unsafe()); 265 EXPECT_EQ("drive/root/Directory 1", result->at(0).path.AsUTF8Unsafe());
267 } 266 }
268 267
269 TEST_F(SearchMetadataTest, SearchMetadata_HostedDocument) { 268 TEST_F(SearchMetadataTest, SearchMetadata_HostedDocument) {
270 FileError error = FILE_ERROR_FAILED; 269 FileError error = FILE_ERROR_FAILED;
271 scoped_ptr<MetadataSearchResultVector> result; 270 scoped_ptr<MetadataSearchResultVector> result;
272 271
273 SearchMetadata( 272 SearchMetadata(
274 base::MessageLoopProxy::current(), resource_metadata_.get(), "Document", 273 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(), "Document",
275 base::Bind(&MatchesType, SEARCH_METADATA_ALL), kDefaultAtMostNumMatches, 274 base::Bind(&MatchesType, SEARCH_METADATA_ALL), kDefaultAtMostNumMatches,
276 google_apis::test_util::CreateCopyResultCallback(&error, &result)); 275 google_apis::test_util::CreateCopyResultCallback(&error, &result));
277 base::RunLoop().RunUntilIdle(); 276 base::RunLoop().RunUntilIdle();
278 EXPECT_EQ(FILE_ERROR_OK, error); 277 EXPECT_EQ(FILE_ERROR_OK, error);
279 ASSERT_TRUE(result); 278 ASSERT_TRUE(result);
280 ASSERT_EQ(1U, result->size()); 279 ASSERT_EQ(1U, result->size());
281 280
282 EXPECT_EQ("drive/root/Document 1 excludeDir-test.gdoc", 281 EXPECT_EQ("drive/root/Document 1 excludeDir-test.gdoc",
283 result->at(0).path.AsUTF8Unsafe()); 282 result->at(0).path.AsUTF8Unsafe());
284 } 283 }
285 284
286 TEST_F(SearchMetadataTest, SearchMetadata_ExcludeHostedDocument) { 285 TEST_F(SearchMetadataTest, SearchMetadata_ExcludeHostedDocument) {
287 FileError error = FILE_ERROR_FAILED; 286 FileError error = FILE_ERROR_FAILED;
288 scoped_ptr<MetadataSearchResultVector> result; 287 scoped_ptr<MetadataSearchResultVector> result;
289 288
290 SearchMetadata( 289 SearchMetadata(
291 base::MessageLoopProxy::current(), resource_metadata_.get(), "Document", 290 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(), "Document",
292 base::Bind(&MatchesType, SEARCH_METADATA_EXCLUDE_HOSTED_DOCUMENTS), 291 base::Bind(&MatchesType, SEARCH_METADATA_EXCLUDE_HOSTED_DOCUMENTS),
293 kDefaultAtMostNumMatches, 292 kDefaultAtMostNumMatches,
294 google_apis::test_util::CreateCopyResultCallback(&error, &result)); 293 google_apis::test_util::CreateCopyResultCallback(&error, &result));
295 base::RunLoop().RunUntilIdle(); 294 base::RunLoop().RunUntilIdle();
296 EXPECT_EQ(FILE_ERROR_OK, error); 295 EXPECT_EQ(FILE_ERROR_OK, error);
297 ASSERT_TRUE(result); 296 ASSERT_TRUE(result);
298 ASSERT_EQ(0U, result->size()); 297 ASSERT_EQ(0U, result->size());
299 } 298 }
300 299
301 TEST_F(SearchMetadataTest, SearchMetadata_SharedWithMe) { 300 TEST_F(SearchMetadataTest, SearchMetadata_SharedWithMe) {
302 FileError error = FILE_ERROR_FAILED; 301 FileError error = FILE_ERROR_FAILED;
303 scoped_ptr<MetadataSearchResultVector> result; 302 scoped_ptr<MetadataSearchResultVector> result;
304 303
305 SearchMetadata( 304 SearchMetadata(
306 base::MessageLoopProxy::current(), resource_metadata_.get(), "", 305 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(), "",
307 base::Bind(&MatchesType, SEARCH_METADATA_SHARED_WITH_ME), 306 base::Bind(&MatchesType, SEARCH_METADATA_SHARED_WITH_ME),
308 kDefaultAtMostNumMatches, 307 kDefaultAtMostNumMatches,
309 google_apis::test_util::CreateCopyResultCallback(&error, &result)); 308 google_apis::test_util::CreateCopyResultCallback(&error, &result));
310 base::RunLoop().RunUntilIdle(); 309 base::RunLoop().RunUntilIdle();
311 EXPECT_EQ(FILE_ERROR_OK, error); 310 EXPECT_EQ(FILE_ERROR_OK, error);
312 ASSERT_TRUE(result); 311 ASSERT_TRUE(result);
313 ASSERT_EQ(1U, result->size()); 312 ASSERT_EQ(1U, result->size());
314 EXPECT_EQ("drive/root/Directory 1/Shared To The Account Owner.txt", 313 EXPECT_EQ("drive/root/Directory 1/Shared To The Account Owner.txt",
315 result->at(0).path.AsUTF8Unsafe()); 314 result->at(0).path.AsUTF8Unsafe());
316 } 315 }
317 316
318 TEST_F(SearchMetadataTest, SearchMetadata_FileAndDirectory) { 317 TEST_F(SearchMetadataTest, SearchMetadata_FileAndDirectory) {
319 FileError error = FILE_ERROR_FAILED; 318 FileError error = FILE_ERROR_FAILED;
320 scoped_ptr<MetadataSearchResultVector> result; 319 scoped_ptr<MetadataSearchResultVector> result;
321 320
322 SearchMetadata( 321 SearchMetadata(
323 base::MessageLoopProxy::current(), resource_metadata_.get(), 322 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(),
324 "excludeDir-test", base::Bind(&MatchesType, SEARCH_METADATA_ALL), 323 "excludeDir-test", base::Bind(&MatchesType, SEARCH_METADATA_ALL),
325 kDefaultAtMostNumMatches, 324 kDefaultAtMostNumMatches,
326 google_apis::test_util::CreateCopyResultCallback(&error, &result)); 325 google_apis::test_util::CreateCopyResultCallback(&error, &result));
327 326
328 base::RunLoop().RunUntilIdle(); 327 base::RunLoop().RunUntilIdle();
329 EXPECT_EQ(FILE_ERROR_OK, error); 328 EXPECT_EQ(FILE_ERROR_OK, error);
330 ASSERT_TRUE(result); 329 ASSERT_TRUE(result);
331 ASSERT_EQ(2U, result->size()); 330 ASSERT_EQ(2U, result->size());
332 331
333 EXPECT_EQ("drive/root/Document 1 excludeDir-test.gdoc", 332 EXPECT_EQ("drive/root/Document 1 excludeDir-test.gdoc",
334 result->at(0).path.AsUTF8Unsafe()); 333 result->at(0).path.AsUTF8Unsafe());
335 EXPECT_EQ("drive/root/Directory 2 excludeDir-test", 334 EXPECT_EQ("drive/root/Directory 2 excludeDir-test",
336 result->at(1).path.AsUTF8Unsafe()); 335 result->at(1).path.AsUTF8Unsafe());
337 } 336 }
338 337
339 TEST_F(SearchMetadataTest, SearchMetadata_ExcludeDirectory) { 338 TEST_F(SearchMetadataTest, SearchMetadata_ExcludeDirectory) {
340 FileError error = FILE_ERROR_FAILED; 339 FileError error = FILE_ERROR_FAILED;
341 scoped_ptr<MetadataSearchResultVector> result; 340 scoped_ptr<MetadataSearchResultVector> result;
342 341
343 SearchMetadata( 342 SearchMetadata(
344 base::MessageLoopProxy::current(), resource_metadata_.get(), 343 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(),
345 "excludeDir-test", 344 "excludeDir-test",
346 base::Bind(&MatchesType, SEARCH_METADATA_EXCLUDE_DIRECTORIES), 345 base::Bind(&MatchesType, SEARCH_METADATA_EXCLUDE_DIRECTORIES),
347 kDefaultAtMostNumMatches, 346 kDefaultAtMostNumMatches,
348 google_apis::test_util::CreateCopyResultCallback(&error, &result)); 347 google_apis::test_util::CreateCopyResultCallback(&error, &result));
349 348
350 base::RunLoop().RunUntilIdle(); 349 base::RunLoop().RunUntilIdle();
351 EXPECT_EQ(FILE_ERROR_OK, error); 350 EXPECT_EQ(FILE_ERROR_OK, error);
352 ASSERT_TRUE(result); 351 ASSERT_TRUE(result);
353 ASSERT_EQ(1U, result->size()); 352 ASSERT_EQ(1U, result->size());
354 353
355 EXPECT_EQ("drive/root/Document 1 excludeDir-test.gdoc", 354 EXPECT_EQ("drive/root/Document 1 excludeDir-test.gdoc",
356 result->at(0).path.AsUTF8Unsafe()); 355 result->at(0).path.AsUTF8Unsafe());
357 } 356 }
358 357
359 // "drive", "drive/root", "drive/other" should be excluded. 358 // "drive", "drive/root", "drive/other" should be excluded.
360 TEST_F(SearchMetadataTest, SearchMetadata_ExcludeSpecialDirectories) { 359 TEST_F(SearchMetadataTest, SearchMetadata_ExcludeSpecialDirectories) {
361 const char* const kQueries[] = { "drive", "root", "other" }; 360 const char* const kQueries[] = { "drive", "root", "other" };
362 for (size_t i = 0; i < arraysize(kQueries); ++i) { 361 for (size_t i = 0; i < arraysize(kQueries); ++i) {
363 FileError error = FILE_ERROR_FAILED; 362 FileError error = FILE_ERROR_FAILED;
364 scoped_ptr<MetadataSearchResultVector> result; 363 scoped_ptr<MetadataSearchResultVector> result;
365 364
366 const std::string query = kQueries[i]; 365 const std::string query = kQueries[i];
367 SearchMetadata( 366 SearchMetadata(
368 base::MessageLoopProxy::current(), resource_metadata_.get(), query, 367 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(), query,
369 base::Bind(&MatchesType, SEARCH_METADATA_ALL), kDefaultAtMostNumMatches, 368 base::Bind(&MatchesType, SEARCH_METADATA_ALL), kDefaultAtMostNumMatches,
370 google_apis::test_util::CreateCopyResultCallback(&error, &result)); 369 google_apis::test_util::CreateCopyResultCallback(&error, &result));
371 370
372 base::RunLoop().RunUntilIdle(); 371 base::RunLoop().RunUntilIdle();
373 EXPECT_EQ(FILE_ERROR_OK, error); 372 EXPECT_EQ(FILE_ERROR_OK, error);
374 ASSERT_TRUE(result); 373 ASSERT_TRUE(result);
375 ASSERT_TRUE(result->empty()) << ": " << query << " should not match"; 374 ASSERT_TRUE(result->empty()) << ": " << query << " should not match";
376 } 375 }
377 } 376 }
378 377
379 TEST_F(SearchMetadataTest, SearchMetadata_Offline) { 378 TEST_F(SearchMetadataTest, SearchMetadata_Offline) {
380 FileError error = FILE_ERROR_FAILED; 379 FileError error = FILE_ERROR_FAILED;
381 scoped_ptr<MetadataSearchResultVector> result; 380 scoped_ptr<MetadataSearchResultVector> result;
382 381
383 SearchMetadata( 382 SearchMetadata(
384 base::MessageLoopProxy::current(), resource_metadata_.get(), "", 383 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(), "",
385 base::Bind(&MatchesType, SEARCH_METADATA_OFFLINE), 384 base::Bind(&MatchesType, SEARCH_METADATA_OFFLINE),
386 kDefaultAtMostNumMatches, 385 kDefaultAtMostNumMatches,
387 google_apis::test_util::CreateCopyResultCallback(&error, &result)); 386 google_apis::test_util::CreateCopyResultCallback(&error, &result));
388 base::RunLoop().RunUntilIdle(); 387 base::RunLoop().RunUntilIdle();
389 EXPECT_EQ(FILE_ERROR_OK, error); 388 EXPECT_EQ(FILE_ERROR_OK, error);
390 ASSERT_EQ(3U, result->size()); 389 ASSERT_EQ(3U, result->size());
391 390
392 // This is not included in the cache but is a hosted document. 391 // This is not included in the cache but is a hosted document.
393 EXPECT_EQ("drive/root/Document 1 excludeDir-test.gdoc", 392 EXPECT_EQ("drive/root/Document 1 excludeDir-test.gdoc",
394 result->at(0).path.AsUTF8Unsafe()); 393 result->at(0).path.AsUTF8Unsafe());
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 } 489 }
491 490
492 TEST(SearchMetadataSimpleTest, FindAndHighlight_MoreMetaChars) { 491 TEST(SearchMetadataSimpleTest, FindAndHighlight_MoreMetaChars) {
493 std::string highlighted_text; 492 std::string highlighted_text;
494 EXPECT_TRUE(FindAndHighlightWrapper("a&b&c&d", "b&c", &highlighted_text)); 493 EXPECT_TRUE(FindAndHighlightWrapper("a&b&c&d", "b&c", &highlighted_text));
495 EXPECT_EQ("a&amp;<b>b&amp;c</b>&amp;d", highlighted_text); 494 EXPECT_EQ("a&amp;<b>b&amp;c</b>&amp;d", highlighted_text);
496 } 495 }
497 496
498 } // namespace internal 497 } // namespace internal
499 } // namespace drive 498 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698