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 "ash/wm/system_modal_container_layout_manager.h" | 5 #include "ash/wm/system_modal_container_layout_manager.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
10 #include "ash/wm/window_util.h" | 10 #include "ash/wm/window_util.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 TransientWindowObserver do1; | 134 TransientWindowObserver do1; |
135 t1->AddObserver(&do1); | 135 t1->AddObserver(&do1); |
136 | 136 |
137 EXPECT_EQ(parent.get(), t1->transient_parent()); | 137 EXPECT_EQ(parent.get(), t1->transient_parent()); |
138 EXPECT_EQ(GetModalContainer(), t1->parent()); | 138 EXPECT_EQ(GetModalContainer(), t1->parent()); |
139 | 139 |
140 // t1 should now be active. | 140 // t1 should now be active. |
141 EXPECT_TRUE(IsActiveWindow(t1)); | 141 EXPECT_TRUE(IsActiveWindow(t1)); |
142 | 142 |
143 // Attempting to click the parent should result in no activation change. | 143 // Attempting to click the parent should result in no activation change. |
144 aura::test::EventGenerator e1(parent.get()); | 144 aura::test::EventGenerator e1(Shell::GetRootWindow(), parent.get()); |
145 e1.ClickLeftButton(); | 145 e1.ClickLeftButton(); |
146 EXPECT_TRUE(IsActiveWindow(t1)); | 146 EXPECT_TRUE(IsActiveWindow(t1)); |
147 | 147 |
148 // Now open another modal transient parented to the original modal transient. | 148 // Now open another modal transient parented to the original modal transient. |
149 aura::Window* t2 = TestWindow::OpenTestWindow(t1, true); | 149 aura::Window* t2 = TestWindow::OpenTestWindow(t1, true); |
150 TransientWindowObserver do2; | 150 TransientWindowObserver do2; |
151 t2->AddObserver(&do2); | 151 t2->AddObserver(&do2); |
152 | 152 |
153 EXPECT_TRUE(IsActiveWindow(t2)); | 153 EXPECT_TRUE(IsActiveWindow(t2)); |
154 | 154 |
155 EXPECT_EQ(t1, t2->transient_parent()); | 155 EXPECT_EQ(t1, t2->transient_parent()); |
156 EXPECT_EQ(GetModalContainer(), t2->parent()); | 156 EXPECT_EQ(GetModalContainer(), t2->parent()); |
157 | 157 |
158 // t2 should still be active, even after clicking on t1. | 158 // t2 should still be active, even after clicking on t1. |
159 aura::test::EventGenerator e2(t1); | 159 aura::test::EventGenerator e2(Shell::GetRootWindow(), t1); |
160 e2.ClickLeftButton(); | 160 e2.ClickLeftButton(); |
161 EXPECT_TRUE(IsActiveWindow(t2)); | 161 EXPECT_TRUE(IsActiveWindow(t2)); |
162 | 162 |
163 // Both transients should be destroyed with parent. | 163 // Both transients should be destroyed with parent. |
164 parent.reset(); | 164 parent.reset(); |
165 EXPECT_TRUE(do1.destroyed()); | 165 EXPECT_TRUE(do1.destroyed()); |
166 EXPECT_TRUE(do2.destroyed()); | 166 EXPECT_TRUE(do2.destroyed()); |
167 } | 167 } |
168 | 168 |
169 // Fails on Mac only. Needs to be implemented. http://crbug.com/111279. | 169 // Fails on Mac only. Needs to be implemented. http://crbug.com/111279. |
(...skipping 12 matching lines...) Expand all Loading... |
182 scoped_ptr<aura::Window> parent(TestWindow::OpenTestWindow(NULL, false)); | 182 scoped_ptr<aura::Window> parent(TestWindow::OpenTestWindow(NULL, false)); |
183 // parent should be active. | 183 // parent should be active. |
184 EXPECT_TRUE(IsActiveWindow(parent.get())); | 184 EXPECT_TRUE(IsActiveWindow(parent.get())); |
185 | 185 |
186 scoped_ptr<aura::Window> transient( | 186 scoped_ptr<aura::Window> transient( |
187 TestWindow::OpenTestWindow(parent.get(), true)); | 187 TestWindow::OpenTestWindow(parent.get(), true)); |
188 // t1 should now be active. | 188 // t1 should now be active. |
189 EXPECT_TRUE(IsActiveWindow(transient.get())); | 189 EXPECT_TRUE(IsActiveWindow(transient.get())); |
190 | 190 |
191 // Attempting to click the parent should result in no activation change. | 191 // Attempting to click the parent should result in no activation change. |
192 aura::test::EventGenerator e1(parent.get()); | 192 aura::test::EventGenerator e1(Shell::GetRootWindow(), parent.get()); |
193 e1.ClickLeftButton(); | 193 e1.ClickLeftButton(); |
194 EXPECT_TRUE(IsActiveWindow(transient.get())); | 194 EXPECT_TRUE(IsActiveWindow(transient.get())); |
195 | 195 |
196 // Now close the transient. | 196 // Now close the transient. |
197 transient.reset(); | 197 transient.reset(); |
198 | 198 |
199 MessageLoopForUI::current()->RunAllPending(); | 199 MessageLoopForUI::current()->RunAllPending(); |
200 | 200 |
201 // parent should now be active again. | 201 // parent should now be active again. |
202 EXPECT_TRUE(IsActiveWindow(parent.get())); | 202 EXPECT_TRUE(IsActiveWindow(parent.get())); |
203 | 203 |
204 // Attempting to click unrelated should activate it. | 204 // Attempting to click unrelated should activate it. |
205 aura::test::EventGenerator e2(unrelated.get()); | 205 aura::test::EventGenerator e2(Shell::GetRootWindow(), unrelated.get()); |
206 e2.ClickLeftButton(); | 206 e2.ClickLeftButton(); |
207 EXPECT_TRUE(IsActiveWindow(unrelated.get())); | 207 EXPECT_TRUE(IsActiveWindow(unrelated.get())); |
208 } | 208 } |
209 | 209 |
210 TEST_F(SystemModalContainerLayoutManagerTest, | 210 TEST_F(SystemModalContainerLayoutManagerTest, |
211 EventFocusContainers) { | 211 EventFocusContainers) { |
212 // Create a normal window and attempt to receive a click event. | 212 // Create a normal window and attempt to receive a click event. |
213 EventTestWindow* main_delegate = new EventTestWindow(false); | 213 EventTestWindow* main_delegate = new EventTestWindow(false); |
214 scoped_ptr<aura::Window> main(main_delegate->OpenTestWindow(NULL)); | 214 scoped_ptr<aura::Window> main(main_delegate->OpenTestWindow(NULL)); |
215 EXPECT_TRUE(IsActiveWindow(main.get())); | 215 EXPECT_TRUE(IsActiveWindow(main.get())); |
216 aura::test::EventGenerator e1(main.get()); | 216 aura::test::EventGenerator e1(Shell::GetRootWindow(), main.get()); |
217 e1.ClickLeftButton(); | 217 e1.ClickLeftButton(); |
218 EXPECT_EQ(1, main_delegate->mouse_presses()); | 218 EXPECT_EQ(1, main_delegate->mouse_presses()); |
219 | 219 |
220 // Create a modal window for the main window and verify that the main window | 220 // Create a modal window for the main window and verify that the main window |
221 // no longer receives mouse events. | 221 // no longer receives mouse events. |
222 EventTestWindow* transient_delegate = new EventTestWindow(true); | 222 EventTestWindow* transient_delegate = new EventTestWindow(true); |
223 aura::Window* transient = transient_delegate->OpenTestWindow(main.get()); | 223 aura::Window* transient = transient_delegate->OpenTestWindow(main.get()); |
224 EXPECT_TRUE(IsActiveWindow(transient)); | 224 EXPECT_TRUE(IsActiveWindow(transient)); |
225 e1.ClickLeftButton(); | 225 e1.ClickLeftButton(); |
226 EXPECT_EQ(1, transient_delegate->mouse_presses()); | 226 EXPECT_EQ(1, transient_delegate->mouse_presses()); |
(...skipping 17 matching lines...) Expand all Loading... |
244 EXPECT_EQ(1, main_delegate->mouse_presses()); | 244 EXPECT_EQ(1, main_delegate->mouse_presses()); |
245 | 245 |
246 // Verify that none of the other containers received any more mouse presses. | 246 // Verify that none of the other containers received any more mouse presses. |
247 EXPECT_EQ(1, transient_delegate->mouse_presses()); | 247 EXPECT_EQ(1, transient_delegate->mouse_presses()); |
248 EXPECT_EQ(1, lock_delegate->mouse_presses()); | 248 EXPECT_EQ(1, lock_delegate->mouse_presses()); |
249 EXPECT_EQ(1, lock_modal_delegate->mouse_presses()); | 249 EXPECT_EQ(1, lock_modal_delegate->mouse_presses()); |
250 } | 250 } |
251 | 251 |
252 } // namespace test | 252 } // namespace test |
253 } // namespace ash | 253 } // namespace ash |
OLD | NEW |