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/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 17 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
18 #include "chrome/browser/chrome_notification_types.h" | |
19 #include "chrome/browser/history/history_backend.h" | 18 #include "chrome/browser/history/history_backend.h" |
20 #include "chrome/browser/history/history_notifications.h" | |
21 #include "chrome/browser/history/history_service.h" | 19 #include "chrome/browser/history/history_service.h" |
22 #include "chrome/browser/history/history_service_factory.h" | 20 #include "chrome/browser/history/history_service_factory.h" |
23 #include "chrome/browser/history/in_memory_url_index.h" | 21 #include "chrome/browser/history/in_memory_url_index.h" |
24 #include "chrome/browser/history/url_index_private_data.h" | 22 #include "chrome/browser/history/url_index_private_data.h" |
25 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
26 #include "chrome/test/base/history_index_restore_observer.h" | 24 #include "chrome/test/base/history_index_restore_observer.h" |
27 #include "chrome/test/base/testing_profile.h" | 25 #include "chrome/test/base/testing_profile.h" |
28 #include "components/bookmarks/test/bookmark_test_helpers.h" | 26 #include "components/bookmarks/test/bookmark_test_helpers.h" |
29 #include "components/history/core/browser/history_client.h" | 27 #include "components/history/core/browser/history_client.h" |
30 #include "components/history/core/browser/history_database.h" | 28 #include "components/history/core/browser/history_database.h" |
31 #include "components/history/core/browser/in_memory_url_index_types.h" | 29 #include "components/history/core/browser/in_memory_url_index_types.h" |
32 #include "content/public/browser/notification_details.h" | |
33 #include "content/public/browser/notification_source.h" | |
34 #include "content/public/test/test_browser_thread_bundle.h" | 30 #include "content/public/test/test_browser_thread_bundle.h" |
35 #include "sql/transaction.h" | 31 #include "sql/transaction.h" |
36 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
37 | 33 |
38 using base::ASCIIToUTF16; | 34 using base::ASCIIToUTF16; |
39 | 35 |
40 namespace { | 36 namespace { |
41 const size_t kMaxMatches = 3; | 37 const size_t kMaxMatches = 3; |
42 } // namespace | 38 } // namespace |
43 | 39 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 sql::Connection& GetDB(); | 102 sql::Connection& GetDB(); |
107 | 103 |
108 // Pass-through functions to simplify our friendship with InMemoryURLIndex. | 104 // Pass-through functions to simplify our friendship with InMemoryURLIndex. |
109 URLIndexPrivateData* GetPrivateData() const; | 105 URLIndexPrivateData* GetPrivateData() const; |
110 base::CancelableTaskTracker* GetPrivateDataTracker() const; | 106 base::CancelableTaskTracker* GetPrivateDataTracker() const; |
111 void ClearPrivateData(); | 107 void ClearPrivateData(); |
112 void set_history_dir(const base::FilePath& dir_path); | 108 void set_history_dir(const base::FilePath& dir_path); |
113 bool GetCacheFilePath(base::FilePath* file_path) const; | 109 bool GetCacheFilePath(base::FilePath* file_path) const; |
114 void PostRestoreFromCacheFileTask(); | 110 void PostRestoreFromCacheFileTask(); |
115 void PostSaveToCacheFileTask(); | 111 void PostSaveToCacheFileTask(); |
116 void Observe(int notification_type, | |
117 const content::NotificationSource& source, | |
118 const content::NotificationDetails& details); | |
119 const std::set<std::string>& scheme_whitelist(); | 112 const std::set<std::string>& scheme_whitelist(); |
120 | 113 |
121 | 114 |
122 // Pass-through functions to simplify our friendship with URLIndexPrivateData. | 115 // Pass-through functions to simplify our friendship with URLIndexPrivateData. |
123 bool UpdateURL(const URLRow& row); | 116 bool UpdateURL(const URLRow& row); |
124 bool DeleteURL(const GURL& url); | 117 bool DeleteURL(const GURL& url); |
125 | 118 |
126 // Data verification helper functions. | 119 // Data verification helper functions. |
127 void ExpectPrivateDataNotEmpty(const URLIndexPrivateData& data); | 120 void ExpectPrivateDataNotEmpty(const URLIndexPrivateData& data); |
128 void ExpectPrivateDataEmpty(const URLIndexPrivateData& data); | 121 void ExpectPrivateDataEmpty(const URLIndexPrivateData& data); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 } | 162 } |
170 | 163 |
171 void InMemoryURLIndexTest::PostRestoreFromCacheFileTask() { | 164 void InMemoryURLIndexTest::PostRestoreFromCacheFileTask() { |
172 url_index_->PostRestoreFromCacheFileTask(); | 165 url_index_->PostRestoreFromCacheFileTask(); |
173 } | 166 } |
174 | 167 |
175 void InMemoryURLIndexTest::PostSaveToCacheFileTask() { | 168 void InMemoryURLIndexTest::PostSaveToCacheFileTask() { |
176 url_index_->PostSaveToCacheFileTask(); | 169 url_index_->PostSaveToCacheFileTask(); |
177 } | 170 } |
178 | 171 |
179 void InMemoryURLIndexTest::Observe( | |
180 int notification_type, | |
181 const content::NotificationSource& source, | |
182 const content::NotificationDetails& details) { | |
183 url_index_->Observe(notification_type, source, details); | |
184 } | |
185 | |
186 const std::set<std::string>& InMemoryURLIndexTest::scheme_whitelist() { | 172 const std::set<std::string>& InMemoryURLIndexTest::scheme_whitelist() { |
187 return url_index_->scheme_whitelist(); | 173 return url_index_->scheme_whitelist(); |
188 } | 174 } |
189 | 175 |
190 bool InMemoryURLIndexTest::UpdateURL(const URLRow& row) { | 176 bool InMemoryURLIndexTest::UpdateURL(const URLRow& row) { |
191 return GetPrivateData()->UpdateURL(history_service_, | 177 return GetPrivateData()->UpdateURL(history_service_, |
192 row, | 178 row, |
193 url_index_->languages_, | 179 url_index_->languages_, |
194 url_index_->scheme_whitelist_, | 180 url_index_->scheme_whitelist_, |
195 GetPrivateDataTracker()); | 181 GetPrivateDataTracker()); |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 EXPECT_FALSE(DeleteURL(url)); | 878 EXPECT_FALSE(DeleteURL(url)); |
893 } | 879 } |
894 | 880 |
895 TEST_F(InMemoryURLIndexTest, ExpireRow) { | 881 TEST_F(InMemoryURLIndexTest, ExpireRow) { |
896 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( | 882 ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( |
897 ASCIIToUTF16("DrudgeReport"), base::string16::npos, kMaxMatches); | 883 ASCIIToUTF16("DrudgeReport"), base::string16::npos, kMaxMatches); |
898 ASSERT_EQ(1U, matches.size()); | 884 ASSERT_EQ(1U, matches.size()); |
899 | 885 |
900 // Determine the row id for the result, remember that id, broadcast a | 886 // Determine the row id for the result, remember that id, broadcast a |
901 // delete notification, then ensure that the row has been deleted. | 887 // delete notification, then ensure that the row has been deleted. |
902 URLsDeletedDetails deleted_details; | 888 URLRows deleted_rows; |
903 deleted_details.all_history = false; | 889 deleted_rows.push_back(matches[0].url_info); |
904 deleted_details.rows.push_back(matches[0].url_info); | 890 url_index_->OnURLsDeleted(nullptr, false, false, deleted_rows, |
905 Observe(chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 891 std::set<GURL>()); |
906 content::Source<InMemoryURLIndexTest>(this), | |
907 content::Details<history::HistoryDetails>(&deleted_details)); | |
908 EXPECT_TRUE(url_index_->HistoryItemsForTerms( | 892 EXPECT_TRUE(url_index_->HistoryItemsForTerms( |
909 ASCIIToUTF16("DrudgeReport"), base::string16::npos, kMaxMatches).empty()); | 893 ASCIIToUTF16("DrudgeReport"), base::string16::npos, kMaxMatches).empty()); |
910 } | 894 } |
911 | 895 |
912 TEST_F(InMemoryURLIndexTest, WhitelistedURLs) { | 896 TEST_F(InMemoryURLIndexTest, WhitelistedURLs) { |
913 struct TestData { | 897 struct TestData { |
914 const std::string url_spec; | 898 const std::string url_spec; |
915 const bool expected_is_whitelisted; | 899 const bool expected_is_whitelisted; |
916 } data[] = { | 900 } data[] = { |
917 // URLs with whitelisted schemes. | 901 // URLs with whitelisted schemes. |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1228 full_file_path.GetComponents(&actual_parts); | 1212 full_file_path.GetComponents(&actual_parts); |
1229 ASSERT_EQ(expected_parts.size(), actual_parts.size()); | 1213 ASSERT_EQ(expected_parts.size(), actual_parts.size()); |
1230 size_t count = expected_parts.size(); | 1214 size_t count = expected_parts.size(); |
1231 for (size_t i = 0; i < count; ++i) | 1215 for (size_t i = 0; i < count; ++i) |
1232 EXPECT_EQ(expected_parts[i], actual_parts[i]); | 1216 EXPECT_EQ(expected_parts[i], actual_parts[i]); |
1233 // Must clear the history_dir_ to satisfy the dtor's DCHECK. | 1217 // Must clear the history_dir_ to satisfy the dtor's DCHECK. |
1234 set_history_dir(base::FilePath()); | 1218 set_history_dir(base::FilePath()); |
1235 } | 1219 } |
1236 | 1220 |
1237 } // namespace history | 1221 } // namespace history |
OLD | NEW |