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

Unified Diff: components/dom_distiller/core/dom_distiller_service_unittest.cc

Issue 442503002: Retrieve article original URL from entryID (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
Index: components/dom_distiller/core/dom_distiller_service_unittest.cc
diff --git a/components/dom_distiller/core/dom_distiller_service_unittest.cc b/components/dom_distiller/core/dom_distiller_service_unittest.cc
index a584f005b6cfe0367f6eb3ba5db2bba8a745e692..01232d083cb3af08f85e88d3032074a0a3154d61 100644
--- a/components/dom_distiller/core/dom_distiller_service_unittest.cc
+++ b/components/dom_distiller/core/dom_distiller_service_unittest.cc
@@ -458,5 +458,110 @@ TEST_F(DomDistillerServiceTest, TestMultiplePageArticle) {
EXPECT_EQ(0u, store_->GetEntries().size());
}
+TEST_F(DomDistillerServiceTest, TestHasEntry) {
+ FakeDistiller* distiller = new FakeDistiller(false);
+ EXPECT_CALL(*distiller_factory_, CreateDistillerImpl())
+ .WillOnce(Return(distiller));
+
+ GURL url("http://www.example.com/p1");
+
+ MockArticleAvailableCallback article_cb;
+ EXPECT_CALL(article_cb, DistillationCompleted(true));
+
+ std::string entry_id = service_->AddToList(
+ url,
+ service_->CreateDefaultDistillerPage(gfx::Size()).Pass(),
+ ArticleCallback(&article_cb));
+
+ ASSERT_FALSE(distiller->GetArticleCallback().is_null());
+ EXPECT_EQ(url, distiller->GetUrl());
+
+ scoped_ptr<DistilledArticleProto> proto = CreateArticleWithURL(url.spec());
+ RunDistillerCallback(distiller, proto.Pass());
+
+ EXPECT_TRUE(service_->HasEntry(entry_id));
+
+ service_->RemoveEntry(entry_id);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(0u, store_->GetEntries().size());
+ EXPECT_FALSE(service_->HasEntry(entry_id));
+}
+
+TEST_F(DomDistillerServiceTest, TestGetUrlForOnePageEntry) {
+ FakeDistiller* distiller = new FakeDistiller(false);
+ EXPECT_CALL(*distiller_factory_, CreateDistillerImpl())
+ .WillOnce(Return(distiller));
+
+ GURL url("http://www.example.com/p1");
+
+ MockArticleAvailableCallback article_cb;
+ EXPECT_CALL(article_cb, DistillationCompleted(true));
+
+ std::string entry_id = service_->AddToList(
+ url,
+ service_->CreateDefaultDistillerPage(gfx::Size()).Pass(),
+ ArticleCallback(&article_cb));
+
+ ASSERT_FALSE(distiller->GetArticleCallback().is_null());
+ EXPECT_EQ(url, distiller->GetUrl());
+
+ scoped_ptr<DistilledArticleProto> proto = CreateArticleWithURL(url.spec());
+ RunDistillerCallback(distiller, proto.Pass());
+
+ // Check if retrieved URL is same as given URL.
+ GURL formattedURL(service_->GetUrlForEntry(entry_id));
nyquist 2014/08/13 20:09:11 Nit: This URL isn't really formatted in any specia
sunangel 2014/08/13 21:49:33 Done.
+ EXPECT_EQ(url, formattedURL);
+
+ service_->RemoveEntry(entry_id);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(0u, store_->GetEntries().size());
+ EXPECT_EQ("", service_->GetUrlForEntry(entry_id));
+}
+
+TEST_F(DomDistillerServiceTest, TestGetUrlForMultiPageEntry) {
+ FakeDistiller* distiller = new FakeDistiller(false);
+ EXPECT_CALL(*distiller_factory_, CreateDistillerImpl())
+ .WillOnce(Return(distiller));
+
+ const int kPageCount = 8;
+
+ std::string base_url("http://www.example.com/p");
+ GURL pages_url[kPageCount];
+ for (int page_num = 0; page_num < kPageCount; ++page_num) {
+ pages_url[page_num] = GURL(base_url + base::IntToString(page_num));
+ }
+
+ MockArticleAvailableCallback article_cb;
+ EXPECT_CALL(article_cb, DistillationCompleted(true));
+
+ std::string entry_id = service_->AddToList(
+ pages_url[0],
+ service_->CreateDefaultDistillerPage(gfx::Size()).Pass(),
+ ArticleCallback(&article_cb));
+
+ ArticleEntry entry;
+ ASSERT_FALSE(distiller->GetArticleCallback().is_null());
+ EXPECT_EQ(pages_url[0], distiller->GetUrl());
+
+ // Create the article with pages to pass to the distiller.
+ scoped_ptr<DistilledArticleProto> proto =
+ CreateArticleWithURL(pages_url[0].spec());
+ for (int page_num = 1; page_num < kPageCount; ++page_num) {
+ DistilledPageProto* distilled_page = proto->add_pages();
+ distilled_page->set_url(pages_url[page_num].spec());
+ }
+
+ RunDistillerCallback(distiller, proto.Pass());
+ EXPECT_TRUE(store_->GetEntryByUrl(pages_url[0], &entry));
+
+ GURL formattedURL(service_->GetUrlForEntry(entry_id));
+ EXPECT_EQ(pages_url[0], formattedURL);
+
+ service_->RemoveEntry(entry_id);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(0u, store_->GetEntries().size());
+ EXPECT_EQ("", service_->GetUrlForEntry(entry_id));
+}
+
} // namespace test
} // namespace dom_distiller

Powered by Google App Engine
This is Rietveld 408576698