Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: chrome/browser/window_sizer_unittest.cc

Issue 160246: Reposition and/or resize window if it becomes off-screen.... (Closed) Base URL: svn://chrome-svn.corp.google.com/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/window_sizer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <vector> 5 #include <vector>
6 6
7 #include "chrome/browser/window_sizer.h" 7 #include "chrome/browser/window_sizer.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 // Some standard monitor sizes (no task bar). 11 // Some standard monitor sizes (no task bar).
12 static const gfx::Rect tentwentyfour(0, 0, 1024, 768); 12 static const gfx::Rect tentwentyfour(0, 0, 1024, 768);
13 static const gfx::Rect twelveeighty(0, 0, 1280, 1024); 13 static const gfx::Rect twelveeighty(0, 0, 1280, 1024);
14 static const gfx::Rect sixteenhundred(0, 0, 1600, 1200); 14 static const gfx::Rect sixteenhundred(0, 0, 1600, 1200);
15 static const gfx::Rect sixteeneighty(0, 0, 1680, 1050); 15 static const gfx::Rect sixteeneighty(0, 0, 1680, 1050);
16 static const gfx::Rect nineteentwenty(0, 0, 1920, 1200); 16 static const gfx::Rect nineteentwenty(0, 0, 1920, 1200);
17 17
18 // Represents a 1024x768 monitor that is not the primary monitor, arranged to 18 // Represents a 1024x768 monitor that is not the primary monitor, arranged to
19 // the immediate left of the primary 1024x768 monitor. 19 // the immediate left of the primary 1024x768 monitor.
20 static const gfx::Rect left_nonprimary(-1024, 0, 1024, 768); 20 static const gfx::Rect left_nonprimary(-1024, 0, 1024, 768);
21 21
22 // Represents a 1024x768 monitor that is not the primary monitor, arranged to 22 // Represents a 1024x768 monitor that is not the primary monitor, arranged to
23 // the immediate right of the primary 1024x768 monitor. 23 // the immediate right of the primary 1024x768 monitor.
24 static const gfx::Rect right_nonprimary(1024, 0, 1024, 768); 24 static const gfx::Rect right_nonprimary(1024, 0, 1024, 768);
25 25
26 // Represents a 1024x768 monitor that is not the primary monitor, arranged to 26 // Represents a 1024x768 monitor that is not the primary monitor, arranged to
27 // the immediate top of the primary 1024x768 monitor. 27 // the immediate top of the primary 1024x768 monitor.
28 static const gfx::Rect top_nonprimary(0, -768, 1024, 768); 28 static const gfx::Rect top_nonprimary(0, -768, 1024, 768);
29 29
30 // Represents a 1024x768 monitor that is not the primary monitor, arranged to
31 // the immediate bottom of the primary 1024x768 monitor.
32 static const gfx::Rect bottom_nonprimary(0, 768, 1024, 768);
33
30 // The work area for 1024x768 monitors with different taskbar orientations. 34 // The work area for 1024x768 monitors with different taskbar orientations.
31 static const gfx::Rect taskbar_bottom_work_area(0, 0, 1024, 734); 35 static const gfx::Rect taskbar_bottom_work_area(0, 0, 1024, 734);
32 static const gfx::Rect taskbar_top_work_area(0, 34, 1024, 734); 36 static const gfx::Rect taskbar_top_work_area(0, 34, 1024, 734);
33 static const gfx::Rect taskbar_left_work_area(107, 0, 917, 768); 37 static const gfx::Rect taskbar_left_work_area(107, 0, 917, 768);
34 static const gfx::Rect taskbar_right_work_area(0, 0, 917, 768); 38 static const gfx::Rect taskbar_right_work_area(0, 0, 917, 768);
35 39
36 static int kWindowTilePixels = WindowSizer::kWindowTilePixels; 40 static int kWindowTilePixels = WindowSizer::kWindowTilePixels;
37 41
38 // Testing implementation of WindowSizer::MonitorInfoProvider that we can use 42 // Testing implementation of WindowSizer::MonitorInfoProvider that we can use
39 // to fake various monitor layouts and sizes. 43 // to fake various monitor layouts and sizes.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 public: 104 public:
101 TestStateProvider() 105 TestStateProvider()
102 : persistent_maximized_(false), 106 : persistent_maximized_(false),
103 has_persistent_data_(false), 107 has_persistent_data_(false),
104 has_last_active_data_(false) { 108 has_last_active_data_(false) {
105 } 109 }
106 virtual ~TestStateProvider() {} 110 virtual ~TestStateProvider() {}
107 111
108 void SetPersistentState(const gfx::Rect& bounds, 112 void SetPersistentState(const gfx::Rect& bounds,
109 bool maximized, 113 bool maximized,
114 const gfx::Rect& work_area,
110 bool has_persistent_data) { 115 bool has_persistent_data) {
111 persistent_bounds_ = bounds; 116 persistent_bounds_ = bounds;
112 persistent_maximized_ = maximized; 117 persistent_maximized_ = maximized;
118 persistent_work_area_ = work_area;
113 has_persistent_data_ = has_persistent_data; 119 has_persistent_data_ = has_persistent_data;
114 } 120 }
115 121
116 void SetLastActiveState(const gfx::Rect& bounds, bool has_last_active_data) { 122 void SetLastActiveState(const gfx::Rect& bounds, bool has_last_active_data) {
117 last_active_bounds_ = bounds; 123 last_active_bounds_ = bounds;
118 has_last_active_data_ = has_last_active_data; 124 has_last_active_data_ = has_last_active_data;
119 } 125 }
120 126
121 // Overridden from WindowSizer::StateProvider: 127 // Overridden from WindowSizer::StateProvider:
122 virtual bool GetPersistentState(gfx::Rect* bounds, bool* maximized) const { 128 virtual bool GetPersistentState(gfx::Rect* bounds,
129 bool* maximized,
130 gfx::Rect* saved_work_area) const {
123 *bounds = persistent_bounds_; 131 *bounds = persistent_bounds_;
124 *maximized = persistent_maximized_; 132 *maximized = persistent_maximized_;
133 *saved_work_area = persistent_work_area_;
125 return has_persistent_data_; 134 return has_persistent_data_;
126 } 135 }
127 136
128 virtual bool GetLastActiveWindowState(gfx::Rect* bounds) const { 137 virtual bool GetLastActiveWindowState(gfx::Rect* bounds) const {
129 *bounds = last_active_bounds_; 138 *bounds = last_active_bounds_;
130 return has_last_active_data_; 139 return has_last_active_data_;
131 } 140 }
132 141
133 private: 142 private:
134 gfx::Rect persistent_bounds_; 143 gfx::Rect persistent_bounds_;
135 bool persistent_maximized_; 144 bool persistent_maximized_;
145 gfx::Rect persistent_work_area_;
136 bool has_persistent_data_; 146 bool has_persistent_data_;
137 147
138 gfx::Rect last_active_bounds_; 148 gfx::Rect last_active_bounds_;
139 bool has_last_active_data_; 149 bool has_last_active_data_;
140 150
141 DISALLOW_COPY_AND_ASSIGN(TestStateProvider); 151 DISALLOW_COPY_AND_ASSIGN(TestStateProvider);
142 }; 152 };
143 153
144 // A convenience function to read the window bounds from the window sizer 154 // A convenience function to read the window bounds from the window sizer
145 // according to the specified configuration. 155 // according to the specified configuration.
146 enum Source { DEFAULT, LAST_ACTIVE, PERSISTED }; 156 enum Source { DEFAULT, LAST_ACTIVE, PERSISTED };
147 static void GetWindowBounds(const gfx::Rect& monitor1_bounds, 157 static void GetWindowBounds(const gfx::Rect& monitor1_bounds,
148 const gfx::Rect& monitor1_work_area, 158 const gfx::Rect& monitor1_work_area,
149 const gfx::Rect& monitor2_bounds, 159 const gfx::Rect& monitor2_bounds,
150 const gfx::Rect& state, 160 const gfx::Rect& state,
151 bool maximized, 161 bool maximized,
162 const gfx::Rect& work_area,
152 Source source, 163 Source source,
153 gfx::Rect* out_bounds, 164 gfx::Rect* out_bounds,
154 bool* out_maximized) { 165 bool* out_maximized) {
155 TestMonitorInfoProvider* mip = new TestMonitorInfoProvider; 166 TestMonitorInfoProvider* mip = new TestMonitorInfoProvider;
156 mip->AddMonitor(monitor1_bounds, monitor1_work_area); 167 mip->AddMonitor(monitor1_bounds, monitor1_work_area);
157 if (!monitor2_bounds.IsEmpty()) 168 if (!monitor2_bounds.IsEmpty())
158 mip->AddMonitor(monitor2_bounds, monitor2_bounds); 169 mip->AddMonitor(monitor2_bounds, monitor2_bounds);
159 TestStateProvider* sp = new TestStateProvider; 170 TestStateProvider* sp = new TestStateProvider;
160 if (source == PERSISTED) 171 if (source == PERSISTED)
161 sp->SetPersistentState(state, maximized, true); 172 sp->SetPersistentState(state, maximized, work_area, true);
162 else if (source == LAST_ACTIVE) 173 else if (source == LAST_ACTIVE)
163 sp->SetLastActiveState(state, true); 174 sp->SetLastActiveState(state, true);
164 WindowSizer sizer(sp, mip); 175 WindowSizer sizer(sp, mip);
165 sizer.DetermineWindowBounds(gfx::Rect(), out_bounds, out_maximized); 176 sizer.DetermineWindowBounds(gfx::Rect(), out_bounds, out_maximized);
166 } 177 }
167 178
168 // Test that the window is sized appropriately for the first run experience 179 // Test that the window is sized appropriately for the first run experience
169 // where the default window bounds calculation is invoked. 180 // where the default window bounds calculation is invoked.
170 TEST(WindowSizerTest, DefaultSizeCase) { 181 TEST(WindowSizerTest, DefaultSizeCase) {
171 { // 4:3 monitor case, 1024x768, no taskbar 182 { // 4:3 monitor case, 1024x768, no taskbar
172 gfx::Rect window_bounds; 183 gfx::Rect window_bounds;
173 bool maximized; 184 bool maximized;
174 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(), 185 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(),
175 false, DEFAULT, &window_bounds, &maximized); 186 false, gfx::Rect(), DEFAULT, &window_bounds, &maximized);
176 EXPECT_FALSE(maximized); 187 EXPECT_FALSE(maximized);
177 EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels, 188 EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels,
178 1024 - kWindowTilePixels * 2, 189 1024 - kWindowTilePixels * 2,
179 768 - kWindowTilePixels * 2), 190 768 - kWindowTilePixels * 2),
180 window_bounds); 191 window_bounds);
181 } 192 }
182 193
183 { // 4:3 monitor case, 1024x768, taskbar on bottom 194 { // 4:3 monitor case, 1024x768, taskbar on bottom
184 gfx::Rect window_bounds; 195 gfx::Rect window_bounds;
185 bool maximized; 196 bool maximized;
186 GetWindowBounds(tentwentyfour, taskbar_bottom_work_area, gfx::Rect(), 197 GetWindowBounds(tentwentyfour, taskbar_bottom_work_area, gfx::Rect(),
187 gfx::Rect(), false, DEFAULT, &window_bounds, &maximized); 198 gfx::Rect(), false, gfx::Rect(), DEFAULT, &window_bounds,
199 &maximized);
188 EXPECT_FALSE(maximized); 200 EXPECT_FALSE(maximized);
189 EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels, 201 EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels,
190 1024 - kWindowTilePixels * 2, 202 1024 - kWindowTilePixels * 2,
191 (taskbar_bottom_work_area.height() - 203 (taskbar_bottom_work_area.height() -
192 kWindowTilePixels * 2)), 204 kWindowTilePixels * 2)),
193 window_bounds); 205 window_bounds);
194 } 206 }
195 207
196 { // 4:3 monitor case, 1024x768, taskbar on right 208 { // 4:3 monitor case, 1024x768, taskbar on right
197 gfx::Rect window_bounds; 209 gfx::Rect window_bounds;
198 bool maximized; 210 bool maximized;
199 GetWindowBounds(tentwentyfour, taskbar_right_work_area, gfx::Rect(), 211 GetWindowBounds(tentwentyfour, taskbar_right_work_area, gfx::Rect(),
200 gfx::Rect(), false, DEFAULT, &window_bounds, &maximized); 212 gfx::Rect(), false, gfx::Rect(), DEFAULT, &window_bounds,
213 &maximized);
201 EXPECT_FALSE(maximized); 214 EXPECT_FALSE(maximized);
202 EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels, 215 EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels,
203 taskbar_right_work_area.width() - kWindowTilePixels*2, 216 taskbar_right_work_area.width() - kWindowTilePixels*2,
204 768 - kWindowTilePixels * 2), 217 768 - kWindowTilePixels * 2),
205 window_bounds); 218 window_bounds);
206 } 219 }
207 220
208 { // 4:3 monitor case, 1024x768, taskbar on left 221 { // 4:3 monitor case, 1024x768, taskbar on left
209 gfx::Rect window_bounds; 222 gfx::Rect window_bounds;
210 bool maximized; 223 bool maximized;
211 GetWindowBounds(tentwentyfour, taskbar_left_work_area, gfx::Rect(), 224 GetWindowBounds(tentwentyfour, taskbar_left_work_area, gfx::Rect(),
212 gfx::Rect(), false, DEFAULT, &window_bounds, &maximized); 225 gfx::Rect(), false, gfx::Rect(), DEFAULT, &window_bounds,
226 &maximized);
213 EXPECT_FALSE(maximized); 227 EXPECT_FALSE(maximized);
214 EXPECT_EQ(gfx::Rect(taskbar_left_work_area.x() + kWindowTilePixels, 228 EXPECT_EQ(gfx::Rect(taskbar_left_work_area.x() + kWindowTilePixels,
215 kWindowTilePixels, 229 kWindowTilePixels,
216 taskbar_left_work_area.width() - kWindowTilePixels * 2, 230 taskbar_left_work_area.width() - kWindowTilePixels * 2,
217 (taskbar_left_work_area.height() - 231 (taskbar_left_work_area.height() -
218 kWindowTilePixels * 2)), 232 kWindowTilePixels * 2)),
219 window_bounds); 233 window_bounds);
220 } 234 }
221 235
222 { // 4:3 monitor case, 1024x768, taskbar on top 236 { // 4:3 monitor case, 1024x768, taskbar on top
223 gfx::Rect window_bounds; 237 gfx::Rect window_bounds;
224 bool maximized; 238 bool maximized;
225 GetWindowBounds(tentwentyfour, taskbar_top_work_area, gfx::Rect(), 239 GetWindowBounds(tentwentyfour, taskbar_top_work_area, gfx::Rect(),
226 gfx::Rect(), false, DEFAULT, &window_bounds, &maximized); 240 gfx::Rect(), false, gfx::Rect(), DEFAULT, &window_bounds,
241 &maximized);
227 EXPECT_FALSE(maximized); 242 EXPECT_FALSE(maximized);
228 EXPECT_EQ(gfx::Rect(kWindowTilePixels, 243 EXPECT_EQ(gfx::Rect(kWindowTilePixels,
229 taskbar_top_work_area.y() + kWindowTilePixels, 244 taskbar_top_work_area.y() + kWindowTilePixels,
230 1024 - kWindowTilePixels * 2, 245 1024 - kWindowTilePixels * 2,
231 taskbar_top_work_area.height() - kWindowTilePixels * 2), 246 taskbar_top_work_area.height() - kWindowTilePixels * 2),
232 window_bounds); 247 window_bounds);
233 } 248 }
234 249
235 { // 4:3 monitor case, 1280x1024 250 { // 4:3 monitor case, 1280x1024
236 gfx::Rect window_bounds; 251 gfx::Rect window_bounds;
237 bool maximized; 252 bool maximized;
238 GetWindowBounds(twelveeighty, twelveeighty, gfx::Rect(), gfx::Rect(), 253 GetWindowBounds(twelveeighty, twelveeighty, gfx::Rect(), gfx::Rect(),
239 false, DEFAULT, &window_bounds, &maximized); 254 false, gfx::Rect(), DEFAULT, &window_bounds, &maximized);
240 EXPECT_FALSE(maximized); 255 EXPECT_FALSE(maximized);
241 EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels, 256 EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels,
242 1050, 257 1050,
243 1024 - kWindowTilePixels * 2), 258 1024 - kWindowTilePixels * 2),
244 window_bounds); 259 window_bounds);
245 } 260 }
246 261
247 { // 4:3 monitor case, 1600x1200 262 { // 4:3 monitor case, 1600x1200
248 gfx::Rect window_bounds; 263 gfx::Rect window_bounds;
249 bool maximized; 264 bool maximized;
250 GetWindowBounds(sixteenhundred, sixteenhundred, gfx::Rect(), gfx::Rect(), 265 GetWindowBounds(sixteenhundred, sixteenhundred, gfx::Rect(), gfx::Rect(),
251 false, DEFAULT, &window_bounds, &maximized); 266 false, gfx::Rect(), DEFAULT, &window_bounds, &maximized);
252 EXPECT_FALSE(maximized); 267 EXPECT_FALSE(maximized);
253 EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels, 268 EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels,
254 1050, 269 1050,
255 1200 - kWindowTilePixels * 2), 270 1200 - kWindowTilePixels * 2),
256 window_bounds); 271 window_bounds);
257 } 272 }
258 273
259 { // 16:10 monitor case, 1680x1050 274 { // 16:10 monitor case, 1680x1050
260 gfx::Rect window_bounds; 275 gfx::Rect window_bounds;
261 bool maximized; 276 bool maximized;
262 GetWindowBounds(sixteeneighty, sixteeneighty, gfx::Rect(), gfx::Rect(), 277 GetWindowBounds(sixteeneighty, sixteeneighty, gfx::Rect(), gfx::Rect(),
263 false, DEFAULT, &window_bounds, &maximized); 278 false, gfx::Rect(), DEFAULT, &window_bounds, &maximized);
264 EXPECT_FALSE(maximized); 279 EXPECT_FALSE(maximized);
265 EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels, 280 EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels,
266 840 - kWindowTilePixels * 3, 281 840 - kWindowTilePixels * 3,
267 1050 - kWindowTilePixels * 2), 282 1050 - kWindowTilePixels * 2),
268 window_bounds); 283 window_bounds);
269 } 284 }
270 285
271 { // 16:10 monitor case, 1920x1200 286 { // 16:10 monitor case, 1920x1200
272 gfx::Rect window_bounds; 287 gfx::Rect window_bounds;
273 bool maximized; 288 bool maximized;
274 GetWindowBounds(nineteentwenty, nineteentwenty, gfx::Rect(), gfx::Rect(), 289 GetWindowBounds(nineteentwenty, nineteentwenty, gfx::Rect(), gfx::Rect(),
275 false, DEFAULT, &window_bounds, &maximized); 290 false, gfx::Rect(), DEFAULT, &window_bounds, &maximized);
276 EXPECT_FALSE(maximized); 291 EXPECT_FALSE(maximized);
277 EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels, 292 EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels,
278 960 - kWindowTilePixels * 3, 293 960 - kWindowTilePixels * 3,
279 1200 - kWindowTilePixels * 2), 294 1200 - kWindowTilePixels * 2),
280 window_bounds); 295 window_bounds);
281 } 296 }
282 } 297 }
283 298
284 // Test that the next opened window is positioned appropriately given the 299 // Test that the next opened window is positioned appropriately given the
285 // bounds of an existing window of the same type. 300 // bounds of an existing window of the same type.
286 TEST(WindowSizerTest, LastWindowBoundsCase) { 301 TEST(WindowSizerTest, LastWindowBoundsCase) {
287 { // normal, in the middle of the screen somewhere. 302 { // normal, in the middle of the screen somewhere.
288 gfx::Rect window_bounds; 303 gfx::Rect window_bounds;
289 bool maximized = false; 304 bool maximized = false;
290 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), 305 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
291 gfx::Rect(kWindowTilePixels, kWindowTilePixels, 500, 400), 306 gfx::Rect(kWindowTilePixels, kWindowTilePixels, 500, 400),
292 false, LAST_ACTIVE, 307 false, gfx::Rect(), LAST_ACTIVE,
293 &window_bounds, &maximized); 308 &window_bounds, &maximized);
294 EXPECT_FALSE(maximized); 309 EXPECT_FALSE(maximized);
295 EXPECT_EQ(gfx::Rect(kWindowTilePixels * 2, 310 EXPECT_EQ(gfx::Rect(kWindowTilePixels * 2,
296 kWindowTilePixels * 2, 500, 400), window_bounds); 311 kWindowTilePixels * 2, 500, 400), window_bounds);
297 } 312 }
298 313
299 { // taskbar on left. 314 { // taskbar on left.
300 gfx::Rect window_bounds; 315 gfx::Rect window_bounds;
301 bool maximized = false; 316 bool maximized = false;
302 GetWindowBounds(tentwentyfour, taskbar_left_work_area, gfx::Rect(), 317 GetWindowBounds(tentwentyfour, taskbar_left_work_area, gfx::Rect(),
303 gfx::Rect(kWindowTilePixels, kWindowTilePixels, 500, 400), 318 gfx::Rect(kWindowTilePixels, kWindowTilePixels, 500, 400),
304 false, LAST_ACTIVE, 319 false, gfx::Rect(), LAST_ACTIVE,
305 &window_bounds, &maximized); 320 &window_bounds, &maximized);
306 EXPECT_FALSE(maximized); 321 EXPECT_FALSE(maximized);
307 EXPECT_EQ(gfx::Rect(kWindowTilePixels * 2, 322 EXPECT_EQ(gfx::Rect(kWindowTilePixels * 2,
308 kWindowTilePixels * 2, 500, 400), window_bounds); 323 kWindowTilePixels * 2, 500, 400), window_bounds);
309 } 324 }
310 325
311 { // taskbar on top. 326 { // taskbar on top.
312 gfx::Rect window_bounds; 327 gfx::Rect window_bounds;
313 bool maximized = false; 328 bool maximized = false;
314 GetWindowBounds(tentwentyfour, taskbar_top_work_area, gfx::Rect(), 329 GetWindowBounds(tentwentyfour, taskbar_top_work_area, gfx::Rect(),
315 gfx::Rect(kWindowTilePixels, kWindowTilePixels, 500, 400), 330 gfx::Rect(kWindowTilePixels, kWindowTilePixels, 500, 400),
316 false, LAST_ACTIVE, 331 false, gfx::Rect(), LAST_ACTIVE,
317 &window_bounds, &maximized); 332 &window_bounds, &maximized);
318 EXPECT_FALSE(maximized); 333 EXPECT_FALSE(maximized);
319 EXPECT_EQ(gfx::Rect(kWindowTilePixels * 2, 334 EXPECT_EQ(gfx::Rect(kWindowTilePixels * 2,
320 kWindowTilePixels * 2, 335 std::max(kWindowTilePixels * 2,
336 34 /* toolbar height */),
321 500, 400), window_bounds); 337 500, 400), window_bounds);
322 } 338 }
323 339
324 { // too small to satisify the minimum visibility condition. 340 { // too small to satisify the minimum visibility condition.
325 gfx::Rect window_bounds; 341 gfx::Rect window_bounds;
326 bool maximized = false; 342 bool maximized = false;
327 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), 343 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
328 gfx::Rect(kWindowTilePixels, kWindowTilePixels, 29, 29), 344 gfx::Rect(kWindowTilePixels, kWindowTilePixels, 29, 29),
329 false, LAST_ACTIVE, 345 false, gfx::Rect(), LAST_ACTIVE,
330 &window_bounds, &maximized); 346 &window_bounds, &maximized);
331 EXPECT_FALSE(maximized); 347 EXPECT_FALSE(maximized);
332 EXPECT_EQ(gfx::Rect(kWindowTilePixels * 2, 348 EXPECT_EQ(gfx::Rect(kWindowTilePixels * 2,
333 kWindowTilePixels * 2, 30 /* not 29 */, 30 /* not 29 */) , 349 kWindowTilePixels * 2, 30 /* not 29 */, 30 /* not 29 */) ,
334 window_bounds); 350 window_bounds);
335 } 351 }
336 352
337 353
338 { // normal, but maximized 354 { // normal, but maximized
339 gfx::Rect window_bounds; 355 gfx::Rect window_bounds;
340 bool maximized = false; 356 bool maximized = false;
341 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), 357 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
342 gfx::Rect(kWindowTilePixels, kWindowTilePixels, 500, 400), 358 gfx::Rect(kWindowTilePixels, kWindowTilePixels, 500, 400),
343 true, LAST_ACTIVE, 359 true, gfx::Rect(), LAST_ACTIVE,
344 &window_bounds, &maximized); 360 &window_bounds, &maximized);
345 EXPECT_FALSE(maximized); 361 EXPECT_FALSE(maximized);
346 EXPECT_EQ(gfx::Rect(kWindowTilePixels * 2, 362 EXPECT_EQ(gfx::Rect(kWindowTilePixels * 2,
347 kWindowTilePixels * 2, 500, 400), window_bounds); 363 kWindowTilePixels * 2, 500, 400), window_bounds);
348 } 364 }
349 365
350 // Linux does not tile windows, so tile adjustment tests don't make sense. 366 // Linux does not tile windows, so tile adjustment tests don't make sense.
351 #if !defined(OS_LINUX) 367 #if !defined(OS_LINUX)
352 { // offset would put the new window offscreen at the bottom but the minimum 368 { // offset would put the new window offscreen at the bottom but the minimum
353 // visibility condition is barely satisfied without relocation. 369 // visibility condition is barely satisfied without relocation.
354 gfx::Rect window_bounds; 370 gfx::Rect window_bounds;
355 bool maximized = false; 371 bool maximized = false;
356 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), 372 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
357 gfx::Rect(10, 728, 500, 400), false, LAST_ACTIVE, 373 gfx::Rect(10, 728, 500, 400), false, gfx::Rect(),
358 &window_bounds, &maximized); 374 LAST_ACTIVE, &window_bounds, &maximized);
359 EXPECT_FALSE(maximized); 375 EXPECT_FALSE(maximized);
360 EXPECT_EQ(gfx::Rect(10 + kWindowTilePixels, 738, 376 EXPECT_EQ(gfx::Rect(10 + kWindowTilePixels, 738,
361 500, 400), window_bounds); 377 500, 400), window_bounds);
362 } 378 }
363 379
364 { // offset would put the new window offscreen at the bottom and the minimum 380 { // offset would put the new window offscreen at the bottom and the minimum
365 // visibility condition is satisified by relocation. 381 // visibility condition is satisified by relocation.
366 gfx::Rect window_bounds; 382 gfx::Rect window_bounds;
367 bool maximized = false; 383 bool maximized = false;
368 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), 384 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
369 gfx::Rect(10, 729, 500, 400), false, LAST_ACTIVE, 385 gfx::Rect(10, 729, 500, 400), false, gfx::Rect(),
370 &window_bounds, &maximized); 386 LAST_ACTIVE, &window_bounds, &maximized);
371 EXPECT_FALSE(maximized); 387 EXPECT_FALSE(maximized);
372 EXPECT_EQ(gfx::Rect(10 + kWindowTilePixels, 738 /* not 739 */, 500, 400), 388 EXPECT_EQ(gfx::Rect(10 + kWindowTilePixels, 738 /* not 739 */, 500, 400),
373 window_bounds); 389 window_bounds);
374 } 390 }
375 391
376 { // offset would put the new window offscreen at the right but the minimum 392 { // offset would put the new window offscreen at the right but the minimum
377 // visibility condition is barely satisfied without relocation. 393 // visibility condition is barely satisfied without relocation.
378 gfx::Rect window_bounds; 394 gfx::Rect window_bounds;
379 bool maximized = false; 395 bool maximized = false;
380 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), 396 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
381 gfx::Rect(984, 10, 500, 400), false, LAST_ACTIVE, 397 gfx::Rect(984, 10, 500, 400), false, gfx::Rect(),
382 &window_bounds, &maximized); 398 LAST_ACTIVE, &window_bounds, &maximized);
383 EXPECT_FALSE(maximized); 399 EXPECT_FALSE(maximized);
384 EXPECT_EQ(gfx::Rect(994, 10 + kWindowTilePixels, 500, 400), window_bounds); 400 EXPECT_EQ(gfx::Rect(994, 10 + kWindowTilePixels, 500, 400), window_bounds);
385 } 401 }
386 402
387 { // offset would put the new window offscreen at the right and the minimum 403 { // offset would put the new window offscreen at the right and the minimum
388 // visibility condition is satisified by relocation. 404 // visibility condition is satisified by relocation.
389 gfx::Rect window_bounds; 405 gfx::Rect window_bounds;
390 bool maximized = false; 406 bool maximized = false;
391 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), 407 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
392 gfx::Rect(985, 10, 500, 400), false, LAST_ACTIVE, 408 gfx::Rect(985, 10, 500, 400), false, gfx::Rect(),
393 &window_bounds, &maximized); 409 LAST_ACTIVE, &window_bounds, &maximized);
394 EXPECT_FALSE(maximized); 410 EXPECT_FALSE(maximized);
395 EXPECT_EQ(gfx::Rect(994 /* not 995 */, 10 + kWindowTilePixels, 411 EXPECT_EQ(gfx::Rect(994 /* not 995 */, 10 + kWindowTilePixels,
396 500, 400), window_bounds); 412 500, 400), window_bounds);
397 } 413 }
398 414
399 { // offset would put the new window offscreen at the bottom right and the 415 { // offset would put the new window offscreen at the bottom right and the
400 // minimum visibility condition is satisified by relocation. 416 // minimum visibility condition is satisified by relocation.
401 gfx::Rect window_bounds; 417 gfx::Rect window_bounds;
402 bool maximized = false; 418 bool maximized = false;
403 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), 419 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
404 gfx::Rect(985, 729, 500, 400), false, LAST_ACTIVE, 420 gfx::Rect(985, 729, 500, 400), false, gfx::Rect(),
405 &window_bounds, &maximized); 421 LAST_ACTIVE, &window_bounds, &maximized);
406 EXPECT_FALSE(maximized); 422 EXPECT_FALSE(maximized);
407 EXPECT_EQ(gfx::Rect(994 /* not 995 */, 738 /* not 739 */, 500, 400), 423 EXPECT_EQ(gfx::Rect(994 /* not 995 */, 738 /* not 739 */, 500, 400),
408 window_bounds); 424 window_bounds);
409 } 425 }
410 #endif // !defined(OS_LINUX) 426 #endif // !defined(OS_LINUX)
411 } 427 }
412 428
413 // Test that the window opened is sized appropriately given persisted sizes. 429 // Test that the window opened is sized appropriately given persisted sizes.
414 TEST(WindowSizerTest, PersistedBoundsCase) { 430 TEST(WindowSizerTest, PersistedBoundsCase) {
415 { // normal, in the middle of the screen somewhere. 431 { // normal, in the middle of the screen somewhere.
416 gfx::Rect initial_bounds(kWindowTilePixels, kWindowTilePixels, 500, 400); 432 gfx::Rect initial_bounds(kWindowTilePixels, kWindowTilePixels, 500, 400);
417 433
418 gfx::Rect window_bounds; 434 gfx::Rect window_bounds;
419 bool maximized; 435 bool maximized;
420 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), initial_bounds, 436 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), initial_bounds,
421 false, PERSISTED, &window_bounds, &maximized); 437 false, gfx::Rect(), PERSISTED, &window_bounds, &maximized);
422 EXPECT_FALSE(maximized); 438 EXPECT_FALSE(maximized);
423 EXPECT_EQ(initial_bounds, window_bounds); 439 EXPECT_EQ(initial_bounds, window_bounds);
424 } 440 }
425 441
426 { // normal, maximized. 442 { // normal, maximized.
427 gfx::Rect initial_bounds(0, 0, 1024, 768); 443 gfx::Rect initial_bounds(0, 0, 1024, 768);
428 444
429 gfx::Rect window_bounds; 445 gfx::Rect window_bounds;
430 bool maximized; 446 bool maximized;
431 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), initial_bounds, 447 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), initial_bounds,
432 true, PERSISTED, &window_bounds, &maximized); 448 true, gfx::Rect(), PERSISTED, &window_bounds, &maximized);
433 EXPECT_TRUE(maximized); 449 EXPECT_TRUE(maximized);
434 EXPECT_EQ(initial_bounds, window_bounds); 450 EXPECT_EQ(initial_bounds, window_bounds);
435 } 451 }
436 452
437 { // normal, on non-primary monitor in negative coords. 453 { // normal, on non-primary monitor in negative coords.
438 gfx::Rect initial_bounds(-600, 10, 500, 400); 454 gfx::Rect initial_bounds(-600, 10, 500, 400);
439 455
440 gfx::Rect window_bounds; 456 gfx::Rect window_bounds;
441 bool maximized; 457 bool maximized;
442 GetWindowBounds(tentwentyfour, tentwentyfour, left_nonprimary, 458 GetWindowBounds(tentwentyfour, tentwentyfour, left_nonprimary,
443 initial_bounds, false, PERSISTED, &window_bounds, 459 initial_bounds, false, gfx::Rect(), PERSISTED,
444 &maximized); 460 &window_bounds, &maximized);
445 EXPECT_FALSE(maximized); 461 EXPECT_FALSE(maximized);
446 EXPECT_EQ(initial_bounds, window_bounds); 462 EXPECT_EQ(initial_bounds, window_bounds);
447 } 463 }
448 464
449 { // normal, on non-primary monitor in negative coords, maximized. 465 { // normal, on non-primary monitor in negative coords, maximized.
450 gfx::Rect initial_bounds(-1024, 0, 1024, 768); 466 gfx::Rect initial_bounds(-1024, 0, 1024, 768);
451 467
452 gfx::Rect window_bounds; 468 gfx::Rect window_bounds;
453 bool maximized; 469 bool maximized;
454 GetWindowBounds(tentwentyfour, tentwentyfour, left_nonprimary, 470 GetWindowBounds(tentwentyfour, tentwentyfour, left_nonprimary,
455 initial_bounds, true, PERSISTED, &window_bounds, 471 initial_bounds, true, gfx::Rect(), PERSISTED,
456 &maximized); 472 &window_bounds, &maximized);
457 EXPECT_TRUE(maximized); 473 EXPECT_TRUE(maximized);
458 EXPECT_EQ(initial_bounds, window_bounds); 474 EXPECT_EQ(initial_bounds, window_bounds);
459 } 475 }
460 476
461 { // off the left but the minimum visibility condition is barely satisfied 477 { // off the left but the minimum visibility condition is barely satisfied
462 // without relocaiton. 478 // without relocaiton.
463 gfx::Rect initial_bounds(-470, 50, 500, 400); 479 gfx::Rect initial_bounds(-470, 50, 500, 400);
464 480
465 gfx::Rect window_bounds; 481 gfx::Rect window_bounds;
466 bool maximized; 482 bool maximized;
467 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), 483 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
468 initial_bounds, false, PERSISTED, 484 initial_bounds, false, gfx::Rect(), PERSISTED,
469 &window_bounds, &maximized); 485 &window_bounds, &maximized);
470 EXPECT_FALSE(maximized); 486 EXPECT_FALSE(maximized);
471 EXPECT_EQ(initial_bounds, window_bounds); 487 EXPECT_EQ(initial_bounds, window_bounds);
472 } 488 }
473 489
474 { // off the left and the minimum visibility condition is satisfied by 490 { // off the left and the minimum visibility condition is satisfied by
475 // relocation. 491 // relocation.
476 gfx::Rect window_bounds; 492 gfx::Rect window_bounds;
477 bool maximized; 493 bool maximized;
478 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), 494 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
479 gfx::Rect(-471, 50, 500, 400), false, PERSISTED, 495 gfx::Rect(-471, 50, 500, 400), false, gfx::Rect(),
480 &window_bounds, &maximized); 496 PERSISTED, &window_bounds, &maximized);
481 EXPECT_FALSE(maximized); 497 EXPECT_FALSE(maximized);
482 EXPECT_EQ(gfx::Rect(-470 /* not -471 */, 50, 500, 400), window_bounds); 498 EXPECT_EQ(gfx::Rect(-470 /* not -471 */, 50, 500, 400), window_bounds);
483 } 499 }
484 500
485 { // off the top but the minimum visibility condition is barely satisified 501 { // off the top
486 // without relocation.
487 gfx::Rect initial_bounds(50, -370, 500, 400); 502 gfx::Rect initial_bounds(50, -370, 500, 400);
488 503
489 gfx::Rect window_bounds; 504 gfx::Rect window_bounds;
490 bool maximized; 505 bool maximized;
491 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), 506 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
492 initial_bounds, false, PERSISTED, 507 gfx::Rect(50, -370, 500, 400), false, gfx::Rect(),
493 &window_bounds, &maximized); 508 PERSISTED, &window_bounds, &maximized);
494 EXPECT_FALSE(maximized); 509 EXPECT_FALSE(maximized);
495 EXPECT_EQ(initial_bounds, window_bounds); 510 EXPECT_EQ(gfx::Rect(50, 0, 500, 400), window_bounds);
496 }
497
498 { // off the top and the minimum visibility condition is satisified by
499 // relocation.
500 gfx::Rect window_bounds;
501 bool maximized;
502 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
503 gfx::Rect(50, -371, 500, 400), false, PERSISTED,
504 &window_bounds, &maximized);
505 EXPECT_FALSE(maximized);
506 EXPECT_EQ(gfx::Rect(50, -370 /* not -371 */, 500, 400), window_bounds);
507 } 511 }
508 512
509 { // off the right but the minimum visibility condition is barely satisified 513 { // off the right but the minimum visibility condition is barely satisified
510 // without relocation. 514 // without relocation.
511 gfx::Rect initial_bounds(994, 50, 500, 400); 515 gfx::Rect initial_bounds(994, 50, 500, 400);
512 516
513 gfx::Rect window_bounds; 517 gfx::Rect window_bounds;
514 bool maximized; 518 bool maximized;
515 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), 519 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
516 initial_bounds, false, PERSISTED, 520 initial_bounds, false, gfx::Rect(), PERSISTED,
517 &window_bounds, &maximized); 521 &window_bounds, &maximized);
518 EXPECT_FALSE(maximized); 522 EXPECT_FALSE(maximized);
519 EXPECT_EQ(initial_bounds, window_bounds); 523 EXPECT_EQ(initial_bounds, window_bounds);
520 } 524 }
521 525
522 { // off the right and the minimum visibility condition is satisified by 526 { // off the right and the minimum visibility condition is satisified by
523 // relocation. 527 // relocation.
524 gfx::Rect window_bounds; 528 gfx::Rect window_bounds;
525 bool maximized; 529 bool maximized;
526 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), 530 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
527 gfx::Rect(995, 50, 500, 400), false, PERSISTED, 531 gfx::Rect(995, 50, 500, 400), false, gfx::Rect(),
528 &window_bounds, &maximized); 532 PERSISTED, &window_bounds, &maximized);
529 EXPECT_FALSE(maximized); 533 EXPECT_FALSE(maximized);
530 EXPECT_EQ(gfx::Rect(994 /* not 995 */, 50, 500, 400), window_bounds); 534 EXPECT_EQ(gfx::Rect(994 /* not 995 */, 50, 500, 400), window_bounds);
531 } 535 }
532 536
533 { // off the bottom but the minimum visibility condition is barely satisified 537 { // off the bottom but the minimum visibility condition is barely satisified
534 // without relocation. 538 // without relocation.
535 gfx::Rect initial_bounds(50, 738, 500, 400); 539 gfx::Rect initial_bounds(50, 738, 500, 400);
536 540
537 gfx::Rect window_bounds; 541 gfx::Rect window_bounds;
538 bool maximized; 542 bool maximized;
539 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), 543 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
540 initial_bounds, false, PERSISTED, 544 initial_bounds, false, gfx::Rect(), PERSISTED,
541 &window_bounds, &maximized); 545 &window_bounds, &maximized);
542 EXPECT_FALSE(maximized); 546 EXPECT_FALSE(maximized);
543 EXPECT_EQ(initial_bounds, window_bounds); 547 EXPECT_EQ(initial_bounds, window_bounds);
544 } 548 }
545 549
546 { // off the bottom and the minimum visibility condition is satisified by 550 { // off the bottom and the minimum visibility condition is satisified by
547 // relocation. 551 // relocation.
548 gfx::Rect window_bounds; 552 gfx::Rect window_bounds;
549 bool maximized; 553 bool maximized;
550 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), 554 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
551 gfx::Rect(50, 739, 500, 400), false, PERSISTED, 555 gfx::Rect(50, 739, 500, 400), false, gfx::Rect(), PERSISTED,
552 &window_bounds, &maximized); 556 &window_bounds, &maximized);
553 EXPECT_FALSE(maximized); 557 EXPECT_FALSE(maximized);
554 EXPECT_EQ(gfx::Rect(50, 738 /* not 739 */, 500, 400), window_bounds); 558 EXPECT_EQ(gfx::Rect(50, 738 /* not 739 */, 500, 400), window_bounds);
555 } 559 }
556 560
557 { // off the topleft and the minimum visibility condition is satisified by 561 { // off the topleft
558 // relocation.
559 gfx::Rect window_bounds; 562 gfx::Rect window_bounds;
560 bool maximized; 563 bool maximized;
561 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), 564 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
562 gfx::Rect(-471, -371, 500, 400), false, PERSISTED, 565 gfx::Rect(-471, -371, 500, 400), false, gfx::Rect(),
563 &window_bounds, &maximized); 566 PERSISTED, &window_bounds, &maximized);
564 EXPECT_FALSE(maximized); 567 EXPECT_FALSE(maximized);
565 EXPECT_EQ(gfx::Rect(-470 /* not -471 */, -370 /* not -371 */, 500, 400), 568 EXPECT_EQ(gfx::Rect(-470 /* not -471 */, 0, 500, 400),
566 window_bounds); 569 window_bounds);
567 } 570 }
568 571
569 { // off the topright and the minimum visibility condition is satisified by 572 { // off the topright and the minimum visibility condition is satisified by
570 // relocation. 573 // relocation.
571 gfx::Rect window_bounds; 574 gfx::Rect window_bounds;
572 bool maximized; 575 bool maximized;
573 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), 576 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
574 gfx::Rect(995, -371, 500, 400), false, PERSISTED, 577 gfx::Rect(995, -371, 500, 400), false, gfx::Rect(),
575 &window_bounds, &maximized); 578 PERSISTED, &window_bounds, &maximized);
576 EXPECT_FALSE(maximized); 579 EXPECT_FALSE(maximized);
577 EXPECT_EQ(gfx::Rect(994 /* not 995 */, -370 /* not -371 */, 500, 400), 580 EXPECT_EQ(gfx::Rect(994 /* not 995 */, 0, 500, 400),
578 window_bounds); 581 window_bounds);
579 } 582 }
580 583
581 { // off the bottomleft and the minimum visibility condition is satisified by 584 { // off the bottomleft and the minimum visibility condition is satisified by
582 // relocation. 585 // relocation.
583 gfx::Rect window_bounds; 586 gfx::Rect window_bounds;
584 bool maximized; 587 bool maximized;
585 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), 588 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
586 gfx::Rect(-471, 739, 500, 400), false, PERSISTED, 589 gfx::Rect(-471, 739, 500, 400), false, gfx::Rect(),
587 &window_bounds, &maximized); 590 PERSISTED, &window_bounds, &maximized);
588 EXPECT_FALSE(maximized); 591 EXPECT_FALSE(maximized);
589 EXPECT_EQ(gfx::Rect(-470 /* not -471 */, 738 /* not 739 */, 500, 400), 592 EXPECT_EQ(gfx::Rect(-470 /* not -471 */, 738 /* not 739 */, 500, 400),
590 window_bounds); 593 window_bounds);
591 } 594 }
592 595
593 { // off the bottomright and the minimum visibility condition is satisified by 596 { // off the bottomright and the minimum visibility condition is satisified by
594 // relocation. 597 // relocation.
595 gfx::Rect window_bounds; 598 gfx::Rect window_bounds;
596 bool maximized; 599 bool maximized;
597 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), 600 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
598 gfx::Rect(995, 739, 500, 400), false, PERSISTED, 601 gfx::Rect(995, 739, 500, 400), false, gfx::Rect(),
599 &window_bounds, &maximized); 602 PERSISTED, &window_bounds, &maximized);
600 EXPECT_FALSE(maximized); 603 EXPECT_FALSE(maximized);
601 EXPECT_EQ(gfx::Rect(994 /* not 995 */, 738 /* not 739 */, 500, 400), 604 EXPECT_EQ(gfx::Rect(994 /* not 995 */, 738 /* not 739 */, 500, 400),
602 window_bounds); 605 window_bounds);
603 } 606 }
604 607
608 { // entirely off left
609 gfx::Rect window_bounds;
610 bool maximized;
611 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
612 gfx::Rect(-700, 50, 500, 400), false, gfx::Rect(),
613 PERSISTED, &window_bounds, &maximized);
614 EXPECT_FALSE(maximized);
615 EXPECT_EQ(gfx::Rect(-470 /* not -700 */, 50, 500, 400), window_bounds);
616 }
617
605 { // entirely off left (monitor was detached since last run) 618 { // entirely off left (monitor was detached since last run)
606 gfx::Rect window_bounds; 619 gfx::Rect window_bounds;
607 bool maximized; 620 bool maximized;
608 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), 621 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
609 gfx::Rect(-700, 50, 500, 400), false, PERSISTED, 622 gfx::Rect(-700, 50, 500, 400), false, left_nonprimary,
610 &window_bounds, &maximized); 623 PERSISTED, &window_bounds, &maximized);
611 EXPECT_FALSE(maximized); 624 EXPECT_FALSE(maximized);
612 EXPECT_EQ(gfx::Rect(-470 /* not -700 */, 50, 500, 400), window_bounds); 625 EXPECT_EQ(gfx::Rect(0, 50, 500, 400), window_bounds);
626 }
627
628 { // entirely off top
629 gfx::Rect window_bounds;
630 bool maximized;
631 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
632 gfx::Rect(50, -500, 500, 400), false, gfx::Rect(),
633 PERSISTED, &window_bounds, &maximized);
634 EXPECT_FALSE(maximized);
635 EXPECT_EQ(gfx::Rect(50, 0, 500, 400), window_bounds);
613 } 636 }
614 637
615 { // entirely off top (monitor was detached since last run) 638 { // entirely off top (monitor was detached since last run)
616 gfx::Rect window_bounds; 639 gfx::Rect window_bounds;
617 bool maximized; 640 bool maximized;
618 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), 641 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
619 gfx::Rect(50, -500, 500, 400), false, PERSISTED, 642 gfx::Rect(50, -500, 500, 400), false, top_nonprimary,
620 &window_bounds, &maximized); 643 PERSISTED, &window_bounds, &maximized);
621 EXPECT_FALSE(maximized); 644 EXPECT_FALSE(maximized);
622 EXPECT_EQ(gfx::Rect(50, -370 /* not -500 */, 500, 400), window_bounds); 645 EXPECT_EQ(gfx::Rect(50, 0, 500, 400), window_bounds);
646 }
647
648 { // entirely off right
649 gfx::Rect window_bounds;
650 bool maximized;
651 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
652 gfx::Rect(1200, 50, 500, 400), false, gfx::Rect(),
653 PERSISTED, &window_bounds, &maximized);
654 EXPECT_FALSE(maximized);
655 EXPECT_EQ(gfx::Rect(994 /* not 1200 */, 50, 500, 400), window_bounds);
623 } 656 }
624 657
625 { // entirely off right (monitor was detached since last run) 658 { // entirely off right (monitor was detached since last run)
626 gfx::Rect window_bounds; 659 gfx::Rect window_bounds;
627 bool maximized; 660 bool maximized;
628 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), 661 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
629 gfx::Rect(1200, 50, 500, 400), false, PERSISTED, 662 gfx::Rect(1200, 50, 500, 400), false, right_nonprimary,
663 PERSISTED, &window_bounds, &maximized);
664 EXPECT_FALSE(maximized);
665 EXPECT_EQ(gfx::Rect(524, 50, 500, 400), window_bounds);
666 }
667
668 { // entirely off bottom
669 gfx::Rect window_bounds;
670 bool maximized;
671 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
672 gfx::Rect(50, 800, 500, 400), false, gfx::Rect(), PERSISTED,
630 &window_bounds, &maximized); 673 &window_bounds, &maximized);
631 EXPECT_FALSE(maximized); 674 EXPECT_FALSE(maximized);
632 EXPECT_EQ(gfx::Rect(994 /* not 1200 */, 50, 500, 400), window_bounds); 675 EXPECT_EQ(gfx::Rect(50, 738 /* not 800 */, 500, 400), window_bounds);
633 } 676 }
634 677
635 { // entirely off bottom (monitor was detached since last run) 678 { // entirely off bottom (monitor was detached since last run)
636 gfx::Rect window_bounds; 679 gfx::Rect window_bounds;
637 bool maximized; 680 bool maximized;
638 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), 681 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
639 gfx::Rect(50, 800, 500, 400), false, PERSISTED, 682 gfx::Rect(50, 800, 500, 400), false, bottom_nonprimary,
640 &window_bounds, &maximized); 683 PERSISTED, &window_bounds, &maximized);
641 EXPECT_FALSE(maximized); 684 EXPECT_FALSE(maximized);
642 EXPECT_EQ(gfx::Rect(50, 738 /* not 800 */, 500, 400), window_bounds); 685 EXPECT_EQ(gfx::Rect(50, 368, 500, 400), window_bounds);
686 }
687
688 { // Non-primary monitor resoultion has changed, but the monitor still
689 // completely contains the window.
690
691 gfx::Rect initial_bounds(1074, 50, 600, 500);
692
693 gfx::Rect window_bounds;
694 bool maximized;
695 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(1024, 0, 800, 600),
696 initial_bounds, false, right_nonprimary,
697 PERSISTED, &window_bounds, &maximized);
698 EXPECT_FALSE(maximized);
699 EXPECT_EQ(initial_bounds, window_bounds);
700 }
701
702 { // Non-primary monitor resoultion has changed, and the window is partially
703 // off-screen.
704
705 gfx::Rect initial_bounds(1274, 50, 600, 500);
706
707 gfx::Rect window_bounds;
708 bool maximized;
709 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(1024, 0, 800, 600),
710 initial_bounds, false, right_nonprimary,
711 PERSISTED, &window_bounds, &maximized);
712 EXPECT_FALSE(maximized);
713 EXPECT_EQ(gfx::Rect(1224, 50, 600, 500), window_bounds);
714 }
715
716 { // Non-primary monitor resoultion has changed, and the window is now too
717 // large for the monitor.
718
719 gfx::Rect initial_bounds(1274, 50, 900, 700);
720
721 gfx::Rect window_bounds;
722 bool maximized;
723 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(1024, 0, 800, 600),
724 initial_bounds, false, right_nonprimary,
725 PERSISTED, &window_bounds, &maximized);
726 EXPECT_FALSE(maximized);
727 EXPECT_EQ(gfx::Rect(1024, 0, 800, 600), window_bounds);
643 } 728 }
644 729
645 { // width and height too small 730 { // width and height too small
646 gfx::Rect window_bounds; 731 gfx::Rect window_bounds;
647 bool maximized; 732 bool maximized;
648 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), 733 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
649 gfx::Rect(kWindowTilePixels, kWindowTilePixels, 29, 29), 734 gfx::Rect(kWindowTilePixels, kWindowTilePixels, 29, 29),
650 false, PERSISTED, 735 false, gfx::Rect(), PERSISTED,
651 &window_bounds, &maximized); 736 &window_bounds, &maximized);
652 EXPECT_FALSE(maximized); 737 EXPECT_FALSE(maximized);
653 EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels, 738 EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels,
654 30 /* not 29 */, 30 /* not 29 */), 739 30 /* not 29 */, 30 /* not 29 */),
655 window_bounds); 740 window_bounds);
656 } 741 }
657 742
658 #if defined(OS_MACOSX) 743 #if defined(OS_MACOSX)
659 { // Saved state is too tall to possibly be resized. Mac resizers 744 { // Saved state is too tall to possibly be resized. Mac resizers
660 // are at the bottom of the window, and no piece of a window can 745 // are at the bottom of the window, and no piece of a window can
661 // be moved higher than the menubar. (Perhaps the user changed 746 // be moved higher than the menubar. (Perhaps the user changed
662 // resolution to something smaller before relaunching Chrome?) 747 // resolution to something smaller before relaunching Chrome?)
663 gfx::Rect window_bounds; 748 gfx::Rect window_bounds;
664 bool maximized; 749 bool maximized;
665 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), 750 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
666 gfx::Rect(kWindowTilePixels, kWindowTilePixels, 30, 5000), 751 gfx::Rect(kWindowTilePixels, kWindowTilePixels, 30, 5000),
667 false, PERSISTED, 752 false, gfx::Rect(), PERSISTED,
668 &window_bounds, &maximized); 753 &window_bounds, &maximized);
669 EXPECT_FALSE(maximized); 754 EXPECT_FALSE(maximized);
670 EXPECT_EQ(tentwentyfour.height(), window_bounds.height()); 755 EXPECT_EQ(tentwentyfour.height(), window_bounds.height());
671 } 756 }
672 #endif // defined(OS_MACOSX) 757 #endif // defined(OS_MACOSX)
673 } 758 }
OLDNEW
« no previous file with comments | « chrome/browser/window_sizer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698