| 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> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <utility> | 13 #include <utility> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/bind.h" | 16 #include "base/bind.h" |
| 17 #include "base/bind_helpers.h" | 17 #include "base/bind_helpers.h" |
| 18 #include "base/location.h" | 18 #include "base/location.h" |
| 19 #include "base/macros.h" | 19 #include "base/macros.h" |
| 20 #include "base/memory/ptr_util.h" |
| 20 #include "base/message_loop/message_loop.h" | 21 #include "base/message_loop/message_loop.h" |
| 21 #include "base/run_loop.h" | 22 #include "base/run_loop.h" |
| 22 #include "base/single_thread_task_runner.h" | 23 #include "base/single_thread_task_runner.h" |
| 23 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" |
| 24 #include "base/threading/thread_task_runner_handle.h" | 25 #include "base/threading/thread_task_runner_handle.h" |
| 25 #include "base/values.h" | 26 #include "base/values.h" |
| 26 #include "components/dom_distiller/core/article_distillation_update.h" | 27 #include "components/dom_distiller/core/article_distillation_update.h" |
| 27 #include "components/dom_distiller/core/distiller_page.h" | 28 #include "components/dom_distiller/core/distiller_page.h" |
| 28 #include "components/dom_distiller/core/fake_distiller_page.h" | 29 #include "components/dom_distiller/core/fake_distiller_page.h" |
| 29 #include "components/dom_distiller/core/proto/distilled_article.pb.h" | 30 #include "components/dom_distiller/core/proto/distilled_article.pb.h" |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 CreateMockDistillerPages(distiller_data.get(), kMaxPagesInArticle, 0)); | 527 CreateMockDistillerPages(distiller_data.get(), kMaxPagesInArticle, 0)); |
| 527 base::RunLoop().RunUntilIdle(); | 528 base::RunLoop().RunUntilIdle(); |
| 528 EXPECT_EQ(kTitle, article_proto_->title()); | 529 EXPECT_EQ(kTitle, article_proto_->title()); |
| 529 EXPECT_EQ(kMaxPagesInArticle, | 530 EXPECT_EQ(kMaxPagesInArticle, |
| 530 static_cast<size_t>(article_proto_->pages_size())); | 531 static_cast<size_t>(article_proto_->pages_size())); |
| 531 } | 532 } |
| 532 | 533 |
| 533 TEST_F(DistillerTest, SinglePageDistillationFailure) { | 534 TEST_F(DistillerTest, SinglePageDistillationFailure) { |
| 534 base::MessageLoopForUI loop; | 535 base::MessageLoopForUI loop; |
| 535 // To simulate failure return a null value. | 536 // To simulate failure return a null value. |
| 536 std::unique_ptr<base::Value> null_value = base::Value::CreateNullValue(); | 537 auto null_value = base::MakeUnique<base::Value>(); |
| 537 distiller_.reset( | 538 distiller_.reset( |
| 538 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); | 539 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); |
| 539 DistillPage(kURL, CreateMockDistillerPage(null_value.get(), GURL(kURL))); | 540 DistillPage(kURL, CreateMockDistillerPage(null_value.get(), GURL(kURL))); |
| 540 base::RunLoop().RunUntilIdle(); | 541 base::RunLoop().RunUntilIdle(); |
| 541 EXPECT_EQ("", article_proto_->title()); | 542 EXPECT_EQ("", article_proto_->title()); |
| 542 EXPECT_EQ(0, article_proto_->pages_size()); | 543 EXPECT_EQ(0, article_proto_->pages_size()); |
| 543 } | 544 } |
| 544 | 545 |
| 545 TEST_F(DistillerTest, MultiplePagesDistillationFailure) { | 546 TEST_F(DistillerTest, MultiplePagesDistillationFailure) { |
| 546 base::MessageLoopForUI loop; | 547 base::MessageLoopForUI loop; |
| 547 const size_t kNumPages = 8; | 548 const size_t kNumPages = 8; |
| 548 std::unique_ptr<MultipageDistillerData> distiller_data = | 549 std::unique_ptr<MultipageDistillerData> distiller_data = |
| 549 CreateMultipageDistillerDataWithoutImages(kNumPages); | 550 CreateMultipageDistillerDataWithoutImages(kNumPages); |
| 550 | 551 |
| 551 // The page number of the failed page. | 552 // The page number of the failed page. |
| 552 size_t failed_page_num = 3; | 553 size_t failed_page_num = 3; |
| 553 // reset distilled data of the failed page. | 554 // reset distilled data of the failed page. |
| 554 distiller_data->distilled_values.erase( | 555 distiller_data->distilled_values.erase( |
| 555 distiller_data->distilled_values.begin() + failed_page_num); | 556 distiller_data->distilled_values.begin() + failed_page_num); |
| 556 distiller_data->distilled_values.insert( | 557 distiller_data->distilled_values.insert( |
| 557 distiller_data->distilled_values.begin() + failed_page_num, | 558 distiller_data->distilled_values.begin() + failed_page_num, |
| 558 base::Value::CreateNullValue()); | 559 base::MakeUnique<base::Value>()); |
| 559 // Expect only calls till the failed page number. | 560 // Expect only calls till the failed page number. |
| 560 distiller_.reset( | 561 distiller_.reset( |
| 561 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); | 562 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); |
| 562 DistillPage( | 563 DistillPage( |
| 563 distiller_data->page_urls[0], | 564 distiller_data->page_urls[0], |
| 564 CreateMockDistillerPages(distiller_data.get(), failed_page_num + 1, 0)); | 565 CreateMockDistillerPages(distiller_data.get(), failed_page_num + 1, 0)); |
| 565 base::RunLoop().RunUntilIdle(); | 566 base::RunLoop().RunUntilIdle(); |
| 566 EXPECT_EQ(kTitle, article_proto_->title()); | 567 EXPECT_EQ(kTitle, article_proto_->title()); |
| 567 VerifyArticleProtoMatchesMultipageData( | 568 VerifyArticleProtoMatchesMultipageData( |
| 568 article_proto_.get(), distiller_data.get(), failed_page_num, kNumPages); | 569 article_proto_.get(), distiller_data.get(), failed_page_num, kNumPages); |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 | 754 |
| 754 ASSERT_TRUE(distiller_page); | 755 ASSERT_TRUE(distiller_page); |
| 755 // Post the task to execute javascript and then delete the distiller. | 756 // Post the task to execute javascript and then delete the distiller. |
| 756 distiller_page->OnDistillationDone(GURL(kURL), distilled_value.get()); | 757 distiller_page->OnDistillationDone(GURL(kURL), distilled_value.get()); |
| 757 distiller_.reset(); | 758 distiller_.reset(); |
| 758 | 759 |
| 759 base::RunLoop().RunUntilIdle(); | 760 base::RunLoop().RunUntilIdle(); |
| 760 } | 761 } |
| 761 | 762 |
| 762 } // namespace dom_distiller | 763 } // namespace dom_distiller |
| OLD | NEW |