| 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 ::testing::AssertionResult RapporSampleAssert(const char* rappor_name, |
| 95 int count) { |
| 96 rappor::TestSample::Shadow* sample_obj = |
| 97 test_browser_client_.getTestRapporService()->GetRecordedSampleForMetric( |
| 98 rappor_name); |
| 99 if (count) { |
| 100 if (!sample_obj) |
| 101 return ::testing::AssertionFailure() |
| 102 << rappor_name << " rappor sample should not be null"; |
| 103 |
| 104 const auto& domain_it = sample_obj->string_fields.find("Domain"); |
| 105 if (domain_it == sample_obj->string_fields.end()) |
| 106 return ::testing::AssertionFailure() |
| 107 << rappor_name << " rappor sample should contain the string " |
| 108 "attribute \"Domain\""; |
| 109 const auto& domain = domain_it->second; |
| 110 if (domain != "bar.com") |
| 111 return ::testing::AssertionFailure() |
| 112 << rappor_name << " rappor expected bar.com domain but had " |
| 113 << domain << " domain"; |
| 114 |
| 115 const auto& latency_it = sample_obj->uint64_fields.find("Latency"); |
| 116 if (latency_it == sample_obj->uint64_fields.end()) |
| 117 return ::testing::AssertionFailure() |
| 118 << rappor_name << " rappor sample should contain the uint64 " |
| 119 "attribute \"Latency\""; |
| 120 const auto& latency_noise = latency_it->second.second; |
| 121 if (latency_noise != rappor::NO_NOISE) |
| 122 return ::testing::AssertionFailure() |
| 123 << rappor_name |
| 124 << " rappor expected rappor::NO_NOISE latency but had " |
| 125 << latency_noise << " latency"; |
| 126 |
| 127 return ::testing::AssertionSuccess(); |
| 128 } else { |
| 129 if (!sample_obj) |
| 130 return ::testing::AssertionSuccess(); |
| 131 else |
| 132 return ::testing::AssertionFailure() << rappor_name |
| 133 << " rappor sample should be null"; |
| 134 } |
| 135 } |
| 136 |
| 94 ::testing::AssertionResult HistogramSizeEq(const char* histogram_name, | 137 ::testing::AssertionResult HistogramSizeEq(const char* histogram_name, |
| 95 int size) { | 138 int size) { |
| 96 uint64_t histogram_size = | 139 uint64_t histogram_size = |
| 97 histogram_tester_->GetAllSamples(histogram_name).size(); | 140 histogram_tester_->GetAllSamples(histogram_name).size(); |
| 98 if (static_cast<uint64_t>(size) == histogram_size) { | 141 if (static_cast<uint64_t>(size) == histogram_size) { |
| 99 return ::testing::AssertionSuccess(); | 142 return ::testing::AssertionSuccess(); |
| 100 } else { | 143 } else { |
| 101 return ::testing::AssertionFailure() << histogram_name << " expected " | 144 return ::testing::AssertionFailure() << histogram_name << " expected " |
| 102 << size << " entries, but had " | 145 << size << " entries, but had " |
| 103 << histogram_size; | 146 << histogram_size; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 128 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostLatencyTrackerTest); | 171 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostLatencyTrackerTest); |
| 129 const int kTestRoutingId = 3; | 172 const int kTestRoutingId = 3; |
| 130 const int kTestProcessId = 1; | 173 const int kTestProcessId = 1; |
| 131 std::unique_ptr<base::HistogramTester> histogram_tester_; | 174 std::unique_ptr<base::HistogramTester> histogram_tester_; |
| 132 RenderWidgetHostLatencyTracker tracker_; | 175 RenderWidgetHostLatencyTracker tracker_; |
| 133 RenderWidgetHostLatencyTrackerTestBrowserClient test_browser_client_; | 176 RenderWidgetHostLatencyTrackerTestBrowserClient test_browser_client_; |
| 134 ContentBrowserClient* old_browser_client_; | 177 ContentBrowserClient* old_browser_client_; |
| 135 }; | 178 }; |
| 136 | 179 |
| 137 TEST_F(RenderWidgetHostLatencyTrackerTest, TestWheelToFirstScrollHistograms) { | 180 TEST_F(RenderWidgetHostLatencyTrackerTest, TestWheelToFirstScrollHistograms) { |
| 181 const GURL url("http://www.foo.bar.com/subpage/1"); |
| 182 contents()->NavigateAndCommit(url); |
| 138 for (bool rendering_on_main : {false, true}) { | 183 for (bool rendering_on_main : {false, true}) { |
| 139 for (bool is_running_navigation_hint_task : {false, true}) { | 184 for (bool is_running_navigation_hint_task : {false, true}) { |
| 140 ResetHistograms(); | 185 ResetHistograms(); |
| 141 { | 186 { |
| 142 auto wheel = SyntheticWebMouseWheelEventBuilder::Build( | 187 auto wheel = SyntheticWebMouseWheelEventBuilder::Build( |
| 143 blink::WebMouseWheelEvent::PhaseChanged); | 188 blink::WebMouseWheelEvent::PhaseChanged); |
| 144 base::TimeTicks now = base::TimeTicks::Now(); | 189 base::TimeTicks now = base::TimeTicks::Now(); |
| 145 wheel.timeStampSeconds = (now - base::TimeTicks()).InSecondsF(); | 190 wheel.timeStampSeconds = (now - base::TimeTicks()).InSecondsF(); |
| 146 ui::LatencyInfo wheel_latency(ui::SourceEventType::WHEEL); | 191 ui::LatencyInfo wheel_latency(ui::SourceEventType::WHEEL); |
| 147 wheel_latency.AddLatencyNumberWithTimestamp( | 192 wheel_latency.AddLatencyNumberWithTimestamp( |
| 148 ui::INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT, | 193 ui::INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT, |
| 149 tracker()->latency_component_id(), 0, now, 1); | 194 tracker()->latency_component_id(), 0, now, 1); |
| 150 AddFakeComponentsWithTimeStamp(*tracker(), &wheel_latency, now); | 195 AddFakeComponentsWithTimeStamp(*tracker(), &wheel_latency, now); |
| 151 AddRenderingScheduledComponent(&wheel_latency, rendering_on_main, now); | 196 AddRenderingScheduledComponent(&wheel_latency, rendering_on_main, now); |
| 152 tracker()->OnInputEvent(wheel, &wheel_latency); | 197 tracker()->OnInputEvent(wheel, &wheel_latency); |
| 153 EXPECT_TRUE(wheel_latency.FindLatency( | 198 EXPECT_TRUE(wheel_latency.FindLatency( |
| 154 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, | 199 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, |
| 155 tracker()->latency_component_id(), nullptr)); | 200 tracker()->latency_component_id(), nullptr)); |
| 156 EXPECT_TRUE(wheel_latency.FindLatency( | 201 EXPECT_TRUE(wheel_latency.FindLatency( |
| 157 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, nullptr)); | 202 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, nullptr)); |
| 158 EXPECT_EQ(1U, wheel_latency.input_coordinates_size()); | 203 EXPECT_EQ(1U, wheel_latency.input_coordinates_size()); |
| 159 tracker()->OnInputEventAck(wheel, &wheel_latency, | 204 tracker()->OnInputEventAck(wheel, &wheel_latency, |
| 160 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 205 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 161 tracker()->OnFrameSwapped(wheel_latency, | 206 tracker()->OnFrameSwapped(wheel_latency, |
| 162 is_running_navigation_hint_task); | 207 is_running_navigation_hint_task); |
| 208 |
| 209 // Rappor metrics. |
| 210 EXPECT_TRUE( |
| 211 RapporSampleAssert("Event.Latency.ScrollUpdate.Touch." |
| 212 "TimeToScrollUpdateSwapBegin2", |
| 213 0)); |
| 214 EXPECT_TRUE( |
| 215 RapporSampleAssert("Event.Latency.ScrollBegin.Touch." |
| 216 "TimeToScrollUpdateSwapBegin2", |
| 217 0)); |
| 218 EXPECT_TRUE( |
| 219 RapporSampleAssert("Event.Latency.ScrollBegin.Wheel." |
| 220 "TimeToScrollUpdateSwapBegin2", |
| 221 2)); |
| 222 EXPECT_EQ( |
| 223 2, test_browser_client_.getTestRapporService()->GetReportsCount()); |
| 224 |
| 225 // UMA histograms. |
| 163 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.WheelUI", 1)); | 226 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.WheelUI", 1)); |
| 164 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.WheelAcked", 1)); | 227 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.WheelAcked", 1)); |
| 165 | 228 |
| 166 EXPECT_TRUE( | 229 EXPECT_TRUE( |
| 167 HistogramSizeEq("Event.Latency.ScrollBegin.Wheel." | 230 HistogramSizeEq("Event.Latency.ScrollBegin.Wheel." |
| 168 "TimeToScrollUpdateSwapBegin2", | 231 "TimeToScrollUpdateSwapBegin2", |
| 169 1)); | 232 1)); |
| 170 EXPECT_TRUE(HistogramSizeEq( | 233 EXPECT_TRUE(HistogramSizeEq( |
| 171 "Event.Latency.ScrollBegin.Wheel.TimeToHandled2_Main", | 234 "Event.Latency.ScrollBegin.Wheel.TimeToHandled2_Main", |
| 172 rendering_on_main ? 1 : 0)); | 235 rendering_on_main ? 1 : 0)); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 "Event.Latency.ScrollUpdate.Wheel.BrowserNotifiedToBeforeGpuSwap2", | 345 "Event.Latency.ScrollUpdate.Wheel.BrowserNotifiedToBeforeGpuSwap2", |
| 283 1)); | 346 1)); |
| 284 EXPECT_TRUE( | 347 EXPECT_TRUE( |
| 285 HistogramSizeEq("Event.Latency.ScrollUpdate.Wheel.GpuSwap2", 1)); | 348 HistogramSizeEq("Event.Latency.ScrollUpdate.Wheel.GpuSwap2", 1)); |
| 286 } | 349 } |
| 287 } | 350 } |
| 288 } | 351 } |
| 289 } | 352 } |
| 290 | 353 |
| 291 TEST_F(RenderWidgetHostLatencyTrackerTest, TestTouchToFirstScrollHistograms) { | 354 TEST_F(RenderWidgetHostLatencyTrackerTest, TestTouchToFirstScrollHistograms) { |
| 355 const GURL url("http://www.foo.bar.com/subpage/1"); |
| 356 contents()->NavigateAndCommit(url); |
| 292 for (bool rendering_on_main : {false, true}) { | 357 for (bool rendering_on_main : {false, true}) { |
| 293 for (bool is_running_navigation_hint_task : {false, true}) { | 358 for (bool is_running_navigation_hint_task : {false, true}) { |
| 294 ResetHistograms(); | 359 ResetHistograms(); |
| 295 { | 360 { |
| 296 auto scroll = SyntheticWebGestureEventBuilder::BuildScrollUpdate( | 361 auto scroll = SyntheticWebGestureEventBuilder::BuildScrollUpdate( |
| 297 5.f, -5.f, 0, blink::WebGestureDeviceTouchscreen); | 362 5.f, -5.f, 0, blink::WebGestureDeviceTouchscreen); |
| 298 base::TimeTicks now = base::TimeTicks::Now(); | 363 base::TimeTicks now = base::TimeTicks::Now(); |
| 299 scroll.timeStampSeconds = (now - base::TimeTicks()).InSecondsF(); | 364 scroll.timeStampSeconds = (now - base::TimeTicks()).InSecondsF(); |
| 300 ui::LatencyInfo scroll_latency; | 365 ui::LatencyInfo scroll_latency; |
| 301 scroll_latency.AddLatencyNumberWithTimestamp( | 366 scroll_latency.AddLatencyNumberWithTimestamp( |
| (...skipping 29 matching lines...) Expand all Loading... |
| 331 tracker()->latency_component_id(), nullptr)); | 396 tracker()->latency_component_id(), nullptr)); |
| 332 EXPECT_TRUE(touch_latency.FindLatency( | 397 EXPECT_TRUE(touch_latency.FindLatency( |
| 333 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, nullptr)); | 398 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, nullptr)); |
| 334 EXPECT_EQ(2U, touch_latency.input_coordinates_size()); | 399 EXPECT_EQ(2U, touch_latency.input_coordinates_size()); |
| 335 tracker()->OnInputEventAck(touch, &touch_latency, | 400 tracker()->OnInputEventAck(touch, &touch_latency, |
| 336 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 401 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 337 tracker()->OnFrameSwapped(touch_latency, | 402 tracker()->OnFrameSwapped(touch_latency, |
| 338 is_running_navigation_hint_task); | 403 is_running_navigation_hint_task); |
| 339 } | 404 } |
| 340 | 405 |
| 406 // Rappor metrics. |
| 407 EXPECT_TRUE( |
| 408 RapporSampleAssert("Event.Latency.ScrollUpdate.Touch." |
| 409 "TimeToScrollUpdateSwapBegin2", |
| 410 0)); |
| 411 EXPECT_TRUE( |
| 412 RapporSampleAssert("Event.Latency.ScrollBegin.Touch." |
| 413 "TimeToScrollUpdateSwapBegin2", |
| 414 2)); |
| 415 EXPECT_TRUE( |
| 416 RapporSampleAssert("Event.Latency.ScrollBegin.Wheel." |
| 417 "TimeToScrollUpdateSwapBegin2", |
| 418 0)); |
| 419 EXPECT_EQ(2, |
| 420 test_browser_client_.getTestRapporService()->GetReportsCount()); |
| 421 |
| 422 // UMA histograms. |
| 341 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.TouchUI", 1)); | 423 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.TouchUI", 1)); |
| 342 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.TouchAcked", 1)); | 424 EXPECT_TRUE(HistogramSizeEq("Event.Latency.Browser.TouchAcked", 1)); |
| 343 EXPECT_TRUE(HistogramSizeEq( | 425 EXPECT_TRUE(HistogramSizeEq( |
| 344 "Event.Latency.TouchToFirstScrollUpdateSwapBegin", 1)); | 426 "Event.Latency.TouchToFirstScrollUpdateSwapBegin", 1)); |
| 345 EXPECT_TRUE( | 427 EXPECT_TRUE( |
| 346 HistogramSizeEq("Event.Latency.TouchToFirstScrollUpdateSwapBegin_" | 428 HistogramSizeEq("Event.Latency.TouchToFirstScrollUpdateSwapBegin_" |
| 347 "IsRunningNavigationHintTask", | 429 "IsRunningNavigationHintTask", |
| 348 is_running_navigation_hint_task ? 1 : 0)); | 430 is_running_navigation_hint_task ? 1 : 0)); |
| 349 EXPECT_TRUE( | 431 EXPECT_TRUE( |
| 350 HistogramSizeEq("Event.Latency.TouchToScrollUpdateSwapBegin", 1)); | 432 HistogramSizeEq("Event.Latency.TouchToScrollUpdateSwapBegin", 1)); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 tracker()->latency_component_id(), nullptr)); | 547 tracker()->latency_component_id(), nullptr)); |
| 466 EXPECT_TRUE(touch_latency.FindLatency( | 548 EXPECT_TRUE(touch_latency.FindLatency( |
| 467 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, nullptr)); | 549 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, nullptr)); |
| 468 EXPECT_EQ(2U, touch_latency.input_coordinates_size()); | 550 EXPECT_EQ(2U, touch_latency.input_coordinates_size()); |
| 469 tracker()->OnInputEventAck(touch, &touch_latency, | 551 tracker()->OnInputEventAck(touch, &touch_latency, |
| 470 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 552 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 471 tracker()->OnFrameSwapped(touch_latency, | 553 tracker()->OnFrameSwapped(touch_latency, |
| 472 is_running_navigation_hint_task); | 554 is_running_navigation_hint_task); |
| 473 } | 555 } |
| 474 | 556 |
| 475 // Rappor metrics | 557 // Rappor metrics. |
| 476 rappor::TestSample::Shadow* sample_obj = | 558 EXPECT_TRUE( |
| 477 test_browser_client_.getTestRapporService() | 559 RapporSampleAssert("Event.Latency.ScrollUpdate.Touch." |
| 478 ->GetRecordedSampleForMetric( | 560 "TimeToScrollUpdateSwapBegin2", |
| 479 "Event.Latency.ScrollUpdate.Touch." | 561 2)); |
| 480 "TimeToScrollUpdateSwapBegin2"); | 562 EXPECT_TRUE( |
| 481 EXPECT_NE(nullptr, sample_obj); | 563 RapporSampleAssert("Event.Latency.ScrollBegin.Touch." |
| 482 const auto& domain_it = sample_obj->string_fields.find("Domain"); | 564 "TimeToScrollUpdateSwapBegin2", |
| 483 EXPECT_NE(domain_it, sample_obj->string_fields.end()); | 565 0)); |
| 484 EXPECT_EQ("bar.com", domain_it->second); | 566 EXPECT_TRUE( |
| 485 const auto& latency_it = sample_obj->uint64_fields.find("Latency"); | 567 RapporSampleAssert("Event.Latency.ScrollBegin.Wheel." |
| 486 EXPECT_NE(latency_it, sample_obj->uint64_fields.end()); | 568 "TimeToScrollUpdateSwapBegin2", |
| 487 EXPECT_EQ(rappor::NO_NOISE, latency_it->second.second); | 569 0)); |
| 488 | |
| 489 EXPECT_EQ(2, | 570 EXPECT_EQ(2, |
| 490 test_browser_client_.getTestRapporService()->GetReportsCount()); | 571 test_browser_client_.getTestRapporService()->GetReportsCount()); |
| 491 | 572 |
| 492 // UMA histograms | 573 // UMA histograms. |
| 493 EXPECT_TRUE(HistogramSizeEq( | 574 EXPECT_TRUE(HistogramSizeEq( |
| 494 "Event.Latency.ScrollBegin.Touch.TimeToScrollUpdateSwapBegin2", 0)); | 575 "Event.Latency.ScrollBegin.Touch.TimeToScrollUpdateSwapBegin2", 0)); |
| 495 EXPECT_TRUE(HistogramSizeEq( | 576 EXPECT_TRUE(HistogramSizeEq( |
| 496 "Event.Latency.ScrollUpdate.Touch.TimeToScrollUpdateSwapBegin2", 1)); | 577 "Event.Latency.ScrollUpdate.Touch.TimeToScrollUpdateSwapBegin2", 1)); |
| 497 EXPECT_TRUE(HistogramSizeEq( | 578 EXPECT_TRUE(HistogramSizeEq( |
| 498 "Event.Latency.ScrollBegin.Touch.TimeToHandled2_Main", 0)); | 579 "Event.Latency.ScrollBegin.Touch.TimeToHandled2_Main", 0)); |
| 499 EXPECT_TRUE(HistogramSizeEq( | 580 EXPECT_TRUE(HistogramSizeEq( |
| 500 "Event.Latency.ScrollBegin.Touch.TimeToHandled2_Impl", 0)); | 581 "Event.Latency.ScrollBegin.Touch.TimeToHandled2_Impl", 0)); |
| 501 EXPECT_TRUE(HistogramSizeEq( | 582 EXPECT_TRUE(HistogramSizeEq( |
| 502 "Event.Latency.ScrollBegin.Touch.HandledToRendererSwap2_Main", 0)); | 583 "Event.Latency.ScrollBegin.Touch.HandledToRendererSwap2_Main", 0)); |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 921 "Event.Latency.BlockingTime.TouchEndDefaultPrevented"), | 1002 "Event.Latency.BlockingTime.TouchEndDefaultPrevented"), |
| 922 ElementsAre(Bucket( | 1003 ElementsAre(Bucket( |
| 923 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1))); | 1004 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1))); |
| 924 EXPECT_THAT(histogram_tester().GetAllSamples( | 1005 EXPECT_THAT(histogram_tester().GetAllSamples( |
| 925 "Event.Latency.BlockingTime.TouchEndDefaultAllowed"), | 1006 "Event.Latency.BlockingTime.TouchEndDefaultAllowed"), |
| 926 ElementsAre(Bucket( | 1007 ElementsAre(Bucket( |
| 927 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1))); | 1008 touchend_timestamps_ms[2] - touchend_timestamps_ms[1], 1))); |
| 928 } | 1009 } |
| 929 | 1010 |
| 930 } // namespace content | 1011 } // namespace content |
| OLD | NEW |