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

Side by Side Diff: components/dom_distiller/content/distiller_page_web_contents_browsertest.cc

Issue 563923002: display error message for empty distilled content (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move test to browsertest to bypass missing resources on ios/android 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/memory/weak_ptr.h" 5 #include "base/memory/weak_ptr.h"
6 #include "base/path_service.h" 6 #include "base/path_service.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "components/dom_distiller/content/distiller_page_web_contents.h" 9 #include "components/dom_distiller/content/distiller_page_web_contents.h"
10 #include "components/dom_distiller/content/web_contents_main_frame_observer.h" 10 #include "components/dom_distiller/content/web_contents_main_frame_observer.h"
11 #include "components/dom_distiller/core/distiller_page.h" 11 #include "components/dom_distiller/core/distiller_page.h"
12 #include "components/dom_distiller/core/proto/distilled_article.pb.h"
13 #include "components/dom_distiller/core/proto/distilled_page.pb.h"
14 #include "components/dom_distiller/core/viewer.h"
12 #include "content/public/browser/browser_context.h" 15 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/navigation_controller.h" 16 #include "content/public/browser/navigation_controller.h"
14 #include "content/public/browser/render_frame_host.h" 17 #include "content/public/browser/render_frame_host.h"
15 #include "content/public/browser/web_contents_observer.h" 18 #include "content/public/browser/web_contents_observer.h"
16 #include "content/public/test/content_browser_test.h" 19 #include "content/public/test/content_browser_test.h"
17 #include "content/shell/browser/shell.h" 20 #include "content/shell/browser/shell.h"
21 #include "grit/components_strings.h"
18 #include "net/test/embedded_test_server/embedded_test_server.h" 22 #include "net/test/embedded_test_server/embedded_test_server.h"
19 #include "testing/gmock/include/gmock/gmock.h" 23 #include "testing/gmock/include/gmock/gmock.h"
20 #include "third_party/dom_distiller_js/dom_distiller.pb.h" 24 #include "third_party/dom_distiller_js/dom_distiller.pb.h"
25 #include "ui/base/l10n/l10n_util.h"
21 #include "ui/base/resource/resource_bundle.h" 26 #include "ui/base/resource/resource_bundle.h"
22 27
23 using content::ContentBrowserTest; 28 using content::ContentBrowserTest;
24 using testing::ContainsRegex; 29 using testing::ContainsRegex;
25 using testing::HasSubstr; 30 using testing::HasSubstr;
26 using testing::Not; 31 using testing::Not;
27 32
28 namespace dom_distiller { 33 namespace dom_distiller {
29 34
30 const char* kSimpleArticlePath = "/simple_article.html"; 35 const char* kSimpleArticlePath = "/simple_article.html";
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 405
401 const proto::MarkupImage markup_image2 = markup_info.images(1); 406 const proto::MarkupImage markup_image2 = markup_info.images(1);
402 EXPECT_EQ("http://test/markup2.gif", markup_image2.url()); 407 EXPECT_EQ("http://test/markup2.gif", markup_image2.url());
403 EXPECT_EQ("https://test/markup2.gif", markup_image2.secure_url()); 408 EXPECT_EQ("https://test/markup2.gif", markup_image2.secure_url());
404 EXPECT_EQ("gif", markup_image2.type()); 409 EXPECT_EQ("gif", markup_image2.type());
405 EXPECT_EQ("", markup_image2.caption()); 410 EXPECT_EQ("", markup_image2.caption());
406 EXPECT_EQ(1000, markup_image2.width()); 411 EXPECT_EQ(1000, markup_image2.width());
407 EXPECT_EQ(600, markup_image2.height()); 412 EXPECT_EQ(600, markup_image2.height());
408 } 413 }
409 414
415 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest,
416 TestTitleAndContentAreNeverEmpty) {
417 const std::string some_title = "some title";
418 const std::string some_content = "some content";
419 const std::string no_title =
420 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_VIEWER_NO_DATA_TITLE);
421 const std::string no_content =
422 l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_VIEWER_NO_DATA_CONTENT);
423
424 { // Test non-empty title and content for article.
425 scoped_ptr<DistilledArticleProto> article_proto(
426 new DistilledArticleProto());
427 article_proto->set_title(some_title);
428 (*(article_proto->add_pages())).set_html(some_content);
429 std::string html = viewer::GetUnsafeArticleHtml(article_proto.get(),
430 DistilledPagePrefs::LIGHT, DistilledPagePrefs::SERIF);
431 EXPECT_THAT(html, HasSubstr(some_title));
432 EXPECT_THAT(html, HasSubstr(some_content));
433 EXPECT_THAT(html, Not(HasSubstr(no_title)));
434 EXPECT_THAT(html, Not(HasSubstr(no_content)));
435 }
436
437 { // Test empty title and content for article.
438 scoped_ptr<DistilledArticleProto> article_proto(
439 new DistilledArticleProto());
440 article_proto->set_title("");
441 (*(article_proto->add_pages())).set_html("");
442 std::string html = viewer::GetUnsafeArticleHtml(article_proto.get(),
443 DistilledPagePrefs::LIGHT, DistilledPagePrefs::SERIF);
444 EXPECT_THAT(html, HasSubstr(no_title));
445 EXPECT_THAT(html, HasSubstr(no_content));
446 EXPECT_THAT(html, Not(HasSubstr(some_title)));
447 EXPECT_THAT(html, Not(HasSubstr(some_content)));
448 }
449
450 { // Test missing title and non-empty content for article.
451 scoped_ptr<DistilledArticleProto> article_proto(
452 new DistilledArticleProto());
453 (*(article_proto->add_pages())).set_html(some_content);
454 std::string html = viewer::GetUnsafeArticleHtml(article_proto.get(),
455 DistilledPagePrefs::LIGHT, DistilledPagePrefs::SERIF);
456 EXPECT_THAT(html, HasSubstr(no_title));
457 EXPECT_THAT(html, HasSubstr(no_content));
458 EXPECT_THAT(html, Not(HasSubstr(some_title)));
459 EXPECT_THAT(html, Not(HasSubstr(some_content)));
460 }
461
462 { // Test non-empty title and missing content for article.
463 scoped_ptr<DistilledArticleProto> article_proto(
464 new DistilledArticleProto());
465 article_proto->set_title(some_title);
466 std::string html = viewer::GetUnsafeArticleHtml(article_proto.get(),
467 DistilledPagePrefs::LIGHT, DistilledPagePrefs::SERIF);
468 EXPECT_THAT(html, HasSubstr(no_title));
469 EXPECT_THAT(html, HasSubstr(no_content));
470 EXPECT_THAT(html, Not(HasSubstr(some_title)));
471 EXPECT_THAT(html, Not(HasSubstr(some_content)));
472 }
473
474 { // Test non-empty title and content for page.
475 scoped_ptr<DistilledPageProto> page_proto(new DistilledPageProto());
476 page_proto->set_title(some_title);
477 page_proto->set_html(some_content);
478 std::string html = viewer::GetUnsafePartialArticleHtml(page_proto.get(),
479 DistilledPagePrefs::LIGHT, DistilledPagePrefs::SERIF);
480 EXPECT_THAT(html, HasSubstr(some_title));
481 EXPECT_THAT(html, HasSubstr(some_content));
482 EXPECT_THAT(html, Not(HasSubstr(no_title)));
483 EXPECT_THAT(html, Not(HasSubstr(no_content)));
484 }
485
486 { // Test empty title and content for page.
487 scoped_ptr<DistilledPageProto> page_proto(new DistilledPageProto());
488 page_proto->set_title("");
489 page_proto->set_html("");
490 std::string html = viewer::GetUnsafePartialArticleHtml(page_proto.get(),
491 DistilledPagePrefs::LIGHT, DistilledPagePrefs::SERIF);
492 EXPECT_THAT(html, HasSubstr(no_title));
493 EXPECT_THAT(html, HasSubstr(no_content));
494 EXPECT_THAT(html, Not(HasSubstr(some_title)));
495 EXPECT_THAT(html, Not(HasSubstr(some_content)));
496 }
497
498 { // Test missing title and non-empty content for page.
499 scoped_ptr<DistilledPageProto> page_proto(new DistilledPageProto());
500 page_proto->set_html(some_content);
501 std::string html = viewer::GetUnsafePartialArticleHtml(page_proto.get(),
502 DistilledPagePrefs::LIGHT, DistilledPagePrefs::SERIF);
503 EXPECT_THAT(html, HasSubstr(no_title));
504 EXPECT_THAT(html, HasSubstr(some_content));
505 EXPECT_THAT(html, Not(HasSubstr(some_title)));
506 EXPECT_THAT(html, Not(HasSubstr(no_content)));
507 }
508
509 { // Test non-empty title and missing content for page.
510 scoped_ptr<DistilledPageProto> page_proto(new DistilledPageProto());
511 page_proto->set_title(some_title);
512 std::string html = viewer::GetUnsafePartialArticleHtml(page_proto.get(),
513 DistilledPagePrefs::LIGHT, DistilledPagePrefs::SERIF);
514 EXPECT_THAT(html, HasSubstr(some_title));
515 EXPECT_THAT(html, HasSubstr(no_content));
516 EXPECT_THAT(html, Not(HasSubstr(no_title)));
517 EXPECT_THAT(html, Not(HasSubstr(some_content)));
518 }
519 }
520
410 } // namespace dom_distiller 521 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698