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

Side by Side Diff: ui/events/blink/input_handler_proxy_unittest.cc

Issue 2695603004: [VSync Queue] Add tracing for event queuing time and coalesced count (Closed)
Patch Set: Add comments for nestable tracing and |first_original_event()| Created 3 years, 10 months 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
« no previous file with comments | « ui/events/blink/event_with_callback.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ui/events/blink/input_handler_proxy.h" 5 #include "ui/events/blink/input_handler_proxy.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/memory/ref_counted_memory.h"
13 #include "base/run_loop.h"
12 #include "base/test/histogram_tester.h" 14 #include "base/test/histogram_tester.h"
13 #include "base/test/scoped_feature_list.h" 15 #include "base/test/scoped_feature_list.h"
14 #include "base/test/simple_test_tick_clock.h" 16 #include "base/test/simple_test_tick_clock.h"
17 #include "base/test/trace_event_analyzer.h"
18 #include "base/trace_event/trace_buffer.h"
15 #include "cc/input/main_thread_scrolling_reason.h" 19 #include "cc/input/main_thread_scrolling_reason.h"
16 #include "cc/trees/swap_promise_monitor.h" 20 #include "cc/trees/swap_promise_monitor.h"
17 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
19 #include "third_party/WebKit/public/platform/WebFloatPoint.h" 23 #include "third_party/WebKit/public/platform/WebFloatPoint.h"
20 #include "third_party/WebKit/public/platform/WebFloatSize.h" 24 #include "third_party/WebKit/public/platform/WebFloatSize.h"
21 #include "third_party/WebKit/public/platform/WebGestureCurve.h" 25 #include "third_party/WebKit/public/platform/WebGestureCurve.h"
22 #include "third_party/WebKit/public/platform/WebInputEvent.h" 26 #include "third_party/WebKit/public/platform/WebInputEvent.h"
23 #include "third_party/WebKit/public/platform/WebKeyboardEvent.h" 27 #include "third_party/WebKit/public/platform/WebKeyboardEvent.h"
24 #include "third_party/WebKit/public/platform/WebMouseWheelEvent.h" 28 #include "third_party/WebKit/public/platform/WebMouseWheelEvent.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 if (type == WebInputEvent::GestureScrollUpdate) { 136 if (type == WebInputEvent::GestureScrollUpdate) {
133 gesture.data.scrollUpdate.deltaY = deltaYOrScale; 137 gesture.data.scrollUpdate.deltaY = deltaYOrScale;
134 } else if (type == WebInputEvent::GesturePinchUpdate) { 138 } else if (type == WebInputEvent::GesturePinchUpdate) {
135 gesture.data.pinchUpdate.scale = deltaYOrScale; 139 gesture.data.pinchUpdate.scale = deltaYOrScale;
136 gesture.x = x; 140 gesture.x = x;
137 gesture.y = y; 141 gesture.y = y;
138 } 142 }
139 return WebInputEventTraits::Clone(gesture); 143 return WebInputEventTraits::Clone(gesture);
140 } 144 }
141 145
146 void OnTraceDataCollected(base::Closure quit_closure,
147 base::trace_event::TraceResultBuffer* buffer,
148 const scoped_refptr<base::RefCountedString>& json,
149 bool has_more_events) {
150 buffer->AddFragment(json->data());
151 if (!has_more_events)
152 quit_closure.Run();
153 }
154
142 class MockInputHandler : public cc::InputHandler { 155 class MockInputHandler : public cc::InputHandler {
143 public: 156 public:
144 MockInputHandler() {} 157 MockInputHandler() {}
145 ~MockInputHandler() override {} 158 ~MockInputHandler() override {}
146 159
147 MOCK_METHOD0(PinchGestureBegin, void()); 160 MOCK_METHOD0(PinchGestureBegin, void());
148 MOCK_METHOD2(PinchGestureUpdate, 161 MOCK_METHOD2(PinchGestureUpdate,
149 void(float magnify_delta, const gfx::Point& anchor)); 162 void(float magnify_delta, const gfx::Point& anchor));
150 MOCK_METHOD0(PinchGestureEnd, void()); 163 MOCK_METHOD0(PinchGestureEnd, void());
151 164
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 502
490 void SetUp() override { 503 void SetUp() override {
491 event_disposition_recorder_.clear(); 504 event_disposition_recorder_.clear();
492 input_handler_proxy_ = base::MakeUnique<TestInputHandlerProxy>( 505 input_handler_proxy_ = base::MakeUnique<TestInputHandlerProxy>(
493 &mock_input_handler_, &mock_client_); 506 &mock_input_handler_, &mock_client_);
494 if (input_handler_proxy_->compositor_event_queue_) 507 if (input_handler_proxy_->compositor_event_queue_)
495 input_handler_proxy_->compositor_event_queue_ = 508 input_handler_proxy_->compositor_event_queue_ =
496 base::MakeUnique<CompositorThreadEventQueue>(); 509 base::MakeUnique<CompositorThreadEventQueue>();
497 } 510 }
498 511
512 void StartTracing() {
513 base::trace_event::TraceLog::GetInstance()->SetEnabled(
514 base::trace_event::TraceConfig("*"),
515 base::trace_event::TraceLog::RECORDING_MODE);
516 }
517
518 void StopTracing() {
519 base::trace_event::TraceLog::GetInstance()->SetDisabled();
520 }
521
522 std::unique_ptr<trace_analyzer::TraceAnalyzer> CreateTraceAnalyzer() {
523 base::trace_event::TraceResultBuffer buffer;
524 base::trace_event::TraceResultBuffer::SimpleOutput trace_output;
525 buffer.SetOutputCallback(trace_output.GetCallback());
526 base::RunLoop run_loop;
527 buffer.Start();
528 base::trace_event::TraceLog::GetInstance()->Flush(
529 base::Bind(&OnTraceDataCollected, run_loop.QuitClosure(),
530 base::Unretained(&buffer)));
531 run_loop.Run();
532 buffer.Finish();
533
534 return base::WrapUnique(
535 trace_analyzer::TraceAnalyzer::Create(trace_output.json_output));
536 }
537
499 void HandleGestureEvent(WebInputEvent::Type type, 538 void HandleGestureEvent(WebInputEvent::Type type,
500 float deltay_or_scale = 0, 539 float deltay_or_scale = 0,
501 int x = 0, 540 int x = 0,
502 int y = 0) { 541 int y = 0) {
503 LatencyInfo latency; 542 LatencyInfo latency;
504 input_handler_proxy_->HandleInputEventWithLatencyInfo( 543 input_handler_proxy_->HandleInputEventWithLatencyInfo(
505 CreateGestureScrollOrPinch(type, deltay_or_scale, x, y), latency, 544 CreateGestureScrollOrPinch(type, deltay_or_scale, x, y), latency,
506 base::Bind( 545 base::Bind(
507 &InputHandlerProxyEventQueueTest::DidHandleInputEventAndOverscroll, 546 &InputHandlerProxyEventQueueTest::DidHandleInputEventAndOverscroll,
508 weak_ptr_factory_.GetWeakPtr())); 547 weak_ptr_factory_.GetWeakPtr()));
(...skipping 16 matching lines...) Expand all
525 input_handler_proxy_->SetTickClockForTesting(std::move(tick_clock)); 564 input_handler_proxy_->SetTickClockForTesting(std::move(tick_clock));
526 } 565 }
527 566
528 protected: 567 protected:
529 base::test::ScopedFeatureList feature_list_; 568 base::test::ScopedFeatureList feature_list_;
530 testing::StrictMock<MockInputHandler> mock_input_handler_; 569 testing::StrictMock<MockInputHandler> mock_input_handler_;
531 std::unique_ptr<TestInputHandlerProxy> input_handler_proxy_; 570 std::unique_ptr<TestInputHandlerProxy> input_handler_proxy_;
532 testing::StrictMock<MockInputHandlerProxyClient> mock_client_; 571 testing::StrictMock<MockInputHandlerProxyClient> mock_client_;
533 std::vector<InputHandlerProxy::EventDisposition> event_disposition_recorder_; 572 std::vector<InputHandlerProxy::EventDisposition> event_disposition_recorder_;
534 573
574 base::MessageLoop loop_;
535 base::WeakPtrFactory<InputHandlerProxyEventQueueTest> weak_ptr_factory_; 575 base::WeakPtrFactory<InputHandlerProxyEventQueueTest> weak_ptr_factory_;
536 }; 576 };
537 577
538 TEST_P(InputHandlerProxyTest, MouseWheelNoListener) { 578 TEST_P(InputHandlerProxyTest, MouseWheelNoListener) {
539 expected_disposition_ = InputHandlerProxy::DROP_EVENT; 579 expected_disposition_ = InputHandlerProxy::DROP_EVENT;
540 EXPECT_CALL(mock_input_handler_, 580 EXPECT_CALL(mock_input_handler_,
541 GetEventListenerProperties(cc::EventListenerClass::kMouseWheel)) 581 GetEventListenerProperties(cc::EventListenerClass::kMouseWheel))
542 .WillOnce(testing::Return(cc::EventListenerProperties::kNone)); 582 .WillOnce(testing::Return(cc::EventListenerProperties::kNone));
543 583
544 WebMouseWheelEvent wheel(WebInputEvent::MouseWheel, WebInputEvent::ControlKey, 584 WebMouseWheelEvent wheel(WebInputEvent::MouseWheel, WebInputEvent::ControlKey,
(...skipping 2869 matching lines...) Expand 10 before | Expand all | Expand 10 after
3414 ToWebGestureEvent(event_queue()[4]->event()).data.scrollUpdate.deltaY); 3454 ToWebGestureEvent(event_queue()[4]->event()).data.scrollUpdate.deltaY);
3415 EXPECT_EQ(WebInputEvent::GesturePinchUpdate, 3455 EXPECT_EQ(WebInputEvent::GesturePinchUpdate,
3416 event_queue()[5]->event().type()); 3456 event_queue()[5]->event().type());
3417 EXPECT_EQ( 3457 EXPECT_EQ(
3418 0.5f, 3458 0.5f,
3419 ToWebGestureEvent(event_queue()[5]->event()).data.pinchUpdate.scale); 3459 ToWebGestureEvent(event_queue()[5]->event()).data.pinchUpdate.scale);
3420 EXPECT_EQ(WebInputEvent::GesturePinchEnd, event_queue()[6]->event().type()); 3460 EXPECT_EQ(WebInputEvent::GesturePinchEnd, event_queue()[6]->event().type());
3421 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); 3461 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
3422 } 3462 }
3423 3463
3464 TEST_F(InputHandlerProxyEventQueueTest, OriginalEventsTracing) {
3465 // Handle scroll on compositor.
3466 cc::InputHandlerScrollResult scroll_result_did_scroll_;
3467 scroll_result_did_scroll_.did_scroll = true;
3468
3469 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
3470 .WillRepeatedly(testing::Return(kImplThreadScrollState));
3471 EXPECT_CALL(mock_input_handler_, SetNeedsAnimateInput())
3472 .Times(::testing::AtLeast(1));
3473 EXPECT_CALL(
3474 mock_input_handler_,
3475 ScrollBy(testing::Property(&cc::ScrollState::delta_y, testing::Gt(0))))
3476 .WillRepeatedly(testing::Return(scroll_result_did_scroll_));
3477 EXPECT_CALL(mock_input_handler_, ScrollEnd(testing::_))
3478 .Times(::testing::AtLeast(1));
3479
3480 StartTracing();
3481 // Simulate scroll.
3482 HandleGestureEvent(WebInputEvent::GestureScrollBegin);
3483 HandleGestureEvent(WebInputEvent::GestureScrollUpdate, -20);
3484 HandleGestureEvent(WebInputEvent::GestureScrollUpdate, -40);
3485 HandleGestureEvent(WebInputEvent::GestureScrollUpdate, -10);
3486 HandleGestureEvent(WebInputEvent::GestureScrollEnd);
3487
3488 // Simulate scroll and pinch.
3489 HandleGestureEvent(WebInputEvent::GestureScrollBegin);
3490 HandleGestureEvent(WebInputEvent::GesturePinchUpdate, 10.0f, 1, 10);
3491 HandleGestureEvent(WebInputEvent::GestureScrollUpdate, -10);
3492 HandleGestureEvent(WebInputEvent::GesturePinchUpdate, 2.0f, 1, 10);
3493 HandleGestureEvent(WebInputEvent::GestureScrollUpdate, -30);
3494 HandleGestureEvent(WebInputEvent::GestureScrollEnd);
3495
3496 // Dispatch all events.
3497 input_handler_proxy_->DeliverInputForBeginFrame();
3498 StopTracing();
3499
3500 // Retrieve tracing data.
3501 std::unique_ptr<trace_analyzer::TraceAnalyzer> analyzer =
3502 CreateTraceAnalyzer();
3503 trace_analyzer::TraceEventVector begin_events;
3504 trace_analyzer::Query begin_query = trace_analyzer::Query::EventPhaseIs(
3505 TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN);
3506 analyzer->FindEvents(begin_query, &begin_events);
3507
3508 trace_analyzer::TraceEventVector end_events;
3509 trace_analyzer::Query end_query =
3510 trace_analyzer::Query::EventPhaseIs(TRACE_EVENT_PHASE_NESTABLE_ASYNC_END);
3511 analyzer->FindEvents(end_query, &end_events);
3512
3513 EXPECT_EQ(5ul, begin_events.size());
3514 EXPECT_EQ(5ul, end_events.size());
3515 EXPECT_EQ(WebInputEvent::GestureScrollUpdate,
3516 end_events[0]->GetKnownArgAsInt("type"));
3517 EXPECT_EQ(3, end_events[0]->GetKnownArgAsInt("coalesced_count"));
3518 EXPECT_EQ(WebInputEvent::GestureScrollEnd,
3519 end_events[1]->GetKnownArgAsInt("type"));
3520
3521 EXPECT_EQ(WebInputEvent::GestureScrollBegin,
3522 end_events[2]->GetKnownArgAsInt("type"));
3523 // Original scroll and pinch updates will be stored in the coalesced
3524 // PinchUpdate of the <ScrollUpdate, PinchUpdate> pair.
3525 // The ScrollUpdate of the pair doesn't carry original events and won't be
3526 // traced.
3527 EXPECT_EQ(WebInputEvent::GesturePinchUpdate,
3528 end_events[3]->GetKnownArgAsInt("type"));
3529 EXPECT_EQ(4, end_events[3]->GetKnownArgAsInt("coalesced_count"));
3530 EXPECT_EQ(WebInputEvent::GestureScrollEnd,
3531 end_events[4]->GetKnownArgAsInt("type"));
3532 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
3533 }
3534
3424 INSTANTIATE_TEST_CASE_P(AnimateInput, 3535 INSTANTIATE_TEST_CASE_P(AnimateInput,
3425 InputHandlerProxyTest, 3536 InputHandlerProxyTest,
3426 testing::ValuesIn(test_types)); 3537 testing::ValuesIn(test_types));
3427 3538
3428 } // namespace test 3539 } // namespace test
3429 } // namespace ui 3540 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/blink/event_with_callback.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698