Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Unified Diff: components/dom_distiller/core/distiller_unittest.cc

Issue 1903853002: Stop fetching the next page if the first page has no content (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/dom_distiller/core/distiller.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/dom_distiller/core/distiller_unittest.cc
diff --git a/components/dom_distiller/core/distiller_unittest.cc b/components/dom_distiller/core/distiller_unittest.cc
index f6b999760c95cfc6d3c2d610bcad69a31110c2fa..81916cb0524bd9877e7754e96c953975ac9bb087 100644
--- a/components/dom_distiller/core/distiller_unittest.cc
+++ b/components/dom_distiller/core/distiller_unittest.cc
@@ -569,6 +569,67 @@ TEST_F(DistillerTest, MultiplePagesDistillationFailure) {
article_proto_.get(), distiller_data.get(), failed_page_num, kNumPages);
}
+TEST_F(DistillerTest, DistillMultiplePagesFirstEmpty) {
+ base::MessageLoopForUI loop;
+ const size_t kNumPages = 8;
+ std::unique_ptr<MultipageDistillerData> distiller_data =
+ CreateMultipageDistillerDataWithoutImages(kNumPages);
+
+ // The first page has no content.
+ const size_t empty_page_num = 0;
+ distiller_data->content[empty_page_num] = "";
+ std::unique_ptr<base::Value> distilled_value =
+ CreateDistilledValueReturnedFromJS(kTitle, "", vector<int>(),
+ GenerateNextPageUrl(kURL, empty_page_num, kNumPages),
+ GeneratePrevPageUrl(kURL, empty_page_num));
+ // Reset distilled data of the first page.
+ distiller_data->distilled_values.erase(
+ distiller_data->distilled_values.begin() + empty_page_num);
+ distiller_data->distilled_values.insert(
+ distiller_data->distilled_values.begin() + empty_page_num,
+ distilled_value.release());
+
+ distiller_.reset(
+ new DistillerImpl(url_fetcher_factory_, DomDistillerOptions()));
+ DistillPage(distiller_data->page_urls[0],
+ CreateMockDistillerPages(distiller_data.get(), 1, 0));
+ base::MessageLoop::current()->RunUntilIdle();
+ // If the first page has no content, stop fetching the next page.
+ EXPECT_EQ(1, article_proto_->pages_size());
+ VerifyArticleProtoMatchesMultipageData(
+ article_proto_.get(), distiller_data.get(), 1, 1);
+}
+
+TEST_F(DistillerTest, DistillMultiplePagesSecondEmpty) {
+ base::MessageLoopForUI loop;
+ const size_t kNumPages = 8;
+ std::unique_ptr<MultipageDistillerData> distiller_data =
+ CreateMultipageDistillerDataWithoutImages(kNumPages);
+
+ // The second page has no content.
+ const size_t empty_page_num = 1;
+ distiller_data->content[empty_page_num] = "";
+ std::unique_ptr<base::Value> distilled_value =
+ CreateDistilledValueReturnedFromJS(kTitle, "", vector<int>(),
+ GenerateNextPageUrl(kURL, empty_page_num, kNumPages),
+ GeneratePrevPageUrl(kURL, empty_page_num));
+ // Reset distilled data of the second page.
+ distiller_data->distilled_values.erase(
+ distiller_data->distilled_values.begin() + empty_page_num);
+ distiller_data->distilled_values.insert(
+ distiller_data->distilled_values.begin() + empty_page_num,
+ distilled_value.release());
+
+ distiller_.reset(
+ new DistillerImpl(url_fetcher_factory_, DomDistillerOptions()));
+ DistillPage(distiller_data->page_urls[0],
+ CreateMockDistillerPages(distiller_data.get(), kNumPages, 0));
+ base::MessageLoop::current()->RunUntilIdle();
+
+ VerifyArticleProtoMatchesMultipageData(
+ article_proto_.get(), distiller_data.get(), kNumPages, kNumPages);
+}
+
TEST_F(DistillerTest, DistillPreviousPage) {
base::MessageLoopForUI loop;
const size_t kNumPages = 8;
« no previous file with comments | « components/dom_distiller/core/distiller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698