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

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: Not my code anymore 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
« no previous file with comments | « chrome/browser/ui/views/ash/window_positioner.cc ('k') | chrome/browser/ui/window_sizer_ash.cc » ('j') | 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) 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"
11 #include "ash/wm/window_resizer.h"
11 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
14 #include "chrome/test/base/testing_profile.h" 15 #include "chrome/test/base/testing_profile.h"
15 #include "chrome/test/base/test_browser_window.h" 16 #include "chrome/test/base/test_browser_window.h"
16 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
17 #include "content/test/render_view_test.h" 18 #include "content/test/render_view_test.h"
18 #include "content/test/test_browser_thread.h" 19 #include "content/test/test_browser_thread.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 : window_positioner_(NULL) { 106 : window_positioner_(NULL) {
106 // Create a message loop. 107 // Create a message loop.
107 MessageLoopForUI* ui_loop = message_loop(); 108 MessageLoopForUI* ui_loop = message_loop();
108 ui_thread_.reset( 109 ui_thread_.reset(
109 new content::TestBrowserThread(content::BrowserThread::UI, ui_loop)); 110 new content::TestBrowserThread(content::BrowserThread::UI, ui_loop));
110 111
111 // Create a browser profile. 112 // Create a browser profile.
112 profile_.reset(new TestingProfile()); 113 profile_.reset(new TestingProfile());
113 } 114 }
114 115
115 WindowPositionerTest::~WindowPositionerTest() {} 116 WindowPositionerTest::~WindowPositionerTest() {
117 profile_.reset(NULL);
118 ui_thread_.reset(NULL);
119 }
116 120
117 void WindowPositionerTest::SetUp() { 121 void WindowPositionerTest::SetUp() {
118 AshTestBase::SetUp(); 122 AshTestBase::SetUp();
119 // Create some default dummy windows. 123 // Create some default dummy windows.
120 aura::Window* default_container = 124 aura::Window* default_container =
121 ash::Shell::GetInstance()->GetContainer( 125 ash::Shell::GetInstance()->GetContainer(
122 ash::internal::kShellWindowId_DefaultContainer); 126 ash::internal::kShellWindowId_DefaultContainer);
123 window_.reset(aura::test::CreateTestWindowWithId(0, default_container)); 127 window_.reset(aura::test::CreateTestWindowWithId(0, default_container));
124 window_->SetBounds(gfx::Rect(16, 32, 640, 320)); 128 window_->SetBounds(gfx::Rect(16, 32, 640, 320));
125 popup_.reset(aura::test::CreateTestWindowWithId(1, default_container)); 129 popup_.reset(aura::test::CreateTestWindowWithId(1, default_container));
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 gfx::Rect cascade_5 = 248 gfx::Rect cascade_5 =
245 window_positioner()->GetPopupPosition(popup_position_5); 249 window_positioner()->GetPopupPosition(popup_position_5);
246 EXPECT_EQ(gfx::Rect(work_area.x() + grid_size_, 250 EXPECT_EQ(gfx::Rect(work_area.x() + grid_size_,
247 work_area.y() + grid_size_, 251 work_area.y() + grid_size_,
248 popup_position_5.width(), popup_position_5.height()), 252 popup_position_5.width(), popup_position_5.height()),
249 cascade_5); 253 cascade_5);
250 } 254 }
251 255
252 TEST_F(WindowPositionerTest, filling) { 256 TEST_F(WindowPositionerTest, filling) {
253 const gfx::Rect work_area = gfx::Screen::GetPrimaryMonitorWorkArea(); 257 const gfx::Rect work_area = gfx::Screen::GetPrimaryMonitorWorkArea();
254 258 int grid = ash::Shell::GetInstance()->GetGridSize();
255 gfx::Rect popup_position(0, 0, 256, 128); 259 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. 260 // 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(), 261 window()->SetBounds(gfx::Rect(work_area.x() + popup_position.width(),
258 work_area.y(), 262 work_area.y(),
259 work_area.width() - 2 * popup_position.width(), 263 work_area.width() - 2 * popup_position.width(),
260 work_area.height())); 264 work_area.height()));
261 window()->Show(); 265 window()->Show();
262 // Check that we are positioned in the top left corner. 266 // Check that we are positioned in the top left corner.
263 gfx::Rect top_left = window_positioner()->GetPopupPosition(popup_position); 267 gfx::Rect top_left = window_positioner()->GetPopupPosition(popup_position);
264 EXPECT_EQ(gfx::Rect(work_area.x(), work_area.y(), 268 EXPECT_EQ(gfx::Rect(work_area.x(), work_area.y(),
265 popup_position.width(), popup_position.height()), 269 popup_position.width(), popup_position.height()),
266 top_left); 270 top_left);
267 271
268 // Now block the found location. 272 // Now block the found location.
269 popup()->SetBounds(top_left); 273 popup()->SetBounds(top_left);
270 popup()->Show(); 274 popup()->Show();
271 gfx::Rect mid_left = window_positioner()->GetPopupPosition(popup_position); 275 gfx::Rect mid_left = window_positioner()->GetPopupPosition(popup_position);
272 EXPECT_EQ(gfx::Rect(work_area.x(), 276 EXPECT_EQ(gfx::Rect(work_area.x(),
273 work_area.y() + top_left.height(), 277 ash::WindowResizer::AlignToGridRoundDown(
274 popup_position.width(), popup_position.height()), 278 work_area.y() + top_left.height(), grid),
279 popup_position.width(), popup_position.height()),
275 mid_left); 280 mid_left);
276 281
277 // Block now everything so that we can only put the popup on the bottom 282 // Block now everything so that we can only put the popup on the bottom
278 // of the left side. 283 // of the left side.
284 // Note: We need to keep one "grid spacing free" if the window does not
285 // fit into the grid (which is true for 200 height).`
279 popup()->SetBounds(gfx::Rect(work_area.x(), work_area.y(), 286 popup()->SetBounds(gfx::Rect(work_area.x(), work_area.y(),
280 popup_position.width(), 287 popup_position.width(),
281 work_area.height() - popup_position.height())); 288 work_area.height() - popup_position.height() -
289 grid + 1));
282 gfx::Rect bottom_left = window_positioner()->GetPopupPosition( 290 gfx::Rect bottom_left = window_positioner()->GetPopupPosition(
283 popup_position); 291 popup_position);
284 EXPECT_EQ(gfx::Rect(work_area.x(), 292 EXPECT_EQ(gfx::Rect(work_area.x(),
285 work_area.y() + work_area.height() - 293 work_area.bottom() - popup_position.height(),
286 popup_position.height(),
287 popup_position.width(), popup_position.height()), 294 popup_position.width(), popup_position.height()),
288 bottom_left); 295 bottom_left);
289 296
290 // Block now enough to force the right side. 297 // Block now enough to force the right side.
291 popup()->SetBounds(gfx::Rect(work_area.x(), work_area.y(), 298 popup()->SetBounds(gfx::Rect(work_area.x(), work_area.y(),
292 popup_position.width(), 299 popup_position.width(),
293 work_area.height() - popup_position.height() + 300 work_area.height() - popup_position.height() +
294 1)); 301 1));
295 gfx::Rect top_right = window_positioner()->GetPopupPosition( 302 gfx::Rect top_right = window_positioner()->GetPopupPosition(
296 popup_position); 303 popup_position);
297 EXPECT_EQ(gfx::Rect(work_area.x() + work_area.width() - 304 EXPECT_EQ(gfx::Rect(ash::WindowResizer::AlignToGridRoundDown(
298 popup_position.width(), 305 work_area.right() - popup_position.width(), grid),
299 work_area.y(), 306 work_area.y(),
300 popup_position.width(), popup_position.height()), 307 popup_position.width(), popup_position.height()),
301 top_right); 308 top_right);
302 } 309 }
303 310
304 TEST_F(WindowPositionerTest, blockedByPanel) { 311 TEST_F(WindowPositionerTest, blockedByPanel) {
305 const gfx::Rect work_area = gfx::Screen::GetPrimaryMonitorWorkArea(); 312 const gfx::Rect work_area = gfx::Screen::GetPrimaryMonitorWorkArea();
306 313
307 gfx::Rect pop_position(0, 0, 200, 200); 314 gfx::Rect pop_position(0, 0, 200, 200);
308 // Let the panel cover everything. 315 // Let the panel cover everything.
(...skipping 14 matching lines...) Expand all
323 330
324 // Check that the popup is placed full screen. 331 // Check that the popup is placed full screen.
325 gfx::Rect full = window_positioner()->GetPopupPosition(pop_position); 332 gfx::Rect full = window_positioner()->GetPopupPosition(pop_position);
326 EXPECT_EQ(gfx::Rect(work_area.x(), work_area.y(), 333 EXPECT_EQ(gfx::Rect(work_area.x(), work_area.y(),
327 pop_position.width(), pop_position.height()), 334 pop_position.width(), pop_position.height()),
328 full); 335 full);
329 } 336 }
330 337
331 } // namespace test 338 } // namespace test
332 } // namespace ash 339 } // namespace ash
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/ash/window_positioner.cc ('k') | chrome/browser/ui/window_sizer_ash.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698