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

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

Issue 285233012: Abstract history dependencies on bookmarks through HistoryClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addresss comments & rebase Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 #include <fstream> 6 #include <fstream>
7 7
8 #include "base/auto_reset.h" 8 #include "base/auto_reset.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 10 matching lines...) Expand all
21 #include "chrome/browser/history/history_notifications.h" 21 #include "chrome/browser/history/history_notifications.h"
22 #include "chrome/browser/history/history_service.h" 22 #include "chrome/browser/history/history_service.h"
23 #include "chrome/browser/history/history_service_factory.h" 23 #include "chrome/browser/history/history_service_factory.h"
24 #include "chrome/browser/history/in_memory_url_index.h" 24 #include "chrome/browser/history/in_memory_url_index.h"
25 #include "chrome/browser/history/in_memory_url_index_types.h" 25 #include "chrome/browser/history/in_memory_url_index_types.h"
26 #include "chrome/browser/history/url_index_private_data.h" 26 #include "chrome/browser/history/url_index_private_data.h"
27 #include "chrome/common/chrome_paths.h" 27 #include "chrome/common/chrome_paths.h"
28 #include "chrome/test/base/history_index_restore_observer.h" 28 #include "chrome/test/base/history_index_restore_observer.h"
29 #include "chrome/test/base/testing_profile.h" 29 #include "chrome/test/base/testing_profile.h"
30 #include "components/bookmarks/test/bookmark_test_helpers.h" 30 #include "components/bookmarks/test/bookmark_test_helpers.h"
31 #include "components/history/core/browser/history_client.h"
31 #include "content/public/browser/notification_details.h" 32 #include "content/public/browser/notification_details.h"
32 #include "content/public/browser/notification_source.h" 33 #include "content/public/browser/notification_source.h"
33 #include "content/public/test/test_browser_thread.h" 34 #include "content/public/test/test_browser_thread.h"
34 #include "sql/transaction.h" 35 #include "sql/transaction.h"
35 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
36 37
37 using base::ASCIIToUTF16; 38 using base::ASCIIToUTF16;
38 using content::BrowserThread; 39 using content::BrowserThread;
39 40
40 namespace { 41 namespace {
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 history_database_->FillVisitRow(statement, &row); 271 history_database_->FillVisitRow(statement, &row);
271 base::Time last_visit = time_right_now; 272 base::Time last_visit = time_right_now;
272 for (int64 i = row.visit_time.ToInternalValue(); i > 0; --i) 273 for (int64 i = row.visit_time.ToInternalValue(); i > 0; --i)
273 last_visit -= day_delta; 274 last_visit -= day_delta;
274 row.visit_time = last_visit; 275 row.visit_time = last_visit;
275 history_database_->UpdateVisitRow(row); 276 history_database_->UpdateVisitRow(row);
276 } 277 }
277 transaction.Commit(); 278 transaction.Commit();
278 } 279 }
279 280
280 url_index_.reset( 281 url_index_.reset(new InMemoryURLIndex(
281 new InMemoryURLIndex(&profile_, base::FilePath(), "en,ja,hi,zh")); 282 &profile_, base::FilePath(), "en,ja,hi,zh",
283 history_service_->history_client()));
282 url_index_->Init(); 284 url_index_->Init();
283 url_index_->RebuildFromHistory(history_database_); 285 url_index_->RebuildFromHistory(history_database_);
284 } 286 }
285 287
286 base::FilePath::StringType InMemoryURLIndexTest::TestDBName() const { 288 base::FilePath::StringType InMemoryURLIndexTest::TestDBName() const {
287 return FILE_PATH_LITERAL("url_history_provider_test.db.txt"); 289 return FILE_PATH_LITERAL("url_history_provider_test.db.txt");
288 } 290 }
289 291
290 void InMemoryURLIndexTest::CheckTerm( 292 void InMemoryURLIndexTest::CheckTerm(
291 const URLIndexPrivateData::SearchTermCacheMap& cache, 293 const URLIndexPrivateData::SearchTermCacheMap& cache,
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 } 430 }
429 431
430 TEST_F(LimitedInMemoryURLIndexTest, Initialization) { 432 TEST_F(LimitedInMemoryURLIndexTest, Initialization) {
431 // Verify that the database contains the expected number of items, which 433 // Verify that the database contains the expected number of items, which
432 // is the pre-filtered count, i.e. all of the items. 434 // is the pre-filtered count, i.e. all of the items.
433 sql::Statement statement(GetDB().GetUniqueStatement("SELECT * FROM urls;")); 435 sql::Statement statement(GetDB().GetUniqueStatement("SELECT * FROM urls;"));
434 ASSERT_TRUE(statement.is_valid()); 436 ASSERT_TRUE(statement.is_valid());
435 uint64 row_count = 0; 437 uint64 row_count = 0;
436 while (statement.Step()) ++row_count; 438 while (statement.Step()) ++row_count;
437 EXPECT_EQ(1U, row_count); 439 EXPECT_EQ(1U, row_count);
438 url_index_.reset( 440 url_index_.reset(new InMemoryURLIndex(
439 new InMemoryURLIndex(&profile_, base::FilePath(), "en,ja,hi,zh")); 441 &profile_, base::FilePath(), "en,ja,hi,zh",
442 history_service_->history_client()));
440 url_index_->Init(); 443 url_index_->Init();
441 url_index_->RebuildFromHistory(history_database_); 444 url_index_->RebuildFromHistory(history_database_);
442 URLIndexPrivateData& private_data(*GetPrivateData()); 445 URLIndexPrivateData& private_data(*GetPrivateData());
443 446
444 // history_info_map_ should have the same number of items as were filtered. 447 // history_info_map_ should have the same number of items as were filtered.
445 EXPECT_EQ(1U, private_data.history_info_map_.size()); 448 EXPECT_EQ(1U, private_data.history_info_map_.size());
446 EXPECT_EQ(35U, private_data.char_word_map_.size()); 449 EXPECT_EQ(35U, private_data.char_word_map_.size());
447 EXPECT_EQ(17U, private_data.word_map_.size()); 450 EXPECT_EQ(17U, private_data.word_map_.size());
448 } 451 }
449 452
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 // Pass-through functions to simplify our friendship with InMemoryURLIndex. 1153 // Pass-through functions to simplify our friendship with InMemoryURLIndex.
1151 void set_history_dir(const base::FilePath& dir_path); 1154 void set_history_dir(const base::FilePath& dir_path);
1152 bool GetCacheFilePath(base::FilePath* file_path) const; 1155 bool GetCacheFilePath(base::FilePath* file_path) const;
1153 1156
1154 base::ScopedTempDir temp_dir_; 1157 base::ScopedTempDir temp_dir_;
1155 scoped_ptr<InMemoryURLIndex> url_index_; 1158 scoped_ptr<InMemoryURLIndex> url_index_;
1156 }; 1159 };
1157 1160
1158 void InMemoryURLIndexCacheTest::SetUp() { 1161 void InMemoryURLIndexCacheTest::SetUp() {
1159 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 1162 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
1163 HistoryClient history_client;
1160 base::FilePath path(temp_dir_.path()); 1164 base::FilePath path(temp_dir_.path());
1161 url_index_.reset( 1165 url_index_.reset(new InMemoryURLIndex(
1162 new InMemoryURLIndex(NULL, path, "en,ja,hi,zh")); 1166 NULL, path, "en,ja,hi,zh", &history_client));
1163 } 1167 }
1164 1168
1165 void InMemoryURLIndexCacheTest::set_history_dir( 1169 void InMemoryURLIndexCacheTest::set_history_dir(
1166 const base::FilePath& dir_path) { 1170 const base::FilePath& dir_path) {
1167 return url_index_->set_history_dir(dir_path); 1171 return url_index_->set_history_dir(dir_path);
1168 } 1172 }
1169 1173
1170 bool InMemoryURLIndexCacheTest::GetCacheFilePath( 1174 bool InMemoryURLIndexCacheTest::GetCacheFilePath(
1171 base::FilePath* file_path) const { 1175 base::FilePath* file_path) const {
1172 DCHECK(file_path); 1176 DCHECK(file_path);
(...skipping 11 matching lines...) Expand all
1184 full_file_path.GetComponents(&actual_parts); 1188 full_file_path.GetComponents(&actual_parts);
1185 ASSERT_EQ(expected_parts.size(), actual_parts.size()); 1189 ASSERT_EQ(expected_parts.size(), actual_parts.size());
1186 size_t count = expected_parts.size(); 1190 size_t count = expected_parts.size();
1187 for (size_t i = 0; i < count; ++i) 1191 for (size_t i = 0; i < count; ++i)
1188 EXPECT_EQ(expected_parts[i], actual_parts[i]); 1192 EXPECT_EQ(expected_parts[i], actual_parts[i]);
1189 // Must clear the history_dir_ to satisfy the dtor's DCHECK. 1193 // Must clear the history_dir_ to satisfy the dtor's DCHECK.
1190 set_history_dir(base::FilePath()); 1194 set_history_dir(base::FilePath());
1191 } 1195 }
1192 1196
1193 } // namespace history 1197 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698