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

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

Issue 717643003: Extract timing info from distiller result (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dd-roll-perf
Patch Set: Created 6 years, 1 month 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 16 matching lines...) Expand all
27 #include "third_party/dom_distiller_js/dom_distiller_json_converter.h" 27 #include "third_party/dom_distiller_js/dom_distiller_json_converter.h"
28 28
29 using std::vector; 29 using std::vector;
30 using std::string; 30 using std::string;
31 using ::testing::Invoke; 31 using ::testing::Invoke;
32 using ::testing::Return; 32 using ::testing::Return;
33 using ::testing::_; 33 using ::testing::_;
34 34
35 using dom_distiller::proto::DomDistillerOptions; 35 using dom_distiller::proto::DomDistillerOptions;
36 using dom_distiller::proto::DomDistillerResult; 36 using dom_distiller::proto::DomDistillerResult;
37 using dom_distiller::proto::TimingEntry;
37 38
38 namespace { 39 namespace {
39 const char kTitle[] = "Title"; 40 const char kTitle[] = "Title";
40 const char kContent[] = "Content"; 41 const char kContent[] = "Content";
41 const char kURL[] = "http://a.com/"; 42 const char kURL[] = "http://a.com/";
42 const size_t kTotalImages = 2; 43 const size_t kTotalImages = 2;
43 const char* kImageURLs[kTotalImages] = {"http://a.com/img1.jpg", 44 const char* kImageURLs[kTotalImages] = {"http://a.com/img1.jpg",
44 "http://a.com/img2.jpg"}; 45 "http://a.com/img2.jpg"};
45 const char* kImageData[kTotalImages] = {"abcde", "12345"}; 46 const char* kImageData[kTotalImages] = {"abcde", "12345"};
46 const char kDebugLog[] = "Debug Log"; 47 const char kDebugLog[] = "Debug Log";
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 scoped_ptr<base::Value> result = 354 scoped_ptr<base::Value> result =
354 dom_distiller::proto::json::DomDistillerResult::WriteToValue(dd_result); 355 dom_distiller::proto::json::DomDistillerResult::WriteToValue(dd_result);
355 distiller_.reset( 356 distiller_.reset(
356 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); 357 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions()));
357 DistillPage(kURL, CreateMockDistillerPage(result.get(), GURL(kURL)).Pass()); 358 DistillPage(kURL, CreateMockDistillerPage(result.get(), GURL(kURL)).Pass());
358 base::MessageLoop::current()->RunUntilIdle(); 359 base::MessageLoop::current()->RunUntilIdle();
359 const DistilledPageProto& first_page = article_proto_->pages(0); 360 const DistilledPageProto& first_page = article_proto_->pages(0);
360 EXPECT_EQ(kDebugLog, first_page.debug_info().log()); 361 EXPECT_EQ(kDebugLog, first_page.debug_info().log());
361 } 362 }
362 363
364 void SetTimingEntry(TimingEntry* entry, const std::string& name, double time) {
365 entry->set_name(name);
366 entry->set_time(time);
367 }
368
369 TEST_F(DistillerTest, DistillPageWithTimingInfo) {
370 base::MessageLoopForUI loop;
371 DomDistillerResult dd_result;
372 dd_result.mutable_timing_info()->set_total_time(1.0);
373 dd_result.mutable_timing_info()->set_markup_parsing_time(2.0);
374 dd_result.mutable_timing_info()->set_document_construction_time(3.0);
375 dd_result.mutable_timing_info()->set_article_processing_time(4.0);
376 dd_result.mutable_timing_info()->set_formatting_time(5.0);
377 SetTimingEntry(
378 dd_result.mutable_timing_info()->add_other_times(), "time0", 6.0);
379 SetTimingEntry(
380 dd_result.mutable_timing_info()->add_other_times(), "time1", 7.0);
381 scoped_ptr<base::Value> result =
382 dom_distiller::proto::json::DomDistillerResult::WriteToValue(dd_result);
383 distiller_.reset(
384 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions()));
385 DistillPage(kURL, CreateMockDistillerPage(result.get(), GURL(kURL)).Pass());
386 base::MessageLoop::current()->RunUntilIdle();
387 const DistilledPageProto& first_page = article_proto_->pages(0);
388 std::map<std::string, double> timings;
389 for (int i = 0; i < first_page.timing_info_size(); ++i) {
390 DistilledPageProto::TimingInfo timing = first_page.timing_info(i);
391 timings[timing.name()] = timing.time();
392 }
393 EXPECT_EQ(7u, timings.size());
394 EXPECT_EQ(1.0, timings["total"]);
395 EXPECT_EQ(2.0, timings["markup_parsing"]);
396 EXPECT_EQ(3.0, timings["document_construction"]);
397 EXPECT_EQ(4.0, timings["article_processing"]);
398 EXPECT_EQ(5.0, timings["formatting"]);
399 EXPECT_EQ(6.0, timings["time0"]);
400 EXPECT_EQ(7.0, timings["time1"]);
401 }
402
363 TEST_F(DistillerTest, DistillPageWithImages) { 403 TEST_F(DistillerTest, DistillPageWithImages) {
364 base::MessageLoopForUI loop; 404 base::MessageLoopForUI loop;
365 vector<int> image_indices; 405 vector<int> image_indices;
366 image_indices.push_back(0); 406 image_indices.push_back(0);
367 image_indices.push_back(1); 407 image_indices.push_back(1);
368 scoped_ptr<base::Value> result = 408 scoped_ptr<base::Value> result =
369 CreateDistilledValueReturnedFromJS(kTitle, kContent, image_indices, ""); 409 CreateDistilledValueReturnedFromJS(kTitle, kContent, image_indices, "");
370 distiller_.reset( 410 distiller_.reset(
371 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions())); 411 new DistillerImpl(url_fetcher_factory_, DomDistillerOptions()));
372 DistillPage(kURL, CreateMockDistillerPage(result.get(), GURL(kURL)).Pass()); 412 DistillPage(kURL, CreateMockDistillerPage(result.get(), GURL(kURL)).Pass());
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 685
646 ASSERT_TRUE(distiller_page); 686 ASSERT_TRUE(distiller_page);
647 // Post the task to execute javascript and then delete the distiller. 687 // Post the task to execute javascript and then delete the distiller.
648 distiller_page->OnDistillationDone(GURL(kURL), distilled_value.get()); 688 distiller_page->OnDistillationDone(GURL(kURL), distilled_value.get());
649 distiller_.reset(); 689 distiller_.reset();
650 690
651 base::MessageLoop::current()->RunUntilIdle(); 691 base::MessageLoop::current()->RunUntilIdle();
652 } 692 }
653 693
654 } // namespace dom_distiller 694 } // 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