Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / ash / wm / workspace / workspace_layout_manager_unittest.cc
blob2a3157e0116635418579aa9315e94cf7ba08e699
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"
7 #include <string>
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/ui_base_types.h"
31 #include "ui/gfx/geometry/insets.h"
32 #include "ui/gfx/screen.h"
33 #include "ui/views/widget/widget.h"
34 #include "ui/views/widget/widget_delegate.h"
35 #include "ui/wm/core/window_util.h"
37 namespace ash {
38 namespace {
40 class MaximizeDelegateView : public views::WidgetDelegateView {
41 public:
42 explicit MaximizeDelegateView(const gfx::Rect& initial_bounds)
43 : initial_bounds_(initial_bounds) {
45 ~MaximizeDelegateView() override {}
47 bool GetSavedWindowPlacement(const views::Widget* widget,
48 gfx::Rect* bounds,
49 ui::WindowShowState* show_state) const override {
50 *bounds = initial_bounds_;
51 *show_state = ui::SHOW_STATE_MAXIMIZED;
52 return true;
55 private:
56 const gfx::Rect initial_bounds_;
58 DISALLOW_COPY_AND_ASSIGN(MaximizeDelegateView);
61 class TestShellObserver : public ShellObserver {
62 public:
63 TestShellObserver() : call_count_(0),
64 is_fullscreen_(false) {
65 Shell::GetInstance()->AddShellObserver(this);
68 ~TestShellObserver() override {
69 Shell::GetInstance()->RemoveShellObserver(this);
72 void OnFullscreenStateChanged(bool is_fullscreen,
73 aura::Window* root_window) override {
74 call_count_++;
75 is_fullscreen_ = is_fullscreen;
78 int call_count() const {
79 return call_count_;
82 bool is_fullscreen() const {
83 return is_fullscreen_;
86 private:
87 int call_count_;
88 bool is_fullscreen_;
90 DISALLOW_COPY_AND_ASSIGN(TestShellObserver);
93 } // namespace
95 typedef test::AshTestBase WorkspaceLayoutManagerTest;
97 // Verifies that a window containing a restore coordinate will be restored to
98 // to the size prior to minimize, keeping the restore rectangle in tact (if
99 // there is one).
100 TEST_F(WorkspaceLayoutManagerTest, RestoreFromMinimizeKeepsRestore) {
101 scoped_ptr<aura::Window> window(
102 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4)));
103 gfx::Rect bounds(10, 15, 25, 35);
104 window->SetBounds(bounds);
106 wm::WindowState* window_state = wm::GetWindowState(window.get());
108 // This will not be used for un-minimizing window.
109 window_state->SetRestoreBoundsInScreen(gfx::Rect(0, 0, 100, 100));
110 window_state->Minimize();
111 window_state->Restore();
112 EXPECT_EQ("0,0 100x100", window_state->GetRestoreBoundsInScreen().ToString());
113 EXPECT_EQ("10,15 25x35", window.get()->bounds().ToString());
115 if (!SupportsMultipleDisplays())
116 return;
118 UpdateDisplay("400x300,500x400");
119 window->SetBoundsInScreen(gfx::Rect(600, 0, 100, 100),
120 ScreenUtil::GetSecondaryDisplay());
121 EXPECT_EQ(Shell::GetAllRootWindows()[1], window->GetRootWindow());
122 window_state->Minimize();
123 // This will not be used for un-minimizing window.
124 window_state->SetRestoreBoundsInScreen(gfx::Rect(0, 0, 100, 100));
125 window_state->Restore();
126 EXPECT_EQ("600,0 100x100", window->GetBoundsInScreen().ToString());
128 // Make sure the unminimized window moves inside the display when
129 // 2nd display is disconnected.
130 window_state->Minimize();
131 UpdateDisplay("400x300");
132 window_state->Restore();
133 EXPECT_EQ(Shell::GetPrimaryRootWindow(), window->GetRootWindow());
134 EXPECT_TRUE(
135 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds()));
138 TEST_F(WorkspaceLayoutManagerTest, KeepMinimumVisibilityInDisplays) {
139 if (!SupportsMultipleDisplays())
140 return;
142 UpdateDisplay("300x400,400x500");
143 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
145 DisplayLayout layout(DisplayLayout::TOP, 0);
146 Shell::GetInstance()->display_manager()->
147 SetLayoutForCurrentDisplays(layout);
148 EXPECT_EQ("0,-500 400x500", root_windows[1]->GetBoundsInScreen().ToString());
150 scoped_ptr<aura::Window> window1(
151 CreateTestWindowInShellWithBounds(gfx::Rect(10, -400, 200, 200)));
152 EXPECT_EQ("10,-400 200x200", window1->GetBoundsInScreen().ToString());
154 // Make sure the caption is visible.
155 scoped_ptr<aura::Window> window2(
156 CreateTestWindowInShellWithBounds(gfx::Rect(10, -600, 200, 200)));
157 EXPECT_EQ("10,-500 200x200", window2->GetBoundsInScreen().ToString());
160 TEST_F(WorkspaceLayoutManagerTest, NoMinimumVisibilityForPopupWindows) {
161 UpdateDisplay("300x400");
163 // Create a popup window out of display boundaries and make sure it is not
164 // moved to have minimum visibility.
165 scoped_ptr<aura::Window> window(
166 CreateTestWindowInShellWithDelegateAndType(NULL,
167 ui::wm::WINDOW_TYPE_POPUP,
169 gfx::Rect(400, 100, 50, 50)));
170 EXPECT_EQ("400,100 50x50", window->GetBoundsInScreen().ToString());
173 TEST_F(WorkspaceLayoutManagerTest, KeepRestoredWindowInDisplay) {
174 if (!SupportsHostWindowResize())
175 return;
176 scoped_ptr<aura::Window> window(
177 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40)));
178 wm::WindowState* window_state = wm::GetWindowState(window.get());
180 // Maximized -> Normal transition.
181 window_state->Maximize();
182 window_state->SetRestoreBoundsInScreen(gfx::Rect(-100, -100, 30, 40));
183 window_state->Restore();
184 EXPECT_TRUE(
185 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds()));
186 // Y bounds should not be negative.
187 EXPECT_EQ("-5,0 30x40", window->bounds().ToString());
189 // Minimized -> Normal transition.
190 window->SetBounds(gfx::Rect(-100, -100, 30, 40));
191 window_state->Minimize();
192 EXPECT_FALSE(
193 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds()));
194 EXPECT_EQ("-100,-100 30x40", window->bounds().ToString());
195 window->Show();
196 EXPECT_TRUE(
197 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds()));
198 // Y bounds should not be negative.
199 EXPECT_EQ("-5,0 30x40", window->bounds().ToString());
201 // Fullscreen -> Normal transition.
202 window->SetBounds(gfx::Rect(0, 0, 30, 40)); // reset bounds.
203 ASSERT_EQ("0,0 30x40", window->bounds().ToString());
204 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
205 EXPECT_EQ(window->bounds(), window->GetRootWindow()->bounds());
206 window_state->SetRestoreBoundsInScreen(gfx::Rect(-100, -100, 30, 40));
207 window_state->Restore();
208 EXPECT_TRUE(
209 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds()));
210 // Y bounds should not be negative.
211 EXPECT_EQ("-5,0 30x40", window->bounds().ToString());
214 TEST_F(WorkspaceLayoutManagerTest, MaximizeInDisplayToBeRestored) {
215 if (!SupportsMultipleDisplays())
216 return;
217 UpdateDisplay("300x400,400x500");
219 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
221 scoped_ptr<aura::Window> window(
222 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40)));
223 EXPECT_EQ(root_windows[0], window->GetRootWindow());
225 wm::WindowState* window_state = wm::GetWindowState(window.get());
226 window_state->SetRestoreBoundsInScreen(gfx::Rect(400, 0, 30, 40));
227 // Maximize the window in 2nd display as the restore bounds
228 // is inside 2nd display.
229 window_state->Maximize();
230 EXPECT_EQ(root_windows[1], window->GetRootWindow());
231 EXPECT_EQ("300,0 400x453", window->GetBoundsInScreen().ToString());
233 window_state->Restore();
234 EXPECT_EQ(root_windows[1], window->GetRootWindow());
235 EXPECT_EQ("400,0 30x40", window->GetBoundsInScreen().ToString());
237 // If the restore bounds intersects with the current display,
238 // don't move.
239 window_state->SetRestoreBoundsInScreen(gfx::Rect(295, 0, 30, 40));
240 window_state->Maximize();
241 EXPECT_EQ(root_windows[1], window->GetRootWindow());
242 EXPECT_EQ("300,0 400x453", window->GetBoundsInScreen().ToString());
244 window_state->Restore();
245 EXPECT_EQ(root_windows[1], window->GetRootWindow());
246 EXPECT_EQ("295,0 30x40", window->GetBoundsInScreen().ToString());
248 // Restoring widget state.
249 scoped_ptr<views::Widget> w1(new views::Widget);
250 views::Widget::InitParams params;
251 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
252 params.delegate = new MaximizeDelegateView(gfx::Rect(400, 0, 30, 40));
253 params.context = root_windows[0];
254 w1->Init(params);
255 w1->Show();
256 EXPECT_TRUE(w1->IsMaximized());
257 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
258 EXPECT_EQ("300,0 400x453", w1->GetWindowBoundsInScreen().ToString());
259 w1->Restore();
260 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
261 EXPECT_EQ("400,0 30x40", w1->GetWindowBoundsInScreen().ToString());
264 TEST_F(WorkspaceLayoutManagerTest, FullscreenInDisplayToBeRestored) {
265 if (!SupportsMultipleDisplays())
266 return;
267 UpdateDisplay("300x400,400x500");
269 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
271 scoped_ptr<aura::Window> window(
272 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40)));
273 EXPECT_EQ(root_windows[0], window->GetRootWindow());
275 wm::WindowState* window_state = wm::GetWindowState(window.get());
276 window_state->SetRestoreBoundsInScreen(gfx::Rect(400, 0, 30, 40));
277 // Maximize the window in 2nd display as the restore bounds
278 // is inside 2nd display.
279 window->SetProperty(aura::client::kShowStateKey,
280 ui::SHOW_STATE_FULLSCREEN);
281 EXPECT_EQ(root_windows[1], window->GetRootWindow());
282 EXPECT_EQ("300,0 400x500", window->GetBoundsInScreen().ToString());
284 window_state->Restore();
285 EXPECT_EQ(root_windows[1], window->GetRootWindow());
286 EXPECT_EQ("400,0 30x40", window->GetBoundsInScreen().ToString());
288 // If the restore bounds intersects with the current display,
289 // don't move.
290 window_state->SetRestoreBoundsInScreen(gfx::Rect(295, 0, 30, 40));
291 window->SetProperty(aura::client::kShowStateKey,
292 ui::SHOW_STATE_FULLSCREEN);
293 EXPECT_EQ(root_windows[1], window->GetRootWindow());
294 EXPECT_EQ("300,0 400x500", window->GetBoundsInScreen().ToString());
296 window_state->Restore();
297 EXPECT_EQ(root_windows[1], window->GetRootWindow());
298 EXPECT_EQ("295,0 30x40", window->GetBoundsInScreen().ToString());
301 // WindowObserver implementation used by DontClobberRestoreBoundsWindowObserver.
302 // This code mirrors what BrowserFrameAsh does. In particular when this code
303 // sees the window was maximized it changes the bounds of a secondary
304 // window. The secondary window mirrors the status window.
305 class DontClobberRestoreBoundsWindowObserver : public aura::WindowObserver {
306 public:
307 DontClobberRestoreBoundsWindowObserver() : window_(NULL) {}
309 void set_window(aura::Window* window) { window_ = window; }
311 void OnWindowPropertyChanged(aura::Window* window,
312 const void* key,
313 intptr_t old) override {
314 if (!window_)
315 return;
317 if (wm::GetWindowState(window)->IsMaximized()) {
318 aura::Window* w = window_;
319 window_ = NULL;
321 gfx::Rect shelf_bounds(Shell::GetPrimaryRootWindowController()->
322 GetShelfLayoutManager()->GetIdealBounds());
323 const gfx::Rect& window_bounds(w->bounds());
324 w->SetBounds(gfx::Rect(window_bounds.x(), shelf_bounds.y() - 1,
325 window_bounds.width(), window_bounds.height()));
329 private:
330 aura::Window* window_;
332 DISALLOW_COPY_AND_ASSIGN(DontClobberRestoreBoundsWindowObserver);
335 // Creates a window, maximized the window and from within the maximized
336 // notification sets the bounds of a window to overlap the shelf. Verifies this
337 // doesn't effect the restore bounds.
338 TEST_F(WorkspaceLayoutManagerTest, DontClobberRestoreBounds) {
339 DontClobberRestoreBoundsWindowObserver window_observer;
340 scoped_ptr<aura::Window> window(new aura::Window(NULL));
341 window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
342 window->Init(ui::LAYER_TEXTURED);
343 window->SetBounds(gfx::Rect(10, 20, 30, 40));
344 // NOTE: for this test to exercise the failure the observer needs to be added
345 // before the parent set. This mimics what BrowserFrameAsh does.
346 window->AddObserver(&window_observer);
347 ParentWindowInPrimaryRootWindow(window.get());
348 window->Show();
350 wm::WindowState* window_state = wm::GetWindowState(window.get());
351 window_state->Activate();
353 scoped_ptr<aura::Window> window2(
354 CreateTestWindowInShellWithBounds(gfx::Rect(12, 20, 30, 40)));
355 ::wm::AddTransientChild(window.get(), window2.get());
356 window2->Show();
358 window_observer.set_window(window2.get());
359 window_state->Maximize();
360 EXPECT_EQ("10,20 30x40",
361 window_state->GetRestoreBoundsInScreen().ToString());
362 window->RemoveObserver(&window_observer);
365 // Verifies when a window is maximized all descendant windows have a size.
366 TEST_F(WorkspaceLayoutManagerTest, ChildBoundsResetOnMaximize) {
367 scoped_ptr<aura::Window> window(
368 CreateTestWindowInShellWithBounds(gfx::Rect(10, 20, 30, 40)));
369 window->Show();
370 wm::WindowState* window_state = wm::GetWindowState(window.get());
371 window_state->Activate();
372 scoped_ptr<aura::Window> child_window(
373 aura::test::CreateTestWindowWithBounds(gfx::Rect(5, 6, 7, 8),
374 window.get()));
375 child_window->Show();
376 window_state->Maximize();
377 EXPECT_EQ("5,6 7x8", child_window->bounds().ToString());
380 // Verifies a window created with maximized state has the maximized
381 // bounds.
382 TEST_F(WorkspaceLayoutManagerTest, MaximizeWithEmptySize) {
383 scoped_ptr<aura::Window> window(
384 aura::test::CreateTestWindowWithBounds(gfx::Rect(0, 0, 0, 0),
385 NULL));
386 wm::GetWindowState(window.get())->Maximize();
387 aura::Window* default_container = Shell::GetContainer(
388 Shell::GetPrimaryRootWindow(), kShellWindowId_DefaultContainer);
389 default_container->AddChild(window.get());
390 window->Show();
391 gfx::Rect work_area(
392 Shell::GetScreen()->GetPrimaryDisplay().work_area());
393 EXPECT_EQ(work_area.ToString(), window->GetBoundsInScreen().ToString());
396 TEST_F(WorkspaceLayoutManagerTest, WindowShouldBeOnScreenWhenAdded) {
397 // Normal window bounds shouldn't be changed.
398 gfx::Rect window_bounds(100, 100, 200, 200);
399 scoped_ptr<aura::Window> window(
400 CreateTestWindowInShellWithBounds(window_bounds));
401 EXPECT_EQ(window_bounds, window->bounds());
403 // If the window is out of the workspace, it would be moved on screen.
404 gfx::Rect root_window_bounds =
405 Shell::GetInstance()->GetPrimaryRootWindow()->bounds();
406 window_bounds.Offset(root_window_bounds.width(), root_window_bounds.height());
407 ASSERT_FALSE(window_bounds.Intersects(root_window_bounds));
408 scoped_ptr<aura::Window> out_window(
409 CreateTestWindowInShellWithBounds(window_bounds));
410 EXPECT_EQ(window_bounds.size(), out_window->bounds().size());
411 gfx::Rect bounds = out_window->bounds();
412 bounds.Intersect(root_window_bounds);
414 // 30% of the window edge must be visible.
415 EXPECT_GT(bounds.width(), out_window->bounds().width() * 0.29);
416 EXPECT_GT(bounds.height(), out_window->bounds().height() * 0.29);
418 aura::Window* parent = out_window->parent();
419 parent->RemoveChild(out_window.get());
420 out_window->SetBounds(gfx::Rect(-200, -200, 200, 200));
421 // UserHasChangedWindowPositionOrSize flag shouldn't turn off this behavior.
422 wm::GetWindowState(window.get())->set_bounds_changed_by_user(true);
423 parent->AddChild(out_window.get());
424 EXPECT_GT(bounds.width(), out_window->bounds().width() * 0.29);
425 EXPECT_GT(bounds.height(), out_window->bounds().height() * 0.29);
427 // Make sure we always make more than 1/3 of the window edge visible even
428 // if the initial bounds intersects with display.
429 window_bounds.SetRect(-150, -150, 200, 200);
430 bounds = window_bounds;
431 bounds.Intersect(root_window_bounds);
433 // Make sure that the initial bounds' visible area is less than 26%
434 // so that the auto adjustment logic kicks in.
435 ASSERT_LT(bounds.width(), out_window->bounds().width() * 0.26);
436 ASSERT_LT(bounds.height(), out_window->bounds().height() * 0.26);
437 ASSERT_TRUE(window_bounds.Intersects(root_window_bounds));
439 scoped_ptr<aura::Window> partially_out_window(
440 CreateTestWindowInShellWithBounds(window_bounds));
441 EXPECT_EQ(window_bounds.size(), partially_out_window->bounds().size());
442 bounds = partially_out_window->bounds();
443 bounds.Intersect(root_window_bounds);
444 EXPECT_GT(bounds.width(), out_window->bounds().width() * 0.29);
445 EXPECT_GT(bounds.height(), out_window->bounds().height() * 0.29);
447 // Make sure the window whose 30% width/height is bigger than display
448 // will be placed correctly.
449 window_bounds.SetRect(-1900, -1900, 3000, 3000);
450 scoped_ptr<aura::Window> window_bigger_than_display(
451 CreateTestWindowInShellWithBounds(window_bounds));
452 EXPECT_GE(root_window_bounds.width(),
453 window_bigger_than_display->bounds().width());
454 EXPECT_GE(root_window_bounds.height(),
455 window_bigger_than_display->bounds().height());
457 bounds = window_bigger_than_display->bounds();
458 bounds.Intersect(root_window_bounds);
459 EXPECT_GT(bounds.width(), out_window->bounds().width() * 0.29);
460 EXPECT_GT(bounds.height(), out_window->bounds().height() * 0.29);
463 // Verifies the size of a window is enforced to be smaller than the work area.
464 TEST_F(WorkspaceLayoutManagerTest, SizeToWorkArea) {
465 // Normal window bounds shouldn't be changed.
466 gfx::Size work_area(
467 Shell::GetScreen()->GetPrimaryDisplay().work_area().size());
468 const gfx::Rect window_bounds(
469 100, 101, work_area.width() + 1, work_area.height() + 2);
470 scoped_ptr<aura::Window> window(
471 CreateTestWindowInShellWithBounds(window_bounds));
472 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(),
473 window->bounds().ToString());
475 // Directly setting the bounds triggers a slightly different code path. Verify
476 // that too.
477 window->SetBounds(window_bounds);
478 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(),
479 window->bounds().ToString());
482 TEST_F(WorkspaceLayoutManagerTest, NotifyFullscreenChanges) {
483 TestShellObserver observer;
484 scoped_ptr<aura::Window> window1(
485 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40)));
486 scoped_ptr<aura::Window> window2(
487 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40)));
488 wm::WindowState* window_state1 = wm::GetWindowState(window1.get());
489 wm::WindowState* window_state2 = wm::GetWindowState(window2.get());
490 window_state2->Activate();
492 const wm::WMEvent toggle_fullscreen_event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
493 window_state2->OnWMEvent(&toggle_fullscreen_event);
494 EXPECT_EQ(1, observer.call_count());
495 EXPECT_TRUE(observer.is_fullscreen());
497 // When window1 moves to the front the fullscreen state should change.
498 window_state1->Activate();
499 EXPECT_EQ(2, observer.call_count());
500 EXPECT_FALSE(observer.is_fullscreen());
502 // It should change back if window2 becomes active again.
503 window_state2->Activate();
504 EXPECT_EQ(3, observer.call_count());
505 EXPECT_TRUE(observer.is_fullscreen());
507 window_state2->OnWMEvent(&toggle_fullscreen_event);
508 EXPECT_EQ(4, observer.call_count());
509 EXPECT_FALSE(observer.is_fullscreen());
511 window_state2->OnWMEvent(&toggle_fullscreen_event);
512 EXPECT_EQ(5, observer.call_count());
513 EXPECT_TRUE(observer.is_fullscreen());
515 // Closing the window should change the fullscreen state.
516 window2.reset();
517 EXPECT_EQ(6, observer.call_count());
518 EXPECT_FALSE(observer.is_fullscreen());
521 // Following "Solo" tests were originally written for BaseLayoutManager.
522 namespace {
524 class WorkspaceLayoutManagerSoloTest : public test::AshTestBase {
525 public:
526 WorkspaceLayoutManagerSoloTest() {}
527 ~WorkspaceLayoutManagerSoloTest() override {}
529 aura::Window* CreateTestWindow(const gfx::Rect& bounds) {
530 return CreateTestWindowInShellWithBounds(bounds);
533 private:
534 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerSoloTest);
537 } // namespace
539 // Tests normal->maximize->normal.
540 TEST_F(WorkspaceLayoutManagerSoloTest, Maximize) {
541 gfx::Rect bounds(100, 100, 200, 200);
542 scoped_ptr<aura::Window> window(CreateTestWindow(bounds));
543 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
544 // Maximized window fills the work area, not the whole display.
545 EXPECT_EQ(
546 ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString(),
547 window->bounds().ToString());
548 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
549 EXPECT_EQ(bounds.ToString(), window->bounds().ToString());
552 // Tests normal->minimize->normal.
553 TEST_F(WorkspaceLayoutManagerSoloTest, Minimize) {
554 gfx::Rect bounds(100, 100, 200, 200);
555 scoped_ptr<aura::Window> window(CreateTestWindow(bounds));
556 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
557 // Note: Currently minimize doesn't do anything except set the state.
558 // See crbug.com/104571.
559 EXPECT_EQ(bounds.ToString(), window->bounds().ToString());
560 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
561 EXPECT_EQ(bounds.ToString(), window->bounds().ToString());
564 // A WindowDelegate which sets the focus when the window
565 // becomes visible.
566 class FocusDelegate : public aura::test::TestWindowDelegate {
567 public:
568 FocusDelegate()
569 : window_(NULL),
570 show_state_(ui::SHOW_STATE_END) {
572 ~FocusDelegate() override {}
574 void set_window(aura::Window* window) { window_ = window; }
576 // aura::test::TestWindowDelegate overrides:
577 void OnWindowTargetVisibilityChanged(bool visible) override {
578 if (window_) {
579 if (visible)
580 window_->Focus();
581 show_state_ = window_->GetProperty(aura::client::kShowStateKey);
585 ui::WindowShowState GetShowStateAndReset() {
586 ui::WindowShowState ret = show_state_;
587 show_state_ = ui::SHOW_STATE_END;
588 return ret;
591 private:
592 aura::Window* window_;
593 ui::WindowShowState show_state_;
595 DISALLOW_COPY_AND_ASSIGN(FocusDelegate);
598 // Make sure that the window's show state is correct in
599 // |WindowDelegate::OnWindowTargetVisibilityChanged|, and setting
600 // focus in this callback doesn't cause DCHECK error. See
601 // crbug.com/168383.
602 TEST_F(WorkspaceLayoutManagerSoloTest, FocusDuringUnminimize) {
603 FocusDelegate delegate;
604 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
605 &delegate, 0, gfx::Rect(100, 100, 100, 100)));
606 delegate.set_window(window.get());
607 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
608 EXPECT_FALSE(window->IsVisible());
609 EXPECT_EQ(ui::SHOW_STATE_MINIMIZED, delegate.GetShowStateAndReset());
610 window->Show();
611 EXPECT_TRUE(window->IsVisible());
612 EXPECT_EQ(ui::SHOW_STATE_NORMAL, delegate.GetShowStateAndReset());
615 // Tests maximized window size during root window resize.
616 TEST_F(WorkspaceLayoutManagerSoloTest, MaximizeRootWindowResize) {
617 gfx::Rect bounds(100, 100, 200, 200);
618 scoped_ptr<aura::Window> window(CreateTestWindow(bounds));
619 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
620 gfx::Rect initial_work_area_bounds =
621 ScreenUtil::GetMaximizedWindowBoundsInParent(window.get());
622 EXPECT_EQ(initial_work_area_bounds.ToString(), window->bounds().ToString());
623 // Enlarge the root window. We should still match the work area size.
624 UpdateDisplay("900x700");
625 EXPECT_EQ(
626 ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString(),
627 window->bounds().ToString());
628 EXPECT_NE(
629 initial_work_area_bounds.ToString(),
630 ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString());
633 // Tests normal->fullscreen->normal.
634 TEST_F(WorkspaceLayoutManagerSoloTest, Fullscreen) {
635 gfx::Rect bounds(100, 100, 200, 200);
636 scoped_ptr<aura::Window> window(CreateTestWindow(bounds));
637 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
638 // Fullscreen window fills the whole display.
639 EXPECT_EQ(Shell::GetScreen()->GetDisplayNearestWindow(
640 window.get()).bounds().ToString(),
641 window->bounds().ToString());
642 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
643 EXPECT_EQ(bounds.ToString(), window->bounds().ToString());
646 // Tests that fullscreen window causes always_on_top windows to stack below.
647 TEST_F(WorkspaceLayoutManagerSoloTest, FullscreenSuspendsAlwaysOnTop) {
648 gfx::Rect bounds(100, 100, 200, 200);
649 scoped_ptr<aura::Window> fullscreen_window(CreateTestWindow(bounds));
650 scoped_ptr<aura::Window> always_on_top_window1(CreateTestWindow(bounds));
651 scoped_ptr<aura::Window> always_on_top_window2(CreateTestWindow(bounds));
652 always_on_top_window1->SetProperty(aura::client::kAlwaysOnTopKey, true);
653 always_on_top_window2->SetProperty(aura::client::kAlwaysOnTopKey, true);
654 // Making a window fullscreen temporarily suspends always on top state.
655 fullscreen_window->SetProperty(aura::client::kShowStateKey,
656 ui::SHOW_STATE_FULLSCREEN);
657 EXPECT_FALSE(
658 always_on_top_window1->GetProperty(aura::client::kAlwaysOnTopKey));
659 EXPECT_FALSE(
660 always_on_top_window2->GetProperty(aura::client::kAlwaysOnTopKey));
661 EXPECT_NE(nullptr, GetRootWindowController(fullscreen_window->GetRootWindow())
662 ->GetWindowForFullscreenMode());
663 // Making fullscreen window normal restores always on top windows.
664 fullscreen_window->SetProperty(aura::client::kShowStateKey,
665 ui::SHOW_STATE_NORMAL);
666 EXPECT_TRUE(
667 always_on_top_window1->GetProperty(aura::client::kAlwaysOnTopKey));
668 EXPECT_TRUE(
669 always_on_top_window2->GetProperty(aura::client::kAlwaysOnTopKey));
670 EXPECT_EQ(nullptr, GetRootWindowController(fullscreen_window->GetRootWindow())
671 ->GetWindowForFullscreenMode());
674 // Tests fullscreen window size during root window resize.
675 TEST_F(WorkspaceLayoutManagerSoloTest, FullscreenRootWindowResize) {
676 gfx::Rect bounds(100, 100, 200, 200);
677 scoped_ptr<aura::Window> window(CreateTestWindow(bounds));
678 // Fullscreen window fills the whole display.
679 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
680 EXPECT_EQ(Shell::GetScreen()->GetDisplayNearestWindow(
681 window.get()).bounds().ToString(),
682 window->bounds().ToString());
683 // Enlarge the root window. We should still match the display size.
684 UpdateDisplay("800x600");
685 EXPECT_EQ(Shell::GetScreen()->GetDisplayNearestWindow(
686 window.get()).bounds().ToString(),
687 window->bounds().ToString());
690 // Tests that when the screen gets smaller the windows aren't bigger than
691 // the screen.
692 TEST_F(WorkspaceLayoutManagerSoloTest, RootWindowResizeShrinksWindows) {
693 scoped_ptr<aura::Window> window(
694 CreateTestWindow(gfx::Rect(10, 20, 500, 400)));
695 gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow(
696 window.get()).work_area();
697 // Invariant: Window is smaller than work area.
698 EXPECT_LE(window->bounds().width(), work_area.width());
699 EXPECT_LE(window->bounds().height(), work_area.height());
701 // Make the root window narrower than our window.
702 UpdateDisplay("300x400");
703 work_area = Shell::GetScreen()->GetDisplayNearestWindow(
704 window.get()).work_area();
705 EXPECT_LE(window->bounds().width(), work_area.width());
706 EXPECT_LE(window->bounds().height(), work_area.height());
708 // Make the root window shorter than our window.
709 UpdateDisplay("300x200");
710 work_area = Shell::GetScreen()->GetDisplayNearestWindow(
711 window.get()).work_area();
712 EXPECT_LE(window->bounds().width(), work_area.width());
713 EXPECT_LE(window->bounds().height(), work_area.height());
715 // Enlarging the root window does not change the window bounds.
716 gfx::Rect old_bounds = window->bounds();
717 UpdateDisplay("800x600");
718 EXPECT_EQ(old_bounds.width(), window->bounds().width());
719 EXPECT_EQ(old_bounds.height(), window->bounds().height());
722 // Verifies maximizing sets the restore bounds, and restoring
723 // restores the bounds.
724 TEST_F(WorkspaceLayoutManagerSoloTest, MaximizeSetsRestoreBounds) {
725 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(10, 20, 30, 40)));
726 wm::WindowState* window_state = wm::GetWindowState(window.get());
728 // Maximize it, which will keep the previous restore bounds.
729 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
730 EXPECT_EQ("10,20 30x40", window_state->GetRestoreBoundsInParent().ToString());
732 // Restore it, which should restore bounds and reset restore bounds.
733 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
734 EXPECT_EQ("10,20 30x40", window->bounds().ToString());
735 EXPECT_FALSE(window_state->HasRestoreBounds());
738 // Verifies maximizing keeps the restore bounds if set.
739 TEST_F(WorkspaceLayoutManagerSoloTest, MaximizeResetsRestoreBounds) {
740 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4)));
742 wm::WindowState* window_state = wm::GetWindowState(window.get());
743 window_state->SetRestoreBoundsInParent(gfx::Rect(10, 11, 12, 13));
745 // Maximize it, which will keep the previous restore bounds.
746 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
747 EXPECT_EQ("10,11 12x13", window_state->GetRestoreBoundsInParent().ToString());
750 // Verifies that the restore bounds do not get reset when restoring to a
751 // maximzied state from a minimized state.
752 TEST_F(WorkspaceLayoutManagerSoloTest,
753 BoundsAfterRestoringToMaximizeFromMinimize) {
754 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4)));
755 gfx::Rect bounds(10, 15, 25, 35);
756 window->SetBounds(bounds);
758 wm::WindowState* window_state = wm::GetWindowState(window.get());
759 // Maximize it, which should reset restore bounds.
760 window_state->Maximize();
761 EXPECT_EQ(bounds.ToString(),
762 window_state->GetRestoreBoundsInParent().ToString());
763 // Minimize the window. The restore bounds should not change.
764 window_state->Minimize();
765 EXPECT_EQ(bounds.ToString(),
766 window_state->GetRestoreBoundsInParent().ToString());
768 // Show the window again. The window should be maximized, and the restore
769 // bounds should not change.
770 window->Show();
771 EXPECT_EQ(bounds.ToString(),
772 window_state->GetRestoreBoundsInParent().ToString());
773 EXPECT_TRUE(window_state->IsMaximized());
775 window_state->Restore();
776 EXPECT_EQ(bounds.ToString(), window->bounds().ToString());
779 // Verify if the window is not resized during screen lock. See: crbug.com/173127
780 TEST_F(WorkspaceLayoutManagerSoloTest, NotResizeWhenScreenIsLocked) {
781 SetCanLockScreen(true);
782 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4)));
783 // window with AlwaysOnTop will be managed by BaseLayoutManager.
784 window->SetProperty(aura::client::kAlwaysOnTopKey, true);
785 window->Show();
787 ShelfLayoutManager* shelf = ShelfLayoutManager::ForShelf(window.get());
788 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
790 window->SetBounds(ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()));
791 gfx::Rect window_bounds = window->bounds();
792 EXPECT_EQ(
793 ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString(),
794 window_bounds.ToString());
796 // The window size should not get touched while we are in lock screen.
797 Shell::GetInstance()->session_state_delegate()->LockScreen();
798 shelf->UpdateVisibilityState();
799 EXPECT_EQ(window_bounds.ToString(), window->bounds().ToString());
801 // Coming out of the lock screen the window size should still remain.
802 Shell::GetInstance()->session_state_delegate()->UnlockScreen();
803 shelf->UpdateVisibilityState();
804 EXPECT_EQ(
805 ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString(),
806 window_bounds.ToString());
807 EXPECT_EQ(window_bounds.ToString(), window->bounds().ToString());
810 // Following tests are written to test the backdrop functionality.
812 namespace {
814 class WorkspaceLayoutManagerBackdropTest : public test::AshTestBase {
815 public:
816 WorkspaceLayoutManagerBackdropTest() : default_container_(nullptr) {}
817 ~WorkspaceLayoutManagerBackdropTest() override {}
819 void SetUp() override {
820 test::AshTestBase::SetUp();
821 UpdateDisplay("800x600");
822 default_container_ = Shell::GetContainer(Shell::GetPrimaryRootWindow(),
823 kShellWindowId_DefaultContainer);
826 aura::Window* CreateTestWindow(const gfx::Rect& bounds) {
827 aura::Window* window = CreateTestWindowInShellWithBounds(bounds);
828 return window;
831 // Turn the top window back drop on / off.
832 void ShowTopWindowBackdrop(bool show) {
833 scoped_ptr<ash::WorkspaceLayoutManagerDelegate> backdrop;
834 if (show) {
835 backdrop.reset(new ash::WorkspaceBackdropDelegate(default_container_));
837 (static_cast<WorkspaceLayoutManager*>(default_container_->layout_manager()))
838 ->SetMaximizeBackdropDelegate(backdrop.Pass());
839 // Closing and / or opening can be a delayed operation.
840 base::MessageLoop::current()->RunUntilIdle();
843 // Return the default container.
844 aura::Window* default_container() { return default_container_; }
846 // Return the order of windows (top most first) as they are in the default
847 // container. If the window is visible it will be a big letter, otherwise a
848 // small one. The backdrop will be an X and unknown windows will be shown as
849 // '!'.
850 std::string GetWindowOrderAsString(aura::Window* backdrop,
851 aura::Window* wa,
852 aura::Window* wb,
853 aura::Window* wc) {
854 std::string result;
855 for (int i = static_cast<int>(default_container()->children().size()) - 1;
856 i >= 0;
857 --i) {
858 if (!result.empty())
859 result += ",";
860 if (default_container()->children()[i] == wa)
861 result += default_container()->children()[i]->IsVisible() ? "A" : "a";
862 else if (default_container()->children()[i] == wb)
863 result += default_container()->children()[i]->IsVisible() ? "B" : "b";
864 else if (default_container()->children()[i] == wc)
865 result += default_container()->children()[i]->IsVisible() ? "C" : "c";
866 else if (default_container()->children()[i] == backdrop)
867 result += default_container()->children()[i]->IsVisible() ? "X" : "x";
868 else
869 result += "!";
871 return result;
874 private:
875 // The default container.
876 aura::Window* default_container_;
878 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerBackdropTest);
881 } // namespace
883 // Check that creating the BackDrop without destroying it does not lead into
884 // a crash.
885 TEST_F(WorkspaceLayoutManagerBackdropTest, BackdropCrashTest) {
886 ShowTopWindowBackdrop(true);
889 // Verify basic assumptions about the backdrop.
890 TEST_F(WorkspaceLayoutManagerBackdropTest, BasicBackdropTests) {
891 // Create a backdrop and see that there is one window (the backdrop) and
892 // that the size is the same as the default container as well as that it is
893 // not visible.
894 ShowTopWindowBackdrop(true);
895 ASSERT_EQ(1U, default_container()->children().size());
896 EXPECT_FALSE(default_container()->children()[0]->IsVisible());
899 // Add a window and make sure that the backdrop is the second child.
900 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4)));
901 window->Show();
902 ASSERT_EQ(2U, default_container()->children().size());
903 EXPECT_TRUE(default_container()->children()[0]->IsVisible());
904 EXPECT_TRUE(default_container()->children()[1]->IsVisible());
905 EXPECT_EQ(window.get(), default_container()->children()[1]);
906 EXPECT_EQ(default_container()->bounds().ToString(),
907 default_container()->children()[0]->bounds().ToString());
910 // With the window gone the backdrop should be invisible again.
911 ASSERT_EQ(1U, default_container()->children().size());
912 EXPECT_FALSE(default_container()->children()[0]->IsVisible());
914 // Destroying the Backdrop should empty the container.
915 ShowTopWindowBackdrop(false);
916 ASSERT_EQ(0U, default_container()->children().size());
919 // Verify that the backdrop gets properly created and placed.
920 TEST_F(WorkspaceLayoutManagerBackdropTest, VerifyBackdropAndItsStacking) {
921 scoped_ptr<aura::Window> window1(CreateTestWindow(gfx::Rect(1, 2, 3, 4)));
922 window1->Show();
924 // Get the default container and check that only a single window is in there.
925 ASSERT_EQ(1U, default_container()->children().size());
926 EXPECT_EQ(window1.get(), default_container()->children()[0]);
927 EXPECT_EQ("A", GetWindowOrderAsString(NULL, window1.get(), NULL, NULL));
929 // Create 2 more windows and check that they are also in the container.
930 scoped_ptr<aura::Window> window2(CreateTestWindow(gfx::Rect(10, 2, 3, 4)));
931 scoped_ptr<aura::Window> window3(CreateTestWindow(gfx::Rect(20, 2, 3, 4)));
932 window2->Show();
933 window3->Show();
935 aura::Window* backdrop = NULL;
936 EXPECT_EQ("C,B,A",
937 GetWindowOrderAsString(backdrop, window1.get(), window2.get(),
938 window3.get()));
940 // Turn on the backdrop mode and check that the window shows up where it
941 // should be (second highest number).
942 ShowTopWindowBackdrop(true);
943 backdrop = default_container()->children()[2];
944 EXPECT_EQ("C,X,B,A",
945 GetWindowOrderAsString(backdrop, window1.get(), window2.get(),
946 window3.get()));
948 // Switch the order of windows and check that it still remains in that
949 // location.
950 default_container()->StackChildAtTop(window2.get());
951 EXPECT_EQ("B,X,C,A",
952 GetWindowOrderAsString(backdrop, window1.get(), window2.get(),
953 window3.get()));
955 // Make the top window invisible and check.
956 window2.get()->Hide();
957 EXPECT_EQ("b,C,X,A",
958 GetWindowOrderAsString(backdrop, window1.get(), window2.get(),
959 window3.get()));
960 // Then delete window after window and see that everything is in order.
961 window1.reset();
962 EXPECT_EQ("b,C,X",
963 GetWindowOrderAsString(backdrop, window1.get(), window2.get(),
964 window3.get()));
965 window3.reset();
966 EXPECT_EQ("b,x",
967 GetWindowOrderAsString(backdrop, window1.get(), window2.get(),
968 window3.get()));
969 ShowTopWindowBackdrop(false);
970 EXPECT_EQ("b",
971 GetWindowOrderAsString(NULL, window1.get(), window2.get(),
972 window3.get()));
975 // Tests that when hidding the shelf, that the backdrop resizes to fill the
976 // entire workspace area.
977 TEST_F(WorkspaceLayoutManagerBackdropTest, ShelfVisibilityChangesBounds) {
978 ShelfLayoutManager* shelf_layout_manager =
979 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
980 ShowTopWindowBackdrop(true);
981 RunAllPendingInMessageLoop();
983 ASSERT_EQ(SHELF_VISIBLE, shelf_layout_manager->visibility_state());
984 gfx::Rect initial_bounds = default_container()->children()[0]->bounds();
985 shelf_layout_manager->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
986 shelf_layout_manager->UpdateVisibilityState();
988 // When the shelf is re-shown WorkspaceLayoutManager shrinks all children
989 // including the backdrop.
990 shelf_layout_manager->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
991 shelf_layout_manager->UpdateVisibilityState();
992 gfx::Rect reduced_bounds = default_container()->children()[0]->bounds();
993 EXPECT_LT(reduced_bounds.height(), initial_bounds.height());
995 shelf_layout_manager->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
996 shelf_layout_manager->UpdateVisibilityState();
998 EXPECT_GT(default_container()->children()[0]->bounds().height(),
999 reduced_bounds.height());
1002 class WorkspaceLayoutManagerKeyboardTest : public test::AshTestBase {
1003 public:
1004 WorkspaceLayoutManagerKeyboardTest() : layout_manager_(nullptr) {}
1005 ~WorkspaceLayoutManagerKeyboardTest() override {}
1007 void SetUp() override {
1008 test::AshTestBase::SetUp();
1009 UpdateDisplay("800x600");
1010 aura::Window* default_container = Shell::GetContainer(
1011 Shell::GetPrimaryRootWindow(), kShellWindowId_DefaultContainer);
1012 layout_manager_ = static_cast<WorkspaceLayoutManager*>(
1013 default_container->layout_manager());
1016 aura::Window* CreateTestWindow(const gfx::Rect& bounds) {
1017 return CreateTestWindowInShellWithBounds(bounds);
1020 void ShowKeyboard() {
1021 layout_manager_->OnKeyboardBoundsChanging(keyboard_bounds_);
1022 restore_work_area_insets_ = Shell::GetScreen()->GetPrimaryDisplay().
1023 GetWorkAreaInsets();
1024 Shell::GetInstance()->SetDisplayWorkAreaInsets(
1025 Shell::GetPrimaryRootWindow(),
1026 gfx::Insets(0, 0, keyboard_bounds_.height(), 0));
1029 void HideKeyboard() {
1030 Shell::GetInstance()->SetDisplayWorkAreaInsets(
1031 Shell::GetPrimaryRootWindow(),
1032 restore_work_area_insets_);
1033 layout_manager_->OnKeyboardBoundsChanging(gfx::Rect());
1036 void SetKeyboardBounds(const gfx::Rect& bounds) {
1037 keyboard_bounds_ = bounds;
1040 private:
1041 gfx::Insets restore_work_area_insets_;
1042 gfx::Rect keyboard_bounds_;
1043 WorkspaceLayoutManager* layout_manager_;
1045 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerKeyboardTest);
1048 // Tests that when a child window gains focus the top level window containing it
1049 // is resized to fit the remaining workspace area.
1050 TEST_F(WorkspaceLayoutManagerKeyboardTest, ChildWindowFocused) {
1051 gfx::Rect work_area(
1052 Shell::GetScreen()->GetPrimaryDisplay().work_area());
1053 gfx::Rect keyboard_bounds(work_area.x(),
1054 work_area.y() + work_area.height() / 2,
1055 work_area.width(),
1056 work_area.height() / 2);
1058 SetKeyboardBounds(keyboard_bounds);
1060 aura::test::TestWindowDelegate delegate1;
1061 scoped_ptr<aura::Window> parent_window(CreateTestWindowInShellWithDelegate(
1062 &delegate1, -1, work_area));
1063 aura::test::TestWindowDelegate delegate2;
1064 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
1065 &delegate2, -1, work_area));
1066 parent_window->AddChild(window.get());
1068 wm::ActivateWindow(window.get());
1070 int available_height =
1071 Shell::GetScreen()->GetPrimaryDisplay().bounds().height() -
1072 keyboard_bounds.height();
1074 gfx::Rect initial_window_bounds(50, 50, 100, 500);
1075 parent_window->SetBounds(initial_window_bounds);
1076 EXPECT_EQ(initial_window_bounds.ToString(),
1077 parent_window->bounds().ToString());
1078 ShowKeyboard();
1079 EXPECT_EQ(gfx::Rect(50, 0, 100, available_height).ToString(),
1080 parent_window->bounds().ToString());
1081 HideKeyboard();
1082 EXPECT_EQ(initial_window_bounds.ToString(),
1083 parent_window->bounds().ToString());
1086 TEST_F(WorkspaceLayoutManagerKeyboardTest, AdjustWindowForA11yKeyboard) {
1087 gfx::Rect work_area(
1088 Shell::GetScreen()->GetPrimaryDisplay().work_area());
1089 gfx::Rect keyboard_bounds(work_area.x(),
1090 work_area.y() + work_area.height() / 2,
1091 work_area.width(),
1092 work_area.height() / 2);
1094 SetKeyboardBounds(keyboard_bounds);
1096 aura::test::TestWindowDelegate delegate;
1097 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
1098 &delegate, -1, work_area));
1100 int available_height =
1101 Shell::GetScreen()->GetPrimaryDisplay().bounds().height() -
1102 keyboard_bounds.height();
1104 wm::ActivateWindow(window.get());
1106 EXPECT_EQ(gfx::Rect(work_area).ToString(), window->bounds().ToString());
1107 ShowKeyboard();
1108 EXPECT_EQ(gfx::Rect(work_area.origin(),
1109 gfx::Size(work_area.width(), available_height)).ToString(),
1110 window->bounds().ToString());
1111 HideKeyboard();
1112 EXPECT_EQ(gfx::Rect(work_area).ToString(), window->bounds().ToString());
1114 gfx::Rect small_window_bound(50, 50, 100, 500);
1115 window->SetBounds(small_window_bound);
1116 EXPECT_EQ(small_window_bound.ToString(), window->bounds().ToString());
1117 ShowKeyboard();
1118 EXPECT_EQ(gfx::Rect(50, 0, 100, available_height).ToString(),
1119 window->bounds().ToString());
1120 HideKeyboard();
1121 EXPECT_EQ(small_window_bound.ToString(), window->bounds().ToString());
1123 gfx::Rect occluded_window_bounds(50,
1124 keyboard_bounds.y() + keyboard_bounds.height()/2, 50,
1125 keyboard_bounds.height()/2);
1126 window->SetBounds(occluded_window_bounds);
1127 EXPECT_EQ(occluded_window_bounds.ToString(),
1128 occluded_window_bounds.ToString());
1129 ShowKeyboard();
1130 EXPECT_EQ(gfx::Rect(50,
1131 keyboard_bounds.y() - keyboard_bounds.height()/2,
1132 occluded_window_bounds.width(),
1133 occluded_window_bounds.height()).ToString(),
1134 window->bounds().ToString());
1135 HideKeyboard();
1136 EXPECT_EQ(occluded_window_bounds.ToString(), window->bounds().ToString());
1139 } // namespace ash