| 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/ash_switches.h" | 5 #include "ash/ash_switches.h" |
| 6 #include "ash/launcher/launcher.h" | 6 #include "ash/launcher/launcher.h" |
| 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/aura_shell_test_base.h" | 9 #include "ash/test/aura_shell_test_base.h" |
| 10 #include "ash/wm/root_window_layout_manager.h" | 10 #include "ash/wm/root_window_layout_manager.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "ui/aura/test/aura_test_base.h" | 13 #include "ui/aura/test/aura_test_base.h" |
| 14 #include "ui/aura/root_window.h" | 14 #include "ui/aura/root_window.h" |
| 15 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 16 #include "ui/gfx/size.h" | 16 #include "ui/gfx/size.h" |
| 17 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
| 18 #include "ui/views/widget/widget_delegate.h" | 18 #include "ui/views/widget/widget_delegate.h" |
| 19 | 19 |
| 20 using aura::RootWindow; |
| 21 |
| 20 namespace ash { | 22 namespace ash { |
| 21 | 23 |
| 22 namespace { | 24 namespace { |
| 23 | 25 |
| 24 views::Widget* CreateTestWindow(const views::Widget::InitParams& params) { | 26 views::Widget* CreateTestWindow(const views::Widget::InitParams& params) { |
| 25 views::Widget* widget = new views::Widget; | 27 views::Widget* widget = new views::Widget; |
| 26 widget->Init(params); | 28 widget->Init(params); |
| 27 return widget; | 29 return widget; |
| 28 } | 30 } |
| 29 | 31 |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 views::Widget* lock_widget = CreateTestWindow(widget_params); | 277 views::Widget* lock_widget = CreateTestWindow(widget_params); |
| 276 ash::Shell::GetInstance()->GetContainer( | 278 ash::Shell::GetInstance()->GetContainer( |
| 277 ash::internal::kShellWindowId_LockScreenContainer)-> | 279 ash::internal::kShellWindowId_LockScreenContainer)-> |
| 278 AddChild(lock_widget->GetNativeView()); | 280 AddChild(lock_widget->GetNativeView()); |
| 279 lock_widget->Show(); | 281 lock_widget->Show(); |
| 280 EXPECT_TRUE(Shell::GetInstance()->IsScreenLocked()); | 282 EXPECT_TRUE(Shell::GetInstance()->IsScreenLocked()); |
| 281 lock_widget->Hide(); | 283 lock_widget->Hide(); |
| 282 EXPECT_FALSE(Shell::GetInstance()->IsScreenLocked()); | 284 EXPECT_FALSE(Shell::GetInstance()->IsScreenLocked()); |
| 283 | 285 |
| 284 // A modal window with a lock window as parent does not lock the screen. The | 286 // A modal window with a lock window as parent does not lock the screen. The |
| 285 // screen is locked only when a lock windown is visible. | 287 // screen is locked only when a lock window is visible. |
| 286 views::Widget* lock_modal_widget = views::Widget::CreateWindowWithParent( | 288 views::Widget* lock_modal_widget = views::Widget::CreateWindowWithParent( |
| 287 new ModalWindow(), lock_widget->GetNativeView()); | 289 new ModalWindow(), lock_widget->GetNativeView()); |
| 288 lock_modal_widget->Show(); | 290 lock_modal_widget->Show(); |
| 289 EXPECT_FALSE(Shell::GetInstance()->IsScreenLocked()); | 291 EXPECT_FALSE(Shell::GetInstance()->IsScreenLocked()); |
| 290 lock_widget->Show(); | 292 lock_widget->Show(); |
| 291 EXPECT_TRUE(Shell::GetInstance()->IsScreenLocked()); | 293 EXPECT_TRUE(Shell::GetInstance()->IsScreenLocked()); |
| 292 lock_modal_widget->Close(); | 294 lock_modal_widget->Close(); |
| 293 EXPECT_TRUE(Shell::GetInstance()->IsScreenLocked()); | 295 EXPECT_TRUE(Shell::GetInstance()->IsScreenLocked()); |
| 294 lock_widget->Close(); | 296 lock_widget->Close(); |
| 295 EXPECT_FALSE(Shell::GetInstance()->IsScreenLocked()); | 297 EXPECT_FALSE(Shell::GetInstance()->IsScreenLocked()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 } | 335 } |
| 334 | 336 |
| 335 TEST_F(ShellTest, ChangeWindowMode) { | 337 TEST_F(ShellTest, ChangeWindowMode) { |
| 336 // We start with the usual window containers. | 338 // We start with the usual window containers. |
| 337 ExpectAllContainers(); | 339 ExpectAllContainers(); |
| 338 // We're not in compact window mode by default. | 340 // We're not in compact window mode by default. |
| 339 Shell* shell = Shell::GetInstance(); | 341 Shell* shell = Shell::GetInstance(); |
| 340 EXPECT_FALSE(shell->IsWindowModeCompact()); | 342 EXPECT_FALSE(shell->IsWindowModeCompact()); |
| 341 // We have a default container event filter (for window drags). | 343 // We have a default container event filter (for window drags). |
| 342 EXPECT_TRUE(GetDefaultContainer()->event_filter()); | 344 EXPECT_TRUE(GetDefaultContainer()->event_filter()); |
| 343 // We have a launcher. | 345 // Launcher is visible. |
| 344 EXPECT_TRUE(shell->launcher()->widget()->IsVisible()); | 346 views::Widget* launcher_widget = shell->launcher()->widget(); |
| 347 EXPECT_TRUE(launcher_widget->IsVisible()); |
| 348 // Launcher is at bottom-left of screen. |
| 349 EXPECT_EQ(0, launcher_widget->GetWindowScreenBounds().x()); |
| 350 EXPECT_EQ(RootWindow::GetInstance()->GetHostSize().height(), |
| 351 launcher_widget->GetWindowScreenBounds().bottom()); |
| 345 // We have a desktop background. | 352 // We have a desktop background. |
| 346 EXPECT_TRUE(shell->root_window_layout_->background_widget()); | 353 EXPECT_TRUE(shell->root_window_layout_->background_widget()); |
| 347 | 354 |
| 348 // Create a normal window. It is not maximized. | 355 // Create a normal window. It is not maximized. |
| 349 views::Widget::InitParams widget_params( | 356 views::Widget::InitParams widget_params( |
| 350 views::Widget::InitParams::TYPE_WINDOW); | 357 views::Widget::InitParams::TYPE_WINDOW); |
| 351 widget_params.bounds.SetRect(11, 22, 300, 400); | 358 widget_params.bounds.SetRect(11, 22, 300, 400); |
| 352 views::Widget* widget = CreateTestWindow(widget_params); | 359 views::Widget* widget = CreateTestWindow(widget_params); |
| 353 widget->Show(); | 360 widget->Show(); |
| 354 EXPECT_FALSE(widget->IsMaximized()); | 361 EXPECT_FALSE(widget->IsMaximized()); |
| 355 | 362 |
| 356 // Set our new mode. | 363 // Set our new mode. |
| 357 shell->ChangeWindowMode(Shell::MODE_COMPACT); | 364 shell->ChangeWindowMode(Shell::MODE_COMPACT); |
| 358 EXPECT_TRUE(shell->IsWindowModeCompact()); | 365 EXPECT_TRUE(shell->IsWindowModeCompact()); |
| 359 // Compact mode does not use a default container event filter. | 366 // Compact mode does not use a default container event filter. |
| 360 EXPECT_FALSE(GetDefaultContainer()->event_filter()); | 367 EXPECT_FALSE(GetDefaultContainer()->event_filter()); |
| 361 // We still have all the usual containers. | 368 // We still have all the usual containers. |
| 362 ExpectAllContainers(); | 369 ExpectAllContainers(); |
| 363 | 370 |
| 364 // In compact window mode, all windows are maximized. | 371 // In compact window mode, all windows are maximized. |
| 365 EXPECT_TRUE(widget->IsMaximized()); | 372 EXPECT_TRUE(widget->IsMaximized()); |
| 366 // Window bounds got updated to fill the work area. | 373 // Window bounds got updated to fill the work area. |
| 367 EXPECT_EQ(widget->GetWorkAreaBoundsInScreen(), | 374 EXPECT_EQ(widget->GetWorkAreaBoundsInScreen(), |
| 368 widget->GetWindowScreenBounds()); | 375 widget->GetWindowScreenBounds()); |
| 369 // Launcher is hidden. | 376 // Launcher is hidden. |
| 370 EXPECT_FALSE(shell->launcher()->widget()->IsVisible()); | 377 EXPECT_FALSE(launcher_widget->IsVisible()); |
| 371 // Desktop background is gone. | 378 // Desktop background is gone. |
| 372 EXPECT_FALSE(shell->root_window_layout_->background_widget()); | 379 EXPECT_FALSE(shell->root_window_layout_->background_widget()); |
| 373 | 380 |
| 374 // Switch back to overlapping mode. | 381 // Switch back to overlapping mode. |
| 375 shell->ChangeWindowMode(Shell::MODE_OVERLAPPING); | 382 shell->ChangeWindowMode(Shell::MODE_OVERLAPPING); |
| 376 EXPECT_FALSE(shell->IsWindowModeCompact()); | 383 EXPECT_FALSE(shell->IsWindowModeCompact()); |
| 377 // Event filter came back. | 384 // Event filter came back. |
| 378 EXPECT_TRUE(GetDefaultContainer()->event_filter()); | 385 EXPECT_TRUE(GetDefaultContainer()->event_filter()); |
| 379 // Launcher is visible again. | 386 // Launcher is visible again. |
| 380 EXPECT_TRUE(shell->launcher()->widget()->IsVisible()); | 387 EXPECT_TRUE(launcher_widget->IsVisible()); |
| 388 // Launcher is at bottom-left of screen. |
| 389 EXPECT_EQ(0, launcher_widget->GetWindowScreenBounds().x()); |
| 390 EXPECT_EQ(RootWindow::GetInstance()->GetHostSize().height(), |
| 391 launcher_widget->GetWindowScreenBounds().bottom()); |
| 381 // Desktop background is back. | 392 // Desktop background is back. |
| 382 EXPECT_TRUE(shell->root_window_layout_->background_widget()); | 393 EXPECT_TRUE(shell->root_window_layout_->background_widget()); |
| 383 | 394 |
| 384 // Clean up. | 395 // Clean up. |
| 385 widget->Close(); | 396 widget->Close(); |
| 386 } | 397 } |
| 387 | 398 |
| 399 // Windows bots won't let us create large root windows, and this behavior is |
| 400 // only relevant on Chrome OS devices. |
| 401 #if defined(OS_CHROMEOS) |
| 402 TEST_F(ShellTest, ResizeRootWindow) { |
| 403 // We dynamically change window mode only with full-screen host windows. |
| 404 AutoResetUseFullscreenHostWindow use_fullscreen_host_window(true); |
| 405 |
| 406 // Switching to a small screen enables compact window mode. |
| 407 RootWindow::GetInstance()->SetHostSize(gfx::Size(1024, 768)); |
| 408 EXPECT_TRUE(Shell::GetInstance()->IsWindowModeCompact()); |
| 409 |
| 410 // Launcher is hidden. |
| 411 views::Widget* launcher_widget = Shell::GetInstance()->launcher()->widget(); |
| 412 EXPECT_FALSE(launcher_widget->IsVisible()); |
| 413 |
| 414 // Switching to a large screen disables compact window mode. |
| 415 RootWindow::GetInstance()->SetHostSize(gfx::Size(1920, 1080)); |
| 416 EXPECT_FALSE(Shell::GetInstance()->IsWindowModeCompact()); |
| 417 |
| 418 // Launcher is in the bottom-left corner of window. |
| 419 EXPECT_EQ(0, launcher_widget->GetWindowScreenBounds().x()); |
| 420 EXPECT_EQ(1080, launcher_widget->GetWindowScreenBounds().bottom()); |
| 421 } |
| 422 #endif // defined(OS_CHROMEOS) |
| 423 |
| 388 } // namespace ash | 424 } // namespace ash |
| OLD | NEW |