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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 prev_page_url); | 160 prev_page_url); |
161 result->distilled_values.push_back(distilled_value.release()); | 161 result->distilled_values.push_back(distilled_value.release()); |
162 } | 162 } |
163 return result.Pass(); | 163 return result.Pass(); |
164 } | 164 } |
165 | 165 |
166 void VerifyArticleProtoMatchesMultipageData( | 166 void VerifyArticleProtoMatchesMultipageData( |
167 const dom_distiller::DistilledArticleProto* article_proto, | 167 const dom_distiller::DistilledArticleProto* article_proto, |
168 const MultipageDistillerData* distiller_data, | 168 const MultipageDistillerData* distiller_data, |
169 size_t pages_size) { | 169 size_t pages_size) { |
170 EXPECT_EQ(pages_size, static_cast<size_t>(article_proto->pages_size())); | 170 ASSERT_EQ(pages_size, static_cast<size_t>(article_proto->pages_size())); |
171 EXPECT_EQ(kTitle, article_proto->title()); | 171 EXPECT_EQ(kTitle, article_proto->title()); |
172 for (size_t page_num = 0; page_num < pages_size; ++page_num) { | 172 for (size_t page_num = 0; page_num < pages_size; ++page_num) { |
173 const dom_distiller::DistilledPageProto& page = | 173 const dom_distiller::DistilledPageProto& page = |
174 article_proto->pages(page_num); | 174 article_proto->pages(page_num); |
175 EXPECT_EQ(distiller_data->content[page_num], page.html()); | 175 EXPECT_EQ(distiller_data->content[page_num], page.html()); |
176 EXPECT_EQ(distiller_data->page_urls[page_num], page.url()); | 176 EXPECT_EQ(distiller_data->page_urls[page_num], page.url()); |
177 EXPECT_EQ(distiller_data->image_ids[page_num].size(), | 177 EXPECT_EQ(distiller_data->image_ids[page_num].size(), |
178 static_cast<size_t>(page.image_size())); | 178 static_cast<size_t>(page.image_size())); |
179 const vector<int>& image_ids_for_page = distiller_data->image_ids[page_num]; | 179 const vector<int>& image_ids_for_page = distiller_data->image_ids[page_num]; |
180 for (size_t img_num = 0; img_num < image_ids_for_page.size(); ++img_num) { | 180 for (size_t img_num = 0; img_num < image_ids_for_page.size(); ++img_num) { |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 | 328 |
329 TEST_F(DistillerTest, DistillPage) { | 329 TEST_F(DistillerTest, DistillPage) { |
330 base::MessageLoopForUI loop; | 330 base::MessageLoopForUI loop; |
331 scoped_ptr<base::Value> result = | 331 scoped_ptr<base::Value> result = |
332 CreateDistilledValueReturnedFromJS(kTitle, kContent, vector<int>(), ""); | 332 CreateDistilledValueReturnedFromJS(kTitle, kContent, vector<int>(), ""); |
333 distiller_.reset( | 333 distiller_.reset( |
334 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); | 334 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); |
335 DistillPage(kURL, CreateMockDistillerPage(result.get(), GURL(kURL)).Pass()); | 335 DistillPage(kURL, CreateMockDistillerPage(result.get(), GURL(kURL)).Pass()); |
336 base::MessageLoop::current()->RunUntilIdle(); | 336 base::MessageLoop::current()->RunUntilIdle(); |
337 EXPECT_EQ(kTitle, article_proto_->title()); | 337 EXPECT_EQ(kTitle, article_proto_->title()); |
338 EXPECT_EQ(article_proto_->pages_size(), 1); | 338 ASSERT_EQ(article_proto_->pages_size(), 1); |
339 const DistilledPageProto& first_page = article_proto_->pages(0); | 339 const DistilledPageProto& first_page = article_proto_->pages(0); |
340 EXPECT_EQ(kContent, first_page.html()); | 340 EXPECT_EQ(kContent, first_page.html()); |
341 EXPECT_EQ(kURL, first_page.url()); | 341 EXPECT_EQ(kURL, first_page.url()); |
342 } | 342 } |
343 | 343 |
344 TEST_F(DistillerTest, DistillPageWithImages) { | 344 TEST_F(DistillerTest, DistillPageWithImages) { |
345 base::MessageLoopForUI loop; | 345 base::MessageLoopForUI loop; |
346 vector<int> image_indices; | 346 vector<int> image_indices; |
347 image_indices.push_back(0); | 347 image_indices.push_back(0); |
348 image_indices.push_back(1); | 348 image_indices.push_back(1); |
349 scoped_ptr<base::Value> result = | 349 scoped_ptr<base::Value> result = |
350 CreateDistilledValueReturnedFromJS(kTitle, kContent, image_indices, ""); | 350 CreateDistilledValueReturnedFromJS(kTitle, kContent, image_indices, ""); |
351 distiller_.reset( | 351 distiller_.reset( |
352 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); | 352 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); |
353 DistillPage(kURL, CreateMockDistillerPage(result.get(), GURL(kURL)).Pass()); | 353 DistillPage(kURL, CreateMockDistillerPage(result.get(), GURL(kURL)).Pass()); |
354 base::MessageLoop::current()->RunUntilIdle(); | 354 base::MessageLoop::current()->RunUntilIdle(); |
355 EXPECT_EQ(kTitle, article_proto_->title()); | 355 EXPECT_EQ(kTitle, article_proto_->title()); |
356 EXPECT_EQ(article_proto_->pages_size(), 1); | 356 ASSERT_EQ(article_proto_->pages_size(), 1); |
357 const DistilledPageProto& first_page = article_proto_->pages(0); | 357 const DistilledPageProto& first_page = article_proto_->pages(0); |
358 EXPECT_EQ(kContent, first_page.html()); | 358 EXPECT_EQ(kContent, first_page.html()); |
359 EXPECT_EQ(kURL, first_page.url()); | 359 EXPECT_EQ(kURL, first_page.url()); |
360 EXPECT_EQ(2, first_page.image_size()); | 360 ASSERT_EQ(2, first_page.image_size()); |
361 EXPECT_EQ(kImageData[0], first_page.image(0).data()); | 361 EXPECT_EQ(kImageData[0], first_page.image(0).data()); |
362 EXPECT_EQ(GetImageName(1, 0), first_page.image(0).name()); | 362 EXPECT_EQ(GetImageName(1, 0), first_page.image(0).name()); |
363 EXPECT_EQ(kImageData[1], first_page.image(1).data()); | 363 EXPECT_EQ(kImageData[1], first_page.image(1).data()); |
364 EXPECT_EQ(GetImageName(1, 1), first_page.image(1).name()); | 364 EXPECT_EQ(GetImageName(1, 1), first_page.image(1).name()); |
365 } | 365 } |
366 | 366 |
367 TEST_F(DistillerTest, DistillMultiplePages) { | 367 TEST_F(DistillerTest, DistillMultiplePages) { |
368 base::MessageLoopForUI loop; | 368 base::MessageLoopForUI loop; |
369 const size_t kNumPages = 8; | 369 const size_t kNumPages = 8; |
370 scoped_ptr<MultipageDistillerData> distiller_data = | 370 scoped_ptr<MultipageDistillerData> distiller_data = |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 scoped_ptr<MultipageDistillerData> distiller_data = | 529 scoped_ptr<MultipageDistillerData> distiller_data = |
530 CreateMultipageDistillerDataWithoutImages(kNumPages); | 530 CreateMultipageDistillerDataWithoutImages(kNumPages); |
531 | 531 |
532 distiller_.reset( | 532 distiller_.reset( |
533 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); | 533 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); |
534 DistillPage(distiller_data->page_urls[start_page_num], | 534 DistillPage(distiller_data->page_urls[start_page_num], |
535 CreateMockDistillerPages( | 535 CreateMockDistillerPages( |
536 distiller_data.get(), kNumPages, start_page_num).Pass()); | 536 distiller_data.get(), kNumPages, start_page_num).Pass()); |
537 base::MessageLoop::current()->RunUntilIdle(); | 537 base::MessageLoop::current()->RunUntilIdle(); |
538 EXPECT_EQ(kTitle, article_proto_->title()); | 538 EXPECT_EQ(kTitle, article_proto_->title()); |
539 EXPECT_EQ(kNumPages, static_cast<size_t>(article_proto_->pages_size())); | 539 ASSERT_EQ(kNumPages, static_cast<size_t>(article_proto_->pages_size())); |
540 EXPECT_EQ(kNumPages, in_sequence_updates_.size()); | 540 EXPECT_EQ(kNumPages, in_sequence_updates_.size()); |
541 | 541 |
542 VerifyIncrementalUpdatesMatch( | 542 VerifyIncrementalUpdatesMatch( |
543 distiller_data.get(), kNumPages, in_sequence_updates_, start_page_num); | 543 distiller_data.get(), kNumPages, in_sequence_updates_, start_page_num); |
544 } | 544 } |
545 | 545 |
546 TEST_F(DistillerTest, IncrementalUpdatesDoNotDeleteFinalArticle) { | 546 TEST_F(DistillerTest, IncrementalUpdatesDoNotDeleteFinalArticle) { |
547 base::MessageLoopForUI loop; | 547 base::MessageLoopForUI loop; |
548 const size_t kNumPages = 8; | 548 const size_t kNumPages = 8; |
549 int start_page_num = 3; | 549 int start_page_num = 3; |
(...skipping 24 matching lines...) Expand all Loading... |
574 int start_page_num = 3; | 574 int start_page_num = 3; |
575 | 575 |
576 distiller_.reset( | 576 distiller_.reset( |
577 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); | 577 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); |
578 DistillPage(distiller_data->page_urls[start_page_num], | 578 DistillPage(distiller_data->page_urls[start_page_num], |
579 CreateMockDistillerPages( | 579 CreateMockDistillerPages( |
580 distiller_data.get(), kNumPages, start_page_num).Pass()); | 580 distiller_data.get(), kNumPages, start_page_num).Pass()); |
581 base::MessageLoop::current()->RunUntilIdle(); | 581 base::MessageLoop::current()->RunUntilIdle(); |
582 EXPECT_EQ(kNumPages, in_sequence_updates_.size()); | 582 EXPECT_EQ(kNumPages, in_sequence_updates_.size()); |
583 EXPECT_EQ(kTitle, article_proto_->title()); | 583 EXPECT_EQ(kTitle, article_proto_->title()); |
584 EXPECT_EQ(kNumPages, static_cast<size_t>(article_proto_->pages_size())); | 584 ASSERT_EQ(kNumPages, static_cast<size_t>(article_proto_->pages_size())); |
585 | 585 |
586 // Delete the article. | 586 // Delete the article. |
587 article_proto_.reset(); | 587 article_proto_.reset(); |
588 VerifyIncrementalUpdatesMatch( | 588 VerifyIncrementalUpdatesMatch( |
589 distiller_data.get(), kNumPages, in_sequence_updates_, start_page_num); | 589 distiller_data.get(), kNumPages, in_sequence_updates_, start_page_num); |
590 } | 590 } |
591 | 591 |
592 TEST_F(DistillerTest, CancelWithDelayedImageFetchCallback) { | 592 TEST_F(DistillerTest, CancelWithDelayedImageFetchCallback) { |
593 base::MessageLoopForUI loop; | 593 base::MessageLoopForUI loop; |
594 vector<int> image_indices; | 594 vector<int> image_indices; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 | 626 |
627 ASSERT_TRUE(distiller_page); | 627 ASSERT_TRUE(distiller_page); |
628 // Post the task to execute javascript and then delete the distiller. | 628 // Post the task to execute javascript and then delete the distiller. |
629 distiller_page->OnDistillationDone(GURL(kURL), distilled_value.get()); | 629 distiller_page->OnDistillationDone(GURL(kURL), distilled_value.get()); |
630 distiller_.reset(); | 630 distiller_.reset(); |
631 | 631 |
632 base::MessageLoop::current()->RunUntilIdle(); | 632 base::MessageLoop::current()->RunUntilIdle(); |
633 } | 633 } |
634 | 634 |
635 } // namespace dom_distiller | 635 } // namespace dom_distiller |
OLD | NEW |