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

Side by Side Diff: chrome/browser/history/in_memory_url_index_unittest.cc

Issue 10096015: Single URL Expires Were Not Being Deleted. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 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
« no previous file with comments | « chrome/browser/history/history_types.h ('k') | chrome/browser/history/shortcuts_backend.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <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"
20 #include "chrome/browser/history/in_memory_url_index_types.h" 21 #include "chrome/browser/history/in_memory_url_index_types.h"
21 #include "chrome/browser/history/in_memory_url_index.h" 22 #include "chrome/browser/history/in_memory_url_index.h"
22 #include "chrome/browser/history/url_index_private_data.h" 23 #include "chrome/browser/history/url_index_private_data.h"
24 #include "chrome/common/chrome_notification_types.h"
23 #include "chrome/common/chrome_paths.h" 25 #include "chrome/common/chrome_paths.h"
26 #include "content/public/browser/notification_details.h"
27 #include "content/public/browser/notification_source.h"
24 #include "chrome/test/base/testing_profile.h" 28 #include "chrome/test/base/testing_profile.h"
25 #include "content/test/test_browser_thread.h" 29 #include "content/test/test_browser_thread.h"
26 #include "sql/transaction.h" 30 #include "sql/transaction.h"
27 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
28 32
29 using content::BrowserThread; 33 using content::BrowserThread;
30 34
31 // The test version of the history url database table ('url') is contained in 35 // The test version of the history url database table ('url') is contained in
32 // a database file created from a text file('url_history_provider_test.db.txt'). 36 // a database file created from a text file('url_history_provider_test.db.txt').
33 // The only difference between this table and a live 'urls' table from a 37 // 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
122 // Pass-through function to simplify our friendship with HistoryService. 126 // Pass-through function to simplify our friendship with HistoryService.
123 sql::Connection& GetDB(); 127 sql::Connection& GetDB();
124 128
125 // Pass-through functions to simplify our friendship with InMemoryURLIndex. 129 // Pass-through functions to simplify our friendship with InMemoryURLIndex.
126 URLIndexPrivateData* GetPrivateData() const; 130 URLIndexPrivateData* GetPrivateData() const;
127 void ClearPrivateData(); 131 void ClearPrivateData();
128 void set_history_dir(const FilePath& dir_path); 132 void set_history_dir(const FilePath& dir_path);
129 bool GetCacheFilePath(FilePath* file_path) const; 133 bool GetCacheFilePath(FilePath* file_path) const;
130 void PostRestoreFromCacheFileTask(); 134 void PostRestoreFromCacheFileTask();
131 void PostSaveToCacheFileTask(); 135 void PostSaveToCacheFileTask();
136 void Observe(int notification_type,
137 const content::NotificationSource& source,
138 const content::NotificationDetails& details);
132 const std::set<std::string>& scheme_whitelist(); 139 const std::set<std::string>& scheme_whitelist();
133 140
134 141
135 // Pass-through functions to simplify our friendship with URLIndexPrivateData. 142 // Pass-through functions to simplify our friendship with URLIndexPrivateData.
136 bool UpdateURL(const URLRow& row); 143 bool UpdateURL(const URLRow& row);
137 bool DeleteURL(const GURL& url); 144 bool DeleteURL(const GURL& url);
138 145
139 // Data verification helper functions. 146 // Data verification helper functions.
140 void ExpectPrivateDataNotEmpty(const URLIndexPrivateData& data); 147 void ExpectPrivateDataNotEmpty(const URLIndexPrivateData& data);
141 void ExpectPrivateDataEmpty(const URLIndexPrivateData& data); 148 void ExpectPrivateDataEmpty(const URLIndexPrivateData& data);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } 186 }
180 187
181 void InMemoryURLIndexTest::PostRestoreFromCacheFileTask() { 188 void InMemoryURLIndexTest::PostRestoreFromCacheFileTask() {
182 url_index_->PostRestoreFromCacheFileTask(); 189 url_index_->PostRestoreFromCacheFileTask();
183 } 190 }
184 191
185 void InMemoryURLIndexTest::PostSaveToCacheFileTask() { 192 void InMemoryURLIndexTest::PostSaveToCacheFileTask() {
186 url_index_->PostSaveToCacheFileTask(); 193 url_index_->PostSaveToCacheFileTask();
187 } 194 }
188 195
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
189 const std::set<std::string>& InMemoryURLIndexTest::scheme_whitelist() { 203 const std::set<std::string>& InMemoryURLIndexTest::scheme_whitelist() {
190 return url_index_->scheme_whitelist(); 204 return url_index_->scheme_whitelist();
191 } 205 }
192 206
193 bool InMemoryURLIndexTest::UpdateURL(const URLRow& row) { 207 bool InMemoryURLIndexTest::UpdateURL(const URLRow& row) {
194 return GetPrivateData()->UpdateURL(row, url_index_->languages_, 208 return GetPrivateData()->UpdateURL(row, url_index_->languages_,
195 url_index_->scheme_whitelist_); 209 url_index_->scheme_whitelist_);
196 } 210 }
197 211
198 bool InMemoryURLIndexTest::DeleteURL(const GURL& url) { 212 bool InMemoryURLIndexTest::DeleteURL(const GURL& url) {
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 URLRow unqualified_row(GURL("http://www.brokeandaloneinmanitoba.com/"), 838 URLRow unqualified_row(GURL("http://www.brokeandaloneinmanitoba.com/"),
825 new_row_id++); 839 new_row_id++);
826 EXPECT_FALSE(UpdateURL(new_row)); 840 EXPECT_FALSE(UpdateURL(new_row));
827 } 841 }
828 842
829 TEST_F(InMemoryURLIndexTest, DeleteRows) { 843 TEST_F(InMemoryURLIndexTest, DeleteRows) {
830 ScoredHistoryMatches matches = 844 ScoredHistoryMatches matches =
831 url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudgeReport")); 845 url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudgeReport"));
832 ASSERT_EQ(1U, matches.size()); 846 ASSERT_EQ(1U, matches.size());
833 847
834 // Determine the row id for that result, delete that id, then search again. 848 // Delete the URL then search again.
835 EXPECT_TRUE(DeleteURL(matches[0].url_info.url())); 849 EXPECT_TRUE(DeleteURL(matches[0].url_info.url()));
836 EXPECT_TRUE(url_index_->HistoryItemsForTerms( 850 EXPECT_TRUE(url_index_->HistoryItemsForTerms(
837 ASCIIToUTF16("DrudgeReport")).empty()); 851 ASCIIToUTF16("DrudgeReport")).empty());
838 852
839 // Make up an URL that does not exist in the database and delete it. 853 // Make up an URL that does not exist in the database and delete it.
840 GURL url("http://www.hokeypokey.com/putyourrightfootin.html"); 854 GURL url("http://www.hokeypokey.com/putyourrightfootin.html");
841 EXPECT_FALSE(DeleteURL(url)); 855 EXPECT_FALSE(DeleteURL(url));
842 } 856 }
843 857
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;
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
844 TEST_F(InMemoryURLIndexTest, WhitelistedURLs) { 875 TEST_F(InMemoryURLIndexTest, WhitelistedURLs) {
845 struct TestData { 876 struct TestData {
846 const std::string url_spec; 877 const std::string url_spec;
847 const bool expected_is_whitelisted; 878 const bool expected_is_whitelisted;
848 } data[] = { 879 } data[] = {
849 // URLs with whitelisted schemes. 880 // URLs with whitelisted schemes.
850 { "about:histograms", true }, 881 { "about:histograms", true },
851 { "chrome://settings", true }, 882 { "chrome://settings", true },
852 { "file://localhost/Users/joeschmoe/sekrets", true }, 883 { "file://localhost/Users/joeschmoe/sekrets", true },
853 { "ftp://public.mycompany.com/myfile.txt", true }, 884 { "ftp://public.mycompany.com/myfile.txt", true },
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 full_file_path.GetComponents(&actual_parts); 1080 full_file_path.GetComponents(&actual_parts);
1050 ASSERT_EQ(expected_parts.size(), actual_parts.size()); 1081 ASSERT_EQ(expected_parts.size(), actual_parts.size());
1051 size_t count = expected_parts.size(); 1082 size_t count = expected_parts.size();
1052 for (size_t i = 0; i < count; ++i) 1083 for (size_t i = 0; i < count; ++i)
1053 EXPECT_EQ(expected_parts[i], actual_parts[i]); 1084 EXPECT_EQ(expected_parts[i], actual_parts[i]);
1054 // Must clear the history_dir_ to satisfy the dtor's DCHECK. 1085 // Must clear the history_dir_ to satisfy the dtor's DCHECK.
1055 set_history_dir(FilePath()); 1086 set_history_dir(FilePath());
1056 } 1087 }
1057 1088
1058 } // namespace history 1089 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/history_types.h ('k') | chrome/browser/history/shortcuts_backend.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698