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

Unified Diff: chrome/browser/history/top_sites_unittest.cc

Issue 5088001: Add pyauto hook for getting and manipulating the data underneath the NTP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/test/functional
Patch Set: add forgotten py files Created 10 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/history/top_sites_unittest.cc
diff --git a/chrome/browser/history/top_sites_unittest.cc b/chrome/browser/history/top_sites_unittest.cc
index f908646ec49aaec8a95914c4aba1ef12c8edd111..d40cbe6b016ab4f45a193538b2a9700a1b5ccefa 100644
--- a/chrome/browser/history/top_sites_unittest.cc
+++ b/chrome/browser/history/top_sites_unittest.cc
@@ -1343,4 +1343,68 @@ TEST_F(TopSitesTest, CreateTopSitesThenHistory) {
EXPECT_TRUE(IsTopSitesLoaded());
}
+// Used for running the refresh method of TopSites synchronously.
+class RefreshRunner {
+ public:
+ RefreshRunner() : number_of_callbacks_(0), waiting_(false) {}
+
+ void Refresh(TopSites* top_sites) {
+ int start_number_of_callbacks = number_of_callbacks_;
+ top_sites->RefreshAndCallback(NewCallback(this, &RefreshRunner::OnRefresh));
+ if (start_number_of_callbacks == number_of_callbacks_) {
+ waiting_ = true;
+ MessageLoop::current()->Run();
+ }
+ }
+
+ int number_of_callbacks() const { return number_of_callbacks_; }
+
+ private:
+ // Callback for TopSites::RefreshAndCallback.
+ void OnRefresh() {
+ number_of_callbacks_++;
+ if (waiting_) {
+ MessageLoop::current()->Quit();
+ waiting_ = false;
+ }
+ }
+
+ int number_of_callbacks_;
+ bool waiting_;
+
+ DISALLOW_COPY_AND_ASSIGN(RefreshRunner);
+};
+
+// This tests RefreshAndCallback, a method only used in higher-level testing.
+TEST_F(TopSitesTest, RefreshCallbackInvoked) {
+ // Test that the callback is invoked.
+ RefreshRunner refresh_runner;
+ refresh_runner.Refresh(top_sites());
+ ASSERT_EQ(1, refresh_runner.number_of_callbacks());
+
+ // Tests that the callback can be invoked again.
+ refresh_runner.Refresh(top_sites());
+ ASSERT_EQ(2, refresh_runner.number_of_callbacks());
+
+ // Test that the callback is not invoked accidentally.
+ StartQueryForMostVisited();
+ WaitForHistory();
+ WaitForTopSites();
+
+ ASSERT_EQ(2, refresh_runner.number_of_callbacks());
+}
+
+// This tests RefreshAndCallback, a method only used in higher-level testing.
+TEST_F(TopSitesTest, RefreshWorks) {
+ GURL google("http://google.com/");
+ AddPageToHistory(google);
+ RefreshRunner refresh_runner;
+ refresh_runner.Refresh(top_sites());
+
+ TopSitesQuerier querier;
+ querier.QueryTopSites(top_sites(), true);
+
+ ASSERT_EQ(1u + GetPrepopulatePages().size(), querier.urls().size());
+}
+
} // namespace history

Powered by Google App Engine
This is Rietveld 408576698