window_state_unittest.cc revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
1a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 2a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// found in the LICENSE file. 4a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 5a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/wm/window_state.h" 6a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 7a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/screen_util.h" 8a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/shell.h" 9a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/test/ash_test_base.h" 10a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/wm/window_state.h" 11a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/wm/wm_event.h" 12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/aura/test/test_window_delegate.h" 13a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/aura/window.h" 14a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace ash { 16a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace wm { 17a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 18a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)typedef test::AshTestBase WindowStateTest; 19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 20a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Test that a window gets properly snapped to the display's edges in a 21a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// multi monitor environment. 22a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)TEST_F(WindowStateTest, SnapWindowBasic) { 23a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!SupportsMultipleDisplays()) 24a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return; 25a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) UpdateDisplay("0+0-500x400, 0+500-600x400"); 27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const gfx::Rect kPrimaryDisplayWorkAreaBounds = 28a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); 29a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const gfx::Rect kSecondaryDisplayWorkAreaBounds = 30a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ScreenUtil::GetSecondaryDisplay().work_area(); 31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 32a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) scoped_ptr<aura::Window> window( 33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); 34a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) wm::WindowState* window_state = wm::GetWindowState(window.get()); 35a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const wm::WMEvent snap_left(wm::WM_EVENT_SNAP_LEFT); 36a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) window_state->OnWMEvent(&snap_left); 37a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gfx::Rect expected = gfx::Rect( 38a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kPrimaryDisplayWorkAreaBounds.x(), 39a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kPrimaryDisplayWorkAreaBounds.y(), 40a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kPrimaryDisplayWorkAreaBounds.width() / 2, 41a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kPrimaryDisplayWorkAreaBounds.height()); 42a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); 43a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 44a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const wm::WMEvent snap_right(wm::WM_EVENT_SNAP_RIGHT); 45a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) window_state->OnWMEvent(&snap_right); 46a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) expected.set_x(kPrimaryDisplayWorkAreaBounds.right() - expected.width()); 47a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); 48a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 49a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Move the window to the secondary display. 50a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) window->SetBoundsInScreen(gfx::Rect(600, 0, 100, 100), 51a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ScreenUtil::GetSecondaryDisplay()); 52a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 53a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) window_state->OnWMEvent(&snap_right); 54a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) expected = gfx::Rect( 55a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kSecondaryDisplayWorkAreaBounds.x() + 56a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kSecondaryDisplayWorkAreaBounds.width() / 2, 57a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kSecondaryDisplayWorkAreaBounds.y(), 58a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kSecondaryDisplayWorkAreaBounds.width() / 2, 59a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kSecondaryDisplayWorkAreaBounds.height()); 60a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); 61a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 62a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) window_state->OnWMEvent(&snap_left); 63a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) expected.set_x(kSecondaryDisplayWorkAreaBounds.x()); 64a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); 65a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 66a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 67a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Test how the minimum and maximum size specified by the aura::WindowDelegate 68a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// affect snapping. 69a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)TEST_F(WindowStateTest, SnapWindowMinimumSize) { 70a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!SupportsHostWindowResize()) 71a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return; 72a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 73a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) UpdateDisplay("0+0-600x900"); 74a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const gfx::Rect kWorkAreaBounds = 75a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); 76a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 77a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) aura::test::TestWindowDelegate delegate; 78a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( 79a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) &delegate, -1, gfx::Rect(0, 100, kWorkAreaBounds.width() - 1, 100))); 80a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 81a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // It should be possible to snap a window with a minimum size. 82a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) delegate.set_minimum_size(gfx::Size(kWorkAreaBounds.width() - 1, 0)); 83a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) wm::WindowState* window_state = wm::GetWindowState(window.get()); 84a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_TRUE(window_state->CanSnap()); 85a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const wm::WMEvent snap_right(wm::WM_EVENT_SNAP_RIGHT); 86a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) window_state->OnWMEvent(&snap_right); 87a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gfx::Rect expected = gfx::Rect(kWorkAreaBounds.x() + 1, 88a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kWorkAreaBounds.y(), 89a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kWorkAreaBounds.width() - 1, 90a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kWorkAreaBounds.height()); 91a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); 92a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 93a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // It should not be possible to snap a window with a maximum size. 94a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) delegate.set_minimum_size(gfx::Size()); 95a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) delegate.set_maximum_size(gfx::Size(kWorkAreaBounds.width() - 1, INT_MAX)); 96a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_FALSE(window_state->CanSnap()); 97a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 98a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 99a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Test that setting the bounds of a snapped window keeps its snapped. 100a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)TEST_F(WindowStateTest, SnapWindowSetBounds) { 101a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!SupportsHostWindowResize()) 102a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return; 103a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 104a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) UpdateDisplay("0+0-900x600"); 105a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const gfx::Rect kWorkAreaBounds = 106a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); 107a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 108a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) scoped_ptr<aura::Window> window( 109a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); 110a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) wm::WindowState* window_state = wm::GetWindowState(window.get()); 111a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const wm::WMEvent snap_left(wm::WM_EVENT_SNAP_LEFT); 112a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) window_state->OnWMEvent(&snap_left); 113a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_EQ(WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType()); 114a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gfx::Rect expected = gfx::Rect(kWorkAreaBounds.x(), 115a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kWorkAreaBounds.y(), 116a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kWorkAreaBounds.width() / 2, 117a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kWorkAreaBounds.height()); 118a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); 119a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 120a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Snapped windows can have any width. 121a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) expected.set_width(500); 122a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) window->SetBounds(gfx::Rect(10, 10, 500, 300)); 123a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); 124a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_EQ(WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType()); 125a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 126a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 127a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Test that snapping left/right preserves the restore bounds. 128a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)TEST_F(WindowStateTest, RestoreBounds) { 129a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) scoped_ptr<aura::Window> window( 130a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); 131a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) wm::WindowState* window_state = wm::GetWindowState(window.get()); 132a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 133a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_TRUE(window_state->IsNormalStateType()); 134a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 135a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // 1) Start with restored window with restore bounds set. 136a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gfx::Rect restore_bounds = window->GetBoundsInScreen(); 137a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) restore_bounds.set_width(restore_bounds.width() + 1); 138a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) window_state->SetRestoreBoundsInScreen(restore_bounds); 139a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const wm::WMEvent snap_left(wm::WM_EVENT_SNAP_LEFT); 140a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) window_state->OnWMEvent(&snap_left); 141a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const wm::WMEvent snap_right(wm::WM_EVENT_SNAP_RIGHT); 142a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) window_state->OnWMEvent(&snap_right); 143a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_NE(restore_bounds.ToString(), window->GetBoundsInScreen().ToString()); 144a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_EQ(restore_bounds.ToString(), 145a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) window_state->GetRestoreBoundsInScreen().ToString()); 146a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) window_state->Restore(); 147a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_EQ(restore_bounds.ToString(), window->GetBoundsInScreen().ToString()); 148a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 149a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // 2) Start with restored bounds set as a result of maximizing the window. 150a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) window_state->Maximize(); 151a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gfx::Rect maximized_bounds = window->GetBoundsInScreen(); 152a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_NE(maximized_bounds.ToString(), restore_bounds.ToString()); 153a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_EQ(restore_bounds.ToString(), 154a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) window_state->GetRestoreBoundsInScreen().ToString()); 155a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 156a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) window_state->OnWMEvent(&snap_left); 157a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_NE(restore_bounds.ToString(), window->GetBoundsInScreen().ToString()); 158a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_NE(maximized_bounds.ToString(), 159a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) window->GetBoundsInScreen().ToString()); 160a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_EQ(restore_bounds.ToString(), 161a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) window_state->GetRestoreBoundsInScreen().ToString()); 162a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 163a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) window_state->Restore(); 164a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_EQ(restore_bounds.ToString(), window->GetBoundsInScreen().ToString()); 165a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 166a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 167a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Test that maximizing an auto managed window, then snapping it puts the window 168a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// at the snapped bounds and not at the auto-managed (centered) bounds. 169a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)TEST_F(WindowStateTest, AutoManaged) { 170a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); 171a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) wm::WindowState* window_state = wm::GetWindowState(window.get()); 172a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) window_state->set_window_position_managed(true); 173a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) window->Hide(); 174a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) window->SetBounds(gfx::Rect(100, 100, 100, 100)); 175a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) window->Show(); 176a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 177a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) window_state->Maximize(); 178a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const wm::WMEvent snap_right(wm::WM_EVENT_SNAP_RIGHT); 179a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) window_state->OnWMEvent(&snap_right); 180a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 181a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const gfx::Rect kWorkAreaBounds = 182a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); 183a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gfx::Rect expected_snapped_bounds( 184a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kWorkAreaBounds.x() + kWorkAreaBounds.width() / 2, 185a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kWorkAreaBounds.y(), 186a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kWorkAreaBounds.width() / 2, 187a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) kWorkAreaBounds.height()); 188a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_EQ(expected_snapped_bounds.ToString(), 189a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) window->GetBoundsInScreen().ToString()); 190a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 191a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // The window should still be auto managed despite being right maximized. 192a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_TRUE(window_state->window_position_managed()); 193a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 194a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 195a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} // namespace wm 196a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} // namespace ash 197