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