OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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_util.h" | 5 #include "ash/wm/window_util.h" |
6 | 6 |
7 #include "ash/screen_ash.h" | 7 #include "ash/screen_ash.h" |
8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
9 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
10 | 10 |
11 namespace ash { | 11 namespace ash { |
12 | 12 |
13 namespace { | |
14 | |
15 std::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 | |
23 typedef test::AshTestBase WindowUtilTest; | 13 typedef test::AshTestBase WindowUtilTest; |
24 | 14 |
25 TEST_F(WindowUtilTest, CenterWindow) { | 15 TEST_F(WindowUtilTest, CenterWindow) { |
26 if (!SupportsMultipleDisplays()) | 16 if (!SupportsMultipleDisplays()) |
27 return; | 17 return; |
28 | 18 |
29 UpdateDisplay("500x400, 600x400"); | 19 UpdateDisplay("500x400, 600x400"); |
30 scoped_ptr<aura::Window> window( | 20 scoped_ptr<aura::Window> window( |
31 CreateTestWindowInShellWithBounds(gfx::Rect(12, 20, 100, 100))); | 21 CreateTestWindowInShellWithBounds(gfx::Rect(12, 20, 100, 100))); |
32 wm::CenterWindow(window.get()); | 22 wm::CenterWindow(window.get()); |
33 EXPECT_EQ("200,126 100x100", window->bounds().ToString()); | 23 EXPECT_EQ("200,126 100x100", window->bounds().ToString()); |
34 EXPECT_EQ("200,126 100x100", window->GetBoundsInScreen().ToString()); | 24 EXPECT_EQ("200,126 100x100", window->GetBoundsInScreen().ToString()); |
35 window->SetBoundsInScreen(gfx::Rect(600, 0, 100, 100), | 25 window->SetBoundsInScreen(gfx::Rect(600, 0, 100, 100), |
36 ScreenAsh::GetSecondaryDisplay()); | 26 ScreenAsh::GetSecondaryDisplay()); |
37 wm::CenterWindow(window.get()); | 27 wm::CenterWindow(window.get()); |
38 EXPECT_EQ("250,126 100x100", window->bounds().ToString()); | 28 EXPECT_EQ("250,126 100x100", window->bounds().ToString()); |
39 EXPECT_EQ("750,126 100x100", window->GetBoundsInScreen().ToString()); | 29 EXPECT_EQ("750,126 100x100", window->GetBoundsInScreen().ToString()); |
40 } | 30 } |
41 | 31 |
42 TEST_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 | 32 } // namespace ash |
OLD | NEW |