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

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

Issue 563923002: display error message for empty distilled content (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added more tests Created 6 years, 3 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
« no previous file with comments | « components/dom_distiller/core/viewer.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/dom_distiller/core/viewer_unittest.cc
diff --git a/components/dom_distiller/core/viewer_unittest.cc b/components/dom_distiller/core/viewer_unittest.cc
index 15c839da134efbf17f576250e1177b0d3a3dac18..861e691a70983848bb61e6bb1f58e75d1519bd50 100644
--- a/components/dom_distiller/core/viewer_unittest.cc
+++ b/components/dom_distiller/core/viewer_unittest.cc
@@ -9,7 +9,9 @@
#include "components/dom_distiller/core/dom_distiller_test_util.h"
#include "components/dom_distiller/core/task_tracker.h"
#include "components/dom_distiller/core/url_constants.h"
+#include "grit/components_strings.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/base/l10n/l10n_util.h"
namespace dom_distiller {
@@ -168,4 +170,109 @@ TEST_F(DomDistillerViewerTest, TestGetDistilledPageFontFamilyJsOutput) {
0);
}
+TEST_F(DomDistillerViewerTest, TestTitleAndContentAreNeverEmpty) {
+ std::string some_title = "some title";
nyquist 2014/09/19 23:47:04 should these be const?
kuan 2014/09/19 23:51:31 Done.
+ std::string some_content = "some content";
+ std::string no_title =
+ l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_VIEWER_NO_DATA_TITLE);
+ 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_NE(std::string::npos, html.find(some_title));
+ EXPECT_NE(std::string::npos, html.find(some_content));
+ EXPECT_EQ(std::string::npos, html.find(no_title));
+ EXPECT_EQ(std::string::npos, html.find(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_NE(std::string::npos, html.find(no_title));
+ EXPECT_NE(std::string::npos, html.find(no_content));
+ EXPECT_EQ(std::string::npos, html.find(some_title));
+ EXPECT_EQ(std::string::npos, html.find(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_NE(std::string::npos, html.find(no_title));
+ EXPECT_NE(std::string::npos, html.find(no_content));
+ EXPECT_EQ(std::string::npos, html.find(some_title));
+ EXPECT_EQ(std::string::npos, html.find(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_NE(std::string::npos, html.find(no_title));
+ EXPECT_NE(std::string::npos, html.find(no_content));
+ EXPECT_EQ(std::string::npos, html.find(some_title));
+ EXPECT_EQ(std::string::npos, html.find(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_NE(std::string::npos, html.find(some_title));
+ EXPECT_NE(std::string::npos, html.find(some_content));
+ EXPECT_EQ(std::string::npos, html.find(no_title));
+ EXPECT_EQ(std::string::npos, html.find(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_NE(std::string::npos, html.find(no_title));
+ EXPECT_NE(std::string::npos, html.find(no_content));
+ EXPECT_EQ(std::string::npos, html.find(some_title));
+ EXPECT_EQ(std::string::npos, html.find(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_NE(std::string::npos, html.find(no_title));
+ EXPECT_NE(std::string::npos, html.find(some_content));
+ EXPECT_EQ(std::string::npos, html.find(some_title));
+ EXPECT_EQ(std::string::npos, html.find(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_NE(std::string::npos, html.find(some_title));
+ EXPECT_NE(std::string::npos, html.find(no_content));
+ EXPECT_EQ(std::string::npos, html.find(no_title));
+ EXPECT_EQ(std::string::npos, html.find(some_content));
+ }
+}
+
} // namespace dom_distiller
« no previous file with comments | « components/dom_distiller/core/viewer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698