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/ui/views/frame/immersive_mode_controller_ash_browsertest.cc

Issue 13866026: Adds functionality to anchor widgets to the top-of-window views in immersive mode (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/frame/immersive_mode_controller_ash.h" 5 #include "chrome/browser/ui/views/frame/immersive_mode_controller_ash.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/root_window_controller.h" 8 #include "ash/root_window_controller.h"
9 #include "ash/shelf/shelf_layout_manager.h" 9 #include "ash/shelf/shelf_layout_manager.h"
10 #include "ash/shelf/shelf_types.h" 10 #include "ash/shelf/shelf_types.h"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "ash/wm/window_properties.h" 12 #include "ash/wm/window_properties.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "chrome/app/chrome_command_ids.h" 14 #include "chrome/app/chrome_command_ids.h"
15 #include "chrome/browser/bookmarks/bookmark_model.h" 15 #include "chrome/browser/bookmarks/bookmark_model.h"
16 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 16 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
17 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h" 17 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h"
18 #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_manager.h" 18 #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_manager.h"
19 #include "chrome/browser/ui/browser_commands.h" 19 #include "chrome/browser/ui/browser_commands.h"
20 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h"
20 #include "chrome/browser/ui/views/browser_dialogs.h" 21 #include "chrome/browser/ui/views/browser_dialogs.h"
21 #include "chrome/browser/ui/views/frame/browser_view.h" 22 #include "chrome/browser/ui/views/frame/browser_view.h"
23 #include "chrome/browser/ui/views/frame/top_container_view.h"
22 #include "chrome/browser/ui/views/tabs/tab.h" 24 #include "chrome/browser/ui/views/tabs/tab.h"
23 #include "chrome/browser/ui/views/tabs/tab_strip.h" 25 #include "chrome/browser/ui/views/tabs/tab_strip.h"
24 #include "chrome/test/base/in_process_browser_test.h" 26 #include "chrome/test/base/in_process_browser_test.h"
25 #include "chrome/test/base/ui_test_utils.h" 27 #include "chrome/test/base/ui_test_utils.h"
26 #include "content/public/browser/javascript_dialog_manager.h" 28 #include "content/public/browser/javascript_dialog_manager.h"
27 #include "ui/compositor/layer_animator.h" 29 #include "ui/compositor/layer_animator.h"
28 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 30 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
29 #include "ui/gfx/rect.h" 31 #include "ui/gfx/rect.h"
30 #include "ui/views/view.h" 32 #include "ui/views/view.h"
31 33
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 // 3) Test that the top-of-window views are only hidden when all of the locks 399 // 3) Test that the top-of-window views are only hidden when all of the locks
398 // are released. 400 // are released.
399 lock2.reset(controller->GetRevealedLock()); 401 lock2.reset(controller->GetRevealedLock());
400 lock1.reset(); 402 lock1.reset();
401 EXPECT_TRUE(controller->IsRevealed()); 403 EXPECT_TRUE(controller->IsRevealed());
402 404
403 lock2.reset(); 405 lock2.reset();
404 EXPECT_FALSE(controller->IsRevealed()); 406 EXPECT_FALSE(controller->IsRevealed());
405 } 407 }
406 408
409 // Test how changing the bounds of the top container repositions anchored
410 // widgets and how the visibility of anchored widgets affects whether the
411 // top-of-window views stay revealed.
412 IN_PROC_BROWSER_TEST_F(ImmersiveModeControllerAshTest, AnchoredWidgets) {
413 gfx::Rect kInitialBounds(100, 100, 100, 100);
414
415 ui::ScopedAnimationDurationScaleMode zero_duration_mode(
416 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
417 BookmarkBarView::DisableAnimationsForTesting(true);
418 ASSERT_TRUE(chrome::UseImmersiveFullscreen());
419 chrome::ToggleFullscreenMode(browser());
420
421 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window());
422 ImmersiveModeControllerAsh* controller =
423 static_cast<ImmersiveModeControllerAsh*>(
424 browser_view->immersive_mode_controller());
James Cook 2013/04/09 22:22:03 Consider asserting that immersive mode is enabled,
425
426 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
427 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
428 params.bounds = kInitialBounds;
429 views::Widget anchored_widget;
430 anchored_widget.Init(params);
431
432 // 1) Test that an anchored widget does not cause the top-of-window views to
433 // reveal but instead prolongs the duration of the reveal till either the
434 // widget is unanchored or is hidden.
435 EXPECT_FALSE(controller->IsRevealed());
436
437 anchored_widget.Show();
438 controller->AnchorWidgetToTopContainer(&anchored_widget, 10);
439
440 // Anchoring a widget should not cause the top-of-window views to reveal.
441 EXPECT_FALSE(controller->IsRevealed());
442
443 controller->StartRevealForTest(true);
444 EXPECT_TRUE(controller->IsRevealed());
445
446 // Once the top-of-window views are revealed, the top-of-window views should
447 // stay revealed as long as there is a visible anchored widget (or something
448 // else like the mouse hover is keeping the top-of-window views revealed).
449 controller->SetMouseHoveredForTest(false);
450 EXPECT_TRUE(controller->IsRevealed());
451 anchored_widget.Hide();
452 EXPECT_FALSE(controller->IsRevealed());
453
454 anchored_widget.Show();
455 EXPECT_FALSE(controller->IsRevealed());
456 controller->StartRevealForTest(true);
457 EXPECT_TRUE(controller->IsRevealed());
458
459 controller->UnanchorWidgetFromTopContainer(&anchored_widget);
460 EXPECT_TRUE(controller->IsRevealed());
461 controller->SetMouseHoveredForTest(false);
462 EXPECT_FALSE(controller->IsRevealed());
463
464 // 2) Test that the anchored widget is repositioned to |y_offset| below
465 // the bottom of the top container when the top container bounds are changed.
466 //
467 // Make sure that the bookmark bar is hidden.
468 ui_test_utils::WaitForBookmarkModelToLoad(
469 BookmarkModelFactory::GetForProfile(browser()->profile()));
470 if (browser_view->IsBookmarkBarVisible())
471 chrome::ExecuteCommand(browser(), IDC_SHOW_BOOKMARK_BAR);
472 EXPECT_FALSE(browser_view->IsBookmarkBarVisible());
473
474 anchored_widget.SetBounds(kInitialBounds);
475
476 // Anchoring the widget should adjust the top-of-window bounds.
477 controller->AnchorWidgetToTopContainer(&anchored_widget, 10);
478 gfx::Rect bounds1 = anchored_widget.GetWindowBoundsInScreen();
479 EXPECT_EQ(bounds1.y(),
480 browser_view->top_container()->GetBoundsInScreen().bottom() + 10);
481 EXPECT_EQ(kInitialBounds.x(), bounds1.x());
482 EXPECT_EQ(kInitialBounds.size(), bounds1.size());
483
484
James Cook 2013/04/09 22:22:03 nit: one blank line
485 controller->StartRevealForTest(true);
486 gfx::Rect bounds2 = anchored_widget.GetWindowBoundsInScreen();
487
488 // The top-of-window bounds changed in the immersive reveal. |anchored_widget|
489 // should have been repositioned.
490 EXPECT_EQ(bounds2.y(),
491 browser_view->top_container()->GetBoundsInScreen().bottom() + 10);
492 EXPECT_EQ(kInitialBounds.x(), bounds2.x());
493 EXPECT_EQ(kInitialBounds.size(), bounds2.size());
494
495 // Showing the bookmark bar changes the top container bounds and should
496 // reposition the anchored widget.
497 chrome::ExecuteCommand(browser(), IDC_SHOW_BOOKMARK_BAR);
498 EXPECT_TRUE(browser_view->IsBookmarkBarVisible());
499 gfx::Rect bounds3 = anchored_widget.GetWindowBoundsInScreen();
500 EXPECT_EQ(bounds3.y(),
501 browser_view->top_container()->GetBoundsInScreen().bottom() + 10);
502 EXPECT_GT(bounds3.y(), bounds2.y());
503 EXPECT_EQ(kInitialBounds.x(), bounds3.x());
504 EXPECT_EQ(kInitialBounds.size(), bounds3.size());
505
506 BookmarkBarView::DisableAnimationsForTesting(false);
507 }
James Cook 2013/04/09 22:22:03 Nice test!
508
407 // Shelf-specific immersive mode tests. 509 // Shelf-specific immersive mode tests.
408 IN_PROC_BROWSER_TEST_F(ImmersiveModeControllerAshTest, ImmersiveShelf) { 510 IN_PROC_BROWSER_TEST_F(ImmersiveModeControllerAshTest, ImmersiveShelf) {
409 ui::ScopedAnimationDurationScaleMode zero_duration_mode( 511 ui::ScopedAnimationDurationScaleMode zero_duration_mode(
410 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); 512 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
411 ASSERT_TRUE(chrome::UseImmersiveFullscreen()); 513 ASSERT_TRUE(chrome::UseImmersiveFullscreen());
412 514
413 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); 515 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window());
414 ImmersiveModeControllerAsh* immersive_controller = 516 ImmersiveModeControllerAsh* immersive_controller =
415 static_cast<ImmersiveModeControllerAsh*>( 517 static_cast<ImmersiveModeControllerAsh*>(
416 browser_view->immersive_mode_controller()); 518 browser_view->immersive_mode_controller());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 552
451 // Setting the window property directly toggles immersive mode. 553 // Setting the window property directly toggles immersive mode.
452 aura::Window* window = browser_view->GetWidget()->GetNativeWindow(); 554 aura::Window* window = browser_view->GetWidget()->GetNativeWindow();
453 window->SetProperty(ash::internal::kImmersiveModeKey, true); 555 window->SetProperty(ash::internal::kImmersiveModeKey, true);
454 EXPECT_TRUE(immersive_controller->IsEnabled()); 556 EXPECT_TRUE(immersive_controller->IsEnabled());
455 window->SetProperty(ash::internal::kImmersiveModeKey, false); 557 window->SetProperty(ash::internal::kImmersiveModeKey, false);
456 EXPECT_FALSE(immersive_controller->IsEnabled()); 558 EXPECT_FALSE(immersive_controller->IsEnabled());
457 } 559 }
458 560
459 #endif // defined(OS_CHROMEOS) 561 #endif // defined(OS_CHROMEOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698