Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: ash/wm/activation_controller_unittest.cc

Issue 11421006: Desktop aura: Break aura::Window::SetParent in two. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Further renames for oshima Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/wm/activation_controller.h" 5 #include "ash/wm/activation_controller.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/shell_window_ids.h" 8 #include "ash/shell_window_ids.h"
9 #include "ash/test/ash_test_base.h" 9 #include "ash/test/ash_test_base.h"
10 #include "ash/test/test_activation_delegate.h" 10 #include "ash/test/test_activation_delegate.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 aura::Window* w7() { return w7_.get(); } 65 aura::Window* w7() { return w7_.get(); }
66 66
67 void DestroyWindow2() { 67 void DestroyWindow2() {
68 w2_.reset(); 68 w2_.reset();
69 } 69 }
70 70
71 private: 71 private:
72 void CreateWindows() { 72 void CreateWindows() {
73 // Create four windows, the first and third are not activatable, the second 73 // Create four windows, the first and third are not activatable, the second
74 // and fourth are. 74 // and fourth are.
75 w1_.reset(CreateWindow(1, &ad_1_, kDefaultContainerID)); 75 w1_.reset(CreateWindowInShell(1, &ad_1_));
76 w2_.reset(CreateWindow(2, &ad_2_, kDefaultContainerID)); 76 w2_.reset(CreateWindowInShell(2, &ad_2_));
77 w3_.reset(CreateWindow(3, &ad_3_, kDefaultContainerID)); 77 w3_.reset(CreateWindowInShell(3, &ad_3_));
78 w4_.reset(CreateWindow(4, &ad_4_, kDefaultContainerID)); 78 w4_.reset(CreateWindowInShell(4, &ad_4_));
79 w5_.reset(CreateWindow(5, &ad_5_, c2)); 79 w5_.reset(CreateWindowWithID(5, &ad_5_, c2));
80 w6_.reset(CreateWindow(6, &ad_6_, c2)); 80 w6_.reset(CreateWindowWithID(6, &ad_6_, c2));
81 w7_.reset(CreateWindow(7, &ad_7_, c3)); 81 w7_.reset(CreateWindowWithID(7, &ad_7_, c3));
82 } 82 }
83 83
84 aura::Window* CreateWindow(int id, 84 aura::Window* CreateWindowInShell(int id,
85 TestActivationDelegate* delegate, 85 TestActivationDelegate* delegate) {
86 int container_id) { 86 aura::Window* window = CreateTestWindowInShellWithDelegate(
87 aura::Window* parent = container_id == kDefaultContainerID ? NULL : 87 &delegate_,
88 id,
89 gfx::Rect());
90 delegate->SetWindow(window);
91 return window;
92 }
93
94 aura::Window* CreateWindowWithID(int id,
95 TestActivationDelegate* delegate,
96 int container_id) {
97 aura::Window* parent =
88 Shell::GetContainer(Shell::GetPrimaryRootWindow(), container_id); 98 Shell::GetContainer(Shell::GetPrimaryRootWindow(), container_id);
89 aura::Window* window = aura::test::CreateTestWindowWithDelegate( 99 aura::Window* window = aura::test::CreateTestWindowWithDelegate(
90 &delegate_, 100 &delegate_,
91 id, 101 id,
92 gfx::Rect(), 102 gfx::Rect(),
93 parent); 103 parent);
94 delegate->SetWindow(window); 104 delegate->SetWindow(window);
95 return window; 105 return window;
96 } 106 }
97 107
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 EXPECT_TRUE(wm::IsActiveWindow(w4())); 195 EXPECT_TRUE(wm::IsActiveWindow(w4()));
186 } 196 }
187 197
188 // Test if the clicking on a menu picks the transient parent as activatable 198 // Test if the clicking on a menu picks the transient parent as activatable
189 // window. 199 // window.
190 TEST_F(ActivationControllerTest, ClickOnMenu) { 200 TEST_F(ActivationControllerTest, ClickOnMenu) {
191 aura::test::TestWindowDelegate wd; 201 aura::test::TestWindowDelegate wd;
192 TestActivationDelegate ad1; 202 TestActivationDelegate ad1;
193 TestActivationDelegate ad2(false); 203 TestActivationDelegate ad2(false);
194 204
195 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( 205 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(
196 &wd, 1, gfx::Rect(100, 100), NULL)); 206 &wd, 1, gfx::Rect(100, 100)));
197 ad1.SetWindow(w1.get()); 207 ad1.SetWindow(w1.get());
198 EXPECT_EQ(NULL, wm::GetActiveWindow()); 208 EXPECT_EQ(NULL, wm::GetActiveWindow());
199 209
200 // Clicking on an activatable window activates the window. 210 // Clicking on an activatable window activates the window.
201 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), w1.get()); 211 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), w1.get());
202 generator.ClickLeftButton(); 212 generator.ClickLeftButton();
203 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 213 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
204 214
205 // Creates a menu that covers the transient parent. 215 // Creates a menu that covers the transient parent.
206 scoped_ptr<aura::Window> menu(aura::test::CreateTestWindowWithDelegateAndType( 216 scoped_ptr<aura::Window> menu(CreateTestWindowInShellWithDelegateAndType(
207 &wd, aura::client::WINDOW_TYPE_MENU, 2, gfx::Rect(100, 100), NULL)); 217 &wd, aura::client::WINDOW_TYPE_MENU, 2, gfx::Rect(100, 100)));
208 ad2.SetWindow(menu.get()); 218 ad2.SetWindow(menu.get());
209 w1->AddTransientChild(menu.get()); 219 w1->AddTransientChild(menu.get());
210 220
211 // Clicking on a menu whose transient parent is active window shouldn't 221 // Clicking on a menu whose transient parent is active window shouldn't
212 // change the active window. 222 // change the active window.
213 generator.ClickLeftButton(); 223 generator.ClickLeftButton();
214 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 224 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
215 } 225 }
216 226
217 // Various assertions for activating/deactivating. 227 // Various assertions for activating/deactivating.
218 TEST_F(ActivationControllerTest, Deactivate) { 228 TEST_F(ActivationControllerTest, Deactivate) {
219 aura::test::TestWindowDelegate d1; 229 aura::test::TestWindowDelegate d1;
220 aura::test::TestWindowDelegate d2; 230 aura::test::TestWindowDelegate d2;
221 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( 231 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(
222 &d1, 1, gfx::Rect(), NULL)); 232 &d1, 1, gfx::Rect()));
223 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( 233 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate(
224 &d2, 2, gfx::Rect(), NULL)); 234 &d2, 2, gfx::Rect()));
225 aura::Window* parent = w1->parent(); 235 aura::Window* parent = w1->parent();
226 parent->Show(); 236 parent->Show();
227 ASSERT_TRUE(parent); 237 ASSERT_TRUE(parent);
228 ASSERT_EQ(2u, parent->children().size()); 238 ASSERT_EQ(2u, parent->children().size());
229 // Activate w2 and make sure it's active and frontmost. 239 // Activate w2 and make sure it's active and frontmost.
230 wm::ActivateWindow(w2.get()); 240 wm::ActivateWindow(w2.get());
231 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); 241 EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
232 EXPECT_FALSE(wm::IsActiveWindow(w1.get())); 242 EXPECT_FALSE(wm::IsActiveWindow(w1.get()));
233 EXPECT_EQ(w2.get(), parent->children()[1]); 243 EXPECT_EQ(w2.get(), parent->children()[1]);
234 244
235 // Activate w1 and make sure it's active and frontmost. 245 // Activate w1 and make sure it's active and frontmost.
236 wm::ActivateWindow(w1.get()); 246 wm::ActivateWindow(w1.get());
237 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 247 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
238 EXPECT_FALSE(wm::IsActiveWindow(w2.get())); 248 EXPECT_FALSE(wm::IsActiveWindow(w2.get()));
239 EXPECT_EQ(w1.get(), parent->children()[1]); 249 EXPECT_EQ(w1.get(), parent->children()[1]);
240 250
241 // Deactivate w1 and make sure w2 becomes active and frontmost. 251 // Deactivate w1 and make sure w2 becomes active and frontmost.
242 wm::DeactivateWindow(w1.get()); 252 wm::DeactivateWindow(w1.get());
243 EXPECT_FALSE(wm::IsActiveWindow(w1.get())); 253 EXPECT_FALSE(wm::IsActiveWindow(w1.get()));
244 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); 254 EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
245 EXPECT_EQ(w2.get(), parent->children()[1]); 255 EXPECT_EQ(w2.get(), parent->children()[1]);
246 } 256 }
247 257
248 // Verifies that when WindowDelegate::OnLostActive is invoked the window is not 258 // Verifies that when WindowDelegate::OnLostActive is invoked the window is not
249 // active. 259 // active.
250 TEST_F(ActivationControllerTest, NotActiveInLostActive) { 260 TEST_F(ActivationControllerTest, NotActiveInLostActive) {
251 TestActivationDelegate ad1; 261 TestActivationDelegate ad1;
252 aura::test::TestWindowDelegate wd; 262 aura::test::TestWindowDelegate wd;
253 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( 263 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(
254 &wd, 1, gfx::Rect(10, 10, 50, 50), NULL)); 264 &wd, 1, gfx::Rect(10, 10, 50, 50)));
255 ad1.SetWindow(w1.get()); 265 ad1.SetWindow(w1.get());
256 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( 266 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate(
257 NULL, 1, gfx::Rect(10, 10, 50, 50), NULL)); 267 NULL, 1, gfx::Rect(10, 10, 50, 50)));
258 268
259 // Activate w1. 269 // Activate w1.
260 wm::ActivateWindow(w1.get()); 270 wm::ActivateWindow(w1.get());
261 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 271 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
262 EXPECT_EQ(1, ad1.activated_count()); 272 EXPECT_EQ(1, ad1.activated_count());
263 // Should not have gotten a OnLostActive yet. 273 // Should not have gotten a OnLostActive yet.
264 EXPECT_EQ(0, ad1.lost_active_count()); 274 EXPECT_EQ(0, ad1.lost_active_count());
265 275
266 // Deactivate the active window. 276 // Deactivate the active window.
267 wm::DeactivateWindow(w1.get()); 277 wm::DeactivateWindow(w1.get());
(...skipping 16 matching lines...) Expand all
284 // active window in OnLostActive. 294 // active window in OnLostActive.
285 EXPECT_EQ(0, ad1.activated_count()); 295 EXPECT_EQ(0, ad1.activated_count());
286 EXPECT_EQ(1, ad1.lost_active_count()); 296 EXPECT_EQ(1, ad1.lost_active_count());
287 EXPECT_FALSE(ad1.window_was_active()); 297 EXPECT_FALSE(ad1.window_was_active());
288 } 298 }
289 299
290 // Verifies that focusing another window or its children causes it to become 300 // Verifies that focusing another window or its children causes it to become
291 // active. 301 // active.
292 TEST_F(ActivationControllerTest, FocusTriggersActivation) { 302 TEST_F(ActivationControllerTest, FocusTriggersActivation) {
293 aura::test::TestWindowDelegate wd; 303 aura::test::TestWindowDelegate wd;
294 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( 304 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(
295 &wd, -1, gfx::Rect(50, 50), NULL)); 305 &wd, -1, gfx::Rect(50, 50)));
296 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( 306 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate(
297 &wd, -2, gfx::Rect(50, 50), NULL)); 307 &wd, -2, gfx::Rect(50, 50)));
298 scoped_ptr<aura::Window> w21(aura::test::CreateTestWindowWithDelegate( 308 scoped_ptr<aura::Window> w21(aura::test::CreateTestWindowWithDelegate(
299 &wd, -21, gfx::Rect(50, 50), w2.get())); 309 &wd, -21, gfx::Rect(50, 50), w2.get()));
300 310
301 wm::ActivateWindow(w1.get()); 311 wm::ActivateWindow(w1.get());
302 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 312 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
303 EXPECT_TRUE(w1->HasFocus()); 313 EXPECT_TRUE(w1->HasFocus());
304 314
305 w2->Focus(); 315 w2->Focus();
306 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); 316 EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
307 EXPECT_TRUE(w2->HasFocus()); 317 EXPECT_TRUE(w2->HasFocus());
308 318
309 wm::ActivateWindow(w1.get()); 319 wm::ActivateWindow(w1.get());
310 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 320 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
311 EXPECT_TRUE(w1->HasFocus()); 321 EXPECT_TRUE(w1->HasFocus());
312 322
313 w21->Focus(); 323 w21->Focus();
314 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); 324 EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
315 EXPECT_TRUE(w21->HasFocus()); 325 EXPECT_TRUE(w21->HasFocus());
316 } 326 }
317 327
318 // Verifies that we prevent all attempts to focus a child of a non-activatable 328 // Verifies that we prevent all attempts to focus a child of a non-activatable
319 // window from claiming focus to that window. 329 // window from claiming focus to that window.
320 TEST_F(ActivationControllerTest, PreventFocusToNonActivatableWindow) { 330 TEST_F(ActivationControllerTest, PreventFocusToNonActivatableWindow) {
321 aura::test::TestWindowDelegate wd; 331 aura::test::TestWindowDelegate wd;
322 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( 332 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(
323 &wd, -1, gfx::Rect(50, 50), NULL)); 333 &wd, -1, gfx::Rect(50, 50)));
324 // The RootWindow is a non-activatable parent. 334 // The RootWindow is a non-activatable parent.
325 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( 335 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate(
326 &wd, -2, gfx::Rect(50, 50), Shell::GetPrimaryRootWindow())); 336 &wd, -2, gfx::Rect(50, 50), Shell::GetPrimaryRootWindow()));
327 scoped_ptr<aura::Window> w21(aura::test::CreateTestWindowWithDelegate( 337 scoped_ptr<aura::Window> w21(aura::test::CreateTestWindowWithDelegate(
328 &wd, -21, gfx::Rect(50, 50), w2.get())); 338 &wd, -21, gfx::Rect(50, 50), w2.get()));
329 339
330 wm::ActivateWindow(w1.get()); 340 wm::ActivateWindow(w1.get());
331 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 341 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
332 EXPECT_TRUE(w1->HasFocus()); 342 EXPECT_TRUE(w1->HasFocus());
333 343
(...skipping 17 matching lines...) Expand all
351 EXPECT_FALSE(w21->HasFocus()); 361 EXPECT_FALSE(w21->HasFocus());
352 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 362 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
353 EXPECT_TRUE(w1->HasFocus()); 363 EXPECT_TRUE(w1->HasFocus());
354 } 364 }
355 365
356 TEST_F(ActivationControllerTest, CanActivateWindowIteselfTest) 366 TEST_F(ActivationControllerTest, CanActivateWindowIteselfTest)
357 { 367 {
358 aura::test::TestWindowDelegate wd; 368 aura::test::TestWindowDelegate wd;
359 369
360 // Normal Window 370 // Normal Window
361 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( 371 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(
362 &wd, -1, gfx::Rect(50, 50), NULL)); 372 &wd, -1, gfx::Rect(50, 50)));
363 EXPECT_TRUE(wm::CanActivateWindow(w1.get())); 373 EXPECT_TRUE(wm::CanActivateWindow(w1.get()));
364 374
365 // The RootWindow is a non-activatable parent. 375 // The RootWindow is a non-activatable parent.
366 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( 376 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate(
367 &wd, -2, gfx::Rect(50, 50), Shell::GetPrimaryRootWindow())); 377 &wd, -2, gfx::Rect(50, 50), Shell::GetPrimaryRootWindow()));
368 scoped_ptr<aura::Window> w21(aura::test::CreateTestWindowWithDelegate( 378 scoped_ptr<aura::Window> w21(aura::test::CreateTestWindowWithDelegate(
369 &wd, -21, gfx::Rect(50, 50), w2.get())); 379 &wd, -21, gfx::Rect(50, 50), w2.get()));
370 EXPECT_FALSE(wm::CanActivateWindow(w2.get())); 380 EXPECT_FALSE(wm::CanActivateWindow(w2.get()));
371 EXPECT_FALSE(wm::CanActivateWindow(w21.get())); 381 EXPECT_FALSE(wm::CanActivateWindow(w21.get()));
372 382
373 // The window has a transient child. 383 // The window has a transient child.
374 scoped_ptr<aura::Window> w3(aura::test::CreateTestWindowWithDelegate( 384 scoped_ptr<aura::Window> w3(CreateTestWindowInShellWithDelegate(
375 &wd, -3, gfx::Rect(50, 50), NULL)); 385 &wd, -3, gfx::Rect(50, 50)));
376 scoped_ptr<aura::Window> w31(aura::test::CreateTestWindowWithDelegate( 386 scoped_ptr<aura::Window> w31(CreateTestWindowInShellWithDelegate(
377 &wd, -31, gfx::Rect(50, 50), NULL)); 387 &wd, -31, gfx::Rect(50, 50)));
378 w3->AddTransientChild(w31.get()); 388 w3->AddTransientChild(w31.get());
379 EXPECT_TRUE(wm::CanActivateWindow(w3.get())); 389 EXPECT_TRUE(wm::CanActivateWindow(w3.get()));
380 EXPECT_TRUE(wm::CanActivateWindow(w31.get())); 390 EXPECT_TRUE(wm::CanActivateWindow(w31.get()));
381 391
382 // The window has a transient window-modal child. 392 // The window has a transient window-modal child.
383 scoped_ptr<aura::Window> w4(aura::test::CreateTestWindowWithDelegate( 393 scoped_ptr<aura::Window> w4(CreateTestWindowInShellWithDelegate(
384 &wd, -4, gfx::Rect(50, 50), NULL)); 394 &wd, -4, gfx::Rect(50, 50)));
385 scoped_ptr<aura::Window> w41(aura::test::CreateTestWindowWithDelegate( 395 scoped_ptr<aura::Window> w41(CreateTestWindowInShellWithDelegate(
386 &wd, -41, gfx::Rect(50, 50), NULL)); 396 &wd, -41, gfx::Rect(50, 50)));
387 w4->AddTransientChild(w41.get()); 397 w4->AddTransientChild(w41.get());
388 w41->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); 398 w41->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
389 EXPECT_FALSE(wm::CanActivateWindow(w4.get())); 399 EXPECT_FALSE(wm::CanActivateWindow(w4.get()));
390 EXPECT_TRUE(wm::CanActivateWindow(w41.get())); 400 EXPECT_TRUE(wm::CanActivateWindow(w41.get()));
391 401
392 // The window has a transient system-modal child. 402 // The window has a transient system-modal child.
393 scoped_ptr<aura::Window> w5(aura::test::CreateTestWindowWithDelegate( 403 scoped_ptr<aura::Window> w5(CreateTestWindowInShellWithDelegate(
394 &wd, -5, gfx::Rect(50, 50), NULL)); 404 &wd, -5, gfx::Rect(50, 50)));
395 scoped_ptr<aura::Window> w51(aura::test::CreateTestWindowWithDelegate( 405 scoped_ptr<aura::Window> w51(CreateTestWindowInShellWithDelegate(
396 &wd, -51, gfx::Rect(50, 50), NULL)); 406 &wd, -51, gfx::Rect(50, 50)));
397 w5->AddTransientChild(w51.get()); 407 w5->AddTransientChild(w51.get());
398 w51->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); 408 w51->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM);
399 EXPECT_TRUE(wm::CanActivateWindow(w5.get())); 409 EXPECT_TRUE(wm::CanActivateWindow(w5.get()));
400 EXPECT_TRUE(wm::CanActivateWindow(w51.get())); 410 EXPECT_TRUE(wm::CanActivateWindow(w51.get()));
401 } 411 }
402 412
403 // Verifies code in ActivationController::OnWindowVisibilityChanged() that keeps 413 // Verifies code in ActivationController::OnWindowVisibilityChanged() that keeps
404 // hiding windows layers stacked above the newly active window while they 414 // hiding windows layers stacked above the newly active window while they
405 // animate away. 415 // animate away.
406 TEST_F(ActivationControllerTest, AnimateHideMaintainsStacking) { 416 TEST_F(ActivationControllerTest, AnimateHideMaintainsStacking) {
407 aura::test::TestWindowDelegate wd; 417 aura::test::TestWindowDelegate wd;
408 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( 418 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(
409 &wd, -1, gfx::Rect(50, 50, 50, 50), NULL)); 419 &wd, -1, gfx::Rect(50, 50, 50, 50)));
410 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( 420 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate(
411 &wd, -2, gfx::Rect(75, 75, 50, 50), NULL)); 421 &wd, -2, gfx::Rect(75, 75, 50, 50)));
412 wm::ActivateWindow(w2.get()); 422 wm::ActivateWindow(w2.get());
413 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); 423 EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
414 w2->Hide(); 424 w2->Hide();
415 typedef std::vector<ui::Layer*> Layers; 425 typedef std::vector<ui::Layer*> Layers;
416 const Layers& children = w1->parent()->layer()->children(); 426 const Layers& children = w1->parent()->layer()->children();
417 Layers::const_iterator w1_iter = 427 Layers::const_iterator w1_iter =
418 std::find(children.begin(), children.end(), w1->layer()); 428 std::find(children.begin(), children.end(), w1->layer());
419 Layers::const_iterator w2_iter = 429 Layers::const_iterator w2_iter =
420 std::find(children.begin(), children.end(), w2->layer()); 430 std::find(children.begin(), children.end(), w2->layer());
421 EXPECT_TRUE(w2_iter > w1_iter); 431 EXPECT_TRUE(w2_iter > w1_iter);
422 } 432 }
423 433
424 // Verifies that activating a minimized window would restore it. 434 // Verifies that activating a minimized window would restore it.
425 TEST_F(ActivationControllerTest, ActivateMinimizedWindow) { 435 TEST_F(ActivationControllerTest, ActivateMinimizedWindow) {
426 aura::test::TestWindowDelegate wd; 436 aura::test::TestWindowDelegate wd;
427 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( 437 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(
428 &wd, -1, gfx::Rect(50, 50), NULL)); 438 &wd, -1, gfx::Rect(50, 50)));
429 439
430 wm::MinimizeWindow(w1.get()); 440 wm::MinimizeWindow(w1.get());
431 EXPECT_TRUE(wm::IsWindowMinimized(w1.get())); 441 EXPECT_TRUE(wm::IsWindowMinimized(w1.get()));
432 442
433 wm::ActivateWindow(w1.get()); 443 wm::ActivateWindow(w1.get());
434 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 444 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
435 EXPECT_FALSE(wm::IsWindowMinimized(w1.get())); 445 EXPECT_FALSE(wm::IsWindowMinimized(w1.get()));
436 } 446 }
437 447
438 // Verifies that a minimized window would not be automatically activated as 448 // Verifies that a minimized window would not be automatically activated as
439 // a replacement active window. 449 // a replacement active window.
440 TEST_F(ActivationControllerTest, NoAutoActivateMinimizedWindow) { 450 TEST_F(ActivationControllerTest, NoAutoActivateMinimizedWindow) {
441 aura::test::TestWindowDelegate wd; 451 aura::test::TestWindowDelegate wd;
442 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( 452 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(
443 &wd, -1, gfx::Rect(50, 50, 50, 50), NULL)); 453 &wd, -1, gfx::Rect(50, 50, 50, 50)));
444 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( 454 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate(
445 &wd, -2, gfx::Rect(75, 75, 50, 50), NULL)); 455 &wd, -2, gfx::Rect(75, 75, 50, 50)));
446 456
447 wm::MinimizeWindow(w1.get()); 457 wm::MinimizeWindow(w1.get());
448 EXPECT_TRUE(wm::IsWindowMinimized(w1.get())); 458 EXPECT_TRUE(wm::IsWindowMinimized(w1.get()));
449 459
450 wm::ActivateWindow(w2.get()); 460 wm::ActivateWindow(w2.get());
451 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); 461 EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
452 462
453 w2->Hide(); 463 w2->Hide();
454 464
455 EXPECT_FALSE(wm::IsActiveWindow(w1.get())); 465 EXPECT_FALSE(wm::IsActiveWindow(w1.get()));
456 EXPECT_TRUE(wm::IsWindowMinimized(w1.get())); 466 EXPECT_TRUE(wm::IsWindowMinimized(w1.get()));
457 } 467 }
458 468
459 // Verifies that a window with a hidden layer can be activated. 469 // Verifies that a window with a hidden layer can be activated.
460 TEST_F(ActivationControllerTest, ActivateWithHiddenLayer) { 470 TEST_F(ActivationControllerTest, ActivateWithHiddenLayer) {
461 aura::test::TestWindowDelegate wd; 471 aura::test::TestWindowDelegate wd;
462 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( 472 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(
463 &wd, -1, gfx::Rect(50, 50, 50, 50), NULL)); 473 &wd, -1, gfx::Rect(50, 50, 50, 50)));
464 474
465 EXPECT_TRUE(wm::CanActivateWindow(w1.get())); 475 EXPECT_TRUE(wm::CanActivateWindow(w1.get()));
466 w1->layer()->SetVisible(false); 476 w1->layer()->SetVisible(false);
467 EXPECT_TRUE(wm::CanActivateWindow(w1.get())); 477 EXPECT_TRUE(wm::CanActivateWindow(w1.get()));
468 } 478 }
469 479
470 // Verifies that a unrelated window cannot be activated when in a system modal 480 // Verifies that a unrelated window cannot be activated when in a system modal
471 // dialog. 481 // dialog.
472 TEST_F(ActivationControllerTest, DontActivateWindowWhenInSystemModalDialog) { 482 TEST_F(ActivationControllerTest, DontActivateWindowWhenInSystemModalDialog) {
473 scoped_ptr<aura::Window> normal_window( 483 scoped_ptr<aura::Window> normal_window(CreateTestWindowInShellWithId(-1));
474 aura::test::CreateTestWindowWithId(-1, NULL));
475 EXPECT_FALSE(wm::IsActiveWindow(normal_window.get())); 484 EXPECT_FALSE(wm::IsActiveWindow(normal_window.get()));
476 wm::ActivateWindow(normal_window.get()); 485 wm::ActivateWindow(normal_window.get());
477 EXPECT_TRUE(wm::IsActiveWindow(normal_window.get())); 486 EXPECT_TRUE(wm::IsActiveWindow(normal_window.get()));
478 487
479 // Create and activate a system modal window. 488 // Create and activate a system modal window.
480 aura::Window* modal_container = 489 aura::Window* modal_container =
481 ash::Shell::GetContainer( 490 ash::Shell::GetContainer(
482 Shell::GetPrimaryRootWindow(), 491 Shell::GetPrimaryRootWindow(),
483 ash::internal::kShellWindowId_SystemModalContainer); 492 ash::internal::kShellWindowId_SystemModalContainer);
484 scoped_ptr<aura::Window> modal_window( 493 scoped_ptr<aura::Window> modal_window(
(...skipping 26 matching lines...) Expand all
511 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( 520 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate(
512 &wd, -1, gfx::Rect(50, 50, 50, 50), lock_container)); 521 &wd, -1, gfx::Rect(50, 50, 50, 50), lock_container));
513 522
514 lock_container->layer()->SetVisible(false); 523 lock_container->layer()->SetVisible(false);
515 w1->Focus(); 524 w1->Focus();
516 EXPECT_TRUE(w1->HasFocus()); 525 EXPECT_TRUE(w1->HasFocus());
517 } 526 }
518 527
519 } // namespace test 528 } // namespace test
520 } // namespace ash 529 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698