Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: ash/wm/window_positioner_unittest.cc

Issue 964503002: Implemented ForceMaximizeBrowserWindowOnFirstRun policy, added unit test and browser test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix after review Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <string>
bartfab (slow) 2015/04/01 14:22:41 This should still be the first include.
peletskyi 2015/04/01 18:55:45 Done.
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/shell/toplevel_window.h" 8 #include "ash/shell/toplevel_window.h"
9 #include "ash/test/ash_test_base.h" 9 #include "ash/test/ash_test_base.h"
10 #include "ash/test/test_shell_delegate.h"
10 #include "ash/wm/window_positioner.h" 11 #include "ash/wm/window_positioner.h"
11 #include "ash/wm/window_state.h" 12 #include "ash/wm/window_state.h"
12 #include "ui/aura/window_event_dispatcher.h" 13 #include "ui/aura/window_event_dispatcher.h"
13 #include "ui/gfx/screen.h" 14 #include "ui/gfx/screen.h"
14 #include "ui/views/widget/widget.h" 15 #include "ui/views/widget/widget.h"
15 #include "ui/views/widget/widget_delegate.h" 16 #include "ui/views/widget/widget_delegate.h"
16 17
17 namespace ash { 18 namespace ash {
18 19
19 typedef test::AshTestBase WindowPositionerTest; 20 typedef test::AshTestBase WindowPositionerTest;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 params.context = Shell::GetPrimaryRootWindow(); 140 params.context = Shell::GetPrimaryRootWindow();
140 widget->Init(params); 141 widget->Init(params);
141 widget->SetBounds(gfx::Rect(450,10, 100, 100)); 142 widget->SetBounds(gfx::Rect(450,10, 100, 100));
142 wm::GetWindowState(widget->GetNativeView())->set_minimum_visibility(true); 143 wm::GetWindowState(widget->GetNativeView())->set_minimum_visibility(true);
143 widget->Show(); 144 widget->Show();
144 // Make sure the bounds is adjusted to be inside the work area. 145 // Make sure the bounds is adjusted to be inside the work area.
145 EXPECT_EQ("390,10 100x100", widget->GetWindowBoundsInScreen().ToString()); 146 EXPECT_EQ("390,10 100x100", widget->GetWindowBoundsInScreen().ToString());
146 widget->CloseNow(); 147 widget->CloseNow();
147 } 148 }
148 149
150 // In general case on first run the browser window will be maximized only for
151 // low resolution screens (width < 1366). In case of big screens the browser is
152 // opened being not maximized. To enforce maximization for all screen
153 // resolutions of full screen one can set "ForceMaximizeBrowserWindowOnFirstRun"
bartfab (slow) 2015/04/01 14:22:41 Nit: s/of full screen/,/
peletskyi 2015/04/01 18:55:45 Done.
154 // policy. In the following tests we check if the window will be opened in
155 // maximized mode for low and high resolution when this policy is set.
156 TEST_F(WindowPositionerTest, FirstRunMaximizeWindowHighResloution) {
157 const int width = ash::WindowPositioner::GetForceMaximizedWidthLimit() + 100;
158 // Set resolution to 1466x300.
159 const std::string resolution = base::IntToString(width) + "x300";
bartfab (slow) 2015/04/01 14:22:41 Nit: #include "base/strings/string_number_conversi
peletskyi 2015/04/01 18:55:45 Done.
160 UpdateDisplay(resolution);
161 gfx::Rect bounds_in_out(0, 0, 320, 240); // random bounds
bartfab (slow) 2015/04/01 14:22:41 Nit: s/random bounds/Random bounds./ (we always fo
peletskyi 2015/04/01 18:55:45 Done.
162 ui::WindowShowState show_state_out = ui::SHOW_STATE_DEFAULT;
163
164 test::TestShellDelegate* delegate =
bartfab (slow) 2015/04/01 14:22:41 Nit: const pointer.
peletskyi 2015/04/01 18:55:45 Method SetForceMaximizeOnFirstRun is not const.
bartfab (slow) 2015/04/02 08:44:28 Const pointer, not pointer to const.
peletskyi 2015/04/02 12:53:28 Done.
165 static_cast<test::TestShellDelegate*>(Shell::GetInstance()->delegate());
166 delegate->SetForceMaximizeOnFirstRun(true);
167
168 WindowPositioner::GetBoundsAndShowStateForNewWindow(
169 Shell::GetScreen(), nullptr, false, ui::SHOW_STATE_DEFAULT,
170 &bounds_in_out, &show_state_out);
171
172 EXPECT_EQ(show_state_out, ui::SHOW_STATE_MAXIMIZED);
173 }
174
175 // For detail see description of FirstRunMaximizeWindowHighResloution.
176 TEST_F(WindowPositionerTest, FirstRunMaximizeWindowLowResolution) {
177 const int width = ash::WindowPositioner::GetForceMaximizedWidthLimit() - 100;
178 // Set resolution to 1266x300.
179 const std::string resolution = base::IntToString(width) + "x300";
180 UpdateDisplay(resolution);
181 gfx::Rect bounds_in_out(0, 0, 320, 240); // random bounds
bartfab (slow) 2015/04/01 14:22:41 Nit: s/random bounds/Random bounds./
peletskyi 2015/04/01 18:55:45 Done.
182 ui::WindowShowState show_state_out = ui::SHOW_STATE_DEFAULT;
183
184 test::TestShellDelegate* delegate =
bartfab (slow) 2015/04/01 14:22:41 Nit: const pointer.
peletskyi 2015/04/01 18:55:45 Method SetForceMaximizeOnFirstRun is not const.
bartfab (slow) 2015/04/02 08:44:28 Const pointer, not pointer to const.
peletskyi 2015/04/02 12:53:28 Done.
185 static_cast<test::TestShellDelegate*>(Shell::GetInstance()->delegate());
186 delegate->SetForceMaximizeOnFirstRun(true);
187
188 WindowPositioner::GetBoundsAndShowStateForNewWindow(
189 Shell::GetScreen(), nullptr, false, ui::SHOW_STATE_DEFAULT,
190 &bounds_in_out, &show_state_out);
191
192 EXPECT_EQ(show_state_out, ui::SHOW_STATE_MAXIMIZED);
193 }
194
149 } // namespace 195 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698