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

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: Address comments. 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
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 10 matching lines...) Expand all
21 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
23 23
24 using std::vector; 24 using std::vector;
25 using std::string; 25 using std::string;
26 using::testing::Invoke; 26 using::testing::Invoke;
27 using::testing::Return; 27 using::testing::Return;
28 using::testing::_; 28 using::testing::_;
29 29
30 namespace { 30 namespace {
31 const size_t kMaxPagesInArticle = 10;
cjhopman 2014/02/15 02:44:15 nit: this can just be moved into the CheckMaxPageL
shashi 2014/02/15 03:15:36 Done.
32
31 const char kTitle[] = "Title"; 33 const char kTitle[] = "Title";
32 const char kContent[] = "Content"; 34 const char kContent[] = "Content";
33 const char kURL[] = "http://a.com/"; 35 const char kURL[] = "http://a.com/";
34 const size_t kTotalImages = 2; 36 const size_t kTotalImages = 2;
35 const char* kImageURLs[kTotalImages] = {"http://a.com/img1.jpg", 37 const char* kImageURLs[kTotalImages] = {"http://a.com/img1.jpg",
36 "http://a.com/img2.jpg"}; 38 "http://a.com/img2.jpg"};
37 const char* kImageData[kTotalImages] = {"abcde", "12345"}; 39 const char* kImageData[kTotalImages] = {"abcde", "12345"};
38 40
39 const string GetImageName(int page_num, int image_num) { 41 const string GetImageName(int page_num, int image_num) {
40 return base::IntToString(page_num) + "_" + base::IntToString(image_num); 42 return base::IntToString(page_num) + "_" + base::IntToString(image_num);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 MOCK_CONST_METHOD1( 112 MOCK_CONST_METHOD1(
111 CreateDistillerPageMock, 113 CreateDistillerPageMock,
112 DistillerPage*(DistillerPage::Delegate* delegate)); 114 DistillerPage*(DistillerPage::Delegate* delegate));
113 115
114 virtual scoped_ptr<DistillerPage> CreateDistillerPage( 116 virtual scoped_ptr<DistillerPage> CreateDistillerPage(
115 DistillerPage::Delegate* delegate) const OVERRIDE { 117 DistillerPage::Delegate* delegate) const OVERRIDE {
116 return scoped_ptr<DistillerPage>(CreateDistillerPageMock(delegate)); 118 return scoped_ptr<DistillerPage>(CreateDistillerPageMock(delegate));
117 } 119 }
118 }; 120 };
119 121
120
121 class DistillerTest : public testing::Test { 122 class DistillerTest : public testing::Test {
122 public: 123 public:
123 virtual ~DistillerTest() {} 124 virtual ~DistillerTest() {}
124 void OnDistillPageDone(scoped_ptr<DistilledArticleProto> proto) { 125 void OnDistillPageDone(scoped_ptr<DistilledArticleProto> proto) {
125 article_proto_ = proto.Pass(); 126 article_proto_ = proto.Pass();
126 } 127 }
127 128
128 protected: 129 protected:
129 scoped_ptr<DistillerImpl> distiller_; 130 scoped_ptr<DistillerImpl> distiller_;
130 scoped_ptr<DistilledArticleProto> article_proto_; 131 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_)); 284 distiller_.reset(new DistillerImpl(page_factory_, url_fetcher_factory_));
284 distiller_->Init(); 285 distiller_->Init();
285 distiller_->DistillPage( 286 distiller_->DistillPage(
286 GURL(kURL), 287 GURL(kURL),
287 base::Bind(&DistillerTest::OnDistillPageDone, base::Unretained(this))); 288 base::Bind(&DistillerTest::OnDistillPageDone, base::Unretained(this)));
288 base::MessageLoop::current()->RunUntilIdle(); 289 base::MessageLoop::current()->RunUntilIdle();
289 EXPECT_EQ(kTitle, article_proto_->title()); 290 EXPECT_EQ(kTitle, article_proto_->title());
290 EXPECT_EQ(article_proto_->pages_size(), 1); 291 EXPECT_EQ(article_proto_->pages_size(), 1);
291 } 292 }
292 293
294 TEST_F(DistillerTest, CheckMaxPageLimit) {
cjhopman 2014/02/15 02:44:15 Nit: maybe test that an article that is exactly th
shashi 2014/02/15 03:15:36 Done.
295 base::MessageLoopForUI loop;
296 string page_urls[kMaxPagesInArticle];
297 scoped_ptr<base::ListValue> list[kMaxPagesInArticle];
298
299 // Note: Next page url of the last page of article is set. So distiller will
300 // try to do kMaxPagesInArticle + 1 calls if the max article limit does not
301 // work.
302 string url_prefix = "http://a.com/";
303 for (size_t page_num = 0; page_num < kMaxPagesInArticle; ++page_num) {
304 page_urls[page_num] = url_prefix + base::IntToString(page_num + 1);
305 string content = "Content for page:" + base::IntToString(page_num);
306 string next_page_url = url_prefix + base::IntToString(page_num + 2);
307 list[page_num] = CreateDistilledValueReturnedFromJS(
308 kTitle, content, vector<int>(), next_page_url);
309 }
310
311 EXPECT_CALL(page_factory_, CreateDistillerPageMock(_))
312 .WillOnce(CreateMockDistillerPages(
313 list, page_urls, static_cast<int>(kMaxPagesInArticle)));
314
315 distiller_.reset(new DistillerImpl(page_factory_, url_fetcher_factory_));
316
317 distiller_->SetMaxNumPagesInArticle(kMaxPagesInArticle);
318
319 distiller_->Init();
320 distiller_->DistillPage(
321 GURL(page_urls[0]),
322 base::Bind(&DistillerTest::OnDistillPageDone, base::Unretained(this)));
323 base::MessageLoop::current()->RunUntilIdle();
324 EXPECT_EQ(kTitle, article_proto_->title());
325 EXPECT_EQ(kMaxPagesInArticle,
326 static_cast<size_t>(article_proto_->pages_size()));
327 }
328
329 TEST_F(DistillerTest, SinglePageDistillationFailure) {
330 base::MessageLoopForUI loop;
331 // To simulate failure return a null value.
332 scoped_ptr<base::Value> nullValue(base::Value::CreateNullValue());
333 EXPECT_CALL(page_factory_, CreateDistillerPageMock(_))
334 .WillOnce(CreateMockDistillerPage(nullValue.get(), GURL(kURL)));
335 distiller_.reset(new DistillerImpl(page_factory_, url_fetcher_factory_));
336 distiller_->Init();
337 distiller_->DistillPage(
338 GURL(kURL),
339 base::Bind(&DistillerTest::OnDistillPageDone, base::Unretained(this)));
340 base::MessageLoop::current()->RunUntilIdle();
341 EXPECT_EQ("", article_proto_->title());
342 EXPECT_EQ(0, article_proto_->pages_size());
343 }
344
345 TEST_F(DistillerTest, MultiplePagesDistillationFailure) {
346 base::MessageLoopForUI loop;
347 const int kNumPages = 8;
348 string content[kNumPages];
349 string page_urls[kNumPages];
350 scoped_ptr<base::Value> distilled_values[kNumPages];
351 // The page number of the failed page.
352 int failed_page_num = 3;
353 string url_prefix = "http://a.com/";
354 for (int page_num = 0; page_num < kNumPages; ++page_num) {
355 page_urls[page_num] = url_prefix + base::IntToString(page_num);
356 content[page_num] = "Content for page:" + base::IntToString(page_num);
357 string next_page_url = url_prefix + base::IntToString(page_num + 1);
358 if (page_num != failed_page_num) {
359 distilled_values[page_num] = CreateDistilledValueReturnedFromJS(
360 kTitle, content[page_num], vector<int>(), next_page_url);
361 } else {
362 distilled_values[page_num].reset(base::Value::CreateNullValue());
363 }
364 }
365
366 // Expect only calls till the failed page number.
367 EXPECT_CALL(page_factory_, CreateDistillerPageMock(_))
368 .WillOnce(CreateMockDistillerPages(
369 distilled_values, page_urls, failed_page_num + 1));
370
371 distiller_.reset(new DistillerImpl(page_factory_, url_fetcher_factory_));
372 distiller_->Init();
373 distiller_->DistillPage(
374 GURL(page_urls[0]),
375 base::Bind(&DistillerTest::OnDistillPageDone, base::Unretained(this)));
376 base::MessageLoop::current()->RunUntilIdle();
377 EXPECT_EQ(kTitle, article_proto_->title());
378 EXPECT_EQ(article_proto_->pages_size(), failed_page_num);
379 for (int page_num = 0; page_num < failed_page_num; ++page_num) {
380 const DistilledPageProto& page = article_proto_->pages(page_num);
381 EXPECT_EQ(content[page_num], page.html());
382 EXPECT_EQ(page_urls[page_num], page.url());
383 }
384 }
385
293 } // namespace dom_distiller 386 } // namespace dom_distiller
OLDNEW
« components/dom_distiller/core/distiller.cc ('K') | « components/dom_distiller/core/distiller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698