platformKeys: Add per-extension sign permissions.
[chromium-blink-merge.git] / ash / wm / workspace / workspace_layout_manager_unittest.cc
bloba1830df010751be7a9174dc84bc3ad8acc64f092
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/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/geometry/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"
41 namespace ash {
42 namespace {
44 class MaximizeDelegateView : public views::WidgetDelegateView {
45 public:
46 explicit MaximizeDelegateView(const gfx::Rect& initial_bounds)
47 : initial_bounds_(initial_bounds) {
49 ~MaximizeDelegateView() override {}
51 bool GetSavedWindowPlacement(const views::Widget* widget,
52 gfx::Rect* bounds,
53 ui::WindowShowState* show_state) const override {
54 *bounds = initial_bounds_;
55 *show_state = ui::SHOW_STATE_MAXIMIZED;
56 return true;
59 private:
60 const gfx::Rect initial_bounds_;
62 DISALLOW_COPY_AND_ASSIGN(MaximizeDelegateView);
65 class TestShellObserver : public ShellObserver {
66 public:
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 {
78 call_count_++;
79 is_fullscreen_ = is_fullscreen;
82 int call_count() const {
83 return call_count_;
86 bool is_fullscreen() const {
87 return is_fullscreen_;
90 private:
91 int call_count_;
92 bool is_fullscreen_;
94 DISALLOW_COPY_AND_ASSIGN(TestShellObserver);
97 } // namespace
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
103 // there is one).
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())
120 return;
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());
138 EXPECT_TRUE(
139 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds()));
142 TEST_F(WorkspaceLayoutManagerTest, KeepMinimumVisibilityInDisplays) {
143 if (!SupportsMultipleDisplays())
144 return;
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())
179 return;
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();
188 EXPECT_TRUE(
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();
196 EXPECT_FALSE(
197 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds()));
198 EXPECT_EQ("-100,-100 30x40", window->bounds().ToString());
199 window->Show();
200 EXPECT_TRUE(
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();
212 EXPECT_TRUE(
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())
220 return;
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,
242 // don't move.
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];
258 w1->Init(params);
259 w1->Show();
260 EXPECT_TRUE(w1->IsMaximized());
261 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
262 EXPECT_EQ("300,0 400x453", w1->GetWindowBoundsInScreen().ToString());
263 w1->Restore();
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())
270 return;
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,
293 // don't move.
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 {
310 public:
311 DontClobberRestoreBoundsWindowObserver() : window_(NULL) {}
313 void set_window(aura::Window* window) { window_ = window; }
315 void OnWindowPropertyChanged(aura::Window* window,
316 const void* key,
317 intptr_t old) override {
318 if (!window_)
319 return;
321 if (wm::GetWindowState(window)->IsMaximized()) {
322 aura::Window* w = window_;
323 window_ = NULL;
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()));
333 private:
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());
352 window->Show();
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());
360 window2->Show();
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)));
373 window->Show();
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),
378 window.get()));
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
385 // bounds.
386 TEST_F(WorkspaceLayoutManagerTest, MaximizeWithEmptySize) {
387 scoped_ptr<aura::Window> window(
388 aura::test::CreateTestWindowWithBounds(gfx::Rect(0, 0, 0, 0),
389 NULL));
390 wm::GetWindowState(window.get())->Maximize();
391 aura::Window* default_container = Shell::GetContainer(
392 Shell::GetPrimaryRootWindow(), kShellWindowId_DefaultContainer);
393 default_container->AddChild(window.get());
394 window->Show();
395 gfx::Rect work_area(
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.
470 gfx::Size work_area(
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
480 // that too.
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.
520 window2.reset();
521 EXPECT_EQ(6, observer.call_count());
522 EXPECT_FALSE(observer.is_fullscreen());
525 // Following "Solo" tests were originally written for BaseLayoutManager.
526 namespace {
528 class WorkspaceLayoutManagerSoloTest : public test::AshTestBase {
529 public:
530 WorkspaceLayoutManagerSoloTest() {}
531 ~WorkspaceLayoutManagerSoloTest() override {}
533 aura::Window* CreateTestWindow(const gfx::Rect& bounds) {
534 return CreateTestWindowInShellWithBounds(bounds);
537 private:
538 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerSoloTest);
541 } // namespace
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.
549 EXPECT_EQ(
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
569 // becomes visible.
570 class FocusDelegate : public aura::test::TestWindowDelegate {
571 public:
572 FocusDelegate()
573 : window_(NULL),
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 {
582 if (window_) {
583 if (visible)
584 window_->Focus();
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;
592 return ret;
595 private:
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
605 // crbug.com/168383.
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());
614 window->Show();
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");
629 EXPECT_EQ(
630 ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString(),
631 window->bounds().ToString());
632 EXPECT_NE(
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
667 // the screen.
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.
746 window->Show();
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);
761 window->Show();
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();
768 EXPECT_EQ(
769 ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString(),
770 window_bounds.ToString());
772 // The window size should not get touched while we are in lock screen.
773 Shell::GetInstance()->session_state_delegate()->LockScreen();
774 shelf->UpdateVisibilityState();
775 EXPECT_EQ(window_bounds.ToString(), window->bounds().ToString());
777 // Coming out of the lock screen the window size should still remain.
778 Shell::GetInstance()->session_state_delegate()->UnlockScreen();
779 shelf->UpdateVisibilityState();
780 EXPECT_EQ(
781 ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString(),
782 window_bounds.ToString());
783 EXPECT_EQ(window_bounds.ToString(), window->bounds().ToString());
786 // Following tests are written to test the backdrop functionality.
788 namespace {
790 class WorkspaceLayoutManagerBackdropTest : public test::AshTestBase {
791 public:
792 WorkspaceLayoutManagerBackdropTest() {}
793 ~WorkspaceLayoutManagerBackdropTest() override {}
795 void SetUp() override {
796 test::AshTestBase::SetUp();
797 UpdateDisplay("800x600");
798 default_container_ = Shell::GetContainer(Shell::GetPrimaryRootWindow(),
799 kShellWindowId_DefaultContainer);
802 aura::Window* CreateTestWindow(const gfx::Rect& bounds) {
803 aura::Window* window = CreateTestWindowInShellWithBounds(bounds);
804 return window;
807 // Turn the top window back drop on / off.
808 void ShowTopWindowBackdrop(bool show) {
809 scoped_ptr<ash::WorkspaceLayoutManagerDelegate> backdrop;
810 if (show) {
811 backdrop.reset(new ash::WorkspaceBackdropDelegate(default_container_));
813 (static_cast<WorkspaceLayoutManager*>(default_container_->layout_manager()))
814 ->SetMaximizeBackdropDelegate(backdrop.Pass());
815 // Closing and / or opening can be a delayed operation.
816 base::MessageLoop::current()->RunUntilIdle();
819 // Return the default container.
820 aura::Window* default_container() { return default_container_; }
822 // Return the order of windows (top most first) as they are in the default
823 // container. If the window is visible it will be a big letter, otherwise a
824 // small one. The backdrop will be an X and unknown windows will be shown as
825 // '!'.
826 std::string GetWindowOrderAsString(aura::Window* backdrop,
827 aura::Window* wa,
828 aura::Window* wb,
829 aura::Window* wc) {
830 std::string result;
831 for (int i = static_cast<int>(default_container()->children().size()) - 1;
832 i >= 0;
833 --i) {
834 if (!result.empty())
835 result += ",";
836 if (default_container()->children()[i] == wa)
837 result += default_container()->children()[i]->IsVisible() ? "A" : "a";
838 else if (default_container()->children()[i] == wb)
839 result += default_container()->children()[i]->IsVisible() ? "B" : "b";
840 else if (default_container()->children()[i] == wc)
841 result += default_container()->children()[i]->IsVisible() ? "C" : "c";
842 else if (default_container()->children()[i] == backdrop)
843 result += default_container()->children()[i]->IsVisible() ? "X" : "x";
844 else
845 result += "!";
847 return result;
850 private:
851 // The default container.
852 aura::Window* default_container_;
854 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerBackdropTest);
857 } // namespace
859 // Check that creating the BackDrop without destroying it does not lead into
860 // a crash.
861 TEST_F(WorkspaceLayoutManagerBackdropTest, BackdropCrashTest) {
862 ShowTopWindowBackdrop(true);
865 // Verify basic assumptions about the backdrop.
866 TEST_F(WorkspaceLayoutManagerBackdropTest, BasicBackdropTests) {
867 // Create a backdrop and see that there is one window (the backdrop) and
868 // that the size is the same as the default container as well as that it is
869 // not visible.
870 ShowTopWindowBackdrop(true);
871 ASSERT_EQ(1U, default_container()->children().size());
872 EXPECT_FALSE(default_container()->children()[0]->IsVisible());
875 // Add a window and make sure that the backdrop is the second child.
876 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4)));
877 window->Show();
878 ASSERT_EQ(2U, default_container()->children().size());
879 EXPECT_TRUE(default_container()->children()[0]->IsVisible());
880 EXPECT_TRUE(default_container()->children()[1]->IsVisible());
881 EXPECT_EQ(window.get(), default_container()->children()[1]);
882 EXPECT_EQ(default_container()->bounds().ToString(),
883 default_container()->children()[0]->bounds().ToString());
886 // With the window gone the backdrop should be invisible again.
887 ASSERT_EQ(1U, default_container()->children().size());
888 EXPECT_FALSE(default_container()->children()[0]->IsVisible());
890 // Destroying the Backdrop should empty the container.
891 ShowTopWindowBackdrop(false);
892 ASSERT_EQ(0U, default_container()->children().size());
895 // Verify that the backdrop gets properly created and placed.
896 TEST_F(WorkspaceLayoutManagerBackdropTest, VerifyBackdropAndItsStacking) {
897 scoped_ptr<aura::Window> window1(CreateTestWindow(gfx::Rect(1, 2, 3, 4)));
898 window1->Show();
900 // Get the default container and check that only a single window is in there.
901 ASSERT_EQ(1U, default_container()->children().size());
902 EXPECT_EQ(window1.get(), default_container()->children()[0]);
903 EXPECT_EQ("A", GetWindowOrderAsString(NULL, window1.get(), NULL, NULL));
905 // Create 2 more windows and check that they are also in the container.
906 scoped_ptr<aura::Window> window2(CreateTestWindow(gfx::Rect(10, 2, 3, 4)));
907 scoped_ptr<aura::Window> window3(CreateTestWindow(gfx::Rect(20, 2, 3, 4)));
908 window2->Show();
909 window3->Show();
911 aura::Window* backdrop = NULL;
912 EXPECT_EQ("C,B,A",
913 GetWindowOrderAsString(backdrop, window1.get(), window2.get(),
914 window3.get()));
916 // Turn on the backdrop mode and check that the window shows up where it
917 // should be (second highest number).
918 ShowTopWindowBackdrop(true);
919 backdrop = default_container()->children()[2];
920 EXPECT_EQ("C,X,B,A",
921 GetWindowOrderAsString(backdrop, window1.get(), window2.get(),
922 window3.get()));
924 // Switch the order of windows and check that it still remains in that
925 // location.
926 default_container()->StackChildAtTop(window2.get());
927 EXPECT_EQ("B,X,C,A",
928 GetWindowOrderAsString(backdrop, window1.get(), window2.get(),
929 window3.get()));
931 // Make the top window invisible and check.
932 window2.get()->Hide();
933 EXPECT_EQ("b,C,X,A",
934 GetWindowOrderAsString(backdrop, window1.get(), window2.get(),
935 window3.get()));
936 // Then delete window after window and see that everything is in order.
937 window1.reset();
938 EXPECT_EQ("b,C,X",
939 GetWindowOrderAsString(backdrop, window1.get(), window2.get(),
940 window3.get()));
941 window3.reset();
942 EXPECT_EQ("b,x",
943 GetWindowOrderAsString(backdrop, window1.get(), window2.get(),
944 window3.get()));
945 ShowTopWindowBackdrop(false);
946 EXPECT_EQ("b",
947 GetWindowOrderAsString(NULL, window1.get(), window2.get(),
948 window3.get()));
951 // Tests that when hidding the shelf, that the backdrop resizes to fill the
952 // entire workspace area.
953 TEST_F(WorkspaceLayoutManagerBackdropTest, ShelfVisibilityChangesBounds) {
954 ShelfLayoutManager* shelf_layout_manager =
955 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
956 ShowTopWindowBackdrop(true);
957 RunAllPendingInMessageLoop();
959 ASSERT_EQ(SHELF_VISIBLE, shelf_layout_manager->visibility_state());
960 gfx::Rect initial_bounds = default_container()->children()[0]->bounds();
961 shelf_layout_manager->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
962 shelf_layout_manager->UpdateVisibilityState();
964 // When the shelf is re-shown WorkspaceLayoutManager shrinks all children
965 // including the backdrop.
966 shelf_layout_manager->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
967 shelf_layout_manager->UpdateVisibilityState();
968 gfx::Rect reduced_bounds = default_container()->children()[0]->bounds();
969 EXPECT_LT(reduced_bounds.height(), initial_bounds.height());
971 shelf_layout_manager->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
972 shelf_layout_manager->UpdateVisibilityState();
974 EXPECT_GT(default_container()->children()[0]->bounds().height(),
975 reduced_bounds.height());
978 class WorkspaceLayoutManagerKeyboardTest : public test::AshTestBase {
979 public:
980 WorkspaceLayoutManagerKeyboardTest() {}
981 ~WorkspaceLayoutManagerKeyboardTest() override {}
983 void SetUp() override {
984 test::AshTestBase::SetUp();
985 UpdateDisplay("800x600");
986 aura::Window* default_container = Shell::GetContainer(
987 Shell::GetPrimaryRootWindow(), kShellWindowId_DefaultContainer);
988 layout_manager_ = static_cast<WorkspaceLayoutManager*>(
989 default_container->layout_manager());
992 aura::Window* CreateTestWindow(const gfx::Rect& bounds) {
993 return CreateTestWindowInShellWithBounds(bounds);
996 void ShowKeyboard() {
997 layout_manager_->OnKeyboardBoundsChanging(keyboard_bounds_);
998 restore_work_area_insets_ = Shell::GetScreen()->GetPrimaryDisplay().
999 GetWorkAreaInsets();
1000 Shell::GetInstance()->SetDisplayWorkAreaInsets(
1001 Shell::GetPrimaryRootWindow(),
1002 gfx::Insets(0, 0, keyboard_bounds_.height(), 0));
1005 void HideKeyboard() {
1006 Shell::GetInstance()->SetDisplayWorkAreaInsets(
1007 Shell::GetPrimaryRootWindow(),
1008 restore_work_area_insets_);
1009 layout_manager_->OnKeyboardBoundsChanging(gfx::Rect());
1012 void SetKeyboardBounds(const gfx::Rect& bounds) {
1013 keyboard_bounds_ = bounds;
1016 void Focus(ui::TextInputClient* text_input_client) {
1017 if (switches::IsTextInputFocusManagerEnabled()) {
1018 ui::TextInputFocusManager::GetInstance()->FocusTextInputClient(
1019 text_input_client);
1020 } else {
1021 aura::Window* root_window =
1022 ash::Shell::GetInstance()->GetPrimaryRootWindow();
1023 ui::InputMethod* input_method =
1024 root_window->GetProperty(aura::client::kRootWindowInputMethodKey);
1025 input_method->SetFocusedTextInputClient(text_input_client);
1029 void Blur(ui::TextInputClient* text_input_client) {
1030 if (switches::IsTextInputFocusManagerEnabled()) {
1031 ui::TextInputFocusManager::GetInstance()->BlurTextInputClient(
1032 text_input_client);
1033 } else {
1034 aura::Window* root_window =
1035 ash::Shell::GetInstance()->GetPrimaryRootWindow();
1036 ui::InputMethod* input_method =
1037 root_window->GetProperty(aura::client::kRootWindowInputMethodKey);
1038 input_method->SetFocusedTextInputClient(NULL);
1042 private:
1043 gfx::Insets restore_work_area_insets_;
1044 gfx::Rect keyboard_bounds_;
1045 WorkspaceLayoutManager* layout_manager_;
1047 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerKeyboardTest);
1050 class FakeTextInputClient : public ui::DummyTextInputClient {
1051 public:
1052 explicit FakeTextInputClient(gfx::NativeWindow window) : window_(window) {}
1053 ~FakeTextInputClient() override {}
1055 gfx::NativeWindow GetAttachedWindow() const override { return window_; }
1057 private:
1058 gfx::NativeWindow window_;
1060 DISALLOW_COPY_AND_ASSIGN(FakeTextInputClient);
1063 // Tests that when a child window gains focus the top level window containing it
1064 // is resized to fit the remaining workspace area.
1065 TEST_F(WorkspaceLayoutManagerKeyboardTest, ChildWindowFocused) {
1066 gfx::Rect work_area(
1067 Shell::GetScreen()->GetPrimaryDisplay().work_area());
1068 gfx::Rect keyboard_bounds(work_area.x(),
1069 work_area.y() + work_area.height() / 2,
1070 work_area.width(),
1071 work_area.height() / 2);
1073 SetKeyboardBounds(keyboard_bounds);
1075 aura::test::TestWindowDelegate delegate1;
1076 scoped_ptr<aura::Window> parent_window(CreateTestWindowInShellWithDelegate(
1077 &delegate1, -1, work_area));
1078 aura::test::TestWindowDelegate delegate2;
1079 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
1080 &delegate2, -1, work_area));
1081 parent_window->AddChild(window.get());
1083 FakeTextInputClient text_input_client(window.get());
1084 Focus(&text_input_client);
1086 int available_height =
1087 Shell::GetScreen()->GetPrimaryDisplay().bounds().height() -
1088 keyboard_bounds.height();
1090 gfx::Rect initial_window_bounds(50, 50, 100, 500);
1091 parent_window->SetBounds(initial_window_bounds);
1092 EXPECT_EQ(initial_window_bounds.ToString(),
1093 parent_window->bounds().ToString());
1094 ShowKeyboard();
1095 EXPECT_EQ(gfx::Rect(50, 0, 100, available_height).ToString(),
1096 parent_window->bounds().ToString());
1097 HideKeyboard();
1098 EXPECT_EQ(initial_window_bounds.ToString(),
1099 parent_window->bounds().ToString());
1101 Blur(&text_input_client);
1104 TEST_F(WorkspaceLayoutManagerKeyboardTest, AdjustWindowForA11yKeyboard) {
1105 gfx::Rect work_area(
1106 Shell::GetScreen()->GetPrimaryDisplay().work_area());
1107 gfx::Rect keyboard_bounds(work_area.x(),
1108 work_area.y() + work_area.height() / 2,
1109 work_area.width(),
1110 work_area.height() / 2);
1112 SetKeyboardBounds(keyboard_bounds);
1114 aura::test::TestWindowDelegate delegate;
1115 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
1116 &delegate, -1, work_area));
1118 FakeTextInputClient text_input_client(window.get());
1119 Focus(&text_input_client);
1121 int available_height =
1122 Shell::GetScreen()->GetPrimaryDisplay().bounds().height() -
1123 keyboard_bounds.height();
1125 EXPECT_EQ(gfx::Rect(work_area).ToString(), window->bounds().ToString());
1126 ShowKeyboard();
1127 EXPECT_EQ(gfx::Rect(work_area.origin(),
1128 gfx::Size(work_area.width(), available_height)).ToString(),
1129 window->bounds().ToString());
1130 HideKeyboard();
1131 EXPECT_EQ(gfx::Rect(work_area).ToString(), window->bounds().ToString());
1133 gfx::Rect small_window_bound(50, 50, 100, 500);
1134 window->SetBounds(small_window_bound);
1135 EXPECT_EQ(small_window_bound.ToString(), window->bounds().ToString());
1136 ShowKeyboard();
1137 EXPECT_EQ(gfx::Rect(50, 0, 100, available_height).ToString(),
1138 window->bounds().ToString());
1139 HideKeyboard();
1140 EXPECT_EQ(small_window_bound.ToString(), window->bounds().ToString());
1142 gfx::Rect occluded_window_bounds(50,
1143 keyboard_bounds.y() + keyboard_bounds.height()/2, 50,
1144 keyboard_bounds.height()/2);
1145 window->SetBounds(occluded_window_bounds);
1146 EXPECT_EQ(occluded_window_bounds.ToString(),
1147 occluded_window_bounds.ToString());
1148 ShowKeyboard();
1149 EXPECT_EQ(gfx::Rect(50,
1150 keyboard_bounds.y() - keyboard_bounds.height()/2,
1151 occluded_window_bounds.width(),
1152 occluded_window_bounds.height()).ToString(),
1153 window->bounds().ToString());
1154 HideKeyboard();
1155 EXPECT_EQ(occluded_window_bounds.ToString(), window->bounds().ToString());
1157 Blur(&text_input_client);
1160 } // namespace ash