| 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 <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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 // Note that only lines whose first character is an upper-case letter are | 47 // Note that only lines whose first character is an upper-case letter are |
| 48 // processed when creating the test database. | 48 // processed when creating the test database. |
| 49 | 49 |
| 50 namespace history { | 50 namespace history { |
| 51 | 51 |
| 52 // ----------------------------------------------------------------------------- | 52 // ----------------------------------------------------------------------------- |
| 53 | 53 |
| 54 // Observer class so the unit tests can wait while the cache is being saved. | 54 // Observer class so the unit tests can wait while the cache is being saved. |
| 55 class CacheFileSaverObserver : public InMemoryURLIndex::SaveCacheObserver { | 55 class CacheFileSaverObserver : public InMemoryURLIndex::SaveCacheObserver { |
| 56 public: | 56 public: |
| 57 explicit CacheFileSaverObserver(MessageLoop* loop); | 57 explicit CacheFileSaverObserver(base::MessageLoop* loop); |
| 58 virtual void OnCacheSaveFinished(bool succeeded) OVERRIDE; | 58 virtual void OnCacheSaveFinished(bool succeeded) OVERRIDE; |
| 59 | 59 |
| 60 MessageLoop* loop_; | 60 base::MessageLoop* loop_; |
| 61 bool succeeded_; | 61 bool succeeded_; |
| 62 DISALLOW_COPY_AND_ASSIGN(CacheFileSaverObserver); | 62 DISALLOW_COPY_AND_ASSIGN(CacheFileSaverObserver); |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 CacheFileSaverObserver::CacheFileSaverObserver(MessageLoop* loop) | 65 CacheFileSaverObserver::CacheFileSaverObserver(base::MessageLoop* loop) |
| 66 : loop_(loop), | 66 : loop_(loop), |
| 67 succeeded_(false) { | 67 succeeded_(false) { |
| 68 DCHECK(loop); | 68 DCHECK(loop); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void CacheFileSaverObserver::OnCacheSaveFinished(bool succeeded) { | 71 void CacheFileSaverObserver::OnCacheSaveFinished(bool succeeded) { |
| 72 succeeded_ = succeeded; | 72 succeeded_ = succeeded; |
| 73 loop_->Quit(); | 73 loop_->Quit(); |
| 74 } | 74 } |
| 75 | 75 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 // Pass-through functions to simplify our friendship with URLIndexPrivateData. | 111 // Pass-through functions to simplify our friendship with URLIndexPrivateData. |
| 112 bool UpdateURL(const URLRow& row); | 112 bool UpdateURL(const URLRow& row); |
| 113 bool DeleteURL(const GURL& url); | 113 bool DeleteURL(const GURL& url); |
| 114 | 114 |
| 115 // Data verification helper functions. | 115 // Data verification helper functions. |
| 116 void ExpectPrivateDataNotEmpty(const URLIndexPrivateData& data); | 116 void ExpectPrivateDataNotEmpty(const URLIndexPrivateData& data); |
| 117 void ExpectPrivateDataEmpty(const URLIndexPrivateData& data); | 117 void ExpectPrivateDataEmpty(const URLIndexPrivateData& data); |
| 118 void ExpectPrivateDataEqual(const URLIndexPrivateData& expected, | 118 void ExpectPrivateDataEqual(const URLIndexPrivateData& expected, |
| 119 const URLIndexPrivateData& actual); | 119 const URLIndexPrivateData& actual); |
| 120 | 120 |
| 121 MessageLoopForUI message_loop_; | 121 base::MessageLoopForUI message_loop_; |
| 122 content::TestBrowserThread ui_thread_; | 122 content::TestBrowserThread ui_thread_; |
| 123 content::TestBrowserThread file_thread_; | 123 content::TestBrowserThread file_thread_; |
| 124 TestingProfile profile_; | 124 TestingProfile profile_; |
| 125 HistoryService* history_service_; | 125 HistoryService* history_service_; |
| 126 | 126 |
| 127 scoped_ptr<InMemoryURLIndex> url_index_; | 127 scoped_ptr<InMemoryURLIndex> url_index_; |
| 128 HistoryDatabase* history_database_; | 128 HistoryDatabase* history_database_; |
| 129 }; | 129 }; |
| 130 | 130 |
| 131 InMemoryURLIndexTest::InMemoryURLIndexTest() | 131 InMemoryURLIndexTest::InMemoryURLIndexTest() |
| (...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1031 EXPECT_TRUE(private_data.word_list_.empty()); | 1031 EXPECT_TRUE(private_data.word_list_.empty()); |
| 1032 EXPECT_TRUE(private_data.available_words_.empty()); | 1032 EXPECT_TRUE(private_data.available_words_.empty()); |
| 1033 EXPECT_TRUE(private_data.word_map_.empty()); | 1033 EXPECT_TRUE(private_data.word_map_.empty()); |
| 1034 EXPECT_TRUE(private_data.char_word_map_.empty()); | 1034 EXPECT_TRUE(private_data.char_word_map_.empty()); |
| 1035 EXPECT_TRUE(private_data.word_id_history_map_.empty()); | 1035 EXPECT_TRUE(private_data.word_id_history_map_.empty()); |
| 1036 EXPECT_TRUE(private_data.history_id_word_map_.empty()); | 1036 EXPECT_TRUE(private_data.history_id_word_map_.empty()); |
| 1037 EXPECT_TRUE(private_data.history_info_map_.empty()); | 1037 EXPECT_TRUE(private_data.history_info_map_.empty()); |
| 1038 EXPECT_TRUE(private_data.word_starts_map_.empty()); | 1038 EXPECT_TRUE(private_data.word_starts_map_.empty()); |
| 1039 | 1039 |
| 1040 HistoryIndexRestoreObserver restore_observer( | 1040 HistoryIndexRestoreObserver restore_observer( |
| 1041 base::Bind(&MessageLoop::Quit, base::Unretained(&message_loop_))); | 1041 base::Bind(&base::MessageLoop::Quit, base::Unretained(&message_loop_))); |
| 1042 url_index_->set_restore_cache_observer(&restore_observer); | 1042 url_index_->set_restore_cache_observer(&restore_observer); |
| 1043 PostRestoreFromCacheFileTask(); | 1043 PostRestoreFromCacheFileTask(); |
| 1044 message_loop_.Run(); | 1044 message_loop_.Run(); |
| 1045 EXPECT_TRUE(restore_observer.succeeded()); | 1045 EXPECT_TRUE(restore_observer.succeeded()); |
| 1046 | 1046 |
| 1047 URLIndexPrivateData& new_data(*GetPrivateData()); | 1047 URLIndexPrivateData& new_data(*GetPrivateData()); |
| 1048 | 1048 |
| 1049 // Make sure the data we have was reloaded from cache. (Version 0 | 1049 // Make sure the data we have was reloaded from cache. (Version 0 |
| 1050 // means rebuilt from history; anything else means restored from | 1050 // means rebuilt from history; anything else means restored from |
| 1051 // a cache version.) | 1051 // a cache version.) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1099 full_file_path.GetComponents(&actual_parts); | 1099 full_file_path.GetComponents(&actual_parts); |
| 1100 ASSERT_EQ(expected_parts.size(), actual_parts.size()); | 1100 ASSERT_EQ(expected_parts.size(), actual_parts.size()); |
| 1101 size_t count = expected_parts.size(); | 1101 size_t count = expected_parts.size(); |
| 1102 for (size_t i = 0; i < count; ++i) | 1102 for (size_t i = 0; i < count; ++i) |
| 1103 EXPECT_EQ(expected_parts[i], actual_parts[i]); | 1103 EXPECT_EQ(expected_parts[i], actual_parts[i]); |
| 1104 // Must clear the history_dir_ to satisfy the dtor's DCHECK. | 1104 // Must clear the history_dir_ to satisfy the dtor's DCHECK. |
| 1105 set_history_dir(base::FilePath()); | 1105 set_history_dir(base::FilePath()); |
| 1106 } | 1106 } |
| 1107 | 1107 |
| 1108 } // namespace history | 1108 } // namespace history |
| OLD | NEW |