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
3 // found in the LICENSE file.
5 #include "athena/wm/split_view_controller.h"
7 #include "athena/screen/public/screen_manager.h"
8 #include "athena/test/athena_test_base.h"
9 #include "athena/wm/public/window_list_provider.h"
10 #include "athena/wm/test/window_manager_impl_test_api.h"
11 #include "base/memory/scoped_vector.h"
12 #include "ui/aura/test/test_window_delegate.h"
13 #include "ui/aura/window.h"
14 #include "ui/gfx/display.h"
15 #include "ui/gfx/screen.h"
19 class SplitViewControllerTest
: public test::AthenaTestBase
{
21 SplitViewControllerTest() {}
22 virtual ~SplitViewControllerTest() {}
24 // test::AthenaTestBase:
25 virtual void SetUp() OVERRIDE
{
26 test::AthenaTestBase::SetUp();
27 api_
.reset(new test::WindowManagerImplTestApi
);
30 virtual void TearDown() OVERRIDE
{
32 test::AthenaTestBase::TearDown();
35 bool IsSplitViewAllowed() const {
36 return api_
->GetSplitViewController()->CanScroll();
39 test::WindowManagerImplTestApi
* api() {
44 scoped_ptr
<test::WindowManagerImplTestApi
> api_
;
46 DISALLOW_COPY_AND_ASSIGN(SplitViewControllerTest
);
49 // Tests that when split mode is activated, the windows on the left and right
50 // are selected correctly.
51 TEST_F(SplitViewControllerTest
, SplitModeActivation
) {
52 aura::test::TestWindowDelegate delegate
;
53 ScopedVector
<aura::Window
> windows
;
54 const int kNumWindows
= 6;
55 for (size_t i
= 0; i
< kNumWindows
; ++i
) {
56 scoped_ptr
<aura::Window
> window
= CreateTestWindow(NULL
, gfx::Rect());
57 windows
.push_back(window
.release());
60 SplitViewController
* controller
= api()->GetSplitViewController();
61 WindowListProvider
* list_provider
= api()->GetWindowListProvider();
62 ASSERT_FALSE(controller
->IsSplitViewModeActive());
64 controller
->ActivateSplitMode(NULL
, NULL
);
65 ASSERT_TRUE(controller
->IsSplitViewModeActive());
66 // The last two windows should be on the left and right, respectively.
67 EXPECT_EQ(windows
[kNumWindows
- 1], controller
->left_window());
68 EXPECT_EQ(windows
[kNumWindows
- 2], controller
->right_window());
70 // Select the window that is currently on the left for the right panel. The
71 // windows should switch.
72 controller
->ActivateSplitMode(NULL
, windows
[kNumWindows
- 1]);
73 EXPECT_EQ(windows
[kNumWindows
- 2], controller
->left_window());
74 EXPECT_EQ(windows
[kNumWindows
- 1], controller
->right_window());
76 controller
->ActivateSplitMode(windows
[kNumWindows
- 1], NULL
);
77 EXPECT_EQ(windows
[kNumWindows
- 1], controller
->left_window());
78 EXPECT_EQ(windows
[kNumWindows
- 2], controller
->right_window());
80 // Select one of the windows behind the stacks for the right panel. The window
81 // on the left should remain unchanged.
82 controller
->ActivateSplitMode(NULL
, windows
[0]);
83 EXPECT_EQ(windows
[kNumWindows
- 1], controller
->left_window());
84 EXPECT_EQ(windows
[0], controller
->right_window());
85 EXPECT_EQ(windows
[0], *list_provider
->GetWindowList().rbegin());
87 controller
->ActivateSplitMode(windows
[1], NULL
);
88 EXPECT_EQ(windows
[1], controller
->left_window());
89 EXPECT_EQ(windows
[0], controller
->right_window());
90 EXPECT_EQ(windows
[1], *list_provider
->GetWindowList().rbegin());
92 controller
->ActivateSplitMode(windows
[4], windows
[5]);
93 EXPECT_EQ(windows
[4], controller
->left_window());
94 EXPECT_EQ(windows
[5], controller
->right_window());
95 EXPECT_EQ(windows
[4], *list_provider
->GetWindowList().rbegin());
96 EXPECT_EQ(windows
[5], *(list_provider
->GetWindowList().rbegin() + 1));
99 TEST_F(SplitViewControllerTest
, LandscapeOnly
) {
100 aura::test::TestWindowDelegate delegate
;
101 ScopedVector
<aura::Window
> windows
;
102 const int kNumWindows
= 2;
103 for (size_t i
= 0; i
< kNumWindows
; ++i
) {
104 scoped_ptr
<aura::Window
> window
= CreateTestWindow(NULL
, gfx::Rect());
105 windows
.push_back(window
.release());
107 ASSERT_EQ(gfx::Display::ROTATE_0
,
108 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().rotation());
110 SplitViewController
* controller
= api()->GetSplitViewController();
111 ASSERT_TRUE(IsSplitViewAllowed());
112 ASSERT_FALSE(controller
->IsSplitViewModeActive());
114 controller
->ActivateSplitMode(NULL
, NULL
);
115 ASSERT_TRUE(controller
->IsSplitViewModeActive());
117 // Screen rotation should be locked while in splitview.
118 ScreenManager::Get()->SetRotation(gfx::Display::ROTATE_90
);
119 EXPECT_EQ(gfx::Display::ROTATE_0
,
120 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().rotation());
122 // Screen is rotated on exiting splitview.
123 controller
->DeactivateSplitMode();
124 ASSERT_EQ(gfx::Display::ROTATE_90
,
125 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().rotation());
127 // Entering splitview should now be disabled now that the screen is in a
128 // portrait orientation.
129 EXPECT_FALSE(IsSplitViewAllowed());
131 // Rotating back to 0 allows splitview again.
132 ScreenManager::Get()->SetRotation(gfx::Display::ROTATE_0
);
133 EXPECT_TRUE(IsSplitViewAllowed());
136 } // namespace athena