| 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..5d6c8bd6029a0d624a02fae65fd98300a18233d6 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,17 @@
|
| #ifndef CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_COMMON_UNITTEST_H_
|
| #define CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_COMMON_UNITTEST_H_
|
|
|
| +#include "ui/gfx/rect.h"
|
| +
|
| +#include <vector>
|
| +
|
| +#include "ash/test/ash_test_base.h"
|
| +#include "base/logging.h"
|
| +#include "chrome/browser/ui/window_sizer/window_sizer.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +#include "chrome/test/base/test_browser_window.h"
|
| +#include "content/public/test/test_browser_thread.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,14 +45,31 @@ 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;
|
| +
|
| +typedef ash::test::AshTestBase WindowSizerTest;
|
| +
|
| +// A special test class for use with browser creation - it will create a
|
| +// browser thread and deletes it after all other things have been destroyed.
|
| +class WindowSizerTestWithBrowser : public WindowSizerTest {
|
| + public:
|
| + WindowSizerTestWithBrowser();
|
| + virtual ~WindowSizerTestWithBrowser();
|
| +
|
| + private:
|
| + // Note: It is important to delete the thread after the browser instances got
|
| + // deleted. For this we transfer the thread here.
|
| + scoped_ptr<content::TestBrowserThread> ui_thread_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(WindowSizerTestWithBrowser);
|
| +};
|
|
|
| // Testing implementation of WindowSizer::MonitorInfoProvider that we can use
|
| // to fake various monitor layouts and sizes.
|
| class TestMonitorInfoProvider : public MonitorInfoProvider {
|
| public:
|
| - TestMonitorInfoProvider();
|
| - virtual ~TestMonitorInfoProvider();
|
| + TestMonitorInfoProvider() {};
|
| + virtual ~TestMonitorInfoProvider() {};
|
|
|
| void AddMonitor(const gfx::Rect& bounds, const gfx::Rect& work_area);
|
|
|
| @@ -62,133 +90,100 @@ 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);
|
| -}
|
| +// A browser window proxy which is able to associate an aura native window with
|
| +// it.
|
| +class TestBrowserWindowAura : public TestBrowserWindow {
|
| + public:
|
| + explicit TestBrowserWindowAura(aura::Window* native_window);
|
| + virtual ~TestBrowserWindowAura();
|
| +
|
| + virtual gfx::NativeWindow GetNativeWindow() OVERRIDE {
|
| + return native_window_;
|
| + }
|
| +
|
| + virtual gfx::Rect GetBounds() const;
|
| +
|
| + private:
|
| + gfx::NativeWindow native_window_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(TestBrowserWindowAura);
|
| +};
|
| +
|
| +// 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.
|
| +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,
|
| + gfx::Rect* out_bounds,
|
| + ui::WindowShowState& out_show_state,
|
| + const Browser* browser,
|
| + const gfx::Rect& passed_in);
|
| +
|
| +// Set up the window bounds, monitor bounds, and work area to get the
|
| +// resulting |out_bounds| from the WindowSizer.
|
| +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_
|
|
|