| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/wm/window_state.h" | 5 #include "ash/wm/window_state.h" |
| 6 | 6 |
| 7 #include "ash/screen_util.h" | 7 #include "ash/screen_util.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
| 10 #include "ash/wm/window_state.h" | 10 #include "ash/wm/window_state.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 kWorkAreaBounds.width() - 1, | 123 kWorkAreaBounds.width() - 1, |
| 124 kWorkAreaBounds.height()); | 124 kWorkAreaBounds.height()); |
| 125 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); | 125 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
| 126 | 126 |
| 127 // It should not be possible to snap a window with a maximum size. | 127 // It should not be possible to snap a window with a maximum size. |
| 128 delegate.set_minimum_size(gfx::Size()); | 128 delegate.set_minimum_size(gfx::Size()); |
| 129 delegate.set_maximum_size(gfx::Size(kWorkAreaBounds.width() - 1, INT_MAX)); | 129 delegate.set_maximum_size(gfx::Size(kWorkAreaBounds.width() - 1, INT_MAX)); |
| 130 EXPECT_FALSE(window_state->CanSnap()); | 130 EXPECT_FALSE(window_state->CanSnap()); |
| 131 } | 131 } |
| 132 | 132 |
| 133 // Test that the minimum size specified by aura::WindowDelegate gets respected. | |
| 134 TEST_F(WindowStateTest, TestRespectMinimumSize) { | |
| 135 if (!SupportsHostWindowResize()) | |
| 136 return; | |
| 137 | |
| 138 UpdateDisplay("0+0-1024x768"); | |
| 139 | |
| 140 aura::test::TestWindowDelegate delegate; | |
| 141 const gfx::Size minimum_size(gfx::Size(500, 300)); | |
| 142 delegate.set_minimum_size(minimum_size); | |
| 143 | |
| 144 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( | |
| 145 &delegate, -1, gfx::Rect(0, 100, 100, 100))); | |
| 146 | |
| 147 // Check that the window has the correct minimum size. | |
| 148 EXPECT_EQ(minimum_size.ToString(), window->bounds().size().ToString()); | |
| 149 | |
| 150 // Set the size to something bigger - that should work. | |
| 151 gfx::Rect bigger_bounds(700, 500, 700, 500); | |
| 152 window->SetBounds(bigger_bounds); | |
| 153 EXPECT_EQ(bigger_bounds.ToString(), window->bounds().ToString()); | |
| 154 | |
| 155 // Set the size to something smaller - that should only resize to the smallest | |
| 156 // possible size. | |
| 157 gfx::Rect smaller_bounds(700, 500, 100, 100); | |
| 158 window->SetBounds(smaller_bounds); | |
| 159 EXPECT_EQ(minimum_size.ToString(), window->bounds().size().ToString()); | |
| 160 } | |
| 161 | |
| 162 // Test that the minimum window size specified by aura::WindowDelegate does not | |
| 163 // exceed the screen size. | |
| 164 TEST_F(WindowStateTest, TestIgnoreTooBigMinimumSize) { | |
| 165 if (!SupportsHostWindowResize()) | |
| 166 return; | |
| 167 | |
| 168 UpdateDisplay("0+0-1024x768"); | |
| 169 const gfx::Size work_area_size = | |
| 170 ash::Shell::GetScreen()->GetPrimaryDisplay().work_area().size(); | |
| 171 const gfx::Size illegal_size(1280, 960); | |
| 172 const gfx::Rect illegal_bounds(gfx::Point(0, 0), illegal_size); | |
| 173 | |
| 174 aura::test::TestWindowDelegate delegate; | |
| 175 const gfx::Size minimum_size(illegal_size); | |
| 176 delegate.set_minimum_size(minimum_size); | |
| 177 | |
| 178 // The creation should force the window to respect the screen size. | |
| 179 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( | |
| 180 &delegate, -1, illegal_bounds)); | |
| 181 EXPECT_EQ(work_area_size.ToString(), window->bounds().size().ToString()); | |
| 182 | |
| 183 // Trying to set the size to something bigger then the screen size should be | |
| 184 // ignored. | |
| 185 window->SetBounds(illegal_bounds); | |
| 186 EXPECT_EQ(work_area_size.ToString(), window->bounds().size().ToString()); | |
| 187 | |
| 188 // Maximizing the window should not allow it to go bigger than that either. | |
| 189 WindowState* window_state = GetWindowState(window.get()); | |
| 190 window_state->Maximize(); | |
| 191 EXPECT_EQ(work_area_size.ToString(), window->bounds().size().ToString()); | |
| 192 } | |
| 193 | |
| 194 // Test that setting the bounds of a snapped window keeps its snapped. | 133 // Test that setting the bounds of a snapped window keeps its snapped. |
| 195 TEST_F(WindowStateTest, SnapWindowSetBounds) { | 134 TEST_F(WindowStateTest, SnapWindowSetBounds) { |
| 196 if (!SupportsHostWindowResize()) | 135 if (!SupportsHostWindowResize()) |
| 197 return; | 136 return; |
| 198 | 137 |
| 199 UpdateDisplay("0+0-900x600"); | 138 UpdateDisplay("0+0-900x600"); |
| 200 const gfx::Rect kWorkAreaBounds = | 139 const gfx::Rect kWorkAreaBounds = |
| 201 ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); | 140 ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); |
| 202 | 141 |
| 203 scoped_ptr<aura::Window> window( | 142 scoped_ptr<aura::Window> window( |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 EXPECT_TRUE(window_state->IsMaximized()); | 249 EXPECT_TRUE(window_state->IsMaximized()); |
| 311 window_state->SetStateObject(old.Pass()); | 250 window_state->SetStateObject(old.Pass()); |
| 312 EXPECT_FALSE(window_state->IsMaximized()); | 251 EXPECT_FALSE(window_state->IsMaximized()); |
| 313 } | 252 } |
| 314 | 253 |
| 315 // TODO(skuhne): Add more unit test to verify the correctness for the restore | 254 // TODO(skuhne): Add more unit test to verify the correctness for the restore |
| 316 // operation. | 255 // operation. |
| 317 | 256 |
| 318 } // namespace wm | 257 } // namespace wm |
| 319 } // namespace ash | 258 } // namespace ash |
| OLD | NEW |