blob: 2abea49a0e90ed991bac53a52758d65c10b37b2d [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]a5e71c92012-06-22 22:09:0820#include "ui/aura/test/test_windows.h"
[email protected]553eae12013-02-01 02:33:5221#include "ui/aura/test/window_test_api.h"
[email protected]c39be8f2012-06-15 22:58:3622#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:2623#include "ui/aura/window_event_dispatcher.h"
[email protected]c39be8f2012-06-15 22:58:3624#include "ui/base/cursor/cursor.h"
[email protected]86ccbd42013-09-18 18:11:5425#include "ui/events/event_handler.h"
[email protected]73c9fd02014-07-28 01:48:5226#include "ui/events/test/event_generator.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() {}
dcheng1f4538e2014-10-27 23:57:0548 ~ModalWidgetDelegate() override {}
[email protected]c39be8f2012-06-15 22:58:3649
50 // Overridden from views::WidgetDelegate:
dcheng1f4538e2014-10-27 23:57:0551 views::View* GetContentsView() override { return this; }
52 ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_SYSTEM; }
[email protected]c39be8f2012-06-15 22:58:3653
54 private:
55 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate);
56};
57
[email protected]334e6182013-01-11 18:35:4158// An event handler which moves the target window to the secondary root window
[email protected]2e98aaf72012-11-08 06:30:5959// at pre-handle phase of a mouse release event.
[email protected]334e6182013-01-11 18:35:4160class MoveWindowByClickEventHandler : public ui::EventHandler {
[email protected]2e98aaf72012-11-08 06:30:5961 public:
[email protected]334e6182013-01-11 18:35:4162 explicit MoveWindowByClickEventHandler(aura::Window* target)
[email protected]2e98aaf72012-11-08 06:30:5963 : target_(target) {}
dcheng1f4538e2014-10-27 23:57:0564 ~MoveWindowByClickEventHandler() override {}
[email protected]2e98aaf72012-11-08 06:30:5965
66 private:
67 // ui::EventHandler overrides:
dcheng1f4538e2014-10-27 23:57:0568 void OnMouseEvent(ui::MouseEvent* event) override {
[email protected]2e98aaf72012-11-08 06:30:5969 if (event->type() == ui::ET_MOUSE_RELEASED) {
[email protected]c9390bd2013-11-08 20:33:1370 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]2e98aaf72012-11-08 06:30:5971 DCHECK_LT(1u, root_windows.size());
72 root_windows[1]->AddChild(target_);
73 }
[email protected]2e98aaf72012-11-08 06:30:5974 }
75
[email protected]2e98aaf72012-11-08 06:30:5976 aura::Window* target_;
[email protected]334e6182013-01-11 18:35:4177 DISALLOW_COPY_AND_ASSIGN(MoveWindowByClickEventHandler);
78};
79
80// An event handler which records the event's locations.
81class EventLocationRecordingEventHandler : public ui::EventHandler {
82 public:
83 explicit EventLocationRecordingEventHandler() {
84 reset();
85 }
dcheng1f4538e2014-10-27 23:57:0586 ~EventLocationRecordingEventHandler() override {}
[email protected]334e6182013-01-11 18:35:4187
88 std::string GetLocationsAndReset() {
89 std::string result =
90 location_.ToString() + " " + root_location_.ToString();
91 reset();
92 return result;
93 }
94
95 private:
96 // ui::EventHandler overrides:
dcheng1f4538e2014-10-27 23:57:0597 void OnMouseEvent(ui::MouseEvent* event) override {
[email protected]334e6182013-01-11 18:35:4198 if (event->type() == ui::ET_MOUSE_MOVED ||
99 event->type() == ui::ET_MOUSE_DRAGGED) {
100 location_ = event->location();
101 root_location_ = event->root_location();
102 }
103 }
104
105 void reset() {
106 location_.SetPoint(-999, -999);
107 root_location_.SetPoint(-999, -999);
108 }
109
110 gfx::Point root_location_;
111 gfx::Point location_;
112
113 DISALLOW_COPY_AND_ASSIGN(EventLocationRecordingEventHandler);
[email protected]2e98aaf72012-11-08 06:30:59114};
115
[email protected]2ca75942014-07-12 04:46:37116class EventLocationHandler : public ui::EventHandler {
117 public:
118 EventLocationHandler() {}
dcheng1f4538e2014-10-27 23:57:05119 ~EventLocationHandler() override {}
[email protected]2ca75942014-07-12 04:46:37120
121 const gfx::Point& press_location() const { return press_location_; }
122 const gfx::Point& release_location() const { return release_location_; }
123
124 private:
125 // ui::EventHandler:
dcheng1f4538e2014-10-27 23:57:05126 void OnMouseEvent(ui::MouseEvent* event) override {
[email protected]2ca75942014-07-12 04:46:37127 if (event->type() == ui::ET_MOUSE_PRESSED)
128 press_location_ = event->location();
129 else if (event->type() == ui::ET_MOUSE_RELEASED)
130 release_location_ = event->location();
131 }
132
133 gfx::Point press_location_;
134 gfx::Point release_location_;
135
136 DISALLOW_COPY_AND_ASSIGN(EventLocationHandler);
137};
138
[email protected]c39be8f2012-06-15 22:58:36139} // namespace
140
[email protected]a2e6af12013-01-07 21:40:35141class ExtendedDesktopTest : public test::AshTestBase {
142 public:
143 views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
144 return CreateTestWidgetWithParentAndContext(
145 NULL, CurrentContext(), bounds, false);
146 }
147
148 views::Widget* CreateTestWidgetWithParent(views::Widget* parent,
149 const gfx::Rect& bounds,
150 bool child) {
151 CHECK(parent);
152 return CreateTestWidgetWithParentAndContext(parent, NULL, bounds, child);
153 }
154
155 views::Widget* CreateTestWidgetWithParentAndContext(views::Widget* parent,
156 gfx::NativeView context,
157 const gfx::Rect& bounds,
158 bool child) {
159 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
160 if (parent)
161 params.parent = parent->GetNativeView();
162 params.context = context;
163 params.bounds = bounds;
164 params.child = child;
165 views::Widget* widget = new views::Widget;
166 widget->Init(params);
167 widget->Show();
168 return widget;
169 }
170};
[email protected]c39be8f2012-06-15 22:58:36171
172// Test conditions that root windows in extended desktop mode
173// must satisfy.
174TEST_F(ExtendedDesktopTest, Basic) {
[email protected]e75642a2013-06-12 17:21:18175 if (!SupportsMultipleDisplays())
176 return;
177
[email protected]f634dd32012-07-23 22:49:07178 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13179 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36180
181 // All root windows must have the root window controller.
182 ASSERT_EQ(2U, root_windows.size());
[email protected]c9390bd2013-11-08 20:33:13183 for (aura::Window::Windows::const_iterator iter = root_windows.begin();
[email protected]c39be8f2012-06-15 22:58:36184 iter != root_windows.end(); ++iter) {
[email protected]093b8d642014-04-03 20:59:28185 EXPECT_TRUE(GetRootWindowController(*iter) != NULL);
[email protected]c39be8f2012-06-15 22:58:36186 }
187 // Make sure root windows share the same controllers.
[email protected]8cfb6722012-11-28 03:28:46188 EXPECT_EQ(aura::client::GetFocusClient(root_windows[0]),
189 aura::client::GetFocusClient(root_windows[1]));
[email protected]c39be8f2012-06-15 22:58:36190 EXPECT_EQ(aura::client::GetActivationClient(root_windows[0]),
191 aura::client::GetActivationClient(root_windows[1]));
192 EXPECT_EQ(aura::client::GetCaptureClient(root_windows[0]),
193 aura::client::GetCaptureClient(root_windows[1]));
194}
195
196TEST_F(ExtendedDesktopTest, Activation) {
[email protected]e75642a2013-06-12 17:21:18197 if (!SupportsMultipleDisplays())
198 return;
199
[email protected]f634dd32012-07-23 22:49:07200 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13201 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36202
[email protected]c39be8f2012-06-15 22:58:36203 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]f634dd32012-07-23 22:49:07204 views::Widget* widget_on_2nd =
205 CreateTestWidget(gfx::Rect(1200, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36206 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
[email protected]f634dd32012-07-23 22:49:07207 EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36208
209 EXPECT_EQ(widget_on_2nd->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46210 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]c39be8f2012-06-15 22:58:36211 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
212
[email protected]73c9fd02014-07-28 01:48:52213 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]f634dd32012-07-23 22:49:07214 // Clicking a window changes the active window and active root window.
[email protected]334e6182013-01-11 18:35:41215 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
216 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36217
218 EXPECT_EQ(widget_on_1st->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46219 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]c39be8f2012-06-15 22:58:36220 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]f634dd32012-07-23 22:49:07221
[email protected]334e6182013-01-11 18:35:41222 event_generator.MoveMouseToCenterOf(widget_on_2nd->GetNativeView());
223 event_generator.ClickLeftButton();
[email protected]f634dd32012-07-23 22:49:07224
225 EXPECT_EQ(widget_on_2nd->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46226 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]f634dd32012-07-23 22:49:07227 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
[email protected]c39be8f2012-06-15 22:58:36228}
229
230TEST_F(ExtendedDesktopTest, SystemModal) {
[email protected]e75642a2013-06-12 17:21:18231 if (!SupportsMultipleDisplays())
232 return;
233
[email protected]f634dd32012-07-23 22:49:07234 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13235 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36236
237 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36238 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]492533b32012-09-21 19:06:14239 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
[email protected]d17642d2013-09-12 23:44:38240 EXPECT_EQ(root_windows[0], Shell::GetTargetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36241
[email protected]c39be8f2012-06-15 22:58:36242 // Open system modal. Make sure it's on 2nd root window and active.
[email protected]a2e6af12013-01-07 21:40:35243 views::Widget* modal_widget = views::Widget::CreateWindowWithContextAndBounds(
244 new ModalWidgetDelegate(),
245 CurrentContext(),
246 gfx::Rect(1200, 100, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36247 modal_widget->Show();
248 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
249 EXPECT_EQ(root_windows[1], modal_widget->GetNativeView()->GetRootWindow());
[email protected]d17642d2013-09-12 23:44:38250 EXPECT_EQ(root_windows[1], Shell::GetTargetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36251
[email protected]73c9fd02014-07-28 01:48:52252 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41253
[email protected]2e236a52012-06-27 22:21:47254 // Clicking a widget on widget_on_1st display should not change activation.
[email protected]334e6182013-01-11 18:35:41255 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
256 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36257 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
[email protected]d17642d2013-09-12 23:44:38258 EXPECT_EQ(root_windows[1], Shell::GetTargetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36259
260 // Close system modal and so clicking a widget should work now.
261 modal_widget->Close();
[email protected]334e6182013-01-11 18:35:41262 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
263 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36264 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]d17642d2013-09-12 23:44:38265 EXPECT_EQ(root_windows[0], Shell::GetTargetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36266}
267
268TEST_F(ExtendedDesktopTest, TestCursor) {
[email protected]e75642a2013-06-12 17:21:18269 if (!SupportsMultipleDisplays())
270 return;
271
[email protected]f634dd32012-07-23 22:49:07272 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13273 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]2374d1812014-03-04 03:42:27274 aura::WindowTreeHost* host0 = root_windows[0]->GetHost();
275 aura::WindowTreeHost* host1 = root_windows[1]->GetHost();
276 EXPECT_EQ(ui::kCursorPointer, host0->last_cursor().native_type());
277 EXPECT_EQ(ui::kCursorPointer, host1->last_cursor().native_type());
[email protected]151ffdff2012-09-11 20:18:35278 Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorCopy);
[email protected]2374d1812014-03-04 03:42:27279 EXPECT_EQ(ui::kCursorCopy, host0->last_cursor().native_type());
280 EXPECT_EQ(ui::kCursorCopy, host1->last_cursor().native_type());
[email protected]c39be8f2012-06-15 22:58:36281}
282
[email protected]718b26c2012-07-24 20:53:23283TEST_F(ExtendedDesktopTest, TestCursorLocation) {
[email protected]e75642a2013-06-12 17:21:18284 if (!SupportsMultipleDisplays())
285 return;
286
[email protected]d0064722013-03-14 18:16:43287 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13288 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]553eae12013-02-01 02:33:52289 aura::test::WindowTestApi root_window0_test_api(root_windows[0]);
290 aura::test::WindowTestApi root_window1_test_api(root_windows[1]);
[email protected]718b26c2012-07-24 20:53:23291
292 root_windows[0]->MoveCursorTo(gfx::Point(10, 10));
[email protected]ffabb1e2012-10-12 19:51:17293 EXPECT_EQ("10,10", Shell::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23294 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
295 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
296 root_windows[1]->MoveCursorTo(gfx::Point(10, 20));
[email protected]ffabb1e2012-10-12 19:51:17297 EXPECT_EQ("1010,20", Shell::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23298 EXPECT_FALSE(root_window0_test_api.ContainsMouse());
299 EXPECT_TRUE(root_window1_test_api.ContainsMouse());
300 root_windows[0]->MoveCursorTo(gfx::Point(20, 10));
[email protected]ffabb1e2012-10-12 19:51:17301 EXPECT_EQ("20,10", Shell::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23302 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
303 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
304}
305
[email protected]20c59762012-06-23 01:10:24306TEST_F(ExtendedDesktopTest, GetRootWindowAt) {
[email protected]e75642a2013-06-12 17:21:18307 if (!SupportsMultipleDisplays())
308 return;
309
[email protected]f634dd32012-07-23 22:49:07310 UpdateDisplay("700x500,500x500");
[email protected]edbfb8d2012-09-03 08:33:43311 SetSecondaryDisplayLayout(DisplayLayout::LEFT);
[email protected]c9390bd2013-11-08 20:33:13312 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24313
[email protected]7203a5e2012-08-06 18:27:46314 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-400, 100)));
315 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-1, 100)));
316 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 300)));
[email protected]24f5e242014-07-22 02:16:09317 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(700, 300)));
[email protected]20c59762012-06-23 01:10:24318
319 // Zero origin.
[email protected]7203a5e2012-08-06 18:27:46320 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 0)));
[email protected]20c59762012-06-23 01:10:24321
[email protected]36168852014-01-07 12:23:28322 // Out of range point should return the nearest root window
323 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-600, 0)));
[email protected]7203a5e2012-08-06 18:27:46324 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(701, 100)));
[email protected]20c59762012-06-23 01:10:24325}
326
327TEST_F(ExtendedDesktopTest, GetRootWindowMatching) {
[email protected]e75642a2013-06-12 17:21:18328 if (!SupportsMultipleDisplays())
329 return;
330
[email protected]f634dd32012-07-23 22:49:07331 UpdateDisplay("700x500,500x500");
[email protected]edbfb8d2012-09-03 08:33:43332 SetSecondaryDisplayLayout(DisplayLayout::LEFT);
[email protected]66b05eac2012-06-27 23:53:10333
[email protected]c9390bd2013-11-08 20:33:13334 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24335
336 // Containing rect.
337 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46338 wm::GetRootWindowMatching(gfx::Rect(-300, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24339 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46340 wm::GetRootWindowMatching(gfx::Rect(100, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24341
342 // Intersecting rect.
343 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46344 wm::GetRootWindowMatching(gfx::Rect(-200, 0, 300, 300)));
[email protected]20c59762012-06-23 01:10:24345 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46346 wm::GetRootWindowMatching(gfx::Rect(-100, 0, 300, 300)));
[email protected]20c59762012-06-23 01:10:24347
348 // Zero origin.
[email protected]66b05eac2012-06-27 23:53:10349 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46350 wm::GetRootWindowMatching(gfx::Rect(0, 0, 0, 0)));
[email protected]66b05eac2012-06-27 23:53:10351 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46352 wm::GetRootWindowMatching(gfx::Rect(0, 0, 1, 1)));
[email protected]20c59762012-06-23 01:10:24353
354 // Empty rect.
355 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46356 wm::GetRootWindowMatching(gfx::Rect(-400, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24357 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46358 wm::GetRootWindowMatching(gfx::Rect(100, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24359
360 // Out of range rect should return the primary root window.
361 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46362 wm::GetRootWindowMatching(gfx::Rect(-600, -300, 50, 50)));
[email protected]20c59762012-06-23 01:10:24363 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46364 wm::GetRootWindowMatching(gfx::Rect(0, 1000, 50, 50)));
[email protected]0f81f442012-06-22 06:20:27365}
366
[email protected]1a015382012-12-01 19:44:59367TEST_F(ExtendedDesktopTest, Capture) {
[email protected]e75642a2013-06-12 17:21:18368 if (!SupportsMultipleDisplays())
369 return;
370
[email protected]f634dd32012-07-23 22:49:07371 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13372 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]a5e71c92012-06-22 22:09:08373
374 aura::test::EventCountDelegate r1_d1;
375 aura::test::EventCountDelegate r1_d2;
376 aura::test::EventCountDelegate r2_d1;
377
378 scoped_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
379 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
380 scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
381 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
382 scoped_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
383 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
[email protected]f634dd32012-07-23 22:49:07384
[email protected]a5e71c92012-06-22 22:09:08385 r1_w1->SetCapture();
386
387 EXPECT_EQ(r1_w1.get(),
388 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]334e6182013-01-11 18:35:41389
[email protected]73c9fd02014-07-28 01:48:52390 ui::test::EventGenerator& generator = GetEventGenerator();
[email protected]d05cf2f2014-02-26 05:31:43391 generator.MoveMouseToCenterOf(r2_w1.get());
392 // |r1_w1| will receive the events because it has capture.
393 EXPECT_EQ("1 1 0", r1_d1.GetMouseMotionCountsAndReset());
394 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
395 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
396
397 generator.ClickLeftButton();
[email protected]a5e71c92012-06-22 22:09:08398 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
399 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
[email protected]b19ba4adf2012-09-07 16:13:29400 // The mouse is outside. On chromeos, the mouse is warped to the
401 // dest root window, but it's not implemented on Win yet, so
402 // no mouse move event on Win.
[email protected]d05cf2f2014-02-26 05:31:43403 EXPECT_EQ("0 0 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08404 EXPECT_EQ("1 1", r1_d1.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43405
406 generator.MoveMouseTo(15, 15);
[email protected]f634dd32012-07-23 22:49:07407 EXPECT_EQ("0 1 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43408 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08409
410 r1_w2->SetCapture();
411 EXPECT_EQ(r1_w2.get(),
412 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]d05cf2f2014-02-26 05:31:43413 generator.MoveMouseBy(10, 10);
414 // |r1_w2| has the capture. So it will receive the mouse-move event.
415 EXPECT_EQ("0 0 0", r1_d1.GetMouseMotionCountsAndReset());
416 EXPECT_EQ("0 1 0", r1_d2.GetMouseMotionCountsAndReset());
417 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
418
419 generator.ClickLeftButton();
[email protected]a5e71c92012-06-22 22:09:08420 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
421 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43422 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08423 EXPECT_EQ("1 1", r1_d2.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43424
[email protected]a5e71c92012-06-22 22:09:08425 r1_w2->ReleaseCapture();
[email protected]36f566532012-09-19 04:07:24426 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]d05cf2f2014-02-26 05:31:43427
428 generator.MoveMouseToCenterOf(r2_w1.get());
429 generator.ClickLeftButton();
[email protected]a5e71c92012-06-22 22:09:08430 EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset());
431 EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset());
432 // Make sure the mouse_moved_handler_ is properly reset.
433 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
434 EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset());
435}
436
[email protected]2ca75942014-07-12 04:46:37437TEST_F(ExtendedDesktopTest, CaptureEventLocation) {
438 if (!SupportsMultipleDisplays())
439 return;
440
441 UpdateDisplay("1000x600,600x400");
442 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
443
444 aura::test::EventCountDelegate r1_d1;
445 aura::test::EventCountDelegate r1_d2;
446 aura::test::EventCountDelegate r2_d1;
447
448 scoped_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
449 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
450 scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
451 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
452 scoped_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
453 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
454
455 r1_w1->SetCapture();
456
[email protected]73c9fd02014-07-28 01:48:52457 ui::test::EventGenerator& generator = GetEventGenerator();
[email protected]2ca75942014-07-12 04:46:37458 generator.MoveMouseToCenterOf(r2_w1.get());
459 EXPECT_EQ(gfx::Point(1060, 60).ToString(),
460 generator.current_location().ToString());
461
462 EventLocationHandler location_handler;
463 r1_w1->AddPreTargetHandler(&location_handler);
464 generator.ClickLeftButton();
465 r1_w1->RemovePreTargetHandler(&location_handler);
466 EXPECT_EQ(gfx::Point(1050, 50).ToString(),
467 location_handler.press_location().ToString());
468 EXPECT_EQ(gfx::Point(1050, 50).ToString(),
469 location_handler.release_location().ToString());
470}
471
472TEST_F(ExtendedDesktopTest, CaptureEventLocationHighDPI) {
473 if (!SupportsMultipleDisplays())
474 return;
475
476 UpdateDisplay("1000x600*2,600x400");
477 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
478
479 aura::test::EventCountDelegate r1_d1;
480 aura::test::EventCountDelegate r1_d2;
481 aura::test::EventCountDelegate r2_d1;
482
483 scoped_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
484 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
485 scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
486 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
487 scoped_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
488 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
489
490 r1_w1->SetCapture();
491
[email protected]73c9fd02014-07-28 01:48:52492 ui::test::EventGenerator& generator = GetEventGenerator();
[email protected]2ca75942014-07-12 04:46:37493 generator.MoveMouseToCenterOf(r2_w1.get());
494 EXPECT_EQ(gfx::Point(560, 60).ToString(),
495 generator.current_location().ToString());
496
497 EventLocationHandler location_handler;
498 r1_w1->AddPreTargetHandler(&location_handler);
499 generator.ClickLeftButton();
500 r1_w1->RemovePreTargetHandler(&location_handler);
501 EXPECT_EQ(gfx::Point(550, 50).ToString(),
502 location_handler.press_location().ToString());
503 EXPECT_EQ(gfx::Point(550, 50).ToString(),
504 location_handler.release_location().ToString());
505}
506
507TEST_F(ExtendedDesktopTest, CaptureEventLocationHighDPI_2) {
508 if (!SupportsMultipleDisplays())
509 return;
510
511 UpdateDisplay("1000x600,600x400*2");
512 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
513
514 aura::test::EventCountDelegate r1_d1;
515 aura::test::EventCountDelegate r1_d2;
516 aura::test::EventCountDelegate r2_d1;
517
518 scoped_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
519 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
520 scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
521 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
522 scoped_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
523 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
524
525 r1_w1->SetCapture();
526
[email protected]73c9fd02014-07-28 01:48:52527 ui::test::EventGenerator& generator = GetEventGenerator();
[email protected]2ca75942014-07-12 04:46:37528 generator.MoveMouseToCenterOf(r2_w1.get());
529 EXPECT_EQ(gfx::Point(1060, 60).ToString(),
530 generator.current_location().ToString());
531
532 EventLocationHandler location_handler;
533 r1_w1->AddPreTargetHandler(&location_handler);
534 generator.ClickLeftButton();
535 r1_w1->RemovePreTargetHandler(&location_handler);
536 // Event-generator dispatches the event in the primary root-window's coord
537 // space. Since the location is (1060, 60), it goes to the secondary
538 // root-window as (30, 30) since the secondary root-window has a device scale
539 // factor of 2.
540 EXPECT_EQ(gfx::Point(1020, 20).ToString(),
541 location_handler.press_location().ToString());
542 EXPECT_EQ(gfx::Point(1020, 20).ToString(),
543 location_handler.release_location().ToString());
544}
545
[email protected]f059c6942012-07-21 14:27:57546TEST_F(ExtendedDesktopTest, MoveWindow) {
[email protected]e75642a2013-06-12 17:21:18547 if (!SupportsMultipleDisplays())
548 return;
549
[email protected]f634dd32012-07-23 22:49:07550 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13551 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]f059c6942012-07-21 14:27:57552 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
553
554 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
555
556 d1->SetBounds(gfx::Rect(1010, 10, 100, 100));
557 EXPECT_EQ("1010,10 100x100",
558 d1->GetWindowBoundsInScreen().ToString());
559
560 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
561
562 d1->SetBounds(gfx::Rect(10, 10, 100, 100));
563 EXPECT_EQ("10,10 100x100",
564 d1->GetWindowBoundsInScreen().ToString());
565
566 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
567
568 // Make sure the bounds which doesn't fit to the root window
569 // works correctly.
570 d1->SetBounds(gfx::Rect(1560, 30, 100, 100));
571 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
572 EXPECT_EQ("1560,30 100x100",
573 d1->GetWindowBoundsInScreen().ToString());
574
575 // Setting outside of root windows will be moved to primary root window.
576 // TODO(oshima): This one probably should pick the closest root window.
577 d1->SetBounds(gfx::Rect(200, 10, 100, 100));
578 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
[email protected]f059c6942012-07-21 14:27:57579}
580
[email protected]2e98aaf72012-11-08 06:30:59581// Verifies if the mouse event arrives to the window even when the window
582// moves to another root in a pre-target handler. See: crbug.com/157583
583TEST_F(ExtendedDesktopTest, MoveWindowByMouseClick) {
[email protected]e75642a2013-06-12 17:21:18584 if (!SupportsMultipleDisplays())
585 return;
586
[email protected]2e98aaf72012-11-08 06:30:59587 UpdateDisplay("1000x600,600x400");
588
[email protected]c9390bd2013-11-08 20:33:13589 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]2e98aaf72012-11-08 06:30:59590 aura::test::EventCountDelegate delegate;
591 scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate(
592 &delegate, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
[email protected]334e6182013-01-11 18:35:41593 MoveWindowByClickEventHandler event_handler(window.get());
594 window->AddPreTargetHandler(&event_handler);
595
[email protected]73c9fd02014-07-28 01:48:52596 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41597
598 event_generator.MoveMouseToCenterOf(window.get());
599 event_generator.ClickLeftButton();
[email protected]2e98aaf72012-11-08 06:30:59600 // Both mouse pressed and released arrive at the window and its delegate.
601 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset());
[email protected]334e6182013-01-11 18:35:41602 // Also event_handler moves the window to another root at mouse release.
[email protected]2e98aaf72012-11-08 06:30:59603 EXPECT_EQ(root_windows[1], window->GetRootWindow());
604}
605
[email protected]1a015382012-12-01 19:44:59606TEST_F(ExtendedDesktopTest, MoveWindowToDisplay) {
[email protected]e75642a2013-06-12 17:21:18607 if (!SupportsMultipleDisplays())
608 return;
609
[email protected]e79f26e2012-08-09 07:12:48610 UpdateDisplay("1000x1000,1000x1000");
[email protected]c9390bd2013-11-08 20:33:13611 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]e79f26e2012-08-09 07:12:48612
[email protected]ffabb1e2012-10-12 19:51:17613 gfx::Display display0 = Shell::GetScreen()->GetDisplayMatching(
614 root_windows[0]->GetBoundsInScreen());
615 gfx::Display display1 = Shell::GetScreen()->GetDisplayMatching(
616 root_windows[1]->GetBoundsInScreen());
[email protected]e79f26e2012-08-09 07:12:48617 EXPECT_NE(display0.id(), display1.id());
618
619 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 1000, 100));
620 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
621
622 // Move the window where the window spans both root windows. Since the second
623 // parameter is |display1|, the window should be shown on the secondary root.
624 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
625 display1);
626 EXPECT_EQ("500,10 1000x100",
627 d1->GetWindowBoundsInScreen().ToString());
628 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
629
630 // Move to the primary root.
631 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
632 display0);
633 EXPECT_EQ("500,10 1000x100",
634 d1->GetWindowBoundsInScreen().ToString());
635 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
636}
637
[email protected]f059c6942012-07-21 14:27:57638TEST_F(ExtendedDesktopTest, MoveWindowWithTransient) {
[email protected]e75642a2013-06-12 17:21:18639 if (!SupportsMultipleDisplays())
640 return;
641
[email protected]f634dd32012-07-23 22:49:07642 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13643 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]f059c6942012-07-21 14:27:57644 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
645 views::Widget* w1_t1 = CreateTestWidgetWithParent(
646 w1, gfx::Rect(50, 50, 50, 50), false /* transient */);
647 // Transient child of the transient child.
648 views::Widget* w1_t11 = CreateTestWidgetWithParent(
[email protected]e6de8552014-05-23 19:05:39649 w1_t1, gfx::Rect(1200, 70, 35, 35), false /* transient */);
[email protected]f059c6942012-07-21 14:27:57650
651 views::Widget* w11 = CreateTestWidgetWithParent(
652 w1, gfx::Rect(10, 10, 40, 40), true /* child */);
653 views::Widget* w11_t1 = CreateTestWidgetWithParent(
654 w1, gfx::Rect(1300, 100, 80, 80), false /* transient */);
655
656 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
657 EXPECT_EQ(root_windows[0], w11->GetNativeView()->GetRootWindow());
658 EXPECT_EQ(root_windows[0], w1_t1->GetNativeView()->GetRootWindow());
659 EXPECT_EQ(root_windows[0], w1_t11->GetNativeView()->GetRootWindow());
660 EXPECT_EQ(root_windows[0], w11_t1->GetNativeView()->GetRootWindow());
661 EXPECT_EQ("50,50 50x50",
662 w1_t1->GetWindowBoundsInScreen().ToString());
[email protected]e6de8552014-05-23 19:05:39663 EXPECT_EQ("1200,70 35x35",
[email protected]f059c6942012-07-21 14:27:57664 w1_t11->GetWindowBoundsInScreen().ToString());
665 EXPECT_EQ("20,20 40x40",
666 w11->GetWindowBoundsInScreen().ToString());
667 EXPECT_EQ("1300,100 80x80",
668 w11_t1->GetWindowBoundsInScreen().ToString());
669
[email protected]24f5e242014-07-22 02:16:09670 w1->SetBounds(gfx::Rect(1100, 10, 100, 100));
[email protected]f059c6942012-07-21 14:27:57671
672 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
673 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
674 EXPECT_EQ(root_windows[1], w1_t11->GetNativeView()->GetRootWindow());
675 EXPECT_EQ(root_windows[1], w11->GetNativeView()->GetRootWindow());
676 EXPECT_EQ(root_windows[1], w11_t1->GetNativeView()->GetRootWindow());
677
678 EXPECT_EQ("1110,20 40x40",
679 w11->GetWindowBoundsInScreen().ToString());
680 // Transient window's screen bounds stays the same.
681 EXPECT_EQ("50,50 50x50",
682 w1_t1->GetWindowBoundsInScreen().ToString());
[email protected]e6de8552014-05-23 19:05:39683 EXPECT_EQ("1200,70 35x35",
[email protected]f059c6942012-07-21 14:27:57684 w1_t11->GetWindowBoundsInScreen().ToString());
685 EXPECT_EQ("1300,100 80x80",
686 w11_t1->GetWindowBoundsInScreen().ToString());
687
688 // Transient window doesn't move between root window unless
689 // its transient parent moves.
690 w1_t1->SetBounds(gfx::Rect(10, 50, 50, 50));
691 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
692 EXPECT_EQ("10,50 50x50",
693 w1_t1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57694}
695
[email protected]ca7060982012-08-08 18:05:25696// Test if the Window::ConvertPointToTarget works across root windows.
[email protected]a5e71c92012-06-22 22:09:08697// TODO(oshima): Move multiple display suport and this test to aura.
698TEST_F(ExtendedDesktopTest, ConvertPoint) {
[email protected]e75642a2013-06-12 17:21:18699 if (!SupportsMultipleDisplays())
700 return;
[email protected]55ad8c12014-01-17 18:24:33701 gfx::Screen* screen = Shell::GetScreen();
[email protected]f634dd32012-07-23 22:49:07702 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13703 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]b8984242013-07-12 07:55:38704 gfx::Display display_1 = screen->GetDisplayNearestWindow(root_windows[0]);
[email protected]a5e71c92012-06-22 22:09:08705 EXPECT_EQ("0,0", display_1.bounds().origin().ToString());
[email protected]b8984242013-07-12 07:55:38706 gfx::Display display_2 = screen->GetDisplayNearestWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07707 EXPECT_EQ("1000,0", display_2.bounds().origin().ToString());
708
[email protected]a5e71c92012-06-22 22:09:08709 aura::Window* d1 =
710 CreateTestWidget(gfx::Rect(10, 10, 100, 100))->GetNativeView();
[email protected]a5e71c92012-06-22 22:09:08711 aura::Window* d2 =
[email protected]f634dd32012-07-23 22:49:07712 CreateTestWidget(gfx::Rect(1020, 20, 100, 100))->GetNativeView();
713 EXPECT_EQ(root_windows[0], d1->GetRootWindow());
714 EXPECT_EQ(root_windows[1], d2->GetRootWindow());
[email protected]a5e71c92012-06-22 22:09:08715
[email protected]a5e71c92012-06-22 22:09:08716 // Convert point in the Root2's window to the Root1's window Coord.
717 gfx::Point p(0, 0);
[email protected]ca7060982012-08-08 18:05:25718 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07719 EXPECT_EQ("1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08720 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25721 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07722 EXPECT_EQ("1010,10", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08723
724 // Convert point in the Root1's window to the Root2's window Coord.
725 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25726 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07727 EXPECT_EQ("-1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08728 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25729 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07730 EXPECT_EQ("-1010,-10", p.ToString());
731
732 // Move the 2nd display to the bottom and test again.
[email protected]edbfb8d2012-09-03 08:33:43733 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM);
[email protected]f634dd32012-07-23 22:49:07734
[email protected]b8984242013-07-12 07:55:38735 display_2 = screen->GetDisplayNearestWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07736 EXPECT_EQ("0,600", display_2.bounds().origin().ToString());
737
738 // Convert point in Root2's window to Root1's window Coord.
739 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25740 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07741 EXPECT_EQ("0,600", p.ToString());
742 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25743 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07744 EXPECT_EQ("10,610", p.ToString());
745
746 // Convert point in Root1's window to Root2's window Coord.
747 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25748 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07749 EXPECT_EQ("0,-600", p.ToString());
750 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25751 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07752 EXPECT_EQ("-10,-610", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08753}
[email protected]f634dd32012-07-23 22:49:07754
[email protected]263898a2012-09-17 17:20:07755TEST_F(ExtendedDesktopTest, OpenSystemTray) {
[email protected]e75642a2013-06-12 17:21:18756 if (!SupportsMultipleDisplays())
757 return;
758
[email protected]596c61c2012-10-29 17:29:43759 UpdateDisplay("500x600,600x400");
[email protected]a0afeb12012-12-10 22:57:09760 SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray();
[email protected]263898a2012-09-17 17:20:07761 ASSERT_FALSE(tray->HasSystemBubble());
762
[email protected]73c9fd02014-07-28 01:48:52763 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41764
[email protected]263898a2012-09-17 17:20:07765 // Opens the tray by a dummy click event and makes sure that adding/removing
766 // displays doesn't break anything.
[email protected]334e6182013-01-11 18:35:41767 event_generator.MoveMouseToCenterOf(tray->GetWidget()->GetNativeWindow());
[email protected]263898a2012-09-17 17:20:07768 event_generator.ClickLeftButton();
769 EXPECT_TRUE(tray->HasSystemBubble());
770
[email protected]596c61c2012-10-29 17:29:43771 UpdateDisplay("500x600");
[email protected]263898a2012-09-17 17:20:07772 EXPECT_TRUE(tray->HasSystemBubble());
[email protected]596c61c2012-10-29 17:29:43773 UpdateDisplay("500x600,600x400");
[email protected]263898a2012-09-17 17:20:07774 EXPECT_TRUE(tray->HasSystemBubble());
775
776 // Closes the tray and again makes sure that adding/removing displays doesn't
777 // break anything.
778 event_generator.ClickLeftButton();
779 RunAllPendingInMessageLoop();
780
781 EXPECT_FALSE(tray->HasSystemBubble());
782
[email protected]596c61c2012-10-29 17:29:43783 UpdateDisplay("500x600");
[email protected]263898a2012-09-17 17:20:07784 EXPECT_FALSE(tray->HasSystemBubble());
[email protected]596c61c2012-10-29 17:29:43785 UpdateDisplay("500x600,600x400");
[email protected]263898a2012-09-17 17:20:07786 EXPECT_FALSE(tray->HasSystemBubble());
787}
788
[email protected]578048512012-09-19 20:01:24789TEST_F(ExtendedDesktopTest, StayInSameRootWindow) {
[email protected]e75642a2013-06-12 17:21:18790 if (!SupportsMultipleDisplays())
791 return;
792
[email protected]578048512012-09-19 20:01:24793 UpdateDisplay("100x100,200x200");
[email protected]c9390bd2013-11-08 20:33:13794 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]a2e6af12013-01-07 21:40:35795 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 50, 50));
[email protected]578048512012-09-19 20:01:24796 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
797 w1->SetBounds(gfx::Rect(150, 10, 50, 50));
798 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
799
800 // The widget stays in the same root if kStayInSameRootWindowKey is set to
801 // true.
[email protected]093b8d642014-04-03 20:59:28802 w1->GetNativeView()->SetProperty(kStayInSameRootWindowKey, true);
[email protected]578048512012-09-19 20:01:24803 w1->SetBounds(gfx::Rect(10, 10, 50, 50));
804 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
805
806 // The widget should now move to the 1st root window without the property.
[email protected]093b8d642014-04-03 20:59:28807 w1->GetNativeView()->ClearProperty(kStayInSameRootWindowKey);
[email protected]578048512012-09-19 20:01:24808 w1->SetBounds(gfx::Rect(10, 10, 50, 50));
809 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
[email protected]e887c6c2013-07-08 19:35:53810
811 // a window in SettingsBubbleContainer and StatusContainer should
812 // not move to another root window regardles of the bounds specified.
813 aura::Window* settings_bubble_container =
814 Shell::GetPrimaryRootWindowController()->GetContainer(
[email protected]093b8d642014-04-03 20:59:28815 kShellWindowId_SettingBubbleContainer);
[email protected]e887c6c2013-07-08 19:35:53816 aura::Window* window = aura::test::CreateTestWindowWithId(
817 100, settings_bubble_container);
818 window->SetBoundsInScreen(gfx::Rect(150, 10, 50, 50),
[email protected]55ad8c12014-01-17 18:24:33819 ScreenUtil::GetSecondaryDisplay());
[email protected]e887c6c2013-07-08 19:35:53820 EXPECT_EQ(root_windows[0], window->GetRootWindow());
821
822 aura::Window* status_container =
823 Shell::GetPrimaryRootWindowController()->GetContainer(
[email protected]093b8d642014-04-03 20:59:28824 kShellWindowId_StatusContainer);
[email protected]e887c6c2013-07-08 19:35:53825 window = aura::test::CreateTestWindowWithId(100, status_container);
826 window->SetBoundsInScreen(gfx::Rect(150, 10, 50, 50),
[email protected]55ad8c12014-01-17 18:24:33827 ScreenUtil::GetSecondaryDisplay());
[email protected]e887c6c2013-07-08 19:35:53828 EXPECT_EQ(root_windows[0], window->GetRootWindow());
[email protected]578048512012-09-19 20:01:24829}
830
[email protected]e67291f12012-10-10 05:52:38831TEST_F(ExtendedDesktopTest, KeyEventsOnLockScreen) {
[email protected]e75642a2013-06-12 17:21:18832 if (!SupportsMultipleDisplays())
833 return;
834
[email protected]e67291f12012-10-10 05:52:38835 UpdateDisplay("100x100,200x200");
[email protected]c9390bd2013-11-08 20:33:13836 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]e67291f12012-10-10 05:52:38837
838 // Create normal windows on both displays.
839 views::Widget* widget1 = CreateTestWidget(
[email protected]ffabb1e2012-10-12 19:51:17840 Shell::GetScreen()->GetPrimaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38841 widget1->Show();
842 EXPECT_EQ(root_windows[0], widget1->GetNativeView()->GetRootWindow());
843 views::Widget* widget2 = CreateTestWidget(
[email protected]55ad8c12014-01-17 18:24:33844 ScreenUtil::GetSecondaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38845 widget2->Show();
846 EXPECT_EQ(root_windows[1], widget2->GetNativeView()->GetRootWindow());
847
848 // Create a LockScreen window.
849 views::Widget* lock_widget = CreateTestWidget(
[email protected]ffabb1e2012-10-12 19:51:17850 Shell::GetScreen()->GetPrimaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38851 views::Textfield* textfield = new views::Textfield;
[email protected]09148952013-03-13 13:25:43852 lock_widget->client_view()->AddChildView(textfield);
[email protected]e67291f12012-10-10 05:52:38853
[email protected]093b8d642014-04-03 20:59:28854 ash::Shell::GetContainer(Shell::GetPrimaryRootWindow(),
855 ash::kShellWindowId_LockScreenContainer)
856 ->AddChild(lock_widget->GetNativeView());
[email protected]e67291f12012-10-10 05:52:38857 lock_widget->Show();
858 textfield->RequestFocus();
859
[email protected]8cfb6722012-11-28 03:28:46860 aura::client::FocusClient* focus_client =
861 aura::client::GetFocusClient(root_windows[0]);
862 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]e67291f12012-10-10 05:52:38863
864 // The lock window should get events on both root windows.
[email protected]73c9fd02014-07-28 01:48:52865 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41866
[email protected]1ea46f6f2014-07-17 07:36:40867 event_generator.set_current_target(root_windows[0]);
[email protected]334e6182013-01-11 18:35:41868 event_generator.PressKey(ui::VKEY_A, 0);
869 event_generator.ReleaseKey(ui::VKEY_A, 0);
[email protected]8cfb6722012-11-28 03:28:46870 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46871 EXPECT_EQ("a", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38872
[email protected]1ea46f6f2014-07-17 07:36:40873 event_generator.set_current_target(root_windows[1]);
[email protected]334e6182013-01-11 18:35:41874 event_generator.PressKey(ui::VKEY_B, 0);
875 event_generator.ReleaseKey(ui::VKEY_B, 0);
[email protected]8cfb6722012-11-28 03:28:46876 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46877 EXPECT_EQ("ab", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38878
879 // Deleting 2nd display. The lock window still should get the events.
880 UpdateDisplay("100x100");
[email protected]334e6182013-01-11 18:35:41881 event_generator.PressKey(ui::VKEY_C, 0);
882 event_generator.ReleaseKey(ui::VKEY_C, 0);
[email protected]8cfb6722012-11-28 03:28:46883 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46884 EXPECT_EQ("abc", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38885
886 // Creating 2nd display again, and lock window still should get events
887 // on both root windows.
888 UpdateDisplay("100x100,200x200");
889 root_windows = Shell::GetAllRootWindows();
[email protected]1ea46f6f2014-07-17 07:36:40890 event_generator.set_current_target(root_windows[0]);
[email protected]334e6182013-01-11 18:35:41891 event_generator.PressKey(ui::VKEY_D, 0);
892 event_generator.ReleaseKey(ui::VKEY_D, 0);
[email protected]8cfb6722012-11-28 03:28:46893 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46894 EXPECT_EQ("abcd", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38895
[email protected]1ea46f6f2014-07-17 07:36:40896 event_generator.set_current_target(root_windows[1]);
[email protected]334e6182013-01-11 18:35:41897 event_generator.PressKey(ui::VKEY_E, 0);
898 event_generator.ReleaseKey(ui::VKEY_E, 0);
[email protected]8cfb6722012-11-28 03:28:46899 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46900 EXPECT_EQ("abcde", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38901}
902
[email protected]334e6182013-01-11 18:35:41903TEST_F(ExtendedDesktopTest, PassiveGrab) {
[email protected]e75642a2013-06-12 17:21:18904 if (!SupportsMultipleDisplays())
905 return;
906
[email protected]334e6182013-01-11 18:35:41907 EventLocationRecordingEventHandler event_handler;
908 ash::Shell::GetInstance()->AddPreTargetHandler(&event_handler);
909
910 UpdateDisplay("300x300,200x200");
911
912 views::Widget* widget = CreateTestWidget(gfx::Rect(50, 50, 200, 200));
913 widget->Show();
914 ASSERT_EQ("50,50 200x200", widget->GetWindowBoundsInScreen().ToString());
915
[email protected]73c9fd02014-07-28 01:48:52916 ui::test::EventGenerator& generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41917 generator.MoveMouseTo(150, 150);
918 EXPECT_EQ("100,100 150,150", event_handler.GetLocationsAndReset());
919
920 generator.PressLeftButton();
921 generator.MoveMouseTo(400, 150);
922
923 EXPECT_EQ("350,100 400,150", event_handler.GetLocationsAndReset());
924
925 generator.ReleaseLeftButton();
926 EXPECT_EQ("-999,-999 -999,-999", event_handler.GetLocationsAndReset());
927
928 generator.MoveMouseTo(400, 150);
929 EXPECT_EQ("100,150 100,150", event_handler.GetLocationsAndReset());
930
931 ash::Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
932}
933
[email protected]c39be8f2012-06-15 22:58:36934} // namespace ash