window_util_unittest.cc revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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.
4
5#include "ash/wm/window_util.h"
6
7#include "ash/screen_util.h"
8#include "ash/test/ash_test_base.h"
9#include "ui/aura/window.h"
10
11namespace ash {
12
13namespace {
14
15std::string GetAdjustedBounds(const gfx::Rect& visible,
16                              gfx::Rect to_be_adjusted) {
17  wm::AdjustBoundsToEnsureMinimumWindowVisibility(visible, &to_be_adjusted);
18  return to_be_adjusted.ToString();
19}
20
21}
22
23typedef test::AshTestBase WindowUtilTest;
24
25TEST_F(WindowUtilTest, CenterWindow) {
26  if (!SupportsMultipleDisplays())
27    return;
28
29  UpdateDisplay("500x400, 600x400");
30  scoped_ptr<aura::Window> window(
31      CreateTestWindowInShellWithBounds(gfx::Rect(12, 20, 100, 100)));
32  wm::CenterWindow(window.get());
33  EXPECT_EQ("200,126 100x100", window->bounds().ToString());
34  EXPECT_EQ("200,126 100x100", window->GetBoundsInScreen().ToString());
35  window->SetBoundsInScreen(gfx::Rect(600, 0, 100, 100),
36                            ScreenUtil::GetSecondaryDisplay());
37  wm::CenterWindow(window.get());
38  EXPECT_EQ("250,126 100x100", window->bounds().ToString());
39  EXPECT_EQ("750,126 100x100", window->GetBoundsInScreen().ToString());
40}
41
42TEST_F(WindowUtilTest, AdjustBoundsToEnsureMinimumVisibility) {
43  const gfx::Rect visible_bounds(0, 0, 100, 100);
44
45  EXPECT_EQ("0,0 90x90",
46            GetAdjustedBounds(visible_bounds, gfx::Rect(0, 0, 90, 90)));
47  EXPECT_EQ("0,0 100x100",
48            GetAdjustedBounds(visible_bounds, gfx::Rect(0, 0, 150, 150)));
49  EXPECT_EQ("-50,0 100x100",
50            GetAdjustedBounds(visible_bounds, gfx::Rect(-50, -50, 150, 150)));
51  EXPECT_EQ("-90,10 100x100",
52            GetAdjustedBounds(visible_bounds, gfx::Rect(-100, 10, 150, 150)));
53  EXPECT_EQ("90,90 100x100",
54            GetAdjustedBounds(visible_bounds, gfx::Rect(100, 100, 150, 150)));
55
56  const gfx::Rect visible_bounds_right(200, 50, 100, 100);
57
58  EXPECT_EQ(
59      "210,60 90x90",
60      GetAdjustedBounds(visible_bounds_right, gfx::Rect(210, 60, 90, 90)));
61  EXPECT_EQ(
62      "210,60 100x100",
63      GetAdjustedBounds(visible_bounds_right, gfx::Rect(210, 60, 150, 150)));
64  EXPECT_EQ(
65      "110,50 100x100",
66      GetAdjustedBounds(visible_bounds_right, gfx::Rect(0, 0, 150, 150)));
67  EXPECT_EQ(
68      "290,50 100x100",
69      GetAdjustedBounds(visible_bounds_right, gfx::Rect(300, 20, 150, 150)));
70  EXPECT_EQ(
71      "110,140 100x100",
72      GetAdjustedBounds(visible_bounds_right, gfx::Rect(-100, 150, 150, 150)));
73
74  const gfx::Rect visible_bounds_left(-200, -50, 100, 100);
75  EXPECT_EQ(
76      "-190,-40 90x90",
77      GetAdjustedBounds(visible_bounds_left, gfx::Rect(-190, -40, 90, 90)));
78  EXPECT_EQ(
79      "-190,-40 100x100",
80      GetAdjustedBounds(visible_bounds_left, gfx::Rect(-190, -40, 150, 150)));
81  EXPECT_EQ(
82      "-250,-40 100x100",
83      GetAdjustedBounds(visible_bounds_left, gfx::Rect(-250, -40, 150, 150)));
84  EXPECT_EQ(
85      "-290,-50 100x100",
86      GetAdjustedBounds(visible_bounds_left, gfx::Rect(-400, -60, 150, 150)));
87  EXPECT_EQ(
88      "-110,0 100x100",
89      GetAdjustedBounds(visible_bounds_left, gfx::Rect(0, 0, 150, 150)));
90}
91
92}  // namespace ash
93