Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/dom_distiller/core/viewer.h" | 5 #include "components/dom_distiller/core/viewer.h" |
| 6 | 6 |
| 7 #include "components/dom_distiller/core/distilled_page_prefs.h" | 7 #include "components/dom_distiller/core/distilled_page_prefs.h" |
| 8 #include "components/dom_distiller/core/dom_distiller_service.h" | 8 #include "components/dom_distiller/core/dom_distiller_service.h" |
| 9 #include "components/dom_distiller/core/dom_distiller_test_util.h" | 9 #include "components/dom_distiller/core/dom_distiller_test_util.h" |
| 10 #include "components/dom_distiller/core/task_tracker.h" | 10 #include "components/dom_distiller/core/task_tracker.h" |
| 11 #include "components/dom_distiller/core/url_constants.h" | 11 #include "components/dom_distiller/core/url_constants.h" |
| 12 #include "grit/components_strings.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | |
| 13 | 15 |
| 14 namespace dom_distiller { | 16 namespace dom_distiller { |
| 15 | 17 |
| 16 const char kTestScheme[] = "myscheme"; | 18 const char kTestScheme[] = "myscheme"; |
| 17 | 19 |
| 18 class FakeViewRequestDelegate : public ViewRequestDelegate { | 20 class FakeViewRequestDelegate : public ViewRequestDelegate { |
| 19 public: | 21 public: |
| 20 virtual ~FakeViewRequestDelegate() {} | 22 virtual ~FakeViewRequestDelegate() {} |
| 21 MOCK_METHOD1(OnArticleReady, void(const DistilledArticleProto* proto)); | 23 MOCK_METHOD1(OnArticleReady, void(const DistilledArticleProto* proto)); |
| 22 MOCK_METHOD1(OnArticleUpdated, | 24 MOCK_METHOD1(OnArticleUpdated, |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 DistilledPagePrefs::SERIF)), | 163 DistilledPagePrefs::SERIF)), |
| 162 0); | 164 0); |
| 163 EXPECT_EQ(kMonospaceJsFontFamily.compare(viewer::GetDistilledPageFontFamilyJs( | 165 EXPECT_EQ(kMonospaceJsFontFamily.compare(viewer::GetDistilledPageFontFamilyJs( |
| 164 DistilledPagePrefs::MONOSPACE)), | 166 DistilledPagePrefs::MONOSPACE)), |
| 165 0); | 167 0); |
| 166 EXPECT_EQ(kSansSerifJsFontFamily.compare(viewer::GetDistilledPageFontFamilyJs( | 168 EXPECT_EQ(kSansSerifJsFontFamily.compare(viewer::GetDistilledPageFontFamilyJs( |
| 167 DistilledPagePrefs::SANS_SERIF)), | 169 DistilledPagePrefs::SANS_SERIF)), |
| 168 0); | 170 0); |
| 169 } | 171 } |
| 170 | 172 |
| 173 TEST_F(DomDistillerViewerTest, TestTitleAndContentAreNeverEmpty) { | |
| 174 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.
| |
| 175 std::string some_content = "some content"; | |
| 176 std::string no_title = | |
| 177 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_VIEWER_NO_DATA_TITLE); | |
| 178 std::string no_content = | |
| 179 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_VIEWER_NO_DATA_CONTENT); | |
| 180 | |
| 181 { // Test non-empty title and content for article. | |
| 182 scoped_ptr<DistilledArticleProto> article_proto( | |
| 183 new DistilledArticleProto()); | |
| 184 article_proto->set_title(some_title); | |
| 185 (*(article_proto->add_pages())).set_html(some_content); | |
| 186 std::string html = viewer::GetUnsafeArticleHtml(article_proto.get(), | |
| 187 DistilledPagePrefs::LIGHT, DistilledPagePrefs::SERIF); | |
| 188 EXPECT_NE(std::string::npos, html.find(some_title)); | |
| 189 EXPECT_NE(std::string::npos, html.find(some_content)); | |
| 190 EXPECT_EQ(std::string::npos, html.find(no_title)); | |
| 191 EXPECT_EQ(std::string::npos, html.find(no_content)); | |
| 192 } | |
| 193 | |
| 194 { // Test empty title and content for article. | |
| 195 scoped_ptr<DistilledArticleProto> article_proto( | |
| 196 new DistilledArticleProto()); | |
| 197 article_proto->set_title(""); | |
| 198 (*(article_proto->add_pages())).set_html(""); | |
| 199 std::string html = viewer::GetUnsafeArticleHtml(article_proto.get(), | |
| 200 DistilledPagePrefs::LIGHT, DistilledPagePrefs::SERIF); | |
| 201 EXPECT_NE(std::string::npos, html.find(no_title)); | |
| 202 EXPECT_NE(std::string::npos, html.find(no_content)); | |
| 203 EXPECT_EQ(std::string::npos, html.find(some_title)); | |
| 204 EXPECT_EQ(std::string::npos, html.find(some_content)); | |
| 205 } | |
| 206 | |
| 207 { // Test missing title and non-empty content for article. | |
| 208 scoped_ptr<DistilledArticleProto> article_proto( | |
| 209 new DistilledArticleProto()); | |
| 210 (*(article_proto->add_pages())).set_html(some_content); | |
| 211 std::string html = viewer::GetUnsafeArticleHtml(article_proto.get(), | |
| 212 DistilledPagePrefs::LIGHT, DistilledPagePrefs::SERIF); | |
| 213 EXPECT_NE(std::string::npos, html.find(no_title)); | |
| 214 EXPECT_NE(std::string::npos, html.find(no_content)); | |
| 215 EXPECT_EQ(std::string::npos, html.find(some_title)); | |
| 216 EXPECT_EQ(std::string::npos, html.find(some_content)); | |
| 217 } | |
| 218 | |
| 219 { // Test non-empty title and missing content for article. | |
| 220 scoped_ptr<DistilledArticleProto> article_proto( | |
| 221 new DistilledArticleProto()); | |
| 222 article_proto->set_title(some_title); | |
| 223 std::string html = viewer::GetUnsafeArticleHtml(article_proto.get(), | |
| 224 DistilledPagePrefs::LIGHT, DistilledPagePrefs::SERIF); | |
| 225 EXPECT_NE(std::string::npos, html.find(no_title)); | |
| 226 EXPECT_NE(std::string::npos, html.find(no_content)); | |
| 227 EXPECT_EQ(std::string::npos, html.find(some_title)); | |
| 228 EXPECT_EQ(std::string::npos, html.find(some_content)); | |
| 229 } | |
| 230 | |
| 231 { // Test non-empty title and content for page. | |
| 232 scoped_ptr<DistilledPageProto> page_proto(new DistilledPageProto()); | |
| 233 page_proto->set_title(some_title); | |
| 234 page_proto->set_html(some_content); | |
| 235 std::string html = viewer::GetUnsafePartialArticleHtml(page_proto.get(), | |
| 236 DistilledPagePrefs::LIGHT, DistilledPagePrefs::SERIF); | |
| 237 EXPECT_NE(std::string::npos, html.find(some_title)); | |
| 238 EXPECT_NE(std::string::npos, html.find(some_content)); | |
| 239 EXPECT_EQ(std::string::npos, html.find(no_title)); | |
| 240 EXPECT_EQ(std::string::npos, html.find(no_content)); | |
| 241 } | |
| 242 | |
| 243 { // Test empty title and content for page. | |
| 244 scoped_ptr<DistilledPageProto> page_proto(new DistilledPageProto()); | |
| 245 page_proto->set_title(""); | |
| 246 page_proto->set_html(""); | |
| 247 std::string html = viewer::GetUnsafePartialArticleHtml(page_proto.get(), | |
| 248 DistilledPagePrefs::LIGHT, DistilledPagePrefs::SERIF); | |
| 249 EXPECT_NE(std::string::npos, html.find(no_title)); | |
| 250 EXPECT_NE(std::string::npos, html.find(no_content)); | |
| 251 EXPECT_EQ(std::string::npos, html.find(some_title)); | |
| 252 EXPECT_EQ(std::string::npos, html.find(some_content)); | |
| 253 } | |
| 254 | |
| 255 { // Test missing title and non-empty content for page. | |
| 256 scoped_ptr<DistilledPageProto> page_proto(new DistilledPageProto()); | |
| 257 page_proto->set_html(some_content); | |
| 258 std::string html = viewer::GetUnsafePartialArticleHtml(page_proto.get(), | |
| 259 DistilledPagePrefs::LIGHT, DistilledPagePrefs::SERIF); | |
| 260 EXPECT_NE(std::string::npos, html.find(no_title)); | |
| 261 EXPECT_NE(std::string::npos, html.find(some_content)); | |
| 262 EXPECT_EQ(std::string::npos, html.find(some_title)); | |
| 263 EXPECT_EQ(std::string::npos, html.find(no_content)); | |
| 264 } | |
| 265 | |
| 266 { // Test non-empty title and missing content for page. | |
| 267 scoped_ptr<DistilledPageProto> page_proto(new DistilledPageProto()); | |
| 268 page_proto->set_title(some_title); | |
| 269 std::string html = viewer::GetUnsafePartialArticleHtml(page_proto.get(), | |
| 270 DistilledPagePrefs::LIGHT, DistilledPagePrefs::SERIF); | |
| 271 EXPECT_NE(std::string::npos, html.find(some_title)); | |
| 272 EXPECT_NE(std::string::npos, html.find(no_content)); | |
| 273 EXPECT_EQ(std::string::npos, html.find(no_title)); | |
| 274 EXPECT_EQ(std::string::npos, html.find(some_content)); | |
| 275 } | |
| 276 } | |
| 277 | |
| 171 } // namespace dom_distiller | 278 } // namespace dom_distiller |
| OLD | NEW |