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 "athena/wm/split_view_controller.h" | 5 #include "athena/wm/split_view_controller.h" |
6 | 6 |
7 #include "athena/screen/public/screen_manager.h" | 7 #include "athena/screen/public/screen_manager.h" |
8 #include "athena/test/athena_test_base.h" | 8 #include "athena/test/athena_test_base.h" |
9 #include "athena/wm/public/window_list_provider.h" | 9 #include "athena/wm/public/window_list_provider.h" |
10 #include "athena/wm/test/window_manager_impl_test_api.h" | 10 #include "athena/wm/test/window_manager_impl_test_api.h" |
11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
12 #include "ui/aura/test/test_window_delegate.h" | |
13 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
14 #include "ui/gfx/display.h" | 13 #include "ui/gfx/display.h" |
15 #include "ui/gfx/screen.h" | 14 #include "ui/gfx/screen.h" |
| 15 #include "ui/wm/core/window_util.h" |
16 | 16 |
17 namespace athena { | 17 namespace athena { |
18 | 18 |
19 class SplitViewControllerTest : public test::AthenaTestBase { | 19 class SplitViewControllerTest : public test::AthenaTestBase { |
20 public: | 20 public: |
21 SplitViewControllerTest() {} | 21 SplitViewControllerTest() {} |
22 virtual ~SplitViewControllerTest() {} | 22 virtual ~SplitViewControllerTest() {} |
23 | 23 |
24 // test::AthenaTestBase: | 24 // test::AthenaTestBase: |
25 virtual void SetUp() OVERRIDE { | 25 virtual void SetUp() OVERRIDE { |
26 test::AthenaTestBase::SetUp(); | 26 test::AthenaTestBase::SetUp(); |
27 api_.reset(new test::WindowManagerImplTestApi); | 27 api_.reset(new test::WindowManagerImplTestApi); |
28 } | 28 } |
29 | 29 |
30 virtual void TearDown() OVERRIDE { | 30 virtual void TearDown() OVERRIDE { |
31 api_.reset(); | 31 api_.reset(); |
32 test::AthenaTestBase::TearDown(); | 32 test::AthenaTestBase::TearDown(); |
33 } | 33 } |
34 | 34 |
| 35 // Creates a window and activates it. |
| 36 scoped_ptr<aura::Window> CreateAndActivateWindow() { |
| 37 scoped_ptr<aura::Window> window = CreateTestWindow(NULL, gfx::Rect()); |
| 38 window->Show(); |
| 39 wm::ActivateWindow(window.get()); |
| 40 return window.Pass(); |
| 41 } |
| 42 |
| 43 // Returns the topmost window in z-order. |
| 44 aura::Window* GetTopmostWindow() const { |
| 45 return *api_->GetWindowListProvider()->GetWindowList().rbegin(); |
| 46 } |
| 47 |
| 48 // Returns the window which second from the top in z-order. |
| 49 aura::Window* GetSecondTopmostWindow() const { |
| 50 return *(api_->GetWindowListProvider()->GetWindowList().rbegin() + 1); |
| 51 } |
| 52 |
35 bool IsSplitViewAllowed() const { | 53 bool IsSplitViewAllowed() const { |
36 return api_->GetSplitViewController()->CanScroll(); | 54 return api_->GetSplitViewController()->CanScroll(); |
37 } | 55 } |
38 | 56 |
39 test::WindowManagerImplTestApi* api() { | 57 test::WindowManagerImplTestApi* api() { |
40 return api_.get(); | 58 return api_.get(); |
41 } | 59 } |
42 | 60 |
43 private: | 61 private: |
44 scoped_ptr<test::WindowManagerImplTestApi> api_; | 62 scoped_ptr<test::WindowManagerImplTestApi> api_; |
45 | 63 |
46 DISALLOW_COPY_AND_ASSIGN(SplitViewControllerTest); | 64 DISALLOW_COPY_AND_ASSIGN(SplitViewControllerTest); |
47 }; | 65 }; |
48 | 66 |
49 // Tests that when split mode is activated, the windows on the left and right | 67 // Tests that when split mode is activated, the windows on the left and right |
50 // are selected correctly. | 68 // are selected correctly. |
51 TEST_F(SplitViewControllerTest, SplitModeActivation) { | 69 TEST_F(SplitViewControllerTest, SplitModeActivation) { |
52 aura::test::TestWindowDelegate delegate; | |
53 ScopedVector<aura::Window> windows; | 70 ScopedVector<aura::Window> windows; |
54 const int kNumWindows = 6; | 71 const int kNumWindows = 6; |
55 for (size_t i = 0; i < kNumWindows; ++i) { | 72 for (size_t i = 0; i < kNumWindows; ++i) { |
56 scoped_ptr<aura::Window> window = CreateTestWindow(NULL, gfx::Rect()); | 73 scoped_ptr<aura::Window> window = CreateAndActivateWindow(); |
57 windows.push_back(window.release()); | 74 windows.push_back(window.release()); |
58 } | 75 } |
59 | 76 |
60 SplitViewController* controller = api()->GetSplitViewController(); | 77 SplitViewController* controller = api()->GetSplitViewController(); |
61 WindowListProvider* list_provider = api()->GetWindowListProvider(); | |
62 ASSERT_FALSE(controller->IsSplitViewModeActive()); | 78 ASSERT_FALSE(controller->IsSplitViewModeActive()); |
63 | 79 |
64 controller->ActivateSplitMode(NULL, NULL); | 80 EXPECT_EQ(windows[kNumWindows - 1], GetTopmostWindow()); |
| 81 EXPECT_EQ(windows[kNumWindows - 2], GetSecondTopmostWindow()); |
| 82 |
| 83 controller->ActivateSplitMode(windows[kNumWindows - 1], NULL); |
65 ASSERT_TRUE(controller->IsSplitViewModeActive()); | 84 ASSERT_TRUE(controller->IsSplitViewModeActive()); |
66 // The last two windows should be on the left and right, respectively. | 85 // The topmost windows should have been picked for the left and right |
| 86 // window. |
67 EXPECT_EQ(windows[kNumWindows - 1], controller->left_window()); | 87 EXPECT_EQ(windows[kNumWindows - 1], controller->left_window()); |
| 88 EXPECT_EQ(windows[kNumWindows - 1], GetTopmostWindow()); |
68 EXPECT_EQ(windows[kNumWindows - 2], controller->right_window()); | 89 EXPECT_EQ(windows[kNumWindows - 2], controller->right_window()); |
| 90 EXPECT_EQ(windows[kNumWindows - 2], GetSecondTopmostWindow()); |
69 | 91 |
70 // Select the window that is currently on the left for the right panel. The | 92 // Select the window that is currently on the left for the right panel. The |
71 // windows should switch. | 93 // windows should switch. |
72 controller->ActivateSplitMode(NULL, windows[kNumWindows - 1]); | 94 controller->ActivateSplitMode(NULL, windows[kNumWindows - 1]); |
73 EXPECT_EQ(windows[kNumWindows - 2], controller->left_window()); | 95 EXPECT_EQ(windows[kNumWindows - 2], controller->left_window()); |
| 96 EXPECT_EQ(windows[kNumWindows - 2], GetSecondTopmostWindow()); |
74 EXPECT_EQ(windows[kNumWindows - 1], controller->right_window()); | 97 EXPECT_EQ(windows[kNumWindows - 1], controller->right_window()); |
| 98 EXPECT_EQ(windows[kNumWindows - 1], GetTopmostWindow()); |
75 | 99 |
76 controller->ActivateSplitMode(windows[kNumWindows - 1], NULL); | 100 controller->ActivateSplitMode(windows[kNumWindows - 1], NULL); |
77 EXPECT_EQ(windows[kNumWindows - 1], controller->left_window()); | 101 EXPECT_EQ(windows[kNumWindows - 1], controller->left_window()); |
| 102 EXPECT_EQ(windows[kNumWindows - 1], GetTopmostWindow()); |
78 EXPECT_EQ(windows[kNumWindows - 2], controller->right_window()); | 103 EXPECT_EQ(windows[kNumWindows - 2], controller->right_window()); |
| 104 EXPECT_EQ(windows[kNumWindows - 2], GetSecondTopmostWindow()); |
79 | 105 |
80 // Select one of the windows behind the stacks for the right panel. The window | 106 // Select one of the windows behind the stacks for the right panel. The window |
81 // on the left should remain unchanged. | 107 // on the left should remain unchanged. |
| 108 wm::ActivateWindow(windows[0]); |
82 controller->ActivateSplitMode(NULL, windows[0]); | 109 controller->ActivateSplitMode(NULL, windows[0]); |
83 EXPECT_EQ(windows[kNumWindows - 1], controller->left_window()); | 110 EXPECT_EQ(windows[kNumWindows - 1], controller->left_window()); |
| 111 EXPECT_EQ(windows[kNumWindows - 1], GetSecondTopmostWindow()); |
84 EXPECT_EQ(windows[0], controller->right_window()); | 112 EXPECT_EQ(windows[0], controller->right_window()); |
85 EXPECT_EQ(windows[0], *list_provider->GetWindowList().rbegin()); | 113 EXPECT_EQ(windows[0], GetTopmostWindow()); |
86 | 114 |
| 115 wm::ActivateWindow(windows[1]); |
87 controller->ActivateSplitMode(windows[1], NULL); | 116 controller->ActivateSplitMode(windows[1], NULL); |
88 EXPECT_EQ(windows[1], controller->left_window()); | 117 EXPECT_EQ(windows[1], controller->left_window()); |
| 118 EXPECT_EQ(windows[1], GetTopmostWindow()); |
89 EXPECT_EQ(windows[0], controller->right_window()); | 119 EXPECT_EQ(windows[0], controller->right_window()); |
90 EXPECT_EQ(windows[1], *list_provider->GetWindowList().rbegin()); | 120 EXPECT_EQ(windows[0], GetSecondTopmostWindow()); |
91 | 121 |
| 122 wm::ActivateWindow(windows[5]); |
92 controller->ActivateSplitMode(windows[4], windows[5]); | 123 controller->ActivateSplitMode(windows[4], windows[5]); |
93 EXPECT_EQ(windows[4], controller->left_window()); | 124 EXPECT_EQ(windows[4], controller->left_window()); |
| 125 EXPECT_EQ(windows[4], GetSecondTopmostWindow()); |
94 EXPECT_EQ(windows[5], controller->right_window()); | 126 EXPECT_EQ(windows[5], controller->right_window()); |
95 EXPECT_EQ(windows[4], *list_provider->GetWindowList().rbegin()); | 127 EXPECT_EQ(windows[5], GetTopmostWindow()); |
96 EXPECT_EQ(windows[5], *(list_provider->GetWindowList().rbegin() + 1)); | |
97 } | 128 } |
98 | 129 |
99 TEST_F(SplitViewControllerTest, LandscapeOnly) { | 130 TEST_F(SplitViewControllerTest, LandscapeOnly) { |
100 aura::test::TestWindowDelegate delegate; | |
101 ScopedVector<aura::Window> windows; | 131 ScopedVector<aura::Window> windows; |
102 const int kNumWindows = 2; | 132 const int kNumWindows = 2; |
103 for (size_t i = 0; i < kNumWindows; ++i) { | 133 for (size_t i = 0; i < kNumWindows; ++i) { |
104 scoped_ptr<aura::Window> window = CreateTestWindow(NULL, gfx::Rect()); | 134 scoped_ptr<aura::Window> window = CreateAndActivateWindow(); |
105 windows.push_back(window.release()); | 135 windows.push_back(window.release()); |
106 } | 136 } |
107 ASSERT_EQ(gfx::Display::ROTATE_0, | 137 ASSERT_EQ(gfx::Display::ROTATE_0, |
108 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().rotation()); | 138 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().rotation()); |
109 | 139 |
110 SplitViewController* controller = api()->GetSplitViewController(); | 140 SplitViewController* controller = api()->GetSplitViewController(); |
111 ASSERT_TRUE(IsSplitViewAllowed()); | 141 ASSERT_TRUE(IsSplitViewAllowed()); |
112 ASSERT_FALSE(controller->IsSplitViewModeActive()); | 142 ASSERT_FALSE(controller->IsSplitViewModeActive()); |
113 | 143 |
114 controller->ActivateSplitMode(NULL, NULL); | 144 controller->ActivateSplitMode(windows[kNumWindows - 1], NULL); |
115 ASSERT_TRUE(controller->IsSplitViewModeActive()); | 145 ASSERT_TRUE(controller->IsSplitViewModeActive()); |
116 | 146 |
117 // Screen rotation should be locked while in splitview. | 147 // Screen rotation should be locked while in splitview. |
118 ScreenManager::Get()->SetRotation(gfx::Display::ROTATE_90); | 148 ScreenManager::Get()->SetRotation(gfx::Display::ROTATE_90); |
119 EXPECT_EQ(gfx::Display::ROTATE_0, | 149 EXPECT_EQ(gfx::Display::ROTATE_0, |
120 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().rotation()); | 150 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().rotation()); |
121 | 151 |
122 // Screen is rotated on exiting splitview. | 152 // Screen is rotated on exiting splitview. |
123 controller->DeactivateSplitMode(); | 153 controller->DeactivateSplitMode(); |
124 ASSERT_EQ(gfx::Display::ROTATE_90, | 154 ASSERT_EQ(gfx::Display::ROTATE_90, |
125 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().rotation()); | 155 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().rotation()); |
126 | 156 |
127 // Entering splitview should now be disabled now that the screen is in a | 157 // Entering splitview should now be disabled now that the screen is in a |
128 // portrait orientation. | 158 // portrait orientation. |
129 EXPECT_FALSE(IsSplitViewAllowed()); | 159 EXPECT_FALSE(IsSplitViewAllowed()); |
130 | 160 |
131 // Rotating back to 0 allows splitview again. | 161 // Rotating back to 0 allows splitview again. |
132 ScreenManager::Get()->SetRotation(gfx::Display::ROTATE_0); | 162 ScreenManager::Get()->SetRotation(gfx::Display::ROTATE_0); |
133 EXPECT_TRUE(IsSplitViewAllowed()); | 163 EXPECT_TRUE(IsSplitViewAllowed()); |
134 } | 164 } |
135 | 165 |
136 } // namespace athena | 166 } // namespace athena |
OLD | NEW |