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

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

Issue 9289034: Fix keyword recognition. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Now handles multiple occurrences of search term in URL. Added test. Created 8 years, 10 months 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) 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 <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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 225
226 // See if a very specific term gives a single result. 226 // See if a very specific term gives a single result.
227 ScoredHistoryMatches matches = 227 ScoredHistoryMatches matches =
228 url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudgeReport")); 228 url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudgeReport"));
229 ASSERT_EQ(1U, matches.size()); 229 ASSERT_EQ(1U, matches.size());
230 230
231 // Verify that we got back the result we expected. 231 // Verify that we got back the result we expected.
232 EXPECT_EQ(5, matches[0].url_info.id()); 232 EXPECT_EQ(5, matches[0].url_info.id());
233 EXPECT_EQ("http://drudgereport.com/", matches[0].url_info.url().spec()); 233 EXPECT_EQ("http://drudgereport.com/", matches[0].url_info.url().spec());
234 EXPECT_EQ(ASCIIToUTF16("DRUDGE REPORT 2010"), matches[0].url_info.title()); 234 EXPECT_EQ(ASCIIToUTF16("DRUDGE REPORT 2010"), matches[0].url_info.title());
235 EXPECT_TRUE(matches[0].can_inline);
236
237 // Make sure a trailing space prevents inline-ability but still results
238 // in the expected result.
239 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudgeReport "));
240 ASSERT_EQ(1U, matches.size());
241 EXPECT_EQ(5, matches[0].url_info.id());
242 EXPECT_EQ("http://drudgereport.com/", matches[0].url_info.url().spec());
243 EXPECT_EQ(ASCIIToUTF16("DRUDGE REPORT 2010"), matches[0].url_info.title());
244 EXPECT_FALSE(matches[0].can_inline);
235 245
236 // Search which should result in multiple results. 246 // Search which should result in multiple results.
237 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("drudge")); 247 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("drudge"));
238 ASSERT_EQ(2U, matches.size()); 248 ASSERT_EQ(2U, matches.size());
239 // The results should be in descending score order. 249 // The results should be in descending score order.
240 EXPECT_GE(matches[0].raw_score, matches[1].raw_score); 250 EXPECT_GE(matches[0].raw_score, matches[1].raw_score);
241 251
242 // Search which should result in nearly perfect result. 252 // Search which should result in nearly perfect result.
243 matches = url_index_->HistoryItemsForTerms( 253 matches = url_index_->HistoryItemsForTerms(
244 ASCIIToUTF16("https NearlyPerfectResult")); 254 ASCIIToUTF16("https NearlyPerfectResult"));
245 ASSERT_EQ(1U, matches.size()); 255 ASSERT_EQ(1U, matches.size());
246 // The results should have a very high score. 256 // The results should have a very high score.
247 EXPECT_GT(matches[0].raw_score, 900); 257 EXPECT_GT(matches[0].raw_score, 900);
248 EXPECT_EQ(32, matches[0].url_info.id()); 258 EXPECT_EQ(32, matches[0].url_info.id());
249 EXPECT_EQ("https://nearlyperfectresult.com/", 259 EXPECT_EQ("https://nearlyperfectresult.com/",
250 matches[0].url_info.url().spec()); // Note: URL gets lowercased. 260 matches[0].url_info.url().spec()); // Note: URL gets lowercased.
251 EXPECT_EQ(ASCIIToUTF16("Practically Perfect Search Result"), 261 EXPECT_EQ(ASCIIToUTF16("Practically Perfect Search Result"),
252 matches[0].url_info.title()); 262 matches[0].url_info.title());
263 EXPECT_FALSE(matches[0].can_inline);
253 264
254 // Search which should result in very poor result. 265 // Search which should result in very poor result.
255 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("z y x")); 266 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("z y x"));
256 ASSERT_EQ(1U, matches.size()); 267 ASSERT_EQ(1U, matches.size());
257 // The results should have a poor score. 268 // The results should have a poor score.
258 EXPECT_LT(matches[0].raw_score, 500); 269 EXPECT_LT(matches[0].raw_score, 500);
259 EXPECT_EQ(33, matches[0].url_info.id()); 270 EXPECT_EQ(33, matches[0].url_info.id());
260 EXPECT_EQ("http://quiteuselesssearchresultxyz.com/", 271 EXPECT_EQ("http://quiteuselesssearchresultxyz.com/",
261 matches[0].url_info.url().spec()); // Note: URL gets lowercased. 272 matches[0].url_info.url().spec()); // Note: URL gets lowercased.
262 EXPECT_EQ(ASCIIToUTF16("Practically Useless Search Result"), 273 EXPECT_EQ(ASCIIToUTF16("Practically Useless Search Result"),
263 matches[0].url_info.title()); 274 matches[0].url_info.title());
275 EXPECT_FALSE(matches[0].can_inline);
264 276
265 // Search which will match at the end of an URL with encoded characters. 277 // Search which will match at the end of an URL with encoded characters.
266 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("ice")); 278 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("ice"));
267 ASSERT_EQ(1U, matches.size()); 279 ASSERT_EQ(1U, matches.size());
280 EXPECT_FALSE(matches[0].can_inline);
281
282 // Verify that a single term can appear multiple times in the URL and as long
283 // as one starts the URL it is still inlined.
284 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("fubar"));
285 ASSERT_EQ(1U, matches.size());
286 EXPECT_EQ(34, matches[0].url_info.id());
287 EXPECT_EQ("http://fubarfubarandfubar.com/", matches[0].url_info.url().spec());
288 EXPECT_EQ(ASCIIToUTF16("Situation Normal -- FUBARED"),
289 matches[0].url_info.title());
290 EXPECT_TRUE(matches[0].can_inline);
268 } 291 }
269 292
270 TEST_F(InMemoryURLIndexTest, URLPrefixMatching) { 293 TEST_F(InMemoryURLIndexTest, URLPrefixMatching) {
271 url_index_.reset(new InMemoryURLIndex(FilePath())); 294 url_index_.reset(new InMemoryURLIndex(FilePath()));
272 url_index_->Init(this, "en,ja,hi,zh"); 295 url_index_->Init(this, "en,ja,hi,zh");
273 296
274 // "drudgere" - found, can inline 297 // "drudgere" - found, can inline
275 ScoredHistoryMatches matches = 298 ScoredHistoryMatches matches =
276 url_index_->HistoryItemsForTerms(ASCIIToUTF16("drudgere")); 299 url_index_->HistoryItemsForTerms(ASCIIToUTF16("drudgere"));
277 ASSERT_EQ(1U, matches.size()); 300 ASSERT_EQ(1U, matches.size());
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), row_id); 379 URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), row_id);
357 new_row.set_last_visit(base::Time::Now()); 380 new_row.set_last_visit(base::Time::Now());
358 url_index_->UpdateURL(row_id, new_row); 381 url_index_->UpdateURL(row_id, new_row);
359 } 382 }
360 383
361 ScoredHistoryMatches matches = 384 ScoredHistoryMatches matches =
362 url_index_->HistoryItemsForTerms(ASCIIToUTF16("b")); 385 url_index_->HistoryItemsForTerms(ASCIIToUTF16("b"));
363 ASSERT_EQ(AutocompleteProvider::kMaxMatches, matches.size()); 386 ASSERT_EQ(AutocompleteProvider::kMaxMatches, matches.size());
364 // There are 7 matches already in the database. 387 // There are 7 matches already in the database.
365 URLIndexPrivateData& private_data(*(url_index_->private_data_.get())); 388 URLIndexPrivateData& private_data(*(url_index_->private_data_.get()));
366 ASSERT_EQ(1007U, private_data.pre_filter_item_count_); 389 ASSERT_EQ(1008U, private_data.pre_filter_item_count_);
367 ASSERT_EQ(500U, private_data.post_filter_item_count_); 390 ASSERT_EQ(500U, private_data.post_filter_item_count_);
368 ASSERT_EQ(AutocompleteProvider::kMaxMatches, 391 ASSERT_EQ(AutocompleteProvider::kMaxMatches,
369 private_data.post_scoring_item_count_); 392 private_data.post_scoring_item_count_);
370 } 393 }
371 394
372 TEST_F(InMemoryURLIndexTest, TitleSearch) { 395 TEST_F(InMemoryURLIndexTest, TitleSearch) {
373 url_index_.reset(new InMemoryURLIndex(FilePath())); 396 url_index_.reset(new InMemoryURLIndex(FilePath()));
374 url_index_->Init(this, "en,ja,hi,zh"); 397 url_index_->Init(this, "en,ja,hi,zh");
375 // Signal if someone has changed the test DB. 398 // Signal if someone has changed the test DB.
376 EXPECT_EQ(27U, url_index_->private_data_->history_info_map_.size()); 399 EXPECT_EQ(28U, url_index_->private_data_->history_info_map_.size());
377 400
378 // Ensure title is being searched. 401 // Ensure title is being searched.
379 ScoredHistoryMatches matches = 402 ScoredHistoryMatches matches =
380 url_index_->HistoryItemsForTerms(ASCIIToUTF16("MORTGAGE RATE DROPS")); 403 url_index_->HistoryItemsForTerms(ASCIIToUTF16("MORTGAGE RATE DROPS"));
381 ASSERT_EQ(1U, matches.size()); 404 ASSERT_EQ(1U, matches.size());
382 405
383 // Verify that we got back the result we expected. 406 // Verify that we got back the result we expected.
384 EXPECT_EQ(1, matches[0].url_info.id()); 407 EXPECT_EQ(1, matches[0].url_info.id());
385 EXPECT_EQ("http://www.reuters.com/article/idUSN0839880620100708", 408 EXPECT_EQ("http://www.reuters.com/article/idUSN0839880620100708",
386 matches[0].url_info.url().spec()); 409 matches[0].url_info.url().spec());
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 const URLRow& expected_row(expected->second); 790 const URLRow& expected_row(expected->second);
768 const URLRow& actual_row(actual->second); 791 const URLRow& actual_row(actual->second);
769 EXPECT_EQ(expected_row.visit_count(), actual_row.visit_count()); 792 EXPECT_EQ(expected_row.visit_count(), actual_row.visit_count());
770 EXPECT_EQ(expected_row.typed_count(), actual_row.typed_count()); 793 EXPECT_EQ(expected_row.typed_count(), actual_row.typed_count());
771 EXPECT_EQ(expected_row.last_visit(), actual_row.last_visit()); 794 EXPECT_EQ(expected_row.last_visit(), actual_row.last_visit());
772 EXPECT_EQ(expected_row.url(), actual_row.url()); 795 EXPECT_EQ(expected_row.url(), actual_row.url());
773 } 796 }
774 } 797 }
775 798
776 } // namespace history 799 } // namespace history
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/history/url_index_private_data.cc » ('j') | chrome/browser/history/url_index_private_data.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698