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