1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ash/wm/window_util.h"
7 #include "ash/screen_util.h"
8 #include "ash/test/ash_test_base.h"
9 #include "ash/wm/window_state.h"
10 #include "ui/aura/window.h"
16 std::string
GetAdjustedBounds(const gfx::Rect
& visible
,
17 gfx::Rect to_be_adjusted
) {
18 wm::AdjustBoundsToEnsureMinimumWindowVisibility(visible
, &to_be_adjusted
);
19 return to_be_adjusted
.ToString();
24 typedef test::AshTestBase WindowUtilTest
;
26 TEST_F(WindowUtilTest
, CenterWindow
) {
27 if (!SupportsMultipleDisplays())
30 UpdateDisplay("500x400, 600x400");
31 scoped_ptr
<aura::Window
> window(
32 CreateTestWindowInShellWithBounds(gfx::Rect(12, 20, 100, 100)));
34 wm::WindowState
* window_state
= wm::GetWindowState(window
.get());
35 EXPECT_FALSE(window_state
->bounds_changed_by_user());
37 wm::CenterWindow(window
.get());
38 // Centring window is considered as a user's action.
39 EXPECT_TRUE(window_state
->bounds_changed_by_user());
40 EXPECT_EQ("200,126 100x100", window
->bounds().ToString());
41 EXPECT_EQ("200,126 100x100", window
->GetBoundsInScreen().ToString());
42 window
->SetBoundsInScreen(gfx::Rect(600, 0, 100, 100),
43 ScreenUtil::GetSecondaryDisplay());
44 wm::CenterWindow(window
.get());
45 EXPECT_EQ("250,126 100x100", window
->bounds().ToString());
46 EXPECT_EQ("750,126 100x100", window
->GetBoundsInScreen().ToString());
49 TEST_F(WindowUtilTest
, AdjustBoundsToEnsureMinimumVisibility
) {
50 const gfx::Rect
visible_bounds(0, 0, 100, 100);
52 EXPECT_EQ("0,0 90x90",
53 GetAdjustedBounds(visible_bounds
, gfx::Rect(0, 0, 90, 90)));
54 EXPECT_EQ("0,0 100x100",
55 GetAdjustedBounds(visible_bounds
, gfx::Rect(0, 0, 150, 150)));
56 EXPECT_EQ("-50,0 100x100",
57 GetAdjustedBounds(visible_bounds
, gfx::Rect(-50, -50, 150, 150)));
58 EXPECT_EQ("-90,10 100x100",
59 GetAdjustedBounds(visible_bounds
, gfx::Rect(-100, 10, 150, 150)));
60 EXPECT_EQ("90,90 100x100",
61 GetAdjustedBounds(visible_bounds
, gfx::Rect(100, 100, 150, 150)));
63 const gfx::Rect
visible_bounds_right(200, 50, 100, 100);
67 GetAdjustedBounds(visible_bounds_right
, gfx::Rect(210, 60, 90, 90)));
70 GetAdjustedBounds(visible_bounds_right
, gfx::Rect(210, 60, 150, 150)));
73 GetAdjustedBounds(visible_bounds_right
, gfx::Rect(0, 0, 150, 150)));
76 GetAdjustedBounds(visible_bounds_right
, gfx::Rect(300, 20, 150, 150)));
79 GetAdjustedBounds(visible_bounds_right
, gfx::Rect(-100, 150, 150, 150)));
81 const gfx::Rect
visible_bounds_left(-200, -50, 100, 100);
84 GetAdjustedBounds(visible_bounds_left
, gfx::Rect(-190, -40, 90, 90)));
87 GetAdjustedBounds(visible_bounds_left
, gfx::Rect(-190, -40, 150, 150)));
90 GetAdjustedBounds(visible_bounds_left
, gfx::Rect(-250, -40, 150, 150)));
93 GetAdjustedBounds(visible_bounds_left
, gfx::Rect(-400, -60, 150, 150)));
96 GetAdjustedBounds(visible_bounds_left
, gfx::Rect(0, 0, 150, 150)));