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