| 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" |
| 11 #include "ash/desktop_background/desktop_background_widget_controller.h" | 11 #include "ash/desktop_background/desktop_background_widget_controller.h" |
| 12 #include "ash/launcher/launcher.h" | 12 #include "ash/launcher/launcher.h" |
| 13 #include "ash/root_window_controller.h" | 13 #include "ash/root_window_controller.h" |
| 14 #include "ash/session_state_delegate.h" | 14 #include "ash/session_state_delegate.h" |
| 15 #include "ash/shelf/shelf_layout_manager.h" | 15 #include "ash/shelf/shelf_layout_manager.h" |
| 16 #include "ash/shelf/shelf_widget.h" | 16 #include "ash/shelf/shelf_widget.h" |
| 17 #include "ash/shell_window_ids.h" | 17 #include "ash/shell_window_ids.h" |
| 18 #include "ash/test/ash_test_base.h" | 18 #include "ash/test/ash_test_base.h" |
| 19 #include "ash/wm/root_window_layout_manager.h" | 19 #include "ash/wm/root_window_layout_manager.h" |
| 20 #include "ash/wm/window_util.h" | 20 #include "ash/wm/window_util.h" |
| 21 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
| 22 #include "ui/aura/client/aura_constants.h" | 22 #include "ui/aura/client/aura_constants.h" |
| 23 #include "ui/aura/root_window.h" | 23 #include "ui/aura/root_window.h" |
| 24 #include "ui/aura/window.h" | 24 #include "ui/aura/window.h" |
| 25 #include "ui/gfx/size.h" | 25 #include "ui/gfx/size.h" |
| 26 #include "ui/views/widget/widget.h" | 26 #include "ui/views/widget/widget.h" |
| 27 #include "ui/views/widget/widget_delegate.h" | 27 #include "ui/views/widget/widget_delegate.h" |
| 28 #include "ui/views/window/dialog_delegate.h" |
| 28 | 29 |
| 29 using aura::RootWindow; | 30 using aura::RootWindow; |
| 30 | 31 |
| 31 namespace ash { | 32 namespace ash { |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 aura::Window* GetDefaultContainer() { | 36 aura::Window* GetDefaultContainer() { |
| 36 return Shell::GetContainer( | 37 return Shell::GetContainer( |
| 37 Shell::GetPrimaryRootWindow(), | 38 Shell::GetPrimaryRootWindow(), |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 // It should be in modal container. | 201 // It should be in modal container. |
| 201 aura::Window* modal_container = Shell::GetContainer( | 202 aura::Window* modal_container = Shell::GetContainer( |
| 202 Shell::GetPrimaryRootWindow(), | 203 Shell::GetPrimaryRootWindow(), |
| 203 internal::kShellWindowId_SystemModalContainer); | 204 internal::kShellWindowId_SystemModalContainer); |
| 204 EXPECT_EQ(modal_container, modal_widget->GetNativeWindow()->parent()); | 205 EXPECT_EQ(modal_container, modal_widget->GetNativeWindow()->parent()); |
| 205 | 206 |
| 206 modal_widget->Close(); | 207 modal_widget->Close(); |
| 207 widget->Close(); | 208 widget->Close(); |
| 208 } | 209 } |
| 209 | 210 |
| 211 class TestModalDialogDelegate : public views::DialogDelegateView { |
| 212 public: |
| 213 TestModalDialogDelegate() {} |
| 214 |
| 215 // Overridden from views::WidgetDelegate: |
| 216 virtual ui::ModalType GetModalType() const OVERRIDE { |
| 217 return ui::MODAL_TYPE_SYSTEM; |
| 218 } |
| 219 }; |
| 220 |
| 210 TEST_F(ShellTest, CreateLockScreenModalWindow) { | 221 TEST_F(ShellTest, CreateLockScreenModalWindow) { |
| 211 views::Widget::InitParams widget_params( | 222 views::Widget::InitParams widget_params( |
| 212 views::Widget::InitParams::TYPE_WINDOW); | 223 views::Widget::InitParams::TYPE_WINDOW); |
| 213 | 224 |
| 214 // Create a normal window. | 225 // Create a normal window. |
| 215 views::Widget* widget = CreateTestWindow(widget_params); | 226 views::Widget* widget = CreateTestWindow(widget_params); |
| 216 widget->Show(); | 227 widget->Show(); |
| 228 EXPECT_TRUE(widget->GetNativeView()->HasFocus()); |
| 217 | 229 |
| 218 // It should be in default container. | 230 // It should be in default container. |
| 219 EXPECT_TRUE(GetDefaultContainer()->Contains( | 231 EXPECT_TRUE(GetDefaultContainer()->Contains( |
| 220 widget->GetNativeWindow()->parent())); | 232 widget->GetNativeWindow()->parent())); |
| 221 | 233 |
| 222 Shell::GetInstance()->session_state_delegate()->LockScreen(); | 234 Shell::GetInstance()->session_state_delegate()->LockScreen(); |
| 223 // Create a LockScreen window. | 235 // Create a LockScreen window. |
| 224 views::Widget* lock_widget = CreateTestWindow(widget_params); | 236 views::Widget* lock_widget = CreateTestWindow(widget_params); |
| 225 ash::Shell::GetContainer( | 237 ash::Shell::GetContainer( |
| 226 Shell::GetPrimaryRootWindow(), | 238 Shell::GetPrimaryRootWindow(), |
| 227 ash::internal::kShellWindowId_LockScreenContainer)-> | 239 ash::internal::kShellWindowId_LockScreenContainer)-> |
| 228 AddChild(lock_widget->GetNativeView()); | 240 AddChild(lock_widget->GetNativeView()); |
| 229 lock_widget->Show(); | 241 lock_widget->Show(); |
| 242 EXPECT_TRUE(lock_widget->GetNativeView()->HasFocus()); |
| 230 | 243 |
| 231 // It should be in LockScreen container. | 244 // It should be in LockScreen container. |
| 232 aura::Window* lock_screen = Shell::GetContainer( | 245 aura::Window* lock_screen = Shell::GetContainer( |
| 233 Shell::GetPrimaryRootWindow(), | 246 Shell::GetPrimaryRootWindow(), |
| 234 ash::internal::kShellWindowId_LockScreenContainer); | 247 ash::internal::kShellWindowId_LockScreenContainer); |
| 235 EXPECT_EQ(lock_screen, lock_widget->GetNativeWindow()->parent()); | 248 EXPECT_EQ(lock_screen, lock_widget->GetNativeWindow()->parent()); |
| 236 | 249 |
| 237 // Create a modal window with a lock window as parent. | 250 // Create a modal window with a lock window as parent. |
| 238 views::Widget* lock_modal_widget = views::Widget::CreateWindowWithParent( | 251 views::Widget* lock_modal_widget = views::Widget::CreateWindowWithParent( |
| 239 new ModalWindow(), lock_widget->GetNativeView()); | 252 new ModalWindow(), lock_widget->GetNativeView()); |
| 240 lock_modal_widget->Show(); | 253 lock_modal_widget->Show(); |
| 254 EXPECT_TRUE(lock_modal_widget->GetNativeView()->HasFocus()); |
| 241 | 255 |
| 242 // It should be in LockScreen modal container. | 256 // It should be in LockScreen modal container. |
| 243 aura::Window* lock_modal_container = Shell::GetContainer( | 257 aura::Window* lock_modal_container = Shell::GetContainer( |
| 244 Shell::GetPrimaryRootWindow(), | 258 Shell::GetPrimaryRootWindow(), |
| 245 ash::internal::kShellWindowId_LockSystemModalContainer); | 259 ash::internal::kShellWindowId_LockSystemModalContainer); |
| 246 EXPECT_EQ(lock_modal_container, | 260 EXPECT_EQ(lock_modal_container, |
| 247 lock_modal_widget->GetNativeWindow()->parent()); | 261 lock_modal_widget->GetNativeWindow()->parent()); |
| 248 | 262 |
| 249 // Create a modal window with a normal window as parent. | 263 // Create a modal window with a normal window as parent. |
| 250 views::Widget* modal_widget = views::Widget::CreateWindowWithParent( | 264 views::Widget* modal_widget = views::Widget::CreateWindowWithParent( |
| 251 new ModalWindow(), widget->GetNativeView()); | 265 new ModalWindow(), widget->GetNativeView()); |
| 252 modal_widget->Show(); | 266 modal_widget->Show(); |
| 267 // Window on lock screen shouldn't lost focus. |
| 268 EXPECT_FALSE(modal_widget->GetNativeView()->HasFocus()); |
| 269 EXPECT_TRUE(lock_modal_widget->GetNativeView()->HasFocus()); |
| 253 | 270 |
| 254 // It should be in non-LockScreen modal container. | 271 // It should be in non-LockScreen modal container. |
| 255 aura::Window* modal_container = Shell::GetContainer( | 272 aura::Window* modal_container = Shell::GetContainer( |
| 256 Shell::GetPrimaryRootWindow(), | 273 Shell::GetPrimaryRootWindow(), |
| 257 ash::internal::kShellWindowId_SystemModalContainer); | 274 ash::internal::kShellWindowId_SystemModalContainer); |
| 258 EXPECT_EQ(modal_container, modal_widget->GetNativeWindow()->parent()); | 275 EXPECT_EQ(modal_container, modal_widget->GetNativeWindow()->parent()); |
| 259 | 276 |
| 277 // Modal dialog without parent, caused crash see crbug.com/226141 |
| 278 views::Widget* modal_dialog = views::DialogDelegate::CreateDialogWidget( |
| 279 new TestModalDialogDelegate(), CurrentContext(), NULL); |
| 280 |
| 281 modal_dialog->Show(); |
| 282 EXPECT_FALSE(modal_dialog->GetNativeView()->HasFocus()); |
| 283 EXPECT_TRUE(lock_modal_widget->GetNativeView()->HasFocus()); |
| 284 |
| 285 modal_dialog->Close(); |
| 286 modal_widget->Close(); |
| 260 modal_widget->Close(); | 287 modal_widget->Close(); |
| 261 lock_modal_widget->Close(); | 288 lock_modal_widget->Close(); |
| 262 lock_widget->Close(); | 289 lock_widget->Close(); |
| 263 widget->Close(); | 290 widget->Close(); |
| 264 } | 291 } |
| 265 | 292 |
| 266 TEST_F(ShellTest, IsScreenLocked) { | 293 TEST_F(ShellTest, IsScreenLocked) { |
| 267 SessionStateDelegate* delegate = | 294 SessionStateDelegate* delegate = |
| 268 Shell::GetInstance()->session_state_delegate(); | 295 Shell::GetInstance()->session_state_delegate(); |
| 269 delegate->LockScreen(); | 296 delegate->LockScreen(); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 private: | 441 private: |
| 415 DISALLOW_COPY_AND_ASSIGN(ShellTest2); | 442 DISALLOW_COPY_AND_ASSIGN(ShellTest2); |
| 416 }; | 443 }; |
| 417 | 444 |
| 418 TEST_F(ShellTest2, DontCrashWhenWindowDeleted) { | 445 TEST_F(ShellTest2, DontCrashWhenWindowDeleted) { |
| 419 window_.reset(new aura::Window(NULL)); | 446 window_.reset(new aura::Window(NULL)); |
| 420 window_->Init(ui::LAYER_NOT_DRAWN); | 447 window_->Init(ui::LAYER_NOT_DRAWN); |
| 421 } | 448 } |
| 422 | 449 |
| 423 } // namespace ash | 450 } // namespace ash |
| OLD | NEW |