[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] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 17 | #include "base/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(); |
| 40 | DisplayLayout layout = display_controller->default_display_layout(); |
| 41 | layout.position = position; |
| 42 | display_controller->SetDefaultDisplayLayout(layout); |
| 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] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 160 | UpdateDisplay("1000x600,600x400"); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 161 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 162 | |
| 163 | // All root windows must have the root window controller. |
| 164 | ASSERT_EQ(2U, root_windows.size()); |
| 165 | for (Shell::RootWindowList::const_iterator iter = root_windows.begin(); |
| 166 | iter != root_windows.end(); ++iter) { |
[email protected] | 7ae52500 | 2012-07-26 23:55:10 | [diff] [blame] | 167 | EXPECT_TRUE(GetRootWindowController(*iter) != NULL); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 168 | } |
| 169 | // Make sure root windows share the same controllers. |
[email protected] | 8cfb672 | 2012-11-28 03:28:46 | [diff] [blame] | 170 | EXPECT_EQ(aura::client::GetFocusClient(root_windows[0]), |
| 171 | aura::client::GetFocusClient(root_windows[1])); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 172 | EXPECT_EQ(aura::client::GetActivationClient(root_windows[0]), |
| 173 | aura::client::GetActivationClient(root_windows[1])); |
| 174 | EXPECT_EQ(aura::client::GetCaptureClient(root_windows[0]), |
| 175 | aura::client::GetCaptureClient(root_windows[1])); |
| 176 | } |
| 177 | |
| 178 | TEST_F(ExtendedDesktopTest, Activation) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 179 | UpdateDisplay("1000x600,600x400"); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 180 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 181 | |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 182 | views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 183 | views::Widget* widget_on_2nd = |
| 184 | CreateTestWidget(gfx::Rect(1200, 10, 100, 100)); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 185 | EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow()); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 186 | EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow()); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 187 | |
| 188 | EXPECT_EQ(widget_on_2nd->GetNativeView(), |
[email protected] | 8cfb672 | 2012-11-28 03:28:46 | [diff] [blame] | 189 | aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow()); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 190 | EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView())); |
| 191 | |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 192 | aura::test::EventGenerator& event_generator(GetEventGenerator()); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 193 | // Clicking a window changes the active window and active root window. |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 194 | event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView()); |
| 195 | event_generator.ClickLeftButton(); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 196 | |
| 197 | EXPECT_EQ(widget_on_1st->GetNativeView(), |
[email protected] | 8cfb672 | 2012-11-28 03:28:46 | [diff] [blame] | 198 | aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow()); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 199 | EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView())); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 200 | |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 201 | event_generator.MoveMouseToCenterOf(widget_on_2nd->GetNativeView()); |
| 202 | event_generator.ClickLeftButton(); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 203 | |
| 204 | EXPECT_EQ(widget_on_2nd->GetNativeView(), |
[email protected] | 8cfb672 | 2012-11-28 03:28:46 | [diff] [blame] | 205 | aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow()); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 206 | EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView())); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | TEST_F(ExtendedDesktopTest, SystemModal) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 210 | UpdateDisplay("1000x600,600x400"); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 211 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 212 | |
| 213 | views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 214 | EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView())); |
[email protected] | 492533b3 | 2012-09-21 19:06:14 | [diff] [blame] | 215 | EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow()); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 216 | EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow()); |
| 217 | |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 218 | // Open system modal. Make sure it's on 2nd root window and active. |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 219 | views::Widget* modal_widget = views::Widget::CreateWindowWithContextAndBounds( |
| 220 | new ModalWidgetDelegate(), |
| 221 | CurrentContext(), |
| 222 | gfx::Rect(1200, 100, 100, 100)); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 223 | modal_widget->Show(); |
| 224 | EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView())); |
| 225 | EXPECT_EQ(root_windows[1], modal_widget->GetNativeView()->GetRootWindow()); |
| 226 | EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow()); |
| 227 | |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 228 | aura::test::EventGenerator& event_generator(GetEventGenerator()); |
| 229 | |
[email protected] | 2e236a5 | 2012-06-27 22:21:47 | [diff] [blame] | 230 | // Clicking a widget on widget_on_1st display should not change activation. |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 231 | event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView()); |
| 232 | event_generator.ClickLeftButton(); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 233 | EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView())); |
| 234 | EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow()); |
| 235 | |
| 236 | // Close system modal and so clicking a widget should work now. |
| 237 | modal_widget->Close(); |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 238 | event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView()); |
| 239 | event_generator.ClickLeftButton(); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 240 | EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView())); |
| 241 | EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow()); |
| 242 | } |
| 243 | |
| 244 | TEST_F(ExtendedDesktopTest, TestCursor) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 245 | UpdateDisplay("1000x600,600x400"); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 246 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 247 | EXPECT_EQ(ui::kCursorPointer, root_windows[0]->last_cursor().native_type()); |
| 248 | EXPECT_EQ(ui::kCursorPointer, root_windows[1]->last_cursor().native_type()); |
[email protected] | 151ffdff | 2012-09-11 20:18:35 | [diff] [blame] | 249 | Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorCopy); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 250 | EXPECT_EQ(ui::kCursorCopy, root_windows[0]->last_cursor().native_type()); |
| 251 | EXPECT_EQ(ui::kCursorCopy, root_windows[1]->last_cursor().native_type()); |
| 252 | } |
| 253 | |
[email protected] | 718b26c | 2012-07-24 20:53:23 | [diff] [blame] | 254 | TEST_F(ExtendedDesktopTest, TestCursorLocation) { |
[email protected] | d006472 | 2013-03-14 18:16:43 | [diff] [blame^] | 255 | UpdateDisplay("1000x600,600x400"); |
[email protected] | 718b26c | 2012-07-24 20:53:23 | [diff] [blame] | 256 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
[email protected] | 553eae1 | 2013-02-01 02:33:52 | [diff] [blame] | 257 | aura::test::WindowTestApi root_window0_test_api(root_windows[0]); |
| 258 | aura::test::WindowTestApi root_window1_test_api(root_windows[1]); |
[email protected] | 718b26c | 2012-07-24 20:53:23 | [diff] [blame] | 259 | |
| 260 | root_windows[0]->MoveCursorTo(gfx::Point(10, 10)); |
[email protected] | ffabb1e | 2012-10-12 19:51:17 | [diff] [blame] | 261 | EXPECT_EQ("10,10", Shell::GetScreen()->GetCursorScreenPoint().ToString()); |
[email protected] | 718b26c | 2012-07-24 20:53:23 | [diff] [blame] | 262 | EXPECT_TRUE(root_window0_test_api.ContainsMouse()); |
| 263 | EXPECT_FALSE(root_window1_test_api.ContainsMouse()); |
| 264 | root_windows[1]->MoveCursorTo(gfx::Point(10, 20)); |
[email protected] | ffabb1e | 2012-10-12 19:51:17 | [diff] [blame] | 265 | EXPECT_EQ("1010,20", Shell::GetScreen()->GetCursorScreenPoint().ToString()); |
[email protected] | 718b26c | 2012-07-24 20:53:23 | [diff] [blame] | 266 | EXPECT_FALSE(root_window0_test_api.ContainsMouse()); |
| 267 | EXPECT_TRUE(root_window1_test_api.ContainsMouse()); |
| 268 | root_windows[0]->MoveCursorTo(gfx::Point(20, 10)); |
[email protected] | ffabb1e | 2012-10-12 19:51:17 | [diff] [blame] | 269 | EXPECT_EQ("20,10", Shell::GetScreen()->GetCursorScreenPoint().ToString()); |
[email protected] | 718b26c | 2012-07-24 20:53:23 | [diff] [blame] | 270 | EXPECT_TRUE(root_window0_test_api.ContainsMouse()); |
| 271 | EXPECT_FALSE(root_window1_test_api.ContainsMouse()); |
| 272 | } |
| 273 | |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 274 | TEST_F(ExtendedDesktopTest, CycleWindows) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 275 | UpdateDisplay("700x500,500x500"); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 276 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 277 | |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 278 | WindowCycleController* controller = |
| 279 | Shell::GetInstance()->window_cycle_controller(); |
| 280 | |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 281 | views::Widget* d1_w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
| 282 | EXPECT_EQ(root_windows[0], d1_w1->GetNativeView()->GetRootWindow()); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 283 | views::Widget* d2_w1 = CreateTestWidget(gfx::Rect(800, 10, 100, 100)); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 284 | EXPECT_EQ(root_windows[1], d2_w1->GetNativeView()->GetRootWindow()); |
| 285 | EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView())); |
| 286 | |
| 287 | controller->HandleCycleWindow(WindowCycleController::FORWARD, false); |
| 288 | EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView())); |
| 289 | controller->HandleCycleWindow(WindowCycleController::FORWARD, false); |
| 290 | EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView())); |
| 291 | controller->HandleCycleWindow(WindowCycleController::BACKWARD, false); |
| 292 | EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView())); |
| 293 | controller->HandleCycleWindow(WindowCycleController::BACKWARD, false); |
| 294 | EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView())); |
| 295 | |
| 296 | // Cycle through all windows across root windows. |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 297 | views::Widget* d1_w2 = CreateTestWidget(gfx::Rect(10, 200, 100, 100)); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 298 | EXPECT_EQ(root_windows[0], d1_w2->GetNativeView()->GetRootWindow()); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 299 | views::Widget* d2_w2 = CreateTestWidget(gfx::Rect(800, 200, 100, 100)); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 300 | EXPECT_EQ(root_windows[1], d2_w2->GetNativeView()->GetRootWindow()); |
| 301 | |
| 302 | controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 303 | EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView())); |
| 304 | controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
[email protected] | 8fef743 | 2012-08-06 15:34:25 | [diff] [blame] | 305 | EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView())); |
| 306 | controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 307 | EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView())); |
| 308 | controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 309 | EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView())); |
| 310 | |
| 311 | // Backwards |
| 312 | controller->HandleCycleWindow(WindowCycleController::BACKWARD, true); |
| 313 | EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView())); |
| 314 | controller->HandleCycleWindow(WindowCycleController::BACKWARD, true); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 315 | EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView())); |
| 316 | controller->HandleCycleWindow(WindowCycleController::BACKWARD, true); |
[email protected] | 8fef743 | 2012-08-06 15:34:25 | [diff] [blame] | 317 | EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView())); |
| 318 | controller->HandleCycleWindow(WindowCycleController::BACKWARD, true); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 319 | EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView())); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | TEST_F(ExtendedDesktopTest, GetRootWindowAt) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 323 | UpdateDisplay("700x500,500x500"); |
[email protected] | edbfb8d | 2012-09-03 08:33:43 | [diff] [blame] | 324 | SetSecondaryDisplayLayout(DisplayLayout::LEFT); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 325 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 326 | |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 327 | EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-400, 100))); |
| 328 | EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-1, 100))); |
| 329 | EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 300))); |
| 330 | EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(700,300))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 331 | |
| 332 | // Zero origin. |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 333 | EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 0))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 334 | |
| 335 | // Out of range point should return the primary root window |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 336 | EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(-600, 0))); |
| 337 | EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(701, 100))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | TEST_F(ExtendedDesktopTest, GetRootWindowMatching) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 341 | UpdateDisplay("700x500,500x500"); |
[email protected] | edbfb8d | 2012-09-03 08:33:43 | [diff] [blame] | 342 | SetSecondaryDisplayLayout(DisplayLayout::LEFT); |
[email protected] | 66b05eac | 2012-06-27 23:53:10 | [diff] [blame] | 343 | |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 344 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 345 | |
| 346 | // Containing rect. |
| 347 | EXPECT_EQ(root_windows[1], |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 348 | wm::GetRootWindowMatching(gfx::Rect(-300, 10, 50, 50))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 349 | EXPECT_EQ(root_windows[0], |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 350 | wm::GetRootWindowMatching(gfx::Rect(100, 10, 50, 50))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 351 | |
| 352 | // Intersecting rect. |
| 353 | EXPECT_EQ(root_windows[1], |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 354 | wm::GetRootWindowMatching(gfx::Rect(-200, 0, 300, 300))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 355 | EXPECT_EQ(root_windows[0], |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 356 | wm::GetRootWindowMatching(gfx::Rect(-100, 0, 300, 300))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 357 | |
| 358 | // Zero origin. |
[email protected] | 66b05eac | 2012-06-27 23:53:10 | [diff] [blame] | 359 | EXPECT_EQ(root_windows[0], |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 360 | wm::GetRootWindowMatching(gfx::Rect(0, 0, 0, 0))); |
[email protected] | 66b05eac | 2012-06-27 23:53:10 | [diff] [blame] | 361 | EXPECT_EQ(root_windows[0], |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 362 | wm::GetRootWindowMatching(gfx::Rect(0, 0, 1, 1))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 363 | |
| 364 | // Empty rect. |
| 365 | EXPECT_EQ(root_windows[1], |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 366 | wm::GetRootWindowMatching(gfx::Rect(-400, 100, 0, 0))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 367 | EXPECT_EQ(root_windows[0], |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 368 | wm::GetRootWindowMatching(gfx::Rect(100, 100, 0, 0))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 369 | |
| 370 | // Out of range rect should return the primary root window. |
| 371 | EXPECT_EQ(root_windows[0], |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 372 | wm::GetRootWindowMatching(gfx::Rect(-600, -300, 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(0, 1000, 50, 50))); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 375 | } |
| 376 | |
[email protected] | 1a01538 | 2012-12-01 19:44:59 | [diff] [blame] | 377 | TEST_F(ExtendedDesktopTest, Capture) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 378 | UpdateDisplay("1000x600,600x400"); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 379 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 380 | |
| 381 | aura::test::EventCountDelegate r1_d1; |
| 382 | aura::test::EventCountDelegate r1_d2; |
| 383 | aura::test::EventCountDelegate r2_d1; |
| 384 | |
| 385 | scoped_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate( |
| 386 | &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0])); |
| 387 | scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate( |
| 388 | &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0])); |
| 389 | scoped_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate( |
| 390 | &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1])); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 391 | |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 392 | r1_w1->SetCapture(); |
| 393 | |
| 394 | EXPECT_EQ(r1_w1.get(), |
| 395 | aura::client::GetCaptureWindow(r2_w1->GetRootWindow())); |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 396 | |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 397 | aura::test::EventGenerator generator2(root_windows[1]); |
| 398 | generator2.MoveMouseToCenterOf(r2_w1.get()); |
| 399 | generator2.ClickLeftButton(); |
| 400 | EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset()); |
| 401 | EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset()); |
[email protected] | b19ba4adf | 2012-09-07 16:13:29 | [diff] [blame] | 402 | // The mouse is outside. On chromeos, the mouse is warped to the |
| 403 | // dest root window, but it's not implemented on Win yet, so |
| 404 | // no mouse move event on Win. |
[email protected] | 7495e503 | 2012-09-07 15:31:45 | [diff] [blame] | 405 | EXPECT_EQ("1 1 0", r1_d1.GetMouseMotionCountsAndReset()); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 406 | EXPECT_EQ("1 1", r1_d1.GetMouseButtonCountsAndReset()); |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 407 | // Emulate passive grab. (15,15) on 1st display is (-985,15) on 2nd |
| 408 | // display. |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 409 | generator2.MoveMouseTo(-985, 15); |
| 410 | EXPECT_EQ("0 1 0", r1_d1.GetMouseMotionCountsAndReset()); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 411 | |
| 412 | r1_w2->SetCapture(); |
| 413 | EXPECT_EQ(r1_w2.get(), |
| 414 | aura::client::GetCaptureWindow(r2_w1->GetRootWindow())); |
| 415 | generator2.MoveMouseBy(10, 10); |
| 416 | generator2.ClickLeftButton(); |
| 417 | EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset()); |
| 418 | EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset()); |
| 419 | // mouse is already entered. |
| 420 | EXPECT_EQ("0 1 0", r1_d2.GetMouseMotionCountsAndReset()); |
| 421 | EXPECT_EQ("1 1", r1_d2.GetMouseButtonCountsAndReset()); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 422 | r1_w2->ReleaseCapture(); |
[email protected] | 36f56653 | 2012-09-19 04:07:24 | [diff] [blame] | 423 | EXPECT_EQ(NULL, aura::client::GetCaptureWindow(r2_w1->GetRootWindow())); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 424 | generator2.MoveMouseTo(15, 15); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 425 | generator2.ClickLeftButton(); |
| 426 | EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset()); |
| 427 | EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset()); |
| 428 | // Make sure the mouse_moved_handler_ is properly reset. |
| 429 | EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset()); |
| 430 | EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset()); |
| 431 | } |
| 432 | |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 433 | TEST_F(ExtendedDesktopTest, MoveWindow) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 434 | UpdateDisplay("1000x600,600x400"); |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 435 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 436 | views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
| 437 | |
| 438 | EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); |
| 439 | |
| 440 | d1->SetBounds(gfx::Rect(1010, 10, 100, 100)); |
| 441 | EXPECT_EQ("1010,10 100x100", |
| 442 | d1->GetWindowBoundsInScreen().ToString()); |
| 443 | |
| 444 | EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow()); |
| 445 | |
| 446 | d1->SetBounds(gfx::Rect(10, 10, 100, 100)); |
| 447 | EXPECT_EQ("10,10 100x100", |
| 448 | d1->GetWindowBoundsInScreen().ToString()); |
| 449 | |
| 450 | EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); |
| 451 | |
| 452 | // Make sure the bounds which doesn't fit to the root window |
| 453 | // works correctly. |
| 454 | d1->SetBounds(gfx::Rect(1560, 30, 100, 100)); |
| 455 | EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow()); |
| 456 | EXPECT_EQ("1560,30 100x100", |
| 457 | d1->GetWindowBoundsInScreen().ToString()); |
| 458 | |
| 459 | // Setting outside of root windows will be moved to primary root window. |
| 460 | // TODO(oshima): This one probably should pick the closest root window. |
| 461 | d1->SetBounds(gfx::Rect(200, 10, 100, 100)); |
| 462 | EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 463 | } |
| 464 | |
[email protected] | 2e98aaf7 | 2012-11-08 06:30:59 | [diff] [blame] | 465 | // Verifies if the mouse event arrives to the window even when the window |
| 466 | // moves to another root in a pre-target handler. See: crbug.com/157583 |
| 467 | TEST_F(ExtendedDesktopTest, MoveWindowByMouseClick) { |
| 468 | UpdateDisplay("1000x600,600x400"); |
| 469 | |
| 470 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 471 | aura::test::EventCountDelegate delegate; |
| 472 | scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate( |
| 473 | &delegate, 0, gfx::Rect(10, 10, 100, 100), root_windows[0])); |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 474 | MoveWindowByClickEventHandler event_handler(window.get()); |
| 475 | window->AddPreTargetHandler(&event_handler); |
| 476 | |
| 477 | aura::test::EventGenerator& event_generator(GetEventGenerator()); |
| 478 | |
| 479 | event_generator.MoveMouseToCenterOf(window.get()); |
| 480 | event_generator.ClickLeftButton(); |
[email protected] | 2e98aaf7 | 2012-11-08 06:30:59 | [diff] [blame] | 481 | // Both mouse pressed and released arrive at the window and its delegate. |
| 482 | EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset()); |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 483 | // Also event_handler moves the window to another root at mouse release. |
[email protected] | 2e98aaf7 | 2012-11-08 06:30:59 | [diff] [blame] | 484 | EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
| 485 | } |
| 486 | |
[email protected] | 1a01538 | 2012-12-01 19:44:59 | [diff] [blame] | 487 | TEST_F(ExtendedDesktopTest, MoveWindowToDisplay) { |
[email protected] | e79f26e | 2012-08-09 07:12:48 | [diff] [blame] | 488 | UpdateDisplay("1000x1000,1000x1000"); |
| 489 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 490 | |
[email protected] | ffabb1e | 2012-10-12 19:51:17 | [diff] [blame] | 491 | gfx::Display display0 = Shell::GetScreen()->GetDisplayMatching( |
| 492 | root_windows[0]->GetBoundsInScreen()); |
| 493 | gfx::Display display1 = Shell::GetScreen()->GetDisplayMatching( |
| 494 | root_windows[1]->GetBoundsInScreen()); |
[email protected] | e79f26e | 2012-08-09 07:12:48 | [diff] [blame] | 495 | EXPECT_NE(display0.id(), display1.id()); |
| 496 | |
| 497 | views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 1000, 100)); |
| 498 | EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); |
| 499 | |
| 500 | // Move the window where the window spans both root windows. Since the second |
| 501 | // parameter is |display1|, the window should be shown on the secondary root. |
| 502 | d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100), |
| 503 | display1); |
| 504 | EXPECT_EQ("500,10 1000x100", |
| 505 | d1->GetWindowBoundsInScreen().ToString()); |
| 506 | EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow()); |
| 507 | |
| 508 | // Move to the primary root. |
| 509 | d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100), |
| 510 | display0); |
| 511 | EXPECT_EQ("500,10 1000x100", |
| 512 | d1->GetWindowBoundsInScreen().ToString()); |
| 513 | EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); |
| 514 | } |
| 515 | |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 516 | TEST_F(ExtendedDesktopTest, MoveWindowWithTransient) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 517 | UpdateDisplay("1000x600,600x400"); |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 518 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 519 | views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
| 520 | views::Widget* w1_t1 = CreateTestWidgetWithParent( |
| 521 | w1, gfx::Rect(50, 50, 50, 50), false /* transient */); |
| 522 | // Transient child of the transient child. |
| 523 | views::Widget* w1_t11 = CreateTestWidgetWithParent( |
| 524 | w1_t1, gfx::Rect(1200, 70, 30, 30), false /* transient */); |
| 525 | |
| 526 | views::Widget* w11 = CreateTestWidgetWithParent( |
| 527 | w1, gfx::Rect(10, 10, 40, 40), true /* child */); |
| 528 | views::Widget* w11_t1 = CreateTestWidgetWithParent( |
| 529 | w1, gfx::Rect(1300, 100, 80, 80), false /* transient */); |
| 530 | |
| 531 | EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow()); |
| 532 | EXPECT_EQ(root_windows[0], w11->GetNativeView()->GetRootWindow()); |
| 533 | EXPECT_EQ(root_windows[0], w1_t1->GetNativeView()->GetRootWindow()); |
| 534 | EXPECT_EQ(root_windows[0], w1_t11->GetNativeView()->GetRootWindow()); |
| 535 | EXPECT_EQ(root_windows[0], w11_t1->GetNativeView()->GetRootWindow()); |
| 536 | EXPECT_EQ("50,50 50x50", |
| 537 | w1_t1->GetWindowBoundsInScreen().ToString()); |
| 538 | EXPECT_EQ("1200,70 30x30", |
| 539 | w1_t11->GetWindowBoundsInScreen().ToString()); |
| 540 | EXPECT_EQ("20,20 40x40", |
| 541 | w11->GetWindowBoundsInScreen().ToString()); |
| 542 | EXPECT_EQ("1300,100 80x80", |
| 543 | w11_t1->GetWindowBoundsInScreen().ToString()); |
| 544 | |
| 545 | w1->SetBounds(gfx::Rect(1100,10,100,100)); |
| 546 | |
| 547 | EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow()); |
| 548 | EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow()); |
| 549 | EXPECT_EQ(root_windows[1], w1_t11->GetNativeView()->GetRootWindow()); |
| 550 | EXPECT_EQ(root_windows[1], w11->GetNativeView()->GetRootWindow()); |
| 551 | EXPECT_EQ(root_windows[1], w11_t1->GetNativeView()->GetRootWindow()); |
| 552 | |
| 553 | EXPECT_EQ("1110,20 40x40", |
| 554 | w11->GetWindowBoundsInScreen().ToString()); |
| 555 | // Transient window's screen bounds stays the same. |
| 556 | EXPECT_EQ("50,50 50x50", |
| 557 | w1_t1->GetWindowBoundsInScreen().ToString()); |
| 558 | EXPECT_EQ("1200,70 30x30", |
| 559 | w1_t11->GetWindowBoundsInScreen().ToString()); |
| 560 | EXPECT_EQ("1300,100 80x80", |
| 561 | w11_t1->GetWindowBoundsInScreen().ToString()); |
| 562 | |
| 563 | // Transient window doesn't move between root window unless |
| 564 | // its transient parent moves. |
| 565 | w1_t1->SetBounds(gfx::Rect(10, 50, 50, 50)); |
| 566 | EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow()); |
| 567 | EXPECT_EQ("10,50 50x50", |
| 568 | w1_t1->GetWindowBoundsInScreen().ToString()); |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 569 | } |
| 570 | |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 571 | namespace internal { |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 572 | // Test if the Window::ConvertPointToTarget works across root windows. |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 573 | // TODO(oshima): Move multiple display suport and this test to aura. |
| 574 | TEST_F(ExtendedDesktopTest, ConvertPoint) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 575 | UpdateDisplay("1000x600,600x400"); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 576 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 577 | gfx::Display& display_1 = |
[email protected] | 3e4351b | 2012-08-09 04:04:16 | [diff] [blame] | 578 | GetDisplayManager()->FindDisplayForRootWindow(root_windows[0]); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 579 | EXPECT_EQ("0,0", display_1.bounds().origin().ToString()); |
| 580 | gfx::Display& display_2 = |
[email protected] | 3e4351b | 2012-08-09 04:04:16 | [diff] [blame] | 581 | GetDisplayManager()->FindDisplayForRootWindow(root_windows[1]); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 582 | EXPECT_EQ("1000,0", display_2.bounds().origin().ToString()); |
| 583 | |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 584 | aura::Window* d1 = |
| 585 | CreateTestWidget(gfx::Rect(10, 10, 100, 100))->GetNativeView(); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 586 | aura::Window* d2 = |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 587 | CreateTestWidget(gfx::Rect(1020, 20, 100, 100))->GetNativeView(); |
| 588 | EXPECT_EQ(root_windows[0], d1->GetRootWindow()); |
| 589 | EXPECT_EQ(root_windows[1], d2->GetRootWindow()); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 590 | |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 591 | // Convert point in the Root2's window to the Root1's window Coord. |
| 592 | gfx::Point p(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 593 | aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 594 | EXPECT_EQ("1000,0", p.ToString()); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 595 | p.SetPoint(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 596 | aura::Window::ConvertPointToTarget(d2, d1, &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 597 | EXPECT_EQ("1010,10", p.ToString()); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 598 | |
| 599 | // Convert point in the Root1's window to the Root2's window Coord. |
| 600 | p.SetPoint(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 601 | aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 602 | EXPECT_EQ("-1000,0", p.ToString()); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 603 | p.SetPoint(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 604 | aura::Window::ConvertPointToTarget(d1, d2, &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 605 | EXPECT_EQ("-1010,-10", p.ToString()); |
| 606 | |
| 607 | // Move the 2nd display to the bottom and test again. |
[email protected] | edbfb8d | 2012-09-03 08:33:43 | [diff] [blame] | 608 | SetSecondaryDisplayLayout(DisplayLayout::BOTTOM); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 609 | |
[email protected] | 3e4351b | 2012-08-09 04:04:16 | [diff] [blame] | 610 | display_2 = GetDisplayManager()->FindDisplayForRootWindow(root_windows[1]); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 611 | EXPECT_EQ("0,600", display_2.bounds().origin().ToString()); |
| 612 | |
| 613 | // Convert point in Root2's window to Root1's window Coord. |
| 614 | p.SetPoint(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 615 | aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 616 | EXPECT_EQ("0,600", p.ToString()); |
| 617 | p.SetPoint(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 618 | aura::Window::ConvertPointToTarget(d2, d1, &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 619 | EXPECT_EQ("10,610", p.ToString()); |
| 620 | |
| 621 | // Convert point in Root1's window to Root2's window Coord. |
| 622 | p.SetPoint(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 623 | aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 624 | EXPECT_EQ("0,-600", p.ToString()); |
| 625 | p.SetPoint(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 626 | aura::Window::ConvertPointToTarget(d1, d2, &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 627 | EXPECT_EQ("-10,-610", p.ToString()); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 628 | } |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 629 | |
[email protected] | 263898a | 2012-09-17 17:20:07 | [diff] [blame] | 630 | TEST_F(ExtendedDesktopTest, OpenSystemTray) { |
[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) { |
| 662 | UpdateDisplay("100x100,200x200"); |
| 663 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 664 | views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 50, 50)); |
[email protected] | 57804851 | 2012-09-19 20:01:24 | [diff] [blame] | 665 | EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow()); |
| 666 | w1->SetBounds(gfx::Rect(150, 10, 50, 50)); |
| 667 | EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow()); |
| 668 | |
| 669 | // The widget stays in the same root if kStayInSameRootWindowKey is set to |
| 670 | // true. |
| 671 | w1->GetNativeView()->SetProperty(internal::kStayInSameRootWindowKey, true); |
| 672 | w1->SetBounds(gfx::Rect(10, 10, 50, 50)); |
| 673 | EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow()); |
| 674 | |
| 675 | // The widget should now move to the 1st root window without the property. |
| 676 | w1->GetNativeView()->ClearProperty(internal::kStayInSameRootWindowKey); |
| 677 | w1->SetBounds(gfx::Rect(10, 10, 50, 50)); |
| 678 | EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow()); |
| 679 | } |
| 680 | |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 681 | TEST_F(ExtendedDesktopTest, KeyEventsOnLockScreen) { |
| 682 | UpdateDisplay("100x100,200x200"); |
| 683 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 684 | |
| 685 | // Create normal windows on both displays. |
| 686 | views::Widget* widget1 = CreateTestWidget( |
[email protected] | ffabb1e | 2012-10-12 19:51:17 | [diff] [blame] | 687 | Shell::GetScreen()->GetPrimaryDisplay().bounds()); |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 688 | widget1->Show(); |
| 689 | EXPECT_EQ(root_windows[0], widget1->GetNativeView()->GetRootWindow()); |
| 690 | views::Widget* widget2 = CreateTestWidget( |
| 691 | ScreenAsh::GetSecondaryDisplay().bounds()); |
| 692 | widget2->Show(); |
| 693 | EXPECT_EQ(root_windows[1], widget2->GetNativeView()->GetRootWindow()); |
| 694 | |
| 695 | // Create a LockScreen window. |
| 696 | views::Widget* lock_widget = CreateTestWidget( |
[email protected] | ffabb1e | 2012-10-12 19:51:17 | [diff] [blame] | 697 | Shell::GetScreen()->GetPrimaryDisplay().bounds()); |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 698 | views::Textfield* textfield = new views::Textfield; |
[email protected] | 0914895 | 2013-03-13 13:25:43 | [diff] [blame] | 699 | lock_widget->client_view()->AddChildView(textfield); |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 700 | |
| 701 | ash::Shell::GetContainer( |
| 702 | Shell::GetPrimaryRootWindow(), |
| 703 | ash::internal::kShellWindowId_LockScreenContainer)-> |
| 704 | AddChild(lock_widget->GetNativeView()); |
| 705 | lock_widget->Show(); |
| 706 | textfield->RequestFocus(); |
| 707 | |
[email protected] | 8cfb672 | 2012-11-28 03:28:46 | [diff] [blame] | 708 | aura::client::FocusClient* focus_client = |
| 709 | aura::client::GetFocusClient(root_windows[0]); |
| 710 | EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow()); |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 711 | |
| 712 | // The lock window should get events on both root windows. |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 713 | aura::test::EventGenerator& event_generator(GetEventGenerator()); |
| 714 | |
| 715 | event_generator.set_current_root_window(root_windows[0]); |
| 716 | event_generator.PressKey(ui::VKEY_A, 0); |
| 717 | event_generator.ReleaseKey(ui::VKEY_A, 0); |
[email protected] | 8cfb672 | 2012-11-28 03:28:46 | [diff] [blame] | 718 | EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow()); |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 719 | EXPECT_EQ("a", UTF16ToASCII(textfield->text())); |
| 720 | |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 721 | event_generator.set_current_root_window(root_windows[1]); |
| 722 | event_generator.PressKey(ui::VKEY_B, 0); |
| 723 | event_generator.ReleaseKey(ui::VKEY_B, 0); |
[email protected] | 8cfb672 | 2012-11-28 03:28:46 | [diff] [blame] | 724 | EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow()); |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 725 | EXPECT_EQ("ab", UTF16ToASCII(textfield->text())); |
| 726 | |
| 727 | // Deleting 2nd display. The lock window still should get the events. |
| 728 | UpdateDisplay("100x100"); |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 729 | event_generator.PressKey(ui::VKEY_C, 0); |
| 730 | event_generator.ReleaseKey(ui::VKEY_C, 0); |
[email protected] | 8cfb672 | 2012-11-28 03:28:46 | [diff] [blame] | 731 | EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow()); |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 732 | EXPECT_EQ("abc", UTF16ToASCII(textfield->text())); |
| 733 | |
| 734 | // Creating 2nd display again, and lock window still should get events |
| 735 | // on both root windows. |
| 736 | UpdateDisplay("100x100,200x200"); |
| 737 | root_windows = Shell::GetAllRootWindows(); |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 738 | event_generator.set_current_root_window(root_windows[0]); |
| 739 | event_generator.PressKey(ui::VKEY_D, 0); |
| 740 | event_generator.ReleaseKey(ui::VKEY_D, 0); |
[email protected] | 8cfb672 | 2012-11-28 03:28:46 | [diff] [blame] | 741 | EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow()); |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 742 | EXPECT_EQ("abcd", UTF16ToASCII(textfield->text())); |
| 743 | |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 744 | event_generator.set_current_root_window(root_windows[1]); |
| 745 | event_generator.PressKey(ui::VKEY_E, 0); |
| 746 | event_generator.ReleaseKey(ui::VKEY_E, 0); |
[email protected] | 8cfb672 | 2012-11-28 03:28:46 | [diff] [blame] | 747 | EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow()); |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 748 | EXPECT_EQ("abcde", UTF16ToASCII(textfield->text())); |
| 749 | } |
| 750 | |
[email protected] | 334e618 | 2013-01-11 18:35:41 | [diff] [blame] | 751 | TEST_F(ExtendedDesktopTest, PassiveGrab) { |
| 752 | EventLocationRecordingEventHandler event_handler; |
| 753 | ash::Shell::GetInstance()->AddPreTargetHandler(&event_handler); |
| 754 | |
| 755 | UpdateDisplay("300x300,200x200"); |
| 756 | |
| 757 | views::Widget* widget = CreateTestWidget(gfx::Rect(50, 50, 200, 200)); |
| 758 | widget->Show(); |
| 759 | ASSERT_EQ("50,50 200x200", widget->GetWindowBoundsInScreen().ToString()); |
| 760 | |
| 761 | aura::test::EventGenerator& generator(GetEventGenerator()); |
| 762 | generator.MoveMouseTo(150, 150); |
| 763 | EXPECT_EQ("100,100 150,150", event_handler.GetLocationsAndReset()); |
| 764 | |
| 765 | generator.PressLeftButton(); |
| 766 | generator.MoveMouseTo(400, 150); |
| 767 | |
| 768 | EXPECT_EQ("350,100 400,150", event_handler.GetLocationsAndReset()); |
| 769 | |
| 770 | generator.ReleaseLeftButton(); |
| 771 | EXPECT_EQ("-999,-999 -999,-999", event_handler.GetLocationsAndReset()); |
| 772 | |
| 773 | generator.MoveMouseTo(400, 150); |
| 774 | EXPECT_EQ("100,150 100,150", event_handler.GetLocationsAndReset()); |
| 775 | |
| 776 | ash::Shell::GetInstance()->RemovePreTargetHandler(&event_handler); |
| 777 | } |
| 778 | |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 779 | } // namespace internal |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 780 | } // namespace ash |