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

Side by Side Diff: services/ui/public/cpp/tests/window_tree_client_unittest.cc

Issue 2248263003: Updates PointerEventRouter to handle switching move type (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: false- Created 4 years, 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "services/ui/public/cpp/window_tree_client.h" 5 #include "services/ui/public/cpp/window_tree_client.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 TestWindowTreeClientDelegate* window_tree_delegate() { 91 TestWindowTreeClientDelegate* window_tree_delegate() {
92 return &window_tree_delegate_; 92 return &window_tree_delegate_;
93 } 93 }
94 94
95 Window* GetFirstRoot() { 95 Window* GetFirstRoot() {
96 return client()->GetRoots().empty() ? nullptr 96 return client()->GetRoots().empty() ? nullptr
97 : *client()->GetRoots().begin(); 97 : *client()->GetRoots().begin();
98 } 98 }
99 99
100 uint32_t GetPointerWatcherId() {
101 return WindowTreeClientPrivate(&tree_client_).pointer_watcher_id();
102 }
103
104 private: 100 private:
105 TestWindowTree window_tree_; 101 TestWindowTree window_tree_;
106 TestWindowTreeClientDelegate window_tree_delegate_; 102 TestWindowTreeClientDelegate window_tree_delegate_;
107 WindowTreeClient tree_client_; 103 WindowTreeClient tree_client_;
108 104
109 DISALLOW_COPY_AND_ASSIGN(WindowTreeSetup); 105 DISALLOW_COPY_AND_ASSIGN(WindowTreeSetup);
110 }; 106 };
111 107
112 class TestInputEventHandler : public InputEventHandler { 108 class TestInputEventHandler : public InputEventHandler {
113 public: 109 public:
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 // window tree. 468 // window tree.
473 TEST_F(WindowTreeClientTest, OnPointerEventObserved) { 469 TEST_F(WindowTreeClientTest, OnPointerEventObserved) {
474 WindowTreeSetup setup; 470 WindowTreeSetup setup;
475 Window* root = setup.GetFirstRoot(); 471 Window* root = setup.GetFirstRoot();
476 ASSERT_TRUE(root); 472 ASSERT_TRUE(root);
477 473
478 // Start a pointer watcher for all events excluding move events. 474 // Start a pointer watcher for all events excluding move events.
479 setup.client()->StartPointerWatcher(false /* want_moves */); 475 setup.client()->StartPointerWatcher(false /* want_moves */);
480 476
481 // Simulate the server sending an observed event. 477 // Simulate the server sending an observed event.
482 uint32_t pointer_watcher_id = setup.GetPointerWatcherId();
483 std::unique_ptr<ui::PointerEvent> pointer_event_down(new ui::PointerEvent( 478 std::unique_ptr<ui::PointerEvent> pointer_event_down(new ui::PointerEvent(
484 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), ui::EF_CONTROL_DOWN, 1, 479 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), ui::EF_CONTROL_DOWN, 1,
485 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH), 480 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH),
486 base::TimeTicks())); 481 base::TimeTicks()));
487 setup.window_tree_client()->OnPointerEventObserved( 482 setup.window_tree_client()->OnPointerEventObserved(
488 std::move(pointer_event_down), pointer_watcher_id, 0u); 483 std::move(pointer_event_down), 0u);
489 484
490 // Delegate sensed the event. 485 // Delegate sensed the event.
491 ui::Event* last_event = setup.window_tree_delegate()->last_event_observed(); 486 ui::Event* last_event = setup.window_tree_delegate()->last_event_observed();
492 EXPECT_EQ(ui::ET_POINTER_DOWN, last_event->type()); 487 EXPECT_EQ(ui::ET_POINTER_DOWN, last_event->type());
493 EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags()); 488 EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags());
494 setup.window_tree_delegate()->Reset(); 489 setup.window_tree_delegate()->Reset();
495 490
496 // Stop the pointer watcher. 491 // Stop the pointer watcher.
497 setup.client()->StopPointerWatcher(); 492 setup.client()->StopPointerWatcher();
498 493
499 // Simulate another event from the server. 494 // Simulate another event from the server.
500 std::unique_ptr<ui::PointerEvent> pointer_event_up(new ui::PointerEvent( 495 std::unique_ptr<ui::PointerEvent> pointer_event_up(new ui::PointerEvent(
501 ui::ET_POINTER_UP, gfx::Point(), gfx::Point(), ui::EF_CONTROL_DOWN, 1, 496 ui::ET_POINTER_UP, gfx::Point(), gfx::Point(), ui::EF_CONTROL_DOWN, 1,
502 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH), 497 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH),
503 base::TimeTicks())); 498 base::TimeTicks()));
504 setup.window_tree_client()->OnPointerEventObserved( 499 setup.window_tree_client()->OnPointerEventObserved(
505 std::move(pointer_event_up), pointer_watcher_id, 0u); 500 std::move(pointer_event_up), 0u);
506 501
507 // No event was sensed. 502 // No event was sensed.
508 EXPECT_FALSE(setup.window_tree_delegate()->last_event_observed()); 503 EXPECT_FALSE(setup.window_tree_delegate()->last_event_observed());
509 } 504 }
510 505
511 // Tests pointer watchers triggered by events that hit this window tree. 506 // Tests pointer watchers triggered by events that hit this window tree.
512 TEST_F(WindowTreeClientTest, OnWindowInputEventWithPointerWatcher) { 507 TEST_F(WindowTreeClientTest, OnWindowInputEventWithPointerWatcher) {
513 WindowTreeSetup setup; 508 WindowTreeSetup setup;
514 Window* root = setup.GetFirstRoot(); 509 Window* root = setup.GetFirstRoot();
515 ASSERT_TRUE(root); 510 ASSERT_TRUE(root);
516 511
517 // Start a pointer watcher for all events excluding move events. 512 // Start a pointer watcher for all events excluding move events.
518 setup.client()->StartPointerWatcher(false /* want_moves */); 513 setup.client()->StartPointerWatcher(false /* want_moves */);
519 514
520 // Simulate the server dispatching an event that also matched the observer. 515 // Simulate the server dispatching an event that also matched the observer.
521 uint32_t pointer_watcher_id = setup.GetPointerWatcherId();
522 std::unique_ptr<ui::PointerEvent> pointer_event_down(new ui::PointerEvent( 516 std::unique_ptr<ui::PointerEvent> pointer_event_down(new ui::PointerEvent(
523 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), ui::EF_CONTROL_DOWN, 1, 517 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), ui::EF_CONTROL_DOWN, 1,
524 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH), 518 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH),
525 base::TimeTicks())); 519 base::TimeTicks()));
526 setup.window_tree_client()->OnWindowInputEvent( 520 setup.window_tree_client()->OnWindowInputEvent(
527 1, server_id(root), std::move(pointer_event_down), pointer_watcher_id); 521 1, server_id(root), std::move(pointer_event_down), true);
528 522
529 // Delegate sensed the event. 523 // Delegate sensed the event.
530 ui::Event* last_event = setup.window_tree_delegate()->last_event_observed(); 524 ui::Event* last_event = setup.window_tree_delegate()->last_event_observed();
531 EXPECT_EQ(ui::ET_POINTER_DOWN, last_event->type()); 525 EXPECT_EQ(ui::ET_POINTER_DOWN, last_event->type());
532 EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags()); 526 EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags());
533 } 527 }
534 528
535 // Tests that replacing a pointer watcher with a new one that has different
536 // |want_moves| values results in only new events being observed.
537 TEST_F(WindowTreeClientTest, PointerWatcherReplaced) {
msw 2016/08/18 22:45:23 Is there a way to keep this test, perhaps at a dif
sky 2016/08/18 23:17:14 Previously this case was interesting because of th
538 WindowTreeSetup setup;
539 Window* root = setup.GetFirstRoot();
540 ASSERT_TRUE(root);
541
542 // Start a pointer watcher for all events excluding move events.
543 setup.client()->StartPointerWatcher(false /* want_moves */);
544 uint32_t pointer_watcher_id1 = setup.GetPointerWatcherId();
545
546 // Replace it with a second watcher that also watches for move events.
547 setup.client()->StartPointerWatcher(true /* want_moves */);
548 uint32_t pointer_watcher_id2 = setup.GetPointerWatcherId();
549
550 // Simulate the server sending an observed event that matched the old watcher
551 // (e.g. that was in-flight when the observer was replaced).
552 std::unique_ptr<ui::PointerEvent> pointer_event_down(new ui::PointerEvent(
553 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), ui::EF_CONTROL_DOWN, 1,
554 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH),
555 base::TimeTicks()));
556 setup.window_tree_client()->OnPointerEventObserved(
557 std::move(pointer_event_down), pointer_watcher_id1, 0u);
558
559 // The event was not sensed, because it does not match the current watcher.
560 EXPECT_FALSE(setup.window_tree_delegate()->last_event_observed());
561
562 // Simulate another event that matches the new watcher.
563 std::unique_ptr<ui::PointerEvent> pointer_event_move(new ui::PointerEvent(
564 ui::ET_POINTER_MOVED, gfx::Point(), gfx::Point(), ui::EF_CONTROL_DOWN, 1,
565 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH),
566 base::TimeTicks()));
567 setup.window_tree_client()->OnPointerEventObserved(
568 std::move(pointer_event_move), pointer_watcher_id2, 0u);
569
570 // The delegate sensed the event.
571 ui::Event* last_event = setup.window_tree_delegate()->last_event_observed();
572 EXPECT_EQ(ui::ET_POINTER_MOVED, last_event->type());
573 EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags());
574 }
575
576 // Verifies focus is reverted if the server replied that the change failed. 529 // Verifies focus is reverted if the server replied that the change failed.
577 TEST_F(WindowTreeClientTest, SetFocusFailed) { 530 TEST_F(WindowTreeClientTest, SetFocusFailed) {
578 WindowTreeSetup setup; 531 WindowTreeSetup setup;
579 Window* root = setup.GetFirstRoot(); 532 Window* root = setup.GetFirstRoot();
580 ASSERT_TRUE(root); 533 ASSERT_TRUE(root);
581 root->SetVisible(true); 534 root->SetVisible(true);
582 Window* child = setup.client()->NewWindow(); 535 Window* child = setup.client()->NewWindow();
583 child->SetVisible(true); 536 child->SetVisible(true);
584 root->AddChild(child); 537 root->AddChild(child);
585 Window* original_focus = setup.client()->GetFocusedWindow(); 538 Window* original_focus = setup.client()->GetFocusedWindow();
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 1075
1123 // Changes originating from server should notify observers too. 1076 // Changes originating from server should notify observers too.
1124 WindowTreeClientPrivate(setup.client()).CallOnCaptureChanged(child2, nullptr); 1077 WindowTreeClientPrivate(setup.client()).CallOnCaptureChanged(child2, nullptr);
1125 EXPECT_EQ(1, capture_recorder.capture_changed_count()); 1078 EXPECT_EQ(1, capture_recorder.capture_changed_count());
1126 EXPECT_EQ(child2_id, capture_recorder.last_gained_capture_window_id()); 1079 EXPECT_EQ(child2_id, capture_recorder.last_gained_capture_window_id());
1127 EXPECT_EQ(0, capture_recorder.last_lost_capture_window_id()); 1080 EXPECT_EQ(0, capture_recorder.last_lost_capture_window_id());
1128 capture_recorder.reset_capture_captured_count(); 1081 capture_recorder.reset_capture_captured_count();
1129 } 1082 }
1130 1083
1131 } // namespace ui 1084 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698