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