summaryrefslogtreecommitdiffstats
path: root/ash/wm/base_layout_manager_unittest.cc
diff options
context:
space:
mode:
authorjamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-18 23:57:05 +0000
committerjamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-18 23:57:05 +0000
commitfc7b744c639fb4a9c25b1dbf5f7553166fdc1801 (patch)
treee3f486d62831674fddc60d6f05689dad8fba3a55 /ash/wm/base_layout_manager_unittest.cc
parentae6c59c831e325ea8cd45340e27acd75d5ddc4e5 (diff)
downloadchromium_src-fc7b744c639fb4a9c25b1dbf5f7553166fdc1801.zip
chromium_src-fc7b744c639fb4a9c25b1dbf5f7553166fdc1801.tar.gz
chromium_src-fc7b744c639fb4a9c25b1dbf5f7553166fdc1801.tar.bz2
Aura: Split out CompactLayoutManager from ToplevelLayoutManager
Move the shared code to BaseLayoutManager. Adjust the unit tests. Alice needs this for some compact mode work she's doing right now. BUG=110648 TEST=Run Aura in both --aura-window-mode=normal and --aura-window-mode=compact, both still start correctly. Also unit test coverage from CompactLayoutManagerTest and ToplevelLayoutManagerTest Review URL: https://chromiumcodereview.appspot.com/9255024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118186 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/wm/base_layout_manager_unittest.cc')
-rw-r--r--ash/wm/base_layout_manager_unittest.cc135
1 files changed, 135 insertions, 0 deletions
diff --git a/ash/wm/base_layout_manager_unittest.cc b/ash/wm/base_layout_manager_unittest.cc
new file mode 100644
index 0000000..6e16543
--- /dev/null
+++ b/ash/wm/base_layout_manager_unittest.cc
@@ -0,0 +1,135 @@
+// 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 "ash/wm/base_layout_manager.h"
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "ui/aura/client/aura_constants.h"
+#include "ui/aura/root_window.h"
+#include "ui/aura/screen_aura.h"
+#include "ui/aura/test/aura_test_base.h"
+#include "ui/aura/test/test_windows.h"
+#include "ui/base/ui_base_types.h"
+#include "ui/aura/window.h"
+
+namespace ash {
+
+namespace {
+
+class BaseLayoutManagerTest : public aura::test::AuraTestBase {
+ public:
+ BaseLayoutManagerTest() : layout_manager_(NULL) {}
+ virtual ~BaseLayoutManagerTest() {}
+
+ virtual void SetUp() OVERRIDE {
+ aura::test::AuraTestBase::SetUp();
+ aura::RootWindow::GetInstance()->screen()->set_work_area_insets(
+ gfx::Insets(1, 2, 3, 4));
+ aura::RootWindow::GetInstance()->SetHostSize(gfx::Size(800, 600));
+ container_.reset(new aura::Window(NULL));
+ container_->Init(ui::Layer::LAYER_HAS_NO_TEXTURE);
+ container_->SetBounds(gfx::Rect(0, 0, 500, 500));
+ layout_manager_ = new internal::BaseLayoutManager();
+ container_->SetLayoutManager(layout_manager_);
+ }
+
+ aura::Window* CreateTestWindow(const gfx::Rect& bounds) {
+ return aura::test::CreateTestWindowWithBounds(bounds, container_.get());
+ }
+
+ private:
+ // Owned by |container_|.
+ internal::BaseLayoutManager* layout_manager_;
+
+ scoped_ptr<aura::Window> container_;
+
+ DISALLOW_COPY_AND_ASSIGN(BaseLayoutManagerTest);
+};
+
+} // namespace
+
+// Tests normal->maximize->normal.
+TEST_F(BaseLayoutManagerTest, Maximize) {
+ gfx::Rect bounds(100, 100, 200, 200);
+ scoped_ptr<aura::Window> window(CreateTestWindow(bounds));
+ window->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
+ // Maximized window fills the work area, not the whole monitor.
+ EXPECT_EQ(gfx::Screen::GetMonitorWorkAreaNearestWindow(window.get()),
+ window->bounds());
+ window->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
+ EXPECT_EQ(bounds, window->bounds());
+}
+
+// Tests maximized window size during root window resize.
+TEST_F(BaseLayoutManagerTest, MaximizeRootWindowResize) {
+ gfx::Rect bounds(100, 100, 200, 200);
+ scoped_ptr<aura::Window> window(CreateTestWindow(bounds));
+ window->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
+ EXPECT_EQ(gfx::Screen::GetMonitorWorkAreaNearestWindow(window.get()),
+ window->bounds());
+ // Enlarge the root window. We should still match the work area size.
+ aura::RootWindow::GetInstance()->SetHostSize(gfx::Size(800, 600));
+ EXPECT_EQ(gfx::Screen::GetMonitorWorkAreaNearestWindow(window.get()),
+ window->bounds());
+}
+
+// Tests normal->fullscreen->normal.
+TEST_F(BaseLayoutManagerTest, Fullscreen) {
+ gfx::Rect bounds(100, 100, 200, 200);
+ scoped_ptr<aura::Window> window(CreateTestWindow(bounds));
+ window->SetIntProperty(aura::client::kShowStateKey,
+ ui::SHOW_STATE_FULLSCREEN);
+ // Fullscreen window fills the whole monitor.
+ EXPECT_EQ(gfx::Screen::GetMonitorAreaNearestWindow(window.get()),
+ window->bounds());
+ window->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
+ EXPECT_EQ(bounds, window->bounds());
+}
+
+// Tests fullscreen window size during root window resize.
+TEST_F(BaseLayoutManagerTest, FullscreenRootWindowResize) {
+ gfx::Rect bounds(100, 100, 200, 200);
+ scoped_ptr<aura::Window> window(CreateTestWindow(bounds));
+ // Fullscreen window fills the whole monitor.
+ window->SetIntProperty(aura::client::kShowStateKey,
+ ui::SHOW_STATE_FULLSCREEN);
+ EXPECT_EQ(gfx::Screen::GetMonitorAreaNearestWindow(window.get()),
+ window->bounds());
+ // Enlarge the root window. We should still match the monitor size.
+ aura::RootWindow::GetInstance()->SetHostSize(gfx::Size(800, 600));
+ EXPECT_EQ(gfx::Screen::GetMonitorAreaNearestWindow(window.get()),
+ window->bounds());
+}
+
+// Tests that when the screen gets smaller the windows aren't bigger than
+// the screen.
+TEST_F(BaseLayoutManagerTest, RootWindowResizeShrinksWindows) {
+ scoped_ptr<aura::Window> window(
+ CreateTestWindow(gfx::Rect(10, 20, 500, 400)));
+ gfx::Rect work_area = gfx::Screen::GetMonitorAreaNearestWindow(window.get());
+ // Invariant: Window is smaller than work area.
+ EXPECT_LE(window->bounds().width(), work_area.width());
+ EXPECT_LE(window->bounds().height(), work_area.height());
+
+ // Make the root window narrower than our window.
+ aura::RootWindow::GetInstance()->SetHostSize(gfx::Size(300, 400));
+ work_area = gfx::Screen::GetMonitorAreaNearestWindow(window.get());
+ EXPECT_LE(window->bounds().width(), work_area.width());
+ EXPECT_LE(window->bounds().height(), work_area.height());
+
+ // Make the root window shorter than our window.
+ aura::RootWindow::GetInstance()->SetHostSize(gfx::Size(300, 200));
+ work_area = gfx::Screen::GetMonitorAreaNearestWindow(window.get());
+ EXPECT_LE(window->bounds().width(), work_area.width());
+ EXPECT_LE(window->bounds().height(), work_area.height());
+
+ // Enlarging the root window does not change the window bounds.
+ gfx::Rect old_bounds = window->bounds();
+ aura::RootWindow::GetInstance()->SetHostSize(gfx::Size(800, 600));
+ EXPECT_EQ(old_bounds.width(), window->bounds().width());
+ EXPECT_EQ(old_bounds.height(), window->bounds().height());
+}
+
+} // namespace ash