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. | |
1079 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), NULL)); | |
1080 OnMouseExitDeletingEventFilter* w1_filter = | |
sky
2013/10/09 13:12:44
Does this leak?
mohsen
2013/10/09 15:12:31
SetEventFilter will pass the ownership of event fi
| |
1081 new OnMouseExitDeletingEventFilter(); | |
1082 w1->SetEventFilter(w1_filter); | |
1083 w1->SetBounds(gfx::Rect(20, 20, 60, 60)); | |
1084 EXPECT_EQ(NULL, root_window()->mouse_moved_handler()); | |
1085 | |
1086 test::EventGenerator generator(root_window(), w1.get()); | |
1087 | |
1088 // Move mouse over window 1 to set it as the |mouse_moved_handler_| for the | |
1089 // root window. | |
1090 generator.MoveMouseTo(51, 51); | |
1091 EXPECT_EQ(w1.get(), root_window()->mouse_moved_handler()); | |
1092 | |
1093 // Create window 2 under the mouse cursor and stack it above window 1. | |
1094 Window* w2 = CreateNormalWindow(2, root_window(), NULL); | |
1095 w2->SetBounds(gfx::Rect(30, 30, 40, 40)); | |
1096 root_window()->StackChildAbove(w2, w1.get()); | |
1097 | |
1098 // Set window 2 as the window that is to be deleted when a mouse-exited event | |
1099 // happens on window 1. | |
1100 w1_filter->set_window_to_delete(w2); | |
1101 | |
1102 // Move mosue over window 2. This should generate a mouse-exited event for | |
1103 // window 1 resulting in deletion of window 2. The original mouse-moved event | |
1104 // that was targeted to window 2 should be dropped since window 2 is | |
1105 // destroyed. This test passes if no crash happens. | |
1106 generator.MoveMouseTo(52, 52); | |
1107 EXPECT_EQ(NULL, root_window()->mouse_moved_handler()); | |
1108 | |
1109 // Check events received by window 1. | |
1110 EXPECT_EQ("MOUSE_ENTERED MOUSE_MOVED MOUSE_EXITED", | |
1111 EventTypesToString(w1_filter->events())); | |
1112 } | |
1113 | |
1050 } // namespace aura | 1114 } // namespace aura |
OLD | NEW |