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 "ui/views/corewm/window_modality_controller.h" | 5 #include "ui/views/corewm/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/wm/window_util.h" | 9 #include "ash/wm/window_util.h" |
10 #include "ui/aura/client/aura_constants.h" | 10 #include "ui/aura/client/aura_constants.h" |
11 #include "ui/aura/root_window.h" | 11 #include "ui/aura/root_window.h" |
12 #include "ui/aura/test/event_generator.h" | 12 #include "ui/aura/test/event_generator.h" |
13 #include "ui/aura/test/test_window_delegate.h" | 13 #include "ui/aura/test/test_window_delegate.h" |
14 #include "ui/aura/test/test_windows.h" | 14 #include "ui/aura/test/test_windows.h" |
15 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
16 #include "ui/base/ui_base_types.h" | 16 #include "ui/base/ui_base_types.h" |
| 17 #include "ui/views/corewm/window_util.h" |
17 #include "ui/views/test/capture_tracking_view.h" | 18 #include "ui/views/test/capture_tracking_view.h" |
18 #include "ui/views/test/child_modal_window.h" | 19 #include "ui/views/test/child_modal_window.h" |
19 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
20 | 21 |
21 namespace ash { | 22 namespace ash { |
22 namespace internal { | 23 namespace internal { |
23 | 24 |
24 typedef test::AshTestBase WindowModalityControllerTest; | 25 typedef test::AshTestBase WindowModalityControllerTest; |
25 | 26 |
26 namespace { | 27 namespace { |
(...skipping 16 matching lines...) Expand all Loading... |
43 // - closing a window passes focus up the stack. | 44 // - closing a window passes focus up the stack. |
44 TEST_F(WindowModalityControllerTest, BasicActivation) { | 45 TEST_F(WindowModalityControllerTest, BasicActivation) { |
45 aura::test::TestWindowDelegate d; | 46 aura::test::TestWindowDelegate d; |
46 scoped_ptr<aura::Window> w1( | 47 scoped_ptr<aura::Window> w1( |
47 CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect())); | 48 CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect())); |
48 scoped_ptr<aura::Window> w11( | 49 scoped_ptr<aura::Window> w11( |
49 CreateTestWindowInShellWithDelegate(&d, -11, gfx::Rect())); | 50 CreateTestWindowInShellWithDelegate(&d, -11, gfx::Rect())); |
50 scoped_ptr<aura::Window> w12( | 51 scoped_ptr<aura::Window> w12( |
51 CreateTestWindowInShellWithDelegate(&d, -12, gfx::Rect())); | 52 CreateTestWindowInShellWithDelegate(&d, -12, gfx::Rect())); |
52 | 53 |
53 w1->AddTransientChild(w11.get()); | 54 views::corewm::AddTransientChild(w1.get(), w11.get()); |
54 wm::ActivateWindow(w1.get()); | 55 wm::ActivateWindow(w1.get()); |
55 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 56 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
56 wm::ActivateWindow(w11.get()); | 57 wm::ActivateWindow(w11.get()); |
57 EXPECT_TRUE(wm::IsActiveWindow(w11.get())); | 58 EXPECT_TRUE(wm::IsActiveWindow(w11.get())); |
58 | 59 |
59 w12->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); | 60 w12->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); |
60 w1->AddTransientChild(w12.get()); | 61 views::corewm::AddTransientChild(w1.get(), w12.get()); |
61 wm::ActivateWindow(w12.get()); | 62 wm::ActivateWindow(w12.get()); |
62 EXPECT_TRUE(wm::IsActiveWindow(w12.get())); | 63 EXPECT_TRUE(wm::IsActiveWindow(w12.get())); |
63 | 64 |
64 wm::ActivateWindow(w11.get()); | 65 wm::ActivateWindow(w11.get()); |
65 EXPECT_TRUE(wm::IsActiveWindow(w11.get())); | 66 EXPECT_TRUE(wm::IsActiveWindow(w11.get())); |
66 | 67 |
67 int check1[] = { -1, -12, -11 }; | 68 int check1[] = { -1, -12, -11 }; |
68 EXPECT_TRUE(ValidateStacking(w1->parent(), check1, arraysize(check1))); | 69 EXPECT_TRUE(ValidateStacking(w1->parent(), check1, arraysize(check1))); |
69 | 70 |
70 wm::ActivateWindow(w1.get()); | 71 wm::ActivateWindow(w1.get()); |
(...skipping 19 matching lines...) Expand all Loading... |
90 aura::test::TestWindowDelegate d; | 91 aura::test::TestWindowDelegate d; |
91 scoped_ptr<aura::Window> w1( | 92 scoped_ptr<aura::Window> w1( |
92 CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect())); | 93 CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect())); |
93 scoped_ptr<aura::Window> w11( | 94 scoped_ptr<aura::Window> w11( |
94 CreateTestWindowInShellWithDelegate(&d, -11, gfx::Rect())); | 95 CreateTestWindowInShellWithDelegate(&d, -11, gfx::Rect())); |
95 scoped_ptr<aura::Window> w111( | 96 scoped_ptr<aura::Window> w111( |
96 CreateTestWindowInShellWithDelegate(&d, -111, gfx::Rect())); | 97 CreateTestWindowInShellWithDelegate(&d, -111, gfx::Rect())); |
97 scoped_ptr<aura::Window> w2( | 98 scoped_ptr<aura::Window> w2( |
98 CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect())); | 99 CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect())); |
99 | 100 |
100 w1->AddTransientChild(w11.get()); | 101 views::corewm::AddTransientChild(w1.get(), w11.get()); |
101 w11->AddTransientChild(w111.get()); | 102 views::corewm::AddTransientChild(w11.get(), w111.get()); |
102 | 103 |
103 wm::ActivateWindow(w1.get()); | 104 wm::ActivateWindow(w1.get()); |
104 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 105 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
105 wm::ActivateWindow(w2.get()); | 106 wm::ActivateWindow(w2.get()); |
106 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | 107 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
107 | 108 |
108 // Set up modality. | 109 // Set up modality. |
109 w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); | 110 w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); |
110 w111->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); | 111 w111->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); |
111 | 112 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 scoped_ptr<aura::Window> w1( | 145 scoped_ptr<aura::Window> w1( |
145 CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect())); | 146 CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect())); |
146 scoped_ptr<aura::Window> w11( | 147 scoped_ptr<aura::Window> w11( |
147 CreateTestWindowInShellWithDelegate(&d, -11, gfx::Rect())); | 148 CreateTestWindowInShellWithDelegate(&d, -11, gfx::Rect())); |
148 // |w111| will be owned and deleted by |w11|. | 149 // |w111| will be owned and deleted by |w11|. |
149 aura::Window* w111 = | 150 aura::Window* w111 = |
150 CreateTestWindowInShellWithDelegate(&d, -111, gfx::Rect()); | 151 CreateTestWindowInShellWithDelegate(&d, -111, gfx::Rect()); |
151 scoped_ptr<aura::Window> w2( | 152 scoped_ptr<aura::Window> w2( |
152 CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect())); | 153 CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect())); |
153 | 154 |
154 w1->AddTransientChild(w11.get()); | 155 views::corewm::AddTransientChild(w1.get(), w11.get()); |
155 w11->AddTransientChild(w111); | 156 views::corewm::AddTransientChild(w11.get(), w111); |
156 | 157 |
157 wm::ActivateWindow(w1.get()); | 158 wm::ActivateWindow(w1.get()); |
158 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 159 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
159 wm::ActivateWindow(w2.get()); | 160 wm::ActivateWindow(w2.get()); |
160 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | 161 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
161 | 162 |
162 // Set up modality. | 163 // Set up modality. |
163 w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); | 164 w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); |
164 w111->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); | 165 w111->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); |
165 | 166 |
(...skipping 12 matching lines...) Expand all Loading... |
178 } | 179 } |
179 | 180 |
180 // Modality also prevents events from being passed to the transient parent. | 181 // Modality also prevents events from being passed to the transient parent. |
181 TEST_F(WindowModalityControllerTest, Events) { | 182 TEST_F(WindowModalityControllerTest, Events) { |
182 aura::test::TestWindowDelegate d; | 183 aura::test::TestWindowDelegate d; |
183 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(&d, -1, | 184 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(&d, -1, |
184 gfx::Rect(0, 0, 100, 100))); | 185 gfx::Rect(0, 0, 100, 100))); |
185 scoped_ptr<aura::Window> w11(CreateTestWindowInShellWithDelegate(&d, -11, | 186 scoped_ptr<aura::Window> w11(CreateTestWindowInShellWithDelegate(&d, -11, |
186 gfx::Rect(20, 20, 50, 50))); | 187 gfx::Rect(20, 20, 50, 50))); |
187 | 188 |
188 w1->AddTransientChild(w11.get()); | 189 views::corewm::AddTransientChild(w1.get(), w11.get()); |
189 | 190 |
190 { | 191 { |
191 // Clicking a point within w1 should activate that window. | 192 // Clicking a point within w1 should activate that window. |
192 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 193 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
193 gfx::Point(10, 10)); | 194 gfx::Point(10, 10)); |
194 generator.ClickLeftButton(); | 195 generator.ClickLeftButton(); |
195 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 196 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
196 } | 197 } |
197 | 198 |
198 w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); | 199 w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); |
(...skipping 18 matching lines...) Expand all Loading... |
217 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get())); | 218 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get())); |
218 scoped_ptr<aura::Window> w2( | 219 scoped_ptr<aura::Window> w2( |
219 CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect())); | 220 CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect())); |
220 w2->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); | 221 w2->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); |
221 | 222 |
222 aura::Window* wt; | 223 aura::Window* wt; |
223 wt = views::corewm::GetModalTransient(w1.get()); | 224 wt = views::corewm::GetModalTransient(w1.get()); |
224 ASSERT_EQ(static_cast<aura::Window*>(NULL), wt); | 225 ASSERT_EQ(static_cast<aura::Window*>(NULL), wt); |
225 | 226 |
226 // Parent w2 to w1. It should get parented to the parent of w1. | 227 // Parent w2 to w1. It should get parented to the parent of w1. |
227 w1->AddTransientChild(w2.get()); | 228 views::corewm::AddTransientChild(w1.get(), w2.get()); |
228 ASSERT_EQ(2U, w1->parent()->children().size()); | 229 ASSERT_EQ(2U, w1->parent()->children().size()); |
229 EXPECT_EQ(-2, w1->parent()->children().at(1)->id()); | 230 EXPECT_EQ(-2, w1->parent()->children().at(1)->id()); |
230 | 231 |
231 // Request the modal transient window for w1, it should be w2. | 232 // Request the modal transient window for w1, it should be w2. |
232 wt = views::corewm::GetModalTransient(w1.get()); | 233 wt = views::corewm::GetModalTransient(w1.get()); |
233 ASSERT_NE(static_cast<aura::Window*>(NULL), wt); | 234 ASSERT_NE(static_cast<aura::Window*>(NULL), wt); |
234 EXPECT_EQ(-2, wt->id()); | 235 EXPECT_EQ(-2, wt->id()); |
235 | 236 |
236 // Request the modal transient window for w11, it should also be w2. | 237 // Request the modal transient window for w11, it should also be w2. |
237 wt = views::corewm::GetModalTransient(w11.get()); | 238 wt = views::corewm::GetModalTransient(w11.get()); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 TEST_F(WindowModalityControllerTest, TouchEvent) { | 320 TEST_F(WindowModalityControllerTest, TouchEvent) { |
320 TouchTrackerWindowDelegate d1; | 321 TouchTrackerWindowDelegate d1; |
321 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(&d1, | 322 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(&d1, |
322 -1, gfx::Rect(0, 0, 100, 100))); | 323 -1, gfx::Rect(0, 0, 100, 100))); |
323 TouchTrackerWindowDelegate d11; | 324 TouchTrackerWindowDelegate d11; |
324 scoped_ptr<aura::Window> w11(CreateTestWindowInShellWithDelegate(&d11, | 325 scoped_ptr<aura::Window> w11(CreateTestWindowInShellWithDelegate(&d11, |
325 -11, gfx::Rect(20, 20, 50, 50))); | 326 -11, gfx::Rect(20, 20, 50, 50))); |
326 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 327 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
327 gfx::Point(10, 10)); | 328 gfx::Point(10, 10)); |
328 | 329 |
329 w1->AddTransientChild(w11.get()); | 330 views::corewm::AddTransientChild(w1.get(), w11.get()); |
330 d1.reset(); | 331 d1.reset(); |
331 d11.reset(); | 332 d11.reset(); |
332 | 333 |
333 { | 334 { |
334 // Clicking a point within w1 should activate that window. | 335 // Clicking a point within w1 should activate that window. |
335 generator.PressMoveAndReleaseTouchTo(gfx::Point(10, 10)); | 336 generator.PressMoveAndReleaseTouchTo(gfx::Point(10, 10)); |
336 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 337 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
337 EXPECT_TRUE(d1.received_touch()); | 338 EXPECT_TRUE(d1.received_touch()); |
338 EXPECT_FALSE(d11.received_touch()); | 339 EXPECT_FALSE(d11.received_touch()); |
339 } | 340 } |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 aura::test::TestWindowDelegate d; | 509 aura::test::TestWindowDelegate d; |
509 scoped_ptr<aura::Window> w1( | 510 scoped_ptr<aura::Window> w1( |
510 CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect())); | 511 CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect())); |
511 scoped_ptr<aura::Window> w2( | 512 scoped_ptr<aura::Window> w2( |
512 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get())); | 513 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get())); |
513 scoped_ptr<aura::Window> w3( | 514 scoped_ptr<aura::Window> w3( |
514 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w2.get())); | 515 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w2.get())); |
515 scoped_ptr<aura::Window> w4( | 516 scoped_ptr<aura::Window> w4( |
516 CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect())); | 517 CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect())); |
517 w4->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); | 518 w4->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); |
518 w1->AddTransientChild(w4.get()); | 519 views::corewm::AddTransientChild(w1.get(), w4.get()); |
519 | 520 |
520 wm::ActivateWindow(w1.get()); | 521 wm::ActivateWindow(w1.get()); |
521 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); | 522 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); |
522 | 523 |
523 wm::ActivateWindow(w2.get()); | 524 wm::ActivateWindow(w2.get()); |
524 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); | 525 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); |
525 | 526 |
526 wm::ActivateWindow(w3.get()); | 527 wm::ActivateWindow(w3.get()); |
527 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); | 528 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); |
528 | 529 |
529 wm::ActivateWindow(w4.get()); | 530 wm::ActivateWindow(w4.get()); |
530 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); | 531 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); |
531 } | 532 } |
532 | 533 |
533 // Child-modal test for the case when the originally clicked window is an | 534 // Child-modal test for the case when the originally clicked window is an |
534 // ancestor of the modal parent. | 535 // ancestor of the modal parent. |
535 TEST_F(WindowModalityControllerTest, ChildModalAncestor) { | 536 TEST_F(WindowModalityControllerTest, ChildModalAncestor) { |
536 aura::test::TestWindowDelegate d; | 537 aura::test::TestWindowDelegate d; |
537 scoped_ptr<aura::Window> w1( | 538 scoped_ptr<aura::Window> w1( |
538 CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect())); | 539 CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect())); |
539 scoped_ptr<aura::Window> w2( | 540 scoped_ptr<aura::Window> w2( |
540 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get())); | 541 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get())); |
541 scoped_ptr<aura::Window> w3( | 542 scoped_ptr<aura::Window> w3( |
542 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w2.get())); | 543 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w2.get())); |
543 scoped_ptr<aura::Window> w4( | 544 scoped_ptr<aura::Window> w4( |
544 CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect())); | 545 CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect())); |
545 w4->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_CHILD); | 546 w4->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_CHILD); |
546 views::corewm::SetModalParent(w4.get(), w2.get()); | 547 views::corewm::SetModalParent(w4.get(), w2.get()); |
547 w1->AddTransientChild(w4.get()); | 548 views::corewm::AddTransientChild(w1.get(), w4.get()); |
548 | 549 |
549 wm::ActivateWindow(w1.get()); | 550 wm::ActivateWindow(w1.get()); |
550 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 551 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
551 | 552 |
552 wm::ActivateWindow(w2.get()); | 553 wm::ActivateWindow(w2.get()); |
553 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); | 554 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); |
554 | 555 |
555 wm::ActivateWindow(w3.get()); | 556 wm::ActivateWindow(w3.get()); |
556 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); | 557 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); |
557 | 558 |
558 wm::ActivateWindow(w4.get()); | 559 wm::ActivateWindow(w4.get()); |
559 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); | 560 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); |
560 } | 561 } |
561 | 562 |
562 } // namespace internal | 563 } // namespace internal |
563 } // namespace ash | 564 } // namespace ash |
OLD | NEW |