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

Side by Side Diff: content/renderer/mus/compositor_mus_connection_unittest.cc

Issue 2265393002: Refactor compositor event handling path to be callback-based (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 3 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "content/renderer/mus/compositor_mus_connection.h" 5 #include "content/renderer/mus/compositor_mus_connection.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 result_(content::InputEventAckState::INPUT_EVENT_ACK_STATE_UNKNOWN) {} 72 result_(content::InputEventAckState::INPUT_EVENT_ACK_STATE_UNKNOWN) {}
73 ~TestInputHandlerManager() override {} 73 ~TestInputHandlerManager() override {}
74 74
75 // Stops overriding the behaviour of HandleInputEvent 75 // Stops overriding the behaviour of HandleInputEvent
76 void ClearHandleInputEventOverride(); 76 void ClearHandleInputEventOverride();
77 77
78 // Overrides the behaviour of HandleInputEvent, returing |result|. 78 // Overrides the behaviour of HandleInputEvent, returing |result|.
79 void SetHandleInputEventResult(content::InputEventAckState result); 79 void SetHandleInputEventResult(content::InputEventAckState result);
80 80
81 // content::InputHandlerManager: 81 // content::InputHandlerManager:
82 content::InputEventAckState HandleInputEvent( 82 void HandleInputEvent(int routing_id,
83 int routing_id, 83 ui::ScopedWebInputEvent input_event,
84 const blink::WebInputEvent* input_event, 84 const ui::LatencyInfo& latency_info,
85 ui::LatencyInfo* latency_info) override; 85 const InputEventAckStateCallback& callback) override;
86 86
87 private: 87 private:
88 // If true content::InputHandlerManager::HandleInputEvent is not called. 88 // If true content::InputHandlerManager::HandleInputEvent is not called.
89 bool override_result_; 89 bool override_result_;
90 90
91 // The result to return in HandleInputEvent if |override_result_|. 91 // The result to return in HandleInputEvent if |override_result_|.
92 content::InputEventAckState result_; 92 content::InputEventAckState result_;
93 93
94 DISALLOW_COPY_AND_ASSIGN(TestInputHandlerManager); 94 DISALLOW_COPY_AND_ASSIGN(TestInputHandlerManager);
95 }; 95 };
96 96
97 void TestInputHandlerManager::ClearHandleInputEventOverride() { 97 void TestInputHandlerManager::ClearHandleInputEventOverride() {
98 override_result_ = false; 98 override_result_ = false;
99 } 99 }
100 100
101 void TestInputHandlerManager::SetHandleInputEventResult( 101 void TestInputHandlerManager::SetHandleInputEventResult(
102 content::InputEventAckState result) { 102 content::InputEventAckState result) {
103 override_result_ = true; 103 override_result_ = true;
104 result_ = result; 104 result_ = result;
105 } 105 }
106 106
107 content::InputEventAckState TestInputHandlerManager::HandleInputEvent( 107 void TestInputHandlerManager::HandleInputEvent(
108 int routing_id, 108 int routing_id,
109 const blink::WebInputEvent* input_event, 109 ui::ScopedWebInputEvent input_event,
110 ui::LatencyInfo* latency_info) { 110 const ui::LatencyInfo& latency_info,
111 if (override_result_) 111 const InputEventAckStateCallback& callback) {
112 return result_; 112 if (override_result_) {
113 return content::InputHandlerManager::HandleInputEvent(routing_id, input_event, 113 callback.Run(result_, std::move(input_event), latency_info, nullptr);
114 latency_info); 114 return;
115 }
116 content::InputHandlerManager::HandleInputEvent(
117 routing_id, std::move(input_event), latency_info, callback);
115 } 118 }
116 119
117 // Empty implementation of InputHandlerManagerClient. 120 // Empty implementation of InputHandlerManagerClient.
118 class TestInputHandlerManagerClient 121 class TestInputHandlerManagerClient
119 : public content::InputHandlerManagerClient { 122 : public content::InputHandlerManagerClient {
120 public: 123 public:
121 TestInputHandlerManagerClient() {} 124 TestInputHandlerManagerClient() {}
122 ~TestInputHandlerManagerClient() override{}; 125 ~TestInputHandlerManagerClient() override{};
123 126
124 // content::InputHandlerManagerClient: 127 // content::InputHandlerManagerClient:
125 void SetBoundHandler(const Handler& handler) override {} 128 void SetBoundHandler(const Handler& handler) override {}
126 void RegisterRoutingID(int routing_id) override {} 129 void RegisterRoutingID(int routing_id) override {}
127 void UnregisterRoutingID(int routing_id) override {} 130 void UnregisterRoutingID(int routing_id) override {}
128 void DidOverscroll(int routing_id, 131 void DidOverscroll(int routing_id,
129 const ui::DidOverscrollParams& params) override {} 132 const ui::DidOverscrollParams& params,
133 bool bundle_ack_with_triggering_event) override {}
130 void DidStartFlinging(int routing_id) override {} 134 void DidStartFlinging(int routing_id) override {}
131 void DidStopFlinging(int routing_id) override {} 135 void DidStopFlinging(int routing_id) override {}
132 void NotifyInputEventHandled( 136 void NotifyInputEventHandled(
133 int routing_id, 137 int routing_id,
134 blink::WebInputEvent::Type type, 138 blink::WebInputEvent::Type type,
135 content::InputEventAckState ack_result) override {} 139 content::InputEventAckState ack_result) override {}
136 140
137 private: 141 private:
138 DISALLOW_COPY_AND_ASSIGN(TestInputHandlerManagerClient); 142 DISALLOW_COPY_AND_ASSIGN(TestInputHandlerManagerClient);
139 }; 143 };
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 417
414 VerifyAndRunQueues(true, true); 418 VerifyAndRunQueues(true, true);
415 419
416 // Only the most recent ack was called. 420 // Only the most recent ack was called.
417 EXPECT_FALSE(test_callback1->called()); 421 EXPECT_FALSE(test_callback1->called());
418 EXPECT_TRUE(test_callback2->called()); 422 EXPECT_TRUE(test_callback2->called());
419 EXPECT_EQ(EventResult::HANDLED, test_callback2->result()); 423 EXPECT_EQ(EventResult::HANDLED, test_callback2->result());
420 } 424 }
421 425
422 // Tests that when an input handler consumes the event, that 426 // Tests that when an input handler consumes the event, that
423 // CompositorMusConnection does not consume the ack, nor calls it. 427 // CompositorMusConnection will consume the ack, but call as UNHANDLED.
424 TEST_F(CompositorMusConnectionTest, InputHandlerConsumes) { 428 TEST_F(CompositorMusConnectionTest, InputHandlerConsumes) {
425 input_handler_manager()->SetHandleInputEventResult( 429 input_handler_manager()->SetHandleInputEventResult(
426 InputEventAckState::INPUT_EVENT_ACK_STATE_CONSUMED); 430 InputEventAckState::INPUT_EVENT_ACK_STATE_CONSUMED);
427 ui::TestWindow test_window; 431 ui::TestWindow test_window;
428 std::unique_ptr<ui::Event> event(GenerateKeyEvent()); 432 std::unique_ptr<ui::Event> event(GenerateKeyEvent());
429 scoped_refptr<TestCallback> test_callback(new TestCallback); 433 scoped_refptr<TestCallback> test_callback(new TestCallback);
430 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback( 434 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback(
431 new base::Callback<void(EventResult)>( 435 new base::Callback<void(EventResult)>(
432 base::Bind(&::TestCallback::ResultCallback, test_callback))); 436 base::Bind(&::TestCallback::ResultCallback, test_callback)));
433 437
434 OnWindowInputEvent(&test_window, *event.get(), &ack_callback); 438 OnWindowInputEvent(&test_window, *event.get(), &ack_callback);
435 439
436 EXPECT_TRUE(ack_callback.get()); 440 EXPECT_FALSE(ack_callback.get());
437 VerifyAndRunQueues(false, false); 441 VerifyAndRunQueues(false, false);
438 EXPECT_FALSE(test_callback->called()); 442 EXPECT_TRUE(test_callback->called());
443 EXPECT_EQ(EventResult::UNHANDLED, test_callback->result());
chongz 2016/08/23 04:35:24 Changed behavior since |CompositorMusConnection::O
439 } 444 }
440 445
441 // Tests that when the renderer will not ack an event, that 446 // Tests that when the renderer will not ack an event, that
442 // CompositorMusConnection does not consume the ack, nor calls it. 447 // CompositorMusConnection will consume the ack, but call as UNHANDLED.
443 TEST_F(CompositorMusConnectionTest, RendererWillNotSendAck) { 448 TEST_F(CompositorMusConnectionTest, RendererWillNotSendAck) {
444 ui::TestWindow test_window; 449 ui::TestWindow test_window;
445 ui::PointerEvent event( 450 ui::PointerEvent event(
446 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), ui::EF_NONE, 0, 451 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), ui::EF_NONE, 0,
447 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE), 452 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE),
448 ui::EventTimeForNow()); 453 ui::EventTimeForNow());
449 454
450 scoped_refptr<TestCallback> test_callback(new TestCallback); 455 scoped_refptr<TestCallback> test_callback(new TestCallback);
451 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback( 456 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback(
452 new base::Callback<void(EventResult)>( 457 new base::Callback<void(EventResult)>(
453 base::Bind(&::TestCallback::ResultCallback, test_callback))); 458 base::Bind(&::TestCallback::ResultCallback, test_callback)));
454 459
455 OnWindowInputEvent(&test_window, event, &ack_callback); 460 OnWindowInputEvent(&test_window, event, &ack_callback);
456 EXPECT_TRUE(ack_callback.get()); 461 EXPECT_FALSE(ack_callback.get());
457 462
458 VerifyAndRunQueues(true, false); 463 VerifyAndRunQueues(true, false);
459 EXPECT_FALSE(test_callback->called()); 464 EXPECT_TRUE(test_callback->called());
465 EXPECT_EQ(EventResult::UNHANDLED, test_callback->result());
460 } 466 }
461 467
462 // Tests that when a touch event id provided, that CompositorMusConnection 468 // Tests that when a touch event id provided, that CompositorMusConnection
463 // consumes the ack. 469 // consumes the ack.
464 TEST_F(CompositorMusConnectionTest, TouchEventConsumed) { 470 TEST_F(CompositorMusConnectionTest, TouchEventConsumed) {
465 TestRenderWidgetInputHandler* input_handler = render_widget_input_handler(); 471 TestRenderWidgetInputHandler* input_handler = render_widget_input_handler();
466 input_handler->set_delegate(connection()); 472 input_handler->set_delegate(connection());
467 input_handler->set_state(InputEventAckState::INPUT_EVENT_ACK_STATE_CONSUMED); 473 input_handler->set_state(InputEventAckState::INPUT_EVENT_ACK_STATE_CONSUMED);
468 474
469 ui::TestWindow test_window; 475 ui::TestWindow test_window;
(...skipping 13 matching lines...) Expand all
483 EXPECT_FALSE(ack_callback.get()); 489 EXPECT_FALSE(ack_callback.get());
484 490
485 VerifyAndRunQueues(true, true); 491 VerifyAndRunQueues(true, true);
486 492
487 // The ack callback should have been called 493 // The ack callback should have been called
488 EXPECT_TRUE(test_callback->called()); 494 EXPECT_TRUE(test_callback->called());
489 EXPECT_EQ(EventResult::HANDLED, test_callback->result()); 495 EXPECT_EQ(EventResult::HANDLED, test_callback->result());
490 } 496 }
491 497
492 } // namespace content 498 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698