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 <algorithm> | 5 #include <algorithm> |
6 #include <map> | 6 #include <map> |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 distiller_data.get(), kMaxPagesInArticle, 0).Pass()); | 523 distiller_data.get(), kMaxPagesInArticle, 0).Pass()); |
524 base::MessageLoop::current()->RunUntilIdle(); | 524 base::MessageLoop::current()->RunUntilIdle(); |
525 EXPECT_EQ(kTitle, article_proto_->title()); | 525 EXPECT_EQ(kTitle, article_proto_->title()); |
526 EXPECT_EQ(kMaxPagesInArticle, | 526 EXPECT_EQ(kMaxPagesInArticle, |
527 static_cast<size_t>(article_proto_->pages_size())); | 527 static_cast<size_t>(article_proto_->pages_size())); |
528 } | 528 } |
529 | 529 |
530 TEST_F(DistillerTest, SinglePageDistillationFailure) { | 530 TEST_F(DistillerTest, SinglePageDistillationFailure) { |
531 base::MessageLoopForUI loop; | 531 base::MessageLoopForUI loop; |
532 // To simulate failure return a null value. | 532 // To simulate failure return a null value. |
533 scoped_ptr<base::Value> nullValue(base::Value::CreateNullValue()); | 533 scoped_ptr<base::Value> null_value = base::Value::CreateNullValue(); |
534 distiller_.reset( | 534 distiller_.reset( |
535 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); | 535 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); |
536 DistillPage(kURL, | 536 DistillPage(kURL, |
537 CreateMockDistillerPage(nullValue.get(), GURL(kURL)).Pass()); | 537 CreateMockDistillerPage(null_value.get(), GURL(kURL)).Pass()); |
538 base::MessageLoop::current()->RunUntilIdle(); | 538 base::MessageLoop::current()->RunUntilIdle(); |
539 EXPECT_EQ("", article_proto_->title()); | 539 EXPECT_EQ("", article_proto_->title()); |
540 EXPECT_EQ(0, article_proto_->pages_size()); | 540 EXPECT_EQ(0, article_proto_->pages_size()); |
541 } | 541 } |
542 | 542 |
543 TEST_F(DistillerTest, MultiplePagesDistillationFailure) { | 543 TEST_F(DistillerTest, MultiplePagesDistillationFailure) { |
544 base::MessageLoopForUI loop; | 544 base::MessageLoopForUI loop; |
545 const size_t kNumPages = 8; | 545 const size_t kNumPages = 8; |
546 scoped_ptr<MultipageDistillerData> distiller_data = | 546 scoped_ptr<MultipageDistillerData> distiller_data = |
547 CreateMultipageDistillerDataWithoutImages(kNumPages); | 547 CreateMultipageDistillerDataWithoutImages(kNumPages); |
548 | 548 |
549 // The page number of the failed page. | 549 // The page number of the failed page. |
550 size_t failed_page_num = 3; | 550 size_t failed_page_num = 3; |
551 // reset distilled data of the failed page. | 551 // reset distilled data of the failed page. |
552 distiller_data->distilled_values.erase( | 552 distiller_data->distilled_values.erase( |
553 distiller_data->distilled_values.begin() + failed_page_num); | 553 distiller_data->distilled_values.begin() + failed_page_num); |
554 distiller_data->distilled_values.insert( | 554 distiller_data->distilled_values.insert( |
555 distiller_data->distilled_values.begin() + failed_page_num, | 555 distiller_data->distilled_values.begin() + failed_page_num, |
556 base::Value::CreateNullValue()); | 556 base::Value::CreateNullValue().release()); |
557 // Expect only calls till the failed page number. | 557 // Expect only calls till the failed page number. |
558 distiller_.reset( | 558 distiller_.reset( |
559 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); | 559 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); |
560 DistillPage(distiller_data->page_urls[0], | 560 DistillPage(distiller_data->page_urls[0], |
561 CreateMockDistillerPages( | 561 CreateMockDistillerPages( |
562 distiller_data.get(), failed_page_num + 1, 0).Pass()); | 562 distiller_data.get(), failed_page_num + 1, 0).Pass()); |
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); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 | 691 |
692 ASSERT_TRUE(distiller_page); | 692 ASSERT_TRUE(distiller_page); |
693 // Post the task to execute javascript and then delete the distiller. | 693 // Post the task to execute javascript and then delete the distiller. |
694 distiller_page->OnDistillationDone(GURL(kURL), distilled_value.get()); | 694 distiller_page->OnDistillationDone(GURL(kURL), distilled_value.get()); |
695 distiller_.reset(); | 695 distiller_.reset(); |
696 | 696 |
697 base::MessageLoop::current()->RunUntilIdle(); | 697 base::MessageLoop::current()->RunUntilIdle(); |
698 } | 698 } |
699 | 699 |
700 } // namespace dom_distiller | 700 } // namespace dom_distiller |
OLD | NEW |