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

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: creis's review, rebase 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:
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 418
416 VerifyAndRunQueues(true, true); 419 VerifyAndRunQueues(true, true);
417 420
418 // Only the most recent ack was called. 421 // Only the most recent ack was called.
419 EXPECT_FALSE(test_callback1->called()); 422 EXPECT_FALSE(test_callback1->called());
420 EXPECT_TRUE(test_callback2->called()); 423 EXPECT_TRUE(test_callback2->called());
421 EXPECT_EQ(EventResult::HANDLED, test_callback2->result()); 424 EXPECT_EQ(EventResult::HANDLED, test_callback2->result());
422 } 425 }
423 426
424 // Tests that when an input handler consumes the event, that 427 // Tests that when an input handler consumes the event, that
425 // CompositorMusConnection does not consume the ack, nor calls it. 428 // CompositorMusConnection will consume the ack, but call as UNHANDLED.
426 TEST_F(CompositorMusConnectionTest, InputHandlerConsumes) { 429 TEST_F(CompositorMusConnectionTest, InputHandlerConsumes) {
427 input_handler_manager()->SetHandleInputEventResult( 430 input_handler_manager()->SetHandleInputEventResult(
428 InputEventAckState::INPUT_EVENT_ACK_STATE_CONSUMED); 431 InputEventAckState::INPUT_EVENT_ACK_STATE_CONSUMED);
429 ui::TestWindow test_window; 432 ui::TestWindow test_window;
430 std::unique_ptr<ui::Event> event(GenerateKeyEvent()); 433 std::unique_ptr<ui::Event> event(GenerateKeyEvent());
431 scoped_refptr<TestCallback> test_callback(new TestCallback); 434 scoped_refptr<TestCallback> test_callback(new TestCallback);
432 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback( 435 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback(
433 new base::Callback<void(EventResult)>( 436 new base::Callback<void(EventResult)>(
434 base::Bind(&::TestCallback::ResultCallback, test_callback))); 437 base::Bind(&::TestCallback::ResultCallback, test_callback)));
435 438
436 OnWindowInputEvent(&test_window, *event.get(), &ack_callback); 439 OnWindowInputEvent(&test_window, *event.get(), &ack_callback);
437 440
438 EXPECT_TRUE(ack_callback.get()); 441 EXPECT_FALSE(ack_callback.get());
439 VerifyAndRunQueues(false, false); 442 VerifyAndRunQueues(false, false);
440 EXPECT_FALSE(test_callback->called()); 443 EXPECT_TRUE(test_callback->called());
444 EXPECT_EQ(EventResult::UNHANDLED, test_callback->result());
441 } 445 }
442 446
443 // Tests that when the renderer will not ack an event, that 447 // Tests that when the renderer will not ack an event, that
444 // CompositorMusConnection does not consume the ack, nor calls it. 448 // CompositorMusConnection will consume the ack, but call as UNHANDLED.
445 TEST_F(CompositorMusConnectionTest, RendererWillNotSendAck) { 449 TEST_F(CompositorMusConnectionTest, RendererWillNotSendAck) {
446 ui::TestWindow test_window; 450 ui::TestWindow test_window;
447 ui::PointerEvent event( 451 ui::PointerEvent event(
448 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), ui::EF_NONE, 0, 0, 452 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), ui::EF_NONE, 0, 0,
449 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE), 453 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE),
450 ui::EventTimeForNow()); 454 ui::EventTimeForNow());
451 455
452 scoped_refptr<TestCallback> test_callback(new TestCallback); 456 scoped_refptr<TestCallback> test_callback(new TestCallback);
453 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback( 457 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback(
454 new base::Callback<void(EventResult)>( 458 new base::Callback<void(EventResult)>(
455 base::Bind(&::TestCallback::ResultCallback, test_callback))); 459 base::Bind(&::TestCallback::ResultCallback, test_callback)));
456 460
457 OnWindowInputEvent(&test_window, event, &ack_callback); 461 OnWindowInputEvent(&test_window, event, &ack_callback);
458 EXPECT_TRUE(ack_callback.get()); 462 EXPECT_FALSE(ack_callback.get());
459 463
460 VerifyAndRunQueues(true, false); 464 VerifyAndRunQueues(true, false);
461 EXPECT_FALSE(test_callback->called()); 465 EXPECT_TRUE(test_callback->called());
466 EXPECT_EQ(EventResult::UNHANDLED, test_callback->result());
462 } 467 }
463 468
464 // Tests that when a touch event id provided, that CompositorMusConnection 469 // Tests that when a touch event id provided, that CompositorMusConnection
465 // consumes the ack. 470 // consumes the ack.
466 TEST_F(CompositorMusConnectionTest, TouchEventConsumed) { 471 TEST_F(CompositorMusConnectionTest, TouchEventConsumed) {
467 TestRenderWidgetInputHandler* input_handler = render_widget_input_handler(); 472 TestRenderWidgetInputHandler* input_handler = render_widget_input_handler();
468 input_handler->set_delegate(connection()); 473 input_handler->set_delegate(connection());
469 input_handler->set_state(InputEventAckState::INPUT_EVENT_ACK_STATE_CONSUMED); 474 input_handler->set_state(InputEventAckState::INPUT_EVENT_ACK_STATE_CONSUMED);
470 475
471 ui::TestWindow test_window; 476 ui::TestWindow test_window;
(...skipping 13 matching lines...) Expand all
485 EXPECT_FALSE(ack_callback.get()); 490 EXPECT_FALSE(ack_callback.get());
486 491
487 VerifyAndRunQueues(true, true); 492 VerifyAndRunQueues(true, true);
488 493
489 // The ack callback should have been called 494 // The ack callback should have been called
490 EXPECT_TRUE(test_callback->called()); 495 EXPECT_TRUE(test_callback->called());
491 EXPECT_EQ(EventResult::HANDLED, test_callback->result()); 496 EXPECT_EQ(EventResult::HANDLED, test_callback->result());
492 } 497 }
493 498
494 } // namespace content 499 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/mus/compositor_mus_connection.cc ('k') | content/renderer/mus/render_widget_mus_connection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698