| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); | 324 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); |
| 325 EXPECT_EQ("Focused id=2,1", | 325 EXPECT_EQ("Focused id=2,1", |
| 326 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); | 326 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); |
| 327 ASSERT_EQ(2u, embed_connection->tracker()->changes()->size()); | 327 ASSERT_EQ(2u, embed_connection->tracker()->changes()->size()); |
| 328 EXPECT_EQ("Focused id=2,1", | 328 EXPECT_EQ("Focused id=2,1", |
| 329 ChangesToDescription1(*embed_connection->tracker()->changes())[0]); | 329 ChangesToDescription1(*embed_connection->tracker()->changes())[0]); |
| 330 EXPECT_EQ("InputEvent window=2,1 event_action=4", | 330 EXPECT_EQ("InputEvent window=2,1 event_action=4", |
| 331 ChangesToDescription1(*embed_connection->tracker()->changes())[1]); | 331 ChangesToDescription1(*embed_connection->tracker()->changes())[1]); |
| 332 } | 332 } |
| 333 | 333 |
| 334 // Tests that a client can observe events outside its bounds. |
| 335 TEST_F(WindowTreeTest, SetEventObserver) { |
| 336 // Create an embedded client. |
| 337 TestWindowTreeClient* client = nullptr; |
| 338 WindowTree* tree = nullptr; |
| 339 ServerWindow* window = nullptr; |
| 340 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&client, &tree, &window)); |
| 341 |
| 342 // Create an event outside the bounds of the client. |
| 343 ui::PointerEvent pointer_down = CreatePointerDownEvent(5, 5); |
| 344 |
| 345 // Events are not observed before setting an observer. |
| 346 DispatchEventAndAckImmediately(pointer_down); |
| 347 ASSERT_EQ(0u, client->tracker()->changes()->size()); |
| 348 |
| 349 // Create an observer for pointer-down events. |
| 350 mojom::EventMatcherPtr matcher = mojom::EventMatcher::New(); |
| 351 matcher->type_matcher = mojom::EventTypeMatcher::New(); |
| 352 matcher->type_matcher->type = mojom::EventType::POINTER_DOWN; |
| 353 WindowTreeTestApi(tree).SetEventObserver(std::move(matcher)); |
| 354 |
| 355 // Pointer-down events are sent to the client. |
| 356 DispatchEventAndAckImmediately(pointer_down); |
| 357 ASSERT_EQ(1u, client->tracker()->changes()->size()); |
| 358 EXPECT_EQ("EventObserved event_action=4", |
| 359 ChangesToDescription1(*client->tracker()->changes())[0]); |
| 360 client->tracker()->changes()->clear(); |
| 361 |
| 362 // Clearing the observer stops sending events to the client. |
| 363 WindowTreeTestApi(tree).ClearEventObserver(); |
| 364 DispatchEventAndAckImmediately(pointer_down); |
| 365 ASSERT_EQ(0u, client->tracker()->changes()->size()); |
| 366 } |
| 367 |
| 368 // Tests that a client using an event observer does not receive events that |
| 369 // don't match the EventMatcher spec. |
| 370 TEST_F(WindowTreeTest, SetEventObserverNonMatching) { |
| 371 // Create an embedded client. |
| 372 TestWindowTreeClient* client = nullptr; |
| 373 WindowTree* tree = nullptr; |
| 374 ServerWindow* window = nullptr; |
| 375 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&client, &tree, &window)); |
| 376 |
| 377 // Create an observer for pointer-down events. |
| 378 mojom::EventMatcherPtr matcher = mojom::EventMatcher::New(); |
| 379 matcher->type_matcher = mojom::EventTypeMatcher::New(); |
| 380 matcher->type_matcher->type = mojom::EventType::POINTER_DOWN; |
| 381 WindowTreeTestApi(tree).SetEventObserver(std::move(matcher)); |
| 382 |
| 383 // Pointer-up events are not sent to the client, since they don't match. |
| 384 DispatchEventAndAckImmediately(CreatePointerUpEvent(5, 5)); |
| 385 ASSERT_EQ(0u, client->tracker()->changes()->size()); |
| 386 } |
| 387 |
| 334 TEST_F(WindowTreeTest, CursorChangesWhenMouseOverWindowAndWindowSetsCursor) { | 388 TEST_F(WindowTreeTest, CursorChangesWhenMouseOverWindowAndWindowSetsCursor) { |
| 335 TestWindowTreeClient* embed_connection = nullptr; | 389 TestWindowTreeClient* embed_connection = nullptr; |
| 336 WindowTree* tree = nullptr; | 390 WindowTree* tree = nullptr; |
| 337 ServerWindow* window = nullptr; | 391 ServerWindow* window = nullptr; |
| 338 EXPECT_NO_FATAL_FAILURE( | 392 EXPECT_NO_FATAL_FAILURE( |
| 339 SetupEventTargeting(&embed_connection, &tree, &window)); | 393 SetupEventTargeting(&embed_connection, &tree, &window)); |
| 340 | 394 |
| 341 // Like in BasicInputEventTarget, we send a pointer down event to be | 395 // Like in BasicInputEventTarget, we send a pointer down event to be |
| 342 // dispatched. This is only to place the mouse cursor over that window though. | 396 // dispatched. This is only to place the mouse cursor over that window though. |
| 343 DispatchEventAndAckImmediately(CreateMouseMoveEvent(21, 22)); | 397 DispatchEventAndAckImmediately(CreateMouseMoveEvent(21, 22)); |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 ASSERT_NE(new_opacity, unknown_window.opacity()); | 926 ASSERT_NE(new_opacity, unknown_window.opacity()); |
| 873 | 927 |
| 874 EXPECT_FALSE(tree->SetWindowOpacity( | 928 EXPECT_FALSE(tree->SetWindowOpacity( |
| 875 ClientWindowId(WindowIdToTransportId(window_id)), new_opacity)); | 929 ClientWindowId(WindowIdToTransportId(window_id)), new_opacity)); |
| 876 EXPECT_NE(new_opacity, unknown_window.opacity()); | 930 EXPECT_NE(new_opacity, unknown_window.opacity()); |
| 877 } | 931 } |
| 878 | 932 |
| 879 } // namespace test | 933 } // namespace test |
| 880 } // namespace ws | 934 } // namespace ws |
| 881 } // namespace mus | 935 } // namespace mus |
| OLD | NEW |