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

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

Issue 2832091: Unpin deleted URLs + better deleting algorithm. (Closed)
Patch Set: After review. Created 10 years, 4 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 | « chrome/browser/history/top_sites.cc ('k') | no next file » | 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "app/l10n_util.h" 5 #include "app/l10n_util.h"
6 #include "base/scoped_temp_dir.h" 6 #include "base/scoped_temp_dir.h"
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "chrome/browser/history/top_sites.h" 8 #include "chrome/browser/history/top_sites.h"
9 #include "chrome/common/chrome_paths.h" 9 #include "chrome/common/chrome_paths.h"
10 #include "chrome/browser/dom_ui/most_visited_handler.h" 10 #include "chrome/browser/dom_ui/most_visited_handler.h"
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 MessageLoop::current()->RunAllPending(); 783 MessageLoop::current()->RunAllPending();
784 top_sites().GetMostVisitedURLs( 784 top_sites().GetMostVisitedURLs(
785 consumer(), 785 consumer(),
786 NewCallback(static_cast<TopSitesTest*>(this), 786 NewCallback(static_cast<TopSitesTest*>(this),
787 &TopSitesTest::OnTopSitesAvailable)); 787 &TopSitesTest::OnTopSitesAvailable));
788 ASSERT_EQ(2u, urls().size()); 788 ASSERT_EQ(2u, urls().size());
789 EXPECT_EQ(welcome_url(), urls()[0].url); 789 EXPECT_EQ(welcome_url(), urls()[0].url);
790 EXPECT_EQ(themes_url(), urls()[1].url); 790 EXPECT_EQ(themes_url(), urls()[1].url);
791 } 791 }
792 792
793 TEST_F(TopSitesTest, PinnedURLsDeleted) {
794 ChromeThread db_loop(ChromeThread::DB, MessageLoop::current());
795 GURL google1_url("http://google.com");
796 GURL google2_url("http://google.com/redirect");
797 GURL google3_url("http://www.google.com");
798 string16 google_title(ASCIIToUTF16("Google"));
799 GURL news_url("http://news.google.com");
800 string16 news_title(ASCIIToUTF16("Google News"));
801
802 MockHistoryServiceImpl hs;
803
804 top_sites().Init(file_name());
805
806 hs.AppendMockPage(google1_url, google_title);
807 hs.AppendMockPage(news_url, news_title);
808 top_sites().SetMockHistoryService(&hs);
809
810 top_sites().StartQueryForMostVisited();
811 MessageLoop::current()->RunAllPending();
812 top_sites().GetMostVisitedURLs(
813 consumer(),
814 NewCallback(static_cast<TopSitesTest*>(this),
815 &TopSitesTest::OnTopSitesAvailable));
816 MessageLoop::current()->RunAllPending();
817 EXPECT_EQ(1u, number_of_callbacks());
818 // 2 extra prepopulated URLs.
819 ASSERT_EQ(4u, urls().size());
820
821 top_sites().AddPinnedURL(news_url, 3);
822 EXPECT_TRUE(top_sites().IsURLPinned(news_url));
823
824 hs.RemoveMostVisitedURL();
825 history::URLsDeletedDetails history_details;
826 history_details.all_history = false;
827 history_details.urls.insert(news_url);
828 Details<URLsDeletedDetails> details(&history_details);
829 top_sites().Observe(NotificationType::HISTORY_URLS_DELETED,
830 Source<Profile> (&profile()),
831 details);
832 MessageLoop::current()->RunAllPending();
833 top_sites().GetMostVisitedURLs(
834 consumer(),
835 NewCallback(static_cast<TopSitesTest*>(this),
836 &TopSitesTest::OnTopSitesAvailable));
837 MessageLoop::current()->RunAllPending();
838 EXPECT_EQ(2u, number_of_callbacks());
839 ASSERT_EQ(3u, urls().size());
840 EXPECT_FALSE(top_sites().IsURLPinned(news_url));
841
842 hs.RemoveMostVisitedURL();
843 history_details.all_history = true;
844 details = Details<HistoryDetails>(&history_details);
845 top_sites().Observe(NotificationType::HISTORY_URLS_DELETED,
846 Source<Profile> (&profile()),
847 details);
848 MessageLoop::current()->RunAllPending();
849 top_sites().GetMostVisitedURLs(
850 consumer(),
851 NewCallback(static_cast<TopSitesTest*>(this),
852 &TopSitesTest::OnTopSitesAvailable));
853 ASSERT_EQ(2u, urls().size());
854 MessageLoop::current()->RunAllPending();
855
856 top_sites().StartQueryForMostVisited();
857 MessageLoop::current()->RunAllPending();
858 top_sites().GetMostVisitedURLs(
859 consumer(),
860 NewCallback(static_cast<TopSitesTest*>(this),
861 &TopSitesTest::OnTopSitesAvailable));
862 ASSERT_EQ(2u, urls().size());
863 EXPECT_EQ(welcome_url(), urls()[0].url);
864 EXPECT_EQ(themes_url(), urls()[1].url);
865 }
866
793 TEST_F(TopSitesTest, GetUpdateDelay) { 867 TEST_F(TopSitesTest, GetUpdateDelay) {
794 top_sites().last_num_urls_changed_ = 0; 868 top_sites().last_num_urls_changed_ = 0;
795 EXPECT_EQ(30, top_sites().GetUpdateDelay().InSeconds()); 869 EXPECT_EQ(30, top_sites().GetUpdateDelay().InSeconds());
796 870
797 top_sites().top_sites_.resize(20); 871 top_sites().top_sites_.resize(20);
798 top_sites().last_num_urls_changed_ = 0; 872 top_sites().last_num_urls_changed_ = 0;
799 EXPECT_EQ(60, top_sites().GetUpdateDelay().InMinutes()); 873 EXPECT_EQ(60, top_sites().GetUpdateDelay().InMinutes());
800 874
801 top_sites().last_num_urls_changed_ = 3; 875 top_sites().last_num_urls_changed_ = 3;
802 EXPECT_EQ(52, top_sites().GetUpdateDelay().InMinutes()); 876 EXPECT_EQ(52, top_sites().GetUpdateDelay().InMinutes());
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
1238 1312
1239 top_sites().RemoveBlacklistedURL(store_url); 1313 top_sites().RemoveBlacklistedURL(store_url);
1240 EXPECT_EQ(6, top_sites().GetIndexForChromeStore(pages)); 1314 EXPECT_EQ(6, top_sites().GetIndexForChromeStore(pages));
1241 1315
1242 top_sites().AddPinnedURL(GURL("http://bbc.com"), 2); 1316 top_sites().AddPinnedURL(GURL("http://bbc.com"), 2);
1243 // All pinned - can't add store. 1317 // All pinned - can't add store.
1244 EXPECT_EQ(-1, top_sites().GetIndexForChromeStore(pages)); 1318 EXPECT_EQ(-1, top_sites().GetIndexForChromeStore(pages));
1245 } 1319 }
1246 1320
1247 } // namespace history 1321 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/top_sites.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698