Index: components/dom_distiller/content/distiller_page_web_contents_browsertest.cc |
diff --git a/components/dom_distiller/content/distiller_page_web_contents_browsertest.cc b/components/dom_distiller/content/distiller_page_web_contents_browsertest.cc |
index 612483c194997047a72704e835be6b12f86026de..2108ee371e4ce4e1e228ce10bc7c60171b8a65a6 100644 |
--- a/components/dom_distiller/content/distiller_page_web_contents_browsertest.cc |
+++ b/components/dom_distiller/content/distiller_page_web_contents_browsertest.cc |
@@ -9,15 +9,20 @@ |
#include "components/dom_distiller/content/distiller_page_web_contents.h" |
#include "components/dom_distiller/content/web_contents_main_frame_observer.h" |
#include "components/dom_distiller/core/distiller_page.h" |
+#include "components/dom_distiller/core/proto/distilled_article.pb.h" |
+#include "components/dom_distiller/core/proto/distilled_page.pb.h" |
+#include "components/dom_distiller/core/viewer.h" |
#include "content/public/browser/browser_context.h" |
#include "content/public/browser/navigation_controller.h" |
#include "content/public/browser/render_frame_host.h" |
#include "content/public/browser/web_contents_observer.h" |
#include "content/public/test/content_browser_test.h" |
#include "content/shell/browser/shell.h" |
+#include "grit/components_strings.h" |
#include "net/test/embedded_test_server/embedded_test_server.h" |
#include "testing/gmock/include/gmock/gmock.h" |
#include "third_party/dom_distiller_js/dom_distiller.pb.h" |
+#include "ui/base/l10n/l10n_util.h" |
#include "ui/base/resource/resource_bundle.h" |
using content::ContentBrowserTest; |
@@ -407,4 +412,110 @@ IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, MarkupInfo) { |
EXPECT_EQ(600, markup_image2.height()); |
} |
+IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, |
+ TestTitleAndContentAreNeverEmpty) { |
+ const std::string some_title = "some title"; |
+ const std::string some_content = "some content"; |
+ const std::string no_title = |
+ l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_VIEWER_NO_DATA_TITLE); |
+ const std::string no_content = |
+ l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_VIEWER_NO_DATA_CONTENT); |
+ |
+ { // Test non-empty title and content for article. |
+ scoped_ptr<DistilledArticleProto> article_proto( |
+ new DistilledArticleProto()); |
+ article_proto->set_title(some_title); |
+ (*(article_proto->add_pages())).set_html(some_content); |
+ std::string html = viewer::GetUnsafeArticleHtml(article_proto.get(), |
+ DistilledPagePrefs::LIGHT, DistilledPagePrefs::SERIF); |
+ EXPECT_THAT(html, HasSubstr(some_title)); |
+ EXPECT_THAT(html, HasSubstr(some_content)); |
+ EXPECT_THAT(html, Not(HasSubstr(no_title))); |
+ EXPECT_THAT(html, Not(HasSubstr(no_content))); |
+ } |
+ |
+ { // Test empty title and content for article. |
+ scoped_ptr<DistilledArticleProto> article_proto( |
+ new DistilledArticleProto()); |
+ article_proto->set_title(""); |
+ (*(article_proto->add_pages())).set_html(""); |
+ std::string html = viewer::GetUnsafeArticleHtml(article_proto.get(), |
+ DistilledPagePrefs::LIGHT, DistilledPagePrefs::SERIF); |
+ EXPECT_THAT(html, HasSubstr(no_title)); |
+ EXPECT_THAT(html, HasSubstr(no_content)); |
+ EXPECT_THAT(html, Not(HasSubstr(some_title))); |
+ EXPECT_THAT(html, Not(HasSubstr(some_content))); |
+ } |
+ |
+ { // Test missing title and non-empty content for article. |
+ scoped_ptr<DistilledArticleProto> article_proto( |
+ new DistilledArticleProto()); |
+ (*(article_proto->add_pages())).set_html(some_content); |
+ std::string html = viewer::GetUnsafeArticleHtml(article_proto.get(), |
+ DistilledPagePrefs::LIGHT, DistilledPagePrefs::SERIF); |
+ EXPECT_THAT(html, HasSubstr(no_title)); |
+ EXPECT_THAT(html, HasSubstr(no_content)); |
+ EXPECT_THAT(html, Not(HasSubstr(some_title))); |
+ EXPECT_THAT(html, Not(HasSubstr(some_content))); |
+ } |
+ |
+ { // Test non-empty title and missing content for article. |
+ scoped_ptr<DistilledArticleProto> article_proto( |
+ new DistilledArticleProto()); |
+ article_proto->set_title(some_title); |
+ std::string html = viewer::GetUnsafeArticleHtml(article_proto.get(), |
+ DistilledPagePrefs::LIGHT, DistilledPagePrefs::SERIF); |
+ EXPECT_THAT(html, HasSubstr(no_title)); |
+ EXPECT_THAT(html, HasSubstr(no_content)); |
+ EXPECT_THAT(html, Not(HasSubstr(some_title))); |
+ EXPECT_THAT(html, Not(HasSubstr(some_content))); |
+ } |
+ |
+ { // Test non-empty title and content for page. |
+ scoped_ptr<DistilledPageProto> page_proto(new DistilledPageProto()); |
+ page_proto->set_title(some_title); |
+ page_proto->set_html(some_content); |
+ std::string html = viewer::GetUnsafePartialArticleHtml(page_proto.get(), |
+ DistilledPagePrefs::LIGHT, DistilledPagePrefs::SERIF); |
+ EXPECT_THAT(html, HasSubstr(some_title)); |
+ EXPECT_THAT(html, HasSubstr(some_content)); |
+ EXPECT_THAT(html, Not(HasSubstr(no_title))); |
+ EXPECT_THAT(html, Not(HasSubstr(no_content))); |
+ } |
+ |
+ { // Test empty title and content for page. |
+ scoped_ptr<DistilledPageProto> page_proto(new DistilledPageProto()); |
+ page_proto->set_title(""); |
+ page_proto->set_html(""); |
+ std::string html = viewer::GetUnsafePartialArticleHtml(page_proto.get(), |
+ DistilledPagePrefs::LIGHT, DistilledPagePrefs::SERIF); |
+ EXPECT_THAT(html, HasSubstr(no_title)); |
+ EXPECT_THAT(html, HasSubstr(no_content)); |
+ EXPECT_THAT(html, Not(HasSubstr(some_title))); |
+ EXPECT_THAT(html, Not(HasSubstr(some_content))); |
+ } |
+ |
+ { // Test missing title and non-empty content for page. |
+ scoped_ptr<DistilledPageProto> page_proto(new DistilledPageProto()); |
+ page_proto->set_html(some_content); |
+ std::string html = viewer::GetUnsafePartialArticleHtml(page_proto.get(), |
+ DistilledPagePrefs::LIGHT, DistilledPagePrefs::SERIF); |
+ EXPECT_THAT(html, HasSubstr(no_title)); |
+ EXPECT_THAT(html, HasSubstr(some_content)); |
+ EXPECT_THAT(html, Not(HasSubstr(some_title))); |
+ EXPECT_THAT(html, Not(HasSubstr(no_content))); |
+ } |
+ |
+ { // Test non-empty title and missing content for page. |
+ scoped_ptr<DistilledPageProto> page_proto(new DistilledPageProto()); |
+ page_proto->set_title(some_title); |
+ std::string html = viewer::GetUnsafePartialArticleHtml(page_proto.get(), |
+ DistilledPagePrefs::LIGHT, DistilledPagePrefs::SERIF); |
+ EXPECT_THAT(html, HasSubstr(some_title)); |
+ EXPECT_THAT(html, HasSubstr(no_content)); |
+ EXPECT_THAT(html, Not(HasSubstr(no_title))); |
+ EXPECT_THAT(html, Not(HasSubstr(some_content))); |
+ } |
+} |
+ |
} // namespace dom_distiller |