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

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

Issue 2482453002: Don't restart the hang renderer timeout on messages ack'd from the compositor thread. (Closed)
Patch Set: Fix comments Created 4 years, 1 month 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 13 matching lines...) Expand all
24 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
25 #include "third_party/WebKit/public/platform/scheduler/test/fake_renderer_schedu ler.h" 25 #include "third_party/WebKit/public/platform/scheduler/test/fake_renderer_schedu ler.h"
26 #include "ui/events/blink/did_overscroll_params.h" 26 #include "ui/events/blink/did_overscroll_params.h"
27 #include "ui/events/event_utils.h" 27 #include "ui/events/event_utils.h"
28 #include "ui/events/mojo/event.mojom.h" 28 #include "ui/events/mojo/event.mojom.h"
29 #include "ui/events/mojo/event_constants.mojom.h" 29 #include "ui/events/mojo/event_constants.mojom.h"
30 #include "ui/events/mojo/keyboard_codes.mojom.h" 30 #include "ui/events/mojo/keyboard_codes.mojom.h"
31 31
32 using ui::mojom::EventResult; 32 using ui::mojom::EventResult;
33 33
34 namespace content {
35
34 namespace { 36 namespace {
35 37
36 // Wrapper for the callback provided to 38 // Wrapper for the callback provided to
37 // CompositorMusConnection:OnWindowInputEvent. This tracks whether the it was 39 // CompositorMusConnection:OnWindowInputEvent. This tracks whether the it was
38 // called, along with the result. 40 // called, along with the result.
39 class TestCallback : public base::RefCounted<TestCallback> { 41 class TestCallback : public base::RefCounted<TestCallback> {
40 public: 42 public:
41 TestCallback() : called_(false), result_(EventResult::UNHANDLED) {} 43 TestCallback() : called_(false), result_(EventResult::UNHANDLED) {}
42 44
43 bool called() { return called_; } 45 bool called() { return called_; }
(...skipping 10 matching lines...) Expand all
54 ~TestCallback() {} 56 ~TestCallback() {}
55 57
56 bool called_; 58 bool called_;
57 EventResult result_; 59 EventResult result_;
58 60
59 DISALLOW_COPY_AND_ASSIGN(TestCallback); 61 DISALLOW_COPY_AND_ASSIGN(TestCallback);
60 }; 62 };
61 63
62 // Allows for overriding the behaviour of HandleInputEvent, to simulate input 64 // Allows for overriding the behaviour of HandleInputEvent, to simulate input
63 // handlers which consume events before they are sent to the renderer. 65 // handlers which consume events before they are sent to the renderer.
64 class TestInputHandlerManager : public content::InputHandlerManager { 66 class TestInputHandlerManager : public InputHandlerManager {
65 public: 67 public:
66 TestInputHandlerManager( 68 TestInputHandlerManager(
67 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 69 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
68 content::InputHandlerManagerClient* client, 70 InputHandlerManagerClient* client,
69 blink::scheduler::RendererScheduler* renderer_scheduler) 71 blink::scheduler::RendererScheduler* renderer_scheduler)
70 : InputHandlerManager(task_runner, client, nullptr, renderer_scheduler), 72 : InputHandlerManager(task_runner, client, nullptr, renderer_scheduler),
71 override_result_(false), 73 override_result_(false),
72 result_(content::InputEventAckState::INPUT_EVENT_ACK_STATE_UNKNOWN) {} 74 result_(InputEventAckState::INPUT_EVENT_ACK_STATE_UNKNOWN) {}
73 ~TestInputHandlerManager() override {} 75 ~TestInputHandlerManager() override {}
74 76
75 // Stops overriding the behaviour of HandleInputEvent 77 // Stops overriding the behaviour of HandleInputEvent
76 void ClearHandleInputEventOverride(); 78 void ClearHandleInputEventOverride();
77 79
78 // Overrides the behaviour of HandleInputEvent, returing |result|. 80 // Overrides the behaviour of HandleInputEvent, returing |result|.
79 void SetHandleInputEventResult(content::InputEventAckState result); 81 void SetHandleInputEventResult(InputEventAckState result);
80 82
81 // content::InputHandlerManager: 83 // InputHandlerManager:
82 void HandleInputEvent(int routing_id, 84 void HandleInputEvent(int routing_id,
83 ui::ScopedWebInputEvent input_event, 85 ui::ScopedWebInputEvent input_event,
84 const ui::LatencyInfo& latency_info, 86 const ui::LatencyInfo& latency_info,
85 const InputEventAckStateCallback& callback) override; 87 const InputEventAckStateCallback& callback) override;
86 88
87 private: 89 private:
88 // If true content::InputHandlerManager::HandleInputEvent is not called. 90 // If true InputHandlerManager::HandleInputEvent is not called.
89 bool override_result_; 91 bool override_result_;
90 92
91 // The result to return in HandleInputEvent if |override_result_|. 93 // The result to return in HandleInputEvent if |override_result_|.
92 content::InputEventAckState result_; 94 InputEventAckState result_;
93 95
94 DISALLOW_COPY_AND_ASSIGN(TestInputHandlerManager); 96 DISALLOW_COPY_AND_ASSIGN(TestInputHandlerManager);
95 }; 97 };
96 98
97 void TestInputHandlerManager::ClearHandleInputEventOverride() { 99 void TestInputHandlerManager::ClearHandleInputEventOverride() {
98 override_result_ = false; 100 override_result_ = false;
99 } 101 }
100 102
101 void TestInputHandlerManager::SetHandleInputEventResult( 103 void TestInputHandlerManager::SetHandleInputEventResult(
102 content::InputEventAckState result) { 104 InputEventAckState result) {
103 override_result_ = true; 105 override_result_ = true;
104 result_ = result; 106 result_ = result;
105 } 107 }
106 108
107 void TestInputHandlerManager::HandleInputEvent( 109 void TestInputHandlerManager::HandleInputEvent(
108 int routing_id, 110 int routing_id,
109 ui::ScopedWebInputEvent input_event, 111 ui::ScopedWebInputEvent input_event,
110 const ui::LatencyInfo& latency_info, 112 const ui::LatencyInfo& latency_info,
111 const InputEventAckStateCallback& callback) { 113 const InputEventAckStateCallback& callback) {
112 if (override_result_) { 114 if (override_result_) {
113 callback.Run(result_, std::move(input_event), latency_info, nullptr); 115 callback.Run(result_, std::move(input_event), latency_info, nullptr);
114 return; 116 return;
115 } 117 }
116 content::InputHandlerManager::HandleInputEvent( 118 InputHandlerManager::HandleInputEvent(routing_id, std::move(input_event),
117 routing_id, std::move(input_event), latency_info, callback); 119 latency_info, callback);
118 } 120 }
119 121
120 // Empty implementation of InputHandlerManagerClient. 122 // Empty implementation of InputHandlerManagerClient.
121 class TestInputHandlerManagerClient 123 class TestInputHandlerManagerClient : public InputHandlerManagerClient {
122 : public content::InputHandlerManagerClient {
123 public: 124 public:
124 TestInputHandlerManagerClient() {} 125 TestInputHandlerManagerClient() {}
125 ~TestInputHandlerManagerClient() override{}; 126 ~TestInputHandlerManagerClient() override{};
126 127
127 // content::InputHandlerManagerClient: 128 // InputHandlerManagerClient:
128 void SetInputHandlerManager( 129 void SetInputHandlerManager(
129 content::InputHandlerManager* input_handler_manager) override {} 130 InputHandlerManager* input_handler_manager) override {}
130 void RegisterRoutingID(int routing_id) override {} 131 void RegisterRoutingID(int routing_id) override {}
131 void UnregisterRoutingID(int routing_id) override {} 132 void UnregisterRoutingID(int routing_id) override {}
132 void DidOverscroll(int routing_id, 133 void DidOverscroll(int routing_id,
133 const ui::DidOverscrollParams& params) override {} 134 const ui::DidOverscrollParams& params) override {}
134 void DidStartFlinging(int routing_id) override {} 135 void DidStartFlinging(int routing_id) override {}
135 void DidStopFlinging(int routing_id) override {} 136 void DidStopFlinging(int routing_id) override {}
136 void DispatchNonBlockingEventToMainThread( 137 void DispatchNonBlockingEventToMainThread(
137 int routing_id, 138 int routing_id,
138 ui::ScopedWebInputEvent event, 139 ui::ScopedWebInputEvent event,
139 const ui::LatencyInfo& latency_info) override {} 140 const ui::LatencyInfo& latency_info) override {}
140 141
141 void NotifyInputEventHandled( 142 void NotifyInputEventHandled(int routing_id,
142 int routing_id, 143 blink::WebInputEvent::Type type,
143 blink::WebInputEvent::Type type, 144 InputEventAckState ack_result) override {}
144 content::InputEventAckState ack_result) override {}
145 void ProcessRafAlignedInput(int routing_id) override {} 145 void ProcessRafAlignedInput(int routing_id) override {}
146 146
147 private: 147 private:
148 DISALLOW_COPY_AND_ASSIGN(TestInputHandlerManagerClient); 148 DISALLOW_COPY_AND_ASSIGN(TestInputHandlerManagerClient);
149 }; 149 };
150 150
151 // Implementation of RenderWidget for testing, performs no initialization. 151 // Implementation of RenderWidget for testing, performs no initialization.
152 class TestRenderWidget : public content::RenderWidget { 152 class TestRenderWidget : public RenderWidget {
153 public: 153 public:
154 explicit TestRenderWidget(content::CompositorDependencies* compositor_deps) 154 explicit TestRenderWidget(CompositorDependencies* compositor_deps)
155 : content::RenderWidget(compositor_deps, 155 : RenderWidget(compositor_deps,
156 blink::WebPopupTypeNone, 156 blink::WebPopupTypeNone,
157 content::ScreenInfo(), 157 ScreenInfo(),
158 true, 158 true,
159 false, 159 false,
160 false) {} 160 false) {}
161 161
162 protected: 162 protected:
163 ~TestRenderWidget() override {} 163 ~TestRenderWidget() override {}
164 164
165 private: 165 private:
166 DISALLOW_COPY_AND_ASSIGN(TestRenderWidget); 166 DISALLOW_COPY_AND_ASSIGN(TestRenderWidget);
167 }; 167 };
168 168
169 // Test override of RenderWidgetInputHandler to allow the control of 169 // Test override of RenderWidgetInputHandler to allow the control of
170 // HandleInputEvent. This will perform no actions on input until a 170 // HandleInputEvent. This will perform no actions on input until a
171 // RenderWidgetInputHandlerDelegate is set. Once set this will always ack 171 // RenderWidgetInputHandlerDelegate is set. Once set this will always ack
172 // received events. 172 // received events.
173 class TestRenderWidgetInputHandler : public content::RenderWidgetInputHandler { 173 class TestRenderWidgetInputHandler : public RenderWidgetInputHandler {
174 public: 174 public:
175 TestRenderWidgetInputHandler(content::RenderWidget* render_widget); 175 TestRenderWidgetInputHandler(RenderWidget* render_widget);
176 ~TestRenderWidgetInputHandler() override {} 176 ~TestRenderWidgetInputHandler() override {}
177 177
178 void set_delegate(content::RenderWidgetInputHandlerDelegate* delegate) { 178 void set_delegate(RenderWidgetInputHandlerDelegate* delegate) {
179 delegate_ = delegate; 179 delegate_ = delegate;
180 } 180 }
181 void set_state(content::InputEventAckState state) { state_ = state; } 181 void set_state(InputEventAckState state) { state_ = state; }
182 182
183 // content::RenderWidgetInputHandler: 183 // RenderWidgetInputHandler:
184 void HandleInputEvent(const blink::WebInputEvent& input_event, 184 void HandleInputEvent(const blink::WebInputEvent& input_event,
185 const ui::LatencyInfo& latency_info, 185 const ui::LatencyInfo& latency_info,
186 content::InputEventDispatchType dispatch_type) override; 186 InputEventDispatchType dispatch_type) override;
187 187
188 private: 188 private:
189 // The input delegate which receives event acks. 189 // The input delegate which receives event acks.
190 content::RenderWidgetInputHandlerDelegate* delegate_; 190 RenderWidgetInputHandlerDelegate* delegate_;
191 191
192 // The result of input handling to send to |delegate_| during the ack. 192 // The result of input handling to send to |delegate_| during the ack.
193 content::InputEventAckState state_; 193 InputEventAckState state_;
194 194
195 DISALLOW_COPY_AND_ASSIGN(TestRenderWidgetInputHandler); 195 DISALLOW_COPY_AND_ASSIGN(TestRenderWidgetInputHandler);
196 }; 196 };
197 197
198 TestRenderWidgetInputHandler::TestRenderWidgetInputHandler( 198 TestRenderWidgetInputHandler::TestRenderWidgetInputHandler(
199 content::RenderWidget* render_widget) 199 RenderWidget* render_widget)
200 : content::RenderWidgetInputHandler(render_widget, render_widget), 200 : RenderWidgetInputHandler(render_widget, render_widget),
201 delegate_(nullptr), 201 delegate_(nullptr),
202 state_(content::InputEventAckState::INPUT_EVENT_ACK_STATE_UNKNOWN) {} 202 state_(InputEventAckState::INPUT_EVENT_ACK_STATE_UNKNOWN) {}
203 203
204 void TestRenderWidgetInputHandler::HandleInputEvent( 204 void TestRenderWidgetInputHandler::HandleInputEvent(
205 const blink::WebInputEvent& input_event, 205 const blink::WebInputEvent& input_event,
206 const ui::LatencyInfo& latency_info, 206 const ui::LatencyInfo& latency_info,
207 content::InputEventDispatchType dispatch_type) { 207 InputEventDispatchType dispatch_type) {
208 if (delegate_) { 208 if (delegate_) {
209 std::unique_ptr<content::InputEventAck> ack( 209 std::unique_ptr<InputEventAck> ack(new InputEventAck(
210 new content::InputEventAck(input_event.type, state_)); 210 InputEventAckSource::COMPOSITOR_THREAD, input_event.type, state_));
211 delegate_->OnInputEventAck(std::move(ack)); 211 delegate_->OnInputEventAck(std::move(ack));
212 } 212 }
213 } 213 }
214 214
215 } // namespace 215 } // namespace
216 216
217 namespace content {
218
219 // Test suite for CompositorMusConnection, this does not setup a full renderer 217 // Test suite for CompositorMusConnection, this does not setup a full renderer
220 // environment. This does not establish a connection to a mus server, nor does 218 // environment. This does not establish a connection to a mus server, nor does
221 // it initialize one. 219 // it initialize one.
222 class CompositorMusConnectionTest : public testing::Test { 220 class CompositorMusConnectionTest : public testing::Test {
223 public: 221 public:
224 CompositorMusConnectionTest() {} 222 CompositorMusConnectionTest() {}
225 ~CompositorMusConnectionTest() override {} 223 ~CompositorMusConnectionTest() override {}
226 224
227 // Returns a valid key event, so that it can be converted to a web event by 225 // Returns a valid key event, so that it can be converted to a web event by
228 // CompositorMusConnection. 226 // CompositorMusConnection.
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 TestRenderWidgetInputHandler* input_handler = render_widget_input_handler(); 342 TestRenderWidgetInputHandler* input_handler = render_widget_input_handler();
345 input_handler->set_delegate(connection()); 343 input_handler->set_delegate(connection());
346 input_handler->set_state( 344 input_handler->set_state(
347 InputEventAckState::INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 345 InputEventAckState::INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
348 346
349 ui::TestWindow test_window; 347 ui::TestWindow test_window;
350 std::unique_ptr<ui::Event> event(GenerateKeyEvent()); 348 std::unique_ptr<ui::Event> event(GenerateKeyEvent());
351 scoped_refptr<TestCallback> test_callback(new TestCallback); 349 scoped_refptr<TestCallback> test_callback(new TestCallback);
352 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback( 350 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback(
353 new base::Callback<void(EventResult)>( 351 new base::Callback<void(EventResult)>(
354 base::Bind(&::TestCallback::ResultCallback, test_callback))); 352 base::Bind(&TestCallback::ResultCallback, test_callback)));
355 353
356 OnWindowInputEvent(&test_window, *event.get(), &ack_callback); 354 OnWindowInputEvent(&test_window, *event.get(), &ack_callback);
357 // OnWindowInputEvent is expected to clear the callback if it plans on 355 // OnWindowInputEvent is expected to clear the callback if it plans on
358 // handling the ack. 356 // handling the ack.
359 EXPECT_FALSE(ack_callback.get()); 357 EXPECT_FALSE(ack_callback.get());
360 358
361 VerifyAndRunQueues(true, true); 359 VerifyAndRunQueues(true, true);
362 360
363 // The ack callback should have been called 361 // The ack callback should have been called
364 EXPECT_TRUE(test_callback->called()); 362 EXPECT_TRUE(test_callback->called());
365 EXPECT_EQ(EventResult::UNHANDLED, test_callback->result()); 363 EXPECT_EQ(EventResult::UNHANDLED, test_callback->result());
366 } 364 }
367 365
368 // Tests that for events which the renderer will ack, and consume, that 366 // Tests that for events which the renderer will ack, and consume, that
369 // CompositorMusConnection consumes the ack during OnWindowInputEvent, and calls 367 // CompositorMusConnection consumes the ack during OnWindowInputEvent, and calls
370 // it with the correct state once processed. 368 // it with the correct state once processed.
371 TEST_F(CompositorMusConnectionTest, Consumed) { 369 TEST_F(CompositorMusConnectionTest, Consumed) {
372 TestRenderWidgetInputHandler* input_handler = render_widget_input_handler(); 370 TestRenderWidgetInputHandler* input_handler = render_widget_input_handler();
373 input_handler->set_delegate(connection()); 371 input_handler->set_delegate(connection());
374 input_handler->set_state(InputEventAckState::INPUT_EVENT_ACK_STATE_CONSUMED); 372 input_handler->set_state(InputEventAckState::INPUT_EVENT_ACK_STATE_CONSUMED);
375 373
376 ui::TestWindow test_window; 374 ui::TestWindow test_window;
377 std::unique_ptr<ui::Event> event(GenerateKeyEvent()); 375 std::unique_ptr<ui::Event> event(GenerateKeyEvent());
378 scoped_refptr<TestCallback> test_callback(new TestCallback); 376 scoped_refptr<TestCallback> test_callback(new TestCallback);
379 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback( 377 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback(
380 new base::Callback<void(EventResult)>( 378 new base::Callback<void(EventResult)>(
381 base::Bind(&::TestCallback::ResultCallback, test_callback))); 379 base::Bind(&TestCallback::ResultCallback, test_callback)));
382 380
383 OnWindowInputEvent(&test_window, *event.get(), &ack_callback); 381 OnWindowInputEvent(&test_window, *event.get(), &ack_callback);
384 // OnWindowInputEvent is expected to clear the callback if it plans on 382 // OnWindowInputEvent is expected to clear the callback if it plans on
385 // handling the ack. 383 // handling the ack.
386 EXPECT_FALSE(ack_callback.get()); 384 EXPECT_FALSE(ack_callback.get());
387 385
388 VerifyAndRunQueues(true, true); 386 VerifyAndRunQueues(true, true);
389 387
390 // The ack callback should have been called 388 // The ack callback should have been called
391 EXPECT_TRUE(test_callback->called()); 389 EXPECT_TRUE(test_callback->called());
392 EXPECT_EQ(EventResult::HANDLED, test_callback->result()); 390 EXPECT_EQ(EventResult::HANDLED, test_callback->result());
393 } 391 }
394 392
395 // Tests that when the RenderWidgetInputHandler does not ack before a new event 393 // Tests that when the RenderWidgetInputHandler does not ack before a new event
396 // arrives, that only the most recent ack is fired. 394 // arrives, that only the most recent ack is fired.
397 TEST_F(CompositorMusConnectionTest, LostAck) { 395 TEST_F(CompositorMusConnectionTest, LostAck) {
398 ui::TestWindow test_window; 396 ui::TestWindow test_window;
399 std::unique_ptr<ui::Event> event1(GenerateKeyEvent()); 397 std::unique_ptr<ui::Event> event1(GenerateKeyEvent());
400 scoped_refptr<TestCallback> test_callback1(new TestCallback); 398 scoped_refptr<TestCallback> test_callback1(new TestCallback);
401 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback1( 399 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback1(
402 new base::Callback<void(EventResult)>( 400 new base::Callback<void(EventResult)>(
403 base::Bind(&::TestCallback::ResultCallback, test_callback1))); 401 base::Bind(&TestCallback::ResultCallback, test_callback1)));
404 402
405 OnWindowInputEvent(&test_window, *event1.get(), &ack_callback1); 403 OnWindowInputEvent(&test_window, *event1.get(), &ack_callback1);
406 EXPECT_FALSE(ack_callback1.get()); 404 EXPECT_FALSE(ack_callback1.get());
407 // When simulating the timeout the ack is never enqueued 405 // When simulating the timeout the ack is never enqueued
408 VerifyAndRunQueues(true, false); 406 VerifyAndRunQueues(true, false);
409 407
410 // Setting a delegate will lead to the next event being acked. Having a 408 // Setting a delegate will lead to the next event being acked. Having a
411 // cleared queue simulates the input handler timing out on an event. 409 // cleared queue simulates the input handler timing out on an event.
412 TestRenderWidgetInputHandler* input_handler = render_widget_input_handler(); 410 TestRenderWidgetInputHandler* input_handler = render_widget_input_handler();
413 input_handler->set_delegate(connection()); 411 input_handler->set_delegate(connection());
414 input_handler->set_state(InputEventAckState::INPUT_EVENT_ACK_STATE_CONSUMED); 412 input_handler->set_state(InputEventAckState::INPUT_EVENT_ACK_STATE_CONSUMED);
415 413
416 std::unique_ptr<ui::Event> event2(GenerateKeyEvent()); 414 std::unique_ptr<ui::Event> event2(GenerateKeyEvent());
417 scoped_refptr<TestCallback> test_callback2(new TestCallback); 415 scoped_refptr<TestCallback> test_callback2(new TestCallback);
418 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback2( 416 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback2(
419 new base::Callback<void(EventResult)>( 417 new base::Callback<void(EventResult)>(
420 base::Bind(&::TestCallback::ResultCallback, test_callback2))); 418 base::Bind(&TestCallback::ResultCallback, test_callback2)));
421 OnWindowInputEvent(&test_window, *event2.get(), &ack_callback2); 419 OnWindowInputEvent(&test_window, *event2.get(), &ack_callback2);
422 EXPECT_FALSE(ack_callback2.get()); 420 EXPECT_FALSE(ack_callback2.get());
423 421
424 VerifyAndRunQueues(true, true); 422 VerifyAndRunQueues(true, true);
425 423
426 // Only the most recent ack was called. 424 // Only the most recent ack was called.
427 EXPECT_FALSE(test_callback1->called()); 425 EXPECT_FALSE(test_callback1->called());
428 EXPECT_TRUE(test_callback2->called()); 426 EXPECT_TRUE(test_callback2->called());
429 EXPECT_EQ(EventResult::HANDLED, test_callback2->result()); 427 EXPECT_EQ(EventResult::HANDLED, test_callback2->result());
430 } 428 }
431 429
432 // Tests that when an input handler consumes the event, that 430 // Tests that when an input handler consumes the event, that
433 // CompositorMusConnection will consume the ack, but call as UNHANDLED. 431 // CompositorMusConnection will consume the ack, but call as UNHANDLED.
434 TEST_F(CompositorMusConnectionTest, InputHandlerConsumes) { 432 TEST_F(CompositorMusConnectionTest, InputHandlerConsumes) {
435 input_handler_manager()->SetHandleInputEventResult( 433 input_handler_manager()->SetHandleInputEventResult(
436 InputEventAckState::INPUT_EVENT_ACK_STATE_CONSUMED); 434 InputEventAckState::INPUT_EVENT_ACK_STATE_CONSUMED);
437 ui::TestWindow test_window; 435 ui::TestWindow test_window;
438 std::unique_ptr<ui::Event> event(GenerateKeyEvent()); 436 std::unique_ptr<ui::Event> event(GenerateKeyEvent());
439 scoped_refptr<TestCallback> test_callback(new TestCallback); 437 scoped_refptr<TestCallback> test_callback(new TestCallback);
440 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback( 438 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback(
441 new base::Callback<void(EventResult)>( 439 new base::Callback<void(EventResult)>(
442 base::Bind(&::TestCallback::ResultCallback, test_callback))); 440 base::Bind(&TestCallback::ResultCallback, test_callback)));
443 441
444 OnWindowInputEvent(&test_window, *event.get(), &ack_callback); 442 OnWindowInputEvent(&test_window, *event.get(), &ack_callback);
445 443
446 EXPECT_FALSE(ack_callback.get()); 444 EXPECT_FALSE(ack_callback.get());
447 VerifyAndRunQueues(false, false); 445 VerifyAndRunQueues(false, false);
448 EXPECT_TRUE(test_callback->called()); 446 EXPECT_TRUE(test_callback->called());
449 EXPECT_EQ(EventResult::UNHANDLED, test_callback->result()); 447 EXPECT_EQ(EventResult::UNHANDLED, test_callback->result());
450 } 448 }
451 449
452 // Tests that when the renderer will not ack an event, that 450 // Tests that when the renderer will not ack an event, that
453 // CompositorMusConnection will consume the ack, but call as UNHANDLED. 451 // CompositorMusConnection will consume the ack, but call as UNHANDLED.
454 TEST_F(CompositorMusConnectionTest, RendererWillNotSendAck) { 452 TEST_F(CompositorMusConnectionTest, RendererWillNotSendAck) {
455 ui::TestWindow test_window; 453 ui::TestWindow test_window;
456 ui::PointerEvent event( 454 ui::PointerEvent event(
457 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), ui::EF_NONE, 0, 0, 455 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), ui::EF_NONE, 0, 0,
458 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE), 456 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE),
459 ui::EventTimeForNow()); 457 ui::EventTimeForNow());
460 458
461 scoped_refptr<TestCallback> test_callback(new TestCallback); 459 scoped_refptr<TestCallback> test_callback(new TestCallback);
462 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback( 460 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback(
463 new base::Callback<void(EventResult)>( 461 new base::Callback<void(EventResult)>(
464 base::Bind(&::TestCallback::ResultCallback, test_callback))); 462 base::Bind(&TestCallback::ResultCallback, test_callback)));
465 463
466 OnWindowInputEvent(&test_window, event, &ack_callback); 464 OnWindowInputEvent(&test_window, event, &ack_callback);
467 EXPECT_FALSE(ack_callback.get()); 465 EXPECT_FALSE(ack_callback.get());
468 466
469 VerifyAndRunQueues(true, false); 467 VerifyAndRunQueues(true, false);
470 EXPECT_TRUE(test_callback->called()); 468 EXPECT_TRUE(test_callback->called());
471 EXPECT_EQ(EventResult::UNHANDLED, test_callback->result()); 469 EXPECT_EQ(EventResult::UNHANDLED, test_callback->result());
472 } 470 }
473 471
474 // Tests that when a touch event id provided, that CompositorMusConnection 472 // Tests that when a touch event id provided, that CompositorMusConnection
475 // consumes the ack. 473 // consumes the ack.
476 TEST_F(CompositorMusConnectionTest, TouchEventConsumed) { 474 TEST_F(CompositorMusConnectionTest, TouchEventConsumed) {
477 TestRenderWidgetInputHandler* input_handler = render_widget_input_handler(); 475 TestRenderWidgetInputHandler* input_handler = render_widget_input_handler();
478 input_handler->set_delegate(connection()); 476 input_handler->set_delegate(connection());
479 input_handler->set_state(InputEventAckState::INPUT_EVENT_ACK_STATE_CONSUMED); 477 input_handler->set_state(InputEventAckState::INPUT_EVENT_ACK_STATE_CONSUMED);
480 478
481 ui::TestWindow test_window; 479 ui::TestWindow test_window;
482 ui::PointerEvent event( 480 ui::PointerEvent event(
483 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), ui::EF_NONE, 0, 0, 481 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), ui::EF_NONE, 0, 0,
484 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH), 482 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH),
485 ui::EventTimeForNow()); 483 ui::EventTimeForNow());
486 484
487 scoped_refptr<TestCallback> test_callback(new TestCallback); 485 scoped_refptr<TestCallback> test_callback(new TestCallback);
488 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback( 486 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback(
489 new base::Callback<void(EventResult)>( 487 new base::Callback<void(EventResult)>(
490 base::Bind(&::TestCallback::ResultCallback, test_callback))); 488 base::Bind(&TestCallback::ResultCallback, test_callback)));
491 489
492 OnWindowInputEvent(&test_window, event, &ack_callback); 490 OnWindowInputEvent(&test_window, event, &ack_callback);
493 // OnWindowInputEvent is expected to clear the callback if it plans on 491 // OnWindowInputEvent is expected to clear the callback if it plans on
494 // handling the ack. 492 // handling the ack.
495 EXPECT_FALSE(ack_callback.get()); 493 EXPECT_FALSE(ack_callback.get());
496 494
497 VerifyAndRunQueues(true, true); 495 VerifyAndRunQueues(true, true);
498 496
499 // The ack callback should have been called 497 // The ack callback should have been called
500 EXPECT_TRUE(test_callback->called()); 498 EXPECT_TRUE(test_callback->called());
501 EXPECT_EQ(EventResult::HANDLED, test_callback->result()); 499 EXPECT_EQ(EventResult::HANDLED, test_callback->result());
502 } 500 }
503 501
504 } // namespace content 502 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698