diff options
author | skuhne@chromium.org <skuhne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-11 14:53:55 +0000 |
---|---|---|
committer | skuhne@chromium.org <skuhne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-11 14:53:55 +0000 |
commit | 8eb3ec7a02c8b90545a70cb28df263780ad9bcd3 (patch) | |
tree | be3091ed8c0dd823092ff189db8dfe545614b0e2 | |
parent | 8bba0da89ce9a659c1979d496cb6d5d0f409576e (diff) | |
download | chromium_src-8eb3ec7a02c8b90545a70cb28df263780ad9bcd3.zip chromium_src-8eb3ec7a02c8b90545a70cb28df263780ad9bcd3.tar.gz chromium_src-8eb3ec7a02c8b90545a70cb28df263780ad9bcd3.tar.bz2 |
Adding new window position logic unit tests.
BUG=121181
TEST=unit test
Review URL: http://codereview.chromium.org/10024035
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@131766 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ash/test/ash_test_base.h | 2 | ||||
-rw-r--r-- | chrome/browser/ui/window_sizer.cc | 6 | ||||
-rw-r--r-- | chrome/browser/ui/window_sizer.h | 6 | ||||
-rw-r--r-- | chrome/browser/ui/window_sizer_aura.cc | 23 | ||||
-rw-r--r-- | chrome/browser/ui/window_sizer_aura_unittest.cc | 668 | ||||
-rw-r--r-- | chrome/browser/ui/window_sizer_common_unittest.h | 194 | ||||
-rw-r--r-- | chrome/browser/ui/window_sizer_unittest.cc | 297 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 10 | ||||
-rw-r--r-- | ui/aura/test/aura_test_helper.h | 2 |
9 files changed, 969 insertions, 239 deletions
diff --git a/ash/test/ash_test_base.h b/ash/test/ash_test_base.h index e7b929f..d78abac 100644 --- a/ash/test/ash_test_base.h +++ b/ash/test/ash_test_base.h @@ -19,6 +19,8 @@ class AshTestBase : public testing::Test { AshTestBase(); virtual ~AshTestBase(); + MessageLoopForUI* message_loop() { return helper_.message_loop(); } + // testing::Test: virtual void SetUp() OVERRIDE; virtual void TearDown() OVERRIDE; diff --git a/chrome/browser/ui/window_sizer.cc b/chrome/browser/ui/window_sizer.cc index 38b7cfe..0f7ed40 100644 --- a/chrome/browser/ui/window_sizer.cc +++ b/chrome/browser/ui/window_sizer.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -124,6 +124,10 @@ class DefaultStateProvider : public WindowSizer::StateProvider { /////////////////////////////////////////////////////////////////////////////// // WindowSizer, public: +// The number of pixels which are kept free top, left and right when a window +// gets positioned to its default location. +const int WindowSizer::kDesktopBorderSize = 16; + WindowSizer::WindowSizer(StateProvider* state_provider, const Browser* browser) : state_provider_(state_provider), monitor_info_provider_(new DefaultMonitorInfoProvider), diff --git a/chrome/browser/ui/window_sizer.h b/chrome/browser/ui/window_sizer.h index 21b6165..9a3553c 100644 --- a/chrome/browser/ui/window_sizer.h +++ b/chrome/browser/ui/window_sizer.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -96,6 +96,10 @@ class WindowSizer { // Returns the default origin for popups of the given size. static gfx::Point GetDefaultPopupOrigin(const gfx::Size& size); + // The number of pixels which are kept free top, left and right when a window + // gets positioned to its default location. + static const int kDesktopBorderSize; + // How much horizontal and vertical offset there is between newly // opened windows. This value may be different on each platform. static const int kWindowTilePixels; diff --git a/chrome/browser/ui/window_sizer_aura.cc b/chrome/browser/ui/window_sizer_aura.cc index c0ba053..ce7a94b 100644 --- a/chrome/browser/ui/window_sizer_aura.cc +++ b/chrome/browser/ui/window_sizer_aura.cc @@ -77,8 +77,8 @@ const int WindowSizer::kWindowTilePixels = 10; // static gfx::Point WindowSizer::GetDefaultPopupOrigin(const gfx::Size& size) { - // TODO(oshima):This is used to control panel/popups, and this may not be - // needed on aura environment as they must be controlled by WM. + // TODO(skuhne): Check if this isn't needed anymore (since it is implemented + // in WindowPositioner) and remove it. return gfx::Point(); } @@ -110,21 +110,24 @@ void WindowSizer::GetDefaultWindowBounds(gfx::Rect* default_bounds) const { gfx::Rect work_area = monitor_info_provider_->GetPrimaryMonitorWorkArea(); - DCHECK_EQ(16, ash::Shell::GetInstance()->GetGridSize()); - int border = 16; + DCHECK_EQ(kDesktopBorderSize, ash::Shell::GetInstance()->GetGridSize()); // There should be a 'desktop' border around the window at the left and right // side. - int default_width = work_area.width() - 2 * border; + int default_width = work_area.width() - 2 * kDesktopBorderSize; // There should also be a 'desktop' border around the window at the top. // Since the workspace excludes the tray area we only need one border size. - int default_height = work_area.height() - border; - if (default_width > 1280) { + int default_height = work_area.height() - kDesktopBorderSize; + int offset_x = kDesktopBorderSize; + int maximum_window_width = 1280; + if (default_width > maximum_window_width) { + // The window should get centered on the screen as well. + offset_x = (work_area.width() - maximum_window_width) / 2; // Never make a window wider then 1280. - default_width = 1280; + default_width = maximum_window_width; } - default_bounds->SetRect(work_area.x() + border, - work_area.y() + border, + default_bounds->SetRect(work_area.x() + offset_x, + work_area.y() + kDesktopBorderSize, default_width, default_height); } diff --git a/chrome/browser/ui/window_sizer_aura_unittest.cc b/chrome/browser/ui/window_sizer_aura_unittest.cc new file mode 100644 index 0000000..9d09b87 --- /dev/null +++ b/chrome/browser/ui/window_sizer_aura_unittest.cc @@ -0,0 +1,668 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/window_sizer.h" + +#include <vector> + +#include "ash/shell.h" +#include "ash/shell_window_ids.h" +#include "ash/test/ash_test_base.h" +#include "ash/test/test_shell_delegate.h" +#include "base/compiler_specific.h" +#include "base/logging.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/window_sizer_common_unittest.h" +#include "chrome/test/base/testing_profile.h" +#include "chrome/test/base/test_browser_window.h" +#include "content/public/browser/browser_thread.h" +#include "content/test/render_view_test.h" +#include "content/test/test_browser_thread.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" +#include "ui/aura/env.h" +#include "ui/aura/root_window.h" +#include "ui/aura/test/test_windows.h" + + +namespace { + +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(); + ~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); +}; + +WindowSizerTestWithBrowser::WindowSizerTestWithBrowser() { + // Set up a UI message thread. + MessageLoopForUI* ui_loop = message_loop(); + ui_thread_.reset( + new content::TestBrowserThread(content::BrowserThread::UI, ui_loop)); +} + +WindowSizerTestWithBrowser::~WindowSizerTestWithBrowser() { +} + +// A browser window proxy which is able to associate an aura native window with +// it. +class TestBrowserWindowAura : public TestBrowserWindow { + public: + TestBrowserWindowAura(Browser* browser, aura::Window *native_window); + ~TestBrowserWindowAura(); + + gfx::NativeWindow GetNativeHandle() OVERRIDE { return native_window_; } + + private: + gfx::NativeWindow native_window_; + + DISALLOW_COPY_AND_ASSIGN(TestBrowserWindowAura); +}; + +} // namespace + +TestBrowserWindowAura::TestBrowserWindowAura(Browser* browser, + aura::Window *native_window) : + TestBrowserWindow(browser), + native_window_(native_window) { +} + +TestBrowserWindowAura::~TestBrowserWindowAura() {} + +// Test that the window is sized appropriately for the first run experience +// where the default window bounds calculation is invoked. +TEST_F(WindowSizerTest, DefaultSizeCase) { + EXPECT_EQ(WindowSizer::kDesktopBorderSize, + ash::Shell::GetInstance()->GetGridSize()); + { // 4:3 monitor case, 1024x768, no taskbar + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(), + gfx::Rect(), DEFAULT, &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, + WindowSizer::kDesktopBorderSize, + 1024 - WindowSizer::kDesktopBorderSize * 2, + 768 - WindowSizer::kDesktopBorderSize), + window_bounds); + } + + { // 4:3 monitor case, 1024x768, taskbar on bottom + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, taskbar_bottom_work_area, gfx::Rect(), + gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, + WindowSizer::kDesktopBorderSize, + 1024 - WindowSizer::kDesktopBorderSize * 2, + (taskbar_bottom_work_area.height() - + WindowSizer::kDesktopBorderSize)), + window_bounds); + } + + { // 4:3 monitor case, 1024x768, taskbar on right + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, taskbar_right_work_area, gfx::Rect(), + gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, + WindowSizer::kDesktopBorderSize, + taskbar_right_work_area.width() - + WindowSizer::kDesktopBorderSize*2, + 768 - WindowSizer::kDesktopBorderSize), + window_bounds); + } + + { // 4:3 monitor case, 1024x768, taskbar on left + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, taskbar_left_work_area, gfx::Rect(), + gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(taskbar_left_work_area.x() + + WindowSizer::kDesktopBorderSize, + WindowSizer::kDesktopBorderSize, + taskbar_left_work_area.width() - + WindowSizer::kDesktopBorderSize * 2, + taskbar_left_work_area.height() - + WindowSizer::kDesktopBorderSize), + window_bounds); + } + + { // 4:3 monitor case, 1024x768, taskbar on top + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, taskbar_top_work_area, gfx::Rect(), + gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, + taskbar_top_work_area.y() + + WindowSizer::kDesktopBorderSize, + 1024 - WindowSizer::kDesktopBorderSize * 2, + taskbar_top_work_area.height() - + WindowSizer::kDesktopBorderSize), + window_bounds); + } + + { // 4:3 monitor case, 1280x1024 + gfx::Rect window_bounds; + GetWindowBounds(twelveeighty, twelveeighty, gfx::Rect(), gfx::Rect(), + gfx::Rect(), DEFAULT, &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, + WindowSizer::kDesktopBorderSize, + 1280 - 2 * WindowSizer::kDesktopBorderSize, + 1024 - WindowSizer::kDesktopBorderSize), + window_bounds); + } + + { // 4:3 monitor case, 1600x1200 + gfx::Rect window_bounds; + GetWindowBounds(sixteenhundred, sixteenhundred, gfx::Rect(), gfx::Rect(), + gfx::Rect(), DEFAULT, &window_bounds, NULL); + EXPECT_EQ(gfx::Rect((1600 - 1280) / 2, WindowSizer::kDesktopBorderSize, + 1280, + 1200 - WindowSizer::kDesktopBorderSize), + window_bounds); + } + + { // 16:10 monitor case, 1680x1050 + gfx::Rect window_bounds; + GetWindowBounds(sixteeneighty, sixteeneighty, gfx::Rect(), gfx::Rect(), + gfx::Rect(), DEFAULT, &window_bounds, NULL); + EXPECT_EQ(gfx::Rect((1680 - 1280) / 2, WindowSizer::kDesktopBorderSize, + 1280, + 1050 - WindowSizer::kDesktopBorderSize), + window_bounds); + } + + { // 16:10 monitor case, 1920x1200 + gfx::Rect window_bounds; + GetWindowBounds(nineteentwenty, nineteentwenty, gfx::Rect(), gfx::Rect(), + gfx::Rect(), DEFAULT, &window_bounds, NULL); + EXPECT_EQ(gfx::Rect((1920 - 1280) / 2, WindowSizer::kDesktopBorderSize, + 1280, + 1200 - WindowSizer::kDesktopBorderSize), + window_bounds); + } +} + +// Test that the next opened window is positioned appropriately given the +// bounds of an existing window of the same type. +TEST_F(WindowSizerTest, LastWindowBoundsCase) { + { // normal, in the middle of the screen somewhere. + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + gfx::Rect(WindowSizer::kDesktopBorderSize, + WindowSizer::kDesktopBorderSize, 500, 400), + gfx::Rect(), LAST_ACTIVE, &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(kWindowTilePixels + WindowSizer::kDesktopBorderSize, + kWindowTilePixels + WindowSizer::kDesktopBorderSize, + 500, 400), + window_bounds); + } + + { // taskbar on top. + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, taskbar_top_work_area, gfx::Rect(), + gfx::Rect(WindowSizer::kDesktopBorderSize, + WindowSizer::kDesktopBorderSize, 500, 400), + gfx::Rect(), LAST_ACTIVE, &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(kWindowTilePixels + WindowSizer::kDesktopBorderSize, + std::max(kWindowTilePixels + + WindowSizer::kDesktopBorderSize, + 34 /* toolbar height */), + 500, 400), window_bounds); + } + + { // Too small to satisify the minimum visibility condition. + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + gfx::Rect(WindowSizer::kDesktopBorderSize, + WindowSizer::kDesktopBorderSize, 29, 29), + gfx::Rect(), LAST_ACTIVE, &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(kWindowTilePixels + WindowSizer::kDesktopBorderSize, + kWindowTilePixels + WindowSizer::kDesktopBorderSize, + 30 /* not 29 */, + 30 /* not 29 */), + window_bounds); + } + + + { // Normal. + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + gfx::Rect(WindowSizer::kDesktopBorderSize, + WindowSizer::kDesktopBorderSize, 500, 400), + gfx::Rect(), LAST_ACTIVE, &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(kWindowTilePixels + WindowSizer::kDesktopBorderSize, + kWindowTilePixels + WindowSizer::kDesktopBorderSize, + 500, 400), + window_bounds); + } +} + +// Test that the window opened is sized appropriately given persisted sizes. +TEST_F(WindowSizerTest, PersistedBoundsCase) { + { // normal, in the middle of the screen somewhere. + gfx::Rect initial_bounds(WindowSizer::kDesktopBorderSize, + WindowSizer::kDesktopBorderSize, 500, 400); + + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), initial_bounds, + gfx::Rect(), PERSISTED, &window_bounds, NULL); + EXPECT_EQ(initial_bounds, window_bounds); + } + + { // Normal. + gfx::Rect initial_bounds(0, 0, 1024, 768); + + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), initial_bounds, + gfx::Rect(), PERSISTED, &window_bounds, NULL); + EXPECT_EQ(initial_bounds, window_bounds); + } + + { // normal, on non-primary monitor in negative coords. + gfx::Rect initial_bounds(-600, 10, 500, 400); + + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, left_nonprimary, + initial_bounds, gfx::Rect(), PERSISTED, &window_bounds, + NULL); + EXPECT_EQ(initial_bounds, window_bounds); + } + + { // normal, on non-primary monitor in negative coords. + gfx::Rect initial_bounds(-1024, 0, 1024, 768); + + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, left_nonprimary, + initial_bounds, gfx::Rect(), PERSISTED, &window_bounds, + NULL); + EXPECT_EQ(initial_bounds, window_bounds); + } + + { // Non-primary monitor resoultion has changed, but the monitor still + // completely contains the window. + + gfx::Rect initial_bounds(1074, 50, 600, 500); + + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(1024, 0, 800, 600), + initial_bounds, right_nonprimary, PERSISTED, + &window_bounds, NULL); + EXPECT_EQ(initial_bounds, window_bounds); + } + + { // Non-primary monitor resoultion has changed, and the window is partially + // off-screen. + + gfx::Rect initial_bounds(1274, 50, 600, 500); + + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(1024, 0, 800, 600), + initial_bounds, right_nonprimary, PERSISTED, + &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(1224, 50, 600, 500), window_bounds); + } + + { // Non-primary monitor resoultion has changed, and the window is now too + // large for the monitor. + + gfx::Rect initial_bounds(1274, 50, 900, 700); + + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(1024, 0, 800, 600), + initial_bounds, right_nonprimary, PERSISTED, + &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(1024, 0, 800, 600), window_bounds); + } + + { // width and height too small + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + gfx::Rect(WindowSizer::kDesktopBorderSize, + WindowSizer::kDesktopBorderSize, 29, 29), + gfx::Rect(), PERSISTED, &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, + WindowSizer::kDesktopBorderSize, + 30 /* not 29 */, 30 /* not 29 */), + window_bounds); + } +} + +////////////////////////////////////////////////////////////////////////////// +// The following unittests have different results on Mac/non-Mac because we +// reposition windows aggressively on Mac. The *WithAggressiveReposition tests +// are run on Mac, and the *WithNonAggressiveRepositioning tests are run on +// other platforms. + +TEST_F(WindowSizerTest, LastWindowOffscreenWithNonAggressiveRepositioning) { + { // taskbar on left. + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, taskbar_left_work_area, gfx::Rect(), + gfx::Rect(WindowSizer::kDesktopBorderSize, + WindowSizer::kDesktopBorderSize, 500, 400), + gfx::Rect(), LAST_ACTIVE, &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(kWindowTilePixels + WindowSizer::kDesktopBorderSize, + kWindowTilePixels + WindowSizer::kDesktopBorderSize, + 500, 400), + window_bounds); + } + + { // offset would put the new window offscreen at the bottom but the minimum + // visibility condition is barely satisfied without relocation. + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + gfx::Rect(10, 728, 500, 400), gfx::Rect(), LAST_ACTIVE, + &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(10 + kWindowTilePixels, 738, + 500, 400), window_bounds); + } + + { // offset would put the new window offscreen at the bottom and the minimum + // visibility condition is satisified by relocation. + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + gfx::Rect(10, 729, 500, 400), gfx::Rect(), LAST_ACTIVE, + &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(10 + kWindowTilePixels, 738 /* not 739 */, 500, 400), + window_bounds); + } + + { // offset would put the new window offscreen at the right but the minimum + // visibility condition is barely satisfied without relocation. + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + gfx::Rect(984, 10, 500, 400), gfx::Rect(), LAST_ACTIVE, + &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(994, 10 + kWindowTilePixels, 500, 400), window_bounds); + } + + { // offset would put the new window offscreen at the right and the minimum + // visibility condition is satisified by relocation. + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + gfx::Rect(985, 10, 500, 400), gfx::Rect(), LAST_ACTIVE, + &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(994 /* not 995 */, 10 + kWindowTilePixels, + 500, 400), window_bounds); + } + + { // offset would put the new window offscreen at the bottom right and the + // minimum visibility condition is satisified by relocation. + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + gfx::Rect(985, 729, 500, 400), gfx::Rect(), LAST_ACTIVE, + &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(994 /* not 995 */, 738 /* not 739 */, 500, 400), + window_bounds); + } +} + +TEST_F(WindowSizerTest, + PersistedWindowOffscreenWithNonAggressiveRepositioning) { + { // off the left but the minimum visibility condition is barely satisfied + // without relocaiton. + gfx::Rect initial_bounds(-470, 50, 500, 400); + + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + initial_bounds, gfx::Rect(), PERSISTED, + &window_bounds, NULL); + EXPECT_EQ(initial_bounds, window_bounds); + } + + { // off the left and the minimum visibility condition is satisfied by + // relocation. + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + gfx::Rect(-471, 50, 500, 400), gfx::Rect(), PERSISTED, + &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(-470 /* not -471 */, 50, 500, 400), window_bounds); + } + + { // off the top + gfx::Rect initial_bounds(50, -370, 500, 400); + + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + gfx::Rect(50, -370, 500, 400), gfx::Rect(), PERSISTED, + &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(50, 0, 500, 400), window_bounds); + } + + { // off the right but the minimum visibility condition is barely satisified + // without relocation. + gfx::Rect initial_bounds(994, 50, 500, 400); + + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + initial_bounds, gfx::Rect(), PERSISTED, + &window_bounds, NULL); + EXPECT_EQ(initial_bounds, window_bounds); + } + + { // off the right and the minimum visibility condition is satisified by + // relocation. + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + gfx::Rect(995, 50, 500, 400), gfx::Rect(), PERSISTED, + &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(994 /* not 995 */, 50, 500, 400), window_bounds); + } + + { // off the bottom but the minimum visibility condition is barely satisified + // without relocation. + gfx::Rect initial_bounds(50, 738, 500, 400); + + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + initial_bounds, gfx::Rect(), PERSISTED, + &window_bounds, NULL); + EXPECT_EQ(initial_bounds, window_bounds); + } + + { // off the bottom and the minimum visibility condition is satisified by + // relocation. + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + gfx::Rect(50, 739, 500, 400), gfx::Rect(), PERSISTED, + &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(50, 738 /* not 739 */, 500, 400), window_bounds); + } + + { // off the topleft + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + gfx::Rect(-471, -371, 500, 400), gfx::Rect(), PERSISTED, + &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(-470 /* not -471 */, 0, 500, 400), + window_bounds); + } + + { // off the topright and the minimum visibility condition is satisified by + // relocation. + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + gfx::Rect(995, -371, 500, 400), gfx::Rect(), PERSISTED, + &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(994 /* not 995 */, 0, 500, 400), + window_bounds); + } + + { // off the bottomleft and the minimum visibility condition is satisified by + // relocation. + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + gfx::Rect(-471, 739, 500, 400), gfx::Rect(), PERSISTED, + &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(-470 /* not -471 */, 738 /* not 739 */, 500, 400), + window_bounds); + } + + { // off the bottomright and the minimum visibility condition is satisified by + // relocation. + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + gfx::Rect(995, 739, 500, 400), gfx::Rect(), PERSISTED, + &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(994 /* not 995 */, 738 /* not 739 */, 500, 400), + window_bounds); + } + + { // entirely off left + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + gfx::Rect(-700, 50, 500, 400), gfx::Rect(), PERSISTED, + &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(-470 /* not -700 */, 50, 500, 400), window_bounds); + } + + { // entirely off left (monitor was detached since last run) + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + gfx::Rect(-700, 50, 500, 400), left_nonprimary, PERSISTED, + &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(0, 50, 500, 400), window_bounds); + } + + { // entirely off top + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + gfx::Rect(50, -500, 500, 400), gfx::Rect(), PERSISTED, + &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(50, 0, 500, 400), window_bounds); + } + + { // entirely off top (monitor was detached since last run) + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + gfx::Rect(50, -500, 500, 400), top_nonprimary, + PERSISTED, &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(50, 0, 500, 400), window_bounds); + } + + { // entirely off right + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + gfx::Rect(1200, 50, 500, 400), gfx::Rect(), PERSISTED, + &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(994 /* not 1200 */, 50, 500, 400), window_bounds); + } + + { // entirely off right (monitor was detached since last run) + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + gfx::Rect(1200, 50, 500, 400), right_nonprimary, + PERSISTED, &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(524, 50, 500, 400), window_bounds); + } + + { // entirely off bottom + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + gfx::Rect(50, 800, 500, 400), gfx::Rect(), PERSISTED, + &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(50, 738 /* not 800 */, 500, 400), window_bounds); + } + + { // entirely off bottom (monitor was detached since last run) + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + gfx::Rect(50, 800, 500, 400), bottom_nonprimary, + PERSISTED, &window_bounds, NULL); + EXPECT_EQ(gfx::Rect(50, 368, 500, 400), window_bounds); + } +} + +// Test that a newly created window gets positioned over a previously created +// window. +TEST_F(WindowSizerTestWithBrowser, PlaceNewWindowOverOldWindow) { + // Create a dummy window. + aura::Window* default_container = + ash::Shell::GetInstance()->GetContainer( + ash::internal::kShellWindowId_DefaultContainer); + scoped_ptr<aura::Window> window( + aura::test::CreateTestWindowWithId(0, default_container)); + window->SetBounds(gfx::Rect(16, 32, 640, 320)); + + scoped_ptr<aura::Window> popup( + aura::test::CreateTestWindowWithId(1, default_container)); + popup->SetBounds(gfx::Rect(16, 32, 128, 256)); + + scoped_ptr<aura::Window> panel( + aura::test::CreateTestWindowWithId(2, default_container)); + panel->SetBounds(gfx::Rect(32, 48, 256, 512)); + + // Create a browser which we can use to pass into the GetWindowBounds + // function. + scoped_ptr<TestingProfile> profile; + profile.reset(new TestingProfile()); + scoped_ptr<Browser> browser; + // Creating a popup handler here to make sure it does not interfere with the + // existing windows. + browser.reset(new Browser(Browser::TYPE_TABBED, profile.get())); + + scoped_ptr<Browser> window_owning_browser; + // Creating a popup handler here to make sure it does not interfere with the + // existing windows. + window_owning_browser.reset(new Browser(Browser::TYPE_TABBED, + profile.get())); + BrowserWindow* browser_window = new TestBrowserWindowAura( + window_owning_browser.get(), + window.get()); + window_owning_browser.get()->SetWindowForTesting(browser_window); + + scoped_ptr<Browser> popup_owning_browser; + // Creating a popup to make sure it does not interfere with the positioning. + popup_owning_browser.reset(new Browser(Browser::TYPE_POPUP, + profile.get())); + BrowserWindow* browser_popup = new TestBrowserWindowAura( + popup_owning_browser.get(), + popup.get()); + popup_owning_browser.get()->SetWindowForTesting(browser_popup); + + scoped_ptr<Browser> panel_owning_browser; + // Creating a panel to make sure it does not interfere with the positioning. + panel_owning_browser.reset(new Browser(Browser::TYPE_PANEL, + profile.get())); + BrowserWindow* browser_panel = new TestBrowserWindowAura( + panel_owning_browser.get(), + panel.get()); + panel_owning_browser.get()->SetWindowForTesting(browser_panel); + + window->Show(); + { // With a shown window it's size should get returned. + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + gfx::Rect(50, 100, 300, 150), bottom_nonprimary, + PERSISTED, &window_bounds, browser.get()); + EXPECT_EQ(gfx::Rect(16, 32, 640, 320), window_bounds); + } + + { // Make sure that popups do not get changed. + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + gfx::Rect(50, 100, 300, 150), bottom_nonprimary, + PERSISTED, &window_bounds, popup_owning_browser.get()); + EXPECT_EQ(gfx::Rect(50, 100, 300, 150), window_bounds); + } + + window->Hide(); + { // If a window is there but not shown the default should be returned. + // The existing popup should not have any impact as well. + gfx::Rect window_bounds; + GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), + gfx::Rect(50, 100, 300, 150), bottom_nonprimary, + PERSISTED, &window_bounds, browser.get()); + EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, + WindowSizer::kDesktopBorderSize, + 1024 - 2 * WindowSizer::kDesktopBorderSize, + 768 - WindowSizer::kDesktopBorderSize), + window_bounds); + } +} diff --git a/chrome/browser/ui/window_sizer_common_unittest.h b/chrome/browser/ui/window_sizer_common_unittest.h new file mode 100644 index 0000000..e56ecda --- /dev/null +++ b/chrome/browser/ui/window_sizer_common_unittest.h @@ -0,0 +1,194 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_WINDOW_SIZER_COMMON_UNITTEST_H_ +#define CHROME_BROWSER_UI_WINDOW_SIZER_COMMON_UNITTEST_H_ +#pragma once + +// 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); +static const gfx::Rect sixteenhundred(0, 0, 1600, 1200); +static const gfx::Rect sixteeneighty(0, 0, 1680, 1050); +static const gfx::Rect nineteentwenty(0, 0, 1920, 1200); + +// Represents a 1024x768 monitor that is not the primary monitor, arranged to +// the immediate left of the primary 1024x768 monitor. +static const gfx::Rect left_nonprimary(-1024, 0, 1024, 768); + +// Represents a 1024x768 monitor that is not the primary monitor, arranged to +// the immediate right of the primary 1024x768 monitor. +static const gfx::Rect right_nonprimary(1024, 0, 1024, 768); + +// Represents a 1024x768 monitor that is not the primary monitor, arranged to +// the immediate top of the primary 1024x768 monitor. +static const gfx::Rect top_nonprimary(0, -768, 1024, 768); + +// Represents a 1024x768 monitor that is not the primary monitor, arranged to +// the immediate bottom of the primary 1024x768 monitor. +static const gfx::Rect bottom_nonprimary(0, 768, 1024, 768); + +// The work area for 1024x768 monitors with different taskbar orientations. +static const gfx::Rect taskbar_bottom_work_area(0, 0, 1024, 734); +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; + +// Testing implementation of WindowSizer::MonitorInfoProvider that we can use +// to fake various monitor layouts and sizes. +class TestMonitorInfoProvider : public MonitorInfoProvider { + public: + TestMonitorInfoProvider(); + virtual ~TestMonitorInfoProvider(); + + void AddMonitor(const gfx::Rect& bounds, const gfx::Rect& work_area); + + // Overridden from WindowSizer::MonitorInfoProvider: + virtual gfx::Rect GetPrimaryMonitorWorkArea() const OVERRIDE; + + virtual gfx::Rect GetPrimaryMonitorBounds() const OVERRIDE; + + virtual gfx::Rect GetMonitorWorkAreaMatching( + const gfx::Rect& match_rect) const OVERRIDE; + + private: + size_t GetMonitorIndexMatchingBounds(const gfx::Rect& match_rect) const; + + std::vector<gfx::Rect> monitor_bounds_; + std::vector<gfx::Rect> work_areas_; + + 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::GetPrimaryMonitorWorkArea() const { + return work_areas_[0]; +} + +gfx::Rect TestMonitorInfoProvider::GetPrimaryMonitorBounds() 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(); + + void SetPersistentState(const gfx::Rect& bounds, + const gfx::Rect& work_area, + bool has_persistent_data); + void SetLastActiveState(const gfx::Rect& bounds, 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; + + private: + gfx::Rect persistent_bounds_; + gfx::Rect persistent_work_area_; + bool has_persistent_data_; + + gfx::Rect last_active_bounds_; + bool has_last_active_data_; + + 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) { + 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(gfx::Rect(), out_bounds); +} + +#endif // CHROME_BROWSER_UI_WINDOW_SIZER_COMMON_UNITTEST_H_ diff --git a/chrome/browser/ui/window_sizer_unittest.cc b/chrome/browser/ui/window_sizer_unittest.cc index d7b91bff..fb7a3a8 100644 --- a/chrome/browser/ui/window_sizer_unittest.cc +++ b/chrome/browser/ui/window_sizer_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,172 +6,18 @@ #include <vector> -// TODO(skuhne): Get these unit tests to work once the beta is out. -#if !defined(USE_ASH) - #include "base/compiler_specific.h" #include "base/logging.h" +#include "chrome/browser/ui/window_sizer_common_unittest.h" #include "testing/gtest/include/gtest/gtest.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); -static const gfx::Rect sixteenhundred(0, 0, 1600, 1200); -static const gfx::Rect sixteeneighty(0, 0, 1680, 1050); -static const gfx::Rect nineteentwenty(0, 0, 1920, 1200); - -// Represents a 1024x768 monitor that is not the primary monitor, arranged to -// the immediate left of the primary 1024x768 monitor. -static const gfx::Rect left_nonprimary(-1024, 0, 1024, 768); - -// Represents a 1024x768 monitor that is not the primary monitor, arranged to -// the immediate right of the primary 1024x768 monitor. -static const gfx::Rect right_nonprimary(1024, 0, 1024, 768); - -// Represents a 1024x768 monitor that is not the primary monitor, arranged to -// the immediate top of the primary 1024x768 monitor. -static const gfx::Rect top_nonprimary(0, -768, 1024, 768); - -// Represents a 1024x768 monitor that is not the primary monitor, arranged to -// the immediate bottom of the primary 1024x768 monitor. -static const gfx::Rect bottom_nonprimary(0, 768, 1024, 768); - -// The work area for 1024x768 monitors with different taskbar orientations. -static const gfx::Rect taskbar_bottom_work_area(0, 0, 1024, 734); -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; - -// Testing implementation of WindowSizer::MonitorInfoProvider that we can use -// to fake various monitor layouts and sizes. -class TestMonitorInfoProvider : public MonitorInfoProvider { - public: - TestMonitorInfoProvider() {} - virtual ~TestMonitorInfoProvider() {} - - void 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: - virtual gfx::Rect GetPrimaryMonitorWorkArea() const OVERRIDE { - return work_areas_[0]; - } - - virtual gfx::Rect GetPrimaryMonitorBounds() const OVERRIDE { - return monitor_bounds_[0]; - } - - virtual gfx::Rect GetMonitorWorkAreaMatching( - const gfx::Rect& match_rect) const OVERRIDE { - return work_areas_[GetMonitorIndexMatchingBounds(match_rect)]; - } - - private: - size_t 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; - } - - std::vector<gfx::Rect> monitor_bounds_; - std::vector<gfx::Rect> work_areas_; - - DISALLOW_COPY_AND_ASSIGN(TestMonitorInfoProvider); -}; - -// Testing implementation of WindowSizer::StateProvider that we use to fake -// persistent storage and existing windows. -class TestStateProvider : public WindowSizer::StateProvider { - public: - TestStateProvider() - : has_persistent_data_(false), - has_last_active_data_(false) { - } - virtual ~TestStateProvider() {} - - void 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 SetLastActiveState(const gfx::Rect& bounds, bool has_last_active_data) { - last_active_bounds_ = bounds; - has_last_active_data_ = has_last_active_data; - } - - // Overridden from WindowSizer::StateProvider: - virtual bool GetPersistentState(gfx::Rect* bounds, - gfx::Rect* saved_work_area) const { - *bounds = persistent_bounds_; - *saved_work_area = persistent_work_area_; - return has_persistent_data_; - } - - virtual bool GetLastActiveWindowState(gfx::Rect* bounds) const { - *bounds = last_active_bounds_; - return has_last_active_data_; - } - - private: - gfx::Rect persistent_bounds_; - gfx::Rect persistent_work_area_; - bool has_persistent_data_; - - gfx::Rect last_active_bounds_; - bool has_last_active_data_; - - DISALLOW_COPY_AND_ASSIGN(TestStateProvider); -}; - -// 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) { - 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); - // TODO(skuhne): Need to pass browser instance here. - WindowSizer sizer(sp, mip, NULL); - sizer.DetermineWindowBounds(gfx::Rect(), out_bounds); -} - // Test that the window is sized appropriately for the first run experience // where the default window bounds calculation is invoked. TEST(WindowSizerTest, DefaultSizeCase) { { // 4:3 monitor case, 1024x768, no taskbar gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(), - gfx::Rect(), DEFAULT, &window_bounds); + gfx::Rect(), DEFAULT, &window_bounds, NULL); EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels, 1024 - kWindowTilePixels * 2, 768 - kWindowTilePixels * 2), @@ -181,7 +27,7 @@ TEST(WindowSizerTest, DefaultSizeCase) { { // 4:3 monitor case, 1024x768, taskbar on bottom gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, taskbar_bottom_work_area, gfx::Rect(), - gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds); + gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds, NULL); EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels, 1024 - kWindowTilePixels * 2, (taskbar_bottom_work_area.height() - @@ -192,7 +38,7 @@ TEST(WindowSizerTest, DefaultSizeCase) { { // 4:3 monitor case, 1024x768, taskbar on right gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, taskbar_right_work_area, gfx::Rect(), - gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds); + gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds, NULL); EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels, taskbar_right_work_area.width() - kWindowTilePixels*2, 768 - kWindowTilePixels * 2), @@ -202,7 +48,7 @@ TEST(WindowSizerTest, DefaultSizeCase) { { // 4:3 monitor case, 1024x768, taskbar on left gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, taskbar_left_work_area, gfx::Rect(), - gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds); + gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds, NULL); EXPECT_EQ(gfx::Rect(taskbar_left_work_area.x() + kWindowTilePixels, kWindowTilePixels, taskbar_left_work_area.width() - kWindowTilePixels * 2, @@ -214,7 +60,7 @@ TEST(WindowSizerTest, DefaultSizeCase) { { // 4:3 monitor case, 1024x768, taskbar on top gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, taskbar_top_work_area, gfx::Rect(), - gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds); + gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds, NULL); EXPECT_EQ(gfx::Rect(kWindowTilePixels, taskbar_top_work_area.y() + kWindowTilePixels, 1024 - kWindowTilePixels * 2, @@ -225,7 +71,7 @@ TEST(WindowSizerTest, DefaultSizeCase) { { // 4:3 monitor case, 1280x1024 gfx::Rect window_bounds; GetWindowBounds(twelveeighty, twelveeighty, gfx::Rect(), gfx::Rect(), - gfx::Rect(), DEFAULT, &window_bounds); + gfx::Rect(), DEFAULT, &window_bounds, NULL); EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels, 1050, 1024 - kWindowTilePixels * 2), @@ -235,7 +81,7 @@ TEST(WindowSizerTest, DefaultSizeCase) { { // 4:3 monitor case, 1600x1200 gfx::Rect window_bounds; GetWindowBounds(sixteenhundred, sixteenhundred, gfx::Rect(), gfx::Rect(), - gfx::Rect(), DEFAULT, &window_bounds); + gfx::Rect(), DEFAULT, &window_bounds, NULL); EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels, 1050, 1200 - kWindowTilePixels * 2), @@ -245,7 +91,7 @@ TEST(WindowSizerTest, DefaultSizeCase) { { // 16:10 monitor case, 1680x1050 gfx::Rect window_bounds; GetWindowBounds(sixteeneighty, sixteeneighty, gfx::Rect(), gfx::Rect(), - gfx::Rect(), DEFAULT, &window_bounds); + gfx::Rect(), DEFAULT, &window_bounds, NULL); EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels, 840 - static_cast<int>(kWindowTilePixels * 1.5), 1050 - kWindowTilePixels * 2), @@ -255,7 +101,7 @@ TEST(WindowSizerTest, DefaultSizeCase) { { // 16:10 monitor case, 1920x1200 gfx::Rect window_bounds; GetWindowBounds(nineteentwenty, nineteentwenty, gfx::Rect(), gfx::Rect(), - gfx::Rect(), DEFAULT, &window_bounds); + gfx::Rect(), DEFAULT, &window_bounds, NULL); EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels, 960 - static_cast<int>(kWindowTilePixels * 1.5), 1200 - kWindowTilePixels * 2), @@ -270,7 +116,7 @@ TEST(WindowSizerTest, LastWindowBoundsCase) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(kWindowTilePixels, kWindowTilePixels, 500, 400), - gfx::Rect(), LAST_ACTIVE, &window_bounds); + gfx::Rect(), LAST_ACTIVE, &window_bounds, NULL); EXPECT_EQ(gfx::Rect(kWindowTilePixels * 2, kWindowTilePixels * 2, 500, 400), window_bounds); } @@ -279,7 +125,7 @@ TEST(WindowSizerTest, LastWindowBoundsCase) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, taskbar_top_work_area, gfx::Rect(), gfx::Rect(kWindowTilePixels, kWindowTilePixels, 500, 400), - gfx::Rect(), LAST_ACTIVE, &window_bounds); + gfx::Rect(), LAST_ACTIVE, &window_bounds, NULL); EXPECT_EQ(gfx::Rect(kWindowTilePixels * 2, std::max(kWindowTilePixels * 2, 34 /* toolbar height */), @@ -290,7 +136,7 @@ TEST(WindowSizerTest, LastWindowBoundsCase) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(kWindowTilePixels, kWindowTilePixels, 29, 29), - gfx::Rect(), LAST_ACTIVE, &window_bounds); + gfx::Rect(), LAST_ACTIVE, &window_bounds, NULL); EXPECT_EQ(gfx::Rect(kWindowTilePixels * 2, kWindowTilePixels * 2, 30 /* not 29 */, @@ -303,7 +149,7 @@ TEST(WindowSizerTest, LastWindowBoundsCase) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(kWindowTilePixels, kWindowTilePixels, 500, 400), - gfx::Rect(), LAST_ACTIVE, &window_bounds); + gfx::Rect(), LAST_ACTIVE, &window_bounds, NULL); EXPECT_EQ(gfx::Rect(kWindowTilePixels * 2, kWindowTilePixels * 2, 500, 400), window_bounds); } @@ -316,7 +162,7 @@ TEST(WindowSizerTest, PersistedBoundsCase) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), initial_bounds, - gfx::Rect(), PERSISTED, &window_bounds); + gfx::Rect(), PERSISTED, &window_bounds, NULL); EXPECT_EQ(initial_bounds, window_bounds); } @@ -325,7 +171,7 @@ TEST(WindowSizerTest, PersistedBoundsCase) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), initial_bounds, - gfx::Rect(), PERSISTED, &window_bounds); + gfx::Rect(), PERSISTED, &window_bounds, NULL); EXPECT_EQ(initial_bounds, window_bounds); } @@ -334,7 +180,8 @@ TEST(WindowSizerTest, PersistedBoundsCase) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, left_nonprimary, - initial_bounds, gfx::Rect(), PERSISTED, &window_bounds); + initial_bounds, gfx::Rect(), PERSISTED, &window_bounds, + NULL); EXPECT_EQ(initial_bounds, window_bounds); } @@ -343,7 +190,8 @@ TEST(WindowSizerTest, PersistedBoundsCase) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, left_nonprimary, - initial_bounds, gfx::Rect(), PERSISTED, &window_bounds); + initial_bounds, gfx::Rect(), PERSISTED, &window_bounds, + NULL); EXPECT_EQ(initial_bounds, window_bounds); } @@ -355,7 +203,7 @@ TEST(WindowSizerTest, PersistedBoundsCase) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(1024, 0, 800, 600), initial_bounds, right_nonprimary, PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(initial_bounds, window_bounds); } @@ -367,7 +215,7 @@ TEST(WindowSizerTest, PersistedBoundsCase) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(1024, 0, 800, 600), initial_bounds, right_nonprimary, PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(1224, 50, 600, 500), window_bounds); } @@ -379,7 +227,7 @@ TEST(WindowSizerTest, PersistedBoundsCase) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(1024, 0, 800, 600), initial_bounds, right_nonprimary, PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(1024, 0, 800, 600), window_bounds); } @@ -387,7 +235,7 @@ TEST(WindowSizerTest, PersistedBoundsCase) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(kWindowTilePixels, kWindowTilePixels, 29, 29), - gfx::Rect(), PERSISTED, &window_bounds); + gfx::Rect(), PERSISTED, &window_bounds, NULL); EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels, 30 /* not 29 */, 30 /* not 29 */), window_bounds); @@ -401,7 +249,7 @@ TEST(WindowSizerTest, PersistedBoundsCase) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(kWindowTilePixels, kWindowTilePixels, 30, 5000), - gfx::Rect(), PERSISTED, &window_bounds); + gfx::Rect(), PERSISTED, &window_bounds, NULL); EXPECT_EQ(tentwentyfour.height(), window_bounds.height()); } #endif // defined(OS_MACOSX) @@ -420,7 +268,7 @@ TEST(WindowSizerTest, LastWindowOffscreenWithAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, taskbar_left_work_area, gfx::Rect(), gfx::Rect(kWindowTilePixels, kWindowTilePixels, 500, 400), - gfx::Rect(), LAST_ACTIVE, &window_bounds); + gfx::Rect(), LAST_ACTIVE, &window_bounds, NULL); EXPECT_EQ(gfx::Rect(taskbar_left_work_area.x(), kWindowTilePixels * 2, 500, 400), window_bounds); } @@ -429,7 +277,7 @@ TEST(WindowSizerTest, LastWindowOffscreenWithAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(10, 729, 500, 400), gfx::Rect(), LAST_ACTIVE, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(10 + kWindowTilePixels, 0 /* not 729 + kWindowTilePixels */, 500, 400), @@ -440,7 +288,7 @@ TEST(WindowSizerTest, LastWindowOffscreenWithAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(985, 10, 500, 400), gfx::Rect(), LAST_ACTIVE, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(0 /* not 985 + kWindowTilePixels*/, 10 + kWindowTilePixels, 500, 400), @@ -451,7 +299,7 @@ TEST(WindowSizerTest, LastWindowOffscreenWithAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(985, 729, 500, 400), gfx::Rect(), LAST_ACTIVE, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(0 /* not 985 + kWindowTilePixels*/, 0 /* not 729 + kWindowTilePixels*/, 500, 400), @@ -464,7 +312,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(-471, 50, 500, 400), gfx::Rect(), PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(0 /* not -471 */, 50, 500, 400), window_bounds); } @@ -472,7 +320,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(50, -370, 500, 400), gfx::Rect(), PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(50, 0, 500, 400), window_bounds); } @@ -480,7 +328,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(995, 50, 500, 400), gfx::Rect(), PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(0 /* not 995 */, 50, 500, 400), window_bounds); } @@ -488,7 +336,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(50, 739, 500, 400), gfx::Rect(), PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(50, 0 /* not 739 */, 500, 400), window_bounds); } @@ -496,7 +344,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(-471, -371, 500, 400), gfx::Rect(), PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(0 /* not -471 */, 0 /* not -371 */, 500, 400), window_bounds); } @@ -505,7 +353,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(995, -371, 500, 400), gfx::Rect(), PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(0 /* not 995 */, 0 /* not -371 */, 500, 400), window_bounds); } @@ -514,7 +362,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(-471, 739, 500, 400), gfx::Rect(), PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(0 /* not -471 */, 0 /* not 739 */, 500, 400), window_bounds); } @@ -523,7 +371,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(995, 739, 500, 400), gfx::Rect(), PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(0 /* not 995 */, 0 /* not 739 */, 500, 400), window_bounds); } @@ -532,7 +380,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(-700, 50, 500, 400), gfx::Rect(), PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(0 /* not -700 */, 50, 500, 400), window_bounds); } @@ -540,7 +388,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(-700, 50, 500, 400), left_nonprimary, - PERSISTED, &window_bounds); + PERSISTED, &window_bounds, NULL); EXPECT_EQ(gfx::Rect(0, 50, 500, 400), window_bounds); } @@ -548,7 +396,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(50, -500, 500, 400), gfx::Rect(), PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(50, 0, 500, 400), window_bounds); } @@ -556,7 +404,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(50, -500, 500, 400), top_nonprimary, PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(50, 0, 500, 400), window_bounds); } @@ -564,7 +412,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(1200, 50, 500, 400), gfx::Rect(), PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(0 /* not 1200 */, 50, 500, 400), window_bounds); } @@ -572,7 +420,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(1200, 50, 500, 400), right_nonprimary, PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(524 /* not 1200 */, 50, 500, 400), window_bounds); } @@ -580,7 +428,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(50, 800, 500, 400), gfx::Rect(), PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(50, 0 /* not 800 */, 500, 400), window_bounds); } @@ -588,7 +436,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(50, 800, 500, 400), bottom_nonprimary, - PERSISTED, &window_bounds); + PERSISTED, &window_bounds, NULL); EXPECT_EQ(gfx::Rect(50, 368 /* not 800 */, 500, 400), window_bounds); } @@ -596,7 +444,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(-100, 50, 2000, 400), gfx::Rect(), PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(0 /* not -100 */, 50, 2000, 400), window_bounds); } } @@ -606,7 +454,7 @@ TEST(WindowSizerTest, LastWindowOffscreenWithNonAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, taskbar_left_work_area, gfx::Rect(), gfx::Rect(kWindowTilePixels, kWindowTilePixels, 500, 400), - gfx::Rect(), LAST_ACTIVE, &window_bounds); + gfx::Rect(), LAST_ACTIVE, &window_bounds, NULL); EXPECT_EQ(gfx::Rect(kWindowTilePixels * 2, kWindowTilePixels * 2, 500, 400), window_bounds); } @@ -618,7 +466,7 @@ TEST(WindowSizerTest, LastWindowOffscreenWithNonAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(10, 728, 500, 400), gfx::Rect(), LAST_ACTIVE, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(10 + kWindowTilePixels, 738, 500, 400), window_bounds); } @@ -628,7 +476,7 @@ TEST(WindowSizerTest, LastWindowOffscreenWithNonAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(10, 729, 500, 400), gfx::Rect(), LAST_ACTIVE, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(10 + kWindowTilePixels, 738 /* not 739 */, 500, 400), window_bounds); } @@ -638,7 +486,7 @@ TEST(WindowSizerTest, LastWindowOffscreenWithNonAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(984, 10, 500, 400), gfx::Rect(), LAST_ACTIVE, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(994, 10 + kWindowTilePixels, 500, 400), window_bounds); } @@ -647,7 +495,7 @@ TEST(WindowSizerTest, LastWindowOffscreenWithNonAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(985, 10, 500, 400), gfx::Rect(), LAST_ACTIVE, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(994 /* not 995 */, 10 + kWindowTilePixels, 500, 400), window_bounds); } @@ -657,7 +505,7 @@ TEST(WindowSizerTest, LastWindowOffscreenWithNonAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(985, 729, 500, 400), gfx::Rect(), LAST_ACTIVE, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(994 /* not 995 */, 738 /* not 739 */, 500, 400), window_bounds); } @@ -672,7 +520,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithNonAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), initial_bounds, gfx::Rect(), PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(initial_bounds, window_bounds); } @@ -681,7 +529,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithNonAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(-471, 50, 500, 400), gfx::Rect(), PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(-470 /* not -471 */, 50, 500, 400), window_bounds); } @@ -691,7 +539,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithNonAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(50, -370, 500, 400), gfx::Rect(), PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(50, 0, 500, 400), window_bounds); } @@ -702,7 +550,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithNonAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), initial_bounds, gfx::Rect(), PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(initial_bounds, window_bounds); } @@ -711,7 +559,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithNonAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(995, 50, 500, 400), gfx::Rect(), PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(994 /* not 995 */, 50, 500, 400), window_bounds); } @@ -722,7 +570,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithNonAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), initial_bounds, gfx::Rect(), PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(initial_bounds, window_bounds); } @@ -731,7 +579,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithNonAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(50, 739, 500, 400), gfx::Rect(), PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(50, 738 /* not 739 */, 500, 400), window_bounds); } @@ -739,7 +587,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithNonAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(-471, -371, 500, 400), gfx::Rect(), PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(-470 /* not -471 */, 0, 500, 400), window_bounds); } @@ -749,7 +597,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithNonAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(995, -371, 500, 400), gfx::Rect(), PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(994 /* not 995 */, 0, 500, 400), window_bounds); } @@ -759,7 +607,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithNonAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(-471, 739, 500, 400), gfx::Rect(), PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(-470 /* not -471 */, 738 /* not 739 */, 500, 400), window_bounds); } @@ -769,7 +617,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithNonAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(995, 739, 500, 400), gfx::Rect(), PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(994 /* not 995 */, 738 /* not 739 */, 500, 400), window_bounds); } @@ -778,7 +626,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithNonAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(-700, 50, 500, 400), gfx::Rect(), PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(-470 /* not -700 */, 50, 500, 400), window_bounds); } @@ -786,7 +634,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithNonAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(-700, 50, 500, 400), left_nonprimary, PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(0, 50, 500, 400), window_bounds); } @@ -794,7 +642,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithNonAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(50, -500, 500, 400), gfx::Rect(), PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(50, 0, 500, 400), window_bounds); } @@ -802,7 +650,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithNonAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(50, -500, 500, 400), top_nonprimary, - PERSISTED, &window_bounds); + PERSISTED, &window_bounds, NULL); EXPECT_EQ(gfx::Rect(50, 0, 500, 400), window_bounds); } @@ -810,7 +658,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithNonAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(1200, 50, 500, 400), gfx::Rect(), PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(994 /* not 1200 */, 50, 500, 400), window_bounds); } @@ -818,7 +666,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithNonAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(1200, 50, 500, 400), right_nonprimary, - PERSISTED, &window_bounds); + PERSISTED, &window_bounds, NULL); EXPECT_EQ(gfx::Rect(524, 50, 500, 400), window_bounds); } @@ -826,7 +674,7 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithNonAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(50, 800, 500, 400), gfx::Rect(), PERSISTED, - &window_bounds); + &window_bounds, NULL); EXPECT_EQ(gfx::Rect(50, 738 /* not 800 */, 500, 400), window_bounds); } @@ -834,9 +682,8 @@ TEST(WindowSizerTest, PersistedWindowOffscreenWithNonAggressiveRepositioning) { gfx::Rect window_bounds; GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(50, 800, 500, 400), bottom_nonprimary, - PERSISTED, &window_bounds); + PERSISTED, &window_bounds, NULL); EXPECT_EQ(gfx::Rect(50, 368, 500, 400), window_bounds); } } #endif //defined(OS_MACOSX) -#endif //defined(USE_ASH) diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 7cdc0c9..21040cc 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1970,6 +1970,7 @@ 'browser/ui/webui/theme_source_unittest.cc', 'browser/ui/webui/web_ui_unittest.cc', 'browser/ui/window_sizer_unittest.cc', + 'browser/ui/window_sizer_aura_unittest.cc', 'browser/ui/window_snapshot/window_snapshot_mac_unittest.mm', 'browser/chrome_to_mobile_service_unittest.cc', 'browser/user_style_sheet_watcher_unittest.cc', @@ -2115,6 +2116,7 @@ '../webkit/fileapi/mock_file_system_options.h', '../webkit/quota/mock_storage_client.cc', '../webkit/quota/mock_storage_client.h', + '../ash/test/test_shell_delegate.cc', ], 'conditions': [ ['enable_background==0', { @@ -2153,6 +2155,11 @@ ['exclude', '^browser/ui/views/bookmarks/bookmark_editor_view_unittest.cc'], ['exclude', '^browser/ui/panels/display_settings_provider_win_unittest.cc'], ['exclude', '^browser/bookmarks/bookmark_node_data_unittest.cc'], + ['exclude', '^browser/ui/window_sizer_unittest.cc'], + ], + 'sources': [ + '../ash/test/ash_test_base.cc', + '../ash/test/ash_test_base.h', ], }], ['enable_task_manager==0', { @@ -2454,11 +2461,10 @@ 'browser/ui/toolbar/toolbar_model_unittest.cc', 'browser/ui/toolbar/wrench_menu_model_unittest.cc', 'browser/ui/webui/html_dialog_tab_contents_delegate_unittest.cc', + 'browser/ui/window_sizer_unittest.cc', 'test/base/browser_with_test_window_test.cc', 'test/base/browser_with_test_window_test.h', 'test/base/test_browser_window.h', - - 'browser/ui/window_sizer_unittest.cc', ], 'sources/': [ ['exclude', '^browser/chrome_to_mobile'], diff --git a/ui/aura/test/aura_test_helper.h b/ui/aura/test/aura_test_helper.h index 90e3580..2de57ec 100644 --- a/ui/aura/test/aura_test_helper.h +++ b/ui/aura/test/aura_test_helper.h @@ -35,6 +35,8 @@ class AuraTestHelper { // Flushes message loop. void RunAllPendingInMessageLoop(RootWindow* root_window); + MessageLoopForUI* message_loop() { return &message_loop_; }; + private: MessageLoopForUI message_loop_; bool setup_called_; |