Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: ash/shell_unittest.cc

Issue 2111443002: mash: Migrate SessionStateDelegate access to WmShell. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/common/ash_switches.h" 10 #include "ash/common/ash_switches.h"
11 #include "ash/common/session/session_state_delegate.h" 11 #include "ash/common/session/session_state_delegate.h"
12 #include "ash/common/shell_window_ids.h" 12 #include "ash/common/shell_window_ids.h"
13 #include "ash/common/wm_shell.h"
13 #include "ash/desktop_background/desktop_background_widget_controller.h" 14 #include "ash/desktop_background/desktop_background_widget_controller.h"
14 #include "ash/display/mouse_cursor_event_filter.h" 15 #include "ash/display/mouse_cursor_event_filter.h"
15 #include "ash/drag_drop/drag_drop_controller.h" 16 #include "ash/drag_drop/drag_drop_controller.h"
16 #include "ash/root_window_controller.h" 17 #include "ash/root_window_controller.h"
17 #include "ash/shelf/shelf.h" 18 #include "ash/shelf/shelf.h"
18 #include "ash/shelf/shelf_layout_manager.h" 19 #include "ash/shelf/shelf_layout_manager.h"
19 #include "ash/shelf/shelf_widget.h" 20 #include "ash/shelf/shelf_widget.h"
20 #include "ash/shell_delegate.h" 21 #include "ash/shell_delegate.h"
21 #include "ash/test/ash_test_base.h" 22 #include "ash/test/ash_test_base.h"
22 #include "ash/test/shell_test_api.h" 23 #include "ash/test/shell_test_api.h"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 void LockScreenAndVerifyMenuClosed() { 158 void LockScreenAndVerifyMenuClosed() {
158 // Verify a menu is open before locking. 159 // Verify a menu is open before locking.
159 views::MenuController* menu_controller = 160 views::MenuController* menu_controller =
160 views::MenuController::GetActiveInstance(); 161 views::MenuController::GetActiveInstance();
161 DCHECK(menu_controller); 162 DCHECK(menu_controller);
162 EXPECT_EQ(views::MenuController::EXIT_NONE, menu_controller->exit_type()); 163 EXPECT_EQ(views::MenuController::EXIT_NONE, menu_controller->exit_type());
163 164
164 // Create a LockScreen window. 165 // Create a LockScreen window.
165 views::Widget::InitParams widget_params( 166 views::Widget::InitParams widget_params(
166 views::Widget::InitParams::TYPE_WINDOW); 167 views::Widget::InitParams::TYPE_WINDOW);
167 SessionStateDelegate* delegate = 168 SessionStateDelegate* delegate = WmShell::Get()->GetSessionStateDelegate();
168 Shell::GetInstance()->session_state_delegate();
169 delegate->LockScreen(); 169 delegate->LockScreen();
170 views::Widget* lock_widget = CreateTestWindow(widget_params); 170 views::Widget* lock_widget = CreateTestWindow(widget_params);
171 ash::Shell::GetContainer(Shell::GetPrimaryRootWindow(), 171 Shell::GetContainer(Shell::GetPrimaryRootWindow(),
172 ash::kShellWindowId_LockScreenContainer) 172 kShellWindowId_LockScreenContainer)
173 ->AddChild(lock_widget->GetNativeView()); 173 ->AddChild(lock_widget->GetNativeView());
174 lock_widget->Show(); 174 lock_widget->Show();
175 EXPECT_TRUE(delegate->IsScreenLocked()); 175 EXPECT_TRUE(delegate->IsScreenLocked());
176 EXPECT_TRUE(lock_widget->GetNativeView()->HasFocus()); 176 EXPECT_TRUE(lock_widget->GetNativeView()->HasFocus());
177 177
178 // Verify menu is closed. 178 // Verify menu is closed.
179 EXPECT_NE(views::MenuController::EXIT_NONE, menu_controller->exit_type()); 179 EXPECT_NE(views::MenuController::EXIT_NONE, menu_controller->exit_type());
180 lock_widget->Close(); 180 lock_widget->Close();
181 delegate->UnlockScreen(); 181 delegate->UnlockScreen();
182 182
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 276
277 // Create a normal window. 277 // Create a normal window.
278 views::Widget* widget = CreateTestWindow(widget_params); 278 views::Widget* widget = CreateTestWindow(widget_params);
279 widget->Show(); 279 widget->Show();
280 EXPECT_TRUE(widget->GetNativeView()->HasFocus()); 280 EXPECT_TRUE(widget->GetNativeView()->HasFocus());
281 281
282 // It should be in default container. 282 // It should be in default container.
283 EXPECT_TRUE( 283 EXPECT_TRUE(
284 GetDefaultContainer()->Contains(widget->GetNativeWindow()->parent())); 284 GetDefaultContainer()->Contains(widget->GetNativeWindow()->parent()));
285 285
286 Shell::GetInstance()->session_state_delegate()->LockScreen(); 286 WmShell::Get()->GetSessionStateDelegate()->LockScreen();
287 // Create a LockScreen window. 287 // Create a LockScreen window.
288 views::Widget* lock_widget = CreateTestWindow(widget_params); 288 views::Widget* lock_widget = CreateTestWindow(widget_params);
289 ash::Shell::GetContainer(Shell::GetPrimaryRootWindow(), 289 Shell::GetContainer(Shell::GetPrimaryRootWindow(),
290 ash::kShellWindowId_LockScreenContainer) 290 kShellWindowId_LockScreenContainer)
291 ->AddChild(lock_widget->GetNativeView()); 291 ->AddChild(lock_widget->GetNativeView());
292 lock_widget->Show(); 292 lock_widget->Show();
293 EXPECT_TRUE(lock_widget->GetNativeView()->HasFocus()); 293 EXPECT_TRUE(lock_widget->GetNativeView()->HasFocus());
294 294
295 // It should be in LockScreen container. 295 // It should be in LockScreen container.
296 aura::Window* lock_screen = Shell::GetContainer( 296 aura::Window* lock_screen = Shell::GetContainer(
297 Shell::GetPrimaryRootWindow(), ash::kShellWindowId_LockScreenContainer); 297 Shell::GetPrimaryRootWindow(), kShellWindowId_LockScreenContainer);
298 EXPECT_EQ(lock_screen, lock_widget->GetNativeWindow()->parent()); 298 EXPECT_EQ(lock_screen, lock_widget->GetNativeWindow()->parent());
299 299
300 // Create a modal window with a lock window as parent. 300 // Create a modal window with a lock window as parent.
301 views::Widget* lock_modal_widget = views::Widget::CreateWindowWithParent( 301 views::Widget* lock_modal_widget = views::Widget::CreateWindowWithParent(
302 new ModalWindow(), lock_widget->GetNativeView()); 302 new ModalWindow(), lock_widget->GetNativeView());
303 lock_modal_widget->Show(); 303 lock_modal_widget->Show();
304 EXPECT_TRUE(lock_modal_widget->GetNativeView()->HasFocus()); 304 EXPECT_TRUE(lock_modal_widget->GetNativeView()->HasFocus());
305 305
306 // It should be in LockScreen modal container. 306 // It should be in LockScreen modal container.
307 aura::Window* lock_modal_container = 307 aura::Window* lock_modal_container =
308 Shell::GetContainer(Shell::GetPrimaryRootWindow(), 308 Shell::GetContainer(Shell::GetPrimaryRootWindow(),
309 ash::kShellWindowId_LockSystemModalContainer); 309 kShellWindowId_LockSystemModalContainer);
310 EXPECT_EQ(lock_modal_container, 310 EXPECT_EQ(lock_modal_container,
311 lock_modal_widget->GetNativeWindow()->parent()); 311 lock_modal_widget->GetNativeWindow()->parent());
312 312
313 // Create a modal window with a normal window as parent. 313 // Create a modal window with a normal window as parent.
314 views::Widget* modal_widget = views::Widget::CreateWindowWithParent( 314 views::Widget* modal_widget = views::Widget::CreateWindowWithParent(
315 new ModalWindow(), widget->GetNativeView()); 315 new ModalWindow(), widget->GetNativeView());
316 modal_widget->Show(); 316 modal_widget->Show();
317 // Window on lock screen shouldn't lost focus. 317 // Window on lock screen shouldn't lost focus.
318 EXPECT_FALSE(modal_widget->GetNativeView()->HasFocus()); 318 EXPECT_FALSE(modal_widget->GetNativeView()->HasFocus());
319 EXPECT_TRUE(lock_modal_widget->GetNativeView()->HasFocus()); 319 EXPECT_TRUE(lock_modal_widget->GetNativeView()->HasFocus());
320 320
321 // It should be in non-LockScreen modal container. 321 // It should be in non-LockScreen modal container.
322 aura::Window* modal_container = Shell::GetContainer( 322 aura::Window* modal_container = Shell::GetContainer(
323 Shell::GetPrimaryRootWindow(), ash::kShellWindowId_SystemModalContainer); 323 Shell::GetPrimaryRootWindow(), kShellWindowId_SystemModalContainer);
324 EXPECT_EQ(modal_container, modal_widget->GetNativeWindow()->parent()); 324 EXPECT_EQ(modal_container, modal_widget->GetNativeWindow()->parent());
325 325
326 // Modal dialog without parent, caused crash see crbug.com/226141 326 // Modal dialog without parent, caused crash see crbug.com/226141
327 views::Widget* modal_dialog = views::DialogDelegate::CreateDialogWidget( 327 views::Widget* modal_dialog = views::DialogDelegate::CreateDialogWidget(
328 new TestModalDialogDelegate(), CurrentContext(), NULL); 328 new TestModalDialogDelegate(), CurrentContext(), NULL);
329 329
330 modal_dialog->Show(); 330 modal_dialog->Show();
331 EXPECT_FALSE(modal_dialog->GetNativeView()->HasFocus()); 331 EXPECT_FALSE(modal_dialog->GetNativeView()->HasFocus());
332 EXPECT_TRUE(lock_modal_widget->GetNativeView()->HasFocus()); 332 EXPECT_TRUE(lock_modal_widget->GetNativeView()->HasFocus());
333 333
334 modal_dialog->Close(); 334 modal_dialog->Close();
335 modal_widget->Close(); 335 modal_widget->Close();
336 modal_widget->Close(); 336 modal_widget->Close();
337 lock_modal_widget->Close(); 337 lock_modal_widget->Close();
338 lock_widget->Close(); 338 lock_widget->Close();
339 widget->Close(); 339 widget->Close();
340 } 340 }
341 341
342 TEST_F(ShellTest, IsScreenLocked) { 342 TEST_F(ShellTest, IsScreenLocked) {
343 SessionStateDelegate* delegate = 343 SessionStateDelegate* delegate = WmShell::Get()->GetSessionStateDelegate();
344 Shell::GetInstance()->session_state_delegate();
345 delegate->LockScreen(); 344 delegate->LockScreen();
346 EXPECT_TRUE(delegate->IsScreenLocked()); 345 EXPECT_TRUE(delegate->IsScreenLocked());
347 delegate->UnlockScreen(); 346 delegate->UnlockScreen();
348 EXPECT_FALSE(delegate->IsScreenLocked()); 347 EXPECT_FALSE(delegate->IsScreenLocked());
349 } 348 }
350 349
351 TEST_F(ShellTest, LockScreenClosesActiveMenu) { 350 TEST_F(ShellTest, LockScreenClosesActiveMenu) {
352 SimpleMenuDelegate menu_delegate; 351 SimpleMenuDelegate menu_delegate;
353 std::unique_ptr<ui::SimpleMenuModel> menu_model( 352 std::unique_ptr<ui::SimpleMenuModel> menu_model(
354 new ui::SimpleMenuModel(&menu_delegate)); 353 new ui::SimpleMenuModel(&menu_delegate));
355 menu_model->AddItem(0, base::ASCIIToUTF16("Menu item")); 354 menu_model->AddItem(0, base::ASCIIToUTF16("Menu item"));
356 views::Widget* widget = ash::Shell::GetPrimaryRootWindowController() 355 views::Widget* widget =
357 ->wallpaper_controller() 356 Shell::GetPrimaryRootWindowController()->wallpaper_controller()->widget();
358 ->widget();
359 std::unique_ptr<views::MenuRunner> menu_runner( 357 std::unique_ptr<views::MenuRunner> menu_runner(
360 new views::MenuRunner(menu_model.get(), views::MenuRunner::CONTEXT_MENU)); 358 new views::MenuRunner(menu_model.get(), views::MenuRunner::CONTEXT_MENU));
361 359
362 // When MenuRunner runs a nested loop the LockScreenAndVerifyMenuClosed 360 // When MenuRunner runs a nested loop the LockScreenAndVerifyMenuClosed
363 // command will fire, check the menu state and ensure the nested menu loop 361 // command will fire, check the menu state and ensure the nested menu loop
364 // is exited so that the test will terminate. 362 // is exited so that the test will terminate.
365 base::ThreadTaskRunnerHandle::Get()->PostTask( 363 base::ThreadTaskRunnerHandle::Get()->PostTask(
366 FROM_HERE, base::Bind(&ShellTest::LockScreenAndVerifyMenuClosed, 364 FROM_HERE, base::Bind(&ShellTest::LockScreenAndVerifyMenuClosed,
367 base::Unretained(this))); 365 base::Unretained(this)));
368 366
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 TEST_F(ShellTest, ToggleAutoHide) { 441 TEST_F(ShellTest, ToggleAutoHide) {
444 std::unique_ptr<aura::Window> window(new aura::Window(NULL)); 442 std::unique_ptr<aura::Window> window(new aura::Window(NULL));
445 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 443 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
446 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); 444 window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
447 window->Init(ui::LAYER_TEXTURED); 445 window->Init(ui::LAYER_TEXTURED);
448 ParentWindowInPrimaryRootWindow(window.get()); 446 ParentWindowInPrimaryRootWindow(window.get());
449 window->Show(); 447 window->Show();
450 wm::ActivateWindow(window.get()); 448 wm::ActivateWindow(window.get());
451 449
452 Shelf* shelf = Shelf::ForPrimaryDisplay(); 450 Shelf* shelf = Shelf::ForPrimaryDisplay();
453 shelf->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 451 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
454 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); 452 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
455 453
456 shelf->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER); 454 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
457 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior()); 455 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
458 456
459 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 457 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
460 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior()); 458 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
461 459
462 shelf->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 460 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
463 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); 461 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
464 462
465 shelf->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER); 463 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
466 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior()); 464 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
467 } 465 }
468 466
469 // Tests that the cursor-filter is ahead of the drag-drop controller in the 467 // Tests that the cursor-filter is ahead of the drag-drop controller in the
470 // pre-target list. 468 // pre-target list.
471 TEST_F(ShellTest, TestPreTargetHandlerOrder) { 469 TEST_F(ShellTest, TestPreTargetHandlerOrder) {
472 Shell* shell = Shell::GetInstance(); 470 Shell* shell = Shell::GetInstance();
473 ui::EventTargetTestApi test_api(shell); 471 ui::EventTargetTestApi test_api(shell);
474 test::ShellTestApi shell_test_api(shell); 472 test::ShellTestApi shell_test_api(shell);
475 473
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 private: 509 private:
512 DISALLOW_COPY_AND_ASSIGN(ShellTest2); 510 DISALLOW_COPY_AND_ASSIGN(ShellTest2);
513 }; 511 };
514 512
515 TEST_F(ShellTest2, DontCrashWhenWindowDeleted) { 513 TEST_F(ShellTest2, DontCrashWhenWindowDeleted) {
516 window_.reset(new aura::Window(NULL)); 514 window_.reset(new aura::Window(NULL));
517 window_->Init(ui::LAYER_NOT_DRAWN); 515 window_->Init(ui::LAYER_NOT_DRAWN);
518 } 516 }
519 517
520 } // namespace ash 518 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698