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.
5 #include "ui/wm/core/window_modality_controller.h"
8 #include "ash/test/ash_test_base.h"
9 #include "ash/test/child_modal_window.h"
10 #include "ash/wm/window_util.h"
11 #include "ui/aura/client/aura_constants.h"
12 #include "ui/aura/test/test_window_delegate.h"
13 #include "ui/aura/test/test_windows.h"
14 #include "ui/aura/window.h"
15 #include "ui/aura/window_event_dispatcher.h"
16 #include "ui/base/ui_base_types.h"
17 #include "ui/events/test/event_generator.h"
18 #include "ui/views/test/capture_tracking_view.h"
19 #include "ui/views/widget/widget.h"
20 #include "ui/wm/core/window_util.h"
24 typedef test::AshTestBase WindowModalityControllerTest
;
28 bool ValidateStacking(aura::Window
* parent
, int ids
[], int count
) {
29 for (int i
= 0; i
< count
; ++i
) {
30 if (parent
->children().at(i
)->id() != ids
[i
])
38 // Creates three windows, w1, w11, and w12. w11 is a non-modal transient, w12 is
41 // - it should be possible to activate w12 even when w11 is open.
42 // - activating w1 activates w12 and updates stacking order appropriately.
43 // - closing a window passes focus up the stack.
44 TEST_F(WindowModalityControllerTest
, BasicActivation
) {
45 aura::test::TestWindowDelegate d
;
46 scoped_ptr
<aura::Window
> w1(
47 CreateTestWindowInShellWithDelegate(&d
, -1, gfx::Rect()));
48 scoped_ptr
<aura::Window
> w11(
49 CreateTestWindowInShellWithDelegate(&d
, -11, gfx::Rect()));
50 scoped_ptr
<aura::Window
> w12(
51 CreateTestWindowInShellWithDelegate(&d
, -12, gfx::Rect()));
53 ::wm::AddTransientChild(w1
.get(), w11
.get());
54 wm::ActivateWindow(w1
.get());
55 EXPECT_TRUE(wm::IsActiveWindow(w1
.get()));
56 wm::ActivateWindow(w11
.get());
57 EXPECT_TRUE(wm::IsActiveWindow(w11
.get()));
59 w12
->SetProperty(aura::client::kModalKey
, ui::MODAL_TYPE_WINDOW
);
60 ::wm::AddTransientChild(w1
.get(), w12
.get());
61 wm::ActivateWindow(w12
.get());
62 EXPECT_TRUE(wm::IsActiveWindow(w12
.get()));
64 wm::ActivateWindow(w11
.get());
65 EXPECT_TRUE(wm::IsActiveWindow(w11
.get()));
67 int check1
[] = { -1, -12, -11 };
68 EXPECT_TRUE(ValidateStacking(w1
->parent(), check1
, arraysize(check1
)));
70 wm::ActivateWindow(w1
.get());
71 EXPECT_TRUE(wm::IsActiveWindow(w12
.get()));
72 // Transient children are always stacked above their transient parent, which
73 // is why this order is not -11, -1, -12.
74 int check2
[] = { -1, -11, -12 };
75 EXPECT_TRUE(ValidateStacking(w1
->parent(), check2
, arraysize(check2
)));
78 EXPECT_TRUE(wm::IsActiveWindow(w11
.get()));
80 EXPECT_TRUE(wm::IsActiveWindow(w1
.get()));
83 // Create two toplevel windows w1 and w2, and nest two modals w11 and w111 below
86 // - activating w1 while w11/w111 is showing always activates most deeply nested
88 // - closing a window passes focus up the stack.
89 TEST_F(WindowModalityControllerTest
, NestedModals
) {
90 aura::test::TestWindowDelegate d
;
91 scoped_ptr
<aura::Window
> w1(
92 CreateTestWindowInShellWithDelegate(&d
, -1, gfx::Rect()));
93 scoped_ptr
<aura::Window
> w11(
94 CreateTestWindowInShellWithDelegate(&d
, -11, gfx::Rect()));
95 scoped_ptr
<aura::Window
> w111(
96 CreateTestWindowInShellWithDelegate(&d
, -111, gfx::Rect()));
97 scoped_ptr
<aura::Window
> w2(
98 CreateTestWindowInShellWithDelegate(&d
, -2, gfx::Rect()));
100 ::wm::AddTransientChild(w1
.get(), w11
.get());
101 ::wm::AddTransientChild(w11
.get(), w111
.get());
103 wm::ActivateWindow(w1
.get());
104 EXPECT_TRUE(wm::IsActiveWindow(w1
.get()));
105 wm::ActivateWindow(w2
.get());
106 EXPECT_TRUE(wm::IsActiveWindow(w2
.get()));
109 w11
->SetProperty(aura::client::kModalKey
, ui::MODAL_TYPE_WINDOW
);
110 w111
->SetProperty(aura::client::kModalKey
, ui::MODAL_TYPE_WINDOW
);
112 wm::ActivateWindow(w1
.get());
113 EXPECT_TRUE(wm::IsActiveWindow(w111
.get()));
114 int check1
[] = { -2, -1, -11, -111 };
115 EXPECT_TRUE(ValidateStacking(w1
->parent(), check1
, arraysize(check1
)));
117 wm::ActivateWindow(w11
.get());
118 EXPECT_TRUE(wm::IsActiveWindow(w111
.get()));
119 EXPECT_TRUE(ValidateStacking(w1
->parent(), check1
, arraysize(check1
)));
121 wm::ActivateWindow(w111
.get());
122 EXPECT_TRUE(wm::IsActiveWindow(w111
.get()));
123 EXPECT_TRUE(ValidateStacking(w1
->parent(), check1
, arraysize(check1
)));
125 wm::ActivateWindow(w2
.get());
126 EXPECT_TRUE(wm::IsActiveWindow(w2
.get()));
127 int check2
[] = { -1, -11, -111, -2 };
128 EXPECT_TRUE(ValidateStacking(w1
->parent(), check2
, arraysize(check2
)));
131 EXPECT_TRUE(wm::IsActiveWindow(w111
.get()));
133 EXPECT_TRUE(wm::IsActiveWindow(w11
.get()));
135 EXPECT_TRUE(wm::IsActiveWindow(w1
.get()));
138 // Create two toplevel windows w1 and w2, and nest two modals w11 and w111 below
141 // - destroying w11 while w111 is focused activates w1.
142 TEST_F(WindowModalityControllerTest
, NestedModalsOuterClosed
) {
143 aura::test::TestWindowDelegate d
;
144 scoped_ptr
<aura::Window
> w1(
145 CreateTestWindowInShellWithDelegate(&d
, -1, gfx::Rect()));
146 scoped_ptr
<aura::Window
> w11(
147 CreateTestWindowInShellWithDelegate(&d
, -11, gfx::Rect()));
148 // |w111| will be owned and deleted by |w11|.
150 CreateTestWindowInShellWithDelegate(&d
, -111, gfx::Rect());
151 scoped_ptr
<aura::Window
> w2(
152 CreateTestWindowInShellWithDelegate(&d
, -2, gfx::Rect()));
154 ::wm::AddTransientChild(w1
.get(), w11
.get());
155 ::wm::AddTransientChild(w11
.get(), w111
);
157 wm::ActivateWindow(w1
.get());
158 EXPECT_TRUE(wm::IsActiveWindow(w1
.get()));
159 wm::ActivateWindow(w2
.get());
160 EXPECT_TRUE(wm::IsActiveWindow(w2
.get()));
163 w11
->SetProperty(aura::client::kModalKey
, ui::MODAL_TYPE_WINDOW
);
164 w111
->SetProperty(aura::client::kModalKey
, ui::MODAL_TYPE_WINDOW
);
166 wm::ActivateWindow(w1
.get());
167 EXPECT_TRUE(wm::IsActiveWindow(w111
));
170 EXPECT_TRUE(wm::IsActiveWindow(w11
.get()));
172 // TODO(oshima): Re-showing doesn't set the focus back to
173 // modal window. There is no such use case right now, but it
177 EXPECT_TRUE(wm::IsActiveWindow(w1
.get()));
180 // Modality also prevents events from being passed to the transient parent.
181 TEST_F(WindowModalityControllerTest
, Events
) {
182 aura::test::TestWindowDelegate d
;
183 scoped_ptr
<aura::Window
> w1(CreateTestWindowInShellWithDelegate(&d
, -1,
184 gfx::Rect(0, 0, 100, 100)));
185 scoped_ptr
<aura::Window
> w11(CreateTestWindowInShellWithDelegate(&d
, -11,
186 gfx::Rect(20, 20, 50, 50)));
188 ::wm::AddTransientChild(w1
.get(), w11
.get());
191 // Clicking a point within w1 should activate that window.
192 ui::test::EventGenerator
generator(Shell::GetPrimaryRootWindow(),
194 generator
.ClickLeftButton();
195 EXPECT_TRUE(wm::IsActiveWindow(w1
.get()));
198 w11
->SetProperty(aura::client::kModalKey
, ui::MODAL_TYPE_WINDOW
);
201 // Clicking a point within w1 should activate w11.
202 ui::test::EventGenerator
generator(Shell::GetPrimaryRootWindow(),
204 generator
.ClickLeftButton();
205 EXPECT_TRUE(wm::IsActiveWindow(w11
.get()));
209 // Events on modal parent activate.
210 TEST_F(WindowModalityControllerTest
, EventsForEclipsedWindows
) {
211 aura::test::TestWindowDelegate d
;
212 scoped_ptr
<aura::Window
> w1(CreateTestWindowInShellWithDelegate(&d
, -1,
213 gfx::Rect(0, 0, 100, 100)));
214 scoped_ptr
<aura::Window
> w11(CreateTestWindowInShellWithDelegate(&d
, -11,
215 gfx::Rect(20, 20, 50, 50)));
216 ::wm::AddTransientChild(w1
.get(), w11
.get());
217 scoped_ptr
<aura::Window
> w2(CreateTestWindowInShellWithDelegate(&d
, -2,
218 gfx::Rect(0, 0, 50, 50)));
220 w11
->SetProperty(aura::client::kModalKey
, ui::MODAL_TYPE_WINDOW
);
222 // Partially eclipse w1 with w2.
223 wm::ActivateWindow(w2
.get());
225 // Clicking a point on w1 that is not eclipsed by w2.
226 ui::test::EventGenerator
generator(Shell::GetPrimaryRootWindow(),
228 generator
.ClickLeftButton();
229 EXPECT_TRUE(wm::IsActiveWindow(w11
.get()));
233 // Creates windows w1 and non activatiable child w11. Creates transient window
234 // w2 and adds it as a transeint child of w1. Ensures that w2 is parented to
235 // the parent of w1, and that GetModalTransient(w11) returns w2.
236 TEST_F(WindowModalityControllerTest
, GetModalTransient
) {
237 aura::test::TestWindowDelegate d
;
238 scoped_ptr
<aura::Window
> w1(
239 CreateTestWindowInShellWithDelegate(&d
, -1, gfx::Rect()));
240 scoped_ptr
<aura::Window
> w11(
241 aura::test::CreateTestWindowWithDelegate(&d
, -11, gfx::Rect(), w1
.get()));
242 scoped_ptr
<aura::Window
> w2(
243 CreateTestWindowInShellWithDelegate(&d
, -2, gfx::Rect()));
244 w2
->SetProperty(aura::client::kModalKey
, ui::MODAL_TYPE_WINDOW
);
247 wt
= ::wm::GetModalTransient(w1
.get());
248 ASSERT_EQ(static_cast<aura::Window
*>(NULL
), wt
);
250 // Parent w2 to w1. It should get parented to the parent of w1.
251 ::wm::AddTransientChild(w1
.get(), w2
.get());
252 ASSERT_EQ(2U, w1
->parent()->children().size());
253 EXPECT_EQ(-2, w1
->parent()->children().at(1)->id());
255 // Request the modal transient window for w1, it should be w2.
256 wt
= ::wm::GetModalTransient(w1
.get());
257 ASSERT_NE(static_cast<aura::Window
*>(NULL
), wt
);
258 EXPECT_EQ(-2, wt
->id());
260 // Request the modal transient window for w11, it should also be w2.
261 wt
= ::wm::GetModalTransient(w11
.get());
262 ASSERT_NE(static_cast<aura::Window
*>(NULL
), wt
);
263 EXPECT_EQ(-2, wt
->id());
266 // Verifies we generate a capture lost when showing a modal window.
267 TEST_F(WindowModalityControllerTest
, ChangeCapture
) {
268 views::Widget
* widget
= views::Widget::CreateWindowWithContext(
269 NULL
, Shell::GetPrimaryRootWindow());
270 scoped_ptr
<aura::Window
> widget_window(widget
->GetNativeView());
271 views::test::CaptureTrackingView
* view
= new views::test::CaptureTrackingView
;
272 widget
->client_view()->AddChildView(view
);
273 widget
->SetBounds(gfx::Rect(0, 0, 200, 200));
274 view
->SetBoundsRect(widget
->client_view()->GetLocalBounds());
277 gfx::Point
center(view
->width() / 2, view
->height() / 2);
278 views::View::ConvertPointToScreen(view
, ¢er
);
279 ui::test::EventGenerator
generator(Shell::GetPrimaryRootWindow(), center
);
280 generator
.PressLeftButton();
281 EXPECT_TRUE(view
->got_press());
283 views::Widget
* modal_widget
=
284 views::Widget::CreateWindowWithParent(NULL
, widget
->GetNativeView());
285 scoped_ptr
<aura::Window
> modal_window(modal_widget
->GetNativeView());
286 modal_window
->SetProperty(aura::client::kModalKey
, ui::MODAL_TYPE_WINDOW
);
287 views::test::CaptureTrackingView
* modal_view
=
288 new views::test::CaptureTrackingView
;
289 modal_widget
->client_view()->AddChildView(modal_view
);
290 modal_widget
->SetBounds(gfx::Rect(50, 50, 200, 200));
291 modal_view
->SetBoundsRect(modal_widget
->client_view()->GetLocalBounds());
292 modal_widget
->Show();
294 EXPECT_TRUE(view
->got_capture_lost());
295 generator
.ReleaseLeftButton();
299 EXPECT_FALSE(modal_view
->got_capture_lost());
300 EXPECT_FALSE(modal_view
->got_press());
302 gfx::Point
modal_center(modal_view
->width() / 2, modal_view
->height() / 2);
303 views::View::ConvertPointToScreen(modal_view
, &modal_center
);
304 generator
.MoveMouseTo(modal_center
, 1);
305 generator
.PressLeftButton();
306 EXPECT_TRUE(modal_view
->got_press());
307 EXPECT_FALSE(modal_view
->got_capture_lost());
308 EXPECT_FALSE(view
->got_capture_lost());
309 EXPECT_FALSE(view
->got_press());
312 class TouchTrackerWindowDelegate
: public aura::test::TestWindowDelegate
{
314 TouchTrackerWindowDelegate()
315 : received_touch_(false),
316 last_event_type_(ui::ET_UNKNOWN
) {
318 ~TouchTrackerWindowDelegate() override
{}
321 received_touch_
= false;
322 last_event_type_
= ui::ET_UNKNOWN
;
325 bool received_touch() const { return received_touch_
; }
326 ui::EventType
last_event_type() const { return last_event_type_
; }
329 // Overridden from aura::test::TestWindowDelegate.
330 void OnTouchEvent(ui::TouchEvent
* event
) override
{
331 received_touch_
= true;
332 last_event_type_
= event
->type();
333 aura::test::TestWindowDelegate::OnTouchEvent(event
);
336 bool received_touch_
;
337 ui::EventType last_event_type_
;
339 DISALLOW_COPY_AND_ASSIGN(TouchTrackerWindowDelegate
);
342 // Modality should prevent events from being passed to the transient parent.
343 TEST_F(WindowModalityControllerTest
, TouchEvent
) {
344 TouchTrackerWindowDelegate d1
;
345 scoped_ptr
<aura::Window
> w1(CreateTestWindowInShellWithDelegate(&d1
,
346 -1, gfx::Rect(0, 0, 100, 100)));
347 TouchTrackerWindowDelegate d11
;
348 scoped_ptr
<aura::Window
> w11(CreateTestWindowInShellWithDelegate(&d11
,
349 -11, gfx::Rect(20, 20, 50, 50)));
350 ui::test::EventGenerator
generator(Shell::GetPrimaryRootWindow(),
353 ::wm::AddTransientChild(w1
.get(), w11
.get());
358 // Clicking a point within w1 should activate that window.
359 generator
.PressMoveAndReleaseTouchTo(gfx::Point(10, 10));
360 EXPECT_TRUE(wm::IsActiveWindow(w1
.get()));
361 EXPECT_TRUE(d1
.received_touch());
362 EXPECT_FALSE(d11
.received_touch());
366 // Adding a modal window while a touch is down should fire a touch cancel.
367 generator
.PressTouch();
368 generator
.MoveTouch(gfx::Point(10, 10));
372 w11
->SetProperty(aura::client::kModalKey
, ui::MODAL_TYPE_WINDOW
);
373 EXPECT_TRUE(d1
.received_touch());
374 EXPECT_EQ(ui::ET_TOUCH_CANCELLED
, d1
.last_event_type());
375 EXPECT_FALSE(d11
.received_touch());
381 // - A |parent| window that hosts a |modal_parent| window within itself. The
382 // |parent| and |modal_parent| windows are not the same window. The
383 // |modal_parent| window is not activatable, because it's contained within the
385 // - A |child| window with parent window |parent|, but is modal to
386 // |modal_parent| window.
388 // - Clicking on the |modal_parent| should activate the |child| window.
389 // - Clicking on the |parent| window outside of the |modal_parent| bounds should
390 // activate the |parent| window.
391 // - Clicking on the |child| while |parent| is active should activate the
393 // - Focus should follow the active window.
394 TEST_F(WindowModalityControllerTest
, ChildModal
) {
395 test::ChildModalParent
* delegate
=
396 new test::ChildModalParent(CurrentContext());
397 views::Widget
* widget
= views::Widget::CreateWindowWithContextAndBounds(
398 delegate
, CurrentContext(), gfx::Rect(0, 0, 400, 400));
401 aura::Window
* parent
= widget
->GetNativeView();
402 EXPECT_TRUE(wm::IsActiveWindow(parent
));
404 aura::Window
* modal_parent
= delegate
->GetModalParent();
405 EXPECT_NE(static_cast<aura::Window
*>(NULL
), modal_parent
);
406 EXPECT_NE(parent
, modal_parent
);
407 EXPECT_FALSE(wm::IsActiveWindow(modal_parent
));
409 delegate
->ShowChild();
410 aura::Window
* child
= delegate
->GetChild();
411 EXPECT_NE(static_cast<aura::Window
*>(NULL
), child
);
413 EXPECT_TRUE(wm::IsActiveWindow(child
));
414 EXPECT_FALSE(wm::IsActiveWindow(modal_parent
));
415 EXPECT_FALSE(wm::IsActiveWindow(parent
));
417 EXPECT_TRUE(child
->HasFocus());
418 EXPECT_FALSE(modal_parent
->HasFocus());
419 EXPECT_FALSE(parent
->HasFocus());
421 wm::ActivateWindow(modal_parent
);
423 EXPECT_TRUE(wm::IsActiveWindow(child
));
424 EXPECT_FALSE(wm::IsActiveWindow(modal_parent
));
425 EXPECT_FALSE(wm::IsActiveWindow(parent
));
427 EXPECT_TRUE(child
->HasFocus());
428 EXPECT_FALSE(modal_parent
->HasFocus());
429 EXPECT_FALSE(parent
->HasFocus());
431 wm::ActivateWindow(parent
);
433 EXPECT_FALSE(wm::IsActiveWindow(child
));
434 EXPECT_FALSE(wm::IsActiveWindow(modal_parent
));
435 EXPECT_TRUE(wm::IsActiveWindow(parent
));
437 EXPECT_FALSE(child
->HasFocus());
438 EXPECT_FALSE(modal_parent
->HasFocus());
439 EXPECT_TRUE(parent
->HasFocus());
441 wm::ActivateWindow(child
);
443 EXPECT_TRUE(wm::IsActiveWindow(child
));
444 EXPECT_FALSE(wm::IsActiveWindow(modal_parent
));
445 EXPECT_FALSE(wm::IsActiveWindow(parent
));
447 EXPECT_TRUE(child
->HasFocus());
448 EXPECT_FALSE(modal_parent
->HasFocus());
449 EXPECT_FALSE(parent
->HasFocus());
452 // Same as |ChildModal| test, but using |EventGenerator| rather than bypassing
453 // it by calling |ActivateWindow|.
454 TEST_F(WindowModalityControllerTest
, ChildModalEventGenerator
) {
455 test::ChildModalParent
* delegate
=
456 new test::ChildModalParent(CurrentContext());
457 views::Widget
* widget
= views::Widget::CreateWindowWithContextAndBounds(
458 delegate
, CurrentContext(), gfx::Rect(0, 0, 400, 400));
461 aura::Window
* parent
= widget
->GetNativeView();
462 EXPECT_TRUE(wm::IsActiveWindow(parent
));
464 aura::Window
* modal_parent
= delegate
->GetModalParent();
465 EXPECT_NE(static_cast<aura::Window
*>(NULL
), modal_parent
);
466 EXPECT_NE(parent
, modal_parent
);
467 EXPECT_FALSE(wm::IsActiveWindow(modal_parent
));
469 delegate
->ShowChild();
470 aura::Window
* child
= delegate
->GetChild();
471 EXPECT_NE(static_cast<aura::Window
*>(NULL
), child
);
473 EXPECT_TRUE(wm::IsActiveWindow(child
));
474 EXPECT_FALSE(wm::IsActiveWindow(modal_parent
));
475 EXPECT_FALSE(wm::IsActiveWindow(parent
));
477 EXPECT_TRUE(child
->HasFocus());
478 EXPECT_FALSE(modal_parent
->HasFocus());
479 EXPECT_FALSE(parent
->HasFocus());
482 ui::test::EventGenerator
generator(
483 Shell::GetPrimaryRootWindow(),
484 parent
->bounds().origin() +
485 gfx::Vector2d(10, parent
->bounds().height() - 10));
486 generator
.ClickLeftButton();
487 generator
.ClickLeftButton();
489 EXPECT_TRUE(wm::IsActiveWindow(child
));
490 EXPECT_FALSE(wm::IsActiveWindow(modal_parent
));
491 EXPECT_FALSE(wm::IsActiveWindow(parent
));
493 EXPECT_TRUE(child
->HasFocus());
494 EXPECT_FALSE(modal_parent
->HasFocus());
495 EXPECT_FALSE(parent
->HasFocus());
499 ui::test::EventGenerator
generator(
500 Shell::GetPrimaryRootWindow(),
501 parent
->bounds().origin() + gfx::Vector2d(10, 10));
502 generator
.ClickLeftButton();
504 EXPECT_FALSE(wm::IsActiveWindow(child
));
505 EXPECT_FALSE(wm::IsActiveWindow(modal_parent
));
506 EXPECT_TRUE(wm::IsActiveWindow(parent
));
508 EXPECT_FALSE(child
->HasFocus());
509 EXPECT_FALSE(modal_parent
->HasFocus());
510 EXPECT_TRUE(parent
->HasFocus());
514 ui::test::EventGenerator
generator(
515 Shell::GetPrimaryRootWindow(),
516 child
->bounds().origin() + gfx::Vector2d(10, 10));
517 generator
.ClickLeftButton();
519 EXPECT_TRUE(wm::IsActiveWindow(child
));
520 EXPECT_FALSE(wm::IsActiveWindow(modal_parent
));
521 EXPECT_FALSE(wm::IsActiveWindow(parent
));
523 EXPECT_TRUE(child
->HasFocus());
524 EXPECT_FALSE(modal_parent
->HasFocus());
525 EXPECT_FALSE(parent
->HasFocus());
529 // Window-modal test for the case when the originally clicked window is an
530 // ancestor of the modal parent.
531 TEST_F(WindowModalityControllerTest
, WindowModalAncestor
) {
532 aura::test::TestWindowDelegate d
;
533 scoped_ptr
<aura::Window
> w1(
534 CreateTestWindowInShellWithDelegate(&d
, -1, gfx::Rect()));
535 scoped_ptr
<aura::Window
> w2(
536 aura::test::CreateTestWindowWithDelegate(&d
, -11, gfx::Rect(), w1
.get()));
537 scoped_ptr
<aura::Window
> w3(
538 aura::test::CreateTestWindowWithDelegate(&d
, -11, gfx::Rect(), w2
.get()));
539 scoped_ptr
<aura::Window
> w4(
540 CreateTestWindowInShellWithDelegate(&d
, -2, gfx::Rect()));
541 w4
->SetProperty(aura::client::kModalKey
, ui::MODAL_TYPE_WINDOW
);
542 ::wm::AddTransientChild(w1
.get(), w4
.get());
544 wm::ActivateWindow(w1
.get());
545 EXPECT_TRUE(wm::IsActiveWindow(w4
.get()));
547 wm::ActivateWindow(w2
.get());
548 EXPECT_TRUE(wm::IsActiveWindow(w4
.get()));
550 wm::ActivateWindow(w3
.get());
551 EXPECT_TRUE(wm::IsActiveWindow(w4
.get()));
553 wm::ActivateWindow(w4
.get());
554 EXPECT_TRUE(wm::IsActiveWindow(w4
.get()));
557 // Child-modal test for the case when the originally clicked window is an
558 // ancestor of the modal parent.
559 TEST_F(WindowModalityControllerTest
, ChildModalAncestor
) {
560 aura::test::TestWindowDelegate d
;
561 scoped_ptr
<aura::Window
> w1(
562 CreateTestWindowInShellWithDelegate(&d
, -1, gfx::Rect()));
563 scoped_ptr
<aura::Window
> w2(
564 aura::test::CreateTestWindowWithDelegate(&d
, -11, gfx::Rect(), w1
.get()));
565 scoped_ptr
<aura::Window
> w3(
566 aura::test::CreateTestWindowWithDelegate(&d
, -11, gfx::Rect(), w2
.get()));
567 scoped_ptr
<aura::Window
> w4(
568 CreateTestWindowInShellWithDelegate(&d
, -2, gfx::Rect()));
569 w4
->SetProperty(aura::client::kModalKey
, ui::MODAL_TYPE_CHILD
);
570 ::wm::SetModalParent(w4
.get(), w2
.get());
571 ::wm::AddTransientChild(w1
.get(), w4
.get());
573 wm::ActivateWindow(w1
.get());
574 EXPECT_TRUE(wm::IsActiveWindow(w1
.get()));
576 wm::ActivateWindow(w2
.get());
577 EXPECT_TRUE(wm::IsActiveWindow(w4
.get()));
579 wm::ActivateWindow(w3
.get());
580 EXPECT_TRUE(wm::IsActiveWindow(w4
.get()));
582 wm::ActivateWindow(w4
.get());
583 EXPECT_TRUE(wm::IsActiveWindow(w4
.get()));