1 // 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.
5 #include "ash/display/display_controller.h"
6 #include "ash/display/display_manager.h"
7 #include "ash/screen_ash.h"
9 #include "ash/shell_window_ids.h"
10 #include "ash/system/tray/system_tray.h"
11 #include "ash/test/ash_test_base.h"
12 #include "ash/wm/coordinate_conversion.h"
13 #include "ash/wm/property_util.h"
14 #include "ash/wm/window_cycle_controller.h"
15 #include "ash/wm/window_properties.h"
16 #include "ash/wm/window_util.h"
17 #include "base/string_util.h"
18 #include "ui/aura/client/activation_client.h"
19 #include "ui/aura/client/capture_client.h"
20 #include "ui/aura/client/focus_client.h"
21 #include "ui/aura/root_window.h"
22 #include "ui/aura/test/event_generator.h"
23 #include "ui/aura/test/test_windows.h"
24 #include "ui/aura/window.h"
25 #include "ui/base/cursor/cursor.h"
26 #include "ui/base/events/event_handler.h"
27 #include "ui/gfx/display.h"
28 #include "ui/gfx/screen.h"
29 #include "ui/views/controls/textfield/textfield.h"
30 #include "ui/views/widget/widget.h"
31 #include "ui/views/widget/widget_delegate.h"
36 views::Widget
* CreateTestWidgetWithParent(views::Widget
* parent
,
37 const gfx::Rect
& bounds
,
39 views::Widget::InitParams
params(views::Widget::InitParams::TYPE_WINDOW
);
41 params
.parent
= parent
->GetNativeView();
42 params
.bounds
= bounds
;
44 views::Widget
* widget
= new views::Widget
;
50 views::Widget
* CreateTestWidget(const gfx::Rect
& bounds
) {
51 return CreateTestWidgetWithParent(NULL
, bounds
, false);
54 void SetSecondaryDisplayLayout(DisplayLayout::Position position
) {
55 DisplayController
* display_controller
=
56 Shell::GetInstance()->display_controller();
57 DisplayLayout layout
= display_controller
->default_display_layout();
58 layout
.position
= position
;
59 display_controller
->SetDefaultDisplayLayout(layout
);
62 class ModalWidgetDelegate
: public views::WidgetDelegateView
{
64 ModalWidgetDelegate() {}
65 virtual ~ModalWidgetDelegate() {}
67 // Overridden from views::WidgetDelegate:
68 virtual views::View
* GetContentsView() OVERRIDE
{
71 virtual ui::ModalType
GetModalType() const OVERRIDE
{
72 return ui::MODAL_TYPE_SYSTEM
;
76 DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate
);
79 internal::DisplayManager
* GetDisplayManager() {
80 return Shell::GetInstance()->display_manager();
83 // An event filter which moves the target window to the secondary root window
84 // at pre-handle phase of a mouse release event.
85 class MoveWindowByClickEventFilter
: public ui::EventHandler
{
87 explicit MoveWindowByClickEventFilter(aura::Window
* target
)
89 virtual ~MoveWindowByClickEventFilter() {}
92 // ui::EventHandler overrides:
93 virtual void OnMouseEvent(ui::MouseEvent
* event
) OVERRIDE
{
94 if (event
->type() == ui::ET_MOUSE_RELEASED
) {
95 Shell::RootWindowList root_windows
= Shell::GetAllRootWindows();
96 DCHECK_LT(1u, root_windows
.size());
97 root_windows
[1]->AddChild(target_
);
101 aura::Window
* target_
;
102 DISALLOW_COPY_AND_ASSIGN(MoveWindowByClickEventFilter
);
107 typedef test::AshTestBase ExtendedDesktopTest
;
109 // Test conditions that root windows in extended desktop mode
111 TEST_F(ExtendedDesktopTest
, Basic
) {
112 UpdateDisplay("1000x600,600x400");
113 Shell::RootWindowList root_windows
= Shell::GetAllRootWindows();
115 // All root windows must have the root window controller.
116 ASSERT_EQ(2U, root_windows
.size());
117 for (Shell::RootWindowList::const_iterator iter
= root_windows
.begin();
118 iter
!= root_windows
.end(); ++iter
) {
119 EXPECT_TRUE(GetRootWindowController(*iter
) != NULL
);
121 // Make sure root windows share the same controllers.
122 EXPECT_EQ(aura::client::GetFocusClient(root_windows
[0]),
123 aura::client::GetFocusClient(root_windows
[1]));
124 EXPECT_EQ(aura::client::GetActivationClient(root_windows
[0]),
125 aura::client::GetActivationClient(root_windows
[1]));
126 EXPECT_EQ(aura::client::GetCaptureClient(root_windows
[0]),
127 aura::client::GetCaptureClient(root_windows
[1]));
130 TEST_F(ExtendedDesktopTest
, Activation
) {
131 UpdateDisplay("1000x600,600x400");
132 Shell::RootWindowList root_windows
= Shell::GetAllRootWindows();
134 views::Widget
* widget_on_1st
= CreateTestWidget(gfx::Rect(10, 10, 100, 100));
135 views::Widget
* widget_on_2nd
=
136 CreateTestWidget(gfx::Rect(1200, 10, 100, 100));
137 EXPECT_EQ(root_windows
[0], widget_on_1st
->GetNativeView()->GetRootWindow());
138 EXPECT_EQ(root_windows
[1], widget_on_2nd
->GetNativeView()->GetRootWindow());
140 EXPECT_EQ(widget_on_2nd
->GetNativeView(),
141 aura::client::GetFocusClient(root_windows
[0])->GetFocusedWindow());
142 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd
->GetNativeView()));
144 aura::test::EventGenerator
generator_1st(root_windows
[0]);
145 aura::test::EventGenerator
generator_2nd(root_windows
[1]);
147 // Clicking a window changes the active window and active root window.
148 generator_1st
.MoveMouseToCenterOf(widget_on_1st
->GetNativeView());
149 generator_1st
.ClickLeftButton();
151 EXPECT_EQ(widget_on_1st
->GetNativeView(),
152 aura::client::GetFocusClient(root_windows
[0])->GetFocusedWindow());
153 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st
->GetNativeView()));
155 generator_2nd
.MoveMouseToCenterOf(widget_on_2nd
->GetNativeView());
156 generator_2nd
.ClickLeftButton();
158 EXPECT_EQ(widget_on_2nd
->GetNativeView(),
159 aura::client::GetFocusClient(root_windows
[0])->GetFocusedWindow());
160 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd
->GetNativeView()));
163 TEST_F(ExtendedDesktopTest
, SystemModal
) {
164 UpdateDisplay("1000x600,600x400");
165 Shell::RootWindowList root_windows
= Shell::GetAllRootWindows();
167 views::Widget
* widget_on_1st
= CreateTestWidget(gfx::Rect(10, 10, 100, 100));
168 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st
->GetNativeView()));
169 EXPECT_EQ(root_windows
[0], widget_on_1st
->GetNativeView()->GetRootWindow());
170 EXPECT_EQ(root_windows
[0], Shell::GetActiveRootWindow());
172 // Open system modal. Make sure it's on 2nd root window and active.
173 views::Widget
* modal_widget
= views::Widget::CreateWindowWithBounds(
174 new ModalWidgetDelegate(), gfx::Rect(1200, 100, 100, 100));
175 modal_widget
->Show();
176 EXPECT_TRUE(wm::IsActiveWindow(modal_widget
->GetNativeView()));
177 EXPECT_EQ(root_windows
[1], modal_widget
->GetNativeView()->GetRootWindow());
178 EXPECT_EQ(root_windows
[1], Shell::GetActiveRootWindow());
180 // Clicking a widget on widget_on_1st display should not change activation.
181 aura::test::EventGenerator
generator_1st(root_windows
[0]);
182 generator_1st
.MoveMouseToCenterOf(widget_on_1st
->GetNativeView());
183 generator_1st
.ClickLeftButton();
184 EXPECT_TRUE(wm::IsActiveWindow(modal_widget
->GetNativeView()));
185 EXPECT_EQ(root_windows
[1], Shell::GetActiveRootWindow());
187 // Close system modal and so clicking a widget should work now.
188 modal_widget
->Close();
189 generator_1st
.MoveMouseToCenterOf(widget_on_1st
->GetNativeView());
190 generator_1st
.ClickLeftButton();
191 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st
->GetNativeView()));
192 EXPECT_EQ(root_windows
[0], Shell::GetActiveRootWindow());
195 TEST_F(ExtendedDesktopTest
, TestCursor
) {
196 UpdateDisplay("1000x600,600x400");
197 Shell::RootWindowList root_windows
= Shell::GetAllRootWindows();
198 EXPECT_EQ(ui::kCursorPointer
, root_windows
[0]->last_cursor().native_type());
199 EXPECT_EQ(ui::kCursorPointer
, root_windows
[1]->last_cursor().native_type());
200 Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorCopy
);
201 EXPECT_EQ(ui::kCursorCopy
, root_windows
[0]->last_cursor().native_type());
202 EXPECT_EQ(ui::kCursorCopy
, root_windows
[1]->last_cursor().native_type());
205 TEST_F(ExtendedDesktopTest
, TestCursorLocation
) {
206 UpdateDisplay("0+0-1000x600,1001+0-600x400");
207 Shell::RootWindowList root_windows
= Shell::GetAllRootWindows();
208 aura::Window::TestApi
root_window0_test_api(root_windows
[0]);
209 aura::Window::TestApi
root_window1_test_api(root_windows
[1]);
211 root_windows
[0]->MoveCursorTo(gfx::Point(10, 10));
212 EXPECT_EQ("10,10", Shell::GetScreen()->GetCursorScreenPoint().ToString());
213 EXPECT_TRUE(root_window0_test_api
.ContainsMouse());
214 EXPECT_FALSE(root_window1_test_api
.ContainsMouse());
215 root_windows
[1]->MoveCursorTo(gfx::Point(10, 20));
216 EXPECT_EQ("1010,20", Shell::GetScreen()->GetCursorScreenPoint().ToString());
217 EXPECT_FALSE(root_window0_test_api
.ContainsMouse());
218 EXPECT_TRUE(root_window1_test_api
.ContainsMouse());
219 root_windows
[0]->MoveCursorTo(gfx::Point(20, 10));
220 EXPECT_EQ("20,10", Shell::GetScreen()->GetCursorScreenPoint().ToString());
221 EXPECT_TRUE(root_window0_test_api
.ContainsMouse());
222 EXPECT_FALSE(root_window1_test_api
.ContainsMouse());
225 TEST_F(ExtendedDesktopTest
, CycleWindows
) {
226 UpdateDisplay("700x500,500x500");
227 Shell::RootWindowList root_windows
= Shell::GetAllRootWindows();
229 WindowCycleController
* controller
=
230 Shell::GetInstance()->window_cycle_controller();
232 views::Widget
* d1_w1
= CreateTestWidget(gfx::Rect(10, 10, 100, 100));
233 EXPECT_EQ(root_windows
[0], d1_w1
->GetNativeView()->GetRootWindow());
234 views::Widget
* d2_w1
= CreateTestWidget(gfx::Rect(800, 10, 100, 100));
235 EXPECT_EQ(root_windows
[1], d2_w1
->GetNativeView()->GetRootWindow());
236 EXPECT_TRUE(wm::IsActiveWindow(d2_w1
->GetNativeView()));
238 controller
->HandleCycleWindow(WindowCycleController::FORWARD
, false);
239 EXPECT_TRUE(wm::IsActiveWindow(d1_w1
->GetNativeView()));
240 controller
->HandleCycleWindow(WindowCycleController::FORWARD
, false);
241 EXPECT_TRUE(wm::IsActiveWindow(d2_w1
->GetNativeView()));
242 controller
->HandleCycleWindow(WindowCycleController::BACKWARD
, false);
243 EXPECT_TRUE(wm::IsActiveWindow(d1_w1
->GetNativeView()));
244 controller
->HandleCycleWindow(WindowCycleController::BACKWARD
, false);
245 EXPECT_TRUE(wm::IsActiveWindow(d2_w1
->GetNativeView()));
247 // Cycle through all windows across root windows.
248 views::Widget
* d1_w2
= CreateTestWidget(gfx::Rect(10, 200, 100, 100));
249 EXPECT_EQ(root_windows
[0], d1_w2
->GetNativeView()->GetRootWindow());
250 views::Widget
* d2_w2
= CreateTestWidget(gfx::Rect(800, 200, 100, 100));
251 EXPECT_EQ(root_windows
[1], d2_w2
->GetNativeView()->GetRootWindow());
253 controller
->HandleCycleWindow(WindowCycleController::FORWARD
, true);
254 EXPECT_TRUE(wm::IsActiveWindow(d1_w2
->GetNativeView()));
255 controller
->HandleCycleWindow(WindowCycleController::FORWARD
, true);
256 EXPECT_TRUE(wm::IsActiveWindow(d2_w1
->GetNativeView()));
257 controller
->HandleCycleWindow(WindowCycleController::FORWARD
, true);
258 EXPECT_TRUE(wm::IsActiveWindow(d1_w1
->GetNativeView()));
259 controller
->HandleCycleWindow(WindowCycleController::FORWARD
, true);
260 EXPECT_TRUE(wm::IsActiveWindow(d2_w2
->GetNativeView()));
263 controller
->HandleCycleWindow(WindowCycleController::BACKWARD
, true);
264 EXPECT_TRUE(wm::IsActiveWindow(d1_w1
->GetNativeView()));
265 controller
->HandleCycleWindow(WindowCycleController::BACKWARD
, true);
266 EXPECT_TRUE(wm::IsActiveWindow(d2_w1
->GetNativeView()));
267 controller
->HandleCycleWindow(WindowCycleController::BACKWARD
, true);
268 EXPECT_TRUE(wm::IsActiveWindow(d1_w2
->GetNativeView()));
269 controller
->HandleCycleWindow(WindowCycleController::BACKWARD
, true);
270 EXPECT_TRUE(wm::IsActiveWindow(d2_w2
->GetNativeView()));
273 TEST_F(ExtendedDesktopTest
, GetRootWindowAt
) {
274 UpdateDisplay("700x500,500x500");
275 SetSecondaryDisplayLayout(DisplayLayout::LEFT
);
276 Shell::RootWindowList root_windows
= Shell::GetAllRootWindows();
278 EXPECT_EQ(root_windows
[1], wm::GetRootWindowAt(gfx::Point(-400, 100)));
279 EXPECT_EQ(root_windows
[1], wm::GetRootWindowAt(gfx::Point(-1, 100)));
280 EXPECT_EQ(root_windows
[0], wm::GetRootWindowAt(gfx::Point(0, 300)));
281 EXPECT_EQ(root_windows
[0], wm::GetRootWindowAt(gfx::Point(700,300)));
284 EXPECT_EQ(root_windows
[0], wm::GetRootWindowAt(gfx::Point(0, 0)));
286 // Out of range point should return the primary root window
287 EXPECT_EQ(root_windows
[0], wm::GetRootWindowAt(gfx::Point(-600, 0)));
288 EXPECT_EQ(root_windows
[0], wm::GetRootWindowAt(gfx::Point(701, 100)));
291 TEST_F(ExtendedDesktopTest
, GetRootWindowMatching
) {
292 UpdateDisplay("700x500,500x500");
293 SetSecondaryDisplayLayout(DisplayLayout::LEFT
);
295 Shell::RootWindowList root_windows
= Shell::GetAllRootWindows();
298 EXPECT_EQ(root_windows
[1],
299 wm::GetRootWindowMatching(gfx::Rect(-300, 10, 50, 50)));
300 EXPECT_EQ(root_windows
[0],
301 wm::GetRootWindowMatching(gfx::Rect(100, 10, 50, 50)));
303 // Intersecting rect.
304 EXPECT_EQ(root_windows
[1],
305 wm::GetRootWindowMatching(gfx::Rect(-200, 0, 300, 300)));
306 EXPECT_EQ(root_windows
[0],
307 wm::GetRootWindowMatching(gfx::Rect(-100, 0, 300, 300)));
310 EXPECT_EQ(root_windows
[0],
311 wm::GetRootWindowMatching(gfx::Rect(0, 0, 0, 0)));
312 EXPECT_EQ(root_windows
[0],
313 wm::GetRootWindowMatching(gfx::Rect(0, 0, 1, 1)));
316 EXPECT_EQ(root_windows
[1],
317 wm::GetRootWindowMatching(gfx::Rect(-400, 100, 0, 0)));
318 EXPECT_EQ(root_windows
[0],
319 wm::GetRootWindowMatching(gfx::Rect(100, 100, 0, 0)));
321 // Out of range rect should return the primary root window.
322 EXPECT_EQ(root_windows
[0],
323 wm::GetRootWindowMatching(gfx::Rect(-600, -300, 50, 50)));
324 EXPECT_EQ(root_windows
[0],
325 wm::GetRootWindowMatching(gfx::Rect(0, 1000, 50, 50)));
328 TEST_F(ExtendedDesktopTest
, Capture
) {
329 UpdateDisplay("1000x600,600x400");
330 Shell::RootWindowList root_windows
= Shell::GetAllRootWindows();
332 aura::test::EventCountDelegate r1_d1
;
333 aura::test::EventCountDelegate r1_d2
;
334 aura::test::EventCountDelegate r2_d1
;
336 scoped_ptr
<aura::Window
> r1_w1(aura::test::CreateTestWindowWithDelegate(
337 &r1_d1
, 0, gfx::Rect(10, 10, 100, 100), root_windows
[0]));
338 scoped_ptr
<aura::Window
> r1_w2(aura::test::CreateTestWindowWithDelegate(
339 &r1_d2
, 0, gfx::Rect(10, 100, 100, 100), root_windows
[0]));
340 scoped_ptr
<aura::Window
> r2_w1(aura::test::CreateTestWindowWithDelegate(
341 &r2_d1
, 0, gfx::Rect(10, 10, 100, 100), root_windows
[1]));
345 EXPECT_EQ(r1_w1
.get(),
346 aura::client::GetCaptureWindow(r2_w1
->GetRootWindow()));
347 aura::test::EventGenerator
generator2(root_windows
[1]);
348 generator2
.MoveMouseToCenterOf(r2_w1
.get());
349 generator2
.ClickLeftButton();
350 EXPECT_EQ("0 0 0", r2_d1
.GetMouseMotionCountsAndReset());
351 EXPECT_EQ("0 0", r2_d1
.GetMouseButtonCountsAndReset());
352 // The mouse is outside. On chromeos, the mouse is warped to the
353 // dest root window, but it's not implemented on Win yet, so
354 // no mouse move event on Win.
355 EXPECT_EQ("1 1 0", r1_d1
.GetMouseMotionCountsAndReset());
356 EXPECT_EQ("1 1", r1_d1
.GetMouseButtonCountsAndReset());
357 // (15,15) on 1st display is (-985,15) on 2nd display.
358 generator2
.MoveMouseTo(-985, 15);
359 EXPECT_EQ("0 1 0", r1_d1
.GetMouseMotionCountsAndReset());
362 EXPECT_EQ(r1_w2
.get(),
363 aura::client::GetCaptureWindow(r2_w1
->GetRootWindow()));
364 generator2
.MoveMouseBy(10, 10);
365 generator2
.ClickLeftButton();
366 EXPECT_EQ("0 0 0", r2_d1
.GetMouseMotionCountsAndReset());
367 EXPECT_EQ("0 0", r2_d1
.GetMouseButtonCountsAndReset());
368 // mouse is already entered.
369 EXPECT_EQ("0 1 0", r1_d2
.GetMouseMotionCountsAndReset());
370 EXPECT_EQ("1 1", r1_d2
.GetMouseButtonCountsAndReset());
372 r1_w2
->ReleaseCapture();
373 EXPECT_EQ(NULL
, aura::client::GetCaptureWindow(r2_w1
->GetRootWindow()));
374 generator2
.MoveMouseTo(15, 15);
375 generator2
.ClickLeftButton();
376 EXPECT_EQ("1 1 0", r2_d1
.GetMouseMotionCountsAndReset());
377 EXPECT_EQ("1 1", r2_d1
.GetMouseButtonCountsAndReset());
378 // Make sure the mouse_moved_handler_ is properly reset.
379 EXPECT_EQ("0 0 0", r1_d2
.GetMouseMotionCountsAndReset());
380 EXPECT_EQ("0 0", r1_d2
.GetMouseButtonCountsAndReset());
383 TEST_F(ExtendedDesktopTest
, MoveWindow
) {
384 UpdateDisplay("1000x600,600x400");
385 Shell::RootWindowList root_windows
= Shell::GetAllRootWindows();
386 views::Widget
* d1
= CreateTestWidget(gfx::Rect(10, 10, 100, 100));
388 EXPECT_EQ(root_windows
[0], d1
->GetNativeView()->GetRootWindow());
390 d1
->SetBounds(gfx::Rect(1010, 10, 100, 100));
391 EXPECT_EQ("1010,10 100x100",
392 d1
->GetWindowBoundsInScreen().ToString());
394 EXPECT_EQ(root_windows
[1], d1
->GetNativeView()->GetRootWindow());
396 d1
->SetBounds(gfx::Rect(10, 10, 100, 100));
397 EXPECT_EQ("10,10 100x100",
398 d1
->GetWindowBoundsInScreen().ToString());
400 EXPECT_EQ(root_windows
[0], d1
->GetNativeView()->GetRootWindow());
402 // Make sure the bounds which doesn't fit to the root window
404 d1
->SetBounds(gfx::Rect(1560, 30, 100, 100));
405 EXPECT_EQ(root_windows
[1], d1
->GetNativeView()->GetRootWindow());
406 EXPECT_EQ("1560,30 100x100",
407 d1
->GetWindowBoundsInScreen().ToString());
409 // Setting outside of root windows will be moved to primary root window.
410 // TODO(oshima): This one probably should pick the closest root window.
411 d1
->SetBounds(gfx::Rect(200, 10, 100, 100));
412 EXPECT_EQ(root_windows
[0], d1
->GetNativeView()->GetRootWindow());
415 // Verifies if the mouse event arrives to the window even when the window
416 // moves to another root in a pre-target handler. See: crbug.com/157583
417 TEST_F(ExtendedDesktopTest
, MoveWindowByMouseClick
) {
418 UpdateDisplay("1000x600,600x400");
420 Shell::RootWindowList root_windows
= Shell::GetAllRootWindows();
421 aura::test::EventCountDelegate delegate
;
422 scoped_ptr
<aura::Window
> window(aura::test::CreateTestWindowWithDelegate(
423 &delegate
, 0, gfx::Rect(10, 10, 100, 100), root_windows
[0]));
424 MoveWindowByClickEventFilter
event_filter(window
.get());
425 window
->AddPreTargetHandler(&event_filter
);
426 aura::test::EventGenerator
generator(root_windows
[0], window
.get());
427 generator
.ClickLeftButton();
428 // Both mouse pressed and released arrive at the window and its delegate.
429 EXPECT_EQ("1 1", delegate
.GetMouseButtonCountsAndReset());
430 // Also event_filter moves the window to another root at mouse release.
431 EXPECT_EQ(root_windows
[1], window
->GetRootWindow());
434 TEST_F(ExtendedDesktopTest
, MoveWindowToDisplay
) {
435 UpdateDisplay("1000x1000,1000x1000");
436 Shell::RootWindowList root_windows
= Shell::GetAllRootWindows();
438 gfx::Display display0
= Shell::GetScreen()->GetDisplayMatching(
439 root_windows
[0]->GetBoundsInScreen());
440 gfx::Display display1
= Shell::GetScreen()->GetDisplayMatching(
441 root_windows
[1]->GetBoundsInScreen());
442 EXPECT_NE(display0
.id(), display1
.id());
444 views::Widget
* d1
= CreateTestWidget(gfx::Rect(10, 10, 1000, 100));
445 EXPECT_EQ(root_windows
[0], d1
->GetNativeView()->GetRootWindow());
447 // Move the window where the window spans both root windows. Since the second
448 // parameter is |display1|, the window should be shown on the secondary root.
449 d1
->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
451 EXPECT_EQ("500,10 1000x100",
452 d1
->GetWindowBoundsInScreen().ToString());
453 EXPECT_EQ(root_windows
[1], d1
->GetNativeView()->GetRootWindow());
455 // Move to the primary root.
456 d1
->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100),
458 EXPECT_EQ("500,10 1000x100",
459 d1
->GetWindowBoundsInScreen().ToString());
460 EXPECT_EQ(root_windows
[0], d1
->GetNativeView()->GetRootWindow());
463 TEST_F(ExtendedDesktopTest
, MoveWindowWithTransient
) {
464 UpdateDisplay("1000x600,600x400");
465 Shell::RootWindowList root_windows
= Shell::GetAllRootWindows();
466 views::Widget
* w1
= CreateTestWidget(gfx::Rect(10, 10, 100, 100));
467 views::Widget
* w1_t1
= CreateTestWidgetWithParent(
468 w1
, gfx::Rect(50, 50, 50, 50), false /* transient */);
469 // Transient child of the transient child.
470 views::Widget
* w1_t11
= CreateTestWidgetWithParent(
471 w1_t1
, gfx::Rect(1200, 70, 30, 30), false /* transient */);
473 views::Widget
* w11
= CreateTestWidgetWithParent(
474 w1
, gfx::Rect(10, 10, 40, 40), true /* child */);
475 views::Widget
* w11_t1
= CreateTestWidgetWithParent(
476 w1
, gfx::Rect(1300, 100, 80, 80), false /* transient */);
478 EXPECT_EQ(root_windows
[0], w1
->GetNativeView()->GetRootWindow());
479 EXPECT_EQ(root_windows
[0], w11
->GetNativeView()->GetRootWindow());
480 EXPECT_EQ(root_windows
[0], w1_t1
->GetNativeView()->GetRootWindow());
481 EXPECT_EQ(root_windows
[0], w1_t11
->GetNativeView()->GetRootWindow());
482 EXPECT_EQ(root_windows
[0], w11_t1
->GetNativeView()->GetRootWindow());
483 EXPECT_EQ("50,50 50x50",
484 w1_t1
->GetWindowBoundsInScreen().ToString());
485 EXPECT_EQ("1200,70 30x30",
486 w1_t11
->GetWindowBoundsInScreen().ToString());
487 EXPECT_EQ("20,20 40x40",
488 w11
->GetWindowBoundsInScreen().ToString());
489 EXPECT_EQ("1300,100 80x80",
490 w11_t1
->GetWindowBoundsInScreen().ToString());
492 w1
->SetBounds(gfx::Rect(1100,10,100,100));
494 EXPECT_EQ(root_windows
[1], w1_t1
->GetNativeView()->GetRootWindow());
495 EXPECT_EQ(root_windows
[1], w1_t1
->GetNativeView()->GetRootWindow());
496 EXPECT_EQ(root_windows
[1], w1_t11
->GetNativeView()->GetRootWindow());
497 EXPECT_EQ(root_windows
[1], w11
->GetNativeView()->GetRootWindow());
498 EXPECT_EQ(root_windows
[1], w11_t1
->GetNativeView()->GetRootWindow());
500 EXPECT_EQ("1110,20 40x40",
501 w11
->GetWindowBoundsInScreen().ToString());
502 // Transient window's screen bounds stays the same.
503 EXPECT_EQ("50,50 50x50",
504 w1_t1
->GetWindowBoundsInScreen().ToString());
505 EXPECT_EQ("1200,70 30x30",
506 w1_t11
->GetWindowBoundsInScreen().ToString());
507 EXPECT_EQ("1300,100 80x80",
508 w11_t1
->GetWindowBoundsInScreen().ToString());
510 // Transient window doesn't move between root window unless
511 // its transient parent moves.
512 w1_t1
->SetBounds(gfx::Rect(10, 50, 50, 50));
513 EXPECT_EQ(root_windows
[1], w1_t1
->GetNativeView()->GetRootWindow());
514 EXPECT_EQ("10,50 50x50",
515 w1_t1
->GetWindowBoundsInScreen().ToString());
519 // Test if the Window::ConvertPointToTarget works across root windows.
520 // TODO(oshima): Move multiple display suport and this test to aura.
521 TEST_F(ExtendedDesktopTest
, ConvertPoint
) {
522 UpdateDisplay("1000x600,600x400");
523 Shell::RootWindowList root_windows
= Shell::GetAllRootWindows();
524 gfx::Display
& display_1
=
525 GetDisplayManager()->FindDisplayForRootWindow(root_windows
[0]);
526 EXPECT_EQ("0,0", display_1
.bounds().origin().ToString());
527 gfx::Display
& display_2
=
528 GetDisplayManager()->FindDisplayForRootWindow(root_windows
[1]);
529 EXPECT_EQ("1000,0", display_2
.bounds().origin().ToString());
532 CreateTestWidget(gfx::Rect(10, 10, 100, 100))->GetNativeView();
534 CreateTestWidget(gfx::Rect(1020, 20, 100, 100))->GetNativeView();
535 EXPECT_EQ(root_windows
[0], d1
->GetRootWindow());
536 EXPECT_EQ(root_windows
[1], d2
->GetRootWindow());
538 // Convert point in the Root2's window to the Root1's window Coord.
540 aura::Window::ConvertPointToTarget(root_windows
[1], root_windows
[0], &p
);
541 EXPECT_EQ("1000,0", p
.ToString());
543 aura::Window::ConvertPointToTarget(d2
, d1
, &p
);
544 EXPECT_EQ("1010,10", p
.ToString());
546 // Convert point in the Root1's window to the Root2's window Coord.
548 aura::Window::ConvertPointToTarget(root_windows
[0], root_windows
[1], &p
);
549 EXPECT_EQ("-1000,0", p
.ToString());
551 aura::Window::ConvertPointToTarget(d1
, d2
, &p
);
552 EXPECT_EQ("-1010,-10", p
.ToString());
554 // Move the 2nd display to the bottom and test again.
555 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM
);
557 display_2
= GetDisplayManager()->FindDisplayForRootWindow(root_windows
[1]);
558 EXPECT_EQ("0,600", display_2
.bounds().origin().ToString());
560 // Convert point in Root2's window to Root1's window Coord.
562 aura::Window::ConvertPointToTarget(root_windows
[1], root_windows
[0], &p
);
563 EXPECT_EQ("0,600", p
.ToString());
565 aura::Window::ConvertPointToTarget(d2
, d1
, &p
);
566 EXPECT_EQ("10,610", p
.ToString());
568 // Convert point in Root1's window to Root2's window Coord.
570 aura::Window::ConvertPointToTarget(root_windows
[0], root_windows
[1], &p
);
571 EXPECT_EQ("0,-600", p
.ToString());
573 aura::Window::ConvertPointToTarget(d1
, d2
, &p
);
574 EXPECT_EQ("-10,-610", p
.ToString());
577 TEST_F(ExtendedDesktopTest
, OpenSystemTray
) {
578 UpdateDisplay("500x600,600x400");
579 SystemTray
* tray
= ash::Shell::GetInstance()->GetPrimarySystemTray();
580 ASSERT_FALSE(tray
->HasSystemBubble());
582 // Opens the tray by a dummy click event and makes sure that adding/removing
583 // displays doesn't break anything.
584 aura::test::EventGenerator
event_generator(
585 ash::Shell::GetInstance()->GetPrimaryRootWindow(),
586 tray
->GetWidget()->GetNativeWindow());
587 event_generator
.ClickLeftButton();
588 EXPECT_TRUE(tray
->HasSystemBubble());
590 UpdateDisplay("500x600");
591 EXPECT_TRUE(tray
->HasSystemBubble());
592 UpdateDisplay("500x600,600x400");
593 EXPECT_TRUE(tray
->HasSystemBubble());
595 // Closes the tray and again makes sure that adding/removing displays doesn't
597 event_generator
.ClickLeftButton();
598 RunAllPendingInMessageLoop();
600 EXPECT_FALSE(tray
->HasSystemBubble());
602 UpdateDisplay("500x600");
603 EXPECT_FALSE(tray
->HasSystemBubble());
604 UpdateDisplay("500x600,600x400");
605 EXPECT_FALSE(tray
->HasSystemBubble());
608 TEST_F(ExtendedDesktopTest
, StayInSameRootWindow
) {
609 UpdateDisplay("100x100,200x200");
610 Shell::RootWindowList root_windows
= Shell::GetAllRootWindows();
611 views::Widget
* w1
= CreateTestWidgetWithParent(
612 NULL
, gfx::Rect(10, 10, 50, 50), false);
613 EXPECT_EQ(root_windows
[0], w1
->GetNativeView()->GetRootWindow());
614 w1
->SetBounds(gfx::Rect(150, 10, 50, 50));
615 EXPECT_EQ(root_windows
[1], w1
->GetNativeView()->GetRootWindow());
617 // The widget stays in the same root if kStayInSameRootWindowKey is set to
619 w1
->GetNativeView()->SetProperty(internal::kStayInSameRootWindowKey
, true);
620 w1
->SetBounds(gfx::Rect(10, 10, 50, 50));
621 EXPECT_EQ(root_windows
[1], w1
->GetNativeView()->GetRootWindow());
623 // The widget should now move to the 1st root window without the property.
624 w1
->GetNativeView()->ClearProperty(internal::kStayInSameRootWindowKey
);
625 w1
->SetBounds(gfx::Rect(10, 10, 50, 50));
626 EXPECT_EQ(root_windows
[0], w1
->GetNativeView()->GetRootWindow());
629 TEST_F(ExtendedDesktopTest
, KeyEventsOnLockScreen
) {
630 UpdateDisplay("100x100,200x200");
631 Shell::RootWindowList root_windows
= Shell::GetAllRootWindows();
633 // Create normal windows on both displays.
634 views::Widget
* widget1
= CreateTestWidget(
635 Shell::GetScreen()->GetPrimaryDisplay().bounds());
637 EXPECT_EQ(root_windows
[0], widget1
->GetNativeView()->GetRootWindow());
638 views::Widget
* widget2
= CreateTestWidget(
639 ScreenAsh::GetSecondaryDisplay().bounds());
641 EXPECT_EQ(root_windows
[1], widget2
->GetNativeView()->GetRootWindow());
643 // Create a LockScreen window.
644 views::Widget
* lock_widget
= CreateTestWidget(
645 Shell::GetScreen()->GetPrimaryDisplay().bounds());
646 views::Textfield
* textfield
= new views::Textfield
;
647 lock_widget
->SetContentsView(textfield
);
649 ash::Shell::GetContainer(
650 Shell::GetPrimaryRootWindow(),
651 ash::internal::kShellWindowId_LockScreenContainer
)->
652 AddChild(lock_widget
->GetNativeView());
654 textfield
->RequestFocus();
656 aura::client::FocusClient
* focus_client
=
657 aura::client::GetFocusClient(root_windows
[0]);
658 EXPECT_EQ(lock_widget
->GetNativeView(), focus_client
->GetFocusedWindow());
660 // The lock window should get events on both root windows.
661 aura::test::EventGenerator
generator1(root_windows
[0]);
662 generator1
.PressKey(ui::VKEY_A
, 0);
663 generator1
.ReleaseKey(ui::VKEY_A
, 0);
664 EXPECT_EQ(lock_widget
->GetNativeView(), focus_client
->GetFocusedWindow());
665 EXPECT_EQ("a", UTF16ToASCII(textfield
->text()));
667 aura::test::EventGenerator
generator2(root_windows
[1]);
668 generator2
.PressKey(ui::VKEY_B
, 0);
669 generator2
.ReleaseKey(ui::VKEY_B
, 0);
670 EXPECT_EQ(lock_widget
->GetNativeView(), focus_client
->GetFocusedWindow());
671 EXPECT_EQ("ab", UTF16ToASCII(textfield
->text()));
673 // Deleting 2nd display. The lock window still should get the events.
674 UpdateDisplay("100x100");
675 generator2
.PressKey(ui::VKEY_C
, 0);
676 generator2
.ReleaseKey(ui::VKEY_C
, 0);
677 EXPECT_EQ(lock_widget
->GetNativeView(), focus_client
->GetFocusedWindow());
678 EXPECT_EQ("abc", UTF16ToASCII(textfield
->text()));
680 // Creating 2nd display again, and lock window still should get events
681 // on both root windows.
682 UpdateDisplay("100x100,200x200");
683 root_windows
= Shell::GetAllRootWindows();
684 generator1
.PressKey(ui::VKEY_D
, 0);
685 generator1
.ReleaseKey(ui::VKEY_D
, 0);
686 EXPECT_EQ(lock_widget
->GetNativeView(), focus_client
->GetFocusedWindow());
687 EXPECT_EQ("abcd", UTF16ToASCII(textfield
->text()));
689 aura::test::EventGenerator
generator22(root_windows
[1]);
690 generator22
.PressKey(ui::VKEY_E
, 0);
691 generator22
.ReleaseKey(ui::VKEY_E
, 0);
692 EXPECT_EQ(lock_widget
->GetNativeView(), focus_client
->GetFocusedWindow());
693 EXPECT_EQ("abcde", UTF16ToASCII(textfield
->text()));
696 } // namespace internal