| 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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 history_database_->FillVisitRow(statement, &row); | 280 history_database_->FillVisitRow(statement, &row); |
| 281 base::Time last_visit = time_right_now; | 281 base::Time last_visit = time_right_now; |
| 282 for (int64 i = row.visit_time.ToInternalValue(); i > 0; --i) | 282 for (int64 i = row.visit_time.ToInternalValue(); i > 0; --i) |
| 283 last_visit -= day_delta; | 283 last_visit -= day_delta; |
| 284 row.visit_time = last_visit; | 284 row.visit_time = last_visit; |
| 285 history_database_->UpdateVisitRow(row); | 285 history_database_->UpdateVisitRow(row); |
| 286 } | 286 } |
| 287 transaction.Commit(); | 287 transaction.Commit(); |
| 288 } | 288 } |
| 289 | 289 |
| 290 url_index_.reset(new InMemoryURLIndex( | 290 url_index_.reset(new InMemoryURLIndex(&profile_, |
| 291 &profile_, base::FilePath(), "en,ja,hi,zh", | 291 history_service_, |
| 292 history_service_->history_client())); | 292 base::FilePath(), |
| 293 "en,ja,hi,zh", |
| 294 history_service_->history_client())); |
| 293 url_index_->Init(); | 295 url_index_->Init(); |
| 294 url_index_->RebuildFromHistory(history_database_); | 296 url_index_->RebuildFromHistory(history_database_); |
| 295 } | 297 } |
| 296 | 298 |
| 297 base::FilePath::StringType InMemoryURLIndexTest::TestDBName() const { | 299 base::FilePath::StringType InMemoryURLIndexTest::TestDBName() const { |
| 298 return FILE_PATH_LITERAL("url_history_provider_test.db.txt"); | 300 return FILE_PATH_LITERAL("url_history_provider_test.db.txt"); |
| 299 } | 301 } |
| 300 | 302 |
| 301 void InMemoryURLIndexTest::CheckTerm( | 303 void InMemoryURLIndexTest::CheckTerm( |
| 302 const URLIndexPrivateData::SearchTermCacheMap& cache, | 304 const URLIndexPrivateData::SearchTermCacheMap& cache, |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 } | 441 } |
| 440 | 442 |
| 441 TEST_F(LimitedInMemoryURLIndexTest, Initialization) { | 443 TEST_F(LimitedInMemoryURLIndexTest, Initialization) { |
| 442 // Verify that the database contains the expected number of items, which | 444 // Verify that the database contains the expected number of items, which |
| 443 // is the pre-filtered count, i.e. all of the items. | 445 // is the pre-filtered count, i.e. all of the items. |
| 444 sql::Statement statement(GetDB().GetUniqueStatement("SELECT * FROM urls;")); | 446 sql::Statement statement(GetDB().GetUniqueStatement("SELECT * FROM urls;")); |
| 445 ASSERT_TRUE(statement.is_valid()); | 447 ASSERT_TRUE(statement.is_valid()); |
| 446 uint64 row_count = 0; | 448 uint64 row_count = 0; |
| 447 while (statement.Step()) ++row_count; | 449 while (statement.Step()) ++row_count; |
| 448 EXPECT_EQ(1U, row_count); | 450 EXPECT_EQ(1U, row_count); |
| 449 url_index_.reset(new InMemoryURLIndex( | 451 url_index_.reset(new InMemoryURLIndex(&profile_, |
| 450 &profile_, base::FilePath(), "en,ja,hi,zh", | 452 history_service_, |
| 451 history_service_->history_client())); | 453 base::FilePath(), |
| 454 "en,ja,hi,zh", |
| 455 history_service_->history_client())); |
| 452 url_index_->Init(); | 456 url_index_->Init(); |
| 453 url_index_->RebuildFromHistory(history_database_); | 457 url_index_->RebuildFromHistory(history_database_); |
| 454 URLIndexPrivateData& private_data(*GetPrivateData()); | 458 URLIndexPrivateData& private_data(*GetPrivateData()); |
| 455 | 459 |
| 456 // history_info_map_ should have the same number of items as were filtered. | 460 // history_info_map_ should have the same number of items as were filtered. |
| 457 EXPECT_EQ(1U, private_data.history_info_map_.size()); | 461 EXPECT_EQ(1U, private_data.history_info_map_.size()); |
| 458 EXPECT_EQ(35U, private_data.char_word_map_.size()); | 462 EXPECT_EQ(35U, private_data.char_word_map_.size()); |
| 459 EXPECT_EQ(17U, private_data.word_map_.size()); | 463 EXPECT_EQ(17U, private_data.word_map_.size()); |
| 460 } | 464 } |
| 461 | 465 |
| (...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1193 | 1197 |
| 1194 base::ScopedTempDir temp_dir_; | 1198 base::ScopedTempDir temp_dir_; |
| 1195 scoped_ptr<InMemoryURLIndex> url_index_; | 1199 scoped_ptr<InMemoryURLIndex> url_index_; |
| 1196 }; | 1200 }; |
| 1197 | 1201 |
| 1198 void InMemoryURLIndexCacheTest::SetUp() { | 1202 void InMemoryURLIndexCacheTest::SetUp() { |
| 1199 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 1203 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 1200 HistoryClient history_client; | 1204 HistoryClient history_client; |
| 1201 base::FilePath path(temp_dir_.path()); | 1205 base::FilePath path(temp_dir_.path()); |
| 1202 url_index_.reset(new InMemoryURLIndex( | 1206 url_index_.reset(new InMemoryURLIndex( |
| 1203 NULL, path, "en,ja,hi,zh", &history_client)); | 1207 NULL, nullptr, path, "en,ja,hi,zh", &history_client)); |
| 1204 } | 1208 } |
| 1205 | 1209 |
| 1206 void InMemoryURLIndexCacheTest::set_history_dir( | 1210 void InMemoryURLIndexCacheTest::set_history_dir( |
| 1207 const base::FilePath& dir_path) { | 1211 const base::FilePath& dir_path) { |
| 1208 return url_index_->set_history_dir(dir_path); | 1212 return url_index_->set_history_dir(dir_path); |
| 1209 } | 1213 } |
| 1210 | 1214 |
| 1211 bool InMemoryURLIndexCacheTest::GetCacheFilePath( | 1215 bool InMemoryURLIndexCacheTest::GetCacheFilePath( |
| 1212 base::FilePath* file_path) const { | 1216 base::FilePath* file_path) const { |
| 1213 DCHECK(file_path); | 1217 DCHECK(file_path); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1225 full_file_path.GetComponents(&actual_parts); | 1229 full_file_path.GetComponents(&actual_parts); |
| 1226 ASSERT_EQ(expected_parts.size(), actual_parts.size()); | 1230 ASSERT_EQ(expected_parts.size(), actual_parts.size()); |
| 1227 size_t count = expected_parts.size(); | 1231 size_t count = expected_parts.size(); |
| 1228 for (size_t i = 0; i < count; ++i) | 1232 for (size_t i = 0; i < count; ++i) |
| 1229 EXPECT_EQ(expected_parts[i], actual_parts[i]); | 1233 EXPECT_EQ(expected_parts[i], actual_parts[i]); |
| 1230 // Must clear the history_dir_ to satisfy the dtor's DCHECK. | 1234 // Must clear the history_dir_ to satisfy the dtor's DCHECK. |
| 1231 set_history_dir(base::FilePath()); | 1235 set_history_dir(base::FilePath()); |
| 1232 } | 1236 } |
| 1233 | 1237 |
| 1234 } // namespace history | 1238 } // namespace history |
| OLD | NEW |