OLD | NEW |
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 "components/drive/search_metadata.h" | 5 #include "components/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/memory/scoped_vector.h" |
10 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
11 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
13 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
14 #include "components/drive/drive_api_util.h" | 15 #include "components/drive/drive_api_util.h" |
15 #include "components/drive/drive_test_util.h" | 16 #include "components/drive/drive_test_util.h" |
16 #include "components/drive/fake_free_disk_space_getter.h" | 17 #include "components/drive/fake_free_disk_space_getter.h" |
17 #include "components/drive/file_cache.h" | 18 #include "components/drive/file_cache.h" |
18 #include "components/drive/file_system_core_util.h" | 19 #include "components/drive/file_system_core_util.h" |
19 #include "content/public/test/test_browser_thread_bundle.h" | 20 #include "content/public/test/test_browser_thread_bundle.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 | 22 |
22 namespace drive { | 23 namespace drive { |
23 namespace internal { | 24 namespace internal { |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 const int kDefaultAtMostNumMatches = 10; | 28 const int kDefaultAtMostNumMatches = 10; |
28 | 29 |
29 // A simple wrapper for testing FindAndHighlightWrapper(). It just converts the | 30 // A simple wrapper for testing FindAndHighlightWrapper(). It just converts the |
30 // query text parameter to FixedPatternStringSearchIgnoringCaseAndAccents. | 31 // query text parameter to FixedPatternStringSearchIgnoringCaseAndAccents. |
31 bool FindAndHighlightWrapper( | 32 bool FindAndHighlightWrapper( |
32 const std::string& text, | 33 const std::string& text, |
33 const std::string& query_text, | 34 const std::string& query_text, |
34 std::string* highlighted_text) { | 35 std::string* highlighted_text) { |
35 base::i18n::FixedPatternStringSearchIgnoringCaseAndAccents query( | 36 ScopedVector<base::i18n::FixedPatternStringSearchIgnoringCaseAndAccents> |
36 base::UTF8ToUTF16(query_text)); | 37 queries; |
37 return FindAndHighlight(text, &query, highlighted_text); | 38 queries.push_back( |
| 39 new base::i18n::FixedPatternStringSearchIgnoringCaseAndAccents( |
| 40 base::UTF8ToUTF16(query_text))); |
| 41 return FindAndHighlight(text, queries, highlighted_text); |
38 } | 42 } |
39 | 43 |
40 } // namespace | 44 } // namespace |
41 | 45 |
42 class SearchMetadataTest : public testing::Test { | 46 class SearchMetadataTest : public testing::Test { |
43 protected: | 47 protected: |
44 void SetUp() override { | 48 void SetUp() override { |
45 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 49 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
46 fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter); | 50 fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter); |
47 | 51 |
(...skipping 22 matching lines...) Expand all Loading... |
70 const std::string temp_file_md5 = "md5"; | 74 const std::string temp_file_md5 = "md5"; |
71 | 75 |
72 ResourceEntry entry; | 76 ResourceEntry entry; |
73 std::string local_id; | 77 std::string local_id; |
74 | 78 |
75 // drive/root | 79 // drive/root |
76 EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->GetIdByPath( | 80 EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->GetIdByPath( |
77 util::GetDriveMyDriveRootPath(), &local_id)); | 81 util::GetDriveMyDriveRootPath(), &local_id)); |
78 const std::string root_local_id = local_id; | 82 const std::string root_local_id = local_id; |
79 | 83 |
80 // drive/root/Directory 1 | 84 // drive/root/Directory-1 |
81 EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(GetDirectoryEntry( | 85 EXPECT_EQ(FILE_ERROR_OK, |
82 "Directory 1", "dir1", 1, root_local_id), &local_id)); | 86 resource_metadata_->AddEntry( |
| 87 GetDirectoryEntry("Directory-1", "dir1", 1, root_local_id), |
| 88 &local_id)); |
83 const std::string dir1_local_id = local_id; | 89 const std::string dir1_local_id = local_id; |
84 | 90 |
85 // drive/root/Directory 1/SubDirectory File 1.txt | 91 // drive/root/Directory-1/SubDirectory File 1.txt |
86 EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(GetFileEntry( | 92 EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(GetFileEntry( |
87 "SubDirectory File 1.txt", "file1a", 2, dir1_local_id), &local_id)); | 93 "SubDirectory File 1.txt", "file1a", 2, dir1_local_id), &local_id)); |
88 EXPECT_EQ(FILE_ERROR_OK, cache_->Store( | 94 EXPECT_EQ(FILE_ERROR_OK, cache_->Store( |
89 local_id, temp_file_md5, temp_file, FileCache::FILE_OPERATION_COPY)); | 95 local_id, temp_file_md5, temp_file, FileCache::FILE_OPERATION_COPY)); |
90 | 96 |
91 // drive/root/Directory 1/Shared To The Account Owner.txt | 97 // drive/root/Directory-1/Shared To The Account Owner.txt |
92 entry = GetFileEntry( | 98 entry = GetFileEntry( |
93 "Shared To The Account Owner.txt", "file1b", 3, dir1_local_id); | 99 "Shared To The Account Owner.txt", "file1b", 3, dir1_local_id); |
94 entry.set_shared_with_me(true); | 100 entry.set_shared_with_me(true); |
95 EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(entry, &local_id)); | 101 EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(entry, &local_id)); |
96 | 102 |
97 // drive/root/Directory 2 excludeDir-test | 103 // drive/root/Directory 2 excludeDir-test |
98 EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(GetDirectoryEntry( | 104 EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(GetDirectoryEntry( |
99 "Directory 2 excludeDir-test", "dir2", 4, root_local_id), &local_id)); | 105 "Directory 2 excludeDir-test", "dir2", 4, root_local_id), &local_id)); |
100 | 106 |
101 // drive/root/Slash \xE2\x88\x95 in directory | 107 // drive/root/Slash \xE2\x88\x95 in directory |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 | 186 |
181 SearchMetadata( | 187 SearchMetadata( |
182 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(), | 188 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(), |
183 "SubDirectory File 1.txt", base::Bind(&MatchesType, SEARCH_METADATA_ALL), | 189 "SubDirectory File 1.txt", base::Bind(&MatchesType, SEARCH_METADATA_ALL), |
184 kDefaultAtMostNumMatches, | 190 kDefaultAtMostNumMatches, |
185 google_apis::test_util::CreateCopyResultCallback(&error, &result)); | 191 google_apis::test_util::CreateCopyResultCallback(&error, &result)); |
186 base::RunLoop().RunUntilIdle(); | 192 base::RunLoop().RunUntilIdle(); |
187 EXPECT_EQ(FILE_ERROR_OK, error); | 193 EXPECT_EQ(FILE_ERROR_OK, error); |
188 ASSERT_TRUE(result); | 194 ASSERT_TRUE(result); |
189 ASSERT_EQ(1U, result->size()); | 195 ASSERT_EQ(1U, result->size()); |
190 EXPECT_EQ("drive/root/Directory 1/SubDirectory File 1.txt", | 196 EXPECT_EQ("drive/root/Directory-1/SubDirectory File 1.txt", |
191 result->at(0).path.AsUTF8Unsafe()); | 197 result->at(0).path.AsUTF8Unsafe()); |
192 } | 198 } |
193 | 199 |
194 // This test checks if |FindAndHighlightWrapper| does case-insensitive search. | 200 // This test checks if |FindAndHighlightWrapper| does case-insensitive search. |
195 // Tricker test cases for |FindAndHighlightWrapper| can be found below. | 201 // Tricker test cases for |FindAndHighlightWrapper| can be found below. |
196 TEST_F(SearchMetadataTest, SearchMetadata_CaseInsensitiveSearch) { | 202 TEST_F(SearchMetadataTest, SearchMetadata_CaseInsensitiveSearch) { |
197 FileError error = FILE_ERROR_FAILED; | 203 FileError error = FILE_ERROR_FAILED; |
198 scoped_ptr<MetadataSearchResultVector> result; | 204 scoped_ptr<MetadataSearchResultVector> result; |
199 | 205 |
200 // The query is all in lower case. | 206 // The query is all in lower case. |
201 SearchMetadata( | 207 SearchMetadata( |
202 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(), | 208 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(), |
203 "subdirectory file 1.txt", base::Bind(&MatchesType, SEARCH_METADATA_ALL), | 209 "subdirectory file 1.txt", base::Bind(&MatchesType, SEARCH_METADATA_ALL), |
204 kDefaultAtMostNumMatches, | 210 kDefaultAtMostNumMatches, |
205 google_apis::test_util::CreateCopyResultCallback(&error, &result)); | 211 google_apis::test_util::CreateCopyResultCallback(&error, &result)); |
206 base::RunLoop().RunUntilIdle(); | 212 base::RunLoop().RunUntilIdle(); |
207 EXPECT_EQ(FILE_ERROR_OK, error); | 213 EXPECT_EQ(FILE_ERROR_OK, error); |
208 ASSERT_TRUE(result); | 214 ASSERT_TRUE(result); |
209 ASSERT_EQ(1U, result->size()); | 215 ASSERT_EQ(1U, result->size()); |
210 EXPECT_EQ("drive/root/Directory 1/SubDirectory File 1.txt", | 216 EXPECT_EQ("drive/root/Directory-1/SubDirectory File 1.txt", |
211 result->at(0).path.AsUTF8Unsafe()); | 217 result->at(0).path.AsUTF8Unsafe()); |
212 } | 218 } |
213 | 219 |
214 TEST_F(SearchMetadataTest, SearchMetadata_RegularFiles) { | 220 TEST_F(SearchMetadataTest, SearchMetadata_RegularFiles) { |
215 FileError error = FILE_ERROR_FAILED; | 221 FileError error = FILE_ERROR_FAILED; |
216 scoped_ptr<MetadataSearchResultVector> result; | 222 scoped_ptr<MetadataSearchResultVector> result; |
217 | 223 |
218 SearchMetadata( | 224 SearchMetadata( |
219 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(), "SubDir", | 225 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(), "SubDir", |
220 base::Bind(&MatchesType, SEARCH_METADATA_ALL), kDefaultAtMostNumMatches, | 226 base::Bind(&MatchesType, SEARCH_METADATA_ALL), kDefaultAtMostNumMatches, |
221 google_apis::test_util::CreateCopyResultCallback(&error, &result)); | 227 google_apis::test_util::CreateCopyResultCallback(&error, &result)); |
222 base::RunLoop().RunUntilIdle(); | 228 base::RunLoop().RunUntilIdle(); |
223 EXPECT_EQ(FILE_ERROR_OK, error); | 229 EXPECT_EQ(FILE_ERROR_OK, error); |
224 ASSERT_TRUE(result); | 230 ASSERT_TRUE(result); |
225 ASSERT_EQ(2U, result->size()); | 231 ASSERT_EQ(2U, result->size()); |
226 | 232 |
227 // All base names should contain "File". The results should be sorted by the | 233 // All base names should contain "File". The results should be sorted by the |
228 // last accessed time in descending order. | 234 // last accessed time in descending order. |
229 EXPECT_EQ("drive/root/Slash \xE2\x88\x95 in directory/Slash SubDir File.txt", | 235 EXPECT_EQ("drive/root/Slash \xE2\x88\x95 in directory/Slash SubDir File.txt", |
230 result->at(0).path.AsUTF8Unsafe()); | 236 result->at(0).path.AsUTF8Unsafe()); |
231 EXPECT_EQ("drive/root/Directory 1/SubDirectory File 1.txt", | 237 EXPECT_EQ("drive/root/Directory-1/SubDirectory File 1.txt", |
232 result->at(1).path.AsUTF8Unsafe()); | 238 result->at(1).path.AsUTF8Unsafe()); |
233 } | 239 } |
234 | 240 |
235 TEST_F(SearchMetadataTest, SearchMetadata_AtMostOneFile) { | 241 TEST_F(SearchMetadataTest, SearchMetadata_AtMostOneFile) { |
236 FileError error = FILE_ERROR_FAILED; | 242 FileError error = FILE_ERROR_FAILED; |
237 scoped_ptr<MetadataSearchResultVector> result; | 243 scoped_ptr<MetadataSearchResultVector> result; |
238 | 244 |
239 // There are two files matching "SubDir" but only one file should be | 245 // There are two files matching "SubDir" but only one file should be |
240 // returned. | 246 // returned. |
241 SearchMetadata( | 247 SearchMetadata( |
242 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(), "SubDir", | 248 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(), "SubDir", |
243 base::Bind(&MatchesType, SEARCH_METADATA_ALL), | 249 base::Bind(&MatchesType, SEARCH_METADATA_ALL), |
244 1, // at_most_num_matches | 250 1, // at_most_num_matches |
245 google_apis::test_util::CreateCopyResultCallback(&error, &result)); | 251 google_apis::test_util::CreateCopyResultCallback(&error, &result)); |
246 base::RunLoop().RunUntilIdle(); | 252 base::RunLoop().RunUntilIdle(); |
247 EXPECT_EQ(FILE_ERROR_OK, error); | 253 EXPECT_EQ(FILE_ERROR_OK, error); |
248 ASSERT_TRUE(result); | 254 ASSERT_TRUE(result); |
249 ASSERT_EQ(1U, result->size()); | 255 ASSERT_EQ(1U, result->size()); |
250 EXPECT_EQ("drive/root/Slash \xE2\x88\x95 in directory/Slash SubDir File.txt", | 256 EXPECT_EQ("drive/root/Slash \xE2\x88\x95 in directory/Slash SubDir File.txt", |
251 result->at(0).path.AsUTF8Unsafe()); | 257 result->at(0).path.AsUTF8Unsafe()); |
252 } | 258 } |
253 | 259 |
254 TEST_F(SearchMetadataTest, SearchMetadata_Directory) { | 260 TEST_F(SearchMetadataTest, SearchMetadata_Directory) { |
255 FileError error = FILE_ERROR_FAILED; | 261 FileError error = FILE_ERROR_FAILED; |
256 scoped_ptr<MetadataSearchResultVector> result; | 262 scoped_ptr<MetadataSearchResultVector> result; |
257 | 263 |
258 SearchMetadata( | 264 SearchMetadata( |
259 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(), | 265 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(), |
260 "Directory 1", base::Bind(&MatchesType, SEARCH_METADATA_ALL), | 266 "Directory-1", base::Bind(&MatchesType, SEARCH_METADATA_ALL), |
261 kDefaultAtMostNumMatches, | 267 kDefaultAtMostNumMatches, |
262 google_apis::test_util::CreateCopyResultCallback(&error, &result)); | 268 google_apis::test_util::CreateCopyResultCallback(&error, &result)); |
263 base::RunLoop().RunUntilIdle(); | 269 base::RunLoop().RunUntilIdle(); |
264 EXPECT_EQ(FILE_ERROR_OK, error); | 270 EXPECT_EQ(FILE_ERROR_OK, error); |
265 ASSERT_TRUE(result); | 271 ASSERT_TRUE(result); |
266 ASSERT_EQ(1U, result->size()); | 272 ASSERT_EQ(1U, result->size()); |
267 EXPECT_EQ("drive/root/Directory 1", result->at(0).path.AsUTF8Unsafe()); | 273 EXPECT_EQ("drive/root/Directory-1", result->at(0).path.AsUTF8Unsafe()); |
268 } | 274 } |
269 | 275 |
270 TEST_F(SearchMetadataTest, SearchMetadata_HostedDocument) { | 276 TEST_F(SearchMetadataTest, SearchMetadata_HostedDocument) { |
271 FileError error = FILE_ERROR_FAILED; | 277 FileError error = FILE_ERROR_FAILED; |
272 scoped_ptr<MetadataSearchResultVector> result; | 278 scoped_ptr<MetadataSearchResultVector> result; |
273 | 279 |
274 SearchMetadata( | 280 SearchMetadata( |
275 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(), "Document", | 281 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(), "Document", |
276 base::Bind(&MatchesType, SEARCH_METADATA_ALL), kDefaultAtMostNumMatches, | 282 base::Bind(&MatchesType, SEARCH_METADATA_ALL), kDefaultAtMostNumMatches, |
277 google_apis::test_util::CreateCopyResultCallback(&error, &result)); | 283 google_apis::test_util::CreateCopyResultCallback(&error, &result)); |
(...skipping 27 matching lines...) Expand all Loading... |
305 | 311 |
306 SearchMetadata( | 312 SearchMetadata( |
307 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(), "", | 313 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(), "", |
308 base::Bind(&MatchesType, SEARCH_METADATA_SHARED_WITH_ME), | 314 base::Bind(&MatchesType, SEARCH_METADATA_SHARED_WITH_ME), |
309 kDefaultAtMostNumMatches, | 315 kDefaultAtMostNumMatches, |
310 google_apis::test_util::CreateCopyResultCallback(&error, &result)); | 316 google_apis::test_util::CreateCopyResultCallback(&error, &result)); |
311 base::RunLoop().RunUntilIdle(); | 317 base::RunLoop().RunUntilIdle(); |
312 EXPECT_EQ(FILE_ERROR_OK, error); | 318 EXPECT_EQ(FILE_ERROR_OK, error); |
313 ASSERT_TRUE(result); | 319 ASSERT_TRUE(result); |
314 ASSERT_EQ(1U, result->size()); | 320 ASSERT_EQ(1U, result->size()); |
315 EXPECT_EQ("drive/root/Directory 1/Shared To The Account Owner.txt", | 321 EXPECT_EQ("drive/root/Directory-1/Shared To The Account Owner.txt", |
316 result->at(0).path.AsUTF8Unsafe()); | 322 result->at(0).path.AsUTF8Unsafe()); |
317 } | 323 } |
318 | 324 |
319 TEST_F(SearchMetadataTest, SearchMetadata_FileAndDirectory) { | 325 TEST_F(SearchMetadataTest, SearchMetadata_FileAndDirectory) { |
320 FileError error = FILE_ERROR_FAILED; | 326 FileError error = FILE_ERROR_FAILED; |
321 scoped_ptr<MetadataSearchResultVector> result; | 327 scoped_ptr<MetadataSearchResultVector> result; |
322 | 328 |
323 SearchMetadata( | 329 SearchMetadata( |
324 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(), | 330 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(), |
325 "excludeDir-test", base::Bind(&MatchesType, SEARCH_METADATA_ALL), | 331 "excludeDir-test", base::Bind(&MatchesType, SEARCH_METADATA_ALL), |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 base::RunLoop().RunUntilIdle(); | 395 base::RunLoop().RunUntilIdle(); |
390 EXPECT_EQ(FILE_ERROR_OK, error); | 396 EXPECT_EQ(FILE_ERROR_OK, error); |
391 ASSERT_EQ(3U, result->size()); | 397 ASSERT_EQ(3U, result->size()); |
392 | 398 |
393 // This is not included in the cache but is a hosted document. | 399 // This is not included in the cache but is a hosted document. |
394 EXPECT_EQ("drive/root/Document 1 excludeDir-test.gdoc", | 400 EXPECT_EQ("drive/root/Document 1 excludeDir-test.gdoc", |
395 result->at(0).path.AsUTF8Unsafe()); | 401 result->at(0).path.AsUTF8Unsafe()); |
396 | 402 |
397 EXPECT_EQ("drive/root/File 2.txt", | 403 EXPECT_EQ("drive/root/File 2.txt", |
398 result->at(1).path.AsUTF8Unsafe()); | 404 result->at(1).path.AsUTF8Unsafe()); |
399 EXPECT_EQ("drive/root/Directory 1/SubDirectory File 1.txt", | 405 EXPECT_EQ("drive/root/Directory-1/SubDirectory File 1.txt", |
400 result->at(2).path.AsUTF8Unsafe()); | 406 result->at(2).path.AsUTF8Unsafe()); |
401 } | 407 } |
402 | 408 |
| 409 TEST_F(SearchMetadataTest, SearchMetadata_MultipleKeywords) { |
| 410 FileError error = FILE_ERROR_FAILED; |
| 411 scoped_ptr<MetadataSearchResultVector> result; |
| 412 |
| 413 SearchMetadata( |
| 414 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(), |
| 415 "Directory 1", base::Bind(&MatchesType, SEARCH_METADATA_ALL), |
| 416 kDefaultAtMostNumMatches, |
| 417 google_apis::test_util::CreateCopyResultCallback(&error, &result)); |
| 418 |
| 419 base::RunLoop().RunUntilIdle(); |
| 420 EXPECT_EQ(FILE_ERROR_OK, error); |
| 421 ASSERT_TRUE(result); |
| 422 ASSERT_EQ(2U, result->size()); |
| 423 |
| 424 EXPECT_EQ("drive/root/Directory-1/SubDirectory File 1.txt", |
| 425 result->at(0).path.AsUTF8Unsafe()); |
| 426 EXPECT_EQ("drive/root/Directory-1", result->at(1).path.AsUTF8Unsafe()); |
| 427 } |
| 428 |
| 429 TEST_F(SearchMetadataTest, |
| 430 SearchMetadata_KeywordsSeparatedWithIdeographicSpace) { |
| 431 FileError error = FILE_ERROR_FAILED; |
| 432 scoped_ptr<MetadataSearchResultVector> result; |
| 433 |
| 434 // \xE3\x80\x80 is ideographic space. |
| 435 SearchMetadata( |
| 436 base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(), |
| 437 "Directory\xE3\x80\x80" |
| 438 "1", |
| 439 base::Bind(&MatchesType, SEARCH_METADATA_ALL), kDefaultAtMostNumMatches, |
| 440 google_apis::test_util::CreateCopyResultCallback(&error, &result)); |
| 441 |
| 442 base::RunLoop().RunUntilIdle(); |
| 443 EXPECT_EQ(FILE_ERROR_OK, error); |
| 444 ASSERT_TRUE(result); |
| 445 ASSERT_EQ(2U, result->size()); |
| 446 |
| 447 EXPECT_EQ("drive/root/Directory-1/SubDirectory File 1.txt", |
| 448 result->at(0).path.AsUTF8Unsafe()); |
| 449 EXPECT_EQ("drive/root/Directory-1", result->at(1).path.AsUTF8Unsafe()); |
| 450 } |
| 451 |
403 TEST(SearchMetadataSimpleTest, FindAndHighlight_ZeroMatches) { | 452 TEST(SearchMetadataSimpleTest, FindAndHighlight_ZeroMatches) { |
404 std::string highlighted_text; | 453 std::string highlighted_text; |
405 EXPECT_FALSE(FindAndHighlightWrapper("text", "query", &highlighted_text)); | 454 EXPECT_FALSE(FindAndHighlightWrapper("text", "query", &highlighted_text)); |
406 } | 455 } |
407 | 456 |
408 TEST(SearchMetadataSimpleTest, FindAndHighlight_EmptyText) { | 457 TEST(SearchMetadataSimpleTest, FindAndHighlight_EmptyText) { |
409 std::string highlighted_text; | 458 std::string highlighted_text; |
410 EXPECT_FALSE(FindAndHighlightWrapper("", "query", &highlighted_text)); | 459 EXPECT_FALSE(FindAndHighlightWrapper("", "query", &highlighted_text)); |
411 } | 460 } |
412 | 461 |
| 462 TEST(SearchMetadataSimpleTest, FindAndHighlight_EmptyQuery) { |
| 463 ScopedVector<base::i18n::FixedPatternStringSearchIgnoringCaseAndAccents> |
| 464 queries; |
| 465 |
| 466 std::string highlighted_text; |
| 467 EXPECT_TRUE(FindAndHighlight("hello", queries, &highlighted_text)); |
| 468 EXPECT_EQ("hello", highlighted_text); |
| 469 } |
| 470 |
413 TEST(SearchMetadataSimpleTest, FindAndHighlight_FullMatch) { | 471 TEST(SearchMetadataSimpleTest, FindAndHighlight_FullMatch) { |
414 std::string highlighted_text; | 472 std::string highlighted_text; |
415 EXPECT_TRUE(FindAndHighlightWrapper("hello", "hello", &highlighted_text)); | 473 EXPECT_TRUE(FindAndHighlightWrapper("hello", "hello", &highlighted_text)); |
416 EXPECT_EQ("<b>hello</b>", highlighted_text); | 474 EXPECT_EQ("<b>hello</b>", highlighted_text); |
417 } | 475 } |
418 | 476 |
419 TEST(SearchMetadataSimpleTest, FindAndHighlight_StartWith) { | 477 TEST(SearchMetadataSimpleTest, FindAndHighlight_StartWith) { |
420 std::string highlighted_text; | 478 std::string highlighted_text; |
421 EXPECT_TRUE(FindAndHighlightWrapper("hello, world", "hello", | 479 EXPECT_TRUE(FindAndHighlightWrapper("hello, world", "hello", |
422 &highlighted_text)); | 480 &highlighted_text)); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 EXPECT_TRUE(FindAndHighlightWrapper( | 524 EXPECT_TRUE(FindAndHighlightWrapper( |
467 "\xE3\x81\xB2\xE3\x82\x9A\xE3\x82\x83\xE3\x83\xBC", | 525 "\xE3\x81\xB2\xE3\x82\x9A\xE3\x82\x83\xE3\x83\xBC", |
468 "\xE3\x83\x94\xE3\x83\xA4", | 526 "\xE3\x83\x94\xE3\x83\xA4", |
469 &highlighted_text)); | 527 &highlighted_text)); |
470 EXPECT_EQ( | 528 EXPECT_EQ( |
471 "<b>\xE3\x81\xB2\xE3\x82\x9A\xE3\x82\x83</b>\xE3\x83\xBC", | 529 "<b>\xE3\x81\xB2\xE3\x82\x9A\xE3\x82\x83</b>\xE3\x83\xBC", |
472 highlighted_text); | 530 highlighted_text); |
473 } | 531 } |
474 | 532 |
475 TEST(SearchMetadataSimpleTest, MultiTextBySingleQuery) { | 533 TEST(SearchMetadataSimpleTest, MultiTextBySingleQuery) { |
476 base::i18n::FixedPatternStringSearchIgnoringCaseAndAccents query( | 534 ScopedVector<base::i18n::FixedPatternStringSearchIgnoringCaseAndAccents> |
477 base::UTF8ToUTF16("hello")); | 535 queries; |
| 536 queries.push_back( |
| 537 new base::i18n::FixedPatternStringSearchIgnoringCaseAndAccents( |
| 538 base::UTF8ToUTF16("hello"))); |
478 | 539 |
479 std::string highlighted_text; | 540 std::string highlighted_text; |
480 EXPECT_TRUE(FindAndHighlight("hello", &query, &highlighted_text)); | 541 EXPECT_TRUE(FindAndHighlight("hello", queries, &highlighted_text)); |
481 EXPECT_EQ("<b>hello</b>", highlighted_text); | 542 EXPECT_EQ("<b>hello</b>", highlighted_text); |
482 EXPECT_FALSE(FindAndHighlight("goodbye", &query, &highlighted_text)); | 543 EXPECT_FALSE(FindAndHighlight("goodbye", queries, &highlighted_text)); |
483 EXPECT_TRUE(FindAndHighlight("1hello2", &query, &highlighted_text)); | 544 EXPECT_TRUE(FindAndHighlight("1hello2", queries, &highlighted_text)); |
484 EXPECT_EQ("1<b>hello</b>2", highlighted_text); | 545 EXPECT_EQ("1<b>hello</b>2", highlighted_text); |
485 } | 546 } |
486 | 547 |
487 TEST(SearchMetadataSimpleTest, FindAndHighlight_MetaChars) { | 548 TEST(SearchMetadataSimpleTest, FindAndHighlight_MetaChars) { |
488 std::string highlighted_text; | 549 std::string highlighted_text; |
489 EXPECT_TRUE(FindAndHighlightWrapper("<hello>", "hello", &highlighted_text)); | 550 EXPECT_TRUE(FindAndHighlightWrapper("<hello>", "hello", &highlighted_text)); |
490 EXPECT_EQ("<<b>hello</b>>", highlighted_text); | 551 EXPECT_EQ("<<b>hello</b>>", highlighted_text); |
491 } | 552 } |
492 | 553 |
493 TEST(SearchMetadataSimpleTest, FindAndHighlight_MoreMetaChars) { | 554 TEST(SearchMetadataSimpleTest, FindAndHighlight_MoreMetaChars) { |
494 std::string highlighted_text; | 555 std::string highlighted_text; |
495 EXPECT_TRUE(FindAndHighlightWrapper("a&b&c&d", "b&c", &highlighted_text)); | 556 EXPECT_TRUE(FindAndHighlightWrapper("a&b&c&d", "b&c", &highlighted_text)); |
496 EXPECT_EQ("a&<b>b&c</b>&d", highlighted_text); | 557 EXPECT_EQ("a&<b>b&c</b>&d", highlighted_text); |
497 } | 558 } |
498 | 559 |
| 560 TEST(SearchMetadataSimpleTest, FindAndHighlight_SurrogatePair) { |
| 561 std::string highlighted_text; |
| 562 // \xF0\x9F\x98\x81 (U+1F601) is a surrogate pair for smile icon of emoji. |
| 563 EXPECT_TRUE(FindAndHighlightWrapper("hi\xF0\x9F\x98\x81hello", |
| 564 "i\xF0\x9F\x98\x81", &highlighted_text)); |
| 565 EXPECT_EQ("h<b>i\xF0\x9F\x98\x81</b>hello", highlighted_text); |
| 566 } |
| 567 |
| 568 TEST(SearchMetadataSimpleTest, FindAndHighlight_MultipleQueries) { |
| 569 ScopedVector<base::i18n::FixedPatternStringSearchIgnoringCaseAndAccents> |
| 570 queries; |
| 571 queries.push_back( |
| 572 new base::i18n::FixedPatternStringSearchIgnoringCaseAndAccents( |
| 573 base::UTF8ToUTF16("hello"))); |
| 574 queries.push_back( |
| 575 new base::i18n::FixedPatternStringSearchIgnoringCaseAndAccents( |
| 576 base::UTF8ToUTF16("good"))); |
| 577 |
| 578 std::string highlighted_text; |
| 579 EXPECT_TRUE( |
| 580 FindAndHighlight("good morning, hello", queries, &highlighted_text)); |
| 581 EXPECT_EQ("<b>good</b> morning, <b>hello</b>", highlighted_text); |
| 582 } |
| 583 |
| 584 TEST(SearchMetadataSimpleTest, FindAndHighlight_OverlappingHighlights) { |
| 585 ScopedVector<base::i18n::FixedPatternStringSearchIgnoringCaseAndAccents> |
| 586 queries; |
| 587 queries.push_back( |
| 588 new base::i18n::FixedPatternStringSearchIgnoringCaseAndAccents( |
| 589 base::UTF8ToUTF16("morning"))); |
| 590 queries.push_back( |
| 591 new base::i18n::FixedPatternStringSearchIgnoringCaseAndAccents( |
| 592 base::UTF8ToUTF16("ing,"))); |
| 593 |
| 594 std::string highlighted_text; |
| 595 EXPECT_TRUE( |
| 596 FindAndHighlight("good morning, hello", queries, &highlighted_text)); |
| 597 EXPECT_EQ("good <b>morning,</b> hello", highlighted_text); |
| 598 } |
| 599 |
499 } // namespace internal | 600 } // namespace internal |
500 } // namespace drive | 601 } // namespace drive |
OLD | NEW |