blob: ea9f9e2c4a3ca91993c3b340af6aae0203aac084 [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:
46 ModalWidgetDelegate() {}
dcheng1f4538e2014-10-27 23:57:0547 ~ModalWidgetDelegate() override {}
[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) {}
dcheng1f4538e2014-10-27 23:57:0562 ~MoveWindowByClickEventHandler() override {}
[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(); }
dcheng1f4538e2014-10-27 23:57:0582 ~EventLocationRecordingEventHandler() override {}
[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:
113 EventLocationHandler() {}
dcheng1f4538e2014-10-27 23:57:05114 ~EventLocationHandler() override {}
[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
[email protected]a2e6af12013-01-07 21:40:35136class ExtendedDesktopTest : public test::AshTestBase {
137 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
167// Test conditions that root windows in extended desktop mode
168// must satisfy.
169TEST_F(ExtendedDesktopTest, Basic) {
[email protected]f634dd32012-07-23 22:49:07170 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13171 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36172
173 // All root windows must have the root window controller.
174 ASSERT_EQ(2U, root_windows.size());
[email protected]c9390bd2013-11-08 20:33:13175 for (aura::Window::Windows::const_iterator iter = root_windows.begin();
[email protected]c39be8f2012-06-15 22:58:36176 iter != root_windows.end(); ++iter) {
oshima95d499b2016-02-10 03:49:56177 EXPECT_TRUE(GetRootWindowController(*iter) != nullptr);
[email protected]c39be8f2012-06-15 22:58:36178 }
179 // Make sure root windows share the same controllers.
[email protected]8cfb6722012-11-28 03:28:46180 EXPECT_EQ(aura::client::GetFocusClient(root_windows[0]),
181 aura::client::GetFocusClient(root_windows[1]));
[email protected]c39be8f2012-06-15 22:58:36182 EXPECT_EQ(aura::client::GetActivationClient(root_windows[0]),
183 aura::client::GetActivationClient(root_windows[1]));
184 EXPECT_EQ(aura::client::GetCaptureClient(root_windows[0]),
185 aura::client::GetCaptureClient(root_windows[1]));
186}
187
188TEST_F(ExtendedDesktopTest, Activation) {
[email protected]f634dd32012-07-23 22:49:07189 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13190 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36191
[email protected]c39be8f2012-06-15 22:58:36192 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]f634dd32012-07-23 22:49:07193 views::Widget* widget_on_2nd =
194 CreateTestWidget(gfx::Rect(1200, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36195 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
[email protected]f634dd32012-07-23 22:49:07196 EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36197
198 EXPECT_EQ(widget_on_2nd->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46199 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]c39be8f2012-06-15 22:58:36200 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
201
[email protected]73c9fd02014-07-28 01:48:52202 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]f634dd32012-07-23 22:49:07203 // Clicking a window changes the active window and active root window.
[email protected]334e6182013-01-11 18:35:41204 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
205 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36206
207 EXPECT_EQ(widget_on_1st->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46208 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]c39be8f2012-06-15 22:58:36209 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]f634dd32012-07-23 22:49:07210
[email protected]334e6182013-01-11 18:35:41211 event_generator.MoveMouseToCenterOf(widget_on_2nd->GetNativeView());
212 event_generator.ClickLeftButton();
[email protected]f634dd32012-07-23 22:49:07213
214 EXPECT_EQ(widget_on_2nd->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46215 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]f634dd32012-07-23 22:49:07216 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
[email protected]c39be8f2012-06-15 22:58:36217}
218
219TEST_F(ExtendedDesktopTest, SystemModal) {
[email protected]f634dd32012-07-23 22:49:07220 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13221 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36222
223 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36224 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]492533b32012-09-21 19:06:14225 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
sky27344382017-03-08 21:30:32226 EXPECT_EQ(root_windows[0], Shell::GetRootWindowForNewWindows());
[email protected]c39be8f2012-06-15 22:58:36227
[email protected]c39be8f2012-06-15 22:58:36228 // Open system modal. Make sure it's on 2nd root window and active.
[email protected]a2e6af12013-01-07 21:40:35229 views::Widget* modal_widget = views::Widget::CreateWindowWithContextAndBounds(
jamescookb8dcef522016-06-25 14:42:55230 new ModalWidgetDelegate(), CurrentContext(),
[email protected]a2e6af12013-01-07 21:40:35231 gfx::Rect(1200, 100, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36232 modal_widget->Show();
233 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
234 EXPECT_EQ(root_windows[1], modal_widget->GetNativeView()->GetRootWindow());
sky27344382017-03-08 21:30:32235 EXPECT_EQ(root_windows[1], Shell::GetRootWindowForNewWindows());
[email protected]c39be8f2012-06-15 22:58:36236
[email protected]73c9fd02014-07-28 01:48:52237 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41238
[email protected]2e236a52012-06-27 22:21:47239 // Clicking a widget on widget_on_1st display should not change activation.
[email protected]334e6182013-01-11 18:35:41240 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
241 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36242 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
sky27344382017-03-08 21:30:32243 EXPECT_EQ(root_windows[1], Shell::GetRootWindowForNewWindows());
[email protected]c39be8f2012-06-15 22:58:36244
245 // Close system modal and so clicking a widget should work now.
246 modal_widget->Close();
[email protected]334e6182013-01-11 18:35:41247 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
248 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36249 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
sky27344382017-03-08 21:30:32250 EXPECT_EQ(root_windows[0], Shell::GetRootWindowForNewWindows());
[email protected]c39be8f2012-06-15 22:58:36251}
252
253TEST_F(ExtendedDesktopTest, TestCursor) {
[email protected]f634dd32012-07-23 22:49:07254 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13255 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]2374d1812014-03-04 03:42:27256 aura::WindowTreeHost* host0 = root_windows[0]->GetHost();
257 aura::WindowTreeHost* host1 = root_windows[1]->GetHost();
ergeeba7c622017-04-25 18:06:16258 EXPECT_EQ(ui::CursorType::kPointer, host0->last_cursor().native_type());
259 EXPECT_EQ(ui::CursorType::kNull, host1->last_cursor().native_type());
260 Shell::Get()->cursor_manager()->SetCursor(ui::CursorType::kCopy);
261 EXPECT_EQ(ui::CursorType::kCopy, host0->last_cursor().native_type());
262 EXPECT_EQ(ui::CursorType::kCopy, host1->last_cursor().native_type());
[email protected]c39be8f2012-06-15 22:58:36263}
264
[email protected]718b26c2012-07-24 20:53:23265TEST_F(ExtendedDesktopTest, TestCursorLocation) {
[email protected]d0064722013-03-14 18:16:43266 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13267 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]553eae12013-02-01 02:33:52268 aura::test::WindowTestApi root_window0_test_api(root_windows[0]);
269 aura::test::WindowTestApi root_window1_test_api(root_windows[1]);
[email protected]718b26c2012-07-24 20:53:23270
271 root_windows[0]->MoveCursorTo(gfx::Point(10, 10));
scottmge8b042972016-01-27 05:07:35272 EXPECT_EQ("10,10",
oshimaf84b0da722016-04-27 19:47:19273 display::Screen::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23274 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
275 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
276 root_windows[1]->MoveCursorTo(gfx::Point(10, 20));
scottmge8b042972016-01-27 05:07:35277 EXPECT_EQ("1010,20",
oshimaf84b0da722016-04-27 19:47:19278 display::Screen::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23279 EXPECT_FALSE(root_window0_test_api.ContainsMouse());
280 EXPECT_TRUE(root_window1_test_api.ContainsMouse());
281 root_windows[0]->MoveCursorTo(gfx::Point(20, 10));
scottmge8b042972016-01-27 05:07:35282 EXPECT_EQ("20,10",
oshimaf84b0da722016-04-27 19:47:19283 display::Screen::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23284 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
285 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
286}
287
[email protected]20c59762012-06-23 01:10:24288TEST_F(ExtendedDesktopTest, GetRootWindowAt) {
[email protected]f634dd32012-07-23 22:49:07289 UpdateDisplay("700x500,500x500");
robliaoc0dfd6b2016-04-07 21:33:56290 SetSecondaryDisplayLayout(display::DisplayPlacement::LEFT);
[email protected]c9390bd2013-11-08 20:33:13291 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24292
varkha3c60fc52017-05-25 16:25:11293 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-400, 100)));
294 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-1, 100)));
295 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 300)));
296 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(700, 300)));
[email protected]20c59762012-06-23 01:10:24297
298 // Zero origin.
varkha3c60fc52017-05-25 16:25:11299 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 0)));
[email protected]20c59762012-06-23 01:10:24300
[email protected]36168852014-01-07 12:23:28301 // Out of range point should return the nearest root window
varkha3c60fc52017-05-25 16:25:11302 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-600, 0)));
303 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(701, 100)));
[email protected]20c59762012-06-23 01:10:24304}
305
306TEST_F(ExtendedDesktopTest, GetRootWindowMatching) {
[email protected]f634dd32012-07-23 22:49:07307 UpdateDisplay("700x500,500x500");
robliaoc0dfd6b2016-04-07 21:33:56308 SetSecondaryDisplayLayout(display::DisplayPlacement::LEFT);
[email protected]66b05eac2012-06-27 23:53:10309
[email protected]c9390bd2013-11-08 20:33:13310 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24311
312 // Containing rect.
varkha3c60fc52017-05-25 16:25:11313 EXPECT_EQ(root_windows[1],
314 wm::GetRootWindowMatching(gfx::Rect(-300, 10, 50, 50)));
315 EXPECT_EQ(root_windows[0],
316 wm::GetRootWindowMatching(gfx::Rect(100, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24317
318 // Intersecting rect.
varkha3c60fc52017-05-25 16:25:11319 EXPECT_EQ(root_windows[1],
320 wm::GetRootWindowMatching(gfx::Rect(-200, 0, 300, 300)));
321 EXPECT_EQ(root_windows[0],
322 wm::GetRootWindowMatching(gfx::Rect(-100, 0, 300, 300)));
[email protected]20c59762012-06-23 01:10:24323
324 // Zero origin.
varkha3c60fc52017-05-25 16:25:11325 EXPECT_EQ(root_windows[0], wm::GetRootWindowMatching(gfx::Rect(0, 0, 0, 0)));
326 EXPECT_EQ(root_windows[0], wm::GetRootWindowMatching(gfx::Rect(0, 0, 1, 1)));
[email protected]20c59762012-06-23 01:10:24327
328 // Empty rect.
varkha3c60fc52017-05-25 16:25:11329 EXPECT_EQ(root_windows[1],
330 wm::GetRootWindowMatching(gfx::Rect(-400, 100, 0, 0)));
331 EXPECT_EQ(root_windows[0],
332 wm::GetRootWindowMatching(gfx::Rect(100, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24333
334 // Out of range rect should return the primary root window.
varkha3c60fc52017-05-25 16:25:11335 EXPECT_EQ(root_windows[0],
336 wm::GetRootWindowMatching(gfx::Rect(-600, -300, 50, 50)));
337 EXPECT_EQ(root_windows[0],
338 wm::GetRootWindowMatching(gfx::Rect(0, 1000, 50, 50)));
[email protected]0f81f442012-06-22 06:20:27339}
340
[email protected]1a015382012-12-01 19:44:59341TEST_F(ExtendedDesktopTest, Capture) {
[email protected]f634dd32012-07-23 22:49:07342 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13343 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]a5e71c92012-06-22 22:09:08344
345 aura::test::EventCountDelegate r1_d1;
346 aura::test::EventCountDelegate r1_d2;
347 aura::test::EventCountDelegate r2_d1;
348
dchenga94547472016-04-08 08:41:11349 std::unique_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]a5e71c92012-06-22 22:09:08350 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11351 std::unique_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
[email protected]a5e71c92012-06-22 22:09:08352 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11353 std::unique_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]a5e71c92012-06-22 22:09:08354 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
[email protected]f634dd32012-07-23 22:49:07355
[email protected]a5e71c92012-06-22 22:09:08356 r1_w1->SetCapture();
357
358 EXPECT_EQ(r1_w1.get(),
359 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]334e6182013-01-11 18:35:41360
[email protected]73c9fd02014-07-28 01:48:52361 ui::test::EventGenerator& generator = GetEventGenerator();
[email protected]d05cf2f2014-02-26 05:31:43362 generator.MoveMouseToCenterOf(r2_w1.get());
363 // |r1_w1| will receive the events because it has capture.
364 EXPECT_EQ("1 1 0", r1_d1.GetMouseMotionCountsAndReset());
365 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
366 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
367
368 generator.ClickLeftButton();
[email protected]a5e71c92012-06-22 22:09:08369 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
370 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
[email protected]b19ba4adf2012-09-07 16:13:29371 // The mouse is outside. On chromeos, the mouse is warped to the
372 // dest root window, but it's not implemented on Win yet, so
373 // no mouse move event on Win.
[email protected]d05cf2f2014-02-26 05:31:43374 EXPECT_EQ("0 0 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08375 EXPECT_EQ("1 1", r1_d1.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43376
377 generator.MoveMouseTo(15, 15);
[email protected]f634dd32012-07-23 22:49:07378 EXPECT_EQ("0 1 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43379 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08380
381 r1_w2->SetCapture();
382 EXPECT_EQ(r1_w2.get(),
383 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]d05cf2f2014-02-26 05:31:43384 generator.MoveMouseBy(10, 10);
385 // |r1_w2| has the capture. So it will receive the mouse-move event.
386 EXPECT_EQ("0 0 0", r1_d1.GetMouseMotionCountsAndReset());
387 EXPECT_EQ("0 1 0", r1_d2.GetMouseMotionCountsAndReset());
388 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
389
390 generator.ClickLeftButton();
[email protected]a5e71c92012-06-22 22:09:08391 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
392 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43393 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08394 EXPECT_EQ("1 1", r1_d2.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43395
[email protected]a5e71c92012-06-22 22:09:08396 r1_w2->ReleaseCapture();
oshima95d499b2016-02-10 03:49:56397 EXPECT_EQ(nullptr, aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]d05cf2f2014-02-26 05:31:43398
399 generator.MoveMouseToCenterOf(r2_w1.get());
400 generator.ClickLeftButton();
[email protected]a5e71c92012-06-22 22:09:08401 EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset());
402 EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset());
403 // Make sure the mouse_moved_handler_ is properly reset.
404 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
405 EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset());
406}
407
[email protected]2ca75942014-07-12 04:46:37408TEST_F(ExtendedDesktopTest, CaptureEventLocation) {
[email protected]2ca75942014-07-12 04:46:37409 UpdateDisplay("1000x600,600x400");
410 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
411
412 aura::test::EventCountDelegate r1_d1;
413 aura::test::EventCountDelegate r1_d2;
414 aura::test::EventCountDelegate r2_d1;
415
dchenga94547472016-04-08 08:41:11416 std::unique_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37417 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11418 std::unique_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37419 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11420 std::unique_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37421 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
422
423 r1_w1->SetCapture();
424
[email protected]73c9fd02014-07-28 01:48:52425 ui::test::EventGenerator& generator = GetEventGenerator();
[email protected]2ca75942014-07-12 04:46:37426 generator.MoveMouseToCenterOf(r2_w1.get());
427 EXPECT_EQ(gfx::Point(1060, 60).ToString(),
428 generator.current_location().ToString());
429
430 EventLocationHandler location_handler;
431 r1_w1->AddPreTargetHandler(&location_handler);
432 generator.ClickLeftButton();
433 r1_w1->RemovePreTargetHandler(&location_handler);
434 EXPECT_EQ(gfx::Point(1050, 50).ToString(),
435 location_handler.press_location().ToString());
436 EXPECT_EQ(gfx::Point(1050, 50).ToString(),
437 location_handler.release_location().ToString());
438}
439
440TEST_F(ExtendedDesktopTest, CaptureEventLocationHighDPI) {
[email protected]2ca75942014-07-12 04:46:37441 UpdateDisplay("1000x600*2,600x400");
442 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
443
444 aura::test::EventCountDelegate r1_d1;
445 aura::test::EventCountDelegate r1_d2;
446 aura::test::EventCountDelegate r2_d1;
447
dchenga94547472016-04-08 08:41:11448 std::unique_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37449 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11450 std::unique_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37451 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11452 std::unique_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37453 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
454
455 r1_w1->SetCapture();
456
[email protected]73c9fd02014-07-28 01:48:52457 ui::test::EventGenerator& generator = GetEventGenerator();
[email protected]2ca75942014-07-12 04:46:37458 generator.MoveMouseToCenterOf(r2_w1.get());
459 EXPECT_EQ(gfx::Point(560, 60).ToString(),
460 generator.current_location().ToString());
461
462 EventLocationHandler location_handler;
463 r1_w1->AddPreTargetHandler(&location_handler);
464 generator.ClickLeftButton();
465 r1_w1->RemovePreTargetHandler(&location_handler);
466 EXPECT_EQ(gfx::Point(550, 50).ToString(),
467 location_handler.press_location().ToString());
468 EXPECT_EQ(gfx::Point(550, 50).ToString(),
469 location_handler.release_location().ToString());
470}
471
472TEST_F(ExtendedDesktopTest, CaptureEventLocationHighDPI_2) {
[email protected]2ca75942014-07-12 04:46:37473 UpdateDisplay("1000x600,600x400*2");
474 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
475
476 aura::test::EventCountDelegate r1_d1;
477 aura::test::EventCountDelegate r1_d2;
478 aura::test::EventCountDelegate r2_d1;
479
dchenga94547472016-04-08 08:41:11480 std::unique_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37481 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11482 std::unique_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37483 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11484 std::unique_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37485 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
486
487 r1_w1->SetCapture();
488
[email protected]73c9fd02014-07-28 01:48:52489 ui::test::EventGenerator& generator = GetEventGenerator();
[email protected]2ca75942014-07-12 04:46:37490 generator.MoveMouseToCenterOf(r2_w1.get());
491 EXPECT_EQ(gfx::Point(1060, 60).ToString(),
492 generator.current_location().ToString());
493
494 EventLocationHandler location_handler;
495 r1_w1->AddPreTargetHandler(&location_handler);
496 generator.ClickLeftButton();
497 r1_w1->RemovePreTargetHandler(&location_handler);
498 // Event-generator dispatches the event in the primary root-window's coord
499 // space. Since the location is (1060, 60), it goes to the secondary
500 // root-window as (30, 30) since the secondary root-window has a device scale
501 // factor of 2.
502 EXPECT_EQ(gfx::Point(1020, 20).ToString(),
503 location_handler.press_location().ToString());
504 EXPECT_EQ(gfx::Point(1020, 20).ToString(),
505 location_handler.release_location().ToString());
506}
507
[email protected]f059c6942012-07-21 14:27:57508TEST_F(ExtendedDesktopTest, MoveWindow) {
[email protected]f634dd32012-07-23 22:49:07509 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13510 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]f059c6942012-07-21 14:27:57511 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
512
513 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
514
515 d1->SetBounds(gfx::Rect(1010, 10, 100, 100));
jamescookb8dcef522016-06-25 14:42:55516 EXPECT_EQ("1010,10 100x100", d1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57517
518 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
519
520 d1->SetBounds(gfx::Rect(10, 10, 100, 100));
jamescookb8dcef522016-06-25 14:42:55521 EXPECT_EQ("10,10 100x100", d1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57522
523 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
524
525 // Make sure the bounds which doesn't fit to the root window
526 // works correctly.
527 d1->SetBounds(gfx::Rect(1560, 30, 100, 100));
528 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
jamescookb8dcef522016-06-25 14:42:55529 EXPECT_EQ("1560,30 100x100", d1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57530
531 // Setting outside of root windows will be moved to primary root window.
532 // TODO(oshima): This one probably should pick the closest root window.
533 d1->SetBounds(gfx::Rect(200, 10, 100, 100));
534 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
[email protected]f059c6942012-07-21 14:27:57535}
536
[email protected]2e98aaf72012-11-08 06:30:59537// Verifies if the mouse event arrives to the window even when the window
538// moves to another root in a pre-target handler. See: crbug.com/157583
539TEST_F(ExtendedDesktopTest, MoveWindowByMouseClick) {
540 UpdateDisplay("1000x600,600x400");
541
[email protected]c9390bd2013-11-08 20:33:13542 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]2e98aaf72012-11-08 06:30:59543 aura::test::EventCountDelegate delegate;
dchenga94547472016-04-08 08:41:11544 std::unique_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate(
[email protected]2e98aaf72012-11-08 06:30:59545 &delegate, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
[email protected]334e6182013-01-11 18:35:41546 MoveWindowByClickEventHandler event_handler(window.get());
547 window->AddPreTargetHandler(&event_handler);
548
[email protected]73c9fd02014-07-28 01:48:52549 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41550
551 event_generator.MoveMouseToCenterOf(window.get());
552 event_generator.ClickLeftButton();
[email protected]2e98aaf72012-11-08 06:30:59553 // Both mouse pressed and released arrive at the window and its delegate.
554 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset());
[email protected]334e6182013-01-11 18:35:41555 // Also event_handler moves the window to another root at mouse release.
[email protected]2e98aaf72012-11-08 06:30:59556 EXPECT_EQ(root_windows[1], window->GetRootWindow());
557}
558
[email protected]1a015382012-12-01 19:44:59559TEST_F(ExtendedDesktopTest, MoveWindowToDisplay) {
[email protected]e79f26e2012-08-09 07:12:48560 UpdateDisplay("1000x1000,1000x1000");
[email protected]c9390bd2013-11-08 20:33:13561 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]e79f26e2012-08-09 07:12:48562
oshimaf84b0da722016-04-27 19:47:19563 display::Display display0 = display::Screen::GetScreen()->GetDisplayMatching(
[email protected]ffabb1e2012-10-12 19:51:17564 root_windows[0]->GetBoundsInScreen());
oshimaf84b0da722016-04-27 19:47:19565 display::Display display1 = display::Screen::GetScreen()->GetDisplayMatching(
[email protected]ffabb1e2012-10-12 19:51:17566 root_windows[1]->GetBoundsInScreen());
[email protected]e79f26e2012-08-09 07:12:48567 EXPECT_NE(display0.id(), display1.id());
568
569 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 1000, 100));
570 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
571
572 // Move the window where the window spans both root windows. Since the second
573 // parameter is |display1|, the window should be shown on the secondary root.
574 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
575 display1);
jamescookb8dcef522016-06-25 14:42:55576 EXPECT_EQ("500,10 1000x100", d1->GetWindowBoundsInScreen().ToString());
[email protected]e79f26e2012-08-09 07:12:48577 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
578
579 // Move to the primary root.
580 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
581 display0);
jamescookb8dcef522016-06-25 14:42:55582 EXPECT_EQ("500,10 1000x100", d1->GetWindowBoundsInScreen().ToString());
[email protected]e79f26e2012-08-09 07:12:48583 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
584}
585
[email protected]f059c6942012-07-21 14:27:57586TEST_F(ExtendedDesktopTest, MoveWindowWithTransient) {
[email protected]f634dd32012-07-23 22:49:07587 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13588 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]f059c6942012-07-21 14:27:57589 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
590 views::Widget* w1_t1 = CreateTestWidgetWithParent(
591 w1, gfx::Rect(50, 50, 50, 50), false /* transient */);
592 // Transient child of the transient child.
593 views::Widget* w1_t11 = CreateTestWidgetWithParent(
[email protected]e6de8552014-05-23 19:05:39594 w1_t1, gfx::Rect(1200, 70, 35, 35), false /* transient */);
[email protected]f059c6942012-07-21 14:27:57595
jamescookb8dcef522016-06-25 14:42:55596 views::Widget* w11 = CreateTestWidgetWithParent(w1, gfx::Rect(10, 10, 40, 40),
597 true /* child */);
[email protected]f059c6942012-07-21 14:27:57598 views::Widget* w11_t1 = CreateTestWidgetWithParent(
599 w1, gfx::Rect(1300, 100, 80, 80), false /* transient */);
600
601 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
602 EXPECT_EQ(root_windows[0], w11->GetNativeView()->GetRootWindow());
603 EXPECT_EQ(root_windows[0], w1_t1->GetNativeView()->GetRootWindow());
604 EXPECT_EQ(root_windows[0], w1_t11->GetNativeView()->GetRootWindow());
605 EXPECT_EQ(root_windows[0], w11_t1->GetNativeView()->GetRootWindow());
jamescookb8dcef522016-06-25 14:42:55606 EXPECT_EQ("50,50 50x50", w1_t1->GetWindowBoundsInScreen().ToString());
607 EXPECT_EQ("1200,70 35x35", w1_t11->GetWindowBoundsInScreen().ToString());
608 EXPECT_EQ("20,20 40x40", w11->GetWindowBoundsInScreen().ToString());
609 EXPECT_EQ("1300,100 80x80", w11_t1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57610
[email protected]24f5e242014-07-22 02:16:09611 w1->SetBounds(gfx::Rect(1100, 10, 100, 100));
[email protected]f059c6942012-07-21 14:27:57612
613 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
614 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
615 EXPECT_EQ(root_windows[1], w1_t11->GetNativeView()->GetRootWindow());
616 EXPECT_EQ(root_windows[1], w11->GetNativeView()->GetRootWindow());
617 EXPECT_EQ(root_windows[1], w11_t1->GetNativeView()->GetRootWindow());
618
jamescookb8dcef522016-06-25 14:42:55619 EXPECT_EQ("1110,20 40x40", w11->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57620 // Transient window's screen bounds stays the same.
jamescookb8dcef522016-06-25 14:42:55621 EXPECT_EQ("50,50 50x50", w1_t1->GetWindowBoundsInScreen().ToString());
622 EXPECT_EQ("1200,70 35x35", w1_t11->GetWindowBoundsInScreen().ToString());
623 EXPECT_EQ("1300,100 80x80", w11_t1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57624
625 // Transient window doesn't move between root window unless
626 // its transient parent moves.
627 w1_t1->SetBounds(gfx::Rect(10, 50, 50, 50));
628 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
jamescookb8dcef522016-06-25 14:42:55629 EXPECT_EQ("10,50 50x50", w1_t1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57630}
631
[email protected]ca7060982012-08-08 18:05:25632// Test if the Window::ConvertPointToTarget works across root windows.
[email protected]a5e71c92012-06-22 22:09:08633TEST_F(ExtendedDesktopTest, ConvertPoint) {
oshimaf84b0da722016-04-27 19:47:19634 display::Screen* screen = display::Screen::GetScreen();
[email protected]f634dd32012-07-23 22:49:07635 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13636 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
oshimaf84b0da722016-04-27 19:47:19637 display::Display display_1 = screen->GetDisplayNearestWindow(root_windows[0]);
[email protected]a5e71c92012-06-22 22:09:08638 EXPECT_EQ("0,0", display_1.bounds().origin().ToString());
oshimaf84b0da722016-04-27 19:47:19639 display::Display display_2 = screen->GetDisplayNearestWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07640 EXPECT_EQ("1000,0", display_2.bounds().origin().ToString());
641
[email protected]a5e71c92012-06-22 22:09:08642 aura::Window* d1 =
643 CreateTestWidget(gfx::Rect(10, 10, 100, 100))->GetNativeView();
[email protected]a5e71c92012-06-22 22:09:08644 aura::Window* d2 =
[email protected]f634dd32012-07-23 22:49:07645 CreateTestWidget(gfx::Rect(1020, 20, 100, 100))->GetNativeView();
646 EXPECT_EQ(root_windows[0], d1->GetRootWindow());
647 EXPECT_EQ(root_windows[1], d2->GetRootWindow());
[email protected]a5e71c92012-06-22 22:09:08648
[email protected]a5e71c92012-06-22 22:09:08649 // Convert point in the Root2's window to the Root1's window Coord.
650 gfx::Point p(0, 0);
[email protected]ca7060982012-08-08 18:05:25651 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07652 EXPECT_EQ("1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08653 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25654 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07655 EXPECT_EQ("1010,10", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08656
657 // Convert point in the Root1's window to the Root2's window Coord.
658 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25659 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07660 EXPECT_EQ("-1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08661 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25662 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07663 EXPECT_EQ("-1010,-10", p.ToString());
664
665 // Move the 2nd display to the bottom and test again.
robliaoc0dfd6b2016-04-07 21:33:56666 SetSecondaryDisplayLayout(display::DisplayPlacement::BOTTOM);
[email protected]f634dd32012-07-23 22:49:07667
[email protected]b8984242013-07-12 07:55:38668 display_2 = screen->GetDisplayNearestWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07669 EXPECT_EQ("0,600", display_2.bounds().origin().ToString());
670
671 // Convert point in Root2's window to Root1's window Coord.
672 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25673 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07674 EXPECT_EQ("0,600", p.ToString());
675 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25676 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07677 EXPECT_EQ("10,610", p.ToString());
678
679 // Convert point in Root1's window to Root2's window Coord.
680 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25681 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07682 EXPECT_EQ("0,-600", p.ToString());
683 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25684 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07685 EXPECT_EQ("-10,-610", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08686}
[email protected]f634dd32012-07-23 22:49:07687
[email protected]263898a2012-09-17 17:20:07688TEST_F(ExtendedDesktopTest, OpenSystemTray) {
[email protected]596c61c2012-10-29 17:29:43689 UpdateDisplay("500x600,600x400");
skycb4be5b2017-04-06 17:52:45690 SystemTray* tray = ash::Shell::Get()->GetPrimarySystemTray();
[email protected]263898a2012-09-17 17:20:07691 ASSERT_FALSE(tray->HasSystemBubble());
692
[email protected]73c9fd02014-07-28 01:48:52693 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41694
[email protected]263898a2012-09-17 17:20:07695 // Opens the tray by a dummy click event and makes sure that adding/removing
696 // displays doesn't break anything.
[email protected]334e6182013-01-11 18:35:41697 event_generator.MoveMouseToCenterOf(tray->GetWidget()->GetNativeWindow());
[email protected]263898a2012-09-17 17:20:07698 event_generator.ClickLeftButton();
699 EXPECT_TRUE(tray->HasSystemBubble());
700
[email protected]596c61c2012-10-29 17:29:43701 UpdateDisplay("500x600");
[email protected]263898a2012-09-17 17:20:07702 EXPECT_TRUE(tray->HasSystemBubble());
[email protected]596c61c2012-10-29 17:29:43703 UpdateDisplay("500x600,600x400");
[email protected]263898a2012-09-17 17:20:07704 EXPECT_TRUE(tray->HasSystemBubble());
705
706 // Closes the tray and again makes sure that adding/removing displays doesn't
707 // break anything.
708 event_generator.ClickLeftButton();
709 RunAllPendingInMessageLoop();
710
711 EXPECT_FALSE(tray->HasSystemBubble());
712
[email protected]596c61c2012-10-29 17:29:43713 UpdateDisplay("500x600");
[email protected]263898a2012-09-17 17:20:07714 EXPECT_FALSE(tray->HasSystemBubble());
[email protected]596c61c2012-10-29 17:29:43715 UpdateDisplay("500x600,600x400");
[email protected]263898a2012-09-17 17:20:07716 EXPECT_FALSE(tray->HasSystemBubble());
717}
718
[email protected]578048512012-09-19 20:01:24719TEST_F(ExtendedDesktopTest, StayInSameRootWindow) {
720 UpdateDisplay("100x100,200x200");
[email protected]c9390bd2013-11-08 20:33:13721 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]a2e6af12013-01-07 21:40:35722 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 50, 50));
[email protected]578048512012-09-19 20:01:24723 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
724 w1->SetBounds(gfx::Rect(150, 10, 50, 50));
725 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
726
skyaecdb0fb2016-09-15 22:14:28727 // The widget stays in the same root if kLockedToRootKey is set to true.
728 w1->GetNativeView()->SetProperty(kLockedToRootKey, true);
[email protected]578048512012-09-19 20:01:24729 w1->SetBounds(gfx::Rect(10, 10, 50, 50));
730 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
731
732 // The widget should now move to the 1st root window without the property.
skyaecdb0fb2016-09-15 22:14:28733 w1->GetNativeView()->ClearProperty(kLockedToRootKey);
[email protected]578048512012-09-19 20:01:24734 w1->SetBounds(gfx::Rect(10, 10, 50, 50));
735 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
[email protected]e887c6c2013-07-08 19:35:53736
737 // a window in SettingsBubbleContainer and StatusContainer should
738 // not move to another root window regardles of the bounds specified.
739 aura::Window* settings_bubble_container =
740 Shell::GetPrimaryRootWindowController()->GetContainer(
[email protected]093b8d642014-04-03 20:59:28741 kShellWindowId_SettingBubbleContainer);
jamescookb8dcef522016-06-25 14:42:55742 aura::Window* window =
743 aura::test::CreateTestWindowWithId(100, settings_bubble_container);
sky8782ff02017-02-23 22:12:42744 window->SetBoundsInScreen(gfx::Rect(150, 10, 50, 50), GetSecondaryDisplay());
[email protected]e887c6c2013-07-08 19:35:53745 EXPECT_EQ(root_windows[0], window->GetRootWindow());
746
747 aura::Window* status_container =
748 Shell::GetPrimaryRootWindowController()->GetContainer(
[email protected]093b8d642014-04-03 20:59:28749 kShellWindowId_StatusContainer);
[email protected]e887c6c2013-07-08 19:35:53750 window = aura::test::CreateTestWindowWithId(100, status_container);
sky8782ff02017-02-23 22:12:42751 window->SetBoundsInScreen(gfx::Rect(150, 10, 50, 50), GetSecondaryDisplay());
[email protected]e887c6c2013-07-08 19:35:53752 EXPECT_EQ(root_windows[0], window->GetRootWindow());
[email protected]578048512012-09-19 20:01:24753}
754
[email protected]e67291f12012-10-10 05:52:38755TEST_F(ExtendedDesktopTest, KeyEventsOnLockScreen) {
756 UpdateDisplay("100x100,200x200");
[email protected]c9390bd2013-11-08 20:33:13757 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]e67291f12012-10-10 05:52:38758
759 // Create normal windows on both displays.
oshimaf84b0da722016-04-27 19:47:19760 views::Widget* widget1 = CreateTestWidget(
761 display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38762 widget1->Show();
763 EXPECT_EQ(root_windows[0], widget1->GetNativeView()->GetRootWindow());
sky8782ff02017-02-23 22:12:42764 views::Widget* widget2 = CreateTestWidget(GetSecondaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38765 widget2->Show();
766 EXPECT_EQ(root_windows[1], widget2->GetNativeView()->GetRootWindow());
767
768 // Create a LockScreen window.
oshimaf84b0da722016-04-27 19:47:19769 views::Widget* lock_widget = CreateTestWidget(
770 display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38771 views::Textfield* textfield = new views::Textfield;
[email protected]09148952013-03-13 13:25:43772 lock_widget->client_view()->AddChildView(textfield);
[email protected]e67291f12012-10-10 05:52:38773
[email protected]093b8d642014-04-03 20:59:28774 ash::Shell::GetContainer(Shell::GetPrimaryRootWindow(),
775 ash::kShellWindowId_LockScreenContainer)
776 ->AddChild(lock_widget->GetNativeView());
[email protected]e67291f12012-10-10 05:52:38777 lock_widget->Show();
778 textfield->RequestFocus();
779
[email protected]8cfb6722012-11-28 03:28:46780 aura::client::FocusClient* focus_client =
781 aura::client::GetFocusClient(root_windows[0]);
782 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]e67291f12012-10-10 05:52:38783
784 // The lock window should get events on both root windows.
[email protected]73c9fd02014-07-28 01:48:52785 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41786
[email protected]1ea46f6f2014-07-17 07:36:40787 event_generator.set_current_target(root_windows[0]);
[email protected]334e6182013-01-11 18:35:41788 event_generator.PressKey(ui::VKEY_A, 0);
789 event_generator.ReleaseKey(ui::VKEY_A, 0);
[email protected]8cfb6722012-11-28 03:28:46790 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46791 EXPECT_EQ("a", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38792
[email protected]1ea46f6f2014-07-17 07:36:40793 event_generator.set_current_target(root_windows[1]);
[email protected]334e6182013-01-11 18:35:41794 event_generator.PressKey(ui::VKEY_B, 0);
795 event_generator.ReleaseKey(ui::VKEY_B, 0);
[email protected]8cfb6722012-11-28 03:28:46796 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46797 EXPECT_EQ("ab", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38798
799 // Deleting 2nd display. The lock window still should get the events.
800 UpdateDisplay("100x100");
pkotwicz5d118a6b12015-02-12 22:23:57801 event_generator.set_current_target(root_windows[0]);
[email protected]334e6182013-01-11 18:35:41802 event_generator.PressKey(ui::VKEY_C, 0);
803 event_generator.ReleaseKey(ui::VKEY_C, 0);
[email protected]8cfb6722012-11-28 03:28:46804 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46805 EXPECT_EQ("abc", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38806
807 // Creating 2nd display again, and lock window still should get events
808 // on both root windows.
809 UpdateDisplay("100x100,200x200");
810 root_windows = Shell::GetAllRootWindows();
[email protected]1ea46f6f2014-07-17 07:36:40811 event_generator.set_current_target(root_windows[0]);
[email protected]334e6182013-01-11 18:35:41812 event_generator.PressKey(ui::VKEY_D, 0);
813 event_generator.ReleaseKey(ui::VKEY_D, 0);
[email protected]8cfb6722012-11-28 03:28:46814 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46815 EXPECT_EQ("abcd", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38816
[email protected]1ea46f6f2014-07-17 07:36:40817 event_generator.set_current_target(root_windows[1]);
[email protected]334e6182013-01-11 18:35:41818 event_generator.PressKey(ui::VKEY_E, 0);
819 event_generator.ReleaseKey(ui::VKEY_E, 0);
[email protected]8cfb6722012-11-28 03:28:46820 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46821 EXPECT_EQ("abcde", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38822}
823
[email protected]334e6182013-01-11 18:35:41824TEST_F(ExtendedDesktopTest, PassiveGrab) {
825 EventLocationRecordingEventHandler event_handler;
skycb4be5b2017-04-06 17:52:45826 ash::Shell::Get()->AddPreTargetHandler(&event_handler);
[email protected]334e6182013-01-11 18:35:41827
828 UpdateDisplay("300x300,200x200");
829
830 views::Widget* widget = CreateTestWidget(gfx::Rect(50, 50, 200, 200));
831 widget->Show();
832 ASSERT_EQ("50,50 200x200", widget->GetWindowBoundsInScreen().ToString());
833
[email protected]73c9fd02014-07-28 01:48:52834 ui::test::EventGenerator& generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41835 generator.MoveMouseTo(150, 150);
836 EXPECT_EQ("100,100 150,150", event_handler.GetLocationsAndReset());
837
838 generator.PressLeftButton();
839 generator.MoveMouseTo(400, 150);
840
841 EXPECT_EQ("350,100 400,150", event_handler.GetLocationsAndReset());
842
843 generator.ReleaseLeftButton();
844 EXPECT_EQ("-999,-999 -999,-999", event_handler.GetLocationsAndReset());
845
846 generator.MoveMouseTo(400, 150);
847 EXPECT_EQ("100,150 100,150", event_handler.GetLocationsAndReset());
848
skycb4be5b2017-04-06 17:52:45849 ash::Shell::Get()->RemovePreTargetHandler(&event_handler);
[email protected]334e6182013-01-11 18:35:41850}
851
[email protected]c39be8f2012-06-15 22:58:36852} // namespace ash