| OLD | NEW | 
|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/system/overview/overview_button_tray.h" | 5 #include "ash/system/overview/overview_button_tray.h" | 
| 6 | 6 | 
| 7 #include "ash/login_status.h" | 7 #include "ash/login_status.h" | 
| 8 #include "ash/public/cpp/config.h" | 8 #include "ash/public/cpp/config.h" | 
| 9 #include "ash/public/cpp/shelf_types.h" | 9 #include "ash/public/cpp/shelf_types.h" | 
| 10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" | 
| 11 #include "ash/rotator/screen_rotation_animator.h" | 11 #include "ash/rotator/screen_rotation_animator.h" | 
| 12 #include "ash/session/session_controller.h" | 12 #include "ash/session/session_controller.h" | 
| 13 #include "ash/shell.h" | 13 #include "ash/shell.h" | 
| 14 #include "ash/shell_port.h" | 14 #include "ash/shell_port.h" | 
| 15 #include "ash/system/status_area_widget.h" | 15 #include "ash/system/status_area_widget.h" | 
| 16 #include "ash/test/ash_test_base.h" | 16 #include "ash/test/ash_test_base.h" | 
| 17 #include "ash/test/ash_test_helper.h" | 17 #include "ash/test/ash_test_helper.h" | 
| 18 #include "ash/test/status_area_widget_test_helper.h" | 18 #include "ash/test/status_area_widget_test_helper.h" | 
| 19 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |  | 
| 20 #include "ash/wm/overview/window_selector_controller.h" | 19 #include "ash/wm/overview/window_selector_controller.h" | 
|  | 20 #include "ash/wm/tablet_mode/tablet_mode_controller.h" | 
| 21 #include "ash/wm/window_util.h" | 21 #include "ash/wm/window_util.h" | 
| 22 #include "base/command_line.h" | 22 #include "base/command_line.h" | 
| 23 #include "base/test/user_action_tester.h" | 23 #include "base/test/user_action_tester.h" | 
| 24 #include "base/time/time.h" | 24 #include "base/time/time.h" | 
| 25 #include "ui/aura/client/aura_constants.h" | 25 #include "ui/aura/client/aura_constants.h" | 
| 26 #include "ui/aura/window.h" | 26 #include "ui/aura/window.h" | 
| 27 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 27 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 
| 28 #include "ui/display/display_switches.h" | 28 #include "ui/display/display_switches.h" | 
| 29 #include "ui/display/manager/display_manager.h" | 29 #include "ui/display/manager/display_manager.h" | 
| 30 #include "ui/events/event.h" | 30 #include "ui/events/event.h" | 
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 91 void OverviewButtonTrayTest::NotifySessionStateChanged() { | 91 void OverviewButtonTrayTest::NotifySessionStateChanged() { | 
| 92   GetTray()->OnSessionStateChanged( | 92   GetTray()->OnSessionStateChanged( | 
| 93       Shell::Get()->session_controller()->GetSessionState()); | 93       Shell::Get()->session_controller()->GetSessionState()); | 
| 94 } | 94 } | 
| 95 | 95 | 
| 96 // Ensures that creation doesn't cause any crashes and adds the image icon. | 96 // Ensures that creation doesn't cause any crashes and adds the image icon. | 
| 97 TEST_F(OverviewButtonTrayTest, BasicConstruction) { | 97 TEST_F(OverviewButtonTrayTest, BasicConstruction) { | 
| 98   EXPECT_TRUE(GetImageView(GetTray()) != NULL); | 98   EXPECT_TRUE(GetImageView(GetTray()) != NULL); | 
| 99 } | 99 } | 
| 100 | 100 | 
| 101 // Test that maximize mode toggle changes visibility. | 101 // Test that tablet mode toggle changes visibility. | 
| 102 // OverviewButtonTray should only be visible when MaximizeMode is enabled. | 102 // OverviewButtonTray should only be visible when TabletMode is enabled. | 
| 103 // By default the system should not have MaximizeMode enabled. | 103 // By default the system should not have TabletMode enabled. | 
| 104 TEST_F(OverviewButtonTrayTest, MaximizeModeObserverOnMaximizeModeToggled) { | 104 TEST_F(OverviewButtonTrayTest, TabletModeObserverOnTabletModeToggled) { | 
| 105   ASSERT_FALSE(GetTray()->visible()); | 105   ASSERT_FALSE(GetTray()->visible()); | 
| 106   Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | 106   Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true); | 
| 107       true); |  | 
| 108   EXPECT_TRUE(GetTray()->visible()); | 107   EXPECT_TRUE(GetTray()->visible()); | 
| 109 | 108 | 
| 110   Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | 109   Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(false); | 
| 111       false); |  | 
| 112   EXPECT_FALSE(GetTray()->visible()); | 110   EXPECT_FALSE(GetTray()->visible()); | 
| 113 } | 111 } | 
| 114 | 112 | 
| 115 // Tests that activating this control brings up window selection mode. | 113 // Tests that activating this control brings up window selection mode. | 
| 116 TEST_F(OverviewButtonTrayTest, PerformAction) { | 114 TEST_F(OverviewButtonTrayTest, PerformAction) { | 
| 117   ASSERT_FALSE(Shell::Get()->window_selector_controller()->IsSelecting()); | 115   ASSERT_FALSE(Shell::Get()->window_selector_controller()->IsSelecting()); | 
| 118 | 116 | 
| 119   // Overview Mode only works when there is a window | 117   // Overview Mode only works when there is a window | 
| 120   std::unique_ptr<aura::Window> window( | 118   std::unique_ptr<aura::Window> window( | 
| 121       CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | 119       CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | 
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 183   EXPECT_EQ(2, user_action_tester.GetActionCount(kTrayOverview)); | 181   EXPECT_EQ(2, user_action_tester.GetActionCount(kTrayOverview)); | 
| 184 | 182 | 
| 185   // Tapping on the control to exit overview mode should record the | 183   // Tapping on the control to exit overview mode should record the | 
| 186   // user action. | 184   // user action. | 
| 187   GetTray()->PerformAction(tap); | 185   GetTray()->PerformAction(tap); | 
| 188   ASSERT_FALSE(Shell::Get()->window_selector_controller()->IsSelecting()); | 186   ASSERT_FALSE(Shell::Get()->window_selector_controller()->IsSelecting()); | 
| 189   EXPECT_EQ(3, user_action_tester.GetActionCount(kTrayOverview)); | 187   EXPECT_EQ(3, user_action_tester.GetActionCount(kTrayOverview)); | 
| 190 } | 188 } | 
| 191 | 189 | 
| 192 // Tests that a second OverviewButtonTray has been created, and only shows | 190 // Tests that a second OverviewButtonTray has been created, and only shows | 
| 193 // when MaximizeMode has been enabled,  when we are using multiple displays. | 191 // when TabletMode has been enabled,  when we are using multiple displays. | 
| 194 // By default the DisplayManger is in extended mode. | 192 // By default the DisplayManger is in extended mode. | 
| 195 TEST_F(OverviewButtonTrayTest, DisplaysOnBothDisplays) { | 193 TEST_F(OverviewButtonTrayTest, DisplaysOnBothDisplays) { | 
| 196   UpdateDisplay("400x400,200x200"); | 194   UpdateDisplay("400x400,200x200"); | 
| 197   EXPECT_FALSE(GetTray()->visible()); | 195   EXPECT_FALSE(GetTray()->visible()); | 
| 198   EXPECT_FALSE(GetSecondaryTray()->visible()); | 196   EXPECT_FALSE(GetSecondaryTray()->visible()); | 
| 199   Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | 197   Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true); | 
| 200       true); |  | 
| 201   EXPECT_TRUE(GetTray()->visible()); | 198   EXPECT_TRUE(GetTray()->visible()); | 
| 202   EXPECT_TRUE(GetSecondaryTray()->visible()); | 199   EXPECT_TRUE(GetSecondaryTray()->visible()); | 
| 203   Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | 200   Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(false); | 
| 204       false); |  | 
| 205 } | 201 } | 
| 206 | 202 | 
| 207 // Tests if Maximize Mode is enabled before a secondary display is attached | 203 // Tests if Maximize Mode is enabled before a secondary display is attached | 
| 208 // that the second OverviewButtonTray should be created in a visible state. | 204 // that the second OverviewButtonTray should be created in a visible state. | 
| 209 TEST_F(OverviewButtonTrayTest, SecondaryTrayCreatedVisible) { | 205 TEST_F(OverviewButtonTrayTest, SecondaryTrayCreatedVisible) { | 
| 210   Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | 206   Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true); | 
| 211       true); |  | 
| 212   UpdateDisplay("400x400,200x200"); | 207   UpdateDisplay("400x400,200x200"); | 
| 213   EXPECT_TRUE(GetSecondaryTray()->visible()); | 208   EXPECT_TRUE(GetSecondaryTray()->visible()); | 
| 214   Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | 209   Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(false); | 
| 215       false); |  | 
| 216 } | 210 } | 
| 217 | 211 | 
| 218 // Tests that the tray loses visibility when a user logs out, and that it | 212 // Tests that the tray loses visibility when a user logs out, and that it | 
| 219 // regains visibility when a user logs back in. | 213 // regains visibility when a user logs back in. | 
| 220 TEST_F(OverviewButtonTrayTest, VisibilityChangesForLoginStatus) { | 214 TEST_F(OverviewButtonTrayTest, VisibilityChangesForLoginStatus) { | 
| 221   Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | 215   Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true); | 
| 222       true); |  | 
| 223   SetUserLoggedIn(false); | 216   SetUserLoggedIn(false); | 
| 224   Shell::Get()->UpdateAfterLoginStatusChange(LoginStatus::NOT_LOGGED_IN); | 217   Shell::Get()->UpdateAfterLoginStatusChange(LoginStatus::NOT_LOGGED_IN); | 
| 225   EXPECT_FALSE(GetTray()->visible()); | 218   EXPECT_FALSE(GetTray()->visible()); | 
| 226   SetUserLoggedIn(true); | 219   SetUserLoggedIn(true); | 
| 227   SetSessionStarted(true); | 220   SetSessionStarted(true); | 
| 228   Shell::Get()->UpdateAfterLoginStatusChange(LoginStatus::USER); | 221   Shell::Get()->UpdateAfterLoginStatusChange(LoginStatus::USER); | 
| 229   EXPECT_TRUE(GetTray()->visible()); | 222   EXPECT_TRUE(GetTray()->visible()); | 
| 230   SetUserAddingScreenRunning(true); | 223   SetUserAddingScreenRunning(true); | 
| 231   NotifySessionStateChanged(); | 224   NotifySessionStateChanged(); | 
| 232   EXPECT_FALSE(GetTray()->visible()); | 225   EXPECT_FALSE(GetTray()->visible()); | 
| 233   SetUserAddingScreenRunning(false); | 226   SetUserAddingScreenRunning(false); | 
| 234   NotifySessionStateChanged(); | 227   NotifySessionStateChanged(); | 
| 235   EXPECT_TRUE(GetTray()->visible()); | 228   EXPECT_TRUE(GetTray()->visible()); | 
| 236   Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | 229   Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(false); | 
| 237       false); |  | 
| 238 } | 230 } | 
| 239 | 231 | 
| 240 // Tests that the tray only renders as active while selection is ongoing. Any | 232 // Tests that the tray only renders as active while selection is ongoing. Any | 
| 241 // dismissal of overview mode clears the active state. | 233 // dismissal of overview mode clears the active state. | 
| 242 TEST_F(OverviewButtonTrayTest, ActiveStateOnlyDuringOverviewMode) { | 234 TEST_F(OverviewButtonTrayTest, ActiveStateOnlyDuringOverviewMode) { | 
| 243   ASSERT_FALSE(Shell::Get()->window_selector_controller()->IsSelecting()); | 235   ASSERT_FALSE(Shell::Get()->window_selector_controller()->IsSelecting()); | 
| 244   ASSERT_FALSE(GetTray()->is_active()); | 236   ASSERT_FALSE(GetTray()->is_active()); | 
| 245 | 237 | 
| 246   // Overview Mode only works when there is a window | 238   // Overview Mode only works when there is a window | 
| 247   std::unique_ptr<aura::Window> window( | 239   std::unique_ptr<aura::Window> window( | 
| 248       CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | 240       CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | 
| 249 | 241 | 
| 250   EXPECT_TRUE(Shell::Get()->window_selector_controller()->ToggleOverview()); | 242   EXPECT_TRUE(Shell::Get()->window_selector_controller()->ToggleOverview()); | 
| 251   EXPECT_TRUE(Shell::Get()->window_selector_controller()->IsSelecting()); | 243   EXPECT_TRUE(Shell::Get()->window_selector_controller()->IsSelecting()); | 
| 252   EXPECT_TRUE(GetTray()->is_active()); | 244   EXPECT_TRUE(GetTray()->is_active()); | 
| 253 | 245 | 
| 254   EXPECT_TRUE(Shell::Get()->window_selector_controller()->ToggleOverview()); | 246   EXPECT_TRUE(Shell::Get()->window_selector_controller()->ToggleOverview()); | 
| 255   EXPECT_FALSE(Shell::Get()->window_selector_controller()->IsSelecting()); | 247   EXPECT_FALSE(Shell::Get()->window_selector_controller()->IsSelecting()); | 
| 256   EXPECT_FALSE(GetTray()->is_active()); | 248   EXPECT_FALSE(GetTray()->is_active()); | 
| 257 } | 249 } | 
| 258 | 250 | 
| 259 // Test that when a hide animation is aborted via deletion, that the | 251 // Test that when a hide animation is aborted via deletion, that the | 
| 260 // OverviewButton is still hidden. | 252 // OverviewButton is still hidden. | 
| 261 TEST_F(OverviewButtonTrayTest, HideAnimationAlwaysCompletes) { | 253 TEST_F(OverviewButtonTrayTest, HideAnimationAlwaysCompletes) { | 
| 262   // TODO: disabled as ScreenRotationAnimator does not work in mash, | 254   // TODO: disabled as ScreenRotationAnimator does not work in mash, | 
| 263   // http://crbug.com/696754. | 255   // http://crbug.com/696754. | 
| 264   if (Shell::GetAshConfig() == Config::MASH) | 256   if (Shell::GetAshConfig() == Config::MASH) | 
| 265     return; | 257     return; | 
| 266 | 258 | 
| 267   Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | 259   Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true); | 
| 268       true); |  | 
| 269 | 260 | 
| 270   // Long duration for hide animation, to allow it to be interrupted. | 261   // Long duration for hide animation, to allow it to be interrupted. | 
| 271   std::unique_ptr<ui::ScopedAnimationDurationScaleMode> hide_duration( | 262   std::unique_ptr<ui::ScopedAnimationDurationScaleMode> hide_duration( | 
| 272       new ui::ScopedAnimationDurationScaleMode( | 263       new ui::ScopedAnimationDurationScaleMode( | 
| 273           ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); | 264           ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); | 
| 274   GetTray()->SetVisible(false); | 265   GetTray()->SetVisible(false); | 
| 275 | 266 | 
| 276   // ScreenRotationAnimator copies the current layers, and deletes them upon | 267   // ScreenRotationAnimator copies the current layers, and deletes them upon | 
| 277   // completion. Allow its animation to complete first. | 268   // completion. Allow its animation to complete first. | 
| 278   std::unique_ptr<ui::ScopedAnimationDurationScaleMode> rotate_duration( | 269   std::unique_ptr<ui::ScopedAnimationDurationScaleMode> rotate_duration( | 
| 279       new ui::ScopedAnimationDurationScaleMode( | 270       new ui::ScopedAnimationDurationScaleMode( | 
| 280           ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); | 271           ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); | 
| 281   ash::ScreenRotationAnimator(display::Display::InternalDisplayId()) | 272   ash::ScreenRotationAnimator(display::Display::InternalDisplayId()) | 
| 282       .Rotate(display::Display::ROTATE_270, | 273       .Rotate(display::Display::ROTATE_270, | 
| 283               display::Display::ROTATION_SOURCE_ACTIVE); | 274               display::Display::ROTATION_SOURCE_ACTIVE); | 
| 284 | 275 | 
| 285   RunAllPendingInMessageLoop(); | 276   RunAllPendingInMessageLoop(); | 
| 286   EXPECT_FALSE(GetTray()->visible()); | 277   EXPECT_FALSE(GetTray()->visible()); | 
| 287 } | 278 } | 
| 288 | 279 | 
| 289 // Tests that the overview button becomes visible when the user enters | 280 // Tests that the overview button becomes visible when the user enters | 
| 290 // maximize mode with a system modal window open, and that it hides once | 281 // tablet mode with a system modal window open, and that it hides once | 
| 291 // the user exits maximize mode. | 282 // the user exits tablet mode. | 
| 292 TEST_F(OverviewButtonTrayTest, VisibilityChangesForSystemModalWindow) { | 283 TEST_F(OverviewButtonTrayTest, VisibilityChangesForSystemModalWindow) { | 
| 293   // TODO(jonross): When CreateTestWindow*() have been unified, use the | 284   // TODO(jonross): When CreateTestWindow*() have been unified, use the | 
| 294   // appropriate method to replace this setup. (crbug.com/483503) | 285   // appropriate method to replace this setup. (crbug.com/483503) | 
| 295   std::unique_ptr<aura::Window> window(new aura::Window(nullptr)); | 286   std::unique_ptr<aura::Window> window(new aura::Window(nullptr)); | 
| 296   window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); | 287   window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); | 
| 297   window->SetType(aura::client::WINDOW_TYPE_NORMAL); | 288   window->SetType(aura::client::WINDOW_TYPE_NORMAL); | 
| 298   window->Init(ui::LAYER_TEXTURED); | 289   window->Init(ui::LAYER_TEXTURED); | 
| 299   window->Show(); | 290   window->Show(); | 
| 300   ParentWindowInPrimaryRootWindow(window.get()); | 291   ParentWindowInPrimaryRootWindow(window.get()); | 
| 301 | 292 | 
| 302   ASSERT_TRUE(ShellPort::Get()->IsSystemModalWindowOpen()); | 293   ASSERT_TRUE(ShellPort::Get()->IsSystemModalWindowOpen()); | 
| 303   Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | 294   Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true); | 
| 304       true); |  | 
| 305   EXPECT_TRUE(GetTray()->visible()); | 295   EXPECT_TRUE(GetTray()->visible()); | 
| 306   Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | 296   Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(false); | 
| 307       false); |  | 
| 308   EXPECT_FALSE(GetTray()->visible()); | 297   EXPECT_FALSE(GetTray()->visible()); | 
| 309 } | 298 } | 
| 310 | 299 | 
| 311 }  // namespace ash | 300 }  // namespace ash | 
| OLD | NEW | 
|---|