OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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. |
| 4 |
| 5 #include "ash/root_window_controller.h" |
| 6 #include "ash/screen_util.h" |
| 7 #include "ash/shell.h" |
| 8 #include "ash/shell_window_ids.h" |
| 9 #include "ash/test/ash_test_base.h" |
| 10 #include "ash/wm/window_state.h" |
| 11 #include "base/basictypes.h" |
| 12 #include "base/command_line.h" |
| 13 #include "ui/aura/client/aura_constants.h" |
| 14 #include "ui/aura/window.h" |
| 15 #include "ui/gfx/screen.h" |
| 16 #include "ui/keyboard/keyboard_controller.h" |
| 17 #include "ui/keyboard/keyboard_controller_proxy.h" |
| 18 #include "ui/keyboard/keyboard_switches.h" |
| 19 #include "ui/keyboard/keyboard_util.h" |
| 20 #include "ui/views/widget/widget.h" |
| 21 |
| 22 namespace ash { |
| 23 namespace test { |
| 24 |
| 25 namespace { |
| 26 |
| 27 const int kVirtualKeyboardHeight = 100; |
| 28 |
| 29 } // namespace |
| 30 |
| 31 class LockLayoutManagerTest : public AshTestBase { |
| 32 public: |
| 33 virtual void SetUp() OVERRIDE { |
| 34 // Allow a virtual keyboard (and initialize it per default). |
| 35 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 36 keyboard::switches::kEnableVirtualKeyboard); |
| 37 AshTestBase::SetUp(); |
| 38 Shell::GetPrimaryRootWindowController()->ActivateKeyboard( |
| 39 keyboard::KeyboardController::GetInstance()); |
| 40 } |
| 41 |
| 42 virtual void TearDown() OVERRIDE { |
| 43 Shell::GetPrimaryRootWindowController()->DeactivateKeyboard( |
| 44 keyboard::KeyboardController::GetInstance()); |
| 45 AshTestBase::TearDown(); |
| 46 } |
| 47 |
| 48 aura::Window* CreateTestLoginWindowWithBounds(const gfx::Rect& bounds) { |
| 49 aura::Window* parent = Shell::GetPrimaryRootWindowController()-> |
| 50 GetContainer(ash::kShellWindowId_LockScreenContainer); |
| 51 views::Widget* widget = |
| 52 views::Widget::CreateWindowWithParentAndBounds(NULL, parent, bounds); |
| 53 widget->Show(); |
| 54 return widget->GetNativeView(); |
| 55 } |
| 56 |
| 57 // Show or hide the keyboard. |
| 58 void ShowKeyboard(bool show) { |
| 59 keyboard::KeyboardController* keyboard = |
| 60 keyboard::KeyboardController::GetInstance(); |
| 61 ASSERT_TRUE(keyboard); |
| 62 if (show == keyboard->keyboard_visible()) |
| 63 return; |
| 64 |
| 65 if (show) { |
| 66 keyboard->ShowKeyboard(true); |
| 67 if (keyboard->proxy()->GetKeyboardWindow()->bounds().height() == 0) { |
| 68 keyboard->proxy()->GetKeyboardWindow()->SetBounds( |
| 69 keyboard::KeyboardBoundsFromWindowBounds( |
| 70 keyboard->GetContainerWindow()->bounds(), |
| 71 kVirtualKeyboardHeight)); |
| 72 } |
| 73 } else { |
| 74 keyboard->HideKeyboard(keyboard::KeyboardController::HIDE_REASON_MANUAL); |
| 75 } |
| 76 |
| 77 DCHECK_EQ(show, keyboard->keyboard_visible()); |
| 78 } |
| 79 }; |
| 80 |
| 81 TEST_F(LockLayoutManagerTest, WindowBoundsAreEqualToScreen) { |
| 82 gfx::Rect screen_bounds = Shell::GetScreen()->GetPrimaryDisplay().bounds(); |
| 83 |
| 84 scoped_ptr<aura::Window> window( |
| 85 CreateTestLoginWindowWithBounds(gfx::Rect(10, 10, 300, 300))); |
| 86 EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 87 |
| 88 gfx::Rect work_area = |
| 89 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window.get()); |
| 90 window->SetBounds(work_area); |
| 91 |
| 92 // Usually work_area takes Shelf into account but that doesn't affect |
| 93 // LockScreen container windows. |
| 94 EXPECT_NE(work_area.ToString(), window->GetBoundsInScreen().ToString()); |
| 95 EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 96 |
| 97 window->SetBounds(gfx::Rect(100, 100, 200, 200)); |
| 98 EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 99 } |
| 100 |
| 101 TEST_F(LockLayoutManagerTest, KeyboardBounds) { |
| 102 gfx::Rect screen_bounds = Shell::GetScreen()->GetPrimaryDisplay().bounds(); |
| 103 |
| 104 scoped_ptr<aura::Window> window(CreateTestLoginWindowWithBounds(gfx::Rect())); |
| 105 EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 106 |
| 107 // When virtual keyboard overscroll is enabled keyboard bounds should not |
| 108 // affect window bounds. |
| 109 keyboard::SetKeyboardOverscrollOverride( |
| 110 keyboard::KEYBOARD_OVERSCROLL_OVERRIDE_ENABLED); |
| 111 ShowKeyboard(true); |
| 112 EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 113 ShowKeyboard(false); |
| 114 |
| 115 // When virtual keyboard overscroll is disabled keyboard bounds do |
| 116 // affect window bounds. |
| 117 keyboard::SetKeyboardOverscrollOverride( |
| 118 keyboard::KEYBOARD_OVERSCROLL_OVERRIDE_DISABLED); |
| 119 ShowKeyboard(true); |
| 120 keyboard::KeyboardController* keyboard = |
| 121 keyboard::KeyboardController::GetInstance(); |
| 122 gfx::Rect target_bounds(screen_bounds); |
| 123 target_bounds.set_height(target_bounds.height() - |
| 124 keyboard->proxy()->GetKeyboardWindow()->bounds().height()); |
| 125 EXPECT_EQ(target_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 126 ShowKeyboard(false); |
| 127 |
| 128 keyboard::SetKeyboardOverscrollOverride( |
| 129 keyboard::KEYBOARD_OVERSCROLL_OVERRIDE_NONE); |
| 130 } |
| 131 |
| 132 TEST_F(LockLayoutManagerTest, MultipleMonitors) { |
| 133 if (!SupportsMultipleDisplays()) |
| 134 return; |
| 135 |
| 136 UpdateDisplay("300x400,400x500"); |
| 137 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 138 |
| 139 gfx::Rect screen_bounds = Shell::GetScreen()->GetPrimaryDisplay().bounds(); |
| 140 scoped_ptr<aura::Window> window(CreateTestLoginWindowWithBounds(gfx::Rect())); |
| 141 EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 142 |
| 143 EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
| 144 |
| 145 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 146 window_state->SetRestoreBoundsInScreen(gfx::Rect(400, 0, 30, 40)); |
| 147 |
| 148 // Maximize the window with as the restore bounds is inside 2nd display but |
| 149 // lock container windows are always on primary display. |
| 150 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
| 151 EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
| 152 EXPECT_EQ("0,0 300x400", window->GetBoundsInScreen().ToString()); |
| 153 |
| 154 window_state->Restore(); |
| 155 EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
| 156 EXPECT_EQ("0,0 300x400", window->GetBoundsInScreen().ToString()); |
| 157 |
| 158 window_state->SetRestoreBoundsInScreen(gfx::Rect(280, 0, 30, 40)); |
| 159 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
| 160 EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
| 161 EXPECT_EQ("0,0 300x400", window->GetBoundsInScreen().ToString()); |
| 162 |
| 163 window_state->Restore(); |
| 164 EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
| 165 EXPECT_EQ("0,0 300x400", window->GetBoundsInScreen().ToString()); |
| 166 |
| 167 gfx::Rect work_area = |
| 168 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window.get()); |
| 169 window->SetBounds(work_area); |
| 170 // Usually work_area takes Shelf into account but that doesn't affect |
| 171 // LockScreen container windows. |
| 172 EXPECT_NE(work_area.ToString(), window->GetBoundsInScreen().ToString()); |
| 173 EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 174 } |
| 175 |
| 176 } // namespace test |
| 177 } // namespace ash |
OLD | NEW |