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/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/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
9 #include "ash/test/test_activation_delegate.h" | 10 #include "ash/test/test_activation_delegate.h" |
10 #include "ash/wm/window_util.h" | 11 #include "ash/wm/window_util.h" |
11 #include "ui/aura/focus_manager.h" | 12 #include "ui/aura/focus_manager.h" |
12 #include "ui/aura/root_window.h" | 13 #include "ui/aura/root_window.h" |
13 #include "ui/aura/test/event_generator.h" | 14 #include "ui/aura/test/event_generator.h" |
14 #include "ui/aura/test/test_window_delegate.h" | 15 #include "ui/aura/test/test_window_delegate.h" |
15 #include "ui/aura/test/test_windows.h" | 16 #include "ui/aura/test/test_windows.h" |
16 | 17 |
17 #if defined(OS_WIN) | 18 #if defined(OS_WIN) |
18 // Windows headers define macros for these function names which screw with us. | 19 // Windows headers define macros for these function names which screw with us. |
19 #if defined(CreateWindow) | 20 #if defined(CreateWindow) |
20 #undef CreateWindow | 21 #undef CreateWindow |
21 #endif | 22 #endif |
22 #endif | 23 #endif |
23 | 24 |
| 25 namespace { |
| 26 |
| 27 // Containers used for the tests. |
| 28 const int c1 = ash::internal::kShellWindowId_DefaultContainer; |
| 29 const int c2 = ash::internal::kShellWindowId_AlwaysOnTopContainer; |
| 30 const int c3 = ash::internal::kShellWindowId_LockScreenContainer; |
| 31 |
| 32 } // namespace |
| 33 |
24 namespace ash { | 34 namespace ash { |
25 namespace test { | 35 namespace test { |
26 | 36 |
27 typedef test::AshTestBase ActivationControllerTest; | 37 typedef test::AshTestBase ActivationControllerTest; |
28 | 38 |
29 // Utilities for a set of tests that test | 39 // Utilities for a set of tests that test |
30 // ActivationController::GetTopmostWindowToActivate(). | 40 // ActivationController::GetTopmostWindowToActivate(). |
31 class GetTopmostWindowToActivateTest : public ActivationControllerTest { | 41 class GetTopmostWindowToActivateTest : public ActivationControllerTest { |
32 public: | 42 public: |
33 GetTopmostWindowToActivateTest() : ad_1_(false), ad_3_(false) {} | 43 GetTopmostWindowToActivateTest() : ad_1_(false), ad_3_(false) {} |
34 virtual ~GetTopmostWindowToActivateTest() {} | 44 virtual ~GetTopmostWindowToActivateTest() {} |
35 | 45 |
36 // Overridden from ActivationControllerTest: | 46 // Overridden from ActivationControllerTest: |
37 virtual void SetUp() OVERRIDE { | 47 virtual void SetUp() OVERRIDE { |
38 ActivationControllerTest::SetUp(); | 48 ActivationControllerTest::SetUp(); |
39 CreateWindows(); | 49 CreateWindows(); |
40 } | 50 } |
41 virtual void TearDown() OVERRIDE { | 51 virtual void TearDown() OVERRIDE { |
42 DestroyWindows(); | 52 DestroyWindows(); |
43 ActivationControllerTest::TearDown(); | 53 ActivationControllerTest::TearDown(); |
44 } | 54 } |
45 | 55 |
46 protected: | 56 protected: |
47 aura::Window* w1() { return w1_.get(); } | 57 aura::Window* w1() { return w1_.get(); } |
48 aura::Window* w2() { return w2_.get(); } | 58 aura::Window* w2() { return w2_.get(); } |
49 aura::Window* w3() { return w3_.get(); } | 59 aura::Window* w3() { return w3_.get(); } |
50 aura::Window* w4() { return w4_.get(); } | 60 aura::Window* w4() { return w4_.get(); } |
| 61 aura::Window* w5() { return w5_.get(); } |
| 62 aura::Window* w6() { return w6_.get(); } |
| 63 aura::Window* w7() { return w7_.get(); } |
51 | 64 |
52 void DestroyWindow2() { | 65 void DestroyWindow2() { |
53 w2_.reset(); | 66 w2_.reset(); |
54 } | 67 } |
55 | 68 |
56 private: | 69 private: |
57 void CreateWindows() { | 70 void CreateWindows() { |
58 // Create four windows, the first and third are not activatable, the second | 71 // Create four windows, the first and third are not activatable, the second |
59 // and fourth are. | 72 // and fourth are. |
60 w1_.reset(CreateWindow(1, &ad_1_)); | 73 w1_.reset(CreateWindow(1, &ad_1_, c1)); |
61 w2_.reset(CreateWindow(2, &ad_2_)); | 74 w2_.reset(CreateWindow(2, &ad_2_, c1)); |
62 w3_.reset(CreateWindow(3, &ad_3_)); | 75 w3_.reset(CreateWindow(3, &ad_3_, c1)); |
63 w4_.reset(CreateWindow(4, &ad_4_)); | 76 w4_.reset(CreateWindow(4, &ad_4_, c1)); |
| 77 w5_.reset(CreateWindow(5, &ad_5_, c2)); |
| 78 w6_.reset(CreateWindow(6, &ad_6_, c2)); |
| 79 w7_.reset(CreateWindow(7, &ad_7_, c3)); |
64 } | 80 } |
65 | 81 |
66 aura::Window* CreateWindow(int id, TestActivationDelegate* delegate) { | 82 aura::Window* CreateWindow(int id, |
| 83 TestActivationDelegate* delegate, |
| 84 int container_id) { |
67 aura::Window* window = aura::test::CreateTestWindowWithDelegate( | 85 aura::Window* window = aura::test::CreateTestWindowWithDelegate( |
68 &delegate_, id, gfx::Rect(), NULL); | 86 &delegate_, |
| 87 id, |
| 88 gfx::Rect(), |
| 89 Shell::GetInstance()->GetContainer(container_id)); |
69 delegate->SetWindow(window); | 90 delegate->SetWindow(window); |
70 return window; | 91 return window; |
71 } | 92 } |
72 | 93 |
73 void DestroyWindows() { | 94 void DestroyWindows() { |
74 w1_.reset(); | 95 w1_.reset(); |
75 w2_.reset(); | 96 w2_.reset(); |
76 w3_.reset(); | 97 w3_.reset(); |
77 w4_.reset(); | 98 w4_.reset(); |
| 99 w5_.reset(); |
| 100 w6_.reset(); |
| 101 w7_.reset(); |
78 } | 102 } |
79 | 103 |
80 aura::test::TestWindowDelegate delegate_; | 104 aura::test::TestWindowDelegate delegate_; |
81 TestActivationDelegate ad_1_; | 105 TestActivationDelegate ad_1_; |
82 TestActivationDelegate ad_2_; | 106 TestActivationDelegate ad_2_; |
83 TestActivationDelegate ad_3_; | 107 TestActivationDelegate ad_3_; |
84 TestActivationDelegate ad_4_; | 108 TestActivationDelegate ad_4_; |
| 109 TestActivationDelegate ad_5_; |
| 110 TestActivationDelegate ad_6_; |
| 111 TestActivationDelegate ad_7_; |
85 scoped_ptr<aura::Window> w1_; // Non-activatable. | 112 scoped_ptr<aura::Window> w1_; // Non-activatable. |
86 scoped_ptr<aura::Window> w2_; // Activatable. | 113 scoped_ptr<aura::Window> w2_; // Activatable. |
87 scoped_ptr<aura::Window> w3_; // Non-activatable. | 114 scoped_ptr<aura::Window> w3_; // Non-activatable. |
88 scoped_ptr<aura::Window> w4_; // Activatable. | 115 scoped_ptr<aura::Window> w4_; // Activatable. |
| 116 scoped_ptr<aura::Window> w5_; // Activatable - Always on top. |
| 117 scoped_ptr<aura::Window> w6_; // Activatable - Always on top. |
| 118 scoped_ptr<aura::Window> w7_; // Activatable - Lock screen window. |
89 | 119 |
90 DISALLOW_COPY_AND_ASSIGN(GetTopmostWindowToActivateTest); | 120 DISALLOW_COPY_AND_ASSIGN(GetTopmostWindowToActivateTest); |
91 }; | 121 }; |
92 | 122 |
93 // Hiding the active window should activate the next valid activatable window. | 123 // Hiding the active window should activate the next valid activatable window. |
94 TEST_F(GetTopmostWindowToActivateTest, HideActivatesNext) { | 124 TEST_F(GetTopmostWindowToActivateTest, HideActivatesNext) { |
95 wm::ActivateWindow(w2()); | 125 wm::ActivateWindow(w2()); |
96 EXPECT_TRUE(wm::IsActiveWindow(w2())); | 126 EXPECT_TRUE(wm::IsActiveWindow(w2())); |
97 | 127 |
98 w2()->Hide(); | 128 w2()->Hide(); |
(...skipping 14 matching lines...) Expand all Loading... |
113 // Deactivating the active window should activate the next valid activatable | 143 // Deactivating the active window should activate the next valid activatable |
114 // window. | 144 // window. |
115 TEST_F(GetTopmostWindowToActivateTest, DeactivateActivatesNext) { | 145 TEST_F(GetTopmostWindowToActivateTest, DeactivateActivatesNext) { |
116 wm::ActivateWindow(w2()); | 146 wm::ActivateWindow(w2()); |
117 EXPECT_TRUE(wm::IsActiveWindow(w2())); | 147 EXPECT_TRUE(wm::IsActiveWindow(w2())); |
118 | 148 |
119 wm::DeactivateWindow(w2()); | 149 wm::DeactivateWindow(w2()); |
120 EXPECT_TRUE(wm::IsActiveWindow(w4())); | 150 EXPECT_TRUE(wm::IsActiveWindow(w4())); |
121 } | 151 } |
122 | 152 |
| 153 // Test that hiding a window in a higher container will activate another window |
| 154 // in that container. |
| 155 TEST_F(GetTopmostWindowToActivateTest, HideActivatesSameContainer) { |
| 156 wm::ActivateWindow(w6()); |
| 157 EXPECT_TRUE(wm::IsActiveWindow(w6())); |
| 158 |
| 159 w6()->Hide(); |
| 160 EXPECT_TRUE(wm::IsActiveWindow(w5())); |
| 161 } |
| 162 |
| 163 // Test that hiding the lock window will activate a window from the next highest |
| 164 // container. |
| 165 TEST_F(GetTopmostWindowToActivateTest, UnlockActivatesNextHighestContainer) { |
| 166 wm::ActivateWindow(w7()); |
| 167 EXPECT_TRUE(wm::IsActiveWindow(w7())); |
| 168 |
| 169 w7()->Hide(); |
| 170 EXPECT_TRUE(wm::IsActiveWindow(w6())); |
| 171 } |
| 172 |
| 173 // Test that hiding a window in a higher container with no other windows will |
| 174 // activate a window in a lower container. |
| 175 TEST_F(GetTopmostWindowToActivateTest, HideActivatesNextHighestContainer) { |
| 176 w5()->Hide(); |
| 177 wm::ActivateWindow(w6()); |
| 178 EXPECT_TRUE(wm::IsActiveWindow(w6())); |
| 179 |
| 180 w6()->Hide(); |
| 181 EXPECT_TRUE(wm::IsActiveWindow(w4())); |
| 182 } |
| 183 |
123 // Test if the clicking on a menu picks the transient parent as activatable | 184 // Test if the clicking on a menu picks the transient parent as activatable |
124 // window. | 185 // window. |
125 TEST_F(ActivationControllerTest, ClickOnMenu) { | 186 TEST_F(ActivationControllerTest, ClickOnMenu) { |
126 aura::test::TestWindowDelegate wd; | 187 aura::test::TestWindowDelegate wd; |
127 TestActivationDelegate ad1; | 188 TestActivationDelegate ad1; |
128 TestActivationDelegate ad2(false); | 189 TestActivationDelegate ad2(false); |
129 | 190 |
130 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( | 191 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( |
131 &wd, 1, gfx::Rect(100, 100), NULL)); | 192 &wd, 1, gfx::Rect(100, 100), NULL)); |
132 ad1.SetWindow(w1.get()); | 193 ad1.SetWindow(w1.get()); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 | 344 |
284 // Try focusing |w21|. Same rules apply. | 345 // Try focusing |w21|. Same rules apply. |
285 EXPECT_FALSE(wm::IsActiveWindow(w2.get())); | 346 EXPECT_FALSE(wm::IsActiveWindow(w2.get())); |
286 EXPECT_FALSE(w21->HasFocus()); | 347 EXPECT_FALSE(w21->HasFocus()); |
287 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 348 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
288 EXPECT_TRUE(w1->HasFocus()); | 349 EXPECT_TRUE(w1->HasFocus()); |
289 } | 350 } |
290 | 351 |
291 } // namespace test | 352 } // namespace test |
292 } // namespace ash | 353 } // namespace ash |
OLD | NEW |