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

Side by Side Diff: ui/aura/mus/window_tree_client_unittest.cc

Issue 2779093004: Update event states in Env when target window has been destroyed. (Closed)
Patch Set: get EnvInputStateController from Env Created 3 years, 7 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 | « ui/aura/mus/window_tree_client.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ui/aura/mus/window_tree_client.h" 5 #include "ui/aura/mus/window_tree_client.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 658
659 namespace { 659 namespace {
660 660
661 class InputEventBasicTestWindowDelegate : public test::TestWindowDelegate { 661 class InputEventBasicTestWindowDelegate : public test::TestWindowDelegate {
662 public: 662 public:
663 explicit InputEventBasicTestWindowDelegate(TestWindowTree* test_window_tree) 663 explicit InputEventBasicTestWindowDelegate(TestWindowTree* test_window_tree)
664 : test_window_tree_(test_window_tree) {} 664 : test_window_tree_(test_window_tree) {}
665 ~InputEventBasicTestWindowDelegate() override {} 665 ~InputEventBasicTestWindowDelegate() override {}
666 666
667 bool got_move() const { return got_move_; } 667 bool got_move() const { return got_move_; }
668 bool got_press() const { return got_press_; }
669 bool got_release() const { return got_release_; }
668 bool was_acked() const { return was_acked_; } 670 bool was_acked() const { return was_acked_; }
669 const gfx::Point& last_event_location() const { return last_event_location_; } 671 const gfx::Point& last_event_location() const { return last_event_location_; }
670 void set_event_id(uint32_t event_id) { event_id_ = event_id; } 672 void set_event_id(uint32_t event_id) { event_id_ = event_id; }
671 673
672 // TestWindowDelegate:: 674 // TestWindowDelegate::
673 void OnMouseEvent(ui::MouseEvent* event) override { 675 void OnMouseEvent(ui::MouseEvent* event) override {
674 was_acked_ = test_window_tree_->WasEventAcked(event_id_); 676 was_acked_ = test_window_tree_->WasEventAcked(event_id_);
675 if (event->type() == ui::ET_MOUSE_MOVED) 677 if (event->type() == ui::ET_MOUSE_MOVED)
676 got_move_ = true; 678 got_move_ = true;
679 else if (event->type() == ui::ET_MOUSE_PRESSED)
680 got_press_ = true;
681 else if (event->type() == ui::ET_MOUSE_RELEASED)
682 got_release_ = true;
677 last_event_location_ = event->location(); 683 last_event_location_ = event->location();
678 event->SetHandled(); 684 event->SetHandled();
679 } 685 }
686
687 void OnTouchEvent(ui::TouchEvent* event) override {
688 was_acked_ = test_window_tree_->WasEventAcked(event_id_);
689 if (event->type() == ui::ET_TOUCH_PRESSED)
690 got_press_ = true;
691 else if (event->type() == ui::ET_TOUCH_RELEASED)
692 got_release_ = true;
693 last_event_location_ = event->location();
694 event->SetHandled();
695 }
680 696
681 void reset() { 697 void reset() {
682 was_acked_ = false; 698 was_acked_ = false;
683 got_move_ = false; 699 got_move_ = false;
700 got_press_ = false;
701 got_release_ = false;
684 last_event_location_ = gfx::Point(); 702 last_event_location_ = gfx::Point();
685 event_id_ = 0; 703 event_id_ = 0;
686 } 704 }
687 705
688 private: 706 private:
689 TestWindowTree* test_window_tree_; 707 TestWindowTree* test_window_tree_;
690 bool was_acked_ = false; 708 bool was_acked_ = false;
691 bool got_move_ = false; 709 bool got_move_ = false;
710 bool got_press_ = false;
711 bool got_release_ = false;
692 gfx::Point last_event_location_; 712 gfx::Point last_event_location_;
693 uint32_t event_id_ = 0; 713 uint32_t event_id_ = 0;
694 714
695 DISALLOW_COPY_AND_ASSIGN(InputEventBasicTestWindowDelegate); 715 DISALLOW_COPY_AND_ASSIGN(InputEventBasicTestWindowDelegate);
696 }; 716 };
697 717
698 class InputEventBasicTestEventHandler : public ui::test::TestEventHandler { 718 class InputEventBasicTestEventHandler : public ui::test::TestEventHandler {
699 public: 719 public:
700 InputEventBasicTestEventHandler() {} 720 explicit InputEventBasicTestEventHandler(Window* target_window)
721 : target_window_(target_window) {}
701 ~InputEventBasicTestEventHandler() override {} 722 ~InputEventBasicTestEventHandler() override {}
702 723
703 bool got_move() const { return got_move_; } 724 bool got_move() const { return got_move_; }
704 const gfx::Point& last_event_location() const { return last_event_location_; } 725 const gfx::Point& last_event_location() const { return last_event_location_; }
705 void set_event_id(uint32_t event_id) { event_id_ = event_id; } 726 void set_event_id(uint32_t event_id) { event_id_ = event_id; }
706 727
707 // ui::test::TestEventHandler overrides. 728 // ui::test::TestEventHandler overrides.
708 void OnMouseEvent(ui::MouseEvent* event) override { 729 void OnMouseEvent(ui::MouseEvent* event) override {
709 if (event->type() == ui::ET_MOUSE_MOVED) 730 if (event->target() == target_window_) {
710 got_move_ = true; 731 if (event->type() == ui::ET_MOUSE_MOVED)
711 last_event_location_ = event->location(); 732 got_move_ = true;
712 event->SetHandled(); 733 last_event_location_ = event->location();
734 event->SetHandled();
735 }
713 } 736 }
714 737
715 void reset() { 738 void reset() {
716 got_move_ = false; 739 got_move_ = false;
717 last_event_location_ = gfx::Point(); 740 last_event_location_ = gfx::Point();
718 event_id_ = 0; 741 event_id_ = 0;
719 } 742 }
720 743
721 private: 744 private:
745 Window* target_window_ = nullptr;
722 bool got_move_ = false; 746 bool got_move_ = false;
723 gfx::Point last_event_location_; 747 gfx::Point last_event_location_;
724 uint32_t event_id_ = 0; 748 uint32_t event_id_ = 0;
725 749
726 DISALLOW_COPY_AND_ASSIGN(InputEventBasicTestEventHandler); 750 DISALLOW_COPY_AND_ASSIGN(InputEventBasicTestEventHandler);
727 }; 751 };
728 752
729 } // namespace 753 } // namespace
730 754
731 TEST_F(WindowTreeClientClientTest, InputEventBasic) { 755 TEST_F(WindowTreeClientClientTest, InputEventBasic) {
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 child2.reset(); 1028 child2.reset();
1005 child1.reset(); 1029 child1.reset();
1006 window_tree_host.reset(); 1030 window_tree_host.reset();
1007 capture_client.reset(); 1031 capture_client.reset();
1008 } 1032 }
1009 1033
1010 TEST_F(WindowTreeClientClientTest, InputEventRootWindow) { 1034 TEST_F(WindowTreeClientClientTest, InputEventRootWindow) {
1011 WindowTreeHostMus window_tree_host( 1035 WindowTreeHostMus window_tree_host(
1012 CreateInitParamsForTopLevel(window_tree_client_impl())); 1036 CreateInitParamsForTopLevel(window_tree_client_impl()));
1013 Window* top_level = window_tree_host.window(); 1037 Window* top_level = window_tree_host.window();
1014 InputEventBasicTestEventHandler root_handler; 1038 InputEventBasicTestEventHandler root_handler(top_level);
1015 top_level->AddPreTargetHandler(&root_handler); 1039 top_level->AddPreTargetHandler(&root_handler);
1016 const gfx::Rect bounds(0, 0, 100, 100); 1040 const gfx::Rect bounds(0, 0, 100, 100);
1017 window_tree_host.SetBoundsInPixels(bounds); 1041 window_tree_host.SetBoundsInPixels(bounds);
1018 window_tree_host.InitHost(); 1042 window_tree_host.InitHost();
1019 window_tree_host.Show(); 1043 window_tree_host.Show();
1020 EXPECT_EQ(bounds, top_level->bounds()); 1044 EXPECT_EQ(bounds, top_level->bounds());
1021 EXPECT_EQ(bounds, window_tree_host.GetBoundsInPixels()); 1045 EXPECT_EQ(bounds, window_tree_host.GetBoundsInPixels());
1022 InputEventBasicTestWindowDelegate child_delegate(window_tree()); 1046 InputEventBasicTestWindowDelegate child_delegate(window_tree());
1023 Window child(&child_delegate); 1047 Window child(&child_delegate);
1024 child.Init(ui::LAYER_NOT_DRAWN); 1048 child.Init(ui::LAYER_NOT_DRAWN);
(...skipping 17 matching lines...) Expand all
1042 1066
1043 EXPECT_TRUE(window_tree()->WasEventAcked(event_id)); 1067 EXPECT_TRUE(window_tree()->WasEventAcked(event_id));
1044 EXPECT_EQ(ui::mojom::EventResult::HANDLED, 1068 EXPECT_EQ(ui::mojom::EventResult::HANDLED,
1045 window_tree()->GetEventResult(event_id)); 1069 window_tree()->GetEventResult(event_id));
1046 EXPECT_TRUE(root_handler.got_move()); 1070 EXPECT_TRUE(root_handler.got_move());
1047 EXPECT_EQ(gfx::Point(20, 30), root_handler.last_event_location()); 1071 EXPECT_EQ(gfx::Point(20, 30), root_handler.last_event_location());
1048 EXPECT_FALSE(child_delegate.got_move()); 1072 EXPECT_FALSE(child_delegate.got_move());
1049 EXPECT_EQ(gfx::Point(), child_delegate.last_event_location()); 1073 EXPECT_EQ(gfx::Point(), child_delegate.last_event_location());
1050 } 1074 }
1051 1075
1076 TEST_F(WindowTreeClientClientTest, InputMouseEventNoWindow) {
1077 Env* env = Env::GetInstance();
1078 InputEventBasicTestWindowDelegate window_delegate(window_tree());
1079 WindowTreeHostMus window_tree_host(
1080 CreateInitParamsForTopLevel(window_tree_client_impl()));
1081 Window* top_level = window_tree_host.window();
1082 const gfx::Rect bounds(0, 0, 100, 100);
1083 window_tree_host.SetBoundsInPixels(bounds);
1084 window_tree_host.InitHost();
1085 window_tree_host.Show();
1086 EXPECT_EQ(bounds, top_level->bounds());
1087 EXPECT_EQ(bounds, window_tree_host.GetBoundsInPixels());
1088 Window child(&window_delegate);
1089 child.Init(ui::LAYER_NOT_DRAWN);
1090 top_level->AddChild(&child);
1091 child.SetBounds(gfx::Rect(10, 10, 100, 100));
1092 child.Show();
1093
1094 EXPECT_FALSE(window_delegate.got_press());
1095 EXPECT_FALSE(env->IsMouseButtonDown());
1096 EXPECT_FALSE(env->mouse_button_flags());
1097 EXPECT_EQ(gfx::Point(), env->last_mouse_location());
1098
1099 const gfx::Point event_location(2, 3);
1100 uint32_t event_id = 1;
1101 window_delegate.set_event_id(event_id);
1102 ui::PointerEvent pointer_event_down(
1103 ui::ET_POINTER_DOWN, event_location, gfx::Point(),
1104 ui::EF_LEFT_MOUSE_BUTTON, 0,
1105 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE, 0),
1106 ui::EventTimeForNow());
1107 window_tree_client()->OnWindowInputEvent(
1108 event_id, server_id(&child), window_tree_host.display_id(),
1109 ui::Event::Clone(pointer_event_down), 0);
1110 EXPECT_TRUE(window_tree()->WasEventAcked(event_id));
1111 EXPECT_EQ(ui::mojom::EventResult::HANDLED,
1112 window_tree()->GetEventResult(event_id));
1113 EXPECT_TRUE(window_delegate.got_press());
1114 EXPECT_TRUE(env->IsMouseButtonDown());
1115 EXPECT_EQ(1024, env->mouse_button_flags()); // ui::EF_LEFT_MOUSE_BUTTON
1116 EXPECT_EQ(event_location, env->last_mouse_location());
1117 window_delegate.reset();
1118
1119 const gfx::Point event_location1(4, 5);
1120 event_id = 2;
1121 window_delegate.set_event_id(event_id);
1122 ui::PointerEvent pointer_event_up(
1123 ui::ET_POINTER_UP, event_location1, gfx::Point(),
1124 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON,
1125 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE, 0),
1126 ui::EventTimeForNow());
1127 window_tree_client()->OnWindowInputEvent(
1128 event_id, kInvalidServerId, window_tree_host.display_id(),
1129 ui::Event::Clone(pointer_event_up), 0);
1130 EXPECT_TRUE(window_tree()->WasEventAcked(event_id));
1131 // WindowTreeClient::OnWindowInputEvent cannot find a target window with
1132 // kInvalidServerId but should use the event to update event states kept in
1133 // aura::Env, location shouldn't be updated.
1134 EXPECT_EQ(ui::mojom::EventResult::UNHANDLED,
1135 window_tree()->GetEventResult(event_id));
1136 EXPECT_FALSE(window_delegate.got_release());
1137 EXPECT_FALSE(env->IsMouseButtonDown());
1138 EXPECT_FALSE(env->mouse_button_flags());
1139 EXPECT_EQ(event_location, env->last_mouse_location());
1140 }
1141
1142 TEST_F(WindowTreeClientClientTest, InputTouchEventNoWindow) {
1143 Env* env = Env::GetInstance();
1144 InputEventBasicTestWindowDelegate window_delegate(window_tree());
1145 WindowTreeHostMus window_tree_host(
1146 CreateInitParamsForTopLevel(window_tree_client_impl()));
1147 Window* top_level = window_tree_host.window();
1148 const gfx::Rect bounds(0, 0, 100, 100);
1149 window_tree_host.SetBoundsInPixels(bounds);
1150 window_tree_host.InitHost();
1151 window_tree_host.Show();
1152 EXPECT_EQ(bounds, top_level->bounds());
1153 EXPECT_EQ(bounds, window_tree_host.GetBoundsInPixels());
1154 Window child(&window_delegate);
1155 child.Init(ui::LAYER_NOT_DRAWN);
1156 top_level->AddChild(&child);
1157 child.SetBounds(gfx::Rect(10, 10, 100, 100));
1158 child.Show();
1159
1160 EXPECT_FALSE(window_delegate.got_press());
1161 EXPECT_FALSE(env->is_touch_down());
1162
1163 const gfx::Point event_location(2, 3);
1164 uint32_t event_id = 1;
1165 window_delegate.set_event_id(event_id);
1166 ui::PointerEvent pointer_event_down(
1167 ui::ET_POINTER_DOWN, event_location, gfx::Point(), 0, 0,
1168 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0),
1169 ui::EventTimeForNow());
1170 window_tree_client()->OnWindowInputEvent(
1171 event_id, server_id(&child), window_tree_host.display_id(),
1172 ui::Event::Clone(pointer_event_down), 0);
1173 EXPECT_TRUE(window_tree()->WasEventAcked(event_id));
1174 EXPECT_EQ(ui::mojom::EventResult::HANDLED,
1175 window_tree()->GetEventResult(event_id));
1176 EXPECT_TRUE(window_delegate.got_press());
1177 EXPECT_TRUE(env->is_touch_down());
1178 window_delegate.reset();
1179
1180 event_id = 2;
1181 window_delegate.set_event_id(event_id);
1182 ui::PointerEvent pointer_event_up(
1183 ui::ET_POINTER_UP, event_location, gfx::Point(), 0, 0,
1184 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0),
1185 ui::EventTimeForNow());
1186 window_tree_client()->OnWindowInputEvent(
1187 event_id, kInvalidServerId, window_tree_host.display_id(),
1188 ui::Event::Clone(pointer_event_up), 0);
1189 EXPECT_TRUE(window_tree()->WasEventAcked(event_id));
1190 // WindowTreeClient::OnWindowInputEvent cannot find a target window with
1191 // kInvalidServerId but should use the event to update event states kept in
1192 // aura::Env.
1193 EXPECT_EQ(ui::mojom::EventResult::UNHANDLED,
1194 window_tree()->GetEventResult(event_id));
1195 EXPECT_FALSE(window_delegate.got_release());
1196 EXPECT_FALSE(env->is_touch_down());
1197 }
1198
1052 class WindowTreeClientPointerObserverTest : public WindowTreeClientClientTest { 1199 class WindowTreeClientPointerObserverTest : public WindowTreeClientClientTest {
1053 public: 1200 public:
1054 WindowTreeClientPointerObserverTest() {} 1201 WindowTreeClientPointerObserverTest() {}
1055 ~WindowTreeClientPointerObserverTest() override {} 1202 ~WindowTreeClientPointerObserverTest() override {}
1056 1203
1057 void DeleteLastEventObserved() { last_event_observed_.reset(); } 1204 void DeleteLastEventObserved() { last_event_observed_.reset(); }
1058 const ui::PointerEvent* last_event_observed() const { 1205 const ui::PointerEvent* last_event_observed() const {
1059 return last_event_observed_.get(); 1206 return last_event_observed_.get();
1060 } 1207 }
1061 1208
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 window_tree_client()->OnPointerEventObserved(std::move(pointer_event_up), 0u, 1256 window_tree_client()->OnPointerEventObserved(std::move(pointer_event_up), 0u,
1110 0); 1257 0);
1111 1258
1112 // No event was sensed. 1259 // No event was sensed.
1113 EXPECT_FALSE(last_event_observed()); 1260 EXPECT_FALSE(last_event_observed());
1114 } 1261 }
1115 1262
1116 // Tests pointer watchers triggered by events that hit this window tree. 1263 // Tests pointer watchers triggered by events that hit this window tree.
1117 TEST_F(WindowTreeClientPointerObserverTest, 1264 TEST_F(WindowTreeClientPointerObserverTest,
1118 OnWindowInputEventWithPointerWatcher) { 1265 OnWindowInputEventWithPointerWatcher) {
1119 std::unique_ptr<Window> top_level(base::MakeUnique<Window>(nullptr)); 1266 WindowTreeHostMus window_tree_host(
1120 top_level->SetType(ui::wm::WINDOW_TYPE_NORMAL); 1267 CreateInitParamsForTopLevel(window_tree_client_impl()));
1121 top_level->Init(ui::LAYER_NOT_DRAWN); 1268 Window* top_level = window_tree_host.window();
1122 top_level->SetBounds(gfx::Rect(0, 0, 100, 100)); 1269 const gfx::Rect bounds(0, 0, 100, 100);
1123 top_level->Show(); 1270 window_tree_host.SetBoundsInPixels(bounds);
1271 window_tree_host.InitHost();
1272 window_tree_host.Show();
1273 EXPECT_EQ(bounds, top_level->bounds());
1124 1274
1125 // Start a pointer watcher for all events excluding move events. 1275 // Start a pointer watcher for all events excluding move events.
1126 window_tree_client_impl()->StartPointerWatcher(false /* want_moves */); 1276 window_tree_client_impl()->StartPointerWatcher(false /* want_moves */);
1127 1277
1128 // Simulate the server dispatching an event that also matched the observer. 1278 // Simulate the server dispatching an event that also matched the observer.
1129 std::unique_ptr<ui::PointerEvent> pointer_event_down(new ui::PointerEvent( 1279 std::unique_ptr<ui::PointerEvent> pointer_event_down(new ui::PointerEvent(
1130 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), ui::EF_CONTROL_DOWN, 0, 1280 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), ui::EF_CONTROL_DOWN, 0,
1131 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1), 1281 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1),
1132 base::TimeTicks::Now())); 1282 base::TimeTicks::Now()));
1133 window_tree_client()->OnWindowInputEvent(1, server_id(top_level.get()), 0, 1283 window_tree_client()->OnWindowInputEvent(1, server_id(top_level), 0,
1134 std::move(pointer_event_down), true); 1284 std::move(pointer_event_down), true);
1135 1285
1136 // Delegate sensed the event. 1286 // Delegate sensed the event.
1137 const ui::Event* last_event = last_event_observed(); 1287 const ui::Event* last_event = last_event_observed();
1138 ASSERT_TRUE(last_event); 1288 ASSERT_TRUE(last_event);
1139 EXPECT_EQ(ui::ET_POINTER_DOWN, last_event->type()); 1289 EXPECT_EQ(ui::ET_POINTER_DOWN, last_event->type());
1140 EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags()); 1290 EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags());
1141 } 1291 }
1142 1292
1143 // Verifies focus is reverted if the server replied that the change failed. 1293 // Verifies focus is reverted if the server replied that the change failed.
(...skipping 1110 matching lines...) Expand 10 before | Expand all | Expand 10 after
2254 window_tree()->GetEventResult(event_id)); 2404 window_tree()->GetEventResult(event_id));
2255 EXPECT_TRUE(window_delegate1.got_move()); 2405 EXPECT_TRUE(window_delegate1.got_move());
2256 EXPECT_FALSE(window_delegate2.got_move()); 2406 EXPECT_FALSE(window_delegate2.got_move());
2257 gfx::Point transformed_event_location_in_dip(event_location_in_dip.x() + 20, 2407 gfx::Point transformed_event_location_in_dip(event_location_in_dip.x() + 20,
2258 event_location_in_dip.y() + 30); 2408 event_location_in_dip.y() + 30);
2259 EXPECT_EQ(transformed_event_location_in_dip, 2409 EXPECT_EQ(transformed_event_location_in_dip,
2260 window_delegate1.last_event_location()); 2410 window_delegate1.last_event_location());
2261 } 2411 }
2262 2412
2263 } // namespace aura 2413 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/mus/window_tree_client.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698