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

Side by Side Diff: chrome/browser/ui/views/ash/window_positioner_unittest.cc

Issue 9969164: Ignoring alignment when it pushes a window out of the screen (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Moving align to grid functionality into WindowPositioner / WindowSizer Created 8 years, 8 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
OLDNEW
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/views/ash/window_positioner.h" 5 #include "chrome/browser/ui/views/ash/window_positioner.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/shell_window_ids.h" 8 #include "ash/shell_window_ids.h"
9 #include "ash/test/ash_test_base.h" 9 #include "ash/test/ash_test_base.h"
10 #include "ash/test/test_shell_delegate.h" 10 #include "ash/test/test_shell_delegate.h"
(...skipping 10 matching lines...) Expand all
21 #include "ui/aura/env.h" 21 #include "ui/aura/env.h"
22 #include "ui/aura/root_window.h" 22 #include "ui/aura/root_window.h"
23 #include "ui/aura/test/test_windows.h" 23 #include "ui/aura/test/test_windows.h"
24 #include "ui/gfx/screen.h" 24 #include "ui/gfx/screen.h"
25 25
26 namespace ash { 26 namespace ash {
27 namespace test { 27 namespace test {
28 28
29 namespace { 29 namespace {
30 30
31 // A function which aligns a size to a step within the grid.
32 int align(int size, int alignment_factor) {
33 if (alignment_factor > 1) {
34 return size - size % alignment_factor;
35 }
36 return size;
37 }
38
31 // A browser window proxy which is able to associate an aura native window with 39 // A browser window proxy which is able to associate an aura native window with
32 // it. 40 // it.
33 class TestBrowserWindowAura : public TestBrowserWindow { 41 class TestBrowserWindowAura : public TestBrowserWindow {
34 public: 42 public:
35 TestBrowserWindowAura(Browser* browser, aura::Window *native_window); 43 TestBrowserWindowAura(Browser* browser, aura::Window *native_window);
36 virtual ~TestBrowserWindowAura(); 44 virtual ~TestBrowserWindowAura();
37 45
38 virtual gfx::NativeWindow GetNativeHandle() OVERRIDE { 46 virtual gfx::NativeWindow GetNativeHandle() OVERRIDE {
39 return native_window_; 47 return native_window_;
40 } 48 }
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 gfx::Rect cascade_5 = 252 gfx::Rect cascade_5 =
245 window_positioner()->GetPopupPosition(popup_position_5); 253 window_positioner()->GetPopupPosition(popup_position_5);
246 EXPECT_EQ(gfx::Rect(work_area.x() + grid_size_, 254 EXPECT_EQ(gfx::Rect(work_area.x() + grid_size_,
247 work_area.y() + grid_size_, 255 work_area.y() + grid_size_,
248 popup_position_5.width(), popup_position_5.height()), 256 popup_position_5.width(), popup_position_5.height()),
249 cascade_5); 257 cascade_5);
250 } 258 }
251 259
252 TEST_F(WindowPositionerTest, filling) { 260 TEST_F(WindowPositionerTest, filling) {
253 const gfx::Rect work_area = gfx::Screen::GetPrimaryMonitorWorkArea(); 261 const gfx::Rect work_area = gfx::Screen::GetPrimaryMonitorWorkArea();
254 262 int grid = ash::Shell::GetInstance()->GetGridSize();
255 gfx::Rect popup_position(0, 0, 256, 128); 263 gfx::Rect popup_position(0, 0, 256, 128);
256 // Leave space on the left and the right and see if we fill top to bottom. 264 // Leave space on the left and the right and see if we fill top to bottom.
257 window()->SetBounds(gfx::Rect(work_area.x() + popup_position.width(), 265 window()->SetBounds(gfx::Rect(work_area.x() + popup_position.width(),
258 work_area.y(), 266 work_area.y(),
259 work_area.width() - 2 * popup_position.width(), 267 work_area.width() - 2 * popup_position.width(),
260 work_area.height())); 268 work_area.height()));
261 window()->Show(); 269 window()->Show();
262 // Check that we are positioned in the top left corner. 270 // Check that we are positioned in the top left corner.
263 gfx::Rect top_left = window_positioner()->GetPopupPosition(popup_position); 271 gfx::Rect top_left = window_positioner()->GetPopupPosition(popup_position);
264 EXPECT_EQ(gfx::Rect(work_area.x(), work_area.y(), 272 EXPECT_EQ(gfx::Rect(work_area.x(), work_area.y(),
265 popup_position.width(), popup_position.height()), 273 popup_position.width(), popup_position.height()),
266 top_left); 274 top_left);
267 275
268 // Now block the found location. 276 // Now block the found location.
269 popup()->SetBounds(top_left); 277 popup()->SetBounds(top_left);
270 popup()->Show(); 278 popup()->Show();
271 gfx::Rect mid_left = window_positioner()->GetPopupPosition(popup_position); 279 gfx::Rect mid_left = window_positioner()->GetPopupPosition(popup_position);
272 EXPECT_EQ(gfx::Rect(work_area.x(), 280 EXPECT_EQ(gfx::Rect(work_area.x(),
273 work_area.y() + top_left.height(), 281 work_area.y() + top_left.height(),
274 popup_position.width(), popup_position.height()), 282 popup_position.width(), popup_position.height()),
275 mid_left); 283 mid_left);
276 284
277 // Block now everything so that we can only put the popup on the bottom 285 // Block now everything so that we can only put the popup on the bottom
278 // of the left side. 286 // of the left side.
287 // Note: We need to keep one "grid spacing free" if the window does not
288 // fit into the grid (which is true for 200 height).`
279 popup()->SetBounds(gfx::Rect(work_area.x(), work_area.y(), 289 popup()->SetBounds(gfx::Rect(work_area.x(), work_area.y(),
280 popup_position.width(), 290 popup_position.width(),
281 work_area.height() - popup_position.height())); 291 work_area.height() - popup_position.height() -
292 grid + 1));
282 gfx::Rect bottom_left = window_positioner()->GetPopupPosition( 293 gfx::Rect bottom_left = window_positioner()->GetPopupPosition(
283 popup_position); 294 popup_position);
284 EXPECT_EQ(gfx::Rect(work_area.x(), 295 EXPECT_EQ(gfx::Rect(work_area.x(),
285 work_area.y() + work_area.height() - 296 work_area.bottom() - popup_position.height(),
286 popup_position.height(),
287 popup_position.width(), popup_position.height()), 297 popup_position.width(), popup_position.height()),
288 bottom_left); 298 bottom_left);
289 299
290 // Block now enough to force the right side. 300 // Block now enough to force the right side.
291 popup()->SetBounds(gfx::Rect(work_area.x(), work_area.y(), 301 popup()->SetBounds(gfx::Rect(work_area.x(), work_area.y(),
292 popup_position.width(), 302 popup_position.width(),
293 work_area.height() - popup_position.height() + 303 work_area.height() - popup_position.height() +
294 1)); 304 1));
295 gfx::Rect top_right = window_positioner()->GetPopupPosition( 305 gfx::Rect top_right = window_positioner()->GetPopupPosition(
296 popup_position); 306 popup_position);
297 EXPECT_EQ(gfx::Rect(work_area.x() + work_area.width() - 307 EXPECT_EQ(gfx::Rect(align(work_area.right() -
298 popup_position.width(), 308 popup_position.width(), grid),
299 work_area.y(), 309 work_area.y(),
300 popup_position.width(), popup_position.height()), 310 popup_position.width(), popup_position.height()),
301 top_right); 311 top_right);
302 } 312 }
303 313
304 TEST_F(WindowPositionerTest, blockedByPanel) { 314 TEST_F(WindowPositionerTest, blockedByPanel) {
305 const gfx::Rect work_area = gfx::Screen::GetPrimaryMonitorWorkArea(); 315 const gfx::Rect work_area = gfx::Screen::GetPrimaryMonitorWorkArea();
306 316
307 gfx::Rect pop_position(0, 0, 200, 200); 317 gfx::Rect pop_position(0, 0, 200, 200);
308 // Let the panel cover everything. 318 // Let the panel cover everything.
(...skipping 14 matching lines...) Expand all
323 333
324 // Check that the popup is placed full screen. 334 // Check that the popup is placed full screen.
325 gfx::Rect full = window_positioner()->GetPopupPosition(pop_position); 335 gfx::Rect full = window_positioner()->GetPopupPosition(pop_position);
326 EXPECT_EQ(gfx::Rect(work_area.x(), work_area.y(), 336 EXPECT_EQ(gfx::Rect(work_area.x(), work_area.y(),
327 pop_position.width(), pop_position.height()), 337 pop_position.width(), pop_position.height()),
328 full); 338 full);
329 } 339 }
330 340
331 } // namespace test 341 } // namespace test
332 } // namespace ash 342 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698