Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / window_sizer / window_sizer_common_unittest.h
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.
4
5 #ifndef CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_COMMON_UNITTEST_H_
6 #define CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_COMMON_UNITTEST_H_
7
8 #include <vector>
9
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 "ui/gfx/rect.h"
14
15 // Some standard primary monitor sizes (no task bar).
16 static const gfx::Rect p1024x768(0, 0, 1024, 768);
17 static const gfx::Rect p1280x1024(0, 0, 1280, 1024);
18 static const gfx::Rect p1600x1200(0, 0, 1600, 1200);
19 static const gfx::Rect p1680x1050(0, 0, 1680, 1050);
20 static const gfx::Rect p1920x1200(0, 0, 1920, 1200);
21
22 // Represents a 1024x768 monitor that is the secondary monitor, arranged to
23 // the immediate left of the primary 1024x768 monitor.
24 static const gfx::Rect left_s1024x768(-1024, 0, 1024, 768);
25
26 // Represents a 1024x768 monitor that is the secondary monitor, arranged to
27 // the immediate right of the primary 1024x768 monitor.
28 static const gfx::Rect right_s1024x768(1024, 0, 1024, 768);
29
30 // Represents a 1024x768 monitor that is the secondary monitor, arranged to
31 // the immediate top of the primary 1024x768 monitor.
32 static const gfx::Rect top_s1024x768(0, -768, 1024, 768);
33
34 // Represents a 1024x768 monitor that is the secondary monitor, arranged to
35 // the immediate bottom of the primary 1024x768 monitor.
36 static const gfx::Rect bottom_s1024x768(0, 768, 1024, 768);
37
38 // Represents a 1600x1200 monitor that is the secondary monitor, arranged to
39 // the immediate bottom of the primary 1600x1200 monitor.
40 static const gfx::Rect bottom_s1600x1200(0, 1200, 1600, 1200);
41
42 // The work area for 1024x768 monitors with different taskbar orientations.
43 static const gfx::Rect taskbar_bottom_work_area(0, 0, 1024, 734);
44 static const gfx::Rect taskbar_top_work_area(0, 34, 1024, 734);
45 static const gfx::Rect taskbar_left_work_area(107, 0, 917, 768);
46 static const gfx::Rect taskbar_right_work_area(0, 0, 917, 768);
47
48 extern int kWindowTilePixels;
49
50 // Testing implementation of WindowSizer::StateProvider that we use to fake
51 // persistent storage and existing windows.
52 class TestStateProvider : public WindowSizer::StateProvider {
53  public:
54   TestStateProvider();
55   ~TestStateProvider() override {}
56
57   void SetPersistentState(const gfx::Rect& bounds,
58                           const gfx::Rect& work_area,
59                           ui::WindowShowState show_state,
60                           bool has_persistent_data);
61   void SetLastActiveState(const gfx::Rect& bounds,
62                           ui::WindowShowState show_state,
63                           bool has_last_active_data);
64
65   // Overridden from WindowSizer::StateProvider:
66   bool GetPersistentState(gfx::Rect* bounds,
67                           gfx::Rect* saved_work_area,
68                           ui::WindowShowState* show_state) const override;
69   bool GetLastActiveWindowState(gfx::Rect* bounds,
70                                 ui::WindowShowState* show_state) const override;
71
72  private:
73   gfx::Rect persistent_bounds_;
74   gfx::Rect persistent_work_area_;
75   bool has_persistent_data_;
76   ui::WindowShowState persistent_show_state_;
77
78   gfx::Rect last_active_bounds_;
79   bool has_last_active_data_;
80   ui::WindowShowState last_active_show_state_;
81
82   DISALLOW_COPY_AND_ASSIGN(TestStateProvider);
83 };
84
85 // Several convenience functions which allow to set up a state for
86 // window sizer test operations with a single call.
87
88 enum Source { DEFAULT, LAST_ACTIVE, PERSISTED, BOTH };
89
90 // Sets up the window bounds, monitor bounds, show states and more to get the
91 // resulting |out_bounds| and |out_show_state| from the WindowSizer.
92 // |source| specifies which type of data gets set for the test: Either the
93 // last active window, the persisted value which was stored earlier, both or
94 // none. For all these states the |bounds| and |work_area| get used, for the
95 // show states either |show_state_persisted| or |show_state_last| will be used.
96 void GetWindowBoundsAndShowState(const gfx::Rect& monitor1_bounds,
97                                  const gfx::Rect& monitor1_work_area,
98                                  const gfx::Rect& monitor2_bounds,
99                                  const gfx::Rect& bounds,
100                                  const gfx::Rect& work_area,
101                                  ui::WindowShowState show_state_persisted,
102                                  ui::WindowShowState show_state_last,
103                                  Source source,
104                                  const Browser* browser,
105                                  const gfx::Rect& passed_in,
106                                  gfx::Rect* out_bounds,
107                                  ui::WindowShowState* out_show_state);
108
109 // Sets up the window bounds, monitor bounds, and work area to get the
110 // resulting |out_bounds| from the WindowSizer.
111 // |source| specifies which type of data gets set for the test: Either the
112 // last active window, the persisted value which was stored earlier, both or
113 // none. For all these states the |bounds| and |work_area| get used, for the
114 // show states either |show_state_persisted| or |show_state_last| will be used.
115 void GetWindowBounds(const gfx::Rect& monitor1_bounds,
116                      const gfx::Rect& monitor1_work_area,
117                      const gfx::Rect& monitor2_bounds,
118                      const gfx::Rect& bounds,
119                      const gfx::Rect& work_area,
120                      Source source,
121                      const Browser* browser,
122                      const gfx::Rect& passed_in,
123                      gfx::Rect* out_bounds);
124
125 // Sets up the window |bounds| and various system states which have an influence
126 // on the WindowSizer and then determines the resulting show state from it.
127 // |bounds| specifies the |browser| last or persistent bounds depending on
128 // |source|. The |display_config| is the primary display configuration used.
129 ui::WindowShowState GetWindowShowState(
130     ui::WindowShowState show_state_persisted,
131     ui::WindowShowState show_state_last,
132     Source source,
133     const Browser* browser,
134     const gfx::Rect& bounds,
135     const gfx::Rect& display_config);
136
137 #endif  // CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_COMMON_UNITTEST_H_