Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/root_window_controller.h" | 5 #include "ash/root_window_controller.h" |
| 6 #include "ash/screen_util.h" | 6 #include "ash/screen_util.h" |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
| 9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
| 10 #include "ash/wm/window_state.h" | 10 #include "ash/wm/window_state.h" |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "ui/aura/client/aura_constants.h" | 13 #include "ui/aura/client/aura_constants.h" |
| 14 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 15 #include "ui/gfx/screen.h" | 15 #include "ui/gfx/screen.h" |
| 16 #include "ui/keyboard/keyboard_controller.h" | 16 #include "ui/keyboard/keyboard_controller.h" |
| 17 #include "ui/keyboard/keyboard_controller_proxy.h" | 17 #include "ui/keyboard/keyboard_controller_proxy.h" |
| 18 #include "ui/keyboard/keyboard_switches.h" | 18 #include "ui/keyboard/keyboard_switches.h" |
| 19 #include "ui/keyboard/keyboard_util.h" | 19 #include "ui/keyboard/keyboard_util.h" |
| 20 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
| 21 #include "ui/views/widget/widget_delegate.h" | |
| 21 | 22 |
| 22 namespace ash { | 23 namespace ash { |
| 23 namespace test { | 24 namespace test { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 const int kVirtualKeyboardHeight = 100; | 28 const int kVirtualKeyboardHeight = 100; |
| 28 | 29 |
| 30 // A login implementation of WidgetDelegate. | |
| 31 class LoginTestWidgetDelegate : public views::WidgetDelegate { | |
| 32 public: | |
| 33 explicit LoginTestWidgetDelegate(views::Widget* widget) : widget_(widget) { | |
| 34 } | |
| 35 virtual ~LoginTestWidgetDelegate() {} | |
| 36 | |
| 37 // Overridden from WidgetDelegate: | |
| 38 virtual void DeleteDelegate() OVERRIDE { | |
| 39 delete this; | |
| 40 } | |
| 41 virtual views::Widget* GetWidget() OVERRIDE { | |
| 42 return widget_; | |
| 43 } | |
| 44 virtual const views::Widget* GetWidget() const OVERRIDE { | |
| 45 return widget_; | |
| 46 } | |
| 47 virtual bool CanActivate() const OVERRIDE { | |
| 48 return true; | |
| 49 } | |
| 50 virtual bool ShouldAdvanceFocusToTopLevelWidget() const OVERRIDE { | |
| 51 return true; | |
| 52 } | |
| 53 | |
| 54 private: | |
| 55 views::Widget* widget_; | |
| 56 | |
| 57 DISALLOW_COPY_AND_ASSIGN(LoginTestWidgetDelegate); | |
| 58 }; | |
|
oshima
2014/06/19 20:50:01
It looks to me that this is same as default widget
Nikita (slow)
2014/06/20 03:45:45
Yes, but it has to be explicitly set for TYPE_WIND
| |
| 59 | |
| 29 } // namespace | 60 } // namespace |
| 30 | 61 |
| 31 class LockLayoutManagerTest : public AshTestBase { | 62 class LockLayoutManagerTest : public AshTestBase { |
| 32 public: | 63 public: |
| 33 virtual void SetUp() OVERRIDE { | 64 virtual void SetUp() OVERRIDE { |
| 34 // Allow a virtual keyboard (and initialize it per default). | 65 // Allow a virtual keyboard (and initialize it per default). |
| 35 CommandLine::ForCurrentProcess()->AppendSwitch( | 66 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 36 keyboard::switches::kEnableVirtualKeyboard); | 67 keyboard::switches::kEnableVirtualKeyboard); |
| 37 AshTestBase::SetUp(); | 68 AshTestBase::SetUp(); |
| 38 Shell::GetPrimaryRootWindowController()->ActivateKeyboard( | 69 Shell::GetPrimaryRootWindowController()->ActivateKeyboard( |
| 39 keyboard::KeyboardController::GetInstance()); | 70 keyboard::KeyboardController::GetInstance()); |
| 40 } | 71 } |
| 41 | 72 |
| 42 virtual void TearDown() OVERRIDE { | 73 virtual void TearDown() OVERRIDE { |
| 43 Shell::GetPrimaryRootWindowController()->DeactivateKeyboard( | 74 Shell::GetPrimaryRootWindowController()->DeactivateKeyboard( |
| 44 keyboard::KeyboardController::GetInstance()); | 75 keyboard::KeyboardController::GetInstance()); |
| 45 AshTestBase::TearDown(); | 76 AshTestBase::TearDown(); |
| 46 } | 77 } |
| 47 | 78 |
| 48 aura::Window* CreateTestLoginWindowWithBounds(const gfx::Rect& bounds) { | 79 aura::Window* CreateTestLoginWindow(views::Widget::InitParams params, |
| 80 bool use_delegate) { | |
| 49 aura::Window* parent = Shell::GetPrimaryRootWindowController()-> | 81 aura::Window* parent = Shell::GetPrimaryRootWindowController()-> |
| 50 GetContainer(ash::kShellWindowId_LockScreenContainer); | 82 GetContainer(ash::kShellWindowId_LockScreenContainer); |
| 51 views::Widget* widget = | 83 params.parent = parent; |
| 52 views::Widget::CreateWindowWithParentAndBounds(NULL, parent, bounds); | 84 views::Widget* widget = new views::Widget; |
| 85 if (use_delegate) | |
| 86 params.delegate = new LoginTestWidgetDelegate(widget); | |
| 87 widget->Init(params); | |
| 53 widget->Show(); | 88 widget->Show(); |
| 54 return widget->GetNativeView(); | 89 aura::Window* window = widget->GetNativeView(); |
| 90 return window; | |
| 55 } | 91 } |
| 56 | 92 |
| 57 // Show or hide the keyboard. | 93 // Show or hide the keyboard. |
| 58 void ShowKeyboard(bool show) { | 94 void ShowKeyboard(bool show) { |
| 59 keyboard::KeyboardController* keyboard = | 95 keyboard::KeyboardController* keyboard = |
| 60 keyboard::KeyboardController::GetInstance(); | 96 keyboard::KeyboardController::GetInstance(); |
| 61 ASSERT_TRUE(keyboard); | 97 ASSERT_TRUE(keyboard); |
| 62 if (show == keyboard->keyboard_visible()) | 98 if (show == keyboard->keyboard_visible()) |
| 63 return; | 99 return; |
| 64 | 100 |
| 65 if (show) { | 101 if (show) { |
| 66 keyboard->ShowKeyboard(true); | 102 keyboard->ShowKeyboard(true); |
| 67 if (keyboard->proxy()->GetKeyboardWindow()->bounds().height() == 0) { | 103 if (keyboard->proxy()->GetKeyboardWindow()->bounds().height() == 0) { |
| 68 keyboard->proxy()->GetKeyboardWindow()->SetBounds( | 104 keyboard->proxy()->GetKeyboardWindow()->SetBounds( |
| 69 keyboard::KeyboardBoundsFromWindowBounds( | 105 keyboard::KeyboardBoundsFromWindowBounds( |
| 70 keyboard->GetContainerWindow()->bounds(), | 106 keyboard->GetContainerWindow()->bounds(), |
| 71 kVirtualKeyboardHeight)); | 107 kVirtualKeyboardHeight)); |
| 72 } | 108 } |
| 73 } else { | 109 } else { |
| 74 keyboard->HideKeyboard(keyboard::KeyboardController::HIDE_REASON_MANUAL); | 110 keyboard->HideKeyboard(keyboard::KeyboardController::HIDE_REASON_MANUAL); |
| 75 } | 111 } |
| 76 | 112 |
| 77 DCHECK_EQ(show, keyboard->keyboard_visible()); | 113 DCHECK_EQ(show, keyboard->keyboard_visible()); |
| 78 } | 114 } |
| 79 }; | 115 }; |
| 80 | 116 |
| 81 TEST_F(LockLayoutManagerTest, WindowBoundsAreEqualToScreen) { | 117 TEST_F(LockLayoutManagerTest, NorwmalWindowBoundsArePreserved) { |
| 82 gfx::Rect screen_bounds = Shell::GetScreen()->GetPrimaryDisplay().bounds(); | 118 gfx::Rect screen_bounds = Shell::GetScreen()->GetPrimaryDisplay().bounds(); |
| 83 | 119 |
| 120 views::Widget::InitParams widget_params( | |
| 121 views::Widget::InitParams::TYPE_WINDOW); | |
| 122 const gfx::Rect bounds = gfx::Rect(10, 10, 300, 300); | |
| 123 widget_params.bounds = bounds; | |
| 84 scoped_ptr<aura::Window> window( | 124 scoped_ptr<aura::Window> window( |
| 85 CreateTestLoginWindowWithBounds(gfx::Rect(10, 10, 300, 300))); | 125 CreateTestLoginWindow(widget_params, false /* use_delegate */)); |
| 86 EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString()); | 126 EXPECT_EQ(bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 87 | 127 |
| 88 gfx::Rect work_area = | 128 gfx::Rect work_area = |
| 89 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window.get()); | 129 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window.get()); |
| 90 window->SetBounds(work_area); | 130 window->SetBounds(work_area); |
| 91 | 131 |
| 92 // Usually work_area takes Shelf into account but that doesn't affect | 132 EXPECT_EQ(work_area.ToString(), window->GetBoundsInScreen().ToString()); |
| 93 // LockScreen container windows. | 133 EXPECT_NE(screen_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 94 EXPECT_NE(work_area.ToString(), window->GetBoundsInScreen().ToString()); | |
| 95 EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString()); | |
| 96 | 134 |
| 97 window->SetBounds(gfx::Rect(100, 100, 200, 200)); | 135 const gfx::Rect bounds2 = gfx::Rect(100, 100, 200, 200); |
| 98 EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString()); | 136 window->SetBounds(bounds2); |
| 137 EXPECT_EQ(bounds2.ToString(), window->GetBoundsInScreen().ToString()); | |
| 138 } | |
| 139 | |
| 140 TEST_F(LockLayoutManagerTest, MaximizedFullscreenWindowBoundsAreEqualToScreen) { | |
| 141 gfx::Rect screen_bounds = Shell::GetScreen()->GetPrimaryDisplay().bounds(); | |
| 142 | |
| 143 views::Widget::InitParams widget_params( | |
| 144 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
| 145 widget_params.show_state = ui::SHOW_STATE_MAXIMIZED; | |
| 146 const gfx::Rect bounds = gfx::Rect(10, 10, 300, 300); | |
| 147 widget_params.bounds = bounds; | |
| 148 // Maximized TYPE_WINDOW_FRAMELESS windows needs a delegate defined otherwise | |
| 149 // it won't get initial SetBounds event. | |
| 150 scoped_ptr<aura::Window> maximized_window( | |
| 151 CreateTestLoginWindow(widget_params, true /* use_delegate */)); | |
| 152 | |
| 153 widget_params.show_state = ui::SHOW_STATE_FULLSCREEN; | |
| 154 widget_params.delegate = NULL; | |
| 155 scoped_ptr<aura::Window> fullscreen_window( | |
| 156 CreateTestLoginWindow(widget_params, false /* use_delegate */)); | |
| 157 | |
| 158 EXPECT_EQ(screen_bounds.ToString(), | |
| 159 maximized_window->GetBoundsInScreen().ToString()); | |
| 160 EXPECT_EQ(screen_bounds.ToString(), | |
| 161 fullscreen_window->GetBoundsInScreen().ToString()); | |
| 162 | |
| 163 gfx::Rect work_area = | |
| 164 ScreenUtil::GetDisplayWorkAreaBoundsInParent(maximized_window.get()); | |
| 165 maximized_window->SetBounds(work_area); | |
| 166 | |
| 167 EXPECT_NE(work_area.ToString(), | |
| 168 maximized_window->GetBoundsInScreen().ToString()); | |
| 169 EXPECT_EQ(screen_bounds.ToString(), | |
| 170 maximized_window->GetBoundsInScreen().ToString()); | |
| 171 | |
| 172 work_area = | |
| 173 ScreenUtil::GetDisplayWorkAreaBoundsInParent(fullscreen_window.get()); | |
| 174 fullscreen_window->SetBounds(work_area); | |
| 175 EXPECT_NE(work_area.ToString(), | |
| 176 fullscreen_window->GetBoundsInScreen().ToString()); | |
| 177 EXPECT_EQ(screen_bounds.ToString(), | |
| 178 fullscreen_window->GetBoundsInScreen().ToString()); | |
| 179 | |
| 180 const gfx::Rect bounds2 = gfx::Rect(100, 100, 200, 200); | |
| 181 maximized_window->SetBounds(bounds2); | |
| 182 fullscreen_window->SetBounds(bounds2); | |
| 183 EXPECT_EQ(screen_bounds.ToString(), | |
| 184 maximized_window->GetBoundsInScreen().ToString()); | |
| 185 EXPECT_EQ(screen_bounds.ToString(), | |
| 186 fullscreen_window->GetBoundsInScreen().ToString()); | |
| 99 } | 187 } |
| 100 | 188 |
| 101 TEST_F(LockLayoutManagerTest, KeyboardBounds) { | 189 TEST_F(LockLayoutManagerTest, KeyboardBounds) { |
| 102 gfx::Rect screen_bounds = Shell::GetScreen()->GetPrimaryDisplay().bounds(); | 190 gfx::Rect screen_bounds = Shell::GetScreen()->GetPrimaryDisplay().bounds(); |
| 103 | 191 |
| 104 scoped_ptr<aura::Window> window(CreateTestLoginWindowWithBounds(gfx::Rect())); | 192 views::Widget::InitParams widget_params( |
| 193 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
| 194 widget_params.show_state = ui::SHOW_STATE_FULLSCREEN; | |
| 195 scoped_ptr<aura::Window> window( | |
| 196 CreateTestLoginWindow(widget_params, false /* use_delegate */)); | |
| 197 | |
| 105 EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString()); | 198 EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 106 | 199 |
| 107 // When virtual keyboard overscroll is enabled keyboard bounds should not | 200 // When virtual keyboard overscroll is enabled keyboard bounds should not |
| 108 // affect window bounds. | 201 // affect window bounds. |
| 109 keyboard::SetKeyboardOverscrollOverride( | 202 keyboard::SetKeyboardOverscrollOverride( |
| 110 keyboard::KEYBOARD_OVERSCROLL_OVERRIDE_ENABLED); | 203 keyboard::KEYBOARD_OVERSCROLL_OVERRIDE_ENABLED); |
| 111 ShowKeyboard(true); | 204 ShowKeyboard(true); |
| 112 EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString()); | 205 EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 113 ShowKeyboard(false); | 206 ShowKeyboard(false); |
| 114 | 207 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 127 | 220 |
| 128 keyboard::SetKeyboardOverscrollOverride( | 221 keyboard::SetKeyboardOverscrollOverride( |
| 129 keyboard::KEYBOARD_OVERSCROLL_OVERRIDE_NONE); | 222 keyboard::KEYBOARD_OVERSCROLL_OVERRIDE_NONE); |
| 130 } | 223 } |
| 131 | 224 |
| 132 TEST_F(LockLayoutManagerTest, MultipleMonitors) { | 225 TEST_F(LockLayoutManagerTest, MultipleMonitors) { |
| 133 if (!SupportsMultipleDisplays()) | 226 if (!SupportsMultipleDisplays()) |
| 134 return; | 227 return; |
| 135 | 228 |
| 136 UpdateDisplay("300x400,400x500"); | 229 UpdateDisplay("300x400,400x500"); |
| 230 gfx::Rect screen_bounds = Shell::GetScreen()->GetPrimaryDisplay().bounds(); | |
| 137 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 231 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 138 | 232 |
| 139 gfx::Rect screen_bounds = Shell::GetScreen()->GetPrimaryDisplay().bounds(); | 233 views::Widget::InitParams widget_params( |
| 140 scoped_ptr<aura::Window> window(CreateTestLoginWindowWithBounds(gfx::Rect())); | 234 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 235 widget_params.show_state = ui::SHOW_STATE_FULLSCREEN; | |
| 236 scoped_ptr<aura::Window> window( | |
| 237 CreateTestLoginWindow(widget_params, false /* use_delegate */)); | |
| 238 window->SetProperty(aura::client::kCanMaximizeKey, true); | |
| 239 | |
| 141 EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString()); | 240 EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 142 | 241 |
| 143 EXPECT_EQ(root_windows[0], window->GetRootWindow()); | 242 EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
| 144 | 243 |
| 145 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 244 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 146 window_state->SetRestoreBoundsInScreen(gfx::Rect(400, 0, 30, 40)); | 245 window_state->SetRestoreBoundsInScreen(gfx::Rect(400, 0, 30, 40)); |
| 147 | 246 |
| 148 // Maximize the window with as the restore bounds is inside 2nd display but | 247 // Maximize the window with as the restore bounds is inside 2nd display but |
| 149 // lock container windows are always on primary display. | 248 // lock container windows are always on primary display. |
| 150 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 249 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 168 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window.get()); | 267 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window.get()); |
| 169 window->SetBounds(work_area); | 268 window->SetBounds(work_area); |
| 170 // Usually work_area takes Shelf into account but that doesn't affect | 269 // Usually work_area takes Shelf into account but that doesn't affect |
| 171 // LockScreen container windows. | 270 // LockScreen container windows. |
| 172 EXPECT_NE(work_area.ToString(), window->GetBoundsInScreen().ToString()); | 271 EXPECT_NE(work_area.ToString(), window->GetBoundsInScreen().ToString()); |
| 173 EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString()); | 272 EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 174 } | 273 } |
| 175 | 274 |
| 176 } // namespace test | 275 } // namespace test |
| 177 } // namespace ash | 276 } // namespace ash |
| OLD | NEW |