OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 5 #include <algorithm> |
6 #include <fstream> | 6 #include <fstream> |
7 | 7 |
8 #include "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
12 #include "base/i18n/case_conversion.h" | |
12 #include "base/path_service.h" | 13 #include "base/path_service.h" |
13 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
14 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
17 #include "chrome/browser/autocomplete/in_memory_url_index.h" | 18 #include "chrome/browser/autocomplete/in_memory_url_index.h" |
18 #include "chrome/browser/autocomplete/in_memory_url_index_types.h" | 19 #include "chrome/browser/autocomplete/in_memory_url_index_types.h" |
19 #include "chrome/browser/autocomplete/url_index_private_data.h" | 20 #include "chrome/browser/autocomplete/url_index_private_data.h" |
20 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 21 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
21 #include "chrome/browser/history/history_service_factory.h" | 22 #include "chrome/browser/history/history_service_factory.h" |
(...skipping 1164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1186 // Make sure the data we have was rebuilt from history. (Version 0 | 1187 // Make sure the data we have was rebuilt from history. (Version 0 |
1187 // means rebuilt from history; anything else means restored from | 1188 // means rebuilt from history; anything else means restored from |
1188 // a cache version.) | 1189 // a cache version.) |
1189 EXPECT_EQ(0, new_data.restored_cache_version_); | 1190 EXPECT_EQ(0, new_data.restored_cache_version_); |
1190 EXPECT_NE(fake_rebuild_time, new_data.last_time_rebuilt_from_history_); | 1191 EXPECT_NE(fake_rebuild_time, new_data.last_time_rebuilt_from_history_); |
1191 | 1192 |
1192 // Compare the captured and restored for equality. | 1193 // Compare the captured and restored for equality. |
1193 ExpectPrivateDataEqual(*old_data.get(), new_data); | 1194 ExpectPrivateDataEqual(*old_data.get(), new_data); |
1194 } | 1195 } |
1195 | 1196 |
1197 // Helper function to get lower case |lower_string| and |lower_terms| (words | |
Mark P
2015/06/08 18:13:16
get -> set
Pritam Nikam
2015/06/09 10:03:53
Done.
| |
1198 // list) based on supplied |search_string| and |cursor_position|. | |
Mark P
2015/06/08 18:13:16
It's a bit confusing that we add a space in order
Pritam Nikam
2015/06/09 10:03:52
Done.
| |
1199 void StringToTerms(const char* search_string, | |
Mark P
2015/06/08 18:13:16
nit: Please move this helper function into the ano
Pritam Nikam
2015/06/09 10:03:52
Done.
| |
1200 size_t cursor_position, | |
1201 base::string16* lower_string, | |
1202 String16Vector* lower_terms) { | |
1203 *lower_string = base::i18n::ToLower(ASCIIToUTF16(search_string)); | |
1204 if ((cursor_position != base::string16::npos) && | |
1205 (cursor_position < lower_string->length()) && (cursor_position > 0)) { | |
1206 lower_string->insert(cursor_position, base::ASCIIToUTF16(" ")); | |
1207 } | |
1208 | |
1209 Tokenize(*lower_string, base::kWhitespaceUTF16, lower_terms); | |
1210 } | |
1211 | |
1212 TEST_F(InMemoryURLIndexTest, AddHistoryMatch) { | |
1213 const struct { | |
1214 const char* search_string; | |
1215 size_t cursor_position; | |
1216 const std::vector<size_t> expected_word_starts_offsets; | |
1217 } test_cases[] = { | |
1218 /* No punctuations, only cursor position change. */ | |
Mark P
2015/06/08 18:13:16
style nit: you have indented two space too many he
Pritam Nikam
2015/06/09 10:03:53
Done.
| |
1219 {"ABCD", base::string16::npos, {0}}, | |
Mark P
2015/06/08 18:13:16
style nit: one space inside { before " and one spa
Pritam Nikam
2015/06/09 10:03:52
Done.
| |
1220 {"abcd", 0, {0}}, | |
Mark P
2015/06/08 18:13:16
optional nit: align the { in the expected_word_sta
Pritam Nikam
2015/06/09 10:03:52
Done.
| |
1221 {"AbcD", 1, {0, 0}}, | |
1222 {"abcd", 4, {0}}, | |
1223 | |
1224 /* Staring with punctuation. */ | |
Mark P
2015/06/08 18:13:16
Staring -> Starting
Pritam Nikam
2015/06/09 10:03:52
Done.
| |
1225 {".abcd", base::string16::npos, {1}}, | |
1226 {".abcd", 0, {1}}, | |
1227 {"!abcd", 1, {1, 0}}, | |
1228 {"::abcd", 1, {1, 1}}, | |
1229 {":abcd", 5, {1}}, | |
1230 | |
1231 /* Ending with punctuation. */ | |
1232 {"abcd://", base::string16::npos, {0}}, | |
1233 {"ABCD://", 0, {0}}, | |
1234 {"abcd://", 1, {0, 0}}, | |
1235 {"abcd://", 4, {0, 3}}, | |
1236 {"abcd://", 7, {0}}, | |
1237 | |
1238 /* Punctuation in the middle. */ | |
1239 {"ab.cd", base::string16::npos, {0}}, | |
1240 {"ab.cd", 0, {0}}, | |
1241 {"ab!cd", 1, {0, 0}}, | |
1242 {"AB.cd", 2, {0, 1}}, | |
1243 {"ab:cd", 5, {0}}, | |
Mark P
2015/06/08 18:13:16
Can you add a cursor_position = 3 test in this blo
Pritam Nikam
2015/06/09 10:03:52
Done.
| |
1244 | |
1245 /* Hyphenation */ | |
1246 {"Ab-cd", base::string16::npos, {0}}, | |
1247 {"ab-cd", 0, {0}}, | |
1248 {"-abcd", 0, {1}}, | |
1249 {"-abcd", 1, {1, 0}}, | |
1250 {"abcd-", 2, {0, 0}}, | |
1251 {"abcd-", 4, {0, 1}}, | |
1252 {"ab-cd", 5, {0}}, | |
1253 }; | |
1254 | |
1255 for (size_t i = 0; i < arraysize(test_cases); ++i) { | |
1256 SCOPED_TRACE(testing::Message() | |
1257 << "search_string = " << test_cases[i].search_string | |
1258 << ", cursor_position = " << test_cases[i].cursor_position); | |
1259 | |
1260 base::string16 lower_string; | |
1261 String16Vector lower_terms; | |
1262 StringToTerms(test_cases[i].search_string, test_cases[i].cursor_position, | |
1263 &lower_string, &lower_terms); | |
1264 | |
1265 if (!lower_terms.empty()) { | |
Mark P
2015/06/08 18:13:16
You shouldn't guard this code in this way. For in
Pritam Nikam
2015/06/09 10:03:52
Done.
| |
1266 URLIndexPrivateData::AddHistoryMatch match( | |
1267 nullptr, *GetPrivateData(), kTestLanguages, lower_string, lower_terms, | |
1268 base::Time::Now()); | |
1269 | |
1270 // Verify against expectations. | |
1271 EXPECT_EQ(test_cases[i].expected_word_starts_offsets, | |
1272 match.lower_terms_to_word_starts_offsets_); | |
1273 } | |
1274 } | |
1275 } | |
1276 | |
1196 class InMemoryURLIndexCacheTest : public testing::Test { | 1277 class InMemoryURLIndexCacheTest : public testing::Test { |
1197 public: | 1278 public: |
1198 InMemoryURLIndexCacheTest() {} | 1279 InMemoryURLIndexCacheTest() {} |
1199 | 1280 |
1200 protected: | 1281 protected: |
1201 void SetUp() override; | 1282 void SetUp() override; |
1202 void TearDown() override; | 1283 void TearDown() override; |
1203 | 1284 |
1204 // Pass-through functions to simplify our friendship with InMemoryURLIndex. | 1285 // Pass-through functions to simplify our friendship with InMemoryURLIndex. |
1205 void set_history_dir(const base::FilePath& dir_path); | 1286 void set_history_dir(const base::FilePath& dir_path); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1242 ASSERT_TRUE(GetCacheFilePath(&full_file_path)); | 1323 ASSERT_TRUE(GetCacheFilePath(&full_file_path)); |
1243 std::vector<base::FilePath::StringType> actual_parts; | 1324 std::vector<base::FilePath::StringType> actual_parts; |
1244 full_file_path.GetComponents(&actual_parts); | 1325 full_file_path.GetComponents(&actual_parts); |
1245 ASSERT_EQ(expected_parts.size(), actual_parts.size()); | 1326 ASSERT_EQ(expected_parts.size(), actual_parts.size()); |
1246 size_t count = expected_parts.size(); | 1327 size_t count = expected_parts.size(); |
1247 for (size_t i = 0; i < count; ++i) | 1328 for (size_t i = 0; i < count; ++i) |
1248 EXPECT_EQ(expected_parts[i], actual_parts[i]); | 1329 EXPECT_EQ(expected_parts[i], actual_parts[i]); |
1249 // Must clear the history_dir_ to satisfy the dtor's DCHECK. | 1330 // Must clear the history_dir_ to satisfy the dtor's DCHECK. |
1250 set_history_dir(base::FilePath()); | 1331 set_history_dir(base::FilePath()); |
1251 } | 1332 } |
OLD | NEW |