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

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

Issue 8437035: Revert 108207 - 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 terms; 142 String16Vector original_terms;
143 terms.push_back(UTF8ToUTF16(term)); 143 original_terms.push_back(UTF8ToUTF16(term));
144 return terms; 144 return original_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 terms; 149 String16Vector original_terms;
150 terms.push_back(UTF8ToUTF16(term_1)); 150 original_terms.push_back(UTF8ToUTF16(term_1));
151 terms.push_back(UTF8ToUTF16(term_2)); 151 original_terms.push_back(UTF8ToUTF16(term_2));
152 return terms; 152 return original_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(NULL, FilePath())); 218 url_index_.reset(new InMemoryURLIndex(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(NULL, FilePath())); 230 url_index_.reset(new InMemoryURLIndex(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(NULL, FilePath())); 241 url_index_.reset(new InMemoryURLIndex(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 terms; 274 String16Vector original_terms;
275 terms.push_back(ASCIIToUTF16("z")); 275 original_terms.push_back(ASCIIToUTF16("z"));
276 terms.push_back(ASCIIToUTF16("y")); 276 original_terms.push_back(ASCIIToUTF16("y"));
277 terms.push_back(ASCIIToUTF16("x")); 277 original_terms.push_back(ASCIIToUTF16("x"));
278 matches = url_index_->HistoryItemsForTerms(terms); 278 matches = url_index_->HistoryItemsForTerms(original_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(NULL, FilePath())); 294 url_index_.reset(new InMemoryURLIndex(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(NULL, FilePath())); 308 url_index_.reset(new InMemoryURLIndex(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 terms; 312 String16Vector original_terms;
313 313
314 // Ensure title is being searched. 314 // Ensure title is being searched.
315 terms.push_back(ASCIIToUTF16("MORTGAGE")); 315 original_terms.push_back(ASCIIToUTF16("MORTGAGE"));
316 terms.push_back(ASCIIToUTF16("RATE")); 316 original_terms.push_back(ASCIIToUTF16("RATE"));
317 terms.push_back(ASCIIToUTF16("DROPS")); 317 original_terms.push_back(ASCIIToUTF16("DROPS"));
318 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(terms); 318 ScoredHistoryMatches matches =
319 url_index_->HistoryItemsForTerms(original_terms);
319 ASSERT_EQ(1U, matches.size()); 320 ASSERT_EQ(1U, matches.size());
320 321
321 // Verify that we got back the result we expected. 322 // Verify that we got back the result we expected.
322 EXPECT_EQ(1, matches[0].url_info.id()); 323 EXPECT_EQ(1, matches[0].url_info.id());
323 EXPECT_EQ("http://www.reuters.com/article/idUSN0839880620100708", 324 EXPECT_EQ("http://www.reuters.com/article/idUSN0839880620100708",
324 matches[0].url_info.url().spec()); 325 matches[0].url_info.url().spec());
325 EXPECT_EQ(ASCIIToUTF16( 326 EXPECT_EQ(ASCIIToUTF16(
326 "UPDATE 1-US 30-yr mortgage rate drops to new record low | Reuters"), 327 "UPDATE 1-US 30-yr mortgage rate drops to new record low | Reuters"),
327 matches[0].url_info.title()); 328 matches[0].url_info.title());
328 } 329 }
329 330
330 TEST_F(InMemoryURLIndexTest, TitleChange) { 331 TEST_F(InMemoryURLIndexTest, TitleChange) {
331 url_index_.reset(new InMemoryURLIndex(NULL, FilePath())); 332 url_index_.reset(new InMemoryURLIndex(FilePath()));
332 url_index_->Init(this, "en,ja,hi,zh"); 333 url_index_->Init(this, "en,ja,hi,zh");
333 334
334 // Verify current title terms retrieves desired item. 335 // Verify current title terms retrieves desired item.
335 String16Vector original_terms; 336 String16Vector original_terms;
336 original_terms.push_back(ASCIIToUTF16("lebronomics")); 337 original_terms.push_back(ASCIIToUTF16("lebronomics"));
337 original_terms.push_back(ASCIIToUTF16("could")); 338 original_terms.push_back(ASCIIToUTF16("could"));
338 original_terms.push_back(ASCIIToUTF16("high")); 339 original_terms.push_back(ASCIIToUTF16("high"));
339 original_terms.push_back(ASCIIToUTF16("taxes")); 340 original_terms.push_back(ASCIIToUTF16("taxes"));
340 original_terms.push_back(ASCIIToUTF16("influence")); 341 original_terms.push_back(ASCIIToUTF16("influence"));
341 ScoredHistoryMatches matches = 342 ScoredHistoryMatches matches =
(...skipping 16 matching lines...) Expand all
358 new_terms.push_back(ASCIIToUTF16("eat")); 359 new_terms.push_back(ASCIIToUTF16("eat"));
359 new_terms.push_back(ASCIIToUTF16("oats")); 360 new_terms.push_back(ASCIIToUTF16("oats"));
360 new_terms.push_back(ASCIIToUTF16("little")); 361 new_terms.push_back(ASCIIToUTF16("little"));
361 new_terms.push_back(ASCIIToUTF16("lambs")); 362 new_terms.push_back(ASCIIToUTF16("lambs"));
362 new_terms.push_back(ASCIIToUTF16("ivy")); 363 new_terms.push_back(ASCIIToUTF16("ivy"));
363 matches = url_index_->HistoryItemsForTerms(new_terms); 364 matches = url_index_->HistoryItemsForTerms(new_terms);
364 ASSERT_EQ(0U, matches.size()); 365 ASSERT_EQ(0U, matches.size());
365 366
366 // Update the row. 367 // Update the row.
367 old_row.set_title(ASCIIToUTF16("Does eat oats and little lambs eat ivy")); 368 old_row.set_title(ASCIIToUTF16("Does eat oats and little lambs eat ivy"));
368 url_index_->UpdateURL(old_row); 369 url_index_->UpdateURL(expected_id, old_row);
369 370
370 // Verify we get the row using the new terms but not the original terms. 371 // Verify we get the row using the new terms but not the original terms.
371 matches = url_index_->HistoryItemsForTerms(new_terms); 372 matches = url_index_->HistoryItemsForTerms(new_terms);
372 ASSERT_EQ(1U, matches.size()); 373 ASSERT_EQ(1U, matches.size());
373 EXPECT_EQ(expected_id, matches[0].url_info.id()); 374 EXPECT_EQ(expected_id, matches[0].url_info.id());
374 matches = url_index_->HistoryItemsForTerms(original_terms); 375 matches = url_index_->HistoryItemsForTerms(original_terms);
375 ASSERT_EQ(0U, matches.size()); 376 ASSERT_EQ(0U, matches.size());
376 } 377 }
377 378
378 TEST_F(InMemoryURLIndexTest, NonUniqueTermCharacterSets) { 379 TEST_F(InMemoryURLIndexTest, NonUniqueTermCharacterSets) {
379 url_index_.reset(new InMemoryURLIndex(NULL, FilePath())); 380 url_index_.reset(new InMemoryURLIndex(FilePath()));
380 url_index_->Init(this, "en,ja,hi,zh"); 381 url_index_->Init(this, "en,ja,hi,zh");
381 382
382 // The presence of duplicate characters should succeed. Exercise by cycling 383 // The presence of duplicate characters should succeed. Exercise by cycling
383 // through a string with several duplicate characters. 384 // through a string with several duplicate characters.
384 ScoredHistoryMatches matches = 385 ScoredHistoryMatches matches =
385 url_index_->HistoryItemsForTerms(Make1Term("ABRA")); 386 url_index_->HistoryItemsForTerms(Make1Term("ABRA"));
386 ASSERT_EQ(1U, matches.size()); 387 ASSERT_EQ(1U, matches.size());
387 EXPECT_EQ(28, matches[0].url_info.id()); 388 EXPECT_EQ(28, matches[0].url_info.id());
388 EXPECT_EQ("http://www.ddj.com/windows/184416623", 389 EXPECT_EQ("http://www.ddj.com/windows/184416623",
389 matches[0].url_info.url().spec()); 390 matches[0].url_info.url().spec());
(...skipping 15 matching lines...) Expand all
405 EXPECT_EQ(28, matches[0].url_info.id()); 406 EXPECT_EQ(28, matches[0].url_info.id());
406 } 407 }
407 408
408 TEST_F(InMemoryURLIndexTest, TypedCharacterCaching) { 409 TEST_F(InMemoryURLIndexTest, TypedCharacterCaching) {
409 // Verify that match results for previously typed characters are retained 410 // Verify that match results for previously typed characters are retained
410 // (in the term_char_word_set_cache_) and reused, if possible, in future 411 // (in the term_char_word_set_cache_) and reused, if possible, in future
411 // autocompletes. 412 // autocompletes.
412 typedef InMemoryURLIndex::SearchTermCacheMap::iterator CacheIter; 413 typedef InMemoryURLIndex::SearchTermCacheMap::iterator CacheIter;
413 typedef InMemoryURLIndex::SearchTermCacheItem CacheItem; 414 typedef InMemoryURLIndex::SearchTermCacheItem CacheItem;
414 415
415 url_index_.reset(new InMemoryURLIndex(NULL, FilePath())); 416 url_index_.reset(new InMemoryURLIndex(FilePath()));
416 url_index_->Init(this, "en,ja,hi,zh"); 417 url_index_->Init(this, "en,ja,hi,zh");
417 418
418 InMemoryURLIndex::SearchTermCacheMap& cache(url_index_->search_term_cache_); 419 InMemoryURLIndex::SearchTermCacheMap& cache(url_index_->search_term_cache_);
419 420
420 // The cache should be empty at this point. 421 // The cache should be empty at this point.
421 EXPECT_EQ(0U, cache.size()); 422 EXPECT_EQ(0U, cache.size());
422 423
423 // Now simulate typing search terms into the omnibox and check the state of 424 // Now simulate typing search terms into the omnibox and check the state of
424 // the cache as each item is 'typed'. 425 // the cache as each item is 'typed'.
425 426
426 // Simulate typing "r" giving "r" in the simulated omnibox. The results for 427 // Simulate typing "r" giving "r" in the simulated omnibox. The results for
427 // 'r' will be not cached because it is only 1 character long. 428 // 'r' will be not cached because it is only 1 character long.
428 String16Vector terms; 429 String16Vector original_terms;
429 string16 term_r = ASCIIToUTF16("r"); 430 string16 term_r = ASCIIToUTF16("r");
430 terms.push_back(term_r); 431 original_terms.push_back(term_r);
431 url_index_->HistoryItemsForTerms(terms); 432 url_index_->HistoryItemsForTerms(original_terms);
432 EXPECT_EQ(0U, cache.size()); 433 EXPECT_EQ(0U, cache.size());
433 434
434 // Simulate typing "re" giving "r re" in the simulated omnibox. 435 // Simulate typing "re" giving "r re" in the simulated omnibox.
435 string16 term_re = ASCIIToUTF16("re"); 436 string16 term_re = ASCIIToUTF16("re");
436 terms.push_back(term_re); 437 original_terms.push_back(term_re);
437 // 're' should be cached at this point but not 'r' as it is a single 438 // 're' should be cached at this point but not 'r' as it is a single
438 // character. 439 // character.
439 ASSERT_EQ(2U, terms.size()); 440 ASSERT_EQ(2U, original_terms.size());
440 url_index_->HistoryItemsForTerms(terms); 441 url_index_->HistoryItemsForTerms(original_terms);
441 ASSERT_EQ(1U, cache.size()); 442 ASSERT_EQ(1U, cache.size());
442 CheckTerm(cache, term_re); 443 CheckTerm(cache, term_re);
443 444
444 // Simulate typing "reco" giving "r re reco" in the simulated omnibox. 445 // Simulate typing "reco" giving "r re reco" in the simulated omnibox.
445 string16 term_reco = ASCIIToUTF16("reco"); 446 string16 term_reco = ASCIIToUTF16("reco");
446 terms.push_back(term_reco); 447 original_terms.push_back(term_reco);
447 // 're' and 'reco' should be cached at this point but not 'r' as it is a 448 // 're' and 'reco' should be cached at this point but not 'r' as it is a
448 // single character. 449 // single character.
449 url_index_->HistoryItemsForTerms(terms); 450 url_index_->HistoryItemsForTerms(original_terms);
450 ASSERT_EQ(2U, cache.size()); 451 ASSERT_EQ(2U, cache.size());
451 CheckTerm(cache, term_re); 452 CheckTerm(cache, term_re);
452 CheckTerm(cache, term_reco); 453 CheckTerm(cache, term_reco);
453 454
454 terms.clear(); // Simulate pressing <ESC>. 455 original_terms.clear(); // Simulate pressing <ESC>.
455 456
456 // Simulate typing "mort". 457 // Simulate typing "mort".
457 string16 term_mort = ASCIIToUTF16("mort"); 458 string16 term_mort = ASCIIToUTF16("mort");
458 terms.push_back(term_mort); 459 original_terms.push_back(term_mort);
459 // Since we now have only one search term, the cached results for 're' and 460 // Since we now have only one search term, the cached results for 're' and
460 // 'reco' should be purged, giving us only 1 item in the cache (for 'mort'). 461 // 'reco' should be purged, giving us only 1 item in the cache (for 'mort').
461 url_index_->HistoryItemsForTerms(terms); 462 url_index_->HistoryItemsForTerms(original_terms);
462 ASSERT_EQ(1U, cache.size()); 463 ASSERT_EQ(1U, cache.size());
463 CheckTerm(cache, term_mort); 464 CheckTerm(cache, term_mort);
464 465
465 // Simulate typing "reco" giving "mort reco" in the simulated omnibox. 466 // Simulate typing "reco" giving "mort reco" in the simulated omnibox.
466 terms.push_back(term_reco); 467 original_terms.push_back(term_reco);
467 url_index_->HistoryItemsForTerms(terms); 468 url_index_->HistoryItemsForTerms(original_terms);
468 ASSERT_EQ(2U, cache.size()); 469 ASSERT_EQ(2U, cache.size());
469 CheckTerm(cache, term_mort); 470 CheckTerm(cache, term_mort);
470 CheckTerm(cache, term_reco); 471 CheckTerm(cache, term_reco);
471 472
472 // Simulate a <DELETE> by removing the 'reco' and adding back the 'rec'. 473 // Simulate a <DELETE> by removing the 'reco' and adding back the 'rec'.
473 terms.resize(terms.size() - 1); 474 original_terms.resize(original_terms.size() - 1);
474 string16 term_rec = ASCIIToUTF16("rec"); 475 string16 term_rec = ASCIIToUTF16("rec");
475 terms.push_back(term_rec); 476 original_terms.push_back(term_rec);
476 url_index_->HistoryItemsForTerms(terms); 477 url_index_->HistoryItemsForTerms(original_terms);
477 ASSERT_EQ(2U, cache.size()); 478 ASSERT_EQ(2U, cache.size());
478 CheckTerm(cache, term_mort); 479 CheckTerm(cache, term_mort);
479 CheckTerm(cache, term_rec); 480 CheckTerm(cache, term_rec);
480 } 481 }
481 482
482 TEST_F(InMemoryURLIndexTest, Scoring) { 483 TEST_F(InMemoryURLIndexTest, Scoring) {
483 URLRow row_a(MakeURLRow("http://abcdef", "fedcba", 3, 30, 1)); 484 URLRow row_a(MakeURLRow("http://abcdef", "fedcba", 3, 30, 1));
484 // Test scores based on position. 485 // Test scores based on position.
485 ScoredHistoryMatch scored_a( 486 ScoredHistoryMatch scored_a(
486 InMemoryURLIndex::ScoredMatchForURL(row_a, Make1Term("abc"))); 487 InMemoryURLIndex::ScoredMatchForURL(row_a, Make1Term("abc")));
(...skipping 21 matching lines...) Expand all
508 InMemoryURLIndex::ScoredMatchForURL(row_c, Make1Term("abc"))); 509 InMemoryURLIndex::ScoredMatchForURL(row_c, Make1Term("abc")));
509 EXPECT_GT(scored_g.raw_score, scored_a.raw_score); 510 EXPECT_GT(scored_g.raw_score, scored_a.raw_score);
510 // Test scores based on typed_count. 511 // Test scores based on typed_count.
511 URLRow row_d(MakeURLRow("http://abcdef", "fedcba", 3, 30, 10)); 512 URLRow row_d(MakeURLRow("http://abcdef", "fedcba", 3, 30, 10));
512 ScoredHistoryMatch scored_h( 513 ScoredHistoryMatch scored_h(
513 InMemoryURLIndex::ScoredMatchForURL(row_d, Make1Term("abc"))); 514 InMemoryURLIndex::ScoredMatchForURL(row_d, Make1Term("abc")));
514 EXPECT_GT(scored_h.raw_score, scored_a.raw_score); 515 EXPECT_GT(scored_h.raw_score, scored_a.raw_score);
515 } 516 }
516 517
517 TEST_F(InMemoryURLIndexTest, AddNewRows) { 518 TEST_F(InMemoryURLIndexTest, AddNewRows) {
518 url_index_.reset(new InMemoryURLIndex(NULL, FilePath())); 519 url_index_.reset(new InMemoryURLIndex(FilePath()));
519 url_index_->Init(this, "en,ja,hi,zh"); 520 url_index_->Init(this, "en,ja,hi,zh");
520 String16Vector terms; 521 String16Vector original_terms;
521 522
522 // Verify that the row we're going to add does not already exist. 523 // Verify that the row we're going to add does not already exist.
523 URLID new_row_id = 87654321; 524 URLID new_row_id = 87654321;
524 // Newly created URLRows get a last_visit time of 'right now' so it should 525 // Newly created URLRows get a last_visit time of 'right now' so it should
525 // qualify as a quick result candidate. 526 // qualify as a quick result candidate.
526 terms.push_back(ASCIIToUTF16("brokeandalone")); 527 original_terms.push_back(ASCIIToUTF16("brokeandalone"));
527 EXPECT_TRUE(url_index_->HistoryItemsForTerms(terms).empty()); 528 EXPECT_TRUE(url_index_->HistoryItemsForTerms(original_terms).empty());
528 529
529 // Add a new row. 530 // Add a new row.
530 URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), new_row_id); 531 URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), new_row_id);
531 new_row.set_last_visit(base::Time::Now()); 532 new_row.set_last_visit(base::Time::Now());
532 url_index_->UpdateURL(new_row); 533 url_index_->UpdateURL(new_row_id, new_row);
533 534
534 // Verify that we can retrieve it. 535 // Verify that we can retrieve it.
535 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms(terms).size()); 536 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms(original_terms).size());
536 537
537 // Add it again just to be sure that is harmless. 538 // Add it again just to be sure that is harmless.
538 url_index_->UpdateURL(new_row); 539 url_index_->UpdateURL(new_row_id, new_row);
539 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms(terms).size()); 540 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms(original_terms).size());
540 } 541 }
541 542
542 TEST_F(InMemoryURLIndexTest, DeleteRows) { 543 TEST_F(InMemoryURLIndexTest, DeleteRows) {
543 url_index_.reset(new InMemoryURLIndex(NULL, FilePath())); 544 url_index_.reset(new InMemoryURLIndex(FilePath()));
544 url_index_->Init(this, "en,ja,hi,zh"); 545 url_index_->Init(this, "en,ja,hi,zh");
545 String16Vector terms; 546 String16Vector original_terms;
546 547
547 // Make sure we actually get an existing result. 548 // Make sure we actually get an existing result.
548 terms.push_back(ASCIIToUTF16("DrudgeReport")); 549 original_terms.push_back(ASCIIToUTF16("DrudgeReport"));
549 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(terms); 550 ScoredHistoryMatches matches =
551 url_index_->HistoryItemsForTerms(original_terms);
550 ASSERT_EQ(1U, matches.size()); 552 ASSERT_EQ(1U, matches.size());
551 553
552 // Determine the row id for that result, delete that id, then search again. 554 // Determine the row id for that result, delete that id, then search again.
553 url_index_->DeleteURL(matches[0].url_info); 555 url_index_->DeleteURL(matches[0].url_info.id());
554 EXPECT_TRUE(url_index_->HistoryItemsForTerms(terms).empty()); 556 EXPECT_TRUE(url_index_->HistoryItemsForTerms(original_terms).empty());
555 } 557 }
556 558
557 TEST_F(InMemoryURLIndexTest, WhitelistedURLs) { 559 TEST_F(InMemoryURLIndexTest, WhitelistedURLs) {
558 struct TestData { 560 struct TestData {
559 const std::string url_spec; 561 const std::string url_spec;
560 const bool expected_is_whitelisted; 562 const bool expected_is_whitelisted;
561 } data[] = { 563 } data[] = {
562 // URLs with whitelisted schemes. 564 // URLs with whitelisted schemes.
563 { "about:histograms", true }, 565 { "about:histograms", true },
564 { "chrome://settings", true }, 566 { "chrome://settings", true },
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 { "telnet://mayor_margie:one2rule4All@www.mycity.com:6789/", false }, 622 { "telnet://mayor_margie:one2rule4All@www.mycity.com:6789/", false },
621 { "tftp://example.com/mystartupfile", false }, 623 { "tftp://example.com/mystartupfile", false },
622 { "tip://123.123.123.123/?urn:xopen:xid", false }, 624 { "tip://123.123.123.123/?urn:xopen:xid", false },
623 { "tv:nbc.com", false }, 625 { "tv:nbc.com", false },
624 { "urn:foo:A123,456", false }, 626 { "urn:foo:A123,456", false },
625 { "vemmi://zeus.mctel.fr/demo", false }, 627 { "vemmi://zeus.mctel.fr/demo", false },
626 { "wais://www.mydomain.net:8765/mydatabase", false }, 628 { "wais://www.mydomain.net:8765/mydatabase", false },
627 { "xmpp:node@example.com", false }, 629 { "xmpp:node@example.com", false },
628 { "xmpp://guest@example.com", false }, 630 { "xmpp://guest@example.com", false },
629 }; 631 };
630 url_index_.reset(new InMemoryURLIndex(NULL, FilePath())); 632 url_index_.reset(new InMemoryURLIndex(FilePath()));
631 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { 633 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) {
632 GURL url(data[i].url_spec); 634 GURL url(data[i].url_spec);
633 EXPECT_EQ(data[i].expected_is_whitelisted, 635 EXPECT_EQ(data[i].expected_is_whitelisted,
634 url_index_->URLSchemeIsWhitelisted(url)); 636 url_index_->URLSchemeIsWhitelisted(url));
635 } 637 }
636 } 638 }
637 639
638 TEST_F(InMemoryURLIndexTest, CacheFilePath) { 640 TEST_F(InMemoryURLIndexTest, CacheFilePath) {
639 url_index_.reset(new InMemoryURLIndex( 641 url_index_.reset(new InMemoryURLIndex(FilePath(FILE_PATH_LITERAL(
640 NULL, FilePath(FILE_PATH_LITERAL("/flammmy/frammy/")))); 642 "/flammmy/frammy/"))));
641 FilePath full_file_path; 643 FilePath full_file_path;
642 url_index_->GetCacheFilePath(&full_file_path); 644 url_index_->GetCacheFilePath(&full_file_path);
643 std::vector<FilePath::StringType> expected_parts; 645 std::vector<FilePath::StringType> expected_parts;
644 FilePath(FILE_PATH_LITERAL("/flammmy/frammy/History Provider Cache")). 646 FilePath(FILE_PATH_LITERAL("/flammmy/frammy/History Provider Cache")).
645 GetComponents(&expected_parts); 647 GetComponents(&expected_parts);
646 std::vector<FilePath::StringType> actual_parts; 648 std::vector<FilePath::StringType> actual_parts;
647 full_file_path.GetComponents(&actual_parts); 649 full_file_path.GetComponents(&actual_parts);
648 ASSERT_EQ(expected_parts.size(), actual_parts.size()); 650 ASSERT_EQ(expected_parts.size(), actual_parts.size());
649 size_t count = expected_parts.size(); 651 size_t count = expected_parts.size();
650 for (size_t i = 0; i < count; ++i) 652 for (size_t i = 0; i < count; ++i)
651 EXPECT_EQ(expected_parts[i], actual_parts[i]); 653 EXPECT_EQ(expected_parts[i], actual_parts[i]);
652 // Must clear the history_dir_ to satisfy the dtor's DCHECK. 654 // Must clear the history_dir_ to satisfy the dtor's DCHECK.
653 url_index_->history_dir_.clear(); 655 url_index_->history_dir_.clear();
654 } 656 }
655 657
656 TEST_F(InMemoryURLIndexTest, CacheSaveRestore) { 658 TEST_F(InMemoryURLIndexTest, CacheSaveRestore) {
657 // Save the cache to a protobuf, restore it, and compare the results. 659 // Save the cache to a protobuf, restore it, and compare the results.
658 url_index_.reset(new InMemoryURLIndex(NULL, FilePath())); 660 url_index_.reset(new InMemoryURLIndex(FilePath()));
659 InMemoryURLIndex& url_index(*(url_index_.get())); 661 InMemoryURLIndex& url_index(*(url_index_.get()));
660 url_index.Init(this, "en,ja,hi,zh"); 662 url_index.Init(this, "en,ja,hi,zh");
661 in_memory_url_index::InMemoryURLIndexCacheItem index_cache; 663 in_memory_url_index::InMemoryURLIndexCacheItem index_cache;
662 url_index.SavePrivateData(&index_cache); 664 url_index.SavePrivateData(&index_cache);
663 665
664 // Capture our private data so we can later compare for equality. 666 // Capture our private data so we can later compare for equality.
665 URLIndexPrivateData& private_data(*(url_index_->private_data_)); 667 URLIndexPrivateData& private_data(*(url_index_->private_data_));
666 String16Vector word_list(private_data.word_list_); 668 String16Vector word_list(private_data.word_list_);
667 WordMap word_map(private_data.word_map_); 669 WordMap word_map(private_data.word_map_);
668 CharWordIDMap char_word_map(private_data.char_word_map_); 670 CharWordIDMap char_word_map(private_data.char_word_map_);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 const URLRow& expected_row(expected->second); 725 const URLRow& expected_row(expected->second);
724 const URLRow& actual_row(actual->second); 726 const URLRow& actual_row(actual->second);
725 EXPECT_EQ(expected_row.visit_count(), actual_row.visit_count()); 727 EXPECT_EQ(expected_row.visit_count(), actual_row.visit_count());
726 EXPECT_EQ(expected_row.typed_count(), actual_row.typed_count()); 728 EXPECT_EQ(expected_row.typed_count(), actual_row.typed_count());
727 EXPECT_EQ(expected_row.last_visit(), actual_row.last_visit()); 729 EXPECT_EQ(expected_row.last_visit(), actual_row.last_visit());
728 EXPECT_EQ(expected_row.url(), actual_row.url()); 730 EXPECT_EQ(expected_row.url(), actual_row.url());
729 } 731 }
730 } 732 }
731 733
732 } // namespace history 734 } // 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