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..d3a580412ba4f482502bc3de8159f2f49014caaf 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,16 @@ |
#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" |
sky
2012/10/08 21:01:25
after <vector>
Mr4D (OOO till 08-26)
2012/10/08 23:04:27
Done.
|
+ |
+#include <vector> |
+ |
+#include "base/logging.h" |
+#include "chrome/browser/ui/window_sizer/window_sizer.h" |
sky
2012/10/08 21:01:25
sort
Mr4D (OOO till 08-26)
2012/10/08 23:04:27
Done.
|
+#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,7 +44,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 +72,81 @@ 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. |
+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, |
sky
2012/10/08 21:01:25
Isn't not clear what source means here. Please doc
Mr4D (OOO till 08-26)
2012/10/08 23:04:27
Done.
|
+ gfx::Rect* out_bounds, |
+ ui::WindowShowState* out_show_state, |
sky
2012/10/08 21:01:25
make out params last.
Mr4D (OOO till 08-26)
2012/10/08 23:04:27
Done.
|
+ 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, |
sky
2012/10/08 21:01:25
same comment about source and out params.
Mr4D (OOO till 08-26)
2012/10/08 23:04:27
There are already over 160 calls to this function
|
+ 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_ |