Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / history / top_sites_impl_unittest.cc
index aa4b0bc..799a011 100644 (file)
@@ -5,7 +5,6 @@
 #include "base/bind.h"
 #include "base/memory/weak_ptr.h"
 #include "base/message_loop/message_loop.h"
-#include "base/path_service.h"
 #include "base/strings/utf_string_conversions.h"
 #include "base/task/cancelable_task_tracker.h"
 #include "chrome/browser/chrome_notification_types.h"
@@ -34,8 +33,8 @@ class TestTopSitesObserver : public history::TopSitesObserver {
   explicit TestTopSitesObserver(Profile* profile, history::TopSites* top_sites);
   virtual ~TestTopSitesObserver();
   // TopSitesObserver:
-  virtual void TopSitesLoaded(history::TopSites* top_sites) OVERRIDE;
-  virtual void TopSitesChanged(history::TopSites* top_sites) OVERRIDE;
+  void TopSitesLoaded(history::TopSites* top_sites) override;
+  void TopSitesChanged(history::TopSites* top_sites) override;
 
  private:
   Profile* profile_;
@@ -76,17 +75,14 @@ class WaitForHistoryTask : public HistoryDBTask {
  public:
   WaitForHistoryTask() {}
 
-  virtual bool RunOnDBThread(HistoryBackend* backend,
-                             HistoryDatabase* db) OVERRIDE {
+  bool RunOnDBThread(HistoryBackend* backend, HistoryDatabase* db) override {
     return true;
   }
 
-  virtual void DoneRunOnMainThread() OVERRIDE {
-    base::MessageLoop::current()->Quit();
-  }
+  void DoneRunOnMainThread() override { base::MessageLoop::current()->Quit(); }
 
  private:
-  virtual ~WaitForHistoryTask() {}
+  ~WaitForHistoryTask() override {}
 
   DISALLOW_COPY_AND_ASSIGN(WaitForHistoryTask);
 };
@@ -178,7 +174,7 @@ class TopSitesImplTest : public HistoryUnitTestBase {
         db_thread_(BrowserThread::DB, &message_loop_) {
   }
 
-  virtual void SetUp() {
+  void SetUp() override {
     profile_.reset(new TestingProfile);
     if (CreateHistoryAndTopSites()) {
       ASSERT_TRUE(profile_->CreateHistoryService(false, false));
@@ -187,7 +183,7 @@ class TopSitesImplTest : public HistoryUnitTestBase {
     }
   }
 
-  virtual void TearDown() {
+  void TearDown() override {
     top_sites_observer_.reset();
     profile_.reset();
   }
@@ -1195,8 +1191,74 @@ TEST_F(TopSitesImplTest, AddTemporaryThumbnail) {
   EXPECT_TRUE(ThumbnailEqualsBytes(thumbnail, out.get()));
 }
 
-// Tests variations of blacklisting.
-TEST_F(TopSitesImplTest, Blacklisting) {
+// Tests variations of blacklisting without testing prepopulated page
+// blacklisting.
+TEST_F(TopSitesImplTest, BlacklistingWithoutPrepopulated) {
+  MostVisitedURLList pages;
+  MostVisitedURL url, url1;
+  url.url = GURL("http://bbc.com/");
+  url.redirects.push_back(url.url);
+  pages.push_back(url);
+  url1.url = GURL("http://google.com/");
+  url1.redirects.push_back(url1.url);
+  pages.push_back(url1);
+
+  SetTopSites(pages);
+  EXPECT_FALSE(top_sites()->IsBlacklisted(GURL("http://bbc.com/")));
+
+  // Blacklist google.com.
+  top_sites()->AddBlacklistedURL(GURL("http://google.com/"));
+
+  EXPECT_TRUE(top_sites()->HasBlacklistedItems());
+  EXPECT_TRUE(top_sites()->IsBlacklisted(GURL("http://google.com/")));
+  EXPECT_FALSE(top_sites()->IsBlacklisted(GURL("http://bbc.com/")));
+
+  // Make sure the blacklisted site isn't returned in the results.
+  {
+    TopSitesQuerier q;
+    q.QueryTopSites(top_sites(), true);
+    EXPECT_EQ("http://bbc.com/", q.urls()[0].url.spec());
+  }
+
+  // Recreate top sites and make sure blacklisted url was correctly read.
+  RecreateTopSitesAndBlock();
+  {
+    TopSitesQuerier q;
+    q.QueryTopSites(top_sites(), true);
+    EXPECT_EQ("http://bbc.com/", q.urls()[0].url.spec());
+  }
+
+  // Mark google as no longer blacklisted.
+  top_sites()->RemoveBlacklistedURL(GURL("http://google.com/"));
+  EXPECT_FALSE(top_sites()->HasBlacklistedItems());
+  EXPECT_FALSE(top_sites()->IsBlacklisted(GURL("http://google.com/")));
+
+  // Make sure google is returned now.
+  {
+    TopSitesQuerier q;
+    q.QueryTopSites(top_sites(), true);
+    EXPECT_EQ("http://bbc.com/", q.urls()[0].url.spec());
+    EXPECT_EQ("http://google.com/", q.urls()[1].url.spec());
+  }
+
+  // Remove all blacklisted sites.
+  top_sites()->ClearBlacklistedURLs();
+  EXPECT_FALSE(top_sites()->HasBlacklistedItems());
+
+  {
+    TopSitesQuerier q;
+    q.QueryTopSites(top_sites(), true);
+    EXPECT_EQ("http://bbc.com/", q.urls()[0].url.spec());
+    EXPECT_EQ("http://google.com/", q.urls()[1].url.spec());
+    ASSERT_NO_FATAL_FAILURE(ContainsPrepopulatePages(q, 2));
+  }
+}
+
+#if !defined(OS_ANDROID)
+// Tests variations of blacklisting including blacklisting prepopulated pages.
+// This test is disable for Android because Android does not have any
+// prepopulated pages.
+TEST_F(TopSitesImplTest, BlacklistingWithPrepopulated) {
   MostVisitedURLList pages;
   MostVisitedURL url, url1;
   url.url = GURL("http://bbc.com/");
@@ -1285,6 +1347,7 @@ TEST_F(TopSitesImplTest, Blacklisting) {
     ASSERT_NO_FATAL_FAILURE(ContainsPrepopulatePages(q, 2));
   }
 }
+#endif
 
 // Makes sure prepopulated pages exist.
 TEST_F(TopSitesImplTest, AddPrepopulatedPages) {