| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/wm/activation_controller.h" | |
| 6 | |
| 7 #include "ash/shell.h" | |
| 8 #include "ash/shell_window_ids.h" | |
| 9 #include "ash/test/ash_test_base.h" | |
| 10 #include "ash/test/test_activation_delegate.h" | |
| 11 #include "ash/wm/window_util.h" | |
| 12 #include "ui/aura/client/aura_constants.h" | |
| 13 #include "ui/aura/root_window.h" | |
| 14 #include "ui/aura/test/event_generator.h" | |
| 15 #include "ui/aura/test/test_window_delegate.h" | |
| 16 #include "ui/aura/test/test_windows.h" | |
| 17 #include "ui/compositor/layer.h" | |
| 18 #include "ui/views/corewm/corewm_switches.h" | |
| 19 | |
| 20 #if defined(OS_WIN) | |
| 21 // Windows headers define macros for these function names which screw with us. | |
| 22 #if defined(CreateWindow) | |
| 23 #undef CreateWindow | |
| 24 #endif | |
| 25 #endif | |
| 26 | |
| 27 namespace { | |
| 28 | |
| 29 // Containers used for the tests. | |
| 30 const int kDefaultContainerID = -1; // Used to identify the default container. | |
| 31 const int c2 = ash::internal::kShellWindowId_AlwaysOnTopContainer; | |
| 32 const int c3 = ash::internal::kShellWindowId_LockScreenContainer; | |
| 33 | |
| 34 } // namespace | |
| 35 | |
| 36 namespace ash { | |
| 37 namespace test { | |
| 38 | |
| 39 typedef test::AshTestBase ActivationControllerTest; | |
| 40 | |
| 41 // Utilities for a set of tests that test | |
| 42 // ActivationController::GetTopmostWindowToActivate(). | |
| 43 class GetTopmostWindowToActivateTest : public ActivationControllerTest { | |
| 44 public: | |
| 45 GetTopmostWindowToActivateTest() : ad_1_(false), ad_3_(false) {} | |
| 46 virtual ~GetTopmostWindowToActivateTest() {} | |
| 47 | |
| 48 // Overridden from ActivationControllerTest: | |
| 49 virtual void SetUp() OVERRIDE { | |
| 50 ActivationControllerTest::SetUp(); | |
| 51 CreateWindows(); | |
| 52 } | |
| 53 virtual void TearDown() OVERRIDE { | |
| 54 DestroyWindows(); | |
| 55 ActivationControllerTest::TearDown(); | |
| 56 } | |
| 57 | |
| 58 protected: | |
| 59 aura::Window* w1() { return w1_.get(); } | |
| 60 aura::Window* w2() { return w2_.get(); } | |
| 61 aura::Window* w3() { return w3_.get(); } | |
| 62 aura::Window* w4() { return w4_.get(); } | |
| 63 aura::Window* w5() { return w5_.get(); } | |
| 64 aura::Window* w6() { return w6_.get(); } | |
| 65 aura::Window* w7() { return w7_.get(); } | |
| 66 | |
| 67 void DestroyWindow2() { | |
| 68 w2_.reset(); | |
| 69 } | |
| 70 | |
| 71 private: | |
| 72 void CreateWindows() { | |
| 73 // Create four windows, the first and third are not activatable, the second | |
| 74 // and fourth are. | |
| 75 w1_.reset(CreateWindowInShell(1, &ad_1_)); | |
| 76 w2_.reset(CreateWindowInShell(2, &ad_2_)); | |
| 77 w3_.reset(CreateWindowInShell(3, &ad_3_)); | |
| 78 w4_.reset(CreateWindowInShell(4, &ad_4_)); | |
| 79 w5_.reset(CreateWindowWithID(5, &ad_5_, c2)); | |
| 80 w6_.reset(CreateWindowWithID(6, &ad_6_, c2)); | |
| 81 w7_.reset(CreateWindowWithID(7, &ad_7_, c3)); | |
| 82 } | |
| 83 | |
| 84 aura::Window* CreateWindowInShell(int id, | |
| 85 TestActivationDelegate* delegate) { | |
| 86 aura::Window* window = CreateTestWindowInShellWithDelegate( | |
| 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 = | |
| 98 Shell::GetContainer(Shell::GetPrimaryRootWindow(), container_id); | |
| 99 aura::Window* window = aura::test::CreateTestWindowWithDelegate( | |
| 100 &delegate_, | |
| 101 id, | |
| 102 gfx::Rect(), | |
| 103 parent); | |
| 104 delegate->SetWindow(window); | |
| 105 return window; | |
| 106 } | |
| 107 | |
| 108 void DestroyWindows() { | |
| 109 w1_.reset(); | |
| 110 w2_.reset(); | |
| 111 w3_.reset(); | |
| 112 w4_.reset(); | |
| 113 w5_.reset(); | |
| 114 w6_.reset(); | |
| 115 w7_.reset(); | |
| 116 } | |
| 117 | |
| 118 aura::test::TestWindowDelegate delegate_; | |
| 119 TestActivationDelegate ad_1_; | |
| 120 TestActivationDelegate ad_2_; | |
| 121 TestActivationDelegate ad_3_; | |
| 122 TestActivationDelegate ad_4_; | |
| 123 TestActivationDelegate ad_5_; | |
| 124 TestActivationDelegate ad_6_; | |
| 125 TestActivationDelegate ad_7_; | |
| 126 scoped_ptr<aura::Window> w1_; // Non-activatable. | |
| 127 scoped_ptr<aura::Window> w2_; // Activatable. | |
| 128 scoped_ptr<aura::Window> w3_; // Non-activatable. | |
| 129 scoped_ptr<aura::Window> w4_; // Activatable. | |
| 130 scoped_ptr<aura::Window> w5_; // Activatable - Always on top. | |
| 131 scoped_ptr<aura::Window> w6_; // Activatable - Always on top. | |
| 132 scoped_ptr<aura::Window> w7_; // Activatable - Lock screen window. | |
| 133 | |
| 134 DISALLOW_COPY_AND_ASSIGN(GetTopmostWindowToActivateTest); | |
| 135 }; | |
| 136 | |
| 137 // Hiding the active window should activate the next valid activatable window. | |
| 138 TEST_F(GetTopmostWindowToActivateTest, HideActivatesNext) { | |
| 139 wm::ActivateWindow(w2()); | |
| 140 EXPECT_TRUE(wm::IsActiveWindow(w2())); | |
| 141 | |
| 142 w2()->Hide(); | |
| 143 EXPECT_TRUE(wm::IsActiveWindow(w4())); | |
| 144 } | |
| 145 | |
| 146 // Destroying the active window should activate the next valid activatable | |
| 147 // window. | |
| 148 TEST_F(GetTopmostWindowToActivateTest, DestroyActivatesNext) { | |
| 149 wm::ActivateWindow(w2()); | |
| 150 EXPECT_TRUE(wm::IsActiveWindow(w2())); | |
| 151 | |
| 152 DestroyWindow2(); | |
| 153 EXPECT_EQ(NULL, w2()); | |
| 154 EXPECT_TRUE(wm::IsActiveWindow(w4())); | |
| 155 } | |
| 156 | |
| 157 // Deactivating the active window should activate the next valid activatable | |
| 158 // window. | |
| 159 TEST_F(GetTopmostWindowToActivateTest, DeactivateActivatesNext) { | |
| 160 wm::ActivateWindow(w2()); | |
| 161 EXPECT_TRUE(wm::IsActiveWindow(w2())); | |
| 162 | |
| 163 wm::DeactivateWindow(w2()); | |
| 164 EXPECT_TRUE(wm::IsActiveWindow(w4())); | |
| 165 } | |
| 166 | |
| 167 // Test that hiding a window in a higher container will activate another window | |
| 168 // in that container. | |
| 169 TEST_F(GetTopmostWindowToActivateTest, HideActivatesSameContainer) { | |
| 170 wm::ActivateWindow(w6()); | |
| 171 EXPECT_TRUE(wm::IsActiveWindow(w6())); | |
| 172 | |
| 173 w6()->Hide(); | |
| 174 EXPECT_TRUE(wm::IsActiveWindow(w5())); | |
| 175 } | |
| 176 | |
| 177 // Test that hiding the lock window will activate a window from the next highest | |
| 178 // container. | |
| 179 TEST_F(GetTopmostWindowToActivateTest, UnlockActivatesNextHighestContainer) { | |
| 180 wm::ActivateWindow(w7()); | |
| 181 EXPECT_TRUE(wm::IsActiveWindow(w7())); | |
| 182 | |
| 183 w7()->Hide(); | |
| 184 EXPECT_TRUE(wm::IsActiveWindow(w6())); | |
| 185 } | |
| 186 | |
| 187 // Test that hiding a window in a higher container with no other windows will | |
| 188 // activate a window in a lower container. | |
| 189 TEST_F(GetTopmostWindowToActivateTest, HideActivatesNextHighestContainer) { | |
| 190 w5()->Hide(); | |
| 191 wm::ActivateWindow(w6()); | |
| 192 EXPECT_TRUE(wm::IsActiveWindow(w6())); | |
| 193 | |
| 194 w6()->Hide(); | |
| 195 EXPECT_TRUE(wm::IsActiveWindow(w4())); | |
| 196 } | |
| 197 | |
| 198 // Test if the clicking on a menu picks the transient parent as activatable | |
| 199 // window. | |
| 200 TEST_F(ActivationControllerTest, ClickOnMenu) { | |
| 201 aura::test::TestWindowDelegate wd; | |
| 202 TestActivationDelegate ad1; | |
| 203 TestActivationDelegate ad2(false); | |
| 204 | |
| 205 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( | |
| 206 &wd, 1, gfx::Rect(100, 100))); | |
| 207 ad1.SetWindow(w1.get()); | |
| 208 EXPECT_EQ(NULL, wm::GetActiveWindow()); | |
| 209 | |
| 210 // Clicking on an activatable window activates the window. | |
| 211 aura::test::EventGenerator& generator(GetEventGenerator()); | |
| 212 generator.MoveMouseToCenterOf(w1.get()); | |
| 213 generator.ClickLeftButton(); | |
| 214 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | |
| 215 | |
| 216 // Creates a menu that covers the transient parent. | |
| 217 scoped_ptr<aura::Window> menu(CreateTestWindowInShellWithDelegateAndType( | |
| 218 &wd, aura::client::WINDOW_TYPE_MENU, 2, gfx::Rect(100, 100))); | |
| 219 ad2.SetWindow(menu.get()); | |
| 220 w1->AddTransientChild(menu.get()); | |
| 221 | |
| 222 // Clicking on a menu whose transient parent is active window shouldn't | |
| 223 // change the active window. | |
| 224 generator.ClickLeftButton(); | |
| 225 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | |
| 226 } | |
| 227 | |
| 228 // Various assertions for activating/deactivating. | |
| 229 TEST_F(ActivationControllerTest, Deactivate) { | |
| 230 aura::test::TestWindowDelegate d1; | |
| 231 aura::test::TestWindowDelegate d2; | |
| 232 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( | |
| 233 &d1, 1, gfx::Rect())); | |
| 234 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate( | |
| 235 &d2, 2, gfx::Rect())); | |
| 236 aura::Window* parent = w1->parent(); | |
| 237 parent->Show(); | |
| 238 ASSERT_TRUE(parent); | |
| 239 ASSERT_EQ(2u, parent->children().size()); | |
| 240 // Activate w2 and make sure it's active and frontmost. | |
| 241 wm::ActivateWindow(w2.get()); | |
| 242 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | |
| 243 EXPECT_FALSE(wm::IsActiveWindow(w1.get())); | |
| 244 EXPECT_EQ(w2.get(), parent->children()[1]); | |
| 245 | |
| 246 // Activate w1 and make sure it's active and frontmost. | |
| 247 wm::ActivateWindow(w1.get()); | |
| 248 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | |
| 249 EXPECT_FALSE(wm::IsActiveWindow(w2.get())); | |
| 250 EXPECT_EQ(w1.get(), parent->children()[1]); | |
| 251 | |
| 252 // Deactivate w1 and make sure w2 becomes active and frontmost. | |
| 253 wm::DeactivateWindow(w1.get()); | |
| 254 EXPECT_FALSE(wm::IsActiveWindow(w1.get())); | |
| 255 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | |
| 256 EXPECT_EQ(w2.get(), parent->children()[1]); | |
| 257 } | |
| 258 | |
| 259 // Verifies that when WindowDelegate::OnLostActive is invoked the window is not | |
| 260 // active. | |
| 261 TEST_F(ActivationControllerTest, NotActiveInLostActive) { | |
| 262 // TODO(beng): remove this test once the new focus controller is on. | |
| 263 if (views::corewm::UseFocusController()) | |
| 264 return; | |
| 265 | |
| 266 TestActivationDelegate ad1; | |
| 267 aura::test::TestWindowDelegate wd; | |
| 268 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( | |
| 269 &wd, 1, gfx::Rect(10, 10, 50, 50))); | |
| 270 ad1.SetWindow(w1.get()); | |
| 271 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate( | |
| 272 NULL, 1, gfx::Rect(10, 10, 50, 50))); | |
| 273 | |
| 274 // Activate w1. | |
| 275 wm::ActivateWindow(w1.get()); | |
| 276 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | |
| 277 EXPECT_EQ(1, ad1.activated_count()); | |
| 278 // Should not have gotten a OnLostActive yet. | |
| 279 EXPECT_EQ(0, ad1.lost_active_count()); | |
| 280 | |
| 281 // Deactivate the active window. | |
| 282 wm::DeactivateWindow(w1.get()); | |
| 283 EXPECT_FALSE(wm::IsActiveWindow(w1.get())); | |
| 284 EXPECT_EQ(1, ad1.lost_active_count()); | |
| 285 EXPECT_FALSE(ad1.window_was_active()); | |
| 286 | |
| 287 // Activate w1 again. w1 should have gotten OnActivated. | |
| 288 wm::ActivateWindow(w1.get()); | |
| 289 EXPECT_EQ(2, ad1.activated_count()); | |
| 290 EXPECT_EQ(1, ad1.lost_active_count()); | |
| 291 | |
| 292 // Reset the delegate. | |
| 293 ad1.Clear(); | |
| 294 | |
| 295 // Now activate another window. | |
| 296 wm::ActivateWindow(w2.get()); | |
| 297 | |
| 298 // Should have gotten OnLostActive and w1 shoouldn't have been | |
| 299 // active window in OnLostActive. | |
| 300 EXPECT_EQ(0, ad1.activated_count()); | |
| 301 EXPECT_EQ(1, ad1.lost_active_count()); | |
| 302 EXPECT_FALSE(ad1.window_was_active()); | |
| 303 } | |
| 304 | |
| 305 // Verifies that focusing another window or its children causes it to become | |
| 306 // active. | |
| 307 TEST_F(ActivationControllerTest, FocusTriggersActivation) { | |
| 308 aura::test::TestWindowDelegate wd; | |
| 309 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( | |
| 310 &wd, -1, gfx::Rect(50, 50))); | |
| 311 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate( | |
| 312 &wd, -2, gfx::Rect(50, 50))); | |
| 313 scoped_ptr<aura::Window> w21(aura::test::CreateTestWindowWithDelegate( | |
| 314 &wd, -21, gfx::Rect(50, 50), w2.get())); | |
| 315 | |
| 316 wm::ActivateWindow(w1.get()); | |
| 317 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | |
| 318 EXPECT_TRUE(w1->HasFocus()); | |
| 319 | |
| 320 w2->Focus(); | |
| 321 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | |
| 322 EXPECT_TRUE(w2->HasFocus()); | |
| 323 | |
| 324 wm::ActivateWindow(w1.get()); | |
| 325 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | |
| 326 EXPECT_TRUE(w1->HasFocus()); | |
| 327 | |
| 328 w21->Focus(); | |
| 329 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | |
| 330 EXPECT_TRUE(w21->HasFocus()); | |
| 331 } | |
| 332 | |
| 333 // Verifies that we prevent all attempts to focus a child of a non-activatable | |
| 334 // window from claiming focus to that window. | |
| 335 TEST_F(ActivationControllerTest, PreventFocusToNonActivatableWindow) { | |
| 336 aura::test::TestWindowDelegate wd; | |
| 337 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( | |
| 338 &wd, -1, gfx::Rect(50, 50))); | |
| 339 // The RootWindow is a non-activatable parent. | |
| 340 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( | |
| 341 &wd, -2, gfx::Rect(50, 50), Shell::GetPrimaryRootWindow())); | |
| 342 scoped_ptr<aura::Window> w21(aura::test::CreateTestWindowWithDelegate( | |
| 343 &wd, -21, gfx::Rect(50, 50), w2.get())); | |
| 344 | |
| 345 wm::ActivateWindow(w1.get()); | |
| 346 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | |
| 347 EXPECT_TRUE(w1->HasFocus()); | |
| 348 | |
| 349 // Try activating |w2|. It's not a child of an activatable container, so it | |
| 350 // should neither be activated nor get focus. | |
| 351 wm::ActivateWindow(w2.get()); | |
| 352 EXPECT_FALSE(wm::IsActiveWindow(w2.get())); | |
| 353 EXPECT_FALSE(w2->HasFocus()); | |
| 354 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | |
| 355 EXPECT_TRUE(w1->HasFocus()); | |
| 356 | |
| 357 // Try focusing |w2|. Same rules apply. | |
| 358 w2->Focus(); | |
| 359 EXPECT_FALSE(wm::IsActiveWindow(w2.get())); | |
| 360 EXPECT_FALSE(w2->HasFocus()); | |
| 361 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | |
| 362 EXPECT_TRUE(w1->HasFocus()); | |
| 363 | |
| 364 // Try focusing |w21|. Same rules apply. | |
| 365 EXPECT_FALSE(wm::IsActiveWindow(w2.get())); | |
| 366 EXPECT_FALSE(w21->HasFocus()); | |
| 367 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | |
| 368 EXPECT_TRUE(w1->HasFocus()); | |
| 369 } | |
| 370 | |
| 371 TEST_F(ActivationControllerTest, CanActivateWindowIteselfTest) | |
| 372 { | |
| 373 aura::test::TestWindowDelegate wd; | |
| 374 | |
| 375 // Normal Window | |
| 376 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( | |
| 377 &wd, -1, gfx::Rect(50, 50))); | |
| 378 EXPECT_TRUE(wm::CanActivateWindow(w1.get())); | |
| 379 | |
| 380 // The RootWindow is a non-activatable parent. | |
| 381 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( | |
| 382 &wd, -2, gfx::Rect(50, 50), Shell::GetPrimaryRootWindow())); | |
| 383 scoped_ptr<aura::Window> w21(aura::test::CreateTestWindowWithDelegate( | |
| 384 &wd, -21, gfx::Rect(50, 50), w2.get())); | |
| 385 EXPECT_FALSE(wm::CanActivateWindow(w2.get())); | |
| 386 EXPECT_FALSE(wm::CanActivateWindow(w21.get())); | |
| 387 | |
| 388 // The window has a transient child. | |
| 389 scoped_ptr<aura::Window> w3(CreateTestWindowInShellWithDelegate( | |
| 390 &wd, -3, gfx::Rect(50, 50))); | |
| 391 scoped_ptr<aura::Window> w31(CreateTestWindowInShellWithDelegate( | |
| 392 &wd, -31, gfx::Rect(50, 50))); | |
| 393 w3->AddTransientChild(w31.get()); | |
| 394 EXPECT_TRUE(wm::CanActivateWindow(w3.get())); | |
| 395 EXPECT_TRUE(wm::CanActivateWindow(w31.get())); | |
| 396 | |
| 397 // The window has a transient window-modal child. | |
| 398 scoped_ptr<aura::Window> w4(CreateTestWindowInShellWithDelegate( | |
| 399 &wd, -4, gfx::Rect(50, 50))); | |
| 400 scoped_ptr<aura::Window> w41(CreateTestWindowInShellWithDelegate( | |
| 401 &wd, -41, gfx::Rect(50, 50))); | |
| 402 w4->AddTransientChild(w41.get()); | |
| 403 w41->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); | |
| 404 EXPECT_FALSE(wm::CanActivateWindow(w4.get())); | |
| 405 EXPECT_TRUE(wm::CanActivateWindow(w41.get())); | |
| 406 | |
| 407 // The window has a transient system-modal child. | |
| 408 scoped_ptr<aura::Window> w5(CreateTestWindowInShellWithDelegate( | |
| 409 &wd, -5, gfx::Rect(50, 50))); | |
| 410 scoped_ptr<aura::Window> w51(CreateTestWindowInShellWithDelegate( | |
| 411 &wd, -51, gfx::Rect(50, 50))); | |
| 412 w5->AddTransientChild(w51.get()); | |
| 413 w51->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); | |
| 414 EXPECT_FALSE(wm::CanActivateWindow(w5.get())); | |
| 415 EXPECT_TRUE(wm::CanActivateWindow(w51.get())); | |
| 416 } | |
| 417 | |
| 418 // Verifies code in ActivationController::OnWindowVisibilityChanged() that keeps | |
| 419 // hiding windows layers stacked above the newly active window while they | |
| 420 // animate away. | |
| 421 // TODO(beng): This test now duplicates a test in: | |
| 422 // ui/views/corewm/focus_controller_unittest.cc | |
| 423 // ...and can be removed once the new focus controller is enabled. | |
| 424 TEST_F(ActivationControllerTest, AnimateHideMaintainsStacking) { | |
| 425 aura::test::TestWindowDelegate wd; | |
| 426 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( | |
| 427 &wd, -1, gfx::Rect(50, 50, 50, 50))); | |
| 428 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate( | |
| 429 &wd, -2, gfx::Rect(75, 75, 50, 50))); | |
| 430 wm::ActivateWindow(w2.get()); | |
| 431 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | |
| 432 w2->Hide(); | |
| 433 typedef std::vector<ui::Layer*> Layers; | |
| 434 const Layers& children = w1->parent()->layer()->children(); | |
| 435 Layers::const_iterator w1_iter = | |
| 436 std::find(children.begin(), children.end(), w1->layer()); | |
| 437 Layers::const_iterator w2_iter = | |
| 438 std::find(children.begin(), children.end(), w2->layer()); | |
| 439 EXPECT_TRUE(w2_iter > w1_iter); | |
| 440 } | |
| 441 | |
| 442 // Verifies that activating a minimized window would restore it. | |
| 443 TEST_F(ActivationControllerTest, ActivateMinimizedWindow) { | |
| 444 aura::test::TestWindowDelegate wd; | |
| 445 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( | |
| 446 &wd, -1, gfx::Rect(50, 50))); | |
| 447 | |
| 448 wm::MinimizeWindow(w1.get()); | |
| 449 EXPECT_TRUE(wm::IsWindowMinimized(w1.get())); | |
| 450 | |
| 451 wm::ActivateWindow(w1.get()); | |
| 452 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | |
| 453 EXPECT_FALSE(wm::IsWindowMinimized(w1.get())); | |
| 454 } | |
| 455 | |
| 456 // Verifies that a minimized window would not be automatically activated as | |
| 457 // a replacement active window. | |
| 458 TEST_F(ActivationControllerTest, NoAutoActivateMinimizedWindow) { | |
| 459 aura::test::TestWindowDelegate wd; | |
| 460 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( | |
| 461 &wd, -1, gfx::Rect(50, 50, 50, 50))); | |
| 462 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate( | |
| 463 &wd, -2, gfx::Rect(75, 75, 50, 50))); | |
| 464 | |
| 465 wm::MinimizeWindow(w1.get()); | |
| 466 EXPECT_TRUE(wm::IsWindowMinimized(w1.get())); | |
| 467 | |
| 468 wm::ActivateWindow(w2.get()); | |
| 469 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | |
| 470 | |
| 471 w2->Hide(); | |
| 472 | |
| 473 EXPECT_FALSE(wm::IsActiveWindow(w1.get())); | |
| 474 EXPECT_TRUE(wm::IsWindowMinimized(w1.get())); | |
| 475 } | |
| 476 | |
| 477 // Verifies that a window with a hidden layer can be activated. | |
| 478 TEST_F(ActivationControllerTest, ActivateWithHiddenLayer) { | |
| 479 aura::test::TestWindowDelegate wd; | |
| 480 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( | |
| 481 &wd, -1, gfx::Rect(50, 50, 50, 50))); | |
| 482 | |
| 483 EXPECT_TRUE(wm::CanActivateWindow(w1.get())); | |
| 484 w1->layer()->SetVisible(false); | |
| 485 EXPECT_TRUE(wm::CanActivateWindow(w1.get())); | |
| 486 } | |
| 487 | |
| 488 // Verifies that a unrelated window cannot be activated when in a system modal | |
| 489 // dialog. | |
| 490 TEST_F(ActivationControllerTest, DontActivateWindowWhenInSystemModalDialog) { | |
| 491 scoped_ptr<aura::Window> normal_window(CreateTestWindowInShellWithId(-1)); | |
| 492 EXPECT_FALSE(wm::IsActiveWindow(normal_window.get())); | |
| 493 wm::ActivateWindow(normal_window.get()); | |
| 494 EXPECT_TRUE(wm::IsActiveWindow(normal_window.get())); | |
| 495 | |
| 496 // Create and activate a system modal window. | |
| 497 aura::Window* modal_container = | |
| 498 ash::Shell::GetContainer( | |
| 499 Shell::GetPrimaryRootWindow(), | |
| 500 ash::internal::kShellWindowId_SystemModalContainer); | |
| 501 scoped_ptr<aura::Window> modal_window( | |
| 502 aura::test::CreateTestWindowWithId(-2, modal_container)); | |
| 503 modal_window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); | |
| 504 wm::ActivateWindow(modal_window.get()); | |
| 505 EXPECT_TRUE(ash::Shell::GetInstance()->IsSystemModalWindowOpen()); | |
| 506 EXPECT_FALSE(wm::IsActiveWindow(normal_window.get())); | |
| 507 EXPECT_TRUE(wm::IsActiveWindow(modal_window.get())); | |
| 508 | |
| 509 // We try to but cannot activate the normal window while we | |
| 510 // have the system modal window. | |
| 511 wm::ActivateWindow(normal_window.get()); | |
| 512 EXPECT_TRUE(ash::Shell::GetInstance()->IsSystemModalWindowOpen()); | |
| 513 EXPECT_FALSE(wm::IsActiveWindow(normal_window.get())); | |
| 514 EXPECT_TRUE(wm::IsActiveWindow(modal_window.get())); | |
| 515 | |
| 516 modal_window->Hide(); | |
| 517 modal_window.reset(); | |
| 518 EXPECT_FALSE(ash::Shell::GetInstance()->IsSystemModalWindowOpen()); | |
| 519 EXPECT_TRUE(wm::IsActiveWindow(normal_window.get())); | |
| 520 } | |
| 521 | |
| 522 // Verifies that a lock window can get focus even if lock | |
| 523 // container is not visible (e.g. before animating it). | |
| 524 TEST_F(ActivationControllerTest, ActivateLockScreen) { | |
| 525 aura::Window* lock_container = | |
| 526 Shell::GetContainer(Shell::GetPrimaryRootWindow(), c3); | |
| 527 aura::test::TestWindowDelegate wd; | |
| 528 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( | |
| 529 &wd, -1, gfx::Rect(50, 50, 50, 50), lock_container)); | |
| 530 | |
| 531 lock_container->layer()->SetVisible(false); | |
| 532 w1->Focus(); | |
| 533 EXPECT_TRUE(w1->HasFocus()); | |
| 534 } | |
| 535 | |
| 536 // Verifies that a next active window is chosen from current | |
| 537 // active display. | |
| 538 TEST_F(ActivationControllerTest, NextActiveWindowOnMultipleDisplays) { | |
| 539 if (!SupportsMultipleDisplays()) | |
| 540 return; | |
| 541 | |
| 542 UpdateDisplay("300x300,300x300"); | |
| 543 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | |
| 544 | |
| 545 scoped_ptr<aura::Window> w1_d1(CreateTestWindowInShellWithBounds( | |
| 546 gfx::Rect(10, 10, 100, 100))); | |
| 547 scoped_ptr<aura::Window> w2_d1(CreateTestWindowInShellWithBounds( | |
| 548 gfx::Rect(20, 20, 100, 100))); | |
| 549 | |
| 550 EXPECT_EQ(root_windows[0], w1_d1->GetRootWindow()); | |
| 551 EXPECT_EQ(root_windows[0], w2_d1->GetRootWindow()); | |
| 552 | |
| 553 scoped_ptr<aura::Window> w3_d2(CreateTestWindowInShellWithBounds( | |
| 554 gfx::Rect(310, 10, 100, 100))); | |
| 555 scoped_ptr<aura::Window> w4_d2(CreateTestWindowInShellWithBounds( | |
| 556 gfx::Rect(320, 20, 100, 100))); | |
| 557 EXPECT_EQ(root_windows[1], w3_d2->GetRootWindow()); | |
| 558 EXPECT_EQ(root_windows[1], w4_d2->GetRootWindow()); | |
| 559 | |
| 560 aura::client::ActivationClient* client = | |
| 561 aura::client::GetActivationClient(root_windows[0]); | |
| 562 client->ActivateWindow(w1_d1.get()); | |
| 563 EXPECT_EQ(w1_d1.get(), client->GetActiveWindow()); | |
| 564 | |
| 565 w1_d1.reset(); | |
| 566 EXPECT_EQ(w2_d1.get(), client->GetActiveWindow()); | |
| 567 | |
| 568 client->ActivateWindow(w3_d2.get()); | |
| 569 EXPECT_EQ(w3_d2.get(), client->GetActiveWindow()); | |
| 570 w3_d2.reset(); | |
| 571 EXPECT_EQ(w4_d2.get(), client->GetActiveWindow()); | |
| 572 } | |
| 573 | |
| 574 } // namespace test | |
| 575 } // namespace ash | |
| OLD | NEW |