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

Side by Side Diff: components/omnibox/browser/in_memory_url_index_unittest.cc

Issue 2317123002: c/browser, c/common, components O-P: Change ScopedTempDir::path() to GetPath() (Closed)
Patch Set: Just rebased Created 4 years, 3 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <fstream> 9 #include <fstream>
10 10
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 GetPrivateDataTracker()); 211 GetPrivateDataTracker());
212 } 212 }
213 213
214 bool InMemoryURLIndexTest::DeleteURL(const GURL& url) { 214 bool InMemoryURLIndexTest::DeleteURL(const GURL& url) {
215 return GetPrivateData()->DeleteURL(url); 215 return GetPrivateData()->DeleteURL(url);
216 } 216 }
217 217
218 void InMemoryURLIndexTest::SetUp() { 218 void InMemoryURLIndexTest::SetUp() {
219 // We cannot access the database until the backend has been loaded. 219 // We cannot access the database until the backend has been loaded.
220 if (history_dir_.CreateUniqueTempDir()) 220 if (history_dir_.CreateUniqueTempDir())
221 history_service_ = history::CreateHistoryService(history_dir_.path(), true); 221 history_service_ =
222 history::CreateHistoryService(history_dir_.GetPath(), true);
222 ASSERT_TRUE(history_service_); 223 ASSERT_TRUE(history_service_);
223 BlockUntilInMemoryURLIndexIsRefreshed(url_index_.get()); 224 BlockUntilInMemoryURLIndexIsRefreshed(url_index_.get());
224 225
225 history::HistoryBackend* backend = history_service_->history_backend_.get(); 226 history::HistoryBackend* backend = history_service_->history_backend_.get();
226 history_database_ = backend->db(); 227 history_database_ = backend->db();
227 228
228 // Create and populate a working copy of the URL history database. 229 // Create and populate a working copy of the URL history database.
229 base::FilePath history_proto_path; 230 base::FilePath history_proto_path;
230 PathService::Get(base::DIR_SOURCE_ROOT, &history_proto_path); 231 PathService::Get(base::DIR_SOURCE_ROOT, &history_proto_path);
231 history_proto_path = history_proto_path.AppendASCII("components"); 232 history_proto_path = history_proto_path.AppendASCII("components");
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 const VisitInfoVector& visits = entry->second.visits; 1029 const VisitInfoVector& visits = entry->second.visits;
1029 EXPECT_EQ(10u, visits.size()); 1030 EXPECT_EQ(10u, visits.size());
1030 for (size_t i = 0; i < visits.size(); ++i) 1031 for (size_t i = 0; i < visits.size(); ++i)
1031 EXPECT_EQ(0, static_cast<int32_t>(visits[i].second)); 1032 EXPECT_EQ(0, static_cast<int32_t>(visits[i].second));
1032 } 1033 }
1033 } 1034 }
1034 1035
1035 TEST_F(InMemoryURLIndexTest, CacheSaveRestore) { 1036 TEST_F(InMemoryURLIndexTest, CacheSaveRestore) {
1036 base::ScopedTempDir temp_directory; 1037 base::ScopedTempDir temp_directory;
1037 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); 1038 ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
1038 set_history_dir(temp_directory.path()); 1039 set_history_dir(temp_directory.GetPath());
1039 1040
1040 URLIndexPrivateData& private_data(*GetPrivateData()); 1041 URLIndexPrivateData& private_data(*GetPrivateData());
1041 1042
1042 // Ensure that there is really something there to be saved. 1043 // Ensure that there is really something there to be saved.
1043 EXPECT_FALSE(private_data.word_list_.empty()); 1044 EXPECT_FALSE(private_data.word_list_.empty());
1044 // available_words_ will already be empty since we have freshly built the 1045 // available_words_ will already be empty since we have freshly built the
1045 // data set for this test. 1046 // data set for this test.
1046 EXPECT_TRUE(private_data.available_words_.empty()); 1047 EXPECT_TRUE(private_data.available_words_.empty());
1047 EXPECT_FALSE(private_data.word_map_.empty()); 1048 EXPECT_FALSE(private_data.word_map_.empty());
1048 EXPECT_FALSE(private_data.char_word_map_.empty()); 1049 EXPECT_FALSE(private_data.char_word_map_.empty());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 EXPECT_GT(new_data.restored_cache_version_, 0); 1098 EXPECT_GT(new_data.restored_cache_version_, 0);
1098 EXPECT_EQ(rebuild_time, new_data.last_time_rebuilt_from_history_); 1099 EXPECT_EQ(rebuild_time, new_data.last_time_rebuilt_from_history_);
1099 1100
1100 // Compare the captured and restored for equality. 1101 // Compare the captured and restored for equality.
1101 ExpectPrivateDataEqual(*old_data.get(), new_data); 1102 ExpectPrivateDataEqual(*old_data.get(), new_data);
1102 } 1103 }
1103 1104
1104 TEST_F(InMemoryURLIndexTest, RebuildFromHistoryIfCacheOld) { 1105 TEST_F(InMemoryURLIndexTest, RebuildFromHistoryIfCacheOld) {
1105 base::ScopedTempDir temp_directory; 1106 base::ScopedTempDir temp_directory;
1106 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); 1107 ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
1107 set_history_dir(temp_directory.path()); 1108 set_history_dir(temp_directory.GetPath());
1108 1109
1109 URLIndexPrivateData& private_data(*GetPrivateData()); 1110 URLIndexPrivateData& private_data(*GetPrivateData());
1110 1111
1111 // Ensure that there is really something there to be saved. 1112 // Ensure that there is really something there to be saved.
1112 EXPECT_FALSE(private_data.word_list_.empty()); 1113 EXPECT_FALSE(private_data.word_list_.empty());
1113 // available_words_ will already be empty since we have freshly built the 1114 // available_words_ will already be empty since we have freshly built the
1114 // data set for this test. 1115 // data set for this test.
1115 EXPECT_TRUE(private_data.available_words_.empty()); 1116 EXPECT_TRUE(private_data.available_words_.empty());
1116 EXPECT_FALSE(private_data.word_map_.empty()); 1117 EXPECT_FALSE(private_data.word_map_.empty());
1117 EXPECT_FALSE(private_data.char_word_map_.empty()); 1118 EXPECT_FALSE(private_data.char_word_map_.empty());
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1272 base::SequencedWorkerPoolOwner pool_owner_; 1273 base::SequencedWorkerPoolOwner pool_owner_;
1273 base::ScopedTempDir temp_dir_; 1274 base::ScopedTempDir temp_dir_;
1274 std::unique_ptr<InMemoryURLIndex> url_index_; 1275 std::unique_ptr<InMemoryURLIndex> url_index_;
1275 }; 1276 };
1276 1277
1277 InMemoryURLIndexCacheTest::InMemoryURLIndexCacheTest() 1278 InMemoryURLIndexCacheTest::InMemoryURLIndexCacheTest()
1278 : pool_owner_(3, "Background Pool") {} 1279 : pool_owner_(3, "Background Pool") {}
1279 1280
1280 void InMemoryURLIndexCacheTest::SetUp() { 1281 void InMemoryURLIndexCacheTest::SetUp() {
1281 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 1282 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
1282 base::FilePath path(temp_dir_.path()); 1283 base::FilePath path(temp_dir_.GetPath());
1283 url_index_.reset(new InMemoryURLIndex(nullptr, nullptr, nullptr, 1284 url_index_.reset(new InMemoryURLIndex(nullptr, nullptr, nullptr,
1284 pool_owner_.pool().get(), path, 1285 pool_owner_.pool().get(), path,
1285 SchemeSet())); 1286 SchemeSet()));
1286 } 1287 }
1287 1288
1288 void InMemoryURLIndexCacheTest::TearDown() { 1289 void InMemoryURLIndexCacheTest::TearDown() {
1289 if (url_index_) 1290 if (url_index_)
1290 url_index_->Shutdown(); 1291 url_index_->Shutdown();
1291 } 1292 }
1292 1293
1293 void InMemoryURLIndexCacheTest::set_history_dir( 1294 void InMemoryURLIndexCacheTest::set_history_dir(
1294 const base::FilePath& dir_path) { 1295 const base::FilePath& dir_path) {
1295 return url_index_->set_history_dir(dir_path); 1296 return url_index_->set_history_dir(dir_path);
1296 } 1297 }
1297 1298
1298 bool InMemoryURLIndexCacheTest::GetCacheFilePath( 1299 bool InMemoryURLIndexCacheTest::GetCacheFilePath(
1299 base::FilePath* file_path) const { 1300 base::FilePath* file_path) const {
1300 DCHECK(file_path); 1301 DCHECK(file_path);
1301 return url_index_->GetCacheFilePath(file_path); 1302 return url_index_->GetCacheFilePath(file_path);
1302 } 1303 }
1303 1304
1304 TEST_F(InMemoryURLIndexCacheTest, CacheFilePath) { 1305 TEST_F(InMemoryURLIndexCacheTest, CacheFilePath) {
1305 base::FilePath expectedPath = 1306 base::FilePath expectedPath =
1306 temp_dir_.path().Append(FILE_PATH_LITERAL("History Provider Cache")); 1307 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("History Provider Cache"));
1307 std::vector<base::FilePath::StringType> expected_parts; 1308 std::vector<base::FilePath::StringType> expected_parts;
1308 expectedPath.GetComponents(&expected_parts); 1309 expectedPath.GetComponents(&expected_parts);
1309 base::FilePath full_file_path; 1310 base::FilePath full_file_path;
1310 ASSERT_TRUE(GetCacheFilePath(&full_file_path)); 1311 ASSERT_TRUE(GetCacheFilePath(&full_file_path));
1311 std::vector<base::FilePath::StringType> actual_parts; 1312 std::vector<base::FilePath::StringType> actual_parts;
1312 full_file_path.GetComponents(&actual_parts); 1313 full_file_path.GetComponents(&actual_parts);
1313 ASSERT_EQ(expected_parts.size(), actual_parts.size()); 1314 ASSERT_EQ(expected_parts.size(), actual_parts.size());
1314 size_t count = expected_parts.size(); 1315 size_t count = expected_parts.size();
1315 for (size_t i = 0; i < count; ++i) 1316 for (size_t i = 0; i < count; ++i)
1316 EXPECT_EQ(expected_parts[i], actual_parts[i]); 1317 EXPECT_EQ(expected_parts[i], actual_parts[i]);
1317 // Must clear the history_dir_ to satisfy the dtor's DCHECK. 1318 // Must clear the history_dir_ to satisfy the dtor's DCHECK.
1318 set_history_dir(base::FilePath()); 1319 set_history_dir(base::FilePath());
1319 } 1320 }
OLDNEW
« no previous file with comments | « components/omnibox/browser/history_url_provider_unittest.cc ('k') | components/omnibox/browser/shortcuts_backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698