| Index: chrome/browser/ui/window_sizer/window_sizer_common_unittest.h
|
| diff --git a/chrome/browser/ui/window_sizer/window_sizer_common_unittest.h b/chrome/browser/ui/window_sizer/window_sizer_common_unittest.h
|
| index e295395b4abdfa68a06e905b3d5ae31f53edcd83..b7251b71736fd4b75f8b4956feb0662825b441e7 100644
|
| --- a/chrome/browser/ui/window_sizer/window_sizer_common_unittest.h
|
| +++ b/chrome/browser/ui/window_sizer/window_sizer_common_unittest.h
|
| @@ -5,6 +5,15 @@
|
| #ifndef CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_COMMON_UNITTEST_H_
|
| #define CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_COMMON_UNITTEST_H_
|
|
|
| +#include <vector>
|
| +
|
| +#include "base/logging.h"
|
| +#include "chrome/browser/ui/window_sizer/window_sizer.h"
|
| +#include "chrome/test/base/test_browser_window.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +#include "content/public/test/test_browser_thread.h"
|
| +#include "ui/gfx/rect.h"
|
| +
|
| // Some standard monitor sizes (no task bar).
|
| static const gfx::Rect tentwentyfour(0, 0, 1024, 768);
|
| static const gfx::Rect twelveeighty(0, 0, 1280, 1024);
|
| @@ -34,7 +43,7 @@ static const gfx::Rect taskbar_top_work_area(0, 34, 1024, 734);
|
| static const gfx::Rect taskbar_left_work_area(107, 0, 917, 768);
|
| static const gfx::Rect taskbar_right_work_area(0, 0, 917, 768);
|
|
|
| -static int kWindowTilePixels = WindowSizer::kWindowTilePixels;
|
| +extern int kWindowTilePixels;
|
|
|
| // Testing implementation of WindowSizer::MonitorInfoProvider that we can use
|
| // to fake various monitor layouts and sizes.
|
| @@ -62,133 +71,89 @@ class TestMonitorInfoProvider : public MonitorInfoProvider {
|
| DISALLOW_COPY_AND_ASSIGN(TestMonitorInfoProvider);
|
| };
|
|
|
| -TestMonitorInfoProvider::TestMonitorInfoProvider() {}
|
| -TestMonitorInfoProvider::~TestMonitorInfoProvider() {}
|
| -
|
| -void TestMonitorInfoProvider::AddMonitor(const gfx::Rect& bounds,
|
| - const gfx::Rect& work_area) {
|
| - DCHECK(bounds.Contains(work_area));
|
| - monitor_bounds_.push_back(bounds);
|
| - work_areas_.push_back(work_area);
|
| -}
|
| -
|
| -// Overridden from WindowSizer::MonitorInfoProvider:
|
| -gfx::Rect TestMonitorInfoProvider::GetPrimaryDisplayWorkArea() const {
|
| - return work_areas_[0];
|
| -}
|
| -
|
| -gfx::Rect TestMonitorInfoProvider::GetPrimaryDisplayBounds() const {
|
| - return monitor_bounds_[0];
|
| -}
|
| -
|
| -gfx::Rect TestMonitorInfoProvider::GetMonitorWorkAreaMatching(
|
| - const gfx::Rect& match_rect) const {
|
| - return work_areas_[GetMonitorIndexMatchingBounds(match_rect)];
|
| -}
|
| -
|
| -size_t TestMonitorInfoProvider::GetMonitorIndexMatchingBounds(
|
| - const gfx::Rect& match_rect) const {
|
| - int max_area = 0;
|
| - size_t max_area_index = 0;
|
| - // Loop through all the monitors, finding the one that intersects the
|
| - // largest area of the supplied match rect.
|
| - for (size_t i = 0; i < work_areas_.size(); ++i) {
|
| - gfx::Rect overlap(match_rect.Intersect(work_areas_[i]));
|
| - int area = overlap.width() * overlap.height();
|
| - if (area > max_area) {
|
| - max_area = area;
|
| - max_area_index = i;
|
| - }
|
| - }
|
| - return max_area_index;
|
| -}
|
| -
|
| -
|
| // Testing implementation of WindowSizer::StateProvider that we use to fake
|
| // persistent storage and existing windows.
|
| class TestStateProvider : public WindowSizer::StateProvider {
|
| public:
|
| TestStateProvider();
|
| - virtual ~TestStateProvider();
|
| + virtual ~TestStateProvider() {};
|
|
|
| void SetPersistentState(const gfx::Rect& bounds,
|
| const gfx::Rect& work_area,
|
| + ui::WindowShowState show_state,
|
| bool has_persistent_data);
|
| - void SetLastActiveState(const gfx::Rect& bounds, bool has_last_active_data);
|
| + void SetLastActiveState(const gfx::Rect& bounds,
|
| + ui::WindowShowState show_state,
|
| + bool has_last_active_data);
|
|
|
| // Overridden from WindowSizer::StateProvider:
|
| - virtual bool GetPersistentState(gfx::Rect* bounds,
|
| - gfx::Rect* saved_work_area) const OVERRIDE;
|
| - virtual bool GetLastActiveWindowState(gfx::Rect* bounds) const OVERRIDE;
|
| + virtual bool GetPersistentState(
|
| + gfx::Rect* bounds,
|
| + gfx::Rect* saved_work_area,
|
| + ui::WindowShowState* show_state) const OVERRIDE;
|
| + virtual bool GetLastActiveWindowState(
|
| + gfx::Rect* bounds,
|
| + ui::WindowShowState* show_state) const OVERRIDE;
|
|
|
| private:
|
| gfx::Rect persistent_bounds_;
|
| gfx::Rect persistent_work_area_;
|
| bool has_persistent_data_;
|
| + ui::WindowShowState persistent_show_state_;
|
|
|
| gfx::Rect last_active_bounds_;
|
| bool has_last_active_data_;
|
| + ui::WindowShowState last_active_show_state_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(TestStateProvider);
|
| };
|
|
|
| -TestStateProvider::TestStateProvider():
|
| - has_persistent_data_(false),
|
| - has_last_active_data_(false) {
|
| -}
|
| -
|
| -TestStateProvider::~TestStateProvider() {}
|
| -
|
| -void TestStateProvider::SetPersistentState(const gfx::Rect& bounds,
|
| - const gfx::Rect& work_area,
|
| - bool has_persistent_data) {
|
| - persistent_bounds_ = bounds;
|
| - persistent_work_area_ = work_area;
|
| - has_persistent_data_ = has_persistent_data;
|
| -}
|
| -
|
| -void TestStateProvider::SetLastActiveState(const gfx::Rect& bounds,
|
| - bool has_last_active_data) {
|
| - last_active_bounds_ = bounds;
|
| - has_last_active_data_ = has_last_active_data;
|
| -}
|
| -
|
| -bool TestStateProvider::GetPersistentState(gfx::Rect* bounds,
|
| - gfx::Rect* saved_work_area) const {
|
| - *bounds = persistent_bounds_;
|
| - *saved_work_area = persistent_work_area_;
|
| - return has_persistent_data_;
|
| -}
|
| -
|
| -bool TestStateProvider::GetLastActiveWindowState(gfx::Rect* bounds) const {
|
| - *bounds = last_active_bounds_;
|
| - return has_last_active_data_;
|
| -}
|
| -
|
| -// A convenience function to read the window bounds from the window sizer
|
| -// according to the specified configuration.
|
| -enum Source { DEFAULT, LAST_ACTIVE, PERSISTED };
|
| -static void GetWindowBounds(const gfx::Rect& monitor1_bounds,
|
| - const gfx::Rect& monitor1_work_area,
|
| - const gfx::Rect& monitor2_bounds,
|
| - const gfx::Rect& state,
|
| - const gfx::Rect& work_area,
|
| - Source source,
|
| - gfx::Rect* out_bounds,
|
| - const Browser* browser,
|
| - const gfx::Rect& passed_in) {
|
| - TestMonitorInfoProvider* mip = new TestMonitorInfoProvider;
|
| - mip->AddMonitor(monitor1_bounds, monitor1_work_area);
|
| - if (!monitor2_bounds.IsEmpty())
|
| - mip->AddMonitor(monitor2_bounds, monitor2_bounds);
|
| - TestStateProvider* sp = new TestStateProvider;
|
| - if (source == PERSISTED)
|
| - sp->SetPersistentState(state, work_area, true);
|
| - else if (source == LAST_ACTIVE)
|
| - sp->SetLastActiveState(state, true);
|
| -
|
| - WindowSizer sizer(sp, mip, browser);
|
| - sizer.DetermineWindowBounds(passed_in, out_bounds);
|
| -}
|
| +// Several convenience functions which allow to set up a state for
|
| +// window sizer test operations with a single call.
|
| +
|
| +enum Source { DEFAULT, LAST_ACTIVE, PERSISTED, BOTH };
|
| +
|
| +// Set up the window bounds, monitor bounds, show states and more to get the
|
| +// resulting |out_bounds| and |out_show_state| from the WindowSizer.
|
| +// |source| specifies which type of data gets set for the test: Either the
|
| +// last active window, the persisted value which was stored earlier, both or
|
| +// none. For all these states the |bounds| and |work_area| get used, for the
|
| +// show states either |show_state_persisted| or |show_state_last| will be used.
|
| +void GetWindowBoundsAndShowState(const gfx::Rect& monitor1_bounds,
|
| + const gfx::Rect& monitor1_work_area,
|
| + const gfx::Rect& monitor2_bounds,
|
| + const gfx::Rect& bounds,
|
| + const gfx::Rect& work_area,
|
| + ui::WindowShowState show_state_persisted,
|
| + ui::WindowShowState show_state_last,
|
| + Source source,
|
| + const Browser* browser,
|
| + const gfx::Rect& passed_in,
|
| + gfx::Rect* out_bounds,
|
| + ui::WindowShowState* out_show_state);
|
| +
|
| +// Set up the window bounds, monitor bounds, and work area to get the
|
| +// resulting |out_bounds| from the WindowSizer.
|
| +// |source| specifies which type of data gets set for the test: Either the
|
| +// last active window, the persisted value which was stored earlier, both or
|
| +// none. For all these states the |bounds| and |work_area| get used, for the
|
| +// show states either |show_state_persisted| or |show_state_last| will be used.
|
| +void GetWindowBounds(const gfx::Rect& monitor1_bounds,
|
| + const gfx::Rect& monitor1_work_area,
|
| + const gfx::Rect& monitor2_bounds,
|
| + const gfx::Rect& bounds,
|
| + const gfx::Rect& work_area,
|
| + Source source,
|
| + gfx::Rect* out_bounds,
|
| + const Browser* browser,
|
| + const gfx::Rect& passed_in);
|
| +
|
| +// Set up the various show states and get the resulting show state from
|
| +// the WindowSizer.
|
| +ui::WindowShowState GetWindowShowState(
|
| + ui::WindowShowState show_state_persisted,
|
| + ui::WindowShowState show_state_last,
|
| + Source source,
|
| + const Browser* browser);
|
|
|
| #endif // CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_COMMON_UNITTEST_H_
|
|
|