OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/wm/window_positioner.h" | 5 #include "ash/wm/window_positioner.h" |
6 | 6 |
| 7 #include <string> |
| 8 |
7 #include "ash/shell.h" | 9 #include "ash/shell.h" |
8 #include "ash/shell/toplevel_window.h" | 10 #include "ash/shell/toplevel_window.h" |
9 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
| 12 #include "ash/test/test_shell_delegate.h" |
10 #include "ash/wm/window_positioner.h" | 13 #include "ash/wm/window_positioner.h" |
11 #include "ash/wm/window_state.h" | 14 #include "ash/wm/window_state.h" |
| 15 #include "base/strings/string_number_conversions.h" |
12 #include "ui/aura/window_event_dispatcher.h" | 16 #include "ui/aura/window_event_dispatcher.h" |
13 #include "ui/gfx/screen.h" | 17 #include "ui/gfx/screen.h" |
14 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
15 #include "ui/views/widget/widget_delegate.h" | 19 #include "ui/views/widget/widget_delegate.h" |
16 | 20 |
17 namespace ash { | 21 namespace ash { |
18 | 22 |
19 typedef test::AshTestBase WindowPositionerTest; | 23 typedef test::AshTestBase WindowPositionerTest; |
20 | 24 |
21 TEST_F(WindowPositionerTest, OpenMaximizedWindowOnSecondDisplay) { | 25 TEST_F(WindowPositionerTest, OpenMaximizedWindowOnSecondDisplay) { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 params.context = Shell::GetPrimaryRootWindow(); | 143 params.context = Shell::GetPrimaryRootWindow(); |
140 widget->Init(params); | 144 widget->Init(params); |
141 widget->SetBounds(gfx::Rect(450,10, 100, 100)); | 145 widget->SetBounds(gfx::Rect(450,10, 100, 100)); |
142 wm::GetWindowState(widget->GetNativeView())->set_minimum_visibility(true); | 146 wm::GetWindowState(widget->GetNativeView())->set_minimum_visibility(true); |
143 widget->Show(); | 147 widget->Show(); |
144 // Make sure the bounds is adjusted to be inside the work area. | 148 // Make sure the bounds is adjusted to be inside the work area. |
145 EXPECT_EQ("390,10 100x100", widget->GetWindowBoundsInScreen().ToString()); | 149 EXPECT_EQ("390,10 100x100", widget->GetWindowBoundsInScreen().ToString()); |
146 widget->CloseNow(); | 150 widget->CloseNow(); |
147 } | 151 } |
148 | 152 |
| 153 // In general case on first run the browser window will be maximized only for |
| 154 // low resolution screens (width < 1366). In case of big screens the browser is |
| 155 // opened being not maximized. To enforce maximization for all screen |
| 156 // resolutions, one can set "ForceMaximizeBrowserWindowOnFirstRun" |
| 157 // policy. In the following tests we check if the window will be opened in |
| 158 // maximized mode for low and high resolution when this policy is set. |
| 159 TEST_F(WindowPositionerTest, FirstRunMaximizeWindowHighResloution) { |
| 160 const int width = ash::WindowPositioner::GetForceMaximizedWidthLimit() + 100; |
| 161 // Set resolution to 1466x300. |
| 162 const std::string resolution = base::IntToString(width) + "x300"; |
| 163 UpdateDisplay(resolution); |
| 164 gfx::Rect bounds_in_out(0, 0, 320, 240); // Random bounds. |
| 165 ui::WindowShowState show_state_out = ui::SHOW_STATE_DEFAULT; |
| 166 |
| 167 test::TestShellDelegate* const delegate = |
| 168 static_cast<test::TestShellDelegate*>(Shell::GetInstance()->delegate()); |
| 169 delegate->SetForceMaximizeOnFirstRun(true); |
| 170 |
| 171 WindowPositioner::GetBoundsAndShowStateForNewWindow( |
| 172 Shell::GetScreen(), nullptr, false, ui::SHOW_STATE_DEFAULT, |
| 173 &bounds_in_out, &show_state_out); |
| 174 |
| 175 EXPECT_EQ(show_state_out, ui::SHOW_STATE_MAXIMIZED); |
| 176 } |
| 177 |
| 178 // For detail see description of FirstRunMaximizeWindowHighResloution. |
| 179 TEST_F(WindowPositionerTest, FirstRunMaximizeWindowLowResolution) { |
| 180 const int width = ash::WindowPositioner::GetForceMaximizedWidthLimit() - 100; |
| 181 // Set resolution to 1266x300. |
| 182 const std::string resolution = base::IntToString(width) + "x300"; |
| 183 UpdateDisplay(resolution); |
| 184 gfx::Rect bounds_in_out(0, 0, 320, 240); // Random bounds. |
| 185 ui::WindowShowState show_state_out = ui::SHOW_STATE_DEFAULT; |
| 186 |
| 187 test::TestShellDelegate* const delegate = |
| 188 static_cast<test::TestShellDelegate*>(Shell::GetInstance()->delegate()); |
| 189 delegate->SetForceMaximizeOnFirstRun(true); |
| 190 |
| 191 WindowPositioner::GetBoundsAndShowStateForNewWindow( |
| 192 Shell::GetScreen(), nullptr, false, ui::SHOW_STATE_DEFAULT, |
| 193 &bounds_in_out, &show_state_out); |
| 194 |
| 195 EXPECT_EQ(show_state_out, ui::SHOW_STATE_MAXIMIZED); |
| 196 } |
| 197 |
149 } // namespace | 198 } // namespace |
OLD | NEW |