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