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" |
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 shelf->UpdateVisibilityState(); | 783 shelf->UpdateVisibilityState(); |
784 EXPECT_NE( | 784 EXPECT_NE( |
785 ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString(), | 785 ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString(), |
786 window_bounds.ToString()); | 786 window_bounds.ToString()); |
787 | 787 |
788 Shell::GetInstance()->session_state_delegate()->UnlockScreen(); | 788 Shell::GetInstance()->session_state_delegate()->UnlockScreen(); |
789 shelf->UpdateVisibilityState(); | 789 shelf->UpdateVisibilityState(); |
790 EXPECT_EQ(window_bounds.ToString(), window->bounds().ToString()); | 790 EXPECT_EQ(window_bounds.ToString(), window->bounds().ToString()); |
791 } | 791 } |
792 | 792 |
| 793 // Following tests are written to test the backdrop functionality. |
| 794 |
| 795 namespace { |
| 796 |
| 797 class WorkspaceLayoutManagerBackdropTest : public test::AshTestBase { |
| 798 public: |
| 799 WorkspaceLayoutManagerBackdropTest() {} |
| 800 virtual ~WorkspaceLayoutManagerBackdropTest() {} |
| 801 |
| 802 virtual void SetUp() OVERRIDE { |
| 803 test::AshTestBase::SetUp(); |
| 804 UpdateDisplay("800x600"); |
| 805 default_container_ = Shell::GetContainer( |
| 806 Shell::GetPrimaryRootWindow(), |
| 807 internal::kShellWindowId_DefaultContainer); |
| 808 // We set the size to something smaller then the display to avoid resizing |
| 809 // issues with the shelf. |
| 810 default_container_->SetBounds(gfx::Rect(0, 0, 800, 500)); |
| 811 } |
| 812 |
| 813 aura::Window* CreateTestWindow(const gfx::Rect& bounds) { |
| 814 aura::Window* window = CreateTestWindowInShellWithBounds(bounds); |
| 815 return window; |
| 816 } |
| 817 |
| 818 // Turn the top window back drop on / off. |
| 819 void ShowTopWindowBackdrop(bool show) { |
| 820 (static_cast<internal::WorkspaceLayoutManager*> |
| 821 (default_container_->layout_manager()))->AddBackdropBehindTopWindow( |
| 822 show); |
| 823 // Closing and / or opening can be a delayed operation. |
| 824 base::MessageLoop::current()->RunUntilIdle(); |
| 825 } |
| 826 |
| 827 // Return the default container. |
| 828 aura::Window* default_container() { return default_container_; } |
| 829 |
| 830 // Return the order of windows (top most first) as they are in the default |
| 831 // container. If the window is visible it will be a big letter, otherwise a |
| 832 // small one. The backdrop will be an X and unknown windows will be shown as |
| 833 // '!'. |
| 834 std::string GetWindowOrderAsString(aura::Window* backdrop, |
| 835 aura::Window* wa, |
| 836 aura::Window* wb, |
| 837 aura::Window* wc) { |
| 838 std::string result; |
| 839 for (int i = default_container()->children().size() - 1; |
| 840 i >= 0; |
| 841 --i) { |
| 842 if (!result.empty()) |
| 843 result += ","; |
| 844 if (default_container()->children()[i] == wa) |
| 845 result += default_container()->children()[i]->IsVisible() ? "A" : "a"; |
| 846 else if (default_container()->children()[i] == wb) |
| 847 result += default_container()->children()[i]->IsVisible() ? "B" : "b"; |
| 848 else if (default_container()->children()[i] == wc) |
| 849 result += default_container()->children()[i]->IsVisible() ? "C" : "c"; |
| 850 else if (default_container()->children()[i] == backdrop) |
| 851 result += default_container()->children()[i]->IsVisible() ? "X" : "x"; |
| 852 else |
| 853 result += "!"; |
| 854 } |
| 855 return result; |
| 856 } |
| 857 |
| 858 private: |
| 859 // The default container. |
| 860 aura::Window* default_container_; |
| 861 |
| 862 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerBackdropTest); |
| 863 }; |
| 864 |
| 865 } // namespace |
| 866 |
| 867 // Check that creating the BackDrop without destroying it does not lead into |
| 868 // a crash. |
| 869 TEST_F(WorkspaceLayoutManagerBackdropTest, BackdropCrashTest) { |
| 870 ShowTopWindowBackdrop(true); |
| 871 } |
| 872 |
| 873 // Verify basic assumptions about the backdrop. |
| 874 TEST_F(WorkspaceLayoutManagerBackdropTest, BasicBackdropTests) { |
| 875 // Create a backdrop and see that there is one window (the backdrop) and |
| 876 // that the size is the same as the default container as well as that it is |
| 877 // not visible. |
| 878 ShowTopWindowBackdrop(true); |
| 879 ASSERT_EQ(1U, default_container()->children().size()); |
| 880 EXPECT_FALSE(default_container()->children()[0]->IsVisible()); |
| 881 |
| 882 { |
| 883 // Add a window and make sure that the backdrop is the second child. |
| 884 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); |
| 885 window->Show(); |
| 886 ASSERT_EQ(2U, default_container()->children().size()); |
| 887 EXPECT_TRUE(default_container()->children()[0]->IsVisible()); |
| 888 EXPECT_TRUE(default_container()->children()[1]->IsVisible()); |
| 889 EXPECT_EQ(window.get(), default_container()->children()[1]); |
| 890 EXPECT_EQ(default_container()->bounds().ToString(), |
| 891 default_container()->children()[0]->bounds().ToString()); |
| 892 } |
| 893 |
| 894 // With the window gone the backdrop should be invisible again. |
| 895 ASSERT_EQ(1U, default_container()->children().size()); |
| 896 EXPECT_FALSE(default_container()->children()[0]->IsVisible()); |
| 897 |
| 898 // Destroying the Backdrop should empty the container. |
| 899 ShowTopWindowBackdrop(false); |
| 900 ASSERT_EQ(0U, default_container()->children().size()); |
| 901 } |
| 902 |
| 903 // Verify that the backdrop gets properly created and placed. |
| 904 TEST_F(WorkspaceLayoutManagerBackdropTest, VerifyBackdropAndItsStacking) { |
| 905 scoped_ptr<aura::Window> window1(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); |
| 906 window1->Show(); |
| 907 |
| 908 // Get the default container and check that only a single window is in there. |
| 909 ASSERT_EQ(1U, default_container()->children().size()); |
| 910 EXPECT_EQ(window1.get(), default_container()->children()[0]); |
| 911 EXPECT_EQ("A", GetWindowOrderAsString(NULL, window1.get(), NULL, NULL)); |
| 912 |
| 913 // Create 2 more windows and check that they are also in the container. |
| 914 scoped_ptr<aura::Window> window2(CreateTestWindow(gfx::Rect(10, 2, 3, 4))); |
| 915 scoped_ptr<aura::Window> window3(CreateTestWindow(gfx::Rect(20, 2, 3, 4))); |
| 916 window2->Show(); |
| 917 window3->Show(); |
| 918 |
| 919 aura::Window* backdrop = NULL; |
| 920 EXPECT_EQ("C,B,A", |
| 921 GetWindowOrderAsString(backdrop, window1.get(), window2.get(), |
| 922 window3.get())); |
| 923 |
| 924 // Turn on the backdrop mode and check that the window shows up where it |
| 925 // should be (second highest number). |
| 926 ShowTopWindowBackdrop(true); |
| 927 backdrop = default_container()->children()[2]; |
| 928 EXPECT_EQ("C,X,B,A", |
| 929 GetWindowOrderAsString(backdrop, window1.get(), window2.get(), |
| 930 window3.get())); |
| 931 |
| 932 // Switch the order of windows and check that it still remains in that |
| 933 // location. |
| 934 default_container()->StackChildAtTop(window2.get()); |
| 935 EXPECT_EQ("B,X,C,A", |
| 936 GetWindowOrderAsString(backdrop, window1.get(), window2.get(), |
| 937 window3.get())); |
| 938 |
| 939 // Make the top window invisible and check. |
| 940 window2.get()->Hide(); |
| 941 EXPECT_EQ("b,C,X,A", |
| 942 GetWindowOrderAsString(backdrop, window1.get(), window2.get(), |
| 943 window3.get())); |
| 944 // Then delete window after window and see that everything is in order. |
| 945 window1.reset(); |
| 946 EXPECT_EQ("b,C,X", |
| 947 GetWindowOrderAsString(backdrop, window1.get(), window2.get(), |
| 948 window3.get())); |
| 949 window3.reset(); |
| 950 EXPECT_EQ("b,x", |
| 951 GetWindowOrderAsString(backdrop, window1.get(), window2.get(), |
| 952 window3.get())); |
| 953 ShowTopWindowBackdrop(false); |
| 954 EXPECT_EQ("b", |
| 955 GetWindowOrderAsString(NULL, window1.get(), window2.get(), |
| 956 window3.get())); |
| 957 } |
| 958 |
793 } // namespace ash | 959 } // namespace ash |
OLD | NEW |