| OLD | NEW |
| 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 "components/dom_distiller/core/distiller.h" | 5 #include "components/dom_distiller/core/distiller.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); | 559 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); |
| 560 DistillPage( | 560 DistillPage( |
| 561 distiller_data->page_urls[0], | 561 distiller_data->page_urls[0], |
| 562 CreateMockDistillerPages(distiller_data.get(), failed_page_num + 1, 0)); | 562 CreateMockDistillerPages(distiller_data.get(), failed_page_num + 1, 0)); |
| 563 base::MessageLoop::current()->RunUntilIdle(); | 563 base::MessageLoop::current()->RunUntilIdle(); |
| 564 EXPECT_EQ(kTitle, article_proto_->title()); | 564 EXPECT_EQ(kTitle, article_proto_->title()); |
| 565 VerifyArticleProtoMatchesMultipageData( | 565 VerifyArticleProtoMatchesMultipageData( |
| 566 article_proto_.get(), distiller_data.get(), failed_page_num, kNumPages); | 566 article_proto_.get(), distiller_data.get(), failed_page_num, kNumPages); |
| 567 } | 567 } |
| 568 | 568 |
| 569 TEST_F(DistillerTest, DistillMultiplePagesFirstEmpty) { |
| 570 base::MessageLoopForUI loop; |
| 571 const size_t kNumPages = 8; |
| 572 std::unique_ptr<MultipageDistillerData> distiller_data = |
| 573 CreateMultipageDistillerDataWithoutImages(kNumPages); |
| 574 |
| 575 // The first page has no content. |
| 576 const size_t empty_page_num = 0; |
| 577 distiller_data->content[empty_page_num] = ""; |
| 578 std::unique_ptr<base::Value> distilled_value = |
| 579 CreateDistilledValueReturnedFromJS(kTitle, "", vector<int>(), |
| 580 GenerateNextPageUrl(kURL, empty_page_num, kNumPages), |
| 581 GeneratePrevPageUrl(kURL, empty_page_num)); |
| 582 // Reset distilled data of the first page. |
| 583 distiller_data->distilled_values.erase( |
| 584 distiller_data->distilled_values.begin() + empty_page_num); |
| 585 distiller_data->distilled_values.insert( |
| 586 distiller_data->distilled_values.begin() + empty_page_num, |
| 587 distilled_value.release()); |
| 588 |
| 589 distiller_.reset( |
| 590 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); |
| 591 DistillPage(distiller_data->page_urls[0], |
| 592 CreateMockDistillerPages(distiller_data.get(), 1, 0)); |
| 593 base::MessageLoop::current()->RunUntilIdle(); |
| 594 // If the first page has no content, stop fetching the next page. |
| 595 EXPECT_EQ(1, article_proto_->pages_size()); |
| 596 VerifyArticleProtoMatchesMultipageData( |
| 597 article_proto_.get(), distiller_data.get(), 1, 1); |
| 598 } |
| 599 |
| 600 TEST_F(DistillerTest, DistillMultiplePagesSecondEmpty) { |
| 601 base::MessageLoopForUI loop; |
| 602 const size_t kNumPages = 8; |
| 603 std::unique_ptr<MultipageDistillerData> distiller_data = |
| 604 CreateMultipageDistillerDataWithoutImages(kNumPages); |
| 605 |
| 606 // The second page has no content. |
| 607 const size_t empty_page_num = 1; |
| 608 distiller_data->content[empty_page_num] = ""; |
| 609 std::unique_ptr<base::Value> distilled_value = |
| 610 CreateDistilledValueReturnedFromJS(kTitle, "", vector<int>(), |
| 611 GenerateNextPageUrl(kURL, empty_page_num, kNumPages), |
| 612 GeneratePrevPageUrl(kURL, empty_page_num)); |
| 613 // Reset distilled data of the second page. |
| 614 distiller_data->distilled_values.erase( |
| 615 distiller_data->distilled_values.begin() + empty_page_num); |
| 616 distiller_data->distilled_values.insert( |
| 617 distiller_data->distilled_values.begin() + empty_page_num, |
| 618 distilled_value.release()); |
| 619 |
| 620 distiller_.reset( |
| 621 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); |
| 622 DistillPage(distiller_data->page_urls[0], |
| 623 CreateMockDistillerPages(distiller_data.get(), kNumPages, 0)); |
| 624 base::MessageLoop::current()->RunUntilIdle(); |
| 625 |
| 626 VerifyArticleProtoMatchesMultipageData( |
| 627 article_proto_.get(), distiller_data.get(), kNumPages, kNumPages); |
| 628 } |
| 629 |
| 569 TEST_F(DistillerTest, DistillPreviousPage) { | 630 TEST_F(DistillerTest, DistillPreviousPage) { |
| 570 base::MessageLoopForUI loop; | 631 base::MessageLoopForUI loop; |
| 571 const size_t kNumPages = 8; | 632 const size_t kNumPages = 8; |
| 572 | 633 |
| 573 // The page number of the article on which distillation starts. | 634 // The page number of the article on which distillation starts. |
| 574 int start_page_num = 3; | 635 int start_page_num = 3; |
| 575 std::unique_ptr<MultipageDistillerData> distiller_data = | 636 std::unique_ptr<MultipageDistillerData> distiller_data = |
| 576 CreateMultipageDistillerDataWithoutImages(kNumPages); | 637 CreateMultipageDistillerDataWithoutImages(kNumPages); |
| 577 | 638 |
| 578 distiller_.reset( | 639 distiller_.reset( |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 | 751 |
| 691 ASSERT_TRUE(distiller_page); | 752 ASSERT_TRUE(distiller_page); |
| 692 // Post the task to execute javascript and then delete the distiller. | 753 // Post the task to execute javascript and then delete the distiller. |
| 693 distiller_page->OnDistillationDone(GURL(kURL), distilled_value.get()); | 754 distiller_page->OnDistillationDone(GURL(kURL), distilled_value.get()); |
| 694 distiller_.reset(); | 755 distiller_.reset(); |
| 695 | 756 |
| 696 base::MessageLoop::current()->RunUntilIdle(); | 757 base::MessageLoop::current()->RunUntilIdle(); |
| 697 } | 758 } |
| 698 | 759 |
| 699 } // namespace dom_distiller | 760 } // namespace dom_distiller |
| OLD | NEW |