blob: f1702cd0e67be3fa42cb4ed4d63383d97d9e0b92 [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]6bdf7952012-11-14 10:10:585#include "ash/display/display_manager.h"
[email protected]e887c6c2013-07-08 19:35:536#include "ash/root_window_controller.h"
[email protected]55ad8c12014-01-17 18:24:337#include "ash/screen_util.h"
[email protected]c39be8f2012-06-15 22:58:368#include "ash/shell.h"
[email protected]e67291f12012-10-10 05:52:389#include "ash/shell_window_ids.h"
[email protected]263898a2012-09-17 17:20:0710#include "ash/system/tray/system_tray.h"
[email protected]c39be8f2012-06-15 22:58:3611#include "ash/test/ash_test_base.h"
skya6d587a62016-04-20 02:58:0512#include "ash/wm/aura/wm_window_aura.h"
13#include "ash/wm/common/root_window_finder.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"
robliaoc0dfd6b2016-04-07 21:33:5625#include "ui/display/manager/display_layout.h"
[email protected]86ccbd42013-09-18 18:11:5426#include "ui/events/event_handler.h"
[email protected]73c9fd02014-07-28 01:48:5227#include "ui/events/test/event_generator.h"
[email protected]a5e71c92012-06-22 22:09:0828#include "ui/gfx/display.h"
[email protected]718b26c2012-07-24 20:53:2329#include "ui/gfx/screen.h"
[email protected]e67291f12012-10-10 05:52:3830#include "ui/views/controls/textfield/textfield.h"
[email protected]c39be8f2012-06-15 22:58:3631#include "ui/views/widget/widget.h"
32#include "ui/views/widget/widget_delegate.h"
[email protected]af4552b22014-03-21 19:45:0133#include "ui/wm/public/activation_client.h"
[email protected]c39be8f2012-06-15 22:58:3634
35namespace ash {
36namespace {
37
robliaoc0dfd6b2016-04-07 21:33:5638void SetSecondaryDisplayLayout(display::DisplayPlacement::Position position) {
dchenga94547472016-04-08 08:41:1139 std::unique_ptr<display::DisplayLayout> layout =
oshima5df139f2016-02-17 08:56:2140 Shell::GetInstance()->display_manager()->GetCurrentDisplayLayout().Copy();
robliaodf372032016-03-23 00:42:3441 layout->placement_list[0].position = position;
oshima5df139f2016-02-17 08:56:2142 Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays(
43 std::move(layout));
[email protected]edbfb8d2012-09-03 08:33:4344}
45
[email protected]c39be8f2012-06-15 22:58:3646class ModalWidgetDelegate : public views::WidgetDelegateView {
47 public:
48 ModalWidgetDelegate() {}
dcheng1f4538e2014-10-27 23:57:0549 ~ModalWidgetDelegate() override {}
[email protected]c39be8f2012-06-15 22:58:3650
51 // Overridden from views::WidgetDelegate:
dcheng1f4538e2014-10-27 23:57:0552 views::View* GetContentsView() override { return this; }
53 ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_SYSTEM; }
[email protected]c39be8f2012-06-15 22:58:3654
55 private:
56 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate);
57};
58
[email protected]334e6182013-01-11 18:35:4159// An event handler which moves the target window to the secondary root window
[email protected]2e98aaf72012-11-08 06:30:5960// at pre-handle phase of a mouse release event.
[email protected]334e6182013-01-11 18:35:4161class MoveWindowByClickEventHandler : public ui::EventHandler {
[email protected]2e98aaf72012-11-08 06:30:5962 public:
[email protected]334e6182013-01-11 18:35:4163 explicit MoveWindowByClickEventHandler(aura::Window* target)
[email protected]2e98aaf72012-11-08 06:30:5964 : target_(target) {}
dcheng1f4538e2014-10-27 23:57:0565 ~MoveWindowByClickEventHandler() override {}
[email protected]2e98aaf72012-11-08 06:30:5966
67 private:
68 // ui::EventHandler overrides:
dcheng1f4538e2014-10-27 23:57:0569 void OnMouseEvent(ui::MouseEvent* event) override {
[email protected]2e98aaf72012-11-08 06:30:5970 if (event->type() == ui::ET_MOUSE_RELEASED) {
[email protected]c9390bd2013-11-08 20:33:1371 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]2e98aaf72012-11-08 06:30:5972 DCHECK_LT(1u, root_windows.size());
73 root_windows[1]->AddChild(target_);
74 }
[email protected]2e98aaf72012-11-08 06:30:5975 }
76
[email protected]2e98aaf72012-11-08 06:30:5977 aura::Window* target_;
[email protected]334e6182013-01-11 18:35:4178 DISALLOW_COPY_AND_ASSIGN(MoveWindowByClickEventHandler);
79};
80
81// An event handler which records the event's locations.
82class EventLocationRecordingEventHandler : public ui::EventHandler {
83 public:
84 explicit EventLocationRecordingEventHandler() {
85 reset();
86 }
dcheng1f4538e2014-10-27 23:57:0587 ~EventLocationRecordingEventHandler() override {}
[email protected]334e6182013-01-11 18:35:4188
89 std::string GetLocationsAndReset() {
90 std::string result =
91 location_.ToString() + " " + root_location_.ToString();
92 reset();
93 return result;
94 }
95
96 private:
97 // ui::EventHandler overrides:
dcheng1f4538e2014-10-27 23:57:0598 void OnMouseEvent(ui::MouseEvent* event) override {
[email protected]334e6182013-01-11 18:35:4199 if (event->type() == ui::ET_MOUSE_MOVED ||
100 event->type() == ui::ET_MOUSE_DRAGGED) {
101 location_ = event->location();
102 root_location_ = event->root_location();
103 }
104 }
105
106 void reset() {
107 location_.SetPoint(-999, -999);
108 root_location_.SetPoint(-999, -999);
109 }
110
111 gfx::Point root_location_;
112 gfx::Point location_;
113
114 DISALLOW_COPY_AND_ASSIGN(EventLocationRecordingEventHandler);
[email protected]2e98aaf72012-11-08 06:30:59115};
116
[email protected]2ca75942014-07-12 04:46:37117class EventLocationHandler : public ui::EventHandler {
118 public:
119 EventLocationHandler() {}
dcheng1f4538e2014-10-27 23:57:05120 ~EventLocationHandler() override {}
[email protected]2ca75942014-07-12 04:46:37121
122 const gfx::Point& press_location() const { return press_location_; }
123 const gfx::Point& release_location() const { return release_location_; }
124
125 private:
126 // ui::EventHandler:
dcheng1f4538e2014-10-27 23:57:05127 void OnMouseEvent(ui::MouseEvent* event) override {
[email protected]2ca75942014-07-12 04:46:37128 if (event->type() == ui::ET_MOUSE_PRESSED)
129 press_location_ = event->location();
130 else if (event->type() == ui::ET_MOUSE_RELEASED)
131 release_location_ = event->location();
132 }
133
134 gfx::Point press_location_;
135 gfx::Point release_location_;
136
137 DISALLOW_COPY_AND_ASSIGN(EventLocationHandler);
138};
139
[email protected]c39be8f2012-06-15 22:58:36140} // namespace
141
[email protected]a2e6af12013-01-07 21:40:35142class ExtendedDesktopTest : public test::AshTestBase {
143 public:
144 views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
oshima95d499b2016-02-10 03:49:56145 return CreateTestWidgetWithParentAndContext(nullptr, CurrentContext(),
146 bounds, false);
[email protected]a2e6af12013-01-07 21:40:35147 }
148
149 views::Widget* CreateTestWidgetWithParent(views::Widget* parent,
150 const gfx::Rect& bounds,
151 bool child) {
152 CHECK(parent);
oshima95d499b2016-02-10 03:49:56153 return CreateTestWidgetWithParentAndContext(parent, nullptr, bounds, child);
[email protected]a2e6af12013-01-07 21:40:35154 }
155
156 views::Widget* CreateTestWidgetWithParentAndContext(views::Widget* parent,
157 gfx::NativeView context,
158 const gfx::Rect& bounds,
159 bool child) {
160 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
161 if (parent)
162 params.parent = parent->GetNativeView();
163 params.context = context;
164 params.bounds = bounds;
165 params.child = child;
166 views::Widget* widget = new views::Widget;
167 widget->Init(params);
168 widget->Show();
169 return widget;
170 }
171};
[email protected]c39be8f2012-06-15 22:58:36172
173// Test conditions that root windows in extended desktop mode
174// must satisfy.
175TEST_F(ExtendedDesktopTest, Basic) {
[email protected]e75642a2013-06-12 17:21:18176 if (!SupportsMultipleDisplays())
177 return;
178
[email protected]f634dd32012-07-23 22:49:07179 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13180 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36181
182 // All root windows must have the root window controller.
183 ASSERT_EQ(2U, root_windows.size());
[email protected]c9390bd2013-11-08 20:33:13184 for (aura::Window::Windows::const_iterator iter = root_windows.begin();
[email protected]c39be8f2012-06-15 22:58:36185 iter != root_windows.end(); ++iter) {
oshima95d499b2016-02-10 03:49:56186 EXPECT_TRUE(GetRootWindowController(*iter) != nullptr);
[email protected]c39be8f2012-06-15 22:58:36187 }
188 // Make sure root windows share the same controllers.
[email protected]8cfb6722012-11-28 03:28:46189 EXPECT_EQ(aura::client::GetFocusClient(root_windows[0]),
190 aura::client::GetFocusClient(root_windows[1]));
[email protected]c39be8f2012-06-15 22:58:36191 EXPECT_EQ(aura::client::GetActivationClient(root_windows[0]),
192 aura::client::GetActivationClient(root_windows[1]));
193 EXPECT_EQ(aura::client::GetCaptureClient(root_windows[0]),
194 aura::client::GetCaptureClient(root_windows[1]));
195}
196
197TEST_F(ExtendedDesktopTest, Activation) {
[email protected]e75642a2013-06-12 17:21:18198 if (!SupportsMultipleDisplays())
199 return;
200
[email protected]f634dd32012-07-23 22:49:07201 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13202 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36203
[email protected]c39be8f2012-06-15 22:58:36204 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]f634dd32012-07-23 22:49:07205 views::Widget* widget_on_2nd =
206 CreateTestWidget(gfx::Rect(1200, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36207 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
[email protected]f634dd32012-07-23 22:49:07208 EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36209
210 EXPECT_EQ(widget_on_2nd->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46211 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]c39be8f2012-06-15 22:58:36212 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
213
[email protected]73c9fd02014-07-28 01:48:52214 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]f634dd32012-07-23 22:49:07215 // Clicking a window changes the active window and active root window.
[email protected]334e6182013-01-11 18:35:41216 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
217 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36218
219 EXPECT_EQ(widget_on_1st->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46220 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]c39be8f2012-06-15 22:58:36221 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]f634dd32012-07-23 22:49:07222
[email protected]334e6182013-01-11 18:35:41223 event_generator.MoveMouseToCenterOf(widget_on_2nd->GetNativeView());
224 event_generator.ClickLeftButton();
[email protected]f634dd32012-07-23 22:49:07225
226 EXPECT_EQ(widget_on_2nd->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46227 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]f634dd32012-07-23 22:49:07228 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
[email protected]c39be8f2012-06-15 22:58:36229}
230
231TEST_F(ExtendedDesktopTest, SystemModal) {
[email protected]e75642a2013-06-12 17:21:18232 if (!SupportsMultipleDisplays())
233 return;
234
[email protected]f634dd32012-07-23 22:49:07235 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13236 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36237
238 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36239 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]492533b32012-09-21 19:06:14240 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
[email protected]d17642d2013-09-12 23:44:38241 EXPECT_EQ(root_windows[0], Shell::GetTargetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36242
[email protected]c39be8f2012-06-15 22:58:36243 // Open system modal. Make sure it's on 2nd root window and active.
[email protected]a2e6af12013-01-07 21:40:35244 views::Widget* modal_widget = views::Widget::CreateWindowWithContextAndBounds(
245 new ModalWidgetDelegate(),
246 CurrentContext(),
247 gfx::Rect(1200, 100, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36248 modal_widget->Show();
249 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
250 EXPECT_EQ(root_windows[1], modal_widget->GetNativeView()->GetRootWindow());
[email protected]d17642d2013-09-12 23:44:38251 EXPECT_EQ(root_windows[1], Shell::GetTargetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36252
[email protected]73c9fd02014-07-28 01:48:52253 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41254
[email protected]2e236a52012-06-27 22:21:47255 // Clicking a widget on widget_on_1st display should not change activation.
[email protected]334e6182013-01-11 18:35:41256 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
257 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36258 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
[email protected]d17642d2013-09-12 23:44:38259 EXPECT_EQ(root_windows[1], Shell::GetTargetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36260
261 // Close system modal and so clicking a widget should work now.
262 modal_widget->Close();
[email protected]334e6182013-01-11 18:35:41263 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
264 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36265 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]d17642d2013-09-12 23:44:38266 EXPECT_EQ(root_windows[0], Shell::GetTargetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36267}
268
269TEST_F(ExtendedDesktopTest, TestCursor) {
[email protected]e75642a2013-06-12 17:21:18270 if (!SupportsMultipleDisplays())
271 return;
272
[email protected]f634dd32012-07-23 22:49:07273 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13274 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]2374d1812014-03-04 03:42:27275 aura::WindowTreeHost* host0 = root_windows[0]->GetHost();
276 aura::WindowTreeHost* host1 = root_windows[1]->GetHost();
277 EXPECT_EQ(ui::kCursorPointer, host0->last_cursor().native_type());
kylechard642dcb2016-02-22 15:50:03278 EXPECT_EQ(ui::kCursorNull, host1->last_cursor().native_type());
[email protected]151ffdff2012-09-11 20:18:35279 Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorCopy);
[email protected]2374d1812014-03-04 03:42:27280 EXPECT_EQ(ui::kCursorCopy, host0->last_cursor().native_type());
281 EXPECT_EQ(ui::kCursorCopy, host1->last_cursor().native_type());
[email protected]c39be8f2012-06-15 22:58:36282}
283
[email protected]718b26c2012-07-24 20:53:23284TEST_F(ExtendedDesktopTest, TestCursorLocation) {
[email protected]e75642a2013-06-12 17:21:18285 if (!SupportsMultipleDisplays())
286 return;
287
[email protected]d0064722013-03-14 18:16:43288 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13289 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]553eae12013-02-01 02:33:52290 aura::test::WindowTestApi root_window0_test_api(root_windows[0]);
291 aura::test::WindowTestApi root_window1_test_api(root_windows[1]);
[email protected]718b26c2012-07-24 20:53:23292
293 root_windows[0]->MoveCursorTo(gfx::Point(10, 10));
scottmge8b042972016-01-27 05:07:35294 EXPECT_EQ("10,10",
295 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23296 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
297 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
298 root_windows[1]->MoveCursorTo(gfx::Point(10, 20));
scottmge8b042972016-01-27 05:07:35299 EXPECT_EQ("1010,20",
300 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23301 EXPECT_FALSE(root_window0_test_api.ContainsMouse());
302 EXPECT_TRUE(root_window1_test_api.ContainsMouse());
303 root_windows[0]->MoveCursorTo(gfx::Point(20, 10));
scottmge8b042972016-01-27 05:07:35304 EXPECT_EQ("20,10",
305 gfx::Screen::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");
robliaoc0dfd6b2016-04-07 21:33:56315 SetSecondaryDisplayLayout(display::DisplayPlacement::LEFT);
[email protected]c9390bd2013-11-08 20:33:13316 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24317
skya6d587a62016-04-20 02:58:05318 EXPECT_EQ(root_windows[1], wm::WmWindowAura::GetAuraWindow(
319 wm::GetRootWindowAt(gfx::Point(-400, 100))));
320 EXPECT_EQ(root_windows[1], wm::WmWindowAura::GetAuraWindow(
321 wm::GetRootWindowAt(gfx::Point(-1, 100))));
322 EXPECT_EQ(root_windows[0], wm::WmWindowAura::GetAuraWindow(
323 wm::GetRootWindowAt(gfx::Point(0, 300))));
324 EXPECT_EQ(root_windows[0], wm::WmWindowAura::GetAuraWindow(
325 wm::GetRootWindowAt(gfx::Point(700, 300))));
[email protected]20c59762012-06-23 01:10:24326
327 // Zero origin.
skya6d587a62016-04-20 02:58:05328 EXPECT_EQ(root_windows[0], wm::WmWindowAura::GetAuraWindow(
329 wm::GetRootWindowAt(gfx::Point(0, 0))));
[email protected]20c59762012-06-23 01:10:24330
[email protected]36168852014-01-07 12:23:28331 // Out of range point should return the nearest root window
skya6d587a62016-04-20 02:58:05332 EXPECT_EQ(root_windows[1], wm::WmWindowAura::GetAuraWindow(
333 wm::GetRootWindowAt(gfx::Point(-600, 0))));
334 EXPECT_EQ(root_windows[0], wm::WmWindowAura::GetAuraWindow(
335 wm::GetRootWindowAt(gfx::Point(701, 100))));
[email protected]20c59762012-06-23 01:10:24336}
337
338TEST_F(ExtendedDesktopTest, GetRootWindowMatching) {
[email protected]e75642a2013-06-12 17:21:18339 if (!SupportsMultipleDisplays())
340 return;
341
[email protected]f634dd32012-07-23 22:49:07342 UpdateDisplay("700x500,500x500");
robliaoc0dfd6b2016-04-07 21:33:56343 SetSecondaryDisplayLayout(display::DisplayPlacement::LEFT);
[email protected]66b05eac2012-06-27 23:53:10344
[email protected]c9390bd2013-11-08 20:33:13345 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24346
347 // Containing rect.
348 EXPECT_EQ(root_windows[1],
skya6d587a62016-04-20 02:58:05349 wm::WmWindowAura::GetAuraWindow(
350 wm::GetRootWindowMatching(gfx::Rect(-300, 10, 50, 50))));
[email protected]20c59762012-06-23 01:10:24351 EXPECT_EQ(root_windows[0],
skya6d587a62016-04-20 02:58:05352 wm::WmWindowAura::GetAuraWindow(
353 wm::GetRootWindowMatching(gfx::Rect(100, 10, 50, 50))));
[email protected]20c59762012-06-23 01:10:24354
355 // Intersecting rect.
356 EXPECT_EQ(root_windows[1],
skya6d587a62016-04-20 02:58:05357 wm::WmWindowAura::GetAuraWindow(
358 wm::GetRootWindowMatching(gfx::Rect(-200, 0, 300, 300))));
[email protected]20c59762012-06-23 01:10:24359 EXPECT_EQ(root_windows[0],
skya6d587a62016-04-20 02:58:05360 wm::WmWindowAura::GetAuraWindow(
361 wm::GetRootWindowMatching(gfx::Rect(-100, 0, 300, 300))));
[email protected]20c59762012-06-23 01:10:24362
363 // Zero origin.
[email protected]66b05eac2012-06-27 23:53:10364 EXPECT_EQ(root_windows[0],
skya6d587a62016-04-20 02:58:05365 wm::WmWindowAura::GetAuraWindow(
366 wm::GetRootWindowMatching(gfx::Rect(0, 0, 0, 0))));
[email protected]66b05eac2012-06-27 23:53:10367 EXPECT_EQ(root_windows[0],
skya6d587a62016-04-20 02:58:05368 wm::WmWindowAura::GetAuraWindow(
369 wm::GetRootWindowMatching(gfx::Rect(0, 0, 1, 1))));
[email protected]20c59762012-06-23 01:10:24370
371 // Empty rect.
372 EXPECT_EQ(root_windows[1],
skya6d587a62016-04-20 02:58:05373 wm::WmWindowAura::GetAuraWindow(
374 wm::GetRootWindowMatching(gfx::Rect(-400, 100, 0, 0))));
[email protected]20c59762012-06-23 01:10:24375 EXPECT_EQ(root_windows[0],
skya6d587a62016-04-20 02:58:05376 wm::WmWindowAura::GetAuraWindow(
377 wm::GetRootWindowMatching(gfx::Rect(100, 100, 0, 0))));
[email protected]20c59762012-06-23 01:10:24378
379 // Out of range rect should return the primary root window.
380 EXPECT_EQ(root_windows[0],
skya6d587a62016-04-20 02:58:05381 wm::WmWindowAura::GetAuraWindow(
382 wm::GetRootWindowMatching(gfx::Rect(-600, -300, 50, 50))));
[email protected]20c59762012-06-23 01:10:24383 EXPECT_EQ(root_windows[0],
skya6d587a62016-04-20 02:58:05384 wm::WmWindowAura::GetAuraWindow(
385 wm::GetRootWindowMatching(gfx::Rect(0, 1000, 50, 50))));
[email protected]0f81f442012-06-22 06:20:27386}
387
[email protected]1a015382012-12-01 19:44:59388TEST_F(ExtendedDesktopTest, Capture) {
[email protected]e75642a2013-06-12 17:21:18389 if (!SupportsMultipleDisplays())
390 return;
391
[email protected]f634dd32012-07-23 22:49:07392 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13393 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]a5e71c92012-06-22 22:09:08394
395 aura::test::EventCountDelegate r1_d1;
396 aura::test::EventCountDelegate r1_d2;
397 aura::test::EventCountDelegate r2_d1;
398
dchenga94547472016-04-08 08:41:11399 std::unique_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]a5e71c92012-06-22 22:09:08400 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11401 std::unique_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
[email protected]a5e71c92012-06-22 22:09:08402 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11403 std::unique_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]a5e71c92012-06-22 22:09:08404 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
[email protected]f634dd32012-07-23 22:49:07405
[email protected]a5e71c92012-06-22 22:09:08406 r1_w1->SetCapture();
407
408 EXPECT_EQ(r1_w1.get(),
409 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]334e6182013-01-11 18:35:41410
[email protected]73c9fd02014-07-28 01:48:52411 ui::test::EventGenerator& generator = GetEventGenerator();
[email protected]d05cf2f2014-02-26 05:31:43412 generator.MoveMouseToCenterOf(r2_w1.get());
413 // |r1_w1| will receive the events because it has capture.
414 EXPECT_EQ("1 1 0", r1_d1.GetMouseMotionCountsAndReset());
415 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
416 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
417
418 generator.ClickLeftButton();
[email protected]a5e71c92012-06-22 22:09:08419 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
420 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
[email protected]b19ba4adf2012-09-07 16:13:29421 // The mouse is outside. On chromeos, the mouse is warped to the
422 // dest root window, but it's not implemented on Win yet, so
423 // no mouse move event on Win.
[email protected]d05cf2f2014-02-26 05:31:43424 EXPECT_EQ("0 0 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08425 EXPECT_EQ("1 1", r1_d1.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43426
427 generator.MoveMouseTo(15, 15);
[email protected]f634dd32012-07-23 22:49:07428 EXPECT_EQ("0 1 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43429 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08430
431 r1_w2->SetCapture();
432 EXPECT_EQ(r1_w2.get(),
433 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]d05cf2f2014-02-26 05:31:43434 generator.MoveMouseBy(10, 10);
435 // |r1_w2| has the capture. So it will receive the mouse-move event.
436 EXPECT_EQ("0 0 0", r1_d1.GetMouseMotionCountsAndReset());
437 EXPECT_EQ("0 1 0", r1_d2.GetMouseMotionCountsAndReset());
438 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
439
440 generator.ClickLeftButton();
[email protected]a5e71c92012-06-22 22:09:08441 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
442 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43443 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08444 EXPECT_EQ("1 1", r1_d2.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43445
[email protected]a5e71c92012-06-22 22:09:08446 r1_w2->ReleaseCapture();
oshima95d499b2016-02-10 03:49:56447 EXPECT_EQ(nullptr, aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]d05cf2f2014-02-26 05:31:43448
449 generator.MoveMouseToCenterOf(r2_w1.get());
450 generator.ClickLeftButton();
[email protected]a5e71c92012-06-22 22:09:08451 EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset());
452 EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset());
453 // Make sure the mouse_moved_handler_ is properly reset.
454 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
455 EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset());
456}
457
[email protected]2ca75942014-07-12 04:46:37458TEST_F(ExtendedDesktopTest, CaptureEventLocation) {
459 if (!SupportsMultipleDisplays())
460 return;
461
462 UpdateDisplay("1000x600,600x400");
463 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
464
465 aura::test::EventCountDelegate r1_d1;
466 aura::test::EventCountDelegate r1_d2;
467 aura::test::EventCountDelegate r2_d1;
468
dchenga94547472016-04-08 08:41:11469 std::unique_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37470 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11471 std::unique_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37472 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11473 std::unique_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37474 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
475
476 r1_w1->SetCapture();
477
[email protected]73c9fd02014-07-28 01:48:52478 ui::test::EventGenerator& generator = GetEventGenerator();
[email protected]2ca75942014-07-12 04:46:37479 generator.MoveMouseToCenterOf(r2_w1.get());
480 EXPECT_EQ(gfx::Point(1060, 60).ToString(),
481 generator.current_location().ToString());
482
483 EventLocationHandler location_handler;
484 r1_w1->AddPreTargetHandler(&location_handler);
485 generator.ClickLeftButton();
486 r1_w1->RemovePreTargetHandler(&location_handler);
487 EXPECT_EQ(gfx::Point(1050, 50).ToString(),
488 location_handler.press_location().ToString());
489 EXPECT_EQ(gfx::Point(1050, 50).ToString(),
490 location_handler.release_location().ToString());
491}
492
493TEST_F(ExtendedDesktopTest, CaptureEventLocationHighDPI) {
494 if (!SupportsMultipleDisplays())
495 return;
496
497 UpdateDisplay("1000x600*2,600x400");
498 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
499
500 aura::test::EventCountDelegate r1_d1;
501 aura::test::EventCountDelegate r1_d2;
502 aura::test::EventCountDelegate r2_d1;
503
dchenga94547472016-04-08 08:41:11504 std::unique_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37505 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11506 std::unique_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37507 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11508 std::unique_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37509 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
510
511 r1_w1->SetCapture();
512
[email protected]73c9fd02014-07-28 01:48:52513 ui::test::EventGenerator& generator = GetEventGenerator();
[email protected]2ca75942014-07-12 04:46:37514 generator.MoveMouseToCenterOf(r2_w1.get());
515 EXPECT_EQ(gfx::Point(560, 60).ToString(),
516 generator.current_location().ToString());
517
518 EventLocationHandler location_handler;
519 r1_w1->AddPreTargetHandler(&location_handler);
520 generator.ClickLeftButton();
521 r1_w1->RemovePreTargetHandler(&location_handler);
522 EXPECT_EQ(gfx::Point(550, 50).ToString(),
523 location_handler.press_location().ToString());
524 EXPECT_EQ(gfx::Point(550, 50).ToString(),
525 location_handler.release_location().ToString());
526}
527
528TEST_F(ExtendedDesktopTest, CaptureEventLocationHighDPI_2) {
529 if (!SupportsMultipleDisplays())
530 return;
531
532 UpdateDisplay("1000x600,600x400*2");
533 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
534
535 aura::test::EventCountDelegate r1_d1;
536 aura::test::EventCountDelegate r1_d2;
537 aura::test::EventCountDelegate r2_d1;
538
dchenga94547472016-04-08 08:41:11539 std::unique_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37540 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11541 std::unique_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37542 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11543 std::unique_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37544 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
545
546 r1_w1->SetCapture();
547
[email protected]73c9fd02014-07-28 01:48:52548 ui::test::EventGenerator& generator = GetEventGenerator();
[email protected]2ca75942014-07-12 04:46:37549 generator.MoveMouseToCenterOf(r2_w1.get());
550 EXPECT_EQ(gfx::Point(1060, 60).ToString(),
551 generator.current_location().ToString());
552
553 EventLocationHandler location_handler;
554 r1_w1->AddPreTargetHandler(&location_handler);
555 generator.ClickLeftButton();
556 r1_w1->RemovePreTargetHandler(&location_handler);
557 // Event-generator dispatches the event in the primary root-window's coord
558 // space. Since the location is (1060, 60), it goes to the secondary
559 // root-window as (30, 30) since the secondary root-window has a device scale
560 // factor of 2.
561 EXPECT_EQ(gfx::Point(1020, 20).ToString(),
562 location_handler.press_location().ToString());
563 EXPECT_EQ(gfx::Point(1020, 20).ToString(),
564 location_handler.release_location().ToString());
565}
566
[email protected]f059c6942012-07-21 14:27:57567TEST_F(ExtendedDesktopTest, MoveWindow) {
[email protected]e75642a2013-06-12 17:21:18568 if (!SupportsMultipleDisplays())
569 return;
570
[email protected]f634dd32012-07-23 22:49:07571 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13572 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]f059c6942012-07-21 14:27:57573 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
574
575 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
576
577 d1->SetBounds(gfx::Rect(1010, 10, 100, 100));
578 EXPECT_EQ("1010,10 100x100",
579 d1->GetWindowBoundsInScreen().ToString());
580
581 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
582
583 d1->SetBounds(gfx::Rect(10, 10, 100, 100));
584 EXPECT_EQ("10,10 100x100",
585 d1->GetWindowBoundsInScreen().ToString());
586
587 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
588
589 // Make sure the bounds which doesn't fit to the root window
590 // works correctly.
591 d1->SetBounds(gfx::Rect(1560, 30, 100, 100));
592 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
593 EXPECT_EQ("1560,30 100x100",
594 d1->GetWindowBoundsInScreen().ToString());
595
596 // Setting outside of root windows will be moved to primary root window.
597 // TODO(oshima): This one probably should pick the closest root window.
598 d1->SetBounds(gfx::Rect(200, 10, 100, 100));
599 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
[email protected]f059c6942012-07-21 14:27:57600}
601
[email protected]2e98aaf72012-11-08 06:30:59602// Verifies if the mouse event arrives to the window even when the window
603// moves to another root in a pre-target handler. See: crbug.com/157583
604TEST_F(ExtendedDesktopTest, MoveWindowByMouseClick) {
[email protected]e75642a2013-06-12 17:21:18605 if (!SupportsMultipleDisplays())
606 return;
607
[email protected]2e98aaf72012-11-08 06:30:59608 UpdateDisplay("1000x600,600x400");
609
[email protected]c9390bd2013-11-08 20:33:13610 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]2e98aaf72012-11-08 06:30:59611 aura::test::EventCountDelegate delegate;
dchenga94547472016-04-08 08:41:11612 std::unique_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate(
[email protected]2e98aaf72012-11-08 06:30:59613 &delegate, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
[email protected]334e6182013-01-11 18:35:41614 MoveWindowByClickEventHandler event_handler(window.get());
615 window->AddPreTargetHandler(&event_handler);
616
[email protected]73c9fd02014-07-28 01:48:52617 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41618
619 event_generator.MoveMouseToCenterOf(window.get());
620 event_generator.ClickLeftButton();
[email protected]2e98aaf72012-11-08 06:30:59621 // Both mouse pressed and released arrive at the window and its delegate.
622 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset());
[email protected]334e6182013-01-11 18:35:41623 // Also event_handler moves the window to another root at mouse release.
[email protected]2e98aaf72012-11-08 06:30:59624 EXPECT_EQ(root_windows[1], window->GetRootWindow());
625}
626
[email protected]1a015382012-12-01 19:44:59627TEST_F(ExtendedDesktopTest, MoveWindowToDisplay) {
[email protected]e75642a2013-06-12 17:21:18628 if (!SupportsMultipleDisplays())
629 return;
630
[email protected]e79f26e2012-08-09 07:12:48631 UpdateDisplay("1000x1000,1000x1000");
[email protected]c9390bd2013-11-08 20:33:13632 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]e79f26e2012-08-09 07:12:48633
scottmge8b042972016-01-27 05:07:35634 gfx::Display display0 = gfx::Screen::GetScreen()->GetDisplayMatching(
[email protected]ffabb1e2012-10-12 19:51:17635 root_windows[0]->GetBoundsInScreen());
scottmge8b042972016-01-27 05:07:35636 gfx::Display display1 = gfx::Screen::GetScreen()->GetDisplayMatching(
[email protected]ffabb1e2012-10-12 19:51:17637 root_windows[1]->GetBoundsInScreen());
[email protected]e79f26e2012-08-09 07:12:48638 EXPECT_NE(display0.id(), display1.id());
639
640 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 1000, 100));
641 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
642
643 // Move the window where the window spans both root windows. Since the second
644 // parameter is |display1|, the window should be shown on the secondary root.
645 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
646 display1);
647 EXPECT_EQ("500,10 1000x100",
648 d1->GetWindowBoundsInScreen().ToString());
649 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
650
651 // Move to the primary root.
652 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
653 display0);
654 EXPECT_EQ("500,10 1000x100",
655 d1->GetWindowBoundsInScreen().ToString());
656 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
657}
658
[email protected]f059c6942012-07-21 14:27:57659TEST_F(ExtendedDesktopTest, MoveWindowWithTransient) {
[email protected]e75642a2013-06-12 17:21:18660 if (!SupportsMultipleDisplays())
661 return;
662
[email protected]f634dd32012-07-23 22:49:07663 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13664 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]f059c6942012-07-21 14:27:57665 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
666 views::Widget* w1_t1 = CreateTestWidgetWithParent(
667 w1, gfx::Rect(50, 50, 50, 50), false /* transient */);
668 // Transient child of the transient child.
669 views::Widget* w1_t11 = CreateTestWidgetWithParent(
[email protected]e6de8552014-05-23 19:05:39670 w1_t1, gfx::Rect(1200, 70, 35, 35), false /* transient */);
[email protected]f059c6942012-07-21 14:27:57671
672 views::Widget* w11 = CreateTestWidgetWithParent(
673 w1, gfx::Rect(10, 10, 40, 40), true /* child */);
674 views::Widget* w11_t1 = CreateTestWidgetWithParent(
675 w1, gfx::Rect(1300, 100, 80, 80), false /* transient */);
676
677 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
678 EXPECT_EQ(root_windows[0], w11->GetNativeView()->GetRootWindow());
679 EXPECT_EQ(root_windows[0], w1_t1->GetNativeView()->GetRootWindow());
680 EXPECT_EQ(root_windows[0], w1_t11->GetNativeView()->GetRootWindow());
681 EXPECT_EQ(root_windows[0], w11_t1->GetNativeView()->GetRootWindow());
682 EXPECT_EQ("50,50 50x50",
683 w1_t1->GetWindowBoundsInScreen().ToString());
[email protected]e6de8552014-05-23 19:05:39684 EXPECT_EQ("1200,70 35x35",
[email protected]f059c6942012-07-21 14:27:57685 w1_t11->GetWindowBoundsInScreen().ToString());
686 EXPECT_EQ("20,20 40x40",
687 w11->GetWindowBoundsInScreen().ToString());
688 EXPECT_EQ("1300,100 80x80",
689 w11_t1->GetWindowBoundsInScreen().ToString());
690
[email protected]24f5e242014-07-22 02:16:09691 w1->SetBounds(gfx::Rect(1100, 10, 100, 100));
[email protected]f059c6942012-07-21 14:27:57692
693 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
694 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
695 EXPECT_EQ(root_windows[1], w1_t11->GetNativeView()->GetRootWindow());
696 EXPECT_EQ(root_windows[1], w11->GetNativeView()->GetRootWindow());
697 EXPECT_EQ(root_windows[1], w11_t1->GetNativeView()->GetRootWindow());
698
699 EXPECT_EQ("1110,20 40x40",
700 w11->GetWindowBoundsInScreen().ToString());
701 // Transient window's screen bounds stays the same.
702 EXPECT_EQ("50,50 50x50",
703 w1_t1->GetWindowBoundsInScreen().ToString());
[email protected]e6de8552014-05-23 19:05:39704 EXPECT_EQ("1200,70 35x35",
[email protected]f059c6942012-07-21 14:27:57705 w1_t11->GetWindowBoundsInScreen().ToString());
706 EXPECT_EQ("1300,100 80x80",
707 w11_t1->GetWindowBoundsInScreen().ToString());
708
709 // Transient window doesn't move between root window unless
710 // its transient parent moves.
711 w1_t1->SetBounds(gfx::Rect(10, 50, 50, 50));
712 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
713 EXPECT_EQ("10,50 50x50",
714 w1_t1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57715}
716
[email protected]ca7060982012-08-08 18:05:25717// Test if the Window::ConvertPointToTarget works across root windows.
[email protected]a5e71c92012-06-22 22:09:08718// TODO(oshima): Move multiple display suport and this test to aura.
719TEST_F(ExtendedDesktopTest, ConvertPoint) {
[email protected]e75642a2013-06-12 17:21:18720 if (!SupportsMultipleDisplays())
721 return;
scottmge8b042972016-01-27 05:07:35722 gfx::Screen* screen = gfx::Screen::GetScreen();
[email protected]f634dd32012-07-23 22:49:07723 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13724 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]b8984242013-07-12 07:55:38725 gfx::Display display_1 = screen->GetDisplayNearestWindow(root_windows[0]);
[email protected]a5e71c92012-06-22 22:09:08726 EXPECT_EQ("0,0", display_1.bounds().origin().ToString());
[email protected]b8984242013-07-12 07:55:38727 gfx::Display display_2 = screen->GetDisplayNearestWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07728 EXPECT_EQ("1000,0", display_2.bounds().origin().ToString());
729
[email protected]a5e71c92012-06-22 22:09:08730 aura::Window* d1 =
731 CreateTestWidget(gfx::Rect(10, 10, 100, 100))->GetNativeView();
[email protected]a5e71c92012-06-22 22:09:08732 aura::Window* d2 =
[email protected]f634dd32012-07-23 22:49:07733 CreateTestWidget(gfx::Rect(1020, 20, 100, 100))->GetNativeView();
734 EXPECT_EQ(root_windows[0], d1->GetRootWindow());
735 EXPECT_EQ(root_windows[1], d2->GetRootWindow());
[email protected]a5e71c92012-06-22 22:09:08736
[email protected]a5e71c92012-06-22 22:09:08737 // Convert point in the Root2's window to the Root1's window Coord.
738 gfx::Point p(0, 0);
[email protected]ca7060982012-08-08 18:05:25739 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07740 EXPECT_EQ("1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08741 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25742 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07743 EXPECT_EQ("1010,10", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08744
745 // Convert point in the Root1's window to the Root2's window Coord.
746 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25747 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07748 EXPECT_EQ("-1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08749 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25750 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07751 EXPECT_EQ("-1010,-10", p.ToString());
752
753 // Move the 2nd display to the bottom and test again.
robliaoc0dfd6b2016-04-07 21:33:56754 SetSecondaryDisplayLayout(display::DisplayPlacement::BOTTOM);
[email protected]f634dd32012-07-23 22:49:07755
[email protected]b8984242013-07-12 07:55:38756 display_2 = screen->GetDisplayNearestWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07757 EXPECT_EQ("0,600", display_2.bounds().origin().ToString());
758
759 // Convert point in Root2's window to Root1's window Coord.
760 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25761 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07762 EXPECT_EQ("0,600", p.ToString());
763 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25764 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07765 EXPECT_EQ("10,610", p.ToString());
766
767 // Convert point in Root1's window to Root2's window Coord.
768 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25769 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07770 EXPECT_EQ("0,-600", p.ToString());
771 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25772 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07773 EXPECT_EQ("-10,-610", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08774}
[email protected]f634dd32012-07-23 22:49:07775
[email protected]263898a2012-09-17 17:20:07776TEST_F(ExtendedDesktopTest, OpenSystemTray) {
[email protected]e75642a2013-06-12 17:21:18777 if (!SupportsMultipleDisplays())
778 return;
779
[email protected]596c61c2012-10-29 17:29:43780 UpdateDisplay("500x600,600x400");
[email protected]a0afeb12012-12-10 22:57:09781 SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray();
[email protected]263898a2012-09-17 17:20:07782 ASSERT_FALSE(tray->HasSystemBubble());
783
[email protected]73c9fd02014-07-28 01:48:52784 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41785
[email protected]263898a2012-09-17 17:20:07786 // Opens the tray by a dummy click event and makes sure that adding/removing
787 // displays doesn't break anything.
[email protected]334e6182013-01-11 18:35:41788 event_generator.MoveMouseToCenterOf(tray->GetWidget()->GetNativeWindow());
[email protected]263898a2012-09-17 17:20:07789 event_generator.ClickLeftButton();
790 EXPECT_TRUE(tray->HasSystemBubble());
791
[email protected]596c61c2012-10-29 17:29:43792 UpdateDisplay("500x600");
[email protected]263898a2012-09-17 17:20:07793 EXPECT_TRUE(tray->HasSystemBubble());
[email protected]596c61c2012-10-29 17:29:43794 UpdateDisplay("500x600,600x400");
[email protected]263898a2012-09-17 17:20:07795 EXPECT_TRUE(tray->HasSystemBubble());
796
797 // Closes the tray and again makes sure that adding/removing displays doesn't
798 // break anything.
799 event_generator.ClickLeftButton();
800 RunAllPendingInMessageLoop();
801
802 EXPECT_FALSE(tray->HasSystemBubble());
803
[email protected]596c61c2012-10-29 17:29:43804 UpdateDisplay("500x600");
[email protected]263898a2012-09-17 17:20:07805 EXPECT_FALSE(tray->HasSystemBubble());
[email protected]596c61c2012-10-29 17:29:43806 UpdateDisplay("500x600,600x400");
[email protected]263898a2012-09-17 17:20:07807 EXPECT_FALSE(tray->HasSystemBubble());
808}
809
[email protected]578048512012-09-19 20:01:24810TEST_F(ExtendedDesktopTest, StayInSameRootWindow) {
[email protected]e75642a2013-06-12 17:21:18811 if (!SupportsMultipleDisplays())
812 return;
813
[email protected]578048512012-09-19 20:01:24814 UpdateDisplay("100x100,200x200");
[email protected]c9390bd2013-11-08 20:33:13815 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]a2e6af12013-01-07 21:40:35816 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 50, 50));
[email protected]578048512012-09-19 20:01:24817 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
818 w1->SetBounds(gfx::Rect(150, 10, 50, 50));
819 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
820
821 // The widget stays in the same root if kStayInSameRootWindowKey is set to
822 // true.
[email protected]093b8d642014-04-03 20:59:28823 w1->GetNativeView()->SetProperty(kStayInSameRootWindowKey, true);
[email protected]578048512012-09-19 20:01:24824 w1->SetBounds(gfx::Rect(10, 10, 50, 50));
825 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
826
827 // The widget should now move to the 1st root window without the property.
[email protected]093b8d642014-04-03 20:59:28828 w1->GetNativeView()->ClearProperty(kStayInSameRootWindowKey);
[email protected]578048512012-09-19 20:01:24829 w1->SetBounds(gfx::Rect(10, 10, 50, 50));
830 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
[email protected]e887c6c2013-07-08 19:35:53831
832 // a window in SettingsBubbleContainer and StatusContainer should
833 // not move to another root window regardles of the bounds specified.
834 aura::Window* settings_bubble_container =
835 Shell::GetPrimaryRootWindowController()->GetContainer(
[email protected]093b8d642014-04-03 20:59:28836 kShellWindowId_SettingBubbleContainer);
[email protected]e887c6c2013-07-08 19:35:53837 aura::Window* window = aura::test::CreateTestWindowWithId(
838 100, settings_bubble_container);
839 window->SetBoundsInScreen(gfx::Rect(150, 10, 50, 50),
[email protected]55ad8c12014-01-17 18:24:33840 ScreenUtil::GetSecondaryDisplay());
[email protected]e887c6c2013-07-08 19:35:53841 EXPECT_EQ(root_windows[0], window->GetRootWindow());
842
843 aura::Window* status_container =
844 Shell::GetPrimaryRootWindowController()->GetContainer(
[email protected]093b8d642014-04-03 20:59:28845 kShellWindowId_StatusContainer);
[email protected]e887c6c2013-07-08 19:35:53846 window = aura::test::CreateTestWindowWithId(100, status_container);
847 window->SetBoundsInScreen(gfx::Rect(150, 10, 50, 50),
[email protected]55ad8c12014-01-17 18:24:33848 ScreenUtil::GetSecondaryDisplay());
[email protected]e887c6c2013-07-08 19:35:53849 EXPECT_EQ(root_windows[0], window->GetRootWindow());
[email protected]578048512012-09-19 20:01:24850}
851
[email protected]e67291f12012-10-10 05:52:38852TEST_F(ExtendedDesktopTest, KeyEventsOnLockScreen) {
[email protected]e75642a2013-06-12 17:21:18853 if (!SupportsMultipleDisplays())
854 return;
855
[email protected]e67291f12012-10-10 05:52:38856 UpdateDisplay("100x100,200x200");
[email protected]c9390bd2013-11-08 20:33:13857 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]e67291f12012-10-10 05:52:38858
859 // Create normal windows on both displays.
scottmge8b042972016-01-27 05:07:35860 views::Widget* widget1 =
861 CreateTestWidget(gfx::Screen::GetScreen()->GetPrimaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38862 widget1->Show();
863 EXPECT_EQ(root_windows[0], widget1->GetNativeView()->GetRootWindow());
864 views::Widget* widget2 = CreateTestWidget(
[email protected]55ad8c12014-01-17 18:24:33865 ScreenUtil::GetSecondaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38866 widget2->Show();
867 EXPECT_EQ(root_windows[1], widget2->GetNativeView()->GetRootWindow());
868
869 // Create a LockScreen window.
scottmge8b042972016-01-27 05:07:35870 views::Widget* lock_widget =
871 CreateTestWidget(gfx::Screen::GetScreen()->GetPrimaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38872 views::Textfield* textfield = new views::Textfield;
[email protected]09148952013-03-13 13:25:43873 lock_widget->client_view()->AddChildView(textfield);
[email protected]e67291f12012-10-10 05:52:38874
[email protected]093b8d642014-04-03 20:59:28875 ash::Shell::GetContainer(Shell::GetPrimaryRootWindow(),
876 ash::kShellWindowId_LockScreenContainer)
877 ->AddChild(lock_widget->GetNativeView());
[email protected]e67291f12012-10-10 05:52:38878 lock_widget->Show();
879 textfield->RequestFocus();
880
[email protected]8cfb6722012-11-28 03:28:46881 aura::client::FocusClient* focus_client =
882 aura::client::GetFocusClient(root_windows[0]);
883 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]e67291f12012-10-10 05:52:38884
885 // The lock window should get events on both root windows.
[email protected]73c9fd02014-07-28 01:48:52886 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41887
[email protected]1ea46f6f2014-07-17 07:36:40888 event_generator.set_current_target(root_windows[0]);
[email protected]334e6182013-01-11 18:35:41889 event_generator.PressKey(ui::VKEY_A, 0);
890 event_generator.ReleaseKey(ui::VKEY_A, 0);
[email protected]8cfb6722012-11-28 03:28:46891 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46892 EXPECT_EQ("a", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38893
[email protected]1ea46f6f2014-07-17 07:36:40894 event_generator.set_current_target(root_windows[1]);
[email protected]334e6182013-01-11 18:35:41895 event_generator.PressKey(ui::VKEY_B, 0);
896 event_generator.ReleaseKey(ui::VKEY_B, 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("ab", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38899
900 // Deleting 2nd display. The lock window still should get the events.
901 UpdateDisplay("100x100");
pkotwicz5d118a6b12015-02-12 22:23:57902 event_generator.set_current_target(root_windows[0]);
[email protected]334e6182013-01-11 18:35:41903 event_generator.PressKey(ui::VKEY_C, 0);
904 event_generator.ReleaseKey(ui::VKEY_C, 0);
[email protected]8cfb6722012-11-28 03:28:46905 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46906 EXPECT_EQ("abc", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38907
908 // Creating 2nd display again, and lock window still should get events
909 // on both root windows.
910 UpdateDisplay("100x100,200x200");
911 root_windows = Shell::GetAllRootWindows();
[email protected]1ea46f6f2014-07-17 07:36:40912 event_generator.set_current_target(root_windows[0]);
[email protected]334e6182013-01-11 18:35:41913 event_generator.PressKey(ui::VKEY_D, 0);
914 event_generator.ReleaseKey(ui::VKEY_D, 0);
[email protected]8cfb6722012-11-28 03:28:46915 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46916 EXPECT_EQ("abcd", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38917
[email protected]1ea46f6f2014-07-17 07:36:40918 event_generator.set_current_target(root_windows[1]);
[email protected]334e6182013-01-11 18:35:41919 event_generator.PressKey(ui::VKEY_E, 0);
920 event_generator.ReleaseKey(ui::VKEY_E, 0);
[email protected]8cfb6722012-11-28 03:28:46921 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46922 EXPECT_EQ("abcde", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38923}
924
[email protected]334e6182013-01-11 18:35:41925TEST_F(ExtendedDesktopTest, PassiveGrab) {
[email protected]e75642a2013-06-12 17:21:18926 if (!SupportsMultipleDisplays())
927 return;
928
[email protected]334e6182013-01-11 18:35:41929 EventLocationRecordingEventHandler event_handler;
930 ash::Shell::GetInstance()->AddPreTargetHandler(&event_handler);
931
932 UpdateDisplay("300x300,200x200");
933
934 views::Widget* widget = CreateTestWidget(gfx::Rect(50, 50, 200, 200));
935 widget->Show();
936 ASSERT_EQ("50,50 200x200", widget->GetWindowBoundsInScreen().ToString());
937
[email protected]73c9fd02014-07-28 01:48:52938 ui::test::EventGenerator& generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41939 generator.MoveMouseTo(150, 150);
940 EXPECT_EQ("100,100 150,150", event_handler.GetLocationsAndReset());
941
942 generator.PressLeftButton();
943 generator.MoveMouseTo(400, 150);
944
945 EXPECT_EQ("350,100 400,150", event_handler.GetLocationsAndReset());
946
947 generator.ReleaseLeftButton();
948 EXPECT_EQ("-999,-999 -999,-999", event_handler.GetLocationsAndReset());
949
950 generator.MoveMouseTo(400, 150);
951 EXPECT_EQ("100,150 100,150", event_handler.GetLocationsAndReset());
952
953 ash::Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
954}
955
[email protected]c39be8f2012-06-15 22:58:36956} // namespace ash