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