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 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 std::unique_ptr<MultipageDistillerData> distiller_data = | 547 std::unique_ptr<MultipageDistillerData> distiller_data = |
548 CreateMultipageDistillerDataWithoutImages(kNumPages); | 548 CreateMultipageDistillerDataWithoutImages(kNumPages); |
549 | 549 |
550 // The page number of the failed page. | 550 // The page number of the failed page. |
551 size_t failed_page_num = 3; | 551 size_t failed_page_num = 3; |
552 // reset distilled data of the failed page. | 552 // reset distilled data of the failed page. |
553 distiller_data->distilled_values.erase( | 553 distiller_data->distilled_values.erase( |
554 distiller_data->distilled_values.begin() + failed_page_num); | 554 distiller_data->distilled_values.begin() + failed_page_num); |
555 distiller_data->distilled_values.insert( | 555 distiller_data->distilled_values.insert( |
556 distiller_data->distilled_values.begin() + failed_page_num, | 556 distiller_data->distilled_values.begin() + failed_page_num, |
557 base::Value::CreateNullValue().release()); | 557 base::Value::CreateNullValue()); |
558 // Expect only calls till the failed page number. | 558 // Expect only calls till the failed page number. |
559 distiller_.reset( | 559 distiller_.reset( |
560 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); | 560 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); |
561 DistillPage( | 561 DistillPage( |
562 distiller_data->page_urls[0], | 562 distiller_data->page_urls[0], |
563 CreateMockDistillerPages(distiller_data.get(), failed_page_num + 1, 0)); | 563 CreateMockDistillerPages(distiller_data.get(), failed_page_num + 1, 0)); |
564 base::RunLoop().RunUntilIdle(); | 564 base::RunLoop().RunUntilIdle(); |
565 EXPECT_EQ(kTitle, article_proto_->title()); | 565 EXPECT_EQ(kTitle, article_proto_->title()); |
566 VerifyArticleProtoMatchesMultipageData( | 566 VerifyArticleProtoMatchesMultipageData( |
567 article_proto_.get(), distiller_data.get(), failed_page_num, kNumPages); | 567 article_proto_.get(), distiller_data.get(), failed_page_num, kNumPages); |
(...skipping 10 matching lines...) Expand all Loading... |
578 distiller_data->content[empty_page_num] = ""; | 578 distiller_data->content[empty_page_num] = ""; |
579 std::unique_ptr<base::Value> distilled_value = | 579 std::unique_ptr<base::Value> distilled_value = |
580 CreateDistilledValueReturnedFromJS(kTitle, "", vector<int>(), | 580 CreateDistilledValueReturnedFromJS(kTitle, "", vector<int>(), |
581 GenerateNextPageUrl(kURL, empty_page_num, kNumPages), | 581 GenerateNextPageUrl(kURL, empty_page_num, kNumPages), |
582 GeneratePrevPageUrl(kURL, empty_page_num)); | 582 GeneratePrevPageUrl(kURL, empty_page_num)); |
583 // Reset distilled data of the first page. | 583 // Reset distilled data of the first page. |
584 distiller_data->distilled_values.erase( | 584 distiller_data->distilled_values.erase( |
585 distiller_data->distilled_values.begin() + empty_page_num); | 585 distiller_data->distilled_values.begin() + empty_page_num); |
586 distiller_data->distilled_values.insert( | 586 distiller_data->distilled_values.insert( |
587 distiller_data->distilled_values.begin() + empty_page_num, | 587 distiller_data->distilled_values.begin() + empty_page_num, |
588 distilled_value.release()); | 588 std::move(distilled_value)); |
589 | 589 |
590 distiller_.reset( | 590 distiller_.reset( |
591 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); | 591 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); |
592 DistillPage(distiller_data->page_urls[0], | 592 DistillPage(distiller_data->page_urls[0], |
593 CreateMockDistillerPages(distiller_data.get(), 1, 0)); | 593 CreateMockDistillerPages(distiller_data.get(), 1, 0)); |
594 base::RunLoop().RunUntilIdle(); | 594 base::RunLoop().RunUntilIdle(); |
595 // If the first page has no content, stop fetching the next page. | 595 // If the first page has no content, stop fetching the next page. |
596 EXPECT_EQ(1, article_proto_->pages_size()); | 596 EXPECT_EQ(1, article_proto_->pages_size()); |
597 VerifyArticleProtoMatchesMultipageData( | 597 VerifyArticleProtoMatchesMultipageData( |
598 article_proto_.get(), distiller_data.get(), 1, 1); | 598 article_proto_.get(), distiller_data.get(), 1, 1); |
(...skipping 10 matching lines...) Expand all Loading... |
609 distiller_data->content[empty_page_num] = ""; | 609 distiller_data->content[empty_page_num] = ""; |
610 std::unique_ptr<base::Value> distilled_value = | 610 std::unique_ptr<base::Value> distilled_value = |
611 CreateDistilledValueReturnedFromJS(kTitle, "", vector<int>(), | 611 CreateDistilledValueReturnedFromJS(kTitle, "", vector<int>(), |
612 GenerateNextPageUrl(kURL, empty_page_num, kNumPages), | 612 GenerateNextPageUrl(kURL, empty_page_num, kNumPages), |
613 GeneratePrevPageUrl(kURL, empty_page_num)); | 613 GeneratePrevPageUrl(kURL, empty_page_num)); |
614 // Reset distilled data of the second page. | 614 // Reset distilled data of the second page. |
615 distiller_data->distilled_values.erase( | 615 distiller_data->distilled_values.erase( |
616 distiller_data->distilled_values.begin() + empty_page_num); | 616 distiller_data->distilled_values.begin() + empty_page_num); |
617 distiller_data->distilled_values.insert( | 617 distiller_data->distilled_values.insert( |
618 distiller_data->distilled_values.begin() + empty_page_num, | 618 distiller_data->distilled_values.begin() + empty_page_num, |
619 distilled_value.release()); | 619 std::move(distilled_value)); |
620 | 620 |
621 distiller_.reset( | 621 distiller_.reset( |
622 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); | 622 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); |
623 DistillPage(distiller_data->page_urls[0], | 623 DistillPage(distiller_data->page_urls[0], |
624 CreateMockDistillerPages(distiller_data.get(), kNumPages, 0)); | 624 CreateMockDistillerPages(distiller_data.get(), kNumPages, 0)); |
625 base::RunLoop().RunUntilIdle(); | 625 base::RunLoop().RunUntilIdle(); |
626 | 626 |
627 VerifyArticleProtoMatchesMultipageData( | 627 VerifyArticleProtoMatchesMultipageData( |
628 article_proto_.get(), distiller_data.get(), kNumPages, kNumPages); | 628 article_proto_.get(), distiller_data.get(), kNumPages, kNumPages); |
629 } | 629 } |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
752 | 752 |
753 ASSERT_TRUE(distiller_page); | 753 ASSERT_TRUE(distiller_page); |
754 // Post the task to execute javascript and then delete the distiller. | 754 // Post the task to execute javascript and then delete the distiller. |
755 distiller_page->OnDistillationDone(GURL(kURL), distilled_value.get()); | 755 distiller_page->OnDistillationDone(GURL(kURL), distilled_value.get()); |
756 distiller_.reset(); | 756 distiller_.reset(); |
757 | 757 |
758 base::RunLoop().RunUntilIdle(); | 758 base::RunLoop().RunUntilIdle(); |
759 } | 759 } |
760 | 760 |
761 } // namespace dom_distiller | 761 } // namespace dom_distiller |
OLD | NEW |