| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/shell.h" | 6 #include "ash/shell.h" |
| 7 #include "ash/shell_window_ids.h" | 7 #include "ash/shell_window_ids.h" |
| 8 #include "ash/test/aura_shell_test_base.h" | 8 #include "ash/test/aura_shell_test_base.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "ui/aura/test/aura_test_base.h" | 11 #include "ui/aura/test/aura_test_base.h" |
| 12 #include "ui/aura/root_window.h" | 12 #include "ui/aura/root_window.h" |
| 13 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 14 #include "ui/gfx/size.h" | 14 #include "ui/gfx/size.h" |
| 15 #include "ui/views/widget/widget.h" | 15 #include "ui/views/widget/widget.h" |
| 16 #include "ui/views/widget/widget_delegate.h" | 16 #include "ui/views/widget/widget_delegate.h" |
| 17 | 17 |
| 18 namespace aura_shell { | 18 namespace ash { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 views::Widget* CreateTestWindow(const views::Widget::InitParams& params) { | 22 views::Widget* CreateTestWindow(const views::Widget::InitParams& params) { |
| 23 views::Widget* widget = new views::Widget; | 23 views::Widget* widget = new views::Widget; |
| 24 widget->Init(params); | 24 widget->Init(params); |
| 25 return widget; | 25 return widget; |
| 26 } | 26 } |
| 27 | 27 |
| 28 aura::Window* GetDefaultContainer() { | 28 aura::Window* GetDefaultContainer() { |
| 29 return Shell::GetInstance()->GetContainer( | 29 return Shell::GetInstance()->GetContainer( |
| 30 aura_shell::internal::kShellWindowId_DefaultContainer); | 30 ash::internal::kShellWindowId_DefaultContainer); |
| 31 } | 31 } |
| 32 | 32 |
| 33 aura::Window* GetAlwaysOnTopContainer() { | 33 aura::Window* GetAlwaysOnTopContainer() { |
| 34 return Shell::GetInstance()->GetContainer( | 34 return Shell::GetInstance()->GetContainer( |
| 35 aura_shell::internal::kShellWindowId_AlwaysOnTopContainer); | 35 ash::internal::kShellWindowId_AlwaysOnTopContainer); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void TestCreateWindow(views::Widget::InitParams::Type type, | 38 void TestCreateWindow(views::Widget::InitParams::Type type, |
| 39 bool always_on_top, | 39 bool always_on_top, |
| 40 aura::Window* expected_container) { | 40 aura::Window* expected_container) { |
| 41 views::Widget::InitParams widget_params(type); | 41 views::Widget::InitParams widget_params(type); |
| 42 widget_params.keep_on_top = always_on_top; | 42 widget_params.keep_on_top = always_on_top; |
| 43 | 43 |
| 44 views::Widget* widget = CreateTestWindow(widget_params); | 44 views::Widget* widget = CreateTestWindow(widget_params); |
| 45 widget->Show(); | 45 widget->Show(); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 // It should be in default container. | 156 // It should be in default container. |
| 157 EXPECT_EQ(GetDefaultContainer(), widget->GetNativeWindow()->parent()); | 157 EXPECT_EQ(GetDefaultContainer(), widget->GetNativeWindow()->parent()); |
| 158 | 158 |
| 159 // Create a modal window. | 159 // Create a modal window. |
| 160 views::Widget* modal_widget = views::Widget::CreateWindowWithParent( | 160 views::Widget* modal_widget = views::Widget::CreateWindowWithParent( |
| 161 new ModalWindow(), widget->GetNativeView()); | 161 new ModalWindow(), widget->GetNativeView()); |
| 162 modal_widget->Show(); | 162 modal_widget->Show(); |
| 163 | 163 |
| 164 // It should be in modal container. | 164 // It should be in modal container. |
| 165 aura::Window* modal_container = Shell::GetInstance()->GetContainer( | 165 aura::Window* modal_container = Shell::GetInstance()->GetContainer( |
| 166 aura_shell::internal::kShellWindowId_ModalContainer); | 166 ash::internal::kShellWindowId_ModalContainer); |
| 167 EXPECT_EQ(modal_container, modal_widget->GetNativeWindow()->parent()); | 167 EXPECT_EQ(modal_container, modal_widget->GetNativeWindow()->parent()); |
| 168 | 168 |
| 169 modal_widget->Close(); | 169 modal_widget->Close(); |
| 170 widget->Close(); | 170 widget->Close(); |
| 171 } | 171 } |
| 172 | 172 |
| 173 TEST_F(ShellTest, CreateLockScreenModalWindow) { | 173 TEST_F(ShellTest, CreateLockScreenModalWindow) { |
| 174 views::Widget::InitParams widget_params( | 174 views::Widget::InitParams widget_params( |
| 175 views::Widget::InitParams::TYPE_WINDOW); | 175 views::Widget::InitParams::TYPE_WINDOW); |
| 176 | 176 |
| 177 // Create a normal window. | 177 // Create a normal window. |
| 178 views::Widget* widget = CreateTestWindow(widget_params); | 178 views::Widget* widget = CreateTestWindow(widget_params); |
| 179 widget->Show(); | 179 widget->Show(); |
| 180 | 180 |
| 181 // It should be in default container. | 181 // It should be in default container. |
| 182 EXPECT_EQ(GetDefaultContainer(), widget->GetNativeWindow()->parent()); | 182 EXPECT_EQ(GetDefaultContainer(), widget->GetNativeWindow()->parent()); |
| 183 | 183 |
| 184 // Create a LockScreen window. | 184 // Create a LockScreen window. |
| 185 views::Widget* lock_widget = CreateTestWindow(widget_params); | 185 views::Widget* lock_widget = CreateTestWindow(widget_params); |
| 186 aura_shell::Shell::GetInstance()->GetContainer( | 186 ash::Shell::GetInstance()->GetContainer( |
| 187 aura_shell::internal::kShellWindowId_LockScreenContainer)-> | 187 ash::internal::kShellWindowId_LockScreenContainer)-> |
| 188 AddChild(lock_widget->GetNativeView()); | 188 AddChild(lock_widget->GetNativeView()); |
| 189 lock_widget->Show(); | 189 lock_widget->Show(); |
| 190 | 190 |
| 191 // It should be in LockScreen container. | 191 // It should be in LockScreen container. |
| 192 aura::Window* lock_screen = Shell::GetInstance()->GetContainer( | 192 aura::Window* lock_screen = Shell::GetInstance()->GetContainer( |
| 193 aura_shell::internal::kShellWindowId_LockScreenContainer); | 193 ash::internal::kShellWindowId_LockScreenContainer); |
| 194 EXPECT_EQ(lock_screen, lock_widget->GetNativeWindow()->parent()); | 194 EXPECT_EQ(lock_screen, lock_widget->GetNativeWindow()->parent()); |
| 195 | 195 |
| 196 // Create a modal window with a lock window as parent. | 196 // Create a modal window with a lock window as parent. |
| 197 views::Widget* lock_modal_widget = views::Widget::CreateWindowWithParent( | 197 views::Widget* lock_modal_widget = views::Widget::CreateWindowWithParent( |
| 198 new ModalWindow(), lock_widget->GetNativeView()); | 198 new ModalWindow(), lock_widget->GetNativeView()); |
| 199 lock_modal_widget->Show(); | 199 lock_modal_widget->Show(); |
| 200 | 200 |
| 201 // It should be in LockScreen modal container. | 201 // It should be in LockScreen modal container. |
| 202 aura::Window* lock_modal_container = Shell::GetInstance()->GetContainer( | 202 aura::Window* lock_modal_container = Shell::GetInstance()->GetContainer( |
| 203 aura_shell::internal::kShellWindowId_LockModalContainer); | 203 ash::internal::kShellWindowId_LockModalContainer); |
| 204 EXPECT_EQ(lock_modal_container, | 204 EXPECT_EQ(lock_modal_container, |
| 205 lock_modal_widget->GetNativeWindow()->parent()); | 205 lock_modal_widget->GetNativeWindow()->parent()); |
| 206 | 206 |
| 207 // Create a modal window with a normal window as parent. | 207 // Create a modal window with a normal window as parent. |
| 208 views::Widget* modal_widget = views::Widget::CreateWindowWithParent( | 208 views::Widget* modal_widget = views::Widget::CreateWindowWithParent( |
| 209 new ModalWindow(), widget->GetNativeView()); | 209 new ModalWindow(), widget->GetNativeView()); |
| 210 modal_widget->Show(); | 210 modal_widget->Show(); |
| 211 | 211 |
| 212 // It should be in non-LockScreen modal container. | 212 // It should be in non-LockScreen modal container. |
| 213 aura::Window* modal_container = Shell::GetInstance()->GetContainer( | 213 aura::Window* modal_container = Shell::GetInstance()->GetContainer( |
| 214 aura_shell::internal::kShellWindowId_ModalContainer); | 214 ash::internal::kShellWindowId_ModalContainer); |
| 215 EXPECT_EQ(modal_container, modal_widget->GetNativeWindow()->parent()); | 215 EXPECT_EQ(modal_container, modal_widget->GetNativeWindow()->parent()); |
| 216 | 216 |
| 217 modal_widget->Close(); | 217 modal_widget->Close(); |
| 218 lock_modal_widget->Close(); | 218 lock_modal_widget->Close(); |
| 219 lock_widget->Close(); | 219 lock_widget->Close(); |
| 220 widget->Close(); | 220 widget->Close(); |
| 221 } | 221 } |
| 222 | 222 |
| 223 TEST_F(ShellTest, IsScreenLocked) { | 223 TEST_F(ShellTest, IsScreenLocked) { |
| 224 views::Widget::InitParams widget_params( | 224 views::Widget::InitParams widget_params( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 235 views::Widget* modal_widget = views::Widget::CreateWindowWithParent( | 235 views::Widget* modal_widget = views::Widget::CreateWindowWithParent( |
| 236 new ModalWindow(), widget->GetNativeView()); | 236 new ModalWindow(), widget->GetNativeView()); |
| 237 modal_widget->Show(); | 237 modal_widget->Show(); |
| 238 EXPECT_FALSE(Shell::GetInstance()->IsScreenLocked()); | 238 EXPECT_FALSE(Shell::GetInstance()->IsScreenLocked()); |
| 239 modal_widget->Close(); | 239 modal_widget->Close(); |
| 240 EXPECT_FALSE(Shell::GetInstance()->IsScreenLocked()); | 240 EXPECT_FALSE(Shell::GetInstance()->IsScreenLocked()); |
| 241 widget->Close(); | 241 widget->Close(); |
| 242 | 242 |
| 243 // A lock screen window locks the screen. | 243 // A lock screen window locks the screen. |
| 244 views::Widget* lock_widget = CreateTestWindow(widget_params); | 244 views::Widget* lock_widget = CreateTestWindow(widget_params); |
| 245 aura_shell::Shell::GetInstance()->GetContainer( | 245 ash::Shell::GetInstance()->GetContainer( |
| 246 aura_shell::internal::kShellWindowId_LockScreenContainer)-> | 246 ash::internal::kShellWindowId_LockScreenContainer)-> |
| 247 AddChild(lock_widget->GetNativeView()); | 247 AddChild(lock_widget->GetNativeView()); |
| 248 lock_widget->Show(); | 248 lock_widget->Show(); |
| 249 EXPECT_TRUE(Shell::GetInstance()->IsScreenLocked()); | 249 EXPECT_TRUE(Shell::GetInstance()->IsScreenLocked()); |
| 250 lock_widget->Hide(); | 250 lock_widget->Hide(); |
| 251 EXPECT_FALSE(Shell::GetInstance()->IsScreenLocked()); | 251 EXPECT_FALSE(Shell::GetInstance()->IsScreenLocked()); |
| 252 | 252 |
| 253 // A modal window with a lock window as parent does not lock the screen. The | 253 // A modal window with a lock window as parent does not lock the screen. The |
| 254 // screen is locked only when a lock windown is visible. | 254 // screen is locked only when a lock windown is visible. |
| 255 views::Widget* lock_modal_widget = views::Widget::CreateWindowWithParent( | 255 views::Widget* lock_modal_widget = views::Widget::CreateWindowWithParent( |
| 256 new ModalWindow(), lock_widget->GetNativeView()); | 256 new ModalWindow(), lock_widget->GetNativeView()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 277 // Alex-sized screens need compact mode. | 277 // Alex-sized screens need compact mode. |
| 278 monitor_size.SetSize(1280, 800); | 278 monitor_size.SetSize(1280, 800); |
| 279 EXPECT_TRUE(shell->DefaultToCompactWindowMode(monitor_size, &command_line)); | 279 EXPECT_TRUE(shell->DefaultToCompactWindowMode(monitor_size, &command_line)); |
| 280 | 280 |
| 281 // ZGB-sized screens need compact mode. | 281 // ZGB-sized screens need compact mode. |
| 282 monitor_size.SetSize(1366, 768); | 282 monitor_size.SetSize(1366, 768); |
| 283 EXPECT_TRUE(shell->DefaultToCompactWindowMode(monitor_size, &command_line)); | 283 EXPECT_TRUE(shell->DefaultToCompactWindowMode(monitor_size, &command_line)); |
| 284 | 284 |
| 285 // Even for a small screen, the user can force normal mode. | 285 // Even for a small screen, the user can force normal mode. |
| 286 monitor_size.SetSize(800, 600); | 286 monitor_size.SetSize(800, 600); |
| 287 command_line.AppendSwitchASCII(aura_shell::switches::kAuraWindowMode, | 287 command_line.AppendSwitchASCII(ash::switches::kAuraWindowMode, |
| 288 aura_shell::switches::kAuraWindowModeNormal); | 288 ash::switches::kAuraWindowModeNormal); |
| 289 EXPECT_FALSE(shell->DefaultToCompactWindowMode(monitor_size, &command_line)); | 289 EXPECT_FALSE(shell->DefaultToCompactWindowMode(monitor_size, &command_line)); |
| 290 } | 290 } |
| 291 | 291 |
| 292 } // namespace aura_shell | 292 } // namespace ash |
| OLD | NEW |