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

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

Issue 896983003: Componentize ScoredHistoryMatch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename ScoredHistoryMatchBuilder to ScoredHistoryMatchBuilderImpl Created 5 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
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 <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/path_service.h" 12 #include "base/path_service.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/strings/string16.h" 14 #include "base/strings/string16.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "chrome/browser/autocomplete/scored_history_match_builder_impl.h"
17 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 18 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
18 #include "chrome/browser/history/history_backend.h" 19 #include "chrome/browser/history/history_backend.h"
19 #include "chrome/browser/history/history_service.h" 20 #include "chrome/browser/history/history_service.h"
20 #include "chrome/browser/history/history_service_factory.h" 21 #include "chrome/browser/history/history_service_factory.h"
21 #include "chrome/browser/history/in_memory_url_index.h" 22 #include "chrome/browser/history/in_memory_url_index.h"
22 #include "chrome/browser/history/url_index_private_data.h" 23 #include "chrome/browser/history/url_index_private_data.h"
23 #include "chrome/common/chrome_paths.h" 24 #include "chrome/common/chrome_paths.h"
24 #include "chrome/test/base/history_index_restore_observer.h" 25 #include "chrome/test/base/history_index_restore_observer.h"
25 #include "chrome/test/base/testing_profile.h" 26 #include "chrome/test/base/testing_profile.h"
26 #include "components/bookmarks/test/bookmark_test_helpers.h" 27 #include "components/bookmarks/test/bookmark_test_helpers.h"
27 #include "components/history/core/browser/history_client.h"
28 #include "components/history/core/browser/history_database.h" 28 #include "components/history/core/browser/history_database.h"
29 #include "components/history/core/browser/in_memory_url_index_types.h" 29 #include "components/history/core/browser/in_memory_url_index_types.h"
30 #include "content/public/test/test_browser_thread_bundle.h" 30 #include "content/public/test/test_browser_thread_bundle.h"
31 #include "sql/transaction.h" 31 #include "sql/transaction.h"
32 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
33 33
34 using base::ASCIIToUTF16; 34 using base::ASCIIToUTF16;
35 35
36 namespace {
37 const size_t kMaxMatches = 3;
38 const char kTestLanguages[] = "en,ja,hi,zh";
39 } // namespace
40
41 // The test version of the history url database table ('url') is contained in 36 // The test version of the history url database table ('url') is contained in
42 // a database file created from a text file('url_history_provider_test.db.txt'). 37 // a database file created from a text file('url_history_provider_test.db.txt').
43 // The only difference between this table and a live 'urls' table from a 38 // The only difference between this table and a live 'urls' table from a
44 // profile is that the last_visit_time column in the test table contains a 39 // profile is that the last_visit_time column in the test table contains a
45 // number specifying the number of days relative to 'today' to which the 40 // number specifying the number of days relative to 'today' to which the
46 // absolute time should be set during the test setup stage. 41 // absolute time should be set during the test setup stage.
47 // 42 //
48 // The format of the test database text file is of a SQLite .dump file. 43 // The format of the test database text file is of a SQLite .dump file.
49 // Note that only lines whose first character is an upper-case letter are 44 // Note that only lines whose first character is an upper-case letter are
50 // processed when creating the test database. 45 // processed when creating the test database.
51 46
52 namespace history { 47 namespace history {
48 namespace {
49 const size_t kMaxMatches = 3;
50 const char kTestLanguages[] = "en,ja,hi,zh";
51 } // namespace
53 52
54 // ----------------------------------------------------------------------------- 53 // -----------------------------------------------------------------------------
55 54
56 // Observer class so the unit tests can wait while the cache is being saved. 55 // Observer class so the unit tests can wait while the cache is being saved.
57 class CacheFileSaverObserver : public InMemoryURLIndex::SaveCacheObserver { 56 class CacheFileSaverObserver : public InMemoryURLIndex::SaveCacheObserver {
58 public: 57 public:
59 explicit CacheFileSaverObserver(const base::Closure& task); 58 explicit CacheFileSaverObserver(const base::Closure& task);
60 59
61 bool succeeded() { return succeeded_; } 60 bool succeeded() { return succeeded_; }
62 61
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 // Pass-through functions to simplify our friendship with URLIndexPrivateData. 122 // Pass-through functions to simplify our friendship with URLIndexPrivateData.
124 bool UpdateURL(const URLRow& row); 123 bool UpdateURL(const URLRow& row);
125 bool DeleteURL(const GURL& url); 124 bool DeleteURL(const GURL& url);
126 125
127 // Data verification helper functions. 126 // Data verification helper functions.
128 void ExpectPrivateDataNotEmpty(const URLIndexPrivateData& data); 127 void ExpectPrivateDataNotEmpty(const URLIndexPrivateData& data);
129 void ExpectPrivateDataEmpty(const URLIndexPrivateData& data); 128 void ExpectPrivateDataEmpty(const URLIndexPrivateData& data);
130 void ExpectPrivateDataEqual(const URLIndexPrivateData& expected, 129 void ExpectPrivateDataEqual(const URLIndexPrivateData& expected,
131 const URLIndexPrivateData& actual); 130 const URLIndexPrivateData& actual);
132 131
132 ScoredHistoryMatchBuilderImpl builder_;
133 content::TestBrowserThreadBundle thread_bundle_; 133 content::TestBrowserThreadBundle thread_bundle_;
134 scoped_ptr<InMemoryURLIndex> url_index_; 134 scoped_ptr<InMemoryURLIndex> url_index_;
135 TestingProfile profile_; 135 TestingProfile profile_;
136 HistoryService* history_service_; 136 HistoryService* history_service_;
137 HistoryDatabase* history_database_; 137 HistoryDatabase* history_database_;
138 }; 138 };
139 139
140 InMemoryURLIndexTest::InMemoryURLIndexTest() { 140 InMemoryURLIndexTest::InMemoryURLIndexTest()
141 : builder_(ScoredHistoryMatchBuilderImpl::IsBookmarkedCallback()),
Mark P 2015/02/07 07:00:13 Does this construct an empty callback to pass to b
sdefresne 2015/02/09 10:01:14 Yes, as those tests does not bookmark any URL. The
142 history_service_(nullptr),
143 history_database_(nullptr) {
141 } 144 }
142 145
143 sql::Connection& InMemoryURLIndexTest::GetDB() { 146 sql::Connection& InMemoryURLIndexTest::GetDB() {
144 return history_database_->GetDB(); 147 return history_database_->GetDB();
145 } 148 }
146 149
147 URLIndexPrivateData* InMemoryURLIndexTest::GetPrivateData() const { 150 URLIndexPrivateData* InMemoryURLIndexTest::GetPrivateData() const {
148 DCHECK(url_index_->private_data()); 151 DCHECK(url_index_->private_data());
149 return url_index_->private_data(); 152 return url_index_->private_data();
150 } 153 }
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 base::FilePath::StringType InMemoryURLIndexTest::TestDBName() const { 297 base::FilePath::StringType InMemoryURLIndexTest::TestDBName() const {
295 return FILE_PATH_LITERAL("url_history_provider_test.db.txt"); 298 return FILE_PATH_LITERAL("url_history_provider_test.db.txt");
296 } 299 }
297 300
298 bool InMemoryURLIndexTest::InitializeInMemoryURLIndexInSetUp() const { 301 bool InMemoryURLIndexTest::InitializeInMemoryURLIndexInSetUp() const {
299 return true; 302 return true;
300 } 303 }
301 304
302 void InMemoryURLIndexTest::InitializeInMemoryURLIndex() { 305 void InMemoryURLIndexTest::InitializeInMemoryURLIndex() {
303 DCHECK(!url_index_); 306 DCHECK(!url_index_);
304 url_index_.reset(new InMemoryURLIndex(history_service_, base::FilePath(), 307 url_index_.reset(
305 kTestLanguages, 308 new InMemoryURLIndex(history_service_, base::FilePath(), kTestLanguages));
306 history_service_->history_client()));
307 url_index_->Init(); 309 url_index_->Init();
308 url_index_->RebuildFromHistory(history_database_); 310 url_index_->RebuildFromHistory(history_database_);
309 } 311 }
310 312
311 void InMemoryURLIndexTest::CheckTerm( 313 void InMemoryURLIndexTest::CheckTerm(
312 const URLIndexPrivateData::SearchTermCacheMap& cache, 314 const URLIndexPrivateData::SearchTermCacheMap& cache,
313 base::string16 term) const { 315 base::string16 term) const {
314 URLIndexPrivateData::SearchTermCacheMap::const_iterator cache_iter( 316 URLIndexPrivateData::SearchTermCacheMap::const_iterator cache_iter(
315 cache.find(term)); 317 cache.find(term));
316 ASSERT_TRUE(cache.end() != cache_iter) 318 ASSERT_TRUE(cache.end() != cache_iter)
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 475
474 #if defined(OS_WIN) 476 #if defined(OS_WIN)
475 // Flaky on windows trybots: http://crbug.com/351500 477 // Flaky on windows trybots: http://crbug.com/351500
476 #define MAYBE_Retrieval DISABLED_Retrieval 478 #define MAYBE_Retrieval DISABLED_Retrieval
477 #else 479 #else
478 #define MAYBE_Retrieval Retrieval 480 #define MAYBE_Retrieval Retrieval
479 #endif 481 #endif
480 TEST_F(InMemoryURLIndexTest, MAYBE_Retrieval) { 482 TEST_F(InMemoryURLIndexTest, MAYBE_Retrieval) {
481 // See if a very specific term gives a single result. 483 // See if a very specific term gives a single result.
482 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( 484 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(
483 ASCIIToUTF16("DrudgeReport"), base::string16::npos, kMaxMatches); 485 ASCIIToUTF16("DrudgeReport"), base::string16::npos, kMaxMatches,
486 builder_);
484 ASSERT_EQ(1U, matches.size()); 487 ASSERT_EQ(1U, matches.size());
485 488
486 // Verify that we got back the result we expected. 489 // Verify that we got back the result we expected.
487 EXPECT_EQ(5, matches[0].url_info.id()); 490 EXPECT_EQ(5, matches[0].url_info.id());
488 EXPECT_EQ("http://drudgereport.com/", matches[0].url_info.url().spec()); 491 EXPECT_EQ("http://drudgereport.com/", matches[0].url_info.url().spec());
489 EXPECT_EQ(ASCIIToUTF16("DRUDGE REPORT 2010"), matches[0].url_info.title()); 492 EXPECT_EQ(ASCIIToUTF16("DRUDGE REPORT 2010"), matches[0].url_info.title());
490 EXPECT_TRUE(matches[0].can_inline()); 493 EXPECT_TRUE(matches[0].can_inline);
491 494
492 // Make sure a trailing space prevents inline-ability but still results 495 // Make sure a trailing space prevents inline-ability but still results
493 // in the expected result. 496 // in the expected result.
494 matches = url_index_->HistoryItemsForTerms( 497 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudgeReport "),
495 ASCIIToUTF16("DrudgeReport "), base::string16::npos, kMaxMatches); 498 base::string16::npos, kMaxMatches,
499 builder_);
496 ASSERT_EQ(1U, matches.size()); 500 ASSERT_EQ(1U, matches.size());
497 EXPECT_EQ(5, matches[0].url_info.id()); 501 EXPECT_EQ(5, matches[0].url_info.id());
498 EXPECT_EQ("http://drudgereport.com/", matches[0].url_info.url().spec()); 502 EXPECT_EQ("http://drudgereport.com/", matches[0].url_info.url().spec());
499 EXPECT_EQ(ASCIIToUTF16("DRUDGE REPORT 2010"), matches[0].url_info.title()); 503 EXPECT_EQ(ASCIIToUTF16("DRUDGE REPORT 2010"), matches[0].url_info.title());
500 EXPECT_FALSE(matches[0].can_inline()); 504 EXPECT_FALSE(matches[0].can_inline);
501 505
502 // Search which should result in multiple results. 506 // Search which should result in multiple results.
503 matches = url_index_->HistoryItemsForTerms( 507 matches = url_index_->HistoryItemsForTerms(
504 ASCIIToUTF16("drudge"), base::string16::npos, kMaxMatches); 508 ASCIIToUTF16("drudge"), base::string16::npos, kMaxMatches, builder_);
505 ASSERT_EQ(2U, matches.size()); 509 ASSERT_EQ(2U, matches.size());
506 // The results should be in descending score order. 510 // The results should be in descending score order.
507 EXPECT_GE(matches[0].raw_score(), matches[1].raw_score()); 511 EXPECT_GE(matches[0].raw_score, matches[1].raw_score);
508 512
509 // Search which should result in nearly perfect result. 513 // Search which should result in nearly perfect result.
510 matches = url_index_->HistoryItemsForTerms( 514 matches = url_index_->HistoryItemsForTerms(
511 ASCIIToUTF16("Nearly Perfect Result"), base::string16::npos, kMaxMatches); 515 ASCIIToUTF16("Nearly Perfect Result"), base::string16::npos, kMaxMatches,
516 builder_);
512 ASSERT_EQ(1U, matches.size()); 517 ASSERT_EQ(1U, matches.size());
513 // The results should have a very high score. 518 // The results should have a very high score.
514 EXPECT_GT(matches[0].raw_score(), 900); 519 EXPECT_GT(matches[0].raw_score, 900);
515 EXPECT_EQ(32, matches[0].url_info.id()); 520 EXPECT_EQ(32, matches[0].url_info.id());
516 EXPECT_EQ("https://nearlyperfectresult.com/", 521 EXPECT_EQ("https://nearlyperfectresult.com/",
517 matches[0].url_info.url().spec()); // Note: URL gets lowercased. 522 matches[0].url_info.url().spec()); // Note: URL gets lowercased.
518 EXPECT_EQ(ASCIIToUTF16("Practically Perfect Search Result"), 523 EXPECT_EQ(ASCIIToUTF16("Practically Perfect Search Result"),
519 matches[0].url_info.title()); 524 matches[0].url_info.title());
520 EXPECT_FALSE(matches[0].can_inline()); 525 EXPECT_FALSE(matches[0].can_inline);
521 526
522 // Search which should result in very poor result. 527 // Search which should result in very poor result.
523 matches = url_index_->HistoryItemsForTerms( 528 matches = url_index_->HistoryItemsForTerms(
524 ASCIIToUTF16("qui c"), base::string16::npos, kMaxMatches); 529 ASCIIToUTF16("qui c"), base::string16::npos, kMaxMatches, builder_);
525 ASSERT_EQ(1U, matches.size()); 530 ASSERT_EQ(1U, matches.size());
526 // The results should have a poor score. 531 // The results should have a poor score.
527 EXPECT_LT(matches[0].raw_score(), 500); 532 EXPECT_LT(matches[0].raw_score, 500);
528 EXPECT_EQ(33, matches[0].url_info.id()); 533 EXPECT_EQ(33, matches[0].url_info.id());
529 EXPECT_EQ("http://quiteuselesssearchresultxyz.com/", 534 EXPECT_EQ("http://quiteuselesssearchresultxyz.com/",
530 matches[0].url_info.url().spec()); // Note: URL gets lowercased. 535 matches[0].url_info.url().spec()); // Note: URL gets lowercased.
531 EXPECT_EQ(ASCIIToUTF16("Practically Useless Search Result"), 536 EXPECT_EQ(ASCIIToUTF16("Practically Useless Search Result"),
532 matches[0].url_info.title()); 537 matches[0].url_info.title());
533 EXPECT_FALSE(matches[0].can_inline()); 538 EXPECT_FALSE(matches[0].can_inline);
534 539
535 // Search which will match at the end of an URL with encoded characters. 540 // Search which will match at the end of an URL with encoded characters.
536 matches = url_index_->HistoryItemsForTerms( 541 matches = url_index_->HistoryItemsForTerms(
537 ASCIIToUTF16("Mice"), base::string16::npos, kMaxMatches); 542 ASCIIToUTF16("Mice"), base::string16::npos, kMaxMatches, builder_);
538 ASSERT_EQ(1U, matches.size()); 543 ASSERT_EQ(1U, matches.size());
539 EXPECT_EQ(30, matches[0].url_info.id()); 544 EXPECT_EQ(30, matches[0].url_info.id());
540 EXPECT_FALSE(matches[0].can_inline()); 545 EXPECT_FALSE(matches[0].can_inline);
541 546
542 // Check that URLs are not escaped an escape time. 547 // Check that URLs are not escaped an escape time.
543 matches = url_index_->HistoryItemsForTerms( 548 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("1% wikipedia"),
544 ASCIIToUTF16("1% wikipedia"), base::string16::npos, kMaxMatches); 549 base::string16::npos, kMaxMatches,
550 builder_);
545 ASSERT_EQ(1U, matches.size()); 551 ASSERT_EQ(1U, matches.size());
546 EXPECT_EQ(35, matches[0].url_info.id()); 552 EXPECT_EQ(35, matches[0].url_info.id());
547 EXPECT_EQ("http://en.wikipedia.org/wiki/1%25_rule_(Internet_culture)", 553 EXPECT_EQ("http://en.wikipedia.org/wiki/1%25_rule_(Internet_culture)",
548 matches[0].url_info.url().spec()); 554 matches[0].url_info.url().spec());
549 555
550 // Verify that a single term can appear multiple times in the URL and as long 556 // Verify that a single term can appear multiple times in the URL and as long
551 // as one starts the URL it is still inlined. 557 // as one starts the URL it is still inlined.
552 matches = url_index_->HistoryItemsForTerms( 558 matches = url_index_->HistoryItemsForTerms(
553 ASCIIToUTF16("fubar"), base::string16::npos, kMaxMatches); 559 ASCIIToUTF16("fubar"), base::string16::npos, kMaxMatches, builder_);
554 ASSERT_EQ(1U, matches.size()); 560 ASSERT_EQ(1U, matches.size());
555 EXPECT_EQ(34, matches[0].url_info.id()); 561 EXPECT_EQ(34, matches[0].url_info.id());
556 EXPECT_EQ("http://fubarfubarandfubar.com/", matches[0].url_info.url().spec()); 562 EXPECT_EQ("http://fubarfubarandfubar.com/", matches[0].url_info.url().spec());
557 EXPECT_EQ(ASCIIToUTF16("Situation Normal -- FUBARED"), 563 EXPECT_EQ(ASCIIToUTF16("Situation Normal -- FUBARED"),
558 matches[0].url_info.title()); 564 matches[0].url_info.title());
559 EXPECT_TRUE(matches[0].can_inline()); 565 EXPECT_TRUE(matches[0].can_inline);
560 } 566 }
561 567
562 TEST_F(InMemoryURLIndexTest, CursorPositionRetrieval) { 568 TEST_F(InMemoryURLIndexTest, CursorPositionRetrieval) {
563 // See if a very specific term with no cursor gives an empty result. 569 // See if a very specific term with no cursor gives an empty result.
564 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( 570 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(
565 ASCIIToUTF16("DrudReport"), base::string16::npos, kMaxMatches); 571 ASCIIToUTF16("DrudReport"), base::string16::npos, kMaxMatches, builder_);
566 ASSERT_EQ(0U, matches.size()); 572 ASSERT_EQ(0U, matches.size());
567 573
568 // The same test with the cursor at the end should give an empty result. 574 // The same test with the cursor at the end should give an empty result.
569 matches = url_index_->HistoryItemsForTerms( 575 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudReport"), 10u,
570 ASCIIToUTF16("DrudReport"), 10u, kMaxMatches); 576 kMaxMatches, builder_);
571 ASSERT_EQ(0U, matches.size()); 577 ASSERT_EQ(0U, matches.size());
572 578
573 // If the cursor is between Drud and Report, we should find the desired 579 // If the cursor is between Drud and Report, we should find the desired
574 // result. 580 // result.
575 matches = url_index_->HistoryItemsForTerms( 581 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudReport"), 4u,
576 ASCIIToUTF16("DrudReport"), 4u, kMaxMatches); 582 kMaxMatches, builder_);
577 ASSERT_EQ(1U, matches.size()); 583 ASSERT_EQ(1U, matches.size());
578 EXPECT_EQ("http://drudgereport.com/", matches[0].url_info.url().spec()); 584 EXPECT_EQ("http://drudgereport.com/", matches[0].url_info.url().spec());
579 EXPECT_EQ(ASCIIToUTF16("DRUDGE REPORT 2010"), matches[0].url_info.title()); 585 EXPECT_EQ(ASCIIToUTF16("DRUDGE REPORT 2010"), matches[0].url_info.title());
580 586
581 // Now check multi-word inputs. No cursor should fail to find a 587 // Now check multi-word inputs. No cursor should fail to find a
582 // result on this input. 588 // result on this input.
583 matches = url_index_->HistoryItemsForTerms( 589 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("MORTGAGERATE DROPS"),
584 ASCIIToUTF16("MORTGAGERATE DROPS"), base::string16::npos, kMaxMatches); 590 base::string16::npos, kMaxMatches,
591 builder_);
585 ASSERT_EQ(0U, matches.size()); 592 ASSERT_EQ(0U, matches.size());
586 593
587 // Ditto with cursor at end. 594 // Ditto with cursor at end.
588 matches = url_index_->HistoryItemsForTerms( 595 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("MORTGAGERATE DROPS"),
589 ASCIIToUTF16("MORTGAGERATE DROPS"), 18u, kMaxMatches); 596 18u, kMaxMatches, builder_);
590 ASSERT_EQ(0U, matches.size()); 597 ASSERT_EQ(0U, matches.size());
591 598
592 // If the cursor is between MORTAGE And RATE, we should find the 599 // If the cursor is between MORTAGE And RATE, we should find the
593 // desired result. 600 // desired result.
594 matches = url_index_->HistoryItemsForTerms( 601 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("MORTGAGERATE DROPS"),
595 ASCIIToUTF16("MORTGAGERATE DROPS"), 8u, kMaxMatches); 602 8u, kMaxMatches, builder_);
596 ASSERT_EQ(1U, matches.size()); 603 ASSERT_EQ(1U, matches.size());
597 EXPECT_EQ("http://www.reuters.com/article/idUSN0839880620100708", 604 EXPECT_EQ("http://www.reuters.com/article/idUSN0839880620100708",
598 matches[0].url_info.url().spec()); 605 matches[0].url_info.url().spec());
599 EXPECT_EQ(ASCIIToUTF16( 606 EXPECT_EQ(ASCIIToUTF16(
600 "UPDATE 1-US 30-yr mortgage rate drops to new record low | Reuters"), 607 "UPDATE 1-US 30-yr mortgage rate drops to new record low | Reuters"),
601 matches[0].url_info.title()); 608 matches[0].url_info.title());
602 } 609 }
603 610
604 TEST_F(InMemoryURLIndexTest, URLPrefixMatching) { 611 TEST_F(InMemoryURLIndexTest, URLPrefixMatching) {
605 // "drudgere" - found, can inline 612 // "drudgere" - found, can inline
606 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( 613 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(
607 ASCIIToUTF16("drudgere"), base::string16::npos, kMaxMatches); 614 ASCIIToUTF16("drudgere"), base::string16::npos, kMaxMatches, builder_);
608 ASSERT_EQ(1U, matches.size()); 615 ASSERT_EQ(1U, matches.size());
609 EXPECT_TRUE(matches[0].can_inline()); 616 EXPECT_TRUE(matches[0].can_inline);
610 617
611 // "drudgere" - found, can inline 618 // "drudgere" - found, can inline
612 matches = url_index_->HistoryItemsForTerms( 619 matches = url_index_->HistoryItemsForTerms(
613 ASCIIToUTF16("drudgere"), base::string16::npos, kMaxMatches); 620 ASCIIToUTF16("drudgere"), base::string16::npos, kMaxMatches, builder_);
614 ASSERT_EQ(1U, matches.size()); 621 ASSERT_EQ(1U, matches.size());
615 EXPECT_TRUE(matches[0].can_inline()); 622 EXPECT_TRUE(matches[0].can_inline);
616 623
617 // "www.atdmt" - not found 624 // "www.atdmt" - not found
618 matches = url_index_->HistoryItemsForTerms( 625 matches = url_index_->HistoryItemsForTerms(
619 ASCIIToUTF16("www.atdmt"), base::string16::npos, kMaxMatches); 626 ASCIIToUTF16("www.atdmt"), base::string16::npos, kMaxMatches, builder_);
620 EXPECT_EQ(0U, matches.size()); 627 EXPECT_EQ(0U, matches.size());
621 628
622 // "atdmt" - found, cannot inline 629 // "atdmt" - found, cannot inline
623 matches = url_index_->HistoryItemsForTerms( 630 matches = url_index_->HistoryItemsForTerms(
624 ASCIIToUTF16("atdmt"), base::string16::npos, kMaxMatches); 631 ASCIIToUTF16("atdmt"), base::string16::npos, kMaxMatches, builder_);
625 ASSERT_EQ(1U, matches.size()); 632 ASSERT_EQ(1U, matches.size());
626 EXPECT_FALSE(matches[0].can_inline()); 633 EXPECT_FALSE(matches[0].can_inline);
627 634
628 // "view.atdmt" - found, can inline 635 // "view.atdmt" - found, can inline
629 matches = url_index_->HistoryItemsForTerms( 636 matches = url_index_->HistoryItemsForTerms(
630 ASCIIToUTF16("view.atdmt"), base::string16::npos, kMaxMatches); 637 ASCIIToUTF16("view.atdmt"), base::string16::npos, kMaxMatches, builder_);
631 ASSERT_EQ(1U, matches.size()); 638 ASSERT_EQ(1U, matches.size());
632 EXPECT_TRUE(matches[0].can_inline()); 639 EXPECT_TRUE(matches[0].can_inline);
633 640
634 // "view.atdmt" - found, can inline 641 // "view.atdmt" - found, can inline
635 matches = url_index_->HistoryItemsForTerms( 642 matches = url_index_->HistoryItemsForTerms(
636 ASCIIToUTF16("view.atdmt"), base::string16::npos, kMaxMatches); 643 ASCIIToUTF16("view.atdmt"), base::string16::npos, kMaxMatches, builder_);
637 ASSERT_EQ(1U, matches.size()); 644 ASSERT_EQ(1U, matches.size());
638 EXPECT_TRUE(matches[0].can_inline()); 645 EXPECT_TRUE(matches[0].can_inline);
639 646
640 // "cnn.com" - found, can inline 647 // "cnn.com" - found, can inline
641 matches = url_index_->HistoryItemsForTerms( 648 matches = url_index_->HistoryItemsForTerms(
642 ASCIIToUTF16("cnn.com"), base::string16::npos, kMaxMatches); 649 ASCIIToUTF16("cnn.com"), base::string16::npos, kMaxMatches, builder_);
643 ASSERT_EQ(2U, matches.size()); 650 ASSERT_EQ(2U, matches.size());
644 // One match should be inline-able, the other not. 651 // One match should be inline-able, the other not.
645 EXPECT_TRUE(matches[0].can_inline() != matches[1].can_inline()); 652 EXPECT_TRUE(matches[0].can_inline != matches[1].can_inline);
646 653
647 // "www.cnn.com" - found, can inline 654 // "www.cnn.com" - found, can inline
648 matches = url_index_->HistoryItemsForTerms( 655 matches = url_index_->HistoryItemsForTerms(
649 ASCIIToUTF16("www.cnn.com"), base::string16::npos, kMaxMatches); 656 ASCIIToUTF16("www.cnn.com"), base::string16::npos, kMaxMatches, builder_);
650 ASSERT_EQ(1U, matches.size()); 657 ASSERT_EQ(1U, matches.size());
651 EXPECT_TRUE(matches[0].can_inline()); 658 EXPECT_TRUE(matches[0].can_inline);
652 659
653 // "ww.cnn.com" - found because we allow mid-term matches in hostnames 660 // "ww.cnn.com" - found because we allow mid-term matches in hostnames
654 matches = url_index_->HistoryItemsForTerms( 661 matches = url_index_->HistoryItemsForTerms(
655 ASCIIToUTF16("ww.cnn.com"), base::string16::npos, kMaxMatches); 662 ASCIIToUTF16("ww.cnn.com"), base::string16::npos, kMaxMatches, builder_);
656 ASSERT_EQ(1U, matches.size()); 663 ASSERT_EQ(1U, matches.size());
657 664
658 // "www.cnn.com" - found, can inline 665 // "www.cnn.com" - found, can inline
659 matches = url_index_->HistoryItemsForTerms( 666 matches = url_index_->HistoryItemsForTerms(
660 ASCIIToUTF16("www.cnn.com"), base::string16::npos, kMaxMatches); 667 ASCIIToUTF16("www.cnn.com"), base::string16::npos, kMaxMatches, builder_);
661 ASSERT_EQ(1U, matches.size()); 668 ASSERT_EQ(1U, matches.size());
662 EXPECT_TRUE(matches[0].can_inline()); 669 EXPECT_TRUE(matches[0].can_inline);
663 670
664 // "tp://www.cnn.com" - not found because we don't allow tp as a mid-term 671 // "tp://www.cnn.com" - not found because we don't allow tp as a mid-term
665 // match 672 // match
666 matches = url_index_->HistoryItemsForTerms( 673 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("tp://www.cnn.com"),
667 ASCIIToUTF16("tp://www.cnn.com"), base::string16::npos, kMaxMatches); 674 base::string16::npos, kMaxMatches,
675 builder_);
668 ASSERT_EQ(0U, matches.size()); 676 ASSERT_EQ(0U, matches.size());
669 } 677 }
670 678
671 TEST_F(InMemoryURLIndexTest, ProperStringMatching) { 679 TEST_F(InMemoryURLIndexTest, ProperStringMatching) {
672 // Search for the following with the expected results: 680 // Search for the following with the expected results:
673 // "atdmt view" - found 681 // "atdmt view" - found
674 // "atdmt.view" - not found 682 // "atdmt.view" - not found
675 // "view.atdmt" - found 683 // "view.atdmt" - found
676 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( 684 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(
677 ASCIIToUTF16("atdmt view"), base::string16::npos, kMaxMatches); 685 ASCIIToUTF16("atdmt view"), base::string16::npos, kMaxMatches, builder_);
678 ASSERT_EQ(1U, matches.size()); 686 ASSERT_EQ(1U, matches.size());
679 matches = url_index_->HistoryItemsForTerms( 687 matches = url_index_->HistoryItemsForTerms(
680 ASCIIToUTF16("atdmt.view"), base::string16::npos, kMaxMatches); 688 ASCIIToUTF16("atdmt.view"), base::string16::npos, kMaxMatches, builder_);
681 ASSERT_EQ(0U, matches.size()); 689 ASSERT_EQ(0U, matches.size());
682 matches = url_index_->HistoryItemsForTerms( 690 matches = url_index_->HistoryItemsForTerms(
683 ASCIIToUTF16("view.atdmt"), base::string16::npos, kMaxMatches); 691 ASCIIToUTF16("view.atdmt"), base::string16::npos, kMaxMatches, builder_);
684 ASSERT_EQ(1U, matches.size()); 692 ASSERT_EQ(1U, matches.size());
685 } 693 }
686 694
687 TEST_F(InMemoryURLIndexTest, HugeResultSet) { 695 TEST_F(InMemoryURLIndexTest, HugeResultSet) {
688 // Create a huge set of qualifying history items. 696 // Create a huge set of qualifying history items.
689 for (URLID row_id = 5000; row_id < 6000; ++row_id) { 697 for (URLID row_id = 5000; row_id < 6000; ++row_id) {
690 URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), row_id); 698 URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), row_id);
691 new_row.set_last_visit(base::Time::Now()); 699 new_row.set_last_visit(base::Time::Now());
692 EXPECT_TRUE(UpdateURL(new_row)); 700 EXPECT_TRUE(UpdateURL(new_row));
693 } 701 }
694 702
695 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( 703 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(
696 ASCIIToUTF16("b"), base::string16::npos, kMaxMatches); 704 ASCIIToUTF16("b"), base::string16::npos, kMaxMatches, builder_);
697 URLIndexPrivateData& private_data(*GetPrivateData()); 705 URLIndexPrivateData& private_data(*GetPrivateData());
698 ASSERT_EQ(kMaxMatches, matches.size()); 706 ASSERT_EQ(kMaxMatches, matches.size());
699 // There are 7 matches already in the database. 707 // There are 7 matches already in the database.
700 ASSERT_EQ(1008U, private_data.pre_filter_item_count_); 708 ASSERT_EQ(1008U, private_data.pre_filter_item_count_);
701 ASSERT_EQ(500U, private_data.post_filter_item_count_); 709 ASSERT_EQ(500U, private_data.post_filter_item_count_);
702 ASSERT_EQ(kMaxMatches, private_data.post_scoring_item_count_); 710 ASSERT_EQ(kMaxMatches, private_data.post_scoring_item_count_);
703 } 711 }
704 712
705 #if defined(OS_WIN) 713 #if defined(OS_WIN)
706 // Flaky on windows trybots: http://crbug.com/351500 714 // Flaky on windows trybots: http://crbug.com/351500
707 #define MAYBE_TitleSearch DISABLED_TitleSearch 715 #define MAYBE_TitleSearch DISABLED_TitleSearch
708 #else 716 #else
709 #define MAYBE_TitleSearch TitleSearch 717 #define MAYBE_TitleSearch TitleSearch
710 #endif 718 #endif
711 TEST_F(InMemoryURLIndexTest, MAYBE_TitleSearch) { 719 TEST_F(InMemoryURLIndexTest, MAYBE_TitleSearch) {
712 // Signal if someone has changed the test DB. 720 // Signal if someone has changed the test DB.
713 EXPECT_EQ(29U, GetPrivateData()->history_info_map_.size()); 721 EXPECT_EQ(29U, GetPrivateData()->history_info_map_.size());
714 722
715 // Ensure title is being searched. 723 // Ensure title is being searched.
716 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( 724 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(
717 ASCIIToUTF16("MORTGAGE RATE DROPS"), base::string16::npos, kMaxMatches); 725 ASCIIToUTF16("MORTGAGE RATE DROPS"), base::string16::npos, kMaxMatches,
726 builder_);
718 ASSERT_EQ(1U, matches.size()); 727 ASSERT_EQ(1U, matches.size());
719 728
720 // Verify that we got back the result we expected. 729 // Verify that we got back the result we expected.
721 EXPECT_EQ(1, matches[0].url_info.id()); 730 EXPECT_EQ(1, matches[0].url_info.id());
722 EXPECT_EQ("http://www.reuters.com/article/idUSN0839880620100708", 731 EXPECT_EQ("http://www.reuters.com/article/idUSN0839880620100708",
723 matches[0].url_info.url().spec()); 732 matches[0].url_info.url().spec());
724 EXPECT_EQ(ASCIIToUTF16( 733 EXPECT_EQ(ASCIIToUTF16(
725 "UPDATE 1-US 30-yr mortgage rate drops to new record low | Reuters"), 734 "UPDATE 1-US 30-yr mortgage rate drops to new record low | Reuters"),
726 matches[0].url_info.title()); 735 matches[0].url_info.title());
727 } 736 }
728 737
729 TEST_F(InMemoryURLIndexTest, TitleChange) { 738 TEST_F(InMemoryURLIndexTest, TitleChange) {
730 // Verify current title terms retrieves desired item. 739 // Verify current title terms retrieves desired item.
731 base::string16 original_terms = 740 base::string16 original_terms =
732 ASCIIToUTF16("lebronomics could high taxes influence"); 741 ASCIIToUTF16("lebronomics could high taxes influence");
733 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( 742 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(
734 original_terms, base::string16::npos, kMaxMatches); 743 original_terms, base::string16::npos, kMaxMatches, builder_);
735 ASSERT_EQ(1U, matches.size()); 744 ASSERT_EQ(1U, matches.size());
736 745
737 // Verify that we got back the result we expected. 746 // Verify that we got back the result we expected.
738 const URLID expected_id = 3; 747 const URLID expected_id = 3;
739 EXPECT_EQ(expected_id, matches[0].url_info.id()); 748 EXPECT_EQ(expected_id, matches[0].url_info.id());
740 EXPECT_EQ("http://www.businessandmedia.org/articles/2010/20100708120415.aspx", 749 EXPECT_EQ("http://www.businessandmedia.org/articles/2010/20100708120415.aspx",
741 matches[0].url_info.url().spec()); 750 matches[0].url_info.url().spec());
742 EXPECT_EQ(ASCIIToUTF16( 751 EXPECT_EQ(ASCIIToUTF16(
743 "LeBronomics: Could High Taxes Influence James' Team Decision?"), 752 "LeBronomics: Could High Taxes Influence James' Team Decision?"),
744 matches[0].url_info.title()); 753 matches[0].url_info.title());
745 URLRow old_row(matches[0].url_info); 754 URLRow old_row(matches[0].url_info);
746 755
747 // Verify new title terms retrieves nothing. 756 // Verify new title terms retrieves nothing.
748 base::string16 new_terms = ASCIIToUTF16("does eat oats little lambs ivy"); 757 base::string16 new_terms = ASCIIToUTF16("does eat oats little lambs ivy");
749 matches = url_index_->HistoryItemsForTerms( 758 matches = url_index_->HistoryItemsForTerms(new_terms, base::string16::npos,
750 new_terms, base::string16::npos, kMaxMatches); 759 kMaxMatches, builder_);
751 ASSERT_EQ(0U, matches.size()); 760 ASSERT_EQ(0U, matches.size());
752 761
753 // Update the row. 762 // Update the row.
754 old_row.set_title(ASCIIToUTF16("Does eat oats and little lambs eat ivy")); 763 old_row.set_title(ASCIIToUTF16("Does eat oats and little lambs eat ivy"));
755 EXPECT_TRUE(UpdateURL(old_row)); 764 EXPECT_TRUE(UpdateURL(old_row));
756 765
757 // Verify we get the row using the new terms but not the original terms. 766 // Verify we get the row using the new terms but not the original terms.
758 matches = url_index_->HistoryItemsForTerms( 767 matches = url_index_->HistoryItemsForTerms(new_terms, base::string16::npos,
759 new_terms, base::string16::npos, kMaxMatches); 768 kMaxMatches, builder_);
760 ASSERT_EQ(1U, matches.size()); 769 ASSERT_EQ(1U, matches.size());
761 EXPECT_EQ(expected_id, matches[0].url_info.id()); 770 EXPECT_EQ(expected_id, matches[0].url_info.id());
762 matches = url_index_->HistoryItemsForTerms( 771 matches = url_index_->HistoryItemsForTerms(
763 original_terms, base::string16::npos, kMaxMatches); 772 original_terms, base::string16::npos, kMaxMatches, builder_);
764 ASSERT_EQ(0U, matches.size()); 773 ASSERT_EQ(0U, matches.size());
765 } 774 }
766 775
767 TEST_F(InMemoryURLIndexTest, NonUniqueTermCharacterSets) { 776 TEST_F(InMemoryURLIndexTest, NonUniqueTermCharacterSets) {
768 // The presence of duplicate characters should succeed. Exercise by cycling 777 // The presence of duplicate characters should succeed. Exercise by cycling
769 // through a string with several duplicate characters. 778 // through a string with several duplicate characters.
770 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( 779 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(
771 ASCIIToUTF16("ABRA"), base::string16::npos, kMaxMatches); 780 ASCIIToUTF16("ABRA"), base::string16::npos, kMaxMatches, builder_);
772 ASSERT_EQ(1U, matches.size()); 781 ASSERT_EQ(1U, matches.size());
773 EXPECT_EQ(28, matches[0].url_info.id()); 782 EXPECT_EQ(28, matches[0].url_info.id());
774 EXPECT_EQ("http://www.ddj.com/windows/184416623", 783 EXPECT_EQ("http://www.ddj.com/windows/184416623",
775 matches[0].url_info.url().spec()); 784 matches[0].url_info.url().spec());
776 785
777 matches = url_index_->HistoryItemsForTerms( 786 matches = url_index_->HistoryItemsForTerms(
778 ASCIIToUTF16("ABRACAD"), base::string16::npos, kMaxMatches); 787 ASCIIToUTF16("ABRACAD"), base::string16::npos, kMaxMatches, builder_);
779 ASSERT_EQ(1U, matches.size()); 788 ASSERT_EQ(1U, matches.size());
780 EXPECT_EQ(28, matches[0].url_info.id()); 789 EXPECT_EQ(28, matches[0].url_info.id());
781 790
782 matches = url_index_->HistoryItemsForTerms( 791 matches = url_index_->HistoryItemsForTerms(
783 ASCIIToUTF16("ABRACADABRA"), base::string16::npos, kMaxMatches); 792 ASCIIToUTF16("ABRACADABRA"), base::string16::npos, kMaxMatches, builder_);
784 ASSERT_EQ(1U, matches.size()); 793 ASSERT_EQ(1U, matches.size());
785 EXPECT_EQ(28, matches[0].url_info.id()); 794 EXPECT_EQ(28, matches[0].url_info.id());
786 795
787 matches = url_index_->HistoryItemsForTerms( 796 matches = url_index_->HistoryItemsForTerms(
788 ASCIIToUTF16("ABRACADABR"), base::string16::npos, kMaxMatches); 797 ASCIIToUTF16("ABRACADABR"), base::string16::npos, kMaxMatches, builder_);
789 ASSERT_EQ(1U, matches.size()); 798 ASSERT_EQ(1U, matches.size());
790 EXPECT_EQ(28, matches[0].url_info.id()); 799 EXPECT_EQ(28, matches[0].url_info.id());
791 800
792 matches = url_index_->HistoryItemsForTerms( 801 matches = url_index_->HistoryItemsForTerms(
793 ASCIIToUTF16("ABRACA"), base::string16::npos, kMaxMatches); 802 ASCIIToUTF16("ABRACA"), base::string16::npos, kMaxMatches, builder_);
794 ASSERT_EQ(1U, matches.size()); 803 ASSERT_EQ(1U, matches.size());
795 EXPECT_EQ(28, matches[0].url_info.id()); 804 EXPECT_EQ(28, matches[0].url_info.id());
796 } 805 }
797 806
798 TEST_F(InMemoryURLIndexTest, TypedCharacterCaching) { 807 TEST_F(InMemoryURLIndexTest, TypedCharacterCaching) {
799 // Verify that match results for previously typed characters are retained 808 // Verify that match results for previously typed characters are retained
800 // (in the term_char_word_set_cache_) and reused, if possible, in future 809 // (in the term_char_word_set_cache_) and reused, if possible, in future
801 // autocompletes. 810 // autocompletes.
802 811
803 URLIndexPrivateData::SearchTermCacheMap& cache( 812 URLIndexPrivateData::SearchTermCacheMap& cache(
804 GetPrivateData()->search_term_cache_); 813 GetPrivateData()->search_term_cache_);
805 814
806 // The cache should be empty at this point. 815 // The cache should be empty at this point.
807 EXPECT_EQ(0U, cache.size()); 816 EXPECT_EQ(0U, cache.size());
808 817
809 // Now simulate typing search terms into the omnibox and check the state of 818 // Now simulate typing search terms into the omnibox and check the state of
810 // the cache as each item is 'typed'. 819 // the cache as each item is 'typed'.
811 820
812 // Simulate typing "r" giving "r" in the simulated omnibox. The results for 821 // Simulate typing "r" giving "r" in the simulated omnibox. The results for
813 // 'r' will be not cached because it is only 1 character long. 822 // 'r' will be not cached because it is only 1 character long.
814 url_index_->HistoryItemsForTerms( 823 url_index_->HistoryItemsForTerms(ASCIIToUTF16("r"), base::string16::npos,
815 ASCIIToUTF16("r"), base::string16::npos, kMaxMatches); 824 kMaxMatches, builder_);
816 EXPECT_EQ(0U, cache.size()); 825 EXPECT_EQ(0U, cache.size());
817 826
818 // Simulate typing "re" giving "r re" in the simulated omnibox. 827 // Simulate typing "re" giving "r re" in the simulated omnibox.
819 // 're' should be cached at this point but not 'r' as it is a single 828 // 're' should be cached at this point but not 'r' as it is a single
820 // character. 829 // character.
821 url_index_->HistoryItemsForTerms( 830 url_index_->HistoryItemsForTerms(ASCIIToUTF16("r re"), base::string16::npos,
822 ASCIIToUTF16("r re"), base::string16::npos, kMaxMatches); 831 kMaxMatches, builder_);
823 ASSERT_EQ(1U, cache.size()); 832 ASSERT_EQ(1U, cache.size());
824 CheckTerm(cache, ASCIIToUTF16("re")); 833 CheckTerm(cache, ASCIIToUTF16("re"));
825 834
826 // Simulate typing "reco" giving "r re reco" in the simulated omnibox. 835 // Simulate typing "reco" giving "r re reco" in the simulated omnibox.
827 // 're' and 'reco' should be cached at this point but not 'r' as it is a 836 // 're' and 'reco' should be cached at this point but not 'r' as it is a
828 // single character. 837 // single character.
829 url_index_->HistoryItemsForTerms( 838 url_index_->HistoryItemsForTerms(ASCIIToUTF16("r re reco"),
830 ASCIIToUTF16("r re reco"), base::string16::npos, kMaxMatches); 839 base::string16::npos, kMaxMatches, builder_);
831 ASSERT_EQ(2U, cache.size()); 840 ASSERT_EQ(2U, cache.size());
832 CheckTerm(cache, ASCIIToUTF16("re")); 841 CheckTerm(cache, ASCIIToUTF16("re"));
833 CheckTerm(cache, ASCIIToUTF16("reco")); 842 CheckTerm(cache, ASCIIToUTF16("reco"));
834 843
835 // Simulate typing "mort". 844 // Simulate typing "mort".
836 // Since we now have only one search term, the cached results for 're' and 845 // Since we now have only one search term, the cached results for 're' and
837 // 'reco' should be purged, giving us only 1 item in the cache (for 'mort'). 846 // 'reco' should be purged, giving us only 1 item in the cache (for 'mort').
838 url_index_->HistoryItemsForTerms( 847 url_index_->HistoryItemsForTerms(ASCIIToUTF16("mort"), base::string16::npos,
839 ASCIIToUTF16("mort"), base::string16::npos, kMaxMatches); 848 kMaxMatches, builder_);
840 ASSERT_EQ(1U, cache.size()); 849 ASSERT_EQ(1U, cache.size());
841 CheckTerm(cache, ASCIIToUTF16("mort")); 850 CheckTerm(cache, ASCIIToUTF16("mort"));
842 851
843 // Simulate typing "reco" giving "mort reco" in the simulated omnibox. 852 // Simulate typing "reco" giving "mort reco" in the simulated omnibox.
844 url_index_->HistoryItemsForTerms( 853 url_index_->HistoryItemsForTerms(ASCIIToUTF16("mort reco"),
845 ASCIIToUTF16("mort reco"), base::string16::npos, kMaxMatches); 854 base::string16::npos, kMaxMatches, builder_);
846 ASSERT_EQ(2U, cache.size()); 855 ASSERT_EQ(2U, cache.size());
847 CheckTerm(cache, ASCIIToUTF16("mort")); 856 CheckTerm(cache, ASCIIToUTF16("mort"));
848 CheckTerm(cache, ASCIIToUTF16("reco")); 857 CheckTerm(cache, ASCIIToUTF16("reco"));
849 858
850 // Simulate a <DELETE> by removing the 'reco' and adding back the 'rec'. 859 // Simulate a <DELETE> by removing the 'reco' and adding back the 'rec'.
851 url_index_->HistoryItemsForTerms( 860 url_index_->HistoryItemsForTerms(ASCIIToUTF16("mort rec"),
852 ASCIIToUTF16("mort rec"), base::string16::npos, kMaxMatches); 861 base::string16::npos, kMaxMatches, builder_);
853 ASSERT_EQ(2U, cache.size()); 862 ASSERT_EQ(2U, cache.size());
854 CheckTerm(cache, ASCIIToUTF16("mort")); 863 CheckTerm(cache, ASCIIToUTF16("mort"));
855 CheckTerm(cache, ASCIIToUTF16("rec")); 864 CheckTerm(cache, ASCIIToUTF16("rec"));
856 } 865 }
857 866
858 TEST_F(InMemoryURLIndexTest, AddNewRows) { 867 TEST_F(InMemoryURLIndexTest, AddNewRows) {
859 // Verify that the row we're going to add does not already exist. 868 // Verify that the row we're going to add does not already exist.
860 URLID new_row_id = 87654321; 869 URLID new_row_id = 87654321;
861 // Newly created URLRows get a last_visit time of 'right now' so it should 870 // Newly created URLRows get a last_visit time of 'right now' so it should
862 // qualify as a quick result candidate. 871 // qualify as a quick result candidate.
863 EXPECT_TRUE(url_index_->HistoryItemsForTerms( 872 EXPECT_TRUE(url_index_->HistoryItemsForTerms(ASCIIToUTF16("brokeandalone"),
864 ASCIIToUTF16("brokeandalone"), base::string16::npos, kMaxMatches) 873 base::string16::npos,
865 .empty()); 874 kMaxMatches, builder_).empty());
866 875
867 // Add a new row. 876 // Add a new row.
868 URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), new_row_id++); 877 URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), new_row_id++);
869 new_row.set_last_visit(base::Time::Now()); 878 new_row.set_last_visit(base::Time::Now());
870 EXPECT_TRUE(UpdateURL(new_row)); 879 EXPECT_TRUE(UpdateURL(new_row));
871 880
872 // Verify that we can retrieve it. 881 // Verify that we can retrieve it.
873 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms( 882 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms(ASCIIToUTF16("brokeandalone"),
874 ASCIIToUTF16("brokeandalone"), base::string16::npos, kMaxMatches).size()); 883 base::string16::npos,
884 kMaxMatches, builder_).size());
875 885
876 // Add it again just to be sure that is harmless and that it does not update 886 // Add it again just to be sure that is harmless and that it does not update
877 // the index. 887 // the index.
878 EXPECT_FALSE(UpdateURL(new_row)); 888 EXPECT_FALSE(UpdateURL(new_row));
879 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms( 889 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms(ASCIIToUTF16("brokeandalone"),
880 ASCIIToUTF16("brokeandalone"), base::string16::npos, kMaxMatches).size()); 890 base::string16::npos,
891 kMaxMatches, builder_).size());
881 892
882 // Make up an URL that does not qualify and try to add it. 893 // Make up an URL that does not qualify and try to add it.
883 URLRow unqualified_row(GURL("http://www.brokeandaloneinmanitoba.com/"), 894 URLRow unqualified_row(GURL("http://www.brokeandaloneinmanitoba.com/"),
884 new_row_id++); 895 new_row_id++);
885 EXPECT_FALSE(UpdateURL(new_row)); 896 EXPECT_FALSE(UpdateURL(new_row));
886 } 897 }
887 898
888 TEST_F(InMemoryURLIndexTest, DeleteRows) { 899 TEST_F(InMemoryURLIndexTest, DeleteRows) {
889 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( 900 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(
890 ASCIIToUTF16("DrudgeReport"), base::string16::npos, kMaxMatches); 901 ASCIIToUTF16("DrudgeReport"), base::string16::npos, kMaxMatches,
902 builder_);
891 ASSERT_EQ(1U, matches.size()); 903 ASSERT_EQ(1U, matches.size());
892 904
893 // Delete the URL then search again. 905 // Delete the URL then search again.
894 EXPECT_TRUE(DeleteURL(matches[0].url_info.url())); 906 EXPECT_TRUE(DeleteURL(matches[0].url_info.url()));
895 EXPECT_TRUE(url_index_->HistoryItemsForTerms( 907 EXPECT_TRUE(url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudgeReport"),
896 ASCIIToUTF16("DrudgeReport"), base::string16::npos, kMaxMatches).empty()); 908 base::string16::npos,
909 kMaxMatches, builder_).empty());
897 910
898 // Make up an URL that does not exist in the database and delete it. 911 // Make up an URL that does not exist in the database and delete it.
899 GURL url("http://www.hokeypokey.com/putyourrightfootin.html"); 912 GURL url("http://www.hokeypokey.com/putyourrightfootin.html");
900 EXPECT_FALSE(DeleteURL(url)); 913 EXPECT_FALSE(DeleteURL(url));
901 } 914 }
902 915
903 TEST_F(InMemoryURLIndexTest, ExpireRow) { 916 TEST_F(InMemoryURLIndexTest, ExpireRow) {
904 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( 917 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(
905 ASCIIToUTF16("DrudgeReport"), base::string16::npos, kMaxMatches); 918 ASCIIToUTF16("DrudgeReport"), base::string16::npos, kMaxMatches,
919 builder_);
906 ASSERT_EQ(1U, matches.size()); 920 ASSERT_EQ(1U, matches.size());
907 921
908 // Determine the row id for the result, remember that id, broadcast a 922 // Determine the row id for the result, remember that id, broadcast a
909 // delete notification, then ensure that the row has been deleted. 923 // delete notification, then ensure that the row has been deleted.
910 URLRows deleted_rows; 924 URLRows deleted_rows;
911 deleted_rows.push_back(matches[0].url_info); 925 deleted_rows.push_back(matches[0].url_info);
912 url_index_->OnURLsDeleted(nullptr, false, false, deleted_rows, 926 url_index_->OnURLsDeleted(nullptr, false, false, deleted_rows,
913 std::set<GURL>()); 927 std::set<GURL>());
914 EXPECT_TRUE(url_index_->HistoryItemsForTerms( 928 EXPECT_TRUE(url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudgeReport"),
915 ASCIIToUTF16("DrudgeReport"), base::string16::npos, kMaxMatches).empty()); 929 base::string16::npos,
930 kMaxMatches, builder_).empty());
916 } 931 }
917 932
918 TEST_F(InMemoryURLIndexTest, WhitelistedURLs) { 933 TEST_F(InMemoryURLIndexTest, WhitelistedURLs) {
919 struct TestData { 934 struct TestData {
920 const std::string url_spec; 935 const std::string url_spec;
921 const bool expected_is_whitelisted; 936 const bool expected_is_whitelisted;
922 } data[] = { 937 } data[] = {
923 // URLs with whitelisted schemes. 938 // URLs with whitelisted schemes.
924 { "about:histograms", true }, 939 { "about:histograms", true },
925 { "chrome://settings", true }, 940 { "chrome://settings", true },
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 void set_history_dir(const base::FilePath& dir_path); 1216 void set_history_dir(const base::FilePath& dir_path);
1202 bool GetCacheFilePath(base::FilePath* file_path) const; 1217 bool GetCacheFilePath(base::FilePath* file_path) const;
1203 1218
1204 base::ScopedTempDir temp_dir_; 1219 base::ScopedTempDir temp_dir_;
1205 scoped_ptr<InMemoryURLIndex> url_index_; 1220 scoped_ptr<InMemoryURLIndex> url_index_;
1206 }; 1221 };
1207 1222
1208 void InMemoryURLIndexCacheTest::SetUp() { 1223 void InMemoryURLIndexCacheTest::SetUp() {
1209 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 1224 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
1210 base::FilePath path(temp_dir_.path()); 1225 base::FilePath path(temp_dir_.path());
1211 url_index_.reset( 1226 url_index_.reset(new InMemoryURLIndex(nullptr, path, kTestLanguages));
1212 new InMemoryURLIndex(nullptr, path, kTestLanguages, nullptr));
1213 } 1227 }
1214 1228
1215 void InMemoryURLIndexCacheTest::TearDown() { 1229 void InMemoryURLIndexCacheTest::TearDown() {
1216 if (url_index_) 1230 if (url_index_)
1217 url_index_->ShutDown(); 1231 url_index_->ShutDown();
1218 } 1232 }
1219 1233
1220 void InMemoryURLIndexCacheTest::set_history_dir( 1234 void InMemoryURLIndexCacheTest::set_history_dir(
1221 const base::FilePath& dir_path) { 1235 const base::FilePath& dir_path) {
1222 return url_index_->set_history_dir(dir_path); 1236 return url_index_->set_history_dir(dir_path);
(...skipping 16 matching lines...) Expand all
1239 full_file_path.GetComponents(&actual_parts); 1253 full_file_path.GetComponents(&actual_parts);
1240 ASSERT_EQ(expected_parts.size(), actual_parts.size()); 1254 ASSERT_EQ(expected_parts.size(), actual_parts.size());
1241 size_t count = expected_parts.size(); 1255 size_t count = expected_parts.size();
1242 for (size_t i = 0; i < count; ++i) 1256 for (size_t i = 0; i < count; ++i)
1243 EXPECT_EQ(expected_parts[i], actual_parts[i]); 1257 EXPECT_EQ(expected_parts[i], actual_parts[i]);
1244 // Must clear the history_dir_ to satisfy the dtor's DCHECK. 1258 // Must clear the history_dir_ to satisfy the dtor's DCHECK.
1245 set_history_dir(base::FilePath()); 1259 set_history_dir(base::FilePath());
1246 } 1260 }
1247 1261
1248 } // namespace history 1262 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698