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

Side by Side Diff: chrome/browser/history/in_memory_url_index_unittest.cc

Issue 8384024: HQP Refactoring (in Preparation for SQLite Cache) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <fstream> 5 #include <fstream>
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/string16.h" 10 #include "base/string16.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 URLRow row(GURL(url), 0); 132 URLRow row(GURL(url), 0);
133 row.set_title(UTF8ToUTF16(title)); 133 row.set_title(UTF8ToUTF16(title));
134 row.set_visit_count(visit_count); 134 row.set_visit_count(visit_count);
135 row.set_typed_count(typed_count); 135 row.set_typed_count(typed_count);
136 row.set_last_visit(base::Time::NowFromSystemTime() - 136 row.set_last_visit(base::Time::NowFromSystemTime() -
137 base::TimeDelta::FromDays(last_visit_ago)); 137 base::TimeDelta::FromDays(last_visit_ago));
138 return row; 138 return row;
139 } 139 }
140 140
141 String16Vector InMemoryURLIndexTest::Make1Term(const char* term) const { 141 String16Vector InMemoryURLIndexTest::Make1Term(const char* term) const {
142 String16Vector original_terms; 142 String16Vector terms;
143 original_terms.push_back(UTF8ToUTF16(term)); 143 terms.push_back(UTF8ToUTF16(term));
144 return original_terms; 144 return terms;
145 } 145 }
146 146
147 String16Vector InMemoryURLIndexTest::Make2Terms(const char* term_1, 147 String16Vector InMemoryURLIndexTest::Make2Terms(const char* term_1,
148 const char* term_2) const { 148 const char* term_2) const {
149 String16Vector original_terms; 149 String16Vector terms;
150 original_terms.push_back(UTF8ToUTF16(term_1)); 150 terms.push_back(UTF8ToUTF16(term_1));
151 original_terms.push_back(UTF8ToUTF16(term_2)); 151 terms.push_back(UTF8ToUTF16(term_2));
152 return original_terms; 152 return terms;
153 } 153 }
154 154
155 void InMemoryURLIndexTest::CheckTerm( 155 void InMemoryURLIndexTest::CheckTerm(
156 const InMemoryURLIndex::SearchTermCacheMap& cache, 156 const InMemoryURLIndex::SearchTermCacheMap& cache,
157 string16 term) const { 157 string16 term) const {
158 InMemoryURLIndex::SearchTermCacheMap::const_iterator cache_iter( 158 InMemoryURLIndex::SearchTermCacheMap::const_iterator cache_iter(
159 cache.find(term)); 159 cache.find(term));
160 ASSERT_NE(cache.end(), cache_iter) 160 ASSERT_NE(cache.end(), cache_iter)
161 << "Cache does not contain '" << term << "' but should."; 161 << "Cache does not contain '" << term << "' but should.";
162 InMemoryURLIndex::SearchTermCacheItem cache_item = cache_iter->second; 162 InMemoryURLIndex::SearchTermCacheItem cache_item = cache_iter->second;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 const size_t kMaxLen = arraysize(url_format) + 5; 208 const size_t kMaxLen = arraysize(url_format) + 5;
209 char url_string[kMaxLen + 1]; 209 char url_string[kMaxLen + 1];
210 for (int i = 0; i < 600; ++i) { 210 for (int i = 0; i < 600; ++i) {
211 base::snprintf(url_string, kMaxLen, url_format, i); 211 base::snprintf(url_string, kMaxLen, url_format, i);
212 URLRow row(MakeURLRow(url_string, "Google Search", 20, 0, 20)); 212 URLRow row(MakeURLRow(url_string, "Google Search", 20, 0, 20));
213 AddURL(row); 213 AddURL(row);
214 } 214 }
215 } 215 }
216 216
217 TEST_F(InMemoryURLIndexTest, Construction) { 217 TEST_F(InMemoryURLIndexTest, Construction) {
218 url_index_.reset(new InMemoryURLIndex(FilePath())); 218 url_index_.reset(new InMemoryURLIndex(NULL, FilePath()));
219 EXPECT_TRUE(url_index_.get()); 219 EXPECT_TRUE(url_index_.get());
220 } 220 }
221 221
222 TEST_F(LimitedInMemoryURLIndexTest, Initialization) { 222 TEST_F(LimitedInMemoryURLIndexTest, Initialization) {
223 // Verify that the database contains the expected number of items, which 223 // Verify that the database contains the expected number of items, which
224 // is the pre-filtered count, i.e. all of the items. 224 // is the pre-filtered count, i.e. all of the items.
225 sql::Statement statement(GetDB().GetUniqueStatement("SELECT * FROM urls;")); 225 sql::Statement statement(GetDB().GetUniqueStatement("SELECT * FROM urls;"));
226 EXPECT_TRUE(statement); 226 EXPECT_TRUE(statement);
227 uint64 row_count = 0; 227 uint64 row_count = 0;
228 while (statement.Step()) ++row_count; 228 while (statement.Step()) ++row_count;
229 EXPECT_EQ(1U, row_count); 229 EXPECT_EQ(1U, row_count);
230 url_index_.reset(new InMemoryURLIndex(FilePath())); 230 url_index_.reset(new InMemoryURLIndex(NULL, FilePath()));
231 url_index_->Init(this, "en,ja,hi,zh"); 231 url_index_->Init(this, "en,ja,hi,zh");
232 URLIndexPrivateData& private_data(*(url_index_->private_data_)); 232 URLIndexPrivateData& private_data(*(url_index_->private_data_));
233 233
234 // history_info_map_ should have the same number of items as were filtered. 234 // history_info_map_ should have the same number of items as were filtered.
235 EXPECT_EQ(1U, private_data.history_info_map_.size()); 235 EXPECT_EQ(1U, private_data.history_info_map_.size());
236 EXPECT_EQ(35U, private_data.char_word_map_.size()); 236 EXPECT_EQ(35U, private_data.char_word_map_.size());
237 EXPECT_EQ(17U, private_data.word_map_.size()); 237 EXPECT_EQ(17U, private_data.word_map_.size());
238 } 238 }
239 239
240 TEST_F(InMemoryURLIndexTest, Retrieval) { 240 TEST_F(InMemoryURLIndexTest, Retrieval) {
241 url_index_.reset(new InMemoryURLIndex(FilePath())); 241 url_index_.reset(new InMemoryURLIndex(NULL, FilePath()));
242 url_index_->Init(this, "en,ja,hi,zh"); 242 url_index_->Init(this, "en,ja,hi,zh");
243 // The term will be lowercased by the search. 243 // The term will be lowercased by the search.
244 244
245 // See if a very specific term gives a single result. 245 // See if a very specific term gives a single result.
246 ScoredHistoryMatches matches = 246 ScoredHistoryMatches matches =
247 url_index_->HistoryItemsForTerms(Make1Term("DrudgeReport")); 247 url_index_->HistoryItemsForTerms(Make1Term("DrudgeReport"));
248 ASSERT_EQ(1U, matches.size()); 248 ASSERT_EQ(1U, matches.size());
249 249
250 // Verify that we got back the result we expected. 250 // Verify that we got back the result we expected.
251 EXPECT_EQ(5, matches[0].url_info.id()); 251 EXPECT_EQ(5, matches[0].url_info.id());
(...skipping 12 matching lines...) Expand all
264 ASSERT_EQ(1U, matches.size()); 264 ASSERT_EQ(1U, matches.size());
265 // The results should have a very high score. 265 // The results should have a very high score.
266 EXPECT_GT(matches[0].raw_score, 900); 266 EXPECT_GT(matches[0].raw_score, 900);
267 EXPECT_EQ(32, matches[0].url_info.id()); 267 EXPECT_EQ(32, matches[0].url_info.id());
268 EXPECT_EQ("https://nearlyperfectresult.com/", 268 EXPECT_EQ("https://nearlyperfectresult.com/",
269 matches[0].url_info.url().spec()); // Note: URL gets lowercased. 269 matches[0].url_info.url().spec()); // Note: URL gets lowercased.
270 EXPECT_EQ(ASCIIToUTF16("Practically Perfect Search Result"), 270 EXPECT_EQ(ASCIIToUTF16("Practically Perfect Search Result"),
271 matches[0].url_info.title()); 271 matches[0].url_info.title());
272 272
273 // Search which should result in very poor result. 273 // Search which should result in very poor result.
274 String16Vector original_terms; 274 String16Vector terms;
275 original_terms.push_back(ASCIIToUTF16("z")); 275 terms.push_back(ASCIIToUTF16("z"));
276 original_terms.push_back(ASCIIToUTF16("y")); 276 terms.push_back(ASCIIToUTF16("y"));
277 original_terms.push_back(ASCIIToUTF16("x")); 277 terms.push_back(ASCIIToUTF16("x"));
278 matches = url_index_->HistoryItemsForTerms(original_terms); 278 matches = url_index_->HistoryItemsForTerms(terms);
279 ASSERT_EQ(1U, matches.size()); 279 ASSERT_EQ(1U, matches.size());
280 // The results should have a poor score. 280 // The results should have a poor score.
281 EXPECT_LT(matches[0].raw_score, 500); 281 EXPECT_LT(matches[0].raw_score, 500);
282 EXPECT_EQ(33, matches[0].url_info.id()); 282 EXPECT_EQ(33, matches[0].url_info.id());
283 EXPECT_EQ("http://quiteuselesssearchresultxyz.com/", 283 EXPECT_EQ("http://quiteuselesssearchresultxyz.com/",
284 matches[0].url_info.url().spec()); // Note: URL gets lowercased. 284 matches[0].url_info.url().spec()); // Note: URL gets lowercased.
285 EXPECT_EQ(ASCIIToUTF16("Practically Useless Search Result"), 285 EXPECT_EQ(ASCIIToUTF16("Practically Useless Search Result"),
286 matches[0].url_info.title()); 286 matches[0].url_info.title());
287 287
288 // Search which will match at the end of an URL with encoded characters. 288 // Search which will match at the end of an URL with encoded characters.
289 matches = url_index_->HistoryItemsForTerms(Make1Term("ice")); 289 matches = url_index_->HistoryItemsForTerms(Make1Term("ice"));
290 ASSERT_EQ(1U, matches.size()); 290 ASSERT_EQ(1U, matches.size());
291 } 291 }
292 292
293 TEST_F(ExpandedInMemoryURLIndexTest, ShortCircuit) { 293 TEST_F(ExpandedInMemoryURLIndexTest, ShortCircuit) {
294 url_index_.reset(new InMemoryURLIndex(FilePath())); 294 url_index_.reset(new InMemoryURLIndex(NULL, FilePath()));
295 url_index_->Init(this, "en,ja,hi,zh"); 295 url_index_->Init(this, "en,ja,hi,zh");
296 296
297 // A search for 'w' should short-circuit and not return any matches. 297 // A search for 'w' should short-circuit and not return any matches.
298 ScoredHistoryMatches matches = 298 ScoredHistoryMatches matches =
299 url_index_->HistoryItemsForTerms(Make1Term("w")); 299 url_index_->HistoryItemsForTerms(Make1Term("w"));
300 EXPECT_TRUE(matches.empty()); 300 EXPECT_TRUE(matches.empty());
301 301
302 // A search for 'working' should not short-circuit. 302 // A search for 'working' should not short-circuit.
303 matches = url_index_->HistoryItemsForTerms(Make1Term("working")); 303 matches = url_index_->HistoryItemsForTerms(Make1Term("working"));
304 EXPECT_EQ(1U, matches.size()); 304 EXPECT_EQ(1U, matches.size());
305 } 305 }
306 306
307 TEST_F(InMemoryURLIndexTest, TitleSearch) { 307 TEST_F(InMemoryURLIndexTest, TitleSearch) {
308 url_index_.reset(new InMemoryURLIndex(FilePath())); 308 url_index_.reset(new InMemoryURLIndex(NULL, FilePath()));
309 url_index_->Init(this, "en,ja,hi,zh"); 309 url_index_->Init(this, "en,ja,hi,zh");
310 // Signal if someone has changed the test DB. 310 // Signal if someone has changed the test DB.
311 EXPECT_EQ(27U, url_index_->private_data_->history_info_map_.size()); 311 EXPECT_EQ(27U, url_index_->private_data_->history_info_map_.size());
312 String16Vector original_terms; 312 String16Vector terms;
313 313
314 // Ensure title is being searched. 314 // Ensure title is being searched.
315 original_terms.push_back(ASCIIToUTF16("MORTGAGE")); 315 terms.push_back(ASCIIToUTF16("MORTGAGE"));
316 original_terms.push_back(ASCIIToUTF16("RATE")); 316 terms.push_back(ASCIIToUTF16("RATE"));
317 original_terms.push_back(ASCIIToUTF16("DROPS")); 317 terms.push_back(ASCIIToUTF16("DROPS"));
318 ScoredHistoryMatches matches = 318 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(terms);
319 url_index_->HistoryItemsForTerms(original_terms);
320 ASSERT_EQ(1U, matches.size()); 319 ASSERT_EQ(1U, matches.size());
321 320
322 // Verify that we got back the result we expected. 321 // Verify that we got back the result we expected.
323 EXPECT_EQ(1, matches[0].url_info.id()); 322 EXPECT_EQ(1, matches[0].url_info.id());
324 EXPECT_EQ("http://www.reuters.com/article/idUSN0839880620100708", 323 EXPECT_EQ("http://www.reuters.com/article/idUSN0839880620100708",
325 matches[0].url_info.url().spec()); 324 matches[0].url_info.url().spec());
326 EXPECT_EQ(ASCIIToUTF16( 325 EXPECT_EQ(ASCIIToUTF16(
327 "UPDATE 1-US 30-yr mortgage rate drops to new record low | Reuters"), 326 "UPDATE 1-US 30-yr mortgage rate drops to new record low | Reuters"),
328 matches[0].url_info.title()); 327 matches[0].url_info.title());
329 } 328 }
330 329
331 TEST_F(InMemoryURLIndexTest, TitleChange) { 330 TEST_F(InMemoryURLIndexTest, TitleChange) {
332 url_index_.reset(new InMemoryURLIndex(FilePath())); 331 url_index_.reset(new InMemoryURLIndex(NULL, FilePath()));
333 url_index_->Init(this, "en,ja,hi,zh"); 332 url_index_->Init(this, "en,ja,hi,zh");
334 333
335 // Verify current title terms retrieves desired item. 334 // Verify current title terms retrieves desired item.
336 String16Vector original_terms; 335 String16Vector original_terms;
337 original_terms.push_back(ASCIIToUTF16("lebronomics")); 336 original_terms.push_back(ASCIIToUTF16("lebronomics"));
338 original_terms.push_back(ASCIIToUTF16("could")); 337 original_terms.push_back(ASCIIToUTF16("could"));
339 original_terms.push_back(ASCIIToUTF16("high")); 338 original_terms.push_back(ASCIIToUTF16("high"));
340 original_terms.push_back(ASCIIToUTF16("taxes")); 339 original_terms.push_back(ASCIIToUTF16("taxes"));
341 original_terms.push_back(ASCIIToUTF16("influence")); 340 original_terms.push_back(ASCIIToUTF16("influence"));
342 ScoredHistoryMatches matches = 341 ScoredHistoryMatches matches =
(...skipping 16 matching lines...) Expand all
359 new_terms.push_back(ASCIIToUTF16("eat")); 358 new_terms.push_back(ASCIIToUTF16("eat"));
360 new_terms.push_back(ASCIIToUTF16("oats")); 359 new_terms.push_back(ASCIIToUTF16("oats"));
361 new_terms.push_back(ASCIIToUTF16("little")); 360 new_terms.push_back(ASCIIToUTF16("little"));
362 new_terms.push_back(ASCIIToUTF16("lambs")); 361 new_terms.push_back(ASCIIToUTF16("lambs"));
363 new_terms.push_back(ASCIIToUTF16("ivy")); 362 new_terms.push_back(ASCIIToUTF16("ivy"));
364 matches = url_index_->HistoryItemsForTerms(new_terms); 363 matches = url_index_->HistoryItemsForTerms(new_terms);
365 ASSERT_EQ(0U, matches.size()); 364 ASSERT_EQ(0U, matches.size());
366 365
367 // Update the row. 366 // Update the row.
368 old_row.set_title(ASCIIToUTF16("Does eat oats and little lambs eat ivy")); 367 old_row.set_title(ASCIIToUTF16("Does eat oats and little lambs eat ivy"));
369 url_index_->UpdateURL(expected_id, old_row); 368 url_index_->UpdateURL(old_row);
370 369
371 // Verify we get the row using the new terms but not the original terms. 370 // Verify we get the row using the new terms but not the original terms.
372 matches = url_index_->HistoryItemsForTerms(new_terms); 371 matches = url_index_->HistoryItemsForTerms(new_terms);
373 ASSERT_EQ(1U, matches.size()); 372 ASSERT_EQ(1U, matches.size());
374 EXPECT_EQ(expected_id, matches[0].url_info.id()); 373 EXPECT_EQ(expected_id, matches[0].url_info.id());
375 matches = url_index_->HistoryItemsForTerms(original_terms); 374 matches = url_index_->HistoryItemsForTerms(original_terms);
376 ASSERT_EQ(0U, matches.size()); 375 ASSERT_EQ(0U, matches.size());
377 } 376 }
378 377
379 TEST_F(InMemoryURLIndexTest, NonUniqueTermCharacterSets) { 378 TEST_F(InMemoryURLIndexTest, NonUniqueTermCharacterSets) {
380 url_index_.reset(new InMemoryURLIndex(FilePath())); 379 url_index_.reset(new InMemoryURLIndex(NULL, FilePath()));
381 url_index_->Init(this, "en,ja,hi,zh"); 380 url_index_->Init(this, "en,ja,hi,zh");
382 381
383 // The presence of duplicate characters should succeed. Exercise by cycling 382 // The presence of duplicate characters should succeed. Exercise by cycling
384 // through a string with several duplicate characters. 383 // through a string with several duplicate characters.
385 ScoredHistoryMatches matches = 384 ScoredHistoryMatches matches =
386 url_index_->HistoryItemsForTerms(Make1Term("ABRA")); 385 url_index_->HistoryItemsForTerms(Make1Term("ABRA"));
387 ASSERT_EQ(1U, matches.size()); 386 ASSERT_EQ(1U, matches.size());
388 EXPECT_EQ(28, matches[0].url_info.id()); 387 EXPECT_EQ(28, matches[0].url_info.id());
389 EXPECT_EQ("http://www.ddj.com/windows/184416623", 388 EXPECT_EQ("http://www.ddj.com/windows/184416623",
390 matches[0].url_info.url().spec()); 389 matches[0].url_info.url().spec());
(...skipping 15 matching lines...) Expand all
406 EXPECT_EQ(28, matches[0].url_info.id()); 405 EXPECT_EQ(28, matches[0].url_info.id());
407 } 406 }
408 407
409 TEST_F(InMemoryURLIndexTest, TypedCharacterCaching) { 408 TEST_F(InMemoryURLIndexTest, TypedCharacterCaching) {
410 // Verify that match results for previously typed characters are retained 409 // Verify that match results for previously typed characters are retained
411 // (in the term_char_word_set_cache_) and reused, if possible, in future 410 // (in the term_char_word_set_cache_) and reused, if possible, in future
412 // autocompletes. 411 // autocompletes.
413 typedef InMemoryURLIndex::SearchTermCacheMap::iterator CacheIter; 412 typedef InMemoryURLIndex::SearchTermCacheMap::iterator CacheIter;
414 typedef InMemoryURLIndex::SearchTermCacheItem CacheItem; 413 typedef InMemoryURLIndex::SearchTermCacheItem CacheItem;
415 414
416 url_index_.reset(new InMemoryURLIndex(FilePath())); 415 url_index_.reset(new InMemoryURLIndex(NULL, FilePath()));
417 url_index_->Init(this, "en,ja,hi,zh"); 416 url_index_->Init(this, "en,ja,hi,zh");
418 417
419 InMemoryURLIndex::SearchTermCacheMap& cache(url_index_->search_term_cache_); 418 InMemoryURLIndex::SearchTermCacheMap& cache(url_index_->search_term_cache_);
420 419
421 // The cache should be empty at this point. 420 // The cache should be empty at this point.
422 EXPECT_EQ(0U, cache.size()); 421 EXPECT_EQ(0U, cache.size());
423 422
424 // Now simulate typing search terms into the omnibox and check the state of 423 // Now simulate typing search terms into the omnibox and check the state of
425 // the cache as each item is 'typed'. 424 // the cache as each item is 'typed'.
426 425
427 // Simulate typing "r" giving "r" in the simulated omnibox. The results for 426 // Simulate typing "r" giving "r" in the simulated omnibox. The results for
428 // 'r' will be not cached because it is only 1 character long. 427 // 'r' will be not cached because it is only 1 character long.
429 String16Vector original_terms; 428 String16Vector terms;
430 string16 term_r = ASCIIToUTF16("r"); 429 string16 term_r = ASCIIToUTF16("r");
431 original_terms.push_back(term_r); 430 terms.push_back(term_r);
432 url_index_->HistoryItemsForTerms(original_terms); 431 url_index_->HistoryItemsForTerms(terms);
433 EXPECT_EQ(0U, cache.size()); 432 EXPECT_EQ(0U, cache.size());
434 433
435 // Simulate typing "re" giving "r re" in the simulated omnibox. 434 // Simulate typing "re" giving "r re" in the simulated omnibox.
436 string16 term_re = ASCIIToUTF16("re"); 435 string16 term_re = ASCIIToUTF16("re");
437 original_terms.push_back(term_re); 436 terms.push_back(term_re);
438 // 're' should be cached at this point but not 'r' as it is a single 437 // 're' should be cached at this point but not 'r' as it is a single
439 // character. 438 // character.
440 ASSERT_EQ(2U, original_terms.size()); 439 ASSERT_EQ(2U, terms.size());
441 url_index_->HistoryItemsForTerms(original_terms); 440 url_index_->HistoryItemsForTerms(terms);
442 ASSERT_EQ(1U, cache.size()); 441 ASSERT_EQ(1U, cache.size());
443 CheckTerm(cache, term_re); 442 CheckTerm(cache, term_re);
444 443
445 // Simulate typing "reco" giving "r re reco" in the simulated omnibox. 444 // Simulate typing "reco" giving "r re reco" in the simulated omnibox.
446 string16 term_reco = ASCIIToUTF16("reco"); 445 string16 term_reco = ASCIIToUTF16("reco");
447 original_terms.push_back(term_reco); 446 terms.push_back(term_reco);
448 // 're' and 'reco' should be cached at this point but not 'r' as it is a 447 // 're' and 'reco' should be cached at this point but not 'r' as it is a
449 // single character. 448 // single character.
450 url_index_->HistoryItemsForTerms(original_terms); 449 url_index_->HistoryItemsForTerms(terms);
451 ASSERT_EQ(2U, cache.size()); 450 ASSERT_EQ(2U, cache.size());
452 CheckTerm(cache, term_re); 451 CheckTerm(cache, term_re);
453 CheckTerm(cache, term_reco); 452 CheckTerm(cache, term_reco);
454 453
455 original_terms.clear(); // Simulate pressing <ESC>. 454 terms.clear(); // Simulate pressing <ESC>.
456 455
457 // Simulate typing "mort". 456 // Simulate typing "mort".
458 string16 term_mort = ASCIIToUTF16("mort"); 457 string16 term_mort = ASCIIToUTF16("mort");
459 original_terms.push_back(term_mort); 458 terms.push_back(term_mort);
460 // Since we now have only one search term, the cached results for 're' and 459 // Since we now have only one search term, the cached results for 're' and
461 // 'reco' should be purged, giving us only 1 item in the cache (for 'mort'). 460 // 'reco' should be purged, giving us only 1 item in the cache (for 'mort').
462 url_index_->HistoryItemsForTerms(original_terms); 461 url_index_->HistoryItemsForTerms(terms);
463 ASSERT_EQ(1U, cache.size()); 462 ASSERT_EQ(1U, cache.size());
464 CheckTerm(cache, term_mort); 463 CheckTerm(cache, term_mort);
465 464
466 // Simulate typing "reco" giving "mort reco" in the simulated omnibox. 465 // Simulate typing "reco" giving "mort reco" in the simulated omnibox.
467 original_terms.push_back(term_reco); 466 terms.push_back(term_reco);
468 url_index_->HistoryItemsForTerms(original_terms); 467 url_index_->HistoryItemsForTerms(terms);
469 ASSERT_EQ(2U, cache.size()); 468 ASSERT_EQ(2U, cache.size());
470 CheckTerm(cache, term_mort); 469 CheckTerm(cache, term_mort);
471 CheckTerm(cache, term_reco); 470 CheckTerm(cache, term_reco);
472 471
473 // Simulate a <DELETE> by removing the 'reco' and adding back the 'rec'. 472 // Simulate a <DELETE> by removing the 'reco' and adding back the 'rec'.
474 original_terms.resize(original_terms.size() - 1); 473 terms.resize(terms.size() - 1);
475 string16 term_rec = ASCIIToUTF16("rec"); 474 string16 term_rec = ASCIIToUTF16("rec");
476 original_terms.push_back(term_rec); 475 terms.push_back(term_rec);
477 url_index_->HistoryItemsForTerms(original_terms); 476 url_index_->HistoryItemsForTerms(terms);
478 ASSERT_EQ(2U, cache.size()); 477 ASSERT_EQ(2U, cache.size());
479 CheckTerm(cache, term_mort); 478 CheckTerm(cache, term_mort);
480 CheckTerm(cache, term_rec); 479 CheckTerm(cache, term_rec);
481 } 480 }
482 481
483 TEST_F(InMemoryURLIndexTest, Scoring) { 482 TEST_F(InMemoryURLIndexTest, Scoring) {
484 URLRow row_a(MakeURLRow("http://abcdef", "fedcba", 3, 30, 1)); 483 URLRow row_a(MakeURLRow("http://abcdef", "fedcba", 3, 30, 1));
485 // Test scores based on position. 484 // Test scores based on position.
486 ScoredHistoryMatch scored_a( 485 ScoredHistoryMatch scored_a(
487 InMemoryURLIndex::ScoredMatchForURL(row_a, Make1Term("abc"))); 486 InMemoryURLIndex::ScoredMatchForURL(row_a, Make1Term("abc")));
(...skipping 21 matching lines...) Expand all
509 InMemoryURLIndex::ScoredMatchForURL(row_c, Make1Term("abc"))); 508 InMemoryURLIndex::ScoredMatchForURL(row_c, Make1Term("abc")));
510 EXPECT_GT(scored_g.raw_score, scored_a.raw_score); 509 EXPECT_GT(scored_g.raw_score, scored_a.raw_score);
511 // Test scores based on typed_count. 510 // Test scores based on typed_count.
512 URLRow row_d(MakeURLRow("http://abcdef", "fedcba", 3, 30, 10)); 511 URLRow row_d(MakeURLRow("http://abcdef", "fedcba", 3, 30, 10));
513 ScoredHistoryMatch scored_h( 512 ScoredHistoryMatch scored_h(
514 InMemoryURLIndex::ScoredMatchForURL(row_d, Make1Term("abc"))); 513 InMemoryURLIndex::ScoredMatchForURL(row_d, Make1Term("abc")));
515 EXPECT_GT(scored_h.raw_score, scored_a.raw_score); 514 EXPECT_GT(scored_h.raw_score, scored_a.raw_score);
516 } 515 }
517 516
518 TEST_F(InMemoryURLIndexTest, AddNewRows) { 517 TEST_F(InMemoryURLIndexTest, AddNewRows) {
519 url_index_.reset(new InMemoryURLIndex(FilePath())); 518 url_index_.reset(new InMemoryURLIndex(NULL, FilePath()));
520 url_index_->Init(this, "en,ja,hi,zh"); 519 url_index_->Init(this, "en,ja,hi,zh");
521 String16Vector original_terms; 520 String16Vector terms;
522 521
523 // Verify that the row we're going to add does not already exist. 522 // Verify that the row we're going to add does not already exist.
524 URLID new_row_id = 87654321; 523 URLID new_row_id = 87654321;
525 // Newly created URLRows get a last_visit time of 'right now' so it should 524 // Newly created URLRows get a last_visit time of 'right now' so it should
526 // qualify as a quick result candidate. 525 // qualify as a quick result candidate.
527 original_terms.push_back(ASCIIToUTF16("brokeandalone")); 526 terms.push_back(ASCIIToUTF16("brokeandalone"));
528 EXPECT_TRUE(url_index_->HistoryItemsForTerms(original_terms).empty()); 527 EXPECT_TRUE(url_index_->HistoryItemsForTerms(terms).empty());
529 528
530 // Add a new row. 529 // Add a new row.
531 URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), new_row_id); 530 URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), new_row_id);
532 new_row.set_last_visit(base::Time::Now()); 531 new_row.set_last_visit(base::Time::Now());
533 url_index_->UpdateURL(new_row_id, new_row); 532 url_index_->UpdateURL(new_row);
534 533
535 // Verify that we can retrieve it. 534 // Verify that we can retrieve it.
536 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms(original_terms).size()); 535 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms(terms).size());
537 536
538 // Add it again just to be sure that is harmless. 537 // Add it again just to be sure that is harmless.
539 url_index_->UpdateURL(new_row_id, new_row); 538 url_index_->UpdateURL(new_row);
540 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms(original_terms).size()); 539 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms(terms).size());
541 } 540 }
542 541
543 TEST_F(InMemoryURLIndexTest, DeleteRows) { 542 TEST_F(InMemoryURLIndexTest, DeleteRows) {
544 url_index_.reset(new InMemoryURLIndex(FilePath())); 543 url_index_.reset(new InMemoryURLIndex(NULL, FilePath()));
545 url_index_->Init(this, "en,ja,hi,zh"); 544 url_index_->Init(this, "en,ja,hi,zh");
546 String16Vector original_terms; 545 String16Vector terms;
547 546
548 // Make sure we actually get an existing result. 547 // Make sure we actually get an existing result.
549 original_terms.push_back(ASCIIToUTF16("DrudgeReport")); 548 terms.push_back(ASCIIToUTF16("DrudgeReport"));
550 ScoredHistoryMatches matches = 549 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(terms);
551 url_index_->HistoryItemsForTerms(original_terms);
552 ASSERT_EQ(1U, matches.size()); 550 ASSERT_EQ(1U, matches.size());
553 551
554 // Determine the row id for that result, delete that id, then search again. 552 // Determine the row id for that result, delete that id, then search again.
555 url_index_->DeleteURL(matches[0].url_info.id()); 553 url_index_->DeleteURL(matches[0].url_info);
556 EXPECT_TRUE(url_index_->HistoryItemsForTerms(original_terms).empty()); 554 EXPECT_TRUE(url_index_->HistoryItemsForTerms(terms).empty());
557 } 555 }
558 556
559 TEST_F(InMemoryURLIndexTest, WhitelistedURLs) { 557 TEST_F(InMemoryURLIndexTest, WhitelistedURLs) {
560 struct TestData { 558 struct TestData {
561 const std::string url_spec; 559 const std::string url_spec;
562 const bool expected_is_whitelisted; 560 const bool expected_is_whitelisted;
563 } data[] = { 561 } data[] = {
564 // URLs with whitelisted schemes. 562 // URLs with whitelisted schemes.
565 { "about:histograms", true }, 563 { "about:histograms", true },
566 { "chrome://settings", true }, 564 { "chrome://settings", true },
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 { "telnet://mayor_margie:one2rule4All@www.mycity.com:6789/", false }, 620 { "telnet://mayor_margie:one2rule4All@www.mycity.com:6789/", false },
623 { "tftp://example.com/mystartupfile", false }, 621 { "tftp://example.com/mystartupfile", false },
624 { "tip://123.123.123.123/?urn:xopen:xid", false }, 622 { "tip://123.123.123.123/?urn:xopen:xid", false },
625 { "tv:nbc.com", false }, 623 { "tv:nbc.com", false },
626 { "urn:foo:A123,456", false }, 624 { "urn:foo:A123,456", false },
627 { "vemmi://zeus.mctel.fr/demo", false }, 625 { "vemmi://zeus.mctel.fr/demo", false },
628 { "wais://www.mydomain.net:8765/mydatabase", false }, 626 { "wais://www.mydomain.net:8765/mydatabase", false },
629 { "xmpp:node@example.com", false }, 627 { "xmpp:node@example.com", false },
630 { "xmpp://guest@example.com", false }, 628 { "xmpp://guest@example.com", false },
631 }; 629 };
632 url_index_.reset(new InMemoryURLIndex(FilePath())); 630 url_index_.reset(new InMemoryURLIndex(NULL, FilePath()));
633 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { 631 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) {
634 GURL url(data[i].url_spec); 632 GURL url(data[i].url_spec);
635 EXPECT_EQ(data[i].expected_is_whitelisted, 633 EXPECT_EQ(data[i].expected_is_whitelisted,
636 url_index_->URLSchemeIsWhitelisted(url)); 634 url_index_->URLSchemeIsWhitelisted(url));
637 } 635 }
638 } 636 }
639 637
640 TEST_F(InMemoryURLIndexTest, CacheFilePath) { 638 TEST_F(InMemoryURLIndexTest, CacheFilePath) {
641 url_index_.reset(new InMemoryURLIndex(FilePath(FILE_PATH_LITERAL( 639 url_index_.reset(new InMemoryURLIndex(
642 "/flammmy/frammy/")))); 640 NULL, FilePath(FILE_PATH_LITERAL("/flammmy/frammy/"))));
643 FilePath full_file_path; 641 FilePath full_file_path;
644 url_index_->GetCacheFilePath(&full_file_path); 642 url_index_->GetCacheFilePath(&full_file_path);
645 std::vector<FilePath::StringType> expected_parts; 643 std::vector<FilePath::StringType> expected_parts;
646 FilePath(FILE_PATH_LITERAL("/flammmy/frammy/History Provider Cache")). 644 FilePath(FILE_PATH_LITERAL("/flammmy/frammy/History Provider Cache")).
647 GetComponents(&expected_parts); 645 GetComponents(&expected_parts);
648 std::vector<FilePath::StringType> actual_parts; 646 std::vector<FilePath::StringType> actual_parts;
649 full_file_path.GetComponents(&actual_parts); 647 full_file_path.GetComponents(&actual_parts);
650 ASSERT_EQ(expected_parts.size(), actual_parts.size()); 648 ASSERT_EQ(expected_parts.size(), actual_parts.size());
651 size_t count = expected_parts.size(); 649 size_t count = expected_parts.size();
652 for (size_t i = 0; i < count; ++i) 650 for (size_t i = 0; i < count; ++i)
653 EXPECT_EQ(expected_parts[i], actual_parts[i]); 651 EXPECT_EQ(expected_parts[i], actual_parts[i]);
654 // Must clear the history_dir_ to satisfy the dtor's DCHECK. 652 // Must clear the history_dir_ to satisfy the dtor's DCHECK.
655 url_index_->history_dir_.clear(); 653 url_index_->history_dir_.clear();
656 } 654 }
657 655
658 TEST_F(InMemoryURLIndexTest, CacheSaveRestore) { 656 TEST_F(InMemoryURLIndexTest, CacheSaveRestore) {
659 // Save the cache to a protobuf, restore it, and compare the results. 657 // Save the cache to a protobuf, restore it, and compare the results.
660 url_index_.reset(new InMemoryURLIndex(FilePath())); 658 url_index_.reset(new InMemoryURLIndex(NULL, FilePath()));
661 InMemoryURLIndex& url_index(*(url_index_.get())); 659 InMemoryURLIndex& url_index(*(url_index_.get()));
662 url_index.Init(this, "en,ja,hi,zh"); 660 url_index.Init(this, "en,ja,hi,zh");
663 in_memory_url_index::InMemoryURLIndexCacheItem index_cache; 661 in_memory_url_index::InMemoryURLIndexCacheItem index_cache;
664 url_index.SavePrivateData(&index_cache); 662 url_index.SavePrivateData(&index_cache);
665 663
666 // Capture our private data so we can later compare for equality. 664 // Capture our private data so we can later compare for equality.
667 URLIndexPrivateData& private_data(*(url_index_->private_data_)); 665 URLIndexPrivateData& private_data(*(url_index_->private_data_));
668 String16Vector word_list(private_data.word_list_); 666 String16Vector word_list(private_data.word_list_);
669 WordMap word_map(private_data.word_map_); 667 WordMap word_map(private_data.word_map_);
670 CharWordIDMap char_word_map(private_data.char_word_map_); 668 CharWordIDMap char_word_map(private_data.char_word_map_);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 const URLRow& expected_row(expected->second); 723 const URLRow& expected_row(expected->second);
726 const URLRow& actual_row(actual->second); 724 const URLRow& actual_row(actual->second);
727 EXPECT_EQ(expected_row.visit_count(), actual_row.visit_count()); 725 EXPECT_EQ(expected_row.visit_count(), actual_row.visit_count());
728 EXPECT_EQ(expected_row.typed_count(), actual_row.typed_count()); 726 EXPECT_EQ(expected_row.typed_count(), actual_row.typed_count());
729 EXPECT_EQ(expected_row.last_visit(), actual_row.last_visit()); 727 EXPECT_EQ(expected_row.last_visit(), actual_row.last_visit());
730 EXPECT_EQ(expected_row.url(), actual_row.url()); 728 EXPECT_EQ(expected_row.url(), actual_row.url());
731 } 729 }
732 } 730 }
733 731
734 } // namespace history 732 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/in_memory_url_index.cc ('k') | chrome/browser/sync/profile_sync_service_typed_url_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698