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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <fstream> | 9 #include <fstream> |
10 | 10 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 // number specifying the number of days relative to 'today' to which the | 44 // number specifying the number of days relative to 'today' to which the |
45 // absolute time should be set during the test setup stage. | 45 // absolute time should be set during the test setup stage. |
46 // | 46 // |
47 // The format of the test database text file is of a SQLite .dump file. | 47 // The format of the test database text file is of a SQLite .dump file. |
48 // Note that only lines whose first character is an upper-case letter are | 48 // Note that only lines whose first character is an upper-case letter are |
49 // processed when creating the test database. | 49 // processed when creating the test database. |
50 | 50 |
51 namespace { | 51 namespace { |
52 const size_t kInvalid = base::string16::npos; | 52 const size_t kInvalid = base::string16::npos; |
53 const size_t kMaxMatches = 3; | 53 const size_t kMaxMatches = 3; |
54 const char kTestLanguages[] = "en,ja,hi,zh"; | |
55 const char kClientWhitelistedScheme[] = "xyz"; | 54 const char kClientWhitelistedScheme[] = "xyz"; |
56 | 55 |
57 // Helper function to set lower case |lower_string| and |lower_terms| (words | 56 // Helper function to set lower case |lower_string| and |lower_terms| (words |
58 // list) based on supplied |search_string| and |cursor_position|. If | 57 // list) based on supplied |search_string| and |cursor_position|. If |
59 // |cursor_position| is set and useful (not at either end of the string), allow | 58 // |cursor_position| is set and useful (not at either end of the string), allow |
60 // the |search_string| to be broken at |cursor_position|. We do this by | 59 // the |search_string| to be broken at |cursor_position|. We do this by |
61 // pretending there's a space where the cursor is. |lower_terms| are obtained by | 60 // pretending there's a space where the cursor is. |lower_terms| are obtained by |
62 // splitting the |lower_string| on whitespace into tokens. | 61 // splitting the |lower_string| on whitespace into tokens. |
63 void StringToTerms(const char* search_string, | 62 void StringToTerms(const char* search_string, |
64 size_t cursor_position, | 63 size_t cursor_position, |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 void InMemoryURLIndexTest::PostSaveToCacheFileTask() { | 200 void InMemoryURLIndexTest::PostSaveToCacheFileTask() { |
202 url_index_->PostSaveToCacheFileTask(); | 201 url_index_->PostSaveToCacheFileTask(); |
203 } | 202 } |
204 | 203 |
205 const SchemeSet& InMemoryURLIndexTest::scheme_whitelist() { | 204 const SchemeSet& InMemoryURLIndexTest::scheme_whitelist() { |
206 return url_index_->scheme_whitelist(); | 205 return url_index_->scheme_whitelist(); |
207 } | 206 } |
208 | 207 |
209 bool InMemoryURLIndexTest::UpdateURL(const history::URLRow& row) { | 208 bool InMemoryURLIndexTest::UpdateURL(const history::URLRow& row) { |
210 return GetPrivateData()->UpdateURL( | 209 return GetPrivateData()->UpdateURL( |
211 history_service_.get(), row, url_index_->languages_, | 210 history_service_.get(), row, url_index_->scheme_whitelist_, |
212 url_index_->scheme_whitelist_, GetPrivateDataTracker()); | 211 GetPrivateDataTracker()); |
213 } | 212 } |
214 | 213 |
215 bool InMemoryURLIndexTest::DeleteURL(const GURL& url) { | 214 bool InMemoryURLIndexTest::DeleteURL(const GURL& url) { |
216 return GetPrivateData()->DeleteURL(url); | 215 return GetPrivateData()->DeleteURL(url); |
217 } | 216 } |
218 | 217 |
219 void InMemoryURLIndexTest::SetUp() { | 218 void InMemoryURLIndexTest::SetUp() { |
220 // We cannot access the database until the backend has been loaded. | 219 // We cannot access the database until the backend has been loaded. |
221 if (history_dir_.CreateUniqueTempDir()) { | 220 if (history_dir_.CreateUniqueTempDir()) |
222 history_service_ = history::CreateHistoryService( | 221 history_service_ = history::CreateHistoryService(history_dir_.path(), true); |
223 history_dir_.path(), std::string(), true); | |
224 } | |
225 ASSERT_TRUE(history_service_); | 222 ASSERT_TRUE(history_service_); |
226 BlockUntilInMemoryURLIndexIsRefreshed(url_index_.get()); | 223 BlockUntilInMemoryURLIndexIsRefreshed(url_index_.get()); |
227 | 224 |
228 history::HistoryBackend* backend = history_service_->history_backend_.get(); | 225 history::HistoryBackend* backend = history_service_->history_backend_.get(); |
229 history_database_ = backend->db(); | 226 history_database_ = backend->db(); |
230 | 227 |
231 // Create and populate a working copy of the URL history database. | 228 // Create and populate a working copy of the URL history database. |
232 base::FilePath history_proto_path; | 229 base::FilePath history_proto_path; |
233 PathService::Get(base::DIR_SOURCE_ROOT, &history_proto_path); | 230 PathService::Get(base::DIR_SOURCE_ROOT, &history_proto_path); |
234 history_proto_path = history_proto_path.AppendASCII("components"); | 231 history_proto_path = history_proto_path.AppendASCII("components"); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 return true; | 320 return true; |
324 } | 321 } |
325 | 322 |
326 void InMemoryURLIndexTest::InitializeInMemoryURLIndex() { | 323 void InMemoryURLIndexTest::InitializeInMemoryURLIndex() { |
327 DCHECK(!url_index_); | 324 DCHECK(!url_index_); |
328 | 325 |
329 SchemeSet client_schemes_to_whitelist; | 326 SchemeSet client_schemes_to_whitelist; |
330 client_schemes_to_whitelist.insert(kClientWhitelistedScheme); | 327 client_schemes_to_whitelist.insert(kClientWhitelistedScheme); |
331 url_index_.reset(new InMemoryURLIndex( | 328 url_index_.reset(new InMemoryURLIndex( |
332 nullptr, history_service_.get(), nullptr, pool_owner_.pool().get(), | 329 nullptr, history_service_.get(), nullptr, pool_owner_.pool().get(), |
333 base::FilePath(), kTestLanguages, client_schemes_to_whitelist)); | 330 base::FilePath(), client_schemes_to_whitelist)); |
334 url_index_->Init(); | 331 url_index_->Init(); |
335 url_index_->RebuildFromHistory(history_database_); | 332 url_index_->RebuildFromHistory(history_database_); |
336 } | 333 } |
337 | 334 |
338 void InMemoryURLIndexTest::CheckTerm( | 335 void InMemoryURLIndexTest::CheckTerm( |
339 const URLIndexPrivateData::SearchTermCacheMap& cache, | 336 const URLIndexPrivateData::SearchTermCacheMap& cache, |
340 base::string16 term) const { | 337 base::string16 term) const { |
341 URLIndexPrivateData::SearchTermCacheMap::const_iterator cache_iter( | 338 URLIndexPrivateData::SearchTermCacheMap::const_iterator cache_iter( |
342 cache.find(term)); | 339 cache.find(term)); |
343 ASSERT_TRUE(cache.end() != cache_iter) | 340 ASSERT_TRUE(cache.end() != cache_iter) |
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1238 SCOPED_TRACE(testing::Message() | 1235 SCOPED_TRACE(testing::Message() |
1239 << "search_string = " << test_cases[i].search_string | 1236 << "search_string = " << test_cases[i].search_string |
1240 << ", cursor_position = " << test_cases[i].cursor_position); | 1237 << ", cursor_position = " << test_cases[i].cursor_position); |
1241 | 1238 |
1242 base::string16 lower_string; | 1239 base::string16 lower_string; |
1243 String16Vector lower_terms; | 1240 String16Vector lower_terms; |
1244 StringToTerms(test_cases[i].search_string, test_cases[i].cursor_position, | 1241 StringToTerms(test_cases[i].search_string, test_cases[i].cursor_position, |
1245 &lower_string, &lower_terms); | 1242 &lower_string, &lower_terms); |
1246 URLIndexPrivateData::AddHistoryMatch match(nullptr, nullptr, | 1243 URLIndexPrivateData::AddHistoryMatch match(nullptr, nullptr, |
1247 *GetPrivateData(), | 1244 *GetPrivateData(), |
1248 kTestLanguages, lower_string, | 1245 lower_string, lower_terms, |
1249 lower_terms, base::Time::Now()); | 1246 base::Time::Now()); |
1250 | 1247 |
1251 // Verify against expectations. | 1248 // Verify against expectations. |
1252 EXPECT_EQ(test_cases[i].expected_word_starts_offsets_size, | 1249 EXPECT_EQ(test_cases[i].expected_word_starts_offsets_size, |
1253 match.lower_terms_to_word_starts_offsets_.size()); | 1250 match.lower_terms_to_word_starts_offsets_.size()); |
1254 for (size_t j = 0; j < test_cases[i].expected_word_starts_offsets_size; | 1251 for (size_t j = 0; j < test_cases[i].expected_word_starts_offsets_size; |
1255 ++j) { | 1252 ++j) { |
1256 EXPECT_EQ(test_cases[i].expected_word_starts_offsets[j], | 1253 EXPECT_EQ(test_cases[i].expected_word_starts_offsets[j], |
1257 match.lower_terms_to_word_starts_offsets_[j]); | 1254 match.lower_terms_to_word_starts_offsets_[j]); |
1258 } | 1255 } |
1259 } | 1256 } |
(...skipping 18 matching lines...) Expand all Loading... |
1278 }; | 1275 }; |
1279 | 1276 |
1280 InMemoryURLIndexCacheTest::InMemoryURLIndexCacheTest() | 1277 InMemoryURLIndexCacheTest::InMemoryURLIndexCacheTest() |
1281 : pool_owner_(3, "Background Pool") {} | 1278 : pool_owner_(3, "Background Pool") {} |
1282 | 1279 |
1283 void InMemoryURLIndexCacheTest::SetUp() { | 1280 void InMemoryURLIndexCacheTest::SetUp() { |
1284 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 1281 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
1285 base::FilePath path(temp_dir_.path()); | 1282 base::FilePath path(temp_dir_.path()); |
1286 url_index_.reset(new InMemoryURLIndex(nullptr, nullptr, nullptr, | 1283 url_index_.reset(new InMemoryURLIndex(nullptr, nullptr, nullptr, |
1287 pool_owner_.pool().get(), path, | 1284 pool_owner_.pool().get(), path, |
1288 kTestLanguages, SchemeSet())); | 1285 SchemeSet())); |
1289 } | 1286 } |
1290 | 1287 |
1291 void InMemoryURLIndexCacheTest::TearDown() { | 1288 void InMemoryURLIndexCacheTest::TearDown() { |
1292 if (url_index_) | 1289 if (url_index_) |
1293 url_index_->Shutdown(); | 1290 url_index_->Shutdown(); |
1294 } | 1291 } |
1295 | 1292 |
1296 void InMemoryURLIndexCacheTest::set_history_dir( | 1293 void InMemoryURLIndexCacheTest::set_history_dir( |
1297 const base::FilePath& dir_path) { | 1294 const base::FilePath& dir_path) { |
1298 return url_index_->set_history_dir(dir_path); | 1295 return url_index_->set_history_dir(dir_path); |
(...skipping 14 matching lines...) Expand all Loading... |
1313 ASSERT_TRUE(GetCacheFilePath(&full_file_path)); | 1310 ASSERT_TRUE(GetCacheFilePath(&full_file_path)); |
1314 std::vector<base::FilePath::StringType> actual_parts; | 1311 std::vector<base::FilePath::StringType> actual_parts; |
1315 full_file_path.GetComponents(&actual_parts); | 1312 full_file_path.GetComponents(&actual_parts); |
1316 ASSERT_EQ(expected_parts.size(), actual_parts.size()); | 1313 ASSERT_EQ(expected_parts.size(), actual_parts.size()); |
1317 size_t count = expected_parts.size(); | 1314 size_t count = expected_parts.size(); |
1318 for (size_t i = 0; i < count; ++i) | 1315 for (size_t i = 0; i < count; ++i) |
1319 EXPECT_EQ(expected_parts[i], actual_parts[i]); | 1316 EXPECT_EQ(expected_parts[i], actual_parts[i]); |
1320 // Must clear the history_dir_ to satisfy the dtor's DCHECK. | 1317 // Must clear the history_dir_ to satisfy the dtor's DCHECK. |
1321 set_history_dir(base::FilePath()); | 1318 set_history_dir(base::FilePath()); |
1322 } | 1319 } |
OLD | NEW |