Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ash / wm / maximize_mode / maximize_mode_window_manager_unittest.cc
index 82b07d7..6b1c244 100644 (file)
@@ -4,13 +4,19 @@
 
 #include "ash/wm/maximize_mode/maximize_mode_window_manager.h"
 
+#include "ash/root_window_controller.h"
+#include "ash/screen_util.h"
+#include "ash/shelf/shelf_layout_manager.h"
 #include "ash/shell.h"
 #include "ash/switchable_windows.h"
 #include "ash/test/ash_test_base.h"
 #include "ash/test/shell_test_api.h"
 #include "ash/wm/mru_window_tracker.h"
+#include "ash/wm/overview/window_selector_controller.h"
+#include "ash/wm/window_properties.h"
 #include "ash/wm/window_state.h"
 #include "ash/wm/wm_event.h"
+#include "base/strings/stringprintf.h"
 #include "base/strings/utf_string_conversions.h"
 #include "base/values.h"
 #include "ui/aura/client/aura_constants.h"
@@ -31,21 +37,46 @@ class MaximizeModeWindowManagerTest : public test::AshTestBase {
   MaximizeModeWindowManagerTest() {}
   virtual ~MaximizeModeWindowManagerTest() {}
 
-  // Creates a window. Note: This function will only work with a single root
-  // window.
+  // Creates a window which has a fixed size.
+  aura::Window* CreateFixedSizeNonMaximizableWindow(ui::wm::WindowType type,
+                                                    const gfx::Rect& bounds) {
+    return CreateWindowInWatchedContainer(
+        type, bounds, gfx::Size(), false, false);
+  }
+
+  // Creates a window which can not be maximized, but resized. |max_size|
+  // denotes the maximal possible size, if the size is empty, the window has no
+  // upper limit. Note: This function will only work with a single root window.
   aura::Window* CreateNonMaximizableWindow(ui::wm::WindowType type,
-                                           const gfx::Rect& bounds) {
-    return CreateWindowInWatchedContainer(type, bounds, false);
+                                           const gfx::Rect& bounds,
+                                           const gfx::Size& max_size) {
+    return CreateWindowInWatchedContainer(type, bounds, max_size, false, true);
   }
 
-  // Creates a window.
+  // Creates a maximizable and resizable window.
   aura::Window* CreateWindow(ui::wm::WindowType type,
                              const gfx::Rect bounds) {
-    return CreateWindowInWatchedContainer(type, bounds, true);
+    return CreateWindowInWatchedContainer(
+        type, bounds, gfx::Size(), true, true);
+  }
+
+  // Creates a window which also has a widget.
+  aura::Window* CreateWindowWithWidget(const gfx::Rect& bounds) {
+    views::Widget* widget = new views::Widget();
+    views::Widget::InitParams params;
+    params.context = CurrentContext();
+    // Note: The widget will get deleted with the window.
+    widget->Init(params);
+    widget->Show();
+    aura::Window* window = widget->GetNativeWindow();
+    window->SetBounds(bounds);
+    window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
+
+    return window;
   }
 
   // Create the Maximized mode window manager.
-  ash::internal::MaximizeModeWindowManager* CreateMaximizeModeWindowManager() {
+  ash::MaximizeModeWindowManager* CreateMaximizeModeWindowManager() {
     EXPECT_FALSE(maximize_mode_window_manager());
     Shell::GetInstance()->EnableMaximizeModeWindowManager(true);
     return maximize_mode_window_manager();
@@ -58,7 +89,7 @@ class MaximizeModeWindowManagerTest : public test::AshTestBase {
   }
 
   // Get the maximze window manager.
-  ash::internal::MaximizeModeWindowManager* maximize_mode_window_manager() {
+  ash::MaximizeModeWindowManager* maximize_mode_window_manager() {
     test::ShellTestApi test_api(Shell::GetInstance());
     return test_api.maximize_mode_window_manager();
   }
@@ -74,17 +105,25 @@ class MaximizeModeWindowManagerTest : public test::AshTestBase {
  private:
   // Create a window in one of the containers which are watched by the
   // MaximizeModeWindowManager. Note that this only works with one root window.
+  // If |can_maximize| is not set, |max_size| is the upper limiting size for
+  // the window, whereas an empty size means that there is no limit.
   aura::Window* CreateWindowInWatchedContainer(ui::wm::WindowType type,
                                                const gfx::Rect& bounds,
-                                               bool can_maximize) {
+                                               const gfx::Size& max_size,
+                                               bool can_maximize,
+                                               bool can_resize) {
     aura::test::TestWindowDelegate* delegate = NULL;
     if (!can_maximize) {
       delegate = aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate();
       delegate->set_window_component(HTCAPTION);
+      if (!max_size.IsEmpty())
+        delegate->set_maximum_size(max_size);
     }
     aura::Window* window = aura::test::CreateTestWindowWithDelegateAndType(
         delegate, type, 0, bounds, NULL);
     window->SetProperty(aura::client::kCanMaximizeKey, can_maximize);
+    if (!can_resize)
+      window->SetProperty(aura::client::kCanResizeKey, false);
     aura::Window* container = Shell::GetContainer(
         Shell::GetPrimaryRootWindow(),
         kSwitchableWindowContainerIds[0]);
@@ -98,8 +137,7 @@ class MaximizeModeWindowManagerTest : public test::AshTestBase {
 // Test that creating the object and destroying it without any windows should
 // not cause any problems.
 TEST_F(MaximizeModeWindowManagerTest, SimpleStart) {
-  ash::internal::MaximizeModeWindowManager* manager =
-      CreateMaximizeModeWindowManager();
+  ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
   ASSERT_TRUE(manager);
   EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
   DestroyMaximizeModeWindowManager();
@@ -117,7 +155,7 @@ TEST_F(MaximizeModeWindowManagerTest, PreCreateWindows) {
   scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect1));
   scoped_ptr<aura::Window> w2(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect2));
   scoped_ptr<aura::Window> w3(
-      CreateNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect3));
+      CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect3));
   scoped_ptr<aura::Window> w4(CreateWindow(ui::wm::WINDOW_TYPE_PANEL, rect));
   scoped_ptr<aura::Window> w5(CreateWindow(ui::wm::WINDOW_TYPE_POPUP, rect));
   scoped_ptr<aura::Window> w6(CreateWindow(ui::wm::WINDOW_TYPE_CONTROL, rect));
@@ -132,8 +170,7 @@ TEST_F(MaximizeModeWindowManagerTest, PreCreateWindows) {
 
   // Create the manager and make sure that all qualifying windows were detected
   // and changed.
-  ash::internal::MaximizeModeWindowManager* manager =
-      CreateMaximizeModeWindowManager();
+  ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
   ASSERT_TRUE(manager);
   EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
   EXPECT_TRUE(wm::GetWindowState(w1.get())->IsMaximized());
@@ -170,10 +207,67 @@ TEST_F(MaximizeModeWindowManagerTest, PreCreateWindows) {
   EXPECT_EQ(rect.ToString(), w8->bounds().ToString());
 }
 
+// Test that non-maximizable windows get properly handled when going into
+// maximized mode.
+TEST_F(MaximizeModeWindowManagerTest,
+       PreCreateNonMaximizableButResizableWindows) {
+  // The window bounds.
+  gfx::Rect rect(10, 10, 200, 50);
+  gfx::Size max_size(300, 200);
+  gfx::Size empty_size;
+  scoped_ptr<aura::Window> unlimited_window(
+      CreateNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect, empty_size));
+  scoped_ptr<aura::Window> limited_window(
+      CreateNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect, max_size));
+  scoped_ptr<aura::Window> fixed_window(
+      CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
+  EXPECT_FALSE(wm::GetWindowState(unlimited_window.get())->IsMaximized());
+  EXPECT_EQ(rect.ToString(), unlimited_window->bounds().ToString());
+  EXPECT_FALSE(wm::GetWindowState(limited_window.get())->IsMaximized());
+  EXPECT_EQ(rect.ToString(), limited_window->bounds().ToString());
+  EXPECT_FALSE(wm::GetWindowState(fixed_window.get())->IsMaximized());
+  EXPECT_EQ(rect.ToString(), fixed_window->bounds().ToString());
+
+  gfx::Size workspace_size = ScreenUtil::GetMaximizedWindowBoundsInParent(
+      unlimited_window.get()).size();
+
+  // Create the manager and make sure that all qualifying windows were detected
+  // and changed.
+  ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
+  ASSERT_TRUE(manager);
+  EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
+  // The unlimited window should have the size of the workspace / parent window.
+  EXPECT_FALSE(wm::GetWindowState(unlimited_window.get())->IsMaximized());
+  EXPECT_EQ("0,0", unlimited_window->bounds().origin().ToString());
+  EXPECT_EQ(workspace_size.ToString(),
+            unlimited_window->bounds().size().ToString());
+  // The limited window should have the size of the upper possible bounds.
+  EXPECT_FALSE(wm::GetWindowState(limited_window.get())->IsMaximized());
+  EXPECT_NE(rect.origin().ToString(),
+            limited_window->bounds().origin().ToString());
+  EXPECT_EQ(max_size.ToString(),
+            limited_window->bounds().size().ToString());
+  // The fixed size window should have the size of the original window.
+  EXPECT_FALSE(wm::GetWindowState(fixed_window.get())->IsMaximized());
+  EXPECT_NE(rect.origin().ToString(),
+            fixed_window->bounds().origin().ToString());
+  EXPECT_EQ(rect.size().ToString(),
+            fixed_window->bounds().size().ToString());
+
+  // Destroy the manager again and check that the windows return to their
+  // previous state.
+  DestroyMaximizeModeWindowManager();
+  EXPECT_FALSE(wm::GetWindowState(unlimited_window.get())->IsMaximized());
+  EXPECT_EQ(rect.ToString(), unlimited_window->bounds().ToString());
+  EXPECT_FALSE(wm::GetWindowState(limited_window.get())->IsMaximized());
+  EXPECT_EQ(rect.ToString(), limited_window->bounds().ToString());
+  EXPECT_FALSE(wm::GetWindowState(fixed_window.get())->IsMaximized());
+  EXPECT_EQ(rect.ToString(), fixed_window->bounds().ToString());
+}
+
 // Test that creating windows while a maximizer exists picks them properly up.
 TEST_F(MaximizeModeWindowManagerTest, CreateWindows) {
-  ash::internal::MaximizeModeWindowManager* manager =
-      CreateMaximizeModeWindowManager();
+  ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
   ASSERT_TRUE(manager);
   EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
 
@@ -187,7 +281,7 @@ TEST_F(MaximizeModeWindowManagerTest, CreateWindows) {
   scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect1));
   scoped_ptr<aura::Window> w2(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect2));
   scoped_ptr<aura::Window> w3(
-      CreateNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect3));
+      CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect3));
   scoped_ptr<aura::Window> w4(CreateWindow(ui::wm::WINDOW_TYPE_PANEL, rect));
   scoped_ptr<aura::Window> w5(CreateWindow(ui::wm::WINDOW_TYPE_POPUP, rect));
   scoped_ptr<aura::Window> w6(CreateWindow(ui::wm::WINDOW_TYPE_CONTROL, rect));
@@ -197,7 +291,16 @@ TEST_F(MaximizeModeWindowManagerTest, CreateWindows) {
   EXPECT_TRUE(wm::GetWindowState(w2.get())->IsMaximized());
   EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
   EXPECT_FALSE(wm::GetWindowState(w3.get())->IsMaximized());
-  EXPECT_NE(rect3.ToString(), w3->bounds().ToString());
+
+  // Make sure that the position of the unresizable window is in the middle of
+  // the screen.
+  gfx::Size work_area_size =
+      ScreenUtil::GetDisplayWorkAreaBoundsInParent(w3.get()).size();
+  gfx::Point center =
+      gfx::Point((work_area_size.width() - rect3.size().width()) / 2,
+                 (work_area_size.height() - rect3.size().height()) / 2);
+  gfx::Rect centered_window_bounds = gfx::Rect(center, rect3.size());
+  EXPECT_EQ(centered_window_bounds.ToString(), w3->bounds().ToString());
 
   // All other windows should not have been touched.
   EXPECT_FALSE(wm::GetWindowState(w4.get())->IsMaximized());
@@ -227,10 +330,151 @@ TEST_F(MaximizeModeWindowManagerTest, CreateWindows) {
   EXPECT_EQ(rect.ToString(), w8->bounds().ToString());
 }
 
+// Test that a window which got created while the maximize mode window manager
+// is active gets restored to a usable (non tiny) size upon switching back.
+TEST_F(MaximizeModeWindowManagerTest,
+       CreateWindowInMaximizedModeRestoresToUsefulSize) {
+  ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
+  ASSERT_TRUE(manager);
+  EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
+
+  // We pass in an empty rectangle to simulate a window creation with no
+  // particular size.
+  gfx::Rect empty_rect(0, 0, 0, 0);
+  scoped_ptr<aura::Window> window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL,
+                                               empty_rect));
+  EXPECT_TRUE(wm::GetWindowState(window.get())->IsMaximized());
+  EXPECT_NE(empty_rect.ToString(), window->bounds().ToString());
+  gfx::Rect maximized_size = window->bounds();
+
+  // Destroy the maximize mode and check that the resulting size of the window
+  // is remaining as it is (but not maximized).
+  DestroyMaximizeModeWindowManager();
+
+  EXPECT_FALSE(wm::GetWindowState(window.get())->IsMaximized());
+  EXPECT_EQ(maximized_size.ToString(), window->bounds().ToString());
+}
+
+// Test that non-maximizable windows get properly handled when created in
+// maximized mode.
+TEST_F(MaximizeModeWindowManagerTest,
+       CreateNonMaximizableButResizableWindows) {
+  // Create the manager and make sure that all qualifying windows were detected
+  // and changed.
+  ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
+  ASSERT_TRUE(manager);
+
+  gfx::Rect rect(10, 10, 200, 50);
+  gfx::Size max_size(300, 200);
+  gfx::Size empty_size;
+  scoped_ptr<aura::Window> unlimited_window(
+      CreateNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect, empty_size));
+  scoped_ptr<aura::Window> limited_window(
+      CreateNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect, max_size));
+  scoped_ptr<aura::Window> fixed_window(
+      CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
+
+  gfx::Size workspace_size = ScreenUtil::GetMaximizedWindowBoundsInParent(
+      unlimited_window.get()).size();
+
+  // All windows should be sized now as big as possible and be centered.
+  EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
+  // The unlimited window should have the size of the workspace / parent window.
+  EXPECT_FALSE(wm::GetWindowState(unlimited_window.get())->IsMaximized());
+  EXPECT_EQ("0,0", unlimited_window->bounds().origin().ToString());
+  EXPECT_EQ(workspace_size.ToString(),
+            unlimited_window->bounds().size().ToString());
+  // The limited window should have the size of the upper possible bounds.
+  EXPECT_FALSE(wm::GetWindowState(limited_window.get())->IsMaximized());
+  EXPECT_NE(rect.origin().ToString(),
+            limited_window->bounds().origin().ToString());
+  EXPECT_EQ(max_size.ToString(),
+            limited_window->bounds().size().ToString());
+  // The fixed size window should have the size of the original window.
+  EXPECT_FALSE(wm::GetWindowState(fixed_window.get())->IsMaximized());
+  EXPECT_NE(rect.origin().ToString(),
+            fixed_window->bounds().origin().ToString());
+  EXPECT_EQ(rect.size().ToString(),
+            fixed_window->bounds().size().ToString());
+
+  // Destroy the manager again and check that the windows return to their
+  // creation state.
+  DestroyMaximizeModeWindowManager();
+
+  EXPECT_FALSE(wm::GetWindowState(unlimited_window.get())->IsMaximized());
+  EXPECT_EQ(rect.ToString(), unlimited_window->bounds().ToString());
+  EXPECT_FALSE(wm::GetWindowState(limited_window.get())->IsMaximized());
+  EXPECT_EQ(rect.ToString(), limited_window->bounds().ToString());
+  EXPECT_FALSE(wm::GetWindowState(fixed_window.get())->IsMaximized());
+  EXPECT_EQ(rect.ToString(), fixed_window->bounds().ToString());
+}
+
+// Create a string which consists of the bounds and the state for comparison.
+std::string GetPlacementString(const gfx::Rect& bounds,
+                               ui::WindowShowState state) {
+  return bounds.ToString() + base::StringPrintf(" %d", state);
+}
+
+// Retrieves the window's restore state override - if any - and returns it as a
+// string.
+std::string GetPlacementOverride(aura::Window* window) {
+  gfx::Rect* bounds = window->GetProperty(ash::kRestoreBoundsOverrideKey);
+  if (bounds) {
+    gfx::Rect restore_bounds = *bounds;
+    ui::WindowShowState restore_state =
+        window->GetProperty(ash::kRestoreShowStateOverrideKey);
+    return GetPlacementString(restore_bounds, restore_state);
+  }
+  return std::string();
+}
+
+// Test that the restore state will be kept at its original value for
+// session restauration purposes.
+TEST_F(MaximizeModeWindowManagerTest, TestRestoreIntegrety) {
+  gfx::Rect bounds(10, 10, 200, 50);
+  gfx::Size empty_size;
+  gfx::Rect empty_bounds;
+  scoped_ptr<aura::Window> normal_window(
+      CreateWindowWithWidget(bounds));
+  scoped_ptr<aura::Window> maximized_window(
+      CreateWindowWithWidget(bounds));
+  wm::GetWindowState(maximized_window.get())->Maximize();
+
+  EXPECT_EQ(std::string(), GetPlacementOverride(normal_window.get()));
+  EXPECT_EQ(std::string(), GetPlacementOverride(maximized_window.get()));
+
+  ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
+  ASSERT_TRUE(manager);
+
+  // With the maximization the override states should be returned in its
+  // pre-maximized state.
+  EXPECT_EQ(GetPlacementString(bounds, ui::SHOW_STATE_NORMAL),
+            GetPlacementOverride(normal_window.get()));
+  EXPECT_EQ(GetPlacementString(bounds, ui::SHOW_STATE_MAXIMIZED),
+            GetPlacementOverride(maximized_window.get()));
+
+  // Changing a window's state now does not change the returned result.
+  wm::GetWindowState(maximized_window.get())->Minimize();
+  EXPECT_EQ(GetPlacementString(bounds, ui::SHOW_STATE_MAXIMIZED),
+            GetPlacementOverride(maximized_window.get()));
+
+  // Destroy the manager again and check that the overrides get reset.
+  DestroyMaximizeModeWindowManager();
+  EXPECT_EQ(std::string(), GetPlacementOverride(normal_window.get()));
+  EXPECT_EQ(std::string(), GetPlacementOverride(maximized_window.get()));
+
+  // Changing a window's state now does not bring the overrides back.
+  wm::GetWindowState(maximized_window.get())->Restore();
+  gfx::Rect new_bounds(10, 10, 200, 50);
+  maximized_window->SetBounds(new_bounds);
+
+  EXPECT_EQ(std::string(), GetPlacementOverride(maximized_window.get()));
+}
+
 // Test that windows which got created before the maximizer was created can be
 // destroyed while the maximizer is still running.
 TEST_F(MaximizeModeWindowManagerTest, PreCreateWindowsDeleteWhileActive) {
-  ash::internal::MaximizeModeWindowManager* manager = NULL;
+  ash::MaximizeModeWindowManager* manager = NULL;
   {
     // Bounds for windows we know can be controlled.
     gfx::Rect rect1(10, 10, 200, 50);
@@ -243,7 +487,7 @@ TEST_F(MaximizeModeWindowManagerTest, PreCreateWindowsDeleteWhileActive) {
     scoped_ptr<aura::Window> w2(
         CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect2));
     scoped_ptr<aura::Window> w3(
-        CreateNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect3));
+        CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect3));
 
     // Create the manager and make sure that all qualifying windows were
     // detected and changed.
@@ -258,8 +502,7 @@ TEST_F(MaximizeModeWindowManagerTest, PreCreateWindowsDeleteWhileActive) {
 // Test that windows which got created while the maximizer was running can get
 // destroyed before the maximizer gets destroyed.
 TEST_F(MaximizeModeWindowManagerTest, CreateWindowsAndDeleteWhileActive) {
-  ash::internal::MaximizeModeWindowManager* manager =
-      CreateMaximizeModeWindowManager();
+  ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
   ASSERT_TRUE(manager);
   EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
   {
@@ -272,8 +515,8 @@ TEST_F(MaximizeModeWindowManagerTest, CreateWindowsAndDeleteWhileActive) {
     scoped_ptr<aura::Window> w2(
         CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, gfx::Rect(10, 60, 200, 50)));
     scoped_ptr<aura::Window> w3(
-        CreateNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL,
-                                   gfx::Rect(20, 140, 100, 100)));
+        CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL,
+                                            gfx::Rect(20, 140, 100, 100)));
     // Check that the windows got automatically maximized as well.
     EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
     EXPECT_TRUE(wm::GetWindowState(w1.get())->IsMaximized());
@@ -293,8 +536,7 @@ TEST_F(MaximizeModeWindowManagerTest, MaximizedShouldRemainMaximized) {
   wm::GetWindowState(window.get())->Maximize();
 
   // Create the manager and make sure that the window gets detected.
-  ash::internal::MaximizeModeWindowManager* manager =
-      CreateMaximizeModeWindowManager();
+  ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
   ASSERT_TRUE(manager);
   EXPECT_EQ(1, manager->GetNumberOfManagedWindows());
   EXPECT_TRUE(wm::GetWindowState(window.get())->IsMaximized());
@@ -322,8 +564,7 @@ TEST_F(MaximizeModeWindowManagerTest, MinimizedWindowBehavior) {
   wm::GetWindowState(initially_maximized_window.get())->Maximize();
 
   // Create the manager and make sure that the window gets detected.
-  ash::internal::MaximizeModeWindowManager* manager =
-      CreateMaximizeModeWindowManager();
+  ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
   ASSERT_TRUE(manager);
   EXPECT_EQ(3, manager->GetNumberOfManagedWindows());
   EXPECT_TRUE(wm::GetWindowState(
@@ -352,24 +593,23 @@ TEST_F(MaximizeModeWindowManagerTest, MinimizedWindowBehavior) {
       initially_maximized_window.get())->IsMaximized());
 }
 
-// Check that resizing the desktop does reposition unmaximizable & managed
-// windows.
+// Check that resizing the desktop does reposition unmaximizable, unresizable &
+// managed windows.
 TEST_F(MaximizeModeWindowManagerTest, DesktopSizeChangeMovesUnmaximizable) {
   UpdateDisplay("400x400");
   // This window will move because it does not fit the new bounds.
   gfx::Rect rect(20, 300, 100, 100);
   scoped_ptr<aura::Window> window1(
-      CreateNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
+      CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
   EXPECT_EQ(rect.ToString(), window1->bounds().ToString());
 
   // This window will not move because it does fit the new bounds.
   gfx::Rect rect2(20, 140, 100, 100);
   scoped_ptr<aura::Window> window2(
-      CreateNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect2));
+      CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect2));
 
   // Turning on the manager will reposition (but not resize) the window.
-  ash::internal::MaximizeModeWindowManager* manager =
-      CreateMaximizeModeWindowManager();
+  ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
   ASSERT_TRUE(manager);
   EXPECT_EQ(2, manager->GetNumberOfManagedWindows());
   gfx::Rect moved_bounds(window1->bounds());
@@ -395,11 +635,10 @@ TEST_F(MaximizeModeWindowManagerTest, DesktopSizeChangeMovesUnmaximizable) {
 TEST_F(MaximizeModeWindowManagerTest, SizeChangeReturnWindowToOriginalPos) {
   gfx::Rect rect(20, 140, 100, 100);
   scoped_ptr<aura::Window> window(
-      CreateNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
+      CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
 
   // Turning on the manager will reposition (but not resize) the window.
-  ash::internal::MaximizeModeWindowManager* manager =
-      CreateMaximizeModeWindowManager();
+  ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
   ASSERT_TRUE(manager);
   EXPECT_EQ(1, manager->GetNumberOfManagedWindows());
   gfx::Rect moved_bounds(window->bounds());
@@ -425,11 +664,11 @@ TEST_F(MaximizeModeWindowManagerTest, SizeChangeReturnWindowToOriginalPos) {
 TEST_F(MaximizeModeWindowManagerTest, ModeChangeKeepsMRUOrder) {
   gfx::Rect rect(20, 140, 100, 100);
   scoped_ptr<aura::Window> w1(
-      CreateNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
+      CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
   scoped_ptr<aura::Window> w2(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
   scoped_ptr<aura::Window> w3(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
   scoped_ptr<aura::Window> w4(
-      CreateNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
+      CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
   scoped_ptr<aura::Window> w5(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
 
   // The windows should be in the reverse order of creation in the MRU list.
@@ -444,8 +683,7 @@ TEST_F(MaximizeModeWindowManagerTest, ModeChangeKeepsMRUOrder) {
   }
 
   // Activating the window manager should keep the order.
-  ash::internal::MaximizeModeWindowManager* manager =
-      CreateMaximizeModeWindowManager();
+  ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
   ASSERT_TRUE(manager);
   EXPECT_EQ(5, manager->GetNumberOfManagedWindows());
   {
@@ -489,29 +727,178 @@ TEST_F(MaximizeModeWindowManagerTest, IgnoreRestoreStateChages) {
   DestroyMaximizeModeWindowManager();
 }
 
-// Check that a full screen window is changing to maximized in maximize mode,
-// cannot go to fullscreen and goes back to fullscreen thereafter.
-TEST_F(MaximizeModeWindowManagerTest, FullScreenModeTests) {
+// Check that minimize and restore do the right thing.
+TEST_F(MaximizeModeWindowManagerTest, TestMinimize) {
+  gfx::Rect rect(10, 10, 100, 100);
+  scoped_ptr<aura::Window> window(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL,
+                                  rect));
+  wm::WindowState* window_state = wm::GetWindowState(window.get());
+  EXPECT_EQ(rect.ToString(), window->bounds().ToString());
+  ash::Shell::GetInstance()->EnableMaximizeModeWindowManager(true);
+  EXPECT_TRUE(window_state->IsMaximized());
+  EXPECT_FALSE(window_state->IsMinimized());
+  EXPECT_TRUE(window->IsVisible());
+
+  window_state->Minimize();
+  EXPECT_FALSE(window_state->IsMaximized());
+  EXPECT_TRUE(window_state->IsMinimized());
+  EXPECT_FALSE(window->IsVisible());
+
+  window_state->Maximize();
+  EXPECT_TRUE(window_state->IsMaximized());
+  EXPECT_FALSE(window_state->IsMinimized());
+  EXPECT_TRUE(window->IsVisible());
+
+  ash::Shell::GetInstance()->EnableMaximizeModeWindowManager(false);
+  EXPECT_FALSE(window_state->IsMaximized());
+  EXPECT_FALSE(window_state->IsMinimized());
+  EXPECT_TRUE(window->IsVisible());
+}
+
+// Check that a full screen window is staying full screen in maximize mode,
+// and that it returns to full screen thereafter (if left).
+TEST_F(MaximizeModeWindowManagerTest, KeepFullScreenModeOn) {
   gfx::Rect rect(20, 140, 100, 100);
   scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
   wm::WindowState* window_state = wm::GetWindowState(w1.get());
+
+  ShelfLayoutManager* shelf =
+      Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
+
+  // Allow the shelf to hide.
+  shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
+  EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
+
   wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
   window_state->OnWMEvent(&event);
+
+  // With full screen, the shelf should get hidden.
   EXPECT_TRUE(window_state->IsFullscreen());
+  EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
 
   CreateMaximizeModeWindowManager();
 
-  // Fullscreen mode should now be off and it should not come back while in
-  // maximize mode.
+  // The Full screen mode should continue to be on.
+  EXPECT_TRUE(window_state->IsFullscreen());
+  EXPECT_FALSE(window_state->IsMaximized());
+  EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
+
+  // With leaving the fullscreen mode, the maximized mode should return and the
+  // shelf should become visible.
+  window_state->OnWMEvent(&event);
   EXPECT_FALSE(window_state->IsFullscreen());
   EXPECT_TRUE(window_state->IsMaximized());
-  window_state->OnWMEvent(&event);
+  EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
+
+  // Ending the maximize mode should return to full screen and the shelf should
+  // be hidden again.
+  DestroyMaximizeModeWindowManager();
+  EXPECT_TRUE(window_state->IsFullscreen());
+  EXPECT_FALSE(window_state->IsMaximized());
+  EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
+}
+
+// Check that full screen mode can be turned on in maximized mode and remains
+// upon coming back.
+TEST_F(MaximizeModeWindowManagerTest, AllowFullScreenMode) {
+  gfx::Rect rect(20, 140, 100, 100);
+  scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
+  wm::WindowState* window_state = wm::GetWindowState(w1.get());
+
+  ShelfLayoutManager* shelf =
+      Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
+
+  // Allow the shelf to hide.
+  shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
+
+  EXPECT_FALSE(window_state->IsFullscreen());
+  EXPECT_FALSE(window_state->IsMaximized());
+  EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
+
+  CreateMaximizeModeWindowManager();
+
+  // Fullscreen mode should still be off and the shelf should be visible.
   EXPECT_FALSE(window_state->IsFullscreen());
   EXPECT_TRUE(window_state->IsMaximized());
+  EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
+
+  // After going into fullscreen mode, the shelf should be hidden.
+  wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
+  window_state->OnWMEvent(&event);
+  EXPECT_TRUE(window_state->IsFullscreen());
+  EXPECT_FALSE(window_state->IsMaximized());
+  EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
 
+  // With the destruction of the manager we should remain in full screen.
   DestroyMaximizeModeWindowManager();
   EXPECT_TRUE(window_state->IsFullscreen());
   EXPECT_FALSE(window_state->IsMaximized());
+  EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
+}
+
+// Check that the full screen mode will stay active when the maximize mode is
+// ended.
+TEST_F(MaximizeModeWindowManagerTest,
+       FullScreenModeRemainsWhenCreatedInMaximizedMode) {
+  CreateMaximizeModeWindowManager();
+
+  gfx::Rect rect(20, 140, 100, 100);
+  scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
+  wm::WindowState* window_state = wm::GetWindowState(w1.get());
+  wm::WMEvent event_full_screen(wm::WM_EVENT_TOGGLE_FULLSCREEN);
+  window_state->OnWMEvent(&event_full_screen);
+  EXPECT_TRUE(window_state->IsFullscreen());
+
+  // After the maximize mode manager is ended, full screen will remain.
+  DestroyMaximizeModeWindowManager();
+  EXPECT_TRUE(window_state->IsFullscreen());
+}
+
+// Check that the full screen mode will stay active throughout a maximzied mode
+// session.
+TEST_F(MaximizeModeWindowManagerTest,
+       FullScreenModeRemainsThroughMaximizeModeSwitch) {
+  gfx::Rect rect(20, 140, 100, 100);
+  scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
+  wm::WindowState* window_state = wm::GetWindowState(w1.get());
+  wm::WMEvent event_full_screen(wm::WM_EVENT_TOGGLE_FULLSCREEN);
+  window_state->OnWMEvent(&event_full_screen);
+  EXPECT_TRUE(window_state->IsFullscreen());
+
+  CreateMaximizeModeWindowManager();
+  EXPECT_TRUE(window_state->IsFullscreen());
+  DestroyMaximizeModeWindowManager();
+  EXPECT_TRUE(window_state->IsFullscreen());
+}
+
+// Check that an empty window does not get restored to a tiny size.
+TEST_F(MaximizeModeWindowManagerTest,
+       CreateAndMaximizeInMaximizeModeShouldRetoreToGoodSizeGoingToDefault) {
+  CreateMaximizeModeWindowManager();
+  gfx::Rect rect;
+  scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
+  w1->Show();
+  wm::WindowState* window_state = wm::GetWindowState(w1.get());
+  EXPECT_TRUE(window_state->IsMaximized());
+
+  // There is a calling order in which the restore bounds can get set to an
+  // empty rectangle. We simulate this here.
+  window_state->SetRestoreBoundsInScreen(rect);
+  EXPECT_TRUE(window_state->GetRestoreBoundsInScreen().IsEmpty());
+
+  // Setting the window to a new size will physically not change the window,
+  // but the restore size should get updated so that a restore later on will
+  // return to this size.
+  gfx::Rect requested_bounds(10, 20, 50, 70);
+  w1->SetBounds(requested_bounds);
+  EXPECT_TRUE(window_state->IsMaximized());
+  EXPECT_EQ(requested_bounds.ToString(),
+            window_state->GetRestoreBoundsInScreen().ToString());
+
+  DestroyMaximizeModeWindowManager();
+
+  EXPECT_FALSE(window_state->IsMaximized());
+  EXPECT_EQ(w1->bounds().ToString(), requested_bounds.ToString());
 }
 
 // Check that snapping operations get ignored.
@@ -545,7 +932,7 @@ TEST_F(MaximizeModeWindowManagerTest, SnapModeTests) {
 TEST_F(MaximizeModeWindowManagerTest, TryToDesktopSizeDragUnmaximizable) {
   gfx::Rect rect(10, 10, 100, 100);
   scoped_ptr<aura::Window> window(
-      CreateNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
+      CreateFixedSizeNonMaximizableWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
   EXPECT_EQ(rect.ToString(), window->bounds().ToString());
 
   // 1. Move the mouse over the caption and check that dragging the window does
@@ -587,6 +974,32 @@ TEST_F(MaximizeModeWindowManagerTest, TryToDesktopSizeDragUnmaximizable) {
   EXPECT_EQ(first_dragged_origin.y() + 5, window->bounds().y());
 }
 
+// Test that overview is exited before entering / exiting maximize mode so that
+// the window changes made by MaximizeModeWindowManager do not conflict with
+// those made in WindowOverview.
+TEST_F(MaximizeModeWindowManagerTest, ExitsOverview) {
+  // Bounds for windows we know can be controlled.
+  gfx::Rect rect1(10, 10, 200, 50);
+  gfx::Rect rect2(10, 60, 200, 50);
+  scoped_ptr<aura::Window> w1(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect1));
+  scoped_ptr<aura::Window> w2(CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect2));
+
+  WindowSelectorController* window_selector_controller =
+      Shell::GetInstance()->window_selector_controller();
+  window_selector_controller->ToggleOverview();
+  ASSERT_TRUE(window_selector_controller->IsSelecting());
+  ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
+  ASSERT_TRUE(manager);
+  EXPECT_FALSE(window_selector_controller->IsSelecting());
+
+  window_selector_controller->ToggleOverview();
+  ASSERT_TRUE(window_selector_controller->IsSelecting());
+  // Destroy the manager again and check that the windows return to their
+  // previous state.
+  DestroyMaximizeModeWindowManager();
+  EXPECT_FALSE(window_selector_controller->IsSelecting());
+}
+
 #endif  // OS_WIN
 
 }  // namespace ash