| 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" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 aura::Window::Windows list = | 39 aura::Window::Windows list = |
| 40 api_->GetWindowListProvider()->GetWindowList(); | 40 api_->GetWindowListProvider()->GetWindowList(); |
| 41 aura::Window* topmost = *list.rbegin(); | 41 aura::Window* topmost = *list.rbegin(); |
| 42 aura::Window* second_topmost = *(list.rbegin() + 1); | 42 aura::Window* second_topmost = *(list.rbegin() + 1); |
| 43 return (topmost == controller->left_window() || | 43 return (topmost == controller->left_window() || |
| 44 topmost == controller->right_window()) && | 44 topmost == controller->right_window()) && |
| 45 (second_topmost == controller->left_window() || | 45 (second_topmost == controller->left_window() || |
| 46 second_topmost == controller->right_window()); | 46 second_topmost == controller->right_window()); |
| 47 } | 47 } |
| 48 | 48 |
| 49 // Returns whether only the split view windows are visible. |
| 50 bool OnlySplitViewWindowsVisible() const { |
| 51 SplitViewController* controller = api_->GetSplitViewController(); |
| 52 DCHECK(controller->IsSplitViewModeActive()); |
| 53 aura::Window::Windows list = |
| 54 api_->GetWindowListProvider()->GetWindowList(); |
| 55 for (aura::Window::Windows::const_iterator it = list.begin(); |
| 56 it != list.end(); ++it) { |
| 57 bool in_split_view = (*it == controller->left_window() || |
| 58 *it == controller->right_window()); |
| 59 if (in_split_view != (*it)->IsVisible()) |
| 60 return false; |
| 61 } |
| 62 return true; |
| 63 } |
| 64 |
| 49 bool IsSplitViewAllowed() const { | 65 bool IsSplitViewAllowed() const { |
| 50 return api_->GetSplitViewController()->CanScroll(); | 66 return api_->GetSplitViewController()->CanScroll(); |
| 51 } | 67 } |
| 52 | 68 |
| 53 test::WindowManagerImplTestApi* api() { | 69 test::WindowManagerImplTestApi* api() { |
| 54 return api_.get(); | 70 return api_.get(); |
| 55 } | 71 } |
| 56 | 72 |
| 57 private: | 73 private: |
| 58 scoped_ptr<test::WindowManagerImplTestApi> api_; | 74 scoped_ptr<test::WindowManagerImplTestApi> api_; |
| 59 | 75 |
| 60 DISALLOW_COPY_AND_ASSIGN(SplitViewControllerTest); | 76 DISALLOW_COPY_AND_ASSIGN(SplitViewControllerTest); |
| 61 }; | 77 }; |
| 62 | 78 |
| 63 // Tests that when split mode is activated, the windows on the left and right | 79 // Tests that when split mode is activated, the windows on the left and right |
| 64 // are selected correctly. | 80 // are selected correctly. |
| 65 TEST_F(SplitViewControllerTest, SplitModeActivation) { | 81 TEST_F(SplitViewControllerTest, SplitModeActivation) { |
| 66 aura::test::TestWindowDelegate delegate; | 82 aura::test::TestWindowDelegate delegate; |
| 67 ScopedVector<aura::Window> windows; | 83 ScopedVector<aura::Window> windows; |
| 68 const int kNumWindows = 6; | 84 const int kNumWindows = 6; |
| 69 for (size_t i = 0; i < kNumWindows; ++i) { | 85 for (size_t i = 0; i < kNumWindows; ++i) { |
| 70 scoped_ptr<aura::Window> window = CreateTestWindow(NULL, gfx::Rect()); | 86 scoped_ptr<aura::Window> window = CreateTestWindow(NULL, gfx::Rect()); |
| 71 windows.push_back(window.release()); | 87 windows.push_back(window.release()); |
| 88 windows[i]->Hide(); |
| 72 } | 89 } |
| 73 | 90 |
| 91 windows[kNumWindows - 1]->Show(); |
| 92 |
| 74 SplitViewController* controller = api()->GetSplitViewController(); | 93 SplitViewController* controller = api()->GetSplitViewController(); |
| 75 ASSERT_FALSE(controller->IsSplitViewModeActive()); | 94 ASSERT_FALSE(controller->IsSplitViewModeActive()); |
| 76 | 95 |
| 77 controller->ActivateSplitMode(NULL, NULL); | 96 controller->ActivateSplitMode(NULL, NULL); |
| 78 ASSERT_TRUE(controller->IsSplitViewModeActive()); | 97 ASSERT_TRUE(controller->IsSplitViewModeActive()); |
| 79 // The last two windows should be on the left and right, respectively. | 98 // The last two windows should be on the left and right, respectively. |
| 80 EXPECT_EQ(windows[kNumWindows - 1], controller->left_window()); | 99 EXPECT_EQ(windows[kNumWindows - 1], controller->left_window()); |
| 81 EXPECT_EQ(windows[kNumWindows - 2], controller->right_window()); | 100 EXPECT_EQ(windows[kNumWindows - 2], controller->right_window()); |
| 82 EXPECT_TRUE(SplitViewWindowsTopmost()); | 101 EXPECT_TRUE(SplitViewWindowsTopmost()); |
| 102 EXPECT_TRUE(OnlySplitViewWindowsVisible()); |
| 83 | 103 |
| 84 // Select the window that is currently on the left for the right panel. The | 104 // Select the window that is currently on the left for the right panel. The |
| 85 // windows should switch. | 105 // windows should switch. |
| 86 controller->ActivateSplitMode(NULL, windows[kNumWindows - 1]); | 106 controller->ActivateSplitMode(NULL, windows[kNumWindows - 1]); |
| 87 EXPECT_EQ(windows[kNumWindows - 2], controller->left_window()); | 107 EXPECT_EQ(windows[kNumWindows - 2], controller->left_window()); |
| 88 EXPECT_EQ(windows[kNumWindows - 1], controller->right_window()); | 108 EXPECT_EQ(windows[kNumWindows - 1], controller->right_window()); |
| 89 EXPECT_TRUE(SplitViewWindowsTopmost()); | 109 EXPECT_TRUE(SplitViewWindowsTopmost()); |
| 110 EXPECT_TRUE(OnlySplitViewWindowsVisible()); |
| 90 | 111 |
| 91 controller->ActivateSplitMode(windows[kNumWindows - 1], NULL); | 112 controller->ActivateSplitMode(windows[kNumWindows - 1], NULL); |
| 92 EXPECT_EQ(windows[kNumWindows - 1], controller->left_window()); | 113 EXPECT_EQ(windows[kNumWindows - 1], controller->left_window()); |
| 93 EXPECT_EQ(windows[kNumWindows - 2], controller->right_window()); | 114 EXPECT_EQ(windows[kNumWindows - 2], controller->right_window()); |
| 94 EXPECT_TRUE(SplitViewWindowsTopmost()); | 115 EXPECT_TRUE(SplitViewWindowsTopmost()); |
| 116 EXPECT_TRUE(OnlySplitViewWindowsVisible()); |
| 95 | 117 |
| 96 // Select one of the windows behind the stacks for the right panel. The window | 118 // Select one of the windows behind the stacks for the right panel. The window |
| 97 // on the left should remain unchanged. | 119 // on the left should remain unchanged. |
| 98 controller->ActivateSplitMode(NULL, windows[0]); | 120 controller->ActivateSplitMode(NULL, windows[0]); |
| 99 EXPECT_EQ(windows[kNumWindows - 1], controller->left_window()); | 121 EXPECT_EQ(windows[kNumWindows - 1], controller->left_window()); |
| 100 EXPECT_EQ(windows[0], controller->right_window()); | 122 EXPECT_EQ(windows[0], controller->right_window()); |
| 101 EXPECT_TRUE(SplitViewWindowsTopmost()); | 123 EXPECT_TRUE(SplitViewWindowsTopmost()); |
| 124 EXPECT_TRUE(OnlySplitViewWindowsVisible()); |
| 102 | 125 |
| 103 controller->ActivateSplitMode(windows[1], NULL); | 126 controller->ActivateSplitMode(windows[1], NULL); |
| 104 EXPECT_EQ(windows[1], controller->left_window()); | 127 EXPECT_EQ(windows[1], controller->left_window()); |
| 105 EXPECT_EQ(windows[0], controller->right_window()); | 128 EXPECT_EQ(windows[0], controller->right_window()); |
| 106 EXPECT_TRUE(SplitViewWindowsTopmost()); | 129 EXPECT_TRUE(SplitViewWindowsTopmost()); |
| 130 EXPECT_TRUE(OnlySplitViewWindowsVisible()); |
| 107 | 131 |
| 108 controller->ActivateSplitMode(windows[4], windows[5]); | 132 controller->ActivateSplitMode(windows[4], windows[5]); |
| 109 EXPECT_EQ(windows[4], controller->left_window()); | 133 EXPECT_EQ(windows[4], controller->left_window()); |
| 110 EXPECT_EQ(windows[5], controller->right_window()); | 134 EXPECT_EQ(windows[5], controller->right_window()); |
| 111 EXPECT_TRUE(SplitViewWindowsTopmost()); | 135 EXPECT_TRUE(SplitViewWindowsTopmost()); |
| 136 EXPECT_TRUE(OnlySplitViewWindowsVisible()); |
| 112 | 137 |
| 113 controller->ActivateSplitMode(windows[0], NULL); | 138 controller->ActivateSplitMode(windows[0], NULL); |
| 114 EXPECT_EQ(windows[0], controller->left_window()); | 139 EXPECT_EQ(windows[0], controller->left_window()); |
| 115 EXPECT_EQ(windows[5], controller->right_window()); | 140 EXPECT_EQ(windows[5], controller->right_window()); |
| 116 EXPECT_TRUE(SplitViewWindowsTopmost()); | 141 EXPECT_TRUE(SplitViewWindowsTopmost()); |
| 142 EXPECT_TRUE(OnlySplitViewWindowsVisible()); |
| 117 } | 143 } |
| 118 | 144 |
| 119 TEST_F(SplitViewControllerTest, LandscapeOnly) { | 145 TEST_F(SplitViewControllerTest, LandscapeOnly) { |
| 120 aura::test::TestWindowDelegate delegate; | 146 aura::test::TestWindowDelegate delegate; |
| 121 ScopedVector<aura::Window> windows; | 147 ScopedVector<aura::Window> windows; |
| 122 const int kNumWindows = 2; | 148 const int kNumWindows = 2; |
| 123 for (size_t i = 0; i < kNumWindows; ++i) { | 149 for (size_t i = 0; i < kNumWindows; ++i) { |
| 124 scoped_ptr<aura::Window> window = CreateTestWindow(NULL, gfx::Rect()); | 150 scoped_ptr<aura::Window> window = CreateTestWindow(NULL, gfx::Rect()); |
| 125 windows.push_back(window.release()); | 151 windows.push_back(window.release()); |
| 126 } | 152 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 147 // Entering splitview should now be disabled now that the screen is in a | 173 // Entering splitview should now be disabled now that the screen is in a |
| 148 // portrait orientation. | 174 // portrait orientation. |
| 149 EXPECT_FALSE(IsSplitViewAllowed()); | 175 EXPECT_FALSE(IsSplitViewAllowed()); |
| 150 | 176 |
| 151 // Rotating back to 0 allows splitview again. | 177 // Rotating back to 0 allows splitview again. |
| 152 ScreenManager::Get()->SetRotation(gfx::Display::ROTATE_0); | 178 ScreenManager::Get()->SetRotation(gfx::Display::ROTATE_0); |
| 153 EXPECT_TRUE(IsSplitViewAllowed()); | 179 EXPECT_TRUE(IsSplitViewAllowed()); |
| 154 } | 180 } |
| 155 | 181 |
| 156 } // namespace athena | 182 } // namespace athena |
| OLD | NEW |