| 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/shell.h" | 5 #include "ash/shell.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 #include "ui/views/widget/widget_delegate.h" | 38 #include "ui/views/widget/widget_delegate.h" |
| 39 #include "ui/views/window/dialog_delegate.h" | 39 #include "ui/views/window/dialog_delegate.h" |
| 40 | 40 |
| 41 using aura::RootWindow; | 41 using aura::RootWindow; |
| 42 | 42 |
| 43 namespace ash { | 43 namespace ash { |
| 44 | 44 |
| 45 namespace { | 45 namespace { |
| 46 | 46 |
| 47 aura::Window* GetDefaultContainer() { | 47 aura::Window* GetDefaultContainer() { |
| 48 return Shell::GetContainer( | 48 return Shell::GetContainer(Shell::GetPrimaryRootWindow(), |
| 49 Shell::GetPrimaryRootWindow(), | 49 kShellWindowId_DefaultContainer); |
| 50 internal::kShellWindowId_DefaultContainer); | |
| 51 } | 50 } |
| 52 | 51 |
| 53 aura::Window* GetAlwaysOnTopContainer() { | 52 aura::Window* GetAlwaysOnTopContainer() { |
| 54 return Shell::GetContainer( | 53 return Shell::GetContainer(Shell::GetPrimaryRootWindow(), |
| 55 Shell::GetPrimaryRootWindow(), | 54 kShellWindowId_AlwaysOnTopContainer); |
| 56 internal::kShellWindowId_AlwaysOnTopContainer); | |
| 57 } | 55 } |
| 58 | 56 |
| 59 // Expect ALL the containers! | 57 // Expect ALL the containers! |
| 60 void ExpectAllContainers() { | 58 void ExpectAllContainers() { |
| 61 aura::Window* root_window = Shell::GetPrimaryRootWindow(); | 59 aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
| 60 EXPECT_TRUE(Shell::GetContainer(root_window, |
| 61 kShellWindowId_DesktopBackgroundContainer)); |
| 62 EXPECT_TRUE( |
| 63 Shell::GetContainer(root_window, kShellWindowId_DefaultContainer)); |
| 64 EXPECT_TRUE( |
| 65 Shell::GetContainer(root_window, kShellWindowId_AlwaysOnTopContainer)); |
| 66 EXPECT_TRUE(Shell::GetContainer(root_window, kShellWindowId_PanelContainer)); |
| 67 EXPECT_TRUE(Shell::GetContainer(root_window, kShellWindowId_ShelfContainer)); |
| 68 EXPECT_TRUE( |
| 69 Shell::GetContainer(root_window, kShellWindowId_SystemModalContainer)); |
| 62 EXPECT_TRUE(Shell::GetContainer( | 70 EXPECT_TRUE(Shell::GetContainer( |
| 63 root_window, internal::kShellWindowId_DesktopBackgroundContainer)); | 71 root_window, kShellWindowId_LockScreenBackgroundContainer)); |
| 72 EXPECT_TRUE( |
| 73 Shell::GetContainer(root_window, kShellWindowId_LockScreenContainer)); |
| 74 EXPECT_TRUE(Shell::GetContainer(root_window, |
| 75 kShellWindowId_LockSystemModalContainer)); |
| 76 EXPECT_TRUE(Shell::GetContainer(root_window, kShellWindowId_StatusContainer)); |
| 77 EXPECT_TRUE(Shell::GetContainer(root_window, kShellWindowId_MenuContainer)); |
| 78 EXPECT_TRUE(Shell::GetContainer(root_window, |
| 79 kShellWindowId_DragImageAndTooltipContainer)); |
| 80 EXPECT_TRUE( |
| 81 Shell::GetContainer(root_window, kShellWindowId_SettingBubbleContainer)); |
| 82 EXPECT_TRUE( |
| 83 Shell::GetContainer(root_window, kShellWindowId_OverlayContainer)); |
| 64 EXPECT_TRUE(Shell::GetContainer( | 84 EXPECT_TRUE(Shell::GetContainer( |
| 65 root_window, internal::kShellWindowId_DefaultContainer)); | 85 root_window, kShellWindowId_VirtualKeyboardParentContainer)); |
| 66 EXPECT_TRUE(Shell::GetContainer( | |
| 67 root_window, internal::kShellWindowId_AlwaysOnTopContainer)); | |
| 68 EXPECT_TRUE(Shell::GetContainer( | |
| 69 root_window, internal::kShellWindowId_PanelContainer)); | |
| 70 EXPECT_TRUE(Shell::GetContainer( | |
| 71 root_window, internal::kShellWindowId_ShelfContainer)); | |
| 72 EXPECT_TRUE(Shell::GetContainer( | |
| 73 root_window, internal::kShellWindowId_SystemModalContainer)); | |
| 74 EXPECT_TRUE(Shell::GetContainer( | |
| 75 root_window, internal::kShellWindowId_LockScreenBackgroundContainer)); | |
| 76 EXPECT_TRUE(Shell::GetContainer( | |
| 77 root_window, internal::kShellWindowId_LockScreenContainer)); | |
| 78 EXPECT_TRUE(Shell::GetContainer( | |
| 79 root_window, internal::kShellWindowId_LockSystemModalContainer)); | |
| 80 EXPECT_TRUE(Shell::GetContainer( | |
| 81 root_window, internal::kShellWindowId_StatusContainer)); | |
| 82 EXPECT_TRUE(Shell::GetContainer( | |
| 83 root_window, internal::kShellWindowId_MenuContainer)); | |
| 84 EXPECT_TRUE(Shell::GetContainer( | |
| 85 root_window, internal::kShellWindowId_DragImageAndTooltipContainer)); | |
| 86 EXPECT_TRUE(Shell::GetContainer( | |
| 87 root_window, internal::kShellWindowId_SettingBubbleContainer)); | |
| 88 EXPECT_TRUE(Shell::GetContainer( | |
| 89 root_window, internal::kShellWindowId_OverlayContainer)); | |
| 90 EXPECT_TRUE(Shell::GetContainer( | |
| 91 root_window, internal::kShellWindowId_VirtualKeyboardParentContainer)); | |
| 92 #if defined(OS_CHROMEOS) | 86 #if defined(OS_CHROMEOS) |
| 93 EXPECT_TRUE(Shell::GetContainer( | 87 EXPECT_TRUE( |
| 94 root_window, internal::kShellWindowId_MouseCursorContainer)); | 88 Shell::GetContainer(root_window, kShellWindowId_MouseCursorContainer)); |
| 95 #endif | 89 #endif |
| 96 } | 90 } |
| 97 | 91 |
| 98 class ModalWindow : public views::WidgetDelegateView { | 92 class ModalWindow : public views::WidgetDelegateView { |
| 99 public: | 93 public: |
| 100 ModalWindow() {} | 94 ModalWindow() {} |
| 101 virtual ~ModalWindow() {} | 95 virtual ~ModalWindow() {} |
| 102 | 96 |
| 103 // Overridden from views::WidgetDelegate: | 97 // Overridden from views::WidgetDelegate: |
| 104 virtual views::View* GetContentsView() OVERRIDE { | 98 virtual views::View* GetContentsView() OVERRIDE { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 DCHECK(menu_controller); | 173 DCHECK(menu_controller); |
| 180 EXPECT_EQ(views::MenuController::EXIT_NONE, menu_controller->exit_type()); | 174 EXPECT_EQ(views::MenuController::EXIT_NONE, menu_controller->exit_type()); |
| 181 | 175 |
| 182 // Create a LockScreen window. | 176 // Create a LockScreen window. |
| 183 views::Widget::InitParams widget_params( | 177 views::Widget::InitParams widget_params( |
| 184 views::Widget::InitParams::TYPE_WINDOW); | 178 views::Widget::InitParams::TYPE_WINDOW); |
| 185 SessionStateDelegate* delegate = | 179 SessionStateDelegate* delegate = |
| 186 Shell::GetInstance()->session_state_delegate(); | 180 Shell::GetInstance()->session_state_delegate(); |
| 187 delegate->LockScreen(); | 181 delegate->LockScreen(); |
| 188 views::Widget* lock_widget = CreateTestWindow(widget_params); | 182 views::Widget* lock_widget = CreateTestWindow(widget_params); |
| 189 ash::Shell::GetContainer( | 183 ash::Shell::GetContainer(Shell::GetPrimaryRootWindow(), |
| 190 Shell::GetPrimaryRootWindow(), | 184 ash::kShellWindowId_LockScreenContainer) |
| 191 ash::internal::kShellWindowId_LockScreenContainer)-> | 185 ->AddChild(lock_widget->GetNativeView()); |
| 192 AddChild(lock_widget->GetNativeView()); | |
| 193 lock_widget->Show(); | 186 lock_widget->Show(); |
| 194 EXPECT_TRUE(delegate->IsScreenLocked()); | 187 EXPECT_TRUE(delegate->IsScreenLocked()); |
| 195 EXPECT_TRUE(lock_widget->GetNativeView()->HasFocus()); | 188 EXPECT_TRUE(lock_widget->GetNativeView()->HasFocus()); |
| 196 | 189 |
| 197 // Verify menu is closed. | 190 // Verify menu is closed. |
| 198 EXPECT_NE(views::MenuController::EXIT_NONE, menu_controller->exit_type()); | 191 EXPECT_NE(views::MenuController::EXIT_NONE, menu_controller->exit_type()); |
| 199 lock_widget->Close(); | 192 lock_widget->Close(); |
| 200 delegate->UnlockScreen(); | 193 delegate->UnlockScreen(); |
| 201 | 194 |
| 202 // In case the menu wasn't closed, cancel the menu to exit the nested menu | 195 // In case the menu wasn't closed, cancel the menu to exit the nested menu |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 EXPECT_TRUE(GetDefaultContainer()->Contains( | 260 EXPECT_TRUE(GetDefaultContainer()->Contains( |
| 268 widget->GetNativeWindow()->parent())); | 261 widget->GetNativeWindow()->parent())); |
| 269 | 262 |
| 270 // Create a modal window. | 263 // Create a modal window. |
| 271 views::Widget* modal_widget = views::Widget::CreateWindowWithParent( | 264 views::Widget* modal_widget = views::Widget::CreateWindowWithParent( |
| 272 new ModalWindow(), widget->GetNativeView()); | 265 new ModalWindow(), widget->GetNativeView()); |
| 273 modal_widget->Show(); | 266 modal_widget->Show(); |
| 274 | 267 |
| 275 // It should be in modal container. | 268 // It should be in modal container. |
| 276 aura::Window* modal_container = Shell::GetContainer( | 269 aura::Window* modal_container = Shell::GetContainer( |
| 277 Shell::GetPrimaryRootWindow(), | 270 Shell::GetPrimaryRootWindow(), kShellWindowId_SystemModalContainer); |
| 278 internal::kShellWindowId_SystemModalContainer); | |
| 279 EXPECT_EQ(modal_container, modal_widget->GetNativeWindow()->parent()); | 271 EXPECT_EQ(modal_container, modal_widget->GetNativeWindow()->parent()); |
| 280 | 272 |
| 281 modal_widget->Close(); | 273 modal_widget->Close(); |
| 282 widget->Close(); | 274 widget->Close(); |
| 283 } | 275 } |
| 284 | 276 |
| 285 class TestModalDialogDelegate : public views::DialogDelegateView { | 277 class TestModalDialogDelegate : public views::DialogDelegateView { |
| 286 public: | 278 public: |
| 287 TestModalDialogDelegate() {} | 279 TestModalDialogDelegate() {} |
| 288 | 280 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 301 widget->Show(); | 293 widget->Show(); |
| 302 EXPECT_TRUE(widget->GetNativeView()->HasFocus()); | 294 EXPECT_TRUE(widget->GetNativeView()->HasFocus()); |
| 303 | 295 |
| 304 // It should be in default container. | 296 // It should be in default container. |
| 305 EXPECT_TRUE(GetDefaultContainer()->Contains( | 297 EXPECT_TRUE(GetDefaultContainer()->Contains( |
| 306 widget->GetNativeWindow()->parent())); | 298 widget->GetNativeWindow()->parent())); |
| 307 | 299 |
| 308 Shell::GetInstance()->session_state_delegate()->LockScreen(); | 300 Shell::GetInstance()->session_state_delegate()->LockScreen(); |
| 309 // Create a LockScreen window. | 301 // Create a LockScreen window. |
| 310 views::Widget* lock_widget = CreateTestWindow(widget_params); | 302 views::Widget* lock_widget = CreateTestWindow(widget_params); |
| 311 ash::Shell::GetContainer( | 303 ash::Shell::GetContainer(Shell::GetPrimaryRootWindow(), |
| 312 Shell::GetPrimaryRootWindow(), | 304 ash::kShellWindowId_LockScreenContainer) |
| 313 ash::internal::kShellWindowId_LockScreenContainer)-> | 305 ->AddChild(lock_widget->GetNativeView()); |
| 314 AddChild(lock_widget->GetNativeView()); | |
| 315 lock_widget->Show(); | 306 lock_widget->Show(); |
| 316 EXPECT_TRUE(lock_widget->GetNativeView()->HasFocus()); | 307 EXPECT_TRUE(lock_widget->GetNativeView()->HasFocus()); |
| 317 | 308 |
| 318 // It should be in LockScreen container. | 309 // It should be in LockScreen container. |
| 319 aura::Window* lock_screen = Shell::GetContainer( | 310 aura::Window* lock_screen = Shell::GetContainer( |
| 320 Shell::GetPrimaryRootWindow(), | 311 Shell::GetPrimaryRootWindow(), ash::kShellWindowId_LockScreenContainer); |
| 321 ash::internal::kShellWindowId_LockScreenContainer); | |
| 322 EXPECT_EQ(lock_screen, lock_widget->GetNativeWindow()->parent()); | 312 EXPECT_EQ(lock_screen, lock_widget->GetNativeWindow()->parent()); |
| 323 | 313 |
| 324 // Create a modal window with a lock window as parent. | 314 // Create a modal window with a lock window as parent. |
| 325 views::Widget* lock_modal_widget = views::Widget::CreateWindowWithParent( | 315 views::Widget* lock_modal_widget = views::Widget::CreateWindowWithParent( |
| 326 new ModalWindow(), lock_widget->GetNativeView()); | 316 new ModalWindow(), lock_widget->GetNativeView()); |
| 327 lock_modal_widget->Show(); | 317 lock_modal_widget->Show(); |
| 328 EXPECT_TRUE(lock_modal_widget->GetNativeView()->HasFocus()); | 318 EXPECT_TRUE(lock_modal_widget->GetNativeView()->HasFocus()); |
| 329 | 319 |
| 330 // It should be in LockScreen modal container. | 320 // It should be in LockScreen modal container. |
| 331 aura::Window* lock_modal_container = Shell::GetContainer( | 321 aura::Window* lock_modal_container = |
| 332 Shell::GetPrimaryRootWindow(), | 322 Shell::GetContainer(Shell::GetPrimaryRootWindow(), |
| 333 ash::internal::kShellWindowId_LockSystemModalContainer); | 323 ash::kShellWindowId_LockSystemModalContainer); |
| 334 EXPECT_EQ(lock_modal_container, | 324 EXPECT_EQ(lock_modal_container, |
| 335 lock_modal_widget->GetNativeWindow()->parent()); | 325 lock_modal_widget->GetNativeWindow()->parent()); |
| 336 | 326 |
| 337 // Create a modal window with a normal window as parent. | 327 // Create a modal window with a normal window as parent. |
| 338 views::Widget* modal_widget = views::Widget::CreateWindowWithParent( | 328 views::Widget* modal_widget = views::Widget::CreateWindowWithParent( |
| 339 new ModalWindow(), widget->GetNativeView()); | 329 new ModalWindow(), widget->GetNativeView()); |
| 340 modal_widget->Show(); | 330 modal_widget->Show(); |
| 341 // Window on lock screen shouldn't lost focus. | 331 // Window on lock screen shouldn't lost focus. |
| 342 EXPECT_FALSE(modal_widget->GetNativeView()->HasFocus()); | 332 EXPECT_FALSE(modal_widget->GetNativeView()->HasFocus()); |
| 343 EXPECT_TRUE(lock_modal_widget->GetNativeView()->HasFocus()); | 333 EXPECT_TRUE(lock_modal_widget->GetNativeView()->HasFocus()); |
| 344 | 334 |
| 345 // It should be in non-LockScreen modal container. | 335 // It should be in non-LockScreen modal container. |
| 346 aura::Window* modal_container = Shell::GetContainer( | 336 aura::Window* modal_container = Shell::GetContainer( |
| 347 Shell::GetPrimaryRootWindow(), | 337 Shell::GetPrimaryRootWindow(), ash::kShellWindowId_SystemModalContainer); |
| 348 ash::internal::kShellWindowId_SystemModalContainer); | |
| 349 EXPECT_EQ(modal_container, modal_widget->GetNativeWindow()->parent()); | 338 EXPECT_EQ(modal_container, modal_widget->GetNativeWindow()->parent()); |
| 350 | 339 |
| 351 // Modal dialog without parent, caused crash see crbug.com/226141 | 340 // Modal dialog without parent, caused crash see crbug.com/226141 |
| 352 views::Widget* modal_dialog = views::DialogDelegate::CreateDialogWidget( | 341 views::Widget* modal_dialog = views::DialogDelegate::CreateDialogWidget( |
| 353 new TestModalDialogDelegate(), CurrentContext(), NULL); | 342 new TestModalDialogDelegate(), CurrentContext(), NULL); |
| 354 | 343 |
| 355 modal_dialog->Show(); | 344 modal_dialog->Show(); |
| 356 EXPECT_FALSE(modal_dialog->GetNativeView()->HasFocus()); | 345 EXPECT_FALSE(modal_dialog->GetNativeView()->HasFocus()); |
| 357 EXPECT_TRUE(lock_modal_widget->GetNativeView()->HasFocus()); | 346 EXPECT_TRUE(lock_modal_widget->GetNativeView()->HasFocus()); |
| 358 | 347 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 ExpectAllContainers(); | 390 ExpectAllContainers(); |
| 402 // Shelf is visible. | 391 // Shelf is visible. |
| 403 ShelfWidget* shelf_widget = Shelf::ForPrimaryDisplay()->shelf_widget(); | 392 ShelfWidget* shelf_widget = Shelf::ForPrimaryDisplay()->shelf_widget(); |
| 404 EXPECT_TRUE(shelf_widget->IsVisible()); | 393 EXPECT_TRUE(shelf_widget->IsVisible()); |
| 405 // Shelf is at bottom-left of screen. | 394 // Shelf is at bottom-left of screen. |
| 406 EXPECT_EQ(0, shelf_widget->GetWindowBoundsInScreen().x()); | 395 EXPECT_EQ(0, shelf_widget->GetWindowBoundsInScreen().x()); |
| 407 EXPECT_EQ(Shell::GetPrimaryRootWindow()->GetHost()->GetBounds().height(), | 396 EXPECT_EQ(Shell::GetPrimaryRootWindow()->GetHost()->GetBounds().height(), |
| 408 shelf_widget->GetWindowBoundsInScreen().bottom()); | 397 shelf_widget->GetWindowBoundsInScreen().bottom()); |
| 409 // We have a desktop background but not a bare layer. | 398 // We have a desktop background but not a bare layer. |
| 410 // TODO (antrim): enable once we find out why it fails component build. | 399 // TODO (antrim): enable once we find out why it fails component build. |
| 411 // internal::DesktopBackgroundWidgetController* background = | 400 // DesktopBackgroundWidgetController* background = |
| 412 // Shell::GetPrimaryRootWindow()-> | 401 // Shell::GetPrimaryRootWindow()-> |
| 413 // GetProperty(internal::kWindowDesktopComponent); | 402 // GetProperty(kWindowDesktopComponent); |
| 414 // EXPECT_TRUE(background); | 403 // EXPECT_TRUE(background); |
| 415 // EXPECT_TRUE(background->widget()); | 404 // EXPECT_TRUE(background->widget()); |
| 416 // EXPECT_FALSE(background->layer()); | 405 // EXPECT_FALSE(background->layer()); |
| 417 | 406 |
| 418 // Create a normal window. It is not maximized. | 407 // Create a normal window. It is not maximized. |
| 419 views::Widget::InitParams widget_params( | 408 views::Widget::InitParams widget_params( |
| 420 views::Widget::InitParams::TYPE_WINDOW); | 409 views::Widget::InitParams::TYPE_WINDOW); |
| 421 widget_params.bounds.SetRect(11, 22, 300, 400); | 410 widget_params.bounds.SetRect(11, 22, 300, 400); |
| 422 views::Widget* widget = CreateTestWindow(widget_params); | 411 views::Widget* widget = CreateTestWindow(widget_params); |
| 423 widget->Show(); | 412 widget->Show(); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 private: | 531 private: |
| 543 DISALLOW_COPY_AND_ASSIGN(ShellTest2); | 532 DISALLOW_COPY_AND_ASSIGN(ShellTest2); |
| 544 }; | 533 }; |
| 545 | 534 |
| 546 TEST_F(ShellTest2, DontCrashWhenWindowDeleted) { | 535 TEST_F(ShellTest2, DontCrashWhenWindowDeleted) { |
| 547 window_.reset(new aura::Window(NULL)); | 536 window_.reset(new aura::Window(NULL)); |
| 548 window_->Init(aura::WINDOW_LAYER_NOT_DRAWN); | 537 window_->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
| 549 } | 538 } |
| 550 | 539 |
| 551 } // namespace ash | 540 } // namespace ash |
| OLD | NEW |