| 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" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 // 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'). |
| 38 // 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 |
| 39 // 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 |
| 40 // 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 |
| 41 // absolute time should be set during the test setup stage. | 41 // absolute time should be set during the test setup stage. |
| 42 // | 42 // |
| 43 // 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. |
| 44 // 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 |
| 45 // processed when creating the test database. | 45 // processed when creating the test database. |
| 46 | 46 |
| 47 namespace history { | |
| 48 namespace { | 47 namespace { |
| 49 const size_t kMaxMatches = 3; | 48 const size_t kMaxMatches = 3; |
| 50 const char kTestLanguages[] = "en,ja,hi,zh"; | 49 const char kTestLanguages[] = "en,ja,hi,zh"; |
| 51 } // namespace | 50 } // namespace |
| 52 | 51 |
| 53 // ----------------------------------------------------------------------------- | 52 // ----------------------------------------------------------------------------- |
| 54 | 53 |
| 55 // Observer class so the unit tests can wait while the cache is being saved. | 54 // Observer class so the unit tests can wait while the cache is being saved. |
| 56 class CacheFileSaverObserver : public InMemoryURLIndex::SaveCacheObserver { | 55 class CacheFileSaverObserver : public InMemoryURLIndex::SaveCacheObserver { |
| 57 public: | 56 public: |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 base::CancelableTaskTracker* GetPrivateDataTracker() const; | 112 base::CancelableTaskTracker* GetPrivateDataTracker() const; |
| 114 void ClearPrivateData(); | 113 void ClearPrivateData(); |
| 115 void set_history_dir(const base::FilePath& dir_path); | 114 void set_history_dir(const base::FilePath& dir_path); |
| 116 bool GetCacheFilePath(base::FilePath* file_path) const; | 115 bool GetCacheFilePath(base::FilePath* file_path) const; |
| 117 void PostRestoreFromCacheFileTask(); | 116 void PostRestoreFromCacheFileTask(); |
| 118 void PostSaveToCacheFileTask(); | 117 void PostSaveToCacheFileTask(); |
| 119 const std::set<std::string>& scheme_whitelist(); | 118 const std::set<std::string>& scheme_whitelist(); |
| 120 | 119 |
| 121 | 120 |
| 122 // Pass-through functions to simplify our friendship with URLIndexPrivateData. | 121 // Pass-through functions to simplify our friendship with URLIndexPrivateData. |
| 123 bool UpdateURL(const URLRow& row); | 122 bool UpdateURL(const history::URLRow& row); |
| 124 bool DeleteURL(const GURL& url); | 123 bool DeleteURL(const GURL& url); |
| 125 | 124 |
| 126 // Data verification helper functions. | 125 // Data verification helper functions. |
| 127 void ExpectPrivateDataNotEmpty(const URLIndexPrivateData& data); | 126 void ExpectPrivateDataNotEmpty(const URLIndexPrivateData& data); |
| 128 void ExpectPrivateDataEmpty(const URLIndexPrivateData& data); | 127 void ExpectPrivateDataEmpty(const URLIndexPrivateData& data); |
| 129 void ExpectPrivateDataEqual(const URLIndexPrivateData& expected, | 128 void ExpectPrivateDataEqual(const URLIndexPrivateData& expected, |
| 130 const URLIndexPrivateData& actual); | 129 const URLIndexPrivateData& actual); |
| 131 | 130 |
| 132 ScoredHistoryMatchBuilderImpl builder_; | 131 ScoredHistoryMatchBuilderImpl builder_; |
| 133 content::TestBrowserThreadBundle thread_bundle_; | 132 content::TestBrowserThreadBundle thread_bundle_; |
| 134 scoped_ptr<InMemoryURLIndex> url_index_; | 133 scoped_ptr<InMemoryURLIndex> url_index_; |
| 135 TestingProfile profile_; | 134 TestingProfile profile_; |
| 136 HistoryService* history_service_; | 135 HistoryService* history_service_; |
| 137 HistoryDatabase* history_database_; | 136 history::HistoryDatabase* history_database_; |
| 138 }; | 137 }; |
| 139 | 138 |
| 140 InMemoryURLIndexTest::InMemoryURLIndexTest() | 139 InMemoryURLIndexTest::InMemoryURLIndexTest() |
| 141 : builder_(ScoredHistoryMatchBuilderImpl::IsBookmarkedCallback()), | 140 : builder_(ScoredHistoryMatchBuilderImpl::IsBookmarkedCallback()), |
| 142 history_service_(nullptr), | 141 history_service_(nullptr), |
| 143 history_database_(nullptr) { | 142 history_database_(nullptr) { |
| 144 } | 143 } |
| 145 | 144 |
| 146 sql::Connection& InMemoryURLIndexTest::GetDB() { | 145 sql::Connection& InMemoryURLIndexTest::GetDB() { |
| 147 return history_database_->GetDB(); | 146 return history_database_->GetDB(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 176 } | 175 } |
| 177 | 176 |
| 178 void InMemoryURLIndexTest::PostSaveToCacheFileTask() { | 177 void InMemoryURLIndexTest::PostSaveToCacheFileTask() { |
| 179 url_index_->PostSaveToCacheFileTask(); | 178 url_index_->PostSaveToCacheFileTask(); |
| 180 } | 179 } |
| 181 | 180 |
| 182 const std::set<std::string>& InMemoryURLIndexTest::scheme_whitelist() { | 181 const std::set<std::string>& InMemoryURLIndexTest::scheme_whitelist() { |
| 183 return url_index_->scheme_whitelist(); | 182 return url_index_->scheme_whitelist(); |
| 184 } | 183 } |
| 185 | 184 |
| 186 bool InMemoryURLIndexTest::UpdateURL(const URLRow& row) { | 185 bool InMemoryURLIndexTest::UpdateURL(const history::URLRow& row) { |
| 187 return GetPrivateData()->UpdateURL(history_service_, | 186 return GetPrivateData()->UpdateURL(history_service_, |
| 188 row, | 187 row, |
| 189 url_index_->languages_, | 188 url_index_->languages_, |
| 190 url_index_->scheme_whitelist_, | 189 url_index_->scheme_whitelist_, |
| 191 GetPrivateDataTracker()); | 190 GetPrivateDataTracker()); |
| 192 } | 191 } |
| 193 | 192 |
| 194 bool InMemoryURLIndexTest::DeleteURL(const GURL& url) { | 193 bool InMemoryURLIndexTest::DeleteURL(const GURL& url) { |
| 195 return GetPrivateData()->DeleteURL(url); | 194 return GetPrivateData()->DeleteURL(url); |
| 196 } | 195 } |
| 197 | 196 |
| 198 void InMemoryURLIndexTest::SetUp() { | 197 void InMemoryURLIndexTest::SetUp() { |
| 199 // We cannot access the database until the backend has been loaded. | 198 // We cannot access the database until the backend has been loaded. |
| 200 ASSERT_TRUE(profile_.CreateHistoryService(true, false)); | 199 ASSERT_TRUE(profile_.CreateHistoryService(true, false)); |
| 201 profile_.CreateBookmarkModel(true); | 200 profile_.CreateBookmarkModel(true); |
| 202 bookmarks::test::WaitForBookmarkModelToLoad( | 201 bookmarks::test::WaitForBookmarkModelToLoad( |
| 203 BookmarkModelFactory::GetForProfile(&profile_)); | 202 BookmarkModelFactory::GetForProfile(&profile_)); |
| 204 profile_.BlockUntilHistoryProcessesPendingRequests(); | 203 profile_.BlockUntilHistoryProcessesPendingRequests(); |
| 205 profile_.BlockUntilHistoryIndexIsRefreshed(); | 204 profile_.BlockUntilHistoryIndexIsRefreshed(); |
| 206 history_service_ = HistoryServiceFactory::GetForProfile( | 205 history_service_ = HistoryServiceFactory::GetForProfile( |
| 207 &profile_, ServiceAccessType::EXPLICIT_ACCESS); | 206 &profile_, ServiceAccessType::EXPLICIT_ACCESS); |
| 208 ASSERT_TRUE(history_service_); | 207 ASSERT_TRUE(history_service_); |
| 209 HistoryBackend* backend = history_service_->history_backend_.get(); | 208 history::HistoryBackend* backend = history_service_->history_backend_.get(); |
| 210 history_database_ = backend->db(); | 209 history_database_ = backend->db(); |
| 211 | 210 |
| 212 // Create and populate a working copy of the URL history database. | 211 // Create and populate a working copy of the URL history database. |
| 213 base::FilePath history_proto_path; | 212 base::FilePath history_proto_path; |
| 214 PathService::Get(chrome::DIR_TEST_DATA, &history_proto_path); | 213 PathService::Get(chrome::DIR_TEST_DATA, &history_proto_path); |
| 215 history_proto_path = history_proto_path.Append( | 214 history_proto_path = history_proto_path.Append( |
| 216 FILE_PATH_LITERAL("History")); | 215 FILE_PATH_LITERAL("History")); |
| 217 history_proto_path = history_proto_path.Append(TestDBName()); | 216 history_proto_path = history_proto_path.Append(TestDBName()); |
| 218 EXPECT_TRUE(base::PathExists(history_proto_path)); | 217 EXPECT_TRUE(base::PathExists(history_proto_path)); |
| 219 | 218 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 245 // such that it represents a time relative to 'now'. | 244 // such that it represents a time relative to 'now'. |
| 246 sql::Statement statement(db.GetUniqueStatement( | 245 sql::Statement statement(db.GetUniqueStatement( |
| 247 "SELECT" HISTORY_URL_ROW_FIELDS "FROM urls;")); | 246 "SELECT" HISTORY_URL_ROW_FIELDS "FROM urls;")); |
| 248 ASSERT_TRUE(statement.is_valid()); | 247 ASSERT_TRUE(statement.is_valid()); |
| 249 base::Time time_right_now = base::Time::NowFromSystemTime(); | 248 base::Time time_right_now = base::Time::NowFromSystemTime(); |
| 250 base::TimeDelta day_delta = base::TimeDelta::FromDays(1); | 249 base::TimeDelta day_delta = base::TimeDelta::FromDays(1); |
| 251 { | 250 { |
| 252 sql::Transaction transaction(&db); | 251 sql::Transaction transaction(&db); |
| 253 transaction.Begin(); | 252 transaction.Begin(); |
| 254 while (statement.Step()) { | 253 while (statement.Step()) { |
| 255 URLRow row; | 254 history::URLRow row; |
| 256 history_database_->FillURLRow(statement, &row); | 255 history_database_->FillURLRow(statement, &row); |
| 257 base::Time last_visit = time_right_now; | 256 base::Time last_visit = time_right_now; |
| 258 for (int64 i = row.last_visit().ToInternalValue(); i > 0; --i) | 257 for (int64 i = row.last_visit().ToInternalValue(); i > 0; --i) |
| 259 last_visit -= day_delta; | 258 last_visit -= day_delta; |
| 260 row.set_last_visit(last_visit); | 259 row.set_last_visit(last_visit); |
| 261 history_database_->UpdateURLRow(row.id(), row); | 260 history_database_->UpdateURLRow(row.id(), row); |
| 262 } | 261 } |
| 263 transaction.Commit(); | 262 transaction.Commit(); |
| 264 } | 263 } |
| 265 | 264 |
| 266 // Update the visit_time table column in the "visits" table | 265 // Update the visit_time table column in the "visits" table |
| 267 // such that it represents a time relative to 'now'. | 266 // such that it represents a time relative to 'now'. |
| 268 statement.Assign(db.GetUniqueStatement( | 267 statement.Assign(db.GetUniqueStatement( |
| 269 "SELECT" HISTORY_VISIT_ROW_FIELDS "FROM visits;")); | 268 "SELECT" HISTORY_VISIT_ROW_FIELDS "FROM visits;")); |
| 270 ASSERT_TRUE(statement.is_valid()); | 269 ASSERT_TRUE(statement.is_valid()); |
| 271 { | 270 { |
| 272 sql::Transaction transaction(&db); | 271 sql::Transaction transaction(&db); |
| 273 transaction.Begin(); | 272 transaction.Begin(); |
| 274 while (statement.Step()) { | 273 while (statement.Step()) { |
| 275 VisitRow row; | 274 history::VisitRow row; |
| 276 history_database_->FillVisitRow(statement, &row); | 275 history_database_->FillVisitRow(statement, &row); |
| 277 base::Time last_visit = time_right_now; | 276 base::Time last_visit = time_right_now; |
| 278 for (int64 i = row.visit_time.ToInternalValue(); i > 0; --i) | 277 for (int64 i = row.visit_time.ToInternalValue(); i > 0; --i) |
| 279 last_visit -= day_delta; | 278 last_visit -= day_delta; |
| 280 row.visit_time = last_visit; | 279 row.visit_time = last_visit; |
| 281 history_database_->UpdateVisitRow(row); | 280 history_database_->UpdateVisitRow(row); |
| 282 } | 281 } |
| 283 transaction.Commit(); | 282 transaction.Commit(); |
| 284 } | 283 } |
| 285 | 284 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 | 390 |
| 392 for (HistoryInfoMap::const_iterator expected_info = | 391 for (HistoryInfoMap::const_iterator expected_info = |
| 393 expected.history_info_map_.begin(); | 392 expected.history_info_map_.begin(); |
| 394 expected_info != expected.history_info_map_.end(); ++expected_info) { | 393 expected_info != expected.history_info_map_.end(); ++expected_info) { |
| 395 HistoryInfoMap::const_iterator actual_info = | 394 HistoryInfoMap::const_iterator actual_info = |
| 396 actual.history_info_map_.find(expected_info->first); | 395 actual.history_info_map_.find(expected_info->first); |
| 397 // NOTE(yfriedman): ASSERT_NE can't be used due to incompatibility between | 396 // NOTE(yfriedman): ASSERT_NE can't be used due to incompatibility between |
| 398 // gtest and STLPort in the Android build. See | 397 // gtest and STLPort in the Android build. See |
| 399 // http://code.google.com/p/googletest/issues/detail?id=359 | 398 // http://code.google.com/p/googletest/issues/detail?id=359 |
| 400 ASSERT_TRUE(actual_info != actual.history_info_map_.end()); | 399 ASSERT_TRUE(actual_info != actual.history_info_map_.end()); |
| 401 const URLRow& expected_row(expected_info->second.url_row); | 400 const history::URLRow& expected_row(expected_info->second.url_row); |
| 402 const URLRow& actual_row(actual_info->second.url_row); | 401 const history::URLRow& actual_row(actual_info->second.url_row); |
| 403 EXPECT_EQ(expected_row.visit_count(), actual_row.visit_count()); | 402 EXPECT_EQ(expected_row.visit_count(), actual_row.visit_count()); |
| 404 EXPECT_EQ(expected_row.typed_count(), actual_row.typed_count()); | 403 EXPECT_EQ(expected_row.typed_count(), actual_row.typed_count()); |
| 405 EXPECT_EQ(expected_row.last_visit(), actual_row.last_visit()); | 404 EXPECT_EQ(expected_row.last_visit(), actual_row.last_visit()); |
| 406 EXPECT_EQ(expected_row.url(), actual_row.url()); | 405 EXPECT_EQ(expected_row.url(), actual_row.url()); |
| 407 const VisitInfoVector& expected_visits(expected_info->second.visits); | 406 const VisitInfoVector& expected_visits(expected_info->second.visits); |
| 408 const VisitInfoVector& actual_visits(actual_info->second.visits); | 407 const VisitInfoVector& actual_visits(actual_info->second.visits); |
| 409 EXPECT_EQ(expected_visits.size(), actual_visits.size()); | 408 EXPECT_EQ(expected_visits.size(), actual_visits.size()); |
| 410 for (size_t i = 0; | 409 for (size_t i = 0; |
| 411 i < std::min(expected_visits.size(), actual_visits.size()); ++i) { | 410 i < std::min(expected_visits.size(), actual_visits.size()); ++i) { |
| 412 EXPECT_EQ(expected_visits[i].first, actual_visits[i].first); | 411 EXPECT_EQ(expected_visits[i].first, actual_visits[i].first); |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 matches = url_index_->HistoryItemsForTerms( | 686 matches = url_index_->HistoryItemsForTerms( |
| 688 ASCIIToUTF16("atdmt.view"), base::string16::npos, kMaxMatches, builder_); | 687 ASCIIToUTF16("atdmt.view"), base::string16::npos, kMaxMatches, builder_); |
| 689 ASSERT_EQ(0U, matches.size()); | 688 ASSERT_EQ(0U, matches.size()); |
| 690 matches = url_index_->HistoryItemsForTerms( | 689 matches = url_index_->HistoryItemsForTerms( |
| 691 ASCIIToUTF16("view.atdmt"), base::string16::npos, kMaxMatches, builder_); | 690 ASCIIToUTF16("view.atdmt"), base::string16::npos, kMaxMatches, builder_); |
| 692 ASSERT_EQ(1U, matches.size()); | 691 ASSERT_EQ(1U, matches.size()); |
| 693 } | 692 } |
| 694 | 693 |
| 695 TEST_F(InMemoryURLIndexTest, HugeResultSet) { | 694 TEST_F(InMemoryURLIndexTest, HugeResultSet) { |
| 696 // Create a huge set of qualifying history items. | 695 // Create a huge set of qualifying history items. |
| 697 for (URLID row_id = 5000; row_id < 6000; ++row_id) { | 696 for (history::URLID row_id = 5000; row_id < 6000; ++row_id) { |
| 698 URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), row_id); | 697 history::URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), |
| 698 row_id); |
| 699 new_row.set_last_visit(base::Time::Now()); | 699 new_row.set_last_visit(base::Time::Now()); |
| 700 EXPECT_TRUE(UpdateURL(new_row)); | 700 EXPECT_TRUE(UpdateURL(new_row)); |
| 701 } | 701 } |
| 702 | 702 |
| 703 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( | 703 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( |
| 704 ASCIIToUTF16("b"), base::string16::npos, kMaxMatches, builder_); | 704 ASCIIToUTF16("b"), base::string16::npos, kMaxMatches, builder_); |
| 705 URLIndexPrivateData& private_data(*GetPrivateData()); | 705 URLIndexPrivateData& private_data(*GetPrivateData()); |
| 706 ASSERT_EQ(kMaxMatches, matches.size()); | 706 ASSERT_EQ(kMaxMatches, matches.size()); |
| 707 // There are 7 matches already in the database. | 707 // There are 7 matches already in the database. |
| 708 ASSERT_EQ(1008U, private_data.pre_filter_item_count_); | 708 ASSERT_EQ(1008U, private_data.pre_filter_item_count_); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 737 | 737 |
| 738 TEST_F(InMemoryURLIndexTest, TitleChange) { | 738 TEST_F(InMemoryURLIndexTest, TitleChange) { |
| 739 // Verify current title terms retrieves desired item. | 739 // Verify current title terms retrieves desired item. |
| 740 base::string16 original_terms = | 740 base::string16 original_terms = |
| 741 ASCIIToUTF16("lebronomics could high taxes influence"); | 741 ASCIIToUTF16("lebronomics could high taxes influence"); |
| 742 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( | 742 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( |
| 743 original_terms, base::string16::npos, kMaxMatches, builder_); | 743 original_terms, base::string16::npos, kMaxMatches, builder_); |
| 744 ASSERT_EQ(1U, matches.size()); | 744 ASSERT_EQ(1U, matches.size()); |
| 745 | 745 |
| 746 // Verify that we got back the result we expected. | 746 // Verify that we got back the result we expected. |
| 747 const URLID expected_id = 3; | 747 const history::URLID expected_id = 3; |
| 748 EXPECT_EQ(expected_id, matches[0].url_info.id()); | 748 EXPECT_EQ(expected_id, matches[0].url_info.id()); |
| 749 EXPECT_EQ("http://www.businessandmedia.org/articles/2010/20100708120415.aspx", | 749 EXPECT_EQ("http://www.businessandmedia.org/articles/2010/20100708120415.aspx", |
| 750 matches[0].url_info.url().spec()); | 750 matches[0].url_info.url().spec()); |
| 751 EXPECT_EQ(ASCIIToUTF16( | 751 EXPECT_EQ(ASCIIToUTF16( |
| 752 "LeBronomics: Could High Taxes Influence James' Team Decision?"), | 752 "LeBronomics: Could High Taxes Influence James' Team Decision?"), |
| 753 matches[0].url_info.title()); | 753 matches[0].url_info.title()); |
| 754 URLRow old_row(matches[0].url_info); | 754 history::URLRow old_row(matches[0].url_info); |
| 755 | 755 |
| 756 // Verify new title terms retrieves nothing. | 756 // Verify new title terms retrieves nothing. |
| 757 base::string16 new_terms = ASCIIToUTF16("does eat oats little lambs ivy"); | 757 base::string16 new_terms = ASCIIToUTF16("does eat oats little lambs ivy"); |
| 758 matches = url_index_->HistoryItemsForTerms(new_terms, base::string16::npos, | 758 matches = url_index_->HistoryItemsForTerms(new_terms, base::string16::npos, |
| 759 kMaxMatches, builder_); | 759 kMaxMatches, builder_); |
| 760 ASSERT_EQ(0U, matches.size()); | 760 ASSERT_EQ(0U, matches.size()); |
| 761 | 761 |
| 762 // Update the row. | 762 // Update the row. |
| 763 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")); |
| 764 EXPECT_TRUE(UpdateURL(old_row)); | 764 EXPECT_TRUE(UpdateURL(old_row)); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 // 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'. |
| 860 url_index_->HistoryItemsForTerms(ASCIIToUTF16("mort rec"), | 860 url_index_->HistoryItemsForTerms(ASCIIToUTF16("mort rec"), |
| 861 base::string16::npos, kMaxMatches, builder_); | 861 base::string16::npos, kMaxMatches, builder_); |
| 862 ASSERT_EQ(2U, cache.size()); | 862 ASSERT_EQ(2U, cache.size()); |
| 863 CheckTerm(cache, ASCIIToUTF16("mort")); | 863 CheckTerm(cache, ASCIIToUTF16("mort")); |
| 864 CheckTerm(cache, ASCIIToUTF16("rec")); | 864 CheckTerm(cache, ASCIIToUTF16("rec")); |
| 865 } | 865 } |
| 866 | 866 |
| 867 TEST_F(InMemoryURLIndexTest, AddNewRows) { | 867 TEST_F(InMemoryURLIndexTest, AddNewRows) { |
| 868 // 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. |
| 869 URLID new_row_id = 87654321; | 869 history::URLID new_row_id = 87654321; |
| 870 // Newly created URLRows get a last_visit time of 'right now' so it should | 870 // Newly created history::URLRows get a last_visit time of 'right now' so it |
| 871 // should |
| 871 // qualify as a quick result candidate. | 872 // qualify as a quick result candidate. |
| 872 EXPECT_TRUE(url_index_->HistoryItemsForTerms(ASCIIToUTF16("brokeandalone"), | 873 EXPECT_TRUE(url_index_->HistoryItemsForTerms(ASCIIToUTF16("brokeandalone"), |
| 873 base::string16::npos, | 874 base::string16::npos, |
| 874 kMaxMatches, builder_).empty()); | 875 kMaxMatches, builder_).empty()); |
| 875 | 876 |
| 876 // Add a new row. | 877 // Add a new row. |
| 877 URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), new_row_id++); | 878 history::URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), |
| 879 new_row_id++); |
| 878 new_row.set_last_visit(base::Time::Now()); | 880 new_row.set_last_visit(base::Time::Now()); |
| 879 EXPECT_TRUE(UpdateURL(new_row)); | 881 EXPECT_TRUE(UpdateURL(new_row)); |
| 880 | 882 |
| 881 // Verify that we can retrieve it. | 883 // Verify that we can retrieve it. |
| 882 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms(ASCIIToUTF16("brokeandalone"), | 884 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms(ASCIIToUTF16("brokeandalone"), |
| 883 base::string16::npos, | 885 base::string16::npos, |
| 884 kMaxMatches, builder_).size()); | 886 kMaxMatches, builder_).size()); |
| 885 | 887 |
| 886 // Add it again just to be sure that is harmless and that it does not update | 888 // Add it again just to be sure that is harmless and that it does not update |
| 887 // the index. | 889 // the index. |
| 888 EXPECT_FALSE(UpdateURL(new_row)); | 890 EXPECT_FALSE(UpdateURL(new_row)); |
| 889 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms(ASCIIToUTF16("brokeandalone"), | 891 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms(ASCIIToUTF16("brokeandalone"), |
| 890 base::string16::npos, | 892 base::string16::npos, |
| 891 kMaxMatches, builder_).size()); | 893 kMaxMatches, builder_).size()); |
| 892 | 894 |
| 893 // Make up an URL that does not qualify and try to add it. | 895 // Make up an URL that does not qualify and try to add it. |
| 894 URLRow unqualified_row(GURL("http://www.brokeandaloneinmanitoba.com/"), | 896 history::URLRow unqualified_row( |
| 895 new_row_id++); | 897 GURL("http://www.brokeandaloneinmanitoba.com/"), new_row_id++); |
| 896 EXPECT_FALSE(UpdateURL(new_row)); | 898 EXPECT_FALSE(UpdateURL(new_row)); |
| 897 } | 899 } |
| 898 | 900 |
| 899 TEST_F(InMemoryURLIndexTest, DeleteRows) { | 901 TEST_F(InMemoryURLIndexTest, DeleteRows) { |
| 900 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( | 902 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( |
| 901 ASCIIToUTF16("DrudgeReport"), base::string16::npos, kMaxMatches, | 903 ASCIIToUTF16("DrudgeReport"), base::string16::npos, kMaxMatches, |
| 902 builder_); | 904 builder_); |
| 903 ASSERT_EQ(1U, matches.size()); | 905 ASSERT_EQ(1U, matches.size()); |
| 904 | 906 |
| 905 // Delete the URL then search again. | 907 // Delete the URL then search again. |
| 906 EXPECT_TRUE(DeleteURL(matches[0].url_info.url())); | 908 EXPECT_TRUE(DeleteURL(matches[0].url_info.url())); |
| 907 EXPECT_TRUE(url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudgeReport"), | 909 EXPECT_TRUE(url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudgeReport"), |
| 908 base::string16::npos, | 910 base::string16::npos, |
| 909 kMaxMatches, builder_).empty()); | 911 kMaxMatches, builder_).empty()); |
| 910 | 912 |
| 911 // Make up an URL that does not exist in the database and delete it. | 913 // Make up an URL that does not exist in the database and delete it. |
| 912 GURL url("http://www.hokeypokey.com/putyourrightfootin.html"); | 914 GURL url("http://www.hokeypokey.com/putyourrightfootin.html"); |
| 913 EXPECT_FALSE(DeleteURL(url)); | 915 EXPECT_FALSE(DeleteURL(url)); |
| 914 } | 916 } |
| 915 | 917 |
| 916 TEST_F(InMemoryURLIndexTest, ExpireRow) { | 918 TEST_F(InMemoryURLIndexTest, ExpireRow) { |
| 917 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( | 919 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( |
| 918 ASCIIToUTF16("DrudgeReport"), base::string16::npos, kMaxMatches, | 920 ASCIIToUTF16("DrudgeReport"), base::string16::npos, kMaxMatches, |
| 919 builder_); | 921 builder_); |
| 920 ASSERT_EQ(1U, matches.size()); | 922 ASSERT_EQ(1U, matches.size()); |
| 921 | 923 |
| 922 // Determine the row id for the result, remember that id, broadcast a | 924 // Determine the row id for the result, remember that id, broadcast a |
| 923 // delete notification, then ensure that the row has been deleted. | 925 // delete notification, then ensure that the row has been deleted. |
| 924 URLRows deleted_rows; | 926 history::URLRows deleted_rows; |
| 925 deleted_rows.push_back(matches[0].url_info); | 927 deleted_rows.push_back(matches[0].url_info); |
| 926 url_index_->OnURLsDeleted(nullptr, false, false, deleted_rows, | 928 url_index_->OnURLsDeleted(nullptr, false, false, deleted_rows, |
| 927 std::set<GURL>()); | 929 std::set<GURL>()); |
| 928 EXPECT_TRUE(url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudgeReport"), | 930 EXPECT_TRUE(url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudgeReport"), |
| 929 base::string16::npos, | 931 base::string16::npos, |
| 930 kMaxMatches, builder_).empty()); | 932 kMaxMatches, builder_).empty()); |
| 931 } | 933 } |
| 932 | 934 |
| 933 TEST_F(InMemoryURLIndexTest, WhitelistedURLs) { | 935 TEST_F(InMemoryURLIndexTest, WhitelistedURLs) { |
| 934 struct TestData { | 936 struct TestData { |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1251 ASSERT_TRUE(GetCacheFilePath(&full_file_path)); | 1253 ASSERT_TRUE(GetCacheFilePath(&full_file_path)); |
| 1252 std::vector<base::FilePath::StringType> actual_parts; | 1254 std::vector<base::FilePath::StringType> actual_parts; |
| 1253 full_file_path.GetComponents(&actual_parts); | 1255 full_file_path.GetComponents(&actual_parts); |
| 1254 ASSERT_EQ(expected_parts.size(), actual_parts.size()); | 1256 ASSERT_EQ(expected_parts.size(), actual_parts.size()); |
| 1255 size_t count = expected_parts.size(); | 1257 size_t count = expected_parts.size(); |
| 1256 for (size_t i = 0; i < count; ++i) | 1258 for (size_t i = 0; i < count; ++i) |
| 1257 EXPECT_EQ(expected_parts[i], actual_parts[i]); | 1259 EXPECT_EQ(expected_parts[i], actual_parts[i]); |
| 1258 // Must clear the history_dir_ to satisfy the dtor's DCHECK. | 1260 // Must clear the history_dir_ to satisfy the dtor's DCHECK. |
| 1259 set_history_dir(base::FilePath()); | 1261 set_history_dir(base::FilePath()); |
| 1260 } | 1262 } |
| 1261 | |
| 1262 } // namespace history | |
| OLD | NEW |