blob: c1ce9306d8b96f427eb98036ef429b2c8224aa22 [file] [log] [blame]
[email protected]c39be8f2012-06-15 22:58:361// 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]2e236a52012-06-27 22:21:475#include "ash/display/display_controller.h"
[email protected]6bdf7952012-11-14 10:10:586#include "ash/display/display_manager.h"
[email protected]e887c6c2013-07-08 19:35:537#include "ash/root_window_controller.h"
[email protected]55ad8c12014-01-17 18:24:338#include "ash/screen_util.h"
[email protected]c39be8f2012-06-15 22:58:369#include "ash/shell.h"
[email protected]e67291f12012-10-10 05:52:3810#include "ash/shell_window_ids.h"
[email protected]263898a2012-09-17 17:20:0711#include "ash/system/tray/system_tray.h"
[email protected]c39be8f2012-06-15 22:58:3612#include "ash/test/ash_test_base.h"
[email protected]7203a5e2012-08-06 18:27:4613#include "ash/wm/coordinate_conversion.h"
[email protected]578048512012-09-19 20:01:2414#include "ash/wm/window_properties.h"
[email protected]c39be8f2012-06-15 22:58:3615#include "ash/wm/window_util.h"
[email protected]0836da02013-06-10 19:33:3516#include "base/strings/string_util.h"
[email protected]74f778e2014-03-14 21:11:4617#include "base/strings/utf_string_conversions.h"
[email protected]c39be8f2012-06-15 22:58:3618#include "ui/aura/client/capture_client.h"
[email protected]8cfb6722012-11-28 03:28:4619#include "ui/aura/client/focus_client.h"
[email protected]c39be8f2012-06-15 22:58:3620#include "ui/aura/test/event_generator.h"
[email protected]a5e71c92012-06-22 22:09:0821#include "ui/aura/test/test_windows.h"
[email protected]553eae12013-02-01 02:33:5222#include "ui/aura/test/window_test_api.h"
[email protected]c39be8f2012-06-15 22:58:3623#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:2624#include "ui/aura/window_event_dispatcher.h"
[email protected]c39be8f2012-06-15 22:58:3625#include "ui/base/cursor/cursor.h"
[email protected]86ccbd42013-09-18 18:11:5426#include "ui/events/event_handler.h"
[email protected]a5e71c92012-06-22 22:09:0827#include "ui/gfx/display.h"
[email protected]718b26c2012-07-24 20:53:2328#include "ui/gfx/screen.h"
[email protected]e67291f12012-10-10 05:52:3829#include "ui/views/controls/textfield/textfield.h"
[email protected]c39be8f2012-06-15 22:58:3630#include "ui/views/widget/widget.h"
31#include "ui/views/widget/widget_delegate.h"
[email protected]af4552b22014-03-21 19:45:0132#include "ui/wm/public/activation_client.h"
[email protected]c39be8f2012-06-15 22:58:3633
34namespace ash {
35namespace {
36
[email protected]edbfb8d2012-09-03 08:33:4337void SetSecondaryDisplayLayout(DisplayLayout::Position position) {
[email protected]4bfb3722013-08-14 10:47:2938 DisplayLayout layout =
39 Shell::GetInstance()->display_manager()->GetCurrentDisplayLayout();
[email protected]edbfb8d2012-09-03 08:33:4340 layout.position = position;
[email protected]efbc0502013-10-16 22:24:1541 Shell::GetInstance()->display_manager()->
[email protected]4bfb3722013-08-14 10:47:2942 SetLayoutForCurrentDisplays(layout);
[email protected]edbfb8d2012-09-03 08:33:4343}
44
[email protected]c39be8f2012-06-15 22:58:3645class 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]334e6182013-01-11 18:35:4162// An event handler which moves the target window to the secondary root window
[email protected]2e98aaf72012-11-08 06:30:5963// at pre-handle phase of a mouse release event.
[email protected]334e6182013-01-11 18:35:4164class MoveWindowByClickEventHandler : public ui::EventHandler {
[email protected]2e98aaf72012-11-08 06:30:5965 public:
[email protected]334e6182013-01-11 18:35:4166 explicit MoveWindowByClickEventHandler(aura::Window* target)
[email protected]2e98aaf72012-11-08 06:30:5967 : target_(target) {}
[email protected]334e6182013-01-11 18:35:4168 virtual ~MoveWindowByClickEventHandler() {}
[email protected]2e98aaf72012-11-08 06:30:5969
70 private:
71 // ui::EventHandler overrides:
[email protected]d44efe02012-12-18 06:08:1872 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
[email protected]2e98aaf72012-11-08 06:30:5973 if (event->type() == ui::ET_MOUSE_RELEASED) {
[email protected]c9390bd2013-11-08 20:33:1374 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]2e98aaf72012-11-08 06:30:5975 DCHECK_LT(1u, root_windows.size());
76 root_windows[1]->AddChild(target_);
77 }
[email protected]2e98aaf72012-11-08 06:30:5978 }
79
[email protected]2e98aaf72012-11-08 06:30:5980 aura::Window* target_;
[email protected]334e6182013-01-11 18:35:4181 DISALLOW_COPY_AND_ASSIGN(MoveWindowByClickEventHandler);
82};
83
84// An event handler which records the event's locations.
85class EventLocationRecordingEventHandler : public ui::EventHandler {
86 public:
87 explicit EventLocationRecordingEventHandler() {
88 reset();
89 }
90 virtual ~EventLocationRecordingEventHandler() {}
91
92 std::string GetLocationsAndReset() {
93 std::string result =
94 location_.ToString() + " " + root_location_.ToString();
95 reset();
96 return result;
97 }
98
99 private:
100 // ui::EventHandler overrides:
101 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
102 if (event->type() == ui::ET_MOUSE_MOVED ||
103 event->type() == ui::ET_MOUSE_DRAGGED) {
104 location_ = event->location();
105 root_location_ = event->root_location();
106 }
107 }
108
109 void reset() {
110 location_.SetPoint(-999, -999);
111 root_location_.SetPoint(-999, -999);
112 }
113
114 gfx::Point root_location_;
115 gfx::Point location_;
116
117 DISALLOW_COPY_AND_ASSIGN(EventLocationRecordingEventHandler);
[email protected]2e98aaf72012-11-08 06:30:59118};
119
[email protected]2ca75942014-07-12 04:46:37120class EventLocationHandler : public ui::EventHandler {
121 public:
122 EventLocationHandler() {}
123 virtual ~EventLocationHandler() {}
124
125 const gfx::Point& press_location() const { return press_location_; }
126 const gfx::Point& release_location() const { return release_location_; }
127
128 private:
129 // ui::EventHandler:
130 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
131 if (event->type() == ui::ET_MOUSE_PRESSED)
132 press_location_ = event->location();
133 else if (event->type() == ui::ET_MOUSE_RELEASED)
134 release_location_ = event->location();
135 }
136
137 gfx::Point press_location_;
138 gfx::Point release_location_;
139
140 DISALLOW_COPY_AND_ASSIGN(EventLocationHandler);
141};
142
[email protected]c39be8f2012-06-15 22:58:36143} // namespace
144
[email protected]a2e6af12013-01-07 21:40:35145class ExtendedDesktopTest : public test::AshTestBase {
146 public:
147 views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
148 return CreateTestWidgetWithParentAndContext(
149 NULL, CurrentContext(), bounds, false);
150 }
151
152 views::Widget* CreateTestWidgetWithParent(views::Widget* parent,
153 const gfx::Rect& bounds,
154 bool child) {
155 CHECK(parent);
156 return CreateTestWidgetWithParentAndContext(parent, NULL, bounds, child);
157 }
158
159 views::Widget* CreateTestWidgetWithParentAndContext(views::Widget* parent,
160 gfx::NativeView context,
161 const gfx::Rect& bounds,
162 bool child) {
163 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
164 if (parent)
165 params.parent = parent->GetNativeView();
166 params.context = context;
167 params.bounds = bounds;
168 params.child = child;
169 views::Widget* widget = new views::Widget;
170 widget->Init(params);
171 widget->Show();
172 return widget;
173 }
174};
[email protected]c39be8f2012-06-15 22:58:36175
176// Test conditions that root windows in extended desktop mode
177// must satisfy.
178TEST_F(ExtendedDesktopTest, Basic) {
[email protected]e75642a2013-06-12 17:21:18179 if (!SupportsMultipleDisplays())
180 return;
181
[email protected]f634dd32012-07-23 22:49:07182 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13183 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36184
185 // All root windows must have the root window controller.
186 ASSERT_EQ(2U, root_windows.size());
[email protected]c9390bd2013-11-08 20:33:13187 for (aura::Window::Windows::const_iterator iter = root_windows.begin();
[email protected]c39be8f2012-06-15 22:58:36188 iter != root_windows.end(); ++iter) {
[email protected]093b8d642014-04-03 20:59:28189 EXPECT_TRUE(GetRootWindowController(*iter) != NULL);
[email protected]c39be8f2012-06-15 22:58:36190 }
191 // Make sure root windows share the same controllers.
[email protected]8cfb6722012-11-28 03:28:46192 EXPECT_EQ(aura::client::GetFocusClient(root_windows[0]),
193 aura::client::GetFocusClient(root_windows[1]));
[email protected]c39be8f2012-06-15 22:58:36194 EXPECT_EQ(aura::client::GetActivationClient(root_windows[0]),
195 aura::client::GetActivationClient(root_windows[1]));
196 EXPECT_EQ(aura::client::GetCaptureClient(root_windows[0]),
197 aura::client::GetCaptureClient(root_windows[1]));
198}
199
200TEST_F(ExtendedDesktopTest, Activation) {
[email protected]e75642a2013-06-12 17:21:18201 if (!SupportsMultipleDisplays())
202 return;
203
[email protected]f634dd32012-07-23 22:49:07204 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13205 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36206
[email protected]c39be8f2012-06-15 22:58:36207 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]f634dd32012-07-23 22:49:07208 views::Widget* widget_on_2nd =
209 CreateTestWidget(gfx::Rect(1200, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36210 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
[email protected]f634dd32012-07-23 22:49:07211 EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36212
213 EXPECT_EQ(widget_on_2nd->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46214 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]c39be8f2012-06-15 22:58:36215 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
216
[email protected]334e6182013-01-11 18:35:41217 aura::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]f634dd32012-07-23 22:49:07218 // Clicking a window changes the active window and active root window.
[email protected]334e6182013-01-11 18:35:41219 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
220 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36221
222 EXPECT_EQ(widget_on_1st->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46223 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]c39be8f2012-06-15 22:58:36224 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]f634dd32012-07-23 22:49:07225
[email protected]334e6182013-01-11 18:35:41226 event_generator.MoveMouseToCenterOf(widget_on_2nd->GetNativeView());
227 event_generator.ClickLeftButton();
[email protected]f634dd32012-07-23 22:49:07228
229 EXPECT_EQ(widget_on_2nd->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46230 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]f634dd32012-07-23 22:49:07231 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
[email protected]c39be8f2012-06-15 22:58:36232}
233
234TEST_F(ExtendedDesktopTest, SystemModal) {
[email protected]e75642a2013-06-12 17:21:18235 if (!SupportsMultipleDisplays())
236 return;
237
[email protected]f634dd32012-07-23 22:49:07238 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13239 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36240
241 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36242 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]492533b32012-09-21 19:06:14243 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
[email protected]d17642d2013-09-12 23:44:38244 EXPECT_EQ(root_windows[0], Shell::GetTargetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36245
[email protected]c39be8f2012-06-15 22:58:36246 // Open system modal. Make sure it's on 2nd root window and active.
[email protected]a2e6af12013-01-07 21:40:35247 views::Widget* modal_widget = views::Widget::CreateWindowWithContextAndBounds(
248 new ModalWidgetDelegate(),
249 CurrentContext(),
250 gfx::Rect(1200, 100, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36251 modal_widget->Show();
252 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
253 EXPECT_EQ(root_windows[1], modal_widget->GetNativeView()->GetRootWindow());
[email protected]d17642d2013-09-12 23:44:38254 EXPECT_EQ(root_windows[1], Shell::GetTargetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36255
[email protected]334e6182013-01-11 18:35:41256 aura::test::EventGenerator& event_generator(GetEventGenerator());
257
[email protected]2e236a52012-06-27 22:21:47258 // Clicking a widget on widget_on_1st display should not change activation.
[email protected]334e6182013-01-11 18:35:41259 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
260 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36261 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
[email protected]d17642d2013-09-12 23:44:38262 EXPECT_EQ(root_windows[1], Shell::GetTargetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36263
264 // Close system modal and so clicking a widget should work now.
265 modal_widget->Close();
[email protected]334e6182013-01-11 18:35:41266 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
267 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36268 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]d17642d2013-09-12 23:44:38269 EXPECT_EQ(root_windows[0], Shell::GetTargetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36270}
271
272TEST_F(ExtendedDesktopTest, TestCursor) {
[email protected]e75642a2013-06-12 17:21:18273 if (!SupportsMultipleDisplays())
274 return;
275
[email protected]f634dd32012-07-23 22:49:07276 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13277 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]2374d1812014-03-04 03:42:27278 aura::WindowTreeHost* host0 = root_windows[0]->GetHost();
279 aura::WindowTreeHost* host1 = root_windows[1]->GetHost();
280 EXPECT_EQ(ui::kCursorPointer, host0->last_cursor().native_type());
281 EXPECT_EQ(ui::kCursorPointer, host1->last_cursor().native_type());
[email protected]151ffdff2012-09-11 20:18:35282 Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorCopy);
[email protected]2374d1812014-03-04 03:42:27283 EXPECT_EQ(ui::kCursorCopy, host0->last_cursor().native_type());
284 EXPECT_EQ(ui::kCursorCopy, host1->last_cursor().native_type());
[email protected]c39be8f2012-06-15 22:58:36285}
286
[email protected]718b26c2012-07-24 20:53:23287TEST_F(ExtendedDesktopTest, TestCursorLocation) {
[email protected]e75642a2013-06-12 17:21:18288 if (!SupportsMultipleDisplays())
289 return;
290
[email protected]d0064722013-03-14 18:16:43291 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13292 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]553eae12013-02-01 02:33:52293 aura::test::WindowTestApi root_window0_test_api(root_windows[0]);
294 aura::test::WindowTestApi root_window1_test_api(root_windows[1]);
[email protected]718b26c2012-07-24 20:53:23295
296 root_windows[0]->MoveCursorTo(gfx::Point(10, 10));
[email protected]ffabb1e2012-10-12 19:51:17297 EXPECT_EQ("10,10", Shell::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23298 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
299 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
300 root_windows[1]->MoveCursorTo(gfx::Point(10, 20));
[email protected]ffabb1e2012-10-12 19:51:17301 EXPECT_EQ("1010,20", Shell::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23302 EXPECT_FALSE(root_window0_test_api.ContainsMouse());
303 EXPECT_TRUE(root_window1_test_api.ContainsMouse());
304 root_windows[0]->MoveCursorTo(gfx::Point(20, 10));
[email protected]ffabb1e2012-10-12 19:51:17305 EXPECT_EQ("20,10", Shell::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23306 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
307 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
308}
309
[email protected]20c59762012-06-23 01:10:24310TEST_F(ExtendedDesktopTest, GetRootWindowAt) {
[email protected]e75642a2013-06-12 17:21:18311 if (!SupportsMultipleDisplays())
312 return;
313
[email protected]f634dd32012-07-23 22:49:07314 UpdateDisplay("700x500,500x500");
[email protected]edbfb8d2012-09-03 08:33:43315 SetSecondaryDisplayLayout(DisplayLayout::LEFT);
[email protected]c9390bd2013-11-08 20:33:13316 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24317
[email protected]7203a5e2012-08-06 18:27:46318 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-400, 100)));
319 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-1, 100)));
320 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 300)));
321 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(700,300)));
[email protected]20c59762012-06-23 01:10:24322
323 // Zero origin.
[email protected]7203a5e2012-08-06 18:27:46324 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 0)));
[email protected]20c59762012-06-23 01:10:24325
[email protected]36168852014-01-07 12:23:28326 // Out of range point should return the nearest root window
327 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-600, 0)));
[email protected]7203a5e2012-08-06 18:27:46328 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(701, 100)));
[email protected]20c59762012-06-23 01:10:24329}
330
331TEST_F(ExtendedDesktopTest, GetRootWindowMatching) {
[email protected]e75642a2013-06-12 17:21:18332 if (!SupportsMultipleDisplays())
333 return;
334
[email protected]f634dd32012-07-23 22:49:07335 UpdateDisplay("700x500,500x500");
[email protected]edbfb8d2012-09-03 08:33:43336 SetSecondaryDisplayLayout(DisplayLayout::LEFT);
[email protected]66b05eac2012-06-27 23:53:10337
[email protected]c9390bd2013-11-08 20:33:13338 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24339
340 // Containing rect.
341 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46342 wm::GetRootWindowMatching(gfx::Rect(-300, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24343 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46344 wm::GetRootWindowMatching(gfx::Rect(100, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24345
346 // Intersecting rect.
347 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46348 wm::GetRootWindowMatching(gfx::Rect(-200, 0, 300, 300)));
[email protected]20c59762012-06-23 01:10:24349 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46350 wm::GetRootWindowMatching(gfx::Rect(-100, 0, 300, 300)));
[email protected]20c59762012-06-23 01:10:24351
352 // Zero origin.
[email protected]66b05eac2012-06-27 23:53:10353 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46354 wm::GetRootWindowMatching(gfx::Rect(0, 0, 0, 0)));
[email protected]66b05eac2012-06-27 23:53:10355 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46356 wm::GetRootWindowMatching(gfx::Rect(0, 0, 1, 1)));
[email protected]20c59762012-06-23 01:10:24357
358 // Empty rect.
359 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46360 wm::GetRootWindowMatching(gfx::Rect(-400, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24361 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46362 wm::GetRootWindowMatching(gfx::Rect(100, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24363
364 // Out of range rect should return the primary root window.
365 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46366 wm::GetRootWindowMatching(gfx::Rect(-600, -300, 50, 50)));
[email protected]20c59762012-06-23 01:10:24367 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46368 wm::GetRootWindowMatching(gfx::Rect(0, 1000, 50, 50)));
[email protected]0f81f442012-06-22 06:20:27369}
370
[email protected]1a015382012-12-01 19:44:59371TEST_F(ExtendedDesktopTest, Capture) {
[email protected]e75642a2013-06-12 17:21:18372 if (!SupportsMultipleDisplays())
373 return;
374
[email protected]f634dd32012-07-23 22:49:07375 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13376 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]a5e71c92012-06-22 22:09:08377
378 aura::test::EventCountDelegate r1_d1;
379 aura::test::EventCountDelegate r1_d2;
380 aura::test::EventCountDelegate r2_d1;
381
382 scoped_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
383 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
384 scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
385 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
386 scoped_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
387 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
[email protected]f634dd32012-07-23 22:49:07388
[email protected]a5e71c92012-06-22 22:09:08389 r1_w1->SetCapture();
390
391 EXPECT_EQ(r1_w1.get(),
392 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]334e6182013-01-11 18:35:41393
[email protected]d05cf2f2014-02-26 05:31:43394 aura::test::EventGenerator& generator = GetEventGenerator();
395 generator.MoveMouseToCenterOf(r2_w1.get());
396 // |r1_w1| will receive the events because it has capture.
397 EXPECT_EQ("1 1 0", r1_d1.GetMouseMotionCountsAndReset());
398 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
399 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
400
401 generator.ClickLeftButton();
[email protected]a5e71c92012-06-22 22:09:08402 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
403 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
[email protected]b19ba4adf2012-09-07 16:13:29404 // The mouse is outside. On chromeos, the mouse is warped to the
405 // dest root window, but it's not implemented on Win yet, so
406 // no mouse move event on Win.
[email protected]d05cf2f2014-02-26 05:31:43407 EXPECT_EQ("0 0 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08408 EXPECT_EQ("1 1", r1_d1.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43409
410 generator.MoveMouseTo(15, 15);
[email protected]f634dd32012-07-23 22:49:07411 EXPECT_EQ("0 1 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43412 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08413
414 r1_w2->SetCapture();
415 EXPECT_EQ(r1_w2.get(),
416 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]d05cf2f2014-02-26 05:31:43417 generator.MoveMouseBy(10, 10);
418 // |r1_w2| has the capture. So it will receive the mouse-move event.
419 EXPECT_EQ("0 0 0", r1_d1.GetMouseMotionCountsAndReset());
420 EXPECT_EQ("0 1 0", r1_d2.GetMouseMotionCountsAndReset());
421 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
422
423 generator.ClickLeftButton();
[email protected]a5e71c92012-06-22 22:09:08424 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
425 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43426 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08427 EXPECT_EQ("1 1", r1_d2.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43428
[email protected]a5e71c92012-06-22 22:09:08429 r1_w2->ReleaseCapture();
[email protected]36f566532012-09-19 04:07:24430 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]d05cf2f2014-02-26 05:31:43431
432 generator.MoveMouseToCenterOf(r2_w1.get());
433 generator.ClickLeftButton();
[email protected]a5e71c92012-06-22 22:09:08434 EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset());
435 EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset());
436 // Make sure the mouse_moved_handler_ is properly reset.
437 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
438 EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset());
439}
440
[email protected]2ca75942014-07-12 04:46:37441TEST_F(ExtendedDesktopTest, CaptureEventLocation) {
442 if (!SupportsMultipleDisplays())
443 return;
444
445 UpdateDisplay("1000x600,600x400");
446 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
447
448 aura::test::EventCountDelegate r1_d1;
449 aura::test::EventCountDelegate r1_d2;
450 aura::test::EventCountDelegate r2_d1;
451
452 scoped_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
453 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
454 scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
455 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
456 scoped_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
457 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
458
459 r1_w1->SetCapture();
460
461 aura::test::EventGenerator& generator = GetEventGenerator();
462 generator.MoveMouseToCenterOf(r2_w1.get());
463 EXPECT_EQ(gfx::Point(1060, 60).ToString(),
464 generator.current_location().ToString());
465
466 EventLocationHandler location_handler;
467 r1_w1->AddPreTargetHandler(&location_handler);
468 generator.ClickLeftButton();
469 r1_w1->RemovePreTargetHandler(&location_handler);
470 EXPECT_EQ(gfx::Point(1050, 50).ToString(),
471 location_handler.press_location().ToString());
472 EXPECT_EQ(gfx::Point(1050, 50).ToString(),
473 location_handler.release_location().ToString());
474}
475
476TEST_F(ExtendedDesktopTest, CaptureEventLocationHighDPI) {
477 if (!SupportsMultipleDisplays())
478 return;
479
480 UpdateDisplay("1000x600*2,600x400");
481 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
482
483 aura::test::EventCountDelegate r1_d1;
484 aura::test::EventCountDelegate r1_d2;
485 aura::test::EventCountDelegate r2_d1;
486
487 scoped_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
488 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
489 scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
490 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
491 scoped_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
492 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
493
494 r1_w1->SetCapture();
495
496 aura::test::EventGenerator& generator = GetEventGenerator();
497 generator.MoveMouseToCenterOf(r2_w1.get());
498 EXPECT_EQ(gfx::Point(560, 60).ToString(),
499 generator.current_location().ToString());
500
501 EventLocationHandler location_handler;
502 r1_w1->AddPreTargetHandler(&location_handler);
503 generator.ClickLeftButton();
504 r1_w1->RemovePreTargetHandler(&location_handler);
505 EXPECT_EQ(gfx::Point(550, 50).ToString(),
506 location_handler.press_location().ToString());
507 EXPECT_EQ(gfx::Point(550, 50).ToString(),
508 location_handler.release_location().ToString());
509}
510
511TEST_F(ExtendedDesktopTest, CaptureEventLocationHighDPI_2) {
512 if (!SupportsMultipleDisplays())
513 return;
514
515 UpdateDisplay("1000x600,600x400*2");
516 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
517
518 aura::test::EventCountDelegate r1_d1;
519 aura::test::EventCountDelegate r1_d2;
520 aura::test::EventCountDelegate r2_d1;
521
522 scoped_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
523 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
524 scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
525 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
526 scoped_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
527 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
528
529 r1_w1->SetCapture();
530
531 aura::test::EventGenerator& generator = GetEventGenerator();
532 generator.MoveMouseToCenterOf(r2_w1.get());
533 EXPECT_EQ(gfx::Point(1060, 60).ToString(),
534 generator.current_location().ToString());
535
536 EventLocationHandler location_handler;
537 r1_w1->AddPreTargetHandler(&location_handler);
538 generator.ClickLeftButton();
539 r1_w1->RemovePreTargetHandler(&location_handler);
540 // Event-generator dispatches the event in the primary root-window's coord
541 // space. Since the location is (1060, 60), it goes to the secondary
542 // root-window as (30, 30) since the secondary root-window has a device scale
543 // factor of 2.
544 EXPECT_EQ(gfx::Point(1020, 20).ToString(),
545 location_handler.press_location().ToString());
546 EXPECT_EQ(gfx::Point(1020, 20).ToString(),
547 location_handler.release_location().ToString());
548}
549
[email protected]f059c6942012-07-21 14:27:57550TEST_F(ExtendedDesktopTest, MoveWindow) {
[email protected]e75642a2013-06-12 17:21:18551 if (!SupportsMultipleDisplays())
552 return;
553
[email protected]f634dd32012-07-23 22:49:07554 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13555 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]f059c6942012-07-21 14:27:57556 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
557
558 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
559
560 d1->SetBounds(gfx::Rect(1010, 10, 100, 100));
561 EXPECT_EQ("1010,10 100x100",
562 d1->GetWindowBoundsInScreen().ToString());
563
564 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
565
566 d1->SetBounds(gfx::Rect(10, 10, 100, 100));
567 EXPECT_EQ("10,10 100x100",
568 d1->GetWindowBoundsInScreen().ToString());
569
570 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
571
572 // Make sure the bounds which doesn't fit to the root window
573 // works correctly.
574 d1->SetBounds(gfx::Rect(1560, 30, 100, 100));
575 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
576 EXPECT_EQ("1560,30 100x100",
577 d1->GetWindowBoundsInScreen().ToString());
578
579 // Setting outside of root windows will be moved to primary root window.
580 // TODO(oshima): This one probably should pick the closest root window.
581 d1->SetBounds(gfx::Rect(200, 10, 100, 100));
582 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
[email protected]f059c6942012-07-21 14:27:57583}
584
[email protected]2e98aaf72012-11-08 06:30:59585// Verifies if the mouse event arrives to the window even when the window
586// moves to another root in a pre-target handler. See: crbug.com/157583
587TEST_F(ExtendedDesktopTest, MoveWindowByMouseClick) {
[email protected]e75642a2013-06-12 17:21:18588 if (!SupportsMultipleDisplays())
589 return;
590
[email protected]2e98aaf72012-11-08 06:30:59591 UpdateDisplay("1000x600,600x400");
592
[email protected]c9390bd2013-11-08 20:33:13593 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]2e98aaf72012-11-08 06:30:59594 aura::test::EventCountDelegate delegate;
595 scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate(
596 &delegate, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
[email protected]334e6182013-01-11 18:35:41597 MoveWindowByClickEventHandler event_handler(window.get());
598 window->AddPreTargetHandler(&event_handler);
599
600 aura::test::EventGenerator& event_generator(GetEventGenerator());
601
602 event_generator.MoveMouseToCenterOf(window.get());
603 event_generator.ClickLeftButton();
[email protected]2e98aaf72012-11-08 06:30:59604 // Both mouse pressed and released arrive at the window and its delegate.
605 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset());
[email protected]334e6182013-01-11 18:35:41606 // Also event_handler moves the window to another root at mouse release.
[email protected]2e98aaf72012-11-08 06:30:59607 EXPECT_EQ(root_windows[1], window->GetRootWindow());
608}
609
[email protected]1a015382012-12-01 19:44:59610TEST_F(ExtendedDesktopTest, MoveWindowToDisplay) {
[email protected]e75642a2013-06-12 17:21:18611 if (!SupportsMultipleDisplays())
612 return;
613
[email protected]e79f26e2012-08-09 07:12:48614 UpdateDisplay("1000x1000,1000x1000");
[email protected]c9390bd2013-11-08 20:33:13615 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]e79f26e2012-08-09 07:12:48616
[email protected]ffabb1e2012-10-12 19:51:17617 gfx::Display display0 = Shell::GetScreen()->GetDisplayMatching(
618 root_windows[0]->GetBoundsInScreen());
619 gfx::Display display1 = Shell::GetScreen()->GetDisplayMatching(
620 root_windows[1]->GetBoundsInScreen());
[email protected]e79f26e2012-08-09 07:12:48621 EXPECT_NE(display0.id(), display1.id());
622
623 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 1000, 100));
624 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
625
626 // Move the window where the window spans both root windows. Since the second
627 // parameter is |display1|, the window should be shown on the secondary root.
628 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
629 display1);
630 EXPECT_EQ("500,10 1000x100",
631 d1->GetWindowBoundsInScreen().ToString());
632 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
633
634 // Move to the primary root.
635 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
636 display0);
637 EXPECT_EQ("500,10 1000x100",
638 d1->GetWindowBoundsInScreen().ToString());
639 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
640}
641
[email protected]f059c6942012-07-21 14:27:57642TEST_F(ExtendedDesktopTest, MoveWindowWithTransient) {
[email protected]e75642a2013-06-12 17:21:18643 if (!SupportsMultipleDisplays())
644 return;
645
[email protected]f634dd32012-07-23 22:49:07646 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13647 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]f059c6942012-07-21 14:27:57648 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
649 views::Widget* w1_t1 = CreateTestWidgetWithParent(
650 w1, gfx::Rect(50, 50, 50, 50), false /* transient */);
651 // Transient child of the transient child.
652 views::Widget* w1_t11 = CreateTestWidgetWithParent(
[email protected]e6de8552014-05-23 19:05:39653 w1_t1, gfx::Rect(1200, 70, 35, 35), false /* transient */);
[email protected]f059c6942012-07-21 14:27:57654
655 views::Widget* w11 = CreateTestWidgetWithParent(
656 w1, gfx::Rect(10, 10, 40, 40), true /* child */);
657 views::Widget* w11_t1 = CreateTestWidgetWithParent(
658 w1, gfx::Rect(1300, 100, 80, 80), false /* transient */);
659
660 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
661 EXPECT_EQ(root_windows[0], w11->GetNativeView()->GetRootWindow());
662 EXPECT_EQ(root_windows[0], w1_t1->GetNativeView()->GetRootWindow());
663 EXPECT_EQ(root_windows[0], w1_t11->GetNativeView()->GetRootWindow());
664 EXPECT_EQ(root_windows[0], w11_t1->GetNativeView()->GetRootWindow());
665 EXPECT_EQ("50,50 50x50",
666 w1_t1->GetWindowBoundsInScreen().ToString());
[email protected]e6de8552014-05-23 19:05:39667 EXPECT_EQ("1200,70 35x35",
[email protected]f059c6942012-07-21 14:27:57668 w1_t11->GetWindowBoundsInScreen().ToString());
669 EXPECT_EQ("20,20 40x40",
670 w11->GetWindowBoundsInScreen().ToString());
671 EXPECT_EQ("1300,100 80x80",
672 w11_t1->GetWindowBoundsInScreen().ToString());
673
674 w1->SetBounds(gfx::Rect(1100,10,100,100));
675
676 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
677 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
678 EXPECT_EQ(root_windows[1], w1_t11->GetNativeView()->GetRootWindow());
679 EXPECT_EQ(root_windows[1], w11->GetNativeView()->GetRootWindow());
680 EXPECT_EQ(root_windows[1], w11_t1->GetNativeView()->GetRootWindow());
681
682 EXPECT_EQ("1110,20 40x40",
683 w11->GetWindowBoundsInScreen().ToString());
684 // Transient window's screen bounds stays the same.
685 EXPECT_EQ("50,50 50x50",
686 w1_t1->GetWindowBoundsInScreen().ToString());
[email protected]e6de8552014-05-23 19:05:39687 EXPECT_EQ("1200,70 35x35",
[email protected]f059c6942012-07-21 14:27:57688 w1_t11->GetWindowBoundsInScreen().ToString());
689 EXPECT_EQ("1300,100 80x80",
690 w11_t1->GetWindowBoundsInScreen().ToString());
691
692 // Transient window doesn't move between root window unless
693 // its transient parent moves.
694 w1_t1->SetBounds(gfx::Rect(10, 50, 50, 50));
695 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
696 EXPECT_EQ("10,50 50x50",
697 w1_t1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57698}
699
[email protected]ca7060982012-08-08 18:05:25700// Test if the Window::ConvertPointToTarget works across root windows.
[email protected]a5e71c92012-06-22 22:09:08701// TODO(oshima): Move multiple display suport and this test to aura.
702TEST_F(ExtendedDesktopTest, ConvertPoint) {
[email protected]e75642a2013-06-12 17:21:18703 if (!SupportsMultipleDisplays())
704 return;
[email protected]55ad8c12014-01-17 18:24:33705 gfx::Screen* screen = Shell::GetScreen();
[email protected]f634dd32012-07-23 22:49:07706 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13707 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]b8984242013-07-12 07:55:38708 gfx::Display display_1 = screen->GetDisplayNearestWindow(root_windows[0]);
[email protected]a5e71c92012-06-22 22:09:08709 EXPECT_EQ("0,0", display_1.bounds().origin().ToString());
[email protected]b8984242013-07-12 07:55:38710 gfx::Display display_2 = screen->GetDisplayNearestWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07711 EXPECT_EQ("1000,0", display_2.bounds().origin().ToString());
712
[email protected]a5e71c92012-06-22 22:09:08713 aura::Window* d1 =
714 CreateTestWidget(gfx::Rect(10, 10, 100, 100))->GetNativeView();
[email protected]a5e71c92012-06-22 22:09:08715 aura::Window* d2 =
[email protected]f634dd32012-07-23 22:49:07716 CreateTestWidget(gfx::Rect(1020, 20, 100, 100))->GetNativeView();
717 EXPECT_EQ(root_windows[0], d1->GetRootWindow());
718 EXPECT_EQ(root_windows[1], d2->GetRootWindow());
[email protected]a5e71c92012-06-22 22:09:08719
[email protected]a5e71c92012-06-22 22:09:08720 // Convert point in the Root2's window to the Root1's window Coord.
721 gfx::Point p(0, 0);
[email protected]ca7060982012-08-08 18:05:25722 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07723 EXPECT_EQ("1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08724 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25725 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07726 EXPECT_EQ("1010,10", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08727
728 // Convert point in the Root1's window to the Root2's window Coord.
729 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25730 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07731 EXPECT_EQ("-1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08732 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25733 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07734 EXPECT_EQ("-1010,-10", p.ToString());
735
736 // Move the 2nd display to the bottom and test again.
[email protected]edbfb8d2012-09-03 08:33:43737 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM);
[email protected]f634dd32012-07-23 22:49:07738
[email protected]b8984242013-07-12 07:55:38739 display_2 = screen->GetDisplayNearestWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07740 EXPECT_EQ("0,600", display_2.bounds().origin().ToString());
741
742 // Convert point in Root2's window to Root1's window Coord.
743 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25744 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07745 EXPECT_EQ("0,600", p.ToString());
746 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25747 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07748 EXPECT_EQ("10,610", p.ToString());
749
750 // Convert point in Root1's window to Root2's window Coord.
751 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25752 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07753 EXPECT_EQ("0,-600", p.ToString());
754 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25755 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07756 EXPECT_EQ("-10,-610", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08757}
[email protected]f634dd32012-07-23 22:49:07758
[email protected]263898a2012-09-17 17:20:07759TEST_F(ExtendedDesktopTest, OpenSystemTray) {
[email protected]e75642a2013-06-12 17:21:18760 if (!SupportsMultipleDisplays())
761 return;
762
[email protected]596c61c2012-10-29 17:29:43763 UpdateDisplay("500x600,600x400");
[email protected]a0afeb12012-12-10 22:57:09764 SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray();
[email protected]263898a2012-09-17 17:20:07765 ASSERT_FALSE(tray->HasSystemBubble());
766
[email protected]334e6182013-01-11 18:35:41767 aura::test::EventGenerator& event_generator(GetEventGenerator());
768
[email protected]263898a2012-09-17 17:20:07769 // Opens the tray by a dummy click event and makes sure that adding/removing
770 // displays doesn't break anything.
[email protected]334e6182013-01-11 18:35:41771 event_generator.MoveMouseToCenterOf(tray->GetWidget()->GetNativeWindow());
[email protected]263898a2012-09-17 17:20:07772 event_generator.ClickLeftButton();
773 EXPECT_TRUE(tray->HasSystemBubble());
774
[email protected]596c61c2012-10-29 17:29:43775 UpdateDisplay("500x600");
[email protected]263898a2012-09-17 17:20:07776 EXPECT_TRUE(tray->HasSystemBubble());
[email protected]596c61c2012-10-29 17:29:43777 UpdateDisplay("500x600,600x400");
[email protected]263898a2012-09-17 17:20:07778 EXPECT_TRUE(tray->HasSystemBubble());
779
780 // Closes the tray and again makes sure that adding/removing displays doesn't
781 // break anything.
782 event_generator.ClickLeftButton();
783 RunAllPendingInMessageLoop();
784
785 EXPECT_FALSE(tray->HasSystemBubble());
786
[email protected]596c61c2012-10-29 17:29:43787 UpdateDisplay("500x600");
[email protected]263898a2012-09-17 17:20:07788 EXPECT_FALSE(tray->HasSystemBubble());
[email protected]596c61c2012-10-29 17:29:43789 UpdateDisplay("500x600,600x400");
[email protected]263898a2012-09-17 17:20:07790 EXPECT_FALSE(tray->HasSystemBubble());
791}
792
[email protected]578048512012-09-19 20:01:24793TEST_F(ExtendedDesktopTest, StayInSameRootWindow) {
[email protected]e75642a2013-06-12 17:21:18794 if (!SupportsMultipleDisplays())
795 return;
796
[email protected]578048512012-09-19 20:01:24797 UpdateDisplay("100x100,200x200");
[email protected]c9390bd2013-11-08 20:33:13798 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]a2e6af12013-01-07 21:40:35799 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 50, 50));
[email protected]578048512012-09-19 20:01:24800 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
801 w1->SetBounds(gfx::Rect(150, 10, 50, 50));
802 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
803
804 // The widget stays in the same root if kStayInSameRootWindowKey is set to
805 // true.
[email protected]093b8d642014-04-03 20:59:28806 w1->GetNativeView()->SetProperty(kStayInSameRootWindowKey, true);
[email protected]578048512012-09-19 20:01:24807 w1->SetBounds(gfx::Rect(10, 10, 50, 50));
808 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
809
810 // The widget should now move to the 1st root window without the property.
[email protected]093b8d642014-04-03 20:59:28811 w1->GetNativeView()->ClearProperty(kStayInSameRootWindowKey);
[email protected]578048512012-09-19 20:01:24812 w1->SetBounds(gfx::Rect(10, 10, 50, 50));
813 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
[email protected]e887c6c2013-07-08 19:35:53814
815 // a window in SettingsBubbleContainer and StatusContainer should
816 // not move to another root window regardles of the bounds specified.
817 aura::Window* settings_bubble_container =
818 Shell::GetPrimaryRootWindowController()->GetContainer(
[email protected]093b8d642014-04-03 20:59:28819 kShellWindowId_SettingBubbleContainer);
[email protected]e887c6c2013-07-08 19:35:53820 aura::Window* window = aura::test::CreateTestWindowWithId(
821 100, settings_bubble_container);
822 window->SetBoundsInScreen(gfx::Rect(150, 10, 50, 50),
[email protected]55ad8c12014-01-17 18:24:33823 ScreenUtil::GetSecondaryDisplay());
[email protected]e887c6c2013-07-08 19:35:53824 EXPECT_EQ(root_windows[0], window->GetRootWindow());
825
826 aura::Window* status_container =
827 Shell::GetPrimaryRootWindowController()->GetContainer(
[email protected]093b8d642014-04-03 20:59:28828 kShellWindowId_StatusContainer);
[email protected]e887c6c2013-07-08 19:35:53829 window = aura::test::CreateTestWindowWithId(100, status_container);
830 window->SetBoundsInScreen(gfx::Rect(150, 10, 50, 50),
[email protected]55ad8c12014-01-17 18:24:33831 ScreenUtil::GetSecondaryDisplay());
[email protected]e887c6c2013-07-08 19:35:53832 EXPECT_EQ(root_windows[0], window->GetRootWindow());
[email protected]578048512012-09-19 20:01:24833}
834
[email protected]e67291f12012-10-10 05:52:38835TEST_F(ExtendedDesktopTest, KeyEventsOnLockScreen) {
[email protected]e75642a2013-06-12 17:21:18836 if (!SupportsMultipleDisplays())
837 return;
838
[email protected]e67291f12012-10-10 05:52:38839 UpdateDisplay("100x100,200x200");
[email protected]c9390bd2013-11-08 20:33:13840 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]e67291f12012-10-10 05:52:38841
842 // Create normal windows on both displays.
843 views::Widget* widget1 = CreateTestWidget(
[email protected]ffabb1e2012-10-12 19:51:17844 Shell::GetScreen()->GetPrimaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38845 widget1->Show();
846 EXPECT_EQ(root_windows[0], widget1->GetNativeView()->GetRootWindow());
847 views::Widget* widget2 = CreateTestWidget(
[email protected]55ad8c12014-01-17 18:24:33848 ScreenUtil::GetSecondaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38849 widget2->Show();
850 EXPECT_EQ(root_windows[1], widget2->GetNativeView()->GetRootWindow());
851
852 // Create a LockScreen window.
853 views::Widget* lock_widget = CreateTestWidget(
[email protected]ffabb1e2012-10-12 19:51:17854 Shell::GetScreen()->GetPrimaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38855 views::Textfield* textfield = new views::Textfield;
[email protected]09148952013-03-13 13:25:43856 lock_widget->client_view()->AddChildView(textfield);
[email protected]e67291f12012-10-10 05:52:38857
[email protected]093b8d642014-04-03 20:59:28858 ash::Shell::GetContainer(Shell::GetPrimaryRootWindow(),
859 ash::kShellWindowId_LockScreenContainer)
860 ->AddChild(lock_widget->GetNativeView());
[email protected]e67291f12012-10-10 05:52:38861 lock_widget->Show();
862 textfield->RequestFocus();
863
[email protected]8cfb6722012-11-28 03:28:46864 aura::client::FocusClient* focus_client =
865 aura::client::GetFocusClient(root_windows[0]);
866 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]e67291f12012-10-10 05:52:38867
868 // The lock window should get events on both root windows.
[email protected]334e6182013-01-11 18:35:41869 aura::test::EventGenerator& event_generator(GetEventGenerator());
870
[email protected]a06955222014-03-10 22:47:32871 event_generator.set_current_host(root_windows[0]->GetHost());
[email protected]334e6182013-01-11 18:35:41872 event_generator.PressKey(ui::VKEY_A, 0);
873 event_generator.ReleaseKey(ui::VKEY_A, 0);
[email protected]8cfb6722012-11-28 03:28:46874 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46875 EXPECT_EQ("a", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38876
[email protected]a06955222014-03-10 22:47:32877 event_generator.set_current_host(root_windows[1]->GetHost());
[email protected]334e6182013-01-11 18:35:41878 event_generator.PressKey(ui::VKEY_B, 0);
879 event_generator.ReleaseKey(ui::VKEY_B, 0);
[email protected]8cfb6722012-11-28 03:28:46880 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46881 EXPECT_EQ("ab", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38882
883 // Deleting 2nd display. The lock window still should get the events.
884 UpdateDisplay("100x100");
[email protected]334e6182013-01-11 18:35:41885 event_generator.PressKey(ui::VKEY_C, 0);
886 event_generator.ReleaseKey(ui::VKEY_C, 0);
[email protected]8cfb6722012-11-28 03:28:46887 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46888 EXPECT_EQ("abc", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38889
890 // Creating 2nd display again, and lock window still should get events
891 // on both root windows.
892 UpdateDisplay("100x100,200x200");
893 root_windows = Shell::GetAllRootWindows();
[email protected]a06955222014-03-10 22:47:32894 event_generator.set_current_host(root_windows[0]->GetHost());
[email protected]334e6182013-01-11 18:35:41895 event_generator.PressKey(ui::VKEY_D, 0);
896 event_generator.ReleaseKey(ui::VKEY_D, 0);
[email protected]8cfb6722012-11-28 03:28:46897 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46898 EXPECT_EQ("abcd", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38899
[email protected]a06955222014-03-10 22:47:32900 event_generator.set_current_host(root_windows[1]->GetHost());
[email protected]334e6182013-01-11 18:35:41901 event_generator.PressKey(ui::VKEY_E, 0);
902 event_generator.ReleaseKey(ui::VKEY_E, 0);
[email protected]8cfb6722012-11-28 03:28:46903 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46904 EXPECT_EQ("abcde", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38905}
906
[email protected]334e6182013-01-11 18:35:41907TEST_F(ExtendedDesktopTest, PassiveGrab) {
[email protected]e75642a2013-06-12 17:21:18908 if (!SupportsMultipleDisplays())
909 return;
910
[email protected]334e6182013-01-11 18:35:41911 EventLocationRecordingEventHandler event_handler;
912 ash::Shell::GetInstance()->AddPreTargetHandler(&event_handler);
913
914 UpdateDisplay("300x300,200x200");
915
916 views::Widget* widget = CreateTestWidget(gfx::Rect(50, 50, 200, 200));
917 widget->Show();
918 ASSERT_EQ("50,50 200x200", widget->GetWindowBoundsInScreen().ToString());
919
920 aura::test::EventGenerator& generator(GetEventGenerator());
921 generator.MoveMouseTo(150, 150);
922 EXPECT_EQ("100,100 150,150", event_handler.GetLocationsAndReset());
923
924 generator.PressLeftButton();
925 generator.MoveMouseTo(400, 150);
926
927 EXPECT_EQ("350,100 400,150", event_handler.GetLocationsAndReset());
928
929 generator.ReleaseLeftButton();
930 EXPECT_EQ("-999,-999 -999,-999", event_handler.GetLocationsAndReset());
931
932 generator.MoveMouseTo(400, 150);
933 EXPECT_EQ("100,150 100,150", event_handler.GetLocationsAndReset());
934
935 ash::Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
936}
937
[email protected]c39be8f2012-06-15 22:58:36938} // namespace ash