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