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

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

Issue 562603002: Move PageTransition from //content/public/common to //ui/base (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 3 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
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 "chrome/browser/history/history_backend.h" 5 #include "chrome/browser/history/history_backend.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 } 225 }
226 226
227 class HistoryBackendTest : public HistoryBackendTestBase { 227 class HistoryBackendTest : public HistoryBackendTestBase {
228 public: 228 public:
229 HistoryBackendTest() {} 229 HistoryBackendTest() {}
230 virtual ~HistoryBackendTest() {} 230 virtual ~HistoryBackendTest() {}
231 231
232 protected: 232 protected:
233 void AddRedirectChain(const char* sequence[], int page_id) { 233 void AddRedirectChain(const char* sequence[], int page_id) {
234 AddRedirectChainWithTransitionAndTime(sequence, page_id, 234 AddRedirectChainWithTransitionAndTime(sequence, page_id,
235 content::PAGE_TRANSITION_LINK, 235 ui::PAGE_TRANSITION_LINK,
236 Time::Now()); 236 Time::Now());
237 } 237 }
238 238
239 void AddRedirectChainWithTransitionAndTime( 239 void AddRedirectChainWithTransitionAndTime(
240 const char* sequence[], 240 const char* sequence[],
241 int page_id, 241 int page_id,
242 content::PageTransition transition, 242 ui::PageTransition transition,
243 base::Time time) { 243 base::Time time) {
244 history::RedirectList redirects; 244 history::RedirectList redirects;
245 for (int i = 0; sequence[i] != NULL; ++i) 245 for (int i = 0; sequence[i] != NULL; ++i)
246 redirects.push_back(GURL(sequence[i])); 246 redirects.push_back(GURL(sequence[i]));
247 247
248 ContextID context_id = reinterpret_cast<ContextID>(1); 248 ContextID context_id = reinterpret_cast<ContextID>(1);
249 history::HistoryAddPageArgs request( 249 history::HistoryAddPageArgs request(
250 redirects.back(), time, context_id, page_id, GURL(), 250 redirects.back(), time, context_id, page_id, GURL(),
251 redirects, transition, history::SOURCE_BROWSED, 251 redirects, transition, history::SOURCE_BROWSED,
252 true); 252 true);
(...skipping 11 matching lines...) Expand all
264 base::Time time, 264 base::Time time,
265 int* transition1, int* transition2) { 265 int* transition1, int* transition2) {
266 ContextID dummy_context_id = reinterpret_cast<ContextID>(0x87654321); 266 ContextID dummy_context_id = reinterpret_cast<ContextID>(0x87654321);
267 history::RedirectList redirects; 267 history::RedirectList redirects;
268 if (url1.is_valid()) 268 if (url1.is_valid())
269 redirects.push_back(url1); 269 redirects.push_back(url1);
270 if (url2.is_valid()) 270 if (url2.is_valid())
271 redirects.push_back(url2); 271 redirects.push_back(url2);
272 HistoryAddPageArgs request( 272 HistoryAddPageArgs request(
273 url2, time, dummy_context_id, 0, url1, 273 url2, time, dummy_context_id, 0, url1,
274 redirects, content::PAGE_TRANSITION_CLIENT_REDIRECT, 274 redirects, ui::PAGE_TRANSITION_CLIENT_REDIRECT,
275 history::SOURCE_BROWSED, did_replace); 275 history::SOURCE_BROWSED, did_replace);
276 backend_->AddPage(request); 276 backend_->AddPage(request);
277 277
278 *transition1 = GetTransition(url1); 278 *transition1 = GetTransition(url1);
279 *transition2 = GetTransition(url2); 279 *transition2 = GetTransition(url2);
280 } 280 }
281 281
282 int GetTransition(const GURL& url) { 282 int GetTransition(const GURL& url) {
283 if (!url.is_valid()) 283 if (!url.is_valid())
284 return 0; 284 return 0;
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 // Checks that adding a visit, then calling DeleteAll, and then trying to add 621 // Checks that adding a visit, then calling DeleteAll, and then trying to add
622 // data for the visited page works. This can happen when clearing the history 622 // data for the visited page works. This can happen when clearing the history
623 // immediately after visiting a page. 623 // immediately after visiting a page.
624 TEST_F(HistoryBackendTest, DeleteAllThenAddData) { 624 TEST_F(HistoryBackendTest, DeleteAllThenAddData) {
625 ASSERT_TRUE(backend_.get()); 625 ASSERT_TRUE(backend_.get());
626 626
627 Time visit_time = Time::Now(); 627 Time visit_time = Time::Now();
628 GURL url("http://www.google.com/"); 628 GURL url("http://www.google.com/");
629 HistoryAddPageArgs request(url, visit_time, NULL, 0, GURL(), 629 HistoryAddPageArgs request(url, visit_time, NULL, 0, GURL(),
630 history::RedirectList(), 630 history::RedirectList(),
631 content::PAGE_TRANSITION_KEYWORD_GENERATED, 631 ui::PAGE_TRANSITION_KEYWORD_GENERATED,
632 history::SOURCE_BROWSED, false); 632 history::SOURCE_BROWSED, false);
633 backend_->AddPage(request); 633 backend_->AddPage(request);
634 634
635 // Check that a row was added. 635 // Check that a row was added.
636 URLRow outrow; 636 URLRow outrow;
637 EXPECT_TRUE(backend_->db_->GetRowForURL(url, &outrow)); 637 EXPECT_TRUE(backend_->db_->GetRowForURL(url, &outrow));
638 638
639 // Check that the visit was added. 639 // Check that the visit was added.
640 VisitVector all_visits; 640 VisitVector all_visits;
641 backend_->db_->GetAllVisitsInRange(Time(), Time(), 0, &all_visits); 641 backend_->db_->GetAllVisitsInRange(Time(), Time(), 0, &all_visits);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 // Tests a handful of assertions for a navigation with a type of 764 // Tests a handful of assertions for a navigation with a type of
765 // KEYWORD_GENERATED. 765 // KEYWORD_GENERATED.
766 TEST_F(HistoryBackendTest, KeywordGenerated) { 766 TEST_F(HistoryBackendTest, KeywordGenerated) {
767 ASSERT_TRUE(backend_.get()); 767 ASSERT_TRUE(backend_.get());
768 768
769 GURL url("http://google.com"); 769 GURL url("http://google.com");
770 770
771 Time visit_time = Time::Now() - base::TimeDelta::FromDays(1); 771 Time visit_time = Time::Now() - base::TimeDelta::FromDays(1);
772 HistoryAddPageArgs request(url, visit_time, NULL, 0, GURL(), 772 HistoryAddPageArgs request(url, visit_time, NULL, 0, GURL(),
773 history::RedirectList(), 773 history::RedirectList(),
774 content::PAGE_TRANSITION_KEYWORD_GENERATED, 774 ui::PAGE_TRANSITION_KEYWORD_GENERATED,
775 history::SOURCE_BROWSED, false); 775 history::SOURCE_BROWSED, false);
776 backend_->AddPage(request); 776 backend_->AddPage(request);
777 777
778 // A row should have been added for the url. 778 // A row should have been added for the url.
779 URLRow row; 779 URLRow row;
780 URLID url_id = backend_->db()->GetRowForURL(url, &row); 780 URLID url_id = backend_->db()->GetRowForURL(url, &row);
781 ASSERT_NE(0, url_id); 781 ASSERT_NE(0, url_id);
782 782
783 // The typed count should be 1. 783 // The typed count should be 1.
784 ASSERT_EQ(1, row.typed_count()); 784 ASSERT_EQ(1, row.typed_count());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 TEST_F(HistoryBackendTest, ClientRedirect) { 816 TEST_F(HistoryBackendTest, ClientRedirect) {
817 ASSERT_TRUE(backend_.get()); 817 ASSERT_TRUE(backend_.get());
818 818
819 int transition1; 819 int transition1;
820 int transition2; 820 int transition2;
821 821
822 // Initial transition to page A. 822 // Initial transition to page A.
823 GURL url_a("http://google.com/a"); 823 GURL url_a("http://google.com/a");
824 AddClientRedirect(GURL(), url_a, false, base::Time(), 824 AddClientRedirect(GURL(), url_a, false, base::Time(),
825 &transition1, &transition2); 825 &transition1, &transition2);
826 EXPECT_TRUE(transition2 & content::PAGE_TRANSITION_CHAIN_END); 826 EXPECT_TRUE(transition2 & ui::PAGE_TRANSITION_CHAIN_END);
827 827
828 // User initiated redirect to page B. 828 // User initiated redirect to page B.
829 GURL url_b("http://google.com/b"); 829 GURL url_b("http://google.com/b");
830 AddClientRedirect(url_a, url_b, false, base::Time(), 830 AddClientRedirect(url_a, url_b, false, base::Time(),
831 &transition1, &transition2); 831 &transition1, &transition2);
832 EXPECT_TRUE(transition1 & content::PAGE_TRANSITION_CHAIN_END); 832 EXPECT_TRUE(transition1 & ui::PAGE_TRANSITION_CHAIN_END);
833 EXPECT_TRUE(transition2 & content::PAGE_TRANSITION_CHAIN_END); 833 EXPECT_TRUE(transition2 & ui::PAGE_TRANSITION_CHAIN_END);
834 834
835 // Non-user initiated redirect to page C. 835 // Non-user initiated redirect to page C.
836 GURL url_c("http://google.com/c"); 836 GURL url_c("http://google.com/c");
837 AddClientRedirect(url_b, url_c, true, base::Time(), 837 AddClientRedirect(url_b, url_c, true, base::Time(),
838 &transition1, &transition2); 838 &transition1, &transition2);
839 EXPECT_FALSE(transition1 & content::PAGE_TRANSITION_CHAIN_END); 839 EXPECT_FALSE(transition1 & ui::PAGE_TRANSITION_CHAIN_END);
840 EXPECT_TRUE(transition2 & content::PAGE_TRANSITION_CHAIN_END); 840 EXPECT_TRUE(transition2 & ui::PAGE_TRANSITION_CHAIN_END);
841 } 841 }
842 842
843 TEST_F(HistoryBackendTest, AddPagesWithDetails) { 843 TEST_F(HistoryBackendTest, AddPagesWithDetails) {
844 ASSERT_TRUE(backend_.get()); 844 ASSERT_TRUE(backend_.get());
845 845
846 // Import one non-typed URL, and two recent and one expired typed URLs. 846 // Import one non-typed URL, and two recent and one expired typed URLs.
847 URLRow row1(GURL("https://news.google.com/")); 847 URLRow row1(GURL("https://news.google.com/"));
848 row1.set_visit_count(1); 848 row1.set_visit_count(1);
849 row1.set_last_visit(Time::Now()); 849 row1.set_last_visit(Time::Now());
850 URLRow row2(GURL("https://www.google.com/")); 850 URLRow row2(GURL("https://www.google.com/"));
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 ASSERT_TRUE(backend_.get()); 1099 ASSERT_TRUE(backend_.get());
1100 1100
1101 GURL url("http://anyuser:anypass@www.google.com"); 1101 GURL url("http://anyuser:anypass@www.google.com");
1102 GURL stripped_url("http://www.google.com"); 1102 GURL stripped_url("http://www.google.com");
1103 1103
1104 // Clear all history. 1104 // Clear all history.
1105 backend_->DeleteAllHistory(); 1105 backend_->DeleteAllHistory();
1106 1106
1107 // Visit the url with username, password. 1107 // Visit the url with username, password.
1108 backend_->AddPageVisit(url, base::Time::Now(), 0, 1108 backend_->AddPageVisit(url, base::Time::Now(), 0,
1109 content::PageTransitionFromInt( 1109 ui::PageTransitionFromInt(
1110 content::PageTransitionGetQualifier(content::PAGE_TRANSITION_TYPED)), 1110 ui::PageTransitionGetQualifier(ui::PAGE_TRANSITION_TYPED)),
1111 history::SOURCE_BROWSED); 1111 history::SOURCE_BROWSED);
1112 1112
1113 // Fetch the row information about stripped url from history db. 1113 // Fetch the row information about stripped url from history db.
1114 VisitVector visits; 1114 VisitVector visits;
1115 URLID row_id = backend_->db_->GetRowForURL(stripped_url, NULL); 1115 URLID row_id = backend_->db_->GetRowForURL(stripped_url, NULL);
1116 backend_->db_->GetVisitsForURL(row_id, &visits); 1116 backend_->db_->GetVisitsForURL(row_id, &visits);
1117 1117
1118 // Check if stripped url is stored in database. 1118 // Check if stripped url is stored in database.
1119 ASSERT_EQ(1U, visits.size()); 1119 ASSERT_EQ(1U, visits.size());
1120 } 1120 }
1121 1121
1122 TEST_F(HistoryBackendTest, AddPageVisitSource) { 1122 TEST_F(HistoryBackendTest, AddPageVisitSource) {
1123 ASSERT_TRUE(backend_.get()); 1123 ASSERT_TRUE(backend_.get());
1124 1124
1125 GURL url("http://www.google.com"); 1125 GURL url("http://www.google.com");
1126 1126
1127 // Clear all history. 1127 // Clear all history.
1128 backend_->DeleteAllHistory(); 1128 backend_->DeleteAllHistory();
1129 1129
1130 // Assume visiting the url from an externsion. 1130 // Assume visiting the url from an externsion.
1131 backend_->AddPageVisit( 1131 backend_->AddPageVisit(
1132 url, base::Time::Now(), 0, content::PAGE_TRANSITION_TYPED, 1132 url, base::Time::Now(), 0, ui::PAGE_TRANSITION_TYPED,
1133 history::SOURCE_EXTENSION); 1133 history::SOURCE_EXTENSION);
1134 // Assume the url is imported from Firefox. 1134 // Assume the url is imported from Firefox.
1135 backend_->AddPageVisit(url, base::Time::Now(), 0, 1135 backend_->AddPageVisit(url, base::Time::Now(), 0,
1136 content::PAGE_TRANSITION_TYPED, 1136 ui::PAGE_TRANSITION_TYPED,
1137 history::SOURCE_FIREFOX_IMPORTED); 1137 history::SOURCE_FIREFOX_IMPORTED);
1138 // Assume this url is also synced. 1138 // Assume this url is also synced.
1139 backend_->AddPageVisit(url, base::Time::Now(), 0, 1139 backend_->AddPageVisit(url, base::Time::Now(), 0,
1140 content::PAGE_TRANSITION_TYPED, 1140 ui::PAGE_TRANSITION_TYPED,
1141 history::SOURCE_SYNCED); 1141 history::SOURCE_SYNCED);
1142 1142
1143 // Fetch the row information about the url from history db. 1143 // Fetch the row information about the url from history db.
1144 VisitVector visits; 1144 VisitVector visits;
1145 URLID row_id = backend_->db_->GetRowForURL(url, NULL); 1145 URLID row_id = backend_->db_->GetRowForURL(url, NULL);
1146 backend_->db_->GetVisitsForURL(row_id, &visits); 1146 backend_->db_->GetVisitsForURL(row_id, &visits);
1147 1147
1148 // Check if all the visits to the url are stored in database. 1148 // Check if all the visits to the url are stored in database.
1149 ASSERT_EQ(3U, visits.size()); 1149 ASSERT_EQ(3U, visits.size());
1150 VisitSourceMap visit_sources; 1150 VisitSourceMap visit_sources;
(...skipping 25 matching lines...) Expand all
1176 // Clear all history. 1176 // Clear all history.
1177 backend_->DeleteAllHistory(); 1177 backend_->DeleteAllHistory();
1178 1178
1179 // Create visit times 1179 // Create visit times
1180 base::Time recent_time = base::Time::Now(); 1180 base::Time recent_time = base::Time::Now();
1181 base::TimeDelta visit_age = base::TimeDelta::FromDays(3); 1181 base::TimeDelta visit_age = base::TimeDelta::FromDays(3);
1182 base::Time older_time = recent_time - visit_age; 1182 base::Time older_time = recent_time - visit_age;
1183 1183
1184 // Visit the url with recent time. 1184 // Visit the url with recent time.
1185 backend_->AddPageVisit(url, recent_time, 0, 1185 backend_->AddPageVisit(url, recent_time, 0,
1186 content::PageTransitionFromInt( 1186 ui::PageTransitionFromInt(
1187 content::PageTransitionGetQualifier(content::PAGE_TRANSITION_TYPED)), 1187 ui::PageTransitionGetQualifier(ui::PAGE_TRANSITION_TYPED)),
1188 history::SOURCE_BROWSED); 1188 history::SOURCE_BROWSED);
1189 1189
1190 // Add to the url a visit with older time (could be syncing from another 1190 // Add to the url a visit with older time (could be syncing from another
1191 // client, etc.). 1191 // client, etc.).
1192 backend_->AddPageVisit(url, older_time, 0, 1192 backend_->AddPageVisit(url, older_time, 0,
1193 content::PageTransitionFromInt( 1193 ui::PageTransitionFromInt(
1194 content::PageTransitionGetQualifier(content::PAGE_TRANSITION_TYPED)), 1194 ui::PageTransitionGetQualifier(ui::PAGE_TRANSITION_TYPED)),
1195 history::SOURCE_SYNCED); 1195 history::SOURCE_SYNCED);
1196 1196
1197 // Fetch the row information about url from history db. 1197 // Fetch the row information about url from history db.
1198 VisitVector visits; 1198 VisitVector visits;
1199 URLRow row; 1199 URLRow row;
1200 URLID row_id = backend_->db_->GetRowForURL(url, &row); 1200 URLID row_id = backend_->db_->GetRowForURL(url, &row);
1201 backend_->db_->GetVisitsForURL(row_id, &visits); 1201 backend_->db_->GetVisitsForURL(row_id, &visits);
1202 1202
1203 // Last visit time should be the most recent time, not the most recently added 1203 // Last visit time should be the most recent time, not the most recently added
1204 // visit. 1204 // visit.
1205 ASSERT_EQ(2U, visits.size()); 1205 ASSERT_EQ(2U, visits.size());
1206 ASSERT_EQ(recent_time, row.last_visit()); 1206 ASSERT_EQ(recent_time, row.last_visit());
1207 } 1207 }
1208 1208
1209 TEST_F(HistoryBackendTest, AddPageVisitFiresNotificationWithCorrectDetails) { 1209 TEST_F(HistoryBackendTest, AddPageVisitFiresNotificationWithCorrectDetails) {
1210 ASSERT_TRUE(backend_.get()); 1210 ASSERT_TRUE(backend_.get());
1211 1211
1212 GURL url1("http://www.google.com"); 1212 GURL url1("http://www.google.com");
1213 GURL url2("http://maps.google.com"); 1213 GURL url2("http://maps.google.com");
1214 1214
1215 // Clear all history. 1215 // Clear all history.
1216 backend_->DeleteAllHistory(); 1216 backend_->DeleteAllHistory();
1217 ClearBroadcastedNotifications(); 1217 ClearBroadcastedNotifications();
1218 1218
1219 // Visit two distinct URLs, the second one twice. 1219 // Visit two distinct URLs, the second one twice.
1220 backend_->AddPageVisit(url1, base::Time::Now(), 0, 1220 backend_->AddPageVisit(url1, base::Time::Now(), 0,
1221 content::PAGE_TRANSITION_LINK, 1221 ui::PAGE_TRANSITION_LINK,
1222 history::SOURCE_BROWSED); 1222 history::SOURCE_BROWSED);
1223 for (int i = 0; i < 2; ++i) { 1223 for (int i = 0; i < 2; ++i) {
1224 backend_->AddPageVisit(url2, base::Time::Now(), 0, 1224 backend_->AddPageVisit(url2, base::Time::Now(), 0,
1225 content::PAGE_TRANSITION_TYPED, 1225 ui::PAGE_TRANSITION_TYPED,
1226 history::SOURCE_BROWSED); 1226 history::SOURCE_BROWSED);
1227 } 1227 }
1228 1228
1229 URLRow stored_row1, stored_row2; 1229 URLRow stored_row1, stored_row2;
1230 EXPECT_NE(0, backend_->db_->GetRowForURL(url1, &stored_row1)); 1230 EXPECT_NE(0, backend_->db_->GetRowForURL(url1, &stored_row1));
1231 EXPECT_NE(0, backend_->db_->GetRowForURL(url2, &stored_row2)); 1231 EXPECT_NE(0, backend_->db_->GetRowForURL(url2, &stored_row2));
1232 1232
1233 // Expect that NOTIFICATION_HISTORY_URLS_VISITED has been fired 3x, and that 1233 // Expect that NOTIFICATION_HISTORY_URLS_VISITED has been fired 3x, and that
1234 // each time, the URLRows have the correct URLs and IDs set. 1234 // each time, the URLRows have the correct URLs and IDs set.
1235 ASSERT_EQ(3, num_broadcasted_notifications()); 1235 ASSERT_EQ(3, num_broadcasted_notifications());
1236 ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URL_VISITED, 1236 ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URL_VISITED,
1237 broadcasted_notifications()[0].first); 1237 broadcasted_notifications()[0].first);
1238 const URLVisitedDetails* details = static_cast<const URLVisitedDetails*>( 1238 const URLVisitedDetails* details = static_cast<const URLVisitedDetails*>(
1239 broadcasted_notifications()[0].second); 1239 broadcasted_notifications()[0].second);
1240 EXPECT_EQ(content::PAGE_TRANSITION_LINK, 1240 EXPECT_EQ(ui::PAGE_TRANSITION_LINK,
1241 content::PageTransitionStripQualifier(details->transition)); 1241 ui::PageTransitionStripQualifier(details->transition));
1242 EXPECT_EQ(stored_row1.id(), details->row.id()); 1242 EXPECT_EQ(stored_row1.id(), details->row.id());
1243 EXPECT_EQ(stored_row1.url(), details->row.url()); 1243 EXPECT_EQ(stored_row1.url(), details->row.url());
1244 1244
1245 // No further checking, this case analogous to the first one. 1245 // No further checking, this case analogous to the first one.
1246 ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URL_VISITED, 1246 ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URL_VISITED,
1247 broadcasted_notifications()[1].first); 1247 broadcasted_notifications()[1].first);
1248 1248
1249 ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URL_VISITED, 1249 ASSERT_EQ(chrome::NOTIFICATION_HISTORY_URL_VISITED,
1250 broadcasted_notifications()[2].first); 1250 broadcasted_notifications()[2].first);
1251 details = static_cast<const URLVisitedDetails*>( 1251 details = static_cast<const URLVisitedDetails*>(
1252 broadcasted_notifications()[2].second); 1252 broadcasted_notifications()[2].second);
1253 EXPECT_EQ(content::PAGE_TRANSITION_TYPED, 1253 EXPECT_EQ(ui::PAGE_TRANSITION_TYPED,
1254 content::PageTransitionStripQualifier(details->transition)); 1254 ui::PageTransitionStripQualifier(details->transition));
1255 EXPECT_EQ(stored_row2.id(), details->row.id()); 1255 EXPECT_EQ(stored_row2.id(), details->row.id());
1256 EXPECT_EQ(stored_row2.url(), details->row.url()); 1256 EXPECT_EQ(stored_row2.url(), details->row.url());
1257 } 1257 }
1258 1258
1259 TEST_F(HistoryBackendTest, AddPageArgsSource) { 1259 TEST_F(HistoryBackendTest, AddPageArgsSource) {
1260 ASSERT_TRUE(backend_.get()); 1260 ASSERT_TRUE(backend_.get());
1261 1261
1262 GURL url("http://testpageargs.com"); 1262 GURL url("http://testpageargs.com");
1263 1263
1264 // Assume this page is browsed by user. 1264 // Assume this page is browsed by user.
1265 HistoryAddPageArgs request1(url, base::Time::Now(), NULL, 0, GURL(), 1265 HistoryAddPageArgs request1(url, base::Time::Now(), NULL, 0, GURL(),
1266 history::RedirectList(), 1266 history::RedirectList(),
1267 content::PAGE_TRANSITION_KEYWORD_GENERATED, 1267 ui::PAGE_TRANSITION_KEYWORD_GENERATED,
1268 history::SOURCE_BROWSED, false); 1268 history::SOURCE_BROWSED, false);
1269 backend_->AddPage(request1); 1269 backend_->AddPage(request1);
1270 // Assume this page is synced. 1270 // Assume this page is synced.
1271 HistoryAddPageArgs request2(url, base::Time::Now(), NULL, 0, GURL(), 1271 HistoryAddPageArgs request2(url, base::Time::Now(), NULL, 0, GURL(),
1272 history::RedirectList(), 1272 history::RedirectList(),
1273 content::PAGE_TRANSITION_LINK, 1273 ui::PAGE_TRANSITION_LINK,
1274 history::SOURCE_SYNCED, false); 1274 history::SOURCE_SYNCED, false);
1275 backend_->AddPage(request2); 1275 backend_->AddPage(request2);
1276 // Assume this page is browsed again. 1276 // Assume this page is browsed again.
1277 HistoryAddPageArgs request3(url, base::Time::Now(), NULL, 0, GURL(), 1277 HistoryAddPageArgs request3(url, base::Time::Now(), NULL, 0, GURL(),
1278 history::RedirectList(), 1278 history::RedirectList(),
1279 content::PAGE_TRANSITION_TYPED, 1279 ui::PAGE_TRANSITION_TYPED,
1280 history::SOURCE_BROWSED, false); 1280 history::SOURCE_BROWSED, false);
1281 backend_->AddPage(request3); 1281 backend_->AddPage(request3);
1282 1282
1283 // Three visits should be added with proper sources. 1283 // Three visits should be added with proper sources.
1284 VisitVector visits; 1284 VisitVector visits;
1285 URLRow row; 1285 URLRow row;
1286 URLID id = backend_->db()->GetRowForURL(url, &row); 1286 URLID id = backend_->db()->GetRowForURL(url, &row);
1287 ASSERT_TRUE(backend_->db()->GetVisitsForURL(id, &visits)); 1287 ASSERT_TRUE(backend_->db()->GetVisitsForURL(id, &visits));
1288 ASSERT_EQ(3U, visits.size()); 1288 ASSERT_EQ(3U, visits.size());
1289 VisitSourceMap visit_sources; 1289 VisitSourceMap visit_sources;
1290 ASSERT_TRUE(backend_->GetVisitsSource(visits, &visit_sources)); 1290 ASSERT_TRUE(backend_->GetVisitsSource(visits, &visit_sources));
1291 ASSERT_EQ(1U, visit_sources.size()); 1291 ASSERT_EQ(1U, visit_sources.size());
1292 EXPECT_EQ(history::SOURCE_SYNCED, visit_sources.begin()->second); 1292 EXPECT_EQ(history::SOURCE_SYNCED, visit_sources.begin()->second);
1293 } 1293 }
1294 1294
1295 TEST_F(HistoryBackendTest, AddVisitsSource) { 1295 TEST_F(HistoryBackendTest, AddVisitsSource) {
1296 ASSERT_TRUE(backend_.get()); 1296 ASSERT_TRUE(backend_.get());
1297 1297
1298 GURL url1("http://www.cnn.com"); 1298 GURL url1("http://www.cnn.com");
1299 std::vector<VisitInfo> visits1, visits2; 1299 std::vector<VisitInfo> visits1, visits2;
1300 visits1.push_back(VisitInfo( 1300 visits1.push_back(VisitInfo(
1301 Time::Now() - base::TimeDelta::FromDays(5), 1301 Time::Now() - base::TimeDelta::FromDays(5),
1302 content::PAGE_TRANSITION_LINK)); 1302 ui::PAGE_TRANSITION_LINK));
1303 visits1.push_back(VisitInfo( 1303 visits1.push_back(VisitInfo(
1304 Time::Now() - base::TimeDelta::FromDays(1), 1304 Time::Now() - base::TimeDelta::FromDays(1),
1305 content::PAGE_TRANSITION_LINK)); 1305 ui::PAGE_TRANSITION_LINK));
1306 visits1.push_back(VisitInfo( 1306 visits1.push_back(VisitInfo(
1307 Time::Now(), content::PAGE_TRANSITION_LINK)); 1307 Time::Now(), ui::PAGE_TRANSITION_LINK));
1308 1308
1309 GURL url2("http://www.example.com"); 1309 GURL url2("http://www.example.com");
1310 visits2.push_back(VisitInfo( 1310 visits2.push_back(VisitInfo(
1311 Time::Now() - base::TimeDelta::FromDays(10), 1311 Time::Now() - base::TimeDelta::FromDays(10),
1312 content::PAGE_TRANSITION_LINK)); 1312 ui::PAGE_TRANSITION_LINK));
1313 visits2.push_back(VisitInfo(Time::Now(), content::PAGE_TRANSITION_LINK)); 1313 visits2.push_back(VisitInfo(Time::Now(), ui::PAGE_TRANSITION_LINK));
1314 1314
1315 // Clear all history. 1315 // Clear all history.
1316 backend_->DeleteAllHistory(); 1316 backend_->DeleteAllHistory();
1317 1317
1318 // Add the visits. 1318 // Add the visits.
1319 backend_->AddVisits(url1, visits1, history::SOURCE_IE_IMPORTED); 1319 backend_->AddVisits(url1, visits1, history::SOURCE_IE_IMPORTED);
1320 backend_->AddVisits(url2, visits2, history::SOURCE_SYNCED); 1320 backend_->AddVisits(url2, visits2, history::SOURCE_SYNCED);
1321 1321
1322 // Verify the visits were added with their sources. 1322 // Verify the visits were added with their sources.
1323 VisitVector visits; 1323 VisitVector visits;
(...skipping 15 matching lines...) Expand all
1339 EXPECT_EQ(history::SOURCE_SYNCED, visit_sources[visits[i].visit_id]); 1339 EXPECT_EQ(history::SOURCE_SYNCED, visit_sources[visits[i].visit_id]);
1340 } 1340 }
1341 1341
1342 TEST_F(HistoryBackendTest, GetMostRecentVisits) { 1342 TEST_F(HistoryBackendTest, GetMostRecentVisits) {
1343 ASSERT_TRUE(backend_.get()); 1343 ASSERT_TRUE(backend_.get());
1344 1344
1345 GURL url1("http://www.cnn.com"); 1345 GURL url1("http://www.cnn.com");
1346 std::vector<VisitInfo> visits1; 1346 std::vector<VisitInfo> visits1;
1347 visits1.push_back(VisitInfo( 1347 visits1.push_back(VisitInfo(
1348 Time::Now() - base::TimeDelta::FromDays(5), 1348 Time::Now() - base::TimeDelta::FromDays(5),
1349 content::PAGE_TRANSITION_LINK)); 1349 ui::PAGE_TRANSITION_LINK));
1350 visits1.push_back(VisitInfo( 1350 visits1.push_back(VisitInfo(
1351 Time::Now() - base::TimeDelta::FromDays(1), 1351 Time::Now() - base::TimeDelta::FromDays(1),
1352 content::PAGE_TRANSITION_LINK)); 1352 ui::PAGE_TRANSITION_LINK));
1353 visits1.push_back(VisitInfo( 1353 visits1.push_back(VisitInfo(
1354 Time::Now(), content::PAGE_TRANSITION_LINK)); 1354 Time::Now(), ui::PAGE_TRANSITION_LINK));
1355 1355
1356 // Clear all history. 1356 // Clear all history.
1357 backend_->DeleteAllHistory(); 1357 backend_->DeleteAllHistory();
1358 1358
1359 // Add the visits. 1359 // Add the visits.
1360 backend_->AddVisits(url1, visits1, history::SOURCE_IE_IMPORTED); 1360 backend_->AddVisits(url1, visits1, history::SOURCE_IE_IMPORTED);
1361 1361
1362 // Verify the visits were added with their sources. 1362 // Verify the visits were added with their sources.
1363 VisitVector visits; 1363 VisitVector visits;
1364 URLRow row; 1364 URLRow row;
1365 URLID id = backend_->db()->GetRowForURL(url1, &row); 1365 URLID id = backend_->db()->GetRowForURL(url1, &row);
1366 ASSERT_TRUE(backend_->db()->GetMostRecentVisitsForURL(id, 1, &visits)); 1366 ASSERT_TRUE(backend_->db()->GetMostRecentVisitsForURL(id, 1, &visits));
1367 ASSERT_EQ(1U, visits.size()); 1367 ASSERT_EQ(1U, visits.size());
1368 EXPECT_EQ(visits1[2].first, visits[0].visit_time); 1368 EXPECT_EQ(visits1[2].first, visits[0].visit_time);
1369 } 1369 }
1370 1370
1371 TEST_F(HistoryBackendTest, RemoveVisitsTransitions) { 1371 TEST_F(HistoryBackendTest, RemoveVisitsTransitions) {
1372 ASSERT_TRUE(backend_.get()); 1372 ASSERT_TRUE(backend_.get());
1373 1373
1374 // Clear all history. 1374 // Clear all history.
1375 backend_->DeleteAllHistory(); 1375 backend_->DeleteAllHistory();
1376 1376
1377 GURL url1("http://www.cnn.com"); 1377 GURL url1("http://www.cnn.com");
1378 VisitInfo typed_visit( 1378 VisitInfo typed_visit(
1379 Time::Now() - base::TimeDelta::FromDays(6), 1379 Time::Now() - base::TimeDelta::FromDays(6),
1380 content::PAGE_TRANSITION_TYPED); 1380 ui::PAGE_TRANSITION_TYPED);
1381 VisitInfo reload_visit( 1381 VisitInfo reload_visit(
1382 Time::Now() - base::TimeDelta::FromDays(5), 1382 Time::Now() - base::TimeDelta::FromDays(5),
1383 content::PAGE_TRANSITION_RELOAD); 1383 ui::PAGE_TRANSITION_RELOAD);
1384 VisitInfo link_visit( 1384 VisitInfo link_visit(
1385 Time::Now() - base::TimeDelta::FromDays(4), 1385 Time::Now() - base::TimeDelta::FromDays(4),
1386 content::PAGE_TRANSITION_LINK); 1386 ui::PAGE_TRANSITION_LINK);
1387 std::vector<VisitInfo> visits_to_add; 1387 std::vector<VisitInfo> visits_to_add;
1388 visits_to_add.push_back(typed_visit); 1388 visits_to_add.push_back(typed_visit);
1389 visits_to_add.push_back(reload_visit); 1389 visits_to_add.push_back(reload_visit);
1390 visits_to_add.push_back(link_visit); 1390 visits_to_add.push_back(link_visit);
1391 1391
1392 // Add the visits. 1392 // Add the visits.
1393 backend_->AddVisits(url1, visits_to_add, history::SOURCE_SYNCED); 1393 backend_->AddVisits(url1, visits_to_add, history::SOURCE_SYNCED);
1394 1394
1395 // Verify that the various counts are what we expect. 1395 // Verify that the various counts are what we expect.
1396 VisitVector visits; 1396 VisitVector visits;
(...skipping 26 matching lines...) Expand all
1423 ASSERT_EQ(0, backend_->db()->GetRowForURL(url1, &row)); 1423 ASSERT_EQ(0, backend_->db()->GetRowForURL(url1, &row));
1424 } 1424 }
1425 1425
1426 TEST_F(HistoryBackendTest, RemoveVisitsSource) { 1426 TEST_F(HistoryBackendTest, RemoveVisitsSource) {
1427 ASSERT_TRUE(backend_.get()); 1427 ASSERT_TRUE(backend_.get());
1428 1428
1429 GURL url1("http://www.cnn.com"); 1429 GURL url1("http://www.cnn.com");
1430 std::vector<VisitInfo> visits1, visits2; 1430 std::vector<VisitInfo> visits1, visits2;
1431 visits1.push_back(VisitInfo( 1431 visits1.push_back(VisitInfo(
1432 Time::Now() - base::TimeDelta::FromDays(5), 1432 Time::Now() - base::TimeDelta::FromDays(5),
1433 content::PAGE_TRANSITION_LINK)); 1433 ui::PAGE_TRANSITION_LINK));
1434 visits1.push_back(VisitInfo(Time::Now(), 1434 visits1.push_back(VisitInfo(Time::Now(),
1435 content::PAGE_TRANSITION_LINK)); 1435 ui::PAGE_TRANSITION_LINK));
1436 1436
1437 GURL url2("http://www.example.com"); 1437 GURL url2("http://www.example.com");
1438 visits2.push_back(VisitInfo( 1438 visits2.push_back(VisitInfo(
1439 Time::Now() - base::TimeDelta::FromDays(10), 1439 Time::Now() - base::TimeDelta::FromDays(10),
1440 content::PAGE_TRANSITION_LINK)); 1440 ui::PAGE_TRANSITION_LINK));
1441 visits2.push_back(VisitInfo(Time::Now(), content::PAGE_TRANSITION_LINK)); 1441 visits2.push_back(VisitInfo(Time::Now(), ui::PAGE_TRANSITION_LINK));
1442 1442
1443 // Clear all history. 1443 // Clear all history.
1444 backend_->DeleteAllHistory(); 1444 backend_->DeleteAllHistory();
1445 1445
1446 // Add the visits. 1446 // Add the visits.
1447 backend_->AddVisits(url1, visits1, history::SOURCE_IE_IMPORTED); 1447 backend_->AddVisits(url1, visits1, history::SOURCE_IE_IMPORTED);
1448 backend_->AddVisits(url2, visits2, history::SOURCE_SYNCED); 1448 backend_->AddVisits(url2, visits2, history::SOURCE_SYNCED);
1449 1449
1450 // Verify the visits of url1 were added. 1450 // Verify the visits of url1 were added.
1451 VisitVector visits; 1451 VisitVector visits;
(...skipping 1084 matching lines...) Expand 10 before | Expand all | Expand 10 after
2536 2536
2537 // Clear all history. 2537 // Clear all history.
2538 backend_->DeleteAllHistory(); 2538 backend_->DeleteAllHistory();
2539 2539
2540 Time tested_time = Time::Now().LocalMidnight() + 2540 Time tested_time = Time::Now().LocalMidnight() +
2541 base::TimeDelta::FromHours(4); 2541 base::TimeDelta::FromHours(4);
2542 base::TimeDelta half_an_hour = base::TimeDelta::FromMinutes(30); 2542 base::TimeDelta half_an_hour = base::TimeDelta::FromMinutes(30);
2543 base::TimeDelta one_hour = base::TimeDelta::FromHours(1); 2543 base::TimeDelta one_hour = base::TimeDelta::FromHours(1);
2544 base::TimeDelta one_day = base::TimeDelta::FromDays(1); 2544 base::TimeDelta one_day = base::TimeDelta::FromDays(1);
2545 2545
2546 const content::PageTransition kTypedTransition = 2546 const ui::PageTransition kTypedTransition =
2547 content::PAGE_TRANSITION_TYPED; 2547 ui::PAGE_TRANSITION_TYPED;
2548 const content::PageTransition kKeywordGeneratedTransition = 2548 const ui::PageTransition kKeywordGeneratedTransition =
2549 content::PAGE_TRANSITION_KEYWORD_GENERATED; 2549 ui::PAGE_TRANSITION_KEYWORD_GENERATED;
2550 2550
2551 const char* redirect_sequence[2]; 2551 const char* redirect_sequence[2];
2552 redirect_sequence[1] = NULL; 2552 redirect_sequence[1] = NULL;
2553 2553
2554 redirect_sequence[0] = google; 2554 redirect_sequence[0] = google;
2555 AddRedirectChainWithTransitionAndTime( 2555 AddRedirectChainWithTransitionAndTime(
2556 redirect_sequence, 0, kTypedTransition, 2556 redirect_sequence, 0, kTypedTransition,
2557 tested_time - one_day - half_an_hour * 2); 2557 tested_time - one_day - half_an_hour * 2);
2558 AddRedirectChainWithTransitionAndTime( 2558 AddRedirectChainWithTransitionAndTime(
2559 redirect_sequence, 0, 2559 redirect_sequence, 0,
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
2675 } 2675 }
2676 2676
2677 TEST_F(HistoryBackendTest, UpdateVisitDuration) { 2677 TEST_F(HistoryBackendTest, UpdateVisitDuration) {
2678 // This unit test will test adding and deleting visit details information. 2678 // This unit test will test adding and deleting visit details information.
2679 ASSERT_TRUE(backend_.get()); 2679 ASSERT_TRUE(backend_.get());
2680 2680
2681 GURL url1("http://www.cnn.com"); 2681 GURL url1("http://www.cnn.com");
2682 std::vector<VisitInfo> visit_info1, visit_info2; 2682 std::vector<VisitInfo> visit_info1, visit_info2;
2683 Time start_ts = Time::Now() - base::TimeDelta::FromDays(5); 2683 Time start_ts = Time::Now() - base::TimeDelta::FromDays(5);
2684 Time end_ts = start_ts + base::TimeDelta::FromDays(2); 2684 Time end_ts = start_ts + base::TimeDelta::FromDays(2);
2685 visit_info1.push_back(VisitInfo(start_ts, content::PAGE_TRANSITION_LINK)); 2685 visit_info1.push_back(VisitInfo(start_ts, ui::PAGE_TRANSITION_LINK));
2686 2686
2687 GURL url2("http://www.example.com"); 2687 GURL url2("http://www.example.com");
2688 visit_info2.push_back(VisitInfo(Time::Now() - base::TimeDelta::FromDays(10), 2688 visit_info2.push_back(VisitInfo(Time::Now() - base::TimeDelta::FromDays(10),
2689 content::PAGE_TRANSITION_LINK)); 2689 ui::PAGE_TRANSITION_LINK));
2690 2690
2691 // Clear all history. 2691 // Clear all history.
2692 backend_->DeleteAllHistory(); 2692 backend_->DeleteAllHistory();
2693 2693
2694 // Add the visits. 2694 // Add the visits.
2695 backend_->AddVisits(url1, visit_info1, history::SOURCE_BROWSED); 2695 backend_->AddVisits(url1, visit_info1, history::SOURCE_BROWSED);
2696 backend_->AddVisits(url2, visit_info2, history::SOURCE_BROWSED); 2696 backend_->AddVisits(url2, visit_info2, history::SOURCE_BROWSED);
2697 2697
2698 // Verify the entries for both visits were added in visit_details. 2698 // Verify the entries for both visits were added in visit_details.
2699 VisitVector visits1, visits2; 2699 VisitVector visits1, visits2;
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
2965 // Add a URL. 2965 // Add a URL.
2966 GURL url("http://www.google.com"); 2966 GURL url("http://www.google.com");
2967 HistoryClientMock history_client; 2967 HistoryClientMock history_client;
2968 history_client.AddBookmark(url); 2968 history_client.AddBookmark(url);
2969 scoped_ptr<HistoryService> service( 2969 scoped_ptr<HistoryService> service(
2970 new HistoryService(&history_client, profile.get())); 2970 new HistoryService(&history_client, profile.get()));
2971 EXPECT_TRUE(service->Init(profile->GetPath())); 2971 EXPECT_TRUE(service->Init(profile->GetPath()));
2972 2972
2973 service->AddPage( 2973 service->AddPage(
2974 url, base::Time::Now(), NULL, 1, GURL(), RedirectList(), 2974 url, base::Time::Now(), NULL, 1, GURL(), RedirectList(),
2975 content::PAGE_TRANSITION_TYPED, SOURCE_BROWSED, false); 2975 ui::PAGE_TRANSITION_TYPED, SOURCE_BROWSED, false);
2976 2976
2977 // This won't actually delete the URL, rather it'll empty out the visits. 2977 // This won't actually delete the URL, rather it'll empty out the visits.
2978 // This triggers blocking on the BookmarkModel. 2978 // This triggers blocking on the BookmarkModel.
2979 EXPECT_CALL(history_client, BlockUntilBookmarksLoaded()); 2979 EXPECT_CALL(history_client, BlockUntilBookmarksLoaded());
2980 service->DeleteURL(url); 2980 service->DeleteURL(url);
2981 } 2981 }
2982 2982
2983 // Test DeleteFTSIndexDatabases deletes expected files. 2983 // Test DeleteFTSIndexDatabases deletes expected files.
2984 TEST_F(HistoryBackendTest, DeleteFTSIndexDatabases) { 2984 TEST_F(HistoryBackendTest, DeleteFTSIndexDatabases) {
2985 ASSERT_TRUE(backend_.get()); 2985 ASSERT_TRUE(backend_.get());
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
3215 // Verify that the second term is no longer returned as result, and also check 3215 // Verify that the second term is no longer returned as result, and also check
3216 // at the low level that it is gone for good. The term corresponding to the 3216 // at the low level that it is gone for good. The term corresponding to the
3217 // first URLRow should not be affected. 3217 // first URLRow should not be affected.
3218 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); 3218 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1));
3219 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); 3219 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2));
3220 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); 3220 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL));
3221 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); 3221 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL));
3222 } 3222 }
3223 3223
3224 } // namespace history 3224 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/history_backend.cc ('k') | chrome/browser/history/history_notifications.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698