Avi Drissman | 3a215d1e | 2022-09-07 19:43:09 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
ben@chromium.org | ee3ed10 | 2014-03-11 22:02:01 | [diff] [blame] | 5 | #include "ui/wm/core/window_modality_controller.h" |
ben@chromium.org | 7a8cbb36 | 2012-02-21 16:35:51 | [diff] [blame] | 6 | #include "ash/shell.h" |
ben@chromium.org | 1dd1c1b | 2012-02-17 22:04:47 | [diff] [blame] | 7 | #include "ash/test/ash_test_base.h" |
Sammie Quon | 4183747 | 2023-11-16 18:15:53 | [diff] [blame] | 8 | #include "ash/wm/test/test_child_modal_parent.h" |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 9 | #include "ash/wm/window_util.h" |
| 10 | #include "ui/aura/client/aura_constants.h" |
xdai | 74ce23c | 2016-02-09 20:36:29 | [diff] [blame] | 11 | #include "ui/aura/client/capture_client.h" |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 12 | #include "ui/aura/test/test_window_delegate.h" |
tfarina@chromium.org | 0477e8e6 | 2012-02-27 12:05:29 | [diff] [blame] | 13 | #include "ui/aura/test/test_windows.h" |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 14 | #include "ui/aura/window.h" |
ben@chromium.org | fcc51c95 | 2014-02-21 21:31:26 | [diff] [blame] | 15 | #include "ui/aura/window_event_dispatcher.h" |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 16 | #include "ui/base/ui_base_types.h" |
tapted@chromium.org | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 17 | #include "ui/events/test/event_generator.h" |
ben@chromium.org | 0c2dc01 | 2012-12-02 00:00:23 | [diff] [blame] | 18 | #include "ui/views/test/capture_tracking_view.h" |
sky@chromium.org | 150c02e | 2012-04-27 22:55:40 | [diff] [blame] | 19 | #include "ui/views/widget/widget.h" |
ben@chromium.org | ee3ed10 | 2014-03-11 22:02:01 | [diff] [blame] | 20 | #include "ui/wm/core/window_util.h" |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 21 | |
| 22 | namespace ash { |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 23 | |
James Cook | 317781a | 2017-07-18 02:08:06 | [diff] [blame] | 24 | using WindowModalityControllerTest = AshTestBase; |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 25 | |
| 26 | namespace { |
| 27 | |
| 28 | bool ValidateStacking(aura::Window* parent, int ids[], int count) { |
| 29 | for (int i = 0; i < count; ++i) { |
Allen Bauer | 6d2399c | 2021-05-13 16:06:25 | [diff] [blame] | 30 | if (parent->children().at(i)->GetId() != ids[i]) |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 31 | return false; |
| 32 | } |
| 33 | return true; |
| 34 | } |
| 35 | |
tfarina@chromium.org | 0477e8e6 | 2012-02-27 12:05:29 | [diff] [blame] | 36 | } // namespace |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 37 | |
| 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. |
ivankr@chromium.org | ea6fb6b | 2012-01-31 00:37:03 | [diff] [blame] | 43 | // - closing a window passes focus up the stack. |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 44 | TEST_F(WindowModalityControllerTest, BasicActivation) { |
| 45 | aura::test::TestWindowDelegate d; |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 46 | std::unique_ptr<aura::Window> w1( |
erg@chromium.org | 5ebe610 | 2012-11-28 21:00:03 | [diff] [blame] | 47 | CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect())); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 48 | std::unique_ptr<aura::Window> w11( |
erg@chromium.org | 5ebe610 | 2012-11-28 21:00:03 | [diff] [blame] | 49 | CreateTestWindowInShellWithDelegate(&d, -11, gfx::Rect())); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 50 | std::unique_ptr<aura::Window> w12( |
erg@chromium.org | 5ebe610 | 2012-11-28 21:00:03 | [diff] [blame] | 51 | CreateTestWindowInShellWithDelegate(&d, -12, gfx::Rect())); |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 52 | |
ben@chromium.org | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 53 | ::wm::AddTransientChild(w1.get(), w11.get()); |
tfarina@chromium.org | 0477e8e6 | 2012-02-27 12:05:29 | [diff] [blame] | 54 | wm::ActivateWindow(w1.get()); |
| 55 | EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
| 56 | wm::ActivateWindow(w11.get()); |
| 57 | EXPECT_TRUE(wm::IsActiveWindow(w11.get())); |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 58 | |
benrg@chromium.org | 36e4151 | 2012-02-11 00:29:18 | [diff] [blame] | 59 | w12->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); |
ben@chromium.org | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 60 | ::wm::AddTransientChild(w1.get(), w12.get()); |
tfarina@chromium.org | 0477e8e6 | 2012-02-27 12:05:29 | [diff] [blame] | 61 | wm::ActivateWindow(w12.get()); |
| 62 | EXPECT_TRUE(wm::IsActiveWindow(w12.get())); |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 63 | |
tfarina@chromium.org | 0477e8e6 | 2012-02-27 12:05:29 | [diff] [blame] | 64 | wm::ActivateWindow(w11.get()); |
| 65 | EXPECT_TRUE(wm::IsActiveWindow(w11.get())); |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 66 | |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 67 | int check1[] = {-1, -12, -11}; |
Daniel Cheng | a020cd7 | 2022-02-26 09:23:53 | [diff] [blame] | 68 | EXPECT_TRUE(ValidateStacking(w1->parent(), check1, std::size(check1))); |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 69 | |
tfarina@chromium.org | 0477e8e6 | 2012-02-27 12:05:29 | [diff] [blame] | 70 | wm::ActivateWindow(w1.get()); |
| 71 | EXPECT_TRUE(wm::IsActiveWindow(w12.get())); |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 72 | // Transient children are always stacked above their transient parent, which |
| 73 | // is why this order is not -11, -1, -12. |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 74 | int check2[] = {-1, -11, -12}; |
Daniel Cheng | a020cd7 | 2022-02-26 09:23:53 | [diff] [blame] | 75 | EXPECT_TRUE(ValidateStacking(w1->parent(), check2, std::size(check2))); |
ivankr@chromium.org | ea6fb6b | 2012-01-31 00:37:03 | [diff] [blame] | 76 | |
| 77 | w12.reset(); |
tfarina@chromium.org | 0477e8e6 | 2012-02-27 12:05:29 | [diff] [blame] | 78 | EXPECT_TRUE(wm::IsActiveWindow(w11.get())); |
ivankr@chromium.org | ea6fb6b | 2012-01-31 00:37:03 | [diff] [blame] | 79 | w11.reset(); |
tfarina@chromium.org | 0477e8e6 | 2012-02-27 12:05:29 | [diff] [blame] | 80 | EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 81 | } |
| 82 | |
| 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. |
ivankr@chromium.org | ea6fb6b | 2012-01-31 00:37:03 | [diff] [blame] | 88 | // - closing a window passes focus up the stack. |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 89 | TEST_F(WindowModalityControllerTest, NestedModals) { |
| 90 | aura::test::TestWindowDelegate d; |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 91 | std::unique_ptr<aura::Window> w1( |
erg@chromium.org | 5ebe610 | 2012-11-28 21:00:03 | [diff] [blame] | 92 | CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect())); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 93 | std::unique_ptr<aura::Window> w11( |
erg@chromium.org | 5ebe610 | 2012-11-28 21:00:03 | [diff] [blame] | 94 | CreateTestWindowInShellWithDelegate(&d, -11, gfx::Rect())); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 95 | std::unique_ptr<aura::Window> w111( |
erg@chromium.org | 5ebe610 | 2012-11-28 21:00:03 | [diff] [blame] | 96 | CreateTestWindowInShellWithDelegate(&d, -111, gfx::Rect())); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 97 | std::unique_ptr<aura::Window> w2( |
erg@chromium.org | 5ebe610 | 2012-11-28 21:00:03 | [diff] [blame] | 98 | CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect())); |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 99 | |
ben@chromium.org | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 100 | ::wm::AddTransientChild(w1.get(), w11.get()); |
| 101 | ::wm::AddTransientChild(w11.get(), w111.get()); |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 102 | |
tfarina@chromium.org | 0477e8e6 | 2012-02-27 12:05:29 | [diff] [blame] | 103 | wm::ActivateWindow(w1.get()); |
| 104 | EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
| 105 | wm::ActivateWindow(w2.get()); |
| 106 | EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 107 | |
| 108 | // Set up modality. |
benrg@chromium.org | 36e4151 | 2012-02-11 00:29:18 | [diff] [blame] | 109 | w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); |
| 110 | w111->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 111 | |
tfarina@chromium.org | 0477e8e6 | 2012-02-27 12:05:29 | [diff] [blame] | 112 | wm::ActivateWindow(w1.get()); |
| 113 | EXPECT_TRUE(wm::IsActiveWindow(w111.get())); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 114 | int check1[] = {-2, -1, -11, -111}; |
Daniel Cheng | a020cd7 | 2022-02-26 09:23:53 | [diff] [blame] | 115 | EXPECT_TRUE(ValidateStacking(w1->parent(), check1, std::size(check1))); |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 116 | |
tfarina@chromium.org | 0477e8e6 | 2012-02-27 12:05:29 | [diff] [blame] | 117 | wm::ActivateWindow(w11.get()); |
| 118 | EXPECT_TRUE(wm::IsActiveWindow(w111.get())); |
Daniel Cheng | a020cd7 | 2022-02-26 09:23:53 | [diff] [blame] | 119 | EXPECT_TRUE(ValidateStacking(w1->parent(), check1, std::size(check1))); |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 120 | |
tfarina@chromium.org | 0477e8e6 | 2012-02-27 12:05:29 | [diff] [blame] | 121 | wm::ActivateWindow(w111.get()); |
| 122 | EXPECT_TRUE(wm::IsActiveWindow(w111.get())); |
Daniel Cheng | a020cd7 | 2022-02-26 09:23:53 | [diff] [blame] | 123 | EXPECT_TRUE(ValidateStacking(w1->parent(), check1, std::size(check1))); |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 124 | |
tfarina@chromium.org | 0477e8e6 | 2012-02-27 12:05:29 | [diff] [blame] | 125 | wm::ActivateWindow(w2.get()); |
| 126 | EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 127 | int check2[] = {-1, -11, -111, -2}; |
Daniel Cheng | a020cd7 | 2022-02-26 09:23:53 | [diff] [blame] | 128 | EXPECT_TRUE(ValidateStacking(w1->parent(), check2, std::size(check2))); |
ivankr@chromium.org | ea6fb6b | 2012-01-31 00:37:03 | [diff] [blame] | 129 | |
| 130 | w2.reset(); |
tfarina@chromium.org | 0477e8e6 | 2012-02-27 12:05:29 | [diff] [blame] | 131 | EXPECT_TRUE(wm::IsActiveWindow(w111.get())); |
ivankr@chromium.org | ea6fb6b | 2012-01-31 00:37:03 | [diff] [blame] | 132 | w111.reset(); |
tfarina@chromium.org | 0477e8e6 | 2012-02-27 12:05:29 | [diff] [blame] | 133 | EXPECT_TRUE(wm::IsActiveWindow(w11.get())); |
ivankr@chromium.org | ea6fb6b | 2012-01-31 00:37:03 | [diff] [blame] | 134 | w11.reset(); |
tfarina@chromium.org | 0477e8e6 | 2012-02-27 12:05:29 | [diff] [blame] | 135 | EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
ivankr@chromium.org | ea6fb6b | 2012-01-31 00:37:03 | [diff] [blame] | 136 | } |
| 137 | |
| 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; |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 144 | std::unique_ptr<aura::Window> w1( |
erg@chromium.org | 5ebe610 | 2012-11-28 21:00:03 | [diff] [blame] | 145 | CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect())); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 146 | std::unique_ptr<aura::Window> w11( |
erg@chromium.org | 5ebe610 | 2012-11-28 21:00:03 | [diff] [blame] | 147 | CreateTestWindowInShellWithDelegate(&d, -11, gfx::Rect())); |
ivankr@chromium.org | ea6fb6b | 2012-01-31 00:37:03 | [diff] [blame] | 148 | // |w111| will be owned and deleted by |w11|. |
| 149 | aura::Window* w111 = |
erg@chromium.org | 5ebe610 | 2012-11-28 21:00:03 | [diff] [blame] | 150 | CreateTestWindowInShellWithDelegate(&d, -111, gfx::Rect()); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 151 | std::unique_ptr<aura::Window> w2( |
erg@chromium.org | 5ebe610 | 2012-11-28 21:00:03 | [diff] [blame] | 152 | CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect())); |
ivankr@chromium.org | ea6fb6b | 2012-01-31 00:37:03 | [diff] [blame] | 153 | |
ben@chromium.org | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 154 | ::wm::AddTransientChild(w1.get(), w11.get()); |
| 155 | ::wm::AddTransientChild(w11.get(), w111); |
ivankr@chromium.org | ea6fb6b | 2012-01-31 00:37:03 | [diff] [blame] | 156 | |
tfarina@chromium.org | 0477e8e6 | 2012-02-27 12:05:29 | [diff] [blame] | 157 | wm::ActivateWindow(w1.get()); |
| 158 | EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
| 159 | wm::ActivateWindow(w2.get()); |
| 160 | EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
ivankr@chromium.org | ea6fb6b | 2012-01-31 00:37:03 | [diff] [blame] | 161 | |
| 162 | // Set up modality. |
benrg@chromium.org | 36e4151 | 2012-02-11 00:29:18 | [diff] [blame] | 163 | w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); |
| 164 | w111->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); |
ivankr@chromium.org | ea6fb6b | 2012-01-31 00:37:03 | [diff] [blame] | 165 | |
tfarina@chromium.org | 0477e8e6 | 2012-02-27 12:05:29 | [diff] [blame] | 166 | wm::ActivateWindow(w1.get()); |
| 167 | EXPECT_TRUE(wm::IsActiveWindow(w111)); |
ivankr@chromium.org | ea6fb6b | 2012-01-31 00:37:03 | [diff] [blame] | 168 | |
oshima@chromium.org | a278e260 | 2012-02-16 16:46:35 | [diff] [blame] | 169 | w111->Hide(); |
tfarina@chromium.org | 0477e8e6 | 2012-02-27 12:05:29 | [diff] [blame] | 170 | EXPECT_TRUE(wm::IsActiveWindow(w11.get())); |
oshima@chromium.org | a278e260 | 2012-02-16 16:46:35 | [diff] [blame] | 171 | |
| 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. |
| 175 | |
ivankr@chromium.org | ea6fb6b | 2012-01-31 00:37:03 | [diff] [blame] | 176 | w11.reset(); |
tfarina@chromium.org | 0477e8e6 | 2012-02-27 12:05:29 | [diff] [blame] | 177 | EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | // Modality also prevents events from being passed to the transient parent. |
| 181 | TEST_F(WindowModalityControllerTest, Events) { |
| 182 | aura::test::TestWindowDelegate d; |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 183 | std::unique_ptr<aura::Window> w1( |
| 184 | CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect(0, 0, 100, 100))); |
| 185 | std::unique_ptr<aura::Window> w11( |
| 186 | CreateTestWindowInShellWithDelegate(&d, -11, gfx::Rect(20, 20, 50, 50))); |
| 187 | std::unique_ptr<aura::Window> w111( |
calamity | 8bc4d57e | 2015-06-11 04:48:04 | [diff] [blame] | 188 | CreateTestWindowInShellWithDelegate(&d, -111, gfx::Rect(20, 20, 50, 50))); |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 189 | |
ben@chromium.org | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 190 | ::wm::AddTransientChild(w1.get(), w11.get()); |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 191 | |
calamity | 8bc4d57e | 2015-06-11 04:48:04 | [diff] [blame] | 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()); |
| 195 | |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 196 | { |
| 197 | // Clicking a point within w1 should activate that window. |
tapted@chromium.org | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 198 | ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 199 | gfx::Point(10, 10)); |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 200 | generator.ClickLeftButton(); |
tfarina@chromium.org | 0477e8e6 | 2012-02-27 12:05:29 | [diff] [blame] | 201 | EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 202 | } |
| 203 | |
benrg@chromium.org | 36e4151 | 2012-02-11 00:29:18 | [diff] [blame] | 204 | w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 205 | |
| 206 | { |
| 207 | // Clicking a point within w1 should activate w11. |
tapted@chromium.org | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 208 | ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 209 | gfx::Point(10, 10)); |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 210 | generator.ClickLeftButton(); |
tfarina@chromium.org | 0477e8e6 | 2012-02-27 12:05:29 | [diff] [blame] | 211 | EXPECT_TRUE(wm::IsActiveWindow(w11.get())); |
ben@chromium.org | 8037357 | 2012-01-06 23:14:30 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | |
zelidrag@chromium.org | ca5e056c | 2014-04-26 02:10:35 | [diff] [blame] | 215 | // Events on modal parent activate. |
| 216 | TEST_F(WindowModalityControllerTest, EventsForEclipsedWindows) { |
| 217 | aura::test::TestWindowDelegate d; |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 218 | std::unique_ptr<aura::Window> w1( |
| 219 | CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect(0, 0, 100, 100))); |
| 220 | std::unique_ptr<aura::Window> w11( |
| 221 | CreateTestWindowInShellWithDelegate(&d, -11, gfx::Rect(20, 20, 50, 50))); |
zelidrag@chromium.org | ca5e056c | 2014-04-26 02:10:35 | [diff] [blame] | 222 | ::wm::AddTransientChild(w1.get(), w11.get()); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 223 | std::unique_ptr<aura::Window> w2( |
| 224 | CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect(0, 0, 50, 50))); |
zelidrag@chromium.org | ca5e056c | 2014-04-26 02:10:35 | [diff] [blame] | 225 | |
| 226 | w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); |
| 227 | |
| 228 | // Partially eclipse w1 with w2. |
| 229 | wm::ActivateWindow(w2.get()); |
| 230 | { |
| 231 | // Clicking a point on w1 that is not eclipsed by w2. |
tapted@chromium.org | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 232 | ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 233 | gfx::Point(90, 90)); |
zelidrag@chromium.org | ca5e056c | 2014-04-26 02:10:35 | [diff] [blame] | 234 | generator.ClickLeftButton(); |
| 235 | EXPECT_TRUE(wm::IsActiveWindow(w11.get())); |
| 236 | } |
| 237 | } |
| 238 | |
stevenjb@chromium.org | 0d9334b | 2012-03-14 04:52:28 | [diff] [blame] | 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 |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 241 | // the parent of w1, and that GetModalTransient(w11) returns w2. |
| 242 | TEST_F(WindowModalityControllerTest, GetModalTransient) { |
stevenjb@chromium.org | 0d9334b | 2012-03-14 04:52:28 | [diff] [blame] | 243 | aura::test::TestWindowDelegate d; |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 244 | std::unique_ptr<aura::Window> w1( |
erg@chromium.org | 5ebe610 | 2012-11-28 21:00:03 | [diff] [blame] | 245 | CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect())); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 246 | std::unique_ptr<aura::Window> w11( |
stevenjb@chromium.org | 0d9334b | 2012-03-14 04:52:28 | [diff] [blame] | 247 | aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get())); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 248 | std::unique_ptr<aura::Window> w2( |
erg@chromium.org | 5ebe610 | 2012-11-28 21:00:03 | [diff] [blame] | 249 | CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect())); |
stevenjb@chromium.org | 0d9334b | 2012-03-14 04:52:28 | [diff] [blame] | 250 | w2->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); |
| 251 | |
| 252 | aura::Window* wt; |
ben@chromium.org | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 253 | wt = ::wm::GetModalTransient(w1.get()); |
Mike Wasserman | 16f9521 | 2018-07-04 00:55:50 | [diff] [blame] | 254 | ASSERT_EQ(nullptr, wt); |
stevenjb@chromium.org | 0d9334b | 2012-03-14 04:52:28 | [diff] [blame] | 255 | |
| 256 | // Parent w2 to w1. It should get parented to the parent of w1. |
ben@chromium.org | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 257 | ::wm::AddTransientChild(w1.get(), w2.get()); |
stevenjb@chromium.org | 0d9334b | 2012-03-14 04:52:28 | [diff] [blame] | 258 | ASSERT_EQ(2U, w1->parent()->children().size()); |
Allen Bauer | 6d2399c | 2021-05-13 16:06:25 | [diff] [blame] | 259 | EXPECT_EQ(-2, w1->parent()->children().at(1)->GetId()); |
stevenjb@chromium.org | 0d9334b | 2012-03-14 04:52:28 | [diff] [blame] | 260 | |
| 261 | // Request the modal transient window for w1, it should be w2. |
ben@chromium.org | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 262 | wt = ::wm::GetModalTransient(w1.get()); |
Mike Wasserman | 16f9521 | 2018-07-04 00:55:50 | [diff] [blame] | 263 | ASSERT_NE(nullptr, wt); |
Allen Bauer | 6d2399c | 2021-05-13 16:06:25 | [diff] [blame] | 264 | EXPECT_EQ(-2, wt->GetId()); |
stevenjb@chromium.org | 0d9334b | 2012-03-14 04:52:28 | [diff] [blame] | 265 | |
| 266 | // Request the modal transient window for w11, it should also be w2. |
ben@chromium.org | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 267 | wt = ::wm::GetModalTransient(w11.get()); |
Mike Wasserman | 16f9521 | 2018-07-04 00:55:50 | [diff] [blame] | 268 | ASSERT_NE(nullptr, wt); |
Allen Bauer | 6d2399c | 2021-05-13 16:06:25 | [diff] [blame] | 269 | EXPECT_EQ(-2, wt->GetId()); |
stevenjb@chromium.org | 0d9334b | 2012-03-14 04:52:28 | [diff] [blame] | 270 | } |
| 271 | |
sky@chromium.org | 150c02e | 2012-04-27 22:55:40 | [diff] [blame] | 272 | // Verifies we generate a capture lost when showing a modal window. |
| 273 | TEST_F(WindowModalityControllerTest, ChangeCapture) { |
erg@chromium.org | 6e39206 | 2012-12-12 20:45:42 | [diff] [blame] | 274 | views::Widget* widget = views::Widget::CreateWindowWithContext( |
Peter Kasting | ac8ec15 | 2020-03-05 01:05:50 | [diff] [blame] | 275 | nullptr, Shell::GetPrimaryRootWindow(), gfx::Rect(0, 0, 200, 200)); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 276 | std::unique_ptr<aura::Window> widget_window(widget->GetNativeView()); |
ben@chromium.org | 0c2dc01 | 2012-12-02 00:00:23 | [diff] [blame] | 277 | views::test::CaptureTrackingView* view = new views::test::CaptureTrackingView; |
sky@chromium.org | 150c02e | 2012-04-27 22:55:40 | [diff] [blame] | 278 | widget->client_view()->AddChildView(view); |
sky@chromium.org | 150c02e | 2012-04-27 22:55:40 | [diff] [blame] | 279 | view->SetBoundsRect(widget->client_view()->GetLocalBounds()); |
| 280 | widget->Show(); |
| 281 | |
| 282 | gfx::Point center(view->width() / 2, view->height() / 2); |
| 283 | views::View::ConvertPointToScreen(view, ¢er); |
tapted@chromium.org | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 284 | ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), center); |
sky@chromium.org | 150c02e | 2012-04-27 22:55:40 | [diff] [blame] | 285 | generator.PressLeftButton(); |
| 286 | EXPECT_TRUE(view->got_press()); |
| 287 | |
Peter Kasting | ac8ec15 | 2020-03-05 01:05:50 | [diff] [blame] | 288 | views::Widget* modal_widget = views::Widget::CreateWindowWithParent( |
| 289 | nullptr, widget->GetNativeView(), gfx::Rect(50, 50, 200, 200)); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 290 | std::unique_ptr<aura::Window> modal_window(modal_widget->GetNativeView()); |
sky@chromium.org | 150c02e | 2012-04-27 22:55:40 | [diff] [blame] | 291 | modal_window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); |
ben@chromium.org | 0c2dc01 | 2012-12-02 00:00:23 | [diff] [blame] | 292 | views::test::CaptureTrackingView* modal_view = |
| 293 | new views::test::CaptureTrackingView; |
sky@chromium.org | 150c02e | 2012-04-27 22:55:40 | [diff] [blame] | 294 | modal_widget->client_view()->AddChildView(modal_view); |
sky@chromium.org | 150c02e | 2012-04-27 22:55:40 | [diff] [blame] | 295 | modal_view->SetBoundsRect(modal_widget->client_view()->GetLocalBounds()); |
| 296 | modal_widget->Show(); |
| 297 | |
| 298 | EXPECT_TRUE(view->got_capture_lost()); |
| 299 | generator.ReleaseLeftButton(); |
| 300 | |
| 301 | view->reset(); |
| 302 | |
| 303 | EXPECT_FALSE(modal_view->got_capture_lost()); |
| 304 | EXPECT_FALSE(modal_view->got_press()); |
| 305 | |
| 306 | gfx::Point modal_center(modal_view->width() / 2, modal_view->height() / 2); |
| 307 | views::View::ConvertPointToScreen(modal_view, &modal_center); |
| 308 | generator.MoveMouseTo(modal_center, 1); |
| 309 | generator.PressLeftButton(); |
| 310 | EXPECT_TRUE(modal_view->got_press()); |
| 311 | EXPECT_FALSE(modal_view->got_capture_lost()); |
| 312 | EXPECT_FALSE(view->got_capture_lost()); |
| 313 | EXPECT_FALSE(view->got_press()); |
| 314 | } |
| 315 | |
xdai | 74ce23c | 2016-02-09 20:36:29 | [diff] [blame] | 316 | // Test that when a child modal window becomes visible, we only release the |
| 317 | // capture window if the current capture window is in the hierarchy of the child |
| 318 | // modal window's modal parent window. |
| 319 | TEST_F(WindowModalityControllerTest, ReleaseCapture) { |
Julien Brianceau | 293917a | 2017-08-01 17:32:59 | [diff] [blame] | 320 | // Create a window hierarchy like this: |
robert.bradford | 9f937f5 | 2016-07-18 17:30:48 | [diff] [blame] | 321 | // _______________w0______________ |
| 322 | // | | | |
| 323 | // w1 <------ w3 w2 |
xdai | 74ce23c | 2016-02-09 20:36:29 | [diff] [blame] | 324 | // | (modal to) |
| 325 | // w11 |
| 326 | |
| 327 | aura::test::TestWindowDelegate d; |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 328 | std::unique_ptr<aura::Window> w1( |
xdai | 74ce23c | 2016-02-09 20:36:29 | [diff] [blame] | 329 | CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect())); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 330 | std::unique_ptr<aura::Window> w11( |
xdai | 74ce23c | 2016-02-09 20:36:29 | [diff] [blame] | 331 | aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get())); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 332 | std::unique_ptr<aura::Window> w2( |
xdai | 74ce23c | 2016-02-09 20:36:29 | [diff] [blame] | 333 | CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect())); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 334 | std::unique_ptr<aura::Window> w3( |
xdai | 74ce23c | 2016-02-09 20:36:29 | [diff] [blame] | 335 | CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect())); |
| 336 | w3->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_CHILD); |
| 337 | ::wm::SetModalParent(w3.get(), w1.get()); |
| 338 | |
| 339 | // w1's capture should be released when w3 becomes visible. |
| 340 | w3->Hide(); |
| 341 | aura::client::GetCaptureClient(Shell::GetPrimaryRootWindow()) |
| 342 | ->SetCapture(w1.get()); |
| 343 | EXPECT_EQ(w1.get(), |
| 344 | aura::client::GetCaptureClient(Shell::GetPrimaryRootWindow()) |
| 345 | ->GetGlobalCaptureWindow()); |
| 346 | w3->Show(); |
| 347 | EXPECT_NE(w1.get(), |
| 348 | aura::client::GetCaptureClient(Shell::GetPrimaryRootWindow()) |
| 349 | ->GetGlobalCaptureWindow()); |
| 350 | |
| 351 | // w11's capture should be released when w3 becomes visible. |
| 352 | w3->Hide(); |
| 353 | aura::client::GetCaptureClient(Shell::GetPrimaryRootWindow()) |
| 354 | ->SetCapture(w11.get()); |
| 355 | EXPECT_EQ(w11.get(), |
| 356 | aura::client::GetCaptureClient(Shell::GetPrimaryRootWindow()) |
| 357 | ->GetGlobalCaptureWindow()); |
| 358 | w3->Show(); |
| 359 | EXPECT_NE(w11.get(), |
| 360 | aura::client::GetCaptureClient(Shell::GetPrimaryRootWindow()) |
| 361 | ->GetGlobalCaptureWindow()); |
| 362 | |
| 363 | // w2's capture should not be released when w3 becomes visible. |
| 364 | w3->Hide(); |
| 365 | aura::client::GetCaptureClient(Shell::GetPrimaryRootWindow()) |
| 366 | ->SetCapture(w2.get()); |
| 367 | EXPECT_EQ(w2.get(), |
| 368 | aura::client::GetCaptureClient(Shell::GetPrimaryRootWindow()) |
| 369 | ->GetGlobalCaptureWindow()); |
| 370 | w3->Show(); |
| 371 | EXPECT_EQ(w2.get(), |
| 372 | aura::client::GetCaptureClient(Shell::GetPrimaryRootWindow()) |
| 373 | ->GetGlobalCaptureWindow()); |
| 374 | } |
| 375 | |
sadrul@chromium.org | 08ec2170 | 2012-07-11 00:49:44 | [diff] [blame] | 376 | class TouchTrackerWindowDelegate : public aura::test::TestWindowDelegate { |
| 377 | public: |
tdresser@chromium.org | cb761f78 | 2013-10-21 19:19:42 | [diff] [blame] | 378 | TouchTrackerWindowDelegate() |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 379 | : received_touch_(false), last_event_type_(ui::ET_UNKNOWN) {} |
Peter Boström | ec31a04 | 2021-09-16 23:37:34 | [diff] [blame] | 380 | |
| 381 | TouchTrackerWindowDelegate(const TouchTrackerWindowDelegate&) = delete; |
| 382 | TouchTrackerWindowDelegate& operator=(const TouchTrackerWindowDelegate&) = |
| 383 | delete; |
| 384 | |
Chris Watkins | c24daf6 | 2017-11-28 03:43:09 | [diff] [blame] | 385 | ~TouchTrackerWindowDelegate() override = default; |
sadrul@chromium.org | 08ec2170 | 2012-07-11 00:49:44 | [diff] [blame] | 386 | |
| 387 | void reset() { |
| 388 | received_touch_ = false; |
tdresser@chromium.org | cb761f78 | 2013-10-21 19:19:42 | [diff] [blame] | 389 | last_event_type_ = ui::ET_UNKNOWN; |
sadrul@chromium.org | 08ec2170 | 2012-07-11 00:49:44 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | bool received_touch() const { return received_touch_; } |
tdresser@chromium.org | cb761f78 | 2013-10-21 19:19:42 | [diff] [blame] | 393 | ui::EventType last_event_type() const { return last_event_type_; } |
sadrul@chromium.org | 08ec2170 | 2012-07-11 00:49:44 | [diff] [blame] | 394 | |
| 395 | private: |
| 396 | // Overridden from aura::test::TestWindowDelegate. |
dcheng | 28401c2 | 2014-10-28 01:26:19 | [diff] [blame] | 397 | void OnTouchEvent(ui::TouchEvent* event) override { |
sadrul@chromium.org | 08ec2170 | 2012-07-11 00:49:44 | [diff] [blame] | 398 | received_touch_ = true; |
tdresser@chromium.org | cb761f78 | 2013-10-21 19:19:42 | [diff] [blame] | 399 | last_event_type_ = event->type(); |
sadrul@chromium.org | 6f34b483 | 2012-12-14 16:18:08 | [diff] [blame] | 400 | aura::test::TestWindowDelegate::OnTouchEvent(event); |
sadrul@chromium.org | 08ec2170 | 2012-07-11 00:49:44 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | bool received_touch_; |
tdresser@chromium.org | cb761f78 | 2013-10-21 19:19:42 | [diff] [blame] | 404 | ui::EventType last_event_type_; |
sadrul@chromium.org | 08ec2170 | 2012-07-11 00:49:44 | [diff] [blame] | 405 | }; |
| 406 | |
Weidong Guo | a061f17 | 2018-11-14 03:01:15 | [diff] [blame] | 407 | // Modality should prevent events from being passed to transient window tree |
| 408 | // rooted to the top level window. |
sadrul@chromium.org | 08ec2170 | 2012-07-11 00:49:44 | [diff] [blame] | 409 | TEST_F(WindowModalityControllerTest, TouchEvent) { |
| 410 | TouchTrackerWindowDelegate d1; |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 411 | std::unique_ptr<aura::Window> w1( |
| 412 | CreateTestWindowInShellWithDelegate(&d1, -1, gfx::Rect(0, 0, 100, 100))); |
sadrul@chromium.org | 08ec2170 | 2012-07-11 00:49:44 | [diff] [blame] | 413 | TouchTrackerWindowDelegate d11; |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 414 | std::unique_ptr<aura::Window> w11(CreateTestWindowInShellWithDelegate( |
Weidong Guo | a061f17 | 2018-11-14 03:01:15 | [diff] [blame] | 415 | &d11, -11, gfx::Rect(20, 20, 20, 20))); |
| 416 | TouchTrackerWindowDelegate d12; |
| 417 | std::unique_ptr<aura::Window> w12(CreateTestWindowInShellWithDelegate( |
| 418 | &d12, -12, gfx::Rect(40, 20, 20, 20))); |
| 419 | TouchTrackerWindowDelegate d2; |
| 420 | std::unique_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate( |
| 421 | &d2, -2, gfx::Rect(100, 0, 100, 100))); |
| 422 | |
| 423 | // Make |w11| and |w12| non-resizable to avoid touch events inside its |
| 424 | // transient parent |w1| from going to them because of |
| 425 | // EasyResizeWindowTargeter. |
Valery Arkhangorodsky | 7c9efb2 | 2017-07-13 20:08:06 | [diff] [blame] | 426 | w11->SetProperty(aura::client::kResizeBehaviorKey, |
Scott Violet | 97bdfa33 | 2019-05-23 22:42:50 | [diff] [blame] | 427 | aura::client::kResizeBehaviorCanMaximize | |
| 428 | aura::client::kResizeBehaviorCanMinimize); |
Weidong Guo | a061f17 | 2018-11-14 03:01:15 | [diff] [blame] | 429 | w12->SetProperty(aura::client::kResizeBehaviorKey, |
Scott Violet | 97bdfa33 | 2019-05-23 22:42:50 | [diff] [blame] | 430 | aura::client::kResizeBehaviorCanMaximize | |
| 431 | aura::client::kResizeBehaviorCanMinimize); |
tapted@chromium.org | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 432 | ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 433 | gfx::Point(10, 10)); |
sadrul@chromium.org | 08ec2170 | 2012-07-11 00:49:44 | [diff] [blame] | 434 | |
ben@chromium.org | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 435 | ::wm::AddTransientChild(w1.get(), w11.get()); |
Weidong Guo | a061f17 | 2018-11-14 03:01:15 | [diff] [blame] | 436 | ::wm::AddTransientChild(w1.get(), w12.get()); |
sadrul@chromium.org | 08ec2170 | 2012-07-11 00:49:44 | [diff] [blame] | 437 | d1.reset(); |
| 438 | d11.reset(); |
Weidong Guo | a061f17 | 2018-11-14 03:01:15 | [diff] [blame] | 439 | d12.reset(); |
| 440 | d2.reset(); |
sadrul@chromium.org | 08ec2170 | 2012-07-11 00:49:44 | [diff] [blame] | 441 | |
| 442 | { |
Weidong Guo | a061f17 | 2018-11-14 03:01:15 | [diff] [blame] | 443 | // Adding a modal window while a touch is down in top level transient window |
| 444 | // should fire a touch cancel. |
tdresser@chromium.org | cb761f78 | 2013-10-21 19:19:42 | [diff] [blame] | 445 | generator.PressTouch(); |
Weidong Guo | a061f17 | 2018-11-14 03:01:15 | [diff] [blame] | 446 | generator.MoveTouch(gfx::Point(10, 15)); |
| 447 | EXPECT_TRUE(d1.received_touch()); |
| 448 | EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
tdresser@chromium.org | cb761f78 | 2013-10-21 19:19:42 | [diff] [blame] | 449 | d1.reset(); |
| 450 | d11.reset(); |
Weidong Guo | a061f17 | 2018-11-14 03:01:15 | [diff] [blame] | 451 | d12.reset(); |
| 452 | d2.reset(); |
tdresser@chromium.org | cb761f78 | 2013-10-21 19:19:42 | [diff] [blame] | 453 | |
| 454 | w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); |
| 455 | EXPECT_TRUE(d1.received_touch()); |
| 456 | EXPECT_EQ(ui::ET_TOUCH_CANCELLED, d1.last_event_type()); |
sadrul@chromium.org | 08ec2170 | 2012-07-11 00:49:44 | [diff] [blame] | 457 | EXPECT_FALSE(d11.received_touch()); |
Weidong Guo | a061f17 | 2018-11-14 03:01:15 | [diff] [blame] | 458 | EXPECT_FALSE(d12.received_touch()); |
| 459 | EXPECT_FALSE(d2.received_touch()); |
| 460 | w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_NONE); |
| 461 | } |
| 462 | |
| 463 | { |
| 464 | // Adding a modal window while a touch is down in window tree rooted to top |
| 465 | // level transient window should fire a touch cancel. |
| 466 | generator.MoveTouch(gfx::Point(50, 30)); |
| 467 | generator.PressTouch(); |
| 468 | generator.MoveTouch(gfx::Point(50, 35)); |
| 469 | EXPECT_TRUE(d12.received_touch()); |
| 470 | EXPECT_TRUE(wm::IsActiveWindow(w12.get())); |
| 471 | d1.reset(); |
| 472 | d11.reset(); |
| 473 | d12.reset(); |
| 474 | d2.reset(); |
| 475 | |
| 476 | w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); |
| 477 | EXPECT_FALSE(d1.received_touch()); |
| 478 | EXPECT_FALSE(d11.received_touch()); |
| 479 | EXPECT_TRUE(d12.received_touch()); |
| 480 | EXPECT_EQ(ui::ET_TOUCH_CANCELLED, d12.last_event_type()); |
| 481 | EXPECT_FALSE(d2.received_touch()); |
| 482 | w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_NONE); |
| 483 | } |
| 484 | |
| 485 | { |
| 486 | // Adding a modal window while a touch is down in other transient window |
| 487 | // tree should not fire a touch cancel. |
| 488 | wm::ActivateWindow(w2.get()); |
| 489 | generator.MoveTouch(gfx::Point(110, 10)); |
| 490 | generator.PressTouch(); |
| 491 | generator.MoveTouch(gfx::Point(110, 15)); |
| 492 | EXPECT_TRUE(d2.received_touch()); |
| 493 | EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
| 494 | d1.reset(); |
| 495 | d11.reset(); |
| 496 | d12.reset(); |
| 497 | d2.reset(); |
| 498 | |
| 499 | w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); |
| 500 | EXPECT_FALSE(d1.received_touch()); |
| 501 | EXPECT_FALSE(d11.received_touch()); |
| 502 | EXPECT_FALSE(d12.received_touch()); |
| 503 | EXPECT_FALSE(d2.received_touch()); |
| 504 | w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_NONE); |
| 505 | } |
| 506 | |
| 507 | { |
| 508 | // Adding a child type modal window while a touch is down in other transient |
| 509 | // window tree should not fire a touch cancel. (See |
| 510 | // https://crbug.com/900321) |
| 511 | wm::ActivateWindow(w2.get()); |
| 512 | generator.MoveTouch(gfx::Point(110, 10)); |
| 513 | generator.PressTouch(); |
| 514 | generator.MoveTouch(gfx::Point(110, 15)); |
| 515 | EXPECT_TRUE(d2.received_touch()); |
| 516 | EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
| 517 | d1.reset(); |
| 518 | d11.reset(); |
| 519 | d12.reset(); |
| 520 | d2.reset(); |
| 521 | |
| 522 | w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_CHILD); |
| 523 | EXPECT_FALSE(d1.received_touch()); |
| 524 | EXPECT_FALSE(d11.received_touch()); |
| 525 | EXPECT_FALSE(d12.received_touch()); |
| 526 | EXPECT_FALSE(d2.received_touch()); |
| 527 | w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_NONE); |
sadrul@chromium.org | 08ec2170 | 2012-07-11 00:49:44 | [diff] [blame] | 528 | } |
| 529 | } |
stevenjb@chromium.org | 0d9334b | 2012-03-14 04:52:28 | [diff] [blame] | 530 | |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 531 | // Child-modal test. |
| 532 | // Creates: |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 533 | // - A |top_level| window that hosts a |modal_parent| window within itself. The |
| 534 | // |top_level| and |modal_parent| windows are not the same window. The |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 535 | // |modal_parent| window is not activatable, because it's contained within the |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 536 | // |top_level| window. |
| 537 | // - A |modal_child| window with parent window |top_level|, but is modal to |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 538 | // |modal_parent| window. |
| 539 | // Validates: |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 540 | // - Clicking on the |modal_parent| should activate the |modal_child| window. |
| 541 | // - Clicking on the |top_level| window outside of the |modal_parent| bounds |
| 542 | // should activate the |top_level| window. |
| 543 | // - Clicking on the |modal_child| while |top_level| is active should activate |
| 544 | // the |modal_child| window. |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 545 | // - Focus should follow the active window. |
| 546 | TEST_F(WindowModalityControllerTest, ChildModal) { |
Peter Kasting | 97defc9 | 2020-03-05 18:49:02 | [diff] [blame] | 547 | TestChildModalParent* delegate = TestChildModalParent::Show(GetContext()); |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 548 | aura::Window* top_level = delegate->GetWidget()->GetNativeView(); |
| 549 | EXPECT_TRUE(wm::IsActiveWindow(top_level)); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 550 | |
| 551 | aura::Window* modal_parent = delegate->GetModalParent(); |
Mike Wasserman | 16f9521 | 2018-07-04 00:55:50 | [diff] [blame] | 552 | EXPECT_NE(nullptr, modal_parent); |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 553 | EXPECT_NE(top_level, modal_parent); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 554 | EXPECT_FALSE(wm::IsActiveWindow(modal_parent)); |
| 555 | |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 556 | aura::Window* modal_child = delegate->ShowModalChild(); |
| 557 | EXPECT_NE(nullptr, modal_child); |
| 558 | EXPECT_TRUE(wm::IsActiveWindow(modal_child)); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 559 | EXPECT_FALSE(wm::IsActiveWindow(modal_parent)); |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 560 | EXPECT_FALSE(wm::IsActiveWindow(top_level)); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 561 | |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 562 | EXPECT_TRUE(modal_child->HasFocus()); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 563 | EXPECT_FALSE(modal_parent->HasFocus()); |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 564 | EXPECT_FALSE(top_level->HasFocus()); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 565 | |
| 566 | wm::ActivateWindow(modal_parent); |
| 567 | |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 568 | EXPECT_TRUE(wm::IsActiveWindow(modal_child)); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 569 | EXPECT_FALSE(wm::IsActiveWindow(modal_parent)); |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 570 | EXPECT_FALSE(wm::IsActiveWindow(top_level)); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 571 | |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 572 | EXPECT_TRUE(modal_child->HasFocus()); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 573 | EXPECT_FALSE(modal_parent->HasFocus()); |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 574 | EXPECT_FALSE(top_level->HasFocus()); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 575 | |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 576 | wm::ActivateWindow(top_level); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 577 | |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 578 | EXPECT_FALSE(wm::IsActiveWindow(modal_child)); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 579 | EXPECT_FALSE(wm::IsActiveWindow(modal_parent)); |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 580 | EXPECT_TRUE(wm::IsActiveWindow(top_level)); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 581 | |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 582 | EXPECT_FALSE(modal_child->HasFocus()); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 583 | EXPECT_FALSE(modal_parent->HasFocus()); |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 584 | EXPECT_TRUE(top_level->HasFocus()); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 585 | |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 586 | wm::ActivateWindow(modal_child); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 587 | |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 588 | EXPECT_TRUE(wm::IsActiveWindow(modal_child)); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 589 | EXPECT_FALSE(wm::IsActiveWindow(modal_parent)); |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 590 | EXPECT_FALSE(wm::IsActiveWindow(top_level)); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 591 | |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 592 | EXPECT_TRUE(modal_child->HasFocus()); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 593 | EXPECT_FALSE(modal_parent->HasFocus()); |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 594 | EXPECT_FALSE(top_level->HasFocus()); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | // Same as |ChildModal| test, but using |EventGenerator| rather than bypassing |
| 598 | // it by calling |ActivateWindow|. |
| 599 | TEST_F(WindowModalityControllerTest, ChildModalEventGenerator) { |
Peter Kasting | 97defc9 | 2020-03-05 18:49:02 | [diff] [blame] | 600 | TestChildModalParent* delegate = TestChildModalParent::Show(GetContext()); |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 601 | aura::Window* top_level = delegate->GetWidget()->GetNativeView(); |
| 602 | EXPECT_TRUE(wm::IsActiveWindow(top_level)); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 603 | |
| 604 | aura::Window* modal_parent = delegate->GetModalParent(); |
Mike Wasserman | 16f9521 | 2018-07-04 00:55:50 | [diff] [blame] | 605 | EXPECT_NE(nullptr, modal_parent); |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 606 | EXPECT_NE(top_level, modal_parent); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 607 | EXPECT_FALSE(wm::IsActiveWindow(modal_parent)); |
| 608 | |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 609 | aura::Window* modal_child = delegate->ShowModalChild(); |
| 610 | EXPECT_NE(nullptr, modal_child); |
| 611 | EXPECT_TRUE(wm::IsActiveWindow(modal_child)); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 612 | EXPECT_FALSE(wm::IsActiveWindow(modal_parent)); |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 613 | EXPECT_FALSE(wm::IsActiveWindow(top_level)); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 614 | |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 615 | EXPECT_TRUE(modal_child->HasFocus()); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 616 | EXPECT_FALSE(modal_parent->HasFocus()); |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 617 | EXPECT_FALSE(top_level->HasFocus()); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 618 | |
| 619 | { |
tapted@chromium.org | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 620 | ui::test::EventGenerator generator( |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 621 | Shell::GetPrimaryRootWindow(), |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 622 | top_level->bounds().origin() + |
| 623 | gfx::Vector2d(10, top_level->bounds().height() - 10)); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 624 | generator.ClickLeftButton(); |
| 625 | generator.ClickLeftButton(); |
| 626 | |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 627 | EXPECT_TRUE(wm::IsActiveWindow(modal_child)); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 628 | EXPECT_FALSE(wm::IsActiveWindow(modal_parent)); |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 629 | EXPECT_FALSE(wm::IsActiveWindow(top_level)); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 630 | |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 631 | EXPECT_TRUE(modal_child->HasFocus()); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 632 | EXPECT_FALSE(modal_parent->HasFocus()); |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 633 | EXPECT_FALSE(top_level->HasFocus()); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | { |
tapted@chromium.org | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 637 | ui::test::EventGenerator generator( |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 638 | Shell::GetPrimaryRootWindow(), |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 639 | top_level->bounds().origin() + gfx::Vector2d(10, 10)); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 640 | generator.ClickLeftButton(); |
| 641 | |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 642 | EXPECT_FALSE(wm::IsActiveWindow(modal_child)); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 643 | EXPECT_FALSE(wm::IsActiveWindow(modal_parent)); |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 644 | EXPECT_TRUE(wm::IsActiveWindow(top_level)); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 645 | |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 646 | EXPECT_FALSE(modal_child->HasFocus()); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 647 | EXPECT_FALSE(modal_parent->HasFocus()); |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 648 | EXPECT_TRUE(top_level->HasFocus()); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | { |
tapted@chromium.org | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 652 | ui::test::EventGenerator generator( |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 653 | Shell::GetPrimaryRootWindow(), |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 654 | modal_child->bounds().origin() + gfx::Vector2d(10, 10)); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 655 | generator.ClickLeftButton(); |
| 656 | |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 657 | EXPECT_TRUE(wm::IsActiveWindow(modal_child)); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 658 | EXPECT_FALSE(wm::IsActiveWindow(modal_parent)); |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 659 | EXPECT_FALSE(wm::IsActiveWindow(top_level)); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 660 | |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 661 | EXPECT_TRUE(modal_child->HasFocus()); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 662 | EXPECT_FALSE(modal_parent->HasFocus()); |
Mike Wasserman | ff7c7f2 | 2018-07-16 19:07:33 | [diff] [blame] | 663 | EXPECT_FALSE(top_level->HasFocus()); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 664 | } |
| 665 | } |
| 666 | |
| 667 | // Window-modal test for the case when the originally clicked window is an |
| 668 | // ancestor of the modal parent. |
| 669 | TEST_F(WindowModalityControllerTest, WindowModalAncestor) { |
| 670 | aura::test::TestWindowDelegate d; |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 671 | std::unique_ptr<aura::Window> w1( |
erg@chromium.org | 5ebe610 | 2012-11-28 21:00:03 | [diff] [blame] | 672 | CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect())); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 673 | std::unique_ptr<aura::Window> w2( |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 674 | aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get())); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 675 | std::unique_ptr<aura::Window> w3( |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 676 | aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w2.get())); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 677 | std::unique_ptr<aura::Window> w4( |
erg@chromium.org | 5ebe610 | 2012-11-28 21:00:03 | [diff] [blame] | 678 | CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect())); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 679 | w4->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); |
ben@chromium.org | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 680 | ::wm::AddTransientChild(w1.get(), w4.get()); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 681 | |
| 682 | wm::ActivateWindow(w1.get()); |
| 683 | EXPECT_TRUE(wm::IsActiveWindow(w4.get())); |
| 684 | |
| 685 | wm::ActivateWindow(w2.get()); |
| 686 | EXPECT_TRUE(wm::IsActiveWindow(w4.get())); |
| 687 | |
| 688 | wm::ActivateWindow(w3.get()); |
| 689 | EXPECT_TRUE(wm::IsActiveWindow(w4.get())); |
| 690 | |
| 691 | wm::ActivateWindow(w4.get()); |
| 692 | EXPECT_TRUE(wm::IsActiveWindow(w4.get())); |
| 693 | } |
| 694 | |
| 695 | // Child-modal test for the case when the originally clicked window is an |
| 696 | // ancestor of the modal parent. |
| 697 | TEST_F(WindowModalityControllerTest, ChildModalAncestor) { |
| 698 | aura::test::TestWindowDelegate d; |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 699 | std::unique_ptr<aura::Window> w1( |
erg@chromium.org | 5ebe610 | 2012-11-28 21:00:03 | [diff] [blame] | 700 | CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect())); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 701 | std::unique_ptr<aura::Window> w2( |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 702 | aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get())); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 703 | std::unique_ptr<aura::Window> w3( |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 704 | aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w2.get())); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 705 | std::unique_ptr<aura::Window> w4( |
erg@chromium.org | 5ebe610 | 2012-11-28 21:00:03 | [diff] [blame] | 706 | CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect())); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 707 | w4->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_CHILD); |
ben@chromium.org | e319c7e | 2014-03-14 19:56:14 | [diff] [blame] | 708 | ::wm::SetModalParent(w4.get(), w2.get()); |
| 709 | ::wm::AddTransientChild(w1.get(), w4.get()); |
rouslan@chromium.org | 31d82f4 | 2012-11-28 16:48:21 | [diff] [blame] | 710 | |
| 711 | wm::ActivateWindow(w1.get()); |
| 712 | EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
| 713 | |
| 714 | wm::ActivateWindow(w2.get()); |
| 715 | EXPECT_TRUE(wm::IsActiveWindow(w4.get())); |
| 716 | |
| 717 | wm::ActivateWindow(w3.get()); |
| 718 | EXPECT_TRUE(wm::IsActiveWindow(w4.get())); |
| 719 | |
| 720 | wm::ActivateWindow(w4.get()); |
| 721 | EXPECT_TRUE(wm::IsActiveWindow(w4.get())); |
| 722 | } |
| 723 | |
dhollowa@chromium.org | 8cc94c1 | 2012-01-20 22:49:27 | [diff] [blame] | 724 | } // namespace ash |