1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_COMMON_UNITTEST_H_
6 #define CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_COMMON_UNITTEST_H_
10 #include "base/logging.h"
11 #include "chrome/browser/ui/window_sizer/window_sizer.h"
12 #include "chrome/test/base/test_browser_window.h"
13 #include "content/public/test/test_browser_thread.h"
14 #include "ui/gfx/rect.h"
16 // Some standard primary monitor sizes (no task bar).
17 static const gfx::Rect
p1024x768(0, 0, 1024, 768);
18 static const gfx::Rect
p1280x1024(0, 0, 1280, 1024);
19 static const gfx::Rect
p1600x1200(0, 0, 1600, 1200);
20 static const gfx::Rect
p1680x1050(0, 0, 1680, 1050);
21 static const gfx::Rect
p1920x1200(0, 0, 1920, 1200);
23 // Represents a 1024x768 monitor that is the secondary monitor, arranged to
24 // the immediate left of the primary 1024x768 monitor.
25 static const gfx::Rect
left_s1024x768(-1024, 0, 1024, 768);
27 // Represents a 1024x768 monitor that is the secondary monitor, arranged to
28 // the immediate right of the primary 1024x768 monitor.
29 static const gfx::Rect
right_s1024x768(1024, 0, 1024, 768);
31 // Represents a 1024x768 monitor that is the secondary monitor, arranged to
32 // the immediate top of the primary 1024x768 monitor.
33 static const gfx::Rect
top_s1024x768(0, -768, 1024, 768);
35 // Represents a 1024x768 monitor that is the secondary monitor, arranged to
36 // the immediate bottom of the primary 1024x768 monitor.
37 static const gfx::Rect
bottom_s1024x768(0, 768, 1024, 768);
39 // Represents a 1600x1200 monitor that is the secondary monitor, arranged to
40 // the immediate bottom of the primary 1600x1200 monitor.
41 static const gfx::Rect
bottom_s1600x1200(0, 1200, 1600, 1200);
43 // The work area for 1024x768 monitors with different taskbar orientations.
44 static const gfx::Rect
taskbar_bottom_work_area(0, 0, 1024, 734);
45 static const gfx::Rect
taskbar_top_work_area(0, 34, 1024, 734);
46 static const gfx::Rect
taskbar_left_work_area(107, 0, 917, 768);
47 static const gfx::Rect
taskbar_right_work_area(0, 0, 917, 768);
49 extern int kWindowTilePixels
;
51 // Testing implementation of WindowSizer::StateProvider that we use to fake
52 // persistent storage and existing windows.
53 class TestStateProvider
: public WindowSizer::StateProvider
{
56 virtual ~TestStateProvider() {}
58 void SetPersistentState(const gfx::Rect
& bounds
,
59 const gfx::Rect
& work_area
,
60 ui::WindowShowState show_state
,
61 bool has_persistent_data
);
62 void SetLastActiveState(const gfx::Rect
& bounds
,
63 ui::WindowShowState show_state
,
64 bool has_last_active_data
);
66 // Overridden from WindowSizer::StateProvider:
67 virtual bool GetPersistentState(
69 gfx::Rect
* saved_work_area
,
70 ui::WindowShowState
* show_state
) const OVERRIDE
;
71 virtual bool GetLastActiveWindowState(
73 ui::WindowShowState
* show_state
) const OVERRIDE
;
76 gfx::Rect persistent_bounds_
;
77 gfx::Rect persistent_work_area_
;
78 bool has_persistent_data_
;
79 ui::WindowShowState persistent_show_state_
;
81 gfx::Rect last_active_bounds_
;
82 bool has_last_active_data_
;
83 ui::WindowShowState last_active_show_state_
;
85 DISALLOW_COPY_AND_ASSIGN(TestStateProvider
);
88 // Several convenience functions which allow to set up a state for
89 // window sizer test operations with a single call.
91 enum Source
{ DEFAULT
, LAST_ACTIVE
, PERSISTED
, BOTH
};
93 // Set up the window bounds, monitor bounds, show states and more to get the
94 // resulting |out_bounds| and |out_show_state| from the WindowSizer.
95 // |source| specifies which type of data gets set for the test: Either the
96 // last active window, the persisted value which was stored earlier, both or
97 // none. For all these states the |bounds| and |work_area| get used, for the
98 // show states either |show_state_persisted| or |show_state_last| will be used.
99 void GetWindowBoundsAndShowState(const gfx::Rect
& monitor1_bounds
,
100 const gfx::Rect
& monitor1_work_area
,
101 const gfx::Rect
& monitor2_bounds
,
102 const gfx::Rect
& bounds
,
103 const gfx::Rect
& work_area
,
104 ui::WindowShowState show_state_persisted
,
105 ui::WindowShowState show_state_last
,
107 const Browser
* browser
,
108 const gfx::Rect
& passed_in
,
109 gfx::Rect
* out_bounds
,
110 ui::WindowShowState
* out_show_state
);
112 // Set up the window bounds, monitor bounds, and work area to get the
113 // resulting |out_bounds| from the WindowSizer.
114 // |source| specifies which type of data gets set for the test: Either the
115 // last active window, the persisted value which was stored earlier, both or
116 // none. For all these states the |bounds| and |work_area| get used, for the
117 // show states either |show_state_persisted| or |show_state_last| will be used.
118 void GetWindowBounds(const gfx::Rect
& monitor1_bounds
,
119 const gfx::Rect
& monitor1_work_area
,
120 const gfx::Rect
& monitor2_bounds
,
121 const gfx::Rect
& bounds
,
122 const gfx::Rect
& work_area
,
124 const Browser
* browser
,
125 const gfx::Rect
& passed_in
,
126 gfx::Rect
* out_bounds
);
128 // Set up the various show states and get the resulting show state from
130 // The |display_config| is the primary display configuration used.
131 ui::WindowShowState
GetWindowShowState(
132 ui::WindowShowState show_state_persisted
,
133 ui::WindowShowState show_state_last
,
135 const Browser
* browser
,
136 const gfx::Rect
& display_config
);
138 #endif // CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_COMMON_UNITTEST_H_