blob: ebdb54046f8a9cb6ca11cea702bb50df00388440 [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
sky0702b272016-06-03 22:10:415#include "ash/aura/wm_window_aura.h"
jamescook625f7912016-07-14 01:00:526#include "ash/common/system/tray/system_tray.h"
skyd6063772016-06-01 17:52:217#include "ash/common/wm/root_window_finder.h"
[email protected]6bdf7952012-11-14 10:10:588#include "ash/display/display_manager.h"
jamescook8800b8232016-10-19 12:46:279#include "ash/public/cpp/shell_window_ids.h"
[email protected]e887c6c2013-07-08 19:35:5310#include "ash/root_window_controller.h"
[email protected]c39be8f2012-06-15 22:58:3611#include "ash/shell.h"
12#include "ash/test/ash_test_base.h"
[email protected]578048512012-09-19 20:01:2413#include "ash/wm/window_properties.h"
[email protected]c39be8f2012-06-15 22:58:3614#include "ash/wm/window_util.h"
[email protected]0836da02013-06-10 19:33:3515#include "base/strings/string_util.h"
[email protected]74f778e2014-03-14 21:11:4616#include "base/strings/utf_string_conversions.h"
[email protected]c39be8f2012-06-15 22:58:3617#include "ui/aura/client/capture_client.h"
[email protected]8cfb6722012-11-28 03:28:4618#include "ui/aura/client/focus_client.h"
[email protected]a5e71c92012-06-22 22:09:0819#include "ui/aura/test/test_windows.h"
[email protected]553eae12013-02-01 02:33:5220#include "ui/aura/test/window_test_api.h"
[email protected]c39be8f2012-06-15 22:58:3621#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:2622#include "ui/aura/window_event_dispatcher.h"
[email protected]c39be8f2012-06-15 22:58:3623#include "ui/base/cursor/cursor.h"
oshimaf84b0da722016-04-27 19:47:1924#include "ui/display/display.h"
robliaoc0dfd6b2016-04-07 21:33:5625#include "ui/display/manager/display_layout.h"
oshimaf84b0da722016-04-27 19:47:1926#include "ui/display/screen.h"
[email protected]86ccbd42013-09-18 18:11:5427#include "ui/events/event_handler.h"
[email protected]73c9fd02014-07-28 01:48:5228#include "ui/events/test/event_generator.h"
[email protected]e67291f12012-10-10 05:52:3829#include "ui/views/controls/textfield/textfield.h"
[email protected]c39be8f2012-06-15 22:58:3630#include "ui/views/widget/widget.h"
31#include "ui/views/widget/widget_delegate.h"
[email protected]af4552b22014-03-21 19:45:0132#include "ui/wm/public/activation_client.h"
[email protected]c39be8f2012-06-15 22:58:3633
34namespace ash {
35namespace {
36
robliaoc0dfd6b2016-04-07 21:33:5637void SetSecondaryDisplayLayout(display::DisplayPlacement::Position position) {
dchenga94547472016-04-08 08:41:1138 std::unique_ptr<display::DisplayLayout> layout =
oshima5df139f2016-02-17 08:56:2139 Shell::GetInstance()->display_manager()->GetCurrentDisplayLayout().Copy();
robliaodf372032016-03-23 00:42:3440 layout->placement_list[0].position = position;
oshima5df139f2016-02-17 08:56:2141 Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays(
42 std::move(layout));
[email protected]edbfb8d2012-09-03 08:33:4343}
44
[email protected]c39be8f2012-06-15 22:58:3645class ModalWidgetDelegate : public views::WidgetDelegateView {
46 public:
47 ModalWidgetDelegate() {}
dcheng1f4538e2014-10-27 23:57:0548 ~ModalWidgetDelegate() override {}
[email protected]c39be8f2012-06-15 22:58:3649
50 // Overridden from views::WidgetDelegate:
dcheng1f4538e2014-10-27 23:57:0551 ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_SYSTEM; }
[email protected]c39be8f2012-06-15 22:58:3652
53 private:
54 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate);
55};
56
[email protected]334e6182013-01-11 18:35:4157// An event handler which moves the target window to the secondary root window
[email protected]2e98aaf72012-11-08 06:30:5958// at pre-handle phase of a mouse release event.
[email protected]334e6182013-01-11 18:35:4159class MoveWindowByClickEventHandler : public ui::EventHandler {
[email protected]2e98aaf72012-11-08 06:30:5960 public:
[email protected]334e6182013-01-11 18:35:4161 explicit MoveWindowByClickEventHandler(aura::Window* target)
[email protected]2e98aaf72012-11-08 06:30:5962 : target_(target) {}
dcheng1f4538e2014-10-27 23:57:0563 ~MoveWindowByClickEventHandler() override {}
[email protected]2e98aaf72012-11-08 06:30:5964
65 private:
66 // ui::EventHandler overrides:
dcheng1f4538e2014-10-27 23:57:0567 void OnMouseEvent(ui::MouseEvent* event) override {
[email protected]2e98aaf72012-11-08 06:30:5968 if (event->type() == ui::ET_MOUSE_RELEASED) {
[email protected]c9390bd2013-11-08 20:33:1369 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]2e98aaf72012-11-08 06:30:5970 DCHECK_LT(1u, root_windows.size());
71 root_windows[1]->AddChild(target_);
72 }
[email protected]2e98aaf72012-11-08 06:30:5973 }
74
[email protected]2e98aaf72012-11-08 06:30:5975 aura::Window* target_;
[email protected]334e6182013-01-11 18:35:4176 DISALLOW_COPY_AND_ASSIGN(MoveWindowByClickEventHandler);
77};
78
79// An event handler which records the event's locations.
80class EventLocationRecordingEventHandler : public ui::EventHandler {
81 public:
jamescookb8dcef522016-06-25 14:42:5582 explicit EventLocationRecordingEventHandler() { reset(); }
dcheng1f4538e2014-10-27 23:57:0583 ~EventLocationRecordingEventHandler() override {}
[email protected]334e6182013-01-11 18:35:4184
85 std::string GetLocationsAndReset() {
jamescookb8dcef522016-06-25 14:42:5586 std::string result = location_.ToString() + " " + root_location_.ToString();
[email protected]334e6182013-01-11 18:35:4187 reset();
88 return result;
89 }
90
91 private:
92 // ui::EventHandler overrides:
dcheng1f4538e2014-10-27 23:57:0593 void OnMouseEvent(ui::MouseEvent* event) override {
[email protected]334e6182013-01-11 18:35:4194 if (event->type() == ui::ET_MOUSE_MOVED ||
95 event->type() == ui::ET_MOUSE_DRAGGED) {
96 location_ = event->location();
97 root_location_ = event->root_location();
98 }
99 }
100
101 void reset() {
102 location_.SetPoint(-999, -999);
103 root_location_.SetPoint(-999, -999);
104 }
105
106 gfx::Point root_location_;
107 gfx::Point location_;
108
109 DISALLOW_COPY_AND_ASSIGN(EventLocationRecordingEventHandler);
[email protected]2e98aaf72012-11-08 06:30:59110};
111
[email protected]2ca75942014-07-12 04:46:37112class EventLocationHandler : public ui::EventHandler {
113 public:
114 EventLocationHandler() {}
dcheng1f4538e2014-10-27 23:57:05115 ~EventLocationHandler() override {}
[email protected]2ca75942014-07-12 04:46:37116
117 const gfx::Point& press_location() const { return press_location_; }
118 const gfx::Point& release_location() const { return release_location_; }
119
120 private:
121 // ui::EventHandler:
dcheng1f4538e2014-10-27 23:57:05122 void OnMouseEvent(ui::MouseEvent* event) override {
[email protected]2ca75942014-07-12 04:46:37123 if (event->type() == ui::ET_MOUSE_PRESSED)
124 press_location_ = event->location();
125 else if (event->type() == ui::ET_MOUSE_RELEASED)
126 release_location_ = event->location();
127 }
128
129 gfx::Point press_location_;
130 gfx::Point release_location_;
131
132 DISALLOW_COPY_AND_ASSIGN(EventLocationHandler);
133};
134
[email protected]c39be8f2012-06-15 22:58:36135} // namespace
136
[email protected]a2e6af12013-01-07 21:40:35137class ExtendedDesktopTest : public test::AshTestBase {
138 public:
139 views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
oshima95d499b2016-02-10 03:49:56140 return CreateTestWidgetWithParentAndContext(nullptr, CurrentContext(),
141 bounds, false);
[email protected]a2e6af12013-01-07 21:40:35142 }
143
144 views::Widget* CreateTestWidgetWithParent(views::Widget* parent,
145 const gfx::Rect& bounds,
146 bool child) {
147 CHECK(parent);
oshima95d499b2016-02-10 03:49:56148 return CreateTestWidgetWithParentAndContext(parent, nullptr, bounds, child);
[email protected]a2e6af12013-01-07 21:40:35149 }
150
151 views::Widget* CreateTestWidgetWithParentAndContext(views::Widget* parent,
152 gfx::NativeView context,
153 const gfx::Rect& bounds,
154 bool child) {
155 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
156 if (parent)
157 params.parent = parent->GetNativeView();
158 params.context = context;
159 params.bounds = bounds;
160 params.child = child;
161 views::Widget* widget = new views::Widget;
162 widget->Init(params);
163 widget->Show();
164 return widget;
165 }
166};
[email protected]c39be8f2012-06-15 22:58:36167
168// Test conditions that root windows in extended desktop mode
169// must satisfy.
170TEST_F(ExtendedDesktopTest, Basic) {
[email protected]e75642a2013-06-12 17:21:18171 if (!SupportsMultipleDisplays())
172 return;
173
[email protected]f634dd32012-07-23 22:49:07174 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13175 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36176
177 // All root windows must have the root window controller.
178 ASSERT_EQ(2U, root_windows.size());
[email protected]c9390bd2013-11-08 20:33:13179 for (aura::Window::Windows::const_iterator iter = root_windows.begin();
[email protected]c39be8f2012-06-15 22:58:36180 iter != root_windows.end(); ++iter) {
oshima95d499b2016-02-10 03:49:56181 EXPECT_TRUE(GetRootWindowController(*iter) != nullptr);
[email protected]c39be8f2012-06-15 22:58:36182 }
183 // Make sure root windows share the same controllers.
[email protected]8cfb6722012-11-28 03:28:46184 EXPECT_EQ(aura::client::GetFocusClient(root_windows[0]),
185 aura::client::GetFocusClient(root_windows[1]));
[email protected]c39be8f2012-06-15 22:58:36186 EXPECT_EQ(aura::client::GetActivationClient(root_windows[0]),
187 aura::client::GetActivationClient(root_windows[1]));
188 EXPECT_EQ(aura::client::GetCaptureClient(root_windows[0]),
189 aura::client::GetCaptureClient(root_windows[1]));
190}
191
192TEST_F(ExtendedDesktopTest, Activation) {
[email protected]e75642a2013-06-12 17:21:18193 if (!SupportsMultipleDisplays())
194 return;
195
[email protected]f634dd32012-07-23 22:49:07196 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13197 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36198
[email protected]c39be8f2012-06-15 22:58:36199 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]f634dd32012-07-23 22:49:07200 views::Widget* widget_on_2nd =
201 CreateTestWidget(gfx::Rect(1200, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36202 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
[email protected]f634dd32012-07-23 22:49:07203 EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36204
205 EXPECT_EQ(widget_on_2nd->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46206 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]c39be8f2012-06-15 22:58:36207 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
208
[email protected]73c9fd02014-07-28 01:48:52209 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]f634dd32012-07-23 22:49:07210 // Clicking a window changes the active window and active root window.
[email protected]334e6182013-01-11 18:35:41211 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
212 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36213
214 EXPECT_EQ(widget_on_1st->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46215 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]c39be8f2012-06-15 22:58:36216 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]f634dd32012-07-23 22:49:07217
[email protected]334e6182013-01-11 18:35:41218 event_generator.MoveMouseToCenterOf(widget_on_2nd->GetNativeView());
219 event_generator.ClickLeftButton();
[email protected]f634dd32012-07-23 22:49:07220
221 EXPECT_EQ(widget_on_2nd->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46222 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]f634dd32012-07-23 22:49:07223 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
[email protected]c39be8f2012-06-15 22:58:36224}
225
226TEST_F(ExtendedDesktopTest, SystemModal) {
[email protected]e75642a2013-06-12 17:21:18227 if (!SupportsMultipleDisplays())
228 return;
229
[email protected]f634dd32012-07-23 22:49:07230 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13231 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36232
233 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36234 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]492533b32012-09-21 19:06:14235 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
[email protected]d17642d2013-09-12 23:44:38236 EXPECT_EQ(root_windows[0], Shell::GetTargetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36237
[email protected]c39be8f2012-06-15 22:58:36238 // Open system modal. Make sure it's on 2nd root window and active.
[email protected]a2e6af12013-01-07 21:40:35239 views::Widget* modal_widget = views::Widget::CreateWindowWithContextAndBounds(
jamescookb8dcef522016-06-25 14:42:55240 new ModalWidgetDelegate(), CurrentContext(),
[email protected]a2e6af12013-01-07 21:40:35241 gfx::Rect(1200, 100, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36242 modal_widget->Show();
243 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
244 EXPECT_EQ(root_windows[1], modal_widget->GetNativeView()->GetRootWindow());
[email protected]d17642d2013-09-12 23:44:38245 EXPECT_EQ(root_windows[1], Shell::GetTargetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36246
[email protected]73c9fd02014-07-28 01:48:52247 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41248
[email protected]2e236a52012-06-27 22:21:47249 // Clicking a widget on widget_on_1st display should not change activation.
[email protected]334e6182013-01-11 18:35:41250 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
251 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36252 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
[email protected]d17642d2013-09-12 23:44:38253 EXPECT_EQ(root_windows[1], Shell::GetTargetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36254
255 // Close system modal and so clicking a widget should work now.
256 modal_widget->Close();
[email protected]334e6182013-01-11 18:35:41257 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
258 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36259 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]d17642d2013-09-12 23:44:38260 EXPECT_EQ(root_windows[0], Shell::GetTargetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36261}
262
263TEST_F(ExtendedDesktopTest, TestCursor) {
[email protected]e75642a2013-06-12 17:21:18264 if (!SupportsMultipleDisplays())
265 return;
266
[email protected]f634dd32012-07-23 22:49:07267 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13268 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]2374d1812014-03-04 03:42:27269 aura::WindowTreeHost* host0 = root_windows[0]->GetHost();
270 aura::WindowTreeHost* host1 = root_windows[1]->GetHost();
271 EXPECT_EQ(ui::kCursorPointer, host0->last_cursor().native_type());
kylechard642dcb2016-02-22 15:50:03272 EXPECT_EQ(ui::kCursorNull, host1->last_cursor().native_type());
[email protected]151ffdff2012-09-11 20:18:35273 Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorCopy);
[email protected]2374d1812014-03-04 03:42:27274 EXPECT_EQ(ui::kCursorCopy, host0->last_cursor().native_type());
275 EXPECT_EQ(ui::kCursorCopy, host1->last_cursor().native_type());
[email protected]c39be8f2012-06-15 22:58:36276}
277
[email protected]718b26c2012-07-24 20:53:23278TEST_F(ExtendedDesktopTest, TestCursorLocation) {
[email protected]e75642a2013-06-12 17:21:18279 if (!SupportsMultipleDisplays())
280 return;
281
[email protected]d0064722013-03-14 18:16:43282 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13283 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]553eae12013-02-01 02:33:52284 aura::test::WindowTestApi root_window0_test_api(root_windows[0]);
285 aura::test::WindowTestApi root_window1_test_api(root_windows[1]);
[email protected]718b26c2012-07-24 20:53:23286
287 root_windows[0]->MoveCursorTo(gfx::Point(10, 10));
scottmge8b042972016-01-27 05:07:35288 EXPECT_EQ("10,10",
oshimaf84b0da722016-04-27 19:47:19289 display::Screen::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23290 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
291 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
292 root_windows[1]->MoveCursorTo(gfx::Point(10, 20));
scottmge8b042972016-01-27 05:07:35293 EXPECT_EQ("1010,20",
oshimaf84b0da722016-04-27 19:47:19294 display::Screen::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23295 EXPECT_FALSE(root_window0_test_api.ContainsMouse());
296 EXPECT_TRUE(root_window1_test_api.ContainsMouse());
297 root_windows[0]->MoveCursorTo(gfx::Point(20, 10));
scottmge8b042972016-01-27 05:07:35298 EXPECT_EQ("20,10",
oshimaf84b0da722016-04-27 19:47:19299 display::Screen::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23300 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
301 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
302}
303
[email protected]20c59762012-06-23 01:10:24304TEST_F(ExtendedDesktopTest, GetRootWindowAt) {
[email protected]e75642a2013-06-12 17:21:18305 if (!SupportsMultipleDisplays())
306 return;
307
[email protected]f634dd32012-07-23 22:49:07308 UpdateDisplay("700x500,500x500");
robliaoc0dfd6b2016-04-07 21:33:56309 SetSecondaryDisplayLayout(display::DisplayPlacement::LEFT);
[email protected]c9390bd2013-11-08 20:33:13310 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24311
sky0702b272016-06-03 22:10:41312 EXPECT_EQ(root_windows[1], WmWindowAura::GetAuraWindow(
skya6d587a62016-04-20 02:58:05313 wm::GetRootWindowAt(gfx::Point(-400, 100))));
sky0702b272016-06-03 22:10:41314 EXPECT_EQ(root_windows[1], WmWindowAura::GetAuraWindow(
skya6d587a62016-04-20 02:58:05315 wm::GetRootWindowAt(gfx::Point(-1, 100))));
sky0702b272016-06-03 22:10:41316 EXPECT_EQ(root_windows[0], WmWindowAura::GetAuraWindow(
skya6d587a62016-04-20 02:58:05317 wm::GetRootWindowAt(gfx::Point(0, 300))));
sky0702b272016-06-03 22:10:41318 EXPECT_EQ(root_windows[0], WmWindowAura::GetAuraWindow(
skya6d587a62016-04-20 02:58:05319 wm::GetRootWindowAt(gfx::Point(700, 300))));
[email protected]20c59762012-06-23 01:10:24320
321 // Zero origin.
sky0702b272016-06-03 22:10:41322 EXPECT_EQ(root_windows[0],
323 WmWindowAura::GetAuraWindow(wm::GetRootWindowAt(gfx::Point(0, 0))));
[email protected]20c59762012-06-23 01:10:24324
[email protected]36168852014-01-07 12:23:28325 // Out of range point should return the nearest root window
sky0702b272016-06-03 22:10:41326 EXPECT_EQ(root_windows[1], WmWindowAura::GetAuraWindow(
skya6d587a62016-04-20 02:58:05327 wm::GetRootWindowAt(gfx::Point(-600, 0))));
sky0702b272016-06-03 22:10:41328 EXPECT_EQ(root_windows[0], WmWindowAura::GetAuraWindow(
skya6d587a62016-04-20 02:58:05329 wm::GetRootWindowAt(gfx::Point(701, 100))));
[email protected]20c59762012-06-23 01:10:24330}
331
332TEST_F(ExtendedDesktopTest, GetRootWindowMatching) {
[email protected]e75642a2013-06-12 17:21:18333 if (!SupportsMultipleDisplays())
334 return;
335
[email protected]f634dd32012-07-23 22:49:07336 UpdateDisplay("700x500,500x500");
robliaoc0dfd6b2016-04-07 21:33:56337 SetSecondaryDisplayLayout(display::DisplayPlacement::LEFT);
[email protected]66b05eac2012-06-27 23:53:10338
[email protected]c9390bd2013-11-08 20:33:13339 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24340
341 // Containing rect.
342 EXPECT_EQ(root_windows[1],
sky0702b272016-06-03 22:10:41343 WmWindowAura::GetAuraWindow(
skya6d587a62016-04-20 02:58:05344 wm::GetRootWindowMatching(gfx::Rect(-300, 10, 50, 50))));
[email protected]20c59762012-06-23 01:10:24345 EXPECT_EQ(root_windows[0],
sky0702b272016-06-03 22:10:41346 WmWindowAura::GetAuraWindow(
skya6d587a62016-04-20 02:58:05347 wm::GetRootWindowMatching(gfx::Rect(100, 10, 50, 50))));
[email protected]20c59762012-06-23 01:10:24348
349 // Intersecting rect.
350 EXPECT_EQ(root_windows[1],
sky0702b272016-06-03 22:10:41351 WmWindowAura::GetAuraWindow(
skya6d587a62016-04-20 02:58:05352 wm::GetRootWindowMatching(gfx::Rect(-200, 0, 300, 300))));
[email protected]20c59762012-06-23 01:10:24353 EXPECT_EQ(root_windows[0],
sky0702b272016-06-03 22:10:41354 WmWindowAura::GetAuraWindow(
skya6d587a62016-04-20 02:58:05355 wm::GetRootWindowMatching(gfx::Rect(-100, 0, 300, 300))));
[email protected]20c59762012-06-23 01:10:24356
357 // Zero origin.
[email protected]66b05eac2012-06-27 23:53:10358 EXPECT_EQ(root_windows[0],
sky0702b272016-06-03 22:10:41359 WmWindowAura::GetAuraWindow(
skya6d587a62016-04-20 02:58:05360 wm::GetRootWindowMatching(gfx::Rect(0, 0, 0, 0))));
[email protected]66b05eac2012-06-27 23:53:10361 EXPECT_EQ(root_windows[0],
sky0702b272016-06-03 22:10:41362 WmWindowAura::GetAuraWindow(
skya6d587a62016-04-20 02:58:05363 wm::GetRootWindowMatching(gfx::Rect(0, 0, 1, 1))));
[email protected]20c59762012-06-23 01:10:24364
365 // Empty rect.
366 EXPECT_EQ(root_windows[1],
sky0702b272016-06-03 22:10:41367 WmWindowAura::GetAuraWindow(
skya6d587a62016-04-20 02:58:05368 wm::GetRootWindowMatching(gfx::Rect(-400, 100, 0, 0))));
[email protected]20c59762012-06-23 01:10:24369 EXPECT_EQ(root_windows[0],
sky0702b272016-06-03 22:10:41370 WmWindowAura::GetAuraWindow(
skya6d587a62016-04-20 02:58:05371 wm::GetRootWindowMatching(gfx::Rect(100, 100, 0, 0))));
[email protected]20c59762012-06-23 01:10:24372
373 // Out of range rect should return the primary root window.
374 EXPECT_EQ(root_windows[0],
sky0702b272016-06-03 22:10:41375 WmWindowAura::GetAuraWindow(
skya6d587a62016-04-20 02:58:05376 wm::GetRootWindowMatching(gfx::Rect(-600, -300, 50, 50))));
[email protected]20c59762012-06-23 01:10:24377 EXPECT_EQ(root_windows[0],
sky0702b272016-06-03 22:10:41378 WmWindowAura::GetAuraWindow(
skya6d587a62016-04-20 02:58:05379 wm::GetRootWindowMatching(gfx::Rect(0, 1000, 50, 50))));
[email protected]0f81f442012-06-22 06:20:27380}
381
[email protected]1a015382012-12-01 19:44:59382TEST_F(ExtendedDesktopTest, Capture) {
[email protected]e75642a2013-06-12 17:21:18383 if (!SupportsMultipleDisplays())
384 return;
385
[email protected]f634dd32012-07-23 22:49:07386 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13387 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]a5e71c92012-06-22 22:09:08388
389 aura::test::EventCountDelegate r1_d1;
390 aura::test::EventCountDelegate r1_d2;
391 aura::test::EventCountDelegate r2_d1;
392
dchenga94547472016-04-08 08:41:11393 std::unique_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]a5e71c92012-06-22 22:09:08394 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11395 std::unique_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
[email protected]a5e71c92012-06-22 22:09:08396 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11397 std::unique_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]a5e71c92012-06-22 22:09:08398 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
[email protected]f634dd32012-07-23 22:49:07399
[email protected]a5e71c92012-06-22 22:09:08400 r1_w1->SetCapture();
401
402 EXPECT_EQ(r1_w1.get(),
403 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]334e6182013-01-11 18:35:41404
[email protected]73c9fd02014-07-28 01:48:52405 ui::test::EventGenerator& generator = GetEventGenerator();
[email protected]d05cf2f2014-02-26 05:31:43406 generator.MoveMouseToCenterOf(r2_w1.get());
407 // |r1_w1| will receive the events because it has capture.
408 EXPECT_EQ("1 1 0", r1_d1.GetMouseMotionCountsAndReset());
409 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
410 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
411
412 generator.ClickLeftButton();
[email protected]a5e71c92012-06-22 22:09:08413 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
414 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
[email protected]b19ba4adf2012-09-07 16:13:29415 // The mouse is outside. On chromeos, the mouse is warped to the
416 // dest root window, but it's not implemented on Win yet, so
417 // no mouse move event on Win.
[email protected]d05cf2f2014-02-26 05:31:43418 EXPECT_EQ("0 0 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08419 EXPECT_EQ("1 1", r1_d1.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43420
421 generator.MoveMouseTo(15, 15);
[email protected]f634dd32012-07-23 22:49:07422 EXPECT_EQ("0 1 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43423 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08424
425 r1_w2->SetCapture();
426 EXPECT_EQ(r1_w2.get(),
427 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]d05cf2f2014-02-26 05:31:43428 generator.MoveMouseBy(10, 10);
429 // |r1_w2| has the capture. So it will receive the mouse-move event.
430 EXPECT_EQ("0 0 0", r1_d1.GetMouseMotionCountsAndReset());
431 EXPECT_EQ("0 1 0", r1_d2.GetMouseMotionCountsAndReset());
432 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
433
434 generator.ClickLeftButton();
[email protected]a5e71c92012-06-22 22:09:08435 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
436 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43437 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08438 EXPECT_EQ("1 1", r1_d2.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43439
[email protected]a5e71c92012-06-22 22:09:08440 r1_w2->ReleaseCapture();
oshima95d499b2016-02-10 03:49:56441 EXPECT_EQ(nullptr, aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]d05cf2f2014-02-26 05:31:43442
443 generator.MoveMouseToCenterOf(r2_w1.get());
444 generator.ClickLeftButton();
[email protected]a5e71c92012-06-22 22:09:08445 EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset());
446 EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset());
447 // Make sure the mouse_moved_handler_ is properly reset.
448 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
449 EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset());
450}
451
[email protected]2ca75942014-07-12 04:46:37452TEST_F(ExtendedDesktopTest, CaptureEventLocation) {
453 if (!SupportsMultipleDisplays())
454 return;
455
456 UpdateDisplay("1000x600,600x400");
457 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
458
459 aura::test::EventCountDelegate r1_d1;
460 aura::test::EventCountDelegate r1_d2;
461 aura::test::EventCountDelegate r2_d1;
462
dchenga94547472016-04-08 08:41:11463 std::unique_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37464 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11465 std::unique_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37466 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11467 std::unique_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37468 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
469
470 r1_w1->SetCapture();
471
[email protected]73c9fd02014-07-28 01:48:52472 ui::test::EventGenerator& generator = GetEventGenerator();
[email protected]2ca75942014-07-12 04:46:37473 generator.MoveMouseToCenterOf(r2_w1.get());
474 EXPECT_EQ(gfx::Point(1060, 60).ToString(),
475 generator.current_location().ToString());
476
477 EventLocationHandler location_handler;
478 r1_w1->AddPreTargetHandler(&location_handler);
479 generator.ClickLeftButton();
480 r1_w1->RemovePreTargetHandler(&location_handler);
481 EXPECT_EQ(gfx::Point(1050, 50).ToString(),
482 location_handler.press_location().ToString());
483 EXPECT_EQ(gfx::Point(1050, 50).ToString(),
484 location_handler.release_location().ToString());
485}
486
487TEST_F(ExtendedDesktopTest, CaptureEventLocationHighDPI) {
488 if (!SupportsMultipleDisplays())
489 return;
490
491 UpdateDisplay("1000x600*2,600x400");
492 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
493
494 aura::test::EventCountDelegate r1_d1;
495 aura::test::EventCountDelegate r1_d2;
496 aura::test::EventCountDelegate r2_d1;
497
dchenga94547472016-04-08 08:41:11498 std::unique_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37499 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11500 std::unique_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37501 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11502 std::unique_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37503 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
504
505 r1_w1->SetCapture();
506
[email protected]73c9fd02014-07-28 01:48:52507 ui::test::EventGenerator& generator = GetEventGenerator();
[email protected]2ca75942014-07-12 04:46:37508 generator.MoveMouseToCenterOf(r2_w1.get());
509 EXPECT_EQ(gfx::Point(560, 60).ToString(),
510 generator.current_location().ToString());
511
512 EventLocationHandler location_handler;
513 r1_w1->AddPreTargetHandler(&location_handler);
514 generator.ClickLeftButton();
515 r1_w1->RemovePreTargetHandler(&location_handler);
516 EXPECT_EQ(gfx::Point(550, 50).ToString(),
517 location_handler.press_location().ToString());
518 EXPECT_EQ(gfx::Point(550, 50).ToString(),
519 location_handler.release_location().ToString());
520}
521
522TEST_F(ExtendedDesktopTest, CaptureEventLocationHighDPI_2) {
523 if (!SupportsMultipleDisplays())
524 return;
525
526 UpdateDisplay("1000x600,600x400*2");
527 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
528
529 aura::test::EventCountDelegate r1_d1;
530 aura::test::EventCountDelegate r1_d2;
531 aura::test::EventCountDelegate r2_d1;
532
dchenga94547472016-04-08 08:41:11533 std::unique_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37534 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11535 std::unique_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37536 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11537 std::unique_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37538 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
539
540 r1_w1->SetCapture();
541
[email protected]73c9fd02014-07-28 01:48:52542 ui::test::EventGenerator& generator = GetEventGenerator();
[email protected]2ca75942014-07-12 04:46:37543 generator.MoveMouseToCenterOf(r2_w1.get());
544 EXPECT_EQ(gfx::Point(1060, 60).ToString(),
545 generator.current_location().ToString());
546
547 EventLocationHandler location_handler;
548 r1_w1->AddPreTargetHandler(&location_handler);
549 generator.ClickLeftButton();
550 r1_w1->RemovePreTargetHandler(&location_handler);
551 // Event-generator dispatches the event in the primary root-window's coord
552 // space. Since the location is (1060, 60), it goes to the secondary
553 // root-window as (30, 30) since the secondary root-window has a device scale
554 // factor of 2.
555 EXPECT_EQ(gfx::Point(1020, 20).ToString(),
556 location_handler.press_location().ToString());
557 EXPECT_EQ(gfx::Point(1020, 20).ToString(),
558 location_handler.release_location().ToString());
559}
560
[email protected]f059c6942012-07-21 14:27:57561TEST_F(ExtendedDesktopTest, MoveWindow) {
[email protected]e75642a2013-06-12 17:21:18562 if (!SupportsMultipleDisplays())
563 return;
564
[email protected]f634dd32012-07-23 22:49:07565 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13566 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]f059c6942012-07-21 14:27:57567 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
568
569 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
570
571 d1->SetBounds(gfx::Rect(1010, 10, 100, 100));
jamescookb8dcef522016-06-25 14:42:55572 EXPECT_EQ("1010,10 100x100", d1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57573
574 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
575
576 d1->SetBounds(gfx::Rect(10, 10, 100, 100));
jamescookb8dcef522016-06-25 14:42:55577 EXPECT_EQ("10,10 100x100", d1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57578
579 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
580
581 // Make sure the bounds which doesn't fit to the root window
582 // works correctly.
583 d1->SetBounds(gfx::Rect(1560, 30, 100, 100));
584 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
jamescookb8dcef522016-06-25 14:42:55585 EXPECT_EQ("1560,30 100x100", d1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57586
587 // Setting outside of root windows will be moved to primary root window.
588 // TODO(oshima): This one probably should pick the closest root window.
589 d1->SetBounds(gfx::Rect(200, 10, 100, 100));
590 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
[email protected]f059c6942012-07-21 14:27:57591}
592
[email protected]2e98aaf72012-11-08 06:30:59593// Verifies if the mouse event arrives to the window even when the window
594// moves to another root in a pre-target handler. See: crbug.com/157583
595TEST_F(ExtendedDesktopTest, MoveWindowByMouseClick) {
[email protected]e75642a2013-06-12 17:21:18596 if (!SupportsMultipleDisplays())
597 return;
598
[email protected]2e98aaf72012-11-08 06:30:59599 UpdateDisplay("1000x600,600x400");
600
[email protected]c9390bd2013-11-08 20:33:13601 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]2e98aaf72012-11-08 06:30:59602 aura::test::EventCountDelegate delegate;
dchenga94547472016-04-08 08:41:11603 std::unique_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate(
[email protected]2e98aaf72012-11-08 06:30:59604 &delegate, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
[email protected]334e6182013-01-11 18:35:41605 MoveWindowByClickEventHandler event_handler(window.get());
606 window->AddPreTargetHandler(&event_handler);
607
[email protected]73c9fd02014-07-28 01:48:52608 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41609
610 event_generator.MoveMouseToCenterOf(window.get());
611 event_generator.ClickLeftButton();
[email protected]2e98aaf72012-11-08 06:30:59612 // Both mouse pressed and released arrive at the window and its delegate.
613 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset());
[email protected]334e6182013-01-11 18:35:41614 // Also event_handler moves the window to another root at mouse release.
[email protected]2e98aaf72012-11-08 06:30:59615 EXPECT_EQ(root_windows[1], window->GetRootWindow());
616}
617
[email protected]1a015382012-12-01 19:44:59618TEST_F(ExtendedDesktopTest, MoveWindowToDisplay) {
[email protected]e75642a2013-06-12 17:21:18619 if (!SupportsMultipleDisplays())
620 return;
621
[email protected]e79f26e2012-08-09 07:12:48622 UpdateDisplay("1000x1000,1000x1000");
[email protected]c9390bd2013-11-08 20:33:13623 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]e79f26e2012-08-09 07:12:48624
oshimaf84b0da722016-04-27 19:47:19625 display::Display display0 = display::Screen::GetScreen()->GetDisplayMatching(
[email protected]ffabb1e2012-10-12 19:51:17626 root_windows[0]->GetBoundsInScreen());
oshimaf84b0da722016-04-27 19:47:19627 display::Display display1 = display::Screen::GetScreen()->GetDisplayMatching(
[email protected]ffabb1e2012-10-12 19:51:17628 root_windows[1]->GetBoundsInScreen());
[email protected]e79f26e2012-08-09 07:12:48629 EXPECT_NE(display0.id(), display1.id());
630
631 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 1000, 100));
632 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
633
634 // Move the window where the window spans both root windows. Since the second
635 // parameter is |display1|, the window should be shown on the secondary root.
636 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
637 display1);
jamescookb8dcef522016-06-25 14:42:55638 EXPECT_EQ("500,10 1000x100", d1->GetWindowBoundsInScreen().ToString());
[email protected]e79f26e2012-08-09 07:12:48639 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
640
641 // Move to the primary root.
642 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
643 display0);
jamescookb8dcef522016-06-25 14:42:55644 EXPECT_EQ("500,10 1000x100", d1->GetWindowBoundsInScreen().ToString());
[email protected]e79f26e2012-08-09 07:12:48645 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
646}
647
[email protected]f059c6942012-07-21 14:27:57648TEST_F(ExtendedDesktopTest, MoveWindowWithTransient) {
[email protected]e75642a2013-06-12 17:21:18649 if (!SupportsMultipleDisplays())
650 return;
651
[email protected]f634dd32012-07-23 22:49:07652 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13653 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]f059c6942012-07-21 14:27:57654 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
655 views::Widget* w1_t1 = CreateTestWidgetWithParent(
656 w1, gfx::Rect(50, 50, 50, 50), false /* transient */);
657 // Transient child of the transient child.
658 views::Widget* w1_t11 = CreateTestWidgetWithParent(
[email protected]e6de8552014-05-23 19:05:39659 w1_t1, gfx::Rect(1200, 70, 35, 35), false /* transient */);
[email protected]f059c6942012-07-21 14:27:57660
jamescookb8dcef522016-06-25 14:42:55661 views::Widget* w11 = CreateTestWidgetWithParent(w1, gfx::Rect(10, 10, 40, 40),
662 true /* child */);
[email protected]f059c6942012-07-21 14:27:57663 views::Widget* w11_t1 = CreateTestWidgetWithParent(
664 w1, gfx::Rect(1300, 100, 80, 80), false /* transient */);
665
666 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
667 EXPECT_EQ(root_windows[0], w11->GetNativeView()->GetRootWindow());
668 EXPECT_EQ(root_windows[0], w1_t1->GetNativeView()->GetRootWindow());
669 EXPECT_EQ(root_windows[0], w1_t11->GetNativeView()->GetRootWindow());
670 EXPECT_EQ(root_windows[0], w11_t1->GetNativeView()->GetRootWindow());
jamescookb8dcef522016-06-25 14:42:55671 EXPECT_EQ("50,50 50x50", w1_t1->GetWindowBoundsInScreen().ToString());
672 EXPECT_EQ("1200,70 35x35", w1_t11->GetWindowBoundsInScreen().ToString());
673 EXPECT_EQ("20,20 40x40", w11->GetWindowBoundsInScreen().ToString());
674 EXPECT_EQ("1300,100 80x80", w11_t1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57675
[email protected]24f5e242014-07-22 02:16:09676 w1->SetBounds(gfx::Rect(1100, 10, 100, 100));
[email protected]f059c6942012-07-21 14:27:57677
678 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
679 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
680 EXPECT_EQ(root_windows[1], w1_t11->GetNativeView()->GetRootWindow());
681 EXPECT_EQ(root_windows[1], w11->GetNativeView()->GetRootWindow());
682 EXPECT_EQ(root_windows[1], w11_t1->GetNativeView()->GetRootWindow());
683
jamescookb8dcef522016-06-25 14:42:55684 EXPECT_EQ("1110,20 40x40", w11->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57685 // Transient window's screen bounds stays the same.
jamescookb8dcef522016-06-25 14:42:55686 EXPECT_EQ("50,50 50x50", w1_t1->GetWindowBoundsInScreen().ToString());
687 EXPECT_EQ("1200,70 35x35", w1_t11->GetWindowBoundsInScreen().ToString());
688 EXPECT_EQ("1300,100 80x80", w11_t1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57689
690 // Transient window doesn't move between root window unless
691 // its transient parent moves.
692 w1_t1->SetBounds(gfx::Rect(10, 50, 50, 50));
693 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
jamescookb8dcef522016-06-25 14:42:55694 EXPECT_EQ("10,50 50x50", w1_t1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57695}
696
[email protected]ca7060982012-08-08 18:05:25697// Test if the Window::ConvertPointToTarget works across root windows.
[email protected]a5e71c92012-06-22 22:09:08698// TODO(oshima): Move multiple display suport and this test to aura.
699TEST_F(ExtendedDesktopTest, ConvertPoint) {
[email protected]e75642a2013-06-12 17:21:18700 if (!SupportsMultipleDisplays())
701 return;
oshimaf84b0da722016-04-27 19:47:19702 display::Screen* screen = display::Screen::GetScreen();
[email protected]f634dd32012-07-23 22:49:07703 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13704 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
oshimaf84b0da722016-04-27 19:47:19705 display::Display display_1 = screen->GetDisplayNearestWindow(root_windows[0]);
[email protected]a5e71c92012-06-22 22:09:08706 EXPECT_EQ("0,0", display_1.bounds().origin().ToString());
oshimaf84b0da722016-04-27 19:47:19707 display::Display display_2 = screen->GetDisplayNearestWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07708 EXPECT_EQ("1000,0", display_2.bounds().origin().ToString());
709
[email protected]a5e71c92012-06-22 22:09:08710 aura::Window* d1 =
711 CreateTestWidget(gfx::Rect(10, 10, 100, 100))->GetNativeView();
[email protected]a5e71c92012-06-22 22:09:08712 aura::Window* d2 =
[email protected]f634dd32012-07-23 22:49:07713 CreateTestWidget(gfx::Rect(1020, 20, 100, 100))->GetNativeView();
714 EXPECT_EQ(root_windows[0], d1->GetRootWindow());
715 EXPECT_EQ(root_windows[1], d2->GetRootWindow());
[email protected]a5e71c92012-06-22 22:09:08716
[email protected]a5e71c92012-06-22 22:09:08717 // Convert point in the Root2's window to the Root1's window Coord.
718 gfx::Point p(0, 0);
[email protected]ca7060982012-08-08 18:05:25719 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07720 EXPECT_EQ("1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08721 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25722 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07723 EXPECT_EQ("1010,10", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08724
725 // Convert point in the Root1's window to the Root2's window Coord.
726 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25727 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07728 EXPECT_EQ("-1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08729 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25730 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07731 EXPECT_EQ("-1010,-10", p.ToString());
732
733 // Move the 2nd display to the bottom and test again.
robliaoc0dfd6b2016-04-07 21:33:56734 SetSecondaryDisplayLayout(display::DisplayPlacement::BOTTOM);
[email protected]f634dd32012-07-23 22:49:07735
[email protected]b8984242013-07-12 07:55:38736 display_2 = screen->GetDisplayNearestWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07737 EXPECT_EQ("0,600", display_2.bounds().origin().ToString());
738
739 // Convert point in Root2's window to Root1's window Coord.
740 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25741 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07742 EXPECT_EQ("0,600", p.ToString());
743 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25744 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07745 EXPECT_EQ("10,610", p.ToString());
746
747 // Convert point in Root1's window to Root2's window Coord.
748 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25749 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07750 EXPECT_EQ("0,-600", p.ToString());
751 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25752 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07753 EXPECT_EQ("-10,-610", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08754}
[email protected]f634dd32012-07-23 22:49:07755
[email protected]263898a2012-09-17 17:20:07756TEST_F(ExtendedDesktopTest, OpenSystemTray) {
[email protected]e75642a2013-06-12 17:21:18757 if (!SupportsMultipleDisplays())
758 return;
759
[email protected]596c61c2012-10-29 17:29:43760 UpdateDisplay("500x600,600x400");
[email protected]a0afeb12012-12-10 22:57:09761 SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray();
[email protected]263898a2012-09-17 17:20:07762 ASSERT_FALSE(tray->HasSystemBubble());
763
[email protected]73c9fd02014-07-28 01:48:52764 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41765
[email protected]263898a2012-09-17 17:20:07766 // Opens the tray by a dummy click event and makes sure that adding/removing
767 // displays doesn't break anything.
[email protected]334e6182013-01-11 18:35:41768 event_generator.MoveMouseToCenterOf(tray->GetWidget()->GetNativeWindow());
[email protected]263898a2012-09-17 17:20:07769 event_generator.ClickLeftButton();
770 EXPECT_TRUE(tray->HasSystemBubble());
771
[email protected]596c61c2012-10-29 17:29:43772 UpdateDisplay("500x600");
[email protected]263898a2012-09-17 17:20:07773 EXPECT_TRUE(tray->HasSystemBubble());
[email protected]596c61c2012-10-29 17:29:43774 UpdateDisplay("500x600,600x400");
[email protected]263898a2012-09-17 17:20:07775 EXPECT_TRUE(tray->HasSystemBubble());
776
777 // Closes the tray and again makes sure that adding/removing displays doesn't
778 // break anything.
779 event_generator.ClickLeftButton();
780 RunAllPendingInMessageLoop();
781
782 EXPECT_FALSE(tray->HasSystemBubble());
783
[email protected]596c61c2012-10-29 17:29:43784 UpdateDisplay("500x600");
[email protected]263898a2012-09-17 17:20:07785 EXPECT_FALSE(tray->HasSystemBubble());
[email protected]596c61c2012-10-29 17:29:43786 UpdateDisplay("500x600,600x400");
[email protected]263898a2012-09-17 17:20:07787 EXPECT_FALSE(tray->HasSystemBubble());
788}
789
[email protected]578048512012-09-19 20:01:24790TEST_F(ExtendedDesktopTest, StayInSameRootWindow) {
[email protected]e75642a2013-06-12 17:21:18791 if (!SupportsMultipleDisplays())
792 return;
793
[email protected]578048512012-09-19 20:01:24794 UpdateDisplay("100x100,200x200");
[email protected]c9390bd2013-11-08 20:33:13795 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]a2e6af12013-01-07 21:40:35796 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 50, 50));
[email protected]578048512012-09-19 20:01:24797 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
798 w1->SetBounds(gfx::Rect(150, 10, 50, 50));
799 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
800
skyaecdb0fb2016-09-15 22:14:28801 // The widget stays in the same root if kLockedToRootKey is set to true.
802 w1->GetNativeView()->SetProperty(kLockedToRootKey, true);
[email protected]578048512012-09-19 20:01:24803 w1->SetBounds(gfx::Rect(10, 10, 50, 50));
804 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
805
806 // The widget should now move to the 1st root window without the property.
skyaecdb0fb2016-09-15 22:14:28807 w1->GetNativeView()->ClearProperty(kLockedToRootKey);
[email protected]578048512012-09-19 20:01:24808 w1->SetBounds(gfx::Rect(10, 10, 50, 50));
809 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
[email protected]e887c6c2013-07-08 19:35:53810
811 // a window in SettingsBubbleContainer and StatusContainer should
812 // not move to another root window regardles of the bounds specified.
813 aura::Window* settings_bubble_container =
814 Shell::GetPrimaryRootWindowController()->GetContainer(
[email protected]093b8d642014-04-03 20:59:28815 kShellWindowId_SettingBubbleContainer);
jamescookb8dcef522016-06-25 14:42:55816 aura::Window* window =
817 aura::test::CreateTestWindowWithId(100, settings_bubble_container);
[email protected]e887c6c2013-07-08 19:35:53818 window->SetBoundsInScreen(gfx::Rect(150, 10, 50, 50),
rjkroege980ccfd2016-10-06 18:00:24819 display_manager()->GetSecondaryDisplay());
[email protected]e887c6c2013-07-08 19:35:53820 EXPECT_EQ(root_windows[0], window->GetRootWindow());
821
822 aura::Window* status_container =
823 Shell::GetPrimaryRootWindowController()->GetContainer(
[email protected]093b8d642014-04-03 20:59:28824 kShellWindowId_StatusContainer);
[email protected]e887c6c2013-07-08 19:35:53825 window = aura::test::CreateTestWindowWithId(100, status_container);
826 window->SetBoundsInScreen(gfx::Rect(150, 10, 50, 50),
rjkroege980ccfd2016-10-06 18:00:24827 display_manager()->GetSecondaryDisplay());
[email protected]e887c6c2013-07-08 19:35:53828 EXPECT_EQ(root_windows[0], window->GetRootWindow());
[email protected]578048512012-09-19 20:01:24829}
830
[email protected]e67291f12012-10-10 05:52:38831TEST_F(ExtendedDesktopTest, KeyEventsOnLockScreen) {
[email protected]e75642a2013-06-12 17:21:18832 if (!SupportsMultipleDisplays())
833 return;
834
[email protected]e67291f12012-10-10 05:52:38835 UpdateDisplay("100x100,200x200");
[email protected]c9390bd2013-11-08 20:33:13836 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]e67291f12012-10-10 05:52:38837
838 // Create normal windows on both displays.
oshimaf84b0da722016-04-27 19:47:19839 views::Widget* widget1 = CreateTestWidget(
840 display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38841 widget1->Show();
842 EXPECT_EQ(root_windows[0], widget1->GetNativeView()->GetRootWindow());
jamescookb8dcef522016-06-25 14:42:55843 views::Widget* widget2 =
rjkroege980ccfd2016-10-06 18:00:24844 CreateTestWidget(display_manager()->GetSecondaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38845 widget2->Show();
846 EXPECT_EQ(root_windows[1], widget2->GetNativeView()->GetRootWindow());
847
848 // Create a LockScreen window.
oshimaf84b0da722016-04-27 19:47:19849 views::Widget* lock_widget = CreateTestWidget(
850 display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38851 views::Textfield* textfield = new views::Textfield;
[email protected]09148952013-03-13 13:25:43852 lock_widget->client_view()->AddChildView(textfield);
[email protected]e67291f12012-10-10 05:52:38853
[email protected]093b8d642014-04-03 20:59:28854 ash::Shell::GetContainer(Shell::GetPrimaryRootWindow(),
855 ash::kShellWindowId_LockScreenContainer)
856 ->AddChild(lock_widget->GetNativeView());
[email protected]e67291f12012-10-10 05:52:38857 lock_widget->Show();
858 textfield->RequestFocus();
859
[email protected]8cfb6722012-11-28 03:28:46860 aura::client::FocusClient* focus_client =
861 aura::client::GetFocusClient(root_windows[0]);
862 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]e67291f12012-10-10 05:52:38863
864 // The lock window should get events on both root windows.
[email protected]73c9fd02014-07-28 01:48:52865 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41866
[email protected]1ea46f6f2014-07-17 07:36:40867 event_generator.set_current_target(root_windows[0]);
[email protected]334e6182013-01-11 18:35:41868 event_generator.PressKey(ui::VKEY_A, 0);
869 event_generator.ReleaseKey(ui::VKEY_A, 0);
[email protected]8cfb6722012-11-28 03:28:46870 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46871 EXPECT_EQ("a", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38872
[email protected]1ea46f6f2014-07-17 07:36:40873 event_generator.set_current_target(root_windows[1]);
[email protected]334e6182013-01-11 18:35:41874 event_generator.PressKey(ui::VKEY_B, 0);
875 event_generator.ReleaseKey(ui::VKEY_B, 0);
[email protected]8cfb6722012-11-28 03:28:46876 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46877 EXPECT_EQ("ab", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38878
879 // Deleting 2nd display. The lock window still should get the events.
880 UpdateDisplay("100x100");
pkotwicz5d118a6b12015-02-12 22:23:57881 event_generator.set_current_target(root_windows[0]);
[email protected]334e6182013-01-11 18:35:41882 event_generator.PressKey(ui::VKEY_C, 0);
883 event_generator.ReleaseKey(ui::VKEY_C, 0);
[email protected]8cfb6722012-11-28 03:28:46884 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46885 EXPECT_EQ("abc", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38886
887 // Creating 2nd display again, and lock window still should get events
888 // on both root windows.
889 UpdateDisplay("100x100,200x200");
890 root_windows = Shell::GetAllRootWindows();
[email protected]1ea46f6f2014-07-17 07:36:40891 event_generator.set_current_target(root_windows[0]);
[email protected]334e6182013-01-11 18:35:41892 event_generator.PressKey(ui::VKEY_D, 0);
893 event_generator.ReleaseKey(ui::VKEY_D, 0);
[email protected]8cfb6722012-11-28 03:28:46894 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46895 EXPECT_EQ("abcd", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38896
[email protected]1ea46f6f2014-07-17 07:36:40897 event_generator.set_current_target(root_windows[1]);
[email protected]334e6182013-01-11 18:35:41898 event_generator.PressKey(ui::VKEY_E, 0);
899 event_generator.ReleaseKey(ui::VKEY_E, 0);
[email protected]8cfb6722012-11-28 03:28:46900 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46901 EXPECT_EQ("abcde", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38902}
903
[email protected]334e6182013-01-11 18:35:41904TEST_F(ExtendedDesktopTest, PassiveGrab) {
[email protected]e75642a2013-06-12 17:21:18905 if (!SupportsMultipleDisplays())
906 return;
907
[email protected]334e6182013-01-11 18:35:41908 EventLocationRecordingEventHandler event_handler;
909 ash::Shell::GetInstance()->AddPreTargetHandler(&event_handler);
910
911 UpdateDisplay("300x300,200x200");
912
913 views::Widget* widget = CreateTestWidget(gfx::Rect(50, 50, 200, 200));
914 widget->Show();
915 ASSERT_EQ("50,50 200x200", widget->GetWindowBoundsInScreen().ToString());
916
[email protected]73c9fd02014-07-28 01:48:52917 ui::test::EventGenerator& generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41918 generator.MoveMouseTo(150, 150);
919 EXPECT_EQ("100,100 150,150", event_handler.GetLocationsAndReset());
920
921 generator.PressLeftButton();
922 generator.MoveMouseTo(400, 150);
923
924 EXPECT_EQ("350,100 400,150", event_handler.GetLocationsAndReset());
925
926 generator.ReleaseLeftButton();
927 EXPECT_EQ("-999,-999 -999,-999", event_handler.GetLocationsAndReset());
928
929 generator.MoveMouseTo(400, 150);
930 EXPECT_EQ("100,150 100,150", event_handler.GetLocationsAndReset());
931
932 ash::Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
933}
934
[email protected]c39be8f2012-06-15 22:58:36935} // namespace ash