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

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

Issue 9030031: Move InMemoryURLIndex Caching Operations to FILE Thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
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 <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/message_loop.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/scoped_temp_dir.h"
11 #include "base/string_util.h" 12 #include "base/string_util.h"
12 #include "base/string16.h" 13 #include "base/string16.h"
13 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/autocomplete/autocomplete.h" 15 #include "chrome/browser/autocomplete/autocomplete.h"
15 #include "chrome/browser/history/history.h" 16 #include "chrome/browser/history/history.h"
16 #include "chrome/browser/history/history_backend.h" 17 #include "chrome/browser/history/history_backend.h"
17 #include "chrome/browser/history/history_database.h" 18 #include "chrome/browser/history/history_database.h"
18 #include "chrome/browser/history/in_memory_url_index_types.h" 19 #include "chrome/browser/history/in_memory_url_index_types.h"
19 #include "chrome/browser/history/in_memory_url_index.h" 20 #include "chrome/browser/history/in_memory_url_index.h"
20 #include "chrome/browser/history/url_index_private_data.h" 21 #include "chrome/browser/history/url_index_private_data.h"
21 #include "chrome/common/chrome_paths.h" 22 #include "chrome/common/chrome_paths.h"
22 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
23 #include "content/test/test_browser_thread.h" 24 #include "content/test/test_browser_thread.h"
24 #include "sql/transaction.h" 25 #include "sql/transaction.h"
25 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
26 27
28 using content::BrowserThread;
29
27 // The test version of the history url database table ('url') is contained in 30 // The test version of the history url database table ('url') is contained in
28 // a database file created from a text file('url_history_provider_test.db.txt'). 31 // a database file created from a text file('url_history_provider_test.db.txt').
29 // The only difference between this table and a live 'urls' table from a 32 // The only difference between this table and a live 'urls' table from a
30 // profile is that the last_visit_time column in the test table contains a 33 // profile is that the last_visit_time column in the test table contains a
31 // number specifying the number of days relative to 'today' to which the 34 // number specifying the number of days relative to 'today' to which the
32 // absolute time should be set during the test setup stage. 35 // absolute time should be set during the test setup stage.
33 // 36 //
34 // The format of the test database text file is of a SQLite .dump file. 37 // The format of the test database text file is of a SQLite .dump file.
35 // Note that only lines whose first character is an upper-case letter are 38 // Note that only lines whose first character is an upper-case letter are
36 // processed when creating the test database. 39 // processed when creating the test database.
37 40
38 namespace history { 41 namespace history {
39 42
43 // -----------------------------------------------------------------------------
44
45 // Observer class so the unit tests can wait while the cache is being saved.
46 class CacheFileSaverObserver : public InMemoryURLIndex::SaveCacheObserver {
47 public:
48 explicit CacheFileSaverObserver(MessageLoop* loop);
49 virtual void OnCacheSaveFinished(bool succeeded) OVERRIDE;
50
51 MessageLoop* loop_;
52 bool succeeded_;
53 DISALLOW_COPY_AND_ASSIGN(CacheFileSaverObserver);
54 };
55
56 CacheFileSaverObserver::CacheFileSaverObserver(MessageLoop* loop)
57 : loop_(loop),
58 succeeded_(false) {
59 DCHECK(loop);
60 }
61
62 void CacheFileSaverObserver::OnCacheSaveFinished(bool succeeded) {
63 succeeded_ = succeeded;
64 loop_->Quit();
65 }
66
67 // Observer class so the unit tests can wait while the cache is being restored.
68 class CacheFileReaderObserver : public InMemoryURLIndex::RestoreCacheObserver {
69 public:
70 explicit CacheFileReaderObserver(MessageLoop* loop);
71 virtual void OnCacheRestoreFinished(bool succeeded) OVERRIDE;
72
73 MessageLoop* loop_;
74 bool succeeded_;
75 DISALLOW_COPY_AND_ASSIGN(CacheFileReaderObserver);
76 };
77
78 CacheFileReaderObserver::CacheFileReaderObserver(MessageLoop* loop)
79 : loop_(loop),
80 succeeded_(false) {
81 DCHECK(loop);
82 }
83
84 void CacheFileReaderObserver::OnCacheRestoreFinished(bool succeeded) {
85 succeeded_ = succeeded;
86 loop_->Quit();
87 }
88
89 // -----------------------------------------------------------------------------
90
40 class InMemoryURLIndexTest : public testing::Test { 91 class InMemoryURLIndexTest : public testing::Test {
41 public: 92 public:
42 InMemoryURLIndexTest(); 93 InMemoryURLIndexTest();
43 94
44 protected: 95 protected:
45 // Test setup. 96 // Test setup.
46 virtual void SetUp(); 97 virtual void SetUp();
47 98
48 // Allows the database containing the test data to be customized by 99 // Allows the database containing the test data to be customized by
49 // subclasses. 100 // subclasses.
(...skipping 15 matching lines...) Expand all
65 // Validates that the given |term| is contained in |cache| and that it is 116 // Validates that the given |term| is contained in |cache| and that it is
66 // marked as in-use. 117 // marked as in-use.
67 void CheckTerm(const URLIndexPrivateData::SearchTermCacheMap& cache, 118 void CheckTerm(const URLIndexPrivateData::SearchTermCacheMap& cache,
68 string16 term) const; 119 string16 term) const;
69 120
70 // Pass-through function to simplify our friendship with HistoryService. 121 // Pass-through function to simplify our friendship with HistoryService.
71 sql::Connection& GetDB(); 122 sql::Connection& GetDB();
72 123
73 // Pass-through functions to simplify our friendship with InMemoryURLIndex. 124 // Pass-through functions to simplify our friendship with InMemoryURLIndex.
74 URLIndexPrivateData* GetPrivateData() const; 125 URLIndexPrivateData* GetPrivateData() const;
126 void ClearPrivateData();
127 void set_history_dir(const FilePath& dir_path);
75 bool GetCacheFilePath(FilePath* file_path) const; 128 bool GetCacheFilePath(FilePath* file_path) const;
76 void ClearHistoryDir() const; 129 void PostRestoreFromCacheFileTask();
130 void PostSaveToCacheFileTask();
77 131
78 // Pass-through functions to simplify our friendship with URLIndexPrivateData. 132 // Pass-through functions to simplify our friendship with URLIndexPrivateData.
79 bool UpdateURL(const URLRow& row); 133 bool UpdateURL(const URLRow& row);
80 bool DeleteURL(const GURL& url); 134 bool DeleteURL(const GURL& url);
81 135
82 MessageLoopForUI message_loop_; 136 MessageLoopForUI message_loop_;
83 content::TestBrowserThread ui_thread_; 137 content::TestBrowserThread ui_thread_;
84 content::TestBrowserThread file_thread_; 138 content::TestBrowserThread file_thread_;
85 TestingProfile profile_; 139 TestingProfile profile_;
86 140
87 scoped_ptr<InMemoryURLIndex> url_index_; 141 scoped_ptr<InMemoryURLIndex> url_index_;
88 HistoryDatabase* history_database_; 142 HistoryDatabase* history_database_;
89 }; 143 };
90 144
91 InMemoryURLIndexTest::InMemoryURLIndexTest() 145 InMemoryURLIndexTest::InMemoryURLIndexTest()
92 : ui_thread_(content::BrowserThread::UI, &message_loop_), 146 : ui_thread_(content::BrowserThread::UI, &message_loop_),
93 file_thread_(content::BrowserThread::FILE, &message_loop_) { 147 file_thread_(content::BrowserThread::FILE, &message_loop_) {
94 } 148 }
95 149
96 sql::Connection& InMemoryURLIndexTest::GetDB() { 150 sql::Connection& InMemoryURLIndexTest::GetDB() {
97 return history_database_->GetDB(); 151 return history_database_->GetDB();
98 } 152 }
99 153
100 URLIndexPrivateData* InMemoryURLIndexTest::GetPrivateData() const { 154 URLIndexPrivateData* InMemoryURLIndexTest::GetPrivateData() const {
101 DCHECK(url_index_->private_data_.get()); 155 DCHECK(url_index_->private_data());
102 return url_index_->private_data_.get(); 156 return url_index_->private_data();
157 }
158
159 void InMemoryURLIndexTest::ClearPrivateData() {
160 return url_index_->ClearPrivateData();
161 }
162
163 void InMemoryURLIndexTest::set_history_dir(const FilePath& dir_path) {
164 return url_index_->set_history_dir(dir_path);
103 } 165 }
104 166
105 bool InMemoryURLIndexTest::GetCacheFilePath(FilePath* file_path) const { 167 bool InMemoryURLIndexTest::GetCacheFilePath(FilePath* file_path) const {
106 DCHECK(file_path); 168 DCHECK(file_path);
107 return url_index_->GetCacheFilePath(file_path); 169 return url_index_->GetCacheFilePath(file_path);
108 } 170 }
109 171
110 void InMemoryURLIndexTest::ClearHistoryDir() const { 172 void InMemoryURLIndexTest::PostRestoreFromCacheFileTask() {
111 url_index_->history_dir_.clear(); 173 url_index_->PostRestoreFromCacheFileTask();
174 }
175
176 void InMemoryURLIndexTest::PostSaveToCacheFileTask() {
177 url_index_->PostSaveToCacheFileTask();
112 } 178 }
113 179
114 bool InMemoryURLIndexTest::UpdateURL(const URLRow& row) { 180 bool InMemoryURLIndexTest::UpdateURL(const URLRow& row) {
115 return url_index_->private_data_->UpdateURL(row); 181 return GetPrivateData()->UpdateURL(row);
116 } 182 }
117 183
118 bool InMemoryURLIndexTest::DeleteURL(const GURL& url) { 184 bool InMemoryURLIndexTest::DeleteURL(const GURL& url) {
119 return url_index_->private_data_->DeleteURL(url); 185 return GetPrivateData()->DeleteURL(url);
120 } 186 }
121 187
122 void InMemoryURLIndexTest::SetUp() { 188 void InMemoryURLIndexTest::SetUp() {
123 // We cannot access the database until the backend has been loaded. 189 // We cannot access the database until the backend has been loaded.
124 profile_.CreateHistoryService(true, false); 190 profile_.CreateHistoryService(true, false);
125 profile_.CreateBookmarkModel(true); 191 profile_.CreateBookmarkModel(true);
126 profile_.BlockUntilBookmarkModelLoaded(); 192 profile_.BlockUntilBookmarkModelLoaded();
127 profile_.BlockUntilHistoryProcessesPendingRequests(); 193 profile_.BlockUntilHistoryProcessesPendingRequests();
128 HistoryService* history_service = 194 HistoryService* history_service =
129 profile_.GetHistoryService(Profile::EXPLICIT_ACCESS); 195 profile_.GetHistoryService(Profile::EXPLICIT_ACCESS);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 FilePath::StringType TestDBName() const; 328 FilePath::StringType TestDBName() const;
263 }; 329 };
264 330
265 FilePath::StringType LimitedInMemoryURLIndexTest::TestDBName() const { 331 FilePath::StringType LimitedInMemoryURLIndexTest::TestDBName() const {
266 return FILE_PATH_LITERAL("url_history_provider_test_limited.db.txt"); 332 return FILE_PATH_LITERAL("url_history_provider_test_limited.db.txt");
267 } 333 }
268 334
269 TEST_F(LimitedInMemoryURLIndexTest, Initialization) { 335 TEST_F(LimitedInMemoryURLIndexTest, Initialization) {
270 // Verify that the database contains the expected number of items, which 336 // Verify that the database contains the expected number of items, which
271 // is the pre-filtered count, i.e. all of the items. 337 // is the pre-filtered count, i.e. all of the items.
272 sql::Connection& db(GetDB()); 338 sql::Statement statement(GetDB().GetUniqueStatement("SELECT * FROM urls;"));
273 sql::Statement statement(db.GetUniqueStatement("SELECT * FROM urls;"));
274 ASSERT_TRUE(statement.is_valid()); 339 ASSERT_TRUE(statement.is_valid());
275 uint64 row_count = 0; 340 uint64 row_count = 0;
276 while (statement.Step()) ++row_count; 341 while (statement.Step()) ++row_count;
277 EXPECT_EQ(1U, row_count); 342 EXPECT_EQ(1U, row_count);
278 url_index_.reset( 343 url_index_.reset(
279 new InMemoryURLIndex(&profile_, FilePath(), "en,ja,hi,zh")); 344 new InMemoryURLIndex(&profile_, FilePath(), "en,ja,hi,zh"));
280 url_index_->Init(); 345 url_index_->Init();
281 url_index_->RebuildFromHistory(history_database_); 346 url_index_->RebuildFromHistory(history_database_);
282 URLIndexPrivateData& private_data(*(url_index_->private_data_)); 347 URLIndexPrivateData& private_data(*GetPrivateData());
283 348
284 // history_info_map_ should have the same number of items as were filtered. 349 // history_info_map_ should have the same number of items as were filtered.
285 EXPECT_EQ(1U, private_data.history_info_map_.size()); 350 EXPECT_EQ(1U, private_data.history_info_map_.size());
286 EXPECT_EQ(35U, private_data.char_word_map_.size()); 351 EXPECT_EQ(35U, private_data.char_word_map_.size());
287 EXPECT_EQ(17U, private_data.word_map_.size()); 352 EXPECT_EQ(17U, private_data.word_map_.size());
288 } 353 }
289 354
290 TEST_F(InMemoryURLIndexTest, Retrieval) { 355 TEST_F(InMemoryURLIndexTest, Retrieval) {
291 // See if a very specific term gives a single result. 356 // See if a very specific term gives a single result.
292 ScoredHistoryMatches matches = 357 ScoredHistoryMatches matches =
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 811
747 URLIndexPrivateData& private_data(*GetPrivateData()); 812 URLIndexPrivateData& private_data(*GetPrivateData());
748 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { 813 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) {
749 GURL url(data[i].url_spec); 814 GURL url(data[i].url_spec);
750 EXPECT_EQ(data[i].expected_is_whitelisted, 815 EXPECT_EQ(data[i].expected_is_whitelisted,
751 private_data.URLSchemeIsWhitelisted(url)); 816 private_data.URLSchemeIsWhitelisted(url));
752 } 817 }
753 } 818 }
754 819
755 TEST_F(InMemoryURLIndexTest, CacheSaveRestore) { 820 TEST_F(InMemoryURLIndexTest, CacheSaveRestore) {
756 // Save the cache to a protobuf, restore it, and compare the results. 821 ScopedTempDir temp_directory;
757 in_memory_url_index::InMemoryURLIndexCacheItem index_cache; 822 ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
823 set_history_dir(temp_directory.path());
824
758 URLIndexPrivateData& private_data(*GetPrivateData()); 825 URLIndexPrivateData& private_data(*GetPrivateData());
759 private_data.SavePrivateData(&index_cache);
760 826
761 // Capture our private data so we can later compare for equality. 827 // Ensure that there is really something there to be saved.
762 String16Vector word_list(private_data.word_list_);
763 WordMap word_map(private_data.word_map_);
764 CharWordIDMap char_word_map(private_data.char_word_map_);
765 WordIDHistoryMap word_id_history_map(private_data.word_id_history_map_);
766 HistoryIDWordMap history_id_word_map(private_data.history_id_word_map_);
767 HistoryInfoMap history_info_map(private_data.history_info_map_);
768
769 // Prove that there is really something there.
770 EXPECT_FALSE(private_data.word_list_.empty()); 828 EXPECT_FALSE(private_data.word_list_.empty());
771 // available_words_ will already be empty since we have freshly built the 829 // available_words_ will already be empty since we have freshly built the
772 // data set for this test. 830 // data set for this test.
773 EXPECT_TRUE(private_data.available_words_.empty()); 831 EXPECT_TRUE(private_data.available_words_.empty());
774 EXPECT_FALSE(private_data.word_map_.empty()); 832 EXPECT_FALSE(private_data.word_map_.empty());
775 EXPECT_FALSE(private_data.char_word_map_.empty()); 833 EXPECT_FALSE(private_data.char_word_map_.empty());
776 EXPECT_FALSE(private_data.word_id_history_map_.empty()); 834 EXPECT_FALSE(private_data.word_id_history_map_.empty());
777 EXPECT_FALSE(private_data.history_id_word_map_.empty()); 835 EXPECT_FALSE(private_data.history_id_word_map_.empty());
778 EXPECT_FALSE(private_data.history_info_map_.empty()); 836 EXPECT_FALSE(private_data.history_info_map_.empty());
779 837
780 // Clear and then prove it's clear. 838 // Capture the current private data for later comparison to restored data.
781 private_data.Clear(); 839 URLIndexPrivateData old_data(private_data);
840
841 // Save then restore our private data.
842 CacheFileSaverObserver save_observer(&message_loop_);
843 url_index_->set_save_cache_observer(&save_observer);
844 PostSaveToCacheFileTask();
845 message_loop_.Run();
846 EXPECT_TRUE(save_observer.succeeded_);
847
848 // Clear and then prove it's clear before restoring.
849 ClearPrivateData();
782 EXPECT_TRUE(private_data.word_list_.empty()); 850 EXPECT_TRUE(private_data.word_list_.empty());
783 EXPECT_TRUE(private_data.available_words_.empty()); 851 EXPECT_TRUE(private_data.available_words_.empty());
784 EXPECT_TRUE(private_data.word_map_.empty()); 852 EXPECT_TRUE(private_data.word_map_.empty());
785 EXPECT_TRUE(private_data.char_word_map_.empty()); 853 EXPECT_TRUE(private_data.char_word_map_.empty());
786 EXPECT_TRUE(private_data.word_id_history_map_.empty()); 854 EXPECT_TRUE(private_data.word_id_history_map_.empty());
787 EXPECT_TRUE(private_data.history_id_word_map_.empty()); 855 EXPECT_TRUE(private_data.history_id_word_map_.empty());
788 EXPECT_TRUE(private_data.history_info_map_.empty()); 856 EXPECT_TRUE(private_data.history_info_map_.empty());
789 857
790 // Restore the cache. 858 CacheFileReaderObserver read_observer(&message_loop_);
791 EXPECT_TRUE(private_data.RestorePrivateData(index_cache)); 859 url_index_->set_restore_cache_observer(&read_observer);
860 PostRestoreFromCacheFileTask();
861 message_loop_.Run();
862 EXPECT_TRUE(read_observer.succeeded_);
792 863
793 // Compare the restored and captured for equality. 864 URLIndexPrivateData& new_data(*GetPrivateData());
794 EXPECT_EQ(word_list.size(), private_data.word_list_.size()); 865
795 EXPECT_EQ(word_map.size(), private_data.word_map_.size()); 866 // Compare the captured and restored for equality.
796 EXPECT_EQ(char_word_map.size(), private_data.char_word_map_.size()); 867 EXPECT_EQ(old_data.word_list_.size(), new_data.word_list_.size());
797 EXPECT_EQ(word_id_history_map.size(), 868 EXPECT_EQ(old_data.word_map_.size(), new_data.word_map_.size());
798 private_data.word_id_history_map_.size()); 869 EXPECT_EQ(old_data.char_word_map_.size(), new_data.char_word_map_.size());
799 EXPECT_EQ(history_id_word_map.size(), 870 EXPECT_EQ(old_data.word_id_history_map_.size(),
800 private_data.history_id_word_map_.size()); 871 new_data.word_id_history_map_.size());
801 EXPECT_EQ(history_info_map.size(), private_data.history_info_map_.size()); 872 EXPECT_EQ(old_data.history_id_word_map_.size(),
873 new_data.history_id_word_map_.size());
874 EXPECT_EQ(old_data.history_info_map_.size(),
875 new_data.history_info_map_.size());
802 // WordList must be index-by-index equal. 876 // WordList must be index-by-index equal.
803 size_t count = word_list.size(); 877 size_t count = old_data.word_list_.size();
804 for (size_t i = 0; i < count; ++i) 878 for (size_t i = 0; i < count; ++i)
805 EXPECT_EQ(word_list[i], private_data.word_list_[i]); 879 EXPECT_EQ(old_data.word_list_[i], new_data.word_list_[i]);
806 880
807 ExpectMapOfContainersIdentical(char_word_map, 881 ExpectMapOfContainersIdentical(old_data.char_word_map_,
808 private_data.char_word_map_); 882 new_data.char_word_map_);
809 ExpectMapOfContainersIdentical(word_id_history_map, 883 ExpectMapOfContainersIdentical(old_data.word_id_history_map_,
810 private_data.word_id_history_map_); 884 new_data.word_id_history_map_);
811 ExpectMapOfContainersIdentical(history_id_word_map, 885 ExpectMapOfContainersIdentical(old_data.history_id_word_map_,
812 private_data.history_id_word_map_); 886 new_data.history_id_word_map_);
813 887
814 for (HistoryInfoMap::const_iterator expected = history_info_map.begin(); 888 for (HistoryInfoMap::const_iterator expected =
815 expected != history_info_map.end(); ++expected) { 889 old_data.history_info_map_.begin();
890 expected != old_data.history_info_map_.end(); ++expected) {
816 HistoryInfoMap::const_iterator actual = 891 HistoryInfoMap::const_iterator actual =
817 private_data.history_info_map_.find(expected->first); 892 new_data.history_info_map_.find(expected->first);
818 ASSERT_FALSE(private_data.history_info_map_.end() == actual); 893 ASSERT_FALSE(new_data.history_info_map_.end() == actual);
819 const URLRow& expected_row(expected->second); 894 const URLRow& expected_row(expected->second);
820 const URLRow& actual_row(actual->second); 895 const URLRow& actual_row(actual->second);
821 EXPECT_EQ(expected_row.visit_count(), actual_row.visit_count()); 896 EXPECT_EQ(expected_row.visit_count(), actual_row.visit_count());
822 EXPECT_EQ(expected_row.typed_count(), actual_row.typed_count()); 897 EXPECT_EQ(expected_row.typed_count(), actual_row.typed_count());
823 EXPECT_EQ(expected_row.last_visit(), actual_row.last_visit()); 898 EXPECT_EQ(expected_row.last_visit(), actual_row.last_visit());
824 EXPECT_EQ(expected_row.url(), actual_row.url()); 899 EXPECT_EQ(expected_row.url(), actual_row.url());
825 } 900 }
826 } 901 }
827 902
828 class InMemoryURLIndexCacheTest : public testing::Test { 903 class InMemoryURLIndexCacheTest : public testing::Test {
829 public: 904 public:
830 InMemoryURLIndexCacheTest() {} 905 InMemoryURLIndexCacheTest() {}
831 906
832 protected: 907 protected:
833 virtual void SetUp() OVERRIDE; 908 virtual void SetUp() OVERRIDE;
834 909
910 // Pass-through functions to simplify our friendship with InMemoryURLIndex.
911 void set_history_dir(const FilePath& dir_path);
912 bool GetCacheFilePath(FilePath* file_path) const;
913
835 ScopedTempDir temp_dir_; 914 ScopedTempDir temp_dir_;
836 scoped_ptr<InMemoryURLIndex> url_index_; 915 scoped_ptr<InMemoryURLIndex> url_index_;
837 }; 916 };
838 917
839 void InMemoryURLIndexCacheTest::SetUp() { 918 void InMemoryURLIndexCacheTest::SetUp() {
840 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 919 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
841 FilePath path(temp_dir_.path()); 920 FilePath path(temp_dir_.path());
842 url_index_.reset( 921 url_index_.reset(
843 new InMemoryURLIndex(NULL, path, "en,ja,hi,zh")); 922 new InMemoryURLIndex(NULL, path, "en,ja,hi,zh"));
844 } 923 }
845 924
925 void InMemoryURLIndexCacheTest::set_history_dir(const FilePath& dir_path) {
926 return url_index_->set_history_dir(dir_path);
927 }
928
929 bool InMemoryURLIndexCacheTest::GetCacheFilePath(FilePath* file_path) const {
930 DCHECK(file_path);
931 return url_index_->GetCacheFilePath(file_path);
932 }
933
846 TEST_F(InMemoryURLIndexCacheTest, CacheFilePath) { 934 TEST_F(InMemoryURLIndexCacheTest, CacheFilePath) {
847 FilePath expectedPath = 935 FilePath expectedPath =
848 temp_dir_.path().Append(FILE_PATH_LITERAL("History Provider Cache")); 936 temp_dir_.path().Append(FILE_PATH_LITERAL("History Provider Cache"));
849 std::vector<FilePath::StringType> expected_parts; 937 std::vector<FilePath::StringType> expected_parts;
850 expectedPath.GetComponents(&expected_parts); 938 expectedPath.GetComponents(&expected_parts);
851 FilePath full_file_path; 939 FilePath full_file_path;
852 ASSERT_TRUE(url_index_->GetCacheFilePath(&full_file_path)); 940 ASSERT_TRUE(GetCacheFilePath(&full_file_path));
853 std::vector<FilePath::StringType> actual_parts; 941 std::vector<FilePath::StringType> actual_parts;
854 full_file_path.GetComponents(&actual_parts); 942 full_file_path.GetComponents(&actual_parts);
855 ASSERT_EQ(expected_parts.size(), actual_parts.size()); 943 ASSERT_EQ(expected_parts.size(), actual_parts.size());
856 size_t count = expected_parts.size(); 944 size_t count = expected_parts.size();
857 for (size_t i = 0; i < count; ++i) 945 for (size_t i = 0; i < count; ++i)
858 EXPECT_EQ(expected_parts[i], actual_parts[i]); 946 EXPECT_EQ(expected_parts[i], actual_parts[i]);
859 // Must clear the history_dir_ to satisfy the dtor's DCHECK. 947 // Must clear the history_dir_ to satisfy the dtor's DCHECK.
860 url_index_->history_dir_.clear(); 948 set_history_dir(FilePath());
861 } 949 }
862 950
863 } // namespace history 951 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698