146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// found in the LICENSE file.
446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "ash/display/display_manager.h"
646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "ash/root_window_controller.h"
746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "ash/screen_util.h"
846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "ash/shell.h"
946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "ash/shell_window_ids.h"
1046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "ash/test/ash_test_base.h"
1146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "ash/wm/window_state.h"
1246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "base/basictypes.h"
1346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "base/command_line.h"
1446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "ui/aura/client/aura_constants.h"
1546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "ui/aura/window.h"
1646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "ui/gfx/screen.h"
1746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "ui/keyboard/keyboard_controller.h"
1846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "ui/keyboard/keyboard_controller_proxy.h"
1946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "ui/keyboard/keyboard_switches.h"
2046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "ui/keyboard/keyboard_util.h"
2146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "ui/views/widget/widget.h"
226d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)#include "ui/views/widget/widget_delegate.h"
2346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
2446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)namespace ash {
2546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)namespace test {
2646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
2746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)namespace {
2846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
2946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)const int kVirtualKeyboardHeight = 100;
3046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
316d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)// A login implementation of WidgetDelegate.
326d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)class LoginTestWidgetDelegate : public views::WidgetDelegate {
336d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) public:
346d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  explicit LoginTestWidgetDelegate(views::Widget* widget) : widget_(widget) {
356d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  }
366d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  virtual ~LoginTestWidgetDelegate() {}
376d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
386d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // Overridden from WidgetDelegate:
396d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  virtual void DeleteDelegate() OVERRIDE {
406d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    delete this;
416d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  }
426d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  virtual views::Widget* GetWidget() OVERRIDE {
436d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    return widget_;
446d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  }
456d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  virtual const views::Widget* GetWidget() const OVERRIDE {
466d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    return widget_;
476d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  }
486d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  virtual bool CanActivate() const OVERRIDE {
496d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    return true;
506d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  }
516d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  virtual bool ShouldAdvanceFocusToTopLevelWidget() const OVERRIDE {
526d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    return true;
536d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  }
546d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
556d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) private:
566d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  views::Widget* widget_;
576d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
586d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(LoginTestWidgetDelegate);
596d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)};
606d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
6146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}  // namespace
6246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
6346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)class LockLayoutManagerTest : public AshTestBase {
6446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) public:
6546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  virtual void SetUp() OVERRIDE {
6646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    // Allow a virtual keyboard (and initialize it per default).
6746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    CommandLine::ForCurrentProcess()->AppendSwitch(
6846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)        keyboard::switches::kEnableVirtualKeyboard);
6946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    AshTestBase::SetUp();
7046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    Shell::GetPrimaryRootWindowController()->ActivateKeyboard(
7146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)        keyboard::KeyboardController::GetInstance());
7246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  }
7346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
7446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  virtual void TearDown() OVERRIDE {
7546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    Shell::GetPrimaryRootWindowController()->DeactivateKeyboard(
7646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)        keyboard::KeyboardController::GetInstance());
7746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    AshTestBase::TearDown();
7846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  }
7946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
806d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  aura::Window* CreateTestLoginWindow(views::Widget::InitParams params,
816d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)                                      bool use_delegate) {
8246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    aura::Window* parent = Shell::GetPrimaryRootWindowController()->
8346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)        GetContainer(ash::kShellWindowId_LockScreenContainer);
846d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    params.parent = parent;
856d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    views::Widget* widget = new views::Widget;
866d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    if (use_delegate)
876d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      params.delegate = new LoginTestWidgetDelegate(widget);
886d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    widget->Init(params);
8946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    widget->Show();
906d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    aura::Window* window = widget->GetNativeView();
916d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    return window;
9246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  }
9346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
9446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // Show or hide the keyboard.
9546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  void ShowKeyboard(bool show) {
9646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    keyboard::KeyboardController* keyboard =
9746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)        keyboard::KeyboardController::GetInstance();
9846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    ASSERT_TRUE(keyboard);
9946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    if (show == keyboard->keyboard_visible())
10046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      return;
10146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
10246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    if (show) {
10346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      keyboard->ShowKeyboard(true);
10446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      if (keyboard->proxy()->GetKeyboardWindow()->bounds().height() == 0) {
10546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)        keyboard->proxy()->GetKeyboardWindow()->SetBounds(
10646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)            keyboard::KeyboardBoundsFromWindowBounds(
10746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)                keyboard->GetContainerWindow()->bounds(),
10846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)                kVirtualKeyboardHeight));
10946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      }
11046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    } else {
11146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      keyboard->HideKeyboard(keyboard::KeyboardController::HIDE_REASON_MANUAL);
11246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    }
11346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
11446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    DCHECK_EQ(show, keyboard->keyboard_visible());
11546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  }
11646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)};
11746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
1186d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)TEST_F(LockLayoutManagerTest, NorwmalWindowBoundsArePreserved) {
11946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  gfx::Rect screen_bounds = Shell::GetScreen()->GetPrimaryDisplay().bounds();
12046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
1216d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  views::Widget::InitParams widget_params(
1226d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      views::Widget::InitParams::TYPE_WINDOW);
1236d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  const gfx::Rect bounds = gfx::Rect(10, 10, 300, 300);
1246d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  widget_params.bounds = bounds;
12546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  scoped_ptr<aura::Window> window(
1266d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      CreateTestLoginWindow(widget_params, false /* use_delegate */));
1276d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  EXPECT_EQ(bounds.ToString(), window->GetBoundsInScreen().ToString());
12846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
12946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  gfx::Rect work_area =
13046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      ScreenUtil::GetDisplayWorkAreaBoundsInParent(window.get());
13146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  window->SetBounds(work_area);
13246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
1336d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  EXPECT_EQ(work_area.ToString(), window->GetBoundsInScreen().ToString());
1346d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  EXPECT_NE(screen_bounds.ToString(), window->GetBoundsInScreen().ToString());
13546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
1366d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  const gfx::Rect bounds2 = gfx::Rect(100, 100, 200, 200);
1376d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  window->SetBounds(bounds2);
1386d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  EXPECT_EQ(bounds2.ToString(), window->GetBoundsInScreen().ToString());
1396d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)}
1406d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
1416d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)TEST_F(LockLayoutManagerTest, MaximizedFullscreenWindowBoundsAreEqualToScreen) {
1426d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  gfx::Rect screen_bounds = Shell::GetScreen()->GetPrimaryDisplay().bounds();
1436d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
1446d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  views::Widget::InitParams widget_params(
1456d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
1466d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  widget_params.show_state = ui::SHOW_STATE_MAXIMIZED;
1476d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  const gfx::Rect bounds = gfx::Rect(10, 10, 300, 300);
1486d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  widget_params.bounds = bounds;
1496d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // Maximized TYPE_WINDOW_FRAMELESS windows needs a delegate defined otherwise
1506d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // it won't get initial SetBounds event.
1516d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  scoped_ptr<aura::Window> maximized_window(
1526d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      CreateTestLoginWindow(widget_params, true /* use_delegate */));
1536d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
1546d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  widget_params.show_state = ui::SHOW_STATE_FULLSCREEN;
1556d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  widget_params.delegate = NULL;
1566d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  scoped_ptr<aura::Window> fullscreen_window(
1576d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      CreateTestLoginWindow(widget_params, false  /* use_delegate */));
1586d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
1596d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  EXPECT_EQ(screen_bounds.ToString(),
1606d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)            maximized_window->GetBoundsInScreen().ToString());
1616d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  EXPECT_EQ(screen_bounds.ToString(),
1626d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)            fullscreen_window->GetBoundsInScreen().ToString());
1636d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
1646d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  gfx::Rect work_area =
1656d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      ScreenUtil::GetDisplayWorkAreaBoundsInParent(maximized_window.get());
1666d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  maximized_window->SetBounds(work_area);
1676d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
1686d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  EXPECT_NE(work_area.ToString(),
1696d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)            maximized_window->GetBoundsInScreen().ToString());
1706d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  EXPECT_EQ(screen_bounds.ToString(),
1716d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)            maximized_window->GetBoundsInScreen().ToString());
1726d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
1736d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  work_area =
1746d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      ScreenUtil::GetDisplayWorkAreaBoundsInParent(fullscreen_window.get());
1756d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  fullscreen_window->SetBounds(work_area);
1766d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  EXPECT_NE(work_area.ToString(),
1776d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)            fullscreen_window->GetBoundsInScreen().ToString());
1786d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  EXPECT_EQ(screen_bounds.ToString(),
1796d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)            fullscreen_window->GetBoundsInScreen().ToString());
1806d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
1816d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  const gfx::Rect bounds2 = gfx::Rect(100, 100, 200, 200);
1826d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  maximized_window->SetBounds(bounds2);
1836d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  fullscreen_window->SetBounds(bounds2);
1846d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  EXPECT_EQ(screen_bounds.ToString(),
1856d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)            maximized_window->GetBoundsInScreen().ToString());
1866d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  EXPECT_EQ(screen_bounds.ToString(),
1876d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)            fullscreen_window->GetBoundsInScreen().ToString());
18846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
18946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
19046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)TEST_F(LockLayoutManagerTest, KeyboardBounds) {
19103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay();
19203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  gfx::Rect screen_bounds = primary_display.bounds();
19346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
1946d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  views::Widget::InitParams widget_params(
1956d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
1966d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  widget_params.show_state = ui::SHOW_STATE_FULLSCREEN;
1976d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  scoped_ptr<aura::Window> window(
1986d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      CreateTestLoginWindow(widget_params, false /* use_delegate */));
1996d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
20046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString());
20146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
20246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // When virtual keyboard overscroll is enabled keyboard bounds should not
20346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // affect window bounds.
20446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  keyboard::SetKeyboardOverscrollOverride(
20546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)       keyboard::KEYBOARD_OVERSCROLL_OVERRIDE_ENABLED);
20646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  ShowKeyboard(true);
20746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString());
20803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  gfx::Rect keyboard_bounds =
20903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      keyboard::KeyboardController::GetInstance()->current_keyboard_bounds();
21003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  EXPECT_NE(keyboard_bounds, gfx::Rect());
21146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  ShowKeyboard(false);
21246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
21303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // When keyboard is hidden make sure that rotating the screen gives 100% of
21403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // screen size to window.
21503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // Repro steps for http://crbug.com/401667:
21603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // 1. Set up login screen defaults: VK override disabled
21703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // 2. Show/hide keyboard, make sure that no stale keyboard bounds are cached.
21803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  keyboard::SetKeyboardOverscrollOverride(
21903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)       keyboard::KEYBOARD_OVERSCROLL_OVERRIDE_DISABLED);
22003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  ShowKeyboard(true);
22103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  ShowKeyboard(false);
22203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  ash::DisplayManager* display_manager =
22303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      Shell::GetInstance()->display_manager();
22403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  display_manager->SetDisplayRotation(primary_display.id(),
22503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)                                      gfx::Display::ROTATE_90);
22603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  primary_display = Shell::GetScreen()->GetPrimaryDisplay();
22703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  screen_bounds = primary_display.bounds();
22803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString());
22903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  display_manager->SetDisplayRotation(primary_display.id(),
23003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)                                      gfx::Display::ROTATE_0);
23103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
23246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // When virtual keyboard overscroll is disabled keyboard bounds do
23346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // affect window bounds.
23446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  keyboard::SetKeyboardOverscrollOverride(
23546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)       keyboard::KEYBOARD_OVERSCROLL_OVERRIDE_DISABLED);
23646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  ShowKeyboard(true);
23746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  keyboard::KeyboardController* keyboard =
23846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)        keyboard::KeyboardController::GetInstance();
23903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  primary_display = Shell::GetScreen()->GetPrimaryDisplay();
24003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  screen_bounds = primary_display.bounds();
24146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  gfx::Rect target_bounds(screen_bounds);
24246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  target_bounds.set_height(target_bounds.height() -
24346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      keyboard->proxy()->GetKeyboardWindow()->bounds().height());
24446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  EXPECT_EQ(target_bounds.ToString(), window->GetBoundsInScreen().ToString());
24546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  ShowKeyboard(false);
24646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
24746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  keyboard::SetKeyboardOverscrollOverride(
24846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      keyboard::KEYBOARD_OVERSCROLL_OVERRIDE_NONE);
24946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
25046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
25146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)TEST_F(LockLayoutManagerTest, MultipleMonitors) {
25246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  if (!SupportsMultipleDisplays())
25346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    return;
25446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
25546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  UpdateDisplay("300x400,400x500");
2566d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  gfx::Rect screen_bounds = Shell::GetScreen()->GetPrimaryDisplay().bounds();
25746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  aura::Window::Windows root_windows = Shell::GetAllRootWindows();
25846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
2596d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  views::Widget::InitParams widget_params(
2606d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
2616d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  widget_params.show_state = ui::SHOW_STATE_FULLSCREEN;
2626d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  scoped_ptr<aura::Window> window(
2636d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      CreateTestLoginWindow(widget_params, false /* use_delegate */));
2646d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  window->SetProperty(aura::client::kCanMaximizeKey, true);
2656d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
26646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString());
26746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
26846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  EXPECT_EQ(root_windows[0], window->GetRootWindow());
26946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
27046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  wm::WindowState* window_state = wm::GetWindowState(window.get());
27146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  window_state->SetRestoreBoundsInScreen(gfx::Rect(400, 0, 30, 40));
27246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
27346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // Maximize the window with as the restore bounds is inside 2nd display but
27446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // lock container windows are always on primary display.
27546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
27646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  EXPECT_EQ(root_windows[0], window->GetRootWindow());
27746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  EXPECT_EQ("0,0 300x400", window->GetBoundsInScreen().ToString());
27846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
27946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  window_state->Restore();
28046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  EXPECT_EQ(root_windows[0], window->GetRootWindow());
28146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  EXPECT_EQ("0,0 300x400", window->GetBoundsInScreen().ToString());
28246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
28346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  window_state->SetRestoreBoundsInScreen(gfx::Rect(280, 0, 30, 40));
28446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
28546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  EXPECT_EQ(root_windows[0], window->GetRootWindow());
28646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  EXPECT_EQ("0,0 300x400", window->GetBoundsInScreen().ToString());
28746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
28846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  window_state->Restore();
28946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  EXPECT_EQ(root_windows[0], window->GetRootWindow());
29046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  EXPECT_EQ("0,0 300x400", window->GetBoundsInScreen().ToString());
29146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
29246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  gfx::Rect work_area =
29346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      ScreenUtil::GetDisplayWorkAreaBoundsInParent(window.get());
29446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  window->SetBounds(work_area);
29546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // Usually work_area takes Shelf into account but that doesn't affect
29646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // LockScreen container windows.
29746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  EXPECT_NE(work_area.ToString(), window->GetBoundsInScreen().ToString());
29846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString());
29946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
30046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
30146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}  // namespace test
30246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}  // namespace ash
303