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/scoped_target_root_window.h" | 5 #include "ash/scoped_target_root_window.h" |
6 #include "ash/screen_util.h" | 6 #include "ash/screen_util.h" |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
9 #include "ash/test/test_shell_delegate.h" | 9 #include "ash/test/test_shell_delegate.h" |
10 #include "ash/wm/window_positioner.h" | 10 #include "ash/wm/window_positioner.h" |
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
745 Browser::CreateParams(Browser::TYPE_POPUP, profile.get(), | 745 Browser::CreateParams(Browser::TYPE_POPUP, profile.get(), |
746 chrome::HOST_DESKTOP_TYPE_ASH))); | 746 chrome::HOST_DESKTOP_TYPE_ASH))); |
747 | 747 |
748 // Tabbed windows should retrieve the saved window state - since there is a | 748 // Tabbed windows should retrieve the saved window state - since there is a |
749 // top window. | 749 // top window. |
750 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, | 750 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, |
751 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, | 751 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, |
752 ui::SHOW_STATE_NORMAL, | 752 ui::SHOW_STATE_NORMAL, |
753 BOTH, | 753 BOTH, |
754 browser_window->browser(), | 754 browser_window->browser(), |
755 p1600x1200, | |
755 p1600x1200)); | 756 p1600x1200)); |
757 // A window that is less than the whole work area is set to default state. | |
msw
2014/08/05 16:44:38
nit: s/that is less/smaller/
varkha
2014/08/05 17:55:23
Done.
| |
756 EXPECT_EQ(ui::SHOW_STATE_DEFAULT, | 758 EXPECT_EQ(ui::SHOW_STATE_DEFAULT, |
757 GetWindowShowState(ui::SHOW_STATE_DEFAULT, | 759 GetWindowShowState(ui::SHOW_STATE_DEFAULT, |
758 ui::SHOW_STATE_NORMAL, | 760 ui::SHOW_STATE_NORMAL, |
759 BOTH, | 761 BOTH, |
760 browser_window->browser(), | 762 browser_window->browser(), |
763 p1280x1024, | |
764 p1600x1200)); | |
765 // A window that is sized to occupy the whole work area is maximized. | |
766 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, | |
767 GetWindowShowState(ui::SHOW_STATE_DEFAULT, | |
768 ui::SHOW_STATE_NORMAL, | |
769 BOTH, | |
770 browser_window->browser(), | |
771 p1600x1200, | |
761 p1600x1200)); | 772 p1600x1200)); |
762 // Non tabbed windows should always follow the window saved visibility state. | 773 // Non tabbed windows should always follow the window saved visibility state. |
763 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, | 774 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, |
764 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, | 775 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, |
765 ui::SHOW_STATE_NORMAL, | 776 ui::SHOW_STATE_NORMAL, |
766 BOTH, | 777 BOTH, |
767 browser_popup->browser(), | 778 browser_popup->browser(), |
779 p1600x1200, | |
768 p1600x1200)); | 780 p1600x1200)); |
769 // The non tabbed window will take the status of the last active of its kind. | 781 // The non tabbed window will take the status of the last active of its kind. |
770 EXPECT_EQ(ui::SHOW_STATE_NORMAL, | 782 EXPECT_EQ(ui::SHOW_STATE_NORMAL, |
771 GetWindowShowState(ui::SHOW_STATE_DEFAULT, | 783 GetWindowShowState(ui::SHOW_STATE_DEFAULT, |
772 ui::SHOW_STATE_NORMAL, | 784 ui::SHOW_STATE_NORMAL, |
773 BOTH, | 785 BOTH, |
774 browser_popup->browser(), | 786 browser_popup->browser(), |
787 p1600x1200, | |
775 p1600x1200)); | 788 p1600x1200)); |
776 | 789 |
777 // Now create a top level window and check again for both. Only the tabbed | 790 // Now create a top level window and check again for both. Only the tabbed |
778 // window should follow the top level window's state. | 791 // window should follow the top level window's state. |
779 // Creating a browser & window to play with. | 792 // Creating a browser & window to play with. |
780 scoped_ptr<TestBrowserWindowAura> browser_window2(CreateTestBrowserWindow( | 793 scoped_ptr<TestBrowserWindowAura> browser_window2(CreateTestBrowserWindow( |
781 CreateTestWindowInShellWithId(3), | 794 CreateTestWindowInShellWithId(3), |
782 gfx::Rect(16, 32, 640, 320), | 795 gfx::Rect(16, 32, 640, 320), |
783 Browser::CreateParams(Browser::TYPE_TABBED, profile.get(), | 796 Browser::CreateParams(Browser::TYPE_TABBED, profile.get(), |
784 chrome::HOST_DESKTOP_TYPE_ASH))); | 797 chrome::HOST_DESKTOP_TYPE_ASH))); |
785 | 798 |
786 // A tabbed window should now take the top level window state. | 799 // A tabbed window should now take the top level window state. |
787 EXPECT_EQ(ui::SHOW_STATE_DEFAULT, | 800 EXPECT_EQ(ui::SHOW_STATE_DEFAULT, |
788 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, | 801 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, |
789 ui::SHOW_STATE_DEFAULT, | 802 ui::SHOW_STATE_DEFAULT, |
790 BOTH, | 803 BOTH, |
791 browser_window->browser(), | 804 browser_window->browser(), |
805 p1600x1200, | |
792 p1600x1200)); | 806 p1600x1200)); |
793 // Non tabbed windows should always follow the window saved visibility state. | 807 // Non tabbed windows should always follow the window saved visibility state. |
794 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, | 808 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, |
795 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, | 809 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, |
796 ui::SHOW_STATE_MINIMIZED, | 810 ui::SHOW_STATE_MINIMIZED, |
797 BOTH, | 811 BOTH, |
798 browser_popup->browser(), | 812 browser_popup->browser(), |
813 p1600x1200, | |
799 p1600x1200)); | 814 p1600x1200)); |
800 | 815 |
801 // In smaller screen resolutions we default to maximized if there is no other | 816 // In smaller screen resolutions we default to maximized if there is no other |
802 // window visible. | 817 // window visible. |
803 int min_size = ash::WindowPositioner::GetForceMaximizedWidthLimit() / 2; | 818 int min_size = ash::WindowPositioner::GetForceMaximizedWidthLimit() / 2; |
804 if (min_size > 0) { | 819 if (min_size > 0) { |
805 const gfx::Rect tiny_screen(0, 0, min_size, min_size); | 820 const gfx::Rect tiny_screen(0, 0, min_size, min_size); |
806 EXPECT_EQ(ui::SHOW_STATE_DEFAULT, | 821 EXPECT_EQ(ui::SHOW_STATE_DEFAULT, |
807 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, | 822 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, |
808 ui::SHOW_STATE_DEFAULT, | 823 ui::SHOW_STATE_DEFAULT, |
809 BOTH, | 824 BOTH, |
810 browser_window->browser(), | 825 browser_window->browser(), |
826 tiny_screen, | |
811 tiny_screen)); | 827 tiny_screen)); |
812 browser_window->Hide(); | 828 browser_window->Hide(); |
813 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, | 829 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, |
814 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, | 830 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, |
815 ui::SHOW_STATE_DEFAULT, | 831 ui::SHOW_STATE_DEFAULT, |
816 BOTH, | 832 BOTH, |
817 browser_window2->browser(), | 833 browser_window2->browser(), |
834 tiny_screen, | |
818 tiny_screen)); | 835 tiny_screen)); |
819 | 836 |
820 } | 837 } |
821 } | 838 } |
822 | 839 |
823 // Test that the default show state override behavior is properly handled. | 840 // Test that the default show state override behavior is properly handled. |
824 TEST_F(WindowSizerAshTest, TestShowStateDefaults) { | 841 TEST_F(WindowSizerAshTest, TestShowStateDefaults) { |
825 // Creating a browser & window to play with. | 842 // Creating a browser & window to play with. |
826 scoped_ptr<TestingProfile> profile(new TestingProfile()); | 843 scoped_ptr<TestingProfile> profile(new TestingProfile()); |
827 | 844 |
(...skipping 11 matching lines...) Expand all Loading... | |
839 Browser::CreateParams(Browser::TYPE_POPUP, profile.get(), | 856 Browser::CreateParams(Browser::TYPE_POPUP, profile.get(), |
840 chrome::HOST_DESKTOP_TYPE_ASH))); | 857 chrome::HOST_DESKTOP_TYPE_ASH))); |
841 | 858 |
842 // Check that a browser creation state always get used if not given as | 859 // Check that a browser creation state always get used if not given as |
843 // SHOW_STATE_DEFAULT. On Windows ASH it should be SHOW_STATE_MAXIMIZED. | 860 // SHOW_STATE_DEFAULT. On Windows ASH it should be SHOW_STATE_MAXIMIZED. |
844 ui::WindowShowState window_show_state = | 861 ui::WindowShowState window_show_state = |
845 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, | 862 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, |
846 ui::SHOW_STATE_MAXIMIZED, | 863 ui::SHOW_STATE_MAXIMIZED, |
847 DEFAULT, | 864 DEFAULT, |
848 browser_window->browser(), | 865 browser_window->browser(), |
866 p1600x1200, | |
849 p1600x1200); | 867 p1600x1200); |
850 #if defined(OS_WIN) | 868 #if defined(OS_WIN) |
851 EXPECT_EQ(window_show_state, ui::SHOW_STATE_MAXIMIZED); | 869 EXPECT_EQ(window_show_state, ui::SHOW_STATE_MAXIMIZED); |
852 #else | 870 #else |
853 EXPECT_EQ(window_show_state, ui::SHOW_STATE_DEFAULT); | 871 EXPECT_EQ(window_show_state, ui::SHOW_STATE_DEFAULT); |
854 #endif | 872 #endif |
855 | 873 |
856 browser_window->browser()->set_initial_show_state(ui::SHOW_STATE_MINIMIZED); | 874 browser_window->browser()->set_initial_show_state(ui::SHOW_STATE_MINIMIZED); |
857 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, | 875 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, |
858 ui::SHOW_STATE_MAXIMIZED, | 876 ui::SHOW_STATE_MAXIMIZED, |
859 BOTH, | 877 BOTH, |
860 browser_window->browser(), | 878 browser_window->browser(), |
879 p1600x1200, | |
861 p1600x1200), ui::SHOW_STATE_MINIMIZED); | 880 p1600x1200), ui::SHOW_STATE_MINIMIZED); |
862 browser_window->browser()->set_initial_show_state(ui::SHOW_STATE_NORMAL); | 881 browser_window->browser()->set_initial_show_state(ui::SHOW_STATE_NORMAL); |
863 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, | 882 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, |
864 ui::SHOW_STATE_MAXIMIZED, | 883 ui::SHOW_STATE_MAXIMIZED, |
865 BOTH, | 884 BOTH, |
866 browser_window->browser(), | 885 browser_window->browser(), |
886 p1600x1200, | |
867 p1600x1200), ui::SHOW_STATE_NORMAL); | 887 p1600x1200), ui::SHOW_STATE_NORMAL); |
868 browser_window->browser()->set_initial_show_state(ui::SHOW_STATE_MAXIMIZED); | 888 browser_window->browser()->set_initial_show_state(ui::SHOW_STATE_MAXIMIZED); |
869 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL, | 889 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL, |
870 ui::SHOW_STATE_NORMAL, | 890 ui::SHOW_STATE_NORMAL, |
871 BOTH, | 891 BOTH, |
872 browser_window->browser(), | 892 browser_window->browser(), |
893 p1600x1200, | |
873 p1600x1200), ui::SHOW_STATE_MAXIMIZED); | 894 p1600x1200), ui::SHOW_STATE_MAXIMIZED); |
874 | 895 |
875 // Check that setting the maximized command line option is forcing the | 896 // Check that setting the maximized command line option is forcing the |
876 // maximized state. | 897 // maximized state. |
877 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kStartMaximized); | 898 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kStartMaximized); |
878 | 899 |
879 browser_window->browser()->set_initial_show_state(ui::SHOW_STATE_NORMAL); | 900 browser_window->browser()->set_initial_show_state(ui::SHOW_STATE_NORMAL); |
880 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL, | 901 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL, |
881 ui::SHOW_STATE_NORMAL, | 902 ui::SHOW_STATE_NORMAL, |
882 BOTH, | 903 BOTH, |
883 browser_window->browser(), | 904 browser_window->browser(), |
905 p1600x1200, | |
884 p1600x1200), ui::SHOW_STATE_MAXIMIZED); | 906 p1600x1200), ui::SHOW_STATE_MAXIMIZED); |
885 | 907 |
886 // The popup should favor the initial show state over the command line. | 908 // The popup should favor the initial show state over the command line. |
887 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL, | 909 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL, |
888 ui::SHOW_STATE_NORMAL, | 910 ui::SHOW_STATE_NORMAL, |
889 BOTH, | 911 BOTH, |
890 browser_popup->browser(), | 912 browser_popup->browser(), |
913 p1600x1200, | |
891 p1600x1200), ui::SHOW_STATE_NORMAL); | 914 p1600x1200), ui::SHOW_STATE_NORMAL); |
892 } | 915 } |
893 | 916 |
894 // Test that the target root window is used as the destionation of | 917 TEST_F(WindowSizerAshTest, DefaultStateBecomesMaximized) { |
918 // Create a browser which we can use to pass into the GetWindowBounds | |
msw
2014/08/05 16:44:38
nit: remove "which we can use "
varkha
2014/08/05 17:55:23
Done. Here and elsewhere in this file.
| |
919 // function. | |
920 scoped_ptr<TestingProfile> profile(new TestingProfile()); | |
921 Browser::CreateParams native_params(profile.get(), | |
922 chrome::HOST_DESKTOP_TYPE_ASH); | |
923 scoped_ptr<Browser> browser( | |
924 chrome::CreateBrowserWithTestWindowForParams(&native_params)); | |
925 | |
926 gfx::Rect display_bounds = ash::Shell::GetInstance()->GetScreen()-> | |
927 GetPrimaryDisplay().bounds(); | |
928 gfx::Rect specified_bounds = display_bounds; | |
929 | |
930 // Make a window bigger than the display work area. | |
931 specified_bounds.Inset(-20, -20); | |
932 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; | |
933 gfx::Rect bounds; | |
934 WindowSizer::GetBrowserWindowBoundsAndShowState( | |
935 std::string(), specified_bounds, browser.get(), &bounds, &show_state); | |
936 // The window should start maximized with its restore bounds shrunken. | |
937 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, show_state); | |
938 EXPECT_NE(display_bounds.ToString(), bounds.ToString()); | |
939 EXPECT_TRUE(display_bounds.Contains(bounds)); | |
940 | |
941 // Make a window smaller than the display work area. | |
942 specified_bounds.Inset(100, 100); | |
943 show_state = ui::SHOW_STATE_DEFAULT; | |
944 WindowSizer::GetBrowserWindowBoundsAndShowState( | |
945 std::string(), specified_bounds, browser.get(), &bounds, &show_state); | |
946 // The window should start in default state. | |
947 EXPECT_EQ(ui::SHOW_STATE_DEFAULT, show_state); | |
948 EXPECT_EQ(specified_bounds.ToString(), bounds.ToString()); | |
949 } | |
950 | |
951 // Test that the target root window is used as the destination of | |
895 // the non browser window. This differ from PersistedBoundsCase | 952 // the non browser window. This differ from PersistedBoundsCase |
896 // in that this uses real ash shell implementations + StateProvider | 953 // in that this uses real ash shell implementations + StateProvider |
897 // TargetDisplayProvider, rather than mocks. | 954 // TargetDisplayProvider, rather than mocks. |
898 TEST_F(WindowSizerAshTest, DefaultBoundsInTargetDisplay) { | 955 TEST_F(WindowSizerAshTest, DefaultBoundsInTargetDisplay) { |
899 if (!SupportsMultipleDisplays() || !chrome::ShouldOpenAshOnStartup()) | 956 if (!SupportsMultipleDisplays() || !chrome::ShouldOpenAshOnStartup()) |
900 return; | 957 return; |
901 UpdateDisplay("500x500,600x600"); | 958 UpdateDisplay("500x500,600x600"); |
902 { | 959 { |
903 aura::Window* first_root = | 960 aura::Window* first_root = |
904 ash::Shell::GetAllRootWindows()[0]; | 961 ash::Shell::GetAllRootWindows()[0]; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
939 CreateTestWindowInShellWithId(1), | 996 CreateTestWindowInShellWithId(1), |
940 gfx::Rect(16, 32, 640, 320), | 997 gfx::Rect(16, 32, 640, 320), |
941 trusted_popup_create_params)); | 998 trusted_popup_create_params)); |
942 // Trusted popup windows should follow the saved show state and ignore the | 999 // Trusted popup windows should follow the saved show state and ignore the |
943 // last show state. | 1000 // last show state. |
944 EXPECT_EQ(ui::SHOW_STATE_DEFAULT, | 1001 EXPECT_EQ(ui::SHOW_STATE_DEFAULT, |
945 GetWindowShowState(ui::SHOW_STATE_DEFAULT, | 1002 GetWindowShowState(ui::SHOW_STATE_DEFAULT, |
946 ui::SHOW_STATE_NORMAL, | 1003 ui::SHOW_STATE_NORMAL, |
947 BOTH, | 1004 BOTH, |
948 trusted_popup->browser(), | 1005 trusted_popup->browser(), |
1006 p1280x1024, | |
1007 p1600x1200)); | |
1008 // A popup that is sized to occupy the whole work area is maximized. | |
1009 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, | |
1010 GetWindowShowState(ui::SHOW_STATE_DEFAULT, | |
1011 ui::SHOW_STATE_NORMAL, | |
1012 BOTH, | |
1013 trusted_popup->browser(), | |
1014 p1600x1200, | |
949 p1600x1200)); | 1015 p1600x1200)); |
950 } | 1016 } |
OLD | NEW |