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/wm/workspace/workspace_layout_manager.h"
9 #include "ash/display/display_layout.h"
10 #include "ash/display/display_manager.h"
11 #include "ash/root_window_controller.h"
12 #include "ash/screen_util.h"
13 #include "ash/session/session_state_delegate.h"
14 #include "ash/shelf/shelf_layout_manager.h"
15 #include "ash/shell.h"
16 #include "ash/shell_observer.h"
17 #include "ash/shell_window_ids.h"
18 #include "ash/test/ash_test_base.h"
19 #include "ash/wm/maximize_mode/workspace_backdrop_delegate.h"
20 #include "ash/wm/window_state.h"
21 #include "ash/wm/window_util.h"
22 #include "ash/wm/wm_event.h"
23 #include "ash/wm/workspace/workspace_window_resizer.h"
24 #include "base/basictypes.h"
25 #include "base/compiler_specific.h"
26 #include "ui/aura/client/aura_constants.h"
27 #include "ui/aura/test/test_windows.h"
28 #include "ui/aura/window.h"
29 #include "ui/aura/window_event_dispatcher.h"
30 #include "ui/base/ime/dummy_text_input_client.h"
31 #include "ui/base/ime/input_method.h"
32 #include "ui/base/ime/text_input_focus_manager.h"
33 #include "ui/base/ui_base_switches_util.h"
34 #include "ui/base/ui_base_types.h"
35 #include "ui/gfx/insets.h"
36 #include "ui/gfx/screen.h"
37 #include "ui/views/widget/widget.h"
38 #include "ui/views/widget/widget_delegate.h"
39 #include "ui/wm/core/window_util.h"
44 class MaximizeDelegateView
: public views::WidgetDelegateView
{
46 explicit MaximizeDelegateView(const gfx::Rect
& initial_bounds
)
47 : initial_bounds_(initial_bounds
) {
49 ~MaximizeDelegateView() override
{}
51 bool GetSavedWindowPlacement(const views::Widget
* widget
,
53 ui::WindowShowState
* show_state
) const override
{
54 *bounds
= initial_bounds_
;
55 *show_state
= ui::SHOW_STATE_MAXIMIZED
;
60 const gfx::Rect initial_bounds_
;
62 DISALLOW_COPY_AND_ASSIGN(MaximizeDelegateView
);
65 class TestShellObserver
: public ShellObserver
{
67 TestShellObserver() : call_count_(0),
68 is_fullscreen_(false) {
69 Shell::GetInstance()->AddShellObserver(this);
72 ~TestShellObserver() override
{
73 Shell::GetInstance()->RemoveShellObserver(this);
76 void OnFullscreenStateChanged(bool is_fullscreen
,
77 aura::Window
* root_window
) override
{
79 is_fullscreen_
= is_fullscreen
;
82 int call_count() const {
86 bool is_fullscreen() const {
87 return is_fullscreen_
;
94 DISALLOW_COPY_AND_ASSIGN(TestShellObserver
);
99 typedef test::AshTestBase WorkspaceLayoutManagerTest
;
101 // Verifies that a window containing a restore coordinate will be restored to
102 // to the size prior to minimize, keeping the restore rectangle in tact (if
104 TEST_F(WorkspaceLayoutManagerTest
, RestoreFromMinimizeKeepsRestore
) {
105 scoped_ptr
<aura::Window
> window(
106 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4)));
107 gfx::Rect
bounds(10, 15, 25, 35);
108 window
->SetBounds(bounds
);
110 wm::WindowState
* window_state
= wm::GetWindowState(window
.get());
112 // This will not be used for un-minimizing window.
113 window_state
->SetRestoreBoundsInScreen(gfx::Rect(0, 0, 100, 100));
114 window_state
->Minimize();
115 window_state
->Restore();
116 EXPECT_EQ("0,0 100x100", window_state
->GetRestoreBoundsInScreen().ToString());
117 EXPECT_EQ("10,15 25x35", window
.get()->bounds().ToString());
119 if (!SupportsMultipleDisplays())
122 UpdateDisplay("400x300,500x400");
123 window
->SetBoundsInScreen(gfx::Rect(600, 0, 100, 100),
124 ScreenUtil::GetSecondaryDisplay());
125 EXPECT_EQ(Shell::GetAllRootWindows()[1], window
->GetRootWindow());
126 window_state
->Minimize();
127 // This will not be used for un-minimizing window.
128 window_state
->SetRestoreBoundsInScreen(gfx::Rect(0, 0, 100, 100));
129 window_state
->Restore();
130 EXPECT_EQ("600,0 100x100", window
->GetBoundsInScreen().ToString());
132 // Make sure the unminimized window moves inside the display when
133 // 2nd display is disconnected.
134 window_state
->Minimize();
135 UpdateDisplay("400x300");
136 window_state
->Restore();
137 EXPECT_EQ(Shell::GetPrimaryRootWindow(), window
->GetRootWindow());
139 Shell::GetPrimaryRootWindow()->bounds().Intersects(window
->bounds()));
142 TEST_F(WorkspaceLayoutManagerTest
, KeepMinimumVisibilityInDisplays
) {
143 if (!SupportsMultipleDisplays())
146 UpdateDisplay("300x400,400x500");
147 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
149 DisplayLayout
layout(DisplayLayout::TOP
, 0);
150 Shell::GetInstance()->display_manager()->
151 SetLayoutForCurrentDisplays(layout
);
152 EXPECT_EQ("0,-500 400x500", root_windows
[1]->GetBoundsInScreen().ToString());
154 scoped_ptr
<aura::Window
> window1(
155 CreateTestWindowInShellWithBounds(gfx::Rect(10, -400, 200, 200)));
156 EXPECT_EQ("10,-400 200x200", window1
->GetBoundsInScreen().ToString());
158 // Make sure the caption is visible.
159 scoped_ptr
<aura::Window
> window2(
160 CreateTestWindowInShellWithBounds(gfx::Rect(10, -600, 200, 200)));
161 EXPECT_EQ("10,-500 200x200", window2
->GetBoundsInScreen().ToString());
164 TEST_F(WorkspaceLayoutManagerTest
, NoMinimumVisibilityForPopupWindows
) {
165 UpdateDisplay("300x400");
167 // Create a popup window out of display boundaries and make sure it is not
168 // moved to have minimum visibility.
169 scoped_ptr
<aura::Window
> window(
170 CreateTestWindowInShellWithDelegateAndType(NULL
,
171 ui::wm::WINDOW_TYPE_POPUP
,
173 gfx::Rect(400, 100, 50, 50)));
174 EXPECT_EQ("400,100 50x50", window
->GetBoundsInScreen().ToString());
177 TEST_F(WorkspaceLayoutManagerTest
, KeepRestoredWindowInDisplay
) {
178 if (!SupportsHostWindowResize())
180 scoped_ptr
<aura::Window
> window(
181 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40)));
182 wm::WindowState
* window_state
= wm::GetWindowState(window
.get());
184 // Maximized -> Normal transition.
185 window_state
->Maximize();
186 window_state
->SetRestoreBoundsInScreen(gfx::Rect(-100, -100, 30, 40));
187 window_state
->Restore();
189 Shell::GetPrimaryRootWindow()->bounds().Intersects(window
->bounds()));
190 // Y bounds should not be negative.
191 EXPECT_EQ("-20,0 30x40", window
->bounds().ToString());
193 // Minimized -> Normal transition.
194 window
->SetBounds(gfx::Rect(-100, -100, 30, 40));
195 window_state
->Minimize();
197 Shell::GetPrimaryRootWindow()->bounds().Intersects(window
->bounds()));
198 EXPECT_EQ("-100,-100 30x40", window
->bounds().ToString());
201 Shell::GetPrimaryRootWindow()->bounds().Intersects(window
->bounds()));
202 // Y bounds should not be negative.
203 EXPECT_EQ("-20,0 30x40", window
->bounds().ToString());
205 // Fullscreen -> Normal transition.
206 window
->SetBounds(gfx::Rect(0, 0, 30, 40)); // reset bounds.
207 ASSERT_EQ("0,0 30x40", window
->bounds().ToString());
208 window
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_FULLSCREEN
);
209 EXPECT_EQ(window
->bounds(), window
->GetRootWindow()->bounds());
210 window_state
->SetRestoreBoundsInScreen(gfx::Rect(-100, -100, 30, 40));
211 window_state
->Restore();
213 Shell::GetPrimaryRootWindow()->bounds().Intersects(window
->bounds()));
214 // Y bounds should not be negative.
215 EXPECT_EQ("-20,0 30x40", window
->bounds().ToString());
218 TEST_F(WorkspaceLayoutManagerTest
, MaximizeInDisplayToBeRestored
) {
219 if (!SupportsMultipleDisplays())
221 UpdateDisplay("300x400,400x500");
223 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
225 scoped_ptr
<aura::Window
> window(
226 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40)));
227 EXPECT_EQ(root_windows
[0], window
->GetRootWindow());
229 wm::WindowState
* window_state
= wm::GetWindowState(window
.get());
230 window_state
->SetRestoreBoundsInScreen(gfx::Rect(400, 0, 30, 40));
231 // Maximize the window in 2nd display as the restore bounds
232 // is inside 2nd display.
233 window_state
->Maximize();
234 EXPECT_EQ(root_windows
[1], window
->GetRootWindow());
235 EXPECT_EQ("300,0 400x453", window
->GetBoundsInScreen().ToString());
237 window_state
->Restore();
238 EXPECT_EQ(root_windows
[1], window
->GetRootWindow());
239 EXPECT_EQ("400,0 30x40", window
->GetBoundsInScreen().ToString());
241 // If the restore bounds intersects with the current display,
243 window_state
->SetRestoreBoundsInScreen(gfx::Rect(280, 0, 30, 40));
244 window_state
->Maximize();
245 EXPECT_EQ(root_windows
[1], window
->GetRootWindow());
246 EXPECT_EQ("300,0 400x453", window
->GetBoundsInScreen().ToString());
248 window_state
->Restore();
249 EXPECT_EQ(root_windows
[1], window
->GetRootWindow());
250 EXPECT_EQ("280,0 30x40", window
->GetBoundsInScreen().ToString());
252 // Restoring widget state.
253 scoped_ptr
<views::Widget
> w1(new views::Widget
);
254 views::Widget::InitParams params
;
255 params
.ownership
= views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET
;
256 params
.delegate
= new MaximizeDelegateView(gfx::Rect(400, 0, 30, 40));
257 params
.context
= root_windows
[0];
260 EXPECT_TRUE(w1
->IsMaximized());
261 EXPECT_EQ(root_windows
[1], w1
->GetNativeView()->GetRootWindow());
262 EXPECT_EQ("300,0 400x453", w1
->GetWindowBoundsInScreen().ToString());
264 EXPECT_EQ(root_windows
[1], w1
->GetNativeView()->GetRootWindow());
265 EXPECT_EQ("400,0 30x40", w1
->GetWindowBoundsInScreen().ToString());
268 TEST_F(WorkspaceLayoutManagerTest
, FullscreenInDisplayToBeRestored
) {
269 if (!SupportsMultipleDisplays())
271 UpdateDisplay("300x400,400x500");
273 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
275 scoped_ptr
<aura::Window
> window(
276 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40)));
277 EXPECT_EQ(root_windows
[0], window
->GetRootWindow());
279 wm::WindowState
* window_state
= wm::GetWindowState(window
.get());
280 window_state
->SetRestoreBoundsInScreen(gfx::Rect(400, 0, 30, 40));
281 // Maximize the window in 2nd display as the restore bounds
282 // is inside 2nd display.
283 window
->SetProperty(aura::client::kShowStateKey
,
284 ui::SHOW_STATE_FULLSCREEN
);
285 EXPECT_EQ(root_windows
[1], window
->GetRootWindow());
286 EXPECT_EQ("300,0 400x500", window
->GetBoundsInScreen().ToString());
288 window_state
->Restore();
289 EXPECT_EQ(root_windows
[1], window
->GetRootWindow());
290 EXPECT_EQ("400,0 30x40", window
->GetBoundsInScreen().ToString());
292 // If the restore bounds intersects with the current display,
294 window_state
->SetRestoreBoundsInScreen(gfx::Rect(280, 0, 30, 40));
295 window
->SetProperty(aura::client::kShowStateKey
,
296 ui::SHOW_STATE_FULLSCREEN
);
297 EXPECT_EQ(root_windows
[1], window
->GetRootWindow());
298 EXPECT_EQ("300,0 400x500", window
->GetBoundsInScreen().ToString());
300 window_state
->Restore();
301 EXPECT_EQ(root_windows
[1], window
->GetRootWindow());
302 EXPECT_EQ("280,0 30x40", window
->GetBoundsInScreen().ToString());
305 // WindowObserver implementation used by DontClobberRestoreBoundsWindowObserver.
306 // This code mirrors what BrowserFrameAsh does. In particular when this code
307 // sees the window was maximized it changes the bounds of a secondary
308 // window. The secondary window mirrors the status window.
309 class DontClobberRestoreBoundsWindowObserver
: public aura::WindowObserver
{
311 DontClobberRestoreBoundsWindowObserver() : window_(NULL
) {}
313 void set_window(aura::Window
* window
) { window_
= window
; }
315 void OnWindowPropertyChanged(aura::Window
* window
,
317 intptr_t old
) override
{
321 if (wm::GetWindowState(window
)->IsMaximized()) {
322 aura::Window
* w
= window_
;
325 gfx::Rect
shelf_bounds(Shell::GetPrimaryRootWindowController()->
326 GetShelfLayoutManager()->GetIdealBounds());
327 const gfx::Rect
& window_bounds(w
->bounds());
328 w
->SetBounds(gfx::Rect(window_bounds
.x(), shelf_bounds
.y() - 1,
329 window_bounds
.width(), window_bounds
.height()));
334 aura::Window
* window_
;
336 DISALLOW_COPY_AND_ASSIGN(DontClobberRestoreBoundsWindowObserver
);
339 // Creates a window, maximized the window and from within the maximized
340 // notification sets the bounds of a window to overlap the shelf. Verifies this
341 // doesn't effect the restore bounds.
342 TEST_F(WorkspaceLayoutManagerTest
, DontClobberRestoreBounds
) {
343 DontClobberRestoreBoundsWindowObserver window_observer
;
344 scoped_ptr
<aura::Window
> window(new aura::Window(NULL
));
345 window
->SetType(ui::wm::WINDOW_TYPE_NORMAL
);
346 window
->Init(aura::WINDOW_LAYER_TEXTURED
);
347 window
->SetBounds(gfx::Rect(10, 20, 30, 40));
348 // NOTE: for this test to exercise the failure the observer needs to be added
349 // before the parent set. This mimics what BrowserFrameAsh does.
350 window
->AddObserver(&window_observer
);
351 ParentWindowInPrimaryRootWindow(window
.get());
354 wm::WindowState
* window_state
= wm::GetWindowState(window
.get());
355 window_state
->Activate();
357 scoped_ptr
<aura::Window
> window2(
358 CreateTestWindowInShellWithBounds(gfx::Rect(12, 20, 30, 40)));
359 ::wm::AddTransientChild(window
.get(), window2
.get());
362 window_observer
.set_window(window2
.get());
363 window_state
->Maximize();
364 EXPECT_EQ("10,20 30x40",
365 window_state
->GetRestoreBoundsInScreen().ToString());
366 window
->RemoveObserver(&window_observer
);
369 // Verifies when a window is maximized all descendant windows have a size.
370 TEST_F(WorkspaceLayoutManagerTest
, ChildBoundsResetOnMaximize
) {
371 scoped_ptr
<aura::Window
> window(
372 CreateTestWindowInShellWithBounds(gfx::Rect(10, 20, 30, 40)));
374 wm::WindowState
* window_state
= wm::GetWindowState(window
.get());
375 window_state
->Activate();
376 scoped_ptr
<aura::Window
> child_window(
377 aura::test::CreateTestWindowWithBounds(gfx::Rect(5, 6, 7, 8),
379 child_window
->Show();
380 window_state
->Maximize();
381 EXPECT_EQ("5,6 7x8", child_window
->bounds().ToString());
384 // Verifies a window created with maximized state has the maximized
386 TEST_F(WorkspaceLayoutManagerTest
, MaximizeWithEmptySize
) {
387 scoped_ptr
<aura::Window
> window(
388 aura::test::CreateTestWindowWithBounds(gfx::Rect(0, 0, 0, 0),
390 wm::GetWindowState(window
.get())->Maximize();
391 aura::Window
* default_container
= Shell::GetContainer(
392 Shell::GetPrimaryRootWindow(), kShellWindowId_DefaultContainer
);
393 default_container
->AddChild(window
.get());
396 Shell::GetScreen()->GetPrimaryDisplay().work_area());
397 EXPECT_EQ(work_area
.ToString(), window
->GetBoundsInScreen().ToString());
400 TEST_F(WorkspaceLayoutManagerTest
, WindowShouldBeOnScreenWhenAdded
) {
401 // Normal window bounds shouldn't be changed.
402 gfx::Rect
window_bounds(100, 100, 200, 200);
403 scoped_ptr
<aura::Window
> window(
404 CreateTestWindowInShellWithBounds(window_bounds
));
405 EXPECT_EQ(window_bounds
, window
->bounds());
407 // If the window is out of the workspace, it would be moved on screen.
408 gfx::Rect root_window_bounds
=
409 Shell::GetInstance()->GetPrimaryRootWindow()->bounds();
410 window_bounds
.Offset(root_window_bounds
.width(), root_window_bounds
.height());
411 ASSERT_FALSE(window_bounds
.Intersects(root_window_bounds
));
412 scoped_ptr
<aura::Window
> out_window(
413 CreateTestWindowInShellWithBounds(window_bounds
));
414 EXPECT_EQ(window_bounds
.size(), out_window
->bounds().size());
415 gfx::Rect bounds
= out_window
->bounds();
416 bounds
.Intersect(root_window_bounds
);
418 // 30% of the window edge must be visible.
419 EXPECT_GT(bounds
.width(), out_window
->bounds().width() * 0.29);
420 EXPECT_GT(bounds
.height(), out_window
->bounds().height() * 0.29);
422 aura::Window
* parent
= out_window
->parent();
423 parent
->RemoveChild(out_window
.get());
424 out_window
->SetBounds(gfx::Rect(-200, -200, 200, 200));
425 // UserHasChangedWindowPositionOrSize flag shouldn't turn off this behavior.
426 wm::GetWindowState(window
.get())->set_bounds_changed_by_user(true);
427 parent
->AddChild(out_window
.get());
428 EXPECT_GT(bounds
.width(), out_window
->bounds().width() * 0.29);
429 EXPECT_GT(bounds
.height(), out_window
->bounds().height() * 0.29);
431 // Make sure we always make more than 1/3 of the window edge visible even
432 // if the initial bounds intersects with display.
433 window_bounds
.SetRect(-150, -150, 200, 200);
434 bounds
= window_bounds
;
435 bounds
.Intersect(root_window_bounds
);
437 // Make sure that the initial bounds' visible area is less than 26%
438 // so that the auto adjustment logic kicks in.
439 ASSERT_LT(bounds
.width(), out_window
->bounds().width() * 0.26);
440 ASSERT_LT(bounds
.height(), out_window
->bounds().height() * 0.26);
441 ASSERT_TRUE(window_bounds
.Intersects(root_window_bounds
));
443 scoped_ptr
<aura::Window
> partially_out_window(
444 CreateTestWindowInShellWithBounds(window_bounds
));
445 EXPECT_EQ(window_bounds
.size(), partially_out_window
->bounds().size());
446 bounds
= partially_out_window
->bounds();
447 bounds
.Intersect(root_window_bounds
);
448 EXPECT_GT(bounds
.width(), out_window
->bounds().width() * 0.29);
449 EXPECT_GT(bounds
.height(), out_window
->bounds().height() * 0.29);
451 // Make sure the window whose 30% width/height is bigger than display
452 // will be placed correctly.
453 window_bounds
.SetRect(-1900, -1900, 3000, 3000);
454 scoped_ptr
<aura::Window
> window_bigger_than_display(
455 CreateTestWindowInShellWithBounds(window_bounds
));
456 EXPECT_GE(root_window_bounds
.width(),
457 window_bigger_than_display
->bounds().width());
458 EXPECT_GE(root_window_bounds
.height(),
459 window_bigger_than_display
->bounds().height());
461 bounds
= window_bigger_than_display
->bounds();
462 bounds
.Intersect(root_window_bounds
);
463 EXPECT_GT(bounds
.width(), out_window
->bounds().width() * 0.29);
464 EXPECT_GT(bounds
.height(), out_window
->bounds().height() * 0.29);
467 // Verifies the size of a window is enforced to be smaller than the work area.
468 TEST_F(WorkspaceLayoutManagerTest
, SizeToWorkArea
) {
469 // Normal window bounds shouldn't be changed.
471 Shell::GetScreen()->GetPrimaryDisplay().work_area().size());
472 const gfx::Rect
window_bounds(
473 100, 101, work_area
.width() + 1, work_area
.height() + 2);
474 scoped_ptr
<aura::Window
> window(
475 CreateTestWindowInShellWithBounds(window_bounds
));
476 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area
).ToString(),
477 window
->bounds().ToString());
479 // Directly setting the bounds triggers a slightly different code path. Verify
481 window
->SetBounds(window_bounds
);
482 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area
).ToString(),
483 window
->bounds().ToString());
486 TEST_F(WorkspaceLayoutManagerTest
, NotifyFullscreenChanges
) {
487 TestShellObserver observer
;
488 scoped_ptr
<aura::Window
> window1(
489 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40)));
490 scoped_ptr
<aura::Window
> window2(
491 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40)));
492 wm::WindowState
* window_state1
= wm::GetWindowState(window1
.get());
493 wm::WindowState
* window_state2
= wm::GetWindowState(window2
.get());
494 window_state2
->Activate();
496 const wm::WMEvent
toggle_fullscreen_event(wm::WM_EVENT_TOGGLE_FULLSCREEN
);
497 window_state2
->OnWMEvent(&toggle_fullscreen_event
);
498 EXPECT_EQ(1, observer
.call_count());
499 EXPECT_TRUE(observer
.is_fullscreen());
501 // When window1 moves to the front the fullscreen state should change.
502 window_state1
->Activate();
503 EXPECT_EQ(2, observer
.call_count());
504 EXPECT_FALSE(observer
.is_fullscreen());
506 // It should change back if window2 becomes active again.
507 window_state2
->Activate();
508 EXPECT_EQ(3, observer
.call_count());
509 EXPECT_TRUE(observer
.is_fullscreen());
511 window_state2
->OnWMEvent(&toggle_fullscreen_event
);
512 EXPECT_EQ(4, observer
.call_count());
513 EXPECT_FALSE(observer
.is_fullscreen());
515 window_state2
->OnWMEvent(&toggle_fullscreen_event
);
516 EXPECT_EQ(5, observer
.call_count());
517 EXPECT_TRUE(observer
.is_fullscreen());
519 // Closing the window should change the fullscreen state.
521 EXPECT_EQ(6, observer
.call_count());
522 EXPECT_FALSE(observer
.is_fullscreen());
525 // Following "Solo" tests were originally written for BaseLayoutManager.
528 class WorkspaceLayoutManagerSoloTest
: public test::AshTestBase
{
530 WorkspaceLayoutManagerSoloTest() {}
531 ~WorkspaceLayoutManagerSoloTest() override
{}
533 aura::Window
* CreateTestWindow(const gfx::Rect
& bounds
) {
534 return CreateTestWindowInShellWithBounds(bounds
);
538 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerSoloTest
);
543 // Tests normal->maximize->normal.
544 TEST_F(WorkspaceLayoutManagerSoloTest
, Maximize
) {
545 gfx::Rect
bounds(100, 100, 200, 200);
546 scoped_ptr
<aura::Window
> window(CreateTestWindow(bounds
));
547 window
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
548 // Maximized window fills the work area, not the whole display.
550 ScreenUtil::GetMaximizedWindowBoundsInParent(window
.get()).ToString(),
551 window
->bounds().ToString());
552 window
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_NORMAL
);
553 EXPECT_EQ(bounds
.ToString(), window
->bounds().ToString());
556 // Tests normal->minimize->normal.
557 TEST_F(WorkspaceLayoutManagerSoloTest
, Minimize
) {
558 gfx::Rect
bounds(100, 100, 200, 200);
559 scoped_ptr
<aura::Window
> window(CreateTestWindow(bounds
));
560 window
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MINIMIZED
);
561 // Note: Currently minimize doesn't do anything except set the state.
562 // See crbug.com/104571.
563 EXPECT_EQ(bounds
.ToString(), window
->bounds().ToString());
564 window
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_NORMAL
);
565 EXPECT_EQ(bounds
.ToString(), window
->bounds().ToString());
568 // A WindowDelegate which sets the focus when the window
570 class FocusDelegate
: public aura::test::TestWindowDelegate
{
574 show_state_(ui::SHOW_STATE_END
) {
576 ~FocusDelegate() override
{}
578 void set_window(aura::Window
* window
) { window_
= window
; }
580 // aura::test::TestWindowDelegate overrides:
581 void OnWindowTargetVisibilityChanged(bool visible
) override
{
585 show_state_
= window_
->GetProperty(aura::client::kShowStateKey
);
589 ui::WindowShowState
GetShowStateAndReset() {
590 ui::WindowShowState ret
= show_state_
;
591 show_state_
= ui::SHOW_STATE_END
;
596 aura::Window
* window_
;
597 ui::WindowShowState show_state_
;
599 DISALLOW_COPY_AND_ASSIGN(FocusDelegate
);
602 // Make sure that the window's show state is correct in
603 // |WindowDelegate::OnWindowTargetVisibilityChanged|, and setting
604 // focus in this callback doesn't cause DCHECK error. See
606 TEST_F(WorkspaceLayoutManagerSoloTest
, FocusDuringUnminimize
) {
607 FocusDelegate delegate
;
608 scoped_ptr
<aura::Window
> window(CreateTestWindowInShellWithDelegate(
609 &delegate
, 0, gfx::Rect(100, 100, 100, 100)));
610 delegate
.set_window(window
.get());
611 window
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MINIMIZED
);
612 EXPECT_FALSE(window
->IsVisible());
613 EXPECT_EQ(ui::SHOW_STATE_MINIMIZED
, delegate
.GetShowStateAndReset());
615 EXPECT_TRUE(window
->IsVisible());
616 EXPECT_EQ(ui::SHOW_STATE_NORMAL
, delegate
.GetShowStateAndReset());
619 // Tests maximized window size during root window resize.
620 TEST_F(WorkspaceLayoutManagerSoloTest
, MaximizeRootWindowResize
) {
621 gfx::Rect
bounds(100, 100, 200, 200);
622 scoped_ptr
<aura::Window
> window(CreateTestWindow(bounds
));
623 window
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
624 gfx::Rect initial_work_area_bounds
=
625 ScreenUtil::GetMaximizedWindowBoundsInParent(window
.get());
626 EXPECT_EQ(initial_work_area_bounds
.ToString(), window
->bounds().ToString());
627 // Enlarge the root window. We should still match the work area size.
628 UpdateDisplay("900x700");
630 ScreenUtil::GetMaximizedWindowBoundsInParent(window
.get()).ToString(),
631 window
->bounds().ToString());
633 initial_work_area_bounds
.ToString(),
634 ScreenUtil::GetMaximizedWindowBoundsInParent(window
.get()).ToString());
637 // Tests normal->fullscreen->normal.
638 TEST_F(WorkspaceLayoutManagerSoloTest
, Fullscreen
) {
639 gfx::Rect
bounds(100, 100, 200, 200);
640 scoped_ptr
<aura::Window
> window(CreateTestWindow(bounds
));
641 window
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_FULLSCREEN
);
642 // Fullscreen window fills the whole display.
643 EXPECT_EQ(Shell::GetScreen()->GetDisplayNearestWindow(
644 window
.get()).bounds().ToString(),
645 window
->bounds().ToString());
646 window
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_NORMAL
);
647 EXPECT_EQ(bounds
.ToString(), window
->bounds().ToString());
650 // Tests fullscreen window size during root window resize.
651 TEST_F(WorkspaceLayoutManagerSoloTest
, FullscreenRootWindowResize
) {
652 gfx::Rect
bounds(100, 100, 200, 200);
653 scoped_ptr
<aura::Window
> window(CreateTestWindow(bounds
));
654 // Fullscreen window fills the whole display.
655 window
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_FULLSCREEN
);
656 EXPECT_EQ(Shell::GetScreen()->GetDisplayNearestWindow(
657 window
.get()).bounds().ToString(),
658 window
->bounds().ToString());
659 // Enlarge the root window. We should still match the display size.
660 UpdateDisplay("800x600");
661 EXPECT_EQ(Shell::GetScreen()->GetDisplayNearestWindow(
662 window
.get()).bounds().ToString(),
663 window
->bounds().ToString());
666 // Tests that when the screen gets smaller the windows aren't bigger than
668 TEST_F(WorkspaceLayoutManagerSoloTest
, RootWindowResizeShrinksWindows
) {
669 scoped_ptr
<aura::Window
> window(
670 CreateTestWindow(gfx::Rect(10, 20, 500, 400)));
671 gfx::Rect work_area
= Shell::GetScreen()->GetDisplayNearestWindow(
672 window
.get()).work_area();
673 // Invariant: Window is smaller than work area.
674 EXPECT_LE(window
->bounds().width(), work_area
.width());
675 EXPECT_LE(window
->bounds().height(), work_area
.height());
677 // Make the root window narrower than our window.
678 UpdateDisplay("300x400");
679 work_area
= Shell::GetScreen()->GetDisplayNearestWindow(
680 window
.get()).work_area();
681 EXPECT_LE(window
->bounds().width(), work_area
.width());
682 EXPECT_LE(window
->bounds().height(), work_area
.height());
684 // Make the root window shorter than our window.
685 UpdateDisplay("300x200");
686 work_area
= Shell::GetScreen()->GetDisplayNearestWindow(
687 window
.get()).work_area();
688 EXPECT_LE(window
->bounds().width(), work_area
.width());
689 EXPECT_LE(window
->bounds().height(), work_area
.height());
691 // Enlarging the root window does not change the window bounds.
692 gfx::Rect old_bounds
= window
->bounds();
693 UpdateDisplay("800x600");
694 EXPECT_EQ(old_bounds
.width(), window
->bounds().width());
695 EXPECT_EQ(old_bounds
.height(), window
->bounds().height());
698 // Verifies maximizing sets the restore bounds, and restoring
699 // restores the bounds.
700 TEST_F(WorkspaceLayoutManagerSoloTest
, MaximizeSetsRestoreBounds
) {
701 scoped_ptr
<aura::Window
> window(CreateTestWindow(gfx::Rect(10, 20, 30, 40)));
702 wm::WindowState
* window_state
= wm::GetWindowState(window
.get());
704 // Maximize it, which will keep the previous restore bounds.
705 window
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
706 EXPECT_EQ("10,20 30x40", window_state
->GetRestoreBoundsInParent().ToString());
708 // Restore it, which should restore bounds and reset restore bounds.
709 window
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_NORMAL
);
710 EXPECT_EQ("10,20 30x40", window
->bounds().ToString());
711 EXPECT_FALSE(window_state
->HasRestoreBounds());
714 // Verifies maximizing keeps the restore bounds if set.
715 TEST_F(WorkspaceLayoutManagerSoloTest
, MaximizeResetsRestoreBounds
) {
716 scoped_ptr
<aura::Window
> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4)));
718 wm::WindowState
* window_state
= wm::GetWindowState(window
.get());
719 window_state
->SetRestoreBoundsInParent(gfx::Rect(10, 11, 12, 13));
721 // Maximize it, which will keep the previous restore bounds.
722 window
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
723 EXPECT_EQ("10,11 12x13", window_state
->GetRestoreBoundsInParent().ToString());
726 // Verifies that the restore bounds do not get reset when restoring to a
727 // maximzied state from a minimized state.
728 TEST_F(WorkspaceLayoutManagerSoloTest
,
729 BoundsAfterRestoringToMaximizeFromMinimize
) {
730 scoped_ptr
<aura::Window
> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4)));
731 gfx::Rect
bounds(10, 15, 25, 35);
732 window
->SetBounds(bounds
);
734 wm::WindowState
* window_state
= wm::GetWindowState(window
.get());
735 // Maximize it, which should reset restore bounds.
736 window_state
->Maximize();
737 EXPECT_EQ(bounds
.ToString(),
738 window_state
->GetRestoreBoundsInParent().ToString());
739 // Minimize the window. The restore bounds should not change.
740 window_state
->Minimize();
741 EXPECT_EQ(bounds
.ToString(),
742 window_state
->GetRestoreBoundsInParent().ToString());
744 // Show the window again. The window should be maximized, and the restore
745 // bounds should not change.
747 EXPECT_EQ(bounds
.ToString(),
748 window_state
->GetRestoreBoundsInParent().ToString());
749 EXPECT_TRUE(window_state
->IsMaximized());
751 window_state
->Restore();
752 EXPECT_EQ(bounds
.ToString(), window
->bounds().ToString());
755 // Verify if the window is not resized during screen lock. See: crbug.com/173127
756 TEST_F(WorkspaceLayoutManagerSoloTest
, NotResizeWhenScreenIsLocked
) {
757 SetCanLockScreen(true);
758 scoped_ptr
<aura::Window
> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4)));
759 // window with AlwaysOnTop will be managed by BaseLayoutManager.
760 window
->SetProperty(aura::client::kAlwaysOnTopKey
, true);
763 ShelfLayoutManager
* shelf
= ShelfLayoutManager::ForShelf(window
.get());
764 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
766 window
->SetBounds(ScreenUtil::GetMaximizedWindowBoundsInParent(window
.get()));
767 gfx::Rect window_bounds
= window
->bounds();
769 ScreenUtil::GetMaximizedWindowBoundsInParent(window
.get()).ToString(),
770 window_bounds
.ToString());
772 Shell::GetInstance()->session_state_delegate()->LockScreen();
773 shelf
->UpdateVisibilityState();
775 ScreenUtil::GetMaximizedWindowBoundsInParent(window
.get()).ToString(),
776 window_bounds
.ToString());
778 Shell::GetInstance()->session_state_delegate()->UnlockScreen();
779 shelf
->UpdateVisibilityState();
780 EXPECT_EQ(window_bounds
.ToString(), window
->bounds().ToString());
783 // Following tests are written to test the backdrop functionality.
787 class WorkspaceLayoutManagerBackdropTest
: public test::AshTestBase
{
789 WorkspaceLayoutManagerBackdropTest() {}
790 ~WorkspaceLayoutManagerBackdropTest() override
{}
792 void SetUp() override
{
793 test::AshTestBase::SetUp();
794 UpdateDisplay("800x600");
795 default_container_
= Shell::GetContainer(Shell::GetPrimaryRootWindow(),
796 kShellWindowId_DefaultContainer
);
799 aura::Window
* CreateTestWindow(const gfx::Rect
& bounds
) {
800 aura::Window
* window
= CreateTestWindowInShellWithBounds(bounds
);
804 // Turn the top window back drop on / off.
805 void ShowTopWindowBackdrop(bool show
) {
806 scoped_ptr
<ash::WorkspaceLayoutManagerDelegate
> backdrop
;
808 backdrop
.reset(new ash::WorkspaceBackdropDelegate(default_container_
));
810 (static_cast<WorkspaceLayoutManager
*>(default_container_
->layout_manager()))
811 ->SetMaximizeBackdropDelegate(backdrop
.Pass());
812 // Closing and / or opening can be a delayed operation.
813 base::MessageLoop::current()->RunUntilIdle();
816 // Return the default container.
817 aura::Window
* default_container() { return default_container_
; }
819 // Return the order of windows (top most first) as they are in the default
820 // container. If the window is visible it will be a big letter, otherwise a
821 // small one. The backdrop will be an X and unknown windows will be shown as
823 std::string
GetWindowOrderAsString(aura::Window
* backdrop
,
828 for (int i
= static_cast<int>(default_container()->children().size()) - 1;
833 if (default_container()->children()[i
] == wa
)
834 result
+= default_container()->children()[i
]->IsVisible() ? "A" : "a";
835 else if (default_container()->children()[i
] == wb
)
836 result
+= default_container()->children()[i
]->IsVisible() ? "B" : "b";
837 else if (default_container()->children()[i
] == wc
)
838 result
+= default_container()->children()[i
]->IsVisible() ? "C" : "c";
839 else if (default_container()->children()[i
] == backdrop
)
840 result
+= default_container()->children()[i
]->IsVisible() ? "X" : "x";
848 // The default container.
849 aura::Window
* default_container_
;
851 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerBackdropTest
);
856 // Check that creating the BackDrop without destroying it does not lead into
858 TEST_F(WorkspaceLayoutManagerBackdropTest
, BackdropCrashTest
) {
859 ShowTopWindowBackdrop(true);
862 // Verify basic assumptions about the backdrop.
863 TEST_F(WorkspaceLayoutManagerBackdropTest
, BasicBackdropTests
) {
864 // Create a backdrop and see that there is one window (the backdrop) and
865 // that the size is the same as the default container as well as that it is
867 ShowTopWindowBackdrop(true);
868 ASSERT_EQ(1U, default_container()->children().size());
869 EXPECT_FALSE(default_container()->children()[0]->IsVisible());
872 // Add a window and make sure that the backdrop is the second child.
873 scoped_ptr
<aura::Window
> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4)));
875 ASSERT_EQ(2U, default_container()->children().size());
876 EXPECT_TRUE(default_container()->children()[0]->IsVisible());
877 EXPECT_TRUE(default_container()->children()[1]->IsVisible());
878 EXPECT_EQ(window
.get(), default_container()->children()[1]);
879 EXPECT_EQ(default_container()->bounds().ToString(),
880 default_container()->children()[0]->bounds().ToString());
883 // With the window gone the backdrop should be invisible again.
884 ASSERT_EQ(1U, default_container()->children().size());
885 EXPECT_FALSE(default_container()->children()[0]->IsVisible());
887 // Destroying the Backdrop should empty the container.
888 ShowTopWindowBackdrop(false);
889 ASSERT_EQ(0U, default_container()->children().size());
892 // Verify that the backdrop gets properly created and placed.
893 TEST_F(WorkspaceLayoutManagerBackdropTest
, VerifyBackdropAndItsStacking
) {
894 scoped_ptr
<aura::Window
> window1(CreateTestWindow(gfx::Rect(1, 2, 3, 4)));
897 // Get the default container and check that only a single window is in there.
898 ASSERT_EQ(1U, default_container()->children().size());
899 EXPECT_EQ(window1
.get(), default_container()->children()[0]);
900 EXPECT_EQ("A", GetWindowOrderAsString(NULL
, window1
.get(), NULL
, NULL
));
902 // Create 2 more windows and check that they are also in the container.
903 scoped_ptr
<aura::Window
> window2(CreateTestWindow(gfx::Rect(10, 2, 3, 4)));
904 scoped_ptr
<aura::Window
> window3(CreateTestWindow(gfx::Rect(20, 2, 3, 4)));
908 aura::Window
* backdrop
= NULL
;
910 GetWindowOrderAsString(backdrop
, window1
.get(), window2
.get(),
913 // Turn on the backdrop mode and check that the window shows up where it
914 // should be (second highest number).
915 ShowTopWindowBackdrop(true);
916 backdrop
= default_container()->children()[2];
918 GetWindowOrderAsString(backdrop
, window1
.get(), window2
.get(),
921 // Switch the order of windows and check that it still remains in that
923 default_container()->StackChildAtTop(window2
.get());
925 GetWindowOrderAsString(backdrop
, window1
.get(), window2
.get(),
928 // Make the top window invisible and check.
929 window2
.get()->Hide();
931 GetWindowOrderAsString(backdrop
, window1
.get(), window2
.get(),
933 // Then delete window after window and see that everything is in order.
936 GetWindowOrderAsString(backdrop
, window1
.get(), window2
.get(),
940 GetWindowOrderAsString(backdrop
, window1
.get(), window2
.get(),
942 ShowTopWindowBackdrop(false);
944 GetWindowOrderAsString(NULL
, window1
.get(), window2
.get(),
948 // Tests that when hidding the shelf, that the backdrop resizes to fill the
949 // entire workspace area.
950 TEST_F(WorkspaceLayoutManagerBackdropTest
, ShelfVisibilityChangesBounds
) {
951 ShelfLayoutManager
* shelf_layout_manager
=
952 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
953 ShowTopWindowBackdrop(true);
954 RunAllPendingInMessageLoop();
956 ASSERT_EQ(SHELF_VISIBLE
, shelf_layout_manager
->visibility_state());
957 gfx::Rect initial_bounds
= default_container()->children()[0]->bounds();
958 shelf_layout_manager
->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN
);
959 shelf_layout_manager
->UpdateVisibilityState();
961 // When the shelf is re-shown WorkspaceLayoutManager shrinks all children
962 // including the backdrop.
963 shelf_layout_manager
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
964 shelf_layout_manager
->UpdateVisibilityState();
965 gfx::Rect reduced_bounds
= default_container()->children()[0]->bounds();
966 EXPECT_LT(reduced_bounds
.height(), initial_bounds
.height());
968 shelf_layout_manager
->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN
);
969 shelf_layout_manager
->UpdateVisibilityState();
971 EXPECT_GT(default_container()->children()[0]->bounds().height(),
972 reduced_bounds
.height());
975 class WorkspaceLayoutManagerKeyboardTest
: public test::AshTestBase
{
977 WorkspaceLayoutManagerKeyboardTest() {}
978 ~WorkspaceLayoutManagerKeyboardTest() override
{}
980 void SetUp() override
{
981 test::AshTestBase::SetUp();
982 UpdateDisplay("800x600");
983 aura::Window
* default_container
= Shell::GetContainer(
984 Shell::GetPrimaryRootWindow(), kShellWindowId_DefaultContainer
);
985 layout_manager_
= static_cast<WorkspaceLayoutManager
*>(
986 default_container
->layout_manager());
989 aura::Window
* CreateTestWindow(const gfx::Rect
& bounds
) {
990 return CreateTestWindowInShellWithBounds(bounds
);
993 void ShowKeyboard() {
994 layout_manager_
->OnKeyboardBoundsChanging(keyboard_bounds_
);
995 restore_work_area_insets_
= Shell::GetScreen()->GetPrimaryDisplay().
997 Shell::GetInstance()->SetDisplayWorkAreaInsets(
998 Shell::GetPrimaryRootWindow(),
999 gfx::Insets(0, 0, keyboard_bounds_
.height(), 0));
1002 void HideKeyboard() {
1003 Shell::GetInstance()->SetDisplayWorkAreaInsets(
1004 Shell::GetPrimaryRootWindow(),
1005 restore_work_area_insets_
);
1006 layout_manager_
->OnKeyboardBoundsChanging(gfx::Rect());
1009 void SetKeyboardBounds(const gfx::Rect
& bounds
) {
1010 keyboard_bounds_
= bounds
;
1013 void Focus(ui::TextInputClient
* text_input_client
) {
1014 if (switches::IsTextInputFocusManagerEnabled()) {
1015 ui::TextInputFocusManager::GetInstance()->FocusTextInputClient(
1018 aura::Window
* root_window
=
1019 ash::Shell::GetInstance()->GetPrimaryRootWindow();
1020 ui::InputMethod
* input_method
=
1021 root_window
->GetProperty(aura::client::kRootWindowInputMethodKey
);
1022 input_method
->SetFocusedTextInputClient(text_input_client
);
1026 void Blur(ui::TextInputClient
* text_input_client
) {
1027 if (switches::IsTextInputFocusManagerEnabled()) {
1028 ui::TextInputFocusManager::GetInstance()->BlurTextInputClient(
1031 aura::Window
* root_window
=
1032 ash::Shell::GetInstance()->GetPrimaryRootWindow();
1033 ui::InputMethod
* input_method
=
1034 root_window
->GetProperty(aura::client::kRootWindowInputMethodKey
);
1035 input_method
->SetFocusedTextInputClient(NULL
);
1040 gfx::Insets restore_work_area_insets_
;
1041 gfx::Rect keyboard_bounds_
;
1042 WorkspaceLayoutManager
* layout_manager_
;
1044 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerKeyboardTest
);
1047 class FakeTextInputClient
: public ui::DummyTextInputClient
{
1049 explicit FakeTextInputClient(gfx::NativeWindow window
) : window_(window
) {}
1050 ~FakeTextInputClient() override
{}
1052 gfx::NativeWindow
GetAttachedWindow() const override
{ return window_
; }
1055 gfx::NativeWindow window_
;
1057 DISALLOW_COPY_AND_ASSIGN(FakeTextInputClient
);
1060 // Tests that when a child window gains focus the top level window containing it
1061 // is resized to fit the remaining workspace area.
1062 TEST_F(WorkspaceLayoutManagerKeyboardTest
, ChildWindowFocused
) {
1063 gfx::Rect
work_area(
1064 Shell::GetScreen()->GetPrimaryDisplay().work_area());
1065 gfx::Rect
keyboard_bounds(work_area
.x(),
1066 work_area
.y() + work_area
.height() / 2,
1068 work_area
.height() / 2);
1070 SetKeyboardBounds(keyboard_bounds
);
1072 aura::test::TestWindowDelegate delegate1
;
1073 scoped_ptr
<aura::Window
> parent_window(CreateTestWindowInShellWithDelegate(
1074 &delegate1
, -1, work_area
));
1075 aura::test::TestWindowDelegate delegate2
;
1076 scoped_ptr
<aura::Window
> window(CreateTestWindowInShellWithDelegate(
1077 &delegate2
, -1, work_area
));
1078 parent_window
->AddChild(window
.get());
1080 FakeTextInputClient
text_input_client(window
.get());
1081 Focus(&text_input_client
);
1083 int available_height
=
1084 Shell::GetScreen()->GetPrimaryDisplay().bounds().height() -
1085 keyboard_bounds
.height();
1087 gfx::Rect
initial_window_bounds(50, 50, 100, 500);
1088 parent_window
->SetBounds(initial_window_bounds
);
1089 EXPECT_EQ(initial_window_bounds
.ToString(),
1090 parent_window
->bounds().ToString());
1092 EXPECT_EQ(gfx::Rect(50, 0, 100, available_height
).ToString(),
1093 parent_window
->bounds().ToString());
1095 EXPECT_EQ(initial_window_bounds
.ToString(),
1096 parent_window
->bounds().ToString());
1098 Blur(&text_input_client
);
1101 TEST_F(WorkspaceLayoutManagerKeyboardTest
, AdjustWindowForA11yKeyboard
) {
1102 gfx::Rect
work_area(
1103 Shell::GetScreen()->GetPrimaryDisplay().work_area());
1104 gfx::Rect
keyboard_bounds(work_area
.x(),
1105 work_area
.y() + work_area
.height() / 2,
1107 work_area
.height() / 2);
1109 SetKeyboardBounds(keyboard_bounds
);
1111 aura::test::TestWindowDelegate delegate
;
1112 scoped_ptr
<aura::Window
> window(CreateTestWindowInShellWithDelegate(
1113 &delegate
, -1, work_area
));
1115 FakeTextInputClient
text_input_client(window
.get());
1116 Focus(&text_input_client
);
1118 int available_height
=
1119 Shell::GetScreen()->GetPrimaryDisplay().bounds().height() -
1120 keyboard_bounds
.height();
1122 EXPECT_EQ(gfx::Rect(work_area
).ToString(), window
->bounds().ToString());
1124 EXPECT_EQ(gfx::Rect(work_area
.origin(),
1125 gfx::Size(work_area
.width(), available_height
)).ToString(),
1126 window
->bounds().ToString());
1128 EXPECT_EQ(gfx::Rect(work_area
).ToString(), window
->bounds().ToString());
1130 gfx::Rect
small_window_bound(50, 50, 100, 500);
1131 window
->SetBounds(small_window_bound
);
1132 EXPECT_EQ(small_window_bound
.ToString(), window
->bounds().ToString());
1134 EXPECT_EQ(gfx::Rect(50, 0, 100, available_height
).ToString(),
1135 window
->bounds().ToString());
1137 EXPECT_EQ(small_window_bound
.ToString(), window
->bounds().ToString());
1139 gfx::Rect
occluded_window_bounds(50,
1140 keyboard_bounds
.y() + keyboard_bounds
.height()/2, 50,
1141 keyboard_bounds
.height()/2);
1142 window
->SetBounds(occluded_window_bounds
);
1143 EXPECT_EQ(occluded_window_bounds
.ToString(),
1144 occluded_window_bounds
.ToString());
1146 EXPECT_EQ(gfx::Rect(50,
1147 keyboard_bounds
.y() - keyboard_bounds
.height()/2,
1148 occluded_window_bounds
.width(),
1149 occluded_window_bounds
.height()).ToString(),
1150 window
->bounds().ToString());
1152 EXPECT_EQ(occluded_window_bounds
.ToString(), window
->bounds().ToString());
1154 Blur(&text_input_client
);