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

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

Issue 1806703002: Use ui::Event instead of mojom::EventPtr in mus::InputEventHandler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed feedback. Created 4 years, 9 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 | « content/renderer/mus/compositor_mus_connection.cc ('k') | mash/wm/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/test/test_simple_task_runner.h" 10 #include "base/test/test_simple_task_runner.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "components/mus/public/cpp/tests/test_window.h" 12 #include "components/mus/public/cpp/tests/test_window.h"
13 #include "components/mus/public/interfaces/input_event_constants.mojom.h" 13 #include "components/mus/public/interfaces/input_event_constants.mojom.h"
14 #include "components/mus/public/interfaces/input_events.mojom.h" 14 #include "components/mus/public/interfaces/input_events.mojom.h"
15 #include "components/mus/public/interfaces/input_key_codes.mojom.h" 15 #include "components/mus/public/interfaces/input_key_codes.mojom.h"
16 #include "content/common/input/did_overscroll_params.h" 16 #include "content/common/input/did_overscroll_params.h"
17 #include "content/common/input/input_event_ack.h" 17 #include "content/common/input/input_event_ack.h"
18 #include "content/common/input/input_event_ack_state.h" 18 #include "content/common/input/input_event_ack_state.h"
19 #include "content/public/test/mock_render_thread.h" 19 #include "content/public/test/mock_render_thread.h"
20 #include "content/renderer/input/input_handler_manager.h" 20 #include "content/renderer/input/input_handler_manager.h"
21 #include "content/renderer/input/input_handler_manager_client.h" 21 #include "content/renderer/input/input_handler_manager_client.h"
22 #include "content/renderer/input/render_widget_input_handler.h" 22 #include "content/renderer/input/render_widget_input_handler.h"
23 #include "content/renderer/mus/render_widget_mus_connection.h" 23 #include "content/renderer/mus/render_widget_mus_connection.h"
24 #include "content/renderer/render_widget.h" 24 #include "content/renderer/render_widget.h"
25 #include "content/test/fake_compositor_dependencies.h" 25 #include "content/test/fake_compositor_dependencies.h"
26 #include "content/test/fake_renderer_scheduler.h" 26 #include "content/test/fake_renderer_scheduler.h"
27 #include "mojo/public/cpp/bindings/interface_request.h" 27 #include "mojo/public/cpp/bindings/interface_request.h"
28 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
29 #include "ui/events/event_utils.h"
29 30
30 namespace { 31 namespace {
31 32
32 // Wrapper for the callback provided to 33 // Wrapper for the callback provided to
33 // CompositorMusConnection:OnWindowInputEvent. This tracks whether the it was 34 // CompositorMusConnection:OnWindowInputEvent. This tracks whether the it was
34 // called, along with the result. 35 // called, along with the result.
35 class TestCallback : public base::RefCounted<TestCallback> { 36 class TestCallback : public base::RefCounted<TestCallback> {
36 public: 37 public:
37 TestCallback() : called_(false), result_(false) {} 38 TestCallback() : called_(false), result_(false) {}
38 39
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 namespace content { 201 namespace content {
201 202
202 // Test suite for CompositorMusConnection, this does not setup a full renderer 203 // Test suite for CompositorMusConnection, this does not setup a full renderer
203 // environment. This does not establish a connection to a mus server, nor does 204 // environment. This does not establish a connection to a mus server, nor does
204 // it initialize one. 205 // it initialize one.
205 class CompositorMusConnectionTest : public testing::Test { 206 class CompositorMusConnectionTest : public testing::Test {
206 public: 207 public:
207 CompositorMusConnectionTest() {} 208 CompositorMusConnectionTest() {}
208 ~CompositorMusConnectionTest() override {} 209 ~CompositorMusConnectionTest() override {}
209 210
210 // Initializes |event| with valid parameters for a key event, so that it can 211 // Returns a valid key event, so that it can be converted to a web event by
211 // be converted to a web event by CompositorMusConnection. 212 // CompositorMusConnection.
212 void GenerateKeyEvent(mus::mojom::EventPtr& event); 213 scoped_ptr<ui::Event> GenerateKeyEvent();
213 214
214 // Calls CompositorMusConnection::OnWindowInputEvent. 215 // Calls CompositorMusConnection::OnWindowInputEvent.
215 void OnWindowInputEvent(mus::Window* window, 216 void OnWindowInputEvent(mus::Window* window,
216 mus::mojom::EventPtr event, 217 const ui::Event& event,
217 scoped_ptr<base::Callback<void(bool)>>* ack_callback); 218 scoped_ptr<base::Callback<void(bool)>>* ack_callback);
218 219
219 // Confirms the state of pending tasks enqueued on each task runner, and runs 220 // Confirms the state of pending tasks enqueued on each task runner, and runs
220 // until idle. 221 // until idle.
221 void VerifyAndRunQueues(bool main_task_runner_enqueued, 222 void VerifyAndRunQueues(bool main_task_runner_enqueued,
222 bool compositor_task_runner_enqueued); 223 bool compositor_task_runner_enqueued);
223 224
224 CompositorMusConnection* compositor_connection() { 225 CompositorMusConnection* compositor_connection() {
225 return compositor_connection_.get(); 226 return compositor_connection_.get();
226 } 227 }
(...skipping 29 matching lines...) Expand all
256 // Actual CompositorMusConnection for testing. 257 // Actual CompositorMusConnection for testing.
257 scoped_refptr<CompositorMusConnection> compositor_connection_; 258 scoped_refptr<CompositorMusConnection> compositor_connection_;
258 259
259 // Test implementations, to control input given to |compositor_connection_|. 260 // Test implementations, to control input given to |compositor_connection_|.
260 scoped_ptr<TestInputHandlerManager> input_handler_manager_; 261 scoped_ptr<TestInputHandlerManager> input_handler_manager_;
261 scoped_ptr<TestRenderWidgetInputHandler> render_widget_input_handler_; 262 scoped_ptr<TestRenderWidgetInputHandler> render_widget_input_handler_;
262 263
263 DISALLOW_COPY_AND_ASSIGN(CompositorMusConnectionTest); 264 DISALLOW_COPY_AND_ASSIGN(CompositorMusConnectionTest);
264 }; 265 };
265 266
266 void CompositorMusConnectionTest::GenerateKeyEvent( 267 scoped_ptr<ui::Event> CompositorMusConnectionTest::GenerateKeyEvent() {
267 mus::mojom::EventPtr& event) { 268 return scoped_ptr<ui::Event>(new ui::KeyEvent(
268 event->action = mus::mojom::EventType::KEY_PRESSED; 269 ui::ET_KEY_PRESSED, ui::KeyboardCode::VKEY_A, ui::EF_NONE));
269 event->time_stamp = base::TimeTicks::Now().ToInternalValue();
270 event->key_data = mus::mojom::KeyData::New();
271 event->key_data->is_char = true;
272 event->key_data->windows_key_code = mus::mojom::KeyboardCode::A;
273 } 270 }
274 271
275 void CompositorMusConnectionTest::OnWindowInputEvent( 272 void CompositorMusConnectionTest::OnWindowInputEvent(
276 mus::Window* window, 273 mus::Window* window,
277 mus::mojom::EventPtr event, 274 const ui::Event& event,
278 scoped_ptr<base::Callback<void(bool)>>* ack_callback) { 275 scoped_ptr<base::Callback<void(bool)>>* ack_callback) {
279 compositor_connection_->OnWindowInputEvent(window, std::move(event), 276 compositor_connection_->OnWindowInputEvent(window, event, ack_callback);
280 ack_callback);
281 } 277 }
282 278
283 void CompositorMusConnectionTest::VerifyAndRunQueues( 279 void CompositorMusConnectionTest::VerifyAndRunQueues(
284 bool main_task_runner_enqueued, 280 bool main_task_runner_enqueued,
285 bool compositor_task_runner_enqueued) { 281 bool compositor_task_runner_enqueued) {
286 // Run through the enqueued actions. 282 // Run through the enqueued actions.
287 EXPECT_EQ(main_task_runner_enqueued, main_task_runner_->HasPendingTask()); 283 EXPECT_EQ(main_task_runner_enqueued, main_task_runner_->HasPendingTask());
288 main_task_runner_->RunUntilIdle(); 284 main_task_runner_->RunUntilIdle();
289 285
290 EXPECT_EQ(compositor_task_runner_enqueued, 286 EXPECT_EQ(compositor_task_runner_enqueued,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 // Tests that for events which the renderer will ack, yet not consume, that 323 // Tests that for events which the renderer will ack, yet not consume, that
328 // CompositorMusConnection consumes the ack during OnWindowInputEvent, and calls 324 // CompositorMusConnection consumes the ack during OnWindowInputEvent, and calls
329 // it with the correct state once processed. 325 // it with the correct state once processed.
330 TEST_F(CompositorMusConnectionTest, NotConsumed) { 326 TEST_F(CompositorMusConnectionTest, NotConsumed) {
331 TestRenderWidgetInputHandler* input_handler = render_widget_input_handler(); 327 TestRenderWidgetInputHandler* input_handler = render_widget_input_handler();
332 input_handler->set_delegate(connection()); 328 input_handler->set_delegate(connection());
333 input_handler->set_state( 329 input_handler->set_state(
334 InputEventAckState::INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 330 InputEventAckState::INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
335 331
336 mus::TestWindow test_window; 332 mus::TestWindow test_window;
337 mus::mojom::EventPtr event = mus::mojom::Event::New(); 333 scoped_ptr<ui::Event> event(GenerateKeyEvent());
338 GenerateKeyEvent(event);
339 scoped_refptr<TestCallback> test_callback(new TestCallback); 334 scoped_refptr<TestCallback> test_callback(new TestCallback);
340 scoped_ptr<base::Callback<void(bool)>> ack_callback( 335 scoped_ptr<base::Callback<void(bool)>> ack_callback(
341 new base::Callback<void(bool)>( 336 new base::Callback<void(bool)>(
342 base::Bind(&::TestCallback::BoolCallback, test_callback))); 337 base::Bind(&::TestCallback::BoolCallback, test_callback)));
343 338
344 OnWindowInputEvent(&test_window, std::move(event), &ack_callback); 339 OnWindowInputEvent(&test_window, *event.get(), &ack_callback);
345 // OnWindowInputEvent is expected to clear the callback if it plans on 340 // OnWindowInputEvent is expected to clear the callback if it plans on
346 // handling the ack. 341 // handling the ack.
347 EXPECT_FALSE(ack_callback.get()); 342 EXPECT_FALSE(ack_callback.get());
348 343
349 VerifyAndRunQueues(true, true); 344 VerifyAndRunQueues(true, true);
350 345
351 // The ack callback should have been called 346 // The ack callback should have been called
352 EXPECT_TRUE(test_callback->called()); 347 EXPECT_TRUE(test_callback->called());
353 EXPECT_FALSE(test_callback->result()); 348 EXPECT_FALSE(test_callback->result());
354 } 349 }
355 350
356 // Tests that for events which the renderer will ack, and consume, that 351 // Tests that for events which the renderer will ack, and consume, that
357 // CompositorMusConnection consumes the ack during OnWindowInputEvent, and calls 352 // CompositorMusConnection consumes the ack during OnWindowInputEvent, and calls
358 // it with the correct state once processed. 353 // it with the correct state once processed.
359 TEST_F(CompositorMusConnectionTest, Consumed) { 354 TEST_F(CompositorMusConnectionTest, Consumed) {
360 TestRenderWidgetInputHandler* input_handler = render_widget_input_handler(); 355 TestRenderWidgetInputHandler* input_handler = render_widget_input_handler();
361 input_handler->set_delegate(connection()); 356 input_handler->set_delegate(connection());
362 input_handler->set_state(InputEventAckState::INPUT_EVENT_ACK_STATE_CONSUMED); 357 input_handler->set_state(InputEventAckState::INPUT_EVENT_ACK_STATE_CONSUMED);
363 358
364 mus::TestWindow test_window; 359 mus::TestWindow test_window;
365 mus::mojom::EventPtr event = mus::mojom::Event::New(); 360 scoped_ptr<ui::Event> event(GenerateKeyEvent());
366 GenerateKeyEvent(event);
367 scoped_refptr<TestCallback> test_callback(new TestCallback); 361 scoped_refptr<TestCallback> test_callback(new TestCallback);
368 scoped_ptr<base::Callback<void(bool)>> ack_callback( 362 scoped_ptr<base::Callback<void(bool)>> ack_callback(
369 new base::Callback<void(bool)>( 363 new base::Callback<void(bool)>(
370 base::Bind(&::TestCallback::BoolCallback, test_callback))); 364 base::Bind(&::TestCallback::BoolCallback, test_callback)));
371 365
372 OnWindowInputEvent(&test_window, std::move(event), &ack_callback); 366 OnWindowInputEvent(&test_window, *event.get(), &ack_callback);
373 // OnWindowInputEvent is expected to clear the callback if it plans on 367 // OnWindowInputEvent is expected to clear the callback if it plans on
374 // handling the ack. 368 // handling the ack.
375 EXPECT_FALSE(ack_callback.get()); 369 EXPECT_FALSE(ack_callback.get());
376 370
377 VerifyAndRunQueues(true, true); 371 VerifyAndRunQueues(true, true);
378 372
379 // The ack callback should have been called 373 // The ack callback should have been called
380 EXPECT_TRUE(test_callback->called()); 374 EXPECT_TRUE(test_callback->called());
381 EXPECT_TRUE(test_callback->result()); 375 EXPECT_TRUE(test_callback->result());
382 } 376 }
383 377
384 // Tests that when the RenderWidgetInputHandler does not ack before a new event 378 // Tests that when the RenderWidgetInputHandler does not ack before a new event
385 // arrives, that only the most recent ack is fired. 379 // arrives, that only the most recent ack is fired.
386 TEST_F(CompositorMusConnectionTest, LostAck) { 380 TEST_F(CompositorMusConnectionTest, LostAck) {
387 mus::TestWindow test_window; 381 mus::TestWindow test_window;
388 mus::mojom::EventPtr event1 = mus::mojom::Event::New(); 382 scoped_ptr<ui::Event> event1(GenerateKeyEvent());
389 GenerateKeyEvent(event1);
390 scoped_refptr<TestCallback> test_callback1(new TestCallback); 383 scoped_refptr<TestCallback> test_callback1(new TestCallback);
391 scoped_ptr<base::Callback<void(bool)>> ack_callback1( 384 scoped_ptr<base::Callback<void(bool)>> ack_callback1(
392 new base::Callback<void(bool)>( 385 new base::Callback<void(bool)>(
393 base::Bind(&::TestCallback::BoolCallback, test_callback1))); 386 base::Bind(&::TestCallback::BoolCallback, test_callback1)));
394 387
395 OnWindowInputEvent(&test_window, std::move(event1), &ack_callback1); 388 OnWindowInputEvent(&test_window, *event1.get(), &ack_callback1);
396 EXPECT_FALSE(ack_callback1.get()); 389 EXPECT_FALSE(ack_callback1.get());
397 // When simulating the timeout the ack is never enqueued 390 // When simulating the timeout the ack is never enqueued
398 VerifyAndRunQueues(true, false); 391 VerifyAndRunQueues(true, false);
399 392
400 // Setting a delegate will lead to the next event being acked. Having a 393 // Setting a delegate will lead to the next event being acked. Having a
401 // cleared queue simulates the input handler timing out on an event. 394 // cleared queue simulates the input handler timing out on an event.
402 TestRenderWidgetInputHandler* input_handler = render_widget_input_handler(); 395 TestRenderWidgetInputHandler* input_handler = render_widget_input_handler();
403 input_handler->set_delegate(connection()); 396 input_handler->set_delegate(connection());
404 input_handler->set_state(InputEventAckState::INPUT_EVENT_ACK_STATE_CONSUMED); 397 input_handler->set_state(InputEventAckState::INPUT_EVENT_ACK_STATE_CONSUMED);
405 398
406 mus::mojom::EventPtr event2 = mus::mojom::Event::New(); 399 scoped_ptr<ui::Event> event2(GenerateKeyEvent());
407 GenerateKeyEvent(event2);
408 scoped_refptr<TestCallback> test_callback2(new TestCallback); 400 scoped_refptr<TestCallback> test_callback2(new TestCallback);
409 scoped_ptr<base::Callback<void(bool)>> ack_callback2( 401 scoped_ptr<base::Callback<void(bool)>> ack_callback2(
410 new base::Callback<void(bool)>( 402 new base::Callback<void(bool)>(
411 base::Bind(&::TestCallback::BoolCallback, test_callback2))); 403 base::Bind(&::TestCallback::BoolCallback, test_callback2)));
412 OnWindowInputEvent(&test_window, std::move(event2), &ack_callback2); 404 OnWindowInputEvent(&test_window, *event2.get(), &ack_callback2);
413 EXPECT_FALSE(ack_callback2.get()); 405 EXPECT_FALSE(ack_callback2.get());
414 406
415 VerifyAndRunQueues(true, true); 407 VerifyAndRunQueues(true, true);
416 408
417 // Only the most recent ack was called. 409 // Only the most recent ack was called.
418 EXPECT_FALSE(test_callback1->called()); 410 EXPECT_FALSE(test_callback1->called());
419 EXPECT_TRUE(test_callback2->called()); 411 EXPECT_TRUE(test_callback2->called());
420 EXPECT_TRUE(test_callback2->result()); 412 EXPECT_TRUE(test_callback2->result());
421 } 413 }
422 414
423 // Tests that when an input handler consumes the event, that 415 // Tests that when an input handler consumes the event, that
424 // CompositorMusConnection does not consume the ack, nor calls it. 416 // CompositorMusConnection does not consume the ack, nor calls it.
425 TEST_F(CompositorMusConnectionTest, InputHandlerConsumes) { 417 TEST_F(CompositorMusConnectionTest, InputHandlerConsumes) {
426 input_handler_manager()->SetHandleInputEventResult( 418 input_handler_manager()->SetHandleInputEventResult(
427 InputEventAckState::INPUT_EVENT_ACK_STATE_CONSUMED); 419 InputEventAckState::INPUT_EVENT_ACK_STATE_CONSUMED);
428 mus::TestWindow test_window; 420 mus::TestWindow test_window;
429 mus::mojom::EventPtr event = mus::mojom::Event::New(); 421 scoped_ptr<ui::Event> event(GenerateKeyEvent());
430 GenerateKeyEvent(event);
431 scoped_refptr<TestCallback> test_callback(new TestCallback); 422 scoped_refptr<TestCallback> test_callback(new TestCallback);
432 scoped_ptr<base::Callback<void(bool)>> ack_callback( 423 scoped_ptr<base::Callback<void(bool)>> ack_callback(
433 new base::Callback<void(bool)>( 424 new base::Callback<void(bool)>(
434 base::Bind(&::TestCallback::BoolCallback, test_callback))); 425 base::Bind(&::TestCallback::BoolCallback, test_callback)));
435 426
436 OnWindowInputEvent(&test_window, std::move(event), &ack_callback); 427 OnWindowInputEvent(&test_window, *event.get(), &ack_callback);
437 428
438 EXPECT_TRUE(ack_callback.get()); 429 EXPECT_TRUE(ack_callback.get());
439 VerifyAndRunQueues(false, false); 430 VerifyAndRunQueues(false, false);
440 EXPECT_FALSE(test_callback->called()); 431 EXPECT_FALSE(test_callback->called());
441 } 432 }
442 433
443 // Tests that when the renderer will not ack an event, that 434 // Tests that when the renderer will not ack an event, that
444 // CompositorMusConnection does not consume the ack, nor calls it. 435 // CompositorMusConnection does not consume the ack, nor calls it.
445 TEST_F(CompositorMusConnectionTest, RendererWillNotSendAck) { 436 TEST_F(CompositorMusConnectionTest, RendererWillNotSendAck) {
446 mus::TestWindow test_window; 437 mus::TestWindow test_window;
447 mus::mojom::EventPtr event = mus::mojom::Event::New(); 438 ui::PointerEvent event(ui::ET_POINTER_DOWN,
448 event->action = mus::mojom::EventType::POINTER_DOWN; 439 ui::EventPointerType::POINTER_TYPE_MOUSE, gfx::Point(),
449 event->time_stamp = base::TimeTicks::Now().ToInternalValue(); 440 gfx::Point(), ui::EF_NONE, 0, ui::EventTimeForNow());
450 event->pointer_data = mus::mojom::PointerData::New();
451 441
452 scoped_refptr<TestCallback> test_callback(new TestCallback); 442 scoped_refptr<TestCallback> test_callback(new TestCallback);
453 scoped_ptr<base::Callback<void(bool)>> ack_callback( 443 scoped_ptr<base::Callback<void(bool)>> ack_callback(
454 new base::Callback<void(bool)>( 444 new base::Callback<void(bool)>(
455 base::Bind(&::TestCallback::BoolCallback, test_callback))); 445 base::Bind(&::TestCallback::BoolCallback, test_callback)));
456 446
457 OnWindowInputEvent(&test_window, std::move(event), &ack_callback); 447 OnWindowInputEvent(&test_window, event, &ack_callback);
458 EXPECT_TRUE(ack_callback.get()); 448 EXPECT_TRUE(ack_callback.get());
459 449
460 VerifyAndRunQueues(true, false); 450 VerifyAndRunQueues(true, false);
461 EXPECT_FALSE(test_callback->called()); 451 EXPECT_FALSE(test_callback->called());
462 } 452 }
463 453
464 } // namespace content 454 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/mus/compositor_mus_connection.cc ('k') | mash/wm/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698