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/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/scoped_temp_dir.h" | 12 #include "base/scoped_temp_dir.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "base/string16.h" | 14 #include "base/string16.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "chrome/browser/autocomplete/autocomplete.h" | 16 #include "chrome/browser/autocomplete/autocomplete.h" |
17 #include "chrome/browser/history/history.h" | 17 #include "chrome/browser/history/history.h" |
18 #include "chrome/browser/history/history_backend.h" | 18 #include "chrome/browser/history/history_backend.h" |
19 #include "chrome/browser/history/history_database.h" | 19 #include "chrome/browser/history/history_database.h" |
20 #include "chrome/browser/history/history_notifications.h" | |
21 #include "chrome/browser/history/in_memory_url_index_types.h" | 20 #include "chrome/browser/history/in_memory_url_index_types.h" |
22 #include "chrome/browser/history/in_memory_url_index.h" | 21 #include "chrome/browser/history/in_memory_url_index.h" |
23 #include "chrome/browser/history/url_index_private_data.h" | 22 #include "chrome/browser/history/url_index_private_data.h" |
24 #include "chrome/common/chrome_notification_types.h" | |
25 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
26 #include "content/public/browser/notification_details.h" | |
27 #include "content/public/browser/notification_source.h" | |
28 #include "chrome/test/base/testing_profile.h" | 24 #include "chrome/test/base/testing_profile.h" |
29 #include "content/test/test_browser_thread.h" | 25 #include "content/test/test_browser_thread.h" |
30 #include "sql/transaction.h" | 26 #include "sql/transaction.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
32 | 28 |
33 using content::BrowserThread; | 29 using content::BrowserThread; |
34 | 30 |
35 // The test version of the history url database table ('url') is contained in | 31 // The test version of the history url database table ('url') is contained in |
36 // a database file created from a text file('url_history_provider_test.db.txt'). | 32 // a database file created from a text file('url_history_provider_test.db.txt'). |
37 // The only difference between this table and a live 'urls' table from a | 33 // The only difference between this table and a live 'urls' table from a |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 // Pass-through function to simplify our friendship with HistoryService. | 122 // Pass-through function to simplify our friendship with HistoryService. |
127 sql::Connection& GetDB(); | 123 sql::Connection& GetDB(); |
128 | 124 |
129 // Pass-through functions to simplify our friendship with InMemoryURLIndex. | 125 // Pass-through functions to simplify our friendship with InMemoryURLIndex. |
130 URLIndexPrivateData* GetPrivateData() const; | 126 URLIndexPrivateData* GetPrivateData() const; |
131 void ClearPrivateData(); | 127 void ClearPrivateData(); |
132 void set_history_dir(const FilePath& dir_path); | 128 void set_history_dir(const FilePath& dir_path); |
133 bool GetCacheFilePath(FilePath* file_path) const; | 129 bool GetCacheFilePath(FilePath* file_path) const; |
134 void PostRestoreFromCacheFileTask(); | 130 void PostRestoreFromCacheFileTask(); |
135 void PostSaveToCacheFileTask(); | 131 void PostSaveToCacheFileTask(); |
136 void Observe(int notification_type, | |
137 const content::NotificationSource& source, | |
138 const content::NotificationDetails& details); | |
139 const std::set<std::string>& scheme_whitelist(); | 132 const std::set<std::string>& scheme_whitelist(); |
140 | 133 |
141 | 134 |
142 // Pass-through functions to simplify our friendship with URLIndexPrivateData. | 135 // Pass-through functions to simplify our friendship with URLIndexPrivateData. |
143 bool UpdateURL(const URLRow& row); | 136 bool UpdateURL(const URLRow& row); |
144 bool DeleteURL(const GURL& url); | 137 bool DeleteURL(const GURL& url); |
145 | 138 |
146 // Data verification helper functions. | 139 // Data verification helper functions. |
147 void ExpectPrivateDataNotEmpty(const URLIndexPrivateData& data); | 140 void ExpectPrivateDataNotEmpty(const URLIndexPrivateData& data); |
148 void ExpectPrivateDataEmpty(const URLIndexPrivateData& data); | 141 void ExpectPrivateDataEmpty(const URLIndexPrivateData& data); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 } | 179 } |
187 | 180 |
188 void InMemoryURLIndexTest::PostRestoreFromCacheFileTask() { | 181 void InMemoryURLIndexTest::PostRestoreFromCacheFileTask() { |
189 url_index_->PostRestoreFromCacheFileTask(); | 182 url_index_->PostRestoreFromCacheFileTask(); |
190 } | 183 } |
191 | 184 |
192 void InMemoryURLIndexTest::PostSaveToCacheFileTask() { | 185 void InMemoryURLIndexTest::PostSaveToCacheFileTask() { |
193 url_index_->PostSaveToCacheFileTask(); | 186 url_index_->PostSaveToCacheFileTask(); |
194 } | 187 } |
195 | 188 |
196 void InMemoryURLIndexTest::Observe( | |
197 int notification_type, | |
198 const content::NotificationSource& source, | |
199 const content::NotificationDetails& details) { | |
200 url_index_->Observe(notification_type, source, details); | |
201 } | |
202 | |
203 const std::set<std::string>& InMemoryURLIndexTest::scheme_whitelist() { | 189 const std::set<std::string>& InMemoryURLIndexTest::scheme_whitelist() { |
204 return url_index_->scheme_whitelist(); | 190 return url_index_->scheme_whitelist(); |
205 } | 191 } |
206 | 192 |
207 bool InMemoryURLIndexTest::UpdateURL(const URLRow& row) { | 193 bool InMemoryURLIndexTest::UpdateURL(const URLRow& row) { |
208 return GetPrivateData()->UpdateURL(row, url_index_->languages_, | 194 return GetPrivateData()->UpdateURL(row, url_index_->languages_, |
209 url_index_->scheme_whitelist_); | 195 url_index_->scheme_whitelist_); |
210 } | 196 } |
211 | 197 |
212 bool InMemoryURLIndexTest::DeleteURL(const GURL& url) { | 198 bool InMemoryURLIndexTest::DeleteURL(const GURL& url) { |
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
838 URLRow unqualified_row(GURL("http://www.brokeandaloneinmanitoba.com/"), | 824 URLRow unqualified_row(GURL("http://www.brokeandaloneinmanitoba.com/"), |
839 new_row_id++); | 825 new_row_id++); |
840 EXPECT_FALSE(UpdateURL(new_row)); | 826 EXPECT_FALSE(UpdateURL(new_row)); |
841 } | 827 } |
842 | 828 |
843 TEST_F(InMemoryURLIndexTest, DeleteRows) { | 829 TEST_F(InMemoryURLIndexTest, DeleteRows) { |
844 ScoredHistoryMatches matches = | 830 ScoredHistoryMatches matches = |
845 url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudgeReport")); | 831 url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudgeReport")); |
846 ASSERT_EQ(1U, matches.size()); | 832 ASSERT_EQ(1U, matches.size()); |
847 | 833 |
848 // Delete the URL for then search again. | 834 // Determine the row id for that result, delete that id, then search again. |
849 EXPECT_TRUE(DeleteURL(matches[0].url_info.url())); | 835 EXPECT_TRUE(DeleteURL(matches[0].url_info.url())); |
850 EXPECT_TRUE(url_index_->HistoryItemsForTerms( | 836 EXPECT_TRUE(url_index_->HistoryItemsForTerms( |
851 ASCIIToUTF16("DrudgeReport")).empty()); | 837 ASCIIToUTF16("DrudgeReport")).empty()); |
852 | 838 |
853 // Make up an URL that does not exist in the database and delete it. | 839 // Make up an URL that does not exist in the database and delete it. |
854 GURL url("http://www.hokeypokey.com/putyourrightfootin.html"); | 840 GURL url("http://www.hokeypokey.com/putyourrightfootin.html"); |
855 EXPECT_FALSE(DeleteURL(url)); | 841 EXPECT_FALSE(DeleteURL(url)); |
856 } | 842 } |
857 | 843 |
858 TEST_F(InMemoryURLIndexTest, ExpireRow) { | |
859 ScoredHistoryMatches matches = | |
860 url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudgeReport")); | |
861 ASSERT_EQ(1U, matches.size()); | |
862 | |
863 // Determine the row id for the result, remember that id, broadcast a | |
864 // delete notification, then ensure that the row has been deleted. | |
865 URLsDeletedDetails* deleted_details = new URLsDeletedDetails; | |
866 deleted_details->all_history = false; | |
867 deleted_details->rows.push_back(matches[0].url_info); | |
868 Observe(chrome::NOTIFICATION_HISTORY_URLS_DELETED, | |
869 content::Source<InMemoryURLIndexTest>(this), | |
870 content::Details<history::HistoryDetails>(deleted_details)); | |
871 EXPECT_TRUE(url_index_->HistoryItemsForTerms( | |
872 ASCIIToUTF16("DrudgeReport")).empty()); | |
873 } | |
874 | |
875 TEST_F(InMemoryURLIndexTest, WhitelistedURLs) { | 844 TEST_F(InMemoryURLIndexTest, WhitelistedURLs) { |
876 struct TestData { | 845 struct TestData { |
877 const std::string url_spec; | 846 const std::string url_spec; |
878 const bool expected_is_whitelisted; | 847 const bool expected_is_whitelisted; |
879 } data[] = { | 848 } data[] = { |
880 // URLs with whitelisted schemes. | 849 // URLs with whitelisted schemes. |
881 { "about:histograms", true }, | 850 { "about:histograms", true }, |
882 { "chrome://settings", true }, | 851 { "chrome://settings", true }, |
883 { "file://localhost/Users/joeschmoe/sekrets", true }, | 852 { "file://localhost/Users/joeschmoe/sekrets", true }, |
884 { "ftp://public.mycompany.com/myfile.txt", true }, | 853 { "ftp://public.mycompany.com/myfile.txt", true }, |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1080 full_file_path.GetComponents(&actual_parts); | 1049 full_file_path.GetComponents(&actual_parts); |
1081 ASSERT_EQ(expected_parts.size(), actual_parts.size()); | 1050 ASSERT_EQ(expected_parts.size(), actual_parts.size()); |
1082 size_t count = expected_parts.size(); | 1051 size_t count = expected_parts.size(); |
1083 for (size_t i = 0; i < count; ++i) | 1052 for (size_t i = 0; i < count; ++i) |
1084 EXPECT_EQ(expected_parts[i], actual_parts[i]); | 1053 EXPECT_EQ(expected_parts[i], actual_parts[i]); |
1085 // Must clear the history_dir_ to satisfy the dtor's DCHECK. | 1054 // Must clear the history_dir_ to satisfy the dtor's DCHECK. |
1086 set_history_dir(FilePath()); | 1055 set_history_dir(FilePath()); |
1087 } | 1056 } |
1088 | 1057 |
1089 } // namespace history | 1058 } // namespace history |
OLD | NEW |