OLD | NEW |
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 <fstream> | 6 #include <fstream> |
6 | 7 |
7 #include "base/file_path.h" | 8 #include "base/file_path.h" |
8 #include "base/file_util.h" | 9 #include "base/file_util.h" |
9 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
10 #include "base/path_service.h" | 11 #include "base/path_service.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" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 73 |
73 // Pass-through functions to simplify our friendship with InMemoryURLIndex. | 74 // Pass-through functions to simplify our friendship with InMemoryURLIndex. |
74 URLIndexPrivateData* GetPrivateData() const; | 75 URLIndexPrivateData* GetPrivateData() const; |
75 bool GetCacheFilePath(FilePath* file_path) const; | 76 bool GetCacheFilePath(FilePath* file_path) const; |
76 void ClearHistoryDir() const; | 77 void ClearHistoryDir() const; |
77 | 78 |
78 // Pass-through functions to simplify our friendship with URLIndexPrivateData. | 79 // Pass-through functions to simplify our friendship with URLIndexPrivateData. |
79 bool UpdateURL(const URLRow& row); | 80 bool UpdateURL(const URLRow& row); |
80 bool DeleteURL(const GURL& url); | 81 bool DeleteURL(const GURL& url); |
81 | 82 |
| 83 // Data verification helper functions. |
| 84 void ExpectPrivateDataNotEmpty(const URLIndexPrivateData& data); |
| 85 void ExpectPrivateDataEmpty(const URLIndexPrivateData& data); |
| 86 void ExpectPrivateDataEqual(const URLIndexPrivateData& expected, |
| 87 const URLIndexPrivateData& actual); |
| 88 |
82 MessageLoopForUI message_loop_; | 89 MessageLoopForUI message_loop_; |
83 content::TestBrowserThread ui_thread_; | 90 content::TestBrowserThread ui_thread_; |
84 content::TestBrowserThread file_thread_; | 91 content::TestBrowserThread file_thread_; |
85 TestingProfile profile_; | 92 TestingProfile profile_; |
86 | 93 |
87 scoped_ptr<InMemoryURLIndex> url_index_; | 94 scoped_ptr<InMemoryURLIndex> url_index_; |
88 HistoryDatabase* history_database_; | 95 HistoryDatabase* history_database_; |
89 }; | 96 }; |
90 | 97 |
91 InMemoryURLIndexTest::InMemoryURLIndexTest() | 98 InMemoryURLIndexTest::InMemoryURLIndexTest() |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 string16 term) const { | 236 string16 term) const { |
230 URLIndexPrivateData::SearchTermCacheMap::const_iterator cache_iter( | 237 URLIndexPrivateData::SearchTermCacheMap::const_iterator cache_iter( |
231 cache.find(term)); | 238 cache.find(term)); |
232 ASSERT_NE(cache.end(), cache_iter) | 239 ASSERT_NE(cache.end(), cache_iter) |
233 << "Cache does not contain '" << term << "' but should."; | 240 << "Cache does not contain '" << term << "' but should."; |
234 URLIndexPrivateData::SearchTermCacheItem cache_item = cache_iter->second; | 241 URLIndexPrivateData::SearchTermCacheItem cache_item = cache_iter->second; |
235 EXPECT_TRUE(cache_item.used_) | 242 EXPECT_TRUE(cache_item.used_) |
236 << "Cache item '" << term << "' should be marked as being in use."; | 243 << "Cache item '" << term << "' should be marked as being in use."; |
237 } | 244 } |
238 | 245 |
| 246 void InMemoryURLIndexTest::ExpectPrivateDataNotEmpty( |
| 247 const URLIndexPrivateData& data) { |
| 248 EXPECT_FALSE(data.word_list_.empty()); |
| 249 // available_words_ will be empty since we have freshly built the |
| 250 // data set for these tests. |
| 251 EXPECT_TRUE(data.available_words_.empty()); |
| 252 EXPECT_FALSE(data.word_map_.empty()); |
| 253 EXPECT_FALSE(data.char_word_map_.empty()); |
| 254 EXPECT_FALSE(data.word_id_history_map_.empty()); |
| 255 EXPECT_FALSE(data.history_id_word_map_.empty()); |
| 256 EXPECT_FALSE(data.history_info_map_.empty()); |
| 257 } |
| 258 |
| 259 void InMemoryURLIndexTest::ExpectPrivateDataEmpty( |
| 260 const URLIndexPrivateData& data) { |
| 261 EXPECT_TRUE(data.word_list_.empty()); |
| 262 EXPECT_TRUE(data.available_words_.empty()); |
| 263 EXPECT_TRUE(data.word_map_.empty()); |
| 264 EXPECT_TRUE(data.char_word_map_.empty()); |
| 265 EXPECT_TRUE(data.word_id_history_map_.empty()); |
| 266 EXPECT_TRUE(data.history_id_word_map_.empty()); |
| 267 EXPECT_TRUE(data.history_info_map_.empty()); |
| 268 } |
| 269 |
239 // Helper function which compares two maps for equivalence. The maps' values | 270 // Helper function which compares two maps for equivalence. The maps' values |
240 // are associative containers and their contents are compared as well. | 271 // are associative containers and their contents are compared as well. |
241 template<typename T> | 272 template<typename T> |
242 void ExpectMapOfContainersIdentical(const T& expected, const T& actual) { | 273 void ExpectMapOfContainersIdentical(const T& expected, const T& actual) { |
243 ASSERT_EQ(expected.size(), actual.size()); | 274 ASSERT_EQ(expected.size(), actual.size()); |
244 for (typename T::const_iterator expected_iter = expected.begin(); | 275 for (typename T::const_iterator expected_iter = expected.begin(); |
245 expected_iter != expected.end(); ++expected_iter) { | 276 expected_iter != expected.end(); ++expected_iter) { |
246 typename T::const_iterator actual_iter = actual.find(expected_iter->first); | 277 typename T::const_iterator actual_iter = actual.find(expected_iter->first); |
247 ASSERT_NE(actual.end(), actual_iter); | 278 ASSERT_NE(actual.end(), actual_iter); |
248 typename T::mapped_type const& expected_values(expected_iter->second); | 279 typename T::mapped_type const& expected_values(expected_iter->second); |
249 typename T::mapped_type const& actual_values(actual_iter->second); | 280 typename T::mapped_type const& actual_values(actual_iter->second); |
250 ASSERT_EQ(expected_values.size(), actual_values.size()); | 281 ASSERT_EQ(expected_values.size(), actual_values.size()); |
251 for (typename T::mapped_type::const_iterator set_iter = | 282 for (typename T::mapped_type::const_iterator set_iter = |
252 expected_values.begin(); set_iter != expected_values.end(); ++set_iter) | 283 expected_values.begin(); set_iter != expected_values.end(); ++set_iter) |
253 EXPECT_EQ(actual_values.count(*set_iter), | 284 EXPECT_EQ(actual_values.count(*set_iter), |
254 expected_values.count(*set_iter)); | 285 expected_values.count(*set_iter)); |
255 } | 286 } |
256 } | 287 } |
257 | 288 |
| 289 void InMemoryURLIndexTest::ExpectPrivateDataEqual( |
| 290 const URLIndexPrivateData& expected, |
| 291 const URLIndexPrivateData& actual) { |
| 292 EXPECT_EQ(expected.word_list_.size(), actual.word_list_.size()); |
| 293 EXPECT_EQ(expected.word_map_.size(), actual.word_map_.size()); |
| 294 EXPECT_EQ(expected.char_word_map_.size(), actual.char_word_map_.size()); |
| 295 EXPECT_EQ(expected.word_id_history_map_.size(), |
| 296 actual.word_id_history_map_.size()); |
| 297 EXPECT_EQ(expected.history_id_word_map_.size(), |
| 298 actual.history_id_word_map_.size()); |
| 299 EXPECT_EQ(expected.history_info_map_.size(), actual.history_info_map_.size()); |
| 300 // WordList must be index-by-index equal. |
| 301 size_t count = expected.word_list_.size(); |
| 302 for (size_t i = 0; i < count; ++i) |
| 303 EXPECT_EQ(expected.word_list_[i], actual.word_list_[i]); |
| 304 |
| 305 ExpectMapOfContainersIdentical(expected.char_word_map_, |
| 306 actual.char_word_map_); |
| 307 ExpectMapOfContainersIdentical(expected.word_id_history_map_, |
| 308 actual.word_id_history_map_); |
| 309 ExpectMapOfContainersIdentical(expected.history_id_word_map_, |
| 310 actual.history_id_word_map_); |
| 311 |
| 312 for (HistoryInfoMap::const_iterator expected_info = |
| 313 expected.history_info_map_.begin(); |
| 314 expected_info != expected.history_info_map_.end(); ++expected_info) { |
| 315 HistoryInfoMap::const_iterator actual_info = |
| 316 actual.history_info_map_.find(expected_info->first); |
| 317 ASSERT_NE(actual_info, actual.history_info_map_.end()); |
| 318 const URLRow& expected_row(expected_info->second); |
| 319 const URLRow& actual_row(actual_info->second); |
| 320 EXPECT_EQ(expected_row.visit_count(), actual_row.visit_count()); |
| 321 EXPECT_EQ(expected_row.typed_count(), actual_row.typed_count()); |
| 322 EXPECT_EQ(expected_row.last_visit(), actual_row.last_visit()); |
| 323 EXPECT_EQ(expected_row.url(), actual_row.url()); |
| 324 } |
| 325 |
| 326 for (WordStartsMap::const_iterator expected_starts = |
| 327 expected.word_starts_map_.begin(); |
| 328 expected_starts != expected.word_starts_map_.end(); |
| 329 ++expected_starts) { |
| 330 WordStartsMap::const_iterator actual_starts = |
| 331 actual.word_starts_map_.find(expected_starts->first); |
| 332 ASSERT_NE(actual_starts, actual.word_starts_map_.end()); |
| 333 const RowWordStarts& expected_word_starts(expected_starts->second); |
| 334 const RowWordStarts& actual_word_starts(actual_starts->second); |
| 335 EXPECT_EQ(expected_word_starts.url_word_starts_.size(), |
| 336 actual_word_starts.url_word_starts_.size()); |
| 337 EXPECT_TRUE(std::equal(expected_word_starts.url_word_starts_.begin(), |
| 338 expected_word_starts.url_word_starts_.end(), |
| 339 actual_word_starts.url_word_starts_.begin())); |
| 340 EXPECT_EQ(expected_word_starts.title_word_starts_.size(), |
| 341 actual_word_starts.title_word_starts_.size()); |
| 342 EXPECT_TRUE(std::equal(expected_word_starts.title_word_starts_.begin(), |
| 343 expected_word_starts.title_word_starts_.end(), |
| 344 actual_word_starts.title_word_starts_.begin())); |
| 345 } |
| 346 } |
| 347 |
258 //------------------------------------------------------------------------------ | 348 //------------------------------------------------------------------------------ |
259 | 349 |
260 class LimitedInMemoryURLIndexTest : public InMemoryURLIndexTest { | 350 class LimitedInMemoryURLIndexTest : public InMemoryURLIndexTest { |
261 protected: | 351 protected: |
262 FilePath::StringType TestDBName() const; | 352 FilePath::StringType TestDBName() const; |
263 }; | 353 }; |
264 | 354 |
265 FilePath::StringType LimitedInMemoryURLIndexTest::TestDBName() const { | 355 FilePath::StringType LimitedInMemoryURLIndexTest::TestDBName() const { |
266 return FILE_PATH_LITERAL("url_history_provider_test_limited.db.txt"); | 356 return FILE_PATH_LITERAL("url_history_provider_test_limited.db.txt"); |
267 } | 357 } |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 // Simulate a <DELETE> by removing the 'reco' and adding back the 'rec'. | 671 // Simulate a <DELETE> by removing the 'reco' and adding back the 'rec'. |
582 url_index_->HistoryItemsForTerms(ASCIIToUTF16("mort rec")); | 672 url_index_->HistoryItemsForTerms(ASCIIToUTF16("mort rec")); |
583 ASSERT_EQ(2U, cache.size()); | 673 ASSERT_EQ(2U, cache.size()); |
584 CheckTerm(cache, ASCIIToUTF16("mort")); | 674 CheckTerm(cache, ASCIIToUTF16("mort")); |
585 CheckTerm(cache, ASCIIToUTF16("rec")); | 675 CheckTerm(cache, ASCIIToUTF16("rec")); |
586 } | 676 } |
587 | 677 |
588 TEST_F(InMemoryURLIndexTest, Scoring) { | 678 TEST_F(InMemoryURLIndexTest, Scoring) { |
589 URLRow row_a(MakeURLRow("http://abcdef", "fedcba", 3, 30, 1)); | 679 URLRow row_a(MakeURLRow("http://abcdef", "fedcba", 3, 30, 1)); |
590 // Test scores based on position. | 680 // Test scores based on position. |
| 681 // TODO(mpearson): Set word_starts when ScoredMatchForURL has been modified |
| 682 // to take them into consideration when scoring. |
| 683 RowWordStarts word_starts; |
591 ScoredHistoryMatch scored_a(URLIndexPrivateData::ScoredMatchForURL( | 684 ScoredHistoryMatch scored_a(URLIndexPrivateData::ScoredMatchForURL( |
592 row_a, ASCIIToUTF16("abc"), Make1Term("abc"))); | 685 row_a, ASCIIToUTF16("abc"), Make1Term("abc"), word_starts)); |
593 ScoredHistoryMatch scored_b(URLIndexPrivateData::ScoredMatchForURL( | 686 ScoredHistoryMatch scored_b(URLIndexPrivateData::ScoredMatchForURL( |
594 row_a, ASCIIToUTF16("bcd"), Make1Term("bcd"))); | 687 row_a, ASCIIToUTF16("bcd"), Make1Term("bcd"), word_starts)); |
595 EXPECT_GT(scored_a.raw_score, scored_b.raw_score); | 688 EXPECT_GT(scored_a.raw_score, scored_b.raw_score); |
596 // Test scores based on length. | 689 // Test scores based on length. |
597 ScoredHistoryMatch scored_c(URLIndexPrivateData::ScoredMatchForURL( | 690 ScoredHistoryMatch scored_c(URLIndexPrivateData::ScoredMatchForURL( |
598 row_a, ASCIIToUTF16("abcd"), Make1Term("abcd"))); | 691 row_a, ASCIIToUTF16("abcd"), Make1Term("abcd"), word_starts)); |
599 EXPECT_LT(scored_a.raw_score, scored_c.raw_score); | 692 EXPECT_LT(scored_a.raw_score, scored_c.raw_score); |
600 // Test scores based on order. | 693 // Test scores based on order. |
601 ScoredHistoryMatch scored_d(URLIndexPrivateData::ScoredMatchForURL( | 694 ScoredHistoryMatch scored_d(URLIndexPrivateData::ScoredMatchForURL( |
602 row_a, ASCIIToUTF16("abcdef"), Make2Terms("abc", "def"))); | 695 row_a, ASCIIToUTF16("abcdef"), Make2Terms("abc", "def"), word_starts)); |
603 ScoredHistoryMatch scored_e(URLIndexPrivateData::ScoredMatchForURL( | 696 ScoredHistoryMatch scored_e(URLIndexPrivateData::ScoredMatchForURL( |
604 row_a, ASCIIToUTF16("def abc"), Make2Terms("def", "abc"))); | 697 row_a, ASCIIToUTF16("def abc"), Make2Terms("def", "abc"), word_starts)); |
605 EXPECT_GT(scored_d.raw_score, scored_e.raw_score); | 698 EXPECT_GT(scored_d.raw_score, scored_e.raw_score); |
606 // Test scores based on visit_count. | 699 // Test scores based on visit_count. |
607 URLRow row_b(MakeURLRow("http://abcdef", "fedcba", 10, 30, 1)); | 700 URLRow row_b(MakeURLRow("http://abcdef", "fedcba", 10, 30, 1)); |
608 ScoredHistoryMatch scored_f(URLIndexPrivateData::ScoredMatchForURL( | 701 ScoredHistoryMatch scored_f(URLIndexPrivateData::ScoredMatchForURL( |
609 row_b, ASCIIToUTF16("abc"), Make1Term("abc"))); | 702 row_b, ASCIIToUTF16("abc"), Make1Term("abc"), word_starts)); |
610 EXPECT_GT(scored_f.raw_score, scored_a.raw_score); | 703 EXPECT_GT(scored_f.raw_score, scored_a.raw_score); |
611 // Test scores based on last_visit. | 704 // Test scores based on last_visit. |
612 URLRow row_c(MakeURLRow("http://abcdef", "fedcba", 3, 10, 1)); | 705 URLRow row_c(MakeURLRow("http://abcdef", "fedcba", 3, 10, 1)); |
613 ScoredHistoryMatch scored_g(URLIndexPrivateData::ScoredMatchForURL( | 706 ScoredHistoryMatch scored_g(URLIndexPrivateData::ScoredMatchForURL( |
614 row_c, ASCIIToUTF16("abc"), Make1Term("abc"))); | 707 row_c, ASCIIToUTF16("abc"), Make1Term("abc"), word_starts)); |
615 EXPECT_GT(scored_g.raw_score, scored_a.raw_score); | 708 EXPECT_GT(scored_g.raw_score, scored_a.raw_score); |
616 // Test scores based on typed_count. | 709 // Test scores based on typed_count. |
617 URLRow row_d(MakeURLRow("http://abcdef", "fedcba", 3, 30, 10)); | 710 URLRow row_d(MakeURLRow("http://abcdef", "fedcba", 3, 30, 10)); |
618 ScoredHistoryMatch scored_h(URLIndexPrivateData::ScoredMatchForURL( | 711 ScoredHistoryMatch scored_h(URLIndexPrivateData::ScoredMatchForURL( |
619 row_d, ASCIIToUTF16("abc"), Make1Term("abc"))); | 712 row_d, ASCIIToUTF16("abc"), Make1Term("abc"), word_starts)); |
620 EXPECT_GT(scored_h.raw_score, scored_a.raw_score); | 713 EXPECT_GT(scored_h.raw_score, scored_a.raw_score); |
621 // Test scores based on a terms appearing multiple times. | 714 // Test scores based on a terms appearing multiple times. |
622 URLRow row_i(MakeURLRow("http://csi.csi.csi/csi_csi", | 715 URLRow row_i(MakeURLRow("http://csi.csi.csi/csi_csi", |
623 "CSI Guide to CSI Las Vegas, CSI New York, CSI Provo", 3, 30, 10)); | 716 "CSI Guide to CSI Las Vegas, CSI New York, CSI Provo", 3, 30, 10)); |
624 ScoredHistoryMatch scored_i(URLIndexPrivateData::ScoredMatchForURL( | 717 ScoredHistoryMatch scored_i(URLIndexPrivateData::ScoredMatchForURL( |
625 row_i, ASCIIToUTF16("csi"), Make1Term("csi"))); | 718 row_i, ASCIIToUTF16("csi"), Make1Term("csi"), word_starts)); |
626 EXPECT_LT(scored_i.raw_score, 1400); | 719 EXPECT_LT(scored_i.raw_score, 1400); |
627 } | 720 } |
628 | 721 |
629 TEST_F(InMemoryURLIndexTest, AddNewRows) { | 722 TEST_F(InMemoryURLIndexTest, AddNewRows) { |
630 // Verify that the row we're going to add does not already exist. | 723 // Verify that the row we're going to add does not already exist. |
631 URLID new_row_id = 87654321; | 724 URLID new_row_id = 87654321; |
632 // Newly created URLRows get a last_visit time of 'right now' so it should | 725 // Newly created URLRows get a last_visit time of 'right now' so it should |
633 // qualify as a quick result candidate. | 726 // qualify as a quick result candidate. |
634 EXPECT_TRUE(url_index_->HistoryItemsForTerms( | 727 EXPECT_TRUE(url_index_->HistoryItemsForTerms( |
635 ASCIIToUTF16("brokeandalone")).empty()); | 728 ASCIIToUTF16("brokeandalone")).empty()); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 | 839 |
747 URLIndexPrivateData& private_data(*GetPrivateData()); | 840 URLIndexPrivateData& private_data(*GetPrivateData()); |
748 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { | 841 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { |
749 GURL url(data[i].url_spec); | 842 GURL url(data[i].url_spec); |
750 EXPECT_EQ(data[i].expected_is_whitelisted, | 843 EXPECT_EQ(data[i].expected_is_whitelisted, |
751 private_data.URLSchemeIsWhitelisted(url)); | 844 private_data.URLSchemeIsWhitelisted(url)); |
752 } | 845 } |
753 } | 846 } |
754 | 847 |
755 TEST_F(InMemoryURLIndexTest, CacheSaveRestore) { | 848 TEST_F(InMemoryURLIndexTest, CacheSaveRestore) { |
756 // Save the cache to a protobuf, restore it, and compare the results. | 849 // Part 1: Save the cache to a protobuf, restore it, and compare the results. |
757 in_memory_url_index::InMemoryURLIndexCacheItem index_cache; | 850 in_memory_url_index::InMemoryURLIndexCacheItem index_cache; |
758 URLIndexPrivateData& private_data(*GetPrivateData()); | 851 URLIndexPrivateData& expected(*GetPrivateData()); |
759 private_data.SavePrivateData(&index_cache); | |
760 | 852 |
761 // Capture our private data so we can later compare for equality. | 853 // Capture our private data so we can later compare for equality. |
762 String16Vector word_list(private_data.word_list_); | 854 URLIndexPrivateData actual(expected); |
763 WordMap word_map(private_data.word_map_); | 855 |
764 CharWordIDMap char_word_map(private_data.char_word_map_); | 856 actual.SavePrivateData(&index_cache); |
765 WordIDHistoryMap word_id_history_map(private_data.word_id_history_map_); | 857 |
766 HistoryIDWordMap history_id_word_map(private_data.history_id_word_map_); | 858 // Version check: Make sure this version actually has the word starts. |
767 HistoryInfoMap history_info_map(private_data.history_info_map_); | 859 EXPECT_TRUE(index_cache.has_word_starts_map()); |
| 860 |
| 861 // Save the size of the resulting cache for later versioning comparison. |
| 862 std::string data; |
| 863 EXPECT_TRUE(index_cache.SerializeToString(&data)); |
| 864 size_t current_version_cache_size = data.size(); |
768 | 865 |
769 // Prove that there is really something there. | 866 // Prove that there is really something there. |
770 EXPECT_FALSE(private_data.word_list_.empty()); | 867 ExpectPrivateDataNotEmpty(actual); |
771 // available_words_ will already be empty since we have freshly built the | |
772 // data set for this test. | |
773 EXPECT_TRUE(private_data.available_words_.empty()); | |
774 EXPECT_FALSE(private_data.word_map_.empty()); | |
775 EXPECT_FALSE(private_data.char_word_map_.empty()); | |
776 EXPECT_FALSE(private_data.word_id_history_map_.empty()); | |
777 EXPECT_FALSE(private_data.history_id_word_map_.empty()); | |
778 EXPECT_FALSE(private_data.history_info_map_.empty()); | |
779 | 868 |
780 // Clear and then prove it's clear. | 869 // Clear and then prove it's clear. |
781 private_data.Clear(); | 870 actual.Clear(); |
782 EXPECT_TRUE(private_data.word_list_.empty()); | 871 ExpectPrivateDataEmpty(actual); |
783 EXPECT_TRUE(private_data.available_words_.empty()); | |
784 EXPECT_TRUE(private_data.word_map_.empty()); | |
785 EXPECT_TRUE(private_data.char_word_map_.empty()); | |
786 EXPECT_TRUE(private_data.word_id_history_map_.empty()); | |
787 EXPECT_TRUE(private_data.history_id_word_map_.empty()); | |
788 EXPECT_TRUE(private_data.history_info_map_.empty()); | |
789 | 872 |
790 // Restore the cache. | 873 // Restore the cache. |
791 EXPECT_TRUE(private_data.RestorePrivateData(index_cache)); | 874 EXPECT_TRUE(actual.RestorePrivateData(index_cache)); |
| 875 EXPECT_EQ(kCurrentCacheFileVersion, actual.restored_cache_version_); |
792 | 876 |
793 // Compare the restored and captured for equality. | 877 // Compare the restored and expected for equality. |
794 EXPECT_EQ(word_list.size(), private_data.word_list_.size()); | 878 ExpectPrivateDataEqual(expected, actual); |
795 EXPECT_EQ(word_map.size(), private_data.word_map_.size()); | |
796 EXPECT_EQ(char_word_map.size(), private_data.char_word_map_.size()); | |
797 EXPECT_EQ(word_id_history_map.size(), | |
798 private_data.word_id_history_map_.size()); | |
799 EXPECT_EQ(history_id_word_map.size(), | |
800 private_data.history_id_word_map_.size()); | |
801 EXPECT_EQ(history_info_map.size(), private_data.history_info_map_.size()); | |
802 // WordList must be index-by-index equal. | |
803 size_t count = word_list.size(); | |
804 for (size_t i = 0; i < count; ++i) | |
805 EXPECT_EQ(word_list[i], private_data.word_list_[i]); | |
806 | 879 |
807 ExpectMapOfContainersIdentical(char_word_map, | 880 // Part 2: Save an older version of the cache, restore it, and verify that the |
808 private_data.char_word_map_); | 881 // reversioned portions are as expected. |
809 ExpectMapOfContainersIdentical(word_id_history_map, | 882 URLIndexPrivateData older(expected); |
810 private_data.word_id_history_map_); | 883 in_memory_url_index::InMemoryURLIndexCacheItem older_cache; |
811 ExpectMapOfContainersIdentical(history_id_word_map, | 884 older.set_saved_cache_version(0); |
812 private_data.history_id_word_map_); | 885 older.SavePrivateData(&older_cache); |
813 | 886 |
814 for (HistoryInfoMap::const_iterator expected = history_info_map.begin(); | 887 // Version check: Make sure this version does not have the word starts. |
815 expected != history_info_map.end(); ++expected) { | 888 EXPECT_FALSE(older_cache.has_word_starts_map()); |
816 HistoryInfoMap::const_iterator actual = | 889 |
817 private_data.history_info_map_.find(expected->first); | 890 // Since we shouldn't have saved the word starts information for the version |
818 ASSERT_FALSE(private_data.history_info_map_.end() == actual); | 891 // 0 save immediately above, the cache should be a bit smaller. |
819 const URLRow& expected_row(expected->second); | 892 std::string older_data; |
820 const URLRow& actual_row(actual->second); | 893 EXPECT_TRUE(older_cache.SerializeToString(&older_data)); |
821 EXPECT_EQ(expected_row.visit_count(), actual_row.visit_count()); | 894 size_t old_version_file_size = older_data.size(); |
822 EXPECT_EQ(expected_row.typed_count(), actual_row.typed_count()); | 895 EXPECT_LT(old_version_file_size, current_version_cache_size); |
823 EXPECT_EQ(expected_row.last_visit(), actual_row.last_visit()); | 896 EXPECT_NE(data, older_data); |
824 EXPECT_EQ(expected_row.url(), actual_row.url()); | 897 |
825 } | 898 // Clear and then prove it's clear. |
| 899 older.Clear(); |
| 900 ExpectPrivateDataEmpty(older); |
| 901 |
| 902 // Restore the cache. |
| 903 EXPECT_TRUE(older.RestorePrivateData(older_cache)); |
| 904 EXPECT_EQ(0, older.restored_cache_version_); |
| 905 |
| 906 // Compare the restored and expected for equality. |
| 907 ExpectPrivateDataEqual(expected, older); |
826 } | 908 } |
827 | 909 |
828 class InMemoryURLIndexCacheTest : public testing::Test { | 910 class InMemoryURLIndexCacheTest : public testing::Test { |
829 public: | 911 public: |
830 InMemoryURLIndexCacheTest() {} | 912 InMemoryURLIndexCacheTest() {} |
831 | 913 |
832 protected: | 914 protected: |
833 virtual void SetUp() OVERRIDE; | 915 virtual void SetUp() OVERRIDE; |
834 | 916 |
835 ScopedTempDir temp_dir_; | 917 ScopedTempDir temp_dir_; |
(...skipping 18 matching lines...) Expand all Loading... |
854 full_file_path.GetComponents(&actual_parts); | 936 full_file_path.GetComponents(&actual_parts); |
855 ASSERT_EQ(expected_parts.size(), actual_parts.size()); | 937 ASSERT_EQ(expected_parts.size(), actual_parts.size()); |
856 size_t count = expected_parts.size(); | 938 size_t count = expected_parts.size(); |
857 for (size_t i = 0; i < count; ++i) | 939 for (size_t i = 0; i < count; ++i) |
858 EXPECT_EQ(expected_parts[i], actual_parts[i]); | 940 EXPECT_EQ(expected_parts[i], actual_parts[i]); |
859 // Must clear the history_dir_ to satisfy the dtor's DCHECK. | 941 // Must clear the history_dir_ to satisfy the dtor's DCHECK. |
860 url_index_->history_dir_.clear(); | 942 url_index_->history_dir_.clear(); |
861 } | 943 } |
862 | 944 |
863 } // namespace history | 945 } // namespace history |
OLD | NEW |