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

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: Fix ash_unittests 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/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/test/child_modal_window.h" 10 #include "ash/test/child_modal_window.h"
(...skipping 25 matching lines...) Expand all
36 36
37 // Creates three windows, w1, w11, and w12. w11 is a non-modal transient, w12 is 37 // Creates three windows, w1, w11, and w12. w11 is a non-modal transient, w12 is
38 // a modal transient. 38 // a modal transient.
39 // Validates: 39 // Validates:
40 // - it should be possible to activate w12 even when w11 is open. 40 // - it should be possible to activate w12 even when w11 is open.
41 // - activating w1 activates w12 and updates stacking order appropriately. 41 // - activating w1 activates w12 and updates stacking order appropriately.
42 // - closing a window passes focus up the stack. 42 // - closing a window passes focus up the stack.
43 TEST_F(WindowModalityControllerTest, BasicActivation) { 43 TEST_F(WindowModalityControllerTest, BasicActivation) {
44 aura::test::TestWindowDelegate d; 44 aura::test::TestWindowDelegate d;
45 scoped_ptr<aura::Window> w1( 45 scoped_ptr<aura::Window> w1(
46 aura::test::CreateTestWindowWithDelegate(&d, -1, gfx::Rect(), NULL)); 46 CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect()));
47 scoped_ptr<aura::Window> w11( 47 scoped_ptr<aura::Window> w11(
48 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), NULL)); 48 CreateTestWindowInShellWithDelegate(&d, -11, gfx::Rect()));
49 scoped_ptr<aura::Window> w12( 49 scoped_ptr<aura::Window> w12(
50 aura::test::CreateTestWindowWithDelegate(&d, -12, gfx::Rect(), NULL)); 50 CreateTestWindowInShellWithDelegate(&d, -12, gfx::Rect()));
51 51
52 w1->AddTransientChild(w11.get()); 52 w1->AddTransientChild(w11.get());
53 wm::ActivateWindow(w1.get()); 53 wm::ActivateWindow(w1.get());
54 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 54 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
55 wm::ActivateWindow(w11.get()); 55 wm::ActivateWindow(w11.get());
56 EXPECT_TRUE(wm::IsActiveWindow(w11.get())); 56 EXPECT_TRUE(wm::IsActiveWindow(w11.get()));
57 57
58 w12->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); 58 w12->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
59 w1->AddTransientChild(w12.get()); 59 w1->AddTransientChild(w12.get());
60 wm::ActivateWindow(w12.get()); 60 wm::ActivateWindow(w12.get());
(...skipping 20 matching lines...) Expand all
81 81
82 // Create two toplevel windows w1 and w2, and nest two modals w11 and w111 below 82 // Create two toplevel windows w1 and w2, and nest two modals w11 and w111 below
83 // w1. 83 // w1.
84 // Validates: 84 // Validates:
85 // - activating w1 while w11/w111 is showing always activates most deeply nested 85 // - activating w1 while w11/w111 is showing always activates most deeply nested
86 // descendant. 86 // descendant.
87 // - closing a window passes focus up the stack. 87 // - closing a window passes focus up the stack.
88 TEST_F(WindowModalityControllerTest, NestedModals) { 88 TEST_F(WindowModalityControllerTest, NestedModals) {
89 aura::test::TestWindowDelegate d; 89 aura::test::TestWindowDelegate d;
90 scoped_ptr<aura::Window> w1( 90 scoped_ptr<aura::Window> w1(
91 aura::test::CreateTestWindowWithDelegate(&d, -1, gfx::Rect(), NULL)); 91 CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect()));
92 scoped_ptr<aura::Window> w11( 92 scoped_ptr<aura::Window> w11(
93 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), NULL)); 93 CreateTestWindowInShellWithDelegate(&d, -11, gfx::Rect()));
94 scoped_ptr<aura::Window> w111( 94 scoped_ptr<aura::Window> w111(
95 aura::test::CreateTestWindowWithDelegate(&d, -111, gfx::Rect(), NULL)); 95 CreateTestWindowInShellWithDelegate(&d, -111, gfx::Rect()));
96 scoped_ptr<aura::Window> w2( 96 scoped_ptr<aura::Window> w2(
97 aura::test::CreateTestWindowWithDelegate(&d, -2, gfx::Rect(), NULL)); 97 CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect()));
98 98
99 w1->AddTransientChild(w11.get()); 99 w1->AddTransientChild(w11.get());
100 w11->AddTransientChild(w111.get()); 100 w11->AddTransientChild(w111.get());
101 101
102 wm::ActivateWindow(w1.get()); 102 wm::ActivateWindow(w1.get());
103 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 103 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
104 wm::ActivateWindow(w2.get()); 104 wm::ActivateWindow(w2.get());
105 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); 105 EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
106 106
107 // Set up modality. 107 // Set up modality.
(...skipping 26 matching lines...) Expand all
134 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 134 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
135 } 135 }
136 136
137 // Create two toplevel windows w1 and w2, and nest two modals w11 and w111 below 137 // Create two toplevel windows w1 and w2, and nest two modals w11 and w111 below
138 // w1. 138 // w1.
139 // Validates: 139 // Validates:
140 // - destroying w11 while w111 is focused activates w1. 140 // - destroying w11 while w111 is focused activates w1.
141 TEST_F(WindowModalityControllerTest, NestedModalsOuterClosed) { 141 TEST_F(WindowModalityControllerTest, NestedModalsOuterClosed) {
142 aura::test::TestWindowDelegate d; 142 aura::test::TestWindowDelegate d;
143 scoped_ptr<aura::Window> w1( 143 scoped_ptr<aura::Window> w1(
144 aura::test::CreateTestWindowWithDelegate(&d, -1, gfx::Rect(), NULL)); 144 CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect()));
145 scoped_ptr<aura::Window> w11( 145 scoped_ptr<aura::Window> w11(
146 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), NULL)); 146 CreateTestWindowInShellWithDelegate(&d, -11, gfx::Rect()));
147 // |w111| will be owned and deleted by |w11|. 147 // |w111| will be owned and deleted by |w11|.
148 aura::Window* w111 = 148 aura::Window* w111 =
149 aura::test::CreateTestWindowWithDelegate(&d, -111, gfx::Rect(), NULL); 149 CreateTestWindowInShellWithDelegate(&d, -111, gfx::Rect());
150 scoped_ptr<aura::Window> w2( 150 scoped_ptr<aura::Window> w2(
151 aura::test::CreateTestWindowWithDelegate(&d, -2, gfx::Rect(), NULL)); 151 CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect()));
152 152
153 w1->AddTransientChild(w11.get()); 153 w1->AddTransientChild(w11.get());
154 w11->AddTransientChild(w111); 154 w11->AddTransientChild(w111);
155 155
156 wm::ActivateWindow(w1.get()); 156 wm::ActivateWindow(w1.get());
157 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 157 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
158 wm::ActivateWindow(w2.get()); 158 wm::ActivateWindow(w2.get());
159 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); 159 EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
160 160
161 // Set up modality. 161 // Set up modality.
(...skipping 10 matching lines...) Expand all
172 // modal window. There is no such use case right now, but it 172 // modal window. There is no such use case right now, but it
173 // probably should. 173 // probably should.
174 174
175 w11.reset(); 175 w11.reset();
176 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 176 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
177 } 177 }
178 178
179 // Modality also prevents events from being passed to the transient parent. 179 // Modality also prevents events from being passed to the transient parent.
180 TEST_F(WindowModalityControllerTest, Events) { 180 TEST_F(WindowModalityControllerTest, Events) {
181 aura::test::TestWindowDelegate d; 181 aura::test::TestWindowDelegate d;
182 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate(&d, -1, 182 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(&d, -1,
183 gfx::Rect(0, 0, 100, 100), NULL)); 183 gfx::Rect(0, 0, 100, 100)));
184 scoped_ptr<aura::Window> w11(aura::test::CreateTestWindowWithDelegate(&d, -11, 184 scoped_ptr<aura::Window> w11(CreateTestWindowInShellWithDelegate(&d, -11,
185 gfx::Rect(20, 20, 50, 50), NULL)); 185 gfx::Rect(20, 20, 50, 50)));
186 186
187 w1->AddTransientChild(w11.get()); 187 w1->AddTransientChild(w11.get());
188 188
189 { 189 {
190 // Clicking a point within w1 should activate that window. 190 // Clicking a point within w1 should activate that window.
191 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 191 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
192 gfx::Point(10, 10)); 192 gfx::Point(10, 10));
193 generator.ClickLeftButton(); 193 generator.ClickLeftButton();
194 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 194 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
195 } 195 }
196 196
197 w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); 197 w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
198 198
199 { 199 {
200 // Clicking a point within w1 should activate w11. 200 // Clicking a point within w1 should activate w11.
201 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 201 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
202 gfx::Point(10, 10)); 202 gfx::Point(10, 10));
203 generator.ClickLeftButton(); 203 generator.ClickLeftButton();
204 EXPECT_TRUE(wm::IsActiveWindow(w11.get())); 204 EXPECT_TRUE(wm::IsActiveWindow(w11.get()));
205 } 205 }
206 } 206 }
207 207
208 // Creates windows w1 and non activatiable child w11. Creates transient window 208 // Creates windows w1 and non activatiable child w11. Creates transient window
209 // w2 and adds it as a transeint child of w1. Ensures that w2 is parented to 209 // w2 and adds it as a transeint child of w1. Ensures that w2 is parented to
210 // the parent of w1, and that GetModalTransient(w11) returns w2. 210 // the parent of w1, and that GetModalTransient(w11) returns w2.
211 TEST_F(WindowModalityControllerTest, GetModalTransient) { 211 TEST_F(WindowModalityControllerTest, GetModalTransient) {
212 aura::test::TestWindowDelegate d; 212 aura::test::TestWindowDelegate d;
213 scoped_ptr<aura::Window> w1( 213 scoped_ptr<aura::Window> w1(
214 aura::test::CreateTestWindowWithDelegate(&d, -1, gfx::Rect(), NULL)); 214 CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect()));
215 scoped_ptr<aura::Window> w11( 215 scoped_ptr<aura::Window> w11(
216 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get())); 216 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get()));
217 scoped_ptr<aura::Window> w2( 217 scoped_ptr<aura::Window> w2(
218 aura::test::CreateTestWindowWithDelegate(&d, -2, gfx::Rect(), NULL)); 218 CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect()));
219 w2->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); 219 w2->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
220 220
221 aura::Window* wt; 221 aura::Window* wt;
222 wt = wm::GetModalTransient(w1.get()); 222 wt = wm::GetModalTransient(w1.get());
223 ASSERT_EQ(static_cast<aura::Window*>(NULL), wt); 223 ASSERT_EQ(static_cast<aura::Window*>(NULL), wt);
224 224
225 // Parent w2 to w1. It should get parented to the parent of w1. 225 // Parent w2 to w1. It should get parented to the parent of w1.
226 w1->AddTransientChild(w2.get()); 226 w1->AddTransientChild(w2.get());
227 ASSERT_EQ(2U, w1->parent()->children().size()); 227 ASSERT_EQ(2U, w1->parent()->children().size());
228 EXPECT_EQ(-2, w1->parent()->children().at(1)->id()); 228 EXPECT_EQ(-2, w1->parent()->children().at(1)->id());
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 } 301 }
302 302
303 bool received_touch_; 303 bool received_touch_;
304 304
305 DISALLOW_COPY_AND_ASSIGN(TouchTrackerWindowDelegate); 305 DISALLOW_COPY_AND_ASSIGN(TouchTrackerWindowDelegate);
306 }; 306 };
307 307
308 // Modality should prevent events from being passed to the transient parent. 308 // Modality should prevent events from being passed to the transient parent.
309 TEST_F(WindowModalityControllerTest, TouchEvent) { 309 TEST_F(WindowModalityControllerTest, TouchEvent) {
310 TouchTrackerWindowDelegate d1; 310 TouchTrackerWindowDelegate d1;
311 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate(&d1, 311 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(&d1,
312 -1, gfx::Rect(0, 0, 100, 100), NULL)); 312 -1, gfx::Rect(0, 0, 100, 100)));
313 TouchTrackerWindowDelegate d11; 313 TouchTrackerWindowDelegate d11;
314 scoped_ptr<aura::Window> w11(aura::test::CreateTestWindowWithDelegate(&d11, 314 scoped_ptr<aura::Window> w11(CreateTestWindowInShellWithDelegate(&d11,
315 -11, gfx::Rect(20, 20, 50, 50), NULL)); 315 -11, gfx::Rect(20, 20, 50, 50)));
316 316
317 w1->AddTransientChild(w11.get()); 317 w1->AddTransientChild(w11.get());
318 d1.reset(); 318 d1.reset();
319 d11.reset(); 319 d11.reset();
320 320
321 { 321 {
322 // Clicking a point within w1 should activate that window. 322 // Clicking a point within w1 should activate that window.
323 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 323 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
324 gfx::Point(10, 10)); 324 gfx::Point(10, 10));
325 generator.PressMoveAndReleaseTouchTo(gfx::Point(10, 10)); 325 generator.PressMoveAndReleaseTouchTo(gfx::Point(10, 10));
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 EXPECT_FALSE(modal_parent->HasFocus()); 489 EXPECT_FALSE(modal_parent->HasFocus());
490 EXPECT_FALSE(parent->HasFocus()); 490 EXPECT_FALSE(parent->HasFocus());
491 } 491 }
492 } 492 }
493 493
494 // Window-modal test for the case when the originally clicked window is an 494 // Window-modal test for the case when the originally clicked window is an
495 // ancestor of the modal parent. 495 // ancestor of the modal parent.
496 TEST_F(WindowModalityControllerTest, WindowModalAncestor) { 496 TEST_F(WindowModalityControllerTest, WindowModalAncestor) {
497 aura::test::TestWindowDelegate d; 497 aura::test::TestWindowDelegate d;
498 scoped_ptr<aura::Window> w1( 498 scoped_ptr<aura::Window> w1(
499 aura::test::CreateTestWindowWithDelegate(&d, -1, gfx::Rect(), NULL)); 499 CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect()));
500 scoped_ptr<aura::Window> w2( 500 scoped_ptr<aura::Window> w2(
501 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get())); 501 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get()));
502 scoped_ptr<aura::Window> w3( 502 scoped_ptr<aura::Window> w3(
503 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w2.get())); 503 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w2.get()));
504 scoped_ptr<aura::Window> w4( 504 scoped_ptr<aura::Window> w4(
505 aura::test::CreateTestWindowWithDelegate(&d, -2, gfx::Rect(), NULL)); 505 CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect()));
506 w4->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); 506 w4->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
507 w1->AddTransientChild(w4.get()); 507 w1->AddTransientChild(w4.get());
508 508
509 wm::ActivateWindow(w1.get()); 509 wm::ActivateWindow(w1.get());
510 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); 510 EXPECT_TRUE(wm::IsActiveWindow(w4.get()));
511 511
512 wm::ActivateWindow(w2.get()); 512 wm::ActivateWindow(w2.get());
513 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); 513 EXPECT_TRUE(wm::IsActiveWindow(w4.get()));
514 514
515 wm::ActivateWindow(w3.get()); 515 wm::ActivateWindow(w3.get());
516 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); 516 EXPECT_TRUE(wm::IsActiveWindow(w4.get()));
517 517
518 wm::ActivateWindow(w4.get()); 518 wm::ActivateWindow(w4.get());
519 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); 519 EXPECT_TRUE(wm::IsActiveWindow(w4.get()));
520 } 520 }
521 521
522 // Child-modal test for the case when the originally clicked window is an 522 // Child-modal test for the case when the originally clicked window is an
523 // ancestor of the modal parent. 523 // ancestor of the modal parent.
524 TEST_F(WindowModalityControllerTest, ChildModalAncestor) { 524 TEST_F(WindowModalityControllerTest, ChildModalAncestor) {
525 aura::test::TestWindowDelegate d; 525 aura::test::TestWindowDelegate d;
526 scoped_ptr<aura::Window> w1( 526 scoped_ptr<aura::Window> w1(
527 aura::test::CreateTestWindowWithDelegate(&d, -1, gfx::Rect(), NULL)); 527 CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect()));
528 scoped_ptr<aura::Window> w2( 528 scoped_ptr<aura::Window> w2(
529 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get())); 529 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get()));
530 scoped_ptr<aura::Window> w3( 530 scoped_ptr<aura::Window> w3(
531 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w2.get())); 531 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w2.get()));
532 scoped_ptr<aura::Window> w4( 532 scoped_ptr<aura::Window> w4(
533 aura::test::CreateTestWindowWithDelegate(&d, -2, gfx::Rect(), NULL)); 533 CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect()));
534 w4->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_CHILD); 534 w4->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_CHILD);
535 ash::wm::SetModalParent(w4.get(), w2.get()); 535 ash::wm::SetModalParent(w4.get(), w2.get());
536 w1->AddTransientChild(w4.get()); 536 w1->AddTransientChild(w4.get());
537 537
538 wm::ActivateWindow(w1.get()); 538 wm::ActivateWindow(w1.get());
539 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 539 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
540 540
541 wm::ActivateWindow(w2.get()); 541 wm::ActivateWindow(w2.get());
542 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); 542 EXPECT_TRUE(wm::IsActiveWindow(w4.get()));
543 543
544 wm::ActivateWindow(w3.get()); 544 wm::ActivateWindow(w3.get());
545 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); 545 EXPECT_TRUE(wm::IsActiveWindow(w4.get()));
546 546
547 wm::ActivateWindow(w4.get()); 547 wm::ActivateWindow(w4.get());
548 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); 548 EXPECT_TRUE(wm::IsActiveWindow(w4.get()));
549 } 549 }
550 550
551 } // namespace internal 551 } // namespace internal
552 } // namespace ash 552 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/window_manager_unittest.cc ('k') | ash/wm/workspace/multi_window_resize_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698