Chromium Code Reviews| 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/wm/workspace/workspace_layout_manager.h" | 5 #include "ash/wm/workspace/workspace_layout_manager.h" |
| 6 | 6 |
| 7 #include "ash/display/display_layout.h" | 7 #include "ash/display/display_layout.h" |
| 8 #include "ash/display/display_manager.h" | 8 #include "ash/display/display_manager.h" |
| 9 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
| 10 #include "ash/screen_util.h" | 10 #include "ash/screen_util.h" |
| 11 #include "ash/session_state_delegate.h" | 11 #include "ash/session_state_delegate.h" |
| 12 #include "ash/shelf/shelf_layout_manager.h" | 12 #include "ash/shelf/shelf_layout_manager.h" |
| 13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 14 #include "ash/shell_observer.h" | 14 #include "ash/shell_observer.h" |
| 15 #include "ash/shell_window_ids.h" | 15 #include "ash/shell_window_ids.h" |
| 16 #include "ash/test/ash_test_base.h" | 16 #include "ash/test/ash_test_base.h" |
| 17 #include "ash/wm/maximize_mode/workspace_backdrop_delegate.h" | |
| 17 #include "ash/wm/window_state.h" | 18 #include "ash/wm/window_state.h" |
| 18 #include "ash/wm/window_util.h" | 19 #include "ash/wm/window_util.h" |
| 19 #include "ash/wm/wm_event.h" | 20 #include "ash/wm/wm_event.h" |
| 20 #include "ash/wm/workspace/workspace_window_resizer.h" | 21 #include "ash/wm/workspace/workspace_window_resizer.h" |
| 21 #include "base/basictypes.h" | 22 #include "base/basictypes.h" |
| 22 #include "base/compiler_specific.h" | 23 #include "base/compiler_specific.h" |
| 23 #include "ui/aura/client/aura_constants.h" | 24 #include "ui/aura/client/aura_constants.h" |
| 24 #include "ui/aura/test/test_windows.h" | 25 #include "ui/aura/test/test_windows.h" |
| 25 #include "ui/aura/window.h" | 26 #include "ui/aura/window.h" |
| 26 #include "ui/aura/window_event_dispatcher.h" | 27 #include "ui/aura/window_event_dispatcher.h" |
| (...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 767 shelf->UpdateVisibilityState(); | 768 shelf->UpdateVisibilityState(); |
| 768 EXPECT_NE( | 769 EXPECT_NE( |
| 769 ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString(), | 770 ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString(), |
| 770 window_bounds.ToString()); | 771 window_bounds.ToString()); |
| 771 | 772 |
| 772 Shell::GetInstance()->session_state_delegate()->UnlockScreen(); | 773 Shell::GetInstance()->session_state_delegate()->UnlockScreen(); |
| 773 shelf->UpdateVisibilityState(); | 774 shelf->UpdateVisibilityState(); |
| 774 EXPECT_EQ(window_bounds.ToString(), window->bounds().ToString()); | 775 EXPECT_EQ(window_bounds.ToString(), window->bounds().ToString()); |
| 775 } | 776 } |
| 776 | 777 |
| 778 // Following tests are written to test the backdrop functionality. | |
| 779 | |
| 780 namespace { | |
| 781 | |
| 782 class WorkspaceLayoutManagerBackdropTest : public test::AshTestBase { | |
| 783 public: | |
| 784 WorkspaceLayoutManagerBackdropTest() {} | |
| 785 virtual ~WorkspaceLayoutManagerBackdropTest() {} | |
| 786 | |
| 787 virtual void SetUp() OVERRIDE { | |
| 788 test::AshTestBase::SetUp(); | |
| 789 UpdateDisplay("800x600"); | |
| 790 default_container_ = Shell::GetContainer( | |
| 791 Shell::GetPrimaryRootWindow(), | |
| 792 internal::kShellWindowId_DefaultContainer); | |
| 793 // We set the size to something smaller then the display to avoid resizing | |
| 794 // issues with the shelf. | |
| 795 default_container_->SetBounds(gfx::Rect(0, 0, 800, 500)); | |
| 796 } | |
| 797 | |
| 798 aura::Window* CreateTestWindow(const gfx::Rect& bounds) { | |
| 799 aura::Window* window = CreateTestWindowInShellWithBounds(bounds); | |
| 800 return window; | |
| 801 } | |
| 802 | |
| 803 // Turn the top window back drop on / off. | |
| 804 void ShowTopWindowBackdrop(bool show) { | |
| 805 ash::internal::MaximizeBackdropDelegate* backdrop = NULL; | |
| 806 if (show) { | |
| 807 backdrop = new ash::internal::WorkspaceBackdropDelegate( | |
| 808 default_container_); | |
| 809 } | |
| 810 (static_cast<internal::WorkspaceLayoutManager*> | |
| 811 (default_container_->layout_manager()))->SetMaximizeBackdropDelegate( | |
| 812 backdrop); | |
| 813 // Closing and / or opening can be a delayed operation. | |
| 814 base::MessageLoop::current()->RunUntilIdle(); | |
| 815 } | |
| 816 | |
| 817 // Return the default container. | |
| 818 aura::Window* default_container() { return default_container_; } | |
| 819 | |
| 820 // Return the order of windows (top most first) as they are in the default | |
| 821 // container. If the window is visible it will be a big letter, otherwise a | |
| 822 // small one. The backdrop will be an X and unknown windows will be shown as | |
| 823 // '!'. | |
| 824 std::string GetWindowOrderAsString(aura::Window* backdrop, | |
| 825 aura::Window* wa, | |
| 826 aura::Window* wb, | |
| 827 aura::Window* wc) { | |
| 828 std::string result; | |
| 829 for (int i = default_container()->children().size() - 1; | |
|
sky
2014/03/06 21:34:13
Does this overflow if empty?
Mr4D (OOO till 08-26)
2014/03/07 01:00:12
for (;false;) { do somehting; } should never execu
sky
2014/03/07 15:00:10
I'm not sure which of these this code is interpret
Mr4D (OOO till 08-26)
2014/03/07 15:55:35
size_t. Okay. Done.
| |
| 830 i >= 0; | |
| 831 --i) { | |
| 832 if (!result.empty()) | |
| 833 result += ","; | |
| 834 if (default_container()->children()[i] == wa) | |
| 835 result += default_container()->children()[i]->IsVisible() ? "A" : "a"; | |
| 836 else if (default_container()->children()[i] == wb) | |
| 837 result += default_container()->children()[i]->IsVisible() ? "B" : "b"; | |
| 838 else if (default_container()->children()[i] == wc) | |
| 839 result += default_container()->children()[i]->IsVisible() ? "C" : "c"; | |
| 840 else if (default_container()->children()[i] == backdrop) | |
| 841 result += default_container()->children()[i]->IsVisible() ? "X" : "x"; | |
| 842 else | |
| 843 result += "!"; | |
| 844 } | |
| 845 return result; | |
| 846 } | |
| 847 | |
| 848 private: | |
| 849 // The default container. | |
| 850 aura::Window* default_container_; | |
| 851 | |
| 852 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerBackdropTest); | |
| 853 }; | |
| 854 | |
| 855 } // namespace | |
| 856 | |
| 857 // Check that creating the BackDrop without destroying it does not lead into | |
| 858 // a crash. | |
| 859 TEST_F(WorkspaceLayoutManagerBackdropTest, BackdropCrashTest) { | |
| 860 ShowTopWindowBackdrop(true); | |
| 861 } | |
| 862 | |
| 863 // Verify basic assumptions about the backdrop. | |
| 864 TEST_F(WorkspaceLayoutManagerBackdropTest, BasicBackdropTests) { | |
| 865 // Create a backdrop and see that there is one window (the backdrop) and | |
| 866 // that the size is the same as the default container as well as that it is | |
| 867 // not visible. | |
| 868 ShowTopWindowBackdrop(true); | |
| 869 ASSERT_EQ(1U, default_container()->children().size()); | |
| 870 EXPECT_FALSE(default_container()->children()[0]->IsVisible()); | |
| 871 | |
| 872 { | |
| 873 // Add a window and make sure that the backdrop is the second child. | |
| 874 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); | |
| 875 window->Show(); | |
| 876 ASSERT_EQ(2U, default_container()->children().size()); | |
| 877 EXPECT_TRUE(default_container()->children()[0]->IsVisible()); | |
| 878 EXPECT_TRUE(default_container()->children()[1]->IsVisible()); | |
| 879 EXPECT_EQ(window.get(), default_container()->children()[1]); | |
| 880 EXPECT_EQ(default_container()->bounds().ToString(), | |
| 881 default_container()->children()[0]->bounds().ToString()); | |
| 882 } | |
| 883 | |
| 884 // With the window gone the backdrop should be invisible again. | |
| 885 ASSERT_EQ(1U, default_container()->children().size()); | |
| 886 EXPECT_FALSE(default_container()->children()[0]->IsVisible()); | |
| 887 | |
| 888 // Destroying the Backdrop should empty the container. | |
| 889 ShowTopWindowBackdrop(false); | |
| 890 ASSERT_EQ(0U, default_container()->children().size()); | |
| 891 } | |
| 892 | |
| 893 // Verify that the backdrop gets properly created and placed. | |
| 894 TEST_F(WorkspaceLayoutManagerBackdropTest, VerifyBackdropAndItsStacking) { | |
| 895 scoped_ptr<aura::Window> window1(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); | |
| 896 window1->Show(); | |
| 897 | |
| 898 // Get the default container and check that only a single window is in there. | |
| 899 ASSERT_EQ(1U, default_container()->children().size()); | |
| 900 EXPECT_EQ(window1.get(), default_container()->children()[0]); | |
| 901 EXPECT_EQ("A", GetWindowOrderAsString(NULL, window1.get(), NULL, NULL)); | |
| 902 | |
| 903 // Create 2 more windows and check that they are also in the container. | |
| 904 scoped_ptr<aura::Window> window2(CreateTestWindow(gfx::Rect(10, 2, 3, 4))); | |
| 905 scoped_ptr<aura::Window> window3(CreateTestWindow(gfx::Rect(20, 2, 3, 4))); | |
| 906 window2->Show(); | |
| 907 window3->Show(); | |
| 908 | |
| 909 aura::Window* backdrop = NULL; | |
| 910 EXPECT_EQ("C,B,A", | |
| 911 GetWindowOrderAsString(backdrop, window1.get(), window2.get(), | |
| 912 window3.get())); | |
| 913 | |
| 914 // Turn on the backdrop mode and check that the window shows up where it | |
| 915 // should be (second highest number). | |
| 916 ShowTopWindowBackdrop(true); | |
| 917 backdrop = default_container()->children()[2]; | |
| 918 EXPECT_EQ("C,X,B,A", | |
| 919 GetWindowOrderAsString(backdrop, window1.get(), window2.get(), | |
| 920 window3.get())); | |
| 921 | |
| 922 // Switch the order of windows and check that it still remains in that | |
| 923 // location. | |
| 924 default_container()->StackChildAtTop(window2.get()); | |
| 925 EXPECT_EQ("B,X,C,A", | |
| 926 GetWindowOrderAsString(backdrop, window1.get(), window2.get(), | |
| 927 window3.get())); | |
| 928 | |
| 929 // Make the top window invisible and check. | |
| 930 window2.get()->Hide(); | |
| 931 EXPECT_EQ("b,C,X,A", | |
| 932 GetWindowOrderAsString(backdrop, window1.get(), window2.get(), | |
| 933 window3.get())); | |
| 934 // Then delete window after window and see that everything is in order. | |
| 935 window1.reset(); | |
| 936 EXPECT_EQ("b,C,X", | |
| 937 GetWindowOrderAsString(backdrop, window1.get(), window2.get(), | |
| 938 window3.get())); | |
| 939 window3.reset(); | |
| 940 EXPECT_EQ("b,x", | |
| 941 GetWindowOrderAsString(backdrop, window1.get(), window2.get(), | |
| 942 window3.get())); | |
| 943 ShowTopWindowBackdrop(false); | |
| 944 EXPECT_EQ("b", | |
| 945 GetWindowOrderAsString(NULL, window1.get(), window2.get(), | |
| 946 window3.get())); | |
| 947 } | |
| 948 | |
| 777 } // namespace ash | 949 } // namespace ash |
| OLD | NEW |