blob: 0188cf3f7d5fa106a1fbf13e27c9ce6110e76adc [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
jamescook8800b8232016-10-19 12:46:275#include "ash/public/cpp/shell_window_ids.h"
[email protected]e887c6c2013-07-08 19:35:536#include "ash/root_window_controller.h"
[email protected]c39be8f2012-06-15 22:58:367#include "ash/shell.h"
James Cookb0bf8e82017-04-09 17:01:448#include "ash/system/tray/system_tray.h"
[email protected]c39be8f2012-06-15 22:58:369#include "ash/test/ash_test_base.h"
James Cookb0bf8e82017-04-09 17:01:4410#include "ash/wm/root_window_finder.h"
[email protected]578048512012-09-19 20:01:2411#include "ash/wm/window_properties.h"
[email protected]c39be8f2012-06-15 22:58:3612#include "ash/wm/window_util.h"
[email protected]0836da02013-06-10 19:33:3513#include "base/strings/string_util.h"
[email protected]74f778e2014-03-14 21:11:4614#include "base/strings/utf_string_conversions.h"
[email protected]c39be8f2012-06-15 22:58:3615#include "ui/aura/client/capture_client.h"
[email protected]8cfb6722012-11-28 03:28:4616#include "ui/aura/client/focus_client.h"
[email protected]a5e71c92012-06-22 22:09:0817#include "ui/aura/test/test_windows.h"
[email protected]553eae12013-02-01 02:33:5218#include "ui/aura/test/window_test_api.h"
[email protected]c39be8f2012-06-15 22:58:3619#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:2620#include "ui/aura/window_event_dispatcher.h"
[email protected]c39be8f2012-06-15 22:58:3621#include "ui/base/cursor/cursor.h"
oshimaf84b0da722016-04-27 19:47:1922#include "ui/display/display.h"
kylechar731f85f92016-12-01 20:50:4623#include "ui/display/display_layout.h"
rjkroege72f8154f2016-10-29 00:49:0224#include "ui/display/manager/display_manager.h"
oshimaf84b0da722016-04-27 19:47:1925#include "ui/display/screen.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]e67291f12012-10-10 05:52:3828#include "ui/views/controls/textfield/textfield.h"
[email protected]c39be8f2012-06-15 22:58:3629#include "ui/views/widget/widget.h"
30#include "ui/views/widget/widget_delegate.h"
[email protected]af4552b22014-03-21 19:45:0131#include "ui/wm/public/activation_client.h"
[email protected]c39be8f2012-06-15 22:58:3632
33namespace ash {
34namespace {
35
robliaoc0dfd6b2016-04-07 21:33:5636void SetSecondaryDisplayLayout(display::DisplayPlacement::Position position) {
dchenga94547472016-04-08 08:41:1137 std::unique_ptr<display::DisplayLayout> layout =
skycb4be5b2017-04-06 17:52:4538 Shell::Get()->display_manager()->GetCurrentDisplayLayout().Copy();
robliaodf372032016-03-23 00:42:3439 layout->placement_list[0].position = position;
skycb4be5b2017-04-06 17:52:4540 Shell::Get()->display_manager()->SetLayoutForCurrentDisplays(
oshima5df139f2016-02-17 08:56:2141 std::move(layout));
[email protected]edbfb8d2012-09-03 08:33:4342}
43
[email protected]c39be8f2012-06-15 22:58:3644class ModalWidgetDelegate : public views::WidgetDelegateView {
45 public:
Chris Watkinsc24daf62017-11-28 03:43:0946 ModalWidgetDelegate() = default;
47 ~ModalWidgetDelegate() override = default;
[email protected]c39be8f2012-06-15 22:58:3648
49 // Overridden from views::WidgetDelegate:
dcheng1f4538e2014-10-27 23:57:0550 ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_SYSTEM; }
[email protected]c39be8f2012-06-15 22:58:3651
52 private:
53 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate);
54};
55
[email protected]334e6182013-01-11 18:35:4156// An event handler which moves the target window to the secondary root window
[email protected]2e98aaf72012-11-08 06:30:5957// at pre-handle phase of a mouse release event.
[email protected]334e6182013-01-11 18:35:4158class MoveWindowByClickEventHandler : public ui::EventHandler {
[email protected]2e98aaf72012-11-08 06:30:5959 public:
[email protected]334e6182013-01-11 18:35:4160 explicit MoveWindowByClickEventHandler(aura::Window* target)
[email protected]2e98aaf72012-11-08 06:30:5961 : target_(target) {}
Chris Watkinsc24daf62017-11-28 03:43:0962 ~MoveWindowByClickEventHandler() override = default;
[email protected]2e98aaf72012-11-08 06:30:5963
64 private:
65 // ui::EventHandler overrides:
dcheng1f4538e2014-10-27 23:57:0566 void OnMouseEvent(ui::MouseEvent* event) override {
[email protected]2e98aaf72012-11-08 06:30:5967 if (event->type() == ui::ET_MOUSE_RELEASED) {
[email protected]c9390bd2013-11-08 20:33:1368 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]2e98aaf72012-11-08 06:30:5969 DCHECK_LT(1u, root_windows.size());
70 root_windows[1]->AddChild(target_);
71 }
[email protected]2e98aaf72012-11-08 06:30:5972 }
73
[email protected]2e98aaf72012-11-08 06:30:5974 aura::Window* target_;
[email protected]334e6182013-01-11 18:35:4175 DISALLOW_COPY_AND_ASSIGN(MoveWindowByClickEventHandler);
76};
77
78// An event handler which records the event's locations.
79class EventLocationRecordingEventHandler : public ui::EventHandler {
80 public:
jamescookb8dcef522016-06-25 14:42:5581 explicit EventLocationRecordingEventHandler() { reset(); }
Chris Watkinsc24daf62017-11-28 03:43:0982 ~EventLocationRecordingEventHandler() override = default;
[email protected]334e6182013-01-11 18:35:4183
84 std::string GetLocationsAndReset() {
jamescookb8dcef522016-06-25 14:42:5585 std::string result = location_.ToString() + " " + root_location_.ToString();
[email protected]334e6182013-01-11 18:35:4186 reset();
87 return result;
88 }
89
90 private:
91 // ui::EventHandler overrides:
dcheng1f4538e2014-10-27 23:57:0592 void OnMouseEvent(ui::MouseEvent* event) override {
[email protected]334e6182013-01-11 18:35:4193 if (event->type() == ui::ET_MOUSE_MOVED ||
94 event->type() == ui::ET_MOUSE_DRAGGED) {
95 location_ = event->location();
96 root_location_ = event->root_location();
97 }
98 }
99
100 void reset() {
101 location_.SetPoint(-999, -999);
102 root_location_.SetPoint(-999, -999);
103 }
104
105 gfx::Point root_location_;
106 gfx::Point location_;
107
108 DISALLOW_COPY_AND_ASSIGN(EventLocationRecordingEventHandler);
[email protected]2e98aaf72012-11-08 06:30:59109};
110
[email protected]2ca75942014-07-12 04:46:37111class EventLocationHandler : public ui::EventHandler {
112 public:
Chris Watkinsc24daf62017-11-28 03:43:09113 EventLocationHandler() = default;
114 ~EventLocationHandler() override = default;
[email protected]2ca75942014-07-12 04:46:37115
116 const gfx::Point& press_location() const { return press_location_; }
117 const gfx::Point& release_location() const { return release_location_; }
118
119 private:
120 // ui::EventHandler:
dcheng1f4538e2014-10-27 23:57:05121 void OnMouseEvent(ui::MouseEvent* event) override {
[email protected]2ca75942014-07-12 04:46:37122 if (event->type() == ui::ET_MOUSE_PRESSED)
123 press_location_ = event->location();
124 else if (event->type() == ui::ET_MOUSE_RELEASED)
125 release_location_ = event->location();
126 }
127
128 gfx::Point press_location_;
129 gfx::Point release_location_;
130
131 DISALLOW_COPY_AND_ASSIGN(EventLocationHandler);
132};
133
[email protected]c39be8f2012-06-15 22:58:36134} // namespace
135
James Cook317781a2017-07-18 02:08:06136class ExtendedDesktopTest : public AshTestBase {
[email protected]a2e6af12013-01-07 21:40:35137 public:
138 views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
oshima95d499b2016-02-10 03:49:56139 return CreateTestWidgetWithParentAndContext(nullptr, CurrentContext(),
140 bounds, false);
[email protected]a2e6af12013-01-07 21:40:35141 }
142
143 views::Widget* CreateTestWidgetWithParent(views::Widget* parent,
144 const gfx::Rect& bounds,
145 bool child) {
146 CHECK(parent);
oshima95d499b2016-02-10 03:49:56147 return CreateTestWidgetWithParentAndContext(parent, nullptr, bounds, child);
[email protected]a2e6af12013-01-07 21:40:35148 }
149
150 views::Widget* CreateTestWidgetWithParentAndContext(views::Widget* parent,
151 gfx::NativeView context,
152 const gfx::Rect& bounds,
153 bool child) {
154 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
155 if (parent)
156 params.parent = parent->GetNativeView();
157 params.context = context;
158 params.bounds = bounds;
159 params.child = child;
160 views::Widget* widget = new views::Widget;
161 widget->Init(params);
162 widget->Show();
163 return widget;
164 }
165};
[email protected]c39be8f2012-06-15 22:58:36166
msw257a6a232017-06-01 01:46:30167// Test conditions that root windows in extended desktop mode must satisfy.
[email protected]c39be8f2012-06-15 22:58:36168TEST_F(ExtendedDesktopTest, Basic) {
[email protected]f634dd32012-07-23 22:49:07169 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13170 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36171
msw257a6a232017-06-01 01:46:30172 // All root windows must have a root window controller.
[email protected]c39be8f2012-06-15 22:58:36173 ASSERT_EQ(2U, root_windows.size());
msw257a6a232017-06-01 01:46:30174 EXPECT_TRUE(RootWindowController::ForWindow(root_windows[0]));
175 EXPECT_TRUE(RootWindowController::ForWindow(root_windows[1]));
[email protected]c39be8f2012-06-15 22:58:36176 // Make sure root windows share the same controllers.
[email protected]8cfb6722012-11-28 03:28:46177 EXPECT_EQ(aura::client::GetFocusClient(root_windows[0]),
178 aura::client::GetFocusClient(root_windows[1]));
Thiago Farina3b086a02017-05-30 22:32:50179 EXPECT_EQ(::wm::GetActivationClient(root_windows[0]),
180 ::wm::GetActivationClient(root_windows[1]));
[email protected]c39be8f2012-06-15 22:58:36181 EXPECT_EQ(aura::client::GetCaptureClient(root_windows[0]),
182 aura::client::GetCaptureClient(root_windows[1]));
183}
184
185TEST_F(ExtendedDesktopTest, Activation) {
[email protected]f634dd32012-07-23 22:49:07186 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13187 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36188
[email protected]c39be8f2012-06-15 22:58:36189 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]f634dd32012-07-23 22:49:07190 views::Widget* widget_on_2nd =
191 CreateTestWidget(gfx::Rect(1200, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36192 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
[email protected]f634dd32012-07-23 22:49:07193 EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36194
195 EXPECT_EQ(widget_on_2nd->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46196 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]c39be8f2012-06-15 22:58:36197 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
198
[email protected]73c9fd02014-07-28 01:48:52199 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]f634dd32012-07-23 22:49:07200 // Clicking a window changes the active window and active root window.
[email protected]334e6182013-01-11 18:35:41201 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
202 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36203
204 EXPECT_EQ(widget_on_1st->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46205 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]c39be8f2012-06-15 22:58:36206 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]f634dd32012-07-23 22:49:07207
[email protected]334e6182013-01-11 18:35:41208 event_generator.MoveMouseToCenterOf(widget_on_2nd->GetNativeView());
209 event_generator.ClickLeftButton();
[email protected]f634dd32012-07-23 22:49:07210
211 EXPECT_EQ(widget_on_2nd->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46212 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]f634dd32012-07-23 22:49:07213 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
[email protected]c39be8f2012-06-15 22:58:36214}
215
216TEST_F(ExtendedDesktopTest, SystemModal) {
[email protected]f634dd32012-07-23 22:49:07217 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13218 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36219
220 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36221 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]492533b32012-09-21 19:06:14222 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
sky27344382017-03-08 21:30:32223 EXPECT_EQ(root_windows[0], Shell::GetRootWindowForNewWindows());
[email protected]c39be8f2012-06-15 22:58:36224
[email protected]c39be8f2012-06-15 22:58:36225 // Open system modal. Make sure it's on 2nd root window and active.
[email protected]a2e6af12013-01-07 21:40:35226 views::Widget* modal_widget = views::Widget::CreateWindowWithContextAndBounds(
jamescookb8dcef522016-06-25 14:42:55227 new ModalWidgetDelegate(), CurrentContext(),
[email protected]a2e6af12013-01-07 21:40:35228 gfx::Rect(1200, 100, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36229 modal_widget->Show();
230 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
231 EXPECT_EQ(root_windows[1], modal_widget->GetNativeView()->GetRootWindow());
sky27344382017-03-08 21:30:32232 EXPECT_EQ(root_windows[1], Shell::GetRootWindowForNewWindows());
[email protected]c39be8f2012-06-15 22:58:36233
[email protected]73c9fd02014-07-28 01:48:52234 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41235
[email protected]2e236a52012-06-27 22:21:47236 // Clicking a widget on widget_on_1st display should not change activation.
[email protected]334e6182013-01-11 18:35:41237 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
238 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36239 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
sky27344382017-03-08 21:30:32240 EXPECT_EQ(root_windows[1], Shell::GetRootWindowForNewWindows());
[email protected]c39be8f2012-06-15 22:58:36241
242 // Close system modal and so clicking a widget should work now.
243 modal_widget->Close();
[email protected]334e6182013-01-11 18:35:41244 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
245 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36246 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
sky27344382017-03-08 21:30:32247 EXPECT_EQ(root_windows[0], Shell::GetRootWindowForNewWindows());
[email protected]c39be8f2012-06-15 22:58:36248}
249
250TEST_F(ExtendedDesktopTest, TestCursor) {
[email protected]f634dd32012-07-23 22:49:07251 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13252 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]2374d1812014-03-04 03:42:27253 aura::WindowTreeHost* host0 = root_windows[0]->GetHost();
254 aura::WindowTreeHost* host1 = root_windows[1]->GetHost();
ergeeba7c622017-04-25 18:06:16255 EXPECT_EQ(ui::CursorType::kPointer, host0->last_cursor().native_type());
256 EXPECT_EQ(ui::CursorType::kNull, host1->last_cursor().native_type());
257 Shell::Get()->cursor_manager()->SetCursor(ui::CursorType::kCopy);
258 EXPECT_EQ(ui::CursorType::kCopy, host0->last_cursor().native_type());
259 EXPECT_EQ(ui::CursorType::kCopy, host1->last_cursor().native_type());
[email protected]c39be8f2012-06-15 22:58:36260}
261
[email protected]718b26c2012-07-24 20:53:23262TEST_F(ExtendedDesktopTest, TestCursorLocation) {
[email protected]d0064722013-03-14 18:16:43263 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13264 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]553eae12013-02-01 02:33:52265 aura::test::WindowTestApi root_window0_test_api(root_windows[0]);
266 aura::test::WindowTestApi root_window1_test_api(root_windows[1]);
[email protected]718b26c2012-07-24 20:53:23267
268 root_windows[0]->MoveCursorTo(gfx::Point(10, 10));
scottmge8b042972016-01-27 05:07:35269 EXPECT_EQ("10,10",
oshimaf84b0da722016-04-27 19:47:19270 display::Screen::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23271 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
272 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
273 root_windows[1]->MoveCursorTo(gfx::Point(10, 20));
scottmge8b042972016-01-27 05:07:35274 EXPECT_EQ("1010,20",
oshimaf84b0da722016-04-27 19:47:19275 display::Screen::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23276 EXPECT_FALSE(root_window0_test_api.ContainsMouse());
277 EXPECT_TRUE(root_window1_test_api.ContainsMouse());
278 root_windows[0]->MoveCursorTo(gfx::Point(20, 10));
scottmge8b042972016-01-27 05:07:35279 EXPECT_EQ("20,10",
oshimaf84b0da722016-04-27 19:47:19280 display::Screen::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23281 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
282 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
283}
284
[email protected]20c59762012-06-23 01:10:24285TEST_F(ExtendedDesktopTest, GetRootWindowAt) {
[email protected]f634dd32012-07-23 22:49:07286 UpdateDisplay("700x500,500x500");
robliaoc0dfd6b2016-04-07 21:33:56287 SetSecondaryDisplayLayout(display::DisplayPlacement::LEFT);
[email protected]c9390bd2013-11-08 20:33:13288 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24289
varkha3c60fc52017-05-25 16:25:11290 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-400, 100)));
291 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-1, 100)));
292 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 300)));
293 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(700, 300)));
[email protected]20c59762012-06-23 01:10:24294
295 // Zero origin.
varkha3c60fc52017-05-25 16:25:11296 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 0)));
[email protected]20c59762012-06-23 01:10:24297
[email protected]36168852014-01-07 12:23:28298 // Out of range point should return the nearest root window
varkha3c60fc52017-05-25 16:25:11299 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-600, 0)));
300 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(701, 100)));
[email protected]20c59762012-06-23 01:10:24301}
302
303TEST_F(ExtendedDesktopTest, GetRootWindowMatching) {
[email protected]f634dd32012-07-23 22:49:07304 UpdateDisplay("700x500,500x500");
robliaoc0dfd6b2016-04-07 21:33:56305 SetSecondaryDisplayLayout(display::DisplayPlacement::LEFT);
[email protected]66b05eac2012-06-27 23:53:10306
[email protected]c9390bd2013-11-08 20:33:13307 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24308
309 // Containing rect.
varkha3c60fc52017-05-25 16:25:11310 EXPECT_EQ(root_windows[1],
311 wm::GetRootWindowMatching(gfx::Rect(-300, 10, 50, 50)));
312 EXPECT_EQ(root_windows[0],
313 wm::GetRootWindowMatching(gfx::Rect(100, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24314
315 // Intersecting rect.
varkha3c60fc52017-05-25 16:25:11316 EXPECT_EQ(root_windows[1],
317 wm::GetRootWindowMatching(gfx::Rect(-200, 0, 300, 300)));
318 EXPECT_EQ(root_windows[0],
319 wm::GetRootWindowMatching(gfx::Rect(-100, 0, 300, 300)));
[email protected]20c59762012-06-23 01:10:24320
321 // Zero origin.
varkha3c60fc52017-05-25 16:25:11322 EXPECT_EQ(root_windows[0], wm::GetRootWindowMatching(gfx::Rect(0, 0, 0, 0)));
323 EXPECT_EQ(root_windows[0], wm::GetRootWindowMatching(gfx::Rect(0, 0, 1, 1)));
[email protected]20c59762012-06-23 01:10:24324
325 // Empty rect.
varkha3c60fc52017-05-25 16:25:11326 EXPECT_EQ(root_windows[1],
327 wm::GetRootWindowMatching(gfx::Rect(-400, 100, 0, 0)));
328 EXPECT_EQ(root_windows[0],
329 wm::GetRootWindowMatching(gfx::Rect(100, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24330
331 // Out of range rect should return the primary root window.
varkha3c60fc52017-05-25 16:25:11332 EXPECT_EQ(root_windows[0],
333 wm::GetRootWindowMatching(gfx::Rect(-600, -300, 50, 50)));
334 EXPECT_EQ(root_windows[0],
335 wm::GetRootWindowMatching(gfx::Rect(0, 1000, 50, 50)));
[email protected]0f81f442012-06-22 06:20:27336}
337
[email protected]1a015382012-12-01 19:44:59338TEST_F(ExtendedDesktopTest, Capture) {
[email protected]f634dd32012-07-23 22:49:07339 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13340 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]a5e71c92012-06-22 22:09:08341
342 aura::test::EventCountDelegate r1_d1;
343 aura::test::EventCountDelegate r1_d2;
344 aura::test::EventCountDelegate r2_d1;
345
dchenga94547472016-04-08 08:41:11346 std::unique_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]a5e71c92012-06-22 22:09:08347 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11348 std::unique_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
[email protected]a5e71c92012-06-22 22:09:08349 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11350 std::unique_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]a5e71c92012-06-22 22:09:08351 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
[email protected]f634dd32012-07-23 22:49:07352
[email protected]a5e71c92012-06-22 22:09:08353 r1_w1->SetCapture();
354
355 EXPECT_EQ(r1_w1.get(),
356 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]334e6182013-01-11 18:35:41357
[email protected]73c9fd02014-07-28 01:48:52358 ui::test::EventGenerator& generator = GetEventGenerator();
[email protected]d05cf2f2014-02-26 05:31:43359 generator.MoveMouseToCenterOf(r2_w1.get());
360 // |r1_w1| will receive the events because it has capture.
361 EXPECT_EQ("1 1 0", r1_d1.GetMouseMotionCountsAndReset());
362 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
363 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
364
365 generator.ClickLeftButton();
[email protected]a5e71c92012-06-22 22:09:08366 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
367 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
[email protected]b19ba4adf2012-09-07 16:13:29368 // The mouse is outside. On chromeos, the mouse is warped to the
369 // dest root window, but it's not implemented on Win yet, so
370 // no mouse move event on Win.
[email protected]d05cf2f2014-02-26 05:31:43371 EXPECT_EQ("0 0 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08372 EXPECT_EQ("1 1", r1_d1.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43373
374 generator.MoveMouseTo(15, 15);
[email protected]f634dd32012-07-23 22:49:07375 EXPECT_EQ("0 1 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43376 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08377
378 r1_w2->SetCapture();
379 EXPECT_EQ(r1_w2.get(),
380 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]d05cf2f2014-02-26 05:31:43381 generator.MoveMouseBy(10, 10);
382 // |r1_w2| has the capture. So it will receive the mouse-move event.
383 EXPECT_EQ("0 0 0", r1_d1.GetMouseMotionCountsAndReset());
384 EXPECT_EQ("0 1 0", r1_d2.GetMouseMotionCountsAndReset());
385 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
386
387 generator.ClickLeftButton();
[email protected]a5e71c92012-06-22 22:09:08388 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
389 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43390 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08391 EXPECT_EQ("1 1", r1_d2.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43392
[email protected]a5e71c92012-06-22 22:09:08393 r1_w2->ReleaseCapture();
oshima95d499b2016-02-10 03:49:56394 EXPECT_EQ(nullptr, aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]d05cf2f2014-02-26 05:31:43395
396 generator.MoveMouseToCenterOf(r2_w1.get());
397 generator.ClickLeftButton();
[email protected]a5e71c92012-06-22 22:09:08398 EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset());
399 EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset());
400 // Make sure the mouse_moved_handler_ is properly reset.
401 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
402 EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset());
403}
404
[email protected]2ca75942014-07-12 04:46:37405TEST_F(ExtendedDesktopTest, CaptureEventLocation) {
[email protected]2ca75942014-07-12 04:46:37406 UpdateDisplay("1000x600,600x400");
407 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
408
409 aura::test::EventCountDelegate r1_d1;
410 aura::test::EventCountDelegate r1_d2;
411 aura::test::EventCountDelegate r2_d1;
412
dchenga94547472016-04-08 08:41:11413 std::unique_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37414 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11415 std::unique_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37416 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11417 std::unique_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37418 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
419
420 r1_w1->SetCapture();
421
[email protected]73c9fd02014-07-28 01:48:52422 ui::test::EventGenerator& generator = GetEventGenerator();
[email protected]2ca75942014-07-12 04:46:37423 generator.MoveMouseToCenterOf(r2_w1.get());
424 EXPECT_EQ(gfx::Point(1060, 60).ToString(),
425 generator.current_location().ToString());
426
427 EventLocationHandler location_handler;
428 r1_w1->AddPreTargetHandler(&location_handler);
429 generator.ClickLeftButton();
430 r1_w1->RemovePreTargetHandler(&location_handler);
431 EXPECT_EQ(gfx::Point(1050, 50).ToString(),
432 location_handler.press_location().ToString());
433 EXPECT_EQ(gfx::Point(1050, 50).ToString(),
434 location_handler.release_location().ToString());
435}
436
437TEST_F(ExtendedDesktopTest, CaptureEventLocationHighDPI) {
[email protected]2ca75942014-07-12 04:46:37438 UpdateDisplay("1000x600*2,600x400");
439 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
440
441 aura::test::EventCountDelegate r1_d1;
442 aura::test::EventCountDelegate r1_d2;
443 aura::test::EventCountDelegate r2_d1;
444
dchenga94547472016-04-08 08:41:11445 std::unique_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37446 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11447 std::unique_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37448 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11449 std::unique_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37450 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
451
452 r1_w1->SetCapture();
453
[email protected]73c9fd02014-07-28 01:48:52454 ui::test::EventGenerator& generator = GetEventGenerator();
[email protected]2ca75942014-07-12 04:46:37455 generator.MoveMouseToCenterOf(r2_w1.get());
456 EXPECT_EQ(gfx::Point(560, 60).ToString(),
457 generator.current_location().ToString());
458
459 EventLocationHandler location_handler;
460 r1_w1->AddPreTargetHandler(&location_handler);
461 generator.ClickLeftButton();
462 r1_w1->RemovePreTargetHandler(&location_handler);
463 EXPECT_EQ(gfx::Point(550, 50).ToString(),
464 location_handler.press_location().ToString());
465 EXPECT_EQ(gfx::Point(550, 50).ToString(),
466 location_handler.release_location().ToString());
467}
468
469TEST_F(ExtendedDesktopTest, CaptureEventLocationHighDPI_2) {
[email protected]2ca75942014-07-12 04:46:37470 UpdateDisplay("1000x600,600x400*2");
471 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
472
473 aura::test::EventCountDelegate r1_d1;
474 aura::test::EventCountDelegate r1_d2;
475 aura::test::EventCountDelegate r2_d1;
476
dchenga94547472016-04-08 08:41:11477 std::unique_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37478 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11479 std::unique_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37480 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11481 std::unique_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37482 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
483
484 r1_w1->SetCapture();
485
[email protected]73c9fd02014-07-28 01:48:52486 ui::test::EventGenerator& generator = GetEventGenerator();
[email protected]2ca75942014-07-12 04:46:37487 generator.MoveMouseToCenterOf(r2_w1.get());
488 EXPECT_EQ(gfx::Point(1060, 60).ToString(),
489 generator.current_location().ToString());
490
491 EventLocationHandler location_handler;
492 r1_w1->AddPreTargetHandler(&location_handler);
493 generator.ClickLeftButton();
494 r1_w1->RemovePreTargetHandler(&location_handler);
495 // Event-generator dispatches the event in the primary root-window's coord
496 // space. Since the location is (1060, 60), it goes to the secondary
497 // root-window as (30, 30) since the secondary root-window has a device scale
498 // factor of 2.
499 EXPECT_EQ(gfx::Point(1020, 20).ToString(),
500 location_handler.press_location().ToString());
501 EXPECT_EQ(gfx::Point(1020, 20).ToString(),
502 location_handler.release_location().ToString());
503}
504
[email protected]f059c6942012-07-21 14:27:57505TEST_F(ExtendedDesktopTest, MoveWindow) {
[email protected]f634dd32012-07-23 22:49:07506 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13507 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]f059c6942012-07-21 14:27:57508 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
509
510 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
511
512 d1->SetBounds(gfx::Rect(1010, 10, 100, 100));
jamescookb8dcef522016-06-25 14:42:55513 EXPECT_EQ("1010,10 100x100", d1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57514
515 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
516
517 d1->SetBounds(gfx::Rect(10, 10, 100, 100));
jamescookb8dcef522016-06-25 14:42:55518 EXPECT_EQ("10,10 100x100", d1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57519
520 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
521
522 // Make sure the bounds which doesn't fit to the root window
523 // works correctly.
524 d1->SetBounds(gfx::Rect(1560, 30, 100, 100));
525 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
jamescookb8dcef522016-06-25 14:42:55526 EXPECT_EQ("1560,30 100x100", d1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57527
528 // Setting outside of root windows will be moved to primary root window.
529 // TODO(oshima): This one probably should pick the closest root window.
530 d1->SetBounds(gfx::Rect(200, 10, 100, 100));
531 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
[email protected]f059c6942012-07-21 14:27:57532}
533
[email protected]2e98aaf72012-11-08 06:30:59534// Verifies if the mouse event arrives to the window even when the window
535// moves to another root in a pre-target handler. See: crbug.com/157583
536TEST_F(ExtendedDesktopTest, MoveWindowByMouseClick) {
537 UpdateDisplay("1000x600,600x400");
538
[email protected]c9390bd2013-11-08 20:33:13539 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]2e98aaf72012-11-08 06:30:59540 aura::test::EventCountDelegate delegate;
dchenga94547472016-04-08 08:41:11541 std::unique_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate(
[email protected]2e98aaf72012-11-08 06:30:59542 &delegate, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
[email protected]334e6182013-01-11 18:35:41543 MoveWindowByClickEventHandler event_handler(window.get());
544 window->AddPreTargetHandler(&event_handler);
545
[email protected]73c9fd02014-07-28 01:48:52546 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41547
548 event_generator.MoveMouseToCenterOf(window.get());
549 event_generator.ClickLeftButton();
[email protected]2e98aaf72012-11-08 06:30:59550 // Both mouse pressed and released arrive at the window and its delegate.
551 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset());
[email protected]334e6182013-01-11 18:35:41552 // Also event_handler moves the window to another root at mouse release.
[email protected]2e98aaf72012-11-08 06:30:59553 EXPECT_EQ(root_windows[1], window->GetRootWindow());
554}
555
[email protected]1a015382012-12-01 19:44:59556TEST_F(ExtendedDesktopTest, MoveWindowToDisplay) {
[email protected]e79f26e2012-08-09 07:12:48557 UpdateDisplay("1000x1000,1000x1000");
[email protected]c9390bd2013-11-08 20:33:13558 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]e79f26e2012-08-09 07:12:48559
oshimaf84b0da722016-04-27 19:47:19560 display::Display display0 = display::Screen::GetScreen()->GetDisplayMatching(
[email protected]ffabb1e2012-10-12 19:51:17561 root_windows[0]->GetBoundsInScreen());
oshimaf84b0da722016-04-27 19:47:19562 display::Display display1 = display::Screen::GetScreen()->GetDisplayMatching(
[email protected]ffabb1e2012-10-12 19:51:17563 root_windows[1]->GetBoundsInScreen());
[email protected]e79f26e2012-08-09 07:12:48564 EXPECT_NE(display0.id(), display1.id());
565
566 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 1000, 100));
567 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
568
569 // Move the window where the window spans both root windows. Since the second
570 // parameter is |display1|, the window should be shown on the secondary root.
571 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
572 display1);
jamescookb8dcef522016-06-25 14:42:55573 EXPECT_EQ("500,10 1000x100", d1->GetWindowBoundsInScreen().ToString());
[email protected]e79f26e2012-08-09 07:12:48574 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
575
576 // Move to the primary root.
577 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
578 display0);
jamescookb8dcef522016-06-25 14:42:55579 EXPECT_EQ("500,10 1000x100", d1->GetWindowBoundsInScreen().ToString());
[email protected]e79f26e2012-08-09 07:12:48580 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
581}
582
[email protected]f059c6942012-07-21 14:27:57583TEST_F(ExtendedDesktopTest, MoveWindowWithTransient) {
[email protected]f634dd32012-07-23 22:49:07584 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13585 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]f059c6942012-07-21 14:27:57586 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
587 views::Widget* w1_t1 = CreateTestWidgetWithParent(
588 w1, gfx::Rect(50, 50, 50, 50), false /* transient */);
589 // Transient child of the transient child.
590 views::Widget* w1_t11 = CreateTestWidgetWithParent(
[email protected]e6de8552014-05-23 19:05:39591 w1_t1, gfx::Rect(1200, 70, 35, 35), false /* transient */);
[email protected]f059c6942012-07-21 14:27:57592
jamescookb8dcef522016-06-25 14:42:55593 views::Widget* w11 = CreateTestWidgetWithParent(w1, gfx::Rect(10, 10, 40, 40),
594 true /* child */);
[email protected]f059c6942012-07-21 14:27:57595 views::Widget* w11_t1 = CreateTestWidgetWithParent(
596 w1, gfx::Rect(1300, 100, 80, 80), false /* transient */);
597
598 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
599 EXPECT_EQ(root_windows[0], w11->GetNativeView()->GetRootWindow());
600 EXPECT_EQ(root_windows[0], w1_t1->GetNativeView()->GetRootWindow());
601 EXPECT_EQ(root_windows[0], w1_t11->GetNativeView()->GetRootWindow());
602 EXPECT_EQ(root_windows[0], w11_t1->GetNativeView()->GetRootWindow());
jamescookb8dcef522016-06-25 14:42:55603 EXPECT_EQ("50,50 50x50", w1_t1->GetWindowBoundsInScreen().ToString());
604 EXPECT_EQ("1200,70 35x35", w1_t11->GetWindowBoundsInScreen().ToString());
605 EXPECT_EQ("20,20 40x40", w11->GetWindowBoundsInScreen().ToString());
606 EXPECT_EQ("1300,100 80x80", w11_t1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57607
[email protected]24f5e242014-07-22 02:16:09608 w1->SetBounds(gfx::Rect(1100, 10, 100, 100));
[email protected]f059c6942012-07-21 14:27:57609
610 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
611 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
612 EXPECT_EQ(root_windows[1], w1_t11->GetNativeView()->GetRootWindow());
613 EXPECT_EQ(root_windows[1], w11->GetNativeView()->GetRootWindow());
614 EXPECT_EQ(root_windows[1], w11_t1->GetNativeView()->GetRootWindow());
615
jamescookb8dcef522016-06-25 14:42:55616 EXPECT_EQ("1110,20 40x40", w11->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57617 // Transient window's screen bounds stays the same.
jamescookb8dcef522016-06-25 14:42:55618 EXPECT_EQ("50,50 50x50", w1_t1->GetWindowBoundsInScreen().ToString());
619 EXPECT_EQ("1200,70 35x35", w1_t11->GetWindowBoundsInScreen().ToString());
620 EXPECT_EQ("1300,100 80x80", w11_t1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57621
622 // Transient window doesn't move between root window unless
623 // its transient parent moves.
624 w1_t1->SetBounds(gfx::Rect(10, 50, 50, 50));
625 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
jamescookb8dcef522016-06-25 14:42:55626 EXPECT_EQ("10,50 50x50", w1_t1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57627}
628
[email protected]ca7060982012-08-08 18:05:25629// Test if the Window::ConvertPointToTarget works across root windows.
[email protected]a5e71c92012-06-22 22:09:08630TEST_F(ExtendedDesktopTest, ConvertPoint) {
oshimaf84b0da722016-04-27 19:47:19631 display::Screen* screen = display::Screen::GetScreen();
[email protected]f634dd32012-07-23 22:49:07632 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13633 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
oshimaf84b0da722016-04-27 19:47:19634 display::Display display_1 = screen->GetDisplayNearestWindow(root_windows[0]);
[email protected]a5e71c92012-06-22 22:09:08635 EXPECT_EQ("0,0", display_1.bounds().origin().ToString());
oshimaf84b0da722016-04-27 19:47:19636 display::Display display_2 = screen->GetDisplayNearestWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07637 EXPECT_EQ("1000,0", display_2.bounds().origin().ToString());
638
[email protected]a5e71c92012-06-22 22:09:08639 aura::Window* d1 =
640 CreateTestWidget(gfx::Rect(10, 10, 100, 100))->GetNativeView();
[email protected]a5e71c92012-06-22 22:09:08641 aura::Window* d2 =
[email protected]f634dd32012-07-23 22:49:07642 CreateTestWidget(gfx::Rect(1020, 20, 100, 100))->GetNativeView();
643 EXPECT_EQ(root_windows[0], d1->GetRootWindow());
644 EXPECT_EQ(root_windows[1], d2->GetRootWindow());
[email protected]a5e71c92012-06-22 22:09:08645
[email protected]a5e71c92012-06-22 22:09:08646 // Convert point in the Root2's window to the Root1's window Coord.
647 gfx::Point p(0, 0);
[email protected]ca7060982012-08-08 18:05:25648 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07649 EXPECT_EQ("1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08650 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25651 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07652 EXPECT_EQ("1010,10", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08653
654 // Convert point in the Root1's window to the Root2's window Coord.
655 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25656 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07657 EXPECT_EQ("-1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08658 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25659 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07660 EXPECT_EQ("-1010,-10", p.ToString());
661
662 // Move the 2nd display to the bottom and test again.
robliaoc0dfd6b2016-04-07 21:33:56663 SetSecondaryDisplayLayout(display::DisplayPlacement::BOTTOM);
[email protected]f634dd32012-07-23 22:49:07664
[email protected]b8984242013-07-12 07:55:38665 display_2 = screen->GetDisplayNearestWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07666 EXPECT_EQ("0,600", display_2.bounds().origin().ToString());
667
668 // Convert point in Root2's window to Root1's window Coord.
669 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25670 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07671 EXPECT_EQ("0,600", p.ToString());
672 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25673 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07674 EXPECT_EQ("10,610", p.ToString());
675
676 // Convert point in Root1's window to Root2's window Coord.
677 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25678 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07679 EXPECT_EQ("0,-600", p.ToString());
680 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25681 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07682 EXPECT_EQ("-10,-610", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08683}
[email protected]f634dd32012-07-23 22:49:07684
[email protected]263898a2012-09-17 17:20:07685TEST_F(ExtendedDesktopTest, OpenSystemTray) {
[email protected]596c61c2012-10-29 17:29:43686 UpdateDisplay("500x600,600x400");
skycb4be5b2017-04-06 17:52:45687 SystemTray* tray = ash::Shell::Get()->GetPrimarySystemTray();
[email protected]263898a2012-09-17 17:20:07688 ASSERT_FALSE(tray->HasSystemBubble());
689
[email protected]73c9fd02014-07-28 01:48:52690 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41691
[email protected]263898a2012-09-17 17:20:07692 // Opens the tray by a dummy click event and makes sure that adding/removing
693 // displays doesn't break anything.
[email protected]334e6182013-01-11 18:35:41694 event_generator.MoveMouseToCenterOf(tray->GetWidget()->GetNativeWindow());
[email protected]263898a2012-09-17 17:20:07695 event_generator.ClickLeftButton();
696 EXPECT_TRUE(tray->HasSystemBubble());
697
[email protected]596c61c2012-10-29 17:29:43698 UpdateDisplay("500x600");
[email protected]263898a2012-09-17 17:20:07699 EXPECT_TRUE(tray->HasSystemBubble());
[email protected]596c61c2012-10-29 17:29:43700 UpdateDisplay("500x600,600x400");
[email protected]263898a2012-09-17 17:20:07701 EXPECT_TRUE(tray->HasSystemBubble());
702
703 // Closes the tray and again makes sure that adding/removing displays doesn't
704 // break anything.
705 event_generator.ClickLeftButton();
706 RunAllPendingInMessageLoop();
707
708 EXPECT_FALSE(tray->HasSystemBubble());
709
[email protected]596c61c2012-10-29 17:29:43710 UpdateDisplay("500x600");
[email protected]263898a2012-09-17 17:20:07711 EXPECT_FALSE(tray->HasSystemBubble());
[email protected]596c61c2012-10-29 17:29:43712 UpdateDisplay("500x600,600x400");
[email protected]263898a2012-09-17 17:20:07713 EXPECT_FALSE(tray->HasSystemBubble());
714}
715
[email protected]578048512012-09-19 20:01:24716TEST_F(ExtendedDesktopTest, StayInSameRootWindow) {
717 UpdateDisplay("100x100,200x200");
[email protected]c9390bd2013-11-08 20:33:13718 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]a2e6af12013-01-07 21:40:35719 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 50, 50));
[email protected]578048512012-09-19 20:01:24720 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
721 w1->SetBounds(gfx::Rect(150, 10, 50, 50));
722 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
723
skyaecdb0fb2016-09-15 22:14:28724 // The widget stays in the same root if kLockedToRootKey is set to true.
725 w1->GetNativeView()->SetProperty(kLockedToRootKey, true);
[email protected]578048512012-09-19 20:01:24726 w1->SetBounds(gfx::Rect(10, 10, 50, 50));
727 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
728
729 // The widget should now move to the 1st root window without the property.
skyaecdb0fb2016-09-15 22:14:28730 w1->GetNativeView()->ClearProperty(kLockedToRootKey);
[email protected]578048512012-09-19 20:01:24731 w1->SetBounds(gfx::Rect(10, 10, 50, 50));
732 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
[email protected]e887c6c2013-07-08 19:35:53733
734 // a window in SettingsBubbleContainer and StatusContainer should
735 // not move to another root window regardles of the bounds specified.
736 aura::Window* settings_bubble_container =
737 Shell::GetPrimaryRootWindowController()->GetContainer(
[email protected]093b8d642014-04-03 20:59:28738 kShellWindowId_SettingBubbleContainer);
jamescookb8dcef522016-06-25 14:42:55739 aura::Window* window =
740 aura::test::CreateTestWindowWithId(100, settings_bubble_container);
sky8782ff02017-02-23 22:12:42741 window->SetBoundsInScreen(gfx::Rect(150, 10, 50, 50), GetSecondaryDisplay());
[email protected]e887c6c2013-07-08 19:35:53742 EXPECT_EQ(root_windows[0], window->GetRootWindow());
743
744 aura::Window* status_container =
745 Shell::GetPrimaryRootWindowController()->GetContainer(
[email protected]093b8d642014-04-03 20:59:28746 kShellWindowId_StatusContainer);
[email protected]e887c6c2013-07-08 19:35:53747 window = aura::test::CreateTestWindowWithId(100, status_container);
sky8782ff02017-02-23 22:12:42748 window->SetBoundsInScreen(gfx::Rect(150, 10, 50, 50), GetSecondaryDisplay());
[email protected]e887c6c2013-07-08 19:35:53749 EXPECT_EQ(root_windows[0], window->GetRootWindow());
[email protected]578048512012-09-19 20:01:24750}
751
[email protected]e67291f12012-10-10 05:52:38752TEST_F(ExtendedDesktopTest, KeyEventsOnLockScreen) {
753 UpdateDisplay("100x100,200x200");
[email protected]c9390bd2013-11-08 20:33:13754 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]e67291f12012-10-10 05:52:38755
756 // Create normal windows on both displays.
oshimaf84b0da722016-04-27 19:47:19757 views::Widget* widget1 = CreateTestWidget(
758 display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38759 widget1->Show();
760 EXPECT_EQ(root_windows[0], widget1->GetNativeView()->GetRootWindow());
sky8782ff02017-02-23 22:12:42761 views::Widget* widget2 = CreateTestWidget(GetSecondaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38762 widget2->Show();
763 EXPECT_EQ(root_windows[1], widget2->GetNativeView()->GetRootWindow());
764
765 // Create a LockScreen window.
oshimaf84b0da722016-04-27 19:47:19766 views::Widget* lock_widget = CreateTestWidget(
767 display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38768 views::Textfield* textfield = new views::Textfield;
[email protected]09148952013-03-13 13:25:43769 lock_widget->client_view()->AddChildView(textfield);
[email protected]e67291f12012-10-10 05:52:38770
[email protected]093b8d642014-04-03 20:59:28771 ash::Shell::GetContainer(Shell::GetPrimaryRootWindow(),
772 ash::kShellWindowId_LockScreenContainer)
773 ->AddChild(lock_widget->GetNativeView());
[email protected]e67291f12012-10-10 05:52:38774 lock_widget->Show();
775 textfield->RequestFocus();
776
[email protected]8cfb6722012-11-28 03:28:46777 aura::client::FocusClient* focus_client =
778 aura::client::GetFocusClient(root_windows[0]);
779 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]e67291f12012-10-10 05:52:38780
781 // The lock window should get events on both root windows.
[email protected]73c9fd02014-07-28 01:48:52782 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41783
[email protected]1ea46f6f2014-07-17 07:36:40784 event_generator.set_current_target(root_windows[0]);
[email protected]334e6182013-01-11 18:35:41785 event_generator.PressKey(ui::VKEY_A, 0);
786 event_generator.ReleaseKey(ui::VKEY_A, 0);
[email protected]8cfb6722012-11-28 03:28:46787 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46788 EXPECT_EQ("a", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38789
[email protected]1ea46f6f2014-07-17 07:36:40790 event_generator.set_current_target(root_windows[1]);
[email protected]334e6182013-01-11 18:35:41791 event_generator.PressKey(ui::VKEY_B, 0);
792 event_generator.ReleaseKey(ui::VKEY_B, 0);
[email protected]8cfb6722012-11-28 03:28:46793 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46794 EXPECT_EQ("ab", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38795
796 // Deleting 2nd display. The lock window still should get the events.
797 UpdateDisplay("100x100");
pkotwicz5d118a6b12015-02-12 22:23:57798 event_generator.set_current_target(root_windows[0]);
[email protected]334e6182013-01-11 18:35:41799 event_generator.PressKey(ui::VKEY_C, 0);
800 event_generator.ReleaseKey(ui::VKEY_C, 0);
[email protected]8cfb6722012-11-28 03:28:46801 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46802 EXPECT_EQ("abc", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38803
804 // Creating 2nd display again, and lock window still should get events
805 // on both root windows.
806 UpdateDisplay("100x100,200x200");
807 root_windows = Shell::GetAllRootWindows();
[email protected]1ea46f6f2014-07-17 07:36:40808 event_generator.set_current_target(root_windows[0]);
[email protected]334e6182013-01-11 18:35:41809 event_generator.PressKey(ui::VKEY_D, 0);
810 event_generator.ReleaseKey(ui::VKEY_D, 0);
[email protected]8cfb6722012-11-28 03:28:46811 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46812 EXPECT_EQ("abcd", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38813
[email protected]1ea46f6f2014-07-17 07:36:40814 event_generator.set_current_target(root_windows[1]);
[email protected]334e6182013-01-11 18:35:41815 event_generator.PressKey(ui::VKEY_E, 0);
816 event_generator.ReleaseKey(ui::VKEY_E, 0);
[email protected]8cfb6722012-11-28 03:28:46817 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46818 EXPECT_EQ("abcde", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38819}
820
[email protected]334e6182013-01-11 18:35:41821TEST_F(ExtendedDesktopTest, PassiveGrab) {
822 EventLocationRecordingEventHandler event_handler;
skycb4be5b2017-04-06 17:52:45823 ash::Shell::Get()->AddPreTargetHandler(&event_handler);
[email protected]334e6182013-01-11 18:35:41824
825 UpdateDisplay("300x300,200x200");
826
827 views::Widget* widget = CreateTestWidget(gfx::Rect(50, 50, 200, 200));
828 widget->Show();
829 ASSERT_EQ("50,50 200x200", widget->GetWindowBoundsInScreen().ToString());
830
[email protected]73c9fd02014-07-28 01:48:52831 ui::test::EventGenerator& generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41832 generator.MoveMouseTo(150, 150);
833 EXPECT_EQ("100,100 150,150", event_handler.GetLocationsAndReset());
834
835 generator.PressLeftButton();
836 generator.MoveMouseTo(400, 150);
837
838 EXPECT_EQ("350,100 400,150", event_handler.GetLocationsAndReset());
839
840 generator.ReleaseLeftButton();
841 EXPECT_EQ("-999,-999 -999,-999", event_handler.GetLocationsAndReset());
842
843 generator.MoveMouseTo(400, 150);
844 EXPECT_EQ("100,150 100,150", event_handler.GetLocationsAndReset());
845
skycb4be5b2017-04-06 17:52:45846 ash::Shell::Get()->RemovePreTargetHandler(&event_handler);
[email protected]334e6182013-01-11 18:35:41847}
848
[email protected]c39be8f2012-06-15 22:58:36849} // namespace ash