| Index: chrome/browser/ui/window_sizer/window_sizer_common_unittest.cc
|
| diff --git a/chrome/browser/ui/window_sizer/window_sizer_common_unittest.cc b/chrome/browser/ui/window_sizer/window_sizer_common_unittest.cc
|
| index 954f89e16cb514818a981634572176cf19783f45..6f4bd8d14e619ea55e5754b37bbce3e31c15b9ec 100644
|
| --- a/chrome/browser/ui/window_sizer/window_sizer_common_unittest.cc
|
| +++ b/chrome/browser/ui/window_sizer/window_sizer_common_unittest.cc
|
| @@ -10,49 +10,95 @@
|
| #include "chrome/common/chrome_switches.h"
|
| #include "chrome/test/base/testing_profile.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| +#include "ui/gfx/display.h"
|
| +#include "ui/gfx/screen.h"
|
|
|
| -TestMonitorInfoProvider::TestMonitorInfoProvider() {};
|
| +namespace {
|
|
|
| -TestMonitorInfoProvider::~TestMonitorInfoProvider() {};
|
| +class TestScreen : public gfx::Screen {
|
| + public:
|
| + TestScreen() {}
|
| + virtual ~TestScreen() {}
|
|
|
| -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 gfx::Screen:
|
| + virtual bool IsDIPEnabled() OVERRIDE {
|
| + NOTREACHED();
|
| + return false;
|
| + }
|
|
|
| -// Overridden from WindowSizer::MonitorInfoProvider:
|
| -gfx::Rect TestMonitorInfoProvider::GetPrimaryDisplayWorkArea() const {
|
| - return work_areas_[0];
|
| -}
|
| + virtual gfx::Point GetCursorScreenPoint() OVERRIDE {
|
| + NOTREACHED();
|
| + return gfx::Point();
|
| + }
|
|
|
| -gfx::Rect TestMonitorInfoProvider::GetPrimaryDisplayBounds() const {
|
| - return monitor_bounds_[0];
|
| -}
|
| + virtual gfx::NativeWindow GetWindowAtCursorScreenPoint() OVERRIDE {
|
| + NOTREACHED();
|
| + return NULL;
|
| + }
|
|
|
| -gfx::Rect TestMonitorInfoProvider::GetMonitorWorkAreaMatching(
|
| - const gfx::Rect& match_rect) const {
|
| - return work_areas_[GetMonitorIndexMatchingBounds(match_rect)];
|
| -}
|
| + virtual int GetNumDisplays() const OVERRIDE {
|
| + return displays_.size();
|
| + }
|
| +
|
| + virtual std::vector<gfx::Display> GetAllDisplays() const OVERRIDE {
|
| + return displays_;
|
| + }
|
| +
|
| + virtual gfx::Display GetDisplayNearestWindow(
|
| + gfx::NativeView view) const OVERRIDE {
|
| + NOTREACHED();
|
| + return gfx::Display();
|
| + }
|
| +
|
| + virtual gfx::Display GetDisplayNearestPoint(
|
| + const gfx::Point& point) const OVERRIDE {
|
| + NOTREACHED();
|
| + return gfx::Display();
|
| + }
|
|
|
| -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 = work_areas_[i];
|
| - overlap.Intersect(match_rect);
|
| - int area = overlap.width() * overlap.height();
|
| - if (area > max_area) {
|
| - max_area = area;
|
| - max_area_index = i;
|
| + virtual gfx::Display GetDisplayMatching(
|
| + const gfx::Rect& match_rect) const OVERRIDE {
|
| + int max_area = 0;
|
| + size_t max_area_index = 0;
|
| +
|
| + for (size_t i = 0; i < displays_.size(); ++i) {
|
| + gfx::Rect overlap = displays_[i].bounds();
|
| + overlap.Intersect(match_rect);
|
| + int area = overlap.width() * overlap.height();
|
| + if (area > max_area) {
|
| + max_area = area;
|
| + max_area_index = i;
|
| + }
|
| }
|
| + return displays_[max_area_index];
|
| }
|
| - return max_area_index;
|
| -}
|
| +
|
| + virtual gfx::Display GetPrimaryDisplay() const OVERRIDE {
|
| + return displays_[0];
|
| + }
|
| +
|
| + virtual void AddObserver(gfx::DisplayObserver* observer) OVERRIDE {
|
| + NOTREACHED();
|
| + }
|
| +
|
| + virtual void RemoveObserver(gfx::DisplayObserver* observer) OVERRIDE {
|
| + NOTREACHED();
|
| + }
|
| +
|
| + void AddDisplay(const gfx::Rect& bounds,
|
| + const gfx::Rect& work_area) {
|
| + gfx::Display display(displays_.size(), bounds);
|
| + display.set_work_area(work_area);
|
| + displays_.push_back(display);
|
| + }
|
| +
|
| + private:
|
| + std::vector<gfx::Display> displays_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(TestScreen);
|
| +};
|
| +
|
| +} // namespace
|
|
|
| TestStateProvider::TestStateProvider():
|
| has_persistent_data_(false),
|
| @@ -118,17 +164,17 @@ void GetWindowBoundsAndShowState(
|
| gfx::Rect* out_bounds,
|
| ui::WindowShowState* out_show_state) {
|
| DCHECK(out_show_state);
|
| - TestMonitorInfoProvider* mip = new TestMonitorInfoProvider;
|
| - mip->AddMonitor(monitor1_bounds, monitor1_work_area);
|
| + TestScreen test_screen;
|
| + test_screen.AddDisplay(monitor1_bounds, monitor1_work_area);
|
| if (!monitor2_bounds.IsEmpty())
|
| - mip->AddMonitor(monitor2_bounds, monitor2_bounds);
|
| + test_screen.AddDisplay(monitor2_bounds, monitor2_bounds);
|
| TestStateProvider* sp = new TestStateProvider;
|
| if (source == PERSISTED || source == BOTH)
|
| sp->SetPersistentState(bounds, work_area, show_state_persisted, true);
|
| if (source == LAST_ACTIVE || source == BOTH)
|
| sp->SetLastActiveState(bounds, show_state_last, true);
|
|
|
| - WindowSizer sizer(sp, mip, browser);
|
| + WindowSizer sizer(sp, &test_screen, browser);
|
| sizer.DetermineWindowBoundsAndShowState(passed_in,
|
| out_bounds,
|
| out_show_state);
|
| @@ -158,15 +204,15 @@ ui::WindowShowState GetWindowShowState(
|
| const gfx::Rect& display_config) {
|
| gfx::Rect bounds = display_config;
|
| gfx::Rect work_area = display_config;
|
| - TestMonitorInfoProvider* mip = new TestMonitorInfoProvider;
|
| - mip->AddMonitor(display_config, display_config);
|
| + TestScreen test_screen;
|
| + test_screen.AddDisplay(display_config, display_config);
|
| TestStateProvider* sp = new TestStateProvider;
|
| if (source == PERSISTED || source == BOTH)
|
| sp->SetPersistentState(bounds, work_area, show_state_persisted, true);
|
| if (source == LAST_ACTIVE || source == BOTH)
|
| sp->SetLastActiveState(bounds, show_state_last, true);
|
|
|
| - WindowSizer sizer(sp, mip, browser);
|
| + WindowSizer sizer(sp, &test_screen, browser);
|
|
|
| ui::WindowShowState out_show_state = ui::SHOW_STATE_DEFAULT;
|
| gfx::Rect out_bounds;
|
|
|