OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/window_sizer/window_sizer.h" | 5 #include "chrome/browser/ui/window_sizer/window_sizer.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 }; | 72 }; |
73 | 73 |
74 } // namespace | 74 } // namespace |
75 | 75 |
76 TestBrowserWindowAura::TestBrowserWindowAura(aura::Window *native_window) | 76 TestBrowserWindowAura::TestBrowserWindowAura(aura::Window *native_window) |
77 : native_window_(native_window) { | 77 : native_window_(native_window) { |
78 } | 78 } |
79 | 79 |
80 TestBrowserWindowAura::~TestBrowserWindowAura() {} | 80 TestBrowserWindowAura::~TestBrowserWindowAura() {} |
81 | 81 |
| 82 int AlignToGridRoundDown(int location, int grid_size) { |
| 83 if (grid_size <= 1 || location % grid_size == 0) |
| 84 return location; |
| 85 return location / grid_size * grid_size; |
| 86 } |
| 87 |
82 // Test that the window is sized appropriately for the first run experience | 88 // Test that the window is sized appropriately for the first run experience |
83 // where the default window bounds calculation is invoked. | 89 // where the default window bounds calculation is invoked. |
84 TEST_F(WindowSizerTest, DefaultSizeCase) { | 90 TEST_F(WindowSizerTest, DefaultSizeCase) { |
85 int grid = ash::Shell::GetInstance()->GetGridSize(); | 91 int grid = WindowSizer::kDesktopBorderSize; |
86 EXPECT_EQ(WindowSizer::kDesktopBorderSize, grid); | |
87 { // 4:3 monitor case, 1024x768, no taskbar | 92 { // 4:3 monitor case, 1024x768, no taskbar |
88 gfx::Rect window_bounds; | 93 gfx::Rect window_bounds; |
89 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(), | 94 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(), |
90 gfx::Rect(), DEFAULT, &window_bounds, NULL, gfx::Rect()); | 95 gfx::Rect(), DEFAULT, &window_bounds, NULL, gfx::Rect()); |
91 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, | 96 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, |
92 WindowSizer::kDesktopBorderSize, | 97 WindowSizer::kDesktopBorderSize, |
93 1024 - WindowSizer::kDesktopBorderSize * 2, | 98 1024 - WindowSizer::kDesktopBorderSize * 2, |
94 768 - WindowSizer::kDesktopBorderSize), | 99 768 - WindowSizer::kDesktopBorderSize), |
95 window_bounds); | 100 window_bounds); |
96 } | 101 } |
97 | 102 |
98 { // 4:3 monitor case, 1024x768, taskbar on bottom | 103 { // 4:3 monitor case, 1024x768, taskbar on bottom |
99 gfx::Rect window_bounds; | 104 gfx::Rect window_bounds; |
100 GetWindowBounds(tentwentyfour, taskbar_bottom_work_area, gfx::Rect(), | 105 GetWindowBounds(tentwentyfour, taskbar_bottom_work_area, gfx::Rect(), |
101 gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds, NULL, | 106 gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds, NULL, |
102 gfx::Rect()); | 107 gfx::Rect()); |
103 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, | 108 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, |
104 WindowSizer::kDesktopBorderSize, | 109 WindowSizer::kDesktopBorderSize, |
105 1024 - WindowSizer::kDesktopBorderSize * 2, | 110 1024 - WindowSizer::kDesktopBorderSize * 2, |
106 ash::WindowResizer::AlignToGridRoundDown( | 111 AlignToGridRoundDown( |
107 taskbar_bottom_work_area.height() - | 112 taskbar_bottom_work_area.height() - |
108 WindowSizer::kDesktopBorderSize, grid)), | 113 WindowSizer::kDesktopBorderSize, grid)), |
109 window_bounds); | 114 window_bounds); |
110 } | 115 } |
111 | 116 |
112 { // 4:3 monitor case, 1024x768, taskbar on right | 117 { // 4:3 monitor case, 1024x768, taskbar on right |
113 gfx::Rect window_bounds; | 118 gfx::Rect window_bounds; |
114 GetWindowBounds(tentwentyfour, taskbar_right_work_area, gfx::Rect(), | 119 GetWindowBounds(tentwentyfour, taskbar_right_work_area, gfx::Rect(), |
115 gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds, NULL, | 120 gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds, NULL, |
116 gfx::Rect()); | 121 gfx::Rect()); |
117 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, | 122 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, |
118 WindowSizer::kDesktopBorderSize, | 123 WindowSizer::kDesktopBorderSize, |
119 ash::WindowResizer::AlignToGridRoundDown( | 124 AlignToGridRoundDown( |
120 taskbar_right_work_area.width() - | 125 taskbar_right_work_area.width() - |
121 WindowSizer::kDesktopBorderSize * 2, grid), | 126 WindowSizer::kDesktopBorderSize * 2, grid), |
122 768 - WindowSizer::kDesktopBorderSize), | 127 768 - WindowSizer::kDesktopBorderSize), |
123 window_bounds); | 128 window_bounds); |
124 } | 129 } |
125 | 130 |
126 { // 4:3 monitor case, 1024x768, taskbar on left | 131 { // 4:3 monitor case, 1024x768, taskbar on left |
127 gfx::Rect window_bounds; | 132 gfx::Rect window_bounds; |
128 GetWindowBounds(tentwentyfour, taskbar_left_work_area, gfx::Rect(), | 133 GetWindowBounds(tentwentyfour, taskbar_left_work_area, gfx::Rect(), |
129 gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds, NULL, | 134 gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds, NULL, |
130 gfx::Rect()); | 135 gfx::Rect()); |
131 EXPECT_EQ(gfx::Rect(taskbar_left_work_area.x() + | 136 EXPECT_EQ(gfx::Rect(taskbar_left_work_area.x() + |
132 WindowSizer::kDesktopBorderSize, | 137 WindowSizer::kDesktopBorderSize, |
133 WindowSizer::kDesktopBorderSize, | 138 WindowSizer::kDesktopBorderSize, |
134 ash::WindowResizer::AlignToGridRoundDown( | 139 AlignToGridRoundDown( |
135 taskbar_left_work_area.width() - | 140 taskbar_left_work_area.width() - |
136 WindowSizer::kDesktopBorderSize * 2, grid), | 141 WindowSizer::kDesktopBorderSize * 2, grid), |
137 ash::WindowResizer::AlignToGridRoundDown( | 142 AlignToGridRoundDown( |
138 taskbar_left_work_area.height() - | 143 taskbar_left_work_area.height() - |
139 WindowSizer::kDesktopBorderSize, grid)), | 144 WindowSizer::kDesktopBorderSize, grid)), |
140 window_bounds); | 145 window_bounds); |
141 } | 146 } |
142 | 147 |
143 { // 4:3 monitor case, 1024x768, taskbar on top | 148 { // 4:3 monitor case, 1024x768, taskbar on top |
144 gfx::Rect window_bounds; | 149 gfx::Rect window_bounds; |
145 GetWindowBounds(tentwentyfour, taskbar_top_work_area, gfx::Rect(), | 150 GetWindowBounds(tentwentyfour, taskbar_top_work_area, gfx::Rect(), |
146 gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds, NULL, | 151 gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds, NULL, |
147 gfx::Rect()); | 152 gfx::Rect()); |
148 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, | 153 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, |
149 taskbar_top_work_area.y() + | 154 taskbar_top_work_area.y() + |
150 WindowSizer::kDesktopBorderSize, | 155 WindowSizer::kDesktopBorderSize, |
151 1024 - WindowSizer::kDesktopBorderSize * 2, | 156 1024 - WindowSizer::kDesktopBorderSize * 2, |
152 ash::WindowResizer::AlignToGridRoundDown( | 157 AlignToGridRoundDown( |
153 taskbar_top_work_area.height() - | 158 taskbar_top_work_area.height() - |
154 WindowSizer::kDesktopBorderSize, grid)), | 159 WindowSizer::kDesktopBorderSize, grid)), |
155 window_bounds); | 160 window_bounds); |
156 } | 161 } |
157 | 162 |
158 { // 4:3 monitor case, 1280x1024 | 163 { // 4:3 monitor case, 1280x1024 |
159 gfx::Rect window_bounds; | 164 gfx::Rect window_bounds; |
160 GetWindowBounds(twelveeighty, twelveeighty, gfx::Rect(), gfx::Rect(), | 165 GetWindowBounds(twelveeighty, twelveeighty, gfx::Rect(), gfx::Rect(), |
161 gfx::Rect(), DEFAULT, &window_bounds, NULL, gfx::Rect()); | 166 gfx::Rect(), DEFAULT, &window_bounds, NULL, gfx::Rect()); |
162 EXPECT_EQ(gfx::Rect((1280 - WindowSizer::kMaximumWindowWidth) / 2, | 167 EXPECT_EQ(gfx::Rect((1280 - WindowSizer::kMaximumWindowWidth) / 2, |
(...skipping 14 matching lines...) Expand all Loading... |
177 window_bounds); | 182 window_bounds); |
178 } | 183 } |
179 | 184 |
180 { // 16:10 monitor case, 1680x1050 | 185 { // 16:10 monitor case, 1680x1050 |
181 gfx::Rect window_bounds; | 186 gfx::Rect window_bounds; |
182 GetWindowBounds(sixteeneighty, sixteeneighty, gfx::Rect(), gfx::Rect(), | 187 GetWindowBounds(sixteeneighty, sixteeneighty, gfx::Rect(), gfx::Rect(), |
183 gfx::Rect(), DEFAULT, &window_bounds, NULL, gfx::Rect()); | 188 gfx::Rect(), DEFAULT, &window_bounds, NULL, gfx::Rect()); |
184 EXPECT_EQ(gfx::Rect((1680 - WindowSizer::kMaximumWindowWidth) / 2, | 189 EXPECT_EQ(gfx::Rect((1680 - WindowSizer::kMaximumWindowWidth) / 2, |
185 WindowSizer::kDesktopBorderSize, | 190 WindowSizer::kDesktopBorderSize, |
186 WindowSizer::kMaximumWindowWidth, | 191 WindowSizer::kMaximumWindowWidth, |
187 ash::WindowResizer::AlignToGridRoundDown( | 192 AlignToGridRoundDown( |
188 1050 - WindowSizer::kDesktopBorderSize, | 193 1050 - WindowSizer::kDesktopBorderSize, |
189 grid)), | 194 grid)), |
190 window_bounds); | 195 window_bounds); |
191 } | 196 } |
192 | 197 |
193 { // 16:10 monitor case, 1920x1200 | 198 { // 16:10 monitor case, 1920x1200 |
194 gfx::Rect window_bounds; | 199 gfx::Rect window_bounds; |
195 GetWindowBounds(nineteentwenty, nineteentwenty, gfx::Rect(), gfx::Rect(), | 200 GetWindowBounds(nineteentwenty, nineteentwenty, gfx::Rect(), gfx::Rect(), |
196 gfx::Rect(), DEFAULT, &window_bounds, NULL, gfx::Rect()); | 201 gfx::Rect(), DEFAULT, &window_bounds, NULL, gfx::Rect()); |
197 EXPECT_EQ(gfx::Rect((1920 - WindowSizer::kMaximumWindowWidth) / 2, | 202 EXPECT_EQ(gfx::Rect((1920 - WindowSizer::kMaximumWindowWidth) / 2, |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 } | 703 } |
699 | 704 |
700 { // Check that a window which hangs out of the screen get moved back in. | 705 { // Check that a window which hangs out of the screen get moved back in. |
701 gfx::Rect window_bounds; | 706 gfx::Rect window_bounds; |
702 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(), | 707 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(), |
703 gfx::Rect(), DEFAULT, &window_bounds, NULL, | 708 gfx::Rect(), DEFAULT, &window_bounds, NULL, |
704 gfx::Rect(1020, 700, 100, 100)); | 709 gfx::Rect(1020, 700, 100, 100)); |
705 EXPECT_EQ(gfx::Rect(924, 668, 100, 100), window_bounds); | 710 EXPECT_EQ(gfx::Rect(924, 668, 100, 100), window_bounds); |
706 } | 711 } |
707 } | 712 } |
OLD | NEW |