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

Side by Side Diff: ash/shelf/shelf_layout_manager_unittest.cc

Issue 12313118: Refactor: Shelf Widget (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 9 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 "ash/wm/shelf_layout_manager.h" 5 #include "ash/shelf/shelf_layout_manager.h"
6 6
7 #include "ash/accelerators/accelerator_controller.h" 7 #include "ash/accelerators/accelerator_controller.h"
8 #include "ash/accelerators/accelerator_table.h" 8 #include "ash/accelerators/accelerator_table.h"
9 #include "ash/ash_switches.h" 9 #include "ash/ash_switches.h"
10 #include "ash/display/display_manager.h" 10 #include "ash/display/display_manager.h"
11 #include "ash/focus_cycler.h" 11 #include "ash/focus_cycler.h"
12 #include "ash/launcher/launcher.h" 12 #include "ash/launcher/launcher.h"
13 #include "ash/launcher/launcher_view.h"
13 #include "ash/root_window_controller.h" 14 #include "ash/root_window_controller.h"
14 #include "ash/screen_ash.h" 15 #include "ash/screen_ash.h"
16 #include "ash/shelf/shelf_widget.h"
15 #include "ash/shell.h" 17 #include "ash/shell.h"
16 #include "ash/shell_delegate.h" 18 #include "ash/shell_delegate.h"
17 #include "ash/shell_window_ids.h" 19 #include "ash/shell_window_ids.h"
18 #include "ash/system/status_area_widget.h" 20 #include "ash/system/status_area_widget.h"
19 #include "ash/system/tray/system_tray.h" 21 #include "ash/system/tray/system_tray.h"
20 #include "ash/system/tray/system_tray_item.h" 22 #include "ash/system/tray/system_tray_item.h"
21 #include "ash/test/ash_test_base.h" 23 #include "ash/test/ash_test_base.h"
22 #include "ash/wm/window_util.h" 24 #include "ash/wm/window_util.h"
23 #include "base/command_line.h" 25 #include "base/command_line.h"
24 #include "base/utf_string_conversions.h" 26 #include "base/utf_string_conversions.h"
(...skipping 20 matching lines...) Expand all
45 47
46 namespace { 48 namespace {
47 49
48 void StepWidgetLayerAnimatorToEnd(views::Widget* widget) { 50 void StepWidgetLayerAnimatorToEnd(views::Widget* widget) {
49 ui::AnimationContainerElement* element = 51 ui::AnimationContainerElement* element =
50 static_cast<ui::AnimationContainerElement*>( 52 static_cast<ui::AnimationContainerElement*>(
51 widget->GetNativeView()->layer()->GetAnimator()); 53 widget->GetNativeView()->layer()->GetAnimator());
52 element->Step(base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); 54 element->Step(base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1));
53 } 55 }
54 56
57 ShelfWidget* GetShelfWidget() {
58 return Shell::GetPrimaryRootWindowController()->shelf();
59 }
55 ShelfLayoutManager* GetShelfLayoutManager() { 60 ShelfLayoutManager* GetShelfLayoutManager() {
56 return Shell::GetPrimaryRootWindowController()->shelf(); 61 return Shell::GetPrimaryRootWindowController()->shelf_layout_manager();
57 } 62 }
58 63
59 SystemTray* GetSystemTray() { 64 SystemTray* GetSystemTray() {
60 return Shell::GetPrimaryRootWindowController()->GetSystemTray(); 65 return Shell::GetPrimaryRootWindowController()->GetSystemTray();
61 } 66 }
62 67
63 class ShelfLayoutObserverTest : public ShelfLayoutManager::Observer { 68 class ShelfLayoutObserverTest : public ShelfLayoutManager::Observer {
64 public: 69 public:
65 ShelfLayoutObserverTest() 70 ShelfLayoutObserverTest()
66 : changed_auto_hide_state_(false) { 71 : changed_auto_hide_state_(false) {
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 }; 209 };
205 210
206 // Fails on Mac only. Need to be implemented. http://crbug.com/111279. 211 // Fails on Mac only. Need to be implemented. http://crbug.com/111279.
207 #if defined(OS_MACOSX) || defined(OS_WIN) 212 #if defined(OS_MACOSX) || defined(OS_WIN)
208 #define MAYBE_SetVisible DISABLED_SetVisible 213 #define MAYBE_SetVisible DISABLED_SetVisible
209 #else 214 #else
210 #define MAYBE_SetVisible SetVisible 215 #define MAYBE_SetVisible SetVisible
211 #endif 216 #endif
212 // Makes sure SetVisible updates work area and widget appropriately. 217 // Makes sure SetVisible updates work area and widget appropriately.
213 TEST_F(ShelfLayoutManagerTest, MAYBE_SetVisible) { 218 TEST_F(ShelfLayoutManagerTest, MAYBE_SetVisible) {
214 ShelfLayoutManager* shelf = GetShelfLayoutManager(); 219 ShelfWidget* shelf = GetShelfWidget();
220 ShelfLayoutManager* manager = shelf->shelf_layout_manager();
215 // Force an initial layout. 221 // Force an initial layout.
216 shelf->LayoutShelf(); 222 manager->LayoutShelf();
217 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); 223 EXPECT_EQ(SHELF_VISIBLE, manager->visibility_state());
218 224
219 gfx::Rect status_bounds( 225 gfx::Rect status_bounds(
220 shelf->status_area_widget()->GetWindowBoundsInScreen()); 226 shelf->status_area_widget()->GetWindowBoundsInScreen());
221 gfx::Rect launcher_bounds( 227 gfx::Rect launcher_bounds(
222 shelf->launcher_widget()->GetWindowBoundsInScreen()); 228 shelf->GetWindowBoundsInScreen());
223 int shelf_height = shelf->GetIdealBounds().height(); 229 int shelf_height = manager->GetIdealBounds().height();
224 230
225 const gfx::Display& display = Shell::GetInstance()->display_manager()-> 231 const gfx::Display& display = Shell::GetInstance()->display_manager()->
226 GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); 232 GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
227 ASSERT_NE(-1, display.id()); 233 ASSERT_NE(-1, display.id());
228 // Bottom inset should be the max of widget heights. 234 // Bottom inset should be the max of widget heights.
229 EXPECT_EQ(shelf_height, 235 EXPECT_EQ(shelf_height,
230 display.bounds().bottom() - display.work_area().bottom()); 236 display.bounds().bottom() - display.work_area().bottom());
231 237
232 // Hide the shelf. 238 // Hide the shelf.
233 SetState(shelf, SHELF_HIDDEN); 239 SetState(manager, SHELF_HIDDEN);
234 // Run the animation to completion. 240 // Run the animation to completion.
235 StepWidgetLayerAnimatorToEnd(shelf->launcher_widget()); 241 StepWidgetLayerAnimatorToEnd(shelf);
236 StepWidgetLayerAnimatorToEnd(shelf->status_area_widget()); 242 StepWidgetLayerAnimatorToEnd(shelf->status_area_widget());
237 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state()); 243 EXPECT_EQ(SHELF_HIDDEN, manager->visibility_state());
238 EXPECT_EQ(0, 244 EXPECT_EQ(0,
239 display.bounds().bottom() - display.work_area().bottom()); 245 display.bounds().bottom() - display.work_area().bottom());
240 246
241 // Make sure the bounds of the two widgets changed. 247 // Make sure the bounds of the two widgets changed.
242 EXPECT_GE(shelf->launcher_widget()->GetNativeView()->bounds().y(), 248 EXPECT_GE(shelf->GetNativeView()->bounds().y(),
243 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom()); 249 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom());
244 EXPECT_GE(shelf->status_area_widget()->GetNativeView()->bounds().y(), 250 EXPECT_GE(shelf->status_area_widget()->GetNativeView()->bounds().y(),
245 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom()); 251 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom());
246 252
247 // And show it again. 253 // And show it again.
248 SetState(shelf, SHELF_VISIBLE); 254 SetState(manager, SHELF_VISIBLE);
249 // Run the animation to completion. 255 // Run the animation to completion.
250 StepWidgetLayerAnimatorToEnd(shelf->launcher_widget()); 256 StepWidgetLayerAnimatorToEnd(shelf);
251 StepWidgetLayerAnimatorToEnd(shelf->status_area_widget()); 257 StepWidgetLayerAnimatorToEnd(shelf->status_area_widget());
252 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); 258 EXPECT_EQ(SHELF_VISIBLE, manager->visibility_state());
253 EXPECT_EQ(shelf_height, 259 EXPECT_EQ(shelf_height,
254 display.bounds().bottom() - display.work_area().bottom()); 260 display.bounds().bottom() - display.work_area().bottom());
255 261
256 // Make sure the bounds of the two widgets changed. 262 // Make sure the bounds of the two widgets changed.
257 launcher_bounds = shelf->launcher_widget()->GetNativeView()->bounds(); 263 launcher_bounds = shelf->GetNativeView()->bounds();
258 int bottom = 264 int bottom =
259 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom() - shelf_height; 265 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom() - shelf_height;
260 EXPECT_EQ(launcher_bounds.y(), 266 EXPECT_EQ(launcher_bounds.y(),
261 bottom + (shelf->GetIdealBounds().height() - 267 bottom + (manager->GetIdealBounds().height() -
262 launcher_bounds.height()) / 2); 268 launcher_bounds.height()) / 2);
263 status_bounds = shelf->status_area_widget()->GetNativeView()->bounds(); 269 status_bounds = shelf->status_area_widget()->GetNativeView()->bounds();
264 EXPECT_EQ(status_bounds.y(), 270 EXPECT_EQ(status_bounds.y(),
265 bottom + shelf_height - status_bounds.height()); 271 bottom + shelf_height - status_bounds.height());
266 } 272 }
267 273
268 // Makes sure LayoutShelf invoked while animating cleans things up. 274 // Makes sure LayoutShelf invoked while animating cleans things up.
269 TEST_F(ShelfLayoutManagerTest, LayoutShelfWhileAnimating) { 275 TEST_F(ShelfLayoutManagerTest, LayoutShelfWhileAnimating) {
270 ShelfLayoutManager* shelf = GetShelfLayoutManager(); 276 ShelfWidget* shelf = GetShelfWidget();
271 // Force an initial layout. 277 // Force an initial layout.
272 shelf->LayoutShelf(); 278 shelf->shelf_layout_manager()->LayoutShelf();
273 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); 279 EXPECT_EQ(SHELF_VISIBLE, shelf->shelf_layout_manager()->visibility_state());
274 280
275 const gfx::Display& display = Shell::GetInstance()->display_manager()-> 281 const gfx::Display& display = Shell::GetInstance()->display_manager()->
276 GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); 282 GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
277 283
278 // Hide the shelf. 284 // Hide the shelf.
279 SetState(shelf, SHELF_HIDDEN); 285 SetState(shelf->shelf_layout_manager(), SHELF_HIDDEN);
280 shelf->LayoutShelf(); 286 shelf->shelf_layout_manager()->LayoutShelf();
281 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state()); 287 EXPECT_EQ(SHELF_HIDDEN, shelf->shelf_layout_manager()->visibility_state());
282 EXPECT_EQ(0, display.bounds().bottom() - display.work_area().bottom()); 288 EXPECT_EQ(0, display.bounds().bottom() - display.work_area().bottom());
283 289
284 // Make sure the bounds of the two widgets changed. 290 // Make sure the bounds of the two widgets changed.
285 EXPECT_GE(shelf->launcher_widget()->GetNativeView()->bounds().y(), 291 EXPECT_GE(shelf->GetNativeView()->bounds().y(),
286 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom()); 292 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom());
287 EXPECT_GE(shelf->status_area_widget()->GetNativeView()->bounds().y(), 293 EXPECT_GE(shelf->status_area_widget()->GetNativeView()->bounds().y(),
288 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom()); 294 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom());
289 } 295 }
290 296
291 // Makes sure the launcher is initially sized correctly.
292 TEST_F(ShelfLayoutManagerTest, LauncherInitiallySized) {
293 Launcher* launcher = Launcher::ForPrimaryDisplay();
294 ASSERT_TRUE(launcher);
295 ShelfLayoutManager* shelf_layout_manager = GetShelfLayoutManager();
296 ASSERT_TRUE(shelf_layout_manager);
297 ASSERT_TRUE(shelf_layout_manager->status_area_widget());
298 int status_width = shelf_layout_manager->status_area_widget()->
299 GetWindowBoundsInScreen().width();
300 // Test only makes sense if the status is > 0, which is better be.
301 EXPECT_GT(status_width, 0);
302 EXPECT_EQ(status_width, launcher->status_size().width());
303 }
304
305 // Makes sure the launcher is sized when the status area changes size. 297 // Makes sure the launcher is sized when the status area changes size.
306 TEST_F(ShelfLayoutManagerTest, LauncherUpdatedWhenStatusAreaChangesSize) { 298 TEST_F(ShelfLayoutManagerTest, LauncherUpdatedWhenStatusAreaChangesSize) {
307 Launcher* launcher = Launcher::ForPrimaryDisplay(); 299 Launcher* launcher = Launcher::ForPrimaryDisplay();
308 ASSERT_TRUE(launcher); 300 ASSERT_TRUE(launcher);
309 ShelfLayoutManager* shelf_layout_manager = GetShelfLayoutManager(); 301 ShelfWidget* shelf_widget = GetShelfWidget();
310 ASSERT_TRUE(shelf_layout_manager); 302 ASSERT_TRUE(shelf_widget);
311 ASSERT_TRUE(shelf_layout_manager->status_area_widget()); 303 ASSERT_TRUE(shelf_widget->status_area_widget());
312 shelf_layout_manager->status_area_widget()->SetBounds( 304 shelf_widget->status_area_widget()->SetBounds(
313 gfx::Rect(0, 0, 200, 200)); 305 gfx::Rect(0, 0, 200, 200));
314 EXPECT_EQ(200, launcher->status_size().width()); 306 EXPECT_EQ(200, shelf_widget->GetContentsView()->width() -
307 launcher->GetLauncherViewForTest()->width());
315 } 308 }
316 309
317 // Verifies when the shell is deleted with a full screen window we don't
318 // crash. This test is here as originally the crash was in ShelfLayoutManager.
319 TEST_F(ShelfLayoutManagerTest, DontReferenceLauncherAfterDeletion) {
320 views::Widget* widget = new views::Widget;
321 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
322 params.bounds = gfx::Rect(0, 0, 200, 200);
323 params.context = CurrentContext();
324 // Widget is now owned by the parent window.
325 widget->Init(params);
326 widget->SetFullscreen(true);
327 }
328 310
329 #if defined(OS_WIN) 311 #if defined(OS_WIN)
330 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962 312 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962
331 #define MAYBE_AutoHide DISABLED_AutoHide 313 #define MAYBE_AutoHide DISABLED_AutoHide
332 #else 314 #else
333 #define MAYBE_AutoHide AutoHide 315 #define MAYBE_AutoHide AutoHide
334 #endif 316 #endif
335 317
336 // Various assertions around auto-hide. 318 // Various assertions around auto-hide.
337 TEST_F(ShelfLayoutManagerTest, MAYBE_AutoHide) { 319 TEST_F(ShelfLayoutManagerTest, MAYBE_AutoHide) {
(...skipping 11 matching lines...) Expand all
349 widget->Init(params); 331 widget->Init(params);
350 widget->Maximize(); 332 widget->Maximize();
351 widget->Show(); 333 widget->Show();
352 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); 334 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
353 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); 335 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
354 336
355 // LayoutShelf() forces the animation to completion, at which point the 337 // LayoutShelf() forces the animation to completion, at which point the
356 // launcher should go off the screen. 338 // launcher should go off the screen.
357 shelf->LayoutShelf(); 339 shelf->LayoutShelf();
358 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, 340 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize,
359 shelf->launcher_widget()->GetWindowBoundsInScreen().y()); 341 GetShelfWidget()->GetWindowBoundsInScreen().y());
360 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, 342 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize,
361 Shell::GetScreen()->GetDisplayNearestWindow( 343 Shell::GetScreen()->GetDisplayNearestWindow(
362 root).work_area().bottom()); 344 root).work_area().bottom());
363 345
364 // Move the mouse to the bottom of the screen. 346 // Move the mouse to the bottom of the screen.
365 generator.MoveMouseTo(0, root->bounds().bottom() - 1); 347 generator.MoveMouseTo(0, root->bounds().bottom() - 1);
366 348
367 // Shelf should be shown again (but it shouldn't have changed the work area). 349 // Shelf should be shown again (but it shouldn't have changed the work area).
368 SetState(shelf, SHELF_AUTO_HIDE); 350 SetState(shelf, SHELF_AUTO_HIDE);
369 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); 351 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
370 shelf->LayoutShelf(); 352 shelf->LayoutShelf();
371 EXPECT_EQ(root->bounds().bottom() - shelf->GetIdealBounds().height(), 353 EXPECT_EQ(root->bounds().bottom() - shelf->GetIdealBounds().height(),
372 shelf->launcher_widget()->GetWindowBoundsInScreen().y()); 354 GetShelfWidget()->GetWindowBoundsInScreen().y());
373 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, 355 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize,
374 Shell::GetScreen()->GetDisplayNearestWindow( 356 Shell::GetScreen()->GetDisplayNearestWindow(
375 root).work_area().bottom()); 357 root).work_area().bottom());
376 358
377 // Move mouse back up. 359 // Move mouse back up.
378 generator.MoveMouseTo(0, 0); 360 generator.MoveMouseTo(0, 0);
379 SetState(shelf, SHELF_AUTO_HIDE); 361 SetState(shelf, SHELF_AUTO_HIDE);
380 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); 362 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
381 shelf->LayoutShelf(); 363 shelf->LayoutShelf();
382 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, 364 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize,
383 shelf->launcher_widget()->GetWindowBoundsInScreen().y()); 365 GetShelfWidget()->GetWindowBoundsInScreen().y());
384 366
385 // Drag mouse to bottom of screen. 367 // Drag mouse to bottom of screen.
386 generator.PressLeftButton(); 368 generator.PressLeftButton();
387 generator.MoveMouseTo(0, root->bounds().bottom() - 1); 369 generator.MoveMouseTo(0, root->bounds().bottom() - 1);
388 UpdateAutoHideStateNow(); 370 UpdateAutoHideStateNow();
389 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); 371 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
390 372
391 generator.ReleaseLeftButton(); 373 generator.ReleaseLeftButton();
392 generator.MoveMouseTo(1, root->bounds().bottom() - 1); 374 generator.MoveMouseTo(1, root->bounds().bottom() - 1);
393 UpdateAutoHideStateNow(); 375 UpdateAutoHideStateNow();
(...skipping 23 matching lines...) Expand all
417 widget->Maximize(); 399 widget->Maximize();
418 widget->Show(); 400 widget->Show();
419 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); 401 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
420 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); 402 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
421 403
422 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); 404 aura::RootWindow* root = Shell::GetPrimaryRootWindow();
423 // LayoutShelf() forces the animation to completion, at which point the 405 // LayoutShelf() forces the animation to completion, at which point the
424 // launcher should go off the screen. 406 // launcher should go off the screen.
425 shelf->LayoutShelf(); 407 shelf->LayoutShelf();
426 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, 408 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize,
427 shelf->launcher_widget()->GetWindowBoundsInScreen().y()); 409 GetShelfWidget()->GetWindowBoundsInScreen().y());
428 410
429 aura::Window* lock_container = Shell::GetContainer( 411 aura::Window* lock_container = Shell::GetContainer(
430 Shell::GetPrimaryRootWindow(), 412 Shell::GetPrimaryRootWindow(),
431 internal::kShellWindowId_LockScreenContainer); 413 internal::kShellWindowId_LockScreenContainer);
432 414
433 views::Widget* lock_widget = new views::Widget; 415 views::Widget* lock_widget = new views::Widget;
434 views::Widget::InitParams lock_params( 416 views::Widget::InitParams lock_params(
435 views::Widget::InitParams::TYPE_WINDOW); 417 views::Widget::InitParams::TYPE_WINDOW);
436 lock_params.bounds = gfx::Rect(0, 0, 200, 200); 418 lock_params.bounds = gfx::Rect(0, 0, 200, 200);
437 params.context = CurrentContext(); 419 params.context = CurrentContext();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 params.context = CurrentContext(); 494 params.context = CurrentContext();
513 // Widget is now owned by the parent window. 495 // Widget is now owned by the parent window.
514 widget->Init(params); 496 widget->Init(params);
515 widget->Show(); 497 widget->Show();
516 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 498 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
517 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); 499 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
518 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); 500 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
519 501
520 // Focus the launcher. Have to go through the focus cycler as normal focus 502 // Focus the launcher. Have to go through the focus cycler as normal focus
521 // requests to it do nothing. 503 // requests to it do nothing.
522 shelf->launcher()->GetFocusCycler()->RotateFocus(FocusCycler::FORWARD); 504 GetShelfWidget()->GetFocusCycler()->RotateFocus(FocusCycler::FORWARD);
523 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); 505 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
524 506
525 widget->Activate(); 507 widget->Activate();
526 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); 508 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
527 509
528 // Trying to activate the status should fail, since we only allow activating 510 // Trying to activate the status should fail, since we only allow activating
529 // it when the user is using the keyboard (i.e. through FocusCycler). 511 // it when the user is using the keyboard (i.e. through FocusCycler).
530 shelf->status_area_widget()->Activate(); 512 GetShelfWidget()->status_area_widget()->Activate();
531 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); 513 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
532 514
533 shelf->launcher()->GetFocusCycler()->RotateFocus(FocusCycler::FORWARD); 515 GetShelfWidget()->GetFocusCycler()->RotateFocus(FocusCycler::FORWARD);
534 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state()); 516 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
535 } 517 }
536 518
537 // Makes sure shelf will be visible when app list opens as shelf is in 519 // Makes sure shelf will be visible when app list opens as shelf is in
538 // SHELF_VISIBLE state,and toggling app list won't change shelf 520 // SHELF_VISIBLE state,and toggling app list won't change shelf
539 // visibility state. 521 // visibility state.
540 TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfVisibleState) { 522 TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfVisibleState) {
541 Shell* shell = Shell::GetInstance(); 523 Shell* shell = Shell::GetInstance();
542 internal::RootWindowController* controller =
543 Shell::GetPrimaryRootWindowController();
544 ShelfLayoutManager* shelf = GetShelfLayoutManager(); 524 ShelfLayoutManager* shelf = GetShelfLayoutManager();
545 shelf->LayoutShelf(); 525 shelf->LayoutShelf();
546 controller->SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); 526 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
547 527
548 // Create a normal unmaximized windowm shelf should be visible. 528 // Create a normal unmaximized windowm shelf should be visible.
549 aura::Window* window = CreateTestWindow(); 529 aura::Window* window = CreateTestWindow();
550 window->SetBounds(gfx::Rect(0, 0, 100, 100)); 530 window->SetBounds(gfx::Rect(0, 0, 100, 100));
551 window->Show(); 531 window->Show();
552 EXPECT_FALSE(shell->GetAppListTargetVisibility()); 532 EXPECT_FALSE(shell->GetAppListTargetVisibility());
553 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); 533 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
554 534
555 // Toggle app list to show, and the shelf stays visible. 535 // Toggle app list to show, and the shelf stays visible.
556 shell->ToggleAppList(NULL); 536 shell->ToggleAppList(NULL);
557 EXPECT_TRUE(shell->GetAppListTargetVisibility()); 537 EXPECT_TRUE(shell->GetAppListTargetVisibility());
558 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); 538 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
559 539
560 // Toggle app list to hide, and the shelf stays visible. 540 // Toggle app list to hide, and the shelf stays visible.
561 shell->ToggleAppList(NULL); 541 shell->ToggleAppList(NULL);
562 EXPECT_FALSE(shell->GetAppListTargetVisibility()); 542 EXPECT_FALSE(shell->GetAppListTargetVisibility());
563 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); 543 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
564 } 544 }
565 545
566 // Makes sure shelf will be shown with SHELF_AUTO_HIDE_SHOWN state 546 // Makes sure shelf will be shown with SHELF_AUTO_HIDE_SHOWN state
567 // when app list opens as shelf is in SHELF_AUTO_HIDE state, and 547 // when app list opens as shelf is in SHELF_AUTO_HIDE state, and
568 // toggling app list won't change shelf visibility state. 548 // toggling app list won't change shelf visibility state.
569 TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfAutoHideState) { 549 TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfAutoHideState) {
570 Shell* shell = Shell::GetInstance(); 550 Shell* shell = Shell::GetInstance();
571 ShelfLayoutManager* shelf = GetShelfLayoutManager(); 551 ShelfLayoutManager* shelf = GetShelfLayoutManager();
572 internal::RootWindowController* controller =
573 Shell::GetPrimaryRootWindowController();
574 shelf->LayoutShelf(); 552 shelf->LayoutShelf();
575 controller->SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 553 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
576 554
577 // Create a window and show it in maximized state. 555 // Create a window and show it in maximized state.
578 aura::Window* window = CreateTestWindow(); 556 aura::Window* window = CreateTestWindow();
579 window->SetBounds(gfx::Rect(0, 0, 100, 100)); 557 window->SetBounds(gfx::Rect(0, 0, 100, 100));
580 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 558 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
581 window->Show(); 559 window->Show();
582 wm::ActivateWindow(window); 560 wm::ActivateWindow(window);
583 561
584 EXPECT_FALSE(shell->GetAppListTargetVisibility()); 562 EXPECT_FALSE(shell->GetAppListTargetVisibility());
585 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); 563 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 // Tests SHELF_ALIGNMENT_(LEFT, RIGHT, TOP). 618 // Tests SHELF_ALIGNMENT_(LEFT, RIGHT, TOP).
641 TEST_F(ShelfLayoutManagerTest, MAYBE_SetAlignment) { 619 TEST_F(ShelfLayoutManagerTest, MAYBE_SetAlignment) {
642 ShelfLayoutManager* shelf = GetShelfLayoutManager(); 620 ShelfLayoutManager* shelf = GetShelfLayoutManager();
643 // Force an initial layout. 621 // Force an initial layout.
644 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); 622 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
645 shelf->LayoutShelf(); 623 shelf->LayoutShelf();
646 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); 624 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
647 625
648 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); 626 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT);
649 gfx::Rect launcher_bounds( 627 gfx::Rect launcher_bounds(
650 shelf->launcher_widget()->GetWindowBoundsInScreen()); 628 GetShelfWidget()->GetWindowBoundsInScreen());
651 const internal::DisplayManager* manager = 629 const internal::DisplayManager* manager =
652 Shell::GetInstance()->display_manager(); 630 Shell::GetInstance()->display_manager();
653 gfx::Display display = 631 gfx::Display display =
654 manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); 632 manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
655 ASSERT_NE(-1, display.id()); 633 ASSERT_NE(-1, display.id());
656 EXPECT_EQ(shelf->GetIdealBounds().width(), 634 EXPECT_EQ(shelf->GetIdealBounds().width(),
657 display.GetWorkAreaInsets().left()); 635 display.GetWorkAreaInsets().left());
658 EXPECT_GE( 636 EXPECT_GE(
659 launcher_bounds.width(), 637 launcher_bounds.width(),
660 shelf->launcher_widget()->GetContentsView()->GetPreferredSize().width()); 638 GetShelfWidget()->GetContentsView()->GetPreferredSize().width());
661 EXPECT_EQ(SHELF_ALIGNMENT_LEFT, GetSystemTray()->shelf_alignment()); 639 EXPECT_EQ(SHELF_ALIGNMENT_LEFT, GetSystemTray()->shelf_alignment());
662 StatusAreaWidget* status_area_widget = shelf->status_area_widget(); 640 StatusAreaWidget* status_area_widget = GetShelfWidget()->status_area_widget();
663 gfx::Rect status_bounds(status_area_widget->GetWindowBoundsInScreen()); 641 gfx::Rect status_bounds(status_area_widget->GetWindowBoundsInScreen());
664 EXPECT_GE(status_bounds.width(), 642 EXPECT_GE(status_bounds.width(),
665 status_area_widget->GetContentsView()->GetPreferredSize().width()); 643 status_area_widget->GetContentsView()->GetPreferredSize().width());
666 EXPECT_EQ(shelf->GetIdealBounds().width(), 644 EXPECT_EQ(shelf->GetIdealBounds().width(),
667 display.GetWorkAreaInsets().left()); 645 display.GetWorkAreaInsets().left());
668 EXPECT_EQ(0, display.GetWorkAreaInsets().top()); 646 EXPECT_EQ(0, display.GetWorkAreaInsets().top());
669 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom()); 647 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom());
670 EXPECT_EQ(0, display.GetWorkAreaInsets().right()); 648 EXPECT_EQ(0, display.GetWorkAreaInsets().right());
671 EXPECT_EQ(display.bounds().x(), launcher_bounds.x()); 649 EXPECT_EQ(display.bounds().x(), launcher_bounds.x());
672 EXPECT_EQ(display.bounds().y(), launcher_bounds.y()); 650 EXPECT_EQ(display.bounds().y(), launcher_bounds.y());
673 EXPECT_EQ(display.bounds().height(), launcher_bounds.height()); 651 EXPECT_EQ(display.bounds().height(), launcher_bounds.height());
674 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 652 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
675 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); 653 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
676 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, 654 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize,
677 display.GetWorkAreaInsets().left()); 655 display.GetWorkAreaInsets().left());
678 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, display.work_area().x()); 656 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, display.work_area().x());
679 657
680 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); 658 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
681 shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT); 659 shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT);
682 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); 660 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
683 launcher_bounds = shelf->launcher_widget()->GetWindowBoundsInScreen(); 661 launcher_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
684 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); 662 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
685 ASSERT_NE(-1, display.id()); 663 ASSERT_NE(-1, display.id());
686 EXPECT_EQ(shelf->GetIdealBounds().width(), 664 EXPECT_EQ(shelf->GetIdealBounds().width(),
687 display.GetWorkAreaInsets().right()); 665 display.GetWorkAreaInsets().right());
688 EXPECT_GE(launcher_bounds.width(), 666 EXPECT_GE(launcher_bounds.width(),
689 shelf->launcher_widget()->GetContentsView()->GetPreferredSize().width()); 667 GetShelfWidget()->GetContentsView()->GetPreferredSize().width());
690 EXPECT_EQ(SHELF_ALIGNMENT_RIGHT, GetSystemTray()->shelf_alignment()); 668 EXPECT_EQ(SHELF_ALIGNMENT_RIGHT, GetSystemTray()->shelf_alignment());
691 status_bounds = gfx::Rect(status_area_widget->GetWindowBoundsInScreen()); 669 status_bounds = gfx::Rect(status_area_widget->GetWindowBoundsInScreen());
692 EXPECT_GE(status_bounds.width(), 670 EXPECT_GE(status_bounds.width(),
693 status_area_widget->GetContentsView()->GetPreferredSize().width()); 671 status_area_widget->GetContentsView()->GetPreferredSize().width());
694 EXPECT_EQ(shelf->GetIdealBounds().width(), 672 EXPECT_EQ(shelf->GetIdealBounds().width(),
695 display.GetWorkAreaInsets().right()); 673 display.GetWorkAreaInsets().right());
696 EXPECT_EQ(0, display.GetWorkAreaInsets().top()); 674 EXPECT_EQ(0, display.GetWorkAreaInsets().top());
697 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom()); 675 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom());
698 EXPECT_EQ(0, display.GetWorkAreaInsets().left()); 676 EXPECT_EQ(0, display.GetWorkAreaInsets().left());
699 EXPECT_EQ(display.work_area().right(), launcher_bounds.x()); 677 EXPECT_EQ(display.work_area().right(), launcher_bounds.x());
700 EXPECT_EQ(display.bounds().y(), launcher_bounds.y()); 678 EXPECT_EQ(display.bounds().y(), launcher_bounds.y());
701 EXPECT_EQ(display.bounds().height(), launcher_bounds.height()); 679 EXPECT_EQ(display.bounds().height(), launcher_bounds.height());
702 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 680 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
703 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); 681 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
704 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, 682 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize,
705 display.GetWorkAreaInsets().right()); 683 display.GetWorkAreaInsets().right());
706 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, 684 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize,
707 display.bounds().right() - display.work_area().right()); 685 display.bounds().right() - display.work_area().right());
708 686
709 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); 687 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
710 shelf->SetAlignment(SHELF_ALIGNMENT_TOP); 688 shelf->SetAlignment(SHELF_ALIGNMENT_TOP);
711 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); 689 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
712 launcher_bounds = shelf->launcher_widget()->GetWindowBoundsInScreen(); 690 launcher_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
713 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); 691 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
714 ASSERT_NE(-1, display.id()); 692 ASSERT_NE(-1, display.id());
715 EXPECT_EQ(shelf->GetIdealBounds().height(), 693 EXPECT_EQ(shelf->GetIdealBounds().height(),
716 display.GetWorkAreaInsets().top()); 694 display.GetWorkAreaInsets().top());
717 EXPECT_GE(launcher_bounds.height(), 695 EXPECT_GE(launcher_bounds.height(),
718 shelf->launcher_widget()->GetContentsView()->GetPreferredSize().height()); 696 GetShelfWidget()->GetContentsView()->GetPreferredSize().height());
719 EXPECT_EQ(SHELF_ALIGNMENT_TOP, GetSystemTray()->shelf_alignment()); 697 EXPECT_EQ(SHELF_ALIGNMENT_TOP, GetSystemTray()->shelf_alignment());
720 status_bounds = gfx::Rect(status_area_widget->GetWindowBoundsInScreen()); 698 status_bounds = gfx::Rect(status_area_widget->GetWindowBoundsInScreen());
721 EXPECT_GE(status_bounds.height(), 699 EXPECT_GE(status_bounds.height(),
722 status_area_widget->GetContentsView()->GetPreferredSize().height()); 700 status_area_widget->GetContentsView()->GetPreferredSize().height());
723 EXPECT_EQ(shelf->GetIdealBounds().height(), 701 EXPECT_EQ(shelf->GetIdealBounds().height(),
724 display.GetWorkAreaInsets().top()); 702 display.GetWorkAreaInsets().top());
725 EXPECT_EQ(0, display.GetWorkAreaInsets().right()); 703 EXPECT_EQ(0, display.GetWorkAreaInsets().right());
726 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom()); 704 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom());
727 EXPECT_EQ(0, display.GetWorkAreaInsets().left()); 705 EXPECT_EQ(0, display.GetWorkAreaInsets().left());
728 EXPECT_EQ(display.work_area().y(), launcher_bounds.bottom()); 706 EXPECT_EQ(display.work_area().y(), launcher_bounds.bottom());
729 EXPECT_EQ(display.bounds().x(), launcher_bounds.x()); 707 EXPECT_EQ(display.bounds().x(), launcher_bounds.x());
730 EXPECT_EQ(display.bounds().width(), launcher_bounds.width()); 708 EXPECT_EQ(display.bounds().width(), launcher_bounds.width());
731 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 709 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
732 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); 710 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
733 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, 711 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize,
734 display.GetWorkAreaInsets().top()); 712 display.GetWorkAreaInsets().top());
735 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, 713 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize,
736 display.work_area().y() - display.bounds().y()); 714 display.work_area().y() - display.bounds().y());
737 } 715 }
738 716
739 #if defined(OS_WIN) 717 #if defined(OS_WIN)
740 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962 718 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962
741 #define MAYBE_GestureDrag DISABLED_GestureDrag 719 #define MAYBE_GestureDrag DISABLED_GestureDrag
742 #else 720 #else
743 #define MAYBE_GestureDrag GestureDrag 721 #define MAYBE_GestureDrag GestureDrag
744 #endif 722 #endif
745 723
746 TEST_F(ShelfLayoutManagerTest, MAYBE_GestureDrag) { 724 TEST_F(ShelfLayoutManagerTest, MAYBE_GestureDrag) {
747 ShelfLayoutManager* shelf = GetShelfLayoutManager(); 725 ShelfLayoutManager* shelf = GetShelfLayoutManager();
748 internal::RootWindowController* controller = 726 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
749 Shell::GetPrimaryRootWindowController();
750 controller->SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
751 shelf->LayoutShelf(); 727 shelf->LayoutShelf();
752 728
753 views::Widget* widget = new views::Widget; 729 views::Widget* widget = new views::Widget;
754 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); 730 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
755 params.bounds = gfx::Rect(0, 0, 200, 200); 731 params.bounds = gfx::Rect(0, 0, 200, 200);
756 params.context = CurrentContext(); 732 params.context = CurrentContext();
757 widget->Init(params); 733 widget->Init(params);
758 widget->Show(); 734 widget->Show();
759 widget->Maximize(); 735 widget->Maximize();
760 736
761 aura::Window* window = widget->GetNativeWindow(); 737 aura::Window* window = widget->GetNativeWindow();
762 738
763 gfx::Rect shelf_shown = shelf->launcher_widget()->GetWindowBoundsInScreen(); 739 gfx::Rect shelf_shown = GetShelfWidget()->GetWindowBoundsInScreen();
764 gfx::Rect bounds_shelf = window->bounds(); 740 gfx::Rect bounds_shelf = window->bounds();
765 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); 741 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
766 742
767 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 743 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
768 744
769 // Swipe up on the shelf. This should not change any state. 745 // Swipe up on the shelf. This should not change any state.
770 gfx::Point start = 746 gfx::Point start = GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint();
771 shelf->launcher_widget()->GetWindowBoundsInScreen().CenterPoint();
772 gfx::Point end(start.x(), start.y() + 100); 747 gfx::Point end(start.x(), start.y() + 100);
773 748
774 // Swipe down on the shelf to hide it. 749 // Swipe down on the shelf to hide it.
775 end.set_y(start.y() + 100); 750 end.set_y(start.y() + 100);
776 generator.GestureScrollSequence(start, end, 751 generator.GestureScrollSequence(start, end,
777 base::TimeDelta::FromMilliseconds(10), 1); 752 base::TimeDelta::FromMilliseconds(10), 1);
778 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); 753 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
779 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); 754 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
780 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); 755 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
781 EXPECT_NE(bounds_shelf.ToString(), window->bounds().ToString()); 756 EXPECT_NE(bounds_shelf.ToString(), window->bounds().ToString());
782 EXPECT_NE(shelf_shown.ToString(), 757 EXPECT_NE(shelf_shown.ToString(),
783 shelf->launcher_widget()->GetWindowBoundsInScreen().ToString()); 758 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
784 759
785 gfx::Rect bounds_noshelf = window->bounds(); 760 gfx::Rect bounds_noshelf = window->bounds();
786 gfx::Rect shelf_hidden = shelf->launcher_widget()->GetWindowBoundsInScreen(); 761 gfx::Rect shelf_hidden = GetShelfWidget()->GetWindowBoundsInScreen();
787 762
788 // Swipe up to show the shelf. 763 // Swipe up to show the shelf.
789 generator.GestureScrollSequence(end, start, 764 generator.GestureScrollSequence(end, start,
790 base::TimeDelta::FromMilliseconds(10), 1); 765 base::TimeDelta::FromMilliseconds(10), 1);
791 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); 766 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
792 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior()); 767 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
793 EXPECT_EQ(bounds_shelf.ToString(), window->bounds().ToString()); 768 EXPECT_EQ(bounds_shelf.ToString(), window->bounds().ToString());
794 EXPECT_EQ(shelf_shown.ToString(), 769 EXPECT_EQ(shelf_shown.ToString(),
795 shelf->launcher_widget()->GetWindowBoundsInScreen().ToString()); 770 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
796 771
797 // Swipe up again. The shelf should hide. 772 // Swipe up again. The shelf should hide.
798 end.set_y(start.y() - 100); 773 end.set_y(start.y() - 100);
799 generator.GestureScrollSequence(start, end, 774 generator.GestureScrollSequence(start, end,
800 base::TimeDelta::FromMilliseconds(10), 1); 775 base::TimeDelta::FromMilliseconds(10), 1);
801 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); 776 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
802 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); 777 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
803 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); 778 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
804 EXPECT_EQ(shelf_hidden.ToString(), 779 EXPECT_EQ(shelf_hidden.ToString(),
805 shelf->launcher_widget()->GetWindowBoundsInScreen().ToString()); 780 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
806 781
807 // Swipe up yet again to show it. 782 // Swipe up yet again to show it.
808 end.set_y(start.y() + 100); 783 end.set_y(start.y() + 100);
809 generator.GestureScrollSequence(end, start, 784 generator.GestureScrollSequence(end, start,
810 base::TimeDelta::FromMilliseconds(10), 1); 785 base::TimeDelta::FromMilliseconds(10), 1);
811 786
812 // Swipe down very little. It shouldn't change any state. 787 // Swipe down very little. It shouldn't change any state.
813 end.set_y(start.y() + shelf_shown.height() * 3 / 10); 788 end.set_y(start.y() + shelf_shown.height() * 3 / 10);
814 generator.GestureScrollSequence(start, end, 789 generator.GestureScrollSequence(start, end,
815 base::TimeDelta::FromMilliseconds(100), 1); 790 base::TimeDelta::FromMilliseconds(100), 1);
816 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); 791 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
817 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior()); 792 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
818 EXPECT_EQ(bounds_shelf.ToString(), window->bounds().ToString()); 793 EXPECT_EQ(bounds_shelf.ToString(), window->bounds().ToString());
819 EXPECT_EQ(shelf_shown.ToString(), 794 EXPECT_EQ(shelf_shown.ToString(),
820 shelf->launcher_widget()->GetWindowBoundsInScreen().ToString()); 795 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
821 796
822 // Swipe down again to hide. 797 // Swipe down again to hide.
823 end.set_y(start.y() + 100); 798 end.set_y(start.y() + 100);
824 generator.GestureScrollSequence(start, end, 799 generator.GestureScrollSequence(start, end,
825 base::TimeDelta::FromMilliseconds(10), 1); 800 base::TimeDelta::FromMilliseconds(10), 1);
826 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state()); 801 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
827 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); 802 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
828 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); 803 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
829 EXPECT_EQ(bounds_noshelf.ToString(), window->bounds().ToString()); 804 EXPECT_EQ(bounds_noshelf.ToString(), window->bounds().ToString());
830 EXPECT_EQ(shelf_hidden.ToString(), 805 EXPECT_EQ(shelf_hidden.ToString(),
831 shelf->launcher_widget()->GetWindowBoundsInScreen().ToString()); 806 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
832 807
833 // Swipe up yet again to show it. 808 // Swipe up yet again to show it.
834 end.set_y(start.y() + 100); 809 end.set_y(start.y() + 100);
835 generator.GestureScrollSequence(end, start, 810 generator.GestureScrollSequence(end, start,
836 base::TimeDelta::FromMilliseconds(10), 1); 811 base::TimeDelta::FromMilliseconds(10), 1);
837 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state()); 812 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
838 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior()); 813 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
839 814
840 // Tap on the shelf itself. This should not change anything. 815 // Tap on the shelf itself. This should not change anything.
841 generator.GestureTapAt(start); 816 generator.GestureTapAt(start);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 CreateTestWidget(); 900 CreateTestWidget();
926 901
927 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 902 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
928 SystemTray* tray = GetSystemTray(); 903 SystemTray* tray = GetSystemTray();
929 904
930 // First, make sure the shelf is visible. 905 // First, make sure the shelf is visible.
931 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); 906 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
932 EXPECT_FALSE(tray->HasSystemBubble()); 907 EXPECT_FALSE(tray->HasSystemBubble());
933 908
934 // Now, drag up on the tray to show the bubble. 909 // Now, drag up on the tray to show the bubble.
935 gfx::Point start = 910 gfx::Point start = GetShelfWidget()->status_area_widget()->
936 shelf->status_area_widget()->GetWindowBoundsInScreen().CenterPoint(); 911 GetWindowBoundsInScreen().CenterPoint();
937 gfx::Point end(start.x(), start.y() - 100); 912 gfx::Point end(start.x(), start.y() - 100);
938 generator.GestureScrollSequence(start, end, 913 generator.GestureScrollSequence(start, end,
939 base::TimeDelta::FromMilliseconds(10), 1); 914 base::TimeDelta::FromMilliseconds(10), 1);
940 EXPECT_TRUE(tray->HasSystemBubble()); 915 EXPECT_TRUE(tray->HasSystemBubble());
941 tray->CloseBubbleForTest(); 916 tray->CloseBubbleForTest();
942 RunAllPendingInMessageLoop(); 917 RunAllPendingInMessageLoop();
943 EXPECT_FALSE(tray->HasSystemBubble()); 918 EXPECT_FALSE(tray->HasSystemBubble());
944 919
945 // Drag again, but only a small amount, and slowly. The bubble should not be 920 // Drag again, but only a small amount, and slowly. The bubble should not be
946 // visible. 921 // visible.
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 // Confirm that the shelf is dimmed only when content is maximized and 1024 // Confirm that the shelf is dimmed only when content is maximized and
1050 // shelf is not autohidden. 1025 // shelf is not autohidden.
1051 TEST_F(ShelfLayoutManagerTest, Dimming) { 1026 TEST_F(ShelfLayoutManagerTest, Dimming) {
1052 GetShelfLayoutManager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); 1027 GetShelfLayoutManager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1053 scoped_ptr<aura::Window> w1(CreateTestWindow()); 1028 scoped_ptr<aura::Window> w1(CreateTestWindow());
1054 w1->Show(); 1029 w1->Show();
1055 wm::ActivateWindow(w1.get()); 1030 wm::ActivateWindow(w1.get());
1056 1031
1057 // Normal window doesn't dim shelf. 1032 // Normal window doesn't dim shelf.
1058 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 1033 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
1059 Launcher* launcher = Launcher::ForPrimaryDisplay(); 1034 ShelfWidget* shelf = GetShelfWidget();
1060 EXPECT_FALSE(launcher->GetDimsShelf()); 1035 EXPECT_FALSE(shelf->GetDimsShelf());
1061 1036
1062 // Maximized window does. 1037 // Maximized window does.
1063 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 1038 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
1064 EXPECT_TRUE(launcher->GetDimsShelf()); 1039 EXPECT_TRUE(shelf->GetDimsShelf());
1065 1040
1066 // Change back to normal stops dimming. 1041 // Change back to normal stops dimming.
1067 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 1042 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
1068 EXPECT_FALSE(launcher->GetDimsShelf()); 1043 EXPECT_FALSE(shelf->GetDimsShelf());
1069 1044
1070 // Changing back to maximized dims again. 1045 // Changing back to maximized dims again.
1071 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 1046 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
1072 EXPECT_TRUE(launcher->GetDimsShelf()); 1047 EXPECT_TRUE(shelf->GetDimsShelf());
1073 1048
1074 // Changing shelf to autohide stops dimming. 1049 // Changing shelf to autohide stops dimming.
1075 GetShelfLayoutManager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 1050 GetShelfLayoutManager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1076 EXPECT_FALSE(launcher->GetDimsShelf()); 1051 EXPECT_FALSE(shelf->GetDimsShelf());
1077 } 1052 }
1078 1053
1079 // Make sure that the shelf will not hide if the mouse is between a bubble and 1054 // Make sure that the shelf will not hide if the mouse is between a bubble and
1080 // the shelf. 1055 // the shelf.
1081 TEST_F(ShelfLayoutManagerTest, BubbleEnlargesShelfMouseHitArea) { 1056 TEST_F(ShelfLayoutManagerTest, BubbleEnlargesShelfMouseHitArea) {
1082 ShelfLayoutManager* shelf = GetShelfLayoutManager(); 1057 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1083 StatusAreaWidget* status_area_widget = 1058 StatusAreaWidget* status_area_widget =
1084 Shell::GetPrimaryRootWindowController()->status_area_widget(); 1059 Shell::GetPrimaryRootWindowController()->shelf()->status_area_widget();
1085 SystemTray* tray = GetSystemTray(); 1060 SystemTray* tray = GetSystemTray();
1086 1061
1087 // Create a visible window so auto-hide behavior is enforced. 1062 // Create a visible window so auto-hide behavior is enforced.
1088 CreateTestWidget(); 1063 CreateTestWidget();
1089 1064
1090 shelf->LayoutShelf(); 1065 shelf->LayoutShelf();
1091 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 1066 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1092 1067
1093 // Make two iterations - first without a message bubble which should make 1068 // Make two iterations - first without a message bubble which should make
1094 // the shelf disappear and then with a message bubble which should keep it 1069 // the shelf disappear and then with a message bubble which should keep it
(...skipping 28 matching lines...) Expand all
1123 EXPECT_TRUE(status_area_widget->IsMessageBubbleShown()); 1098 EXPECT_TRUE(status_area_widget->IsMessageBubbleShown());
1124 } else { 1099 } else {
1125 EXPECT_FALSE(shelf->IsVisible()); 1100 EXPECT_FALSE(shelf->IsVisible());
1126 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown()); 1101 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
1127 } 1102 }
1128 } 1103 }
1129 } 1104 }
1130 1105
1131 } // namespace internal 1106 } // namespace internal
1132 } // namespace ash 1107 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698