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

Side by Side Diff: ash/wm/window_modality_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: I think the content_unittests timeout on linux_aura is flake, but try to fix it anyway. Created 8 years, 1 month 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/window_modality_controller.h" 5 #include "ash/wm/window_modality_controller.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h" 8 #include "ash/test/ash_test_base.h"
9 #include "ash/test/capture_tracking_view.h" 9 #include "ash/test/capture_tracking_view.h"
10 #include "ash/wm/window_util.h" 10 #include "ash/wm/window_util.h"
(...skipping 24 matching lines...) Expand all
35 35
36 // Creates three windows, w1, w11, and w12. w11 is a non-modal transient, w12 is 36 // Creates three windows, w1, w11, and w12. w11 is a non-modal transient, w12 is
37 // a modal transient. 37 // a modal transient.
38 // Validates: 38 // Validates:
39 // - it should be possible to activate w12 even when w11 is open. 39 // - it should be possible to activate w12 even when w11 is open.
40 // - activating w1 activates w12 and updates stacking order appropriately. 40 // - activating w1 activates w12 and updates stacking order appropriately.
41 // - closing a window passes focus up the stack. 41 // - closing a window passes focus up the stack.
42 TEST_F(WindowModalityControllerTest, BasicActivation) { 42 TEST_F(WindowModalityControllerTest, BasicActivation) {
43 aura::test::TestWindowDelegate d; 43 aura::test::TestWindowDelegate d;
44 scoped_ptr<aura::Window> w1( 44 scoped_ptr<aura::Window> w1(
45 aura::test::CreateTestWindowWithDelegate(&d, -1, gfx::Rect(), NULL)); 45 CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect()));
46 scoped_ptr<aura::Window> w11( 46 scoped_ptr<aura::Window> w11(
47 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), NULL)); 47 CreateTestWindowInShellWithDelegate(&d, -11, gfx::Rect()));
48 scoped_ptr<aura::Window> w12( 48 scoped_ptr<aura::Window> w12(
49 aura::test::CreateTestWindowWithDelegate(&d, -12, gfx::Rect(), NULL)); 49 CreateTestWindowInShellWithDelegate(&d, -12, gfx::Rect()));
50 50
51 w1->AddTransientChild(w11.get()); 51 w1->AddTransientChild(w11.get());
52 wm::ActivateWindow(w1.get()); 52 wm::ActivateWindow(w1.get());
53 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 53 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
54 wm::ActivateWindow(w11.get()); 54 wm::ActivateWindow(w11.get());
55 EXPECT_TRUE(wm::IsActiveWindow(w11.get())); 55 EXPECT_TRUE(wm::IsActiveWindow(w11.get()));
56 56
57 w12->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); 57 w12->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
58 w1->AddTransientChild(w12.get()); 58 w1->AddTransientChild(w12.get());
59 wm::ActivateWindow(w12.get()); 59 wm::ActivateWindow(w12.get());
(...skipping 20 matching lines...) Expand all
80 80
81 // Create two toplevel windows w1 and w2, and nest two modals w11 and w111 below 81 // Create two toplevel windows w1 and w2, and nest two modals w11 and w111 below
82 // w1. 82 // w1.
83 // Validates: 83 // Validates:
84 // - activating w1 while w11/w111 is showing always activates most deeply nested 84 // - activating w1 while w11/w111 is showing always activates most deeply nested
85 // descendant. 85 // descendant.
86 // - closing a window passes focus up the stack. 86 // - closing a window passes focus up the stack.
87 TEST_F(WindowModalityControllerTest, NestedModals) { 87 TEST_F(WindowModalityControllerTest, NestedModals) {
88 aura::test::TestWindowDelegate d; 88 aura::test::TestWindowDelegate d;
89 scoped_ptr<aura::Window> w1( 89 scoped_ptr<aura::Window> w1(
90 aura::test::CreateTestWindowWithDelegate(&d, -1, gfx::Rect(), NULL)); 90 CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect()));
91 scoped_ptr<aura::Window> w11( 91 scoped_ptr<aura::Window> w11(
92 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), NULL)); 92 CreateTestWindowInShellWithDelegate(&d, -11, gfx::Rect()));
93 scoped_ptr<aura::Window> w111( 93 scoped_ptr<aura::Window> w111(
94 aura::test::CreateTestWindowWithDelegate(&d, -111, gfx::Rect(), NULL)); 94 CreateTestWindowInShellWithDelegate(&d, -111, gfx::Rect()));
95 scoped_ptr<aura::Window> w2( 95 scoped_ptr<aura::Window> w2(
96 aura::test::CreateTestWindowWithDelegate(&d, -2, gfx::Rect(), NULL)); 96 CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect()));
97 97
98 w1->AddTransientChild(w11.get()); 98 w1->AddTransientChild(w11.get());
99 w11->AddTransientChild(w111.get()); 99 w11->AddTransientChild(w111.get());
100 100
101 wm::ActivateWindow(w1.get()); 101 wm::ActivateWindow(w1.get());
102 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 102 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
103 wm::ActivateWindow(w2.get()); 103 wm::ActivateWindow(w2.get());
104 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); 104 EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
105 105
106 // Set up modality. 106 // Set up modality.
(...skipping 26 matching lines...) Expand all
133 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 133 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
134 } 134 }
135 135
136 // Create two toplevel windows w1 and w2, and nest two modals w11 and w111 below 136 // Create two toplevel windows w1 and w2, and nest two modals w11 and w111 below
137 // w1. 137 // w1.
138 // Validates: 138 // Validates:
139 // - destroying w11 while w111 is focused activates w1. 139 // - destroying w11 while w111 is focused activates w1.
140 TEST_F(WindowModalityControllerTest, NestedModalsOuterClosed) { 140 TEST_F(WindowModalityControllerTest, NestedModalsOuterClosed) {
141 aura::test::TestWindowDelegate d; 141 aura::test::TestWindowDelegate d;
142 scoped_ptr<aura::Window> w1( 142 scoped_ptr<aura::Window> w1(
143 aura::test::CreateTestWindowWithDelegate(&d, -1, gfx::Rect(), NULL)); 143 CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect()));
144 scoped_ptr<aura::Window> w11( 144 scoped_ptr<aura::Window> w11(
145 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), NULL)); 145 CreateTestWindowInShellWithDelegate(&d, -11, gfx::Rect()));
146 // |w111| will be owned and deleted by |w11|. 146 // |w111| will be owned and deleted by |w11|.
147 aura::Window* w111 = 147 aura::Window* w111 =
148 aura::test::CreateTestWindowWithDelegate(&d, -111, gfx::Rect(), NULL); 148 CreateTestWindowInShellWithDelegate(&d, -111, gfx::Rect());
149 scoped_ptr<aura::Window> w2( 149 scoped_ptr<aura::Window> w2(
150 aura::test::CreateTestWindowWithDelegate(&d, -2, gfx::Rect(), NULL)); 150 CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect()));
151 151
152 w1->AddTransientChild(w11.get()); 152 w1->AddTransientChild(w11.get());
153 w11->AddTransientChild(w111); 153 w11->AddTransientChild(w111);
154 154
155 wm::ActivateWindow(w1.get()); 155 wm::ActivateWindow(w1.get());
156 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 156 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
157 wm::ActivateWindow(w2.get()); 157 wm::ActivateWindow(w2.get());
158 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); 158 EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
159 159
160 // Set up modality. 160 // Set up modality.
(...skipping 10 matching lines...) Expand all
171 // modal window. There is no such use case right now, but it 171 // modal window. There is no such use case right now, but it
172 // probably should. 172 // probably should.
173 173
174 w11.reset(); 174 w11.reset();
175 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 175 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
176 } 176 }
177 177
178 // Modality also prevents events from being passed to the transient parent. 178 // Modality also prevents events from being passed to the transient parent.
179 TEST_F(WindowModalityControllerTest, Events) { 179 TEST_F(WindowModalityControllerTest, Events) {
180 aura::test::TestWindowDelegate d; 180 aura::test::TestWindowDelegate d;
181 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate(&d, -1, 181 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(&d, -1,
182 gfx::Rect(0, 0, 100, 100), NULL)); 182 gfx::Rect(0, 0, 100, 100)));
183 scoped_ptr<aura::Window> w11(aura::test::CreateTestWindowWithDelegate(&d, -11, 183 scoped_ptr<aura::Window> w11(CreateTestWindowInShellWithDelegate(&d, -11,
184 gfx::Rect(20, 20, 50, 50), NULL)); 184 gfx::Rect(20, 20, 50, 50)));
185 185
186 w1->AddTransientChild(w11.get()); 186 w1->AddTransientChild(w11.get());
187 187
188 { 188 {
189 // Clicking a point within w1 should activate that window. 189 // Clicking a point within w1 should activate that window.
190 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 190 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
191 gfx::Point(10, 10)); 191 gfx::Point(10, 10));
192 generator.ClickLeftButton(); 192 generator.ClickLeftButton();
193 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 193 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
194 } 194 }
195 195
196 w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); 196 w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
197 197
198 { 198 {
199 // Clicking a point within w1 should activate w11. 199 // Clicking a point within w1 should activate w11.
200 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 200 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
201 gfx::Point(10, 10)); 201 gfx::Point(10, 10));
202 generator.ClickLeftButton(); 202 generator.ClickLeftButton();
203 EXPECT_TRUE(wm::IsActiveWindow(w11.get())); 203 EXPECT_TRUE(wm::IsActiveWindow(w11.get()));
204 } 204 }
205 } 205 }
206 206
207 // Creates windows w1 and non activatiable child w11. Creates transient window 207 // Creates windows w1 and non activatiable child w11. Creates transient window
208 // w2 and adds it as a transeint child of w1. Ensures that w2 is parented to 208 // w2 and adds it as a transeint child of w1. Ensures that w2 is parented to
209 // the parent of w1, and that GetWindowModalTransient(w11) returns w2. 209 // the parent of w1, and that GetWindowModalTransient(w11) returns w2.
210 TEST_F(WindowModalityControllerTest, GetWindowModalTransient) { 210 TEST_F(WindowModalityControllerTest, GetWindowModalTransient) {
211 aura::test::TestWindowDelegate d; 211 aura::test::TestWindowDelegate d;
212 scoped_ptr<aura::Window> w1( 212 scoped_ptr<aura::Window> w1(
213 aura::test::CreateTestWindowWithDelegate(&d, -1, gfx::Rect(), NULL)); 213 CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect()));
214 scoped_ptr<aura::Window> w11( 214 scoped_ptr<aura::Window> w11(
215 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get())); 215 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get()));
216 scoped_ptr<aura::Window> w2( 216 scoped_ptr<aura::Window> w2(
217 aura::test::CreateTestWindowWithDelegate(&d, -2, gfx::Rect(), NULL)); 217 CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect()));
218 w2->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); 218 w2->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
219 219
220 aura::Window* wt; 220 aura::Window* wt;
221 wt = wm::GetWindowModalTransient(w1.get()); 221 wt = wm::GetWindowModalTransient(w1.get());
222 ASSERT_EQ(static_cast<aura::Window*>(NULL), wt); 222 ASSERT_EQ(static_cast<aura::Window*>(NULL), wt);
223 223
224 // Parent w2 to w1. It should get parented to the parent of w1. 224 // Parent w2 to w1. It should get parented to the parent of w1.
225 w1->AddTransientChild(w2.get()); 225 w1->AddTransientChild(w2.get());
226 ASSERT_EQ(2U, w1->parent()->children().size()); 226 ASSERT_EQ(2U, w1->parent()->children().size());
227 EXPECT_EQ(-2, w1->parent()->children().at(1)->id()); 227 EXPECT_EQ(-2, w1->parent()->children().at(1)->id());
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 } 300 }
301 301
302 bool received_touch_; 302 bool received_touch_;
303 303
304 DISALLOW_COPY_AND_ASSIGN(TouchTrackerWindowDelegate); 304 DISALLOW_COPY_AND_ASSIGN(TouchTrackerWindowDelegate);
305 }; 305 };
306 306
307 // Modality should prevent events from being passed to the transient parent. 307 // Modality should prevent events from being passed to the transient parent.
308 TEST_F(WindowModalityControllerTest, TouchEvent) { 308 TEST_F(WindowModalityControllerTest, TouchEvent) {
309 TouchTrackerWindowDelegate d1; 309 TouchTrackerWindowDelegate d1;
310 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate(&d1, 310 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(&d1,
311 -1, gfx::Rect(0, 0, 100, 100), NULL)); 311 -1, gfx::Rect(0, 0, 100, 100)));
312 TouchTrackerWindowDelegate d11; 312 TouchTrackerWindowDelegate d11;
313 scoped_ptr<aura::Window> w11(aura::test::CreateTestWindowWithDelegate(&d11, 313 scoped_ptr<aura::Window> w11(CreateTestWindowInShellWithDelegate(&d11,
314 -11, gfx::Rect(20, 20, 50, 50), NULL)); 314 -11, gfx::Rect(20, 20, 50, 50)));
315 315
316 w1->AddTransientChild(w11.get()); 316 w1->AddTransientChild(w11.get());
317 d1.reset(); 317 d1.reset();
318 d11.reset(); 318 d11.reset();
319 319
320 { 320 {
321 // Clicking a point within w1 should activate that window. 321 // Clicking a point within w1 should activate that window.
322 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 322 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
323 gfx::Point(10, 10)); 323 gfx::Point(10, 10));
324 generator.PressMoveAndReleaseTouchTo(gfx::Point(10, 10)); 324 generator.PressMoveAndReleaseTouchTo(gfx::Point(10, 10));
(...skipping 12 matching lines...) Expand all
337 gfx::Point(10, 10)); 337 gfx::Point(10, 10));
338 generator.PressMoveAndReleaseTouchTo(gfx::Point(10, 10)); 338 generator.PressMoveAndReleaseTouchTo(gfx::Point(10, 10));
339 EXPECT_TRUE(wm::IsActiveWindow(w11.get())); 339 EXPECT_TRUE(wm::IsActiveWindow(w11.get()));
340 EXPECT_FALSE(d1.received_touch()); 340 EXPECT_FALSE(d1.received_touch());
341 EXPECT_FALSE(d11.received_touch()); 341 EXPECT_FALSE(d11.received_touch());
342 } 342 }
343 } 343 }
344 344
345 } // namespace internal 345 } // namespace internal
346 } // namespace ash 346 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698