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

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: Rebased 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
420 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window());
421 ImmersiveModeControllerAsh* controller =
422 static_cast<ImmersiveModeControllerAsh*>(
423 browser_view->immersive_mode_controller());
424
425 chrome::ToggleFullscreenMode(browser());
426 ASSERT_TRUE(controller->IsEnabled());
427
428 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
429 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
430 params.bounds = kInitialBounds;
431 views::Widget anchored_widget;
432 anchored_widget.Init(params);
433
434 // 1) Test that an anchored widget does not cause the top-of-window views to
435 // reveal but instead prolongs the duration of the reveal till either the
436 // widget is unanchored or is hidden.
437 EXPECT_FALSE(controller->IsRevealed());
438
439 anchored_widget.Show();
440 controller->AnchorWidgetToTopContainer(&anchored_widget, 10);
441
442 // Anchoring a widget should not cause the top-of-window views to reveal.
443 EXPECT_FALSE(controller->IsRevealed());
444
445 controller->StartRevealForTest(true);
446 EXPECT_TRUE(controller->IsRevealed());
447
448 // Once the top-of-window views are revealed, the top-of-window views should
449 // stay revealed as long as there is a visible anchored widget (or something
450 // else like the mouse hover is keeping the top-of-window views revealed).
451 controller->SetMouseHoveredForTest(false);
452 EXPECT_TRUE(controller->IsRevealed());
453 anchored_widget.Hide();
454 EXPECT_FALSE(controller->IsRevealed());
455
456 anchored_widget.Show();
457 EXPECT_FALSE(controller->IsRevealed());
458 controller->StartRevealForTest(true);
459 EXPECT_TRUE(controller->IsRevealed());
460
461 controller->UnanchorWidgetFromTopContainer(&anchored_widget);
462 EXPECT_TRUE(controller->IsRevealed());
463 controller->SetMouseHoveredForTest(false);
464 EXPECT_FALSE(controller->IsRevealed());
465
466 // 2) Test that the anchored widget is repositioned to |y_offset| below
467 // the bottom of the top container when the top container bounds are changed.
468 //
469 // Make sure that the bookmark bar is hidden.
470 ui_test_utils::WaitForBookmarkModelToLoad(
471 BookmarkModelFactory::GetForProfile(browser()->profile()));
472 if (browser_view->IsBookmarkBarVisible())
473 chrome::ExecuteCommand(browser(), IDC_SHOW_BOOKMARK_BAR);
474 EXPECT_FALSE(browser_view->IsBookmarkBarVisible());
475
476 anchored_widget.SetBounds(kInitialBounds);
477
478 // Anchoring the widget should adjust the top-of-window bounds.
479 controller->AnchorWidgetToTopContainer(&anchored_widget, 10);
480 gfx::Rect bounds1 = anchored_widget.GetWindowBoundsInScreen();
481 EXPECT_EQ(bounds1.y(),
482 browser_view->top_container()->GetBoundsInScreen().bottom() + 10);
483 EXPECT_EQ(kInitialBounds.x(), bounds1.x());
484 EXPECT_EQ(kInitialBounds.size(), bounds1.size());
485
486 controller->StartRevealForTest(true);
487 gfx::Rect bounds2 = anchored_widget.GetWindowBoundsInScreen();
488
489 // The top-of-window bounds changed in the immersive reveal. |anchored_widget|
490 // should have been repositioned.
491 EXPECT_EQ(bounds2.y(),
492 browser_view->top_container()->GetBoundsInScreen().bottom() + 10);
493 EXPECT_EQ(kInitialBounds.x(), bounds2.x());
494 EXPECT_EQ(kInitialBounds.size(), bounds2.size());
495
496 // Showing the bookmark bar changes the top container bounds and should
497 // reposition the anchored widget.
498 chrome::ExecuteCommand(browser(), IDC_SHOW_BOOKMARK_BAR);
499 EXPECT_TRUE(browser_view->IsBookmarkBarVisible());
500 gfx::Rect bounds3 = anchored_widget.GetWindowBoundsInScreen();
501 EXPECT_EQ(bounds3.y(),
502 browser_view->top_container()->GetBoundsInScreen().bottom() + 10);
503 EXPECT_GT(bounds3.y(), bounds2.y());
504 EXPECT_EQ(kInitialBounds.x(), bounds3.x());
505 EXPECT_EQ(kInitialBounds.size(), bounds3.size());
506
507 BookmarkBarView::DisableAnimationsForTesting(false);
508 }
509
407 // Shelf-specific immersive mode tests. 510 // Shelf-specific immersive mode tests.
408 IN_PROC_BROWSER_TEST_F(ImmersiveModeControllerAshTest, ImmersiveShelf) { 511 IN_PROC_BROWSER_TEST_F(ImmersiveModeControllerAshTest, ImmersiveShelf) {
409 ui::ScopedAnimationDurationScaleMode zero_duration_mode( 512 ui::ScopedAnimationDurationScaleMode zero_duration_mode(
410 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); 513 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
411 ASSERT_TRUE(chrome::UseImmersiveFullscreen()); 514 ASSERT_TRUE(chrome::UseImmersiveFullscreen());
412 515
413 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); 516 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window());
414 ImmersiveModeControllerAsh* immersive_controller = 517 ImmersiveModeControllerAsh* immersive_controller =
415 static_cast<ImmersiveModeControllerAsh*>( 518 static_cast<ImmersiveModeControllerAsh*>(
416 browser_view->immersive_mode_controller()); 519 browser_view->immersive_mode_controller());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 553
451 // Setting the window property directly toggles immersive mode. 554 // Setting the window property directly toggles immersive mode.
452 aura::Window* window = browser_view->GetWidget()->GetNativeWindow(); 555 aura::Window* window = browser_view->GetWidget()->GetNativeWindow();
453 window->SetProperty(ash::internal::kImmersiveModeKey, true); 556 window->SetProperty(ash::internal::kImmersiveModeKey, true);
454 EXPECT_TRUE(immersive_controller->IsEnabled()); 557 EXPECT_TRUE(immersive_controller->IsEnabled());
455 window->SetProperty(ash::internal::kImmersiveModeKey, false); 558 window->SetProperty(ash::internal::kImmersiveModeKey, false);
456 EXPECT_FALSE(immersive_controller->IsEnabled()); 559 EXPECT_FALSE(immersive_controller->IsEnabled());
457 } 560 }
458 561
459 #endif // defined(OS_CHROMEOS) 562 #endif // defined(OS_CHROMEOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698