OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/window_targeter.h" | 5 #include "ui/aura/window_targeter.h" |
6 | 6 |
7 #include "ui/aura/scoped_window_targeter.h" | 7 #include "ui/aura/scoped_window_targeter.h" |
8 #include "ui/aura/test/aura_test_base.h" | 8 #include "ui/aura/test/aura_test_base.h" |
9 #include "ui/aura/test/test_window_delegate.h" | 9 #include "ui/aura/test/test_window_delegate.h" |
10 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 EXPECT_EQ(window.get(), targeter->FindTargetForEvent(root, &mouse)); | 111 EXPECT_EQ(window.get(), targeter->FindTargetForEvent(root, &mouse)); |
112 } | 112 } |
113 scoped_targeter.reset(); | 113 scoped_targeter.reset(); |
114 { | 114 { |
115 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, | 115 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, |
116 ui::EF_NONE, ui::EF_NONE); | 116 ui::EF_NONE, ui::EF_NONE); |
117 EXPECT_EQ(child, targeter->FindTargetForEvent(root, &mouse)); | 117 EXPECT_EQ(child, targeter->FindTargetForEvent(root, &mouse)); |
118 } | 118 } |
119 } | 119 } |
120 | 120 |
| 121 // Test that ScopedWindowTargeter does not crash if the window for which it |
| 122 // replaces the targeter gets destroyed before it does. |
| 123 TEST_F(WindowTargeterTest, ScopedWindowTargeterWindowDestroyed) { |
| 124 test::TestWindowDelegate delegate; |
| 125 scoped_ptr<Window> window(CreateNormalWindow(1, root_window(), &delegate)); |
| 126 scoped_ptr<ScopedWindowTargeter> scoped_targeter( |
| 127 new ScopedWindowTargeter(window.get(), scoped_ptr<ui::EventTargeter>( |
| 128 new StaticWindowTargeter(window.get())))); |
| 129 |
| 130 window.reset(); |
| 131 scoped_targeter.reset(); |
| 132 |
| 133 // We did not crash! |
| 134 } |
| 135 |
121 TEST_F(WindowTargeterTest, TargetTransformedWindow) { | 136 TEST_F(WindowTargeterTest, TargetTransformedWindow) { |
122 root_window()->Show(); | 137 root_window()->Show(); |
123 | 138 |
124 test::TestWindowDelegate delegate; | 139 test::TestWindowDelegate delegate; |
125 scoped_ptr<Window> window(CreateNormalWindow(2, root_window(), &delegate)); | 140 scoped_ptr<Window> window(CreateNormalWindow(2, root_window(), &delegate)); |
126 | 141 |
127 const gfx::Rect window_bounds(100, 20, 400, 80); | 142 const gfx::Rect window_bounds(100, 20, 400, 80); |
128 window->SetBounds(window_bounds); | 143 window->SetBounds(window_bounds); |
129 | 144 |
130 ui::EventTarget* root_target = root_window(); | 145 ui::EventTarget* root_target = root_window(); |
(...skipping 25 matching lines...) Expand all Loading... |
156 EXPECT_EQ(gfx::RectF(300, 30, 200, 40).ToString(), | 171 EXPECT_EQ(gfx::RectF(300, 30, 200, 40).ToString(), |
157 GetEffectiveVisibleBoundsInRootWindow(window.get()).ToString()); | 172 GetEffectiveVisibleBoundsInRootWindow(window.get()).ToString()); |
158 { | 173 { |
159 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, | 174 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, |
160 ui::EF_NONE, ui::EF_NONE); | 175 ui::EF_NONE, ui::EF_NONE); |
161 EXPECT_EQ(window.get(), targeter->FindTargetForEvent(root_target, &mouse)); | 176 EXPECT_EQ(window.get(), targeter->FindTargetForEvent(root_target, &mouse)); |
162 } | 177 } |
163 } | 178 } |
164 | 179 |
165 } // namespace aura | 180 } // namespace aura |
OLD | NEW |