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

Side by Side Diff: components/history/core/browser/history_backend_db_unittest.cc

Issue 1924773002: TopSites: filter out non-WebSafe URLs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@topsites_cleanup
Patch Set: comment Created 4 years, 7 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 // History unit tests come in two flavors: 5 // History unit tests come in two flavors:
6 // 6 //
7 // 1. The more complicated style is that the unit test creates a full history 7 // 1. The more complicated style is that the unit test creates a full history
8 // service. This spawns a background thread for the history backend, and 8 // service. This spawns a background thread for the history backend, and
9 // all communication is asynchronous. This is useful for testing more 9 // all communication is asynchronous. This is useful for testing more
10 // complicated things or end-to-end behavior. 10 // complicated things or end-to-end behavior.
(...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 s.BindInt64(1, segment_id); 997 s.BindInt64(1, segment_id);
998 s.BindInt64(2, segment_time.ToInternalValue()); 998 s.BindInt64(2, segment_time.ToInternalValue());
999 s.BindInt(3, 5); // visit count. 999 s.BindInt(3, 5); // visit count.
1000 ASSERT_TRUE(s.Run()); 1000 ASSERT_TRUE(s.Run());
1001 } 1001 }
1002 } 1002 }
1003 1003
1004 // Re-open the db, triggering migration. 1004 // Re-open the db, triggering migration.
1005 CreateBackendAndDatabase(); 1005 CreateBackendAndDatabase();
1006 1006
1007 std::vector<std::unique_ptr<PageUsageData>> results = 1007 std::vector<std::unique_ptr<PageUsageData>> results = db_->QuerySegmentUsage(
1008 db_->QuerySegmentUsage(segment_time, 10); 1008 segment_time, 10, base::Callback<bool(const GURL&)>());
1009 ASSERT_EQ(1u, results.size()); 1009 ASSERT_EQ(1u, results.size());
1010 EXPECT_EQ(url, results[0]->GetURL()); 1010 EXPECT_EQ(url, results[0]->GetURL());
1011 EXPECT_EQ(segment_id, results[0]->GetID()); 1011 EXPECT_EQ(segment_id, results[0]->GetID());
1012 EXPECT_EQ(title, results[0]->GetTitle()); 1012 EXPECT_EQ(title, results[0]->GetTitle());
1013 } 1013 }
1014 1014
1015 TEST_F(HistoryBackendDBTest, CheckLastCompatibleVersion) { 1015 TEST_F(HistoryBackendDBTest, CheckLastCompatibleVersion) {
1016 ASSERT_NO_FATAL_FAILURE(CreateDBVersion(28)); 1016 ASSERT_NO_FATAL_FAILURE(CreateDBVersion(28));
1017 { 1017 {
1018 sql::Connection db; 1018 sql::Connection db;
(...skipping 23 matching lines...) Expand all
1042 sql::MetaTable meta; 1042 sql::MetaTable meta;
1043 meta.Init(&db, 1, 1); 1043 meta.Init(&db, 1, 1);
1044 // Current browser version must be already higher than 28. 1044 // Current browser version must be already higher than 28.
1045 ASSERT_LT(28, HistoryDatabase::GetCurrentVersion()); 1045 ASSERT_LT(28, HistoryDatabase::GetCurrentVersion());
1046 // Expect that version in DB remains the same. 1046 // Expect that version in DB remains the same.
1047 EXPECT_EQ(28, meta.GetVersionNumber()); 1047 EXPECT_EQ(28, meta.GetVersionNumber());
1048 } 1048 }
1049 } 1049 }
1050 } 1050 }
1051 1051
1052 bool FilterURL(const GURL& url) {
1053 return url.SchemeIsHTTPOrHTTPS();
1054 }
1055
1056 TEST_F(HistoryBackendDBTest, QuerySegmentUsage) {
1057 CreateBackendAndDatabase();
1058
1059 const GURL url1("file://bar");
1060 const GURL url2("http://www.foo.com");
1061 const int visit_count1 = 10;
1062 const int visit_count2 = 5;
1063 const base::Time time(base::Time::Now());
1064
1065 URLID url_id1 = db_->AddURL(URLRow(url1));
1066 ASSERT_NE(0, url_id1);
1067 URLID url_id2 = db_->AddURL(URLRow(url2));
1068 ASSERT_NE(0, url_id2);
1069
1070 SegmentID segment_id1 = db_->CreateSegment(
1071 url_id1, VisitSegmentDatabase::ComputeSegmentName(url1));
1072 ASSERT_NE(0, segment_id1);
1073 SegmentID segment_id2 = db_->CreateSegment(
1074 url_id2, VisitSegmentDatabase::ComputeSegmentName(url2));
1075 ASSERT_NE(0, segment_id2);
1076
1077 ASSERT_TRUE(db_->IncreaseSegmentVisitCount(segment_id1, time, visit_count1));
1078 ASSERT_TRUE(db_->IncreaseSegmentVisitCount(segment_id2, time, visit_count2));
1079
1080 // Without a filter, the "file://" URL should win.
1081 std::vector<std::unique_ptr<PageUsageData>> results =
1082 db_->QuerySegmentUsage(time, 1, base::Callback<bool(const GURL&)>());
1083 ASSERT_EQ(1u, results.size());
1084 EXPECT_EQ(url1, results[0]->GetURL());
1085 EXPECT_EQ(segment_id1, results[0]->GetID());
1086
1087 // With the filter, the "file://" URL should be filtered out, so the "http://"
1088 // URL should win instead.
1089 std::vector<std::unique_ptr<PageUsageData>> results2 =
1090 db_->QuerySegmentUsage(time, 1, base::Bind(&FilterURL));
1091 ASSERT_EQ(1u, results2.size());
1092 EXPECT_EQ(url2, results2[0]->GetURL());
1093 EXPECT_EQ(segment_id2, results2[0]->GetID());
1094 }
1095
1052 } // namespace 1096 } // namespace
1053 } // namespace history 1097 } // namespace history
OLDNEW
« no previous file with comments | « components/history/core/browser/history_backend_client.h ('k') | components/history/core/browser/visitsegment_database.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698