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/test/athena_test_base.h" | 8 #include "athena/test/athena_test_base.h" |
8 #include "athena/wm/public/window_list_provider.h" | 9 #include "athena/wm/public/window_list_provider.h" |
9 #include "athena/wm/test/window_manager_impl_test_api.h" | 10 #include "athena/wm/test/window_manager_impl_test_api.h" |
10 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
11 #include "ui/aura/test/test_window_delegate.h" | 12 #include "ui/aura/test/test_window_delegate.h" |
12 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 14 #include "ui/gfx/display.h" |
| 15 #include "ui/gfx/screen.h" |
13 | 16 |
14 namespace athena { | 17 namespace athena { |
15 | 18 |
16 typedef test::AthenaTestBase SplitViewControllerTest; | 19 class SplitViewControllerTest : public test::AthenaTestBase { |
| 20 public: |
| 21 SplitViewControllerTest() {} |
| 22 virtual ~SplitViewControllerTest() {} |
| 23 |
| 24 // test::AthenaTestBase: |
| 25 virtual void SetUp() OVERRIDE { |
| 26 test::AthenaTestBase::SetUp(); |
| 27 api_.reset(new test::WindowManagerImplTestApi); |
| 28 } |
| 29 |
| 30 virtual void TearDown() OVERRIDE { |
| 31 api_.reset(); |
| 32 test::AthenaTestBase::TearDown(); |
| 33 } |
| 34 |
| 35 bool IsSplitViewAllowed() const { |
| 36 return api_->GetSplitViewController()->CanScroll(); |
| 37 } |
| 38 |
| 39 test::WindowManagerImplTestApi* api() { |
| 40 return api_.get(); |
| 41 } |
| 42 |
| 43 private: |
| 44 scoped_ptr<test::WindowManagerImplTestApi> api_; |
| 45 |
| 46 DISALLOW_COPY_AND_ASSIGN(SplitViewControllerTest); |
| 47 }; |
17 | 48 |
18 // Tests that when split mode is activated, the windows on the left and right | 49 // Tests that when split mode is activated, the windows on the left and right |
19 // are selected correctly. | 50 // are selected correctly. |
20 TEST_F(SplitViewControllerTest, SplitModeActivation) { | 51 TEST_F(SplitViewControllerTest, SplitModeActivation) { |
21 aura::test::TestWindowDelegate delegate; | 52 aura::test::TestWindowDelegate delegate; |
22 ScopedVector<aura::Window> windows; | 53 ScopedVector<aura::Window> windows; |
23 const int kNumWindows = 6; | 54 const int kNumWindows = 6; |
24 for (size_t i = 0; i < kNumWindows; ++i) { | 55 for (size_t i = 0; i < kNumWindows; ++i) { |
25 scoped_ptr<aura::Window> window = CreateTestWindow(NULL, gfx::Rect()); | 56 scoped_ptr<aura::Window> window = CreateTestWindow(NULL, gfx::Rect()); |
26 windows.push_back(window.release()); | 57 windows.push_back(window.release()); |
27 } | 58 } |
28 | 59 |
29 test::WindowManagerImplTestApi api; | 60 SplitViewController* controller = api()->GetSplitViewController(); |
30 SplitViewController* controller = api.GetSplitViewController(); | 61 WindowListProvider* list_provider = api()->GetWindowListProvider(); |
31 WindowListProvider* list_provider = api.GetWindowListProvider(); | |
32 ASSERT_FALSE(controller->IsSplitViewModeActive()); | 62 ASSERT_FALSE(controller->IsSplitViewModeActive()); |
33 | 63 |
34 controller->ActivateSplitMode(NULL, NULL); | 64 controller->ActivateSplitMode(NULL, NULL); |
35 ASSERT_TRUE(controller->IsSplitViewModeActive()); | 65 ASSERT_TRUE(controller->IsSplitViewModeActive()); |
36 // The last two windows should be on the left and right, respectively. | 66 // The last two windows should be on the left and right, respectively. |
37 EXPECT_EQ(windows[kNumWindows - 1], controller->left_window()); | 67 EXPECT_EQ(windows[kNumWindows - 1], controller->left_window()); |
38 EXPECT_EQ(windows[kNumWindows - 2], controller->right_window()); | 68 EXPECT_EQ(windows[kNumWindows - 2], controller->right_window()); |
39 | 69 |
40 // Select the window that is currently on the left for the right panel. The | 70 // Select the window that is currently on the left for the right panel. The |
41 // windows should switch. | 71 // windows should switch. |
(...skipping 17 matching lines...) Expand all Loading... |
59 EXPECT_EQ(windows[0], controller->right_window()); | 89 EXPECT_EQ(windows[0], controller->right_window()); |
60 EXPECT_EQ(windows[1], *list_provider->GetWindowList().rbegin()); | 90 EXPECT_EQ(windows[1], *list_provider->GetWindowList().rbegin()); |
61 | 91 |
62 controller->ActivateSplitMode(windows[4], windows[5]); | 92 controller->ActivateSplitMode(windows[4], windows[5]); |
63 EXPECT_EQ(windows[4], controller->left_window()); | 93 EXPECT_EQ(windows[4], controller->left_window()); |
64 EXPECT_EQ(windows[5], controller->right_window()); | 94 EXPECT_EQ(windows[5], controller->right_window()); |
65 EXPECT_EQ(windows[4], *list_provider->GetWindowList().rbegin()); | 95 EXPECT_EQ(windows[4], *list_provider->GetWindowList().rbegin()); |
66 EXPECT_EQ(windows[5], *(list_provider->GetWindowList().rbegin() + 1)); | 96 EXPECT_EQ(windows[5], *(list_provider->GetWindowList().rbegin() + 1)); |
67 } | 97 } |
68 | 98 |
| 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()); |
| 106 } |
| 107 ASSERT_EQ(gfx::Display::ROTATE_0, |
| 108 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().rotation()); |
| 109 |
| 110 SplitViewController* controller = api()->GetSplitViewController(); |
| 111 ASSERT_TRUE(IsSplitViewAllowed()); |
| 112 ASSERT_FALSE(controller->IsSplitViewModeActive()); |
| 113 |
| 114 controller->ActivateSplitMode(NULL, NULL); |
| 115 ASSERT_TRUE(controller->IsSplitViewModeActive()); |
| 116 |
| 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()); |
| 121 |
| 122 // Screen is rotated on exiting splitview. |
| 123 controller->DeactivateSplitMode(); |
| 124 ASSERT_EQ(gfx::Display::ROTATE_90, |
| 125 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().rotation()); |
| 126 |
| 127 // Entering splitview should now be disabled now that the screen is in a |
| 128 // portrait orientation. |
| 129 EXPECT_FALSE(IsSplitViewAllowed()); |
| 130 |
| 131 // Rotating back to 0 allows splitview again. |
| 132 ScreenManager::Get()->SetRotation(gfx::Display::ROTATE_0); |
| 133 EXPECT_TRUE(IsSplitViewAllowed()); |
| 134 } |
| 135 |
69 } // namespace athena | 136 } // namespace athena |
OLD | NEW |