| 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 <fstream> | 5 #include <fstream> |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/message_loop.h" |
| 9 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/string_util.h" |
| 10 #include "base/string16.h" | 12 #include "base/string16.h" |
| 11 #include "base/string_util.h" | |
| 12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/autocomplete/autocomplete.h" | 14 #include "chrome/browser/autocomplete/autocomplete.h" |
| 14 #include "chrome/browser/history/in_memory_database.h" | 15 #include "chrome/browser/history/history.h" |
| 16 #include "chrome/browser/history/history_backend.h" |
| 17 #include "chrome/browser/history/history_database.h" |
| 18 #include "chrome/browser/history/in_memory_url_index_types.h" |
| 15 #include "chrome/browser/history/in_memory_url_index.h" | 19 #include "chrome/browser/history/in_memory_url_index.h" |
| 16 #include "chrome/browser/history/in_memory_url_index_types.h" | 20 #include "chrome/browser/history/url_index_private_data.h" |
| 17 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
| 22 #include "chrome/test/base/testing_profile.h" |
| 23 #include "content/test/test_browser_thread.h" |
| 18 #include "sql/transaction.h" | 24 #include "sql/transaction.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 26 |
| 21 // The test version of the history url database table ('url') is contained in | 27 // The test version of the history url database table ('url') is contained in |
| 22 // a database file created from a text file('url_history_provider_test.db.txt'). | 28 // a database file created from a text file('url_history_provider_test.db.txt'). |
| 23 // The only difference between this table and a live 'urls' table from a | 29 // The only difference between this table and a live 'urls' table from a |
| 24 // profile is that the last_visit_time column in the test table contains a | 30 // profile is that the last_visit_time column in the test table contains a |
| 25 // number specifying the number of days relative to 'today' to which the | 31 // number specifying the number of days relative to 'today' to which the |
| 26 // absolute time should be set during the test setup stage. | 32 // absolute time should be set during the test setup stage. |
| 27 // | 33 // |
| 28 // The format of the test database text file is of a SQLite .dump file. | 34 // The format of the test database text file is of a SQLite .dump file. |
| 29 // Note that only lines whose first character is an upper-case letter are | 35 // Note that only lines whose first character is an upper-case letter are |
| 30 // processed when creating the test database. | 36 // processed when creating the test database. |
| 31 | 37 |
| 32 namespace history { | 38 namespace history { |
| 33 | 39 |
| 34 class InMemoryURLIndexTest : public testing::Test, | 40 class InMemoryURLIndexTest : public testing::Test { |
| 35 public InMemoryDatabase { | |
| 36 public: | 41 public: |
| 37 InMemoryURLIndexTest() { InitFromScratch(); } | 42 InMemoryURLIndexTest(); |
| 38 | 43 |
| 39 protected: | 44 protected: |
| 40 // Test setup. | 45 // Test setup. |
| 41 virtual void SetUp(); | 46 virtual void SetUp(); |
| 42 | 47 |
| 43 // Allows the database containing the test data to be customized by | 48 // Allows the database containing the test data to be customized by |
| 44 // subclasses. | 49 // subclasses. |
| 45 virtual FilePath::StringType TestDBName() const; | 50 virtual FilePath::StringType TestDBName() const; |
| 46 | 51 |
| 47 // Convenience function to create a URLRow with basic data for |url|, |title|, | 52 // Convenience function to create a URLRow with basic data for |url|, |title|, |
| 48 // |visit_count|, and |typed_count|. |last_visit_ago| gives the number of | 53 // |visit_count|, and |typed_count|. |last_visit_ago| gives the number of |
| 49 // days from now to set the URL's last_visit. | 54 // days from now to set the URL's last_visit. |
| 50 URLRow MakeURLRow(const char* url, | 55 URLRow MakeURLRow(const char* url, |
| 51 const char* title, | 56 const char* title, |
| 52 int visit_count, | 57 int visit_count, |
| 53 int last_visit_ago, | 58 int last_visit_ago, |
| 54 int typed_count); | 59 int typed_count); |
| 55 | 60 |
| 56 // Convenience functions for easily creating vectors of search terms. | 61 // Convenience functions for easily creating vectors of search terms. |
| 57 String16Vector Make1Term(const char* term) const; | 62 String16Vector Make1Term(const char* term) const; |
| 58 String16Vector Make2Terms(const char* term_1, const char* term_2) const; | 63 String16Vector Make2Terms(const char* term_1, const char* term_2) const; |
| 59 | 64 |
| 60 // Validates that the given |term| is contained in |cache| and that it is | 65 // Validates that the given |term| is contained in |cache| and that it is |
| 61 // marked as in-use. | 66 // marked as in-use. |
| 62 void CheckTerm(const URLIndexPrivateData::SearchTermCacheMap& cache, | 67 void CheckTerm(const URLIndexPrivateData::SearchTermCacheMap& cache, |
| 63 string16 term) const; | 68 string16 term) const; |
| 64 | 69 |
| 70 // Pass-through function to simplify our friendship with HistoryService. |
| 71 sql::Connection& GetDB(); |
| 72 |
| 73 // Pass-through functions to simplify our friendship with InMemoryURLIndex. |
| 74 URLIndexPrivateData* GetPrivateData() const; |
| 75 bool GetCacheFilePath(FilePath* file_path) const; |
| 76 void ClearHistoryDir() const; |
| 77 |
| 78 // Pass-through functions to simplify our friendship with URLIndexPrivateData. |
| 79 bool UpdateURL(const URLRow& row); |
| 80 bool DeleteURL(const GURL& url); |
| 81 |
| 82 MessageLoopForUI message_loop_; |
| 83 content::TestBrowserThread ui_thread_; |
| 84 content::TestBrowserThread file_thread_; |
| 85 TestingProfile profile_; |
| 86 |
| 65 scoped_ptr<InMemoryURLIndex> url_index_; | 87 scoped_ptr<InMemoryURLIndex> url_index_; |
| 88 HistoryDatabase* history_database_; |
| 66 }; | 89 }; |
| 67 | 90 |
| 91 InMemoryURLIndexTest::InMemoryURLIndexTest() |
| 92 : ui_thread_(content::BrowserThread::UI, &message_loop_), |
| 93 file_thread_(content::BrowserThread::FILE, &message_loop_) { |
| 94 } |
| 95 |
| 96 sql::Connection& InMemoryURLIndexTest::GetDB() { |
| 97 return history_database_->GetDB(); |
| 98 } |
| 99 |
| 100 URLIndexPrivateData* InMemoryURLIndexTest::GetPrivateData() const { |
| 101 DCHECK(url_index_->private_data_.get()); |
| 102 return url_index_->private_data_.get(); |
| 103 } |
| 104 |
| 105 bool InMemoryURLIndexTest::GetCacheFilePath(FilePath* file_path) const { |
| 106 DCHECK(file_path); |
| 107 return url_index_->GetCacheFilePath(file_path); |
| 108 } |
| 109 |
| 110 void InMemoryURLIndexTest::ClearHistoryDir() const { |
| 111 url_index_->history_dir_.clear(); |
| 112 } |
| 113 |
| 114 bool InMemoryURLIndexTest::UpdateURL(const URLRow& row) { |
| 115 return url_index_->private_data_->UpdateURL(row); |
| 116 } |
| 117 |
| 118 bool InMemoryURLIndexTest::DeleteURL(const GURL& url) { |
| 119 return url_index_->private_data_->DeleteURL(url); |
| 120 } |
| 121 |
| 68 void InMemoryURLIndexTest::SetUp() { | 122 void InMemoryURLIndexTest::SetUp() { |
| 123 // We cannot access the database until the backend has been loaded. |
| 124 profile_.CreateHistoryService(true, false); |
| 125 profile_.CreateBookmarkModel(true); |
| 126 profile_.BlockUntilBookmarkModelLoaded(); |
| 127 profile_.BlockUntilHistoryProcessesPendingRequests(); |
| 128 HistoryService* history_service = |
| 129 profile_.GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 130 ASSERT_TRUE(history_service); |
| 131 HistoryBackend* backend = history_service->history_backend_.get(); |
| 132 history_database_ = backend->db(); |
| 133 |
| 69 // Create and populate a working copy of the URL history database. | 134 // Create and populate a working copy of the URL history database. |
| 70 FilePath history_proto_path; | 135 FilePath history_proto_path; |
| 71 PathService::Get(chrome::DIR_TEST_DATA, &history_proto_path); | 136 PathService::Get(chrome::DIR_TEST_DATA, &history_proto_path); |
| 72 history_proto_path = history_proto_path.Append( | 137 history_proto_path = history_proto_path.Append( |
| 73 FILE_PATH_LITERAL("History")); | 138 FILE_PATH_LITERAL("History")); |
| 74 history_proto_path = history_proto_path.Append(TestDBName()); | 139 history_proto_path = history_proto_path.Append(TestDBName()); |
| 75 EXPECT_TRUE(file_util::PathExists(history_proto_path)); | 140 EXPECT_TRUE(file_util::PathExists(history_proto_path)); |
| 76 | 141 |
| 77 std::ifstream proto_file(history_proto_path.value().c_str()); | 142 std::ifstream proto_file(history_proto_path.value().c_str()); |
| 78 static const size_t kCommandBufferMaxSize = 2048; | 143 static const size_t kCommandBufferMaxSize = 2048; |
| 79 char sql_cmd_line[kCommandBufferMaxSize]; | 144 char sql_cmd_line[kCommandBufferMaxSize]; |
| 80 | 145 |
| 81 sql::Connection& db(GetDB()); | 146 sql::Connection& db(GetDB()); |
| 147 ASSERT_TRUE(db.is_open()); |
| 82 { | 148 { |
| 83 sql::Transaction transaction(&db); | 149 sql::Transaction transaction(&db); |
| 84 transaction.Begin(); | 150 transaction.Begin(); |
| 85 while (!proto_file.eof()) { | 151 while (!proto_file.eof()) { |
| 86 proto_file.getline(sql_cmd_line, kCommandBufferMaxSize); | 152 proto_file.getline(sql_cmd_line, kCommandBufferMaxSize); |
| 87 if (!proto_file.eof()) { | 153 if (!proto_file.eof()) { |
| 88 // We only process lines which begin with a upper-case letter. | 154 // We only process lines which begin with a upper-case letter. |
| 89 // TODO(mrossetti): Can iswupper() be used here? | 155 // TODO(mrossetti): Can iswupper() be used here? |
| 90 if (sql_cmd_line[0] >= 'A' && sql_cmd_line[0] <= 'Z') { | 156 if (sql_cmd_line[0] >= 'A' && sql_cmd_line[0] <= 'Z') { |
| 91 std::string sql_cmd(sql_cmd_line); | 157 std::string sql_cmd(sql_cmd_line); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 103 sql::Statement statement(db.GetUniqueStatement( | 169 sql::Statement statement(db.GetUniqueStatement( |
| 104 "SELECT" HISTORY_URL_ROW_FIELDS "FROM urls;")); | 170 "SELECT" HISTORY_URL_ROW_FIELDS "FROM urls;")); |
| 105 ASSERT_TRUE(statement.is_valid()); | 171 ASSERT_TRUE(statement.is_valid()); |
| 106 base::Time time_right_now = base::Time::NowFromSystemTime(); | 172 base::Time time_right_now = base::Time::NowFromSystemTime(); |
| 107 base::TimeDelta day_delta = base::TimeDelta::FromDays(1); | 173 base::TimeDelta day_delta = base::TimeDelta::FromDays(1); |
| 108 { | 174 { |
| 109 sql::Transaction transaction(&db); | 175 sql::Transaction transaction(&db); |
| 110 transaction.Begin(); | 176 transaction.Begin(); |
| 111 while (statement.Step()) { | 177 while (statement.Step()) { |
| 112 URLRow row; | 178 URLRow row; |
| 113 FillURLRow(statement, &row); | 179 history_database_->FillURLRow(statement, &row); |
| 114 base::Time last_visit = time_right_now; | 180 base::Time last_visit = time_right_now; |
| 115 for (int64 i = row.last_visit().ToInternalValue(); i > 0; --i) | 181 for (int64 i = row.last_visit().ToInternalValue(); i > 0; --i) |
| 116 last_visit -= day_delta; | 182 last_visit -= day_delta; |
| 117 row.set_last_visit(last_visit); | 183 row.set_last_visit(last_visit); |
| 118 UpdateURLRow(row.id(), row); | 184 history_database_->UpdateURLRow(row.id(), row); |
| 119 } | 185 } |
| 120 transaction.Commit(); | 186 transaction.Commit(); |
| 121 } | 187 } |
| 188 |
| 189 url_index_.reset( |
| 190 new InMemoryURLIndex(&profile_, FilePath(), "en,ja,hi,zh")); |
| 191 url_index_->Init(); |
| 192 url_index_->RebuildFromHistory(history_database_); |
| 122 } | 193 } |
| 123 | 194 |
| 124 FilePath::StringType InMemoryURLIndexTest::TestDBName() const { | 195 FilePath::StringType InMemoryURLIndexTest::TestDBName() const { |
| 125 return FILE_PATH_LITERAL("url_history_provider_test.db.txt"); | 196 return FILE_PATH_LITERAL("url_history_provider_test.db.txt"); |
| 126 } | 197 } |
| 127 | 198 |
| 128 URLRow InMemoryURLIndexTest::MakeURLRow(const char* url, | 199 URLRow InMemoryURLIndexTest::MakeURLRow(const char* url, |
| 129 const char* title, | 200 const char* title, |
| 130 int visit_count, | 201 int visit_count, |
| 131 int last_visit_ago, | 202 int last_visit_ago, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 | 259 |
| 189 class LimitedInMemoryURLIndexTest : public InMemoryURLIndexTest { | 260 class LimitedInMemoryURLIndexTest : public InMemoryURLIndexTest { |
| 190 protected: | 261 protected: |
| 191 FilePath::StringType TestDBName() const; | 262 FilePath::StringType TestDBName() const; |
| 192 }; | 263 }; |
| 193 | 264 |
| 194 FilePath::StringType LimitedInMemoryURLIndexTest::TestDBName() const { | 265 FilePath::StringType LimitedInMemoryURLIndexTest::TestDBName() const { |
| 195 return FILE_PATH_LITERAL("url_history_provider_test_limited.db.txt"); | 266 return FILE_PATH_LITERAL("url_history_provider_test_limited.db.txt"); |
| 196 } | 267 } |
| 197 | 268 |
| 198 TEST_F(InMemoryURLIndexTest, Construction) { | |
| 199 url_index_.reset(new InMemoryURLIndex(FilePath())); | |
| 200 EXPECT_TRUE(url_index_.get()); | |
| 201 } | |
| 202 | |
| 203 TEST_F(LimitedInMemoryURLIndexTest, Initialization) { | 269 TEST_F(LimitedInMemoryURLIndexTest, Initialization) { |
| 204 // Verify that the database contains the expected number of items, which | 270 // Verify that the database contains the expected number of items, which |
| 205 // is the pre-filtered count, i.e. all of the items. | 271 // is the pre-filtered count, i.e. all of the items. |
| 206 sql::Statement statement(GetDB().GetUniqueStatement("SELECT * FROM urls;")); | 272 sql::Connection& db(GetDB()); |
| 273 sql::Statement statement(db.GetUniqueStatement("SELECT * FROM urls;")); |
| 207 ASSERT_TRUE(statement.is_valid()); | 274 ASSERT_TRUE(statement.is_valid()); |
| 208 uint64 row_count = 0; | 275 uint64 row_count = 0; |
| 209 while (statement.Step()) ++row_count; | 276 while (statement.Step()) ++row_count; |
| 210 EXPECT_EQ(1U, row_count); | 277 EXPECT_EQ(1U, row_count); |
| 211 url_index_.reset(new InMemoryURLIndex(FilePath())); | 278 url_index_.reset( |
| 212 url_index_->Init(this, "en,ja,hi,zh"); | 279 new InMemoryURLIndex(&profile_, FilePath(), "en,ja,hi,zh")); |
| 280 url_index_->Init(); |
| 281 url_index_->RebuildFromHistory(history_database_); |
| 213 URLIndexPrivateData& private_data(*(url_index_->private_data_)); | 282 URLIndexPrivateData& private_data(*(url_index_->private_data_)); |
| 214 | 283 |
| 215 // history_info_map_ should have the same number of items as were filtered. | 284 // history_info_map_ should have the same number of items as were filtered. |
| 216 EXPECT_EQ(1U, private_data.history_info_map_.size()); | 285 EXPECT_EQ(1U, private_data.history_info_map_.size()); |
| 217 EXPECT_EQ(35U, private_data.char_word_map_.size()); | 286 EXPECT_EQ(35U, private_data.char_word_map_.size()); |
| 218 EXPECT_EQ(17U, private_data.word_map_.size()); | 287 EXPECT_EQ(17U, private_data.word_map_.size()); |
| 219 } | 288 } |
| 220 | 289 |
| 221 TEST_F(InMemoryURLIndexTest, Retrieval) { | 290 TEST_F(InMemoryURLIndexTest, Retrieval) { |
| 222 url_index_.reset(new InMemoryURLIndex(FilePath())); | |
| 223 url_index_->Init(this, "en,ja,hi,zh"); | |
| 224 // The term will be lowercased by the search. | |
| 225 | |
| 226 // See if a very specific term gives a single result. | 291 // See if a very specific term gives a single result. |
| 227 ScoredHistoryMatches matches = | 292 ScoredHistoryMatches matches = |
| 228 url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudgeReport")); | 293 url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudgeReport")); |
| 229 ASSERT_EQ(1U, matches.size()); | 294 ASSERT_EQ(1U, matches.size()); |
| 230 | 295 |
| 231 // Verify that we got back the result we expected. | 296 // Verify that we got back the result we expected. |
| 232 EXPECT_EQ(5, matches[0].url_info.id()); | 297 EXPECT_EQ(5, matches[0].url_info.id()); |
| 233 EXPECT_EQ("http://drudgereport.com/", matches[0].url_info.url().spec()); | 298 EXPECT_EQ("http://drudgereport.com/", matches[0].url_info.url().spec()); |
| 234 EXPECT_EQ(ASCIIToUTF16("DRUDGE REPORT 2010"), matches[0].url_info.title()); | 299 EXPECT_EQ(ASCIIToUTF16("DRUDGE REPORT 2010"), matches[0].url_info.title()); |
| 235 EXPECT_TRUE(matches[0].can_inline); | 300 EXPECT_TRUE(matches[0].can_inline); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("fubar")); | 350 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("fubar")); |
| 286 ASSERT_EQ(1U, matches.size()); | 351 ASSERT_EQ(1U, matches.size()); |
| 287 EXPECT_EQ(34, matches[0].url_info.id()); | 352 EXPECT_EQ(34, matches[0].url_info.id()); |
| 288 EXPECT_EQ("http://fubarfubarandfubar.com/", matches[0].url_info.url().spec()); | 353 EXPECT_EQ("http://fubarfubarandfubar.com/", matches[0].url_info.url().spec()); |
| 289 EXPECT_EQ(ASCIIToUTF16("Situation Normal -- FUBARED"), | 354 EXPECT_EQ(ASCIIToUTF16("Situation Normal -- FUBARED"), |
| 290 matches[0].url_info.title()); | 355 matches[0].url_info.title()); |
| 291 EXPECT_TRUE(matches[0].can_inline); | 356 EXPECT_TRUE(matches[0].can_inline); |
| 292 } | 357 } |
| 293 | 358 |
| 294 TEST_F(InMemoryURLIndexTest, URLPrefixMatching) { | 359 TEST_F(InMemoryURLIndexTest, URLPrefixMatching) { |
| 295 url_index_.reset(new InMemoryURLIndex(FilePath())); | |
| 296 url_index_->Init(this, "en,ja,hi,zh"); | |
| 297 | |
| 298 // "drudgere" - found, can inline | 360 // "drudgere" - found, can inline |
| 299 ScoredHistoryMatches matches = | 361 ScoredHistoryMatches matches = |
| 300 url_index_->HistoryItemsForTerms(ASCIIToUTF16("drudgere")); | 362 url_index_->HistoryItemsForTerms(ASCIIToUTF16("drudgere")); |
| 301 ASSERT_EQ(1U, matches.size()); | 363 ASSERT_EQ(1U, matches.size()); |
| 302 EXPECT_TRUE(matches[0].can_inline); | 364 EXPECT_TRUE(matches[0].can_inline); |
| 303 | 365 |
| 304 // "http://drudgere" - found, can inline | 366 // "http://drudgere" - found, can inline |
| 305 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("http://drudgere")); | 367 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("http://drudgere")); |
| 306 ASSERT_EQ(1U, matches.size()); | 368 ASSERT_EQ(1U, matches.size()); |
| 307 EXPECT_TRUE(matches[0].can_inline); | 369 EXPECT_TRUE(matches[0].can_inline); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 EXPECT_TRUE(matches[0].can_inline); | 410 EXPECT_TRUE(matches[0].can_inline); |
| 349 | 411 |
| 350 // "tp://www.cnn.com" - found, cannot inline | 412 // "tp://www.cnn.com" - found, cannot inline |
| 351 matches = | 413 matches = |
| 352 url_index_->HistoryItemsForTerms(ASCIIToUTF16("tp://www.cnn.com")); | 414 url_index_->HistoryItemsForTerms(ASCIIToUTF16("tp://www.cnn.com")); |
| 353 ASSERT_EQ(1U, matches.size()); | 415 ASSERT_EQ(1U, matches.size()); |
| 354 EXPECT_TRUE(!matches[0].can_inline); | 416 EXPECT_TRUE(!matches[0].can_inline); |
| 355 } | 417 } |
| 356 | 418 |
| 357 TEST_F(InMemoryURLIndexTest, ProperStringMatching) { | 419 TEST_F(InMemoryURLIndexTest, ProperStringMatching) { |
| 358 url_index_.reset(new InMemoryURLIndex(FilePath())); | |
| 359 url_index_->Init(this, "en,ja,hi,zh"); | |
| 360 | |
| 361 // Search for the following with the expected results: | 420 // Search for the following with the expected results: |
| 362 // "atdmt view" - found | 421 // "atdmt view" - found |
| 363 // "atdmt.view" - not found | 422 // "atdmt.view" - not found |
| 364 // "view.atdmt" - found | 423 // "view.atdmt" - found |
| 365 ScoredHistoryMatches matches = | 424 ScoredHistoryMatches matches = |
| 366 url_index_->HistoryItemsForTerms(ASCIIToUTF16("atdmt view")); | 425 url_index_->HistoryItemsForTerms(ASCIIToUTF16("atdmt view")); |
| 367 ASSERT_EQ(1U, matches.size()); | 426 ASSERT_EQ(1U, matches.size()); |
| 368 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("atdmt.view")); | 427 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("atdmt.view")); |
| 369 ASSERT_EQ(0U, matches.size()); | 428 ASSERT_EQ(0U, matches.size()); |
| 370 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("view.atdmt")); | 429 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("view.atdmt")); |
| 371 ASSERT_EQ(1U, matches.size()); | 430 ASSERT_EQ(1U, matches.size()); |
| 372 } | 431 } |
| 373 | 432 |
| 374 TEST_F(InMemoryURLIndexTest, HugeResultSet) { | 433 TEST_F(InMemoryURLIndexTest, HugeResultSet) { |
| 375 url_index_.reset(new InMemoryURLIndex(FilePath())); | |
| 376 url_index_->Init(this, "en,ja,hi,zh"); | |
| 377 | |
| 378 // Create a huge set of qualifying history items. | 434 // Create a huge set of qualifying history items. |
| 379 for (URLID row_id = 5000; row_id < 6000; ++row_id) { | 435 for (URLID row_id = 5000; row_id < 6000; ++row_id) { |
| 380 URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), row_id); | 436 URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), row_id); |
| 381 new_row.set_last_visit(base::Time::Now()); | 437 new_row.set_last_visit(base::Time::Now()); |
| 382 url_index_->UpdateURL(row_id, new_row); | 438 EXPECT_TRUE(UpdateURL(new_row)); |
| 383 } | 439 } |
| 384 | 440 |
| 385 ScoredHistoryMatches matches = | 441 ScoredHistoryMatches matches = |
| 386 url_index_->HistoryItemsForTerms(ASCIIToUTF16("b")); | 442 url_index_->HistoryItemsForTerms(ASCIIToUTF16("b")); |
| 443 URLIndexPrivateData& private_data(*GetPrivateData()); |
| 387 ASSERT_EQ(AutocompleteProvider::kMaxMatches, matches.size()); | 444 ASSERT_EQ(AutocompleteProvider::kMaxMatches, matches.size()); |
| 388 // There are 7 matches already in the database. | 445 // There are 7 matches already in the database. |
| 389 URLIndexPrivateData& private_data(*(url_index_->private_data_.get())); | |
| 390 ASSERT_EQ(1008U, private_data.pre_filter_item_count_); | 446 ASSERT_EQ(1008U, private_data.pre_filter_item_count_); |
| 391 ASSERT_EQ(500U, private_data.post_filter_item_count_); | 447 ASSERT_EQ(500U, private_data.post_filter_item_count_); |
| 392 ASSERT_EQ(AutocompleteProvider::kMaxMatches, | 448 ASSERT_EQ(AutocompleteProvider::kMaxMatches, |
| 393 private_data.post_scoring_item_count_); | 449 private_data.post_scoring_item_count_); |
| 394 } | 450 } |
| 395 | 451 |
| 396 TEST_F(InMemoryURLIndexTest, TitleSearch) { | 452 TEST_F(InMemoryURLIndexTest, TitleSearch) { |
| 397 url_index_.reset(new InMemoryURLIndex(FilePath())); | |
| 398 url_index_->Init(this, "en,ja,hi,zh"); | |
| 399 // Signal if someone has changed the test DB. | 453 // Signal if someone has changed the test DB. |
| 400 EXPECT_EQ(28U, url_index_->private_data_->history_info_map_.size()); | 454 EXPECT_EQ(28U, GetPrivateData()->history_info_map_.size()); |
| 401 | 455 |
| 402 // Ensure title is being searched. | 456 // Ensure title is being searched. |
| 403 ScoredHistoryMatches matches = | 457 ScoredHistoryMatches matches = |
| 404 url_index_->HistoryItemsForTerms(ASCIIToUTF16("MORTGAGE RATE DROPS")); | 458 url_index_->HistoryItemsForTerms(ASCIIToUTF16("MORTGAGE RATE DROPS")); |
| 405 ASSERT_EQ(1U, matches.size()); | 459 ASSERT_EQ(1U, matches.size()); |
| 406 | 460 |
| 407 // Verify that we got back the result we expected. | 461 // Verify that we got back the result we expected. |
| 408 EXPECT_EQ(1, matches[0].url_info.id()); | 462 EXPECT_EQ(1, matches[0].url_info.id()); |
| 409 EXPECT_EQ("http://www.reuters.com/article/idUSN0839880620100708", | 463 EXPECT_EQ("http://www.reuters.com/article/idUSN0839880620100708", |
| 410 matches[0].url_info.url().spec()); | 464 matches[0].url_info.url().spec()); |
| 411 EXPECT_EQ(ASCIIToUTF16( | 465 EXPECT_EQ(ASCIIToUTF16( |
| 412 "UPDATE 1-US 30-yr mortgage rate drops to new record low | Reuters"), | 466 "UPDATE 1-US 30-yr mortgage rate drops to new record low | Reuters"), |
| 413 matches[0].url_info.title()); | 467 matches[0].url_info.title()); |
| 414 } | 468 } |
| 415 | 469 |
| 416 TEST_F(InMemoryURLIndexTest, TitleChange) { | 470 TEST_F(InMemoryURLIndexTest, TitleChange) { |
| 417 url_index_.reset(new InMemoryURLIndex(FilePath())); | |
| 418 url_index_->Init(this, "en,ja,hi,zh"); | |
| 419 | |
| 420 // Verify current title terms retrieves desired item. | 471 // Verify current title terms retrieves desired item. |
| 421 string16 original_terms = | 472 string16 original_terms = |
| 422 ASCIIToUTF16("lebronomics could high taxes influence"); | 473 ASCIIToUTF16("lebronomics could high taxes influence"); |
| 423 ScoredHistoryMatches matches = | 474 ScoredHistoryMatches matches = |
| 424 url_index_->HistoryItemsForTerms(original_terms); | 475 url_index_->HistoryItemsForTerms(original_terms); |
| 425 ASSERT_EQ(1U, matches.size()); | 476 ASSERT_EQ(1U, matches.size()); |
| 426 | 477 |
| 427 // Verify that we got back the result we expected. | 478 // Verify that we got back the result we expected. |
| 428 const URLID expected_id = 3; | 479 const URLID expected_id = 3; |
| 429 EXPECT_EQ(expected_id, matches[0].url_info.id()); | 480 EXPECT_EQ(expected_id, matches[0].url_info.id()); |
| 430 EXPECT_EQ("http://www.businessandmedia.org/articles/2010/20100708120415.aspx", | 481 EXPECT_EQ("http://www.businessandmedia.org/articles/2010/20100708120415.aspx", |
| 431 matches[0].url_info.url().spec()); | 482 matches[0].url_info.url().spec()); |
| 432 EXPECT_EQ(ASCIIToUTF16( | 483 EXPECT_EQ(ASCIIToUTF16( |
| 433 "LeBronomics: Could High Taxes Influence James' Team Decision?"), | 484 "LeBronomics: Could High Taxes Influence James' Team Decision?"), |
| 434 matches[0].url_info.title()); | 485 matches[0].url_info.title()); |
| 435 URLRow old_row(matches[0].url_info); | 486 URLRow old_row(matches[0].url_info); |
| 436 | 487 |
| 437 // Verify new title terms retrieves nothing. | 488 // Verify new title terms retrieves nothing. |
| 438 string16 new_terms = ASCIIToUTF16("does eat oats little lambs ivy"); | 489 string16 new_terms = ASCIIToUTF16("does eat oats little lambs ivy"); |
| 439 matches = url_index_->HistoryItemsForTerms(new_terms); | 490 matches = url_index_->HistoryItemsForTerms(new_terms); |
| 440 ASSERT_EQ(0U, matches.size()); | 491 ASSERT_EQ(0U, matches.size()); |
| 441 | 492 |
| 442 // Update the row. | 493 // Update the row. |
| 443 old_row.set_title(ASCIIToUTF16("Does eat oats and little lambs eat ivy")); | 494 old_row.set_title(ASCIIToUTF16("Does eat oats and little lambs eat ivy")); |
| 444 url_index_->UpdateURL(expected_id, old_row); | 495 EXPECT_TRUE(UpdateURL(old_row)); |
| 445 | 496 |
| 446 // Verify we get the row using the new terms but not the original terms. | 497 // Verify we get the row using the new terms but not the original terms. |
| 447 matches = url_index_->HistoryItemsForTerms(new_terms); | 498 matches = url_index_->HistoryItemsForTerms(new_terms); |
| 448 ASSERT_EQ(1U, matches.size()); | 499 ASSERT_EQ(1U, matches.size()); |
| 449 EXPECT_EQ(expected_id, matches[0].url_info.id()); | 500 EXPECT_EQ(expected_id, matches[0].url_info.id()); |
| 450 matches = url_index_->HistoryItemsForTerms(original_terms); | 501 matches = url_index_->HistoryItemsForTerms(original_terms); |
| 451 ASSERT_EQ(0U, matches.size()); | 502 ASSERT_EQ(0U, matches.size()); |
| 452 } | 503 } |
| 453 | 504 |
| 454 TEST_F(InMemoryURLIndexTest, NonUniqueTermCharacterSets) { | 505 TEST_F(InMemoryURLIndexTest, NonUniqueTermCharacterSets) { |
| 455 url_index_.reset(new InMemoryURLIndex(FilePath())); | |
| 456 url_index_->Init(this, "en,ja,hi,zh"); | |
| 457 | |
| 458 // The presence of duplicate characters should succeed. Exercise by cycling | 506 // The presence of duplicate characters should succeed. Exercise by cycling |
| 459 // through a string with several duplicate characters. | 507 // through a string with several duplicate characters. |
| 460 ScoredHistoryMatches matches = | 508 ScoredHistoryMatches matches = |
| 461 url_index_->HistoryItemsForTerms(ASCIIToUTF16("ABRA")); | 509 url_index_->HistoryItemsForTerms(ASCIIToUTF16("ABRA")); |
| 462 ASSERT_EQ(1U, matches.size()); | 510 ASSERT_EQ(1U, matches.size()); |
| 463 EXPECT_EQ(28, matches[0].url_info.id()); | 511 EXPECT_EQ(28, matches[0].url_info.id()); |
| 464 EXPECT_EQ("http://www.ddj.com/windows/184416623", | 512 EXPECT_EQ("http://www.ddj.com/windows/184416623", |
| 465 matches[0].url_info.url().spec()); | 513 matches[0].url_info.url().spec()); |
| 466 | 514 |
| 467 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("ABRACAD")); | 515 matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("ABRACAD")); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 481 EXPECT_EQ(28, matches[0].url_info.id()); | 529 EXPECT_EQ(28, matches[0].url_info.id()); |
| 482 } | 530 } |
| 483 | 531 |
| 484 TEST_F(InMemoryURLIndexTest, TypedCharacterCaching) { | 532 TEST_F(InMemoryURLIndexTest, TypedCharacterCaching) { |
| 485 // Verify that match results for previously typed characters are retained | 533 // Verify that match results for previously typed characters are retained |
| 486 // (in the term_char_word_set_cache_) and reused, if possible, in future | 534 // (in the term_char_word_set_cache_) and reused, if possible, in future |
| 487 // autocompletes. | 535 // autocompletes. |
| 488 typedef URLIndexPrivateData::SearchTermCacheMap::iterator CacheIter; | 536 typedef URLIndexPrivateData::SearchTermCacheMap::iterator CacheIter; |
| 489 typedef URLIndexPrivateData::SearchTermCacheItem CacheItem; | 537 typedef URLIndexPrivateData::SearchTermCacheItem CacheItem; |
| 490 | 538 |
| 491 url_index_.reset(new InMemoryURLIndex(FilePath())); | |
| 492 url_index_->Init(this, "en,ja,hi,zh"); | |
| 493 | |
| 494 URLIndexPrivateData::SearchTermCacheMap& cache( | 539 URLIndexPrivateData::SearchTermCacheMap& cache( |
| 495 url_index_->private_data_->search_term_cache_); | 540 GetPrivateData()->search_term_cache_); |
| 496 | 541 |
| 497 // The cache should be empty at this point. | 542 // The cache should be empty at this point. |
| 498 EXPECT_EQ(0U, cache.size()); | 543 EXPECT_EQ(0U, cache.size()); |
| 499 | 544 |
| 500 // Now simulate typing search terms into the omnibox and check the state of | 545 // Now simulate typing search terms into the omnibox and check the state of |
| 501 // the cache as each item is 'typed'. | 546 // the cache as each item is 'typed'. |
| 502 | 547 |
| 503 // Simulate typing "r" giving "r" in the simulated omnibox. The results for | 548 // Simulate typing "r" giving "r" in the simulated omnibox. The results for |
| 504 // 'r' will be not cached because it is only 1 character long. | 549 // 'r' will be not cached because it is only 1 character long. |
| 505 url_index_->HistoryItemsForTerms(ASCIIToUTF16("r")); | 550 url_index_->HistoryItemsForTerms(ASCIIToUTF16("r")); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 EXPECT_GT(scored_h.raw_score, scored_a.raw_score); | 620 EXPECT_GT(scored_h.raw_score, scored_a.raw_score); |
| 576 // Test scores based on a terms appearing multiple times. | 621 // Test scores based on a terms appearing multiple times. |
| 577 URLRow row_i(MakeURLRow("http://csi.csi.csi/csi_csi", | 622 URLRow row_i(MakeURLRow("http://csi.csi.csi/csi_csi", |
| 578 "CSI Guide to CSI Las Vegas, CSI New York, CSI Provo", 3, 30, 10)); | 623 "CSI Guide to CSI Las Vegas, CSI New York, CSI Provo", 3, 30, 10)); |
| 579 ScoredHistoryMatch scored_i(URLIndexPrivateData::ScoredMatchForURL( | 624 ScoredHistoryMatch scored_i(URLIndexPrivateData::ScoredMatchForURL( |
| 580 row_i, ASCIIToUTF16("csi"), Make1Term("csi"))); | 625 row_i, ASCIIToUTF16("csi"), Make1Term("csi"))); |
| 581 EXPECT_LT(scored_i.raw_score, 1400); | 626 EXPECT_LT(scored_i.raw_score, 1400); |
| 582 } | 627 } |
| 583 | 628 |
| 584 TEST_F(InMemoryURLIndexTest, AddNewRows) { | 629 TEST_F(InMemoryURLIndexTest, AddNewRows) { |
| 585 url_index_.reset(new InMemoryURLIndex(FilePath())); | |
| 586 url_index_->Init(this, "en,ja,hi,zh"); | |
| 587 | |
| 588 // Verify that the row we're going to add does not already exist. | 630 // Verify that the row we're going to add does not already exist. |
| 589 URLID new_row_id = 87654321; | 631 URLID new_row_id = 87654321; |
| 590 // Newly created URLRows get a last_visit time of 'right now' so it should | 632 // Newly created URLRows get a last_visit time of 'right now' so it should |
| 591 // qualify as a quick result candidate. | 633 // qualify as a quick result candidate. |
| 592 EXPECT_TRUE(url_index_->HistoryItemsForTerms( | 634 EXPECT_TRUE(url_index_->HistoryItemsForTerms( |
| 593 ASCIIToUTF16("brokeandalone")).empty()); | 635 ASCIIToUTF16("brokeandalone")).empty()); |
| 594 | 636 |
| 595 // Add a new row. | 637 // Add a new row. |
| 596 URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), new_row_id); | 638 URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), new_row_id++); |
| 597 new_row.set_last_visit(base::Time::Now()); | 639 new_row.set_last_visit(base::Time::Now()); |
| 598 url_index_->UpdateURL(new_row_id, new_row); | 640 EXPECT_TRUE(UpdateURL(new_row)); |
| 599 | 641 |
| 600 // Verify that we can retrieve it. | 642 // Verify that we can retrieve it. |
| 601 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms( | 643 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms( |
| 602 ASCIIToUTF16("brokeandalone")).size()); | 644 ASCIIToUTF16("brokeandalone")).size()); |
| 603 | 645 |
| 604 // Add it again just to be sure that is harmless. | 646 // Add it again just to be sure that is harmless and that it does not update |
| 605 url_index_->UpdateURL(new_row_id, new_row); | 647 // the index. |
| 648 EXPECT_FALSE(UpdateURL(new_row)); |
| 606 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms( | 649 EXPECT_EQ(1U, url_index_->HistoryItemsForTerms( |
| 607 ASCIIToUTF16("brokeandalone")).size()); | 650 ASCIIToUTF16("brokeandalone")).size()); |
| 651 |
| 652 // Make up an URL that does not qualify and try to add it. |
| 653 URLRow unqualified_row(GURL("http://www.brokeandaloneinmanitoba.com/"), |
| 654 new_row_id++); |
| 655 EXPECT_FALSE(UpdateURL(new_row)); |
| 608 } | 656 } |
| 609 | 657 |
| 610 TEST_F(InMemoryURLIndexTest, DeleteRows) { | 658 TEST_F(InMemoryURLIndexTest, DeleteRows) { |
| 611 url_index_.reset(new InMemoryURLIndex(FilePath())); | |
| 612 url_index_->Init(this, "en,ja,hi,zh"); | |
| 613 | |
| 614 ScoredHistoryMatches matches = | 659 ScoredHistoryMatches matches = |
| 615 url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudgeReport")); | 660 url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudgeReport")); |
| 616 ASSERT_EQ(1U, matches.size()); | 661 ASSERT_EQ(1U, matches.size()); |
| 617 | 662 |
| 618 // Determine the row id for that result, delete that id, then search again. | 663 // Determine the row id for that result, delete that id, then search again. |
| 619 url_index_->DeleteURL(matches[0].url_info.id()); | 664 EXPECT_TRUE(DeleteURL(matches[0].url_info.url())); |
| 620 EXPECT_TRUE(url_index_->HistoryItemsForTerms( | 665 EXPECT_TRUE(url_index_->HistoryItemsForTerms( |
| 621 ASCIIToUTF16("DrudgeReport")).empty()); | 666 ASCIIToUTF16("DrudgeReport")).empty()); |
| 667 |
| 668 // Make up an URL that does not exist in the database and delete it. |
| 669 GURL url("http://www.hokeypokey.com/putyourrightfootin.html"); |
| 670 EXPECT_FALSE(DeleteURL(url)); |
| 622 } | 671 } |
| 623 | 672 |
| 624 TEST_F(InMemoryURLIndexTest, WhitelistedURLs) { | 673 TEST_F(InMemoryURLIndexTest, WhitelistedURLs) { |
| 625 struct TestData { | 674 struct TestData { |
| 626 const std::string url_spec; | 675 const std::string url_spec; |
| 627 const bool expected_is_whitelisted; | 676 const bool expected_is_whitelisted; |
| 628 } data[] = { | 677 } data[] = { |
| 629 // URLs with whitelisted schemes. | 678 // URLs with whitelisted schemes. |
| 630 { "about:histograms", true }, | 679 { "about:histograms", true }, |
| 631 { "chrome://settings", true }, | 680 { "chrome://settings", true }, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 { "telnet://mayor_margie:one2rule4All@www.mycity.com:6789/", false }, | 736 { "telnet://mayor_margie:one2rule4All@www.mycity.com:6789/", false }, |
| 688 { "tftp://example.com/mystartupfile", false }, | 737 { "tftp://example.com/mystartupfile", false }, |
| 689 { "tip://123.123.123.123/?urn:xopen:xid", false }, | 738 { "tip://123.123.123.123/?urn:xopen:xid", false }, |
| 690 { "tv:nbc.com", false }, | 739 { "tv:nbc.com", false }, |
| 691 { "urn:foo:A123,456", false }, | 740 { "urn:foo:A123,456", false }, |
| 692 { "vemmi://zeus.mctel.fr/demo", false }, | 741 { "vemmi://zeus.mctel.fr/demo", false }, |
| 693 { "wais://www.mydomain.net:8765/mydatabase", false }, | 742 { "wais://www.mydomain.net:8765/mydatabase", false }, |
| 694 { "xmpp:node@example.com", false }, | 743 { "xmpp:node@example.com", false }, |
| 695 { "xmpp://guest@example.com", false }, | 744 { "xmpp://guest@example.com", false }, |
| 696 }; | 745 }; |
| 697 url_index_.reset(new InMemoryURLIndex(FilePath())); | 746 |
| 698 URLIndexPrivateData& private_data(*(url_index_->private_data_.get())); | 747 URLIndexPrivateData& private_data(*GetPrivateData()); |
| 699 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { | 748 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { |
| 700 GURL url(data[i].url_spec); | 749 GURL url(data[i].url_spec); |
| 701 EXPECT_EQ(data[i].expected_is_whitelisted, | 750 EXPECT_EQ(data[i].expected_is_whitelisted, |
| 702 private_data.URLSchemeIsWhitelisted(url)); | 751 private_data.URLSchemeIsWhitelisted(url)); |
| 703 } | 752 } |
| 704 } | 753 } |
| 705 | 754 |
| 706 TEST_F(InMemoryURLIndexTest, CacheFilePath) { | |
| 707 url_index_.reset(new InMemoryURLIndex(FilePath(FILE_PATH_LITERAL( | |
| 708 "/flammmy/frammy/")))); | |
| 709 FilePath full_file_path; | |
| 710 url_index_->GetCacheFilePath(&full_file_path); | |
| 711 std::vector<FilePath::StringType> expected_parts; | |
| 712 FilePath(FILE_PATH_LITERAL("/flammmy/frammy/History Provider Cache")). | |
| 713 GetComponents(&expected_parts); | |
| 714 std::vector<FilePath::StringType> actual_parts; | |
| 715 full_file_path.GetComponents(&actual_parts); | |
| 716 ASSERT_EQ(expected_parts.size(), actual_parts.size()); | |
| 717 size_t count = expected_parts.size(); | |
| 718 for (size_t i = 0; i < count; ++i) | |
| 719 EXPECT_EQ(expected_parts[i], actual_parts[i]); | |
| 720 // Must clear the history_dir_ to satisfy the dtor's DCHECK. | |
| 721 url_index_->history_dir_.clear(); | |
| 722 } | |
| 723 | |
| 724 TEST_F(InMemoryURLIndexTest, CacheSaveRestore) { | 755 TEST_F(InMemoryURLIndexTest, CacheSaveRestore) { |
| 725 // Save the cache to a protobuf, restore it, and compare the results. | 756 // Save the cache to a protobuf, restore it, and compare the results. |
| 726 url_index_.reset(new InMemoryURLIndex(FilePath())); | |
| 727 InMemoryURLIndex& url_index(*(url_index_.get())); | |
| 728 url_index.Init(this, "en,ja,hi,zh"); | |
| 729 in_memory_url_index::InMemoryURLIndexCacheItem index_cache; | 757 in_memory_url_index::InMemoryURLIndexCacheItem index_cache; |
| 730 URLIndexPrivateData& private_data(*(url_index_->private_data_.get())); | 758 URLIndexPrivateData& private_data(*GetPrivateData()); |
| 731 private_data.SavePrivateData(&index_cache); | 759 private_data.SavePrivateData(&index_cache); |
| 732 | 760 |
| 733 // Capture our private data so we can later compare for equality. | 761 // Capture our private data so we can later compare for equality. |
| 734 String16Vector word_list(private_data.word_list_); | 762 String16Vector word_list(private_data.word_list_); |
| 735 WordMap word_map(private_data.word_map_); | 763 WordMap word_map(private_data.word_map_); |
| 736 CharWordIDMap char_word_map(private_data.char_word_map_); | 764 CharWordIDMap char_word_map(private_data.char_word_map_); |
| 737 WordIDHistoryMap word_id_history_map(private_data.word_id_history_map_); | 765 WordIDHistoryMap word_id_history_map(private_data.word_id_history_map_); |
| 738 HistoryIDWordMap history_id_word_map(private_data.history_id_word_map_); | 766 HistoryIDWordMap history_id_word_map(private_data.history_id_word_map_); |
| 739 HistoryInfoMap history_info_map(private_data.history_info_map_); | 767 HistoryInfoMap history_info_map(private_data.history_info_map_); |
| 740 | 768 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 ASSERT_FALSE(private_data.history_info_map_.end() == actual); | 818 ASSERT_FALSE(private_data.history_info_map_.end() == actual); |
| 791 const URLRow& expected_row(expected->second); | 819 const URLRow& expected_row(expected->second); |
| 792 const URLRow& actual_row(actual->second); | 820 const URLRow& actual_row(actual->second); |
| 793 EXPECT_EQ(expected_row.visit_count(), actual_row.visit_count()); | 821 EXPECT_EQ(expected_row.visit_count(), actual_row.visit_count()); |
| 794 EXPECT_EQ(expected_row.typed_count(), actual_row.typed_count()); | 822 EXPECT_EQ(expected_row.typed_count(), actual_row.typed_count()); |
| 795 EXPECT_EQ(expected_row.last_visit(), actual_row.last_visit()); | 823 EXPECT_EQ(expected_row.last_visit(), actual_row.last_visit()); |
| 796 EXPECT_EQ(expected_row.url(), actual_row.url()); | 824 EXPECT_EQ(expected_row.url(), actual_row.url()); |
| 797 } | 825 } |
| 798 } | 826 } |
| 799 | 827 |
| 828 class InMemoryURLIndexCacheTest : public testing::Test { |
| 829 public: |
| 830 InMemoryURLIndexCacheTest() {} |
| 831 |
| 832 protected: |
| 833 virtual void SetUp() OVERRIDE; |
| 834 |
| 835 ScopedTempDir temp_dir_; |
| 836 scoped_ptr<InMemoryURLIndex> url_index_; |
| 837 }; |
| 838 |
| 839 void InMemoryURLIndexCacheTest::SetUp() { |
| 840 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 841 FilePath path(temp_dir_.path()); |
| 842 url_index_.reset( |
| 843 new InMemoryURLIndex(NULL, path, "en,ja,hi,zh")); |
| 844 } |
| 845 |
| 846 TEST_F(InMemoryURLIndexCacheTest, CacheFilePath) { |
| 847 FilePath expectedPath = |
| 848 temp_dir_.path().Append(FILE_PATH_LITERAL("History Provider Cache")); |
| 849 std::vector<FilePath::StringType> expected_parts; |
| 850 expectedPath.GetComponents(&expected_parts); |
| 851 FilePath full_file_path; |
| 852 ASSERT_TRUE(url_index_->GetCacheFilePath(&full_file_path)); |
| 853 std::vector<FilePath::StringType> actual_parts; |
| 854 full_file_path.GetComponents(&actual_parts); |
| 855 ASSERT_EQ(expected_parts.size(), actual_parts.size()); |
| 856 size_t count = expected_parts.size(); |
| 857 for (size_t i = 0; i < count; ++i) |
| 858 EXPECT_EQ(expected_parts[i], actual_parts[i]); |
| 859 // Must clear the history_dir_ to satisfy the dtor's DCHECK. |
| 860 url_index_->history_dir_.clear(); |
| 861 } |
| 862 |
| 800 } // namespace history | 863 } // namespace history |
| OLD | NEW |