[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 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. |
| 4 | |
jamescook | 8800b823 | 2016-10-19 12:46:27 | [diff] [blame] | 5 | #include "ash/public/cpp/shell_window_ids.h" |
[email protected] | e887c6c | 2013-07-08 19:35:53 | [diff] [blame] | 6 | #include "ash/root_window_controller.h" |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 7 | #include "ash/shell.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 8 | #include "ash/system/tray/system_tray.h" |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 9 | #include "ash/test/ash_test_base.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 10 | #include "ash/wm/root_window_finder.h" |
[email protected] | 57804851 | 2012-09-19 20:01:24 | [diff] [blame] | 11 | #include "ash/wm/window_properties.h" |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 12 | #include "ash/wm/window_util.h" |
[email protected] | 0836da0 | 2013-06-10 19:33:35 | [diff] [blame] | 13 | #include "base/strings/string_util.h" |
[email protected] | 74f778e | 2014-03-14 21:11:46 | [diff] [blame] | 14 | #include "base/strings/utf_string_conversions.h" |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 15 | #include "ui/aura/client/capture_client.h" |
[email protected] | 8cfb672 | 2012-11-28 03:28:46 | [diff] [blame] | 16 | #include "ui/aura/client/focus_client.h" |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 17 | #include "ui/aura/test/test_windows.h" |
[email protected] | 553eae1 | 2013-02-01 02:33:52 | [diff] [blame] | 18 | #include "ui/aura/test/window_test_api.h" |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 19 | #include "ui/aura/window.h" |
[email protected] | fcc51c95 | 2014-02-21 21:31:26 | [diff] [blame] | 20 | #include "ui/aura/window_event_dispatcher.h" |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 21 | #include "ui/base/cursor/cursor.h" |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 22 | #include "ui/display/display.h" |
kylechar | 731f85f9 | 2016-12-01 20:50:46 | [diff] [blame] | 23 | #include "ui/display/display_layout.h" |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 24 | #include "ui/display/manager/display_manager.h" |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 25 | #include "ui/display/screen.h" |
[email protected] | 86ccbd4 | 2013-09-18 18:11:54 | [diff] [blame] | 26 | #include "ui/events/event_handler.h" |
[email protected] | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 27 | #include "ui/events/test/event_generator.h" |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 28 | #include "ui/views/controls/textfield/textfield.h" |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 29 | #include "ui/views/widget/widget.h" |
| 30 | #include "ui/views/widget/widget_delegate.h" |
[email protected] | af4552b2 | 2014-03-21 19:45:01 | [diff] [blame] | 31 | #include "ui/wm/public/activation_client.h" |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 32 | |
| 33 | namespace ash { |
| 34 | namespace { |
| 35 | |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 36 | void SetSecondaryDisplayLayout(display::DisplayPlacement::Position position) { |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 37 | std::unique_ptr<display::DisplayLayout> layout = |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 38 | Shell::Get()->display_manager()->GetCurrentDisplayLayout().Copy(); |
robliao | df37203 | 2016-03-23 00:42:34 | [diff] [blame] | 39 | layout->placement_list[0].position = position; |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 40 | Shell::Get()->display_manager()->SetLayoutForCurrentDisplays( |
oshima | 5df139f | 2016-02-17 08:56:21 | [diff] [blame] | 41 | std::move(layout)); |
[email protected] | edbfb8d | 2012-09-03 08:33:43 | [diff] [blame] | 42 | } |
| 43 | |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 44 | class ModalWidgetDelegate : public views::WidgetDelegateView { |
| 45 | public: |
Chris Watkins | c24daf6 | 2017-11-28 03:43:09 | [diff] [blame^] | 46 | ModalWidgetDelegate() = default; |
| 47 | ~ModalWidgetDelegate() override = default; |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 48 | |
| 49 | // Overridden from views::WidgetDelegate: |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 50 | ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_SYSTEM; } |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 51 | |
| 52 | private: |
| 53 | DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate); |
| 54 | }; |
| 55 | |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 56 | // An event handler which moves the target window to the secondary root window |
[email protected] | 2e98aaf7 | 2012-11-08 06:30:59 | [diff] [blame] | 57 | // at pre-handle phase of a mouse release event. |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 58 | class MoveWindowByClickEventHandler : public ui::EventHandler { |
[email protected] | 2e98aaf7 | 2012-11-08 06:30:59 | [diff] [blame] | 59 | public: |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 60 | explicit MoveWindowByClickEventHandler(aura::Window* target) |
[email protected] | 2e98aaf7 | 2012-11-08 06:30:59 | [diff] [blame] | 61 | : target_(target) {} |
Chris Watkins | c24daf6 | 2017-11-28 03:43:09 | [diff] [blame^] | 62 | ~MoveWindowByClickEventHandler() override = default; |
[email protected] | 2e98aaf7 | 2012-11-08 06:30:59 | [diff] [blame] | 63 | |
| 64 | private: |
| 65 | // ui::EventHandler overrides: |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 66 | void OnMouseEvent(ui::MouseEvent* event) override { |
[email protected] | 2e98aaf7 | 2012-11-08 06:30:59 | [diff] [blame] | 67 | if (event->type() == ui::ET_MOUSE_RELEASED) { |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 68 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
[email protected] | 2e98aaf7 | 2012-11-08 06:30:59 | [diff] [blame] | 69 | DCHECK_LT(1u, root_windows.size()); |
| 70 | root_windows[1]->AddChild(target_); |
| 71 | } |
[email protected] | 2e98aaf7 | 2012-11-08 06:30:59 | [diff] [blame] | 72 | } |
| 73 | |
[email protected] | 2e98aaf7 | 2012-11-08 06:30:59 | [diff] [blame] | 74 | aura::Window* target_; |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 75 | DISALLOW_COPY_AND_ASSIGN(MoveWindowByClickEventHandler); |
| 76 | }; |
| 77 | |
| 78 | // An event handler which records the event's locations. |
| 79 | class EventLocationRecordingEventHandler : public ui::EventHandler { |
| 80 | public: |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 81 | explicit EventLocationRecordingEventHandler() { reset(); } |
Chris Watkins | c24daf6 | 2017-11-28 03:43:09 | [diff] [blame^] | 82 | ~EventLocationRecordingEventHandler() override = default; |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 83 | |
| 84 | std::string GetLocationsAndReset() { |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 85 | std::string result = location_.ToString() + " " + root_location_.ToString(); |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 86 | reset(); |
| 87 | return result; |
| 88 | } |
| 89 | |
| 90 | private: |
| 91 | // ui::EventHandler overrides: |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 92 | void OnMouseEvent(ui::MouseEvent* event) override { |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 93 | if (event->type() == ui::ET_MOUSE_MOVED || |
| 94 | event->type() == ui::ET_MOUSE_DRAGGED) { |
| 95 | location_ = event->location(); |
| 96 | root_location_ = event->root_location(); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | void reset() { |
| 101 | location_.SetPoint(-999, -999); |
| 102 | root_location_.SetPoint(-999, -999); |
| 103 | } |
| 104 | |
| 105 | gfx::Point root_location_; |
| 106 | gfx::Point location_; |
| 107 | |
| 108 | DISALLOW_COPY_AND_ASSIGN(EventLocationRecordingEventHandler); |
[email protected] | 2e98aaf7 | 2012-11-08 06:30:59 | [diff] [blame] | 109 | }; |
| 110 | |
[email protected] | 2ca7594 | 2014-07-12 04:46:37 | [diff] [blame] | 111 | class EventLocationHandler : public ui::EventHandler { |
| 112 | public: |
Chris Watkins | c24daf6 | 2017-11-28 03:43:09 | [diff] [blame^] | 113 | EventLocationHandler() = default; |
| 114 | ~EventLocationHandler() override = default; |
[email protected] | 2ca7594 | 2014-07-12 04:46:37 | [diff] [blame] | 115 | |
| 116 | const gfx::Point& press_location() const { return press_location_; } |
| 117 | const gfx::Point& release_location() const { return release_location_; } |
| 118 | |
| 119 | private: |
| 120 | // ui::EventHandler: |
dcheng | 1f4538e | 2014-10-27 23:57:05 | [diff] [blame] | 121 | void OnMouseEvent(ui::MouseEvent* event) override { |
[email protected] | 2ca7594 | 2014-07-12 04:46:37 | [diff] [blame] | 122 | if (event->type() == ui::ET_MOUSE_PRESSED) |
| 123 | press_location_ = event->location(); |
| 124 | else if (event->type() == ui::ET_MOUSE_RELEASED) |
| 125 | release_location_ = event->location(); |
| 126 | } |
| 127 | |
| 128 | gfx::Point press_location_; |
| 129 | gfx::Point release_location_; |
| 130 | |
| 131 | DISALLOW_COPY_AND_ASSIGN(EventLocationHandler); |
| 132 | }; |
| 133 | |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 134 | } // namespace |
| 135 | |
James Cook | 317781a | 2017-07-18 02:08:06 | [diff] [blame] | 136 | class ExtendedDesktopTest : public AshTestBase { |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 137 | public: |
| 138 | views::Widget* CreateTestWidget(const gfx::Rect& bounds) { |
oshima | 95d499b | 2016-02-10 03:49:56 | [diff] [blame] | 139 | return CreateTestWidgetWithParentAndContext(nullptr, CurrentContext(), |
| 140 | bounds, false); |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | views::Widget* CreateTestWidgetWithParent(views::Widget* parent, |
| 144 | const gfx::Rect& bounds, |
| 145 | bool child) { |
| 146 | CHECK(parent); |
oshima | 95d499b | 2016-02-10 03:49:56 | [diff] [blame] | 147 | return CreateTestWidgetWithParentAndContext(parent, nullptr, bounds, child); |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | views::Widget* CreateTestWidgetWithParentAndContext(views::Widget* parent, |
| 151 | gfx::NativeView context, |
| 152 | const gfx::Rect& bounds, |
| 153 | bool child) { |
| 154 | views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 155 | if (parent) |
| 156 | params.parent = parent->GetNativeView(); |
| 157 | params.context = context; |
| 158 | params.bounds = bounds; |
| 159 | params.child = child; |
| 160 | views::Widget* widget = new views::Widget; |
| 161 | widget->Init(params); |
| 162 | widget->Show(); |
| 163 | return widget; |
| 164 | } |
| 165 | }; |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 166 | |
msw | 257a6a23 | 2017-06-01 01:46:30 | [diff] [blame] | 167 | // Test conditions that root windows in extended desktop mode must satisfy. |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 168 | TEST_F(ExtendedDesktopTest, Basic) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 169 | UpdateDisplay("1000x600,600x400"); |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 170 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 171 | |
msw | 257a6a23 | 2017-06-01 01:46:30 | [diff] [blame] | 172 | // All root windows must have a root window controller. |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 173 | ASSERT_EQ(2U, root_windows.size()); |
msw | 257a6a23 | 2017-06-01 01:46:30 | [diff] [blame] | 174 | EXPECT_TRUE(RootWindowController::ForWindow(root_windows[0])); |
| 175 | EXPECT_TRUE(RootWindowController::ForWindow(root_windows[1])); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 176 | // Make sure root windows share the same controllers. |
[email protected] | 8cfb672 | 2012-11-28 03:28:46 | [diff] [blame] | 177 | EXPECT_EQ(aura::client::GetFocusClient(root_windows[0]), |
| 178 | aura::client::GetFocusClient(root_windows[1])); |
Thiago Farina | 3b086a0 | 2017-05-30 22:32:50 | [diff] [blame] | 179 | EXPECT_EQ(::wm::GetActivationClient(root_windows[0]), |
| 180 | ::wm::GetActivationClient(root_windows[1])); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 181 | EXPECT_EQ(aura::client::GetCaptureClient(root_windows[0]), |
| 182 | aura::client::GetCaptureClient(root_windows[1])); |
| 183 | } |
| 184 | |
| 185 | TEST_F(ExtendedDesktopTest, Activation) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 186 | UpdateDisplay("1000x600,600x400"); |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 187 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 188 | |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 189 | views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 190 | views::Widget* widget_on_2nd = |
| 191 | CreateTestWidget(gfx::Rect(1200, 10, 100, 100)); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 192 | EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow()); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 193 | EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow()); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 194 | |
| 195 | EXPECT_EQ(widget_on_2nd->GetNativeView(), |
[email protected] | 8cfb672 | 2012-11-28 03:28:46 | [diff] [blame] | 196 | aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow()); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 197 | EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView())); |
| 198 | |
[email protected] | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 199 | ui::test::EventGenerator& event_generator(GetEventGenerator()); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 200 | // Clicking a window changes the active window and active root window. |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 201 | event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView()); |
| 202 | event_generator.ClickLeftButton(); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 203 | |
| 204 | EXPECT_EQ(widget_on_1st->GetNativeView(), |
[email protected] | 8cfb672 | 2012-11-28 03:28:46 | [diff] [blame] | 205 | aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow()); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 206 | EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView())); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 207 | |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 208 | event_generator.MoveMouseToCenterOf(widget_on_2nd->GetNativeView()); |
| 209 | event_generator.ClickLeftButton(); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 210 | |
| 211 | EXPECT_EQ(widget_on_2nd->GetNativeView(), |
[email protected] | 8cfb672 | 2012-11-28 03:28:46 | [diff] [blame] | 212 | aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow()); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 213 | EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView())); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | TEST_F(ExtendedDesktopTest, SystemModal) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 217 | UpdateDisplay("1000x600,600x400"); |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 218 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 219 | |
| 220 | views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 221 | EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView())); |
[email protected] | 492533b3 | 2012-09-21 19:06:14 | [diff] [blame] | 222 | EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow()); |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 223 | EXPECT_EQ(root_windows[0], Shell::GetRootWindowForNewWindows()); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 224 | |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 225 | // Open system modal. Make sure it's on 2nd root window and active. |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 226 | views::Widget* modal_widget = views::Widget::CreateWindowWithContextAndBounds( |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 227 | new ModalWidgetDelegate(), CurrentContext(), |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 228 | gfx::Rect(1200, 100, 100, 100)); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 229 | modal_widget->Show(); |
| 230 | EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView())); |
| 231 | EXPECT_EQ(root_windows[1], modal_widget->GetNativeView()->GetRootWindow()); |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 232 | EXPECT_EQ(root_windows[1], Shell::GetRootWindowForNewWindows()); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 233 | |
[email protected] | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 234 | ui::test::EventGenerator& event_generator(GetEventGenerator()); |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 235 | |
[email protected] | 2e236a5 | 2012-06-27 22:21:47 | [diff] [blame] | 236 | // Clicking a widget on widget_on_1st display should not change activation. |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 237 | event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView()); |
| 238 | event_generator.ClickLeftButton(); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 239 | EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView())); |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 240 | EXPECT_EQ(root_windows[1], Shell::GetRootWindowForNewWindows()); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 241 | |
| 242 | // Close system modal and so clicking a widget should work now. |
| 243 | modal_widget->Close(); |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 244 | event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView()); |
| 245 | event_generator.ClickLeftButton(); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 246 | EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView())); |
sky | 2734438 | 2017-03-08 21:30:32 | [diff] [blame] | 247 | EXPECT_EQ(root_windows[0], Shell::GetRootWindowForNewWindows()); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | TEST_F(ExtendedDesktopTest, TestCursor) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 251 | UpdateDisplay("1000x600,600x400"); |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 252 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
[email protected] | 2374d181 | 2014-03-04 03:42:27 | [diff] [blame] | 253 | aura::WindowTreeHost* host0 = root_windows[0]->GetHost(); |
| 254 | aura::WindowTreeHost* host1 = root_windows[1]->GetHost(); |
erg | eeba7c62 | 2017-04-25 18:06:16 | [diff] [blame] | 255 | EXPECT_EQ(ui::CursorType::kPointer, host0->last_cursor().native_type()); |
| 256 | EXPECT_EQ(ui::CursorType::kNull, host1->last_cursor().native_type()); |
| 257 | Shell::Get()->cursor_manager()->SetCursor(ui::CursorType::kCopy); |
| 258 | EXPECT_EQ(ui::CursorType::kCopy, host0->last_cursor().native_type()); |
| 259 | EXPECT_EQ(ui::CursorType::kCopy, host1->last_cursor().native_type()); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 260 | } |
| 261 | |
[email protected] | 718b26c | 2012-07-24 20:53:23 | [diff] [blame] | 262 | TEST_F(ExtendedDesktopTest, TestCursorLocation) { |
[email protected] | d006472 | 2013-03-14 18:16:43 | [diff] [blame] | 263 | UpdateDisplay("1000x600,600x400"); |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 264 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
[email protected] | 553eae1 | 2013-02-01 02:33:52 | [diff] [blame] | 265 | aura::test::WindowTestApi root_window0_test_api(root_windows[0]); |
| 266 | aura::test::WindowTestApi root_window1_test_api(root_windows[1]); |
[email protected] | 718b26c | 2012-07-24 20:53:23 | [diff] [blame] | 267 | |
| 268 | root_windows[0]->MoveCursorTo(gfx::Point(10, 10)); |
scottmg | e8b04297 | 2016-01-27 05:07:35 | [diff] [blame] | 269 | EXPECT_EQ("10,10", |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 270 | display::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
[email protected] | 718b26c | 2012-07-24 20:53:23 | [diff] [blame] | 271 | EXPECT_TRUE(root_window0_test_api.ContainsMouse()); |
| 272 | EXPECT_FALSE(root_window1_test_api.ContainsMouse()); |
| 273 | root_windows[1]->MoveCursorTo(gfx::Point(10, 20)); |
scottmg | e8b04297 | 2016-01-27 05:07:35 | [diff] [blame] | 274 | EXPECT_EQ("1010,20", |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 275 | display::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
[email protected] | 718b26c | 2012-07-24 20:53:23 | [diff] [blame] | 276 | EXPECT_FALSE(root_window0_test_api.ContainsMouse()); |
| 277 | EXPECT_TRUE(root_window1_test_api.ContainsMouse()); |
| 278 | root_windows[0]->MoveCursorTo(gfx::Point(20, 10)); |
scottmg | e8b04297 | 2016-01-27 05:07:35 | [diff] [blame] | 279 | EXPECT_EQ("20,10", |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 280 | display::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
[email protected] | 718b26c | 2012-07-24 20:53:23 | [diff] [blame] | 281 | EXPECT_TRUE(root_window0_test_api.ContainsMouse()); |
| 282 | EXPECT_FALSE(root_window1_test_api.ContainsMouse()); |
| 283 | } |
| 284 | |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 285 | TEST_F(ExtendedDesktopTest, GetRootWindowAt) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 286 | UpdateDisplay("700x500,500x500"); |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 287 | SetSecondaryDisplayLayout(display::DisplayPlacement::LEFT); |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 288 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 289 | |
varkha | 3c60fc5 | 2017-05-25 16:25:11 | [diff] [blame] | 290 | EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-400, 100))); |
| 291 | EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-1, 100))); |
| 292 | EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 300))); |
| 293 | EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(700, 300))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 294 | |
| 295 | // Zero origin. |
varkha | 3c60fc5 | 2017-05-25 16:25:11 | [diff] [blame] | 296 | EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 0))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 297 | |
[email protected] | 3616885 | 2014-01-07 12:23:28 | [diff] [blame] | 298 | // Out of range point should return the nearest root window |
varkha | 3c60fc5 | 2017-05-25 16:25:11 | [diff] [blame] | 299 | EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-600, 0))); |
| 300 | EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(701, 100))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | TEST_F(ExtendedDesktopTest, GetRootWindowMatching) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 304 | UpdateDisplay("700x500,500x500"); |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 305 | SetSecondaryDisplayLayout(display::DisplayPlacement::LEFT); |
[email protected] | 66b05eac | 2012-06-27 23:53:10 | [diff] [blame] | 306 | |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 307 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 308 | |
| 309 | // Containing rect. |
varkha | 3c60fc5 | 2017-05-25 16:25:11 | [diff] [blame] | 310 | EXPECT_EQ(root_windows[1], |
| 311 | wm::GetRootWindowMatching(gfx::Rect(-300, 10, 50, 50))); |
| 312 | EXPECT_EQ(root_windows[0], |
| 313 | wm::GetRootWindowMatching(gfx::Rect(100, 10, 50, 50))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 314 | |
| 315 | // Intersecting rect. |
varkha | 3c60fc5 | 2017-05-25 16:25:11 | [diff] [blame] | 316 | EXPECT_EQ(root_windows[1], |
| 317 | wm::GetRootWindowMatching(gfx::Rect(-200, 0, 300, 300))); |
| 318 | EXPECT_EQ(root_windows[0], |
| 319 | wm::GetRootWindowMatching(gfx::Rect(-100, 0, 300, 300))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 320 | |
| 321 | // Zero origin. |
varkha | 3c60fc5 | 2017-05-25 16:25:11 | [diff] [blame] | 322 | EXPECT_EQ(root_windows[0], wm::GetRootWindowMatching(gfx::Rect(0, 0, 0, 0))); |
| 323 | EXPECT_EQ(root_windows[0], wm::GetRootWindowMatching(gfx::Rect(0, 0, 1, 1))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 324 | |
| 325 | // Empty rect. |
varkha | 3c60fc5 | 2017-05-25 16:25:11 | [diff] [blame] | 326 | EXPECT_EQ(root_windows[1], |
| 327 | wm::GetRootWindowMatching(gfx::Rect(-400, 100, 0, 0))); |
| 328 | EXPECT_EQ(root_windows[0], |
| 329 | wm::GetRootWindowMatching(gfx::Rect(100, 100, 0, 0))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 330 | |
| 331 | // Out of range rect should return the primary root window. |
varkha | 3c60fc5 | 2017-05-25 16:25:11 | [diff] [blame] | 332 | EXPECT_EQ(root_windows[0], |
| 333 | wm::GetRootWindowMatching(gfx::Rect(-600, -300, 50, 50))); |
| 334 | EXPECT_EQ(root_windows[0], |
| 335 | wm::GetRootWindowMatching(gfx::Rect(0, 1000, 50, 50))); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 336 | } |
| 337 | |
[email protected] | 1a01538 | 2012-12-01 19:44:59 | [diff] [blame] | 338 | TEST_F(ExtendedDesktopTest, Capture) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 339 | UpdateDisplay("1000x600,600x400"); |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 340 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 341 | |
| 342 | aura::test::EventCountDelegate r1_d1; |
| 343 | aura::test::EventCountDelegate r1_d2; |
| 344 | aura::test::EventCountDelegate r2_d1; |
| 345 | |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 346 | std::unique_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate( |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 347 | &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0])); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 348 | std::unique_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate( |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 349 | &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0])); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 350 | std::unique_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate( |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 351 | &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1])); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 352 | |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 353 | r1_w1->SetCapture(); |
| 354 | |
| 355 | EXPECT_EQ(r1_w1.get(), |
| 356 | aura::client::GetCaptureWindow(r2_w1->GetRootWindow())); |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 357 | |
[email protected] | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 358 | ui::test::EventGenerator& generator = GetEventGenerator(); |
[email protected] | d05cf2f | 2014-02-26 05:31:43 | [diff] [blame] | 359 | generator.MoveMouseToCenterOf(r2_w1.get()); |
| 360 | // |r1_w1| will receive the events because it has capture. |
| 361 | EXPECT_EQ("1 1 0", r1_d1.GetMouseMotionCountsAndReset()); |
| 362 | EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset()); |
| 363 | EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset()); |
| 364 | |
| 365 | generator.ClickLeftButton(); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 366 | EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset()); |
| 367 | EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset()); |
[email protected] | b19ba4adf | 2012-09-07 16:13:29 | [diff] [blame] | 368 | // The mouse is outside. On chromeos, the mouse is warped to the |
| 369 | // dest root window, but it's not implemented on Win yet, so |
| 370 | // no mouse move event on Win. |
[email protected] | d05cf2f | 2014-02-26 05:31:43 | [diff] [blame] | 371 | EXPECT_EQ("0 0 0", r1_d1.GetMouseMotionCountsAndReset()); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 372 | EXPECT_EQ("1 1", r1_d1.GetMouseButtonCountsAndReset()); |
[email protected] | d05cf2f | 2014-02-26 05:31:43 | [diff] [blame] | 373 | |
| 374 | generator.MoveMouseTo(15, 15); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 375 | EXPECT_EQ("0 1 0", r1_d1.GetMouseMotionCountsAndReset()); |
[email protected] | d05cf2f | 2014-02-26 05:31:43 | [diff] [blame] | 376 | EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset()); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 377 | |
| 378 | r1_w2->SetCapture(); |
| 379 | EXPECT_EQ(r1_w2.get(), |
| 380 | aura::client::GetCaptureWindow(r2_w1->GetRootWindow())); |
[email protected] | d05cf2f | 2014-02-26 05:31:43 | [diff] [blame] | 381 | generator.MoveMouseBy(10, 10); |
| 382 | // |r1_w2| has the capture. So it will receive the mouse-move event. |
| 383 | EXPECT_EQ("0 0 0", r1_d1.GetMouseMotionCountsAndReset()); |
| 384 | EXPECT_EQ("0 1 0", r1_d2.GetMouseMotionCountsAndReset()); |
| 385 | EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset()); |
| 386 | |
| 387 | generator.ClickLeftButton(); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 388 | EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset()); |
| 389 | EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset()); |
[email protected] | d05cf2f | 2014-02-26 05:31:43 | [diff] [blame] | 390 | EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset()); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 391 | EXPECT_EQ("1 1", r1_d2.GetMouseButtonCountsAndReset()); |
[email protected] | d05cf2f | 2014-02-26 05:31:43 | [diff] [blame] | 392 | |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 393 | r1_w2->ReleaseCapture(); |
oshima | 95d499b | 2016-02-10 03:49:56 | [diff] [blame] | 394 | EXPECT_EQ(nullptr, aura::client::GetCaptureWindow(r2_w1->GetRootWindow())); |
[email protected] | d05cf2f | 2014-02-26 05:31:43 | [diff] [blame] | 395 | |
| 396 | generator.MoveMouseToCenterOf(r2_w1.get()); |
| 397 | generator.ClickLeftButton(); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 398 | EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset()); |
| 399 | EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset()); |
| 400 | // Make sure the mouse_moved_handler_ is properly reset. |
| 401 | EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset()); |
| 402 | EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset()); |
| 403 | } |
| 404 | |
[email protected] | 2ca7594 | 2014-07-12 04:46:37 | [diff] [blame] | 405 | TEST_F(ExtendedDesktopTest, CaptureEventLocation) { |
[email protected] | 2ca7594 | 2014-07-12 04:46:37 | [diff] [blame] | 406 | UpdateDisplay("1000x600,600x400"); |
| 407 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 408 | |
| 409 | aura::test::EventCountDelegate r1_d1; |
| 410 | aura::test::EventCountDelegate r1_d2; |
| 411 | aura::test::EventCountDelegate r2_d1; |
| 412 | |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 413 | std::unique_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate( |
[email protected] | 2ca7594 | 2014-07-12 04:46:37 | [diff] [blame] | 414 | &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0])); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 415 | std::unique_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate( |
[email protected] | 2ca7594 | 2014-07-12 04:46:37 | [diff] [blame] | 416 | &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0])); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 417 | std::unique_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate( |
[email protected] | 2ca7594 | 2014-07-12 04:46:37 | [diff] [blame] | 418 | &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1])); |
| 419 | |
| 420 | r1_w1->SetCapture(); |
| 421 | |
[email protected] | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 422 | ui::test::EventGenerator& generator = GetEventGenerator(); |
[email protected] | 2ca7594 | 2014-07-12 04:46:37 | [diff] [blame] | 423 | generator.MoveMouseToCenterOf(r2_w1.get()); |
| 424 | EXPECT_EQ(gfx::Point(1060, 60).ToString(), |
| 425 | generator.current_location().ToString()); |
| 426 | |
| 427 | EventLocationHandler location_handler; |
| 428 | r1_w1->AddPreTargetHandler(&location_handler); |
| 429 | generator.ClickLeftButton(); |
| 430 | r1_w1->RemovePreTargetHandler(&location_handler); |
| 431 | EXPECT_EQ(gfx::Point(1050, 50).ToString(), |
| 432 | location_handler.press_location().ToString()); |
| 433 | EXPECT_EQ(gfx::Point(1050, 50).ToString(), |
| 434 | location_handler.release_location().ToString()); |
| 435 | } |
| 436 | |
| 437 | TEST_F(ExtendedDesktopTest, CaptureEventLocationHighDPI) { |
[email protected] | 2ca7594 | 2014-07-12 04:46:37 | [diff] [blame] | 438 | UpdateDisplay("1000x600*2,600x400"); |
| 439 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 440 | |
| 441 | aura::test::EventCountDelegate r1_d1; |
| 442 | aura::test::EventCountDelegate r1_d2; |
| 443 | aura::test::EventCountDelegate r2_d1; |
| 444 | |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 445 | std::unique_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate( |
[email protected] | 2ca7594 | 2014-07-12 04:46:37 | [diff] [blame] | 446 | &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0])); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 447 | std::unique_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate( |
[email protected] | 2ca7594 | 2014-07-12 04:46:37 | [diff] [blame] | 448 | &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0])); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 449 | std::unique_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate( |
[email protected] | 2ca7594 | 2014-07-12 04:46:37 | [diff] [blame] | 450 | &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1])); |
| 451 | |
| 452 | r1_w1->SetCapture(); |
| 453 | |
[email protected] | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 454 | ui::test::EventGenerator& generator = GetEventGenerator(); |
[email protected] | 2ca7594 | 2014-07-12 04:46:37 | [diff] [blame] | 455 | generator.MoveMouseToCenterOf(r2_w1.get()); |
| 456 | EXPECT_EQ(gfx::Point(560, 60).ToString(), |
| 457 | generator.current_location().ToString()); |
| 458 | |
| 459 | EventLocationHandler location_handler; |
| 460 | r1_w1->AddPreTargetHandler(&location_handler); |
| 461 | generator.ClickLeftButton(); |
| 462 | r1_w1->RemovePreTargetHandler(&location_handler); |
| 463 | EXPECT_EQ(gfx::Point(550, 50).ToString(), |
| 464 | location_handler.press_location().ToString()); |
| 465 | EXPECT_EQ(gfx::Point(550, 50).ToString(), |
| 466 | location_handler.release_location().ToString()); |
| 467 | } |
| 468 | |
| 469 | TEST_F(ExtendedDesktopTest, CaptureEventLocationHighDPI_2) { |
[email protected] | 2ca7594 | 2014-07-12 04:46:37 | [diff] [blame] | 470 | UpdateDisplay("1000x600,600x400*2"); |
| 471 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 472 | |
| 473 | aura::test::EventCountDelegate r1_d1; |
| 474 | aura::test::EventCountDelegate r1_d2; |
| 475 | aura::test::EventCountDelegate r2_d1; |
| 476 | |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 477 | std::unique_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate( |
[email protected] | 2ca7594 | 2014-07-12 04:46:37 | [diff] [blame] | 478 | &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0])); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 479 | std::unique_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate( |
[email protected] | 2ca7594 | 2014-07-12 04:46:37 | [diff] [blame] | 480 | &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0])); |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 481 | std::unique_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate( |
[email protected] | 2ca7594 | 2014-07-12 04:46:37 | [diff] [blame] | 482 | &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1])); |
| 483 | |
| 484 | r1_w1->SetCapture(); |
| 485 | |
[email protected] | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 486 | ui::test::EventGenerator& generator = GetEventGenerator(); |
[email protected] | 2ca7594 | 2014-07-12 04:46:37 | [diff] [blame] | 487 | generator.MoveMouseToCenterOf(r2_w1.get()); |
| 488 | EXPECT_EQ(gfx::Point(1060, 60).ToString(), |
| 489 | generator.current_location().ToString()); |
| 490 | |
| 491 | EventLocationHandler location_handler; |
| 492 | r1_w1->AddPreTargetHandler(&location_handler); |
| 493 | generator.ClickLeftButton(); |
| 494 | r1_w1->RemovePreTargetHandler(&location_handler); |
| 495 | // Event-generator dispatches the event in the primary root-window's coord |
| 496 | // space. Since the location is (1060, 60), it goes to the secondary |
| 497 | // root-window as (30, 30) since the secondary root-window has a device scale |
| 498 | // factor of 2. |
| 499 | EXPECT_EQ(gfx::Point(1020, 20).ToString(), |
| 500 | location_handler.press_location().ToString()); |
| 501 | EXPECT_EQ(gfx::Point(1020, 20).ToString(), |
| 502 | location_handler.release_location().ToString()); |
| 503 | } |
| 504 | |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 505 | TEST_F(ExtendedDesktopTest, MoveWindow) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 506 | UpdateDisplay("1000x600,600x400"); |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 507 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 508 | views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
| 509 | |
| 510 | EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); |
| 511 | |
| 512 | d1->SetBounds(gfx::Rect(1010, 10, 100, 100)); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 513 | EXPECT_EQ("1010,10 100x100", d1->GetWindowBoundsInScreen().ToString()); |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 514 | |
| 515 | EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow()); |
| 516 | |
| 517 | d1->SetBounds(gfx::Rect(10, 10, 100, 100)); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 518 | EXPECT_EQ("10,10 100x100", d1->GetWindowBoundsInScreen().ToString()); |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 519 | |
| 520 | EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); |
| 521 | |
| 522 | // Make sure the bounds which doesn't fit to the root window |
| 523 | // works correctly. |
| 524 | d1->SetBounds(gfx::Rect(1560, 30, 100, 100)); |
| 525 | EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow()); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 526 | EXPECT_EQ("1560,30 100x100", d1->GetWindowBoundsInScreen().ToString()); |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 527 | |
| 528 | // Setting outside of root windows will be moved to primary root window. |
| 529 | // TODO(oshima): This one probably should pick the closest root window. |
| 530 | d1->SetBounds(gfx::Rect(200, 10, 100, 100)); |
| 531 | EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 532 | } |
| 533 | |
[email protected] | 2e98aaf7 | 2012-11-08 06:30:59 | [diff] [blame] | 534 | // Verifies if the mouse event arrives to the window even when the window |
| 535 | // moves to another root in a pre-target handler. See: crbug.com/157583 |
| 536 | TEST_F(ExtendedDesktopTest, MoveWindowByMouseClick) { |
| 537 | UpdateDisplay("1000x600,600x400"); |
| 538 | |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 539 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
[email protected] | 2e98aaf7 | 2012-11-08 06:30:59 | [diff] [blame] | 540 | aura::test::EventCountDelegate delegate; |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 541 | std::unique_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate( |
[email protected] | 2e98aaf7 | 2012-11-08 06:30:59 | [diff] [blame] | 542 | &delegate, 0, gfx::Rect(10, 10, 100, 100), root_windows[0])); |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 543 | MoveWindowByClickEventHandler event_handler(window.get()); |
| 544 | window->AddPreTargetHandler(&event_handler); |
| 545 | |
[email protected] | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 546 | ui::test::EventGenerator& event_generator(GetEventGenerator()); |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 547 | |
| 548 | event_generator.MoveMouseToCenterOf(window.get()); |
| 549 | event_generator.ClickLeftButton(); |
[email protected] | 2e98aaf7 | 2012-11-08 06:30:59 | [diff] [blame] | 550 | // Both mouse pressed and released arrive at the window and its delegate. |
| 551 | EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset()); |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 552 | // Also event_handler moves the window to another root at mouse release. |
[email protected] | 2e98aaf7 | 2012-11-08 06:30:59 | [diff] [blame] | 553 | EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
| 554 | } |
| 555 | |
[email protected] | 1a01538 | 2012-12-01 19:44:59 | [diff] [blame] | 556 | TEST_F(ExtendedDesktopTest, MoveWindowToDisplay) { |
[email protected] | e79f26e | 2012-08-09 07:12:48 | [diff] [blame] | 557 | UpdateDisplay("1000x1000,1000x1000"); |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 558 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
[email protected] | e79f26e | 2012-08-09 07:12:48 | [diff] [blame] | 559 | |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 560 | display::Display display0 = display::Screen::GetScreen()->GetDisplayMatching( |
[email protected] | ffabb1e | 2012-10-12 19:51:17 | [diff] [blame] | 561 | root_windows[0]->GetBoundsInScreen()); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 562 | display::Display display1 = display::Screen::GetScreen()->GetDisplayMatching( |
[email protected] | ffabb1e | 2012-10-12 19:51:17 | [diff] [blame] | 563 | root_windows[1]->GetBoundsInScreen()); |
[email protected] | e79f26e | 2012-08-09 07:12:48 | [diff] [blame] | 564 | EXPECT_NE(display0.id(), display1.id()); |
| 565 | |
| 566 | views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 1000, 100)); |
| 567 | EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); |
| 568 | |
| 569 | // Move the window where the window spans both root windows. Since the second |
| 570 | // parameter is |display1|, the window should be shown on the secondary root. |
| 571 | d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100), |
| 572 | display1); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 573 | EXPECT_EQ("500,10 1000x100", d1->GetWindowBoundsInScreen().ToString()); |
[email protected] | e79f26e | 2012-08-09 07:12:48 | [diff] [blame] | 574 | EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow()); |
| 575 | |
| 576 | // Move to the primary root. |
| 577 | d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100), |
| 578 | display0); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 579 | EXPECT_EQ("500,10 1000x100", d1->GetWindowBoundsInScreen().ToString()); |
[email protected] | e79f26e | 2012-08-09 07:12:48 | [diff] [blame] | 580 | EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); |
| 581 | } |
| 582 | |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 583 | TEST_F(ExtendedDesktopTest, MoveWindowWithTransient) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 584 | UpdateDisplay("1000x600,600x400"); |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 585 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 586 | views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
| 587 | views::Widget* w1_t1 = CreateTestWidgetWithParent( |
| 588 | w1, gfx::Rect(50, 50, 50, 50), false /* transient */); |
| 589 | // Transient child of the transient child. |
| 590 | views::Widget* w1_t11 = CreateTestWidgetWithParent( |
[email protected] | e6de855 | 2014-05-23 19:05:39 | [diff] [blame] | 591 | w1_t1, gfx::Rect(1200, 70, 35, 35), false /* transient */); |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 592 | |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 593 | views::Widget* w11 = CreateTestWidgetWithParent(w1, gfx::Rect(10, 10, 40, 40), |
| 594 | true /* child */); |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 595 | views::Widget* w11_t1 = CreateTestWidgetWithParent( |
| 596 | w1, gfx::Rect(1300, 100, 80, 80), false /* transient */); |
| 597 | |
| 598 | EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow()); |
| 599 | EXPECT_EQ(root_windows[0], w11->GetNativeView()->GetRootWindow()); |
| 600 | EXPECT_EQ(root_windows[0], w1_t1->GetNativeView()->GetRootWindow()); |
| 601 | EXPECT_EQ(root_windows[0], w1_t11->GetNativeView()->GetRootWindow()); |
| 602 | EXPECT_EQ(root_windows[0], w11_t1->GetNativeView()->GetRootWindow()); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 603 | EXPECT_EQ("50,50 50x50", w1_t1->GetWindowBoundsInScreen().ToString()); |
| 604 | EXPECT_EQ("1200,70 35x35", w1_t11->GetWindowBoundsInScreen().ToString()); |
| 605 | EXPECT_EQ("20,20 40x40", w11->GetWindowBoundsInScreen().ToString()); |
| 606 | EXPECT_EQ("1300,100 80x80", w11_t1->GetWindowBoundsInScreen().ToString()); |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 607 | |
[email protected] | 24f5e24 | 2014-07-22 02:16:09 | [diff] [blame] | 608 | w1->SetBounds(gfx::Rect(1100, 10, 100, 100)); |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 609 | |
| 610 | EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow()); |
| 611 | EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow()); |
| 612 | EXPECT_EQ(root_windows[1], w1_t11->GetNativeView()->GetRootWindow()); |
| 613 | EXPECT_EQ(root_windows[1], w11->GetNativeView()->GetRootWindow()); |
| 614 | EXPECT_EQ(root_windows[1], w11_t1->GetNativeView()->GetRootWindow()); |
| 615 | |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 616 | EXPECT_EQ("1110,20 40x40", w11->GetWindowBoundsInScreen().ToString()); |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 617 | // Transient window's screen bounds stays the same. |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 618 | EXPECT_EQ("50,50 50x50", w1_t1->GetWindowBoundsInScreen().ToString()); |
| 619 | EXPECT_EQ("1200,70 35x35", w1_t11->GetWindowBoundsInScreen().ToString()); |
| 620 | EXPECT_EQ("1300,100 80x80", w11_t1->GetWindowBoundsInScreen().ToString()); |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 621 | |
| 622 | // Transient window doesn't move between root window unless |
| 623 | // its transient parent moves. |
| 624 | w1_t1->SetBounds(gfx::Rect(10, 50, 50, 50)); |
| 625 | EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow()); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 626 | EXPECT_EQ("10,50 50x50", w1_t1->GetWindowBoundsInScreen().ToString()); |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 627 | } |
| 628 | |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 629 | // Test if the Window::ConvertPointToTarget works across root windows. |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 630 | TEST_F(ExtendedDesktopTest, ConvertPoint) { |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 631 | display::Screen* screen = display::Screen::GetScreen(); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 632 | UpdateDisplay("1000x600,600x400"); |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 633 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 634 | display::Display display_1 = screen->GetDisplayNearestWindow(root_windows[0]); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 635 | EXPECT_EQ("0,0", display_1.bounds().origin().ToString()); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 636 | display::Display display_2 = screen->GetDisplayNearestWindow(root_windows[1]); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 637 | EXPECT_EQ("1000,0", display_2.bounds().origin().ToString()); |
| 638 | |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 639 | aura::Window* d1 = |
| 640 | CreateTestWidget(gfx::Rect(10, 10, 100, 100))->GetNativeView(); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 641 | aura::Window* d2 = |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 642 | CreateTestWidget(gfx::Rect(1020, 20, 100, 100))->GetNativeView(); |
| 643 | EXPECT_EQ(root_windows[0], d1->GetRootWindow()); |
| 644 | EXPECT_EQ(root_windows[1], d2->GetRootWindow()); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 645 | |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 646 | // Convert point in the Root2's window to the Root1's window Coord. |
| 647 | gfx::Point p(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 648 | aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 649 | EXPECT_EQ("1000,0", p.ToString()); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 650 | p.SetPoint(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 651 | aura::Window::ConvertPointToTarget(d2, d1, &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 652 | EXPECT_EQ("1010,10", p.ToString()); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 653 | |
| 654 | // Convert point in the Root1's window to the Root2's window Coord. |
| 655 | p.SetPoint(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 656 | aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 657 | EXPECT_EQ("-1000,0", p.ToString()); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 658 | p.SetPoint(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 659 | aura::Window::ConvertPointToTarget(d1, d2, &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 660 | EXPECT_EQ("-1010,-10", p.ToString()); |
| 661 | |
| 662 | // Move the 2nd display to the bottom and test again. |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 663 | SetSecondaryDisplayLayout(display::DisplayPlacement::BOTTOM); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 664 | |
[email protected] | b898424 | 2013-07-12 07:55:38 | [diff] [blame] | 665 | display_2 = screen->GetDisplayNearestWindow(root_windows[1]); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 666 | EXPECT_EQ("0,600", display_2.bounds().origin().ToString()); |
| 667 | |
| 668 | // Convert point in Root2's window to Root1's window Coord. |
| 669 | p.SetPoint(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 670 | aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 671 | EXPECT_EQ("0,600", p.ToString()); |
| 672 | p.SetPoint(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 673 | aura::Window::ConvertPointToTarget(d2, d1, &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 674 | EXPECT_EQ("10,610", p.ToString()); |
| 675 | |
| 676 | // Convert point in Root1's window to Root2's window Coord. |
| 677 | p.SetPoint(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 678 | aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 679 | EXPECT_EQ("0,-600", p.ToString()); |
| 680 | p.SetPoint(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 681 | aura::Window::ConvertPointToTarget(d1, d2, &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 682 | EXPECT_EQ("-10,-610", p.ToString()); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 683 | } |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 684 | |
[email protected] | 263898a | 2012-09-17 17:20:07 | [diff] [blame] | 685 | TEST_F(ExtendedDesktopTest, OpenSystemTray) { |
[email protected] | 596c61c | 2012-10-29 17:29:43 | [diff] [blame] | 686 | UpdateDisplay("500x600,600x400"); |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 687 | SystemTray* tray = ash::Shell::Get()->GetPrimarySystemTray(); |
[email protected] | 263898a | 2012-09-17 17:20:07 | [diff] [blame] | 688 | ASSERT_FALSE(tray->HasSystemBubble()); |
| 689 | |
[email protected] | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 690 | ui::test::EventGenerator& event_generator(GetEventGenerator()); |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 691 | |
[email protected] | 263898a | 2012-09-17 17:20:07 | [diff] [blame] | 692 | // Opens the tray by a dummy click event and makes sure that adding/removing |
| 693 | // displays doesn't break anything. |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 694 | event_generator.MoveMouseToCenterOf(tray->GetWidget()->GetNativeWindow()); |
[email protected] | 263898a | 2012-09-17 17:20:07 | [diff] [blame] | 695 | event_generator.ClickLeftButton(); |
| 696 | EXPECT_TRUE(tray->HasSystemBubble()); |
| 697 | |
[email protected] | 596c61c | 2012-10-29 17:29:43 | [diff] [blame] | 698 | UpdateDisplay("500x600"); |
[email protected] | 263898a | 2012-09-17 17:20:07 | [diff] [blame] | 699 | EXPECT_TRUE(tray->HasSystemBubble()); |
[email protected] | 596c61c | 2012-10-29 17:29:43 | [diff] [blame] | 700 | UpdateDisplay("500x600,600x400"); |
[email protected] | 263898a | 2012-09-17 17:20:07 | [diff] [blame] | 701 | EXPECT_TRUE(tray->HasSystemBubble()); |
| 702 | |
| 703 | // Closes the tray and again makes sure that adding/removing displays doesn't |
| 704 | // break anything. |
| 705 | event_generator.ClickLeftButton(); |
| 706 | RunAllPendingInMessageLoop(); |
| 707 | |
| 708 | EXPECT_FALSE(tray->HasSystemBubble()); |
| 709 | |
[email protected] | 596c61c | 2012-10-29 17:29:43 | [diff] [blame] | 710 | UpdateDisplay("500x600"); |
[email protected] | 263898a | 2012-09-17 17:20:07 | [diff] [blame] | 711 | EXPECT_FALSE(tray->HasSystemBubble()); |
[email protected] | 596c61c | 2012-10-29 17:29:43 | [diff] [blame] | 712 | UpdateDisplay("500x600,600x400"); |
[email protected] | 263898a | 2012-09-17 17:20:07 | [diff] [blame] | 713 | EXPECT_FALSE(tray->HasSystemBubble()); |
| 714 | } |
| 715 | |
[email protected] | 57804851 | 2012-09-19 20:01:24 | [diff] [blame] | 716 | TEST_F(ExtendedDesktopTest, StayInSameRootWindow) { |
| 717 | UpdateDisplay("100x100,200x200"); |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 718 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 719 | views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 50, 50)); |
[email protected] | 57804851 | 2012-09-19 20:01:24 | [diff] [blame] | 720 | EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow()); |
| 721 | w1->SetBounds(gfx::Rect(150, 10, 50, 50)); |
| 722 | EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow()); |
| 723 | |
sky | aecdb0fb | 2016-09-15 22:14:28 | [diff] [blame] | 724 | // The widget stays in the same root if kLockedToRootKey is set to true. |
| 725 | w1->GetNativeView()->SetProperty(kLockedToRootKey, true); |
[email protected] | 57804851 | 2012-09-19 20:01:24 | [diff] [blame] | 726 | w1->SetBounds(gfx::Rect(10, 10, 50, 50)); |
| 727 | EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow()); |
| 728 | |
| 729 | // The widget should now move to the 1st root window without the property. |
sky | aecdb0fb | 2016-09-15 22:14:28 | [diff] [blame] | 730 | w1->GetNativeView()->ClearProperty(kLockedToRootKey); |
[email protected] | 57804851 | 2012-09-19 20:01:24 | [diff] [blame] | 731 | w1->SetBounds(gfx::Rect(10, 10, 50, 50)); |
| 732 | EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow()); |
[email protected] | e887c6c | 2013-07-08 19:35:53 | [diff] [blame] | 733 | |
| 734 | // a window in SettingsBubbleContainer and StatusContainer should |
| 735 | // not move to another root window regardles of the bounds specified. |
| 736 | aura::Window* settings_bubble_container = |
| 737 | Shell::GetPrimaryRootWindowController()->GetContainer( |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 738 | kShellWindowId_SettingBubbleContainer); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 739 | aura::Window* window = |
| 740 | aura::test::CreateTestWindowWithId(100, settings_bubble_container); |
sky | 8782ff0 | 2017-02-23 22:12:42 | [diff] [blame] | 741 | window->SetBoundsInScreen(gfx::Rect(150, 10, 50, 50), GetSecondaryDisplay()); |
[email protected] | e887c6c | 2013-07-08 19:35:53 | [diff] [blame] | 742 | EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
| 743 | |
| 744 | aura::Window* status_container = |
| 745 | Shell::GetPrimaryRootWindowController()->GetContainer( |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 746 | kShellWindowId_StatusContainer); |
[email protected] | e887c6c | 2013-07-08 19:35:53 | [diff] [blame] | 747 | window = aura::test::CreateTestWindowWithId(100, status_container); |
sky | 8782ff0 | 2017-02-23 22:12:42 | [diff] [blame] | 748 | window->SetBoundsInScreen(gfx::Rect(150, 10, 50, 50), GetSecondaryDisplay()); |
[email protected] | e887c6c | 2013-07-08 19:35:53 | [diff] [blame] | 749 | EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
[email protected] | 57804851 | 2012-09-19 20:01:24 | [diff] [blame] | 750 | } |
| 751 | |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 752 | TEST_F(ExtendedDesktopTest, KeyEventsOnLockScreen) { |
| 753 | UpdateDisplay("100x100,200x200"); |
[email protected] | c9390bd | 2013-11-08 20:33:13 | [diff] [blame] | 754 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 755 | |
| 756 | // Create normal windows on both displays. |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 757 | views::Widget* widget1 = CreateTestWidget( |
| 758 | display::Screen::GetScreen()->GetPrimaryDisplay().bounds()); |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 759 | widget1->Show(); |
| 760 | EXPECT_EQ(root_windows[0], widget1->GetNativeView()->GetRootWindow()); |
sky | 8782ff0 | 2017-02-23 22:12:42 | [diff] [blame] | 761 | views::Widget* widget2 = CreateTestWidget(GetSecondaryDisplay().bounds()); |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 762 | widget2->Show(); |
| 763 | EXPECT_EQ(root_windows[1], widget2->GetNativeView()->GetRootWindow()); |
| 764 | |
| 765 | // Create a LockScreen window. |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 766 | views::Widget* lock_widget = CreateTestWidget( |
| 767 | display::Screen::GetScreen()->GetPrimaryDisplay().bounds()); |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 768 | views::Textfield* textfield = new views::Textfield; |
[email protected] | 0914895 | 2013-03-13 13:25:43 | [diff] [blame] | 769 | lock_widget->client_view()->AddChildView(textfield); |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 770 | |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 771 | ash::Shell::GetContainer(Shell::GetPrimaryRootWindow(), |
| 772 | ash::kShellWindowId_LockScreenContainer) |
| 773 | ->AddChild(lock_widget->GetNativeView()); |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 774 | lock_widget->Show(); |
| 775 | textfield->RequestFocus(); |
| 776 | |
[email protected] | 8cfb672 | 2012-11-28 03:28:46 | [diff] [blame] | 777 | aura::client::FocusClient* focus_client = |
| 778 | aura::client::GetFocusClient(root_windows[0]); |
| 779 | EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow()); |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 780 | |
| 781 | // The lock window should get events on both root windows. |
[email protected] | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 782 | ui::test::EventGenerator& event_generator(GetEventGenerator()); |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 783 | |
[email protected] | 1ea46f6f | 2014-07-17 07:36:40 | [diff] [blame] | 784 | event_generator.set_current_target(root_windows[0]); |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 785 | event_generator.PressKey(ui::VKEY_A, 0); |
| 786 | event_generator.ReleaseKey(ui::VKEY_A, 0); |
[email protected] | 8cfb672 | 2012-11-28 03:28:46 | [diff] [blame] | 787 | EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow()); |
[email protected] | 74f778e | 2014-03-14 21:11:46 | [diff] [blame] | 788 | EXPECT_EQ("a", base::UTF16ToASCII(textfield->text())); |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 789 | |
[email protected] | 1ea46f6f | 2014-07-17 07:36:40 | [diff] [blame] | 790 | event_generator.set_current_target(root_windows[1]); |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 791 | event_generator.PressKey(ui::VKEY_B, 0); |
| 792 | event_generator.ReleaseKey(ui::VKEY_B, 0); |
[email protected] | 8cfb672 | 2012-11-28 03:28:46 | [diff] [blame] | 793 | EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow()); |
[email protected] | 74f778e | 2014-03-14 21:11:46 | [diff] [blame] | 794 | EXPECT_EQ("ab", base::UTF16ToASCII(textfield->text())); |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 795 | |
| 796 | // Deleting 2nd display. The lock window still should get the events. |
| 797 | UpdateDisplay("100x100"); |
pkotwicz | 5d118a6b1 | 2015-02-12 22:23:57 | [diff] [blame] | 798 | event_generator.set_current_target(root_windows[0]); |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 799 | event_generator.PressKey(ui::VKEY_C, 0); |
| 800 | event_generator.ReleaseKey(ui::VKEY_C, 0); |
[email protected] | 8cfb672 | 2012-11-28 03:28:46 | [diff] [blame] | 801 | EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow()); |
[email protected] | 74f778e | 2014-03-14 21:11:46 | [diff] [blame] | 802 | EXPECT_EQ("abc", base::UTF16ToASCII(textfield->text())); |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 803 | |
| 804 | // Creating 2nd display again, and lock window still should get events |
| 805 | // on both root windows. |
| 806 | UpdateDisplay("100x100,200x200"); |
| 807 | root_windows = Shell::GetAllRootWindows(); |
[email protected] | 1ea46f6f | 2014-07-17 07:36:40 | [diff] [blame] | 808 | event_generator.set_current_target(root_windows[0]); |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 809 | event_generator.PressKey(ui::VKEY_D, 0); |
| 810 | event_generator.ReleaseKey(ui::VKEY_D, 0); |
[email protected] | 8cfb672 | 2012-11-28 03:28:46 | [diff] [blame] | 811 | EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow()); |
[email protected] | 74f778e | 2014-03-14 21:11:46 | [diff] [blame] | 812 | EXPECT_EQ("abcd", base::UTF16ToASCII(textfield->text())); |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 813 | |
[email protected] | 1ea46f6f | 2014-07-17 07:36:40 | [diff] [blame] | 814 | event_generator.set_current_target(root_windows[1]); |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 815 | event_generator.PressKey(ui::VKEY_E, 0); |
| 816 | event_generator.ReleaseKey(ui::VKEY_E, 0); |
[email protected] | 8cfb672 | 2012-11-28 03:28:46 | [diff] [blame] | 817 | EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow()); |
[email protected] | 74f778e | 2014-03-14 21:11:46 | [diff] [blame] | 818 | EXPECT_EQ("abcde", base::UTF16ToASCII(textfield->text())); |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 819 | } |
| 820 | |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 821 | TEST_F(ExtendedDesktopTest, PassiveGrab) { |
| 822 | EventLocationRecordingEventHandler event_handler; |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 823 | ash::Shell::Get()->AddPreTargetHandler(&event_handler); |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 824 | |
| 825 | UpdateDisplay("300x300,200x200"); |
| 826 | |
| 827 | views::Widget* widget = CreateTestWidget(gfx::Rect(50, 50, 200, 200)); |
| 828 | widget->Show(); |
| 829 | ASSERT_EQ("50,50 200x200", widget->GetWindowBoundsInScreen().ToString()); |
| 830 | |
[email protected] | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 831 | ui::test::EventGenerator& generator(GetEventGenerator()); |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 832 | generator.MoveMouseTo(150, 150); |
| 833 | EXPECT_EQ("100,100 150,150", event_handler.GetLocationsAndReset()); |
| 834 | |
| 835 | generator.PressLeftButton(); |
| 836 | generator.MoveMouseTo(400, 150); |
| 837 | |
| 838 | EXPECT_EQ("350,100 400,150", event_handler.GetLocationsAndReset()); |
| 839 | |
| 840 | generator.ReleaseLeftButton(); |
| 841 | EXPECT_EQ("-999,-999 -999,-999", event_handler.GetLocationsAndReset()); |
| 842 | |
| 843 | generator.MoveMouseTo(400, 150); |
| 844 | EXPECT_EQ("100,150 100,150", event_handler.GetLocationsAndReset()); |
| 845 | |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 846 | ash::Shell::Get()->RemovePreTargetHandler(&event_handler); |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 847 | } |
| 848 | |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 849 | } // namespace ash |