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