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