blob: 444f39b76eeddb9dc730eeb1f704fe7b903890d1 [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
James Cook6def4d9d2017-03-05 22:13:475#include "ash/common/system/tray/system_tray.h"
James Cook643b7182017-03-05 22:02:586#include "ash/common/wm/root_window_finder.h"
James Cook6316a552017-03-05 21:46:217#include "ash/common/wm_window.h"
jamescook8800b8232016-10-19 12:46:278#include "ash/public/cpp/shell_window_ids.h"
[email protected]e887c6c2013-07-08 19:35:539#include "ash/root_window_controller.h"
[email protected]c39be8f2012-06-15 22:58:3610#include "ash/shell.h"
11#include "ash/test/ash_test_base.h"
[email protected]578048512012-09-19 20:01:2412#include "ash/wm/window_properties.h"
[email protected]c39be8f2012-06-15 22:58:3613#include "ash/wm/window_util.h"
[email protected]0836da02013-06-10 19:33:3514#include "base/strings/string_util.h"
[email protected]74f778e2014-03-14 21:11:4615#include "base/strings/utf_string_conversions.h"
[email protected]c39be8f2012-06-15 22:58:3616#include "ui/aura/client/capture_client.h"
[email protected]8cfb6722012-11-28 03:28:4617#include "ui/aura/client/focus_client.h"
[email protected]a5e71c92012-06-22 22:09:0818#include "ui/aura/test/test_windows.h"
[email protected]553eae12013-02-01 02:33:5219#include "ui/aura/test/window_test_api.h"
[email protected]c39be8f2012-06-15 22:58:3620#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:2621#include "ui/aura/window_event_dispatcher.h"
[email protected]c39be8f2012-06-15 22:58:3622#include "ui/base/cursor/cursor.h"
oshimaf84b0da722016-04-27 19:47:1923#include "ui/display/display.h"
kylechar731f85f92016-12-01 20:50:4624#include "ui/display/display_layout.h"
rjkroege72f8154f2016-10-29 00:49:0225#include "ui/display/manager/display_manager.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 =
skycb4be5b2017-04-06 17:52:4539 Shell::Get()->display_manager()->GetCurrentDisplayLayout().Copy();
robliaodf372032016-03-23 00:42:3440 layout->placement_list[0].position = position;
skycb4be5b2017-04-06 17:52:4541 Shell::Get()->display_manager()->SetLayoutForCurrentDisplays(
oshima5df139f2016-02-17 08:56:2142 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]f634dd32012-07-23 22:49:07171 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13172 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36173
174 // All root windows must have the root window controller.
175 ASSERT_EQ(2U, root_windows.size());
[email protected]c9390bd2013-11-08 20:33:13176 for (aura::Window::Windows::const_iterator iter = root_windows.begin();
[email protected]c39be8f2012-06-15 22:58:36177 iter != root_windows.end(); ++iter) {
oshima95d499b2016-02-10 03:49:56178 EXPECT_TRUE(GetRootWindowController(*iter) != nullptr);
[email protected]c39be8f2012-06-15 22:58:36179 }
180 // Make sure root windows share the same controllers.
[email protected]8cfb6722012-11-28 03:28:46181 EXPECT_EQ(aura::client::GetFocusClient(root_windows[0]),
182 aura::client::GetFocusClient(root_windows[1]));
[email protected]c39be8f2012-06-15 22:58:36183 EXPECT_EQ(aura::client::GetActivationClient(root_windows[0]),
184 aura::client::GetActivationClient(root_windows[1]));
185 EXPECT_EQ(aura::client::GetCaptureClient(root_windows[0]),
186 aura::client::GetCaptureClient(root_windows[1]));
187}
188
189TEST_F(ExtendedDesktopTest, Activation) {
[email protected]f634dd32012-07-23 22:49:07190 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13191 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36192
[email protected]c39be8f2012-06-15 22:58:36193 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]f634dd32012-07-23 22:49:07194 views::Widget* widget_on_2nd =
195 CreateTestWidget(gfx::Rect(1200, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36196 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
[email protected]f634dd32012-07-23 22:49:07197 EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36198
199 EXPECT_EQ(widget_on_2nd->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46200 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]c39be8f2012-06-15 22:58:36201 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
202
[email protected]73c9fd02014-07-28 01:48:52203 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]f634dd32012-07-23 22:49:07204 // Clicking a window changes the active window and active root window.
[email protected]334e6182013-01-11 18:35:41205 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
206 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36207
208 EXPECT_EQ(widget_on_1st->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46209 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]c39be8f2012-06-15 22:58:36210 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]f634dd32012-07-23 22:49:07211
[email protected]334e6182013-01-11 18:35:41212 event_generator.MoveMouseToCenterOf(widget_on_2nd->GetNativeView());
213 event_generator.ClickLeftButton();
[email protected]f634dd32012-07-23 22:49:07214
215 EXPECT_EQ(widget_on_2nd->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46216 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]f634dd32012-07-23 22:49:07217 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
[email protected]c39be8f2012-06-15 22:58:36218}
219
220TEST_F(ExtendedDesktopTest, SystemModal) {
[email protected]f634dd32012-07-23 22:49:07221 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13222 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36223
224 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36225 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]492533b32012-09-21 19:06:14226 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
sky27344382017-03-08 21:30:32227 EXPECT_EQ(root_windows[0], Shell::GetRootWindowForNewWindows());
[email protected]c39be8f2012-06-15 22:58:36228
[email protected]c39be8f2012-06-15 22:58:36229 // Open system modal. Make sure it's on 2nd root window and active.
[email protected]a2e6af12013-01-07 21:40:35230 views::Widget* modal_widget = views::Widget::CreateWindowWithContextAndBounds(
jamescookb8dcef522016-06-25 14:42:55231 new ModalWidgetDelegate(), CurrentContext(),
[email protected]a2e6af12013-01-07 21:40:35232 gfx::Rect(1200, 100, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36233 modal_widget->Show();
234 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
235 EXPECT_EQ(root_windows[1], modal_widget->GetNativeView()->GetRootWindow());
sky27344382017-03-08 21:30:32236 EXPECT_EQ(root_windows[1], Shell::GetRootWindowForNewWindows());
[email protected]c39be8f2012-06-15 22:58:36237
[email protected]73c9fd02014-07-28 01:48:52238 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41239
[email protected]2e236a52012-06-27 22:21:47240 // Clicking a widget on widget_on_1st display should not change activation.
[email protected]334e6182013-01-11 18:35:41241 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
242 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36243 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
sky27344382017-03-08 21:30:32244 EXPECT_EQ(root_windows[1], Shell::GetRootWindowForNewWindows());
[email protected]c39be8f2012-06-15 22:58:36245
246 // Close system modal and so clicking a widget should work now.
247 modal_widget->Close();
[email protected]334e6182013-01-11 18:35:41248 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
249 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36250 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
sky27344382017-03-08 21:30:32251 EXPECT_EQ(root_windows[0], Shell::GetRootWindowForNewWindows());
[email protected]c39be8f2012-06-15 22:58:36252}
253
254TEST_F(ExtendedDesktopTest, TestCursor) {
[email protected]f634dd32012-07-23 22:49:07255 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13256 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]2374d1812014-03-04 03:42:27257 aura::WindowTreeHost* host0 = root_windows[0]->GetHost();
258 aura::WindowTreeHost* host1 = root_windows[1]->GetHost();
259 EXPECT_EQ(ui::kCursorPointer, host0->last_cursor().native_type());
kylechard642dcb2016-02-22 15:50:03260 EXPECT_EQ(ui::kCursorNull, host1->last_cursor().native_type());
skycb4be5b2017-04-06 17:52:45261 Shell::Get()->cursor_manager()->SetCursor(ui::kCursorCopy);
[email protected]2374d1812014-03-04 03:42:27262 EXPECT_EQ(ui::kCursorCopy, host0->last_cursor().native_type());
263 EXPECT_EQ(ui::kCursorCopy, host1->last_cursor().native_type());
[email protected]c39be8f2012-06-15 22:58:36264}
265
[email protected]718b26c2012-07-24 20:53:23266TEST_F(ExtendedDesktopTest, TestCursorLocation) {
[email protected]d0064722013-03-14 18:16:43267 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13268 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]553eae12013-02-01 02:33:52269 aura::test::WindowTestApi root_window0_test_api(root_windows[0]);
270 aura::test::WindowTestApi root_window1_test_api(root_windows[1]);
[email protected]718b26c2012-07-24 20:53:23271
272 root_windows[0]->MoveCursorTo(gfx::Point(10, 10));
scottmge8b042972016-01-27 05:07:35273 EXPECT_EQ("10,10",
oshimaf84b0da722016-04-27 19:47:19274 display::Screen::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23275 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
276 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
277 root_windows[1]->MoveCursorTo(gfx::Point(10, 20));
scottmge8b042972016-01-27 05:07:35278 EXPECT_EQ("1010,20",
oshimaf84b0da722016-04-27 19:47:19279 display::Screen::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23280 EXPECT_FALSE(root_window0_test_api.ContainsMouse());
281 EXPECT_TRUE(root_window1_test_api.ContainsMouse());
282 root_windows[0]->MoveCursorTo(gfx::Point(20, 10));
scottmge8b042972016-01-27 05:07:35283 EXPECT_EQ("20,10",
oshimaf84b0da722016-04-27 19:47:19284 display::Screen::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23285 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
286 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
287}
288
[email protected]20c59762012-06-23 01:10:24289TEST_F(ExtendedDesktopTest, GetRootWindowAt) {
[email protected]f634dd32012-07-23 22:49:07290 UpdateDisplay("700x500,500x500");
robliaoc0dfd6b2016-04-07 21:33:56291 SetSecondaryDisplayLayout(display::DisplayPlacement::LEFT);
[email protected]c9390bd2013-11-08 20:33:13292 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24293
sky5dbc91d52017-01-13 00:26:14294 EXPECT_EQ(root_windows[1], WmWindow::GetAuraWindow(
skya6d587a62016-04-20 02:58:05295 wm::GetRootWindowAt(gfx::Point(-400, 100))));
sky5dbc91d52017-01-13 00:26:14296 EXPECT_EQ(root_windows[1],
297 WmWindow::GetAuraWindow(wm::GetRootWindowAt(gfx::Point(-1, 100))));
298 EXPECT_EQ(root_windows[0],
299 WmWindow::GetAuraWindow(wm::GetRootWindowAt(gfx::Point(0, 300))));
300 EXPECT_EQ(root_windows[0],
301 WmWindow::GetAuraWindow(wm::GetRootWindowAt(gfx::Point(700, 300))));
[email protected]20c59762012-06-23 01:10:24302
303 // Zero origin.
sky0702b272016-06-03 22:10:41304 EXPECT_EQ(root_windows[0],
sky5dbc91d52017-01-13 00:26:14305 WmWindow::GetAuraWindow(wm::GetRootWindowAt(gfx::Point(0, 0))));
[email protected]20c59762012-06-23 01:10:24306
[email protected]36168852014-01-07 12:23:28307 // Out of range point should return the nearest root window
sky5dbc91d52017-01-13 00:26:14308 EXPECT_EQ(root_windows[1],
309 WmWindow::GetAuraWindow(wm::GetRootWindowAt(gfx::Point(-600, 0))));
310 EXPECT_EQ(root_windows[0],
311 WmWindow::GetAuraWindow(wm::GetRootWindowAt(gfx::Point(701, 100))));
[email protected]20c59762012-06-23 01:10:24312}
313
314TEST_F(ExtendedDesktopTest, GetRootWindowMatching) {
[email protected]f634dd32012-07-23 22:49:07315 UpdateDisplay("700x500,500x500");
robliaoc0dfd6b2016-04-07 21:33:56316 SetSecondaryDisplayLayout(display::DisplayPlacement::LEFT);
[email protected]66b05eac2012-06-27 23:53:10317
[email protected]c9390bd2013-11-08 20:33:13318 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24319
320 // Containing rect.
sky5dbc91d52017-01-13 00:26:14321 EXPECT_EQ(root_windows[1], WmWindow::GetAuraWindow(wm::GetRootWindowMatching(
322 gfx::Rect(-300, 10, 50, 50))));
323 EXPECT_EQ(root_windows[0], WmWindow::GetAuraWindow(wm::GetRootWindowMatching(
324 gfx::Rect(100, 10, 50, 50))));
[email protected]20c59762012-06-23 01:10:24325
326 // Intersecting rect.
sky5dbc91d52017-01-13 00:26:14327 EXPECT_EQ(root_windows[1], WmWindow::GetAuraWindow(wm::GetRootWindowMatching(
328 gfx::Rect(-200, 0, 300, 300))));
329 EXPECT_EQ(root_windows[0], WmWindow::GetAuraWindow(wm::GetRootWindowMatching(
330 gfx::Rect(-100, 0, 300, 300))));
[email protected]20c59762012-06-23 01:10:24331
332 // Zero origin.
sky5dbc91d52017-01-13 00:26:14333 EXPECT_EQ(root_windows[0], WmWindow::GetAuraWindow(wm::GetRootWindowMatching(
334 gfx::Rect(0, 0, 0, 0))));
335 EXPECT_EQ(root_windows[0], WmWindow::GetAuraWindow(wm::GetRootWindowMatching(
336 gfx::Rect(0, 0, 1, 1))));
[email protected]20c59762012-06-23 01:10:24337
338 // Empty rect.
sky5dbc91d52017-01-13 00:26:14339 EXPECT_EQ(root_windows[1], WmWindow::GetAuraWindow(wm::GetRootWindowMatching(
340 gfx::Rect(-400, 100, 0, 0))));
341 EXPECT_EQ(root_windows[0], WmWindow::GetAuraWindow(wm::GetRootWindowMatching(
342 gfx::Rect(100, 100, 0, 0))));
[email protected]20c59762012-06-23 01:10:24343
344 // Out of range rect should return the primary root window.
sky5dbc91d52017-01-13 00:26:14345 EXPECT_EQ(root_windows[0], WmWindow::GetAuraWindow(wm::GetRootWindowMatching(
346 gfx::Rect(-600, -300, 50, 50))));
347 EXPECT_EQ(root_windows[0], WmWindow::GetAuraWindow(wm::GetRootWindowMatching(
348 gfx::Rect(0, 1000, 50, 50))));
[email protected]0f81f442012-06-22 06:20:27349}
350
[email protected]1a015382012-12-01 19:44:59351TEST_F(ExtendedDesktopTest, Capture) {
[email protected]f634dd32012-07-23 22:49:07352 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13353 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]a5e71c92012-06-22 22:09:08354
355 aura::test::EventCountDelegate r1_d1;
356 aura::test::EventCountDelegate r1_d2;
357 aura::test::EventCountDelegate r2_d1;
358
dchenga94547472016-04-08 08:41:11359 std::unique_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]a5e71c92012-06-22 22:09:08360 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11361 std::unique_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
[email protected]a5e71c92012-06-22 22:09:08362 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11363 std::unique_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]a5e71c92012-06-22 22:09:08364 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
[email protected]f634dd32012-07-23 22:49:07365
[email protected]a5e71c92012-06-22 22:09:08366 r1_w1->SetCapture();
367
368 EXPECT_EQ(r1_w1.get(),
369 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]334e6182013-01-11 18:35:41370
[email protected]73c9fd02014-07-28 01:48:52371 ui::test::EventGenerator& generator = GetEventGenerator();
[email protected]d05cf2f2014-02-26 05:31:43372 generator.MoveMouseToCenterOf(r2_w1.get());
373 // |r1_w1| will receive the events because it has capture.
374 EXPECT_EQ("1 1 0", r1_d1.GetMouseMotionCountsAndReset());
375 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
376 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
377
378 generator.ClickLeftButton();
[email protected]a5e71c92012-06-22 22:09:08379 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
380 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
[email protected]b19ba4adf2012-09-07 16:13:29381 // The mouse is outside. On chromeos, the mouse is warped to the
382 // dest root window, but it's not implemented on Win yet, so
383 // no mouse move event on Win.
[email protected]d05cf2f2014-02-26 05:31:43384 EXPECT_EQ("0 0 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08385 EXPECT_EQ("1 1", r1_d1.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43386
387 generator.MoveMouseTo(15, 15);
[email protected]f634dd32012-07-23 22:49:07388 EXPECT_EQ("0 1 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43389 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08390
391 r1_w2->SetCapture();
392 EXPECT_EQ(r1_w2.get(),
393 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]d05cf2f2014-02-26 05:31:43394 generator.MoveMouseBy(10, 10);
395 // |r1_w2| has the capture. So it will receive the mouse-move event.
396 EXPECT_EQ("0 0 0", r1_d1.GetMouseMotionCountsAndReset());
397 EXPECT_EQ("0 1 0", r1_d2.GetMouseMotionCountsAndReset());
398 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
399
400 generator.ClickLeftButton();
[email protected]a5e71c92012-06-22 22:09:08401 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
402 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43403 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08404 EXPECT_EQ("1 1", r1_d2.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43405
[email protected]a5e71c92012-06-22 22:09:08406 r1_w2->ReleaseCapture();
oshima95d499b2016-02-10 03:49:56407 EXPECT_EQ(nullptr, aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]d05cf2f2014-02-26 05:31:43408
409 generator.MoveMouseToCenterOf(r2_w1.get());
410 generator.ClickLeftButton();
[email protected]a5e71c92012-06-22 22:09:08411 EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset());
412 EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset());
413 // Make sure the mouse_moved_handler_ is properly reset.
414 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
415 EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset());
416}
417
[email protected]2ca75942014-07-12 04:46:37418TEST_F(ExtendedDesktopTest, CaptureEventLocation) {
[email protected]2ca75942014-07-12 04:46:37419 UpdateDisplay("1000x600,600x400");
420 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
421
422 aura::test::EventCountDelegate r1_d1;
423 aura::test::EventCountDelegate r1_d2;
424 aura::test::EventCountDelegate r2_d1;
425
dchenga94547472016-04-08 08:41:11426 std::unique_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37427 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11428 std::unique_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37429 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11430 std::unique_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37431 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
432
433 r1_w1->SetCapture();
434
[email protected]73c9fd02014-07-28 01:48:52435 ui::test::EventGenerator& generator = GetEventGenerator();
[email protected]2ca75942014-07-12 04:46:37436 generator.MoveMouseToCenterOf(r2_w1.get());
437 EXPECT_EQ(gfx::Point(1060, 60).ToString(),
438 generator.current_location().ToString());
439
440 EventLocationHandler location_handler;
441 r1_w1->AddPreTargetHandler(&location_handler);
442 generator.ClickLeftButton();
443 r1_w1->RemovePreTargetHandler(&location_handler);
444 EXPECT_EQ(gfx::Point(1050, 50).ToString(),
445 location_handler.press_location().ToString());
446 EXPECT_EQ(gfx::Point(1050, 50).ToString(),
447 location_handler.release_location().ToString());
448}
449
450TEST_F(ExtendedDesktopTest, CaptureEventLocationHighDPI) {
[email protected]2ca75942014-07-12 04:46:37451 UpdateDisplay("1000x600*2,600x400");
452 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
453
454 aura::test::EventCountDelegate r1_d1;
455 aura::test::EventCountDelegate r1_d2;
456 aura::test::EventCountDelegate r2_d1;
457
dchenga94547472016-04-08 08:41:11458 std::unique_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37459 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11460 std::unique_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37461 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11462 std::unique_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37463 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
464
465 r1_w1->SetCapture();
466
[email protected]73c9fd02014-07-28 01:48:52467 ui::test::EventGenerator& generator = GetEventGenerator();
[email protected]2ca75942014-07-12 04:46:37468 generator.MoveMouseToCenterOf(r2_w1.get());
469 EXPECT_EQ(gfx::Point(560, 60).ToString(),
470 generator.current_location().ToString());
471
472 EventLocationHandler location_handler;
473 r1_w1->AddPreTargetHandler(&location_handler);
474 generator.ClickLeftButton();
475 r1_w1->RemovePreTargetHandler(&location_handler);
476 EXPECT_EQ(gfx::Point(550, 50).ToString(),
477 location_handler.press_location().ToString());
478 EXPECT_EQ(gfx::Point(550, 50).ToString(),
479 location_handler.release_location().ToString());
480}
481
482TEST_F(ExtendedDesktopTest, CaptureEventLocationHighDPI_2) {
[email protected]2ca75942014-07-12 04:46:37483 UpdateDisplay("1000x600,600x400*2");
484 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
485
486 aura::test::EventCountDelegate r1_d1;
487 aura::test::EventCountDelegate r1_d2;
488 aura::test::EventCountDelegate r2_d1;
489
dchenga94547472016-04-08 08:41:11490 std::unique_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37491 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11492 std::unique_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37493 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11494 std::unique_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37495 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
496
497 r1_w1->SetCapture();
498
[email protected]73c9fd02014-07-28 01:48:52499 ui::test::EventGenerator& generator = GetEventGenerator();
[email protected]2ca75942014-07-12 04:46:37500 generator.MoveMouseToCenterOf(r2_w1.get());
501 EXPECT_EQ(gfx::Point(1060, 60).ToString(),
502 generator.current_location().ToString());
503
504 EventLocationHandler location_handler;
505 r1_w1->AddPreTargetHandler(&location_handler);
506 generator.ClickLeftButton();
507 r1_w1->RemovePreTargetHandler(&location_handler);
508 // Event-generator dispatches the event in the primary root-window's coord
509 // space. Since the location is (1060, 60), it goes to the secondary
510 // root-window as (30, 30) since the secondary root-window has a device scale
511 // factor of 2.
512 EXPECT_EQ(gfx::Point(1020, 20).ToString(),
513 location_handler.press_location().ToString());
514 EXPECT_EQ(gfx::Point(1020, 20).ToString(),
515 location_handler.release_location().ToString());
516}
517
[email protected]f059c6942012-07-21 14:27:57518TEST_F(ExtendedDesktopTest, MoveWindow) {
[email protected]f634dd32012-07-23 22:49:07519 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13520 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]f059c6942012-07-21 14:27:57521 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
522
523 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
524
525 d1->SetBounds(gfx::Rect(1010, 10, 100, 100));
jamescookb8dcef522016-06-25 14:42:55526 EXPECT_EQ("1010,10 100x100", d1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57527
528 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
529
530 d1->SetBounds(gfx::Rect(10, 10, 100, 100));
jamescookb8dcef522016-06-25 14:42:55531 EXPECT_EQ("10,10 100x100", d1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57532
533 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
534
535 // Make sure the bounds which doesn't fit to the root window
536 // works correctly.
537 d1->SetBounds(gfx::Rect(1560, 30, 100, 100));
538 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
jamescookb8dcef522016-06-25 14:42:55539 EXPECT_EQ("1560,30 100x100", d1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57540
541 // Setting outside of root windows will be moved to primary root window.
542 // TODO(oshima): This one probably should pick the closest root window.
543 d1->SetBounds(gfx::Rect(200, 10, 100, 100));
544 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
[email protected]f059c6942012-07-21 14:27:57545}
546
[email protected]2e98aaf72012-11-08 06:30:59547// Verifies if the mouse event arrives to the window even when the window
548// moves to another root in a pre-target handler. See: crbug.com/157583
549TEST_F(ExtendedDesktopTest, MoveWindowByMouseClick) {
550 UpdateDisplay("1000x600,600x400");
551
[email protected]c9390bd2013-11-08 20:33:13552 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]2e98aaf72012-11-08 06:30:59553 aura::test::EventCountDelegate delegate;
dchenga94547472016-04-08 08:41:11554 std::unique_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate(
[email protected]2e98aaf72012-11-08 06:30:59555 &delegate, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
[email protected]334e6182013-01-11 18:35:41556 MoveWindowByClickEventHandler event_handler(window.get());
557 window->AddPreTargetHandler(&event_handler);
558
[email protected]73c9fd02014-07-28 01:48:52559 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41560
561 event_generator.MoveMouseToCenterOf(window.get());
562 event_generator.ClickLeftButton();
[email protected]2e98aaf72012-11-08 06:30:59563 // Both mouse pressed and released arrive at the window and its delegate.
564 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset());
[email protected]334e6182013-01-11 18:35:41565 // Also event_handler moves the window to another root at mouse release.
[email protected]2e98aaf72012-11-08 06:30:59566 EXPECT_EQ(root_windows[1], window->GetRootWindow());
567}
568
[email protected]1a015382012-12-01 19:44:59569TEST_F(ExtendedDesktopTest, MoveWindowToDisplay) {
[email protected]e79f26e2012-08-09 07:12:48570 UpdateDisplay("1000x1000,1000x1000");
[email protected]c9390bd2013-11-08 20:33:13571 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]e79f26e2012-08-09 07:12:48572
oshimaf84b0da722016-04-27 19:47:19573 display::Display display0 = display::Screen::GetScreen()->GetDisplayMatching(
[email protected]ffabb1e2012-10-12 19:51:17574 root_windows[0]->GetBoundsInScreen());
oshimaf84b0da722016-04-27 19:47:19575 display::Display display1 = display::Screen::GetScreen()->GetDisplayMatching(
[email protected]ffabb1e2012-10-12 19:51:17576 root_windows[1]->GetBoundsInScreen());
[email protected]e79f26e2012-08-09 07:12:48577 EXPECT_NE(display0.id(), display1.id());
578
579 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 1000, 100));
580 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
581
582 // Move the window where the window spans both root windows. Since the second
583 // parameter is |display1|, the window should be shown on the secondary root.
584 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
585 display1);
jamescookb8dcef522016-06-25 14:42:55586 EXPECT_EQ("500,10 1000x100", d1->GetWindowBoundsInScreen().ToString());
[email protected]e79f26e2012-08-09 07:12:48587 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
588
589 // Move to the primary root.
590 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
591 display0);
jamescookb8dcef522016-06-25 14:42:55592 EXPECT_EQ("500,10 1000x100", d1->GetWindowBoundsInScreen().ToString());
[email protected]e79f26e2012-08-09 07:12:48593 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
594}
595
[email protected]f059c6942012-07-21 14:27:57596TEST_F(ExtendedDesktopTest, MoveWindowWithTransient) {
[email protected]f634dd32012-07-23 22:49:07597 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13598 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]f059c6942012-07-21 14:27:57599 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
600 views::Widget* w1_t1 = CreateTestWidgetWithParent(
601 w1, gfx::Rect(50, 50, 50, 50), false /* transient */);
602 // Transient child of the transient child.
603 views::Widget* w1_t11 = CreateTestWidgetWithParent(
[email protected]e6de8552014-05-23 19:05:39604 w1_t1, gfx::Rect(1200, 70, 35, 35), false /* transient */);
[email protected]f059c6942012-07-21 14:27:57605
jamescookb8dcef522016-06-25 14:42:55606 views::Widget* w11 = CreateTestWidgetWithParent(w1, gfx::Rect(10, 10, 40, 40),
607 true /* child */);
[email protected]f059c6942012-07-21 14:27:57608 views::Widget* w11_t1 = CreateTestWidgetWithParent(
609 w1, gfx::Rect(1300, 100, 80, 80), false /* transient */);
610
611 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
612 EXPECT_EQ(root_windows[0], w11->GetNativeView()->GetRootWindow());
613 EXPECT_EQ(root_windows[0], w1_t1->GetNativeView()->GetRootWindow());
614 EXPECT_EQ(root_windows[0], w1_t11->GetNativeView()->GetRootWindow());
615 EXPECT_EQ(root_windows[0], w11_t1->GetNativeView()->GetRootWindow());
jamescookb8dcef522016-06-25 14:42:55616 EXPECT_EQ("50,50 50x50", w1_t1->GetWindowBoundsInScreen().ToString());
617 EXPECT_EQ("1200,70 35x35", w1_t11->GetWindowBoundsInScreen().ToString());
618 EXPECT_EQ("20,20 40x40", w11->GetWindowBoundsInScreen().ToString());
619 EXPECT_EQ("1300,100 80x80", w11_t1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57620
[email protected]24f5e242014-07-22 02:16:09621 w1->SetBounds(gfx::Rect(1100, 10, 100, 100));
[email protected]f059c6942012-07-21 14:27:57622
623 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
624 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
625 EXPECT_EQ(root_windows[1], w1_t11->GetNativeView()->GetRootWindow());
626 EXPECT_EQ(root_windows[1], w11->GetNativeView()->GetRootWindow());
627 EXPECT_EQ(root_windows[1], w11_t1->GetNativeView()->GetRootWindow());
628
jamescookb8dcef522016-06-25 14:42:55629 EXPECT_EQ("1110,20 40x40", w11->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57630 // Transient window's screen bounds stays the same.
jamescookb8dcef522016-06-25 14:42:55631 EXPECT_EQ("50,50 50x50", w1_t1->GetWindowBoundsInScreen().ToString());
632 EXPECT_EQ("1200,70 35x35", w1_t11->GetWindowBoundsInScreen().ToString());
633 EXPECT_EQ("1300,100 80x80", w11_t1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57634
635 // Transient window doesn't move between root window unless
636 // its transient parent moves.
637 w1_t1->SetBounds(gfx::Rect(10, 50, 50, 50));
638 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
jamescookb8dcef522016-06-25 14:42:55639 EXPECT_EQ("10,50 50x50", w1_t1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57640}
641
[email protected]ca7060982012-08-08 18:05:25642// Test if the Window::ConvertPointToTarget works across root windows.
[email protected]a5e71c92012-06-22 22:09:08643TEST_F(ExtendedDesktopTest, ConvertPoint) {
oshimaf84b0da722016-04-27 19:47:19644 display::Screen* screen = display::Screen::GetScreen();
[email protected]f634dd32012-07-23 22:49:07645 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13646 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
oshimaf84b0da722016-04-27 19:47:19647 display::Display display_1 = screen->GetDisplayNearestWindow(root_windows[0]);
[email protected]a5e71c92012-06-22 22:09:08648 EXPECT_EQ("0,0", display_1.bounds().origin().ToString());
oshimaf84b0da722016-04-27 19:47:19649 display::Display display_2 = screen->GetDisplayNearestWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07650 EXPECT_EQ("1000,0", display_2.bounds().origin().ToString());
651
[email protected]a5e71c92012-06-22 22:09:08652 aura::Window* d1 =
653 CreateTestWidget(gfx::Rect(10, 10, 100, 100))->GetNativeView();
[email protected]a5e71c92012-06-22 22:09:08654 aura::Window* d2 =
[email protected]f634dd32012-07-23 22:49:07655 CreateTestWidget(gfx::Rect(1020, 20, 100, 100))->GetNativeView();
656 EXPECT_EQ(root_windows[0], d1->GetRootWindow());
657 EXPECT_EQ(root_windows[1], d2->GetRootWindow());
[email protected]a5e71c92012-06-22 22:09:08658
[email protected]a5e71c92012-06-22 22:09:08659 // Convert point in the Root2's window to the Root1's window Coord.
660 gfx::Point p(0, 0);
[email protected]ca7060982012-08-08 18:05:25661 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07662 EXPECT_EQ("1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08663 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25664 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07665 EXPECT_EQ("1010,10", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08666
667 // Convert point in the Root1's window to the Root2's window Coord.
668 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25669 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07670 EXPECT_EQ("-1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08671 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25672 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07673 EXPECT_EQ("-1010,-10", p.ToString());
674
675 // Move the 2nd display to the bottom and test again.
robliaoc0dfd6b2016-04-07 21:33:56676 SetSecondaryDisplayLayout(display::DisplayPlacement::BOTTOM);
[email protected]f634dd32012-07-23 22:49:07677
[email protected]b8984242013-07-12 07:55:38678 display_2 = screen->GetDisplayNearestWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07679 EXPECT_EQ("0,600", display_2.bounds().origin().ToString());
680
681 // Convert point in Root2's window to Root1's window Coord.
682 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25683 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07684 EXPECT_EQ("0,600", p.ToString());
685 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25686 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07687 EXPECT_EQ("10,610", p.ToString());
688
689 // Convert point in Root1's window to Root2's window Coord.
690 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25691 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07692 EXPECT_EQ("0,-600", p.ToString());
693 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25694 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07695 EXPECT_EQ("-10,-610", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08696}
[email protected]f634dd32012-07-23 22:49:07697
[email protected]263898a2012-09-17 17:20:07698TEST_F(ExtendedDesktopTest, OpenSystemTray) {
[email protected]596c61c2012-10-29 17:29:43699 UpdateDisplay("500x600,600x400");
skycb4be5b2017-04-06 17:52:45700 SystemTray* tray = ash::Shell::Get()->GetPrimarySystemTray();
[email protected]263898a2012-09-17 17:20:07701 ASSERT_FALSE(tray->HasSystemBubble());
702
[email protected]73c9fd02014-07-28 01:48:52703 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41704
[email protected]263898a2012-09-17 17:20:07705 // Opens the tray by a dummy click event and makes sure that adding/removing
706 // displays doesn't break anything.
[email protected]334e6182013-01-11 18:35:41707 event_generator.MoveMouseToCenterOf(tray->GetWidget()->GetNativeWindow());
[email protected]263898a2012-09-17 17:20:07708 event_generator.ClickLeftButton();
709 EXPECT_TRUE(tray->HasSystemBubble());
710
[email protected]596c61c2012-10-29 17:29:43711 UpdateDisplay("500x600");
[email protected]263898a2012-09-17 17:20:07712 EXPECT_TRUE(tray->HasSystemBubble());
[email protected]596c61c2012-10-29 17:29:43713 UpdateDisplay("500x600,600x400");
[email protected]263898a2012-09-17 17:20:07714 EXPECT_TRUE(tray->HasSystemBubble());
715
716 // Closes the tray and again makes sure that adding/removing displays doesn't
717 // break anything.
718 event_generator.ClickLeftButton();
719 RunAllPendingInMessageLoop();
720
721 EXPECT_FALSE(tray->HasSystemBubble());
722
[email protected]596c61c2012-10-29 17:29:43723 UpdateDisplay("500x600");
[email protected]263898a2012-09-17 17:20:07724 EXPECT_FALSE(tray->HasSystemBubble());
[email protected]596c61c2012-10-29 17:29:43725 UpdateDisplay("500x600,600x400");
[email protected]263898a2012-09-17 17:20:07726 EXPECT_FALSE(tray->HasSystemBubble());
727}
728
[email protected]578048512012-09-19 20:01:24729TEST_F(ExtendedDesktopTest, StayInSameRootWindow) {
730 UpdateDisplay("100x100,200x200");
[email protected]c9390bd2013-11-08 20:33:13731 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]a2e6af12013-01-07 21:40:35732 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 50, 50));
[email protected]578048512012-09-19 20:01:24733 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
734 w1->SetBounds(gfx::Rect(150, 10, 50, 50));
735 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
736
skyaecdb0fb2016-09-15 22:14:28737 // The widget stays in the same root if kLockedToRootKey is set to true.
738 w1->GetNativeView()->SetProperty(kLockedToRootKey, true);
[email protected]578048512012-09-19 20:01:24739 w1->SetBounds(gfx::Rect(10, 10, 50, 50));
740 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
741
742 // The widget should now move to the 1st root window without the property.
skyaecdb0fb2016-09-15 22:14:28743 w1->GetNativeView()->ClearProperty(kLockedToRootKey);
[email protected]578048512012-09-19 20:01:24744 w1->SetBounds(gfx::Rect(10, 10, 50, 50));
745 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
[email protected]e887c6c2013-07-08 19:35:53746
747 // a window in SettingsBubbleContainer and StatusContainer should
748 // not move to another root window regardles of the bounds specified.
749 aura::Window* settings_bubble_container =
750 Shell::GetPrimaryRootWindowController()->GetContainer(
[email protected]093b8d642014-04-03 20:59:28751 kShellWindowId_SettingBubbleContainer);
jamescookb8dcef522016-06-25 14:42:55752 aura::Window* window =
753 aura::test::CreateTestWindowWithId(100, settings_bubble_container);
sky8782ff02017-02-23 22:12:42754 window->SetBoundsInScreen(gfx::Rect(150, 10, 50, 50), GetSecondaryDisplay());
[email protected]e887c6c2013-07-08 19:35:53755 EXPECT_EQ(root_windows[0], window->GetRootWindow());
756
757 aura::Window* status_container =
758 Shell::GetPrimaryRootWindowController()->GetContainer(
[email protected]093b8d642014-04-03 20:59:28759 kShellWindowId_StatusContainer);
[email protected]e887c6c2013-07-08 19:35:53760 window = aura::test::CreateTestWindowWithId(100, status_container);
sky8782ff02017-02-23 22:12:42761 window->SetBoundsInScreen(gfx::Rect(150, 10, 50, 50), GetSecondaryDisplay());
[email protected]e887c6c2013-07-08 19:35:53762 EXPECT_EQ(root_windows[0], window->GetRootWindow());
[email protected]578048512012-09-19 20:01:24763}
764
[email protected]e67291f12012-10-10 05:52:38765TEST_F(ExtendedDesktopTest, KeyEventsOnLockScreen) {
766 UpdateDisplay("100x100,200x200");
[email protected]c9390bd2013-11-08 20:33:13767 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]e67291f12012-10-10 05:52:38768
769 // Create normal windows on both displays.
oshimaf84b0da722016-04-27 19:47:19770 views::Widget* widget1 = CreateTestWidget(
771 display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38772 widget1->Show();
773 EXPECT_EQ(root_windows[0], widget1->GetNativeView()->GetRootWindow());
sky8782ff02017-02-23 22:12:42774 views::Widget* widget2 = CreateTestWidget(GetSecondaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38775 widget2->Show();
776 EXPECT_EQ(root_windows[1], widget2->GetNativeView()->GetRootWindow());
777
778 // Create a LockScreen window.
oshimaf84b0da722016-04-27 19:47:19779 views::Widget* lock_widget = CreateTestWidget(
780 display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38781 views::Textfield* textfield = new views::Textfield;
[email protected]09148952013-03-13 13:25:43782 lock_widget->client_view()->AddChildView(textfield);
[email protected]e67291f12012-10-10 05:52:38783
[email protected]093b8d642014-04-03 20:59:28784 ash::Shell::GetContainer(Shell::GetPrimaryRootWindow(),
785 ash::kShellWindowId_LockScreenContainer)
786 ->AddChild(lock_widget->GetNativeView());
[email protected]e67291f12012-10-10 05:52:38787 lock_widget->Show();
788 textfield->RequestFocus();
789
[email protected]8cfb6722012-11-28 03:28:46790 aura::client::FocusClient* focus_client =
791 aura::client::GetFocusClient(root_windows[0]);
792 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]e67291f12012-10-10 05:52:38793
794 // The lock window should get events on both root windows.
[email protected]73c9fd02014-07-28 01:48:52795 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41796
[email protected]1ea46f6f2014-07-17 07:36:40797 event_generator.set_current_target(root_windows[0]);
[email protected]334e6182013-01-11 18:35:41798 event_generator.PressKey(ui::VKEY_A, 0);
799 event_generator.ReleaseKey(ui::VKEY_A, 0);
[email protected]8cfb6722012-11-28 03:28:46800 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46801 EXPECT_EQ("a", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38802
[email protected]1ea46f6f2014-07-17 07:36:40803 event_generator.set_current_target(root_windows[1]);
[email protected]334e6182013-01-11 18:35:41804 event_generator.PressKey(ui::VKEY_B, 0);
805 event_generator.ReleaseKey(ui::VKEY_B, 0);
[email protected]8cfb6722012-11-28 03:28:46806 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46807 EXPECT_EQ("ab", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38808
809 // Deleting 2nd display. The lock window still should get the events.
810 UpdateDisplay("100x100");
pkotwicz5d118a6b12015-02-12 22:23:57811 event_generator.set_current_target(root_windows[0]);
[email protected]334e6182013-01-11 18:35:41812 event_generator.PressKey(ui::VKEY_C, 0);
813 event_generator.ReleaseKey(ui::VKEY_C, 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("abc", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38816
817 // Creating 2nd display again, and lock window still should get events
818 // on both root windows.
819 UpdateDisplay("100x100,200x200");
820 root_windows = Shell::GetAllRootWindows();
[email protected]1ea46f6f2014-07-17 07:36:40821 event_generator.set_current_target(root_windows[0]);
[email protected]334e6182013-01-11 18:35:41822 event_generator.PressKey(ui::VKEY_D, 0);
823 event_generator.ReleaseKey(ui::VKEY_D, 0);
[email protected]8cfb6722012-11-28 03:28:46824 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46825 EXPECT_EQ("abcd", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38826
[email protected]1ea46f6f2014-07-17 07:36:40827 event_generator.set_current_target(root_windows[1]);
[email protected]334e6182013-01-11 18:35:41828 event_generator.PressKey(ui::VKEY_E, 0);
829 event_generator.ReleaseKey(ui::VKEY_E, 0);
[email protected]8cfb6722012-11-28 03:28:46830 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46831 EXPECT_EQ("abcde", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38832}
833
[email protected]334e6182013-01-11 18:35:41834TEST_F(ExtendedDesktopTest, PassiveGrab) {
835 EventLocationRecordingEventHandler event_handler;
skycb4be5b2017-04-06 17:52:45836 ash::Shell::Get()->AddPreTargetHandler(&event_handler);
[email protected]334e6182013-01-11 18:35:41837
838 UpdateDisplay("300x300,200x200");
839
840 views::Widget* widget = CreateTestWidget(gfx::Rect(50, 50, 200, 200));
841 widget->Show();
842 ASSERT_EQ("50,50 200x200", widget->GetWindowBoundsInScreen().ToString());
843
[email protected]73c9fd02014-07-28 01:48:52844 ui::test::EventGenerator& generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41845 generator.MoveMouseTo(150, 150);
846 EXPECT_EQ("100,100 150,150", event_handler.GetLocationsAndReset());
847
848 generator.PressLeftButton();
849 generator.MoveMouseTo(400, 150);
850
851 EXPECT_EQ("350,100 400,150", event_handler.GetLocationsAndReset());
852
853 generator.ReleaseLeftButton();
854 EXPECT_EQ("-999,-999 -999,-999", event_handler.GetLocationsAndReset());
855
856 generator.MoveMouseTo(400, 150);
857 EXPECT_EQ("100,150 100,150", event_handler.GetLocationsAndReset());
858
skycb4be5b2017-04-06 17:52:45859 ash::Shell::Get()->RemovePreTargetHandler(&event_handler);
[email protected]334e6182013-01-11 18:35:41860}
861
[email protected]c39be8f2012-06-15 22:58:36862} // namespace ash