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

Side by Side Diff: components/dom_distiller/core/distiller_unittest.cc

Issue 130543003: Store page no for distilled pages undergoing distillation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix nitz. Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « components/dom_distiller/core/distiller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <map> 5 #include <map>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 MOCK_CONST_METHOD1( 110 MOCK_CONST_METHOD1(
111 CreateDistillerPageMock, 111 CreateDistillerPageMock,
112 DistillerPage*(DistillerPage::Delegate* delegate)); 112 DistillerPage*(DistillerPage::Delegate* delegate));
113 113
114 virtual scoped_ptr<DistillerPage> CreateDistillerPage( 114 virtual scoped_ptr<DistillerPage> CreateDistillerPage(
115 DistillerPage::Delegate* delegate) const OVERRIDE { 115 DistillerPage::Delegate* delegate) const OVERRIDE {
116 return scoped_ptr<DistillerPage>(CreateDistillerPageMock(delegate)); 116 return scoped_ptr<DistillerPage>(CreateDistillerPageMock(delegate));
117 } 117 }
118 }; 118 };
119 119
120
121 class DistillerTest : public testing::Test { 120 class DistillerTest : public testing::Test {
122 public: 121 public:
123 virtual ~DistillerTest() {} 122 virtual ~DistillerTest() {}
124 void OnDistillPageDone(scoped_ptr<DistilledArticleProto> proto) { 123 void OnDistillPageDone(scoped_ptr<DistilledArticleProto> proto) {
125 article_proto_ = proto.Pass(); 124 article_proto_ = proto.Pass();
126 } 125 }
127 126
128 protected: 127 protected:
129 scoped_ptr<DistillerImpl> distiller_; 128 scoped_ptr<DistillerImpl> distiller_;
130 scoped_ptr<DistilledArticleProto> article_proto_; 129 scoped_ptr<DistilledArticleProto> article_proto_;
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 distiller_.reset(new DistillerImpl(page_factory_, url_fetcher_factory_)); 282 distiller_.reset(new DistillerImpl(page_factory_, url_fetcher_factory_));
284 distiller_->Init(); 283 distiller_->Init();
285 distiller_->DistillPage( 284 distiller_->DistillPage(
286 GURL(kURL), 285 GURL(kURL),
287 base::Bind(&DistillerTest::OnDistillPageDone, base::Unretained(this))); 286 base::Bind(&DistillerTest::OnDistillPageDone, base::Unretained(this)));
288 base::MessageLoop::current()->RunUntilIdle(); 287 base::MessageLoop::current()->RunUntilIdle();
289 EXPECT_EQ(kTitle, article_proto_->title()); 288 EXPECT_EQ(kTitle, article_proto_->title());
290 EXPECT_EQ(article_proto_->pages_size(), 1); 289 EXPECT_EQ(article_proto_->pages_size(), 1);
291 } 290 }
292 291
292 TEST_F(DistillerTest, CheckMaxPageLimit) {
293 base::MessageLoopForUI loop;
294 const size_t kMaxPagesInArticle = 10;
295 string page_urls[kMaxPagesInArticle];
296 scoped_ptr<base::ListValue> list[kMaxPagesInArticle];
297
298 // Note: Next page url of the last page of article is set. So distiller will
299 // try to do kMaxPagesInArticle + 1 calls if the max article limit does not
300 // work.
301 string url_prefix = "http://a.com/";
302 for (size_t page_num = 0; page_num < kMaxPagesInArticle; ++page_num) {
303 page_urls[page_num] = url_prefix + base::IntToString(page_num + 1);
304 string content = "Content for page:" + base::IntToString(page_num);
305 string next_page_url = url_prefix + base::IntToString(page_num + 2);
306 list[page_num] = CreateDistilledValueReturnedFromJS(
307 kTitle, content, vector<int>(), next_page_url);
308 }
309
310 EXPECT_CALL(page_factory_, CreateDistillerPageMock(_))
311 .WillOnce(CreateMockDistillerPages(
312 list, page_urls, static_cast<int>(kMaxPagesInArticle)));
313
314 distiller_.reset(new DistillerImpl(page_factory_, url_fetcher_factory_));
315
316 distiller_->SetMaxNumPagesInArticle(kMaxPagesInArticle);
317
318 distiller_->Init();
319 distiller_->DistillPage(
320 GURL(page_urls[0]),
321 base::Bind(&DistillerTest::OnDistillPageDone, base::Unretained(this)));
322 base::MessageLoop::current()->RunUntilIdle();
323 EXPECT_EQ(kTitle, article_proto_->title());
324 EXPECT_EQ(kMaxPagesInArticle,
325 static_cast<size_t>(article_proto_->pages_size()));
326
327 // Now check if distilling an article with exactly the page limit works by
328 // resetting the next page url of the last page of the article.
329 list[kMaxPagesInArticle - 1] =
330 CreateDistilledValueReturnedFromJS(kTitle, "Content", vector<int>(), "");
331 EXPECT_CALL(page_factory_, CreateDistillerPageMock(_))
332 .WillOnce(CreateMockDistillerPages(
333 list, page_urls, static_cast<int>(kMaxPagesInArticle)));
334
335 distiller_.reset(new DistillerImpl(page_factory_, url_fetcher_factory_));
336 distiller_->SetMaxNumPagesInArticle(kMaxPagesInArticle);
337
338 distiller_->Init();
339 distiller_->DistillPage(
340 GURL(page_urls[0]),
341 base::Bind(&DistillerTest::OnDistillPageDone, base::Unretained(this)));
342 base::MessageLoop::current()->RunUntilIdle();
343 EXPECT_EQ(kTitle, article_proto_->title());
344 EXPECT_EQ(kMaxPagesInArticle,
345 static_cast<size_t>(article_proto_->pages_size()));
346 }
347
348 TEST_F(DistillerTest, SinglePageDistillationFailure) {
349 base::MessageLoopForUI loop;
350 // To simulate failure return a null value.
351 scoped_ptr<base::Value> nullValue(base::Value::CreateNullValue());
352 EXPECT_CALL(page_factory_, CreateDistillerPageMock(_))
353 .WillOnce(CreateMockDistillerPage(nullValue.get(), GURL(kURL)));
354 distiller_.reset(new DistillerImpl(page_factory_, url_fetcher_factory_));
355 distiller_->Init();
356 distiller_->DistillPage(
357 GURL(kURL),
358 base::Bind(&DistillerTest::OnDistillPageDone, base::Unretained(this)));
359 base::MessageLoop::current()->RunUntilIdle();
360 EXPECT_EQ("", article_proto_->title());
361 EXPECT_EQ(0, article_proto_->pages_size());
362 }
363
364 TEST_F(DistillerTest, MultiplePagesDistillationFailure) {
365 base::MessageLoopForUI loop;
366 const int kNumPages = 8;
367 string content[kNumPages];
368 string page_urls[kNumPages];
369 scoped_ptr<base::Value> distilled_values[kNumPages];
370 // The page number of the failed page.
371 int failed_page_num = 3;
372 string url_prefix = "http://a.com/";
373 for (int page_num = 0; page_num < kNumPages; ++page_num) {
374 page_urls[page_num] = url_prefix + base::IntToString(page_num);
375 content[page_num] = "Content for page:" + base::IntToString(page_num);
376 string next_page_url = url_prefix + base::IntToString(page_num + 1);
377 if (page_num != failed_page_num) {
378 distilled_values[page_num] = CreateDistilledValueReturnedFromJS(
379 kTitle, content[page_num], vector<int>(), next_page_url);
380 } else {
381 distilled_values[page_num].reset(base::Value::CreateNullValue());
382 }
383 }
384
385 // Expect only calls till the failed page number.
386 EXPECT_CALL(page_factory_, CreateDistillerPageMock(_))
387 .WillOnce(CreateMockDistillerPages(
388 distilled_values, page_urls, failed_page_num + 1));
389
390 distiller_.reset(new DistillerImpl(page_factory_, url_fetcher_factory_));
391 distiller_->Init();
392 distiller_->DistillPage(
393 GURL(page_urls[0]),
394 base::Bind(&DistillerTest::OnDistillPageDone, base::Unretained(this)));
395 base::MessageLoop::current()->RunUntilIdle();
396 EXPECT_EQ(kTitle, article_proto_->title());
397 EXPECT_EQ(article_proto_->pages_size(), failed_page_num);
398 for (int page_num = 0; page_num < failed_page_num; ++page_num) {
399 const DistilledPageProto& page = article_proto_->pages(page_num);
400 EXPECT_EQ(content[page_num], page.html());
401 EXPECT_EQ(page_urls[page_num], page.url());
402 }
403 }
404
293 } // namespace dom_distiller 405 } // namespace dom_distiller
OLDNEW
« 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