| 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/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
| 8 #include "ash/session/session_state_delegate.h" | 8 #include "ash/session/session_state_delegate.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
| 11 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
| 12 #include "ash/wm/window_util.h" | 12 #include "ash/wm/window_util.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "ui/aura/test/event_generator.h" | |
| 17 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 18 #include "ui/aura/window_event_dispatcher.h" | 17 #include "ui/aura/window_event_dispatcher.h" |
| 19 #include "ui/compositor/layer.h" | 18 #include "ui/compositor/layer.h" |
| 20 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 19 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
| 21 #include "ui/compositor/test/layer_animator_test_controller.h" | 20 #include "ui/compositor/test/layer_animator_test_controller.h" |
| 21 #include "ui/events/test/event_generator.h" |
| 22 #include "ui/gfx/screen.h" | 22 #include "ui/gfx/screen.h" |
| 23 #include "ui/keyboard/keyboard_controller.h" | 23 #include "ui/keyboard/keyboard_controller.h" |
| 24 #include "ui/keyboard/keyboard_controller_proxy.h" | 24 #include "ui/keyboard/keyboard_controller_proxy.h" |
| 25 #include "ui/keyboard/keyboard_switches.h" | 25 #include "ui/keyboard/keyboard_switches.h" |
| 26 #include "ui/keyboard/keyboard_util.h" | 26 #include "ui/keyboard/keyboard_util.h" |
| 27 #include "ui/views/test/capture_tracking_view.h" | 27 #include "ui/views/test/capture_tracking_view.h" |
| 28 #include "ui/views/widget/widget.h" | 28 #include "ui/views/widget/widget.h" |
| 29 #include "ui/views/widget/widget_delegate.h" | 29 #include "ui/views/widget/widget_delegate.h" |
| 30 #include "ui/wm/core/window_util.h" | 30 #include "ui/wm/core/window_util.h" |
| 31 | 31 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 TransientWindowObserver do1; | 223 TransientWindowObserver do1; |
| 224 t1->AddObserver(&do1); | 224 t1->AddObserver(&do1); |
| 225 | 225 |
| 226 EXPECT_EQ(parent.get(), ::wm::GetTransientParent(t1)); | 226 EXPECT_EQ(parent.get(), ::wm::GetTransientParent(t1)); |
| 227 EXPECT_EQ(GetModalContainer(), t1->parent()); | 227 EXPECT_EQ(GetModalContainer(), t1->parent()); |
| 228 | 228 |
| 229 // t1 should now be active. | 229 // t1 should now be active. |
| 230 EXPECT_TRUE(wm::IsActiveWindow(t1)); | 230 EXPECT_TRUE(wm::IsActiveWindow(t1)); |
| 231 | 231 |
| 232 // Attempting to click the parent should result in no activation change. | 232 // Attempting to click the parent should result in no activation change. |
| 233 aura::test::EventGenerator e1(Shell::GetPrimaryRootWindow(), parent.get()); | 233 ui::test::EventGenerator e1(Shell::GetPrimaryRootWindow(), parent.get()); |
| 234 e1.ClickLeftButton(); | 234 e1.ClickLeftButton(); |
| 235 EXPECT_TRUE(wm::IsActiveWindow(t1)); | 235 EXPECT_TRUE(wm::IsActiveWindow(t1)); |
| 236 | 236 |
| 237 // Now open another modal transient parented to the original modal transient. | 237 // Now open another modal transient parented to the original modal transient. |
| 238 aura::Window* t2 = OpenTestWindowWithParent(t1, true); | 238 aura::Window* t2 = OpenTestWindowWithParent(t1, true); |
| 239 TransientWindowObserver do2; | 239 TransientWindowObserver do2; |
| 240 t2->AddObserver(&do2); | 240 t2->AddObserver(&do2); |
| 241 | 241 |
| 242 EXPECT_TRUE(wm::IsActiveWindow(t2)); | 242 EXPECT_TRUE(wm::IsActiveWindow(t2)); |
| 243 | 243 |
| 244 EXPECT_EQ(t1, ::wm::GetTransientParent(t2)); | 244 EXPECT_EQ(t1, ::wm::GetTransientParent(t2)); |
| 245 EXPECT_EQ(GetModalContainer(), t2->parent()); | 245 EXPECT_EQ(GetModalContainer(), t2->parent()); |
| 246 | 246 |
| 247 // t2 should still be active, even after clicking on t1. | 247 // t2 should still be active, even after clicking on t1. |
| 248 aura::test::EventGenerator e2(Shell::GetPrimaryRootWindow(), t1); | 248 ui::test::EventGenerator e2(Shell::GetPrimaryRootWindow(), t1); |
| 249 e2.ClickLeftButton(); | 249 e2.ClickLeftButton(); |
| 250 EXPECT_TRUE(wm::IsActiveWindow(t2)); | 250 EXPECT_TRUE(wm::IsActiveWindow(t2)); |
| 251 | 251 |
| 252 // Both transients should be destroyed with parent. | 252 // Both transients should be destroyed with parent. |
| 253 parent.reset(); | 253 parent.reset(); |
| 254 EXPECT_TRUE(do1.destroyed()); | 254 EXPECT_TRUE(do1.destroyed()); |
| 255 EXPECT_TRUE(do2.destroyed()); | 255 EXPECT_TRUE(do2.destroyed()); |
| 256 } | 256 } |
| 257 | 257 |
| 258 TEST_F(SystemModalContainerLayoutManagerTest, ModalNonTransient) { | 258 TEST_F(SystemModalContainerLayoutManagerTest, ModalNonTransient) { |
| 259 scoped_ptr<aura::Window> t1(OpenToplevelTestWindow(true)); | 259 scoped_ptr<aura::Window> t1(OpenToplevelTestWindow(true)); |
| 260 // parent should be active. | 260 // parent should be active. |
| 261 EXPECT_TRUE(wm::IsActiveWindow(t1.get())); | 261 EXPECT_TRUE(wm::IsActiveWindow(t1.get())); |
| 262 TransientWindowObserver do1; | 262 TransientWindowObserver do1; |
| 263 t1->AddObserver(&do1); | 263 t1->AddObserver(&do1); |
| 264 | 264 |
| 265 EXPECT_EQ(NULL, ::wm::GetTransientParent(t1.get())); | 265 EXPECT_EQ(NULL, ::wm::GetTransientParent(t1.get())); |
| 266 EXPECT_EQ(GetModalContainer(), t1->parent()); | 266 EXPECT_EQ(GetModalContainer(), t1->parent()); |
| 267 | 267 |
| 268 // t1 should now be active. | 268 // t1 should now be active. |
| 269 EXPECT_TRUE(wm::IsActiveWindow(t1.get())); | 269 EXPECT_TRUE(wm::IsActiveWindow(t1.get())); |
| 270 | 270 |
| 271 // Attempting to click the parent should result in no activation change. | 271 // Attempting to click the parent should result in no activation change. |
| 272 aura::test::EventGenerator e1(Shell::GetPrimaryRootWindow(), | 272 ui::test::EventGenerator e1(Shell::GetPrimaryRootWindow(), |
| 273 Shell::GetPrimaryRootWindow()); | 273 Shell::GetPrimaryRootWindow()); |
| 274 e1.ClickLeftButton(); | 274 e1.ClickLeftButton(); |
| 275 EXPECT_TRUE(wm::IsActiveWindow(t1.get())); | 275 EXPECT_TRUE(wm::IsActiveWindow(t1.get())); |
| 276 | 276 |
| 277 // Now open another modal transient parented to the original modal transient. | 277 // Now open another modal transient parented to the original modal transient. |
| 278 aura::Window* t2 = OpenTestWindowWithParent(t1.get(), true); | 278 aura::Window* t2 = OpenTestWindowWithParent(t1.get(), true); |
| 279 TransientWindowObserver do2; | 279 TransientWindowObserver do2; |
| 280 t2->AddObserver(&do2); | 280 t2->AddObserver(&do2); |
| 281 | 281 |
| 282 EXPECT_TRUE(wm::IsActiveWindow(t2)); | 282 EXPECT_TRUE(wm::IsActiveWindow(t2)); |
| 283 | 283 |
| 284 EXPECT_EQ(t1, ::wm::GetTransientParent(t2)); | 284 EXPECT_EQ(t1, ::wm::GetTransientParent(t2)); |
| 285 EXPECT_EQ(GetModalContainer(), t2->parent()); | 285 EXPECT_EQ(GetModalContainer(), t2->parent()); |
| 286 | 286 |
| 287 // t2 should still be active, even after clicking on t1. | 287 // t2 should still be active, even after clicking on t1. |
| 288 aura::test::EventGenerator e2(Shell::GetPrimaryRootWindow(), t1.get()); | 288 ui::test::EventGenerator e2(Shell::GetPrimaryRootWindow(), t1.get()); |
| 289 e2.ClickLeftButton(); | 289 e2.ClickLeftButton(); |
| 290 EXPECT_TRUE(wm::IsActiveWindow(t2)); | 290 EXPECT_TRUE(wm::IsActiveWindow(t2)); |
| 291 | 291 |
| 292 // Both transients should be destroyed with parent. | 292 // Both transients should be destroyed with parent. |
| 293 t1.reset(); | 293 t1.reset(); |
| 294 EXPECT_TRUE(do1.destroyed()); | 294 EXPECT_TRUE(do1.destroyed()); |
| 295 EXPECT_TRUE(do2.destroyed()); | 295 EXPECT_TRUE(do2.destroyed()); |
| 296 } | 296 } |
| 297 | 297 |
| 298 // Tests that we can activate an unrelated window after a modal window is closed | 298 // Tests that we can activate an unrelated window after a modal window is closed |
| 299 // for a window. | 299 // for a window. |
| 300 TEST_F(SystemModalContainerLayoutManagerTest, CanActivateAfterEndModalSession) { | 300 TEST_F(SystemModalContainerLayoutManagerTest, CanActivateAfterEndModalSession) { |
| 301 scoped_ptr<aura::Window> unrelated(OpenToplevelTestWindow(false)); | 301 scoped_ptr<aura::Window> unrelated(OpenToplevelTestWindow(false)); |
| 302 unrelated->SetBounds(gfx::Rect(100, 100, 50, 50)); | 302 unrelated->SetBounds(gfx::Rect(100, 100, 50, 50)); |
| 303 scoped_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); | 303 scoped_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); |
| 304 // parent should be active. | 304 // parent should be active. |
| 305 EXPECT_TRUE(wm::IsActiveWindow(parent.get())); | 305 EXPECT_TRUE(wm::IsActiveWindow(parent.get())); |
| 306 | 306 |
| 307 scoped_ptr<aura::Window> transient( | 307 scoped_ptr<aura::Window> transient( |
| 308 OpenTestWindowWithParent(parent.get(), true)); | 308 OpenTestWindowWithParent(parent.get(), true)); |
| 309 // t1 should now be active. | 309 // t1 should now be active. |
| 310 EXPECT_TRUE(wm::IsActiveWindow(transient.get())); | 310 EXPECT_TRUE(wm::IsActiveWindow(transient.get())); |
| 311 | 311 |
| 312 // Attempting to click the parent should result in no activation change. | 312 // Attempting to click the parent should result in no activation change. |
| 313 aura::test::EventGenerator e1(Shell::GetPrimaryRootWindow(), parent.get()); | 313 ui::test::EventGenerator e1(Shell::GetPrimaryRootWindow(), parent.get()); |
| 314 e1.ClickLeftButton(); | 314 e1.ClickLeftButton(); |
| 315 EXPECT_TRUE(wm::IsActiveWindow(transient.get())); | 315 EXPECT_TRUE(wm::IsActiveWindow(transient.get())); |
| 316 | 316 |
| 317 // Now close the transient. | 317 // Now close the transient. |
| 318 transient->Hide(); | 318 transient->Hide(); |
| 319 TestWindow::CloseTestWindow(transient.release()); | 319 TestWindow::CloseTestWindow(transient.release()); |
| 320 | 320 |
| 321 base::RunLoop().RunUntilIdle(); | 321 base::RunLoop().RunUntilIdle(); |
| 322 | 322 |
| 323 // parent should now be active again. | 323 // parent should now be active again. |
| 324 EXPECT_TRUE(wm::IsActiveWindow(parent.get())); | 324 EXPECT_TRUE(wm::IsActiveWindow(parent.get())); |
| 325 | 325 |
| 326 // Attempting to click unrelated should activate it. | 326 // Attempting to click unrelated should activate it. |
| 327 aura::test::EventGenerator e2(Shell::GetPrimaryRootWindow(), unrelated.get()); | 327 ui::test::EventGenerator e2(Shell::GetPrimaryRootWindow(), unrelated.get()); |
| 328 e2.ClickLeftButton(); | 328 e2.ClickLeftButton(); |
| 329 EXPECT_TRUE(wm::IsActiveWindow(unrelated.get())); | 329 EXPECT_TRUE(wm::IsActiveWindow(unrelated.get())); |
| 330 } | 330 } |
| 331 | 331 |
| 332 TEST_F(SystemModalContainerLayoutManagerTest, EventFocusContainers) { | 332 TEST_F(SystemModalContainerLayoutManagerTest, EventFocusContainers) { |
| 333 // Create a normal window and attempt to receive a click event. | 333 // Create a normal window and attempt to receive a click event. |
| 334 EventTestWindow* main_delegate = new EventTestWindow(false); | 334 EventTestWindow* main_delegate = new EventTestWindow(false); |
| 335 scoped_ptr<aura::Window> main( | 335 scoped_ptr<aura::Window> main( |
| 336 main_delegate->OpenTestWindowWithContext(CurrentContext())); | 336 main_delegate->OpenTestWindowWithContext(CurrentContext())); |
| 337 EXPECT_TRUE(wm::IsActiveWindow(main.get())); | 337 EXPECT_TRUE(wm::IsActiveWindow(main.get())); |
| 338 aura::test::EventGenerator e1(Shell::GetPrimaryRootWindow(), main.get()); | 338 ui::test::EventGenerator e1(Shell::GetPrimaryRootWindow(), main.get()); |
| 339 e1.ClickLeftButton(); | 339 e1.ClickLeftButton(); |
| 340 EXPECT_EQ(1, main_delegate->mouse_presses()); | 340 EXPECT_EQ(1, main_delegate->mouse_presses()); |
| 341 | 341 |
| 342 // Create a modal window for the main window and verify that the main window | 342 // Create a modal window for the main window and verify that the main window |
| 343 // no longer receives mouse events. | 343 // no longer receives mouse events. |
| 344 EventTestWindow* transient_delegate = new EventTestWindow(true); | 344 EventTestWindow* transient_delegate = new EventTestWindow(true); |
| 345 aura::Window* transient = | 345 aura::Window* transient = |
| 346 transient_delegate->OpenTestWindowWithParent(main.get()); | 346 transient_delegate->OpenTestWindowWithParent(main.get()); |
| 347 EXPECT_TRUE(wm::IsActiveWindow(transient)); | 347 EXPECT_TRUE(wm::IsActiveWindow(transient)); |
| 348 e1.ClickLeftButton(); | 348 e1.ClickLeftButton(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 views::Widget* widget = views::Widget::CreateWindowWithContext( | 400 views::Widget* widget = views::Widget::CreateWindowWithContext( |
| 401 new TestWindow(false), CurrentContext()); | 401 new TestWindow(false), CurrentContext()); |
| 402 scoped_ptr<aura::Window> widget_window(widget->GetNativeView()); | 402 scoped_ptr<aura::Window> widget_window(widget->GetNativeView()); |
| 403 views::test::CaptureTrackingView* view = new views::test::CaptureTrackingView; | 403 views::test::CaptureTrackingView* view = new views::test::CaptureTrackingView; |
| 404 widget->GetContentsView()->AddChildView(view); | 404 widget->GetContentsView()->AddChildView(view); |
| 405 view->SetBoundsRect(widget->GetContentsView()->bounds()); | 405 view->SetBoundsRect(widget->GetContentsView()->bounds()); |
| 406 widget->Show(); | 406 widget->Show(); |
| 407 | 407 |
| 408 gfx::Point center(view->width() / 2, view->height() / 2); | 408 gfx::Point center(view->width() / 2, view->height() / 2); |
| 409 views::View::ConvertPointToScreen(view, ¢er); | 409 views::View::ConvertPointToScreen(view, ¢er); |
| 410 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), center); | 410 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), center); |
| 411 generator.PressLeftButton(); | 411 generator.PressLeftButton(); |
| 412 EXPECT_TRUE(view->got_press()); | 412 EXPECT_TRUE(view->got_press()); |
| 413 scoped_ptr<aura::Window> modal_window( | 413 scoped_ptr<aura::Window> modal_window( |
| 414 OpenTestWindowWithParent(widget->GetNativeView(), true)); | 414 OpenTestWindowWithParent(widget->GetNativeView(), true)); |
| 415 modal_window->Show(); | 415 modal_window->Show(); |
| 416 EXPECT_TRUE(view->got_capture_lost()); | 416 EXPECT_TRUE(view->got_capture_lost()); |
| 417 } | 417 } |
| 418 | 418 |
| 419 // Verifies that the window gets moved into the visible screen area upon screen | 419 // Verifies that the window gets moved into the visible screen area upon screen |
| 420 // resize. | 420 // resize. |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 ShowKeyboard(true); | 650 ShowKeyboard(true); |
| 651 EXPECT_EQ(modal_size.ToString(), modal_window->bounds().size().ToString()); | 651 EXPECT_EQ(modal_size.ToString(), modal_window->bounds().size().ToString()); |
| 652 EXPECT_EQ(modal_origin.x(), modal_window->bounds().x()); | 652 EXPECT_EQ(modal_origin.x(), modal_window->bounds().x()); |
| 653 EXPECT_EQ(0, modal_window->bounds().y()); | 653 EXPECT_EQ(0, modal_window->bounds().y()); |
| 654 | 654 |
| 655 ShowKeyboard(false); | 655 ShowKeyboard(false); |
| 656 } | 656 } |
| 657 | 657 |
| 658 } // namespace test | 658 } // namespace test |
| 659 } // namespace ash | 659 } // namespace ash |
| OLD | NEW |