From da0bbb16cc00553245e806aa8c5adc4c38f7a9ed Mon Sep 17 00:00:00 2001 From: peletskyi Date: Wed, 8 Apr 2015 10:11:04 -0700 Subject: Implemented ForceMaximizeBrowserWindowOnFirstRun policy, added unit test and browser test. BUG=356285 Review URL: https://codereview.chromium.org/964503002 Cr-Commit-Position: refs/heads/master@{#324244} --- ash/shell/shell_delegate_impl.cc | 4 +++ ash/shell/shell_delegate_impl.h | 1 + ash/shell_delegate.h | 5 ++++ ash/test/test_shell_delegate.cc | 5 ++++ ash/test/test_shell_delegate.h | 5 ++++ ash/wm/window_positioner.cc | 22 +++++++++++----- ash/wm/window_positioner_unittest.cc | 49 ++++++++++++++++++++++++++++++++++++ 7 files changed, 85 insertions(+), 6 deletions(-) (limited to 'ash') diff --git a/ash/shell/shell_delegate_impl.cc b/ash/shell/shell_delegate_impl.cc index dc081c6..4af993a 100644 --- a/ash/shell/shell_delegate_impl.cc +++ b/ash/shell/shell_delegate_impl.cc @@ -181,6 +181,10 @@ bool ShellDelegateImpl::IsMultiAccountEnabled() const { return false; } +bool ShellDelegateImpl::IsForceMaximizeOnFirstRun() const { + return false; +} + void ShellDelegateImpl::PreInit() { } diff --git a/ash/shell/shell_delegate_impl.h b/ash/shell/shell_delegate_impl.h index 502161d..255401a 100644 --- a/ash/shell/shell_delegate_impl.h +++ b/ash/shell/shell_delegate_impl.h @@ -39,6 +39,7 @@ class ShellDelegateImpl : public ash::ShellDelegate { bool IsMultiProfilesEnabled() const override; bool IsRunningInForcedAppMode() const override; bool IsMultiAccountEnabled() const override; + bool IsForceMaximizeOnFirstRun() const override; void PreInit() override; void PreShutdown() override; void Exit() override; diff --git a/ash/shell_delegate.h b/ash/shell_delegate.h index 148f686..64f8139 100644 --- a/ash/shell_delegate.h +++ b/ash/shell_delegate.h @@ -83,6 +83,11 @@ class ASH_EXPORT ShellDelegate { // Returns true if multi account is enabled. virtual bool IsMultiAccountEnabled() const = 0; + // Returns true if the first window shown on first run should be + // unconditionally maximized, overriding the heuristic that normally chooses + // the window size. + virtual bool IsForceMaximizeOnFirstRun() const = 0; + // Called before processing |Shell::Init()| so that the delegate // can perform tasks necessary before the shell is initialized. virtual void PreInit() = 0; diff --git a/ash/test/test_shell_delegate.cc b/ash/test/test_shell_delegate.cc index 9b11604..ee6fd44 100644 --- a/ash/test/test_shell_delegate.cc +++ b/ash/test/test_shell_delegate.cc @@ -82,6 +82,7 @@ class MediaDelegateImpl : public MediaDelegate { TestShellDelegate::TestShellDelegate() : num_exit_requests_(0), multi_profiles_enabled_(false), + force_maximize_on_first_run_(false), test_session_state_delegate_(NULL) { } @@ -108,6 +109,10 @@ bool TestShellDelegate::IsMultiAccountEnabled() const { return false; } +bool TestShellDelegate::IsForceMaximizeOnFirstRun() const { + return force_maximize_on_first_run_; +} + void TestShellDelegate::PreInit() { } diff --git a/ash/test/test_shell_delegate.h b/ash/test/test_shell_delegate.h index 95e9487..9b273fc 100644 --- a/ash/test/test_shell_delegate.h +++ b/ash/test/test_shell_delegate.h @@ -36,6 +36,7 @@ class TestShellDelegate : public ShellDelegate { bool IsMultiProfilesEnabled() const override; bool IsRunningInForcedAppMode() const override; bool IsMultiAccountEnabled() const override; + bool IsForceMaximizeOnFirstRun() const override; void PreInit() override; void PreShutdown() override; void Exit() override; @@ -63,10 +64,14 @@ class TestShellDelegate : public ShellDelegate { int num_exit_requests() const { return num_exit_requests_; } void SetMediaCaptureState(MediaCaptureState state); + void SetForceMaximizeOnFirstRun(bool maximize) { + force_maximize_on_first_run_ = maximize; + }; private: int num_exit_requests_; bool multi_profiles_enabled_; + bool force_maximize_on_first_run_; scoped_ptr active_browser_context_; scoped_ptr app_list_view_delegate_; diff --git a/ash/wm/window_positioner.cc b/ash/wm/window_positioner.cc index 4e80ed8..eed15a0 100644 --- a/ash/wm/window_positioner.cc +++ b/ash/wm/window_positioner.cc @@ -6,6 +6,7 @@ #include "ash/screen_util.h" #include "ash/shell.h" +#include "ash/shell_delegate.h" #include "ash/shell_window_ids.h" #include "ash/wm/mru_window_tracker.h" #include "ash/wm/window_resizer.h" @@ -246,7 +247,6 @@ void WindowPositioner::GetBoundsAndShowStateForNewWindow( ui::WindowShowState show_state_in, gfx::Rect* bounds_in_out, ui::WindowShowState* show_state_out) { - // Always open new window in the target display. aura::Window* target = Shell::GetTargetRootWindow(); @@ -264,14 +264,24 @@ void WindowPositioner::GetBoundsAndShowStateForNewWindow( // Use adjusted saved bounds, if there is one. if (is_saved_bounds) return; - // When using "small screens" we want to always open in full screen mode. - if (show_state_in == ui::SHOW_STATE_DEFAULT && (maximize_first_window || - (work_area.width() <= GetForceMaximizedWidthLimit() && - (!new_window || !wm::GetWindowState(new_window)->IsFullscreen())))) { - *show_state_out = ui::SHOW_STATE_MAXIMIZED; + + if (show_state_in == ui::SHOW_STATE_DEFAULT) { + const bool maximize_first_window_on_first_run = + Shell::GetInstance()->delegate()->IsForceMaximizeOnFirstRun(); + // We want to always open maximized on "small screens" or when policy + // tells us to. + const bool set_maximized = + maximize_first_window || + ((work_area.width() <= GetForceMaximizedWidthLimit() || + maximize_first_window_on_first_run) && + (!new_window || !wm::GetWindowState(new_window)->IsFullscreen())); + + if (set_maximized) + *show_state_out = ui::SHOW_STATE_MAXIMIZED; } return; } + wm::WindowState* top_window_state = wm::GetWindowState(top_window); bool maximized = top_window_state->IsMaximized(); // We ignore the saved show state, but look instead for the top level diff --git a/ash/wm/window_positioner_unittest.cc b/ash/wm/window_positioner_unittest.cc index af320bc..79f9a84 100644 --- a/ash/wm/window_positioner_unittest.cc +++ b/ash/wm/window_positioner_unittest.cc @@ -4,11 +4,15 @@ #include "ash/wm/window_positioner.h" +#include + #include "ash/shell.h" #include "ash/shell/toplevel_window.h" #include "ash/test/ash_test_base.h" +#include "ash/test/test_shell_delegate.h" #include "ash/wm/window_positioner.h" #include "ash/wm/window_state.h" +#include "base/strings/string_number_conversions.h" #include "ui/aura/window_event_dispatcher.h" #include "ui/gfx/screen.h" #include "ui/views/widget/widget.h" @@ -146,4 +150,49 @@ TEST_F(WindowPositionerTest, EnsureMinimumVisibility) { widget->CloseNow(); } +// In general case on first run the browser window will be maximized only for +// low resolution screens (width < 1366). In case of big screens the browser is +// opened being not maximized. To enforce maximization for all screen +// resolutions, one can set "ForceMaximizeBrowserWindowOnFirstRun" +// policy. In the following tests we check if the window will be opened in +// maximized mode for low and high resolution when this policy is set. +TEST_F(WindowPositionerTest, FirstRunMaximizeWindowHighResloution) { + const int width = ash::WindowPositioner::GetForceMaximizedWidthLimit() + 100; + // Set resolution to 1466x300. + const std::string resolution = base::IntToString(width) + "x300"; + UpdateDisplay(resolution); + gfx::Rect bounds_in_out(0, 0, 320, 240); // Random bounds. + ui::WindowShowState show_state_out = ui::SHOW_STATE_DEFAULT; + + test::TestShellDelegate* const delegate = + static_cast(Shell::GetInstance()->delegate()); + delegate->SetForceMaximizeOnFirstRun(true); + + WindowPositioner::GetBoundsAndShowStateForNewWindow( + Shell::GetScreen(), nullptr, false, ui::SHOW_STATE_DEFAULT, + &bounds_in_out, &show_state_out); + + EXPECT_EQ(show_state_out, ui::SHOW_STATE_MAXIMIZED); +} + +// For detail see description of FirstRunMaximizeWindowHighResloution. +TEST_F(WindowPositionerTest, FirstRunMaximizeWindowLowResolution) { + const int width = ash::WindowPositioner::GetForceMaximizedWidthLimit() - 100; + // Set resolution to 1266x300. + const std::string resolution = base::IntToString(width) + "x300"; + UpdateDisplay(resolution); + gfx::Rect bounds_in_out(0, 0, 320, 240); // Random bounds. + ui::WindowShowState show_state_out = ui::SHOW_STATE_DEFAULT; + + test::TestShellDelegate* const delegate = + static_cast(Shell::GetInstance()->delegate()); + delegate->SetForceMaximizeOnFirstRun(true); + + WindowPositioner::GetBoundsAndShowStateForNewWindow( + Shell::GetScreen(), nullptr, false, ui::SHOW_STATE_DEFAULT, + &bounds_in_out, &show_state_out); + + EXPECT_EQ(show_state_out, ui::SHOW_STATE_MAXIMIZED); +} + } // namespace -- cgit v1.1