blob: e625eda079f3fcaae1c23561a57ae49f321071e0 [file] [log] [blame]
[email protected]c39be8f2012-06-15 22:58:361// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]6bdf7952012-11-14 10:10:585#include "ash/display/display_manager.h"
[email protected]e887c6c2013-07-08 19:35:536#include "ash/root_window_controller.h"
[email protected]55ad8c12014-01-17 18:24:337#include "ash/screen_util.h"
[email protected]c39be8f2012-06-15 22:58:368#include "ash/shell.h"
[email protected]e67291f12012-10-10 05:52:389#include "ash/shell_window_ids.h"
[email protected]263898a2012-09-17 17:20:0710#include "ash/system/tray/system_tray.h"
[email protected]c39be8f2012-06-15 22:58:3611#include "ash/test/ash_test_base.h"
[email protected]7203a5e2012-08-06 18:27:4612#include "ash/wm/coordinate_conversion.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"
robliaoc0dfd6b2016-04-07 21:33:5624#include "ui/display/manager/display_layout.h"
[email protected]86ccbd42013-09-18 18:11:5425#include "ui/events/event_handler.h"
[email protected]73c9fd02014-07-28 01:48:5226#include "ui/events/test/event_generator.h"
[email protected]a5e71c92012-06-22 22:09:0827#include "ui/gfx/display.h"
[email protected]718b26c2012-07-24 20:53:2328#include "ui/gfx/screen.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 views::View* GetContentsView() override { return this; }
52 ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_SYSTEM; }
[email protected]c39be8f2012-06-15 22:58:3653
54 private:
55 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate);
56};
57
[email protected]334e6182013-01-11 18:35:4158// An event handler which moves the target window to the secondary root window
[email protected]2e98aaf72012-11-08 06:30:5959// at pre-handle phase of a mouse release event.
[email protected]334e6182013-01-11 18:35:4160class MoveWindowByClickEventHandler : public ui::EventHandler {
[email protected]2e98aaf72012-11-08 06:30:5961 public:
[email protected]334e6182013-01-11 18:35:4162 explicit MoveWindowByClickEventHandler(aura::Window* target)
[email protected]2e98aaf72012-11-08 06:30:5963 : target_(target) {}
dcheng1f4538e2014-10-27 23:57:0564 ~MoveWindowByClickEventHandler() override {}
[email protected]2e98aaf72012-11-08 06:30:5965
66 private:
67 // ui::EventHandler overrides:
dcheng1f4538e2014-10-27 23:57:0568 void OnMouseEvent(ui::MouseEvent* event) override {
[email protected]2e98aaf72012-11-08 06:30:5969 if (event->type() == ui::ET_MOUSE_RELEASED) {
[email protected]c9390bd2013-11-08 20:33:1370 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]2e98aaf72012-11-08 06:30:5971 DCHECK_LT(1u, root_windows.size());
72 root_windows[1]->AddChild(target_);
73 }
[email protected]2e98aaf72012-11-08 06:30:5974 }
75
[email protected]2e98aaf72012-11-08 06:30:5976 aura::Window* target_;
[email protected]334e6182013-01-11 18:35:4177 DISALLOW_COPY_AND_ASSIGN(MoveWindowByClickEventHandler);
78};
79
80// An event handler which records the event's locations.
81class EventLocationRecordingEventHandler : public ui::EventHandler {
82 public:
83 explicit EventLocationRecordingEventHandler() {
84 reset();
85 }
dcheng1f4538e2014-10-27 23:57:0586 ~EventLocationRecordingEventHandler() override {}
[email protected]334e6182013-01-11 18:35:4187
88 std::string GetLocationsAndReset() {
89 std::string result =
90 location_.ToString() + " " + root_location_.ToString();
91 reset();
92 return result;
93 }
94
95 private:
96 // ui::EventHandler overrides:
dcheng1f4538e2014-10-27 23:57:0597 void OnMouseEvent(ui::MouseEvent* event) override {
[email protected]334e6182013-01-11 18:35:4198 if (event->type() == ui::ET_MOUSE_MOVED ||
99 event->type() == ui::ET_MOUSE_DRAGGED) {
100 location_ = event->location();
101 root_location_ = event->root_location();
102 }
103 }
104
105 void reset() {
106 location_.SetPoint(-999, -999);
107 root_location_.SetPoint(-999, -999);
108 }
109
110 gfx::Point root_location_;
111 gfx::Point location_;
112
113 DISALLOW_COPY_AND_ASSIGN(EventLocationRecordingEventHandler);
[email protected]2e98aaf72012-11-08 06:30:59114};
115
[email protected]2ca75942014-07-12 04:46:37116class EventLocationHandler : public ui::EventHandler {
117 public:
118 EventLocationHandler() {}
dcheng1f4538e2014-10-27 23:57:05119 ~EventLocationHandler() override {}
[email protected]2ca75942014-07-12 04:46:37120
121 const gfx::Point& press_location() const { return press_location_; }
122 const gfx::Point& release_location() const { return release_location_; }
123
124 private:
125 // ui::EventHandler:
dcheng1f4538e2014-10-27 23:57:05126 void OnMouseEvent(ui::MouseEvent* event) override {
[email protected]2ca75942014-07-12 04:46:37127 if (event->type() == ui::ET_MOUSE_PRESSED)
128 press_location_ = event->location();
129 else if (event->type() == ui::ET_MOUSE_RELEASED)
130 release_location_ = event->location();
131 }
132
133 gfx::Point press_location_;
134 gfx::Point release_location_;
135
136 DISALLOW_COPY_AND_ASSIGN(EventLocationHandler);
137};
138
[email protected]c39be8f2012-06-15 22:58:36139} // namespace
140
[email protected]a2e6af12013-01-07 21:40:35141class ExtendedDesktopTest : public test::AshTestBase {
142 public:
143 views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
oshima95d499b2016-02-10 03:49:56144 return CreateTestWidgetWithParentAndContext(nullptr, CurrentContext(),
145 bounds, false);
[email protected]a2e6af12013-01-07 21:40:35146 }
147
148 views::Widget* CreateTestWidgetWithParent(views::Widget* parent,
149 const gfx::Rect& bounds,
150 bool child) {
151 CHECK(parent);
oshima95d499b2016-02-10 03:49:56152 return CreateTestWidgetWithParentAndContext(parent, nullptr, bounds, child);
[email protected]a2e6af12013-01-07 21:40:35153 }
154
155 views::Widget* CreateTestWidgetWithParentAndContext(views::Widget* parent,
156 gfx::NativeView context,
157 const gfx::Rect& bounds,
158 bool child) {
159 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
160 if (parent)
161 params.parent = parent->GetNativeView();
162 params.context = context;
163 params.bounds = bounds;
164 params.child = child;
165 views::Widget* widget = new views::Widget;
166 widget->Init(params);
167 widget->Show();
168 return widget;
169 }
170};
[email protected]c39be8f2012-06-15 22:58:36171
172// Test conditions that root windows in extended desktop mode
173// must satisfy.
174TEST_F(ExtendedDesktopTest, Basic) {
[email protected]e75642a2013-06-12 17:21:18175 if (!SupportsMultipleDisplays())
176 return;
177
[email protected]f634dd32012-07-23 22:49:07178 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13179 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36180
181 // All root windows must have the root window controller.
182 ASSERT_EQ(2U, root_windows.size());
[email protected]c9390bd2013-11-08 20:33:13183 for (aura::Window::Windows::const_iterator iter = root_windows.begin();
[email protected]c39be8f2012-06-15 22:58:36184 iter != root_windows.end(); ++iter) {
oshima95d499b2016-02-10 03:49:56185 EXPECT_TRUE(GetRootWindowController(*iter) != nullptr);
[email protected]c39be8f2012-06-15 22:58:36186 }
187 // Make sure root windows share the same controllers.
[email protected]8cfb6722012-11-28 03:28:46188 EXPECT_EQ(aura::client::GetFocusClient(root_windows[0]),
189 aura::client::GetFocusClient(root_windows[1]));
[email protected]c39be8f2012-06-15 22:58:36190 EXPECT_EQ(aura::client::GetActivationClient(root_windows[0]),
191 aura::client::GetActivationClient(root_windows[1]));
192 EXPECT_EQ(aura::client::GetCaptureClient(root_windows[0]),
193 aura::client::GetCaptureClient(root_windows[1]));
194}
195
196TEST_F(ExtendedDesktopTest, Activation) {
[email protected]e75642a2013-06-12 17:21:18197 if (!SupportsMultipleDisplays())
198 return;
199
[email protected]f634dd32012-07-23 22:49:07200 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13201 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36202
[email protected]c39be8f2012-06-15 22:58:36203 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]f634dd32012-07-23 22:49:07204 views::Widget* widget_on_2nd =
205 CreateTestWidget(gfx::Rect(1200, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36206 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
[email protected]f634dd32012-07-23 22:49:07207 EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36208
209 EXPECT_EQ(widget_on_2nd->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46210 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]c39be8f2012-06-15 22:58:36211 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
212
[email protected]73c9fd02014-07-28 01:48:52213 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]f634dd32012-07-23 22:49:07214 // Clicking a window changes the active window and active root window.
[email protected]334e6182013-01-11 18:35:41215 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
216 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36217
218 EXPECT_EQ(widget_on_1st->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46219 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]c39be8f2012-06-15 22:58:36220 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]f634dd32012-07-23 22:49:07221
[email protected]334e6182013-01-11 18:35:41222 event_generator.MoveMouseToCenterOf(widget_on_2nd->GetNativeView());
223 event_generator.ClickLeftButton();
[email protected]f634dd32012-07-23 22:49:07224
225 EXPECT_EQ(widget_on_2nd->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46226 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]f634dd32012-07-23 22:49:07227 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
[email protected]c39be8f2012-06-15 22:58:36228}
229
230TEST_F(ExtendedDesktopTest, SystemModal) {
[email protected]e75642a2013-06-12 17:21:18231 if (!SupportsMultipleDisplays())
232 return;
233
[email protected]f634dd32012-07-23 22:49:07234 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13235 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36236
237 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36238 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]492533b32012-09-21 19:06:14239 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
[email protected]d17642d2013-09-12 23:44:38240 EXPECT_EQ(root_windows[0], Shell::GetTargetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36241
[email protected]c39be8f2012-06-15 22:58:36242 // Open system modal. Make sure it's on 2nd root window and active.
[email protected]a2e6af12013-01-07 21:40:35243 views::Widget* modal_widget = views::Widget::CreateWindowWithContextAndBounds(
244 new ModalWidgetDelegate(),
245 CurrentContext(),
246 gfx::Rect(1200, 100, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36247 modal_widget->Show();
248 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
249 EXPECT_EQ(root_windows[1], modal_widget->GetNativeView()->GetRootWindow());
[email protected]d17642d2013-09-12 23:44:38250 EXPECT_EQ(root_windows[1], Shell::GetTargetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36251
[email protected]73c9fd02014-07-28 01:48:52252 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41253
[email protected]2e236a52012-06-27 22:21:47254 // Clicking a widget on widget_on_1st display should not change activation.
[email protected]334e6182013-01-11 18:35:41255 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
256 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36257 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView()));
[email protected]d17642d2013-09-12 23:44:38258 EXPECT_EQ(root_windows[1], Shell::GetTargetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36259
260 // Close system modal and so clicking a widget should work now.
261 modal_widget->Close();
[email protected]334e6182013-01-11 18:35:41262 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
263 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36264 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]d17642d2013-09-12 23:44:38265 EXPECT_EQ(root_windows[0], Shell::GetTargetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36266}
267
268TEST_F(ExtendedDesktopTest, TestCursor) {
[email protected]e75642a2013-06-12 17:21:18269 if (!SupportsMultipleDisplays())
270 return;
271
[email protected]f634dd32012-07-23 22:49:07272 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13273 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]2374d1812014-03-04 03:42:27274 aura::WindowTreeHost* host0 = root_windows[0]->GetHost();
275 aura::WindowTreeHost* host1 = root_windows[1]->GetHost();
276 EXPECT_EQ(ui::kCursorPointer, host0->last_cursor().native_type());
kylechard642dcb2016-02-22 15:50:03277 EXPECT_EQ(ui::kCursorNull, host1->last_cursor().native_type());
[email protected]151ffdff2012-09-11 20:18:35278 Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorCopy);
[email protected]2374d1812014-03-04 03:42:27279 EXPECT_EQ(ui::kCursorCopy, host0->last_cursor().native_type());
280 EXPECT_EQ(ui::kCursorCopy, host1->last_cursor().native_type());
[email protected]c39be8f2012-06-15 22:58:36281}
282
[email protected]718b26c2012-07-24 20:53:23283TEST_F(ExtendedDesktopTest, TestCursorLocation) {
[email protected]e75642a2013-06-12 17:21:18284 if (!SupportsMultipleDisplays())
285 return;
286
[email protected]d0064722013-03-14 18:16:43287 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13288 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]553eae12013-02-01 02:33:52289 aura::test::WindowTestApi root_window0_test_api(root_windows[0]);
290 aura::test::WindowTestApi root_window1_test_api(root_windows[1]);
[email protected]718b26c2012-07-24 20:53:23291
292 root_windows[0]->MoveCursorTo(gfx::Point(10, 10));
scottmge8b042972016-01-27 05:07:35293 EXPECT_EQ("10,10",
294 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23295 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
296 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
297 root_windows[1]->MoveCursorTo(gfx::Point(10, 20));
scottmge8b042972016-01-27 05:07:35298 EXPECT_EQ("1010,20",
299 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23300 EXPECT_FALSE(root_window0_test_api.ContainsMouse());
301 EXPECT_TRUE(root_window1_test_api.ContainsMouse());
302 root_windows[0]->MoveCursorTo(gfx::Point(20, 10));
scottmge8b042972016-01-27 05:07:35303 EXPECT_EQ("20,10",
304 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23305 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
306 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
307}
308
[email protected]20c59762012-06-23 01:10:24309TEST_F(ExtendedDesktopTest, GetRootWindowAt) {
[email protected]e75642a2013-06-12 17:21:18310 if (!SupportsMultipleDisplays())
311 return;
312
[email protected]f634dd32012-07-23 22:49:07313 UpdateDisplay("700x500,500x500");
robliaoc0dfd6b2016-04-07 21:33:56314 SetSecondaryDisplayLayout(display::DisplayPlacement::LEFT);
[email protected]c9390bd2013-11-08 20:33:13315 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24316
[email protected]7203a5e2012-08-06 18:27:46317 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-400, 100)));
318 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-1, 100)));
319 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 300)));
[email protected]24f5e242014-07-22 02:16:09320 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(700, 300)));
[email protected]20c59762012-06-23 01:10:24321
322 // Zero origin.
[email protected]7203a5e2012-08-06 18:27:46323 EXPECT_EQ(root_windows[0], 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
326 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-600, 0)));
[email protected]7203a5e2012-08-06 18:27:46327 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(701, 100)));
[email protected]20c59762012-06-23 01:10:24328}
329
330TEST_F(ExtendedDesktopTest, GetRootWindowMatching) {
[email protected]e75642a2013-06-12 17:21:18331 if (!SupportsMultipleDisplays())
332 return;
333
[email protected]f634dd32012-07-23 22:49:07334 UpdateDisplay("700x500,500x500");
robliaoc0dfd6b2016-04-07 21:33:56335 SetSecondaryDisplayLayout(display::DisplayPlacement::LEFT);
[email protected]66b05eac2012-06-27 23:53:10336
[email protected]c9390bd2013-11-08 20:33:13337 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24338
339 // Containing rect.
340 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46341 wm::GetRootWindowMatching(gfx::Rect(-300, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24342 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46343 wm::GetRootWindowMatching(gfx::Rect(100, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24344
345 // Intersecting rect.
346 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46347 wm::GetRootWindowMatching(gfx::Rect(-200, 0, 300, 300)));
[email protected]20c59762012-06-23 01:10:24348 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46349 wm::GetRootWindowMatching(gfx::Rect(-100, 0, 300, 300)));
[email protected]20c59762012-06-23 01:10:24350
351 // Zero origin.
[email protected]66b05eac2012-06-27 23:53:10352 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46353 wm::GetRootWindowMatching(gfx::Rect(0, 0, 0, 0)));
[email protected]66b05eac2012-06-27 23:53:10354 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46355 wm::GetRootWindowMatching(gfx::Rect(0, 0, 1, 1)));
[email protected]20c59762012-06-23 01:10:24356
357 // Empty rect.
358 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46359 wm::GetRootWindowMatching(gfx::Rect(-400, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24360 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46361 wm::GetRootWindowMatching(gfx::Rect(100, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24362
363 // Out of range rect should return the primary root window.
364 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46365 wm::GetRootWindowMatching(gfx::Rect(-600, -300, 50, 50)));
[email protected]20c59762012-06-23 01:10:24366 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46367 wm::GetRootWindowMatching(gfx::Rect(0, 1000, 50, 50)));
[email protected]0f81f442012-06-22 06:20:27368}
369
[email protected]1a015382012-12-01 19:44:59370TEST_F(ExtendedDesktopTest, Capture) {
[email protected]e75642a2013-06-12 17:21:18371 if (!SupportsMultipleDisplays())
372 return;
373
[email protected]f634dd32012-07-23 22:49:07374 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13375 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]a5e71c92012-06-22 22:09:08376
377 aura::test::EventCountDelegate r1_d1;
378 aura::test::EventCountDelegate r1_d2;
379 aura::test::EventCountDelegate r2_d1;
380
dchenga94547472016-04-08 08:41:11381 std::unique_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]a5e71c92012-06-22 22:09:08382 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11383 std::unique_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
[email protected]a5e71c92012-06-22 22:09:08384 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11385 std::unique_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]a5e71c92012-06-22 22:09:08386 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
[email protected]f634dd32012-07-23 22:49:07387
[email protected]a5e71c92012-06-22 22:09:08388 r1_w1->SetCapture();
389
390 EXPECT_EQ(r1_w1.get(),
391 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]334e6182013-01-11 18:35:41392
[email protected]73c9fd02014-07-28 01:48:52393 ui::test::EventGenerator& generator = GetEventGenerator();
[email protected]d05cf2f2014-02-26 05:31:43394 generator.MoveMouseToCenterOf(r2_w1.get());
395 // |r1_w1| will receive the events because it has capture.
396 EXPECT_EQ("1 1 0", r1_d1.GetMouseMotionCountsAndReset());
397 EXPECT_EQ("0 0 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]b19ba4adf2012-09-07 16:13:29403 // The mouse is outside. On chromeos, the mouse is warped to the
404 // dest root window, but it's not implemented on Win yet, so
405 // no mouse move event on Win.
[email protected]d05cf2f2014-02-26 05:31:43406 EXPECT_EQ("0 0 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08407 EXPECT_EQ("1 1", r1_d1.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43408
409 generator.MoveMouseTo(15, 15);
[email protected]f634dd32012-07-23 22:49:07410 EXPECT_EQ("0 1 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43411 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08412
413 r1_w2->SetCapture();
414 EXPECT_EQ(r1_w2.get(),
415 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]d05cf2f2014-02-26 05:31:43416 generator.MoveMouseBy(10, 10);
417 // |r1_w2| has the capture. So it will receive the mouse-move event.
418 EXPECT_EQ("0 0 0", r1_d1.GetMouseMotionCountsAndReset());
419 EXPECT_EQ("0 1 0", r1_d2.GetMouseMotionCountsAndReset());
420 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
421
422 generator.ClickLeftButton();
[email protected]a5e71c92012-06-22 22:09:08423 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
424 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43425 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08426 EXPECT_EQ("1 1", r1_d2.GetMouseButtonCountsAndReset());
[email protected]d05cf2f2014-02-26 05:31:43427
[email protected]a5e71c92012-06-22 22:09:08428 r1_w2->ReleaseCapture();
oshima95d499b2016-02-10 03:49:56429 EXPECT_EQ(nullptr, aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]d05cf2f2014-02-26 05:31:43430
431 generator.MoveMouseToCenterOf(r2_w1.get());
432 generator.ClickLeftButton();
[email protected]a5e71c92012-06-22 22:09:08433 EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset());
434 EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset());
435 // Make sure the mouse_moved_handler_ is properly reset.
436 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
437 EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset());
438}
439
[email protected]2ca75942014-07-12 04:46:37440TEST_F(ExtendedDesktopTest, CaptureEventLocation) {
441 if (!SupportsMultipleDisplays())
442 return;
443
444 UpdateDisplay("1000x600,600x400");
445 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
446
447 aura::test::EventCountDelegate r1_d1;
448 aura::test::EventCountDelegate r1_d2;
449 aura::test::EventCountDelegate r2_d1;
450
dchenga94547472016-04-08 08:41:11451 std::unique_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37452 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11453 std::unique_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37454 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11455 std::unique_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37456 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
457
458 r1_w1->SetCapture();
459
[email protected]73c9fd02014-07-28 01:48:52460 ui::test::EventGenerator& generator = GetEventGenerator();
[email protected]2ca75942014-07-12 04:46:37461 generator.MoveMouseToCenterOf(r2_w1.get());
462 EXPECT_EQ(gfx::Point(1060, 60).ToString(),
463 generator.current_location().ToString());
464
465 EventLocationHandler location_handler;
466 r1_w1->AddPreTargetHandler(&location_handler);
467 generator.ClickLeftButton();
468 r1_w1->RemovePreTargetHandler(&location_handler);
469 EXPECT_EQ(gfx::Point(1050, 50).ToString(),
470 location_handler.press_location().ToString());
471 EXPECT_EQ(gfx::Point(1050, 50).ToString(),
472 location_handler.release_location().ToString());
473}
474
475TEST_F(ExtendedDesktopTest, CaptureEventLocationHighDPI) {
476 if (!SupportsMultipleDisplays())
477 return;
478
479 UpdateDisplay("1000x600*2,600x400");
480 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
481
482 aura::test::EventCountDelegate r1_d1;
483 aura::test::EventCountDelegate r1_d2;
484 aura::test::EventCountDelegate r2_d1;
485
dchenga94547472016-04-08 08:41:11486 std::unique_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37487 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11488 std::unique_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37489 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11490 std::unique_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37491 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
492
493 r1_w1->SetCapture();
494
[email protected]73c9fd02014-07-28 01:48:52495 ui::test::EventGenerator& generator = GetEventGenerator();
[email protected]2ca75942014-07-12 04:46:37496 generator.MoveMouseToCenterOf(r2_w1.get());
497 EXPECT_EQ(gfx::Point(560, 60).ToString(),
498 generator.current_location().ToString());
499
500 EventLocationHandler location_handler;
501 r1_w1->AddPreTargetHandler(&location_handler);
502 generator.ClickLeftButton();
503 r1_w1->RemovePreTargetHandler(&location_handler);
504 EXPECT_EQ(gfx::Point(550, 50).ToString(),
505 location_handler.press_location().ToString());
506 EXPECT_EQ(gfx::Point(550, 50).ToString(),
507 location_handler.release_location().ToString());
508}
509
510TEST_F(ExtendedDesktopTest, CaptureEventLocationHighDPI_2) {
511 if (!SupportsMultipleDisplays())
512 return;
513
514 UpdateDisplay("1000x600,600x400*2");
515 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
516
517 aura::test::EventCountDelegate r1_d1;
518 aura::test::EventCountDelegate r1_d2;
519 aura::test::EventCountDelegate r2_d1;
520
dchenga94547472016-04-08 08:41:11521 std::unique_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37522 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11523 std::unique_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37524 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
dchenga94547472016-04-08 08:41:11525 std::unique_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
[email protected]2ca75942014-07-12 04:46:37526 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
527
528 r1_w1->SetCapture();
529
[email protected]73c9fd02014-07-28 01:48:52530 ui::test::EventGenerator& generator = GetEventGenerator();
[email protected]2ca75942014-07-12 04:46:37531 generator.MoveMouseToCenterOf(r2_w1.get());
532 EXPECT_EQ(gfx::Point(1060, 60).ToString(),
533 generator.current_location().ToString());
534
535 EventLocationHandler location_handler;
536 r1_w1->AddPreTargetHandler(&location_handler);
537 generator.ClickLeftButton();
538 r1_w1->RemovePreTargetHandler(&location_handler);
539 // Event-generator dispatches the event in the primary root-window's coord
540 // space. Since the location is (1060, 60), it goes to the secondary
541 // root-window as (30, 30) since the secondary root-window has a device scale
542 // factor of 2.
543 EXPECT_EQ(gfx::Point(1020, 20).ToString(),
544 location_handler.press_location().ToString());
545 EXPECT_EQ(gfx::Point(1020, 20).ToString(),
546 location_handler.release_location().ToString());
547}
548
[email protected]f059c6942012-07-21 14:27:57549TEST_F(ExtendedDesktopTest, MoveWindow) {
[email protected]e75642a2013-06-12 17:21:18550 if (!SupportsMultipleDisplays())
551 return;
552
[email protected]f634dd32012-07-23 22:49:07553 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13554 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]f059c6942012-07-21 14:27:57555 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
556
557 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
558
559 d1->SetBounds(gfx::Rect(1010, 10, 100, 100));
560 EXPECT_EQ("1010,10 100x100",
561 d1->GetWindowBoundsInScreen().ToString());
562
563 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
564
565 d1->SetBounds(gfx::Rect(10, 10, 100, 100));
566 EXPECT_EQ("10,10 100x100",
567 d1->GetWindowBoundsInScreen().ToString());
568
569 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
570
571 // Make sure the bounds which doesn't fit to the root window
572 // works correctly.
573 d1->SetBounds(gfx::Rect(1560, 30, 100, 100));
574 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
575 EXPECT_EQ("1560,30 100x100",
576 d1->GetWindowBoundsInScreen().ToString());
577
578 // Setting outside of root windows will be moved to primary root window.
579 // TODO(oshima): This one probably should pick the closest root window.
580 d1->SetBounds(gfx::Rect(200, 10, 100, 100));
581 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
[email protected]f059c6942012-07-21 14:27:57582}
583
[email protected]2e98aaf72012-11-08 06:30:59584// Verifies if the mouse event arrives to the window even when the window
585// moves to another root in a pre-target handler. See: crbug.com/157583
586TEST_F(ExtendedDesktopTest, MoveWindowByMouseClick) {
[email protected]e75642a2013-06-12 17:21:18587 if (!SupportsMultipleDisplays())
588 return;
589
[email protected]2e98aaf72012-11-08 06:30:59590 UpdateDisplay("1000x600,600x400");
591
[email protected]c9390bd2013-11-08 20:33:13592 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]2e98aaf72012-11-08 06:30:59593 aura::test::EventCountDelegate delegate;
dchenga94547472016-04-08 08:41:11594 std::unique_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate(
[email protected]2e98aaf72012-11-08 06:30:59595 &delegate, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
[email protected]334e6182013-01-11 18:35:41596 MoveWindowByClickEventHandler event_handler(window.get());
597 window->AddPreTargetHandler(&event_handler);
598
[email protected]73c9fd02014-07-28 01:48:52599 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41600
601 event_generator.MoveMouseToCenterOf(window.get());
602 event_generator.ClickLeftButton();
[email protected]2e98aaf72012-11-08 06:30:59603 // Both mouse pressed and released arrive at the window and its delegate.
604 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset());
[email protected]334e6182013-01-11 18:35:41605 // Also event_handler moves the window to another root at mouse release.
[email protected]2e98aaf72012-11-08 06:30:59606 EXPECT_EQ(root_windows[1], window->GetRootWindow());
607}
608
[email protected]1a015382012-12-01 19:44:59609TEST_F(ExtendedDesktopTest, MoveWindowToDisplay) {
[email protected]e75642a2013-06-12 17:21:18610 if (!SupportsMultipleDisplays())
611 return;
612
[email protected]e79f26e2012-08-09 07:12:48613 UpdateDisplay("1000x1000,1000x1000");
[email protected]c9390bd2013-11-08 20:33:13614 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]e79f26e2012-08-09 07:12:48615
scottmge8b042972016-01-27 05:07:35616 gfx::Display display0 = gfx::Screen::GetScreen()->GetDisplayMatching(
[email protected]ffabb1e2012-10-12 19:51:17617 root_windows[0]->GetBoundsInScreen());
scottmge8b042972016-01-27 05:07:35618 gfx::Display display1 = gfx::Screen::GetScreen()->GetDisplayMatching(
[email protected]ffabb1e2012-10-12 19:51:17619 root_windows[1]->GetBoundsInScreen());
[email protected]e79f26e2012-08-09 07:12:48620 EXPECT_NE(display0.id(), display1.id());
621
622 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 1000, 100));
623 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
624
625 // Move the window where the window spans both root windows. Since the second
626 // parameter is |display1|, the window should be shown on the secondary root.
627 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
628 display1);
629 EXPECT_EQ("500,10 1000x100",
630 d1->GetWindowBoundsInScreen().ToString());
631 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
632
633 // Move to the primary root.
634 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
635 display0);
636 EXPECT_EQ("500,10 1000x100",
637 d1->GetWindowBoundsInScreen().ToString());
638 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
639}
640
[email protected]f059c6942012-07-21 14:27:57641TEST_F(ExtendedDesktopTest, MoveWindowWithTransient) {
[email protected]e75642a2013-06-12 17:21:18642 if (!SupportsMultipleDisplays())
643 return;
644
[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();
[email protected]f059c6942012-07-21 14:27:57647 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
648 views::Widget* w1_t1 = CreateTestWidgetWithParent(
649 w1, gfx::Rect(50, 50, 50, 50), false /* transient */);
650 // Transient child of the transient child.
651 views::Widget* w1_t11 = CreateTestWidgetWithParent(
[email protected]e6de8552014-05-23 19:05:39652 w1_t1, gfx::Rect(1200, 70, 35, 35), false /* transient */);
[email protected]f059c6942012-07-21 14:27:57653
654 views::Widget* w11 = CreateTestWidgetWithParent(
655 w1, gfx::Rect(10, 10, 40, 40), true /* child */);
656 views::Widget* w11_t1 = CreateTestWidgetWithParent(
657 w1, gfx::Rect(1300, 100, 80, 80), false /* transient */);
658
659 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
660 EXPECT_EQ(root_windows[0], w11->GetNativeView()->GetRootWindow());
661 EXPECT_EQ(root_windows[0], w1_t1->GetNativeView()->GetRootWindow());
662 EXPECT_EQ(root_windows[0], w1_t11->GetNativeView()->GetRootWindow());
663 EXPECT_EQ(root_windows[0], w11_t1->GetNativeView()->GetRootWindow());
664 EXPECT_EQ("50,50 50x50",
665 w1_t1->GetWindowBoundsInScreen().ToString());
[email protected]e6de8552014-05-23 19:05:39666 EXPECT_EQ("1200,70 35x35",
[email protected]f059c6942012-07-21 14:27:57667 w1_t11->GetWindowBoundsInScreen().ToString());
668 EXPECT_EQ("20,20 40x40",
669 w11->GetWindowBoundsInScreen().ToString());
670 EXPECT_EQ("1300,100 80x80",
671 w11_t1->GetWindowBoundsInScreen().ToString());
672
[email protected]24f5e242014-07-22 02:16:09673 w1->SetBounds(gfx::Rect(1100, 10, 100, 100));
[email protected]f059c6942012-07-21 14:27:57674
675 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
676 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
677 EXPECT_EQ(root_windows[1], w1_t11->GetNativeView()->GetRootWindow());
678 EXPECT_EQ(root_windows[1], w11->GetNativeView()->GetRootWindow());
679 EXPECT_EQ(root_windows[1], w11_t1->GetNativeView()->GetRootWindow());
680
681 EXPECT_EQ("1110,20 40x40",
682 w11->GetWindowBoundsInScreen().ToString());
683 // Transient window's screen bounds stays the same.
684 EXPECT_EQ("50,50 50x50",
685 w1_t1->GetWindowBoundsInScreen().ToString());
[email protected]e6de8552014-05-23 19:05:39686 EXPECT_EQ("1200,70 35x35",
[email protected]f059c6942012-07-21 14:27:57687 w1_t11->GetWindowBoundsInScreen().ToString());
688 EXPECT_EQ("1300,100 80x80",
689 w11_t1->GetWindowBoundsInScreen().ToString());
690
691 // Transient window doesn't move between root window unless
692 // its transient parent moves.
693 w1_t1->SetBounds(gfx::Rect(10, 50, 50, 50));
694 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
695 EXPECT_EQ("10,50 50x50",
696 w1_t1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57697}
698
[email protected]ca7060982012-08-08 18:05:25699// Test if the Window::ConvertPointToTarget works across root windows.
[email protected]a5e71c92012-06-22 22:09:08700// TODO(oshima): Move multiple display suport and this test to aura.
701TEST_F(ExtendedDesktopTest, ConvertPoint) {
[email protected]e75642a2013-06-12 17:21:18702 if (!SupportsMultipleDisplays())
703 return;
scottmge8b042972016-01-27 05:07:35704 gfx::Screen* screen = gfx::Screen::GetScreen();
[email protected]f634dd32012-07-23 22:49:07705 UpdateDisplay("1000x600,600x400");
[email protected]c9390bd2013-11-08 20:33:13706 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]b8984242013-07-12 07:55:38707 gfx::Display display_1 = screen->GetDisplayNearestWindow(root_windows[0]);
[email protected]a5e71c92012-06-22 22:09:08708 EXPECT_EQ("0,0", display_1.bounds().origin().ToString());
[email protected]b8984242013-07-12 07:55:38709 gfx::Display display_2 = screen->GetDisplayNearestWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07710 EXPECT_EQ("1000,0", display_2.bounds().origin().ToString());
711
[email protected]a5e71c92012-06-22 22:09:08712 aura::Window* d1 =
713 CreateTestWidget(gfx::Rect(10, 10, 100, 100))->GetNativeView();
[email protected]a5e71c92012-06-22 22:09:08714 aura::Window* d2 =
[email protected]f634dd32012-07-23 22:49:07715 CreateTestWidget(gfx::Rect(1020, 20, 100, 100))->GetNativeView();
716 EXPECT_EQ(root_windows[0], d1->GetRootWindow());
717 EXPECT_EQ(root_windows[1], d2->GetRootWindow());
[email protected]a5e71c92012-06-22 22:09:08718
[email protected]a5e71c92012-06-22 22:09:08719 // Convert point in the Root2's window to the Root1's window Coord.
720 gfx::Point p(0, 0);
[email protected]ca7060982012-08-08 18:05:25721 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07722 EXPECT_EQ("1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08723 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25724 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07725 EXPECT_EQ("1010,10", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08726
727 // Convert point in the Root1's window to the Root2's window Coord.
728 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25729 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07730 EXPECT_EQ("-1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08731 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25732 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07733 EXPECT_EQ("-1010,-10", p.ToString());
734
735 // Move the 2nd display to the bottom and test again.
robliaoc0dfd6b2016-04-07 21:33:56736 SetSecondaryDisplayLayout(display::DisplayPlacement::BOTTOM);
[email protected]f634dd32012-07-23 22:49:07737
[email protected]b8984242013-07-12 07:55:38738 display_2 = screen->GetDisplayNearestWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07739 EXPECT_EQ("0,600", display_2.bounds().origin().ToString());
740
741 // Convert point in Root2's window to Root1's window Coord.
742 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25743 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07744 EXPECT_EQ("0,600", p.ToString());
745 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25746 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07747 EXPECT_EQ("10,610", p.ToString());
748
749 // Convert point in Root1's window to Root2's window Coord.
750 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25751 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07752 EXPECT_EQ("0,-600", p.ToString());
753 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25754 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07755 EXPECT_EQ("-10,-610", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08756}
[email protected]f634dd32012-07-23 22:49:07757
[email protected]263898a2012-09-17 17:20:07758TEST_F(ExtendedDesktopTest, OpenSystemTray) {
[email protected]e75642a2013-06-12 17:21:18759 if (!SupportsMultipleDisplays())
760 return;
761
[email protected]596c61c2012-10-29 17:29:43762 UpdateDisplay("500x600,600x400");
[email protected]a0afeb12012-12-10 22:57:09763 SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray();
[email protected]263898a2012-09-17 17:20:07764 ASSERT_FALSE(tray->HasSystemBubble());
765
[email protected]73c9fd02014-07-28 01:48:52766 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41767
[email protected]263898a2012-09-17 17:20:07768 // Opens the tray by a dummy click event and makes sure that adding/removing
769 // displays doesn't break anything.
[email protected]334e6182013-01-11 18:35:41770 event_generator.MoveMouseToCenterOf(tray->GetWidget()->GetNativeWindow());
[email protected]263898a2012-09-17 17:20:07771 event_generator.ClickLeftButton();
772 EXPECT_TRUE(tray->HasSystemBubble());
773
[email protected]596c61c2012-10-29 17:29:43774 UpdateDisplay("500x600");
[email protected]263898a2012-09-17 17:20:07775 EXPECT_TRUE(tray->HasSystemBubble());
[email protected]596c61c2012-10-29 17:29:43776 UpdateDisplay("500x600,600x400");
[email protected]263898a2012-09-17 17:20:07777 EXPECT_TRUE(tray->HasSystemBubble());
778
779 // Closes the tray and again makes sure that adding/removing displays doesn't
780 // break anything.
781 event_generator.ClickLeftButton();
782 RunAllPendingInMessageLoop();
783
784 EXPECT_FALSE(tray->HasSystemBubble());
785
[email protected]596c61c2012-10-29 17:29:43786 UpdateDisplay("500x600");
[email protected]263898a2012-09-17 17:20:07787 EXPECT_FALSE(tray->HasSystemBubble());
[email protected]596c61c2012-10-29 17:29:43788 UpdateDisplay("500x600,600x400");
[email protected]263898a2012-09-17 17:20:07789 EXPECT_FALSE(tray->HasSystemBubble());
790}
791
[email protected]578048512012-09-19 20:01:24792TEST_F(ExtendedDesktopTest, StayInSameRootWindow) {
[email protected]e75642a2013-06-12 17:21:18793 if (!SupportsMultipleDisplays())
794 return;
795
[email protected]578048512012-09-19 20:01:24796 UpdateDisplay("100x100,200x200");
[email protected]c9390bd2013-11-08 20:33:13797 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]a2e6af12013-01-07 21:40:35798 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 50, 50));
[email protected]578048512012-09-19 20:01:24799 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
800 w1->SetBounds(gfx::Rect(150, 10, 50, 50));
801 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
802
803 // The widget stays in the same root if kStayInSameRootWindowKey is set to
804 // true.
[email protected]093b8d642014-04-03 20:59:28805 w1->GetNativeView()->SetProperty(kStayInSameRootWindowKey, true);
[email protected]578048512012-09-19 20:01:24806 w1->SetBounds(gfx::Rect(10, 10, 50, 50));
807 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
808
809 // The widget should now move to the 1st root window without the property.
[email protected]093b8d642014-04-03 20:59:28810 w1->GetNativeView()->ClearProperty(kStayInSameRootWindowKey);
[email protected]578048512012-09-19 20:01:24811 w1->SetBounds(gfx::Rect(10, 10, 50, 50));
812 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
[email protected]e887c6c2013-07-08 19:35:53813
814 // a window in SettingsBubbleContainer and StatusContainer should
815 // not move to another root window regardles of the bounds specified.
816 aura::Window* settings_bubble_container =
817 Shell::GetPrimaryRootWindowController()->GetContainer(
[email protected]093b8d642014-04-03 20:59:28818 kShellWindowId_SettingBubbleContainer);
[email protected]e887c6c2013-07-08 19:35:53819 aura::Window* window = aura::test::CreateTestWindowWithId(
820 100, settings_bubble_container);
821 window->SetBoundsInScreen(gfx::Rect(150, 10, 50, 50),
[email protected]55ad8c12014-01-17 18:24:33822 ScreenUtil::GetSecondaryDisplay());
[email protected]e887c6c2013-07-08 19:35:53823 EXPECT_EQ(root_windows[0], window->GetRootWindow());
824
825 aura::Window* status_container =
826 Shell::GetPrimaryRootWindowController()->GetContainer(
[email protected]093b8d642014-04-03 20:59:28827 kShellWindowId_StatusContainer);
[email protected]e887c6c2013-07-08 19:35:53828 window = aura::test::CreateTestWindowWithId(100, status_container);
829 window->SetBoundsInScreen(gfx::Rect(150, 10, 50, 50),
[email protected]55ad8c12014-01-17 18:24:33830 ScreenUtil::GetSecondaryDisplay());
[email protected]e887c6c2013-07-08 19:35:53831 EXPECT_EQ(root_windows[0], window->GetRootWindow());
[email protected]578048512012-09-19 20:01:24832}
833
[email protected]e67291f12012-10-10 05:52:38834TEST_F(ExtendedDesktopTest, KeyEventsOnLockScreen) {
[email protected]e75642a2013-06-12 17:21:18835 if (!SupportsMultipleDisplays())
836 return;
837
[email protected]e67291f12012-10-10 05:52:38838 UpdateDisplay("100x100,200x200");
[email protected]c9390bd2013-11-08 20:33:13839 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]e67291f12012-10-10 05:52:38840
841 // Create normal windows on both displays.
scottmge8b042972016-01-27 05:07:35842 views::Widget* widget1 =
843 CreateTestWidget(gfx::Screen::GetScreen()->GetPrimaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38844 widget1->Show();
845 EXPECT_EQ(root_windows[0], widget1->GetNativeView()->GetRootWindow());
846 views::Widget* widget2 = CreateTestWidget(
[email protected]55ad8c12014-01-17 18:24:33847 ScreenUtil::GetSecondaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38848 widget2->Show();
849 EXPECT_EQ(root_windows[1], widget2->GetNativeView()->GetRootWindow());
850
851 // Create a LockScreen window.
scottmge8b042972016-01-27 05:07:35852 views::Widget* lock_widget =
853 CreateTestWidget(gfx::Screen::GetScreen()->GetPrimaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38854 views::Textfield* textfield = new views::Textfield;
[email protected]09148952013-03-13 13:25:43855 lock_widget->client_view()->AddChildView(textfield);
[email protected]e67291f12012-10-10 05:52:38856
[email protected]093b8d642014-04-03 20:59:28857 ash::Shell::GetContainer(Shell::GetPrimaryRootWindow(),
858 ash::kShellWindowId_LockScreenContainer)
859 ->AddChild(lock_widget->GetNativeView());
[email protected]e67291f12012-10-10 05:52:38860 lock_widget->Show();
861 textfield->RequestFocus();
862
[email protected]8cfb6722012-11-28 03:28:46863 aura::client::FocusClient* focus_client =
864 aura::client::GetFocusClient(root_windows[0]);
865 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]e67291f12012-10-10 05:52:38866
867 // The lock window should get events on both root windows.
[email protected]73c9fd02014-07-28 01:48:52868 ui::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41869
[email protected]1ea46f6f2014-07-17 07:36:40870 event_generator.set_current_target(root_windows[0]);
[email protected]334e6182013-01-11 18:35:41871 event_generator.PressKey(ui::VKEY_A, 0);
872 event_generator.ReleaseKey(ui::VKEY_A, 0);
[email protected]8cfb6722012-11-28 03:28:46873 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46874 EXPECT_EQ("a", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38875
[email protected]1ea46f6f2014-07-17 07:36:40876 event_generator.set_current_target(root_windows[1]);
[email protected]334e6182013-01-11 18:35:41877 event_generator.PressKey(ui::VKEY_B, 0);
878 event_generator.ReleaseKey(ui::VKEY_B, 0);
[email protected]8cfb6722012-11-28 03:28:46879 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46880 EXPECT_EQ("ab", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38881
882 // Deleting 2nd display. The lock window still should get the events.
883 UpdateDisplay("100x100");
pkotwicz5d118a6b12015-02-12 22:23:57884 event_generator.set_current_target(root_windows[0]);
[email protected]334e6182013-01-11 18:35:41885 event_generator.PressKey(ui::VKEY_C, 0);
886 event_generator.ReleaseKey(ui::VKEY_C, 0);
[email protected]8cfb6722012-11-28 03:28:46887 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46888 EXPECT_EQ("abc", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38889
890 // Creating 2nd display again, and lock window still should get events
891 // on both root windows.
892 UpdateDisplay("100x100,200x200");
893 root_windows = Shell::GetAllRootWindows();
[email protected]1ea46f6f2014-07-17 07:36:40894 event_generator.set_current_target(root_windows[0]);
[email protected]334e6182013-01-11 18:35:41895 event_generator.PressKey(ui::VKEY_D, 0);
896 event_generator.ReleaseKey(ui::VKEY_D, 0);
[email protected]8cfb6722012-11-28 03:28:46897 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46898 EXPECT_EQ("abcd", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38899
[email protected]1ea46f6f2014-07-17 07:36:40900 event_generator.set_current_target(root_windows[1]);
[email protected]334e6182013-01-11 18:35:41901 event_generator.PressKey(ui::VKEY_E, 0);
902 event_generator.ReleaseKey(ui::VKEY_E, 0);
[email protected]8cfb6722012-11-28 03:28:46903 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]74f778e2014-03-14 21:11:46904 EXPECT_EQ("abcde", base::UTF16ToASCII(textfield->text()));
[email protected]e67291f12012-10-10 05:52:38905}
906
[email protected]334e6182013-01-11 18:35:41907TEST_F(ExtendedDesktopTest, PassiveGrab) {
[email protected]e75642a2013-06-12 17:21:18908 if (!SupportsMultipleDisplays())
909 return;
910
[email protected]334e6182013-01-11 18:35:41911 EventLocationRecordingEventHandler event_handler;
912 ash::Shell::GetInstance()->AddPreTargetHandler(&event_handler);
913
914 UpdateDisplay("300x300,200x200");
915
916 views::Widget* widget = CreateTestWidget(gfx::Rect(50, 50, 200, 200));
917 widget->Show();
918 ASSERT_EQ("50,50 200x200", widget->GetWindowBoundsInScreen().ToString());
919
[email protected]73c9fd02014-07-28 01:48:52920 ui::test::EventGenerator& generator(GetEventGenerator());
[email protected]334e6182013-01-11 18:35:41921 generator.MoveMouseTo(150, 150);
922 EXPECT_EQ("100,100 150,150", event_handler.GetLocationsAndReset());
923
924 generator.PressLeftButton();
925 generator.MoveMouseTo(400, 150);
926
927 EXPECT_EQ("350,100 400,150", event_handler.GetLocationsAndReset());
928
929 generator.ReleaseLeftButton();
930 EXPECT_EQ("-999,-999 -999,-999", event_handler.GetLocationsAndReset());
931
932 generator.MoveMouseTo(400, 150);
933 EXPECT_EQ("100,150 100,150", event_handler.GetLocationsAndReset());
934
935 ash::Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
936}
937
[email protected]c39be8f2012-06-15 22:58:36938} // namespace ash