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/public/window_manager.h" | 5 #include "athena/wm/public/window_manager.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 | 9 #include "athena/wm/public/window_list_provider.h" |
9 typedef athena::test::AthenaTestBase WindowManagerTest; | 10 #include "athena/wm/split_view_controller.h" |
| 11 #include "athena/wm/window_manager_impl.h" |
| 12 #include "ui/aura/client/window_tree_client.h" |
| 13 #include "ui/aura/test/test_window_delegate.h" |
| 14 #include "ui/aura/window.h" |
| 15 #include "ui/base/hit_test.h" |
| 16 #include "ui/events/test/event_generator.h" |
| 17 #include "ui/gfx/display.h" |
| 18 #include "ui/gfx/screen.h" |
| 19 #include "ui/wm/core/window_util.h" |
| 20 |
| 21 namespace { |
| 22 |
| 23 scoped_ptr<aura::Window> CreateWindow(aura::WindowDelegate* delegate) { |
| 24 scoped_ptr<aura::Window> window(new aura::Window(delegate)); |
| 25 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
| 26 window->Init(aura::WINDOW_LAYER_SOLID_COLOR); |
| 27 window->Show(); |
| 28 return window.Pass(); |
| 29 } |
| 30 |
| 31 } // namespace |
| 32 |
| 33 namespace athena { |
| 34 |
| 35 class WindowManagerImplTestApi { |
| 36 public: |
| 37 WindowManagerImplTestApi() |
| 38 : wm_(static_cast<WindowManagerImpl*>(WindowManager::GetInstance())) {} |
| 39 ~WindowManagerImplTestApi() {} |
| 40 |
| 41 WindowManager* wm() { return wm_; } |
| 42 |
| 43 WindowListProvider* window_list_provider() { |
| 44 return wm_->window_list_provider_.get(); |
| 45 } |
| 46 |
| 47 SplitViewController* split_view_controller() { |
| 48 return wm_->split_view_controller_.get(); |
| 49 } |
| 50 |
| 51 private: |
| 52 WindowManagerImpl* wm_; |
| 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(WindowManagerImplTestApi); |
| 55 }; |
| 56 |
| 57 typedef test::AthenaTestBase WindowManagerTest; |
10 | 58 |
11 TEST_F(WindowManagerTest, Empty) { | 59 TEST_F(WindowManagerTest, Empty) { |
12 } | 60 } |
| 61 |
| 62 TEST_F(WindowManagerTest, OverviewModeBasics) { |
| 63 aura::test::TestWindowDelegate delegate; |
| 64 scoped_ptr<aura::Window> first(CreateWindow(&delegate)); |
| 65 scoped_ptr<aura::Window> second(CreateWindow(&delegate)); |
| 66 |
| 67 WindowManagerImplTestApi wm_api; |
| 68 aura::client::ParentWindowWithContext( |
| 69 first.get(), ScreenManager::Get()->GetContext(), gfx::Rect()); |
| 70 aura::client::ParentWindowWithContext( |
| 71 second.get(), ScreenManager::Get()->GetContext(), gfx::Rect()); |
| 72 |
| 73 ASSERT_FALSE(wm_api.wm()->IsOverviewModeActive()); |
| 74 EXPECT_EQ(first->bounds().ToString(), second->bounds().ToString()); |
| 75 EXPECT_EQ(gfx::Screen::GetNativeScreen() |
| 76 ->GetPrimaryDisplay() |
| 77 .work_area() |
| 78 .size() |
| 79 .ToString(), |
| 80 first->bounds().size().ToString()); |
| 81 EXPECT_FALSE(wm_api.wm()->IsOverviewModeActive()); |
| 82 |
| 83 // Tests that going into overview mode does not change the window bounds. |
| 84 wm_api.wm()->ToggleOverview(); |
| 85 ASSERT_TRUE(wm_api.wm()->IsOverviewModeActive()); |
| 86 EXPECT_EQ(first->bounds().ToString(), second->bounds().ToString()); |
| 87 EXPECT_EQ(gfx::Screen::GetNativeScreen() |
| 88 ->GetPrimaryDisplay() |
| 89 .work_area() |
| 90 .size() |
| 91 .ToString(), |
| 92 first->bounds().size().ToString()); |
| 93 } |
| 94 |
| 95 TEST_F(WindowManagerTest, BezelGestureToSplitViewMode) { |
| 96 aura::test::TestWindowDelegate delegate; |
| 97 scoped_ptr<aura::Window> first(CreateWindow(&delegate)); |
| 98 scoped_ptr<aura::Window> second(CreateWindow(&delegate)); |
| 99 scoped_ptr<aura::Window> third(CreateWindow(&delegate)); |
| 100 |
| 101 WindowManagerImplTestApi wm_api; |
| 102 aura::client::ParentWindowWithContext( |
| 103 first.get(), ScreenManager::Get()->GetContext(), gfx::Rect()); |
| 104 aura::client::ParentWindowWithContext( |
| 105 second.get(), ScreenManager::Get()->GetContext(), gfx::Rect()); |
| 106 aura::client::ParentWindowWithContext( |
| 107 third.get(), ScreenManager::Get()->GetContext(), gfx::Rect()); |
| 108 |
| 109 // Test that going into split-view mode with two-finger gesture selects the |
| 110 // correct windows on left and right splits. |
| 111 ui::test::EventGenerator generator(root_window()); |
| 112 const gfx::Point start_points[2] = { |
| 113 gfx::Point(2, 10), gfx::Point(4, 20), |
| 114 }; |
| 115 const int kEventTimeSepration = 16; |
| 116 int x_middle = root_window()->bounds().width() / 2; |
| 117 generator.GestureMultiFingerScroll( |
| 118 2, start_points, kEventTimeSepration, 1, x_middle, 0); |
| 119 ASSERT_TRUE(wm_api.split_view_controller()->IsSplitViewModeActive()); |
| 120 EXPECT_EQ(second.get(), wm_api.split_view_controller()->left_window()); |
| 121 EXPECT_EQ(third.get(), wm_api.split_view_controller()->right_window()); |
| 122 EXPECT_EQ(second->bounds().size().ToString(), |
| 123 third->bounds().size().ToString()); |
| 124 } |
| 125 |
| 126 TEST_F(WindowManagerTest, BezelGestureToSwitchBetweenWindows) { |
| 127 aura::test::TestWindowDelegate delegate; |
| 128 scoped_ptr<aura::Window> first(CreateWindow(&delegate)); |
| 129 scoped_ptr<aura::Window> second(CreateWindow(&delegate)); |
| 130 scoped_ptr<aura::Window> third(CreateWindow(&delegate)); |
| 131 |
| 132 WindowManagerImplTestApi wm_api; |
| 133 aura::client::ParentWindowWithContext( |
| 134 first.get(), ScreenManager::Get()->GetContext(), gfx::Rect()); |
| 135 aura::client::ParentWindowWithContext( |
| 136 second.get(), ScreenManager::Get()->GetContext(), gfx::Rect()); |
| 137 aura::client::ParentWindowWithContext( |
| 138 third.get(), ScreenManager::Get()->GetContext(), gfx::Rect()); |
| 139 |
| 140 EXPECT_EQ(third.get(), wm_api.window_list_provider()->GetWindowList().back()); |
| 141 |
| 142 // Do a two-finger swipe from the left bezel. |
| 143 ui::test::EventGenerator generator(root_window()); |
| 144 const gfx::Point left_bezel_points[2] = { |
| 145 gfx::Point(2, 10), gfx::Point(4, 20), |
| 146 }; |
| 147 const int kEventTimeSepration = 16; |
| 148 int width = root_window()->bounds().width(); |
| 149 generator.GestureMultiFingerScroll( |
| 150 2, left_bezel_points, kEventTimeSepration, 1, width, 0); |
| 151 EXPECT_TRUE(wm::IsActiveWindow(second.get())); |
| 152 EXPECT_EQ(second.get(), |
| 153 wm_api.window_list_provider()->GetWindowList().back()); |
| 154 } |
| 155 |
| 156 TEST_F(WindowManagerTest, TitleDragSwitchBetweenWindows) { |
| 157 aura::test::TestWindowDelegate delegate; |
| 158 delegate.set_window_component(HTCAPTION); |
| 159 scoped_ptr<aura::Window> first(CreateWindow(&delegate)); |
| 160 scoped_ptr<aura::Window> second(CreateWindow(&delegate)); |
| 161 scoped_ptr<aura::Window> third(CreateWindow(&delegate)); |
| 162 |
| 163 WindowManagerImplTestApi wm_api; |
| 164 aura::client::ParentWindowWithContext( |
| 165 first.get(), ScreenManager::Get()->GetContext(), gfx::Rect()); |
| 166 aura::client::ParentWindowWithContext( |
| 167 second.get(), ScreenManager::Get()->GetContext(), gfx::Rect()); |
| 168 aura::client::ParentWindowWithContext( |
| 169 third.get(), ScreenManager::Get()->GetContext(), gfx::Rect()); |
| 170 |
| 171 EXPECT_EQ(third.get(), wm_api.window_list_provider()->GetWindowList().back()); |
| 172 |
| 173 // Do a title-swipe from the top to switch to the previous window. |
| 174 ui::test::EventGenerator generator(root_window()); |
| 175 generator.GestureScrollSequence(gfx::Point(20, 10), |
| 176 gfx::Point(20, 400), |
| 177 base::TimeDelta::FromMilliseconds(20), |
| 178 5); |
| 179 EXPECT_TRUE(wm::IsActiveWindow(second.get())); |
| 180 EXPECT_EQ(second.get(), |
| 181 wm_api.window_list_provider()->GetWindowList().back()); |
| 182 |
| 183 // Performing the same gesture again will switch back to |third|. |
| 184 generator.GestureScrollSequence(gfx::Point(20, 10), |
| 185 gfx::Point(20, 400), |
| 186 base::TimeDelta::FromMilliseconds(20), |
| 187 5); |
| 188 EXPECT_TRUE(wm::IsActiveWindow(third.get())); |
| 189 EXPECT_EQ(third.get(), wm_api.window_list_provider()->GetWindowList().back()); |
| 190 } |
| 191 |
| 192 TEST_F(WindowManagerTest, TitleDragSwitchBetweenWindowsInSplitViewMode) { |
| 193 aura::test::TestWindowDelegate delegate; |
| 194 delegate.set_window_component(HTCAPTION); |
| 195 scoped_ptr<aura::Window> first(CreateWindow(&delegate)); |
| 196 scoped_ptr<aura::Window> second(CreateWindow(&delegate)); |
| 197 scoped_ptr<aura::Window> third(CreateWindow(&delegate)); |
| 198 scoped_ptr<aura::Window> fourth(CreateWindow(&delegate)); |
| 199 |
| 200 WindowManagerImplTestApi wm_api; |
| 201 aura::client::ParentWindowWithContext( |
| 202 first.get(), ScreenManager::Get()->GetContext(), gfx::Rect()); |
| 203 aura::client::ParentWindowWithContext( |
| 204 second.get(), ScreenManager::Get()->GetContext(), gfx::Rect()); |
| 205 aura::client::ParentWindowWithContext( |
| 206 third.get(), ScreenManager::Get()->GetContext(), gfx::Rect()); |
| 207 aura::client::ParentWindowWithContext( |
| 208 fourth.get(), ScreenManager::Get()->GetContext(), gfx::Rect()); |
| 209 |
| 210 // Test that going into split-view mode with two-finger gesture selects the |
| 211 // correct windows on left and right splits. |
| 212 ui::test::EventGenerator generator(root_window()); |
| 213 const gfx::Point start_points[2] = { |
| 214 gfx::Point(2, 10), gfx::Point(4, 20), |
| 215 }; |
| 216 const int kEventTimeSepration = 16; |
| 217 int x_middle = root_window()->bounds().width() / 2; |
| 218 generator.GestureMultiFingerScroll( |
| 219 2, start_points, kEventTimeSepration, 1, x_middle, 0); |
| 220 ASSERT_TRUE(wm_api.split_view_controller()->IsSplitViewModeActive()); |
| 221 EXPECT_EQ(third.get(), wm_api.split_view_controller()->left_window()); |
| 222 EXPECT_EQ(fourth.get(), wm_api.split_view_controller()->right_window()); |
| 223 |
| 224 // Swipe the title of the left window. It should switch to |second|. |
| 225 generator.GestureScrollSequence(gfx::Point(20, 10), |
| 226 gfx::Point(20, 400), |
| 227 base::TimeDelta::FromMilliseconds(20), |
| 228 5); |
| 229 EXPECT_EQ(second.get(), wm_api.split_view_controller()->left_window()); |
| 230 EXPECT_EQ(fourth.get(), wm_api.split_view_controller()->right_window()); |
| 231 aura::Window::Windows windows = |
| 232 wm_api.window_list_provider()->GetWindowList(); |
| 233 ASSERT_EQ(4u, windows.size()); |
| 234 EXPECT_EQ(second.get(), windows[3]); |
| 235 EXPECT_EQ(third.get(), windows[2]); |
| 236 EXPECT_EQ(fourth.get(), windows[1]); |
| 237 |
| 238 // Swipe the title of the right window now. It should switch to |third|. |
| 239 generator.GestureScrollSequence(gfx::Point(x_middle + 20, 10), |
| 240 gfx::Point(x_middle + 20, 400), |
| 241 base::TimeDelta::FromMilliseconds(20), |
| 242 5); |
| 243 EXPECT_EQ(second.get(), wm_api.split_view_controller()->left_window()); |
| 244 EXPECT_EQ(third.get(), wm_api.split_view_controller()->right_window()); |
| 245 } |
| 246 |
| 247 } // namespace athena |
OLD | NEW |