| OLD | NEW |
| 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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 DispatchEventAndAckImmediately(CreatePointerUpEvent(21, 22)); | 253 DispatchEventAndAckImmediately(CreatePointerUpEvent(21, 22)); |
| 254 wm_client()->tracker()->changes()->clear(); | 254 wm_client()->tracker()->changes()->clear(); |
| 255 tree1_client->tracker()->changes()->clear(); | 255 tree1_client->tracker()->changes()->clear(); |
| 256 | 256 |
| 257 // Press in the same location. Should not get a focus change event (only input | 257 // Press in the same location. Should not get a focus change event (only input |
| 258 // event). | 258 // event). |
| 259 DispatchEventAndAckImmediately(CreatePointerDownEvent(61, 22)); | 259 DispatchEventAndAckImmediately(CreatePointerDownEvent(61, 22)); |
| 260 EXPECT_EQ(child1, display()->GetFocusedWindow()); | 260 EXPECT_EQ(child1, display()->GetFocusedWindow()); |
| 261 ASSERT_EQ(wm_client()->tracker()->changes()->size(), 1u) | 261 ASSERT_EQ(wm_client()->tracker()->changes()->size(), 1u) |
| 262 << SingleChangeToDescription(*wm_client()->tracker()->changes()); | 262 << SingleChangeToDescription(*wm_client()->tracker()->changes()); |
| 263 EXPECT_EQ("InputEvent window=0,3 event_action=4", | 263 EXPECT_EQ("InputEvent window=0,3 event_action=16", |
| 264 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); | 264 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); |
| 265 EXPECT_TRUE(tree1_client->tracker()->changes()->empty()); | 265 EXPECT_TRUE(tree1_client->tracker()->changes()->empty()); |
| 266 } | 266 } |
| 267 | 267 |
| 268 TEST_F(WindowTreeTest, BasicInputEventTarget) { | 268 TEST_F(WindowTreeTest, BasicInputEventTarget) { |
| 269 TestWindowTreeClient* embed_client = nullptr; | 269 TestWindowTreeClient* embed_client = nullptr; |
| 270 WindowTree* tree = nullptr; | 270 WindowTree* tree = nullptr; |
| 271 ServerWindow* window = nullptr; | 271 ServerWindow* window = nullptr; |
| 272 EXPECT_NO_FATAL_FAILURE( | 272 EXPECT_NO_FATAL_FAILURE( |
| 273 SetupEventTargeting(&embed_client, &tree, &window)); | 273 SetupEventTargeting(&embed_client, &tree, &window)); |
| 274 | 274 |
| 275 // Send an event to |v1|. |embed_client| should get the event, not | 275 // Send an event to |v1|. |embed_client| should get the event, not |
| 276 // |wm_client|, since |v1| lives inside an embedded window. | 276 // |wm_client|, since |v1| lives inside an embedded window. |
| 277 DispatchEventAndAckImmediately(CreatePointerDownEvent(21, 22)); | 277 DispatchEventAndAckImmediately(CreatePointerDownEvent(21, 22)); |
| 278 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); | 278 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); |
| 279 EXPECT_EQ("Focused id=2,1", | 279 EXPECT_EQ("Focused id=2,1", |
| 280 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); | 280 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); |
| 281 ASSERT_EQ(2u, embed_client->tracker()->changes()->size()); | 281 ASSERT_EQ(2u, embed_client->tracker()->changes()->size()); |
| 282 EXPECT_EQ("Focused id=2,1", | 282 EXPECT_EQ("Focused id=2,1", |
| 283 ChangesToDescription1(*embed_client->tracker()->changes())[0]); | 283 ChangesToDescription1(*embed_client->tracker()->changes())[0]); |
| 284 EXPECT_EQ("InputEvent window=2,1 event_action=4", | 284 EXPECT_EQ("InputEvent window=2,1 event_action=16", |
| 285 ChangesToDescription1(*embed_client->tracker()->changes())[1]); | 285 ChangesToDescription1(*embed_client->tracker()->changes())[1]); |
| 286 } | 286 } |
| 287 | 287 |
| 288 // Tests that a client can observe events outside its bounds. | 288 // Tests that a client can observe events outside its bounds. |
| 289 TEST_F(WindowTreeTest, SetEventObserver) { | 289 TEST_F(WindowTreeTest, SetEventObserver) { |
| 290 // Create an embedded client. | 290 // Create an embedded client. |
| 291 TestWindowTreeClient* client = nullptr; | 291 TestWindowTreeClient* client = nullptr; |
| 292 WindowTree* tree = nullptr; | 292 WindowTree* tree = nullptr; |
| 293 ServerWindow* window = nullptr; | 293 ServerWindow* window = nullptr; |
| 294 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&client, &tree, &window)); | 294 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&client, &tree, &window)); |
| 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(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=4 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 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 349 WindowTreeTestApi(tree).SetEventObserver( | 349 WindowTreeTestApi(tree).SetEventObserver( |
| 350 CreateEventMatcher(mojom::EventType::POINTER_UP), 111u); | 350 CreateEventMatcher(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=6 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(mojom::EventType::POINTER_UP), 111u); |
| 374 WindowTreeTestApi(other_tree) | 374 WindowTreeTestApi(other_tree) |
| 375 .SetEventObserver(CreateEventMatcher(mojom::EventType::POINTER_UP), 222u); | 375 .SetEventObserver(CreateEventMatcher(mojom::EventType::POINTER_UP), 222u); |
| 376 | 376 |
| 377 // An event is observed by the wm tree, but not by the other user's tree. | 377 // An event is observed by the wm tree, but not by the other user's tree. |
| 378 DispatchEventAndAckImmediately(CreatePointerUpEvent(5, 5)); | 378 DispatchEventAndAckImmediately(CreatePointerUpEvent(5, 5)); |
| 379 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); | 379 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); |
| 380 EXPECT_EQ("InputEvent window=0,3 event_action=6 event_observer_id=111", | 380 EXPECT_EQ("InputEvent window=0,3 event_action=18 event_observer_id=111", |
| 381 SingleChangeToDescription(*wm_client()->tracker()->changes())); | 381 SingleChangeToDescription(*wm_client()->tracker()->changes())); |
| 382 ASSERT_EQ(0u, other_binding->client()->tracker()->changes()->size()); | 382 ASSERT_EQ(0u, other_binding->client()->tracker()->changes()->size()); |
| 383 } | 383 } |
| 384 | 384 |
| 385 // Tests that an event observer cannot observe keystrokes. | 385 // Tests that an event observer cannot observe keystrokes. |
| 386 TEST_F(WindowTreeTest, SetEventObserverKeyEventsDisallowed) { | 386 TEST_F(WindowTreeTest, SetEventObserverKeyEventsDisallowed) { |
| 387 WindowTreeTestApi(wm_tree()).SetEventObserver( | 387 WindowTreeTestApi(wm_tree()).SetEventObserver( |
| 388 CreateEventMatcher(mojom::EventType::KEY_PRESSED), 111u); | 388 CreateEventMatcher(mojom::EventType::KEY_PRESSED), 111u); |
| 389 ui::KeyEvent key_pressed(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); | 389 ui::KeyEvent key_pressed(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); |
| 390 DispatchEventAndAckImmediately(key_pressed); | 390 DispatchEventAndAckImmediately(key_pressed); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 EXPECT_TRUE( | 533 EXPECT_TRUE( |
| 534 wm_tree()->NewWindow(embed_window_id, ServerWindow::Properties())); | 534 wm_tree()->NewWindow(embed_window_id, ServerWindow::Properties())); |
| 535 EXPECT_TRUE(wm_tree()->SetWindowVisibility(embed_window_id, true)); | 535 EXPECT_TRUE(wm_tree()->SetWindowVisibility(embed_window_id, true)); |
| 536 ASSERT_TRUE(FirstRoot(wm_tree())); | 536 ASSERT_TRUE(FirstRoot(wm_tree())); |
| 537 EXPECT_TRUE(wm_tree()->AddWindow(FirstRootId(wm_tree()), embed_window_id)); | 537 EXPECT_TRUE(wm_tree()->AddWindow(FirstRootId(wm_tree()), embed_window_id)); |
| 538 display()->root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 538 display()->root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 539 | 539 |
| 540 wm_client()->tracker()->changes()->clear(); | 540 wm_client()->tracker()->changes()->clear(); |
| 541 DispatchEventWithoutAck(CreateMouseMoveEvent(21, 22)); | 541 DispatchEventWithoutAck(CreateMouseMoveEvent(21, 22)); |
| 542 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); | 542 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); |
| 543 EXPECT_EQ("InputEvent window=0,3 event_action=5", | 543 EXPECT_EQ("InputEvent window=0,3 event_action=17", |
| 544 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); | 544 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); |
| 545 wm_client()->tracker()->changes()->clear(); | 545 wm_client()->tracker()->changes()->clear(); |
| 546 | 546 |
| 547 // Send another event. This event shouldn't reach the client. | 547 // Send another event. This event shouldn't reach the client. |
| 548 DispatchEventWithoutAck(CreateMouseMoveEvent(21, 22)); | 548 DispatchEventWithoutAck(CreateMouseMoveEvent(21, 22)); |
| 549 ASSERT_EQ(0u, wm_client()->tracker()->changes()->size()); | 549 ASSERT_EQ(0u, wm_client()->tracker()->changes()->size()); |
| 550 | 550 |
| 551 // Ack the first event. That should trigger the dispatch of the second event. | 551 // Ack the first event. That should trigger the dispatch of the second event. |
| 552 AckPreviousEvent(); | 552 AckPreviousEvent(); |
| 553 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); | 553 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); |
| 554 EXPECT_EQ("InputEvent window=0,3 event_action=5", | 554 EXPECT_EQ("InputEvent window=0,3 event_action=17", |
| 555 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); | 555 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); |
| 556 } | 556 } |
| 557 | 557 |
| 558 // Establish client, call NewTopLevelWindow(), make sure get id, and make | 558 // Establish client, call NewTopLevelWindow(), make sure get id, and make |
| 559 // sure client paused. | 559 // sure client paused. |
| 560 TEST_F(WindowTreeTest, NewTopLevelWindow) { | 560 TEST_F(WindowTreeTest, NewTopLevelWindow) { |
| 561 TestWindowManager wm_internal; | 561 TestWindowManager wm_internal; |
| 562 set_window_manager_internal(wm_tree(), &wm_internal); | 562 set_window_manager_internal(wm_tree(), &wm_internal); |
| 563 | 563 |
| 564 TestWindowTreeBinding* child_binding; | 564 TestWindowTreeBinding* child_binding; |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 994 ASSERT_NE(new_opacity, unknown_window.opacity()); | 994 ASSERT_NE(new_opacity, unknown_window.opacity()); |
| 995 | 995 |
| 996 EXPECT_FALSE(tree->SetWindowOpacity( | 996 EXPECT_FALSE(tree->SetWindowOpacity( |
| 997 ClientWindowId(WindowIdToTransportId(window_id)), new_opacity)); | 997 ClientWindowId(WindowIdToTransportId(window_id)), new_opacity)); |
| 998 EXPECT_NE(new_opacity, unknown_window.opacity()); | 998 EXPECT_NE(new_opacity, unknown_window.opacity()); |
| 999 } | 999 } |
| 1000 | 1000 |
| 1001 } // namespace test | 1001 } // namespace test |
| 1002 } // namespace ws | 1002 } // namespace ws |
| 1003 } // namespace mus | 1003 } // namespace mus |
| OLD | NEW |