Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" | 6 #include "components/rappor/public/rappor_utils.h" |
| 7 #include "components/rappor/test_rappor_service.h" | 7 #include "components/rappor/test_rappor_service.h" |
| 8 #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" |
| 9 #include "content/common/input/synthetic_web_input_event_builders.h" | 9 #include "content/common/input/synthetic_web_input_event_builders.h" |
| 10 #include "content/public/browser/native_web_keyboard_event.h" | 10 #include "content/public/browser/native_web_keyboard_event.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 class RenderWidgetHostLatencyTrackerTest | 86 class RenderWidgetHostLatencyTrackerTest |
| 87 : public RenderViewHostImplTestHarness { | 87 : public RenderViewHostImplTestHarness { |
| 88 public: | 88 public: |
| 89 RenderWidgetHostLatencyTrackerTest() : old_browser_client_(NULL) { | 89 RenderWidgetHostLatencyTrackerTest() : old_browser_client_(NULL) { |
| 90 tracker_.Initialize(kTestRoutingId, kTestProcessId); | 90 tracker_.Initialize(kTestRoutingId, kTestProcessId); |
| 91 ResetHistograms(); | 91 ResetHistograms(); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void RapporSampleAssert(const char* rappor_name, int count) { | |
| 95 rappor::TestSample::Shadow* sample_obj = | |
| 96 test_browser_client_.getTestRapporService()->GetRecordedSampleForMetric( | |
| 97 rappor_name); | |
| 98 if (count) { | |
| 99 EXPECT_NE(nullptr, sample_obj); | |
| 100 if (sample_obj) { | |
| 101 const auto& domain_it = sample_obj->string_fields.find("Domain"); | |
| 102 EXPECT_NE(domain_it, sample_obj->string_fields.end()); | |
| 103 EXPECT_EQ("bar.com", domain_it->second); | |
| 104 const auto& latency_it = sample_obj->uint64_fields.find("Latency"); | |
| 105 EXPECT_NE(latency_it, sample_obj->uint64_fields.end()); | |
| 106 EXPECT_EQ(rappor::NO_NOISE, latency_it->second.second); | |
| 107 } | |
| 108 EXPECT_EQ(count, | |
| 109 test_browser_client_.getTestRapporService()->GetReportsCount()); | |
| 110 } else { | |
| 111 EXPECT_EQ(nullptr, sample_obj); | |
| 112 } | |
| 113 } | |
| 114 | |
| 94 ::testing::AssertionResult HistogramSizeEq(const char* histogram_name, | 115 ::testing::AssertionResult HistogramSizeEq(const char* histogram_name, |
| 95 int size) { | 116 int size) { |
| 96 uint64_t histogram_size = | 117 uint64_t histogram_size = |
| 97 histogram_tester_->GetAllSamples(histogram_name).size(); | 118 histogram_tester_->GetAllSamples(histogram_name).size(); |
| 98 if (static_cast<uint64_t>(size) == histogram_size) { | 119 if (static_cast<uint64_t>(size) == histogram_size) { |
| 99 return ::testing::AssertionSuccess(); | 120 return ::testing::AssertionSuccess(); |
| 100 } else { | 121 } else { |
| 101 return ::testing::AssertionFailure() << histogram_name << " expected " | 122 return ::testing::AssertionFailure() << histogram_name << " expected " |
| 102 << size << " entries, but had " | 123 << size << " entries, but had " |
| 103 << histogram_size; | 124 << histogram_size; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 128 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostLatencyTrackerTest); | 149 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostLatencyTrackerTest); |
| 129 const int kTestRoutingId = 3; | 150 const int kTestRoutingId = 3; |
| 130 const int kTestProcessId = 1; | 151 const int kTestProcessId = 1; |
| 131 std::unique_ptr<base::HistogramTester> histogram_tester_; | 152 std::unique_ptr<base::HistogramTester> histogram_tester_; |
| 132 RenderWidgetHostLatencyTracker tracker_; | 153 RenderWidgetHostLatencyTracker tracker_; |
| 133 RenderWidgetHostLatencyTrackerTestBrowserClient test_browser_client_; | 154 RenderWidgetHostLatencyTrackerTestBrowserClient test_browser_client_; |
| 134 ContentBrowserClient* old_browser_client_; | 155 ContentBrowserClient* old_browser_client_; |
| 135 }; | 156 }; |
| 136 | 157 |
| 137 TEST_F(RenderWidgetHostLatencyTrackerTest, TestWheelToFirstScrollHistograms) { | 158 TEST_F(RenderWidgetHostLatencyTrackerTest, TestWheelToFirstScrollHistograms) { |
| 159 const GURL url("http://www.foo.bar.com/subpage/1"); | |
| 160 contents()->NavigateAndCommit(url); | |
| 138 for (bool rendering_on_main : {false, true}) { | 161 for (bool rendering_on_main : {false, true}) { |
| 139 for (bool is_running_navigation_hint_task : {false, true}) { | 162 for (bool is_running_navigation_hint_task : {false, true}) { |
| 140 ResetHistograms(); | 163 ResetHistograms(); |
| 141 { | 164 { |
| 142 auto wheel = SyntheticWebMouseWheelEventBuilder::Build( | 165 auto wheel = SyntheticWebMouseWheelEventBuilder::Build( |
| 143 blink::WebMouseWheelEvent::PhaseChanged); | 166 blink::WebMouseWheelEvent::PhaseChanged); |
| 144 base::TimeTicks now = base::TimeTicks::Now(); | 167 base::TimeTicks now = base::TimeTicks::Now(); |
| 145 wheel.timeStampSeconds = (now - base::TimeTicks()).InSecondsF(); | 168 wheel.timeStampSeconds = (now - base::TimeTicks()).InSecondsF(); |
| 146 ui::LatencyInfo wheel_latency(ui::SourceEventType::WHEEL); | 169 ui::LatencyInfo wheel_latency(ui::SourceEventType::WHEEL); |
| 147 wheel_latency.AddLatencyNumberWithTimestamp( | 170 wheel_latency.AddLatencyNumberWithTimestamp( |
| 148 ui::INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT, | 171 ui::INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT, |
| 149 tracker()->latency_component_id(), 0, now, 1); | 172 tracker()->latency_component_id(), 0, now, 1); |
| 150 AddFakeComponentsWithTimeStamp(*tracker(), &wheel_latency, now); | 173 AddFakeComponentsWithTimeStamp(*tracker(), &wheel_latency, now); |
| 151 AddRenderingScheduledComponent(&wheel_latency, rendering_on_main, now); | 174 AddRenderingScheduledComponent(&wheel_latency, rendering_on_main, now); |
| 152 tracker()->OnInputEvent(wheel, &wheel_latency); | 175 tracker()->OnInputEvent(wheel, &wheel_latency); |
| 153 EXPECT_TRUE(wheel_latency.FindLatency( | 176 EXPECT_TRUE(wheel_latency.FindLatency( |
| 154 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, | 177 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, |
| 155 tracker()->latency_component_id(), nullptr)); | 178 tracker()->latency_component_id(), nullptr)); |
| 156 EXPECT_TRUE(wheel_latency.FindLatency( | 179 EXPECT_TRUE(wheel_latency.FindLatency( |
| 157 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, nullptr)); | 180 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, nullptr)); |
| 158 EXPECT_EQ(1U, wheel_latency.input_coordinates_size()); | 181 EXPECT_EQ(1U, wheel_latency.input_coordinates_size()); |
| 159 tracker()->OnInputEventAck(wheel, &wheel_latency, | 182 tracker()->OnInputEventAck(wheel, &wheel_latency, |
| 160 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 183 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 161 tracker()->OnFrameSwapped(wheel_latency, | 184 tracker()->OnFrameSwapped(wheel_latency, |
| 162 is_running_navigation_hint_task); | 185 is_running_navigation_hint_task); |
| 186 | |
| 187 | |
|
Avi (use Gerrit)
2016/12/20 17:46:53
one blank line
| |
| 188 // Rappor metrics | |
| 189 RapporSampleAssert( | |
| 190 "Event.Latency.ScrollUpdate.Touch." | |
| 191 "TimeToScrollUpdateSwapBegin2", 0); | |
| 192 RapporSampleAssert( | |
| 193 "Event.Latency.ScrollBegin.Touch." | |
| 194 "TimeToScrollUpdateSwapBegin2", 0); | |
| 195 RapporSampleAssert( | |
| 196 "Event.Latency.ScrollBegin.Wheel." | |
| 197 "TimeToScrollUpdateSwapBegin2", 2); | |
| 198 | |
| 199 // UMA histograms | |
| 163 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.WheelUI", 1)); | 200 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.WheelUI", 1)); |
| 164 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.WheelAcked", 1)); | 201 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.WheelAcked", 1)); |
| 165 | 202 |
| 166 EXPECT_TRUE( | 203 EXPECT_TRUE( |
| 167 HistogramSizeEq("Event.Latency.ScrollBegin.Wheel." | 204 HistogramSizeEq("Event.Latency.ScrollBegin.Wheel." |
| 168 "TimeToScrollUpdateSwapBegin2", | 205 "TimeToScrollUpdateSwapBegin2", |
| 169 1)); | 206 1)); |
| 170 EXPECT_TRUE(HistogramSizeEq( | 207 EXPECT_TRUE(HistogramSizeEq( |
| 171 "Event.Latency.ScrollBegin.Wheel.TimeToHandled2_Main", | 208 "Event.Latency.ScrollBegin.Wheel.TimeToHandled2_Main", |
| 172 rendering_on_main ? 1 : 0)); | 209 rendering_on_main ? 1 : 0)); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 "Event.Latency.ScrollUpdate.Wheel.BrowserNotifiedToBeforeGpuSwap2", | 319 "Event.Latency.ScrollUpdate.Wheel.BrowserNotifiedToBeforeGpuSwap2", |
| 283 1)); | 320 1)); |
| 284 EXPECT_TRUE( | 321 EXPECT_TRUE( |
| 285 HistogramSizeEq("Event.Latency.ScrollUpdate.Wheel.GpuSwap2", 1)); | 322 HistogramSizeEq("Event.Latency.ScrollUpdate.Wheel.GpuSwap2", 1)); |
| 286 } | 323 } |
| 287 } | 324 } |
| 288 } | 325 } |
| 289 } | 326 } |
| 290 | 327 |
| 291 TEST_F(RenderWidgetHostLatencyTrackerTest, TestTouchToFirstScrollHistograms) { | 328 TEST_F(RenderWidgetHostLatencyTrackerTest, TestTouchToFirstScrollHistograms) { |
| 329 const GURL url("http://www.foo.bar.com/subpage/1"); | |
| 330 contents()->NavigateAndCommit(url); | |
| 292 for (bool rendering_on_main : {false, true}) { | 331 for (bool rendering_on_main : {false, true}) { |
| 293 for (bool is_running_navigation_hint_task : {false, true}) { | 332 for (bool is_running_navigation_hint_task : {false, true}) { |
| 294 ResetHistograms(); | 333 ResetHistograms(); |
| 295 { | 334 { |
| 296 auto scroll = SyntheticWebGestureEventBuilder::BuildScrollUpdate( | 335 auto scroll = SyntheticWebGestureEventBuilder::BuildScrollUpdate( |
| 297 5.f, -5.f, 0, blink::WebGestureDeviceTouchscreen); | 336 5.f, -5.f, 0, blink::WebGestureDeviceTouchscreen); |
| 298 base::TimeTicks now = base::TimeTicks::Now(); | 337 base::TimeTicks now = base::TimeTicks::Now(); |
| 299 scroll.timeStampSeconds = (now - base::TimeTicks()).InSecondsF(); | 338 scroll.timeStampSeconds = (now - base::TimeTicks()).InSecondsF(); |
| 300 ui::LatencyInfo scroll_latency; | 339 ui::LatencyInfo scroll_latency; |
| 301 scroll_latency.AddLatencyNumberWithTimestamp( | 340 scroll_latency.AddLatencyNumberWithTimestamp( |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 331 tracker()->latency_component_id(), nullptr)); | 370 tracker()->latency_component_id(), nullptr)); |
| 332 EXPECT_TRUE(touch_latency.FindLatency( | 371 EXPECT_TRUE(touch_latency.FindLatency( |
| 333 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, nullptr)); | 372 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, nullptr)); |
| 334 EXPECT_EQ(2U, touch_latency.input_coordinates_size()); | 373 EXPECT_EQ(2U, touch_latency.input_coordinates_size()); |
| 335 tracker()->OnInputEventAck(touch, &touch_latency, | 374 tracker()->OnInputEventAck(touch, &touch_latency, |
| 336 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 375 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 337 tracker()->OnFrameSwapped(touch_latency, | 376 tracker()->OnFrameSwapped(touch_latency, |
| 338 is_running_navigation_hint_task); | 377 is_running_navigation_hint_task); |
| 339 } | 378 } |
| 340 | 379 |
| 380 // Rappor metrics | |
| 381 RapporSampleAssert( | |
| 382 "Event.Latency.ScrollUpdate.Touch." | |
| 383 "TimeToScrollUpdateSwapBegin2", 0); | |
| 384 RapporSampleAssert( | |
| 385 "Event.Latency.ScrollBegin.Touch." | |
| 386 "TimeToScrollUpdateSwapBegin2", 2); | |
| 387 RapporSampleAssert( | |
| 388 "Event.Latency.ScrollBegin.Wheel." | |
| 389 "TimeToScrollUpdateSwapBegin2", 0); | |
| 390 | |
| 391 // UMA histograms | |
| 341 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.TouchUI", 1)); | 392 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.TouchUI", 1)); |
| 342 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.TouchAcked", 1)); | 393 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.TouchAcked", 1)); |
| 343 EXPECT_TRUE(HistogramSizeEq( | 394 EXPECT_TRUE(HistogramSizeEq( |
| 344 "Event.Latency.TouchToFirstScrollUpdateSwapBegin", 1)); | 395 "Event.Latency.TouchToFirstScrollUpdateSwapBegin", 1)); |
| 345 EXPECT_TRUE( | 396 EXPECT_TRUE( |
| 346 HistogramSizeEq("Event.Latency.TouchToFirstScrollUpdateSwapBegin_" | 397 HistogramSizeEq("Event.Latency.TouchToFirstScrollUpdateSwapBegin_" |
| 347 "IsRunningNavigationHintTask", | 398 "IsRunningNavigationHintTask", |
| 348 is_running_navigation_hint_task ? 1 : 0)); | 399 is_running_navigation_hint_task ? 1 : 0)); |
| 349 EXPECT_TRUE( | 400 EXPECT_TRUE( |
| 350 HistogramSizeEq("Event.Latency.TouchToScrollUpdateSwapBegin", 1)); | 401 HistogramSizeEq("Event.Latency.TouchToScrollUpdateSwapBegin", 1)); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 EXPECT_TRUE(touch_latency.FindLatency( | 517 EXPECT_TRUE(touch_latency.FindLatency( |
| 467 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, nullptr)); | 518 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, nullptr)); |
| 468 EXPECT_EQ(2U, touch_latency.input_coordinates_size()); | 519 EXPECT_EQ(2U, touch_latency.input_coordinates_size()); |
| 469 tracker()->OnInputEventAck(touch, &touch_latency, | 520 tracker()->OnInputEventAck(touch, &touch_latency, |
| 470 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 521 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 471 tracker()->OnFrameSwapped(touch_latency, | 522 tracker()->OnFrameSwapped(touch_latency, |
| 472 is_running_navigation_hint_task); | 523 is_running_navigation_hint_task); |
| 473 } | 524 } |
| 474 | 525 |
| 475 // Rappor metrics | 526 // Rappor metrics |
| 476 rappor::TestSample::Shadow* sample_obj = | 527 RapporSampleAssert( |
| 477 test_browser_client_.getTestRapporService() | 528 "Event.Latency.ScrollUpdate.Touch." |
| 478 ->GetRecordedSampleForMetric( | 529 "TimeToScrollUpdateSwapBegin2", 2); |
| 479 "Event.Latency.ScrollUpdate.Touch." | 530 RapporSampleAssert( |
| 480 "TimeToScrollUpdateSwapBegin2"); | 531 "Event.Latency.ScrollBegin.Touch." |
| 481 EXPECT_NE(nullptr, sample_obj); | 532 "TimeToScrollUpdateSwapBegin2", 0); |
| 482 const auto& domain_it = sample_obj->string_fields.find("Domain"); | 533 RapporSampleAssert( |
| 483 EXPECT_NE(domain_it, sample_obj->string_fields.end()); | 534 "Event.Latency.ScrollBegin.Wheel." |
| 484 EXPECT_EQ("bar.com", domain_it->second); | 535 "TimeToScrollUpdateSwapBegin2", 0); |
| 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 | 536 |
| 492 // UMA histograms | 537 // UMA histograms |
| 493 EXPECT_TRUE(HistogramSizeEq( | 538 EXPECT_TRUE(HistogramSizeEq( |
| 494 "Event.Latency.ScrollBegin.Touch.TimeToScrollUpdateSwapBegin2", 0)); | 539 "Event.Latency.ScrollBegin.Touch.TimeToScrollUpdateSwapBegin2", 0)); |
| 495 EXPECT_TRUE(HistogramSizeEq( | 540 EXPECT_TRUE(HistogramSizeEq( |
| 496 "Event.Latency.ScrollUpdate.Touch.TimeToScrollUpdateSwapBegin2", 1)); | 541 "Event.Latency.ScrollUpdate.Touch.TimeToScrollUpdateSwapBegin2", 1)); |
| 497 EXPECT_TRUE(HistogramSizeEq( | 542 EXPECT_TRUE(HistogramSizeEq( |
| 498 "Event.Latency.ScrollBegin.Touch.TimeToHandled2_Main", 0)); | 543 "Event.Latency.ScrollBegin.Touch.TimeToHandled2_Main", 0)); |
| 499 EXPECT_TRUE(HistogramSizeEq( | 544 EXPECT_TRUE(HistogramSizeEq( |
| 500 "Event.Latency.ScrollBegin.Touch.TimeToHandled2_Impl", 0)); | 545 "Event.Latency.ScrollBegin.Touch.TimeToHandled2_Impl", 0)); |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 921 "Event.Latency.BlockingTime.TouchEndDefaultPrevented"), | 966 "Event.Latency.BlockingTime.TouchEndDefaultPrevented"), |
| 922 ElementsAre(Bucket( | 967 ElementsAre(Bucket( |
| 923 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1))); | 968 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1))); |
| 924 EXPECT_THAT(histogram_tester().GetAllSamples( | 969 EXPECT_THAT(histogram_tester().GetAllSamples( |
| 925 "Event.Latency.BlockingTime.TouchEndDefaultAllowed"), | 970 "Event.Latency.BlockingTime.TouchEndDefaultAllowed"), |
| 926 ElementsAre(Bucket( | 971 ElementsAre(Bucket( |
| 927 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1))); | 972 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1))); |
| 928 } | 973 } |
| 929 | 974 |
| 930 } // namespace content | 975 } // namespace content |
| OLD | NEW |