Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / ash / wm / window_modality_controller_unittest.cc
blob977e70ce6b6086904abb204cce396092d3e44b37
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"
7 #include "ash/shell.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"
22 namespace ash {
24 typedef test::AshTestBase WindowModalityControllerTest;
26 namespace {
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])
31 return false;
33 return true;
36 } // namespace
38 // Creates three windows, w1, w11, and w12. w11 is a non-modal transient, w12 is
39 // a modal transient.
40 // Validates:
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)));
77 w12.reset();
78 EXPECT_TRUE(wm::IsActiveWindow(w11.get()));
79 w11.reset();
80 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
83 // Create two toplevel windows w1 and w2, and nest two modals w11 and w111 below
84 // w1.
85 // Validates:
86 // - activating w1 while w11/w111 is showing always activates most deeply nested
87 // descendant.
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()));
108 // Set up modality.
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)));
130 w2.reset();
131 EXPECT_TRUE(wm::IsActiveWindow(w111.get()));
132 w111.reset();
133 EXPECT_TRUE(wm::IsActiveWindow(w11.get()));
134 w11.reset();
135 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
138 // Create two toplevel windows w1 and w2, and nest two modals w11 and w111 below
139 // w1.
140 // Validates:
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|.
149 aura::Window* w111 =
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()));
162 // Set up modality.
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));
169 w111->Hide();
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
174 // probably should.
176 w11.reset();
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)));
187 scoped_ptr<aura::Window> w111(
188 CreateTestWindowInShellWithDelegate(&d, -111, gfx::Rect(20, 20, 50, 50)));
190 ::wm::AddTransientChild(w1.get(), w11.get());
192 // Add a non-modal child to the modal window in order to ensure modality still
193 // works in this case. This is a regression test for https://crbug.com/456697.
194 ::wm::AddTransientChild(w11.get(), w111.get());
197 // Clicking a point within w1 should activate that window.
198 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
199 gfx::Point(10, 10));
200 generator.ClickLeftButton();
201 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
204 w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
207 // Clicking a point within w1 should activate w11.
208 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
209 gfx::Point(10, 10));
210 generator.ClickLeftButton();
211 EXPECT_TRUE(wm::IsActiveWindow(w11.get()));
215 // Events on modal parent activate.
216 TEST_F(WindowModalityControllerTest, EventsForEclipsedWindows) {
217 aura::test::TestWindowDelegate d;
218 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(&d, -1,
219 gfx::Rect(0, 0, 100, 100)));
220 scoped_ptr<aura::Window> w11(CreateTestWindowInShellWithDelegate(&d, -11,
221 gfx::Rect(20, 20, 50, 50)));
222 ::wm::AddTransientChild(w1.get(), w11.get());
223 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate(&d, -2,
224 gfx::Rect(0, 0, 50, 50)));
226 w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
228 // Partially eclipse w1 with w2.
229 wm::ActivateWindow(w2.get());
231 // Clicking a point on w1 that is not eclipsed by w2.
232 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
233 gfx::Point(90, 90));
234 generator.ClickLeftButton();
235 EXPECT_TRUE(wm::IsActiveWindow(w11.get()));
239 // Creates windows w1 and non activatiable child w11. Creates transient window
240 // w2 and adds it as a transeint child of w1. Ensures that w2 is parented to
241 // the parent of w1, and that GetModalTransient(w11) returns w2.
242 TEST_F(WindowModalityControllerTest, GetModalTransient) {
243 aura::test::TestWindowDelegate d;
244 scoped_ptr<aura::Window> w1(
245 CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect()));
246 scoped_ptr<aura::Window> w11(
247 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get()));
248 scoped_ptr<aura::Window> w2(
249 CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect()));
250 w2->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
252 aura::Window* wt;
253 wt = ::wm::GetModalTransient(w1.get());
254 ASSERT_EQ(static_cast<aura::Window*>(NULL), wt);
256 // Parent w2 to w1. It should get parented to the parent of w1.
257 ::wm::AddTransientChild(w1.get(), w2.get());
258 ASSERT_EQ(2U, w1->parent()->children().size());
259 EXPECT_EQ(-2, w1->parent()->children().at(1)->id());
261 // Request the modal transient window for w1, it should be w2.
262 wt = ::wm::GetModalTransient(w1.get());
263 ASSERT_NE(static_cast<aura::Window*>(NULL), wt);
264 EXPECT_EQ(-2, wt->id());
266 // Request the modal transient window for w11, it should also be w2.
267 wt = ::wm::GetModalTransient(w11.get());
268 ASSERT_NE(static_cast<aura::Window*>(NULL), wt);
269 EXPECT_EQ(-2, wt->id());
272 // Verifies we generate a capture lost when showing a modal window.
273 TEST_F(WindowModalityControllerTest, ChangeCapture) {
274 views::Widget* widget = views::Widget::CreateWindowWithContext(
275 NULL, Shell::GetPrimaryRootWindow());
276 scoped_ptr<aura::Window> widget_window(widget->GetNativeView());
277 views::test::CaptureTrackingView* view = new views::test::CaptureTrackingView;
278 widget->client_view()->AddChildView(view);
279 widget->SetBounds(gfx::Rect(0, 0, 200, 200));
280 view->SetBoundsRect(widget->client_view()->GetLocalBounds());
281 widget->Show();
283 gfx::Point center(view->width() / 2, view->height() / 2);
284 views::View::ConvertPointToScreen(view, &center);
285 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), center);
286 generator.PressLeftButton();
287 EXPECT_TRUE(view->got_press());
289 views::Widget* modal_widget =
290 views::Widget::CreateWindowWithParent(NULL, widget->GetNativeView());
291 scoped_ptr<aura::Window> modal_window(modal_widget->GetNativeView());
292 modal_window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
293 views::test::CaptureTrackingView* modal_view =
294 new views::test::CaptureTrackingView;
295 modal_widget->client_view()->AddChildView(modal_view);
296 modal_widget->SetBounds(gfx::Rect(50, 50, 200, 200));
297 modal_view->SetBoundsRect(modal_widget->client_view()->GetLocalBounds());
298 modal_widget->Show();
300 EXPECT_TRUE(view->got_capture_lost());
301 generator.ReleaseLeftButton();
303 view->reset();
305 EXPECT_FALSE(modal_view->got_capture_lost());
306 EXPECT_FALSE(modal_view->got_press());
308 gfx::Point modal_center(modal_view->width() / 2, modal_view->height() / 2);
309 views::View::ConvertPointToScreen(modal_view, &modal_center);
310 generator.MoveMouseTo(modal_center, 1);
311 generator.PressLeftButton();
312 EXPECT_TRUE(modal_view->got_press());
313 EXPECT_FALSE(modal_view->got_capture_lost());
314 EXPECT_FALSE(view->got_capture_lost());
315 EXPECT_FALSE(view->got_press());
318 class TouchTrackerWindowDelegate : public aura::test::TestWindowDelegate {
319 public:
320 TouchTrackerWindowDelegate()
321 : received_touch_(false),
322 last_event_type_(ui::ET_UNKNOWN) {
324 ~TouchTrackerWindowDelegate() override {}
326 void reset() {
327 received_touch_ = false;
328 last_event_type_ = ui::ET_UNKNOWN;
331 bool received_touch() const { return received_touch_; }
332 ui::EventType last_event_type() const { return last_event_type_; }
334 private:
335 // Overridden from aura::test::TestWindowDelegate.
336 void OnTouchEvent(ui::TouchEvent* event) override {
337 received_touch_ = true;
338 last_event_type_ = event->type();
339 aura::test::TestWindowDelegate::OnTouchEvent(event);
342 bool received_touch_;
343 ui::EventType last_event_type_;
345 DISALLOW_COPY_AND_ASSIGN(TouchTrackerWindowDelegate);
348 // Modality should prevent events from being passed to the transient parent.
349 TEST_F(WindowModalityControllerTest, TouchEvent) {
350 TouchTrackerWindowDelegate d1;
351 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(&d1,
352 -1, gfx::Rect(0, 0, 100, 100)));
353 TouchTrackerWindowDelegate d11;
354 scoped_ptr<aura::Window> w11(CreateTestWindowInShellWithDelegate(&d11,
355 -11, gfx::Rect(20, 20, 50, 50)));
356 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
357 gfx::Point(10, 10));
359 ::wm::AddTransientChild(w1.get(), w11.get());
360 d1.reset();
361 d11.reset();
364 // Clicking a point within w1 should activate that window.
365 generator.PressMoveAndReleaseTouchTo(gfx::Point(10, 10));
366 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
367 EXPECT_TRUE(d1.received_touch());
368 EXPECT_FALSE(d11.received_touch());
372 // Adding a modal window while a touch is down should fire a touch cancel.
373 generator.PressTouch();
374 generator.MoveTouch(gfx::Point(10, 10));
375 d1.reset();
376 d11.reset();
378 w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
379 EXPECT_TRUE(d1.received_touch());
380 EXPECT_EQ(ui::ET_TOUCH_CANCELLED, d1.last_event_type());
381 EXPECT_FALSE(d11.received_touch());
385 // Child-modal test.
386 // Creates:
387 // - A |parent| window that hosts a |modal_parent| window within itself. The
388 // |parent| and |modal_parent| windows are not the same window. The
389 // |modal_parent| window is not activatable, because it's contained within the
390 // |parent| window.
391 // - A |child| window with parent window |parent|, but is modal to
392 // |modal_parent| window.
393 // Validates:
394 // - Clicking on the |modal_parent| should activate the |child| window.
395 // - Clicking on the |parent| window outside of the |modal_parent| bounds should
396 // activate the |parent| window.
397 // - Clicking on the |child| while |parent| is active should activate the
398 // |child| window.
399 // - Focus should follow the active window.
400 TEST_F(WindowModalityControllerTest, ChildModal) {
401 test::ChildModalParent* delegate =
402 new test::ChildModalParent(CurrentContext());
403 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
404 delegate, CurrentContext(), gfx::Rect(0, 0, 400, 400));
405 widget->Show();
407 aura::Window* parent = widget->GetNativeView();
408 EXPECT_TRUE(wm::IsActiveWindow(parent));
410 aura::Window* modal_parent = delegate->GetModalParent();
411 EXPECT_NE(static_cast<aura::Window*>(NULL), modal_parent);
412 EXPECT_NE(parent, modal_parent);
413 EXPECT_FALSE(wm::IsActiveWindow(modal_parent));
415 delegate->ShowChild();
416 aura::Window* child = delegate->GetChild();
417 EXPECT_NE(static_cast<aura::Window*>(NULL), child);
419 EXPECT_TRUE(wm::IsActiveWindow(child));
420 EXPECT_FALSE(wm::IsActiveWindow(modal_parent));
421 EXPECT_FALSE(wm::IsActiveWindow(parent));
423 EXPECT_TRUE(child->HasFocus());
424 EXPECT_FALSE(modal_parent->HasFocus());
425 EXPECT_FALSE(parent->HasFocus());
427 wm::ActivateWindow(modal_parent);
429 EXPECT_TRUE(wm::IsActiveWindow(child));
430 EXPECT_FALSE(wm::IsActiveWindow(modal_parent));
431 EXPECT_FALSE(wm::IsActiveWindow(parent));
433 EXPECT_TRUE(child->HasFocus());
434 EXPECT_FALSE(modal_parent->HasFocus());
435 EXPECT_FALSE(parent->HasFocus());
437 wm::ActivateWindow(parent);
439 EXPECT_FALSE(wm::IsActiveWindow(child));
440 EXPECT_FALSE(wm::IsActiveWindow(modal_parent));
441 EXPECT_TRUE(wm::IsActiveWindow(parent));
443 EXPECT_FALSE(child->HasFocus());
444 EXPECT_FALSE(modal_parent->HasFocus());
445 EXPECT_TRUE(parent->HasFocus());
447 wm::ActivateWindow(child);
449 EXPECT_TRUE(wm::IsActiveWindow(child));
450 EXPECT_FALSE(wm::IsActiveWindow(modal_parent));
451 EXPECT_FALSE(wm::IsActiveWindow(parent));
453 EXPECT_TRUE(child->HasFocus());
454 EXPECT_FALSE(modal_parent->HasFocus());
455 EXPECT_FALSE(parent->HasFocus());
458 // Same as |ChildModal| test, but using |EventGenerator| rather than bypassing
459 // it by calling |ActivateWindow|.
460 TEST_F(WindowModalityControllerTest, ChildModalEventGenerator) {
461 test::ChildModalParent* delegate =
462 new test::ChildModalParent(CurrentContext());
463 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
464 delegate, CurrentContext(), gfx::Rect(0, 0, 400, 400));
465 widget->Show();
467 aura::Window* parent = widget->GetNativeView();
468 EXPECT_TRUE(wm::IsActiveWindow(parent));
470 aura::Window* modal_parent = delegate->GetModalParent();
471 EXPECT_NE(static_cast<aura::Window*>(NULL), modal_parent);
472 EXPECT_NE(parent, modal_parent);
473 EXPECT_FALSE(wm::IsActiveWindow(modal_parent));
475 delegate->ShowChild();
476 aura::Window* child = delegate->GetChild();
477 EXPECT_NE(static_cast<aura::Window*>(NULL), child);
479 EXPECT_TRUE(wm::IsActiveWindow(child));
480 EXPECT_FALSE(wm::IsActiveWindow(modal_parent));
481 EXPECT_FALSE(wm::IsActiveWindow(parent));
483 EXPECT_TRUE(child->HasFocus());
484 EXPECT_FALSE(modal_parent->HasFocus());
485 EXPECT_FALSE(parent->HasFocus());
488 ui::test::EventGenerator generator(
489 Shell::GetPrimaryRootWindow(),
490 parent->bounds().origin() +
491 gfx::Vector2d(10, parent->bounds().height() - 10));
492 generator.ClickLeftButton();
493 generator.ClickLeftButton();
495 EXPECT_TRUE(wm::IsActiveWindow(child));
496 EXPECT_FALSE(wm::IsActiveWindow(modal_parent));
497 EXPECT_FALSE(wm::IsActiveWindow(parent));
499 EXPECT_TRUE(child->HasFocus());
500 EXPECT_FALSE(modal_parent->HasFocus());
501 EXPECT_FALSE(parent->HasFocus());
505 ui::test::EventGenerator generator(
506 Shell::GetPrimaryRootWindow(),
507 parent->bounds().origin() + gfx::Vector2d(10, 10));
508 generator.ClickLeftButton();
510 EXPECT_FALSE(wm::IsActiveWindow(child));
511 EXPECT_FALSE(wm::IsActiveWindow(modal_parent));
512 EXPECT_TRUE(wm::IsActiveWindow(parent));
514 EXPECT_FALSE(child->HasFocus());
515 EXPECT_FALSE(modal_parent->HasFocus());
516 EXPECT_TRUE(parent->HasFocus());
520 ui::test::EventGenerator generator(
521 Shell::GetPrimaryRootWindow(),
522 child->bounds().origin() + gfx::Vector2d(10, 10));
523 generator.ClickLeftButton();
525 EXPECT_TRUE(wm::IsActiveWindow(child));
526 EXPECT_FALSE(wm::IsActiveWindow(modal_parent));
527 EXPECT_FALSE(wm::IsActiveWindow(parent));
529 EXPECT_TRUE(child->HasFocus());
530 EXPECT_FALSE(modal_parent->HasFocus());
531 EXPECT_FALSE(parent->HasFocus());
535 // Window-modal test for the case when the originally clicked window is an
536 // ancestor of the modal parent.
537 TEST_F(WindowModalityControllerTest, WindowModalAncestor) {
538 aura::test::TestWindowDelegate d;
539 scoped_ptr<aura::Window> w1(
540 CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect()));
541 scoped_ptr<aura::Window> w2(
542 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get()));
543 scoped_ptr<aura::Window> w3(
544 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w2.get()));
545 scoped_ptr<aura::Window> w4(
546 CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect()));
547 w4->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
548 ::wm::AddTransientChild(w1.get(), w4.get());
550 wm::ActivateWindow(w1.get());
551 EXPECT_TRUE(wm::IsActiveWindow(w4.get()));
553 wm::ActivateWindow(w2.get());
554 EXPECT_TRUE(wm::IsActiveWindow(w4.get()));
556 wm::ActivateWindow(w3.get());
557 EXPECT_TRUE(wm::IsActiveWindow(w4.get()));
559 wm::ActivateWindow(w4.get());
560 EXPECT_TRUE(wm::IsActiveWindow(w4.get()));
563 // Child-modal test for the case when the originally clicked window is an
564 // ancestor of the modal parent.
565 TEST_F(WindowModalityControllerTest, ChildModalAncestor) {
566 aura::test::TestWindowDelegate d;
567 scoped_ptr<aura::Window> w1(
568 CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect()));
569 scoped_ptr<aura::Window> w2(
570 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get()));
571 scoped_ptr<aura::Window> w3(
572 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w2.get()));
573 scoped_ptr<aura::Window> w4(
574 CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect()));
575 w4->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_CHILD);
576 ::wm::SetModalParent(w4.get(), w2.get());
577 ::wm::AddTransientChild(w1.get(), w4.get());
579 wm::ActivateWindow(w1.get());
580 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
582 wm::ActivateWindow(w2.get());
583 EXPECT_TRUE(wm::IsActiveWindow(w4.get()));
585 wm::ActivateWindow(w3.get());
586 EXPECT_TRUE(wm::IsActiveWindow(w4.get()));
588 wm::ActivateWindow(w4.get());
589 EXPECT_TRUE(wm::IsActiveWindow(w4.get()));
592 } // namespace ash