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