summaryrefslogtreecommitdiffstats
path: root/chrome/browser/history/top_sites_unittest.cc
diff options
context:
space:
mode:
authornshkrob@chromium.org <nshkrob@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-09 18:37:49 +0000
committernshkrob@chromium.org <nshkrob@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-09 18:37:49 +0000
commitf395404b3b46a8dcc316bd57035dd59539151613 (patch)
treea8fe655c87ae6eaa791a7d8df8da53ddf1692183 /chrome/browser/history/top_sites_unittest.cc
parent689fa1c501df5063de1f9d1272d58cd8efe5ce1d (diff)
downloadchromium_src-f395404b3b46a8dcc316bd57035dd59539151613.zip
chromium_src-f395404b3b46a8dcc316bd57035dd59539151613.tar.gz
chromium_src-f395404b3b46a8dcc316bd57035dd59539151613.tar.bz2
1. Create and use the TopSites database file.
2. Timed updates of the database based on the number of sites changed. BUG=None TEST=TopSitesTest Review URL: http://codereview.chromium.org/2746002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49294 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/history/top_sites_unittest.cc')
-rw-r--r--chrome/browser/history/top_sites_unittest.cc61
1 files changed, 61 insertions, 0 deletions
diff --git a/chrome/browser/history/top_sites_unittest.cc b/chrome/browser/history/top_sites_unittest.cc
index 0cf282a..698ac1d 100644
--- a/chrome/browser/history/top_sites_unittest.cc
+++ b/chrome/browser/history/top_sites_unittest.cc
@@ -7,6 +7,7 @@
#include "chrome/browser/history/top_sites.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/browser/history/top_sites_database.h"
+#include "chrome/browser/history/history_notifications.h"
#include "chrome/test/testing_profile.h"
#include "chrome/tools/profiles/thumbnail-inl.h"
#include "gfx/codec/jpeg_codec.h"
@@ -28,6 +29,7 @@ class TopSitesTest : public testing::Test {
}
TopSites& top_sites() { return *top_sites_; }
+ Profile& profile() {return *profile_;}
FilePath& file_name() { return file_name_; }
RefCountedBytes* google_thumbnail() { return google_thumbnail_; }
RefCountedBytes* random_thumbnail() { return random_thumbnail_; }
@@ -88,6 +90,7 @@ class TopSitesTest : public testing::Test {
scoped_refptr<RefCountedBytes> google_thumbnail_;
scoped_refptr<RefCountedBytes> random_thumbnail_;
scoped_refptr<RefCountedBytes> weewar_thumbnail_;
+ MessageLoop message_loop_;
DISALLOW_COPY_AND_ASSIGN(TopSitesTest);
};
@@ -117,6 +120,11 @@ class MockHistoryServiceImpl : public TopSites::MockHistoryService {
most_visited_urls_.push_back(page);
}
+ // Removes the last URL in the list.
+ void RemoveMostVisitedURL() {
+ most_visited_urls_.pop_back();
+ }
+
private:
MostVisitedURLList most_visited_urls_;
};
@@ -607,4 +615,57 @@ TEST_F(TopSitesTest, RealDatabase) {
EXPECT_TRUE(high_score.Equals(out_2.thumbnail_score));
}
+TEST_F(TopSitesTest, DeleteNotifications) {
+ GURL google1_url("http://google.com");
+ GURL google2_url("http://google.com/redirect");
+ GURL google3_url("http://www.google.com");
+ string16 google_title(ASCIIToUTF16("Google"));
+ GURL news_url("http://news.google.com");
+ string16 news_title(ASCIIToUTF16("Google News"));
+
+ MockHistoryServiceImpl hs;
+
+ top_sites().Init(file_name());
+
+ hs.AppendMockPage(google1_url, google_title);
+ hs.AppendMockPage(news_url, news_title);
+ top_sites().SetMockHistoryService(&hs);
+
+ top_sites().StartQueryForMostVisited();
+
+ MostVisitedURLList result = top_sites().GetMostVisitedURLs();
+ ASSERT_EQ(2u, result.size());
+
+ hs.RemoveMostVisitedURL();
+
+ history::URLsDeletedDetails details;
+ details.all_history = false;
+ top_sites().Observe(NotificationType::HISTORY_URLS_DELETED,
+ Source<Profile> (&profile()),
+ (const NotificationDetails&)details);
+
+ result = top_sites().GetMostVisitedURLs();
+ ASSERT_EQ(1u, result.size());
+ EXPECT_EQ(google_title, result[0].title);
+
+ hs.RemoveMostVisitedURL();
+ details.all_history = true;
+ top_sites().Observe(NotificationType::HISTORY_URLS_DELETED,
+ Source<Profile> (&profile()),
+ (const NotificationDetails&)details);
+ result = top_sites().GetMostVisitedURLs();
+ ASSERT_EQ(0u, result.size());
+}
+
+TEST_F(TopSitesTest, GetUpdateDelay) {
+ top_sites().last_num_urls_changed_ = 0;
+ EXPECT_EQ(60, top_sites().GetUpdateDelay().InMinutes());
+
+ top_sites().last_num_urls_changed_ = 3;
+ EXPECT_EQ(52, top_sites().GetUpdateDelay().InMinutes());
+
+ top_sites().last_num_urls_changed_ = 20;
+ EXPECT_EQ(1, top_sites().GetUpdateDelay().InMinutes());
+}
+
} // namespace history