OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/wm/tablet_mode/tablet_mode_window_manager.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "ash/ash_switches.h" | |
10 #include "ash/public/cpp/config.h" | |
11 #include "ash/root_window_controller.h" | |
12 #include "ash/screen_util.h" | |
13 #include "ash/shelf/shelf.h" | |
14 #include "ash/shell.h" | |
15 #include "ash/shell_port.h" | |
16 #include "ash/test/ash_test_base.h" | |
17 #include "ash/test/shell_test_api.h" | |
18 #include "ash/wm/mru_window_tracker.h" | |
19 #include "ash/wm/overview/window_selector_controller.h" | |
20 #include "ash/wm/switchable_windows.h" | |
21 #include "ash/wm/tablet_mode/tablet_mode_controller.h" | |
22 #include "ash/wm/window_properties.h" | |
23 #include "ash/wm/window_state.h" | |
24 #include "ash/wm/window_state_observer.h" | |
25 #include "ash/wm/window_util.h" | |
26 #include "ash/wm/wm_event.h" | |
27 #include "ash/wm_window.h" | |
28 #include "base/command_line.h" | |
29 #include "base/strings/stringprintf.h" | |
30 #include "base/strings/utf_string_conversions.h" | |
31 #include "base/values.h" | |
32 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" | |
33 #include "ui/aura/client/aura_constants.h" | |
34 #include "ui/aura/test/test_window_delegate.h" | |
35 #include "ui/aura/test/test_windows.h" | |
36 #include "ui/aura/window.h" | |
37 #include "ui/base/hit_test.h" | |
38 #include "ui/events/test/event_generator.h" | |
39 #include "ui/views/widget/widget.h" | |
40 | |
41 namespace ash { | |
42 | |
43 class TabletModeWindowManagerTest : public test::AshTestBase { | |
44 public: | |
45 TabletModeWindowManagerTest() {} | |
46 ~TabletModeWindowManagerTest() override {} | |
47 | |
48 // Creates a window which has a fixed size. | |
49 aura::Window* CreateFixedSizeNonMaximizableWindow( | |
50 aura::client::WindowType type, | |
51 const gfx::Rect& bounds) { | |
52 return CreateWindowInWatchedContainer(type, bounds, gfx::Size(), false, | |
53 false); | |
54 } | |
55 | |
56 // Creates a window which can not be maximized, but resized. |max_size| | |
57 // denotes the maximal possible size, if the size is empty, the window has no | |
58 // upper limit. Note: This function will only work with a single root window. | |
59 aura::Window* CreateNonMaximizableWindow(aura::client::WindowType type, | |
60 const gfx::Rect& bounds, | |
61 const gfx::Size& max_size) { | |
62 return CreateWindowInWatchedContainer(type, bounds, max_size, false, true); | |
63 } | |
64 | |
65 // Creates a maximizable and resizable window. | |
66 aura::Window* CreateWindow(aura::client::WindowType type, | |
67 const gfx::Rect bounds) { | |
68 return CreateWindowInWatchedContainer(type, bounds, gfx::Size(), true, | |
69 true); | |
70 } | |
71 | |
72 // Creates a window which also has a widget. | |
73 aura::Window* CreateWindowWithWidget(const gfx::Rect& bounds) { | |
74 views::Widget* widget = new views::Widget(); | |
75 views::Widget::InitParams params; | |
76 params.context = CurrentContext(); | |
77 // Note: The widget will get deleted with the window. | |
78 widget->Init(params); | |
79 widget->Show(); | |
80 aura::Window* window = widget->GetNativeWindow(); | |
81 window->SetBounds(bounds); | |
82 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | |
83 | |
84 return window; | |
85 } | |
86 | |
87 // Create the Maximized mode window manager. | |
88 TabletModeWindowManager* CreateTabletModeWindowManager() { | |
89 EXPECT_FALSE(tablet_mode_window_manager()); | |
90 Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true); | |
91 return tablet_mode_window_manager(); | |
92 } | |
93 | |
94 // Destroy the tablet mode window manager. | |
95 void DestroyTabletModeWindowManager() { | |
96 Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager( | |
97 false); | |
98 EXPECT_FALSE(tablet_mode_window_manager()); | |
99 } | |
100 | |
101 // Get the maximze window manager. | |
102 TabletModeWindowManager* tablet_mode_window_manager() { | |
103 return Shell::Get() | |
104 ->tablet_mode_controller() | |
105 ->tablet_mode_window_manager_.get(); | |
106 } | |
107 | |
108 // Resize our desktop. | |
109 void ResizeDesktop(int width_delta) { | |
110 gfx::Size size = | |
111 display::Screen::GetScreen() | |
112 ->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()) | |
113 .size(); | |
114 size.Enlarge(0, width_delta); | |
115 UpdateDisplay(size.ToString()); | |
116 } | |
117 | |
118 private: | |
119 // Create a window in one of the containers which are watched by the | |
120 // TabletModeWindowManager. Note that this only works with one root window. | |
121 // If |can_maximize| is not set, |max_size| is the upper limiting size for | |
122 // the window, whereas an empty size means that there is no limit. | |
123 aura::Window* CreateWindowInWatchedContainer(aura::client::WindowType type, | |
124 const gfx::Rect& bounds, | |
125 const gfx::Size& max_size, | |
126 bool can_maximize, | |
127 bool can_resize) { | |
128 aura::test::TestWindowDelegate* delegate = NULL; | |
129 if (!can_maximize) { | |
130 delegate = aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(); | |
131 delegate->set_window_component(HTCAPTION); | |
132 if (!max_size.IsEmpty()) | |
133 delegate->set_maximum_size(max_size); | |
134 } | |
135 aura::Window* window = aura::test::CreateTestWindowWithDelegateAndType( | |
136 delegate, type, 0, bounds, NULL); | |
137 int32_t behavior = ui::mojom::kResizeBehaviorNone; | |
138 behavior |= can_resize ? ui::mojom::kResizeBehaviorCanResize : 0; | |
139 behavior |= can_maximize ? ui::mojom::kResizeBehaviorCanMaximize : 0; | |
140 window->SetProperty(aura::client::kResizeBehaviorKey, behavior); | |
141 aura::Window* container = Shell::GetContainer( | |
142 Shell::GetPrimaryRootWindow(), wm::kSwitchableWindowContainerIds[0]); | |
143 container->AddChild(window); | |
144 return window; | |
145 } | |
146 | |
147 DISALLOW_COPY_AND_ASSIGN(TabletModeWindowManagerTest); | |
148 }; | |
149 | |
150 // Test that creating the object and destroying it without any windows should | |
151 // not cause any problems. | |
152 TEST_F(TabletModeWindowManagerTest, SimpleStart) { | |
153 TabletModeWindowManager* manager = CreateTabletModeWindowManager(); | |
154 ASSERT_TRUE(manager); | |
155 EXPECT_EQ(0, manager->GetNumberOfManagedWindows()); | |
156 DestroyTabletModeWindowManager(); | |
157 } | |
158 | |
159 // Test that existing windows will handled properly when going into maximized | |
160 // mode. | |
161 TEST_F(TabletModeWindowManagerTest, PreCreateWindows) { | |
162 // Bounds for windows we know can be controlled. | |
163 gfx::Rect rect1(10, 10, 200, 50); | |
164 gfx::Rect rect2(10, 60, 200, 50); | |
165 gfx::Rect rect3(20, 140, 100, 100); | |
166 // Bounds for anything else. | |
167 gfx::Rect rect(80, 90, 100, 110); | |
168 std::unique_ptr<aura::Window> w1( | |
169 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect1)); | |
170 std::unique_ptr<aura::Window> w2( | |
171 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect2)); | |
172 std::unique_ptr<aura::Window> w3(CreateFixedSizeNonMaximizableWindow( | |
173 aura::client::WINDOW_TYPE_NORMAL, rect3)); | |
174 std::unique_ptr<aura::Window> w4( | |
175 CreateWindow(aura::client::WINDOW_TYPE_PANEL, rect)); | |
176 std::unique_ptr<aura::Window> w5( | |
177 CreateWindow(aura::client::WINDOW_TYPE_POPUP, rect)); | |
178 std::unique_ptr<aura::Window> w6( | |
179 CreateWindow(aura::client::WINDOW_TYPE_CONTROL, rect)); | |
180 std::unique_ptr<aura::Window> w7( | |
181 CreateWindow(aura::client::WINDOW_TYPE_MENU, rect)); | |
182 std::unique_ptr<aura::Window> w8( | |
183 CreateWindow(aura::client::WINDOW_TYPE_TOOLTIP, rect)); | |
184 EXPECT_FALSE(wm::GetWindowState(w1.get())->IsMaximized()); | |
185 EXPECT_FALSE(wm::GetWindowState(w2.get())->IsMaximized()); | |
186 EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMaximized()); | |
187 EXPECT_EQ(rect1.ToString(), w1->bounds().ToString()); | |
188 EXPECT_EQ(rect2.ToString(), w2->bounds().ToString()); | |
189 EXPECT_EQ(rect3.ToString(), w3->bounds().ToString()); | |
190 | |
191 // Create the manager and make sure that all qualifying windows were detected | |
192 // and changed. | |
193 TabletModeWindowManager* manager = CreateTabletModeWindowManager(); | |
194 ASSERT_TRUE(manager); | |
195 EXPECT_EQ(3, manager->GetNumberOfManagedWindows()); | |
196 EXPECT_TRUE(wm::GetWindowState(w1.get())->IsMaximized()); | |
197 EXPECT_TRUE(wm::GetWindowState(w2.get())->IsMaximized()); | |
198 EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMaximized()); | |
199 EXPECT_NE(rect3.origin().ToString(), w3->bounds().origin().ToString()); | |
200 EXPECT_EQ(rect3.size().ToString(), w3->bounds().size().ToString()); | |
201 | |
202 // All other windows should not have been touched. | |
203 EXPECT_FALSE(wm::GetWindowState(w4.get())->IsMaximized()); | |
204 EXPECT_FALSE(wm::GetWindowState(w5.get())->IsMaximized()); | |
205 EXPECT_FALSE(wm::GetWindowState(w6.get())->IsMaximized()); | |
206 EXPECT_FALSE(wm::GetWindowState(w7.get())->IsMaximized()); | |
207 EXPECT_FALSE(wm::GetWindowState(w8.get())->IsMaximized()); | |
208 EXPECT_EQ(rect.ToString(), w4->bounds().ToString()); | |
209 EXPECT_EQ(rect.ToString(), w5->bounds().ToString()); | |
210 EXPECT_EQ(rect.ToString(), w6->bounds().ToString()); | |
211 EXPECT_EQ(rect.ToString(), w7->bounds().ToString()); | |
212 EXPECT_EQ(rect.ToString(), w8->bounds().ToString()); | |
213 | |
214 // Destroy the manager again and check that the windows return to their | |
215 // previous state. | |
216 DestroyTabletModeWindowManager(); | |
217 EXPECT_FALSE(wm::GetWindowState(w1.get())->IsMaximized()); | |
218 EXPECT_FALSE(wm::GetWindowState(w2.get())->IsMaximized()); | |
219 EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMaximized()); | |
220 EXPECT_EQ(rect1.ToString(), w1->bounds().ToString()); | |
221 EXPECT_EQ(rect2.ToString(), w2->bounds().ToString()); | |
222 EXPECT_EQ(rect3.ToString(), w3->bounds().ToString()); | |
223 EXPECT_EQ(rect.ToString(), w4->bounds().ToString()); | |
224 EXPECT_EQ(rect.ToString(), w5->bounds().ToString()); | |
225 EXPECT_EQ(rect.ToString(), w6->bounds().ToString()); | |
226 EXPECT_EQ(rect.ToString(), w7->bounds().ToString()); | |
227 EXPECT_EQ(rect.ToString(), w8->bounds().ToString()); | |
228 } | |
229 | |
230 // The same test as the above but while a system modal dialog is shown. | |
231 TEST_F(TabletModeWindowManagerTest, GoingToMaximizedWithModalDialogPresent) { | |
232 // Bounds for windows we know can be controlled. | |
233 gfx::Rect rect1(10, 10, 200, 50); | |
234 gfx::Rect rect2(10, 60, 200, 50); | |
235 gfx::Rect rect3(20, 140, 100, 100); | |
236 // Bounds for anything else. | |
237 gfx::Rect rect(80, 90, 100, 110); | |
238 std::unique_ptr<aura::Window> w1( | |
239 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect1)); | |
240 std::unique_ptr<aura::Window> w2( | |
241 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect2)); | |
242 std::unique_ptr<aura::Window> w3(CreateFixedSizeNonMaximizableWindow( | |
243 aura::client::WINDOW_TYPE_NORMAL, rect3)); | |
244 std::unique_ptr<aura::Window> w4( | |
245 CreateWindow(aura::client::WINDOW_TYPE_PANEL, rect)); | |
246 std::unique_ptr<aura::Window> w5( | |
247 CreateWindow(aura::client::WINDOW_TYPE_POPUP, rect)); | |
248 std::unique_ptr<aura::Window> w6( | |
249 CreateWindow(aura::client::WINDOW_TYPE_CONTROL, rect)); | |
250 std::unique_ptr<aura::Window> w7( | |
251 CreateWindow(aura::client::WINDOW_TYPE_MENU, rect)); | |
252 std::unique_ptr<aura::Window> w8( | |
253 CreateWindow(aura::client::WINDOW_TYPE_TOOLTIP, rect)); | |
254 EXPECT_FALSE(wm::GetWindowState(w1.get())->IsMaximized()); | |
255 EXPECT_FALSE(wm::GetWindowState(w2.get())->IsMaximized()); | |
256 EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMaximized()); | |
257 EXPECT_EQ(rect1.ToString(), w1->bounds().ToString()); | |
258 EXPECT_EQ(rect2.ToString(), w2->bounds().ToString()); | |
259 EXPECT_EQ(rect3.ToString(), w3->bounds().ToString()); | |
260 | |
261 // Enable system modal dialog, and make sure both shelves are still hidden. | |
262 ShellPort::Get()->SimulateModalWindowOpenForTesting(true); | |
263 EXPECT_TRUE(ShellPort::Get()->IsSystemModalWindowOpen()); | |
264 | |
265 // Create the manager and make sure that all qualifying windows were detected | |
266 // and changed. | |
267 TabletModeWindowManager* manager = CreateTabletModeWindowManager(); | |
268 ASSERT_TRUE(manager); | |
269 EXPECT_EQ(3, manager->GetNumberOfManagedWindows()); | |
270 EXPECT_TRUE(wm::GetWindowState(w1.get())->IsMaximized()); | |
271 EXPECT_TRUE(wm::GetWindowState(w2.get())->IsMaximized()); | |
272 EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMaximized()); | |
273 EXPECT_NE(rect3.origin().ToString(), w3->bounds().origin().ToString()); | |
274 EXPECT_EQ(rect3.size().ToString(), w3->bounds().size().ToString()); | |
275 | |
276 // All other windows should not have been touched. | |
277 EXPECT_FALSE(wm::GetWindowState(w4.get())->IsMaximized()); | |
278 EXPECT_FALSE(wm::GetWindowState(w5.get())->IsMaximized()); | |
279 EXPECT_FALSE(wm::GetWindowState(w6.get())->IsMaximized()); | |
280 EXPECT_FALSE(wm::GetWindowState(w7.get())->IsMaximized()); | |
281 EXPECT_FALSE(wm::GetWindowState(w8.get())->IsMaximized()); | |
282 EXPECT_EQ(rect.ToString(), w4->bounds().ToString()); | |
283 EXPECT_EQ(rect.ToString(), w5->bounds().ToString()); | |
284 EXPECT_EQ(rect.ToString(), w6->bounds().ToString()); | |
285 EXPECT_EQ(rect.ToString(), w7->bounds().ToString()); | |
286 EXPECT_EQ(rect.ToString(), w8->bounds().ToString()); | |
287 | |
288 // Destroy the manager again and check that the windows return to their | |
289 // previous state. | |
290 DestroyTabletModeWindowManager(); | |
291 EXPECT_FALSE(wm::GetWindowState(w1.get())->IsMaximized()); | |
292 EXPECT_FALSE(wm::GetWindowState(w2.get())->IsMaximized()); | |
293 EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMaximized()); | |
294 EXPECT_EQ(rect1.ToString(), w1->bounds().ToString()); | |
295 EXPECT_EQ(rect2.ToString(), w2->bounds().ToString()); | |
296 EXPECT_EQ(rect3.ToString(), w3->bounds().ToString()); | |
297 EXPECT_EQ(rect.ToString(), w4->bounds().ToString()); | |
298 EXPECT_EQ(rect.ToString(), w5->bounds().ToString()); | |
299 EXPECT_EQ(rect.ToString(), w6->bounds().ToString()); | |
300 EXPECT_EQ(rect.ToString(), w7->bounds().ToString()); | |
301 EXPECT_EQ(rect.ToString(), w8->bounds().ToString()); | |
302 } | |
303 | |
304 // Test that non-maximizable windows get properly handled when going into | |
305 // tablet mode. | |
306 TEST_F(TabletModeWindowManagerTest, | |
307 PreCreateNonMaximizableButResizableWindows) { | |
308 // The window bounds. | |
309 gfx::Rect rect(10, 10, 200, 50); | |
310 gfx::Size max_size(300, 200); | |
311 gfx::Size empty_size; | |
312 std::unique_ptr<aura::Window> unlimited_window(CreateNonMaximizableWindow( | |
313 aura::client::WINDOW_TYPE_NORMAL, rect, empty_size)); | |
314 std::unique_ptr<aura::Window> limited_window(CreateNonMaximizableWindow( | |
315 aura::client::WINDOW_TYPE_NORMAL, rect, max_size)); | |
316 std::unique_ptr<aura::Window> fixed_window( | |
317 CreateFixedSizeNonMaximizableWindow(aura::client::WINDOW_TYPE_NORMAL, | |
318 rect)); | |
319 EXPECT_FALSE(wm::GetWindowState(unlimited_window.get())->IsMaximized()); | |
320 EXPECT_EQ(rect.ToString(), unlimited_window->bounds().ToString()); | |
321 EXPECT_FALSE(wm::GetWindowState(limited_window.get())->IsMaximized()); | |
322 EXPECT_EQ(rect.ToString(), limited_window->bounds().ToString()); | |
323 EXPECT_FALSE(wm::GetWindowState(fixed_window.get())->IsMaximized()); | |
324 EXPECT_EQ(rect.ToString(), fixed_window->bounds().ToString()); | |
325 | |
326 gfx::Size workspace_size = | |
327 ScreenUtil::GetMaximizedWindowBoundsInParent(unlimited_window.get()) | |
328 .size(); | |
329 | |
330 // Create the manager and make sure that all qualifying windows were detected | |
331 // and changed. | |
332 TabletModeWindowManager* manager = CreateTabletModeWindowManager(); | |
333 ASSERT_TRUE(manager); | |
334 EXPECT_EQ(3, manager->GetNumberOfManagedWindows()); | |
335 // The unlimited window should have the size of the workspace / parent window. | |
336 EXPECT_FALSE(wm::GetWindowState(unlimited_window.get())->IsMaximized()); | |
337 EXPECT_EQ("0,0", unlimited_window->bounds().origin().ToString()); | |
338 EXPECT_EQ(workspace_size.ToString(), | |
339 unlimited_window->bounds().size().ToString()); | |
340 // The limited window should have the size of the upper possible bounds. | |
341 EXPECT_FALSE(wm::GetWindowState(limited_window.get())->IsMaximized()); | |
342 EXPECT_NE(rect.origin().ToString(), | |
343 limited_window->bounds().origin().ToString()); | |
344 EXPECT_EQ(max_size.ToString(), limited_window->bounds().size().ToString()); | |
345 // The fixed size window should have the size of the original window. | |
346 EXPECT_FALSE(wm::GetWindowState(fixed_window.get())->IsMaximized()); | |
347 EXPECT_NE(rect.origin().ToString(), | |
348 fixed_window->bounds().origin().ToString()); | |
349 EXPECT_EQ(rect.size().ToString(), fixed_window->bounds().size().ToString()); | |
350 | |
351 // Destroy the manager again and check that the windows return to their | |
352 // previous state. | |
353 DestroyTabletModeWindowManager(); | |
354 EXPECT_FALSE(wm::GetWindowState(unlimited_window.get())->IsMaximized()); | |
355 EXPECT_EQ(rect.ToString(), unlimited_window->bounds().ToString()); | |
356 EXPECT_FALSE(wm::GetWindowState(limited_window.get())->IsMaximized()); | |
357 EXPECT_EQ(rect.ToString(), limited_window->bounds().ToString()); | |
358 EXPECT_FALSE(wm::GetWindowState(fixed_window.get())->IsMaximized()); | |
359 EXPECT_EQ(rect.ToString(), fixed_window->bounds().ToString()); | |
360 } | |
361 | |
362 // Test that creating windows while a maximizer exists picks them properly up. | |
363 TEST_F(TabletModeWindowManagerTest, CreateWindows) { | |
364 TabletModeWindowManager* manager = CreateTabletModeWindowManager(); | |
365 ASSERT_TRUE(manager); | |
366 EXPECT_EQ(0, manager->GetNumberOfManagedWindows()); | |
367 | |
368 // Create the windows and see that the window manager picks them up. | |
369 // Rects for windows we know can be controlled. | |
370 gfx::Rect rect1(10, 10, 200, 50); | |
371 gfx::Rect rect2(10, 60, 200, 50); | |
372 gfx::Rect rect3(20, 140, 100, 100); | |
373 // One rect for anything else. | |
374 gfx::Rect rect(80, 90, 100, 110); | |
375 std::unique_ptr<aura::Window> w1( | |
376 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect1)); | |
377 std::unique_ptr<aura::Window> w2( | |
378 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect2)); | |
379 std::unique_ptr<aura::Window> w3(CreateFixedSizeNonMaximizableWindow( | |
380 aura::client::WINDOW_TYPE_NORMAL, rect3)); | |
381 std::unique_ptr<aura::Window> w4( | |
382 CreateWindow(aura::client::WINDOW_TYPE_PANEL, rect)); | |
383 std::unique_ptr<aura::Window> w5( | |
384 CreateWindow(aura::client::WINDOW_TYPE_POPUP, rect)); | |
385 std::unique_ptr<aura::Window> w6( | |
386 CreateWindow(aura::client::WINDOW_TYPE_CONTROL, rect)); | |
387 std::unique_ptr<aura::Window> w7( | |
388 CreateWindow(aura::client::WINDOW_TYPE_MENU, rect)); | |
389 std::unique_ptr<aura::Window> w8( | |
390 CreateWindow(aura::client::WINDOW_TYPE_TOOLTIP, rect)); | |
391 EXPECT_TRUE(wm::GetWindowState(w1.get())->IsMaximized()); | |
392 EXPECT_TRUE(wm::GetWindowState(w2.get())->IsMaximized()); | |
393 EXPECT_EQ(3, manager->GetNumberOfManagedWindows()); | |
394 EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMaximized()); | |
395 | |
396 // Make sure that the position of the unresizable window is in the middle of | |
397 // the screen. | |
398 gfx::Size work_area_size = | |
399 ScreenUtil::GetDisplayWorkAreaBoundsInParent(w3.get()).size(); | |
400 gfx::Point center = | |
401 gfx::Point((work_area_size.width() - rect3.size().width()) / 2, | |
402 (work_area_size.height() - rect3.size().height()) / 2); | |
403 gfx::Rect centered_window_bounds = gfx::Rect(center, rect3.size()); | |
404 EXPECT_EQ(centered_window_bounds.ToString(), w3->bounds().ToString()); | |
405 | |
406 // All other windows should not have been touched. | |
407 EXPECT_FALSE(wm::GetWindowState(w4.get())->IsMaximized()); | |
408 EXPECT_FALSE(wm::GetWindowState(w5.get())->IsMaximized()); | |
409 EXPECT_FALSE(wm::GetWindowState(w6.get())->IsMaximized()); | |
410 EXPECT_FALSE(wm::GetWindowState(w7.get())->IsMaximized()); | |
411 EXPECT_FALSE(wm::GetWindowState(w8.get())->IsMaximized()); | |
412 EXPECT_EQ(rect.ToString(), w4->bounds().ToString()); | |
413 EXPECT_EQ(rect.ToString(), w5->bounds().ToString()); | |
414 EXPECT_EQ(rect.ToString(), w6->bounds().ToString()); | |
415 EXPECT_EQ(rect.ToString(), w7->bounds().ToString()); | |
416 EXPECT_EQ(rect.ToString(), w8->bounds().ToString()); | |
417 | |
418 // After the tablet mode was disabled all windows fall back into the mode | |
419 // they were created for. | |
420 DestroyTabletModeWindowManager(); | |
421 EXPECT_FALSE(wm::GetWindowState(w1.get())->IsMaximized()); | |
422 EXPECT_FALSE(wm::GetWindowState(w2.get())->IsMaximized()); | |
423 EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMaximized()); | |
424 EXPECT_EQ(rect1.ToString(), w1->bounds().ToString()); | |
425 EXPECT_EQ(rect2.ToString(), w2->bounds().ToString()); | |
426 EXPECT_EQ(rect3.ToString(), w3->bounds().ToString()); | |
427 EXPECT_EQ(rect.ToString(), w4->bounds().ToString()); | |
428 EXPECT_EQ(rect.ToString(), w5->bounds().ToString()); | |
429 EXPECT_EQ(rect.ToString(), w6->bounds().ToString()); | |
430 EXPECT_EQ(rect.ToString(), w7->bounds().ToString()); | |
431 EXPECT_EQ(rect.ToString(), w8->bounds().ToString()); | |
432 } | |
433 | |
434 // Test that a window which got created while the tablet mode window manager | |
435 // is active gets restored to a usable (non tiny) size upon switching back. | |
436 TEST_F(TabletModeWindowManagerTest, | |
437 CreateWindowInMaximizedModeRestoresToUsefulSize) { | |
438 TabletModeWindowManager* manager = CreateTabletModeWindowManager(); | |
439 ASSERT_TRUE(manager); | |
440 EXPECT_EQ(0, manager->GetNumberOfManagedWindows()); | |
441 | |
442 // We pass in an empty rectangle to simulate a window creation with no | |
443 // particular size. | |
444 gfx::Rect empty_rect(0, 0, 0, 0); | |
445 std::unique_ptr<aura::Window> window( | |
446 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, empty_rect)); | |
447 EXPECT_TRUE(wm::GetWindowState(window.get())->IsMaximized()); | |
448 EXPECT_NE(empty_rect.ToString(), window->bounds().ToString()); | |
449 gfx::Rect maximized_size = window->bounds(); | |
450 | |
451 // Destroy the tablet mode and check that the resulting size of the window | |
452 // is remaining as it is (but not maximized). | |
453 DestroyTabletModeWindowManager(); | |
454 | |
455 EXPECT_FALSE(wm::GetWindowState(window.get())->IsMaximized()); | |
456 EXPECT_EQ(maximized_size.ToString(), window->bounds().ToString()); | |
457 } | |
458 | |
459 // Test that non-maximizable windows get properly handled when created in | |
460 // tablet mode. | |
461 TEST_F(TabletModeWindowManagerTest, CreateNonMaximizableButResizableWindows) { | |
462 // Create the manager and make sure that all qualifying windows were detected | |
463 // and changed. | |
464 TabletModeWindowManager* manager = CreateTabletModeWindowManager(); | |
465 ASSERT_TRUE(manager); | |
466 | |
467 gfx::Rect rect(10, 10, 200, 50); | |
468 gfx::Size max_size(300, 200); | |
469 gfx::Size empty_size; | |
470 std::unique_ptr<aura::Window> unlimited_window(CreateNonMaximizableWindow( | |
471 aura::client::WINDOW_TYPE_NORMAL, rect, empty_size)); | |
472 std::unique_ptr<aura::Window> limited_window(CreateNonMaximizableWindow( | |
473 aura::client::WINDOW_TYPE_NORMAL, rect, max_size)); | |
474 std::unique_ptr<aura::Window> fixed_window( | |
475 CreateFixedSizeNonMaximizableWindow(aura::client::WINDOW_TYPE_NORMAL, | |
476 rect)); | |
477 | |
478 gfx::Size workspace_size = | |
479 ScreenUtil::GetMaximizedWindowBoundsInParent(unlimited_window.get()) | |
480 .size(); | |
481 | |
482 // All windows should be sized now as big as possible and be centered. | |
483 EXPECT_EQ(3, manager->GetNumberOfManagedWindows()); | |
484 // The unlimited window should have the size of the workspace / parent window. | |
485 EXPECT_FALSE(wm::GetWindowState(unlimited_window.get())->IsMaximized()); | |
486 EXPECT_EQ("0,0", unlimited_window->bounds().origin().ToString()); | |
487 EXPECT_EQ(workspace_size.ToString(), | |
488 unlimited_window->bounds().size().ToString()); | |
489 // The limited window should have the size of the upper possible bounds. | |
490 EXPECT_FALSE(wm::GetWindowState(limited_window.get())->IsMaximized()); | |
491 EXPECT_NE(rect.origin().ToString(), | |
492 limited_window->bounds().origin().ToString()); | |
493 EXPECT_EQ(max_size.ToString(), limited_window->bounds().size().ToString()); | |
494 // The fixed size window should have the size of the original window. | |
495 EXPECT_FALSE(wm::GetWindowState(fixed_window.get())->IsMaximized()); | |
496 EXPECT_NE(rect.origin().ToString(), | |
497 fixed_window->bounds().origin().ToString()); | |
498 EXPECT_EQ(rect.size().ToString(), fixed_window->bounds().size().ToString()); | |
499 | |
500 // Destroy the manager again and check that the windows return to their | |
501 // creation state. | |
502 DestroyTabletModeWindowManager(); | |
503 | |
504 EXPECT_FALSE(wm::GetWindowState(unlimited_window.get())->IsMaximized()); | |
505 EXPECT_EQ(rect.ToString(), unlimited_window->bounds().ToString()); | |
506 EXPECT_FALSE(wm::GetWindowState(limited_window.get())->IsMaximized()); | |
507 EXPECT_EQ(rect.ToString(), limited_window->bounds().ToString()); | |
508 EXPECT_FALSE(wm::GetWindowState(fixed_window.get())->IsMaximized()); | |
509 EXPECT_EQ(rect.ToString(), fixed_window->bounds().ToString()); | |
510 } | |
511 | |
512 // Create a string which consists of the bounds and the state for comparison. | |
513 std::string GetPlacementString(const gfx::Rect& bounds, | |
514 ui::WindowShowState state) { | |
515 return bounds.ToString() + base::StringPrintf(" %d", state); | |
516 } | |
517 | |
518 // Retrieves the window's restore state override - if any - and returns it as a | |
519 // string. | |
520 std::string GetPlacementOverride(aura::Window* window) { | |
521 gfx::Rect* bounds = window->GetProperty(kRestoreBoundsOverrideKey); | |
522 if (bounds) { | |
523 gfx::Rect restore_bounds = *bounds; | |
524 ui::WindowShowState restore_state = | |
525 window->GetProperty(kRestoreShowStateOverrideKey); | |
526 return GetPlacementString(restore_bounds, restore_state); | |
527 } | |
528 return std::string(); | |
529 } | |
530 | |
531 // Test that the restore state will be kept at its original value for | |
532 // session restauration purposes. | |
533 TEST_F(TabletModeWindowManagerTest, TestRestoreIntegrety) { | |
534 gfx::Rect bounds(10, 10, 200, 50); | |
535 gfx::Size empty_size; | |
536 gfx::Rect empty_bounds; | |
537 std::unique_ptr<aura::Window> normal_window(CreateWindowWithWidget(bounds)); | |
538 std::unique_ptr<aura::Window> maximized_window( | |
539 CreateWindowWithWidget(bounds)); | |
540 wm::GetWindowState(maximized_window.get())->Maximize(); | |
541 | |
542 EXPECT_EQ(std::string(), GetPlacementOverride(normal_window.get())); | |
543 EXPECT_EQ(std::string(), GetPlacementOverride(maximized_window.get())); | |
544 | |
545 TabletModeWindowManager* manager = CreateTabletModeWindowManager(); | |
546 ASSERT_TRUE(manager); | |
547 | |
548 // With the maximization the override states should be returned in its | |
549 // pre-maximized state. | |
550 EXPECT_EQ(GetPlacementString(bounds, ui::SHOW_STATE_NORMAL), | |
551 GetPlacementOverride(normal_window.get())); | |
552 EXPECT_EQ(GetPlacementString(bounds, ui::SHOW_STATE_MAXIMIZED), | |
553 GetPlacementOverride(maximized_window.get())); | |
554 | |
555 // Changing a window's state now does not change the returned result. | |
556 wm::GetWindowState(maximized_window.get())->Minimize(); | |
557 EXPECT_EQ(GetPlacementString(bounds, ui::SHOW_STATE_MAXIMIZED), | |
558 GetPlacementOverride(maximized_window.get())); | |
559 | |
560 // Destroy the manager again and check that the overrides get reset. | |
561 DestroyTabletModeWindowManager(); | |
562 EXPECT_EQ(std::string(), GetPlacementOverride(normal_window.get())); | |
563 EXPECT_EQ(std::string(), GetPlacementOverride(maximized_window.get())); | |
564 | |
565 // Changing a window's state now does not bring the overrides back. | |
566 wm::GetWindowState(maximized_window.get())->Restore(); | |
567 gfx::Rect new_bounds(10, 10, 200, 50); | |
568 maximized_window->SetBounds(new_bounds); | |
569 | |
570 EXPECT_EQ(std::string(), GetPlacementOverride(maximized_window.get())); | |
571 } | |
572 | |
573 // Test that windows which got created before the maximizer was created can be | |
574 // destroyed while the maximizer is still running. | |
575 TEST_F(TabletModeWindowManagerTest, PreCreateWindowsDeleteWhileActive) { | |
576 TabletModeWindowManager* manager = NULL; | |
577 { | |
578 // Bounds for windows we know can be controlled. | |
579 gfx::Rect rect1(10, 10, 200, 50); | |
580 gfx::Rect rect2(10, 60, 200, 50); | |
581 gfx::Rect rect3(20, 140, 100, 100); | |
582 // Bounds for anything else. | |
583 gfx::Rect rect(80, 90, 100, 110); | |
584 std::unique_ptr<aura::Window> w1( | |
585 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect1)); | |
586 std::unique_ptr<aura::Window> w2( | |
587 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect2)); | |
588 std::unique_ptr<aura::Window> w3(CreateFixedSizeNonMaximizableWindow( | |
589 aura::client::WINDOW_TYPE_NORMAL, rect3)); | |
590 | |
591 // Create the manager and make sure that all qualifying windows were | |
592 // detected and changed. | |
593 manager = CreateTabletModeWindowManager(); | |
594 ASSERT_TRUE(manager); | |
595 EXPECT_EQ(3, manager->GetNumberOfManagedWindows()); | |
596 } | |
597 EXPECT_EQ(0, manager->GetNumberOfManagedWindows()); | |
598 DestroyTabletModeWindowManager(); | |
599 } | |
600 | |
601 // Test that windows which got created while the maximizer was running can get | |
602 // destroyed before the maximizer gets destroyed. | |
603 TEST_F(TabletModeWindowManagerTest, CreateWindowsAndDeleteWhileActive) { | |
604 TabletModeWindowManager* manager = CreateTabletModeWindowManager(); | |
605 ASSERT_TRUE(manager); | |
606 EXPECT_EQ(0, manager->GetNumberOfManagedWindows()); | |
607 { | |
608 // Bounds for windows we know can be controlled. | |
609 gfx::Rect rect1(10, 10, 200, 50); | |
610 gfx::Rect rect2(10, 60, 200, 50); | |
611 gfx::Rect rect3(20, 140, 100, 100); | |
612 std::unique_ptr<aura::Window> w1(CreateWindow( | |
613 aura::client::WINDOW_TYPE_NORMAL, gfx::Rect(10, 10, 200, 50))); | |
614 std::unique_ptr<aura::Window> w2(CreateWindow( | |
615 aura::client::WINDOW_TYPE_NORMAL, gfx::Rect(10, 60, 200, 50))); | |
616 std::unique_ptr<aura::Window> w3(CreateFixedSizeNonMaximizableWindow( | |
617 aura::client::WINDOW_TYPE_NORMAL, gfx::Rect(20, 140, 100, 100))); | |
618 // Check that the windows got automatically maximized as well. | |
619 EXPECT_EQ(3, manager->GetNumberOfManagedWindows()); | |
620 EXPECT_TRUE(wm::GetWindowState(w1.get())->IsMaximized()); | |
621 EXPECT_TRUE(wm::GetWindowState(w2.get())->IsMaximized()); | |
622 EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMaximized()); | |
623 } | |
624 EXPECT_EQ(0, manager->GetNumberOfManagedWindows()); | |
625 DestroyTabletModeWindowManager(); | |
626 } | |
627 | |
628 // Test that windows which were maximized stay maximized. | |
629 TEST_F(TabletModeWindowManagerTest, MaximizedShouldRemainMaximized) { | |
630 // Bounds for windows we know can be controlled. | |
631 gfx::Rect rect(10, 10, 200, 50); | |
632 std::unique_ptr<aura::Window> window( | |
633 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
634 wm::GetWindowState(window.get())->Maximize(); | |
635 | |
636 // Create the manager and make sure that the window gets detected. | |
637 TabletModeWindowManager* manager = CreateTabletModeWindowManager(); | |
638 ASSERT_TRUE(manager); | |
639 EXPECT_EQ(1, manager->GetNumberOfManagedWindows()); | |
640 EXPECT_TRUE(wm::GetWindowState(window.get())->IsMaximized()); | |
641 | |
642 // Destroy the manager again and check that the window will remain maximized. | |
643 DestroyTabletModeWindowManager(); | |
644 EXPECT_TRUE(wm::GetWindowState(window.get())->IsMaximized()); | |
645 wm::GetWindowState(window.get())->Restore(); | |
646 EXPECT_EQ(rect.ToString(), window->bounds().ToString()); | |
647 } | |
648 | |
649 // Test that minimized windows do neither get maximized nor restored upon | |
650 // entering tablet mode and get restored to their previous state after | |
651 // leaving. | |
652 TEST_F(TabletModeWindowManagerTest, MinimizedWindowBehavior) { | |
653 // Bounds for windows we know can be controlled. | |
654 gfx::Rect rect(10, 10, 200, 50); | |
655 std::unique_ptr<aura::Window> initially_minimized_window( | |
656 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
657 std::unique_ptr<aura::Window> initially_normal_window( | |
658 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
659 std::unique_ptr<aura::Window> initially_maximized_window( | |
660 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
661 wm::GetWindowState(initially_minimized_window.get())->Minimize(); | |
662 wm::GetWindowState(initially_maximized_window.get())->Maximize(); | |
663 | |
664 // Create the manager and make sure that the window gets detected. | |
665 TabletModeWindowManager* manager = CreateTabletModeWindowManager(); | |
666 ASSERT_TRUE(manager); | |
667 EXPECT_EQ(3, manager->GetNumberOfManagedWindows()); | |
668 EXPECT_TRUE( | |
669 wm::GetWindowState(initially_minimized_window.get())->IsMinimized()); | |
670 EXPECT_TRUE(wm::GetWindowState(initially_normal_window.get())->IsMaximized()); | |
671 EXPECT_TRUE( | |
672 wm::GetWindowState(initially_maximized_window.get())->IsMaximized()); | |
673 // Now minimize the second window to check that upon leaving the window | |
674 // will get restored to its minimized state. | |
675 wm::GetWindowState(initially_normal_window.get())->Minimize(); | |
676 wm::GetWindowState(initially_maximized_window.get())->Minimize(); | |
677 EXPECT_TRUE( | |
678 wm::GetWindowState(initially_minimized_window.get())->IsMinimized()); | |
679 EXPECT_TRUE(wm::GetWindowState(initially_normal_window.get())->IsMinimized()); | |
680 EXPECT_TRUE( | |
681 wm::GetWindowState(initially_maximized_window.get())->IsMinimized()); | |
682 | |
683 // Destroy the manager again and check that the window will get minimized. | |
684 DestroyTabletModeWindowManager(); | |
685 EXPECT_TRUE( | |
686 wm::GetWindowState(initially_minimized_window.get())->IsMinimized()); | |
687 EXPECT_FALSE( | |
688 wm::GetWindowState(initially_normal_window.get())->IsMinimized()); | |
689 EXPECT_TRUE( | |
690 wm::GetWindowState(initially_maximized_window.get())->IsMaximized()); | |
691 } | |
692 | |
693 // Check that resizing the desktop does reposition unmaximizable, unresizable & | |
694 // managed windows. | |
695 TEST_F(TabletModeWindowManagerTest, DesktopSizeChangeMovesUnmaximizable) { | |
696 UpdateDisplay("400x400"); | |
697 // This window will move because it does not fit the new bounds. | |
698 gfx::Rect rect(20, 300, 100, 100); | |
699 std::unique_ptr<aura::Window> window1(CreateFixedSizeNonMaximizableWindow( | |
700 aura::client::WINDOW_TYPE_NORMAL, rect)); | |
701 EXPECT_EQ(rect.ToString(), window1->bounds().ToString()); | |
702 | |
703 // This window will not move because it does fit the new bounds. | |
704 gfx::Rect rect2(20, 140, 100, 100); | |
705 std::unique_ptr<aura::Window> window2(CreateFixedSizeNonMaximizableWindow( | |
706 aura::client::WINDOW_TYPE_NORMAL, rect2)); | |
707 | |
708 // Turning on the manager will reposition (but not resize) the window. | |
709 TabletModeWindowManager* manager = CreateTabletModeWindowManager(); | |
710 ASSERT_TRUE(manager); | |
711 EXPECT_EQ(2, manager->GetNumberOfManagedWindows()); | |
712 gfx::Rect moved_bounds(window1->bounds()); | |
713 EXPECT_NE(rect.origin().ToString(), moved_bounds.origin().ToString()); | |
714 EXPECT_EQ(rect.size().ToString(), moved_bounds.size().ToString()); | |
715 | |
716 // Simulating a desktop resize should move the window again. | |
717 UpdateDisplay("300x300"); | |
718 gfx::Rect new_moved_bounds(window1->bounds()); | |
719 EXPECT_NE(rect.origin().ToString(), new_moved_bounds.origin().ToString()); | |
720 EXPECT_EQ(rect.size().ToString(), new_moved_bounds.size().ToString()); | |
721 EXPECT_NE(moved_bounds.origin().ToString(), new_moved_bounds.ToString()); | |
722 | |
723 // Turning off the mode should not restore to the initial coordinates since | |
724 // the new resolution is smaller and the window was on the edge. | |
725 DestroyTabletModeWindowManager(); | |
726 EXPECT_NE(rect.ToString(), window1->bounds().ToString()); | |
727 EXPECT_EQ(rect2.ToString(), window2->bounds().ToString()); | |
728 } | |
729 | |
730 // Check that windows return to original location if desktop size changes to | |
731 // something else and back while in tablet mode. | |
732 TEST_F(TabletModeWindowManagerTest, SizeChangeReturnWindowToOriginalPos) { | |
733 gfx::Rect rect(20, 140, 100, 100); | |
734 std::unique_ptr<aura::Window> window(CreateFixedSizeNonMaximizableWindow( | |
735 aura::client::WINDOW_TYPE_NORMAL, rect)); | |
736 | |
737 // Turning on the manager will reposition (but not resize) the window. | |
738 TabletModeWindowManager* manager = CreateTabletModeWindowManager(); | |
739 ASSERT_TRUE(manager); | |
740 EXPECT_EQ(1, manager->GetNumberOfManagedWindows()); | |
741 gfx::Rect moved_bounds(window->bounds()); | |
742 EXPECT_NE(rect.origin().ToString(), moved_bounds.origin().ToString()); | |
743 EXPECT_EQ(rect.size().ToString(), moved_bounds.size().ToString()); | |
744 | |
745 // Simulating a desktop resize should move the window again. | |
746 ResizeDesktop(-10); | |
747 gfx::Rect new_moved_bounds(window->bounds()); | |
748 EXPECT_NE(rect.origin().ToString(), new_moved_bounds.origin().ToString()); | |
749 EXPECT_EQ(rect.size().ToString(), new_moved_bounds.size().ToString()); | |
750 EXPECT_NE(moved_bounds.origin().ToString(), new_moved_bounds.ToString()); | |
751 | |
752 // Then resize back to the original desktop size which should move windows | |
753 // to their original location after leaving the tablet mode. | |
754 ResizeDesktop(10); | |
755 DestroyTabletModeWindowManager(); | |
756 EXPECT_EQ(rect.ToString(), window->bounds().ToString()); | |
757 } | |
758 | |
759 // Check that enabling of the tablet mode does not have an impact on the MRU | |
760 // order of windows. | |
761 TEST_F(TabletModeWindowManagerTest, ModeChangeKeepsMRUOrder) { | |
762 gfx::Rect rect(20, 140, 100, 100); | |
763 std::unique_ptr<aura::Window> w1(CreateFixedSizeNonMaximizableWindow( | |
764 aura::client::WINDOW_TYPE_NORMAL, rect)); | |
765 std::unique_ptr<aura::Window> w2( | |
766 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
767 std::unique_ptr<aura::Window> w3( | |
768 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
769 std::unique_ptr<aura::Window> w4(CreateFixedSizeNonMaximizableWindow( | |
770 aura::client::WINDOW_TYPE_NORMAL, rect)); | |
771 std::unique_ptr<aura::Window> w5( | |
772 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
773 | |
774 // The windows should be in the reverse order of creation in the MRU list. | |
775 { | |
776 aura::Window::Windows windows = | |
777 Shell::Get()->mru_window_tracker()->BuildMruWindowList(); | |
778 | |
779 EXPECT_EQ(w1.get(), windows[4]); | |
780 EXPECT_EQ(w2.get(), windows[3]); | |
781 EXPECT_EQ(w3.get(), windows[2]); | |
782 EXPECT_EQ(w4.get(), windows[1]); | |
783 EXPECT_EQ(w5.get(), windows[0]); | |
784 } | |
785 | |
786 // Activating the window manager should keep the order. | |
787 TabletModeWindowManager* manager = CreateTabletModeWindowManager(); | |
788 ASSERT_TRUE(manager); | |
789 EXPECT_EQ(5, manager->GetNumberOfManagedWindows()); | |
790 { | |
791 aura::Window::Windows windows = | |
792 Shell::Get()->mru_window_tracker()->BuildMruWindowList(); | |
793 // We do not test maximization here again since that was done already. | |
794 EXPECT_EQ(w1.get(), windows[4]); | |
795 EXPECT_EQ(w2.get(), windows[3]); | |
796 EXPECT_EQ(w3.get(), windows[2]); | |
797 EXPECT_EQ(w4.get(), windows[1]); | |
798 EXPECT_EQ(w5.get(), windows[0]); | |
799 } | |
800 | |
801 // Destroying should still keep the order. | |
802 DestroyTabletModeWindowManager(); | |
803 { | |
804 aura::Window::Windows windows = | |
805 Shell::Get()->mru_window_tracker()->BuildMruWindowList(); | |
806 // We do not test maximization here again since that was done already. | |
807 EXPECT_EQ(w1.get(), windows[4]); | |
808 EXPECT_EQ(w2.get(), windows[3]); | |
809 EXPECT_EQ(w3.get(), windows[2]); | |
810 EXPECT_EQ(w4.get(), windows[1]); | |
811 EXPECT_EQ(w5.get(), windows[0]); | |
812 } | |
813 } | |
814 | |
815 // Check that a restore state change does always restore to maximized. | |
816 TEST_F(TabletModeWindowManagerTest, IgnoreRestoreStateChages) { | |
817 gfx::Rect rect(20, 140, 100, 100); | |
818 std::unique_ptr<aura::Window> w1( | |
819 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
820 wm::WindowState* window_state = wm::GetWindowState(w1.get()); | |
821 CreateTabletModeWindowManager(); | |
822 EXPECT_TRUE(window_state->IsMaximized()); | |
823 window_state->Minimize(); | |
824 EXPECT_TRUE(window_state->IsMinimized()); | |
825 window_state->Restore(); | |
826 EXPECT_TRUE(window_state->IsMaximized()); | |
827 window_state->Restore(); | |
828 EXPECT_TRUE(window_state->IsMaximized()); | |
829 DestroyTabletModeWindowManager(); | |
830 } | |
831 | |
832 // Check that minimize and restore do the right thing. | |
833 TEST_F(TabletModeWindowManagerTest, TestMinimize) { | |
834 gfx::Rect rect(10, 10, 100, 100); | |
835 std::unique_ptr<aura::Window> window( | |
836 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
837 wm::WindowState* window_state = wm::GetWindowState(window.get()); | |
838 EXPECT_EQ(rect.ToString(), window->bounds().ToString()); | |
839 Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true); | |
840 EXPECT_TRUE(window_state->IsMaximized()); | |
841 EXPECT_FALSE(window_state->IsMinimized()); | |
842 EXPECT_TRUE(window->IsVisible()); | |
843 | |
844 window_state->Minimize(); | |
845 EXPECT_FALSE(window_state->IsMaximized()); | |
846 EXPECT_TRUE(window_state->IsMinimized()); | |
847 EXPECT_FALSE(window->IsVisible()); | |
848 | |
849 window_state->Maximize(); | |
850 EXPECT_TRUE(window_state->IsMaximized()); | |
851 EXPECT_FALSE(window_state->IsMinimized()); | |
852 EXPECT_TRUE(window->IsVisible()); | |
853 | |
854 Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(false); | |
855 EXPECT_FALSE(window_state->IsMaximized()); | |
856 EXPECT_FALSE(window_state->IsMinimized()); | |
857 EXPECT_TRUE(window->IsVisible()); | |
858 } | |
859 | |
860 // Check that a full screen window remains full screen upon entering maximize | |
861 // mode. Furthermore, checks that this window is not full screen upon exiting | |
862 // tablet mode if it was un-full-screened while in tablet mode. | |
863 TEST_F(TabletModeWindowManagerTest, KeepFullScreenModeOn) { | |
864 gfx::Rect rect(20, 140, 100, 100); | |
865 std::unique_ptr<aura::Window> w1( | |
866 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
867 wm::WindowState* window_state = wm::GetWindowState(w1.get()); | |
868 | |
869 Shelf* shelf = GetPrimaryShelf(); | |
870 | |
871 // Allow the shelf to hide. | |
872 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | |
873 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); | |
874 | |
875 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); | |
876 window_state->OnWMEvent(&event); | |
877 | |
878 // With full screen, the shelf should get hidden. | |
879 EXPECT_TRUE(window_state->IsFullscreen()); | |
880 EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState()); | |
881 | |
882 CreateTabletModeWindowManager(); | |
883 | |
884 // The Full screen mode should continue to be on. | |
885 EXPECT_TRUE(window_state->IsFullscreen()); | |
886 EXPECT_FALSE(window_state->IsMaximized()); | |
887 EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState()); | |
888 | |
889 // With leaving the fullscreen mode, the tablet mode should return and the | |
890 // shelf should maintain its state from before tablet mode. | |
891 window_state->OnWMEvent(&event); | |
892 EXPECT_FALSE(window_state->IsFullscreen()); | |
893 EXPECT_TRUE(window_state->IsMaximized()); | |
894 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); | |
895 | |
896 // We left fullscreen mode while in tablet mode, so the window should | |
897 // remain maximized and the shelf should not change state upon exiting | |
898 // tablet mode. | |
899 DestroyTabletModeWindowManager(); | |
900 EXPECT_FALSE(window_state->IsFullscreen()); | |
901 EXPECT_TRUE(window_state->IsMaximized()); | |
902 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); | |
903 } | |
904 | |
905 // Similar to the fullscreen mode, the pinned mode should be kept as well. | |
906 TEST_F(TabletModeWindowManagerTest, KeepPinnedModeOn_Case1) { | |
907 // Scenario: in the default state, pin a window, enter to the tablet mode, | |
908 // then unpin. | |
909 gfx::Rect rect(20, 140, 100, 100); | |
910 std::unique_ptr<aura::Window> w1( | |
911 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
912 wm::WindowState* window_state = wm::GetWindowState(w1.get()); | |
913 EXPECT_FALSE(window_state->IsPinned()); | |
914 | |
915 // Pin the window. | |
916 { | |
917 wm::WMEvent event(wm::WM_EVENT_PIN); | |
918 window_state->OnWMEvent(&event); | |
919 } | |
920 EXPECT_TRUE(window_state->IsPinned()); | |
921 | |
922 // Enter to Maximized mode. | |
923 // The pinned mode should continue to be on. | |
924 CreateTabletModeWindowManager(); | |
925 EXPECT_TRUE(window_state->IsPinned()); | |
926 | |
927 // Then unpin. | |
928 window_state->Restore(); | |
929 EXPECT_FALSE(window_state->IsPinned()); | |
930 | |
931 // Exit from Maximized mode. | |
932 // The window should not be back to the pinned mode. | |
933 DestroyTabletModeWindowManager(); | |
934 EXPECT_FALSE(window_state->IsPinned()); | |
935 } | |
936 | |
937 TEST_F(TabletModeWindowManagerTest, KeepPinnedModeOn_Case2) { | |
938 // Scenario: in the tablet mode, pin a window, exit from the maximized | |
939 // mode, then unpin. | |
940 gfx::Rect rect(20, 140, 100, 100); | |
941 std::unique_ptr<aura::Window> w1( | |
942 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
943 wm::WindowState* window_state = wm::GetWindowState(w1.get()); | |
944 EXPECT_FALSE(window_state->IsPinned()); | |
945 | |
946 // Enter to Maximized mode. | |
947 CreateTabletModeWindowManager(); | |
948 EXPECT_FALSE(window_state->IsPinned()); | |
949 | |
950 // Pin the window. | |
951 { | |
952 wm::WMEvent event(wm::WM_EVENT_PIN); | |
953 window_state->OnWMEvent(&event); | |
954 } | |
955 EXPECT_TRUE(window_state->IsPinned()); | |
956 | |
957 // Exit from Maximized mode. | |
958 // The pinned mode should continue to be on. | |
959 DestroyTabletModeWindowManager(); | |
960 EXPECT_TRUE(window_state->IsPinned()); | |
961 | |
962 // Then unpin. | |
963 window_state->Restore(); | |
964 EXPECT_FALSE(window_state->IsPinned()); | |
965 | |
966 // Enter again to Maximized mode for verification. | |
967 // The window should not be back to the pinned mode. | |
968 CreateTabletModeWindowManager(); | |
969 EXPECT_FALSE(window_state->IsPinned()); | |
970 | |
971 // Exit from Maximized mode. | |
972 DestroyTabletModeWindowManager(); | |
973 EXPECT_FALSE(window_state->IsPinned()); | |
974 } | |
975 | |
976 TEST_F(TabletModeWindowManagerTest, KeepPinnedModeOn_Case3) { | |
977 // Scenario: in the default state, pin a window, enter to the tablet mode, | |
978 // exit from the tablet mode, then unpin. | |
979 gfx::Rect rect(20, 140, 100, 100); | |
980 std::unique_ptr<aura::Window> w1( | |
981 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
982 wm::WindowState* window_state = wm::GetWindowState(w1.get()); | |
983 EXPECT_FALSE(window_state->IsPinned()); | |
984 | |
985 // Pin the window. | |
986 { | |
987 wm::WMEvent event(wm::WM_EVENT_PIN); | |
988 window_state->OnWMEvent(&event); | |
989 } | |
990 EXPECT_TRUE(window_state->IsPinned()); | |
991 | |
992 // Enter to Maximized mode. | |
993 // The pinned mode should continue to be on. | |
994 CreateTabletModeWindowManager(); | |
995 EXPECT_TRUE(window_state->IsPinned()); | |
996 | |
997 // Exit from Maximized mode. | |
998 // The pinned mode should continue to be on, too. | |
999 DestroyTabletModeWindowManager(); | |
1000 EXPECT_TRUE(window_state->IsPinned()); | |
1001 | |
1002 // Then unpin. | |
1003 window_state->Restore(); | |
1004 EXPECT_FALSE(window_state->IsPinned()); | |
1005 | |
1006 // Enter again to Maximized mode for verification. | |
1007 // The window should not be back to the pinned mode. | |
1008 CreateTabletModeWindowManager(); | |
1009 EXPECT_FALSE(window_state->IsPinned()); | |
1010 | |
1011 // Exit from Maximized mode. | |
1012 DestroyTabletModeWindowManager(); | |
1013 } | |
1014 | |
1015 TEST_F(TabletModeWindowManagerTest, KeepPinnedModeOn_Case4) { | |
1016 // Scenario: in the tablet mode, pin a window, exit from the maximized | |
1017 // mode, enter back to the tablet mode, then unpin. | |
1018 gfx::Rect rect(20, 140, 100, 100); | |
1019 std::unique_ptr<aura::Window> w1( | |
1020 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
1021 wm::WindowState* window_state = wm::GetWindowState(w1.get()); | |
1022 EXPECT_FALSE(window_state->IsPinned()); | |
1023 | |
1024 // Enter to Maximized mode. | |
1025 CreateTabletModeWindowManager(); | |
1026 EXPECT_FALSE(window_state->IsPinned()); | |
1027 | |
1028 // Pin the window. | |
1029 { | |
1030 wm::WMEvent event(wm::WM_EVENT_PIN); | |
1031 window_state->OnWMEvent(&event); | |
1032 } | |
1033 EXPECT_TRUE(window_state->IsPinned()); | |
1034 | |
1035 // Exit from Maximized mode. | |
1036 // The pinned mode should continue to be on. | |
1037 DestroyTabletModeWindowManager(); | |
1038 EXPECT_TRUE(window_state->IsPinned()); | |
1039 | |
1040 // Enter again to Maximized mode. | |
1041 // The pinned mode should continue to be on, too. | |
1042 CreateTabletModeWindowManager(); | |
1043 EXPECT_TRUE(window_state->IsPinned()); | |
1044 | |
1045 // Then unpin. | |
1046 window_state->Restore(); | |
1047 EXPECT_FALSE(window_state->IsPinned()); | |
1048 | |
1049 // Exit from Maximized mode. | |
1050 // The window should not be back to the pinned mode. | |
1051 DestroyTabletModeWindowManager(); | |
1052 EXPECT_FALSE(window_state->IsPinned()); | |
1053 } | |
1054 | |
1055 // Verifies that if a window is un-full-screened while in tablet mode, | |
1056 // other changes to that window's state (such as minimizing it) are | |
1057 // preserved upon exiting tablet mode. | |
1058 TEST_F(TabletModeWindowManagerTest, MinimizePreservedAfterLeavingFullscreen) { | |
1059 gfx::Rect rect(20, 140, 100, 100); | |
1060 std::unique_ptr<aura::Window> w1( | |
1061 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
1062 wm::WindowState* window_state = wm::GetWindowState(w1.get()); | |
1063 | |
1064 Shelf* shelf = GetPrimaryShelf(); | |
1065 | |
1066 // Allow the shelf to hide and enter full screen. | |
1067 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | |
1068 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); | |
1069 window_state->OnWMEvent(&event); | |
1070 ASSERT_FALSE(window_state->IsMinimized()); | |
1071 | |
1072 // Enter tablet mode, exit full screen, and then minimize the window. | |
1073 CreateTabletModeWindowManager(); | |
1074 window_state->OnWMEvent(&event); | |
1075 window_state->Minimize(); | |
1076 ASSERT_TRUE(window_state->IsMinimized()); | |
1077 | |
1078 // The window should remain minimized when exiting tablet mode. | |
1079 DestroyTabletModeWindowManager(); | |
1080 EXPECT_TRUE(window_state->IsMinimized()); | |
1081 } | |
1082 | |
1083 // Check that full screen mode can be turned on in tablet mode and remains | |
1084 // upon coming back. | |
1085 TEST_F(TabletModeWindowManagerTest, AllowFullScreenMode) { | |
1086 gfx::Rect rect(20, 140, 100, 100); | |
1087 std::unique_ptr<aura::Window> w1( | |
1088 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
1089 wm::WindowState* window_state = wm::GetWindowState(w1.get()); | |
1090 | |
1091 Shelf* shelf = GetPrimaryShelf(); | |
1092 | |
1093 // Allow the shelf to hide. | |
1094 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | |
1095 | |
1096 EXPECT_FALSE(window_state->IsFullscreen()); | |
1097 EXPECT_FALSE(window_state->IsMaximized()); | |
1098 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); | |
1099 | |
1100 CreateTabletModeWindowManager(); | |
1101 | |
1102 // Fullscreen mode should still be off and the shelf should maintain its | |
1103 // state. | |
1104 EXPECT_FALSE(window_state->IsFullscreen()); | |
1105 EXPECT_TRUE(window_state->IsMaximized()); | |
1106 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); | |
1107 | |
1108 // After going into fullscreen mode, the shelf should be hidden. | |
1109 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); | |
1110 window_state->OnWMEvent(&event); | |
1111 EXPECT_TRUE(window_state->IsFullscreen()); | |
1112 EXPECT_FALSE(window_state->IsMaximized()); | |
1113 EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState()); | |
1114 | |
1115 // With the destruction of the manager we should remain in full screen. | |
1116 DestroyTabletModeWindowManager(); | |
1117 EXPECT_TRUE(window_state->IsFullscreen()); | |
1118 EXPECT_FALSE(window_state->IsMaximized()); | |
1119 EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState()); | |
1120 } | |
1121 | |
1122 // Check that the full screen mode will stay active when the tablet mode is | |
1123 // ended. | |
1124 TEST_F(TabletModeWindowManagerTest, | |
1125 FullScreenModeRemainsWhenCreatedInMaximizedMode) { | |
1126 CreateTabletModeWindowManager(); | |
1127 | |
1128 gfx::Rect rect(20, 140, 100, 100); | |
1129 std::unique_ptr<aura::Window> w1( | |
1130 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
1131 wm::WindowState* window_state = wm::GetWindowState(w1.get()); | |
1132 wm::WMEvent event_full_screen(wm::WM_EVENT_TOGGLE_FULLSCREEN); | |
1133 window_state->OnWMEvent(&event_full_screen); | |
1134 EXPECT_TRUE(window_state->IsFullscreen()); | |
1135 | |
1136 // After the tablet mode manager is ended, full screen will remain. | |
1137 DestroyTabletModeWindowManager(); | |
1138 EXPECT_TRUE(window_state->IsFullscreen()); | |
1139 } | |
1140 | |
1141 // Check that the full screen mode will stay active throughout a maximzied mode | |
1142 // session. | |
1143 TEST_F(TabletModeWindowManagerTest, | |
1144 FullScreenModeRemainsThroughTabletModeSwitch) { | |
1145 gfx::Rect rect(20, 140, 100, 100); | |
1146 std::unique_ptr<aura::Window> w1( | |
1147 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
1148 wm::WindowState* window_state = wm::GetWindowState(w1.get()); | |
1149 wm::WMEvent event_full_screen(wm::WM_EVENT_TOGGLE_FULLSCREEN); | |
1150 window_state->OnWMEvent(&event_full_screen); | |
1151 EXPECT_TRUE(window_state->IsFullscreen()); | |
1152 | |
1153 CreateTabletModeWindowManager(); | |
1154 EXPECT_TRUE(window_state->IsFullscreen()); | |
1155 DestroyTabletModeWindowManager(); | |
1156 EXPECT_TRUE(window_state->IsFullscreen()); | |
1157 } | |
1158 | |
1159 // Check that an empty window does not get restored to a tiny size. | |
1160 TEST_F(TabletModeWindowManagerTest, | |
1161 CreateAndMaximizeInTabletModeShouldRetoreToGoodSizeGoingToDefault) { | |
1162 CreateTabletModeWindowManager(); | |
1163 gfx::Rect rect; | |
1164 std::unique_ptr<aura::Window> w1( | |
1165 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
1166 w1->Show(); | |
1167 wm::WindowState* window_state = wm::GetWindowState(w1.get()); | |
1168 EXPECT_TRUE(window_state->IsMaximized()); | |
1169 | |
1170 // There is a calling order in which the restore bounds can get set to an | |
1171 // empty rectangle. We simulate this here. | |
1172 window_state->SetRestoreBoundsInScreen(rect); | |
1173 EXPECT_TRUE(window_state->GetRestoreBoundsInScreen().IsEmpty()); | |
1174 | |
1175 // Setting the window to a new size will physically not change the window, | |
1176 // but the restore size should get updated so that a restore later on will | |
1177 // return to this size. | |
1178 gfx::Rect requested_bounds(10, 20, 50, 70); | |
1179 w1->SetBounds(requested_bounds); | |
1180 EXPECT_TRUE(window_state->IsMaximized()); | |
1181 EXPECT_EQ(requested_bounds.ToString(), | |
1182 window_state->GetRestoreBoundsInScreen().ToString()); | |
1183 | |
1184 DestroyTabletModeWindowManager(); | |
1185 | |
1186 EXPECT_FALSE(window_state->IsMaximized()); | |
1187 EXPECT_EQ(w1->bounds().ToString(), requested_bounds.ToString()); | |
1188 } | |
1189 | |
1190 // Check that snapping operations get ignored. | |
1191 TEST_F(TabletModeWindowManagerTest, SnapModeTests) { | |
1192 gfx::Rect rect(20, 140, 100, 100); | |
1193 std::unique_ptr<aura::Window> w1( | |
1194 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
1195 wm::WindowState* window_state = wm::GetWindowState(w1.get()); | |
1196 wm::WMEvent event_left(wm::WM_EVENT_SNAP_LEFT); | |
1197 wm::WMEvent event_right(wm::WM_EVENT_SNAP_RIGHT); | |
1198 window_state->OnWMEvent(&event_left); | |
1199 EXPECT_TRUE(window_state->IsSnapped()); | |
1200 | |
1201 CreateTabletModeWindowManager(); | |
1202 | |
1203 // Fullscreen mode should now be off and it should not come back while in | |
1204 // tablet mode. | |
1205 EXPECT_FALSE(window_state->IsSnapped()); | |
1206 EXPECT_TRUE(window_state->IsMaximized()); | |
1207 window_state->OnWMEvent(&event_left); | |
1208 EXPECT_FALSE(window_state->IsSnapped()); | |
1209 EXPECT_TRUE(window_state->IsMaximized()); | |
1210 window_state->OnWMEvent(&event_right); | |
1211 EXPECT_FALSE(window_state->IsSnapped()); | |
1212 EXPECT_TRUE(window_state->IsMaximized()); | |
1213 | |
1214 DestroyTabletModeWindowManager(); | |
1215 EXPECT_TRUE(window_state->IsSnapped()); | |
1216 } | |
1217 | |
1218 // Check that non maximizable windows cannot be dragged by the user. | |
1219 TEST_F(TabletModeWindowManagerTest, TryToDesktopSizeDragUnmaximizable) { | |
1220 gfx::Rect rect(10, 10, 100, 100); | |
1221 std::unique_ptr<aura::Window> window(CreateFixedSizeNonMaximizableWindow( | |
1222 aura::client::WINDOW_TYPE_NORMAL, rect)); | |
1223 EXPECT_EQ(rect.ToString(), window->bounds().ToString()); | |
1224 | |
1225 // 1. Move the mouse over the caption and check that dragging the window does | |
1226 // change the location. | |
1227 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | |
1228 generator.MoveMouseTo(gfx::Point(rect.x() + 2, rect.y() + 2)); | |
1229 generator.PressLeftButton(); | |
1230 generator.MoveMouseBy(10, 5); | |
1231 RunAllPendingInMessageLoop(); | |
1232 generator.ReleaseLeftButton(); | |
1233 gfx::Point first_dragged_origin = window->bounds().origin(); | |
1234 EXPECT_EQ(rect.x() + 10, first_dragged_origin.x()); | |
1235 EXPECT_EQ(rect.y() + 5, first_dragged_origin.y()); | |
1236 | |
1237 // 2. Check that turning on the manager will stop allowing the window from | |
1238 // dragging. | |
1239 Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true); | |
1240 gfx::Rect center_bounds(window->bounds()); | |
1241 EXPECT_NE(rect.origin().ToString(), center_bounds.origin().ToString()); | |
1242 generator.MoveMouseTo( | |
1243 gfx::Point(center_bounds.x() + 1, center_bounds.y() + 1)); | |
1244 generator.PressLeftButton(); | |
1245 generator.MoveMouseBy(10, 5); | |
1246 RunAllPendingInMessageLoop(); | |
1247 generator.ReleaseLeftButton(); | |
1248 EXPECT_EQ(center_bounds.x(), window->bounds().x()); | |
1249 EXPECT_EQ(center_bounds.y(), window->bounds().y()); | |
1250 Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(false); | |
1251 | |
1252 // 3. Releasing the mazimize manager again will restore the window to its | |
1253 // previous bounds and | |
1254 generator.MoveMouseTo( | |
1255 gfx::Point(first_dragged_origin.x() + 1, first_dragged_origin.y() + 1)); | |
1256 generator.PressLeftButton(); | |
1257 generator.MoveMouseBy(10, 5); | |
1258 RunAllPendingInMessageLoop(); | |
1259 generator.ReleaseLeftButton(); | |
1260 EXPECT_EQ(first_dragged_origin.x() + 10, window->bounds().x()); | |
1261 EXPECT_EQ(first_dragged_origin.y() + 5, window->bounds().y()); | |
1262 } | |
1263 | |
1264 // Test that overview is exited before entering / exiting tablet mode so that | |
1265 // the window changes made by TabletModeWindowManager do not conflict with | |
1266 // those made in WindowOverview. | |
1267 TEST_F(TabletModeWindowManagerTest, ExitsOverview) { | |
1268 // Bounds for windows we know can be controlled. | |
1269 gfx::Rect rect1(10, 10, 200, 50); | |
1270 gfx::Rect rect2(10, 60, 200, 50); | |
1271 std::unique_ptr<aura::Window> w1( | |
1272 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect1)); | |
1273 std::unique_ptr<aura::Window> w2( | |
1274 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect2)); | |
1275 | |
1276 WindowSelectorController* window_selector_controller = | |
1277 Shell::Get()->window_selector_controller(); | |
1278 ASSERT_TRUE(window_selector_controller->ToggleOverview()); | |
1279 ASSERT_TRUE(window_selector_controller->IsSelecting()); | |
1280 TabletModeWindowManager* manager = CreateTabletModeWindowManager(); | |
1281 ASSERT_TRUE(manager); | |
1282 EXPECT_FALSE(window_selector_controller->IsSelecting()); | |
1283 | |
1284 ASSERT_TRUE(window_selector_controller->ToggleOverview()); | |
1285 ASSERT_TRUE(window_selector_controller->IsSelecting()); | |
1286 // Destroy the manager again and check that the windows return to their | |
1287 // previous state. | |
1288 DestroyTabletModeWindowManager(); | |
1289 EXPECT_FALSE(window_selector_controller->IsSelecting()); | |
1290 } | |
1291 | |
1292 // Test that an edge swipe from the top will end full screen mode. | |
1293 TEST_F(TabletModeWindowManagerTest, ExitFullScreenWithEdgeSwipeFromTop) { | |
1294 // TODO: investigate failure. http://crbug.com/698093. | |
1295 if (Shell::GetAshConfig() == Config::MASH) | |
1296 return; | |
1297 | |
1298 gfx::Rect rect(10, 10, 200, 50); | |
1299 std::unique_ptr<aura::Window> background_window( | |
1300 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
1301 std::unique_ptr<aura::Window> foreground_window( | |
1302 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
1303 wm::WindowState* background_window_state = | |
1304 wm::GetWindowState(background_window.get()); | |
1305 wm::WindowState* foreground_window_state = | |
1306 wm::GetWindowState(foreground_window.get()); | |
1307 wm::ActivateWindow(foreground_window.get()); | |
1308 CreateTabletModeWindowManager(); | |
1309 | |
1310 // Fullscreen both windows. | |
1311 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); | |
1312 background_window_state->OnWMEvent(&event); | |
1313 foreground_window_state->OnWMEvent(&event); | |
1314 EXPECT_TRUE(background_window_state->IsFullscreen()); | |
1315 EXPECT_TRUE(foreground_window_state->IsFullscreen()); | |
1316 EXPECT_EQ(foreground_window.get(), wm::GetActiveWindow()); | |
1317 | |
1318 // Do an edge swipe top into screen. | |
1319 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | |
1320 generator.GestureScrollSequence(gfx::Point(50, 0), gfx::Point(50, 100), | |
1321 base::TimeDelta::FromMilliseconds(20), 10); | |
1322 | |
1323 EXPECT_FALSE(foreground_window_state->IsFullscreen()); | |
1324 EXPECT_TRUE(background_window_state->IsFullscreen()); | |
1325 | |
1326 // Do a second edge swipe top into screen. | |
1327 generator.GestureScrollSequence(gfx::Point(50, 0), gfx::Point(50, 100), | |
1328 base::TimeDelta::FromMilliseconds(20), 10); | |
1329 | |
1330 EXPECT_FALSE(foreground_window_state->IsFullscreen()); | |
1331 EXPECT_TRUE(background_window_state->IsFullscreen()); | |
1332 | |
1333 DestroyTabletModeWindowManager(); | |
1334 } | |
1335 | |
1336 // Test that an edge swipe from the bottom will end full screen mode. | |
1337 TEST_F(TabletModeWindowManagerTest, ExitFullScreenWithEdgeSwipeFromBottom) { | |
1338 // TODO: investigate failure. http://crbug.com/698093. | |
1339 if (Shell::GetAshConfig() == Config::MASH) | |
1340 return; | |
1341 | |
1342 gfx::Rect rect(10, 10, 200, 50); | |
1343 std::unique_ptr<aura::Window> background_window( | |
1344 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
1345 std::unique_ptr<aura::Window> foreground_window( | |
1346 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
1347 wm::WindowState* background_window_state = | |
1348 wm::GetWindowState(background_window.get()); | |
1349 wm::WindowState* foreground_window_state = | |
1350 wm::GetWindowState(foreground_window.get()); | |
1351 wm::ActivateWindow(foreground_window.get()); | |
1352 CreateTabletModeWindowManager(); | |
1353 | |
1354 // Fullscreen both windows. | |
1355 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); | |
1356 background_window_state->OnWMEvent(&event); | |
1357 foreground_window_state->OnWMEvent(&event); | |
1358 EXPECT_TRUE(background_window_state->IsFullscreen()); | |
1359 EXPECT_TRUE(foreground_window_state->IsFullscreen()); | |
1360 EXPECT_EQ(foreground_window.get(), wm::GetActiveWindow()); | |
1361 | |
1362 // Do an edge swipe bottom into screen. | |
1363 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | |
1364 int y = Shell::GetPrimaryRootWindow()->bounds().bottom(); | |
1365 generator.GestureScrollSequence(gfx::Point(50, y), gfx::Point(50, y - 100), | |
1366 base::TimeDelta::FromMilliseconds(20), 10); | |
1367 | |
1368 EXPECT_FALSE(foreground_window_state->IsFullscreen()); | |
1369 EXPECT_TRUE(background_window_state->IsFullscreen()); | |
1370 | |
1371 DestroyTabletModeWindowManager(); | |
1372 } | |
1373 | |
1374 // Test that an edge touch press at the top will end full screen mode. | |
1375 TEST_F(TabletModeWindowManagerTest, ExitFullScreenWithEdgeTouchAtTop) { | |
1376 // TODO: investigate failure. http://crbug.com/698093. | |
1377 if (Shell::GetAshConfig() == Config::MASH) | |
1378 return; | |
1379 | |
1380 gfx::Rect rect(10, 10, 200, 50); | |
1381 std::unique_ptr<aura::Window> background_window( | |
1382 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
1383 std::unique_ptr<aura::Window> foreground_window( | |
1384 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
1385 wm::WindowState* background_window_state = | |
1386 wm::GetWindowState(background_window.get()); | |
1387 wm::WindowState* foreground_window_state = | |
1388 wm::GetWindowState(foreground_window.get()); | |
1389 wm::ActivateWindow(foreground_window.get()); | |
1390 CreateTabletModeWindowManager(); | |
1391 | |
1392 // Fullscreen both windows. | |
1393 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); | |
1394 background_window_state->OnWMEvent(&event); | |
1395 foreground_window_state->OnWMEvent(&event); | |
1396 EXPECT_TRUE(background_window_state->IsFullscreen()); | |
1397 EXPECT_TRUE(foreground_window_state->IsFullscreen()); | |
1398 EXPECT_EQ(foreground_window.get(), wm::GetActiveWindow()); | |
1399 | |
1400 // Touch tap on the top edge. | |
1401 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | |
1402 generator.GestureTapAt(gfx::Point(100, 0)); | |
1403 EXPECT_FALSE(foreground_window_state->IsFullscreen()); | |
1404 EXPECT_TRUE(background_window_state->IsFullscreen()); | |
1405 | |
1406 // Try the same again and see that nothing changes. | |
1407 generator.GestureTapAt(gfx::Point(100, 0)); | |
1408 EXPECT_FALSE(foreground_window_state->IsFullscreen()); | |
1409 EXPECT_TRUE(background_window_state->IsFullscreen()); | |
1410 | |
1411 DestroyTabletModeWindowManager(); | |
1412 } | |
1413 | |
1414 // Test that an edge touch press at the bottom will end full screen mode. | |
1415 TEST_F(TabletModeWindowManagerTest, ExitFullScreenWithEdgeTouchAtBottom) { | |
1416 // TODO: investigate failure. http://crbug.com/698093. | |
1417 if (Shell::GetAshConfig() == Config::MASH) | |
1418 return; | |
1419 | |
1420 gfx::Rect rect(10, 10, 200, 50); | |
1421 std::unique_ptr<aura::Window> background_window( | |
1422 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
1423 std::unique_ptr<aura::Window> foreground_window( | |
1424 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
1425 wm::WindowState* background_window_state = | |
1426 wm::GetWindowState(background_window.get()); | |
1427 wm::WindowState* foreground_window_state = | |
1428 wm::GetWindowState(foreground_window.get()); | |
1429 wm::ActivateWindow(foreground_window.get()); | |
1430 CreateTabletModeWindowManager(); | |
1431 | |
1432 // Fullscreen both windows. | |
1433 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); | |
1434 background_window_state->OnWMEvent(&event); | |
1435 foreground_window_state->OnWMEvent(&event); | |
1436 EXPECT_TRUE(background_window_state->IsFullscreen()); | |
1437 EXPECT_TRUE(foreground_window_state->IsFullscreen()); | |
1438 EXPECT_EQ(foreground_window.get(), wm::GetActiveWindow()); | |
1439 | |
1440 // Touch tap on the bottom edge. | |
1441 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | |
1442 generator.GestureTapAt( | |
1443 gfx::Point(100, Shell::GetPrimaryRootWindow()->bounds().bottom() - 1)); | |
1444 EXPECT_FALSE(foreground_window_state->IsFullscreen()); | |
1445 EXPECT_TRUE(background_window_state->IsFullscreen()); | |
1446 | |
1447 // Try the same again and see that nothing changes. | |
1448 generator.GestureTapAt( | |
1449 gfx::Point(100, Shell::GetPrimaryRootWindow()->bounds().bottom() - 1)); | |
1450 EXPECT_FALSE(foreground_window_state->IsFullscreen()); | |
1451 EXPECT_TRUE(background_window_state->IsFullscreen()); | |
1452 | |
1453 DestroyTabletModeWindowManager(); | |
1454 } | |
1455 | |
1456 // Test that an edge swipe from the top on an immersive mode window will not end | |
1457 // full screen mode. | |
1458 TEST_F(TabletModeWindowManagerTest, NoExitImmersiveModeWithEdgeSwipeFromTop) { | |
1459 std::unique_ptr<aura::Window> window(CreateWindow( | |
1460 aura::client::WINDOW_TYPE_NORMAL, gfx::Rect(10, 10, 200, 50))); | |
1461 wm::WindowState* window_state = wm::GetWindowState(window.get()); | |
1462 wm::ActivateWindow(window.get()); | |
1463 CreateTabletModeWindowManager(); | |
1464 | |
1465 // Fullscreen the window. | |
1466 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); | |
1467 window_state->OnWMEvent(&event); | |
1468 EXPECT_TRUE(window_state->IsFullscreen()); | |
1469 EXPECT_FALSE(window_state->in_immersive_fullscreen()); | |
1470 EXPECT_EQ(window.get(), wm::GetActiveWindow()); | |
1471 | |
1472 window_state->set_in_immersive_fullscreen(true); | |
1473 | |
1474 // Do an edge swipe top into screen. | |
1475 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | |
1476 generator.GestureScrollSequence(gfx::Point(50, 0), gfx::Point(50, 100), | |
1477 base::TimeDelta::FromMilliseconds(20), 10); | |
1478 | |
1479 // It should have not exited full screen or immersive mode. | |
1480 EXPECT_TRUE(window_state->IsFullscreen()); | |
1481 EXPECT_TRUE(window_state->in_immersive_fullscreen()); | |
1482 | |
1483 DestroyTabletModeWindowManager(); | |
1484 } | |
1485 | |
1486 // Test that an edge swipe from the bottom will not end immersive mode. | |
1487 TEST_F(TabletModeWindowManagerTest, | |
1488 NoExitImmersiveModeWithEdgeSwipeFromBottom) { | |
1489 std::unique_ptr<aura::Window> window(CreateWindow( | |
1490 aura::client::WINDOW_TYPE_NORMAL, gfx::Rect(10, 10, 200, 50))); | |
1491 wm::WindowState* window_state = wm::GetWindowState(window.get()); | |
1492 wm::ActivateWindow(window.get()); | |
1493 CreateTabletModeWindowManager(); | |
1494 | |
1495 // Fullscreen the window. | |
1496 wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); | |
1497 window_state->OnWMEvent(&event); | |
1498 EXPECT_TRUE(window_state->IsFullscreen()); | |
1499 EXPECT_FALSE(window_state->in_immersive_fullscreen()); | |
1500 EXPECT_EQ(window.get(), wm::GetActiveWindow()); | |
1501 window_state->set_in_immersive_fullscreen(true); | |
1502 EXPECT_TRUE(window_state->in_immersive_fullscreen()); | |
1503 | |
1504 // Do an edge swipe bottom into screen. | |
1505 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | |
1506 int y = Shell::GetPrimaryRootWindow()->bounds().bottom(); | |
1507 generator.GestureScrollSequence(gfx::Point(50, y), gfx::Point(50, y - 100), | |
1508 base::TimeDelta::FromMilliseconds(20), 10); | |
1509 | |
1510 // The window should still be full screen and immersive. | |
1511 EXPECT_TRUE(window_state->IsFullscreen()); | |
1512 EXPECT_TRUE(window_state->in_immersive_fullscreen()); | |
1513 | |
1514 DestroyTabletModeWindowManager(); | |
1515 } | |
1516 | |
1517 // Tests that windows with the always-on-top property are not managed by | |
1518 // the TabletModeWindowManager while tablet mode is engaged (i.e., | |
1519 // they remain free-floating). | |
1520 TEST_F(TabletModeWindowManagerTest, AlwaysOnTopWindows) { | |
1521 gfx::Rect rect1(10, 10, 200, 50); | |
1522 gfx::Rect rect2(20, 140, 100, 100); | |
1523 | |
1524 // Create two windows with the always-on-top property. | |
1525 std::unique_ptr<aura::Window> w1( | |
1526 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect1)); | |
1527 std::unique_ptr<aura::Window> w2(CreateFixedSizeNonMaximizableWindow( | |
1528 aura::client::WINDOW_TYPE_NORMAL, rect2)); | |
1529 w1->SetProperty(aura::client::kAlwaysOnTopKey, true); | |
1530 w2->SetProperty(aura::client::kAlwaysOnTopKey, true); | |
1531 EXPECT_FALSE(wm::GetWindowState(w1.get())->IsMaximized()); | |
1532 EXPECT_FALSE(wm::GetWindowState(w2.get())->IsMaximized()); | |
1533 EXPECT_EQ(rect1.ToString(), w1->bounds().ToString()); | |
1534 EXPECT_EQ(rect2.ToString(), w2->bounds().ToString()); | |
1535 EXPECT_TRUE(wm::GetWindowState(w1.get())->can_be_dragged()); | |
1536 EXPECT_TRUE(wm::GetWindowState(w2.get())->can_be_dragged()); | |
1537 | |
1538 // Enter tablet mode. Neither window should be managed because they have | |
1539 // the always-on-top property set, which means that none of their properties | |
1540 // should change. | |
1541 TabletModeWindowManager* manager = CreateTabletModeWindowManager(); | |
1542 ASSERT_TRUE(manager); | |
1543 EXPECT_EQ(0, manager->GetNumberOfManagedWindows()); | |
1544 EXPECT_FALSE(wm::GetWindowState(w1.get())->IsMaximized()); | |
1545 EXPECT_FALSE(wm::GetWindowState(w2.get())->IsMaximized()); | |
1546 EXPECT_EQ(rect1.ToString(), w1->bounds().ToString()); | |
1547 EXPECT_EQ(rect2.ToString(), w2->bounds().ToString()); | |
1548 EXPECT_TRUE(wm::GetWindowState(w1.get())->can_be_dragged()); | |
1549 EXPECT_TRUE(wm::GetWindowState(w2.get())->can_be_dragged()); | |
1550 | |
1551 // Remove the always-on-top property from both windows while in maximize | |
1552 // mode. The windows should become managed, which means they should be | |
1553 // maximized/centered and no longer be draggable. | |
1554 w1->SetProperty(aura::client::kAlwaysOnTopKey, false); | |
1555 w2->SetProperty(aura::client::kAlwaysOnTopKey, false); | |
1556 EXPECT_EQ(2, manager->GetNumberOfManagedWindows()); | |
1557 EXPECT_TRUE(wm::GetWindowState(w1.get())->IsMaximized()); | |
1558 EXPECT_FALSE(wm::GetWindowState(w2.get())->IsMaximized()); | |
1559 EXPECT_NE(rect1.origin().ToString(), w1->bounds().origin().ToString()); | |
1560 EXPECT_NE(rect1.size().ToString(), w1->bounds().size().ToString()); | |
1561 EXPECT_NE(rect2.origin().ToString(), w2->bounds().origin().ToString()); | |
1562 EXPECT_EQ(rect2.size().ToString(), w2->bounds().size().ToString()); | |
1563 EXPECT_FALSE(wm::GetWindowState(w1.get())->can_be_dragged()); | |
1564 EXPECT_FALSE(wm::GetWindowState(w2.get())->can_be_dragged()); | |
1565 | |
1566 // Applying the always-on-top property to both windows while in maximize | |
1567 // mode should cause both windows to return to their original size, | |
1568 // position, and state. | |
1569 w1->SetProperty(aura::client::kAlwaysOnTopKey, true); | |
1570 w2->SetProperty(aura::client::kAlwaysOnTopKey, true); | |
1571 EXPECT_EQ(0, manager->GetNumberOfManagedWindows()); | |
1572 EXPECT_FALSE(wm::GetWindowState(w1.get())->IsMaximized()); | |
1573 EXPECT_FALSE(wm::GetWindowState(w2.get())->IsMaximized()); | |
1574 EXPECT_EQ(rect1.ToString(), w1->bounds().ToString()); | |
1575 EXPECT_EQ(rect2.ToString(), w2->bounds().ToString()); | |
1576 EXPECT_TRUE(wm::GetWindowState(w1.get())->can_be_dragged()); | |
1577 EXPECT_TRUE(wm::GetWindowState(w2.get())->can_be_dragged()); | |
1578 | |
1579 // The always-on-top windows should not change when leaving tablet mode. | |
1580 DestroyTabletModeWindowManager(); | |
1581 EXPECT_FALSE(wm::GetWindowState(w1.get())->IsMaximized()); | |
1582 EXPECT_FALSE(wm::GetWindowState(w2.get())->IsMaximized()); | |
1583 EXPECT_EQ(rect1.ToString(), w1->bounds().ToString()); | |
1584 EXPECT_EQ(rect2.ToString(), w2->bounds().ToString()); | |
1585 EXPECT_TRUE(wm::GetWindowState(w1.get())->can_be_dragged()); | |
1586 EXPECT_TRUE(wm::GetWindowState(w2.get())->can_be_dragged()); | |
1587 } | |
1588 | |
1589 // Tests that windows that can control maximized bounds are not maximized | |
1590 // and not tracked. | |
1591 TEST_F(TabletModeWindowManagerTest, DontMaximizeClientManagedWindows) { | |
1592 gfx::Rect rect(10, 10, 200, 50); | |
1593 std::unique_ptr<aura::Window> window( | |
1594 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
1595 | |
1596 wm::GetWindowState(window.get())->set_allow_set_bounds_direct(true); | |
1597 | |
1598 TabletModeWindowManager* manager = CreateTabletModeWindowManager(); | |
1599 EXPECT_FALSE(wm::GetWindowState(window.get())->IsMaximized()); | |
1600 EXPECT_EQ(0, manager->GetNumberOfManagedWindows()); | |
1601 } | |
1602 | |
1603 namespace { | |
1604 | |
1605 class TestObserver : public wm::WindowStateObserver { | |
1606 public: | |
1607 TestObserver(){}; | |
1608 ~TestObserver() override{}; | |
1609 | |
1610 // wm::WindowStateObserver: | |
1611 void OnPreWindowStateTypeChange(wm::WindowState* window_state, | |
1612 wm::WindowStateType old_type) override { | |
1613 pre_count_++; | |
1614 last_old_state_ = old_type; | |
1615 } | |
1616 | |
1617 void OnPostWindowStateTypeChange(wm::WindowState* window_state, | |
1618 wm::WindowStateType old_type) override { | |
1619 post_count_++; | |
1620 EXPECT_EQ(last_old_state_, old_type); | |
1621 } | |
1622 | |
1623 int GetPreCountAndReset() { | |
1624 int r = pre_count_; | |
1625 pre_count_ = 0; | |
1626 return r; | |
1627 } | |
1628 | |
1629 int GetPostCountAndReset() { | |
1630 int r = post_count_; | |
1631 post_count_ = 0; | |
1632 return r; | |
1633 } | |
1634 | |
1635 wm::WindowStateType GetLastOldStateAndReset() { | |
1636 wm::WindowStateType r = last_old_state_; | |
1637 last_old_state_ = wm::WINDOW_STATE_TYPE_DEFAULT; | |
1638 return r; | |
1639 } | |
1640 | |
1641 private: | |
1642 int pre_count_ = 0; | |
1643 int post_count_ = 0; | |
1644 wm::WindowStateType last_old_state_ = wm::WINDOW_STATE_TYPE_DEFAULT; | |
1645 | |
1646 DISALLOW_COPY_AND_ASSIGN(TestObserver); | |
1647 }; | |
1648 | |
1649 } // namespace | |
1650 | |
1651 TEST_F(TabletModeWindowManagerTest, StateTyepChange) { | |
1652 TestObserver observer; | |
1653 gfx::Rect rect(10, 10, 200, 50); | |
1654 std::unique_ptr<aura::Window> window( | |
1655 CreateWindow(aura::client::WINDOW_TYPE_NORMAL, rect)); | |
1656 | |
1657 CreateTabletModeWindowManager(); | |
1658 | |
1659 wm::WindowState* window_state = wm::GetWindowState(window.get()); | |
1660 window_state->AddObserver(&observer); | |
1661 | |
1662 window->Show(); | |
1663 EXPECT_TRUE(window_state->IsMaximized()); | |
1664 EXPECT_EQ(0, observer.GetPreCountAndReset()); | |
1665 EXPECT_EQ(0, observer.GetPostCountAndReset()); | |
1666 | |
1667 // Window is already in tablet mode. | |
1668 wm::WMEvent maximize_event(wm::WM_EVENT_MAXIMIZE); | |
1669 window_state->OnWMEvent(&maximize_event); | |
1670 EXPECT_EQ(0, observer.GetPreCountAndReset()); | |
1671 EXPECT_EQ(0, observer.GetPostCountAndReset()); | |
1672 | |
1673 wm::WMEvent fullscreen_event(wm::WM_EVENT_FULLSCREEN); | |
1674 window_state->OnWMEvent(&fullscreen_event); | |
1675 EXPECT_EQ(1, observer.GetPreCountAndReset()); | |
1676 EXPECT_EQ(1, observer.GetPostCountAndReset()); | |
1677 EXPECT_EQ(wm::WINDOW_STATE_TYPE_MAXIMIZED, | |
1678 observer.GetLastOldStateAndReset()); | |
1679 | |
1680 window_state->OnWMEvent(&maximize_event); | |
1681 EXPECT_EQ(1, observer.GetPreCountAndReset()); | |
1682 EXPECT_EQ(1, observer.GetPostCountAndReset()); | |
1683 EXPECT_EQ(wm::WINDOW_STATE_TYPE_FULLSCREEN, | |
1684 observer.GetLastOldStateAndReset()); | |
1685 | |
1686 wm::WMEvent minimize_event(wm::WM_EVENT_MINIMIZE); | |
1687 window_state->OnWMEvent(&minimize_event); | |
1688 EXPECT_EQ(1, observer.GetPreCountAndReset()); | |
1689 EXPECT_EQ(1, observer.GetPostCountAndReset()); | |
1690 EXPECT_EQ(wm::WINDOW_STATE_TYPE_MAXIMIZED, | |
1691 observer.GetLastOldStateAndReset()); | |
1692 | |
1693 wm::WMEvent restore_event(wm::WM_EVENT_NORMAL); | |
1694 window_state->OnWMEvent(&restore_event); | |
1695 EXPECT_EQ(1, observer.GetPreCountAndReset()); | |
1696 EXPECT_EQ(1, observer.GetPostCountAndReset()); | |
1697 EXPECT_EQ(wm::WINDOW_STATE_TYPE_MINIMIZED, | |
1698 observer.GetLastOldStateAndReset()); | |
1699 | |
1700 window_state->RemoveObserver(&observer); | |
1701 | |
1702 DestroyTabletModeWindowManager(); | |
1703 } | |
1704 | |
1705 } // namespace ash | |
OLD | NEW |