Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / ash / wm / window_util_unittest.cc
blob3ce125932bf97734d6ca87db8e60edad608a523b
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"
12 namespace ash {
14 namespace {
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())
28 return;
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("-75,10 100x100",
59 GetAdjustedBounds(visible_bounds, gfx::Rect(-100, 10, 150, 150)));
60 EXPECT_EQ("75,75 100x100",
61 GetAdjustedBounds(visible_bounds, gfx::Rect(100, 100, 150, 150)));
63 const gfx::Rect visible_bounds_right(200, 50, 100, 100);
65 EXPECT_EQ(
66 "210,60 90x90",
67 GetAdjustedBounds(visible_bounds_right, gfx::Rect(210, 60, 90, 90)));
68 EXPECT_EQ(
69 "210,60 100x100",
70 GetAdjustedBounds(visible_bounds_right, gfx::Rect(210, 60, 150, 150)));
71 EXPECT_EQ("125,50 100x100",
72 GetAdjustedBounds(visible_bounds_right, gfx::Rect(0, 0, 150, 150)));
73 EXPECT_EQ("275,50 100x100", GetAdjustedBounds(visible_bounds_right,
74 gfx::Rect(300, 20, 150, 150)));
75 EXPECT_EQ(
76 "125,125 100x100",
77 GetAdjustedBounds(visible_bounds_right, gfx::Rect(-100, 150, 150, 150)));
79 const gfx::Rect visible_bounds_left(-200, -50, 100, 100);
80 EXPECT_EQ(
81 "-190,-40 90x90",
82 GetAdjustedBounds(visible_bounds_left, gfx::Rect(-190, -40, 90, 90)));
83 EXPECT_EQ(
84 "-190,-40 100x100",
85 GetAdjustedBounds(visible_bounds_left, gfx::Rect(-190, -40, 150, 150)));
86 EXPECT_EQ(
87 "-250,-40 100x100",
88 GetAdjustedBounds(visible_bounds_left, gfx::Rect(-250, -40, 150, 150)));
89 EXPECT_EQ(
90 "-275,-50 100x100",
91 GetAdjustedBounds(visible_bounds_left, gfx::Rect(-400, -60, 150, 150)));
92 EXPECT_EQ("-125,0 100x100",
93 GetAdjustedBounds(visible_bounds_left, gfx::Rect(0, 0, 150, 150)));
96 } // namespace ash