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

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

Issue 1011943003: Don't treat back/forwards as typed transitions in history. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add tests Created 5 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
« no previous file with comments | « no previous file | components/history/core/browser/expire_history_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 "components/history/core/browser/history_backend.h" 5 #include "components/history/core/browser/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 870 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 EXPECT_TRUE(backend_->db()->GetVisitsForURL(url_id, &visits)); 881 EXPECT_TRUE(backend_->db()->GetVisitsForURL(url_id, &visits));
882 EXPECT_EQ(1U, visits.size()); 882 EXPECT_EQ(1U, visits.size());
883 883
884 // But no visible visits. 884 // But no visible visits.
885 visits.clear(); 885 visits.clear();
886 QueryOptions query_options; 886 QueryOptions query_options;
887 query_options.max_count = 1; 887 query_options.max_count = 1;
888 backend_->db()->GetVisibleVisitsInRange(query_options, &visits); 888 backend_->db()->GetVisibleVisitsInRange(query_options, &visits);
889 EXPECT_TRUE(visits.empty()); 889 EXPECT_TRUE(visits.empty());
890 890
891 // Going back to the same entry should not increment the typed count.
892 ui::PageTransition back_transition = ui::PageTransitionFromInt(
893 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FORWARD_BACK);
894 HistoryAddPageArgs back_request(url, visit_time, NULL, 0, GURL(),
895 history::RedirectList(), back_transition,
896 history::SOURCE_BROWSED, false);
897 backend_->AddPage(back_request);
898 url_id = backend_->db()->GetRowForURL(url, &row);
899 ASSERT_NE(0, url_id);
900 ASSERT_EQ(1, row.typed_count());
901
891 // Expire the visits. 902 // Expire the visits.
892 std::set<GURL> restrict_urls; 903 std::set<GURL> restrict_urls;
893 backend_->expire_backend()->ExpireHistoryBetween(restrict_urls, 904 backend_->expire_backend()->ExpireHistoryBetween(restrict_urls,
894 visit_time, Time::Now()); 905 visit_time, Time::Now());
895 906
896 // The visit should have been nuked. 907 // The visit should have been nuked.
897 visits.clear(); 908 visits.clear();
898 EXPECT_TRUE(backend_->db()->GetVisitsForURL(url_id, &visits)); 909 EXPECT_TRUE(backend_->db()->GetVisitsForURL(url_id, &visits));
899 EXPECT_TRUE(visits.empty()); 910 EXPECT_TRUE(visits.empty());
900 911
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 1206
1196 // Fetch the row information about stripped url from history db. 1207 // Fetch the row information about stripped url from history db.
1197 VisitVector visits; 1208 VisitVector visits;
1198 URLID row_id = backend_->db_->GetRowForURL(stripped_url, NULL); 1209 URLID row_id = backend_->db_->GetRowForURL(stripped_url, NULL);
1199 backend_->db_->GetVisitsForURL(row_id, &visits); 1210 backend_->db_->GetVisitsForURL(row_id, &visits);
1200 1211
1201 // Check if stripped url is stored in database. 1212 // Check if stripped url is stored in database.
1202 ASSERT_EQ(1U, visits.size()); 1213 ASSERT_EQ(1U, visits.size());
1203 } 1214 }
1204 1215
1216 TEST_F(HistoryBackendTest, AddPageVisitBackForward) {
1217 ASSERT_TRUE(backend_.get());
1218
1219 GURL url("http://www.google.com");
1220
1221 // Clear all history.
1222 backend_->DeleteAllHistory();
1223
1224 // Visit the url after typing it.
1225 backend_->AddPageVisit(url, base::Time::Now(), 0,
1226 ui::PAGE_TRANSITION_TYPED,
1227 history::SOURCE_BROWSED);
1228
1229 // Ensure both the typed count and visit count are 1.
1230 VisitVector visits;
1231 URLRow row;
1232 URLID id = backend_->db()->GetRowForURL(url, &row);
1233 ASSERT_TRUE(backend_->db()->GetVisitsForURL(id, &visits));
1234 EXPECT_EQ(1, row.typed_count());
1235 EXPECT_EQ(1, row.visit_count());
1236
1237 // Visit the url again via back/forward.
1238 backend_->AddPageVisit(url, base::Time::Now(), 0,
1239 ui::PageTransitionFromInt(
1240 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FORWARD_BACK),
1241 history::SOURCE_BROWSED);
1242
1243 // Ensure the typed count is still 1 but the visit count is 2.
1244 id = backend_->db()->GetRowForURL(url, &row);
1245 ASSERT_TRUE(backend_->db()->GetVisitsForURL(id, &visits));
1246 EXPECT_EQ(1, row.typed_count());
1247 EXPECT_EQ(2, row.visit_count());
1248 }
1249
1250 TEST_F(HistoryBackendTest, AddPageVisitRedirectBackForward) {
1251 ASSERT_TRUE(backend_.get());
1252
1253 GURL url1("http://www.google.com");
1254 GURL url2("http://www.chromium.org");
1255
1256 // Clear all history.
1257 backend_->DeleteAllHistory();
1258
1259 // Visit a typed URL with a redirect.
1260 backend_->AddPageVisit(url1, base::Time::Now(), 0,
1261 ui::PAGE_TRANSITION_TYPED,
1262 history::SOURCE_BROWSED);
1263 backend_->AddPageVisit(url2, base::Time::Now(), 0,
1264 ui::PageTransitionFromInt(
1265 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_CLIENT_REDIRECT),
1266 history::SOURCE_BROWSED);
1267
1268 // Ensure the redirected URL does not count as typed.
1269 VisitVector visits;
1270 URLRow row;
1271 URLID id = backend_->db()->GetRowForURL(url2, &row);
1272 ASSERT_TRUE(backend_->db()->GetVisitsForURL(id, &visits));
1273 EXPECT_EQ(0, row.typed_count());
1274 EXPECT_EQ(1, row.visit_count());
1275
1276 // Visit the redirected url again via back/forward.
1277 backend_->AddPageVisit(url2, base::Time::Now(), 0,
1278 ui::PageTransitionFromInt(
1279 ui::PAGE_TRANSITION_TYPED |
1280 ui::PAGE_TRANSITION_FORWARD_BACK |
1281 ui::PAGE_TRANSITION_CLIENT_REDIRECT),
1282 history::SOURCE_BROWSED);
1283
1284 // Ensure the typed count is still 1 but the visit count is 2.
1285 id = backend_->db()->GetRowForURL(url2, &row);
1286 ASSERT_TRUE(backend_->db()->GetVisitsForURL(id, &visits));
1287 EXPECT_EQ(0, row.typed_count());
1288 EXPECT_EQ(2, row.visit_count());
1289 }
1290
1205 TEST_F(HistoryBackendTest, AddPageVisitSource) { 1291 TEST_F(HistoryBackendTest, AddPageVisitSource) {
1206 ASSERT_TRUE(backend_.get()); 1292 ASSERT_TRUE(backend_.get());
1207 1293
1208 GURL url("http://www.google.com"); 1294 GURL url("http://www.google.com");
1209 1295
1210 // Clear all history. 1296 // Clear all history.
1211 backend_->DeleteAllHistory(); 1297 backend_->DeleteAllHistory();
1212 1298
1213 // Assume visiting the url from an externsion. 1299 // Assume visiting the url from an externsion.
1214 backend_->AddPageVisit( 1300 backend_->AddPageVisit(
(...skipping 2075 matching lines...) Expand 10 before | Expand all | Expand 10 after
3290 // Verify that the second term is no longer returned as result, and also check 3376 // Verify that the second term is no longer returned as result, and also check
3291 // at the low level that it is gone for good. The term corresponding to the 3377 // at the low level that it is gone for good. The term corresponding to the
3292 // first URLRow should not be affected. 3378 // first URLRow should not be affected.
3293 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); 3379 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1));
3294 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); 3380 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2));
3295 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); 3381 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL));
3296 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); 3382 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL));
3297 } 3383 }
3298 3384
3299 } // namespace history 3385 } // namespace history
OLDNEW
« no previous file with comments | « no previous file | components/history/core/browser/expire_history_backend.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698