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