blob: 36161e046d01e34c11cb7d00212c3002bf7beebf [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]2e236a52012-06-27 22:21:475#include "ash/display/display_controller.h"
[email protected]6bdf7952012-11-14 10:10:586#include "ash/display/display_manager.h"
[email protected]e887c6c2013-07-08 19:35:537#include "ash/root_window_controller.h"
[email protected]e67291f12012-10-10 05:52:388#include "ash/screen_ash.h"
[email protected]c39be8f2012-06-15 22:58:369#include "ash/shell.h"
[email protected]e67291f12012-10-10 05:52:3810#include "ash/shell_window_ids.h"
[email protected]263898a2012-09-17 17:20:0711#include "ash/system/tray/system_tray.h"
[email protected]c39be8f2012-06-15 22:58:3612#include "ash/test/ash_test_base.h"
[email protected]7203a5e2012-08-06 18:27:4613#include "ash/wm/coordinate_conversion.h"
[email protected]7ae525002012-07-26 23:55:1014#include "ash/wm/property_util.h"
[email protected]0f81f442012-06-22 06:20:2715#include "ash/wm/window_cycle_controller.h"
[email protected]578048512012-09-19 20:01:2416#include "ash/wm/window_properties.h"
[email protected]c39be8f2012-06-15 22:58:3617#include "ash/wm/window_util.h"
[email protected]0836da02013-06-10 19:33:3518#include "base/strings/string_util.h"
[email protected]c39be8f2012-06-15 22:58:3619#include "ui/aura/client/activation_client.h"
20#include "ui/aura/client/capture_client.h"
[email protected]8cfb6722012-11-28 03:28:4621#include "ui/aura/client/focus_client.h"
[email protected]c39be8f2012-06-15 22:58:3622#include "ui/aura/root_window.h"
23#include "ui/aura/test/event_generator.h"
[email protected]a5e71c92012-06-22 22:09:0824#include "ui/aura/test/test_windows.h"
[email protected]553eae12013-02-01 02:33:5225#include "ui/aura/test/window_test_api.h"
[email protected]c39be8f2012-06-15 22:58:3626#include "ui/aura/window.h"
27#include "ui/base/cursor/cursor.h"
[email protected]2e98aaf72012-11-08 06:30:5928#include "ui/base/events/event_handler.h"
[email protected]a5e71c92012-06-22 22:09:0829#include "ui/gfx/display.h"
[email protected]718b26c2012-07-24 20:53:2330#include "ui/gfx/screen.h"
[email protected]e67291f12012-10-10 05:52:3831#include "ui/views/controls/textfield/textfield.h"
[email protected]c39be8f2012-06-15 22:58:3632#include "ui/views/widget/widget.h"
33#include "ui/views/widget/widget_delegate.h"
34
35namespace ash {
36namespace {
37
[email protected]edbfb8d2012-09-03 08:33:4338void SetSecondaryDisplayLayout(DisplayLayout::Position position) {
39 DisplayController* display_controller =
40 Shell::GetInstance()->display_controller();
[email protected]29190fd2013-03-30 16:09:5041 DisplayLayout layout = display_controller->GetCurrentDisplayLayout();
[email protected]edbfb8d2012-09-03 08:33:4342 layout.position = position;
[email protected]29190fd2013-03-30 16:09:5043 display_controller->SetLayoutForCurrentDisplays(layout);
[email protected]edbfb8d2012-09-03 08:33:4344}
45
[email protected]b8984242013-07-12 07:55:3846internal::DisplayManager* GetDisplayManager() {
47 return Shell::GetInstance()->display_manager();
48}
49
[email protected]c39be8f2012-06-15 22:58:3650class ModalWidgetDelegate : public views::WidgetDelegateView {
51 public:
52 ModalWidgetDelegate() {}
53 virtual ~ModalWidgetDelegate() {}
54
55 // Overridden from views::WidgetDelegate:
56 virtual views::View* GetContentsView() OVERRIDE {
57 return this;
58 }
59 virtual ui::ModalType GetModalType() const OVERRIDE {
60 return ui::MODAL_TYPE_SYSTEM;
61 }
62
63 private:
64 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate);
65};
66
[email protected]334e6182013-01-11 18:35:4167// An event handler which moves the target window to the secondary root window
[email protected]2e98aaf72012-11-08 06:30:5968// at pre-handle phase of a mouse release event.
[email protected]334e6182013-01-11 18:35:4169class MoveWindowByClickEventHandler : public ui::EventHandler {
[email protected]2e98aaf72012-11-08 06:30:5970 public:
[email protected]334e6182013-01-11 18:35:4171 explicit MoveWindowByClickEventHandler(aura::Window* target)
[email protected]2e98aaf72012-11-08 06:30:5972 : target_(target) {}
[email protected]334e6182013-01-11 18:35:4173 virtual ~MoveWindowByClickEventHandler() {}
[email protected]2e98aaf72012-11-08 06:30:5974
75 private:
76 // ui::EventHandler overrides:
[email protected]d44efe02012-12-18 06:08:1877 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
[email protected]2e98aaf72012-11-08 06:30:5978 if (event->type() == ui::ET_MOUSE_RELEASED) {
79 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
80 DCHECK_LT(1u, root_windows.size());
81 root_windows[1]->AddChild(target_);
82 }
[email protected]2e98aaf72012-11-08 06:30:5983 }
84
[email protected]2e98aaf72012-11-08 06:30:5985 aura::Window* target_;
[email protected]334e6182013-01-11 18:35:4186 DISALLOW_COPY_AND_ASSIGN(MoveWindowByClickEventHandler);
87};
88
89// An event handler which records the event's locations.
90class EventLocationRecordingEventHandler : public ui::EventHandler {
91 public:
92 explicit EventLocationRecordingEventHandler() {
93 reset();
94 }
95 virtual ~EventLocationRecordingEventHandler() {}
96
97 std::string GetLocationsAndReset() {
98 std::string result =
99 location_.ToString() + " " + root_location_.ToString();
100 reset();
101 return result;
102 }
103
104 private:
105 // ui::EventHandler overrides:
106 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
107 if (event->type() == ui::ET_MOUSE_MOVED ||
108 event->type() == ui::ET_MOUSE_DRAGGED) {
109 location_ = event->location();
110 root_location_ = event->root_location();
111 }
112 }
113
114 void reset() {
115 location_.SetPoint(-999, -999);
116 root_location_.SetPoint(-999, -999);
117 }
118
119 gfx::Point root_location_;
120 gfx::Point location_;
121
122 DISALLOW_COPY_AND_ASSIGN(EventLocationRecordingEventHandler);
[email protected]2e98aaf72012-11-08 06:30:59123};
124
[email protected]c39be8f2012-06-15 22:58:36125} // namespace
126
[email protected]a2e6af12013-01-07 21:40:35127class ExtendedDesktopTest : public test::AshTestBase {
128 public:
129 views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
130 return CreateTestWidgetWithParentAndContext(
131 NULL, CurrentContext(), bounds, false);
132 }
133
134 views::Widget* CreateTestWidgetWithParent(views::Widget* parent,
135 const gfx::Rect& bounds,
136 bool child) {
137 CHECK(parent);
138 return CreateTestWidgetWithParentAndContext(parent, NULL, bounds, child);
139 }
140
141 views::Widget* CreateTestWidgetWithParentAndContext(views::Widget* parent,
142 gfx::NativeView context,
143 const gfx::Rect& bounds,
144 bool child) {
145 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
146 if (parent)
147 params.parent = parent->GetNativeView();
148 params.context = context;
149 params.bounds = bounds;
150 params.child = child;
151 views::Widget* widget = new views::Widget;
152 widget->Init(params);
153 widget->Show();
154 return widget;
155 }
156};
[email protected]c39be8f2012-06-15 22:58:36157
158// Test conditions that root windows in extended desktop mode
159// must satisfy.
160TEST_F(ExtendedDesktopTest, Basic) {
[email protected]e75642a2013-06-12 17:21:18161 if (!SupportsMultipleDisplays())
162 return;
163
[email protected]f634dd32012-07-23 22:49:07164 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:36165 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
166
167 // All root windows must have the root window controller.
168 ASSERT_EQ(2U, root_windows.size());
169 for (Shell::RootWindowList::const_iterator iter = root_windows.begin();
170 iter != root_windows.end(); ++iter) {
[email protected]7ae525002012-07-26 23:55:10171 EXPECT_TRUE(GetRootWindowController(*iter) != NULL);
[email protected]c39be8f2012-06-15 22:58:36172 }
173 // Make sure root windows share the same controllers.
[email protected]8cfb6722012-11-28 03:28:46174 EXPECT_EQ(aura::client::GetFocusClient(root_windows[0]),
175 aura::client::GetFocusClient(root_windows[1]));
[email protected]c39be8f2012-06-15 22:58:36176 EXPECT_EQ(aura::client::GetActivationClient(root_windows[0]),
177 aura::client::GetActivationClient(root_windows[1]));
178 EXPECT_EQ(aura::client::GetCaptureClient(root_windows[0]),
179 aura::client::GetCaptureClient(root_windows[1]));
180}
181
182TEST_F(ExtendedDesktopTest, Activation) {
[email protected]e75642a2013-06-12 17:21:18183 if (!SupportsMultipleDisplays())
184 return;
185
[email protected]f634dd32012-07-23 22:49:07186 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:36187 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
188
[email protected]c39be8f2012-06-15 22:58:36189 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]f634dd32012-07-23 22:49:07190 views::Widget* widget_on_2nd =
191 CreateTestWidget(gfx::Rect(1200, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36192 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
[email protected]f634dd32012-07-23 22:49:07193 EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36194
195 EXPECT_EQ(widget_on_2nd->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46196 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]c39be8f2012-06-15 22:58:36197 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
198
[email protected]334e6182013-01-11 18:35:41199 aura::test::EventGenerator& event_generator(GetEventGenerator());
[email protected]f634dd32012-07-23 22:49:07200 // Clicking a window changes the active window and active root window.
[email protected]334e6182013-01-11 18:35:41201 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView());
202 event_generator.ClickLeftButton();
[email protected]c39be8f2012-06-15 22:58:36203
204 EXPECT_EQ(widget_on_1st->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46205 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]c39be8f2012-06-15 22:58:36206 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]f634dd32012-07-23 22:49:07207
[email protected]334e6182013-01-11 18:35:41208 event_generator.MoveMouseToCenterOf(widget_on_2nd->GetNativeView());
209 event_generator.ClickLeftButton();
[email protected]f634dd32012-07-23 22:49:07210
211 EXPECT_EQ(widget_on_2nd->GetNativeView(),
[email protected]8cfb6722012-11-28 03:28:46212 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
[email protected]f634dd32012-07-23 22:49:07213 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
[email protected]c39be8f2012-06-15 22:58:36214}
215
216TEST_F(ExtendedDesktopTest, SystemModal) {
[email protected]e75642a2013-06-12 17:21:18217 if (!SupportsMultipleDisplays())
218 return;
219
[email protected]f634dd32012-07-23 22:49:07220 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:36221 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36222
223 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36224 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]492533b32012-09-21 19:06:14225 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36226 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow());
227
[email protected]c39be8f2012-06-15 22:58:36228 // Open system modal. Make sure it's on 2nd root window and active.
[email protected]a2e6af12013-01-07 21:40:35229 views::Widget* modal_widget = views::Widget::CreateWindowWithContextAndBounds(
230 new ModalWidgetDelegate(),
231 CurrentContext(),
232 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());
236 EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow());
237
[email protected]334e6182013-01-11 18:35:41238 aura::test::EventGenerator& event_generator(GetEventGenerator());
239
[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()));
244 EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow());
245
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()));
251 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow());
252}
253
254TEST_F(ExtendedDesktopTest, TestCursor) {
[email protected]e75642a2013-06-12 17:21:18255 if (!SupportsMultipleDisplays())
256 return;
257
[email protected]f634dd32012-07-23 22:49:07258 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:36259 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36260 EXPECT_EQ(ui::kCursorPointer, root_windows[0]->last_cursor().native_type());
261 EXPECT_EQ(ui::kCursorPointer, root_windows[1]->last_cursor().native_type());
[email protected]151ffdff2012-09-11 20:18:35262 Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorCopy);
[email protected]c39be8f2012-06-15 22:58:36263 EXPECT_EQ(ui::kCursorCopy, root_windows[0]->last_cursor().native_type());
264 EXPECT_EQ(ui::kCursorCopy, root_windows[1]->last_cursor().native_type());
265}
266
[email protected]718b26c2012-07-24 20:53:23267TEST_F(ExtendedDesktopTest, TestCursorLocation) {
[email protected]e75642a2013-06-12 17:21:18268 if (!SupportsMultipleDisplays())
269 return;
270
[email protected]d0064722013-03-14 18:16:43271 UpdateDisplay("1000x600,600x400");
[email protected]718b26c2012-07-24 20:53:23272 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]553eae12013-02-01 02:33:52273 aura::test::WindowTestApi root_window0_test_api(root_windows[0]);
274 aura::test::WindowTestApi root_window1_test_api(root_windows[1]);
[email protected]718b26c2012-07-24 20:53:23275
276 root_windows[0]->MoveCursorTo(gfx::Point(10, 10));
[email protected]ffabb1e2012-10-12 19:51:17277 EXPECT_EQ("10,10", Shell::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23278 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
279 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
280 root_windows[1]->MoveCursorTo(gfx::Point(10, 20));
[email protected]ffabb1e2012-10-12 19:51:17281 EXPECT_EQ("1010,20", Shell::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23282 EXPECT_FALSE(root_window0_test_api.ContainsMouse());
283 EXPECT_TRUE(root_window1_test_api.ContainsMouse());
284 root_windows[0]->MoveCursorTo(gfx::Point(20, 10));
[email protected]ffabb1e2012-10-12 19:51:17285 EXPECT_EQ("20,10", Shell::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23286 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
287 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
288}
289
[email protected]0f81f442012-06-22 06:20:27290TEST_F(ExtendedDesktopTest, CycleWindows) {
[email protected]e75642a2013-06-12 17:21:18291 if (!SupportsMultipleDisplays())
292 return;
293
[email protected]f634dd32012-07-23 22:49:07294 UpdateDisplay("700x500,500x500");
[email protected]0f81f442012-06-22 06:20:27295 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24296
[email protected]0f81f442012-06-22 06:20:27297 WindowCycleController* controller =
298 Shell::GetInstance()->window_cycle_controller();
299
[email protected]0f81f442012-06-22 06:20:27300 views::Widget* d1_w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
301 EXPECT_EQ(root_windows[0], d1_w1->GetNativeView()->GetRootWindow());
[email protected]20c59762012-06-23 01:10:24302 views::Widget* d2_w1 = CreateTestWidget(gfx::Rect(800, 10, 100, 100));
[email protected]0f81f442012-06-22 06:20:27303 EXPECT_EQ(root_windows[1], d2_w1->GetNativeView()->GetRootWindow());
304 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
305
306 controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
307 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
308 controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
309 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
310 controller->HandleCycleWindow(WindowCycleController::BACKWARD, false);
311 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
312 controller->HandleCycleWindow(WindowCycleController::BACKWARD, false);
313 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
314
315 // Cycle through all windows across root windows.
[email protected]20c59762012-06-23 01:10:24316 views::Widget* d1_w2 = CreateTestWidget(gfx::Rect(10, 200, 100, 100));
[email protected]0f81f442012-06-22 06:20:27317 EXPECT_EQ(root_windows[0], d1_w2->GetNativeView()->GetRootWindow());
[email protected]20c59762012-06-23 01:10:24318 views::Widget* d2_w2 = CreateTestWidget(gfx::Rect(800, 200, 100, 100));
[email protected]0f81f442012-06-22 06:20:27319 EXPECT_EQ(root_windows[1], d2_w2->GetNativeView()->GetRootWindow());
320
321 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
[email protected]0f81f442012-06-22 06:20:27322 EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView()));
323 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
[email protected]8fef7432012-08-06 15:34:25324 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
325 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
[email protected]0f81f442012-06-22 06:20:27326 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
327 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
328 EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView()));
329
330 // Backwards
331 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
332 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView()));
333 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
[email protected]0f81f442012-06-22 06:20:27334 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
335 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
[email protected]8fef7432012-08-06 15:34:25336 EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView()));
337 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
[email protected]0f81f442012-06-22 06:20:27338 EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView()));
[email protected]20c59762012-06-23 01:10:24339}
340
341TEST_F(ExtendedDesktopTest, GetRootWindowAt) {
[email protected]e75642a2013-06-12 17:21:18342 if (!SupportsMultipleDisplays())
343 return;
344
[email protected]f634dd32012-07-23 22:49:07345 UpdateDisplay("700x500,500x500");
[email protected]edbfb8d2012-09-03 08:33:43346 SetSecondaryDisplayLayout(DisplayLayout::LEFT);
[email protected]20c59762012-06-23 01:10:24347 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24348
[email protected]7203a5e2012-08-06 18:27:46349 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-400, 100)));
350 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-1, 100)));
351 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 300)));
352 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(700,300)));
[email protected]20c59762012-06-23 01:10:24353
354 // Zero origin.
[email protected]7203a5e2012-08-06 18:27:46355 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 0)));
[email protected]20c59762012-06-23 01:10:24356
357 // Out of range point should return the primary root window
[email protected]7203a5e2012-08-06 18:27:46358 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(-600, 0)));
359 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(701, 100)));
[email protected]20c59762012-06-23 01:10:24360}
361
362TEST_F(ExtendedDesktopTest, GetRootWindowMatching) {
[email protected]e75642a2013-06-12 17:21:18363 if (!SupportsMultipleDisplays())
364 return;
365
[email protected]f634dd32012-07-23 22:49:07366 UpdateDisplay("700x500,500x500");
[email protected]edbfb8d2012-09-03 08:33:43367 SetSecondaryDisplayLayout(DisplayLayout::LEFT);
[email protected]66b05eac2012-06-27 23:53:10368
[email protected]20c59762012-06-23 01:10:24369 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24370
371 // Containing rect.
372 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46373 wm::GetRootWindowMatching(gfx::Rect(-300, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24374 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46375 wm::GetRootWindowMatching(gfx::Rect(100, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24376
377 // Intersecting rect.
378 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46379 wm::GetRootWindowMatching(gfx::Rect(-200, 0, 300, 300)));
[email protected]20c59762012-06-23 01:10:24380 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46381 wm::GetRootWindowMatching(gfx::Rect(-100, 0, 300, 300)));
[email protected]20c59762012-06-23 01:10:24382
383 // Zero origin.
[email protected]66b05eac2012-06-27 23:53:10384 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46385 wm::GetRootWindowMatching(gfx::Rect(0, 0, 0, 0)));
[email protected]66b05eac2012-06-27 23:53:10386 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46387 wm::GetRootWindowMatching(gfx::Rect(0, 0, 1, 1)));
[email protected]20c59762012-06-23 01:10:24388
389 // Empty rect.
390 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46391 wm::GetRootWindowMatching(gfx::Rect(-400, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24392 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46393 wm::GetRootWindowMatching(gfx::Rect(100, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24394
395 // Out of range rect should return the primary root window.
396 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46397 wm::GetRootWindowMatching(gfx::Rect(-600, -300, 50, 50)));
[email protected]20c59762012-06-23 01:10:24398 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46399 wm::GetRootWindowMatching(gfx::Rect(0, 1000, 50, 50)));
[email protected]0f81f442012-06-22 06:20:27400}
401
[email protected]1a015382012-12-01 19:44:59402TEST_F(ExtendedDesktopTest, Capture) {
[email protected]e75642a2013-06-12 17:21:18403 if (!SupportsMultipleDisplays())
404 return;
405
[email protected]f634dd32012-07-23 22:49:07406 UpdateDisplay("1000x600,600x400");
[email protected]a5e71c92012-06-22 22:09:08407 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
408
409 aura::test::EventCountDelegate r1_d1;
410 aura::test::EventCountDelegate r1_d2;
411 aura::test::EventCountDelegate r2_d1;
412
413 scoped_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
414 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
415 scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
416 &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
417 scoped_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
418 &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
[email protected]f634dd32012-07-23 22:49:07419
[email protected]a5e71c92012-06-22 22:09:08420 r1_w1->SetCapture();
421
422 EXPECT_EQ(r1_w1.get(),
423 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]334e6182013-01-11 18:35:41424
[email protected]a5e71c92012-06-22 22:09:08425 aura::test::EventGenerator generator2(root_windows[1]);
426 generator2.MoveMouseToCenterOf(r2_w1.get());
427 generator2.ClickLeftButton();
428 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
429 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
[email protected]b19ba4adf2012-09-07 16:13:29430 // The mouse is outside. On chromeos, the mouse is warped to the
431 // dest root window, but it's not implemented on Win yet, so
432 // no mouse move event on Win.
[email protected]7495e5032012-09-07 15:31:45433 EXPECT_EQ("1 1 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08434 EXPECT_EQ("1 1", r1_d1.GetMouseButtonCountsAndReset());
[email protected]334e6182013-01-11 18:35:41435 // Emulate passive grab. (15,15) on 1st display is (-985,15) on 2nd
436 // display.
[email protected]f634dd32012-07-23 22:49:07437 generator2.MoveMouseTo(-985, 15);
438 EXPECT_EQ("0 1 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08439
440 r1_w2->SetCapture();
441 EXPECT_EQ(r1_w2.get(),
442 aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
443 generator2.MoveMouseBy(10, 10);
444 generator2.ClickLeftButton();
445 EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset());
446 EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset());
447 // mouse is already entered.
448 EXPECT_EQ("0 1 0", r1_d2.GetMouseMotionCountsAndReset());
449 EXPECT_EQ("1 1", r1_d2.GetMouseButtonCountsAndReset());
[email protected]a5e71c92012-06-22 22:09:08450 r1_w2->ReleaseCapture();
[email protected]36f566532012-09-19 04:07:24451 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]f634dd32012-07-23 22:49:07452 generator2.MoveMouseTo(15, 15);
[email protected]a5e71c92012-06-22 22:09:08453 generator2.ClickLeftButton();
454 EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset());
455 EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset());
456 // Make sure the mouse_moved_handler_ is properly reset.
457 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset());
458 EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset());
459}
460
[email protected]f059c6942012-07-21 14:27:57461TEST_F(ExtendedDesktopTest, MoveWindow) {
[email protected]e75642a2013-06-12 17:21:18462 if (!SupportsMultipleDisplays())
463 return;
464
[email protected]f634dd32012-07-23 22:49:07465 UpdateDisplay("1000x600,600x400");
[email protected]f059c6942012-07-21 14:27:57466 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
467 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
468
469 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
470
471 d1->SetBounds(gfx::Rect(1010, 10, 100, 100));
472 EXPECT_EQ("1010,10 100x100",
473 d1->GetWindowBoundsInScreen().ToString());
474
475 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
476
477 d1->SetBounds(gfx::Rect(10, 10, 100, 100));
478 EXPECT_EQ("10,10 100x100",
479 d1->GetWindowBoundsInScreen().ToString());
480
481 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
482
483 // Make sure the bounds which doesn't fit to the root window
484 // works correctly.
485 d1->SetBounds(gfx::Rect(1560, 30, 100, 100));
486 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
487 EXPECT_EQ("1560,30 100x100",
488 d1->GetWindowBoundsInScreen().ToString());
489
490 // Setting outside of root windows will be moved to primary root window.
491 // TODO(oshima): This one probably should pick the closest root window.
492 d1->SetBounds(gfx::Rect(200, 10, 100, 100));
493 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
[email protected]f059c6942012-07-21 14:27:57494}
495
[email protected]2e98aaf72012-11-08 06:30:59496// Verifies if the mouse event arrives to the window even when the window
497// moves to another root in a pre-target handler. See: crbug.com/157583
498TEST_F(ExtendedDesktopTest, MoveWindowByMouseClick) {
[email protected]e75642a2013-06-12 17:21:18499 if (!SupportsMultipleDisplays())
500 return;
501
[email protected]2e98aaf72012-11-08 06:30:59502 UpdateDisplay("1000x600,600x400");
503
504 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
505 aura::test::EventCountDelegate delegate;
506 scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate(
507 &delegate, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
[email protected]334e6182013-01-11 18:35:41508 MoveWindowByClickEventHandler event_handler(window.get());
509 window->AddPreTargetHandler(&event_handler);
510
511 aura::test::EventGenerator& event_generator(GetEventGenerator());
512
513 event_generator.MoveMouseToCenterOf(window.get());
514 event_generator.ClickLeftButton();
[email protected]2e98aaf72012-11-08 06:30:59515 // Both mouse pressed and released arrive at the window and its delegate.
516 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset());
[email protected]334e6182013-01-11 18:35:41517 // Also event_handler moves the window to another root at mouse release.
[email protected]2e98aaf72012-11-08 06:30:59518 EXPECT_EQ(root_windows[1], window->GetRootWindow());
519}
520
[email protected]1a015382012-12-01 19:44:59521TEST_F(ExtendedDesktopTest, MoveWindowToDisplay) {
[email protected]e75642a2013-06-12 17:21:18522 if (!SupportsMultipleDisplays())
523 return;
524
[email protected]e79f26e2012-08-09 07:12:48525 UpdateDisplay("1000x1000,1000x1000");
526 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
527
[email protected]ffabb1e2012-10-12 19:51:17528 gfx::Display display0 = Shell::GetScreen()->GetDisplayMatching(
529 root_windows[0]->GetBoundsInScreen());
530 gfx::Display display1 = Shell::GetScreen()->GetDisplayMatching(
531 root_windows[1]->GetBoundsInScreen());
[email protected]e79f26e2012-08-09 07:12:48532 EXPECT_NE(display0.id(), display1.id());
533
534 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 1000, 100));
535 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
536
537 // Move the window where the window spans both root windows. Since the second
538 // parameter is |display1|, the window should be shown on the secondary root.
539 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
540 display1);
541 EXPECT_EQ("500,10 1000x100",
542 d1->GetWindowBoundsInScreen().ToString());
543 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow());
544
545 // Move to the primary root.
546 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
547 display0);
548 EXPECT_EQ("500,10 1000x100",
549 d1->GetWindowBoundsInScreen().ToString());
550 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow());
551}
552
[email protected]f059c6942012-07-21 14:27:57553TEST_F(ExtendedDesktopTest, MoveWindowWithTransient) {
[email protected]e75642a2013-06-12 17:21:18554 if (!SupportsMultipleDisplays())
555 return;
556
[email protected]f634dd32012-07-23 22:49:07557 UpdateDisplay("1000x600,600x400");
[email protected]f059c6942012-07-21 14:27:57558 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
559 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
560 views::Widget* w1_t1 = CreateTestWidgetWithParent(
561 w1, gfx::Rect(50, 50, 50, 50), false /* transient */);
562 // Transient child of the transient child.
563 views::Widget* w1_t11 = CreateTestWidgetWithParent(
564 w1_t1, gfx::Rect(1200, 70, 30, 30), false /* transient */);
565
566 views::Widget* w11 = CreateTestWidgetWithParent(
567 w1, gfx::Rect(10, 10, 40, 40), true /* child */);
568 views::Widget* w11_t1 = CreateTestWidgetWithParent(
569 w1, gfx::Rect(1300, 100, 80, 80), false /* transient */);
570
571 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
572 EXPECT_EQ(root_windows[0], w11->GetNativeView()->GetRootWindow());
573 EXPECT_EQ(root_windows[0], w1_t1->GetNativeView()->GetRootWindow());
574 EXPECT_EQ(root_windows[0], w1_t11->GetNativeView()->GetRootWindow());
575 EXPECT_EQ(root_windows[0], w11_t1->GetNativeView()->GetRootWindow());
576 EXPECT_EQ("50,50 50x50",
577 w1_t1->GetWindowBoundsInScreen().ToString());
578 EXPECT_EQ("1200,70 30x30",
579 w1_t11->GetWindowBoundsInScreen().ToString());
580 EXPECT_EQ("20,20 40x40",
581 w11->GetWindowBoundsInScreen().ToString());
582 EXPECT_EQ("1300,100 80x80",
583 w11_t1->GetWindowBoundsInScreen().ToString());
584
585 w1->SetBounds(gfx::Rect(1100,10,100,100));
586
587 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
588 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
589 EXPECT_EQ(root_windows[1], w1_t11->GetNativeView()->GetRootWindow());
590 EXPECT_EQ(root_windows[1], w11->GetNativeView()->GetRootWindow());
591 EXPECT_EQ(root_windows[1], w11_t1->GetNativeView()->GetRootWindow());
592
593 EXPECT_EQ("1110,20 40x40",
594 w11->GetWindowBoundsInScreen().ToString());
595 // Transient window's screen bounds stays the same.
596 EXPECT_EQ("50,50 50x50",
597 w1_t1->GetWindowBoundsInScreen().ToString());
598 EXPECT_EQ("1200,70 30x30",
599 w1_t11->GetWindowBoundsInScreen().ToString());
600 EXPECT_EQ("1300,100 80x80",
601 w11_t1->GetWindowBoundsInScreen().ToString());
602
603 // Transient window doesn't move between root window unless
604 // its transient parent moves.
605 w1_t1->SetBounds(gfx::Rect(10, 50, 50, 50));
606 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow());
607 EXPECT_EQ("10,50 50x50",
608 w1_t1->GetWindowBoundsInScreen().ToString());
[email protected]f059c6942012-07-21 14:27:57609}
610
[email protected]ca7060982012-08-08 18:05:25611// Test if the Window::ConvertPointToTarget works across root windows.
[email protected]a5e71c92012-06-22 22:09:08612// TODO(oshima): Move multiple display suport and this test to aura.
613TEST_F(ExtendedDesktopTest, ConvertPoint) {
[email protected]e75642a2013-06-12 17:21:18614 if (!SupportsMultipleDisplays())
615 return;
[email protected]b8984242013-07-12 07:55:38616 gfx::Screen* screen = Shell::GetInstance()->screen();
[email protected]f634dd32012-07-23 22:49:07617 UpdateDisplay("1000x600,600x400");
[email protected]a5e71c92012-06-22 22:09:08618 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]b8984242013-07-12 07:55:38619 gfx::Display display_1 = screen->GetDisplayNearestWindow(root_windows[0]);
[email protected]a5e71c92012-06-22 22:09:08620 EXPECT_EQ("0,0", display_1.bounds().origin().ToString());
[email protected]b8984242013-07-12 07:55:38621 gfx::Display display_2 = screen->GetDisplayNearestWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07622 EXPECT_EQ("1000,0", display_2.bounds().origin().ToString());
623
[email protected]a5e71c92012-06-22 22:09:08624 aura::Window* d1 =
625 CreateTestWidget(gfx::Rect(10, 10, 100, 100))->GetNativeView();
[email protected]a5e71c92012-06-22 22:09:08626 aura::Window* d2 =
[email protected]f634dd32012-07-23 22:49:07627 CreateTestWidget(gfx::Rect(1020, 20, 100, 100))->GetNativeView();
628 EXPECT_EQ(root_windows[0], d1->GetRootWindow());
629 EXPECT_EQ(root_windows[1], d2->GetRootWindow());
[email protected]a5e71c92012-06-22 22:09:08630
[email protected]a5e71c92012-06-22 22:09:08631 // Convert point in the Root2's window to the Root1's window Coord.
632 gfx::Point p(0, 0);
[email protected]ca7060982012-08-08 18:05:25633 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07634 EXPECT_EQ("1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08635 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25636 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07637 EXPECT_EQ("1010,10", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08638
639 // Convert point in the Root1's window to the Root2's window Coord.
640 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25641 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07642 EXPECT_EQ("-1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08643 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25644 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07645 EXPECT_EQ("-1010,-10", p.ToString());
646
647 // Move the 2nd display to the bottom and test again.
[email protected]edbfb8d2012-09-03 08:33:43648 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM);
[email protected]f634dd32012-07-23 22:49:07649
[email protected]b8984242013-07-12 07:55:38650 display_2 = screen->GetDisplayNearestWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07651 EXPECT_EQ("0,600", display_2.bounds().origin().ToString());
652
653 // Convert point in Root2's window to Root1's window Coord.
654 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25655 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07656 EXPECT_EQ("0,600", p.ToString());
657 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25658 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07659 EXPECT_EQ("10,610", p.ToString());
660
661 // Convert point in Root1's window to Root2's window Coord.
662 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25663 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07664 EXPECT_EQ("0,-600", p.ToString());
665 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25666 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07667 EXPECT_EQ("-10,-610", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08668}
[email protected]f634dd32012-07-23 22:49:07669
[email protected]263898a2012-09-17 17:20:07670TEST_F(ExtendedDesktopTest, OpenSystemTray) {
[email protected]e75642a2013-06-12 17:21:18671 if (!SupportsMultipleDisplays())
672 return;
673
[email protected]596c61c2012-10-29 17:29:43674 UpdateDisplay("500x600,600x400");
[email protected]a0afeb12012-12-10 22:57:09675 SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray();
[email protected]263898a2012-09-17 17:20:07676 ASSERT_FALSE(tray->HasSystemBubble());
677
[email protected]334e6182013-01-11 18:35:41678 aura::test::EventGenerator& event_generator(GetEventGenerator());
679
[email protected]263898a2012-09-17 17:20:07680 // Opens the tray by a dummy click event and makes sure that adding/removing
681 // displays doesn't break anything.
[email protected]334e6182013-01-11 18:35:41682 event_generator.MoveMouseToCenterOf(tray->GetWidget()->GetNativeWindow());
[email protected]263898a2012-09-17 17:20:07683 event_generator.ClickLeftButton();
684 EXPECT_TRUE(tray->HasSystemBubble());
685
[email protected]596c61c2012-10-29 17:29:43686 UpdateDisplay("500x600");
[email protected]263898a2012-09-17 17:20:07687 EXPECT_TRUE(tray->HasSystemBubble());
[email protected]596c61c2012-10-29 17:29:43688 UpdateDisplay("500x600,600x400");
[email protected]263898a2012-09-17 17:20:07689 EXPECT_TRUE(tray->HasSystemBubble());
690
691 // Closes the tray and again makes sure that adding/removing displays doesn't
692 // break anything.
693 event_generator.ClickLeftButton();
694 RunAllPendingInMessageLoop();
695
696 EXPECT_FALSE(tray->HasSystemBubble());
697
[email protected]596c61c2012-10-29 17:29:43698 UpdateDisplay("500x600");
[email protected]263898a2012-09-17 17:20:07699 EXPECT_FALSE(tray->HasSystemBubble());
[email protected]596c61c2012-10-29 17:29:43700 UpdateDisplay("500x600,600x400");
[email protected]263898a2012-09-17 17:20:07701 EXPECT_FALSE(tray->HasSystemBubble());
702}
703
[email protected]578048512012-09-19 20:01:24704TEST_F(ExtendedDesktopTest, StayInSameRootWindow) {
[email protected]e75642a2013-06-12 17:21:18705 if (!SupportsMultipleDisplays())
706 return;
707
[email protected]578048512012-09-19 20:01:24708 UpdateDisplay("100x100,200x200");
709 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]a2e6af12013-01-07 21:40:35710 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 50, 50));
[email protected]578048512012-09-19 20:01:24711 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
712 w1->SetBounds(gfx::Rect(150, 10, 50, 50));
713 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
714
715 // The widget stays in the same root if kStayInSameRootWindowKey is set to
716 // true.
717 w1->GetNativeView()->SetProperty(internal::kStayInSameRootWindowKey, true);
718 w1->SetBounds(gfx::Rect(10, 10, 50, 50));
719 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
720
721 // The widget should now move to the 1st root window without the property.
722 w1->GetNativeView()->ClearProperty(internal::kStayInSameRootWindowKey);
723 w1->SetBounds(gfx::Rect(10, 10, 50, 50));
724 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow());
[email protected]e887c6c2013-07-08 19:35:53725
726 // a window in SettingsBubbleContainer and StatusContainer should
727 // not move to another root window regardles of the bounds specified.
728 aura::Window* settings_bubble_container =
729 Shell::GetPrimaryRootWindowController()->GetContainer(
[email protected]b8984242013-07-12 07:55:38730 internal::kShellWindowId_SettingBubbleContainer);
[email protected]e887c6c2013-07-08 19:35:53731 aura::Window* window = aura::test::CreateTestWindowWithId(
732 100, settings_bubble_container);
733 window->SetBoundsInScreen(gfx::Rect(150, 10, 50, 50),
734 ScreenAsh::GetSecondaryDisplay());
735 EXPECT_EQ(root_windows[0], window->GetRootWindow());
736
737 aura::Window* status_container =
738 Shell::GetPrimaryRootWindowController()->GetContainer(
[email protected]b8984242013-07-12 07:55:38739 internal::kShellWindowId_StatusContainer);
[email protected]e887c6c2013-07-08 19:35:53740 window = aura::test::CreateTestWindowWithId(100, status_container);
741 window->SetBoundsInScreen(gfx::Rect(150, 10, 50, 50),
742 ScreenAsh::GetSecondaryDisplay());
743 EXPECT_EQ(root_windows[0], window->GetRootWindow());
[email protected]578048512012-09-19 20:01:24744}
745
[email protected]e67291f12012-10-10 05:52:38746TEST_F(ExtendedDesktopTest, KeyEventsOnLockScreen) {
[email protected]e75642a2013-06-12 17:21:18747 if (!SupportsMultipleDisplays())
748 return;
749
[email protected]e67291f12012-10-10 05:52:38750 UpdateDisplay("100x100,200x200");
751 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
752
753 // Create normal windows on both displays.
754 views::Widget* widget1 = CreateTestWidget(
[email protected]ffabb1e2012-10-12 19:51:17755 Shell::GetScreen()->GetPrimaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38756 widget1->Show();
757 EXPECT_EQ(root_windows[0], widget1->GetNativeView()->GetRootWindow());
758 views::Widget* widget2 = CreateTestWidget(
759 ScreenAsh::GetSecondaryDisplay().bounds());
760 widget2->Show();
761 EXPECT_EQ(root_windows[1], widget2->GetNativeView()->GetRootWindow());
762
763 // Create a LockScreen window.
764 views::Widget* lock_widget = CreateTestWidget(
[email protected]ffabb1e2012-10-12 19:51:17765 Shell::GetScreen()->GetPrimaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38766 views::Textfield* textfield = new views::Textfield;
[email protected]09148952013-03-13 13:25:43767 lock_widget->client_view()->AddChildView(textfield);
[email protected]e67291f12012-10-10 05:52:38768
769 ash::Shell::GetContainer(
770 Shell::GetPrimaryRootWindow(),
771 ash::internal::kShellWindowId_LockScreenContainer)->
772 AddChild(lock_widget->GetNativeView());
773 lock_widget->Show();
774 textfield->RequestFocus();
775
[email protected]8cfb6722012-11-28 03:28:46776 aura::client::FocusClient* focus_client =
777 aura::client::GetFocusClient(root_windows[0]);
778 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]e67291f12012-10-10 05:52:38779
780 // The lock window should get events on both root windows.
[email protected]334e6182013-01-11 18:35:41781 aura::test::EventGenerator& event_generator(GetEventGenerator());
782
783 event_generator.set_current_root_window(root_windows[0]);
784 event_generator.PressKey(ui::VKEY_A, 0);
785 event_generator.ReleaseKey(ui::VKEY_A, 0);
[email protected]8cfb6722012-11-28 03:28:46786 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]e67291f12012-10-10 05:52:38787 EXPECT_EQ("a", UTF16ToASCII(textfield->text()));
788
[email protected]334e6182013-01-11 18:35:41789 event_generator.set_current_root_window(root_windows[1]);
790 event_generator.PressKey(ui::VKEY_B, 0);
791 event_generator.ReleaseKey(ui::VKEY_B, 0);
[email protected]8cfb6722012-11-28 03:28:46792 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]e67291f12012-10-10 05:52:38793 EXPECT_EQ("ab", UTF16ToASCII(textfield->text()));
794
795 // Deleting 2nd display. The lock window still should get the events.
796 UpdateDisplay("100x100");
[email protected]334e6182013-01-11 18:35:41797 event_generator.PressKey(ui::VKEY_C, 0);
798 event_generator.ReleaseKey(ui::VKEY_C, 0);
[email protected]8cfb6722012-11-28 03:28:46799 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]e67291f12012-10-10 05:52:38800 EXPECT_EQ("abc", UTF16ToASCII(textfield->text()));
801
802 // Creating 2nd display again, and lock window still should get events
803 // on both root windows.
804 UpdateDisplay("100x100,200x200");
805 root_windows = Shell::GetAllRootWindows();
[email protected]334e6182013-01-11 18:35:41806 event_generator.set_current_root_window(root_windows[0]);
807 event_generator.PressKey(ui::VKEY_D, 0);
808 event_generator.ReleaseKey(ui::VKEY_D, 0);
[email protected]8cfb6722012-11-28 03:28:46809 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]e67291f12012-10-10 05:52:38810 EXPECT_EQ("abcd", UTF16ToASCII(textfield->text()));
811
[email protected]334e6182013-01-11 18:35:41812 event_generator.set_current_root_window(root_windows[1]);
813 event_generator.PressKey(ui::VKEY_E, 0);
814 event_generator.ReleaseKey(ui::VKEY_E, 0);
[email protected]8cfb6722012-11-28 03:28:46815 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
[email protected]e67291f12012-10-10 05:52:38816 EXPECT_EQ("abcde", UTF16ToASCII(textfield->text()));
817}
818
[email protected]334e6182013-01-11 18:35:41819TEST_F(ExtendedDesktopTest, PassiveGrab) {
[email protected]e75642a2013-06-12 17:21:18820 if (!SupportsMultipleDisplays())
821 return;
822
[email protected]334e6182013-01-11 18:35:41823 EventLocationRecordingEventHandler event_handler;
824 ash::Shell::GetInstance()->AddPreTargetHandler(&event_handler);
825
826 UpdateDisplay("300x300,200x200");
827
828 views::Widget* widget = CreateTestWidget(gfx::Rect(50, 50, 200, 200));
829 widget->Show();
830 ASSERT_EQ("50,50 200x200", widget->GetWindowBoundsInScreen().ToString());
831
832 aura::test::EventGenerator& generator(GetEventGenerator());
833 generator.MoveMouseTo(150, 150);
834 EXPECT_EQ("100,100 150,150", event_handler.GetLocationsAndReset());
835
836 generator.PressLeftButton();
837 generator.MoveMouseTo(400, 150);
838
839 EXPECT_EQ("350,100 400,150", event_handler.GetLocationsAndReset());
840
841 generator.ReleaseLeftButton();
842 EXPECT_EQ("-999,-999 -999,-999", event_handler.GetLocationsAndReset());
843
844 generator.MoveMouseTo(400, 150);
845 EXPECT_EQ("100,150 100,150", event_handler.GetLocationsAndReset());
846
847 ash::Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
848}
849
[email protected]c39be8f2012-06-15 22:58:36850} // namespace ash