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

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

Issue 504263002: Add DebugInfo to DistilledPageProto. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove-intermediate-distilledpageinfo-structs
Patch Set: merged in upstream Created 6 years, 3 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
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 <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 27 matching lines...) Expand all
38 using dom_distiller::proto::DomDistillerResult; 38 using dom_distiller::proto::DomDistillerResult;
39 39
40 namespace { 40 namespace {
41 const char kTitle[] = "Title"; 41 const char kTitle[] = "Title";
42 const char kContent[] = "Content"; 42 const char kContent[] = "Content";
43 const char kURL[] = "http://a.com/"; 43 const char kURL[] = "http://a.com/";
44 const size_t kTotalImages = 2; 44 const size_t kTotalImages = 2;
45 const char* kImageURLs[kTotalImages] = {"http://a.com/img1.jpg", 45 const char* kImageURLs[kTotalImages] = {"http://a.com/img1.jpg",
46 "http://a.com/img2.jpg"}; 46 "http://a.com/img2.jpg"};
47 const char* kImageData[kTotalImages] = {"abcde", "12345"}; 47 const char* kImageData[kTotalImages] = {"abcde", "12345"};
48 const char kDebugLog[] = "Debug Log";
48 49
49 const string GetImageName(int page_num, int image_num) { 50 const string GetImageName(int page_num, int image_num) {
50 return base::IntToString(page_num) + "_" + base::IntToString(image_num); 51 return base::IntToString(page_num) + "_" + base::IntToString(image_num);
51 } 52 }
52 53
53 scoped_ptr<base::Value> CreateDistilledValueReturnedFromJS( 54 scoped_ptr<base::Value> CreateDistilledValueReturnedFromJS(
54 const string& title, 55 const string& title,
55 const string& content, 56 const string& content,
56 const vector<int>& image_indices, 57 const vector<int>& image_indices,
57 const string& next_page_url, 58 const string& next_page_url,
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); 335 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions()));
335 DistillPage(kURL, CreateMockDistillerPage(result.get(), GURL(kURL)).Pass()); 336 DistillPage(kURL, CreateMockDistillerPage(result.get(), GURL(kURL)).Pass());
336 base::MessageLoop::current()->RunUntilIdle(); 337 base::MessageLoop::current()->RunUntilIdle();
337 EXPECT_EQ(kTitle, article_proto_->title()); 338 EXPECT_EQ(kTitle, article_proto_->title());
338 ASSERT_EQ(article_proto_->pages_size(), 1); 339 ASSERT_EQ(article_proto_->pages_size(), 1);
339 const DistilledPageProto& first_page = article_proto_->pages(0); 340 const DistilledPageProto& first_page = article_proto_->pages(0);
340 EXPECT_EQ(kContent, first_page.html()); 341 EXPECT_EQ(kContent, first_page.html());
341 EXPECT_EQ(kURL, first_page.url()); 342 EXPECT_EQ(kURL, first_page.url());
342 } 343 }
343 344
345 TEST_F(DistillerTest, DistillPageWithDebugInfo) {
346 base::MessageLoopForUI loop;
347 DomDistillerResult dd_result;
348 dd_result.mutable_debug_info()->set_log(kDebugLog);
349 scoped_ptr<base::Value> result =
350 dom_distiller::proto::json::DomDistillerResult::WriteToValue(dd_result);
351 distiller_.reset(
352 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions()));
353 DistillPage(kURL, CreateMockDistillerPage(result.get(), GURL(kURL)).Pass());
354 base::MessageLoop::current()->RunUntilIdle();
355 const DistilledPageProto& first_page = article_proto_->pages(0);
356 EXPECT_EQ(kDebugLog, first_page.debug_info().log());
357 }
358
344 TEST_F(DistillerTest, DistillPageWithImages) { 359 TEST_F(DistillerTest, DistillPageWithImages) {
345 base::MessageLoopForUI loop; 360 base::MessageLoopForUI loop;
346 vector<int> image_indices; 361 vector<int> image_indices;
347 image_indices.push_back(0); 362 image_indices.push_back(0);
348 image_indices.push_back(1); 363 image_indices.push_back(1);
349 scoped_ptr<base::Value> result = 364 scoped_ptr<base::Value> result =
350 CreateDistilledValueReturnedFromJS(kTitle, kContent, image_indices, ""); 365 CreateDistilledValueReturnedFromJS(kTitle, kContent, image_indices, "");
351 distiller_.reset( 366 distiller_.reset(
352 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); 367 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions()));
353 DistillPage(kURL, CreateMockDistillerPage(result.get(), GURL(kURL)).Pass()); 368 DistillPage(kURL, CreateMockDistillerPage(result.get(), GURL(kURL)).Pass());
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 641
627 ASSERT_TRUE(distiller_page); 642 ASSERT_TRUE(distiller_page);
628 // Post the task to execute javascript and then delete the distiller. 643 // Post the task to execute javascript and then delete the distiller.
629 distiller_page->OnDistillationDone(GURL(kURL), distilled_value.get()); 644 distiller_page->OnDistillationDone(GURL(kURL), distilled_value.get());
630 distiller_.reset(); 645 distiller_.reset();
631 646
632 base::MessageLoop::current()->RunUntilIdle(); 647 base::MessageLoop::current()->RunUntilIdle();
633 } 648 }
634 649
635 } // namespace dom_distiller 650 } // namespace dom_distiller
OLDNEW
« no previous file with comments | « components/dom_distiller/core/distiller.cc ('k') | components/dom_distiller/core/proto/distilled_page.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698