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) { | |
|
tdresser
2016/12/22 15:17:14
Can this be a method returning an AssertionResult
Navid Zolghadr
2016/12/22 16:58:49
Done.
| |
| 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 // Rappor metrics | |
|
tdresser
2016/12/22 15:17:14
Missing . at the end, and elsewhere.
Navid Zolghadr
2016/12/22 16:58:49
Done.
| |
| 188 RapporSampleAssert( | |
| 189 "Event.Latency.ScrollUpdate.Touch." | |
| 190 "TimeToScrollUpdateSwapBegin2", 0); | |
| 191 RapporSampleAssert( | |
| 192 "Event.Latency.ScrollBegin.Touch." | |
| 193 "TimeToScrollUpdateSwapBegin2", 0); | |
| 194 RapporSampleAssert( | |
| 195 "Event.Latency.ScrollBegin.Wheel." | |
| 196 "TimeToScrollUpdateSwapBegin2", 2); | |
| 197 | |
| 198 // UMA histograms | |
| 163 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.WheelUI", 1)); | 199 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.WheelUI", 1)); |
| 164 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.WheelAcked", 1)); | 200 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.WheelAcked", 1)); |
| 165 | 201 |
| 166 EXPECT_TRUE( | 202 EXPECT_TRUE( |
| 167 HistogramSizeEq("Event.Latency.ScrollBegin.Wheel." | 203 HistogramSizeEq("Event.Latency.ScrollBegin.Wheel." |
| 168 "TimeToScrollUpdateSwapBegin2", | 204 "TimeToScrollUpdateSwapBegin2", |
| 169 1)); | 205 1)); |
| 170 EXPECT_TRUE(HistogramSizeEq( | 206 EXPECT_TRUE(HistogramSizeEq( |
| 171 "Event.Latency.ScrollBegin.Wheel.TimeToHandled2_Main", | 207 "Event.Latency.ScrollBegin.Wheel.TimeToHandled2_Main", |
| 172 rendering_on_main ? 1 : 0)); | 208 rendering_on_main ? 1 : 0)); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 "Event.Latency.ScrollUpdate.Wheel.BrowserNotifiedToBeforeGpuSwap2", | 318 "Event.Latency.ScrollUpdate.Wheel.BrowserNotifiedToBeforeGpuSwap2", |
| 283 1)); | 319 1)); |
| 284 EXPECT_TRUE( | 320 EXPECT_TRUE( |
| 285 HistogramSizeEq("Event.Latency.ScrollUpdate.Wheel.GpuSwap2", 1)); | 321 HistogramSizeEq("Event.Latency.ScrollUpdate.Wheel.GpuSwap2", 1)); |
| 286 } | 322 } |
| 287 } | 323 } |
| 288 } | 324 } |
| 289 } | 325 } |
| 290 | 326 |
| 291 TEST_F(RenderWidgetHostLatencyTrackerTest, TestTouchToFirstScrollHistograms) { | 327 TEST_F(RenderWidgetHostLatencyTrackerTest, TestTouchToFirstScrollHistograms) { |
| 328 const GURL url("http://www.foo.bar.com/subpage/1"); | |
| 329 contents()->NavigateAndCommit(url); | |
| 292 for (bool rendering_on_main : {false, true}) { | 330 for (bool rendering_on_main : {false, true}) { |
| 293 for (bool is_running_navigation_hint_task : {false, true}) { | 331 for (bool is_running_navigation_hint_task : {false, true}) { |
| 294 ResetHistograms(); | 332 ResetHistograms(); |
| 295 { | 333 { |
| 296 auto scroll = SyntheticWebGestureEventBuilder::BuildScrollUpdate( | 334 auto scroll = SyntheticWebGestureEventBuilder::BuildScrollUpdate( |
| 297 5.f, -5.f, 0, blink::WebGestureDeviceTouchscreen); | 335 5.f, -5.f, 0, blink::WebGestureDeviceTouchscreen); |
| 298 base::TimeTicks now = base::TimeTicks::Now(); | 336 base::TimeTicks now = base::TimeTicks::Now(); |
| 299 scroll.timeStampSeconds = (now - base::TimeTicks()).InSecondsF(); | 337 scroll.timeStampSeconds = (now - base::TimeTicks()).InSecondsF(); |
| 300 ui::LatencyInfo scroll_latency; | 338 ui::LatencyInfo scroll_latency; |
| 301 scroll_latency.AddLatencyNumberWithTimestamp( | 339 scroll_latency.AddLatencyNumberWithTimestamp( |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 331 tracker()->latency_component_id(), nullptr)); | 369 tracker()->latency_component_id(), nullptr)); |
| 332 EXPECT_TRUE(touch_latency.FindLatency( | 370 EXPECT_TRUE(touch_latency.FindLatency( |
| 333 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, nullptr)); | 371 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, nullptr)); |
| 334 EXPECT_EQ(2U, touch_latency.input_coordinates_size()); | 372 EXPECT_EQ(2U, touch_latency.input_coordinates_size()); |
| 335 tracker()->OnInputEventAck(touch, &touch_latency, | 373 tracker()->OnInputEventAck(touch, &touch_latency, |
| 336 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 374 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 337 tracker()->OnFrameSwapped(touch_latency, | 375 tracker()->OnFrameSwapped(touch_latency, |
| 338 is_running_navigation_hint_task); | 376 is_running_navigation_hint_task); |
| 339 } | 377 } |
| 340 | 378 |
| 379 // Rappor metrics | |
| 380 RapporSampleAssert( | |
| 381 "Event.Latency.ScrollUpdate.Touch." | |
| 382 "TimeToScrollUpdateSwapBegin2", 0); | |
| 383 RapporSampleAssert( | |
| 384 "Event.Latency.ScrollBegin.Touch." | |
| 385 "TimeToScrollUpdateSwapBegin2", 2); | |
| 386 RapporSampleAssert( | |
| 387 "Event.Latency.ScrollBegin.Wheel." | |
| 388 "TimeToScrollUpdateSwapBegin2", 0); | |
| 389 | |
| 390 // UMA histograms | |
| 341 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.TouchUI", 1)); | 391 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.TouchUI", 1)); |
| 342 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.TouchAcked", 1)); | 392 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.TouchAcked", 1)); |
| 343 EXPECT_TRUE(HistogramSizeEq( | 393 EXPECT_TRUE(HistogramSizeEq( |
| 344 "Event.Latency.TouchToFirstScrollUpdateSwapBegin", 1)); | 394 "Event.Latency.TouchToFirstScrollUpdateSwapBegin", 1)); |
| 345 EXPECT_TRUE( | 395 EXPECT_TRUE( |
| 346 HistogramSizeEq("Event.Latency.TouchToFirstScrollUpdateSwapBegin_" | 396 HistogramSizeEq("Event.Latency.TouchToFirstScrollUpdateSwapBegin_" |
| 347 "IsRunningNavigationHintTask", | 397 "IsRunningNavigationHintTask", |
| 348 is_running_navigation_hint_task ? 1 : 0)); | 398 is_running_navigation_hint_task ? 1 : 0)); |
| 349 EXPECT_TRUE( | 399 EXPECT_TRUE( |
| 350 HistogramSizeEq("Event.Latency.TouchToScrollUpdateSwapBegin", 1)); | 400 HistogramSizeEq("Event.Latency.TouchToScrollUpdateSwapBegin", 1)); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 EXPECT_TRUE(touch_latency.FindLatency( | 516 EXPECT_TRUE(touch_latency.FindLatency( |
| 467 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, nullptr)); | 517 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, nullptr)); |
| 468 EXPECT_EQ(2U, touch_latency.input_coordinates_size()); | 518 EXPECT_EQ(2U, touch_latency.input_coordinates_size()); |
| 469 tracker()->OnInputEventAck(touch, &touch_latency, | 519 tracker()->OnInputEventAck(touch, &touch_latency, |
| 470 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 520 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 471 tracker()->OnFrameSwapped(touch_latency, | 521 tracker()->OnFrameSwapped(touch_latency, |
| 472 is_running_navigation_hint_task); | 522 is_running_navigation_hint_task); |
| 473 } | 523 } |
| 474 | 524 |
| 475 // Rappor metrics | 525 // Rappor metrics |
| 476 rappor::TestSample::Shadow* sample_obj = | 526 RapporSampleAssert( |
| 477 test_browser_client_.getTestRapporService() | 527 "Event.Latency.ScrollUpdate.Touch." |
| 478 ->GetRecordedSampleForMetric( | 528 "TimeToScrollUpdateSwapBegin2", 2); |
| 479 "Event.Latency.ScrollUpdate.Touch." | 529 RapporSampleAssert( |
| 480 "TimeToScrollUpdateSwapBegin2"); | 530 "Event.Latency.ScrollBegin.Touch." |
| 481 EXPECT_NE(nullptr, sample_obj); | 531 "TimeToScrollUpdateSwapBegin2", 0); |
| 482 const auto& domain_it = sample_obj->string_fields.find("Domain"); | 532 RapporSampleAssert( |
| 483 EXPECT_NE(domain_it, sample_obj->string_fields.end()); | 533 "Event.Latency.ScrollBegin.Wheel." |
| 484 EXPECT_EQ("bar.com", domain_it->second); | 534 "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 | 535 |
| 492 // UMA histograms | 536 // UMA histograms |
| 493 EXPECT_TRUE(HistogramSizeEq( | 537 EXPECT_TRUE(HistogramSizeEq( |
| 494 "Event.Latency.ScrollBegin.Touch.TimeToScrollUpdateSwapBegin2", 0)); | 538 "Event.Latency.ScrollBegin.Touch.TimeToScrollUpdateSwapBegin2", 0)); |
| 495 EXPECT_TRUE(HistogramSizeEq( | 539 EXPECT_TRUE(HistogramSizeEq( |
| 496 "Event.Latency.ScrollUpdate.Touch.TimeToScrollUpdateSwapBegin2", 1)); | 540 "Event.Latency.ScrollUpdate.Touch.TimeToScrollUpdateSwapBegin2", 1)); |
| 497 EXPECT_TRUE(HistogramSizeEq( | 541 EXPECT_TRUE(HistogramSizeEq( |
| 498 "Event.Latency.ScrollBegin.Touch.TimeToHandled2_Main", 0)); | 542 "Event.Latency.ScrollBegin.Touch.TimeToHandled2_Main", 0)); |
| 499 EXPECT_TRUE(HistogramSizeEq( | 543 EXPECT_TRUE(HistogramSizeEq( |
| 500 "Event.Latency.ScrollBegin.Touch.TimeToHandled2_Impl", 0)); | 544 "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"), | 965 "Event.Latency.BlockingTime.TouchEndDefaultPrevented"), |
| 922 ElementsAre(Bucket( | 966 ElementsAre(Bucket( |
| 923 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1))); | 967 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1))); |
| 924 EXPECT_THAT(histogram_tester().GetAllSamples( | 968 EXPECT_THAT(histogram_tester().GetAllSamples( |
| 925 "Event.Latency.BlockingTime.TouchEndDefaultAllowed"), | 969 "Event.Latency.BlockingTime.TouchEndDefaultAllowed"), |
| 926 ElementsAre(Bucket( | 970 ElementsAre(Bucket( |
| 927 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1))); | 971 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1))); |
| 928 } | 972 } |
| 929 | 973 |
| 930 } // namespace content | 974 } // namespace content |
| OLD | NEW |