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

Side by Side Diff: content/browser/renderer_host/input/render_widget_host_latency_tracker_unittest.cc

Issue 2492793004: Add TimeToScrollUpdateSwapBegin2 in RAPPOR (Closed)
Patch Set: add tests Created 4 years 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/test/histogram_tester.h" 5 #include "base/test/histogram_tester.h"
6 #include "components/rappor/public/rappor_utils.h"
7 #include "components/rappor/test_rappor_service.h"
6 #include "content/browser/renderer_host/input/render_widget_host_latency_tracker .h" 8 #include "content/browser/renderer_host/input/render_widget_host_latency_tracker .h"
7 #include "content/common/input/synthetic_web_input_event_builders.h" 9 #include "content/common/input/synthetic_web_input_event_builders.h"
8 #include "content/public/browser/native_web_keyboard_event.h" 10 #include "content/public/browser/native_web_keyboard_event.h"
11 #include "content/test/test_content_browser_client.h"
12 #include "content/test/test_render_view_host.h"
13 #include "content/test/test_web_contents.h"
9 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
11 16
12 using base::Bucket; 17 using base::Bucket;
13 using blink::WebInputEvent; 18 using blink::WebInputEvent;
14 using testing::ElementsAre; 19 using testing::ElementsAre;
15 20
16 namespace content { 21 namespace content {
17 namespace { 22 namespace {
18 23
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 57
53 } else { 58 } else {
54 latency->AddLatencyNumberWithTimestamp( 59 latency->AddLatencyNumberWithTimestamp(
55 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_IMPL_COMPONENT, 0, 0, 60 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_IMPL_COMPONENT, 0, 0,
56 time_stamp, 1); 61 time_stamp, 1);
57 } 62 }
58 } 63 }
59 64
60 } // namespace 65 } // namespace
61 66
62 class RenderWidgetHostLatencyTrackerTest : public testing::Test { 67 class RenderWidgetHostLatencyTrackerTestBrowserClient
68 : public TestContentBrowserClient {
63 public: 69 public:
64 RenderWidgetHostLatencyTrackerTest() { 70 RenderWidgetHostLatencyTrackerTestBrowserClient() {}
71 ~RenderWidgetHostLatencyTrackerTestBrowserClient() override {}
72
73 rappor::RapporService* GetRapporService() override {
74 return &rappor_service_;
75 }
76
77 rappor::TestRapporServiceImpl* getTestRapporService() {
78 return &rappor_service_;
79 }
80
81 private:
82 rappor::TestRapporServiceImpl rappor_service_;
83 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostLatencyTrackerTestBrowserClient);
84 };
85
86 class RenderWidgetHostLatencyTrackerTest
87 : public RenderViewHostImplTestHarness {
88 public:
89 RenderWidgetHostLatencyTrackerTest() : old_browser_client_(NULL) {
65 tracker_.Initialize(kTestRoutingId, kTestProcessId); 90 tracker_.Initialize(kTestRoutingId, kTestProcessId);
66 ResetHistograms(); 91 ResetHistograms();
67 } 92 }
68 93
69 ::testing::AssertionResult HistogramSizeEq(const char* histogram_name, 94 ::testing::AssertionResult HistogramSizeEq(const char* histogram_name,
70 int size) { 95 int size) {
71 uint64_t histogram_size = 96 uint64_t histogram_size =
72 histogram_tester_->GetAllSamples(histogram_name).size(); 97 histogram_tester_->GetAllSamples(histogram_name).size();
73 if (static_cast<uint64_t>(size) == histogram_size) { 98 if (static_cast<uint64_t>(size) == histogram_size) {
74 return ::testing::AssertionSuccess(); 99 return ::testing::AssertionSuccess();
75 } else { 100 } else {
76 return ::testing::AssertionFailure() << histogram_name << " expected " 101 return ::testing::AssertionFailure() << histogram_name << " expected "
77 << size << " entries, but had " 102 << size << " entries, but had "
78 << histogram_size; 103 << histogram_size;
79 } 104 }
80 } 105 }
81 106
82 RenderWidgetHostLatencyTracker* tracker() { return &tracker_; } 107 RenderWidgetHostLatencyTracker* tracker() { return &tracker_; }
83 void ResetHistograms() { 108 void ResetHistograms() {
84 histogram_tester_.reset(new base::HistogramTester()); 109 histogram_tester_.reset(new base::HistogramTester());
85 } 110 }
86 111
87 const base::HistogramTester& histogram_tester() { 112 const base::HistogramTester& histogram_tester() {
88 return *histogram_tester_; 113 return *histogram_tester_;
89 } 114 }
90 115
91 private: 116 void SetUp() override {
117 RenderViewHostImplTestHarness::SetUp();
118 old_browser_client_ = SetBrowserClientForTesting(&test_browser_client_);
119 tracker_.SetDelegate(contents());
120 }
121
122 void TearDown() override {
123 SetBrowserClientForTesting(old_browser_client_);
124 RenderViewHostImplTestHarness::TearDown();
125 }
126
127 protected:
92 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostLatencyTrackerTest); 128 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostLatencyTrackerTest);
93 const int kTestRoutingId = 3; 129 const int kTestRoutingId = 3;
94 const int kTestProcessId = 1; 130 const int kTestProcessId = 1;
95 std::unique_ptr<base::HistogramTester> histogram_tester_; 131 std::unique_ptr<base::HistogramTester> histogram_tester_;
96 RenderWidgetHostLatencyTracker tracker_; 132 RenderWidgetHostLatencyTracker tracker_;
133 RenderWidgetHostLatencyTrackerTestBrowserClient test_browser_client_;
134 ContentBrowserClient* old_browser_client_;
97 }; 135 };
98 136
99 TEST_F(RenderWidgetHostLatencyTrackerTest, TestWheelToFirstScrollHistograms) { 137 TEST_F(RenderWidgetHostLatencyTrackerTest, TestWheelToFirstScrollHistograms) {
100 for (bool rendering_on_main : {false, true}) { 138 for (bool rendering_on_main : {false, true}) {
101 for (bool is_running_navigation_hint_task : {false, true}) { 139 for (bool is_running_navigation_hint_task : {false, true}) {
102 ResetHistograms(); 140 ResetHistograms();
103 { 141 {
104 auto wheel = SyntheticWebMouseWheelEventBuilder::Build( 142 auto wheel = SyntheticWebMouseWheelEventBuilder::Build(
105 blink::WebMouseWheelEvent::PhaseChanged); 143 blink::WebMouseWheelEvent::PhaseChanged);
106 base::TimeTicks now = base::TimeTicks::Now(); 144 base::TimeTicks now = base::TimeTicks::Now();
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 EXPECT_TRUE(HistogramSizeEq( 412 EXPECT_TRUE(HistogramSizeEq(
375 "Event.Latency.ScrollUpdate.Touch.BrowserNotifiedToBeforeGpuSwap2", 413 "Event.Latency.ScrollUpdate.Touch.BrowserNotifiedToBeforeGpuSwap2",
376 0)); 414 0));
377 EXPECT_TRUE( 415 EXPECT_TRUE(
378 HistogramSizeEq("Event.Latency.ScrollUpdate.Touch.GpuSwap2", 0)); 416 HistogramSizeEq("Event.Latency.ScrollUpdate.Touch.GpuSwap2", 0));
379 } 417 }
380 } 418 }
381 } 419 }
382 420
383 TEST_F(RenderWidgetHostLatencyTrackerTest, TestTouchToScrollHistograms) { 421 TEST_F(RenderWidgetHostLatencyTrackerTest, TestTouchToScrollHistograms) {
422 const GURL url("http://www.foo.bar.com/subpage/1");
423 contents()->NavigateAndCommit(url);
384 for (bool rendering_on_main : {false, true}) { 424 for (bool rendering_on_main : {false, true}) {
385 for (bool is_running_navigation_hint_task : {false, true}) { 425 for (bool is_running_navigation_hint_task : {false, true}) {
386 ResetHistograms(); 426 ResetHistograms();
427 EXPECT_EQ(0,
428 test_browser_client_.getTestRapporService()->GetReportsCount());
387 { 429 {
388 auto scroll = SyntheticWebGestureEventBuilder::BuildScrollUpdate( 430 auto scroll = SyntheticWebGestureEventBuilder::BuildScrollUpdate(
389 5.f, -5.f, 0, blink::WebGestureDeviceTouchscreen); 431 5.f, -5.f, 0, blink::WebGestureDeviceTouchscreen);
390 base::TimeTicks now = base::TimeTicks::Now(); 432 base::TimeTicks now = base::TimeTicks::Now();
391 scroll.timeStampSeconds = (now - base::TimeTicks()).InSecondsF(); 433 scroll.timeStampSeconds = (now - base::TimeTicks()).InSecondsF();
392 ui::LatencyInfo scroll_latency; 434 ui::LatencyInfo scroll_latency;
393 scroll_latency.AddLatencyNumberWithTimestamp( 435 scroll_latency.AddLatencyNumberWithTimestamp(
394 ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT, 436 ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT,
395 tracker()->latency_component_id(), 0, now, 1); 437 tracker()->latency_component_id(), 0, now, 1);
396 AddFakeComponentsWithTimeStamp(*tracker(), &scroll_latency, now); 438 AddFakeComponentsWithTimeStamp(*tracker(), &scroll_latency, now);
(...skipping 26 matching lines...) Expand all
423 tracker()->latency_component_id(), nullptr)); 465 tracker()->latency_component_id(), nullptr));
424 EXPECT_TRUE(touch_latency.FindLatency( 466 EXPECT_TRUE(touch_latency.FindLatency(
425 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, nullptr)); 467 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, nullptr));
426 EXPECT_EQ(2U, touch_latency.input_coordinates_size()); 468 EXPECT_EQ(2U, touch_latency.input_coordinates_size());
427 tracker()->OnInputEventAck(touch, &touch_latency, 469 tracker()->OnInputEventAck(touch, &touch_latency,
428 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 470 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
429 tracker()->OnFrameSwapped(touch_latency, 471 tracker()->OnFrameSwapped(touch_latency,
430 is_running_navigation_hint_task); 472 is_running_navigation_hint_task);
431 } 473 }
432 474
475 // Rappor metrics
476 rappor::TestSample::Shadow* sample_obj =
477 test_browser_client_.getTestRapporService()
478 ->GetRecordedSampleForMetric(
479 "Event.Latency.ScrollUpdate.Touch."
480 "TimeToScrollUpdateSwapBegin2");
481 EXPECT_NE(nullptr, sample_obj);
482 const auto& domain_it = sample_obj->string_fields.find("Domain");
483 EXPECT_NE(domain_it, sample_obj->string_fields.end());
484 EXPECT_EQ("bar.com", domain_it->second);
485 const auto& latency_it = sample_obj->uint64_fields.find("Latency");
486 EXPECT_NE(latency_it, sample_obj->uint64_fields.end());
487 EXPECT_EQ(rappor::NO_NOISE, latency_it->second.second);
488
489 EXPECT_EQ(2,
490 test_browser_client_.getTestRapporService()->GetReportsCount());
491
492 // UMA histograms
433 EXPECT_TRUE(HistogramSizeEq( 493 EXPECT_TRUE(HistogramSizeEq(
434 "Event.Latency.ScrollBegin.Touch.TimeToScrollUpdateSwapBegin2", 0)); 494 "Event.Latency.ScrollBegin.Touch.TimeToScrollUpdateSwapBegin2", 0));
435 EXPECT_TRUE(HistogramSizeEq( 495 EXPECT_TRUE(HistogramSizeEq(
436 "Event.Latency.ScrollUpdate.Touch.TimeToScrollUpdateSwapBegin2", 1)); 496 "Event.Latency.ScrollUpdate.Touch.TimeToScrollUpdateSwapBegin2", 1));
437 EXPECT_TRUE(HistogramSizeEq( 497 EXPECT_TRUE(HistogramSizeEq(
438 "Event.Latency.ScrollBegin.Touch.TimeToHandled2_Main", 0)); 498 "Event.Latency.ScrollBegin.Touch.TimeToHandled2_Main", 0));
439 EXPECT_TRUE(HistogramSizeEq( 499 EXPECT_TRUE(HistogramSizeEq(
440 "Event.Latency.ScrollBegin.Touch.TimeToHandled2_Impl", 0)); 500 "Event.Latency.ScrollBegin.Touch.TimeToHandled2_Impl", 0));
441 EXPECT_TRUE(HistogramSizeEq( 501 EXPECT_TRUE(HistogramSizeEq(
442 "Event.Latency.ScrollBegin.Touch.HandledToRendererSwap2_Main", 0)); 502 "Event.Latency.ScrollBegin.Touch.HandledToRendererSwap2_Main", 0));
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 "Event.Latency.BlockingTime.TouchEndDefaultPrevented"), 921 "Event.Latency.BlockingTime.TouchEndDefaultPrevented"),
862 ElementsAre(Bucket( 922 ElementsAre(Bucket(
863 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1))); 923 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1)));
864 EXPECT_THAT(histogram_tester().GetAllSamples( 924 EXPECT_THAT(histogram_tester().GetAllSamples(
865 "Event.Latency.BlockingTime.TouchEndDefaultAllowed"), 925 "Event.Latency.BlockingTime.TouchEndDefaultAllowed"),
866 ElementsAre(Bucket( 926 ElementsAre(Bucket(
867 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1))); 927 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1)));
868 } 928 }
869 929
870 } // namespace content 930 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698