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

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: Fix unit tests Created 6 years, 7 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 11 matching lines...) Expand all
22 #include "chrome/browser/history/history_notifications.h" 22 #include "chrome/browser/history/history_notifications.h"
23 #include "chrome/browser/history/history_service.h" 23 #include "chrome/browser/history/history_service.h"
24 #include "chrome/browser/history/history_service_factory.h" 24 #include "chrome/browser/history/history_service_factory.h"
25 #include "chrome/browser/history/in_memory_url_index.h" 25 #include "chrome/browser/history/in_memory_url_index.h"
26 #include "chrome/browser/history/in_memory_url_index_types.h" 26 #include "chrome/browser/history/in_memory_url_index_types.h"
27 #include "chrome/browser/history/url_index_private_data.h" 27 #include "chrome/browser/history/url_index_private_data.h"
28 #include "chrome/common/chrome_paths.h" 28 #include "chrome/common/chrome_paths.h"
29 #include "chrome/test/base/history_index_restore_observer.h" 29 #include "chrome/test/base/history_index_restore_observer.h"
30 #include "chrome/test/base/testing_profile.h" 30 #include "chrome/test/base/testing_profile.h"
31 #include "components/bookmarks/test/bookmark_test_helpers.h" 31 #include "components/bookmarks/test/bookmark_test_helpers.h"
32 #include "components/history/core/browser/test_history_client.h"
32 #include "content/public/browser/notification_details.h" 33 #include "content/public/browser/notification_details.h"
33 #include "content/public/browser/notification_source.h" 34 #include "content/public/browser/notification_source.h"
34 #include "content/public/test/test_browser_thread.h" 35 #include "content/public/test/test_browser_thread.h"
35 #include "sql/transaction.h" 36 #include "sql/transaction.h"
36 #include "testing/gtest/include/gtest/gtest.h" 37 #include "testing/gtest/include/gtest/gtest.h"
37 38
38 using base::ASCIIToUTF16; 39 using base::ASCIIToUTF16;
39 using content::BrowserThread; 40 using content::BrowserThread;
40 41
41 // The test version of the history url database table ('url') is contained in 42 // The test version of the history url database table ('url') is contained in
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 history_database_->FillVisitRow(statement, &row); 268 history_database_->FillVisitRow(statement, &row);
268 base::Time last_visit = time_right_now; 269 base::Time last_visit = time_right_now;
269 for (int64 i = row.visit_time.ToInternalValue(); i > 0; --i) 270 for (int64 i = row.visit_time.ToInternalValue(); i > 0; --i)
270 last_visit -= day_delta; 271 last_visit -= day_delta;
271 row.visit_time = last_visit; 272 row.visit_time = last_visit;
272 history_database_->UpdateVisitRow(row); 273 history_database_->UpdateVisitRow(row);
273 } 274 }
274 transaction.Commit(); 275 transaction.Commit();
275 } 276 }
276 277
277 url_index_.reset( 278 url_index_.reset(new InMemoryURLIndex(
278 new InMemoryURLIndex(&profile_, base::FilePath(), "en,ja,hi,zh")); 279 &profile_, base::FilePath(), "en,ja,hi,zh",
280 history_service_->history_client()));
279 url_index_->Init(); 281 url_index_->Init();
280 url_index_->RebuildFromHistory(history_database_); 282 url_index_->RebuildFromHistory(history_database_);
281 } 283 }
282 284
283 base::FilePath::StringType InMemoryURLIndexTest::TestDBName() const { 285 base::FilePath::StringType InMemoryURLIndexTest::TestDBName() const {
284 return FILE_PATH_LITERAL("url_history_provider_test.db.txt"); 286 return FILE_PATH_LITERAL("url_history_provider_test.db.txt");
285 } 287 }
286 288
287 void InMemoryURLIndexTest::CheckTerm( 289 void InMemoryURLIndexTest::CheckTerm(
288 const URLIndexPrivateData::SearchTermCacheMap& cache, 290 const URLIndexPrivateData::SearchTermCacheMap& cache,
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 } 427 }
426 428
427 TEST_F(LimitedInMemoryURLIndexTest, Initialization) { 429 TEST_F(LimitedInMemoryURLIndexTest, Initialization) {
428 // Verify that the database contains the expected number of items, which 430 // Verify that the database contains the expected number of items, which
429 // is the pre-filtered count, i.e. all of the items. 431 // is the pre-filtered count, i.e. all of the items.
430 sql::Statement statement(GetDB().GetUniqueStatement("SELECT * FROM urls;")); 432 sql::Statement statement(GetDB().GetUniqueStatement("SELECT * FROM urls;"));
431 ASSERT_TRUE(statement.is_valid()); 433 ASSERT_TRUE(statement.is_valid());
432 uint64 row_count = 0; 434 uint64 row_count = 0;
433 while (statement.Step()) ++row_count; 435 while (statement.Step()) ++row_count;
434 EXPECT_EQ(1U, row_count); 436 EXPECT_EQ(1U, row_count);
435 url_index_.reset( 437 url_index_.reset(new InMemoryURLIndex(
436 new InMemoryURLIndex(&profile_, base::FilePath(), "en,ja,hi,zh")); 438 &profile_, base::FilePath(), "en,ja,hi,zh",
439 history_service_->history_client()));
437 url_index_->Init(); 440 url_index_->Init();
438 url_index_->RebuildFromHistory(history_database_); 441 url_index_->RebuildFromHistory(history_database_);
439 URLIndexPrivateData& private_data(*GetPrivateData()); 442 URLIndexPrivateData& private_data(*GetPrivateData());
440 443
441 // history_info_map_ should have the same number of items as were filtered. 444 // history_info_map_ should have the same number of items as were filtered.
442 EXPECT_EQ(1U, private_data.history_info_map_.size()); 445 EXPECT_EQ(1U, private_data.history_info_map_.size());
443 EXPECT_EQ(35U, private_data.char_word_map_.size()); 446 EXPECT_EQ(35U, private_data.char_word_map_.size());
444 EXPECT_EQ(17U, private_data.word_map_.size()); 447 EXPECT_EQ(17U, private_data.word_map_.size());
445 } 448 }
446 449
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 // Pass-through functions to simplify our friendship with InMemoryURLIndex. 1146 // Pass-through functions to simplify our friendship with InMemoryURLIndex.
1144 void set_history_dir(const base::FilePath& dir_path); 1147 void set_history_dir(const base::FilePath& dir_path);
1145 bool GetCacheFilePath(base::FilePath* file_path) const; 1148 bool GetCacheFilePath(base::FilePath* file_path) const;
1146 1149
1147 base::ScopedTempDir temp_dir_; 1150 base::ScopedTempDir temp_dir_;
1148 scoped_ptr<InMemoryURLIndex> url_index_; 1151 scoped_ptr<InMemoryURLIndex> url_index_;
1149 }; 1152 };
1150 1153
1151 void InMemoryURLIndexCacheTest::SetUp() { 1154 void InMemoryURLIndexCacheTest::SetUp() {
1152 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 1155 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
1156 TestHistoryClient history_client;
1153 base::FilePath path(temp_dir_.path()); 1157 base::FilePath path(temp_dir_.path());
1154 url_index_.reset( 1158 url_index_.reset(new InMemoryURLIndex(
1155 new InMemoryURLIndex(NULL, path, "en,ja,hi,zh")); 1159 NULL, path, "en,ja,hi,zh", &history_client));
1156 } 1160 }
1157 1161
1158 void InMemoryURLIndexCacheTest::set_history_dir( 1162 void InMemoryURLIndexCacheTest::set_history_dir(
1159 const base::FilePath& dir_path) { 1163 const base::FilePath& dir_path) {
1160 return url_index_->set_history_dir(dir_path); 1164 return url_index_->set_history_dir(dir_path);
1161 } 1165 }
1162 1166
1163 bool InMemoryURLIndexCacheTest::GetCacheFilePath( 1167 bool InMemoryURLIndexCacheTest::GetCacheFilePath(
1164 base::FilePath* file_path) const { 1168 base::FilePath* file_path) const {
1165 DCHECK(file_path); 1169 DCHECK(file_path);
(...skipping 11 matching lines...) Expand all
1177 full_file_path.GetComponents(&actual_parts); 1181 full_file_path.GetComponents(&actual_parts);
1178 ASSERT_EQ(expected_parts.size(), actual_parts.size()); 1182 ASSERT_EQ(expected_parts.size(), actual_parts.size());
1179 size_t count = expected_parts.size(); 1183 size_t count = expected_parts.size();
1180 for (size_t i = 0; i < count; ++i) 1184 for (size_t i = 0; i < count; ++i)
1181 EXPECT_EQ(expected_parts[i], actual_parts[i]); 1185 EXPECT_EQ(expected_parts[i], actual_parts[i]);
1182 // Must clear the history_dir_ to satisfy the dtor's DCHECK. 1186 // Must clear the history_dir_ to satisfy the dtor's DCHECK.
1183 set_history_dir(base::FilePath()); 1187 set_history_dir(base::FilePath());
1184 } 1188 }
1185 1189
1186 } // namespace history 1190 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698