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

Side by Side Diff: components/mus/ws/window_tree_unittest.cc

Issue 2057793002: Reorganize event mojom files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed typos in comments. Created 4 years, 6 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 | « components/mus/ws/window_tree.cc ('k') | content/renderer/mus/compositor_mus_connection.cc » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/mus/ws/window_tree.h" 5 #include "components/mus/ws/window_tree.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 return ui::PointerEvent( 80 return ui::PointerEvent(
81 ui::MouseEvent(ui::ET_MOUSE_RELEASED, gfx::Point(x, y), gfx::Point(x, y), 81 ui::MouseEvent(ui::ET_MOUSE_RELEASED, gfx::Point(x, y), gfx::Point(x, y),
82 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 82 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
83 ui::EF_LEFT_MOUSE_BUTTON)); 83 ui::EF_LEFT_MOUSE_BUTTON));
84 } 84 }
85 85
86 ServerWindow* GetCaptureWindow(Display* display) { 86 ServerWindow* GetCaptureWindow(Display* display) {
87 return display->GetActiveWindowManagerState()->capture_window(); 87 return display->GetActiveWindowManagerState()->capture_window();
88 } 88 }
89 89
90 mojom::EventMatcherPtr CreateEventMatcher(mojom::EventType type) { 90 mojom::EventMatcherPtr CreateEventMatcher(ui::mojom::EventType type) {
91 mojom::EventMatcherPtr matcher = mojom::EventMatcher::New(); 91 mojom::EventMatcherPtr matcher = mojom::EventMatcher::New();
92 matcher->type_matcher = mojom::EventTypeMatcher::New(); 92 matcher->type_matcher = mojom::EventTypeMatcher::New();
93 matcher->type_matcher->type = type; 93 matcher->type_matcher->type = type;
94 return matcher; 94 return matcher;
95 } 95 }
96 96
97 } // namespace 97 } // namespace
98 98
99 // ----------------------------------------------------------------------------- 99 // -----------------------------------------------------------------------------
100 100
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 295
296 // Create an event outside the bounds of the client. 296 // Create an event outside the bounds of the client.
297 ui::PointerEvent pointer_down = CreatePointerDownEvent(5, 5); 297 ui::PointerEvent pointer_down = CreatePointerDownEvent(5, 5);
298 298
299 // Events are not observed before setting an observer. 299 // Events are not observed before setting an observer.
300 DispatchEventAndAckImmediately(pointer_down); 300 DispatchEventAndAckImmediately(pointer_down);
301 ASSERT_EQ(0u, client->tracker()->changes()->size()); 301 ASSERT_EQ(0u, client->tracker()->changes()->size());
302 302
303 // Create an observer for pointer-down events. 303 // Create an observer for pointer-down events.
304 WindowTreeTestApi(tree).SetEventObserver( 304 WindowTreeTestApi(tree).SetEventObserver(
305 CreateEventMatcher(mojom::EventType::POINTER_DOWN), 111u); 305 CreateEventMatcher(ui::mojom::EventType::POINTER_DOWN), 111u);
306 306
307 // Pointer-down events are sent to the client. 307 // Pointer-down events are sent to the client.
308 DispatchEventAndAckImmediately(pointer_down); 308 DispatchEventAndAckImmediately(pointer_down);
309 ASSERT_EQ(1u, client->tracker()->changes()->size()); 309 ASSERT_EQ(1u, client->tracker()->changes()->size());
310 EXPECT_EQ("EventObserved event_action=16 event_observer_id=111", 310 EXPECT_EQ("EventObserved event_action=16 event_observer_id=111",
311 ChangesToDescription1(*client->tracker()->changes())[0]); 311 ChangesToDescription1(*client->tracker()->changes())[0]);
312 client->tracker()->changes()->clear(); 312 client->tracker()->changes()->clear();
313 313
314 // Clearing the observer stops sending events to the client. 314 // Clearing the observer stops sending events to the client.
315 WindowTreeTestApi(tree).SetEventObserver(nullptr, 0u); 315 WindowTreeTestApi(tree).SetEventObserver(nullptr, 0u);
316 DispatchEventAndAckImmediately(pointer_down); 316 DispatchEventAndAckImmediately(pointer_down);
317 ASSERT_EQ(0u, client->tracker()->changes()->size()); 317 ASSERT_EQ(0u, client->tracker()->changes()->size());
318 } 318 }
319 319
320 // Tests that a client using an event observer does not receive events that 320 // Tests that a client using an event observer does not receive events that
321 // don't match the EventMatcher spec. 321 // don't match the EventMatcher spec.
322 TEST_F(WindowTreeTest, SetEventObserverNonMatching) { 322 TEST_F(WindowTreeTest, SetEventObserverNonMatching) {
323 // Create an embedded client. 323 // Create an embedded client.
324 TestWindowTreeClient* client = nullptr; 324 TestWindowTreeClient* client = nullptr;
325 WindowTree* tree = nullptr; 325 WindowTree* tree = nullptr;
326 ServerWindow* window = nullptr; 326 ServerWindow* window = nullptr;
327 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&client, &tree, &window)); 327 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&client, &tree, &window));
328 328
329 // Create an observer for pointer-down events. 329 // Create an observer for pointer-down events.
330 WindowTreeTestApi(tree).SetEventObserver( 330 WindowTreeTestApi(tree).SetEventObserver(
331 CreateEventMatcher(mojom::EventType::POINTER_DOWN), 111u); 331 CreateEventMatcher(ui::mojom::EventType::POINTER_DOWN), 111u);
332 332
333 // Pointer-up events are not sent to the client, since they don't match. 333 // Pointer-up events are not sent to the client, since they don't match.
334 DispatchEventAndAckImmediately(CreatePointerUpEvent(5, 5)); 334 DispatchEventAndAckImmediately(CreatePointerUpEvent(5, 5));
335 ASSERT_EQ(0u, client->tracker()->changes()->size()); 335 ASSERT_EQ(0u, client->tracker()->changes()->size());
336 } 336 }
337 337
338 // Tests that an event that both hits a client window and matches an event 338 // Tests that an event that both hits a client window and matches an event
339 // observer is sent only once to the client. 339 // observer is sent only once to the client.
340 TEST_F(WindowTreeTest, SetEventObserverSendsOnce) { 340 TEST_F(WindowTreeTest, SetEventObserverSendsOnce) {
341 // Create an embedded client. 341 // Create an embedded client.
342 TestWindowTreeClient* client = nullptr; 342 TestWindowTreeClient* client = nullptr;
343 WindowTree* tree = nullptr; 343 WindowTree* tree = nullptr;
344 ServerWindow* window = nullptr; 344 ServerWindow* window = nullptr;
345 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&client, &tree, &window)); 345 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&client, &tree, &window));
346 346
347 // Create an observer for pointer-up events (which do not cause focus 347 // Create an observer for pointer-up events (which do not cause focus
348 // changes). 348 // changes).
349 WindowTreeTestApi(tree).SetEventObserver( 349 WindowTreeTestApi(tree).SetEventObserver(
350 CreateEventMatcher(mojom::EventType::POINTER_UP), 111u); 350 CreateEventMatcher(ui::mojom::EventType::POINTER_UP), 111u);
351 351
352 // Create an event inside the bounds of the client. 352 // Create an event inside the bounds of the client.
353 ui::PointerEvent pointer_up = CreatePointerUpEvent(25, 25); 353 ui::PointerEvent pointer_up = CreatePointerUpEvent(25, 25);
354 354
355 // The event is dispatched once, with a flag set that it matched the event 355 // The event is dispatched once, with a flag set that it matched the event
356 // observer. 356 // observer.
357 DispatchEventAndAckImmediately(pointer_up); 357 DispatchEventAndAckImmediately(pointer_up);
358 ASSERT_EQ(1u, client->tracker()->changes()->size()); 358 ASSERT_EQ(1u, client->tracker()->changes()->size());
359 EXPECT_EQ("InputEvent window=2,1 event_action=18 event_observer_id=111", 359 EXPECT_EQ("InputEvent window=2,1 event_action=18 event_observer_id=111",
360 SingleChangeToDescription(*client->tracker()->changes())); 360 SingleChangeToDescription(*client->tracker()->changes()));
361 } 361 }
362 362
363 // Tests that events generated by user A are not observed by event observers for 363 // Tests that events generated by user A are not observed by event observers for
364 // user B. 364 // user B.
365 TEST_F(WindowTreeTest, SetEventObserverWrongUser) { 365 TEST_F(WindowTreeTest, SetEventObserverWrongUser) {
366 // Embed a window tree belonging to a different user. 366 // Embed a window tree belonging to a different user.
367 TestWindowTreeBinding* other_binding; 367 TestWindowTreeBinding* other_binding;
368 WindowTree* other_tree = CreateNewTree("other_user", &other_binding); 368 WindowTree* other_tree = CreateNewTree("other_user", &other_binding);
369 other_binding->client()->tracker()->changes()->clear(); 369 other_binding->client()->tracker()->changes()->clear();
370 370
371 // Set event observers on both the wm tree and the other user's tree. 371 // Set event observers on both the wm tree and the other user's tree.
372 WindowTreeTestApi(wm_tree()).SetEventObserver( 372 WindowTreeTestApi(wm_tree()).SetEventObserver(
373 CreateEventMatcher(mojom::EventType::POINTER_UP), 111u); 373 CreateEventMatcher(ui::mojom::EventType::POINTER_UP), 111u);
374 WindowTreeTestApi(other_tree) 374 WindowTreeTestApi(other_tree)
375 .SetEventObserver(CreateEventMatcher(mojom::EventType::POINTER_UP), 222u); 375 .SetEventObserver(CreateEventMatcher(ui::mojom::EventType::POINTER_UP),
376 222u);
376 377
377 // An event is observed by the wm tree, but not by the other user's tree. 378 // An event is observed by the wm tree, but not by the other user's tree.
378 DispatchEventAndAckImmediately(CreatePointerUpEvent(5, 5)); 379 DispatchEventAndAckImmediately(CreatePointerUpEvent(5, 5));
379 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); 380 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size());
380 EXPECT_EQ("InputEvent window=0,3 event_action=18 event_observer_id=111", 381 EXPECT_EQ("InputEvent window=0,3 event_action=18 event_observer_id=111",
381 SingleChangeToDescription(*wm_client()->tracker()->changes())); 382 SingleChangeToDescription(*wm_client()->tracker()->changes()));
382 ASSERT_EQ(0u, other_binding->client()->tracker()->changes()->size()); 383 ASSERT_EQ(0u, other_binding->client()->tracker()->changes()->size());
383 } 384 }
384 385
385 // Tests that an event observer cannot observe keystrokes. 386 // Tests that an event observer cannot observe keystrokes.
386 TEST_F(WindowTreeTest, SetEventObserverKeyEventsDisallowed) { 387 TEST_F(WindowTreeTest, SetEventObserverKeyEventsDisallowed) {
387 WindowTreeTestApi(wm_tree()).SetEventObserver( 388 WindowTreeTestApi(wm_tree()).SetEventObserver(
388 CreateEventMatcher(mojom::EventType::KEY_PRESSED), 111u); 389 CreateEventMatcher(ui::mojom::EventType::KEY_PRESSED), 111u);
389 ui::KeyEvent key_pressed(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); 390 ui::KeyEvent key_pressed(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE);
390 DispatchEventAndAckImmediately(key_pressed); 391 DispatchEventAndAckImmediately(key_pressed);
391 EXPECT_EQ(0u, wm_client()->tracker()->changes()->size()); 392 EXPECT_EQ(0u, wm_client()->tracker()->changes()->size());
392 393
393 WindowTreeTestApi(wm_tree()).SetEventObserver( 394 WindowTreeTestApi(wm_tree()).SetEventObserver(
394 CreateEventMatcher(mojom::EventType::KEY_RELEASED), 222u); 395 CreateEventMatcher(ui::mojom::EventType::KEY_RELEASED), 222u);
395 ui::KeyEvent key_released(ui::ET_KEY_RELEASED, ui::VKEY_A, ui::EF_NONE); 396 ui::KeyEvent key_released(ui::ET_KEY_RELEASED, ui::VKEY_A, ui::EF_NONE);
396 DispatchEventAndAckImmediately(key_released); 397 DispatchEventAndAckImmediately(key_released);
397 EXPECT_EQ(0u, wm_client()->tracker()->changes()->size()); 398 EXPECT_EQ(0u, wm_client()->tracker()->changes()->size());
398 } 399 }
399 400
400 TEST_F(WindowTreeTest, CursorChangesWhenMouseOverWindowAndWindowSetsCursor) { 401 TEST_F(WindowTreeTest, CursorChangesWhenMouseOverWindowAndWindowSetsCursor) {
401 TestWindowTreeClient* embed_client = nullptr; 402 TestWindowTreeClient* embed_client = nullptr;
402 WindowTree* tree = nullptr; 403 WindowTree* tree = nullptr;
403 ServerWindow* window = nullptr; 404 ServerWindow* window = nullptr;
404 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window)); 405 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window));
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 ASSERT_NE(new_opacity, unknown_window.opacity()); 995 ASSERT_NE(new_opacity, unknown_window.opacity());
995 996
996 EXPECT_FALSE(tree->SetWindowOpacity( 997 EXPECT_FALSE(tree->SetWindowOpacity(
997 ClientWindowId(WindowIdToTransportId(window_id)), new_opacity)); 998 ClientWindowId(WindowIdToTransportId(window_id)), new_opacity));
998 EXPECT_NE(new_opacity, unknown_window.opacity()); 999 EXPECT_NE(new_opacity, unknown_window.opacity());
999 } 1000 }
1000 1001
1001 } // namespace test 1002 } // namespace test
1002 } // namespace ws 1003 } // namespace ws
1003 } // namespace mus 1004 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/window_tree.cc ('k') | content/renderer/mus/compositor_mus_connection.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698