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

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: Added missing changed file to CL. 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();
131 const std::set<std::string>& scheme_whitelist();
132
77 133
78 // Pass-through functions to simplify our friendship with URLIndexPrivateData. 134 // Pass-through functions to simplify our friendship with URLIndexPrivateData.
79 bool UpdateURL(const URLRow& row); 135 bool UpdateURL(const URLRow& row);
80 bool DeleteURL(const GURL& url); 136 bool DeleteURL(const GURL& url);
81 137
82 MessageLoopForUI message_loop_; 138 MessageLoopForUI message_loop_;
83 content::TestBrowserThread ui_thread_; 139 content::TestBrowserThread ui_thread_;
84 content::TestBrowserThread file_thread_; 140 content::TestBrowserThread file_thread_;
85 TestingProfile profile_; 141 TestingProfile profile_;
86 142
87 scoped_ptr<InMemoryURLIndex> url_index_; 143 scoped_ptr<InMemoryURLIndex> url_index_;
88 HistoryDatabase* history_database_; 144 HistoryDatabase* history_database_;
89 }; 145 };
90 146
91 InMemoryURLIndexTest::InMemoryURLIndexTest() 147 InMemoryURLIndexTest::InMemoryURLIndexTest()
92 : ui_thread_(content::BrowserThread::UI, &message_loop_), 148 : ui_thread_(content::BrowserThread::UI, &message_loop_),
93 file_thread_(content::BrowserThread::FILE, &message_loop_) { 149 file_thread_(content::BrowserThread::FILE, &message_loop_) {
94 } 150 }
95 151
96 sql::Connection& InMemoryURLIndexTest::GetDB() { 152 sql::Connection& InMemoryURLIndexTest::GetDB() {
97 return history_database_->GetDB(); 153 return history_database_->GetDB();
98 } 154 }
99 155
100 URLIndexPrivateData* InMemoryURLIndexTest::GetPrivateData() const { 156 URLIndexPrivateData* InMemoryURLIndexTest::GetPrivateData() const {
101 DCHECK(url_index_->private_data_.get()); 157 DCHECK(url_index_->private_data());
102 return url_index_->private_data_.get(); 158 return url_index_->private_data();
159 }
160
161 void InMemoryURLIndexTest::ClearPrivateData() {
162 return url_index_->ClearPrivateData();
163 }
164
165 void InMemoryURLIndexTest::set_history_dir(const FilePath& dir_path) {
166 return url_index_->set_history_dir(dir_path);
103 } 167 }
104 168
105 bool InMemoryURLIndexTest::GetCacheFilePath(FilePath* file_path) const { 169 bool InMemoryURLIndexTest::GetCacheFilePath(FilePath* file_path) const {
106 DCHECK(file_path); 170 DCHECK(file_path);
107 return url_index_->GetCacheFilePath(file_path); 171 return url_index_->GetCacheFilePath(file_path);
108 } 172 }
109 173
110 void InMemoryURLIndexTest::ClearHistoryDir() const { 174 void InMemoryURLIndexTest::PostRestoreFromCacheFileTask() {
111 url_index_->history_dir_.clear(); 175 url_index_->PostRestoreFromCacheFileTask();
176 }
177
178 void InMemoryURLIndexTest::PostSaveToCacheFileTask() {
179 url_index_->PostSaveToCacheFileTask();
180 }
181
182 const std::set<std::string>& InMemoryURLIndexTest::scheme_whitelist() {
183 return url_index_->scheme_whitelist();
112 } 184 }
113 185
114 bool InMemoryURLIndexTest::UpdateURL(const URLRow& row) { 186 bool InMemoryURLIndexTest::UpdateURL(const URLRow& row) {
115 return url_index_->private_data_->UpdateURL(row); 187 return GetPrivateData()->UpdateURL(row, url_index_->languages_,
188 url_index_->scheme_whitelist_);
116 } 189 }
117 190
118 bool InMemoryURLIndexTest::DeleteURL(const GURL& url) { 191 bool InMemoryURLIndexTest::DeleteURL(const GURL& url) {
119 return url_index_->private_data_->DeleteURL(url); 192 return GetPrivateData()->DeleteURL(url);
120 } 193 }
121 194
122 void InMemoryURLIndexTest::SetUp() { 195 void InMemoryURLIndexTest::SetUp() {
123 // We cannot access the database until the backend has been loaded. 196 // We cannot access the database until the backend has been loaded.
124 profile_.CreateHistoryService(true, false); 197 profile_.CreateHistoryService(true, false);
125 profile_.CreateBookmarkModel(true); 198 profile_.CreateBookmarkModel(true);
126 profile_.BlockUntilBookmarkModelLoaded(); 199 profile_.BlockUntilBookmarkModelLoaded();
127 profile_.BlockUntilHistoryProcessesPendingRequests(); 200 profile_.BlockUntilHistoryProcessesPendingRequests();
128 HistoryService* history_service = 201 HistoryService* history_service =
129 profile_.GetHistoryService(Profile::EXPLICIT_ACCESS); 202 profile_.GetHistoryService(Profile::EXPLICIT_ACCESS);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 FilePath::StringType TestDBName() const; 335 FilePath::StringType TestDBName() const;
263 }; 336 };
264 337
265 FilePath::StringType LimitedInMemoryURLIndexTest::TestDBName() const { 338 FilePath::StringType LimitedInMemoryURLIndexTest::TestDBName() const {
266 return FILE_PATH_LITERAL("url_history_provider_test_limited.db.txt"); 339 return FILE_PATH_LITERAL("url_history_provider_test_limited.db.txt");
267 } 340 }
268 341
269 TEST_F(LimitedInMemoryURLIndexTest, Initialization) { 342 TEST_F(LimitedInMemoryURLIndexTest, Initialization) {
270 // Verify that the database contains the expected number of items, which 343 // Verify that the database contains the expected number of items, which
271 // is the pre-filtered count, i.e. all of the items. 344 // is the pre-filtered count, i.e. all of the items.
272 sql::Connection& db(GetDB()); 345 sql::Statement statement(GetDB().GetUniqueStatement("SELECT * FROM urls;"));
273 sql::Statement statement(db.GetUniqueStatement("SELECT * FROM urls;"));
274 ASSERT_TRUE(statement.is_valid()); 346 ASSERT_TRUE(statement.is_valid());
275 uint64 row_count = 0; 347 uint64 row_count = 0;
276 while (statement.Step()) ++row_count; 348 while (statement.Step()) ++row_count;
277 EXPECT_EQ(1U, row_count); 349 EXPECT_EQ(1U, row_count);
278 url_index_.reset( 350 url_index_.reset(
279 new InMemoryURLIndex(&profile_, FilePath(), "en,ja,hi,zh")); 351 new InMemoryURLIndex(&profile_, FilePath(), "en,ja,hi,zh"));
280 url_index_->Init(); 352 url_index_->Init();
281 url_index_->RebuildFromHistory(history_database_); 353 url_index_->RebuildFromHistory(history_database_);
282 URLIndexPrivateData& private_data(*(url_index_->private_data_)); 354 URLIndexPrivateData& private_data(*GetPrivateData());
283 355
284 // history_info_map_ should have the same number of items as were filtered. 356 // history_info_map_ should have the same number of items as were filtered.
285 EXPECT_EQ(1U, private_data.history_info_map_.size()); 357 EXPECT_EQ(1U, private_data.history_info_map_.size());
286 EXPECT_EQ(35U, private_data.char_word_map_.size()); 358 EXPECT_EQ(35U, private_data.char_word_map_.size());
287 EXPECT_EQ(17U, private_data.word_map_.size()); 359 EXPECT_EQ(17U, private_data.word_map_.size());
288 } 360 }
289 361
290 TEST_F(InMemoryURLIndexTest, Retrieval) { 362 TEST_F(InMemoryURLIndexTest, Retrieval) {
291 // See if a very specific term gives a single result. 363 // See if a very specific term gives a single result.
292 ScoredHistoryMatches matches = 364 ScoredHistoryMatches matches =
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 { "tip://123.123.123.123/?urn:xopen:xid", false }, 810 { "tip://123.123.123.123/?urn:xopen:xid", false },
739 { "tv:nbc.com", false }, 811 { "tv:nbc.com", false },
740 { "urn:foo:A123,456", false }, 812 { "urn:foo:A123,456", false },
741 { "vemmi://zeus.mctel.fr/demo", false }, 813 { "vemmi://zeus.mctel.fr/demo", false },
742 { "wais://www.mydomain.net:8765/mydatabase", false }, 814 { "wais://www.mydomain.net:8765/mydatabase", false },
743 { "xmpp:node@example.com", false }, 815 { "xmpp:node@example.com", false },
744 { "xmpp://guest@example.com", false }, 816 { "xmpp://guest@example.com", false },
745 }; 817 };
746 818
747 URLIndexPrivateData& private_data(*GetPrivateData()); 819 URLIndexPrivateData& private_data(*GetPrivateData());
820 const std::set<std::string>& whitelist(scheme_whitelist());
748 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { 821 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) {
749 GURL url(data[i].url_spec); 822 GURL url(data[i].url_spec);
750 EXPECT_EQ(data[i].expected_is_whitelisted, 823 EXPECT_EQ(data[i].expected_is_whitelisted,
751 private_data.URLSchemeIsWhitelisted(url)); 824 private_data.URLSchemeIsWhitelisted(url, whitelist));
752 } 825 }
753 } 826 }
754 827
755 TEST_F(InMemoryURLIndexTest, CacheSaveRestore) { 828 TEST_F(InMemoryURLIndexTest, CacheSaveRestore) {
756 // Save the cache to a protobuf, restore it, and compare the results. 829 ScopedTempDir temp_directory;
757 in_memory_url_index::InMemoryURLIndexCacheItem index_cache; 830 ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
831 set_history_dir(temp_directory.path());
832
758 URLIndexPrivateData& private_data(*GetPrivateData()); 833 URLIndexPrivateData& private_data(*GetPrivateData());
759 private_data.SavePrivateData(&index_cache);
760 834
761 // Capture our private data so we can later compare for equality. 835 // 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()); 836 EXPECT_FALSE(private_data.word_list_.empty());
771 // available_words_ will already be empty since we have freshly built the 837 // available_words_ will already be empty since we have freshly built the
772 // data set for this test. 838 // data set for this test.
773 EXPECT_TRUE(private_data.available_words_.empty()); 839 EXPECT_TRUE(private_data.available_words_.empty());
774 EXPECT_FALSE(private_data.word_map_.empty()); 840 EXPECT_FALSE(private_data.word_map_.empty());
775 EXPECT_FALSE(private_data.char_word_map_.empty()); 841 EXPECT_FALSE(private_data.char_word_map_.empty());
776 EXPECT_FALSE(private_data.word_id_history_map_.empty()); 842 EXPECT_FALSE(private_data.word_id_history_map_.empty());
777 EXPECT_FALSE(private_data.history_id_word_map_.empty()); 843 EXPECT_FALSE(private_data.history_id_word_map_.empty());
778 EXPECT_FALSE(private_data.history_info_map_.empty()); 844 EXPECT_FALSE(private_data.history_info_map_.empty());
779 845
780 // Clear and then prove it's clear. 846 // Capture the current private data for later comparison to restored data.
781 private_data.Clear(); 847 scoped_refptr<URLIndexPrivateData> old_data(private_data.Duplicate());
848
849 // Save then restore our private data.
850 CacheFileSaverObserver save_observer(&message_loop_);
851 url_index_->set_save_cache_observer(&save_observer);
852 PostSaveToCacheFileTask();
853 message_loop_.Run();
854 EXPECT_TRUE(save_observer.succeeded_);
855
856 // Clear and then prove it's clear before restoring.
857 ClearPrivateData();
782 EXPECT_TRUE(private_data.word_list_.empty()); 858 EXPECT_TRUE(private_data.word_list_.empty());
783 EXPECT_TRUE(private_data.available_words_.empty()); 859 EXPECT_TRUE(private_data.available_words_.empty());
784 EXPECT_TRUE(private_data.word_map_.empty()); 860 EXPECT_TRUE(private_data.word_map_.empty());
785 EXPECT_TRUE(private_data.char_word_map_.empty()); 861 EXPECT_TRUE(private_data.char_word_map_.empty());
786 EXPECT_TRUE(private_data.word_id_history_map_.empty()); 862 EXPECT_TRUE(private_data.word_id_history_map_.empty());
787 EXPECT_TRUE(private_data.history_id_word_map_.empty()); 863 EXPECT_TRUE(private_data.history_id_word_map_.empty());
788 EXPECT_TRUE(private_data.history_info_map_.empty()); 864 EXPECT_TRUE(private_data.history_info_map_.empty());
789 865
790 // Restore the cache. 866 CacheFileReaderObserver read_observer(&message_loop_);
791 EXPECT_TRUE(private_data.RestorePrivateData(index_cache)); 867 url_index_->set_restore_cache_observer(&read_observer);
868 PostRestoreFromCacheFileTask();
869 message_loop_.Run();
870 EXPECT_TRUE(read_observer.succeeded_);
792 871
793 // Compare the restored and captured for equality. 872 URLIndexPrivateData& new_data(*GetPrivateData());
794 EXPECT_EQ(word_list.size(), private_data.word_list_.size()); 873
795 EXPECT_EQ(word_map.size(), private_data.word_map_.size()); 874 // Compare the captured and restored for equality.
796 EXPECT_EQ(char_word_map.size(), private_data.char_word_map_.size()); 875 EXPECT_EQ(old_data->word_list_.size(), new_data.word_list_.size());
797 EXPECT_EQ(word_id_history_map.size(), 876 EXPECT_EQ(old_data->word_map_.size(), new_data.word_map_.size());
798 private_data.word_id_history_map_.size()); 877 EXPECT_EQ(old_data->char_word_map_.size(), new_data.char_word_map_.size());
799 EXPECT_EQ(history_id_word_map.size(), 878 EXPECT_EQ(old_data->word_id_history_map_.size(),
800 private_data.history_id_word_map_.size()); 879 new_data.word_id_history_map_.size());
801 EXPECT_EQ(history_info_map.size(), private_data.history_info_map_.size()); 880 EXPECT_EQ(old_data->history_id_word_map_.size(),
881 new_data.history_id_word_map_.size());
882 EXPECT_EQ(old_data->history_info_map_.size(),
883 new_data.history_info_map_.size());
802 // WordList must be index-by-index equal. 884 // WordList must be index-by-index equal.
803 size_t count = word_list.size(); 885 size_t count = old_data->word_list_.size();
804 for (size_t i = 0; i < count; ++i) 886 for (size_t i = 0; i < count; ++i)
805 EXPECT_EQ(word_list[i], private_data.word_list_[i]); 887 EXPECT_EQ(old_data->word_list_[i], new_data.word_list_[i]);
806 888
807 ExpectMapOfContainersIdentical(char_word_map, 889 ExpectMapOfContainersIdentical(old_data->char_word_map_,
808 private_data.char_word_map_); 890 new_data.char_word_map_);
809 ExpectMapOfContainersIdentical(word_id_history_map, 891 ExpectMapOfContainersIdentical(old_data->word_id_history_map_,
810 private_data.word_id_history_map_); 892 new_data.word_id_history_map_);
811 ExpectMapOfContainersIdentical(history_id_word_map, 893 ExpectMapOfContainersIdentical(old_data->history_id_word_map_,
812 private_data.history_id_word_map_); 894 new_data.history_id_word_map_);
813 895
814 for (HistoryInfoMap::const_iterator expected = history_info_map.begin(); 896 for (HistoryInfoMap::const_iterator expected =
815 expected != history_info_map.end(); ++expected) { 897 old_data->history_info_map_.begin();
898 expected != old_data->history_info_map_.end(); ++expected) {
816 HistoryInfoMap::const_iterator actual = 899 HistoryInfoMap::const_iterator actual =
817 private_data.history_info_map_.find(expected->first); 900 new_data.history_info_map_.find(expected->first);
818 ASSERT_FALSE(private_data.history_info_map_.end() == actual); 901 ASSERT_FALSE(new_data.history_info_map_.end() == actual);
819 const URLRow& expected_row(expected->second); 902 const URLRow& expected_row(expected->second);
820 const URLRow& actual_row(actual->second); 903 const URLRow& actual_row(actual->second);
821 EXPECT_EQ(expected_row.visit_count(), actual_row.visit_count()); 904 EXPECT_EQ(expected_row.visit_count(), actual_row.visit_count());
822 EXPECT_EQ(expected_row.typed_count(), actual_row.typed_count()); 905 EXPECT_EQ(expected_row.typed_count(), actual_row.typed_count());
823 EXPECT_EQ(expected_row.last_visit(), actual_row.last_visit()); 906 EXPECT_EQ(expected_row.last_visit(), actual_row.last_visit());
824 EXPECT_EQ(expected_row.url(), actual_row.url()); 907 EXPECT_EQ(expected_row.url(), actual_row.url());
825 } 908 }
826 } 909 }
827 910
828 class InMemoryURLIndexCacheTest : public testing::Test { 911 class InMemoryURLIndexCacheTest : public testing::Test {
829 public: 912 public:
830 InMemoryURLIndexCacheTest() {} 913 InMemoryURLIndexCacheTest() {}
831 914
832 protected: 915 protected:
833 virtual void SetUp() OVERRIDE; 916 virtual void SetUp() OVERRIDE;
834 917
918 // Pass-through functions to simplify our friendship with InMemoryURLIndex.
919 void set_history_dir(const FilePath& dir_path);
920 bool GetCacheFilePath(FilePath* file_path) const;
921
835 ScopedTempDir temp_dir_; 922 ScopedTempDir temp_dir_;
836 scoped_ptr<InMemoryURLIndex> url_index_; 923 scoped_ptr<InMemoryURLIndex> url_index_;
837 }; 924 };
838 925
839 void InMemoryURLIndexCacheTest::SetUp() { 926 void InMemoryURLIndexCacheTest::SetUp() {
840 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 927 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
841 FilePath path(temp_dir_.path()); 928 FilePath path(temp_dir_.path());
842 url_index_.reset( 929 url_index_.reset(
843 new InMemoryURLIndex(NULL, path, "en,ja,hi,zh")); 930 new InMemoryURLIndex(NULL, path, "en,ja,hi,zh"));
844 } 931 }
845 932
933 void InMemoryURLIndexCacheTest::set_history_dir(const FilePath& dir_path) {
934 return url_index_->set_history_dir(dir_path);
935 }
936
937 bool InMemoryURLIndexCacheTest::GetCacheFilePath(FilePath* file_path) const {
938 DCHECK(file_path);
939 return url_index_->GetCacheFilePath(file_path);
940 }
941
846 TEST_F(InMemoryURLIndexCacheTest, CacheFilePath) { 942 TEST_F(InMemoryURLIndexCacheTest, CacheFilePath) {
847 FilePath expectedPath = 943 FilePath expectedPath =
848 temp_dir_.path().Append(FILE_PATH_LITERAL("History Provider Cache")); 944 temp_dir_.path().Append(FILE_PATH_LITERAL("History Provider Cache"));
849 std::vector<FilePath::StringType> expected_parts; 945 std::vector<FilePath::StringType> expected_parts;
850 expectedPath.GetComponents(&expected_parts); 946 expectedPath.GetComponents(&expected_parts);
851 FilePath full_file_path; 947 FilePath full_file_path;
852 ASSERT_TRUE(url_index_->GetCacheFilePath(&full_file_path)); 948 ASSERT_TRUE(GetCacheFilePath(&full_file_path));
853 std::vector<FilePath::StringType> actual_parts; 949 std::vector<FilePath::StringType> actual_parts;
854 full_file_path.GetComponents(&actual_parts); 950 full_file_path.GetComponents(&actual_parts);
855 ASSERT_EQ(expected_parts.size(), actual_parts.size()); 951 ASSERT_EQ(expected_parts.size(), actual_parts.size());
856 size_t count = expected_parts.size(); 952 size_t count = expected_parts.size();
857 for (size_t i = 0; i < count; ++i) 953 for (size_t i = 0; i < count; ++i)
858 EXPECT_EQ(expected_parts[i], actual_parts[i]); 954 EXPECT_EQ(expected_parts[i], actual_parts[i]);
859 // Must clear the history_dir_ to satisfy the dtor's DCHECK. 955 // Must clear the history_dir_ to satisfy the dtor's DCHECK.
860 url_index_->history_dir_.clear(); 956 set_history_dir(FilePath());
861 } 957 }
862 958
863 } // namespace history 959 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698