OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ash/shell.h" | 5 #include "ash/shell.h" |
6 #include "ash/test/ash_test_base.h" | 6 #include "ash/test/ash_test_base.h" |
7 #include "ash/test/test_session_state_delegate.h" | 7 #include "ash/test/test_session_state_delegate.h" |
8 #include "ash/test/test_shell_delegate.h" | 8 #include "ash/test/test_shell_delegate.h" |
9 #include "ash/wm/window_state.h" | 9 #include "ash/wm/window_state.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 ScopedUserManagerEnabler scoped_user_manager_; | 44 ScopedUserManagerEnabler scoped_user_manager_; |
45 | 45 |
46 DISALLOW_COPY_AND_ASSIGN(WallpaperPrivateApiUnittest); | 46 DISALLOW_COPY_AND_ASSIGN(WallpaperPrivateApiUnittest); |
47 }; | 47 }; |
48 | 48 |
49 class TestMinimizeFunction | 49 class TestMinimizeFunction |
50 : public WallpaperPrivateMinimizeInactiveWindowsFunction { | 50 : public WallpaperPrivateMinimizeInactiveWindowsFunction { |
51 public: | 51 public: |
52 TestMinimizeFunction() {} | 52 TestMinimizeFunction() {} |
53 | 53 |
54 virtual bool RunImpl() OVERRIDE { | 54 virtual bool RunAsync() OVERRIDE { |
55 return WallpaperPrivateMinimizeInactiveWindowsFunction::RunImpl(); | 55 return WallpaperPrivateMinimizeInactiveWindowsFunction::RunAsync(); |
56 } | 56 } |
57 | 57 |
58 protected: | 58 protected: |
59 virtual ~TestMinimizeFunction() {} | 59 virtual ~TestMinimizeFunction() {} |
60 }; | 60 }; |
61 | 61 |
62 class TestRestoreFunction | 62 class TestRestoreFunction |
63 : public WallpaperPrivateRestoreMinimizedWindowsFunction { | 63 : public WallpaperPrivateRestoreMinimizedWindowsFunction { |
64 public: | 64 public: |
65 TestRestoreFunction() {} | 65 TestRestoreFunction() {} |
66 | 66 |
67 virtual bool RunImpl() OVERRIDE { | 67 virtual bool RunAsync() OVERRIDE { |
68 return WallpaperPrivateRestoreMinimizedWindowsFunction::RunImpl(); | 68 return WallpaperPrivateRestoreMinimizedWindowsFunction::RunAsync(); |
69 } | 69 } |
70 protected: | 70 protected: |
71 virtual ~TestRestoreFunction() {} | 71 virtual ~TestRestoreFunction() {} |
72 }; | 72 }; |
73 | 73 |
74 } // namespace | 74 } // namespace |
75 | 75 |
76 TEST_F(WallpaperPrivateApiUnittest, HideAndRestoreWindows) { | 76 TEST_F(WallpaperPrivateApiUnittest, HideAndRestoreWindows) { |
77 fake_user_manager()->AddUser(kTestAccount1); | 77 fake_user_manager()->AddUser(kTestAccount1); |
78 scoped_ptr<aura::Window> window3(CreateTestWindowInShellWithId(3)); | 78 scoped_ptr<aura::Window> window3(CreateTestWindowInShellWithId(3)); |
(...skipping 14 matching lines...) Expand all Loading... |
93 EXPECT_FALSE(window1_state->IsMinimized()); | 93 EXPECT_FALSE(window1_state->IsMinimized()); |
94 EXPECT_FALSE(window2_state->IsMinimized()); | 94 EXPECT_FALSE(window2_state->IsMinimized()); |
95 EXPECT_TRUE(window3_state->IsMinimized()); | 95 EXPECT_TRUE(window3_state->IsMinimized()); |
96 | 96 |
97 // We then activate window 0 (i.e. wallpaper picker) and call the minimize | 97 // We then activate window 0 (i.e. wallpaper picker) and call the minimize |
98 // function. | 98 // function. |
99 window0_state->Activate(); | 99 window0_state->Activate(); |
100 EXPECT_TRUE(window0_state->IsActive()); | 100 EXPECT_TRUE(window0_state->IsActive()); |
101 scoped_refptr<TestMinimizeFunction> minimize_function( | 101 scoped_refptr<TestMinimizeFunction> minimize_function( |
102 new TestMinimizeFunction()); | 102 new TestMinimizeFunction()); |
103 EXPECT_TRUE(minimize_function->RunImpl()); | 103 EXPECT_TRUE(minimize_function->RunAsync()); |
104 | 104 |
105 // All windows except window 0 should be minimized. | 105 // All windows except window 0 should be minimized. |
106 EXPECT_FALSE(window0_state->IsMinimized()); | 106 EXPECT_FALSE(window0_state->IsMinimized()); |
107 EXPECT_TRUE(window1_state->IsMinimized()); | 107 EXPECT_TRUE(window1_state->IsMinimized()); |
108 EXPECT_TRUE(window2_state->IsMinimized()); | 108 EXPECT_TRUE(window2_state->IsMinimized()); |
109 EXPECT_TRUE(window3_state->IsMinimized()); | 109 EXPECT_TRUE(window3_state->IsMinimized()); |
110 | 110 |
111 // Then we destroy window 0 and call the restore function. | 111 // Then we destroy window 0 and call the restore function. |
112 window0.reset(); | 112 window0.reset(); |
113 scoped_refptr<TestRestoreFunction> restore_function( | 113 scoped_refptr<TestRestoreFunction> restore_function( |
114 new TestRestoreFunction()); | 114 new TestRestoreFunction()); |
115 EXPECT_TRUE(restore_function->RunImpl()); | 115 EXPECT_TRUE(restore_function->RunAsync()); |
116 | 116 |
117 // Windows 1 and 2 should no longer be minimized. Window 1 should again | 117 // Windows 1 and 2 should no longer be minimized. Window 1 should again |
118 // be maximized. Window 3 should still be minimized. | 118 // be maximized. Window 3 should still be minimized. |
119 EXPECT_TRUE(window1_state->IsMaximized()); | 119 EXPECT_TRUE(window1_state->IsMaximized()); |
120 EXPECT_FALSE(window2_state->IsMinimized()); | 120 EXPECT_FALSE(window2_state->IsMinimized()); |
121 EXPECT_TRUE(window3_state->IsMinimized()); | 121 EXPECT_TRUE(window3_state->IsMinimized()); |
122 } | 122 } |
123 | 123 |
124 // Test for multiple calls to |MinimizeInactiveWindows| before call | 124 // Test for multiple calls to |MinimizeInactiveWindows| before call |
125 // |RestoreWindows|: | 125 // |RestoreWindows|: |
126 // 1. If all window hasn't change their states, the following calls are noops. | 126 // 1. If all window hasn't change their states, the following calls are noops. |
127 // 2. If some windows are manually unminimized, the following call will minimize | 127 // 2. If some windows are manually unminimized, the following call will minimize |
128 // all the unminimized windows. | 128 // all the unminimized windows. |
129 TEST_F(WallpaperPrivateApiUnittest, HideAndManualUnminimizeWindows) { | 129 TEST_F(WallpaperPrivateApiUnittest, HideAndManualUnminimizeWindows) { |
130 fake_user_manager()->AddUser(kTestAccount1); | 130 fake_user_manager()->AddUser(kTestAccount1); |
131 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); | 131 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); |
132 scoped_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); | 132 scoped_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); |
133 | 133 |
134 ash::wm::WindowState* window0_state = ash::wm::GetWindowState(window0.get()); | 134 ash::wm::WindowState* window0_state = ash::wm::GetWindowState(window0.get()); |
135 ash::wm::WindowState* window1_state = ash::wm::GetWindowState(window1.get()); | 135 ash::wm::WindowState* window1_state = ash::wm::GetWindowState(window1.get()); |
136 | 136 |
137 // We then activate window 0 (i.e. wallpaper picker) and call the minimize | 137 // We then activate window 0 (i.e. wallpaper picker) and call the minimize |
138 // function. | 138 // function. |
139 window0_state->Activate(); | 139 window0_state->Activate(); |
140 EXPECT_TRUE(window0_state->IsActive()); | 140 EXPECT_TRUE(window0_state->IsActive()); |
141 scoped_refptr<TestMinimizeFunction> minimize_function_0( | 141 scoped_refptr<TestMinimizeFunction> minimize_function_0( |
142 new TestMinimizeFunction()); | 142 new TestMinimizeFunction()); |
143 EXPECT_TRUE(minimize_function_0->RunImpl()); | 143 EXPECT_TRUE(minimize_function_0->RunAsync()); |
144 | 144 |
145 // All windows except window 0 should be minimized. | 145 // All windows except window 0 should be minimized. |
146 EXPECT_FALSE(window0_state->IsMinimized()); | 146 EXPECT_FALSE(window0_state->IsMinimized()); |
147 EXPECT_TRUE(window1_state->IsMinimized()); | 147 EXPECT_TRUE(window1_state->IsMinimized()); |
148 | 148 |
149 // Calls minimize function again should be an noop if window state didn't | 149 // Calls minimize function again should be an noop if window state didn't |
150 // change. | 150 // change. |
151 scoped_refptr<TestMinimizeFunction> minimize_function_1( | 151 scoped_refptr<TestMinimizeFunction> minimize_function_1( |
152 new TestMinimizeFunction()); | 152 new TestMinimizeFunction()); |
153 EXPECT_TRUE(minimize_function_1->RunImpl()); | 153 EXPECT_TRUE(minimize_function_1->RunAsync()); |
154 | 154 |
155 // All windows except window 0 should be minimized. | 155 // All windows except window 0 should be minimized. |
156 EXPECT_FALSE(window0_state->IsMinimized()); | 156 EXPECT_FALSE(window0_state->IsMinimized()); |
157 EXPECT_TRUE(window1_state->IsMinimized()); | 157 EXPECT_TRUE(window1_state->IsMinimized()); |
158 | 158 |
159 // Manually unminimize window 1. | 159 // Manually unminimize window 1. |
160 window1_state->Unminimize(); | 160 window1_state->Unminimize(); |
161 EXPECT_FALSE(window1_state->IsMinimized()); | 161 EXPECT_FALSE(window1_state->IsMinimized()); |
162 window0_state->Activate(); | 162 window0_state->Activate(); |
163 | 163 |
164 scoped_refptr<TestMinimizeFunction> minimize_function_2( | 164 scoped_refptr<TestMinimizeFunction> minimize_function_2( |
165 new TestMinimizeFunction()); | 165 new TestMinimizeFunction()); |
166 EXPECT_TRUE(minimize_function_2->RunImpl()); | 166 EXPECT_TRUE(minimize_function_2->RunAsync()); |
167 | 167 |
168 // Window 1 should be minimized again. | 168 // Window 1 should be minimized again. |
169 EXPECT_FALSE(window0_state->IsMinimized()); | 169 EXPECT_FALSE(window0_state->IsMinimized()); |
170 EXPECT_TRUE(window1_state->IsMinimized()); | 170 EXPECT_TRUE(window1_state->IsMinimized()); |
171 | 171 |
172 // Then we destroy window 0 and call the restore function. | 172 // Then we destroy window 0 and call the restore function. |
173 window0.reset(); | 173 window0.reset(); |
174 scoped_refptr<TestRestoreFunction> restore_function( | 174 scoped_refptr<TestRestoreFunction> restore_function( |
175 new TestRestoreFunction()); | 175 new TestRestoreFunction()); |
176 EXPECT_TRUE(restore_function->RunImpl()); | 176 EXPECT_TRUE(restore_function->RunAsync()); |
177 | 177 |
178 // Windows 1 should no longer be minimized. | 178 // Windows 1 should no longer be minimized. |
179 EXPECT_FALSE(window1_state->IsMinimized()); | 179 EXPECT_FALSE(window1_state->IsMinimized()); |
180 } | 180 } |
181 | 181 |
182 class WallpaperPrivateApiMultiUserUnittest | 182 class WallpaperPrivateApiMultiUserUnittest |
183 : public WallpaperPrivateApiUnittest { | 183 : public WallpaperPrivateApiUnittest { |
184 public: | 184 public: |
185 WallpaperPrivateApiMultiUserUnittest() | 185 WallpaperPrivateApiMultiUserUnittest() |
186 : multi_user_window_manager_(NULL), | 186 : multi_user_window_manager_(NULL), |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 EXPECT_FALSE(window2_state->IsMinimized()); | 273 EXPECT_FALSE(window2_state->IsMinimized()); |
274 EXPECT_FALSE(window3_state->IsMinimized()); | 274 EXPECT_FALSE(window3_state->IsMinimized()); |
275 EXPECT_FALSE(window4_state->IsMinimized()); | 275 EXPECT_FALSE(window4_state->IsMinimized()); |
276 | 276 |
277 // We then activate window 0 (i.e. wallpaper picker) and call the minimize | 277 // We then activate window 0 (i.e. wallpaper picker) and call the minimize |
278 // function. | 278 // function. |
279 window0_state->Activate(); | 279 window0_state->Activate(); |
280 EXPECT_TRUE(window0_state->IsActive()); | 280 EXPECT_TRUE(window0_state->IsActive()); |
281 scoped_refptr<TestMinimizeFunction> minimize_function_0( | 281 scoped_refptr<TestMinimizeFunction> minimize_function_0( |
282 new TestMinimizeFunction()); | 282 new TestMinimizeFunction()); |
283 EXPECT_TRUE(minimize_function_0->RunImpl()); | 283 EXPECT_TRUE(minimize_function_0->RunAsync()); |
284 | 284 |
285 // All windows except window 0 should be minimized. | 285 // All windows except window 0 should be minimized. |
286 EXPECT_FALSE(window0_state->IsMinimized()); | 286 EXPECT_FALSE(window0_state->IsMinimized()); |
287 EXPECT_TRUE(window1_state->IsMinimized()); | 287 EXPECT_TRUE(window1_state->IsMinimized()); |
288 | 288 |
289 // All windows that belong to inactive user should not be affected. | 289 // All windows that belong to inactive user should not be affected. |
290 EXPECT_FALSE(window2_state->IsMinimized()); | 290 EXPECT_FALSE(window2_state->IsMinimized()); |
291 EXPECT_FALSE(window3_state->IsMinimized()); | 291 EXPECT_FALSE(window3_state->IsMinimized()); |
292 EXPECT_FALSE(window4_state->IsMinimized()); | 292 EXPECT_FALSE(window4_state->IsMinimized()); |
293 | 293 |
294 // Activate kTestAccount2. kTestAccount1 becomes inactive user. | 294 // Activate kTestAccount2. kTestAccount1 becomes inactive user. |
295 SwitchActiveUser(kTestAccount2); | 295 SwitchActiveUser(kTestAccount2); |
296 | 296 |
297 window2_state->Activate(); | 297 window2_state->Activate(); |
298 EXPECT_TRUE(window2_state->IsActive()); | 298 EXPECT_TRUE(window2_state->IsActive()); |
299 scoped_refptr<TestMinimizeFunction> minimize_function_1( | 299 scoped_refptr<TestMinimizeFunction> minimize_function_1( |
300 new TestMinimizeFunction()); | 300 new TestMinimizeFunction()); |
301 EXPECT_TRUE(minimize_function_1->RunImpl()); | 301 EXPECT_TRUE(minimize_function_1->RunAsync()); |
302 | 302 |
303 // All windows except window 2 should be minimized. | 303 // All windows except window 2 should be minimized. |
304 EXPECT_FALSE(window2_state->IsMinimized()); | 304 EXPECT_FALSE(window2_state->IsMinimized()); |
305 EXPECT_TRUE(window3_state->IsMinimized()); | 305 EXPECT_TRUE(window3_state->IsMinimized()); |
306 EXPECT_TRUE(window4_state->IsMinimized()); | 306 EXPECT_TRUE(window4_state->IsMinimized()); |
307 | 307 |
308 // All windows that belong to inactive user should not be affected. | 308 // All windows that belong to inactive user should not be affected. |
309 EXPECT_FALSE(window0_state->IsMinimized()); | 309 EXPECT_FALSE(window0_state->IsMinimized()); |
310 EXPECT_TRUE(window1_state->IsMinimized()); | 310 EXPECT_TRUE(window1_state->IsMinimized()); |
311 | 311 |
312 // Destroy window 4. Nothing should happen to other windows. | 312 // Destroy window 4. Nothing should happen to other windows. |
313 window4_state->Unminimize(); | 313 window4_state->Unminimize(); |
314 window4.reset(); | 314 window4.reset(); |
315 | 315 |
316 EXPECT_FALSE(window2_state->IsMinimized()); | 316 EXPECT_FALSE(window2_state->IsMinimized()); |
317 EXPECT_TRUE(window3_state->IsMinimized()); | 317 EXPECT_TRUE(window3_state->IsMinimized()); |
318 EXPECT_FALSE(window0_state->IsMinimized()); | 318 EXPECT_FALSE(window0_state->IsMinimized()); |
319 EXPECT_TRUE(window1_state->IsMinimized()); | 319 EXPECT_TRUE(window1_state->IsMinimized()); |
320 | 320 |
321 // Then we destroy window 2 and call the restore function. | 321 // Then we destroy window 2 and call the restore function. |
322 window2.reset(); | 322 window2.reset(); |
323 scoped_refptr<TestRestoreFunction> restore_function_0( | 323 scoped_refptr<TestRestoreFunction> restore_function_0( |
324 new TestRestoreFunction()); | 324 new TestRestoreFunction()); |
325 EXPECT_TRUE(restore_function_0->RunImpl()); | 325 EXPECT_TRUE(restore_function_0->RunAsync()); |
326 | 326 |
327 EXPECT_FALSE(window3_state->IsMinimized()); | 327 EXPECT_FALSE(window3_state->IsMinimized()); |
328 | 328 |
329 // All windows that belong to inactive user should not be affected. | 329 // All windows that belong to inactive user should not be affected. |
330 EXPECT_FALSE(window0_state->IsMinimized()); | 330 EXPECT_FALSE(window0_state->IsMinimized()); |
331 EXPECT_TRUE(window1_state->IsMinimized()); | 331 EXPECT_TRUE(window1_state->IsMinimized()); |
332 | 332 |
333 SwitchActiveUser(kTestAccount1); | 333 SwitchActiveUser(kTestAccount1); |
334 | 334 |
335 // Then we destroy window 0 and call the restore function. | 335 // Then we destroy window 0 and call the restore function. |
336 window0.reset(); | 336 window0.reset(); |
337 scoped_refptr<TestRestoreFunction> restore_function_1( | 337 scoped_refptr<TestRestoreFunction> restore_function_1( |
338 new TestRestoreFunction()); | 338 new TestRestoreFunction()); |
339 EXPECT_TRUE(restore_function_1->RunImpl()); | 339 EXPECT_TRUE(restore_function_1->RunAsync()); |
340 | 340 |
341 EXPECT_FALSE(window1_state->IsMinimized()); | 341 EXPECT_FALSE(window1_state->IsMinimized()); |
342 EXPECT_FALSE(window3_state->IsMinimized()); | 342 EXPECT_FALSE(window3_state->IsMinimized()); |
343 } | 343 } |
344 | 344 |
345 // In multi profile mode, user may teleport windows. Teleported window should | 345 // In multi profile mode, user may teleport windows. Teleported window should |
346 // also be minimized when open wallpaper picker. | 346 // also be minimized when open wallpaper picker. |
347 TEST_F(WallpaperPrivateApiMultiUserUnittest, HideTeleportedWindow) { | 347 TEST_F(WallpaperPrivateApiMultiUserUnittest, HideTeleportedWindow) { |
348 SetUpMultiUserWindowManager(kTestAccount1, | 348 SetUpMultiUserWindowManager(kTestAccount1, |
349 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_MIXED); | 349 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_MIXED); |
(...skipping 23 matching lines...) Expand all Loading... |
373 EXPECT_FALSE(window1_state->IsMinimized()); | 373 EXPECT_FALSE(window1_state->IsMinimized()); |
374 EXPECT_FALSE(window2_state->IsMinimized()); | 374 EXPECT_FALSE(window2_state->IsMinimized()); |
375 EXPECT_FALSE(window3_state->IsMinimized()); | 375 EXPECT_FALSE(window3_state->IsMinimized()); |
376 | 376 |
377 // We then activate window 0 (i.e. wallpaper picker) and call the minimize | 377 // We then activate window 0 (i.e. wallpaper picker) and call the minimize |
378 // function. | 378 // function. |
379 window0_state->Activate(); | 379 window0_state->Activate(); |
380 EXPECT_TRUE(window0_state->IsActive()); | 380 EXPECT_TRUE(window0_state->IsActive()); |
381 scoped_refptr<TestMinimizeFunction> minimize_function_0( | 381 scoped_refptr<TestMinimizeFunction> minimize_function_0( |
382 new TestMinimizeFunction()); | 382 new TestMinimizeFunction()); |
383 EXPECT_TRUE(minimize_function_0->RunImpl()); | 383 EXPECT_TRUE(minimize_function_0->RunAsync()); |
384 | 384 |
385 // All windows except window 0 should be minimized. | 385 // All windows except window 0 should be minimized. |
386 EXPECT_FALSE(window0_state->IsMinimized()); | 386 EXPECT_FALSE(window0_state->IsMinimized()); |
387 EXPECT_TRUE(window1_state->IsMinimized()); | 387 EXPECT_TRUE(window1_state->IsMinimized()); |
388 | 388 |
389 // Teleported window should also be minimized. | 389 // Teleported window should also be minimized. |
390 EXPECT_TRUE(window2_state->IsMinimized()); | 390 EXPECT_TRUE(window2_state->IsMinimized()); |
391 // Other window should remain the same. | 391 // Other window should remain the same. |
392 EXPECT_FALSE(window3_state->IsMinimized()); | 392 EXPECT_FALSE(window3_state->IsMinimized()); |
393 | 393 |
394 // Then we destroy window 0 and call the restore function. | 394 // Then we destroy window 0 and call the restore function. |
395 window0.reset(); | 395 window0.reset(); |
396 scoped_refptr<TestRestoreFunction> restore_function_1( | 396 scoped_refptr<TestRestoreFunction> restore_function_1( |
397 new TestRestoreFunction()); | 397 new TestRestoreFunction()); |
398 EXPECT_TRUE(restore_function_1->RunImpl()); | 398 EXPECT_TRUE(restore_function_1->RunAsync()); |
399 | 399 |
400 EXPECT_FALSE(window1_state->IsMinimized()); | 400 EXPECT_FALSE(window1_state->IsMinimized()); |
401 EXPECT_FALSE(window2_state->IsMinimized()); | 401 EXPECT_FALSE(window2_state->IsMinimized()); |
402 EXPECT_FALSE(window3_state->IsMinimized()); | 402 EXPECT_FALSE(window3_state->IsMinimized()); |
403 } | 403 } |
404 | 404 |
405 } // namespace chromeos | 405 } // namespace chromeos |
OLD | NEW |