OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "ash/shell_window_ids.h" | 6 #include "ash/shell_window_ids.h" |
7 #include "ash/test/ash_test_base.h" | 7 #include "ash/test/ash_test_base.h" |
8 #include "ash/test/test_session_state_delegate.h" | 8 #include "ash/test/test_session_state_delegate.h" |
9 #include "ash/test/test_shell_delegate.h" | 9 #include "ash/test/test_shell_delegate.h" |
10 #include "ash/wm/window_state.h" | 10 #include "ash/wm/window_state.h" |
| 11 #include "ash/wm/wm_event.h" |
11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
12 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
16 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" | 17 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" |
17 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h" | 18 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h" |
| 19 #include "chrome/browser/ui/ash/multi_user/user_switch_animator_chromeos.h" |
18 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
20 #include "ui/aura/client/aura_constants.h" | 22 #include "ui/aura/client/aura_constants.h" |
21 #include "ui/aura/window_event_dispatcher.h" | 23 #include "ui/aura/window_event_dispatcher.h" |
22 #include "ui/base/ui_base_types.h" | 24 #include "ui/base/ui_base_types.h" |
23 #include "ui/wm/core/window_util.h" | 25 #include "ui/wm/core/window_util.h" |
24 #include "ui/wm/public/activation_client.h" | 26 #include "ui/wm/public/activation_client.h" |
25 | 27 |
26 namespace ash { | 28 namespace ash { |
27 namespace test { | 29 namespace test { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 // The test session state observer does not automatically call the window | 101 // The test session state observer does not automatically call the window |
100 // manager. This function gets the current user from it and also sets it to | 102 // manager. This function gets the current user from it and also sets it to |
101 // the multi user window manager. | 103 // the multi user window manager. |
102 std::string GetAndValidateCurrentUserFromSessionStateObserver() { | 104 std::string GetAndValidateCurrentUserFromSessionStateObserver() { |
103 const std::string& user = session_state_delegate()->get_activated_user(); | 105 const std::string& user = session_state_delegate()->get_activated_user(); |
104 if (user != multi_user_window_manager_->GetCurrentUserForTest()) | 106 if (user != multi_user_window_manager_->GetCurrentUserForTest()) |
105 multi_user_window_manager()->ActiveUserChanged(user); | 107 multi_user_window_manager()->ActiveUserChanged(user); |
106 return user; | 108 return user; |
107 } | 109 } |
108 | 110 |
| 111 // Initiate a user transition. |
| 112 void StartUserTransitionAnimation(const std::string& user_id) { |
| 113 multi_user_window_manager_->ActiveUserChanged(user_id); |
| 114 } |
| 115 |
| 116 // Call next animation step. |
| 117 void AdvanceUserTransitionAnimation() { |
| 118 multi_user_window_manager_->animation_->AdvanceUserTransitionAnimation(); |
| 119 } |
| 120 |
| 121 // Return the user id of the wallpaper which is currently set. |
| 122 const std::string& GetWallaperUserIdForTest() { |
| 123 return multi_user_window_manager_->animation_->wallpaper_user_id_for_test(); |
| 124 } |
| 125 |
| 126 // Returns true if the given window covers the screen. |
| 127 bool CoversScreen(aura::Window* window) { |
| 128 return chrome::UserSwichAnimatorChromeOS::CoversScreen( |
| 129 window); |
| 130 } |
| 131 |
109 private: | 132 private: |
110 // These get created for each session. | 133 // These get created for each session. |
111 std::vector<aura::Window*> window_; | 134 std::vector<aura::Window*> window_; |
112 | 135 |
113 // The instance of the MultiUserWindowManager. | 136 // The instance of the MultiUserWindowManager. |
114 chrome::MultiUserWindowManagerChromeOS* multi_user_window_manager_; | 137 chrome::MultiUserWindowManagerChromeOS* multi_user_window_manager_; |
115 | 138 |
116 // The session state delegate. | 139 // The session state delegate. |
117 ash::test::TestSessionStateDelegate* session_state_delegate_; | 140 ash::test::TestSessionStateDelegate* session_state_delegate_; |
118 | 141 |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 EXPECT_EQ("H[A], S[B], H[C]", GetStatus()); | 714 EXPECT_EQ("H[A], S[B], H[C]", GetStatus()); |
692 EXPECT_EQ("B", GetOwnersOfVisibleWindowsAsString()); | 715 EXPECT_EQ("B", GetOwnersOfVisibleWindowsAsString()); |
693 | 716 |
694 SwitchUserAndWaitForAnimation("A"); | 717 SwitchUserAndWaitForAnimation("A"); |
695 | 718 |
696 EXPECT_EQ("S[A], H[B], H[C]", GetStatus()); | 719 EXPECT_EQ("S[A], H[B], H[C]", GetStatus()); |
697 | 720 |
698 // Switch the user quickly to another user and before the animation is done | 721 // Switch the user quickly to another user and before the animation is done |
699 // switch back and see that this works. | 722 // switch back and see that this works. |
700 multi_user_window_manager()->ActiveUserChanged("B"); | 723 multi_user_window_manager()->ActiveUserChanged("B"); |
701 // Check that at this time we have nothing visible (in the middle of the | 724 // With the start of the animation B should become visible. |
702 // animation). | 725 EXPECT_EQ("H[A], S[B], H[C]", GetStatus()); |
703 EXPECT_EQ("H[A], H[B], H[C]", GetStatus()); | |
704 // Check that after switching to C, C is fully visible. | 726 // Check that after switching to C, C is fully visible. |
705 SwitchUserAndWaitForAnimation("C"); | 727 SwitchUserAndWaitForAnimation("C"); |
706 EXPECT_EQ("H[A], H[B], S[C]", GetStatus()); | 728 EXPECT_EQ("H[A], H[B], S[C]", GetStatus()); |
707 } | 729 } |
708 | 730 |
| 731 // Test that using the full user switch, the animations are transitioning as |
| 732 // we expect them to in all animation steps. |
| 733 TEST_F(MultiUserWindowManagerChromeOSTest, AnimationSteps) { |
| 734 SetUpForThisManyWindows(3); |
| 735 // Turn the use of delays and animation on. |
| 736 multi_user_window_manager()->SetAnimationsForTest(false); |
| 737 // Set some owners and make sure we got what we asked for. |
| 738 multi_user_window_manager()->SetWindowOwner(window(0), "A"); |
| 739 multi_user_window_manager()->SetWindowOwner(window(1), "B"); |
| 740 multi_user_window_manager()->SetWindowOwner(window(2), "C"); |
| 741 EXPECT_FALSE(CoversScreen(window(0))); |
| 742 EXPECT_FALSE(CoversScreen(window(1))); |
| 743 EXPECT_EQ("S[A], H[B], H[C]", GetStatus()); |
| 744 EXPECT_EQ("A", GetOwnersOfVisibleWindowsAsString()); |
| 745 EXPECT_NE(ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN, |
| 746 ash::Shell::GetInstance()->GetShelfAutoHideBehavior( |
| 747 window(0)->GetRootWindow())); |
| 748 EXPECT_EQ(1.0f, window(0)->layer()->GetTargetOpacity()); |
| 749 |
| 750 // Start the animation and see that the old window is becoming invisible, the |
| 751 // new one visible, the background starts transitionining and the shelf hides. |
| 752 StartUserTransitionAnimation("B"); |
| 753 EXPECT_EQ("->B", GetWallaperUserIdForTest()); |
| 754 EXPECT_EQ("H[A], S[B], H[C]", GetStatus()); |
| 755 EXPECT_EQ(0.0f, window(0)->layer()->GetTargetOpacity()); |
| 756 EXPECT_EQ(1.0f, window(1)->layer()->GetTargetOpacity()); |
| 757 EXPECT_EQ(ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN, |
| 758 ash::Shell::GetInstance()->GetShelfAutoHideBehavior( |
| 759 window(0)->GetRootWindow())); |
| 760 |
| 761 // Staring the next step should show the shelf again, but there are many |
| 762 // subsystems missing (preferences system, ChromeLauncherController, ...) |
| 763 // which should set the shelf to its users state. Since that isn't there we |
| 764 // can only make sure that it stays where it is. |
| 765 AdvanceUserTransitionAnimation(); |
| 766 EXPECT_EQ("->B", GetWallaperUserIdForTest()); |
| 767 EXPECT_EQ("H[A], S[B], H[C]", GetStatus()); |
| 768 EXPECT_EQ(ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN, |
| 769 ash::Shell::GetInstance()->GetShelfAutoHideBehavior( |
| 770 window(0)->GetRootWindow())); |
| 771 |
| 772 // After the finalize the animation of the wallpaper should be finished. |
| 773 AdvanceUserTransitionAnimation(); |
| 774 EXPECT_EQ("B", GetWallaperUserIdForTest()); |
| 775 } |
| 776 |
| 777 // Test that the screen coverage is properly determined. |
| 778 TEST_F(MultiUserWindowManagerChromeOSTest, AnimationStepsScreenCoverage) { |
| 779 SetUpForThisManyWindows(3); |
| 780 // Maximizing, fully covering the screen by bounds or fullscreen mode should |
| 781 // make CoversScreen return true. |
| 782 wm::GetWindowState(window(0))->Maximize(); |
| 783 window(1)->SetBounds(gfx::Rect(0, 0, 3000, 3000)); |
| 784 |
| 785 EXPECT_TRUE(CoversScreen(window(0))); |
| 786 EXPECT_TRUE(CoversScreen(window(1))); |
| 787 EXPECT_FALSE(CoversScreen(window(2))); |
| 788 |
| 789 ash::wm::WMEvent event(ash::wm::WM_EVENT_FULLSCREEN); |
| 790 wm::GetWindowState(window(2))->OnWMEvent(&event); |
| 791 EXPECT_TRUE(CoversScreen(window(2))); |
| 792 } |
| 793 |
| 794 // Test that switching from a desktop which has a maximized window to a desktop |
| 795 // which has no maximized window will produce the proper animation. |
| 796 TEST_F(MultiUserWindowManagerChromeOSTest, AnimationStepsMaximizeToNormal) { |
| 797 SetUpForThisManyWindows(3); |
| 798 // Turn the use of delays and animation on. |
| 799 multi_user_window_manager()->SetAnimationsForTest(false); |
| 800 // Set some owners and make sure we got what we asked for. |
| 801 multi_user_window_manager()->SetWindowOwner(window(0), "A"); |
| 802 wm::GetWindowState(window(0))->Maximize(); |
| 803 multi_user_window_manager()->SetWindowOwner(window(1), "B"); |
| 804 multi_user_window_manager()->SetWindowOwner(window(2), "C"); |
| 805 EXPECT_TRUE(CoversScreen(window(0))); |
| 806 EXPECT_FALSE(CoversScreen(window(1))); |
| 807 EXPECT_EQ("S[A], H[B], H[C]", GetStatus()); |
| 808 EXPECT_EQ("A", GetOwnersOfVisibleWindowsAsString()); |
| 809 EXPECT_EQ(1.0f, window(0)->layer()->GetTargetOpacity()); |
| 810 |
| 811 // Start the animation and see that the new background is immediately set. |
| 812 StartUserTransitionAnimation("B"); |
| 813 EXPECT_EQ("H[A], S[B], H[C]", GetStatus()); |
| 814 EXPECT_EQ("B", GetWallaperUserIdForTest()); |
| 815 EXPECT_EQ(0.0f, window(0)->layer()->GetTargetOpacity()); |
| 816 EXPECT_EQ(1.0f, window(1)->layer()->GetTargetOpacity()); |
| 817 |
| 818 // The next step will not change anything. |
| 819 AdvanceUserTransitionAnimation(); |
| 820 EXPECT_EQ("B", GetWallaperUserIdForTest()); |
| 821 EXPECT_EQ(0.0f, window(0)->layer()->GetTargetOpacity()); |
| 822 EXPECT_EQ(1.0f, window(1)->layer()->GetTargetOpacity()); |
| 823 |
| 824 // The final step will also not have any visible impact. |
| 825 AdvanceUserTransitionAnimation(); |
| 826 EXPECT_EQ("H[A], S[B], H[C]", GetStatus()); |
| 827 EXPECT_EQ("B", GetWallaperUserIdForTest()); |
| 828 EXPECT_EQ(0.0f, window(0)->layer()->GetTargetOpacity()); |
| 829 EXPECT_EQ(1.0f, window(1)->layer()->GetTargetOpacity()); |
| 830 } |
| 831 |
| 832 // Test that switching from a desktop which has a normal window to a desktop |
| 833 // which has a maximized window will produce the proper animation. |
| 834 TEST_F(MultiUserWindowManagerChromeOSTest, AnimationStepsNormalToMaximized) { |
| 835 SetUpForThisManyWindows(3); |
| 836 // Turn the use of delays and animation on. |
| 837 multi_user_window_manager()->SetAnimationsForTest(false); |
| 838 // Set some owners and make sure we got what we asked for. |
| 839 multi_user_window_manager()->SetWindowOwner(window(0), "A"); |
| 840 multi_user_window_manager()->SetWindowOwner(window(1), "B"); |
| 841 wm::GetWindowState(window(1))->Maximize(); |
| 842 multi_user_window_manager()->SetWindowOwner(window(2), "C"); |
| 843 EXPECT_FALSE(CoversScreen(window(0))); |
| 844 EXPECT_TRUE(CoversScreen(window(1))); |
| 845 EXPECT_EQ("S[A], H[B], H[C]", GetStatus()); |
| 846 EXPECT_EQ("A", GetOwnersOfVisibleWindowsAsString()); |
| 847 EXPECT_EQ(1.0f, window(0)->layer()->GetTargetOpacity()); |
| 848 |
| 849 // Start the animation and see that the old window is becoming invisible, the |
| 850 // new one visible and the background remains as is. |
| 851 StartUserTransitionAnimation("B"); |
| 852 EXPECT_EQ("H[A], S[B], H[C]", GetStatus()); |
| 853 EXPECT_EQ("", GetWallaperUserIdForTest()); |
| 854 EXPECT_EQ(0.0f, window(0)->layer()->GetTargetOpacity()); |
| 855 EXPECT_EQ(1.0f, window(1)->layer()->GetTargetOpacity()); |
| 856 |
| 857 // The next step will not change anything. |
| 858 AdvanceUserTransitionAnimation(); |
| 859 EXPECT_EQ("", GetWallaperUserIdForTest()); |
| 860 EXPECT_EQ(0.0f, window(0)->layer()->GetTargetOpacity()); |
| 861 EXPECT_EQ(1.0f, window(1)->layer()->GetTargetOpacity()); |
| 862 |
| 863 // The final step however will switch the background. |
| 864 AdvanceUserTransitionAnimation(); |
| 865 EXPECT_EQ("H[A], S[B], H[C]", GetStatus()); |
| 866 EXPECT_EQ("B", GetWallaperUserIdForTest()); |
| 867 EXPECT_EQ(0.0f, window(0)->layer()->GetTargetOpacity()); |
| 868 EXPECT_EQ(1.0f, window(1)->layer()->GetTargetOpacity()); |
| 869 } |
| 870 |
| 871 // Test that switching from a desktop which has a maximized window to a desktop |
| 872 // which has a maximized window will produce the proper animation. |
| 873 TEST_F(MultiUserWindowManagerChromeOSTest, AnimationStepsMaximizedToMaximized) { |
| 874 SetUpForThisManyWindows(3); |
| 875 // Turn the use of delays and animation on. |
| 876 multi_user_window_manager()->SetAnimationsForTest(false); |
| 877 // Set some owners and make sure we got what we asked for. |
| 878 multi_user_window_manager()->SetWindowOwner(window(0), "A"); |
| 879 wm::GetWindowState(window(0))->Maximize(); |
| 880 multi_user_window_manager()->SetWindowOwner(window(1), "B"); |
| 881 wm::GetWindowState(window(1))->Maximize(); |
| 882 multi_user_window_manager()->SetWindowOwner(window(2), "C"); |
| 883 EXPECT_TRUE(CoversScreen(window(0))); |
| 884 EXPECT_TRUE(CoversScreen(window(1))); |
| 885 EXPECT_EQ("S[A], H[B], H[C]", GetStatus()); |
| 886 EXPECT_EQ("A", GetOwnersOfVisibleWindowsAsString()); |
| 887 EXPECT_EQ(1.0f, window(0)->layer()->GetTargetOpacity()); |
| 888 |
| 889 // Start the animation and see that the old window is staying visible, the |
| 890 // new one slowly visible and the background changes immediately. |
| 891 StartUserTransitionAnimation("B"); |
| 892 EXPECT_EQ("S[A], S[B], H[C]", GetStatus()); |
| 893 EXPECT_EQ("B", GetWallaperUserIdForTest()); |
| 894 EXPECT_EQ(1.0f, window(0)->layer()->GetTargetOpacity()); |
| 895 EXPECT_EQ(1.0f, window(1)->layer()->GetTargetOpacity()); |
| 896 |
| 897 // The next step will not change anything. |
| 898 AdvanceUserTransitionAnimation(); |
| 899 EXPECT_EQ("B", GetWallaperUserIdForTest()); |
| 900 EXPECT_EQ(1.0f, window(0)->layer()->GetTargetOpacity()); |
| 901 EXPECT_EQ(1.0f, window(1)->layer()->GetTargetOpacity()); |
| 902 |
| 903 // The final step however will hide the old window. |
| 904 AdvanceUserTransitionAnimation(); |
| 905 EXPECT_EQ("H[A], S[B], H[C]", GetStatus()); |
| 906 EXPECT_EQ("B", GetWallaperUserIdForTest()); |
| 907 EXPECT_EQ(0.0f, window(0)->layer()->GetTargetOpacity()); |
| 908 EXPECT_EQ(1.0f, window(1)->layer()->GetTargetOpacity()); |
| 909 |
| 910 // Switching back will preserve the z-order by instantly showing the new |
| 911 // window, hiding the layer above it and switching instantly the wallpaper. |
| 912 StartUserTransitionAnimation("A"); |
| 913 EXPECT_EQ("S[A], H[B], H[C]", GetStatus()); |
| 914 EXPECT_EQ("A", GetWallaperUserIdForTest()); |
| 915 EXPECT_EQ(1.0f, window(0)->layer()->GetTargetOpacity()); |
| 916 EXPECT_EQ(0.0f, window(1)->layer()->GetTargetOpacity()); |
| 917 |
| 918 // The next step will not change anything. |
| 919 AdvanceUserTransitionAnimation(); |
| 920 EXPECT_EQ("A", GetWallaperUserIdForTest()); |
| 921 EXPECT_EQ(1.0f, window(0)->layer()->GetTargetOpacity()); |
| 922 EXPECT_EQ(0.0f, window(1)->layer()->GetTargetOpacity()); |
| 923 |
| 924 // The final step is also not changing anything to the status. |
| 925 AdvanceUserTransitionAnimation(); |
| 926 EXPECT_EQ("S[A], H[B], H[C]", GetStatus()); |
| 927 EXPECT_EQ("A", GetWallaperUserIdForTest()); |
| 928 EXPECT_EQ(1.0f, window(0)->layer()->GetTargetOpacity()); |
| 929 EXPECT_EQ(0.0f, window(1)->layer()->GetTargetOpacity()); |
| 930 } |
| 931 |
709 // Test that showing a window for another user also switches the desktop. | 932 // Test that showing a window for another user also switches the desktop. |
710 TEST_F(MultiUserWindowManagerChromeOSTest, ShowForUserSwitchesDesktop) { | 933 TEST_F(MultiUserWindowManagerChromeOSTest, ShowForUserSwitchesDesktop) { |
711 SetUpForThisManyWindows(3); | 934 SetUpForThisManyWindows(3); |
712 multi_user_window_manager()->ActiveUserChanged("a"); | 935 multi_user_window_manager()->ActiveUserChanged("a"); |
713 session_state_delegate()->SwitchActiveUser("a"); | 936 session_state_delegate()->SwitchActiveUser("a"); |
714 | 937 |
715 // Set some owners and make sure we got what we asked for. | 938 // Set some owners and make sure we got what we asked for. |
716 multi_user_window_manager()->SetWindowOwner(window(0), "a"); | 939 multi_user_window_manager()->SetWindowOwner(window(0), "a"); |
717 multi_user_window_manager()->SetWindowOwner(window(1), "b"); | 940 multi_user_window_manager()->SetWindowOwner(window(1), "b"); |
718 multi_user_window_manager()->SetWindowOwner(window(2), "c"); | 941 multi_user_window_manager()->SetWindowOwner(window(2), "c"); |
(...skipping 18 matching lines...) Expand all Loading... |
737 EXPECT_EQ("S[a,b], S[b], S[c,b]", GetStatus()); | 960 EXPECT_EQ("S[a,b], S[b], S[c,b]", GetStatus()); |
738 | 961 |
739 // Check that teleporting back will also change the desktop. | 962 // Check that teleporting back will also change the desktop. |
740 multi_user_window_manager()->ShowWindowForUser(window(2), "c"); | 963 multi_user_window_manager()->ShowWindowForUser(window(2), "c"); |
741 EXPECT_EQ("c", GetAndValidateCurrentUserFromSessionStateObserver()); | 964 EXPECT_EQ("c", GetAndValidateCurrentUserFromSessionStateObserver()); |
742 EXPECT_EQ("H[a,b], H[b], S[c]", GetStatus()); | 965 EXPECT_EQ("H[a,b], H[b], S[c]", GetStatus()); |
743 } | 966 } |
744 | 967 |
745 } // namespace test | 968 } // namespace test |
746 } // namespace ash | 969 } // namespace ash |
OLD | NEW |