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

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

Issue 10050016: Removes pinning code from TopSites as we no longer need it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove printfs 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
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/format_macros.h" 8 #include "base/format_macros.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/scoped_temp_dir.h" 10 #include "base/scoped_temp_dir.h"
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 851
852 { 852 {
853 TopSitesQuerier querier; 853 TopSitesQuerier querier;
854 querier.QueryTopSites(top_sites(), false); 854 querier.QueryTopSites(top_sites(), false);
855 855
856 ASSERT_EQ(GetPrepopulatePages().size(), querier.urls().size()); 856 ASSERT_EQ(GetPrepopulatePages().size(), querier.urls().size());
857 ASSERT_NO_FATAL_FAILURE(ContainsPrepopulatePages(querier, 0)); 857 ASSERT_NO_FATAL_FAILURE(ContainsPrepopulatePages(querier, 0));
858 } 858 }
859 } 859 }
860 860
861 TEST_F(TopSitesTest, PinnedURLsDeleted) {
862 GURL google1_url("http://google.com");
863 GURL google2_url("http://google.com/redirect");
864 GURL google3_url("http://www.google.com");
865 string16 google_title(ASCIIToUTF16("Google"));
866 GURL news_url("http://news.google.com");
867 string16 news_title(ASCIIToUTF16("Google News"));
868
869 AddPageToHistory(google1_url, google_title);
870 AddPageToHistory(news_url, news_title);
871
872 RefreshTopSitesAndRecreate();
873
874 {
875 TopSitesQuerier querier;
876 querier.QueryTopSites(top_sites(), false);
877
878 // Take into account prepopulated URLs.
879 ASSERT_EQ(GetPrepopulatePages().size() + 2, querier.urls().size());
880 }
881
882 top_sites()->AddPinnedURL(news_url, 3);
883 EXPECT_TRUE(top_sites()->IsURLPinned(news_url));
884
885 DeleteURL(news_url);
886 WaitForHistory();
887
888 {
889 TopSitesQuerier querier;
890 querier.QueryTopSites(top_sites(), false);
891
892 // Take into account prepopulated URLs.
893 ASSERT_EQ(GetPrepopulatePages().size() + 1, querier.urls().size());
894 EXPECT_FALSE(top_sites()->IsURLPinned(news_url));
895 }
896
897 history_service()->ExpireHistoryBetween(
898 std::set<GURL>(), base::Time(), base::Time(),
899 consumer(), base::Bind(&TopSitesTest::EmptyCallback,
900 base::Unretained(this))),
901 WaitForHistory();
902
903 {
904 TopSitesQuerier querier;
905 querier.QueryTopSites(top_sites(), false);
906
907 // Take into account prepopulated URLs.
908 ASSERT_EQ(GetPrepopulatePages().size(), querier.urls().size());
909 EXPECT_FALSE(top_sites()->IsURLPinned(google1_url));
910 ASSERT_NO_FATAL_FAILURE(ContainsPrepopulatePages(querier, 0));
911 }
912 }
913
914 // Makes sure GetUpdateDelay is updated appropriately. 861 // Makes sure GetUpdateDelay is updated appropriately.
915 TEST_F(TopSitesTest, GetUpdateDelay) { 862 TEST_F(TopSitesTest, GetUpdateDelay) {
916 SetLastNumUrlsChanged(0); 863 SetLastNumUrlsChanged(0);
917 EXPECT_EQ(30, GetUpdateDelay().InSeconds()); 864 EXPECT_EQ(30, GetUpdateDelay().InSeconds());
918 865
919 MostVisitedURLList url_list; 866 MostVisitedURLList url_list;
920 url_list.resize(20); 867 url_list.resize(20);
921 GURL tmp_url(GURL("http://x")); 868 GURL tmp_url(GURL("http://x"));
922 for (size_t i = 0; i < url_list.size(); ++i) { 869 for (size_t i = 0; i < url_list.size(); ++i) {
923 url_list[i].url = tmp_url; 870 url_list[i].url = tmp_url;
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 { 1147 {
1201 TopSitesQuerier q; 1148 TopSitesQuerier q;
1202 q.QueryTopSites(top_sites(), true); 1149 q.QueryTopSites(top_sites(), true);
1203 ASSERT_EQ(2u + GetPrepopulatePages().size(), q.urls().size()); 1150 ASSERT_EQ(2u + GetPrepopulatePages().size(), q.urls().size());
1204 EXPECT_EQ("http://bbc.com/", q.urls()[0].url.spec()); 1151 EXPECT_EQ("http://bbc.com/", q.urls()[0].url.spec());
1205 EXPECT_EQ("http://google.com/", q.urls()[1].url.spec()); 1152 EXPECT_EQ("http://google.com/", q.urls()[1].url.spec());
1206 ASSERT_NO_FATAL_FAILURE(ContainsPrepopulatePages(q, 2)); 1153 ASSERT_NO_FATAL_FAILURE(ContainsPrepopulatePages(q, 2));
1207 } 1154 }
1208 } 1155 }
1209 1156
1210 // Tests variations of pinning/unpinning urls.
1211 TEST_F(TopSitesTest, PinnedURLs) {
1212 MostVisitedURLList pages;
1213 MostVisitedURL url, url1;
1214 url.url = GURL("http://bbc.com/");
1215 url.redirects.push_back(url.url);
1216 pages.push_back(url);
1217 url1.url = GURL("http://google.com/");
1218 url1.redirects.push_back(url1.url);
1219 pages.push_back(url1);
1220
1221 SetTopSites(pages);
1222
1223 EXPECT_FALSE(top_sites()->IsURLPinned(GURL("http://bbc.com/")));
1224
1225 {
1226 TopSitesQuerier q;
1227 q.QueryTopSites(top_sites(), true);
1228 ASSERT_EQ(2u + GetPrepopulatePages().size(), q.urls().size());
1229 EXPECT_EQ("http://bbc.com/", q.urls()[0].url.spec());
1230 EXPECT_EQ("http://google.com/", q.urls()[1].url.spec());
1231 ASSERT_NO_FATAL_FAILURE(ContainsPrepopulatePages(q, 2));
1232 }
1233
1234 top_sites()->AddPinnedURL(GURL("http://google.com/"), 3);
1235 EXPECT_FALSE(top_sites()->IsURLPinned(GURL("http://bbc.com/")));
1236 EXPECT_FALSE(top_sites()->IsURLPinned(GetPrepopulatePages()[0].url));
1237
1238 {
1239 TopSitesQuerier q;
1240 q.QueryTopSites(top_sites(), true);
1241 ASSERT_EQ(4u, q.urls().size());
1242 EXPECT_EQ("http://bbc.com/", q.urls()[0].url.spec());
1243 ASSERT_NO_FATAL_FAILURE(ContainsPrepopulatePages(q, 1));
1244 EXPECT_EQ("http://google.com/", q.urls()[3].url.spec());
1245 }
1246
1247 top_sites()->RemovePinnedURL(GURL("http://google.com/"));
1248 EXPECT_FALSE(top_sites()->IsURLPinned(GURL("http://google.com/")));
1249 {
1250 TopSitesQuerier q;
1251 q.QueryTopSites(top_sites(), true);
1252
1253 ASSERT_EQ(2u + GetPrepopulatePages().size(), q.urls().size());
1254 EXPECT_EQ("http://bbc.com/", q.urls()[0].url.spec());
1255 EXPECT_EQ("http://google.com/", q.urls()[1].url.spec());
1256 ASSERT_NO_FATAL_FAILURE(ContainsPrepopulatePages(q, 2));
1257 }
1258
1259 GURL prepopulate_url = GetPrepopulatePages()[0].url;
1260 top_sites()->AddPinnedURL(GURL("http://bbc.com"), 1);
1261 top_sites()->AddPinnedURL(prepopulate_url, 0);
1262 {
1263 TopSitesQuerier q;
1264 q.QueryTopSites(top_sites(), true);
1265
1266 ASSERT_EQ(3u + GetPrepopulatePages().size() - 1, q.urls().size());
1267 EXPECT_EQ(prepopulate_url, q.urls()[0].url);
1268 EXPECT_EQ("http://bbc.com/", q.urls()[1].url.spec());
1269 EXPECT_EQ("http://google.com/", q.urls()[2].url.spec());
1270 if (GetPrepopulatePages().size() > 1)
1271 EXPECT_EQ(GetPrepopulatePages()[1].url, q.urls()[3].url);
1272 }
1273
1274 // Recreate and make sure state remains the same.
1275 RecreateTopSitesAndBlock();
1276 {
1277 TopSitesQuerier q;
1278 q.QueryTopSites(top_sites(), true);
1279
1280 ASSERT_EQ(3u + GetPrepopulatePages().size() - 1, q.urls().size());
1281 EXPECT_EQ(prepopulate_url, q.urls()[0].url);
1282 EXPECT_EQ("http://bbc.com/", q.urls()[1].url.spec());
1283 EXPECT_EQ("http://google.com/", q.urls()[2].url.spec());
1284 if (GetPrepopulatePages().size() > 1)
1285 EXPECT_EQ(GetPrepopulatePages()[1].url, q.urls()[3].url);
1286 }
1287 }
1288
1289 // Tests blacklisting and pinning.
1290 TEST_F(TopSitesTest, BlacklistingAndPinnedURLs) {
1291 MostVisitedURLList prepopulate_urls = GetPrepopulatePages();
1292 if (prepopulate_urls.size() < 2)
1293 return;
1294
1295 top_sites()->AddPinnedURL(prepopulate_urls[0].url, 1);
1296 top_sites()->AddBlacklistedURL(prepopulate_urls[1].url);
1297
1298 {
1299 TopSitesQuerier q;
1300 q.QueryTopSites(top_sites(), true);
1301
1302 ASSERT_LE(2u, q.urls().size());
1303 EXPECT_EQ(GURL(), q.urls()[0].url);
1304 EXPECT_EQ(prepopulate_urls[0].url, q.urls()[1].url);
1305 }
1306 }
1307
1308 // Makes sure prepopulated pages exist. 1157 // Makes sure prepopulated pages exist.
1309 TEST_F(TopSitesTest, AddPrepopulatedPages) { 1158 TEST_F(TopSitesTest, AddPrepopulatedPages) {
1310 TopSitesQuerier q; 1159 TopSitesQuerier q;
1311 q.QueryTopSites(top_sites(), true); 1160 q.QueryTopSites(top_sites(), true);
1312 EXPECT_EQ(GetPrepopulatePages().size(), q.urls().size()); 1161 EXPECT_EQ(GetPrepopulatePages().size(), q.urls().size());
1313 ASSERT_NO_FATAL_FAILURE(ContainsPrepopulatePages(q, 0)); 1162 ASSERT_NO_FATAL_FAILURE(ContainsPrepopulatePages(q, 0));
1314 1163
1315 MostVisitedURLList pages = q.urls(); 1164 MostVisitedURLList pages = q.urls();
1316 EXPECT_FALSE(AddPrepopulatedPages(&pages)); 1165 EXPECT_FALSE(AddPrepopulatedPages(&pages));
1317 1166
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 ui_test_utils::WindowedNotificationObserver observer( 1234 ui_test_utils::WindowedNotificationObserver observer(
1386 chrome::NOTIFICATION_TOP_SITES_LOADED, 1235 chrome::NOTIFICATION_TOP_SITES_LOADED,
1387 content::Source<Profile>(profile())); 1236 content::Source<Profile>(profile()));
1388 profile()->CreateTopSites(); 1237 profile()->CreateTopSites();
1389 profile()->GetHistoryService(Profile::EXPLICIT_ACCESS)->UnloadBackend(); 1238 profile()->GetHistoryService(Profile::EXPLICIT_ACCESS)->UnloadBackend();
1390 profile()->BlockUntilHistoryProcessesPendingRequests(); 1239 profile()->BlockUntilHistoryProcessesPendingRequests();
1391 observer.Wait(); 1240 observer.Wait();
1392 } 1241 }
1393 1242
1394 } // namespace history 1243 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/top_sites.cc ('k') | chrome/browser/ui/webui/ntp/most_visited_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698