OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/root_window.h" | 5 #include "ui/aura/root_window.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/aura/client/event_client.h" | 10 #include "ui/aura/client/event_client.h" |
(...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1040 } | 1040 } |
1041 | 1041 |
1042 // We expect two tap down events. One from the repost and the other one from | 1042 // We expect two tap down events. One from the repost and the other one from |
1043 // the scroll sequence posted above. | 1043 // the scroll sequence posted above. |
1044 EXPECT_EQ(tap_down_count, 2); | 1044 EXPECT_EQ(tap_down_count, 2); |
1045 | 1045 |
1046 EXPECT_EQ(kExpectedTargetEvents, | 1046 EXPECT_EQ(kExpectedTargetEvents, |
1047 EventTypesToString(repost_event_recorder->events())); | 1047 EventTypesToString(repost_event_recorder->events())); |
1048 } | 1048 } |
1049 | 1049 |
| 1050 class OnMouseExitDeletingEventFilter : public EventFilterRecorder { |
| 1051 public: |
| 1052 OnMouseExitDeletingEventFilter() : window_to_delete_(NULL) {} |
| 1053 virtual ~OnMouseExitDeletingEventFilter() {} |
| 1054 |
| 1055 void set_window_to_delete(Window* window_to_delete) { |
| 1056 window_to_delete_ = window_to_delete; |
| 1057 } |
| 1058 |
| 1059 private: |
| 1060 // Overridden from ui::EventHandler: |
| 1061 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { |
| 1062 EventFilterRecorder::OnMouseEvent(event); |
| 1063 if (window_to_delete_) { |
| 1064 delete window_to_delete_; |
| 1065 window_to_delete_ = NULL; |
| 1066 } |
| 1067 } |
| 1068 |
| 1069 Window* window_to_delete_; |
| 1070 |
| 1071 DISALLOW_COPY_AND_ASSIGN(OnMouseExitDeletingEventFilter); |
| 1072 }; |
| 1073 |
| 1074 // Tests that RootWindow drops mouse-moved event that is supposed to be sent to |
| 1075 // a child, but the child is destroyed because of the synthesized mouse-exit |
| 1076 // event generated on the previous mouse_moved_handler_. |
| 1077 TEST_F(RootWindowTest, DeleteWindowDuringMouseMovedDispatch) { |
| 1078 // Create window 1 and set its event filter. Window 1 will take ownership of |
| 1079 // the event filter. |
| 1080 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), NULL)); |
| 1081 OnMouseExitDeletingEventFilter* w1_filter = |
| 1082 new OnMouseExitDeletingEventFilter(); |
| 1083 w1->SetEventFilter(w1_filter); |
| 1084 w1->SetBounds(gfx::Rect(20, 20, 60, 60)); |
| 1085 EXPECT_EQ(NULL, root_window()->mouse_moved_handler()); |
| 1086 |
| 1087 test::EventGenerator generator(root_window(), w1.get()); |
| 1088 |
| 1089 // Move mouse over window 1 to set it as the |mouse_moved_handler_| for the |
| 1090 // root window. |
| 1091 generator.MoveMouseTo(51, 51); |
| 1092 EXPECT_EQ(w1.get(), root_window()->mouse_moved_handler()); |
| 1093 |
| 1094 // Create window 2 under the mouse cursor and stack it above window 1. |
| 1095 Window* w2 = CreateNormalWindow(2, root_window(), NULL); |
| 1096 w2->SetBounds(gfx::Rect(30, 30, 40, 40)); |
| 1097 root_window()->StackChildAbove(w2, w1.get()); |
| 1098 |
| 1099 // Set window 2 as the window that is to be deleted when a mouse-exited event |
| 1100 // happens on window 1. |
| 1101 w1_filter->set_window_to_delete(w2); |
| 1102 |
| 1103 // Move mosue over window 2. This should generate a mouse-exited event for |
| 1104 // window 1 resulting in deletion of window 2. The original mouse-moved event |
| 1105 // that was targeted to window 2 should be dropped since window 2 is |
| 1106 // destroyed. This test passes if no crash happens. |
| 1107 generator.MoveMouseTo(52, 52); |
| 1108 EXPECT_EQ(NULL, root_window()->mouse_moved_handler()); |
| 1109 |
| 1110 // Check events received by window 1. |
| 1111 EXPECT_EQ("MOUSE_ENTERED MOUSE_MOVED MOUSE_EXITED", |
| 1112 EventTypesToString(w1_filter->events())); |
| 1113 } |
| 1114 |
1050 } // namespace aura | 1115 } // namespace aura |
OLD | NEW |