| 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" |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 } else { | 188 } else { |
| 189 keyboard->HideKeyboard(keyboard::KeyboardController::HIDE_REASON_MANUAL); | 189 keyboard->HideKeyboard(keyboard::KeyboardController::HIDE_REASON_MANUAL); |
| 190 } | 190 } |
| 191 | 191 |
| 192 DCHECK_EQ(show, keyboard->keyboard_visible()); | 192 DCHECK_EQ(show, keyboard->keyboard_visible()); |
| 193 } | 193 } |
| 194 | 194 |
| 195 }; | 195 }; |
| 196 | 196 |
| 197 TEST_F(SystemModalContainerLayoutManagerTest, NonModalTransient) { | 197 TEST_F(SystemModalContainerLayoutManagerTest, NonModalTransient) { |
| 198 scoped_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); | 198 std::unique_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); |
| 199 aura::Window* transient = OpenTestWindowWithParent(parent.get(), false); | 199 aura::Window* transient = OpenTestWindowWithParent(parent.get(), false); |
| 200 TransientWindowObserver destruction_observer; | 200 TransientWindowObserver destruction_observer; |
| 201 transient->AddObserver(&destruction_observer); | 201 transient->AddObserver(&destruction_observer); |
| 202 | 202 |
| 203 EXPECT_EQ(parent.get(), ::wm::GetTransientParent(transient)); | 203 EXPECT_EQ(parent.get(), ::wm::GetTransientParent(transient)); |
| 204 EXPECT_EQ(parent->parent(), transient->parent()); | 204 EXPECT_EQ(parent->parent(), transient->parent()); |
| 205 | 205 |
| 206 // The transient should be destroyed with its parent. | 206 // The transient should be destroyed with its parent. |
| 207 parent.reset(); | 207 parent.reset(); |
| 208 EXPECT_TRUE(destruction_observer.destroyed()); | 208 EXPECT_TRUE(destruction_observer.destroyed()); |
| 209 } | 209 } |
| 210 | 210 |
| 211 TEST_F(SystemModalContainerLayoutManagerTest, ModalTransient) { | 211 TEST_F(SystemModalContainerLayoutManagerTest, ModalTransient) { |
| 212 scoped_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); | 212 std::unique_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); |
| 213 // parent should be active. | 213 // parent should be active. |
| 214 EXPECT_TRUE(wm::IsActiveWindow(parent.get())); | 214 EXPECT_TRUE(wm::IsActiveWindow(parent.get())); |
| 215 aura::Window* t1 = OpenTestWindowWithParent(parent.get(), true); | 215 aura::Window* t1 = OpenTestWindowWithParent(parent.get(), true); |
| 216 | 216 |
| 217 TransientWindowObserver do1; | 217 TransientWindowObserver do1; |
| 218 t1->AddObserver(&do1); | 218 t1->AddObserver(&do1); |
| 219 | 219 |
| 220 EXPECT_EQ(parent.get(), ::wm::GetTransientParent(t1)); | 220 EXPECT_EQ(parent.get(), ::wm::GetTransientParent(t1)); |
| 221 EXPECT_EQ(GetModalContainer(), t1->parent()); | 221 EXPECT_EQ(GetModalContainer(), t1->parent()); |
| 222 | 222 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 243 e2.ClickLeftButton(); | 243 e2.ClickLeftButton(); |
| 244 EXPECT_TRUE(wm::IsActiveWindow(t2)); | 244 EXPECT_TRUE(wm::IsActiveWindow(t2)); |
| 245 | 245 |
| 246 // Both transients should be destroyed with parent. | 246 // Both transients should be destroyed with parent. |
| 247 parent.reset(); | 247 parent.reset(); |
| 248 EXPECT_TRUE(do1.destroyed()); | 248 EXPECT_TRUE(do1.destroyed()); |
| 249 EXPECT_TRUE(do2.destroyed()); | 249 EXPECT_TRUE(do2.destroyed()); |
| 250 } | 250 } |
| 251 | 251 |
| 252 TEST_F(SystemModalContainerLayoutManagerTest, ModalNonTransient) { | 252 TEST_F(SystemModalContainerLayoutManagerTest, ModalNonTransient) { |
| 253 scoped_ptr<aura::Window> t1(OpenToplevelTestWindow(true)); | 253 std::unique_ptr<aura::Window> t1(OpenToplevelTestWindow(true)); |
| 254 // parent should be active. | 254 // parent should be active. |
| 255 EXPECT_TRUE(wm::IsActiveWindow(t1.get())); | 255 EXPECT_TRUE(wm::IsActiveWindow(t1.get())); |
| 256 TransientWindowObserver do1; | 256 TransientWindowObserver do1; |
| 257 t1->AddObserver(&do1); | 257 t1->AddObserver(&do1); |
| 258 | 258 |
| 259 EXPECT_EQ(NULL, ::wm::GetTransientParent(t1.get())); | 259 EXPECT_EQ(NULL, ::wm::GetTransientParent(t1.get())); |
| 260 EXPECT_EQ(GetModalContainer(), t1->parent()); | 260 EXPECT_EQ(GetModalContainer(), t1->parent()); |
| 261 | 261 |
| 262 // t1 should now be active. | 262 // t1 should now be active. |
| 263 EXPECT_TRUE(wm::IsActiveWindow(t1.get())); | 263 EXPECT_TRUE(wm::IsActiveWindow(t1.get())); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 285 | 285 |
| 286 // Both transients should be destroyed with parent. | 286 // Both transients should be destroyed with parent. |
| 287 t1.reset(); | 287 t1.reset(); |
| 288 EXPECT_TRUE(do1.destroyed()); | 288 EXPECT_TRUE(do1.destroyed()); |
| 289 EXPECT_TRUE(do2.destroyed()); | 289 EXPECT_TRUE(do2.destroyed()); |
| 290 } | 290 } |
| 291 | 291 |
| 292 // Tests that we can activate an unrelated window after a modal window is closed | 292 // Tests that we can activate an unrelated window after a modal window is closed |
| 293 // for a window. | 293 // for a window. |
| 294 TEST_F(SystemModalContainerLayoutManagerTest, CanActivateAfterEndModalSession) { | 294 TEST_F(SystemModalContainerLayoutManagerTest, CanActivateAfterEndModalSession) { |
| 295 scoped_ptr<aura::Window> unrelated(OpenToplevelTestWindow(false)); | 295 std::unique_ptr<aura::Window> unrelated(OpenToplevelTestWindow(false)); |
| 296 unrelated->SetBounds(gfx::Rect(100, 100, 50, 50)); | 296 unrelated->SetBounds(gfx::Rect(100, 100, 50, 50)); |
| 297 scoped_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); | 297 std::unique_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); |
| 298 // parent should be active. | 298 // parent should be active. |
| 299 EXPECT_TRUE(wm::IsActiveWindow(parent.get())); | 299 EXPECT_TRUE(wm::IsActiveWindow(parent.get())); |
| 300 | 300 |
| 301 scoped_ptr<aura::Window> transient( | 301 std::unique_ptr<aura::Window> transient( |
| 302 OpenTestWindowWithParent(parent.get(), true)); | 302 OpenTestWindowWithParent(parent.get(), true)); |
| 303 // t1 should now be active. | 303 // t1 should now be active. |
| 304 EXPECT_TRUE(wm::IsActiveWindow(transient.get())); | 304 EXPECT_TRUE(wm::IsActiveWindow(transient.get())); |
| 305 | 305 |
| 306 // Attempting to click the parent should result in no activation change. | 306 // Attempting to click the parent should result in no activation change. |
| 307 ui::test::EventGenerator e1(Shell::GetPrimaryRootWindow(), parent.get()); | 307 ui::test::EventGenerator e1(Shell::GetPrimaryRootWindow(), parent.get()); |
| 308 e1.ClickLeftButton(); | 308 e1.ClickLeftButton(); |
| 309 EXPECT_TRUE(wm::IsActiveWindow(transient.get())); | 309 EXPECT_TRUE(wm::IsActiveWindow(transient.get())); |
| 310 | 310 |
| 311 // Now close the transient. | 311 // Now close the transient. |
| 312 transient->Hide(); | 312 transient->Hide(); |
| 313 TestWindow::CloseTestWindow(transient.release()); | 313 TestWindow::CloseTestWindow(transient.release()); |
| 314 | 314 |
| 315 base::RunLoop().RunUntilIdle(); | 315 base::RunLoop().RunUntilIdle(); |
| 316 | 316 |
| 317 // parent should now be active again. | 317 // parent should now be active again. |
| 318 EXPECT_TRUE(wm::IsActiveWindow(parent.get())); | 318 EXPECT_TRUE(wm::IsActiveWindow(parent.get())); |
| 319 | 319 |
| 320 // Attempting to click unrelated should activate it. | 320 // Attempting to click unrelated should activate it. |
| 321 ui::test::EventGenerator e2(Shell::GetPrimaryRootWindow(), unrelated.get()); | 321 ui::test::EventGenerator e2(Shell::GetPrimaryRootWindow(), unrelated.get()); |
| 322 e2.ClickLeftButton(); | 322 e2.ClickLeftButton(); |
| 323 EXPECT_TRUE(wm::IsActiveWindow(unrelated.get())); | 323 EXPECT_TRUE(wm::IsActiveWindow(unrelated.get())); |
| 324 } | 324 } |
| 325 | 325 |
| 326 TEST_F(SystemModalContainerLayoutManagerTest, EventFocusContainers) { | 326 TEST_F(SystemModalContainerLayoutManagerTest, EventFocusContainers) { |
| 327 // Create a normal window and attempt to receive a click event. | 327 // Create a normal window and attempt to receive a click event. |
| 328 EventTestWindow* main_delegate = new EventTestWindow(false); | 328 EventTestWindow* main_delegate = new EventTestWindow(false); |
| 329 scoped_ptr<aura::Window> main( | 329 std::unique_ptr<aura::Window> main( |
| 330 main_delegate->OpenTestWindowWithContext(CurrentContext())); | 330 main_delegate->OpenTestWindowWithContext(CurrentContext())); |
| 331 EXPECT_TRUE(wm::IsActiveWindow(main.get())); | 331 EXPECT_TRUE(wm::IsActiveWindow(main.get())); |
| 332 ui::test::EventGenerator e1(Shell::GetPrimaryRootWindow(), main.get()); | 332 ui::test::EventGenerator e1(Shell::GetPrimaryRootWindow(), main.get()); |
| 333 e1.ClickLeftButton(); | 333 e1.ClickLeftButton(); |
| 334 EXPECT_EQ(1, main_delegate->mouse_presses()); | 334 EXPECT_EQ(1, main_delegate->mouse_presses()); |
| 335 | 335 |
| 336 // Create a modal window for the main window and verify that the main window | 336 // Create a modal window for the main window and verify that the main window |
| 337 // no longer receives mouse events. | 337 // no longer receives mouse events. |
| 338 EventTestWindow* transient_delegate = new EventTestWindow(true); | 338 EventTestWindow* transient_delegate = new EventTestWindow(true); |
| 339 aura::Window* transient = | 339 aura::Window* transient = |
| 340 transient_delegate->OpenTestWindowWithParent(main.get()); | 340 transient_delegate->OpenTestWindowWithParent(main.get()); |
| 341 EXPECT_TRUE(wm::IsActiveWindow(transient)); | 341 EXPECT_TRUE(wm::IsActiveWindow(transient)); |
| 342 e1.ClickLeftButton(); | 342 e1.ClickLeftButton(); |
| 343 EXPECT_EQ(1, transient_delegate->mouse_presses()); | 343 EXPECT_EQ(1, transient_delegate->mouse_presses()); |
| 344 | 344 |
| 345 for (int block_reason = FIRST_BLOCK_REASON; | 345 for (int block_reason = FIRST_BLOCK_REASON; |
| 346 block_reason < NUMBER_OF_BLOCK_REASONS; | 346 block_reason < NUMBER_OF_BLOCK_REASONS; |
| 347 ++block_reason) { | 347 ++block_reason) { |
| 348 // Create a window in the lock screen container and ensure that it receives | 348 // Create a window in the lock screen container and ensure that it receives |
| 349 // the mouse event instead of the modal window (crbug.com/110920). | 349 // the mouse event instead of the modal window (crbug.com/110920). |
| 350 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); | 350 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); |
| 351 EventTestWindow* lock_delegate = new EventTestWindow(false); | 351 EventTestWindow* lock_delegate = new EventTestWindow(false); |
| 352 scoped_ptr<aura::Window> lock(lock_delegate->OpenTestWindowWithParent( | 352 std::unique_ptr<aura::Window> lock(lock_delegate->OpenTestWindowWithParent( |
| 353 Shell::GetPrimaryRootWindowController()->GetContainer( | 353 Shell::GetPrimaryRootWindowController()->GetContainer( |
| 354 ash::kShellWindowId_LockScreenContainer))); | 354 ash::kShellWindowId_LockScreenContainer))); |
| 355 EXPECT_TRUE(wm::IsActiveWindow(lock.get())); | 355 EXPECT_TRUE(wm::IsActiveWindow(lock.get())); |
| 356 e1.ClickLeftButton(); | 356 e1.ClickLeftButton(); |
| 357 EXPECT_EQ(1, lock_delegate->mouse_presses()); | 357 EXPECT_EQ(1, lock_delegate->mouse_presses()); |
| 358 | 358 |
| 359 // Make sure that a modal container created by the lock screen can still | 359 // Make sure that a modal container created by the lock screen can still |
| 360 // receive mouse events. | 360 // receive mouse events. |
| 361 EventTestWindow* lock_modal_delegate = new EventTestWindow(true); | 361 EventTestWindow* lock_modal_delegate = new EventTestWindow(true); |
| 362 aura::Window* lock_modal = | 362 aura::Window* lock_modal = |
| (...skipping 12 matching lines...) Expand all Loading... |
| 375 // Makes sure we don't crash if a modal window is shown while the parent window | 375 // Makes sure we don't crash if a modal window is shown while the parent window |
| 376 // is hidden. | 376 // is hidden. |
| 377 TEST_F(SystemModalContainerLayoutManagerTest, ShowModalWhileHidden) { | 377 TEST_F(SystemModalContainerLayoutManagerTest, ShowModalWhileHidden) { |
| 378 // Hide the lock screen. | 378 // Hide the lock screen. |
| 379 Shell::GetPrimaryRootWindowController() | 379 Shell::GetPrimaryRootWindowController() |
| 380 ->GetContainer(kShellWindowId_SystemModalContainer) | 380 ->GetContainer(kShellWindowId_SystemModalContainer) |
| 381 ->layer() | 381 ->layer() |
| 382 ->SetOpacity(0); | 382 ->SetOpacity(0); |
| 383 | 383 |
| 384 // Create a modal window. | 384 // Create a modal window. |
| 385 scoped_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); | 385 std::unique_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); |
| 386 scoped_ptr<aura::Window> modal_window( | 386 std::unique_ptr<aura::Window> modal_window( |
| 387 OpenTestWindowWithParent(parent.get(), true)); | 387 OpenTestWindowWithParent(parent.get(), true)); |
| 388 parent->Show(); | 388 parent->Show(); |
| 389 modal_window->Show(); | 389 modal_window->Show(); |
| 390 } | 390 } |
| 391 | 391 |
| 392 // Verifies we generate a capture lost when showing a modal window. | 392 // Verifies we generate a capture lost when showing a modal window. |
| 393 TEST_F(SystemModalContainerLayoutManagerTest, ChangeCapture) { | 393 TEST_F(SystemModalContainerLayoutManagerTest, ChangeCapture) { |
| 394 views::Widget* widget = views::Widget::CreateWindowWithContext( | 394 views::Widget* widget = views::Widget::CreateWindowWithContext( |
| 395 new TestWindow(false), CurrentContext()); | 395 new TestWindow(false), CurrentContext()); |
| 396 scoped_ptr<aura::Window> widget_window(widget->GetNativeView()); | 396 std::unique_ptr<aura::Window> widget_window(widget->GetNativeView()); |
| 397 views::test::CaptureTrackingView* view = new views::test::CaptureTrackingView; | 397 views::test::CaptureTrackingView* view = new views::test::CaptureTrackingView; |
| 398 widget->GetContentsView()->AddChildView(view); | 398 widget->GetContentsView()->AddChildView(view); |
| 399 view->SetBoundsRect(widget->GetContentsView()->bounds()); | 399 view->SetBoundsRect(widget->GetContentsView()->bounds()); |
| 400 widget->Show(); | 400 widget->Show(); |
| 401 | 401 |
| 402 gfx::Point center(view->width() / 2, view->height() / 2); | 402 gfx::Point center(view->width() / 2, view->height() / 2); |
| 403 views::View::ConvertPointToScreen(view, ¢er); | 403 views::View::ConvertPointToScreen(view, ¢er); |
| 404 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), center); | 404 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), center); |
| 405 generator.PressLeftButton(); | 405 generator.PressLeftButton(); |
| 406 EXPECT_TRUE(view->got_press()); | 406 EXPECT_TRUE(view->got_press()); |
| 407 scoped_ptr<aura::Window> modal_window( | 407 std::unique_ptr<aura::Window> modal_window( |
| 408 OpenTestWindowWithParent(widget->GetNativeView(), true)); | 408 OpenTestWindowWithParent(widget->GetNativeView(), true)); |
| 409 modal_window->Show(); | 409 modal_window->Show(); |
| 410 EXPECT_TRUE(view->got_capture_lost()); | 410 EXPECT_TRUE(view->got_capture_lost()); |
| 411 } | 411 } |
| 412 | 412 |
| 413 // Verifies that the window gets moved into the visible screen area upon screen | 413 // Verifies that the window gets moved into the visible screen area upon screen |
| 414 // resize. | 414 // resize. |
| 415 TEST_F(SystemModalContainerLayoutManagerTest, KeepVisible) { | 415 TEST_F(SystemModalContainerLayoutManagerTest, KeepVisible) { |
| 416 GetModalContainer()->SetBounds(gfx::Rect(0, 0, 1024, 768)); | 416 GetModalContainer()->SetBounds(gfx::Rect(0, 0, 1024, 768)); |
| 417 scoped_ptr<aura::Window> main(OpenTestWindowWithParent(GetModalContainer(), | 417 std::unique_ptr<aura::Window> main( |
| 418 true)); | 418 OpenTestWindowWithParent(GetModalContainer(), true)); |
| 419 main->SetBounds(gfx::Rect(924, 668, 100, 100)); | 419 main->SetBounds(gfx::Rect(924, 668, 100, 100)); |
| 420 // We set now the bounds of the root window to something new which will | 420 // We set now the bounds of the root window to something new which will |
| 421 // Then trigger the repos operation. | 421 // Then trigger the repos operation. |
| 422 GetModalContainer()->SetBounds(gfx::Rect(0, 0, 800, 600)); | 422 GetModalContainer()->SetBounds(gfx::Rect(0, 0, 800, 600)); |
| 423 | 423 |
| 424 gfx::Rect bounds = main->bounds(); | 424 gfx::Rect bounds = main->bounds(); |
| 425 EXPECT_EQ(bounds, gfx::Rect(700, 500, 100, 100)); | 425 EXPECT_EQ(bounds, gfx::Rect(700, 500, 100, 100)); |
| 426 } | 426 } |
| 427 | 427 |
| 428 // Verifies that centered windows will remain centered after the visible screen | 428 // Verifies that centered windows will remain centered after the visible screen |
| 429 // area changed. | 429 // area changed. |
| 430 TEST_F(SystemModalContainerLayoutManagerTest, KeepCentered) { | 430 TEST_F(SystemModalContainerLayoutManagerTest, KeepCentered) { |
| 431 GetModalContainer()->SetBounds(gfx::Rect(0, 0, 800, 600)); | 431 GetModalContainer()->SetBounds(gfx::Rect(0, 0, 800, 600)); |
| 432 scoped_ptr<aura::Window> main(OpenTestWindowWithParent(GetModalContainer(), | 432 std::unique_ptr<aura::Window> main( |
| 433 true)); | 433 OpenTestWindowWithParent(GetModalContainer(), true)); |
| 434 // Center the window. | 434 // Center the window. |
| 435 main->SetBounds(gfx::Rect((800 - 512) / 2, (600 - 256) / 2, 512, 256)); | 435 main->SetBounds(gfx::Rect((800 - 512) / 2, (600 - 256) / 2, 512, 256)); |
| 436 | 436 |
| 437 // We set now the bounds of the root window to something new which will | 437 // We set now the bounds of the root window to something new which will |
| 438 // Then trigger the reposition operation. | 438 // Then trigger the reposition operation. |
| 439 GetModalContainer()->SetBounds(gfx::Rect(0, 0, 1024, 768)); | 439 GetModalContainer()->SetBounds(gfx::Rect(0, 0, 1024, 768)); |
| 440 | 440 |
| 441 // The window should still be centered. | 441 // The window should still be centered. |
| 442 gfx::Rect bounds = main->bounds(); | 442 gfx::Rect bounds = main->bounds(); |
| 443 EXPECT_EQ(bounds.ToString(), gfx::Rect(256, 256, 512, 256).ToString()); | 443 EXPECT_EQ(bounds.ToString(), gfx::Rect(256, 256, 512, 256).ToString()); |
| 444 } | 444 } |
| 445 | 445 |
| 446 TEST_F(SystemModalContainerLayoutManagerTest, ShowNormalBackgroundOrLocked) { | 446 TEST_F(SystemModalContainerLayoutManagerTest, ShowNormalBackgroundOrLocked) { |
| 447 scoped_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); | 447 std::unique_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); |
| 448 scoped_ptr<aura::Window> modal_window( | 448 std::unique_ptr<aura::Window> modal_window( |
| 449 OpenTestWindowWithParent(parent.get(), true)); | 449 OpenTestWindowWithParent(parent.get(), true)); |
| 450 parent->Show(); | 450 parent->Show(); |
| 451 modal_window->Show(); | 451 modal_window->Show(); |
| 452 | 452 |
| 453 // Normal system modal window. Shows normal system modal background and not | 453 // Normal system modal window. Shows normal system modal background and not |
| 454 // locked. | 454 // locked. |
| 455 EXPECT_TRUE(AllRootWindowsHaveModalBackgrounds()); | 455 EXPECT_TRUE(AllRootWindowsHaveModalBackgrounds()); |
| 456 EXPECT_FALSE(AllRootWindowsHaveLockedModalBackgrounds()); | 456 EXPECT_FALSE(AllRootWindowsHaveLockedModalBackgrounds()); |
| 457 | 457 |
| 458 TestWindow::CloseTestWindow(modal_window.release()); | 458 TestWindow::CloseTestWindow(modal_window.release()); |
| 459 EXPECT_FALSE(AllRootWindowsHaveModalBackgrounds()); | 459 EXPECT_FALSE(AllRootWindowsHaveModalBackgrounds()); |
| 460 EXPECT_FALSE(AllRootWindowsHaveLockedModalBackgrounds()); | 460 EXPECT_FALSE(AllRootWindowsHaveLockedModalBackgrounds()); |
| 461 | 461 |
| 462 for (int block_reason = FIRST_BLOCK_REASON; | 462 for (int block_reason = FIRST_BLOCK_REASON; |
| 463 block_reason < NUMBER_OF_BLOCK_REASONS; | 463 block_reason < NUMBER_OF_BLOCK_REASONS; |
| 464 ++block_reason) { | 464 ++block_reason) { |
| 465 // Normal system modal window while blocked. Shows blocked system modal | 465 // Normal system modal window while blocked. Shows blocked system modal |
| 466 // background. | 466 // background. |
| 467 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); | 467 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); |
| 468 scoped_ptr<aura::Window> lock_parent(OpenTestWindowWithParent( | 468 std::unique_ptr<aura::Window> lock_parent(OpenTestWindowWithParent( |
| 469 Shell::GetPrimaryRootWindowController()->GetContainer( | 469 Shell::GetPrimaryRootWindowController()->GetContainer( |
| 470 ash::kShellWindowId_LockScreenContainer), | 470 ash::kShellWindowId_LockScreenContainer), |
| 471 false)); | 471 false)); |
| 472 scoped_ptr<aura::Window> lock_modal_window(OpenTestWindowWithParent( | 472 std::unique_ptr<aura::Window> lock_modal_window( |
| 473 lock_parent.get(), true)); | 473 OpenTestWindowWithParent(lock_parent.get(), true)); |
| 474 lock_parent->Show(); | 474 lock_parent->Show(); |
| 475 lock_modal_window->Show(); | 475 lock_modal_window->Show(); |
| 476 EXPECT_FALSE(AllRootWindowsHaveModalBackgrounds()); | 476 EXPECT_FALSE(AllRootWindowsHaveModalBackgrounds()); |
| 477 EXPECT_TRUE(AllRootWindowsHaveLockedModalBackgrounds()); | 477 EXPECT_TRUE(AllRootWindowsHaveLockedModalBackgrounds()); |
| 478 TestWindow::CloseTestWindow(lock_modal_window.release()); | 478 TestWindow::CloseTestWindow(lock_modal_window.release()); |
| 479 | 479 |
| 480 // Normal system modal window while blocked, but it belongs to the normal | 480 // Normal system modal window while blocked, but it belongs to the normal |
| 481 // window. Shouldn't show blocked system modal background, but normal. | 481 // window. Shouldn't show blocked system modal background, but normal. |
| 482 scoped_ptr<aura::Window> modal_window( | 482 std::unique_ptr<aura::Window> modal_window( |
| 483 OpenTestWindowWithParent(parent.get(), true)); | 483 OpenTestWindowWithParent(parent.get(), true)); |
| 484 modal_window->Show(); | 484 modal_window->Show(); |
| 485 EXPECT_TRUE(AllRootWindowsHaveModalBackgrounds()); | 485 EXPECT_TRUE(AllRootWindowsHaveModalBackgrounds()); |
| 486 EXPECT_FALSE(AllRootWindowsHaveLockedModalBackgrounds()); | 486 EXPECT_FALSE(AllRootWindowsHaveLockedModalBackgrounds()); |
| 487 TestWindow::CloseTestWindow(modal_window.release()); | 487 TestWindow::CloseTestWindow(modal_window.release()); |
| 488 UnblockUserSession(); | 488 UnblockUserSession(); |
| 489 // Here we should check the behavior of the locked system modal dialog when | 489 // Here we should check the behavior of the locked system modal dialog when |
| 490 // unlocked, but such case isn't handled very well right now. | 490 // unlocked, but such case isn't handled very well right now. |
| 491 // See crbug.com/157660 | 491 // See crbug.com/157660 |
| 492 // TODO(mukai): add the test case when the bug is fixed. | 492 // TODO(mukai): add the test case when the bug is fixed. |
| 493 } | 493 } |
| 494 } | 494 } |
| 495 | 495 |
| 496 TEST_F(SystemModalContainerLayoutManagerTest, MultiDisplays) { | 496 TEST_F(SystemModalContainerLayoutManagerTest, MultiDisplays) { |
| 497 if (!SupportsMultipleDisplays()) | 497 if (!SupportsMultipleDisplays()) |
| 498 return; | 498 return; |
| 499 | 499 |
| 500 UpdateDisplay("500x500,500x500"); | 500 UpdateDisplay("500x500,500x500"); |
| 501 | 501 |
| 502 scoped_ptr<aura::Window> normal(OpenToplevelTestWindow(false)); | 502 std::unique_ptr<aura::Window> normal(OpenToplevelTestWindow(false)); |
| 503 normal->SetBounds(gfx::Rect(100, 100, 50, 50)); | 503 normal->SetBounds(gfx::Rect(100, 100, 50, 50)); |
| 504 | 504 |
| 505 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 505 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 506 EXPECT_EQ(2U, root_windows.size()); | 506 EXPECT_EQ(2U, root_windows.size()); |
| 507 aura::Window* container1 = Shell::GetContainer( | 507 aura::Window* container1 = Shell::GetContainer( |
| 508 root_windows[0], ash::kShellWindowId_SystemModalContainer); | 508 root_windows[0], ash::kShellWindowId_SystemModalContainer); |
| 509 aura::Window* container2 = Shell::GetContainer( | 509 aura::Window* container2 = Shell::GetContainer( |
| 510 root_windows[1], ash::kShellWindowId_SystemModalContainer); | 510 root_windows[1], ash::kShellWindowId_SystemModalContainer); |
| 511 | 511 |
| 512 scoped_ptr<aura::Window> modal1( | 512 std::unique_ptr<aura::Window> modal1( |
| 513 OpenTestWindowWithParent(container1, true)); | 513 OpenTestWindowWithParent(container1, true)); |
| 514 EXPECT_TRUE(AllRootWindowsHaveModalBackgrounds()); | 514 EXPECT_TRUE(AllRootWindowsHaveModalBackgrounds()); |
| 515 EXPECT_TRUE(wm::IsActiveWindow(modal1.get())); | 515 EXPECT_TRUE(wm::IsActiveWindow(modal1.get())); |
| 516 | 516 |
| 517 scoped_ptr<aura::Window> modal11( | 517 std::unique_ptr<aura::Window> modal11( |
| 518 OpenTestWindowWithParent(container1, true)); | 518 OpenTestWindowWithParent(container1, true)); |
| 519 EXPECT_TRUE(wm::IsActiveWindow(modal11.get())); | 519 EXPECT_TRUE(wm::IsActiveWindow(modal11.get())); |
| 520 | 520 |
| 521 scoped_ptr<aura::Window> modal2( | 521 std::unique_ptr<aura::Window> modal2( |
| 522 OpenTestWindowWithParent(container2, true)); | 522 OpenTestWindowWithParent(container2, true)); |
| 523 EXPECT_TRUE(wm::IsActiveWindow(modal2.get())); | 523 EXPECT_TRUE(wm::IsActiveWindow(modal2.get())); |
| 524 | 524 |
| 525 // Sanity check if they're on the correct containers. | 525 // Sanity check if they're on the correct containers. |
| 526 EXPECT_EQ(container1, modal1->parent()); | 526 EXPECT_EQ(container1, modal1->parent()); |
| 527 EXPECT_EQ(container1, modal11->parent()); | 527 EXPECT_EQ(container1, modal11->parent()); |
| 528 EXPECT_EQ(container2, modal2->parent()); | 528 EXPECT_EQ(container2, modal2->parent()); |
| 529 | 529 |
| 530 TestWindow::CloseTestWindow(modal2.release()); | 530 TestWindow::CloseTestWindow(modal2.release()); |
| 531 EXPECT_TRUE(AllRootWindowsHaveModalBackgrounds()); | 531 EXPECT_TRUE(AllRootWindowsHaveModalBackgrounds()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 556 SystemModalDialogGetPushedFromKeyboard) { | 556 SystemModalDialogGetPushedFromKeyboard) { |
| 557 const gfx::Rect& container_bounds = GetModalContainer()->bounds(); | 557 const gfx::Rect& container_bounds = GetModalContainer()->bounds(); |
| 558 // Place the window at the bottom of the screen. | 558 // Place the window at the bottom of the screen. |
| 559 gfx::Size modal_size(100, 100); | 559 gfx::Size modal_size(100, 100); |
| 560 gfx::Point modal_origin = gfx::Point( | 560 gfx::Point modal_origin = gfx::Point( |
| 561 (container_bounds.right() - modal_size.width()) / 2, // X centered | 561 (container_bounds.right() - modal_size.width()) / 2, // X centered |
| 562 container_bounds.bottom() - modal_size.height()); // at bottom | 562 container_bounds.bottom() - modal_size.height()); // at bottom |
| 563 gfx::Rect modal_bounds = gfx::Rect(modal_origin, modal_size); | 563 gfx::Rect modal_bounds = gfx::Rect(modal_origin, modal_size); |
| 564 | 564 |
| 565 // Create a modal window. | 565 // Create a modal window. |
| 566 scoped_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); | 566 std::unique_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); |
| 567 scoped_ptr<aura::Window> modal_window( | 567 std::unique_ptr<aura::Window> modal_window( |
| 568 OpenTestWindowWithParent(parent.get(), true)); | 568 OpenTestWindowWithParent(parent.get(), true)); |
| 569 modal_window->SetBounds(modal_bounds); | 569 modal_window->SetBounds(modal_bounds); |
| 570 parent->Show(); | 570 parent->Show(); |
| 571 modal_window->Show(); | 571 modal_window->Show(); |
| 572 | 572 |
| 573 EXPECT_EQ(modal_bounds.ToString(), modal_window->bounds().ToString()); | 573 EXPECT_EQ(modal_bounds.ToString(), modal_window->bounds().ToString()); |
| 574 | 574 |
| 575 // The keyboard gets shown and the dialog should get pushed. | 575 // The keyboard gets shown and the dialog should get pushed. |
| 576 ShowKeyboard(true); | 576 ShowKeyboard(true); |
| 577 EXPECT_NE(modal_bounds.ToString(), modal_window->bounds().ToString()); | 577 EXPECT_NE(modal_bounds.ToString(), modal_window->bounds().ToString()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 593 const gfx::Rect& container_bounds = GetModalContainer()->bounds(); | 593 const gfx::Rect& container_bounds = GetModalContainer()->bounds(); |
| 594 const gfx::Size screen_size = Shell::GetPrimaryRootWindow()->bounds().size(); | 594 const gfx::Size screen_size = Shell::GetPrimaryRootWindow()->bounds().size(); |
| 595 // Place the window at the bottom of the screen. | 595 // Place the window at the bottom of the screen. |
| 596 gfx::Size modal_size(100, screen_size.height() - 70); | 596 gfx::Size modal_size(100, screen_size.height() - 70); |
| 597 gfx::Point modal_origin = gfx::Point( | 597 gfx::Point modal_origin = gfx::Point( |
| 598 (container_bounds.right() - modal_size.width()) / 2, // X centered | 598 (container_bounds.right() - modal_size.width()) / 2, // X centered |
| 599 container_bounds.bottom() - modal_size.height()); // at bottom | 599 container_bounds.bottom() - modal_size.height()); // at bottom |
| 600 gfx::Rect modal_bounds = gfx::Rect(modal_origin, modal_size); | 600 gfx::Rect modal_bounds = gfx::Rect(modal_origin, modal_size); |
| 601 | 601 |
| 602 // Create a modal window. | 602 // Create a modal window. |
| 603 scoped_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); | 603 std::unique_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); |
| 604 scoped_ptr<aura::Window> modal_window( | 604 std::unique_ptr<aura::Window> modal_window( |
| 605 OpenTestWindowWithParent(parent.get(), true)); | 605 OpenTestWindowWithParent(parent.get(), true)); |
| 606 modal_window->SetBounds(modal_bounds); | 606 modal_window->SetBounds(modal_bounds); |
| 607 parent->Show(); | 607 parent->Show(); |
| 608 modal_window->Show(); | 608 modal_window->Show(); |
| 609 | 609 |
| 610 EXPECT_EQ(modal_bounds.ToString(), modal_window->bounds().ToString()); | 610 EXPECT_EQ(modal_bounds.ToString(), modal_window->bounds().ToString()); |
| 611 | 611 |
| 612 // The keyboard gets shown and the dialog should get pushed up, but not get | 612 // The keyboard gets shown and the dialog should get pushed up, but not get |
| 613 // cropped (and aligned to the top). | 613 // cropped (and aligned to the top). |
| 614 ShowKeyboard(true); | 614 ShowKeyboard(true); |
| 615 EXPECT_EQ(modal_size.ToString(), modal_window->bounds().size().ToString()); | 615 EXPECT_EQ(modal_size.ToString(), modal_window->bounds().size().ToString()); |
| 616 EXPECT_EQ(modal_origin.x(), modal_window->bounds().x()); | 616 EXPECT_EQ(modal_origin.x(), modal_window->bounds().x()); |
| 617 EXPECT_EQ(0, modal_window->bounds().y()); | 617 EXPECT_EQ(0, modal_window->bounds().y()); |
| 618 | 618 |
| 619 ShowKeyboard(false); | 619 ShowKeyboard(false); |
| 620 } | 620 } |
| 621 | 621 |
| 622 // Test that windows will not get cropped through the visible virtual keyboard - | 622 // Test that windows will not get cropped through the visible virtual keyboard - |
| 623 // if not centered. | 623 // if not centered. |
| 624 TEST_F(SystemModalContainerLayoutManagerTest, | 624 TEST_F(SystemModalContainerLayoutManagerTest, |
| 625 SystemModalDialogGetPushedButNotCroppedFromKeyboardIfNotCentered) { | 625 SystemModalDialogGetPushedButNotCroppedFromKeyboardIfNotCentered) { |
| 626 const gfx::Size screen_size = Shell::GetPrimaryRootWindow()->bounds().size(); | 626 const gfx::Size screen_size = Shell::GetPrimaryRootWindow()->bounds().size(); |
| 627 // Place the window at the bottom of the screen. | 627 // Place the window at the bottom of the screen. |
| 628 gfx::Size modal_size(100, screen_size.height() - 70); | 628 gfx::Size modal_size(100, screen_size.height() - 70); |
| 629 gfx::Point modal_origin = gfx::Point(10, 20); | 629 gfx::Point modal_origin = gfx::Point(10, 20); |
| 630 gfx::Rect modal_bounds = gfx::Rect(modal_origin, modal_size); | 630 gfx::Rect modal_bounds = gfx::Rect(modal_origin, modal_size); |
| 631 | 631 |
| 632 // Create a modal window. | 632 // Create a modal window. |
| 633 scoped_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); | 633 std::unique_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); |
| 634 scoped_ptr<aura::Window> modal_window( | 634 std::unique_ptr<aura::Window> modal_window( |
| 635 OpenTestWindowWithParent(parent.get(), true)); | 635 OpenTestWindowWithParent(parent.get(), true)); |
| 636 modal_window->SetBounds(modal_bounds); | 636 modal_window->SetBounds(modal_bounds); |
| 637 parent->Show(); | 637 parent->Show(); |
| 638 modal_window->Show(); | 638 modal_window->Show(); |
| 639 | 639 |
| 640 EXPECT_EQ(modal_bounds.ToString(), modal_window->bounds().ToString()); | 640 EXPECT_EQ(modal_bounds.ToString(), modal_window->bounds().ToString()); |
| 641 | 641 |
| 642 // The keyboard gets shown and the dialog should get pushed up, but not get | 642 // The keyboard gets shown and the dialog should get pushed up, but not get |
| 643 // cropped (and aligned to the top). | 643 // cropped (and aligned to the top). |
| 644 ShowKeyboard(true); | 644 ShowKeyboard(true); |
| 645 EXPECT_EQ(modal_size.ToString(), modal_window->bounds().size().ToString()); | 645 EXPECT_EQ(modal_size.ToString(), modal_window->bounds().size().ToString()); |
| 646 EXPECT_EQ(modal_origin.x(), modal_window->bounds().x()); | 646 EXPECT_EQ(modal_origin.x(), modal_window->bounds().x()); |
| 647 EXPECT_EQ(0, modal_window->bounds().y()); | 647 EXPECT_EQ(0, modal_window->bounds().y()); |
| 648 | 648 |
| 649 ShowKeyboard(false); | 649 ShowKeyboard(false); |
| 650 } | 650 } |
| 651 | 651 |
| 652 } // namespace test | 652 } // namespace test |
| 653 } // namespace ash | 653 } // namespace ash |
| OLD | NEW |