OLD | NEW |
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 "ash/wm/window_util.h" |
13 #include "base/command_line.h" | 14 #include "base/command_line.h" |
14 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
15 #include "chrome/browser/bookmarks/bookmark_model.h" | 16 #include "chrome/browser/bookmarks/bookmark_model.h" |
16 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 17 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
17 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h" | 18 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h" |
18 #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_manager.h" | 19 #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_manager.h" |
19 #include "chrome/browser/ui/browser_commands.h" | 20 #include "chrome/browser/ui/browser_commands.h" |
20 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" | 21 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" |
21 #include "chrome/browser/ui/views/browser_dialogs.h" | 22 #include "chrome/browser/ui/views/browser_dialogs.h" |
22 #include "chrome/browser/ui/views/frame/browser_view.h" | 23 #include "chrome/browser/ui/views/frame/browser_view.h" |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 EXPECT_TRUE(controller->IsRevealed()); | 263 EXPECT_TRUE(controller->IsRevealed()); |
263 chrome::HideBookmarkBubbleView(); | 264 chrome::HideBookmarkBubbleView(); |
264 EXPECT_FALSE(controller->IsRevealed()); | 265 EXPECT_FALSE(controller->IsRevealed()); |
265 | 266 |
266 // 4) Test that focusing the web contents hides the top-of-window views. | 267 // 4) Test that focusing the web contents hides the top-of-window views. |
267 browser_view->SetFocusToLocationBar(false); | 268 browser_view->SetFocusToLocationBar(false); |
268 EXPECT_TRUE(controller->IsRevealed()); | 269 EXPECT_TRUE(controller->IsRevealed()); |
269 browser_view->GetTabContentsContainerView()->RequestFocus(); | 270 browser_view->GetTabContentsContainerView()->RequestFocus(); |
270 EXPECT_FALSE(controller->IsRevealed()); | 271 EXPECT_FALSE(controller->IsRevealed()); |
271 | 272 |
272 // 5) Test that a dialog opened by the web contents does not initiate a | 273 // 5) Test that a loss of focus of the location bar to the web contents |
| 274 // while immersive mode is disabled is properly registered. |
| 275 browser_view->SetFocusToLocationBar(false); |
| 276 EXPECT_TRUE(controller->IsRevealed()); |
| 277 chrome::ToggleFullscreenMode(browser()); |
| 278 EXPECT_FALSE(controller->IsEnabled()); |
| 279 EXPECT_FALSE(controller->IsRevealed()); |
| 280 browser_view->GetTabContentsContainerView()->RequestFocus(); |
| 281 chrome::ToggleFullscreenMode(browser()); |
| 282 EXPECT_TRUE(controller->IsEnabled()); |
| 283 EXPECT_FALSE(controller->IsRevealed()); |
| 284 |
| 285 // Repeat test but with a revealed lock acquired when immersive mode is |
| 286 // enabled because the code path is different. |
| 287 browser_view->SetFocusToLocationBar(false); |
| 288 EXPECT_TRUE(controller->IsRevealed()); |
| 289 chrome::ToggleFullscreenMode(browser()); |
| 290 scoped_ptr<ImmersiveModeController::RevealedLock> lock( |
| 291 controller->GetRevealedLock()); |
| 292 EXPECT_FALSE(controller->IsRevealed()); |
| 293 browser_view->GetTabContentsContainerView()->RequestFocus(); |
| 294 chrome::ToggleFullscreenMode(browser()); |
| 295 EXPECT_TRUE(controller->IsRevealed()); |
| 296 lock.reset(); |
| 297 EXPECT_FALSE(controller->IsRevealed()); |
| 298 |
| 299 // 6) Test that a dialog opened by the web contents does not initiate a |
273 // reveal. | 300 // reveal. |
274 AppModalDialogQueue* queue = AppModalDialogQueue::GetInstance(); | 301 AppModalDialogQueue* queue = AppModalDialogQueue::GetInstance(); |
275 EXPECT_FALSE(queue->HasActiveDialog()); | 302 EXPECT_FALSE(queue->HasActiveDialog()); |
276 content::WebContents* web_contents = browser_view->GetActiveWebContents(); | 303 content::WebContents* web_contents = browser_view->GetActiveWebContents(); |
277 GetJavaScriptDialogManagerInstance()->RunBeforeUnloadDialog( | 304 GetJavaScriptDialogManagerInstance()->RunBeforeUnloadDialog( |
278 web_contents, | 305 web_contents, |
279 string16(), | 306 string16(), |
280 false, | 307 false, |
281 base::Bind( | 308 base::Bind( |
282 &ImmersiveModeControllerAshTest::OnBeforeUnloadJavaScriptDialogClosed, | 309 &ImmersiveModeControllerAshTest::OnBeforeUnloadJavaScriptDialogClosed, |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); | 447 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); |
421 ImmersiveModeControllerAsh* controller = | 448 ImmersiveModeControllerAsh* controller = |
422 static_cast<ImmersiveModeControllerAsh*>( | 449 static_cast<ImmersiveModeControllerAsh*>( |
423 browser_view->immersive_mode_controller()); | 450 browser_view->immersive_mode_controller()); |
424 | 451 |
425 chrome::ToggleFullscreenMode(browser()); | 452 chrome::ToggleFullscreenMode(browser()); |
426 ASSERT_TRUE(controller->IsEnabled()); | 453 ASSERT_TRUE(controller->IsEnabled()); |
427 | 454 |
428 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 455 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
429 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 456 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 457 params.parent = browser_view->GetNativeWindow(); |
430 params.bounds = kInitialBounds; | 458 params.bounds = kInitialBounds; |
431 views::Widget anchored_widget; | 459 views::Widget anchored_widget; |
432 anchored_widget.Init(params); | 460 anchored_widget.Init(params); |
433 | 461 |
434 // 1) Test that an anchored widget does not cause the top-of-window views to | 462 // 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 | 463 // reveal but instead prolongs the duration of the reveal till either the |
436 // widget is unanchored or is hidden. | 464 // widget is unanchored or is hidden. |
437 EXPECT_FALSE(controller->IsRevealed()); | 465 EXPECT_FALSE(controller->IsRevealed()); |
438 | 466 |
439 anchored_widget.Show(); | 467 anchored_widget.Show(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 // reposition the anchored widget. | 525 // reposition the anchored widget. |
498 chrome::ExecuteCommand(browser(), IDC_SHOW_BOOKMARK_BAR); | 526 chrome::ExecuteCommand(browser(), IDC_SHOW_BOOKMARK_BAR); |
499 EXPECT_TRUE(browser_view->IsBookmarkBarVisible()); | 527 EXPECT_TRUE(browser_view->IsBookmarkBarVisible()); |
500 gfx::Rect bounds3 = anchored_widget.GetWindowBoundsInScreen(); | 528 gfx::Rect bounds3 = anchored_widget.GetWindowBoundsInScreen(); |
501 EXPECT_EQ(bounds3.y(), | 529 EXPECT_EQ(bounds3.y(), |
502 browser_view->top_container()->GetBoundsInScreen().bottom() + 10); | 530 browser_view->top_container()->GetBoundsInScreen().bottom() + 10); |
503 EXPECT_GT(bounds3.y(), bounds2.y()); | 531 EXPECT_GT(bounds3.y(), bounds2.y()); |
504 EXPECT_EQ(kInitialBounds.x(), bounds3.x()); | 532 EXPECT_EQ(kInitialBounds.x(), bounds3.x()); |
505 EXPECT_EQ(kInitialBounds.size(), bounds3.size()); | 533 EXPECT_EQ(kInitialBounds.size(), bounds3.size()); |
506 | 534 |
| 535 // 3) Test that the anchored widget is not repositioned when immersive mode |
| 536 // is not enabled. |
| 537 chrome::ToggleFullscreenMode(browser()); |
| 538 ASSERT_FALSE(controller->IsEnabled()); |
| 539 chrome::ExecuteCommand(browser(), IDC_SHOW_BOOKMARK_BAR); |
| 540 EXPECT_EQ(bounds3, anchored_widget.GetWindowBoundsInScreen()); |
| 541 EXPECT_NE(browser_view->top_container()->GetBoundsInScreen().bottom() + 10, |
| 542 bounds3.bottom()); |
| 543 |
| 544 // 4) Test that reenabling immersive fullscreen repositions any anchored |
| 545 // widgets. |
| 546 // |
| 547 // Maximize the window so that a bounds change in the top container is not |
| 548 // reported when entering immersive fullscreen. The top container has the |
| 549 // same bounds when |browser_view| is maximized as when the top container is |
| 550 // revealed when |browser_view_| is in immersive mode. |
| 551 ash::wm::MaximizeWindow(browser_view->GetNativeWindow()); |
| 552 chrome::ToggleFullscreenMode(browser()); |
| 553 ASSERT_TRUE(controller->IsEnabled()); |
| 554 |
| 555 gfx::Rect bounds4 = anchored_widget.GetWindowBoundsInScreen(); |
| 556 EXPECT_NE(bounds3, bounds4); |
| 557 EXPECT_EQ(bounds4.y(), |
| 558 browser_view->top_container()->GetBoundsInScreen().bottom() + 10); |
| 559 EXPECT_EQ(kInitialBounds.x(), bounds4.x()); |
| 560 EXPECT_EQ(kInitialBounds.size(), bounds4.size()); |
| 561 |
507 BookmarkBarView::DisableAnimationsForTesting(false); | 562 BookmarkBarView::DisableAnimationsForTesting(false); |
508 } | 563 } |
509 | 564 |
510 // Shelf-specific immersive mode tests. | 565 // Shelf-specific immersive mode tests. |
511 IN_PROC_BROWSER_TEST_F(ImmersiveModeControllerAshTest, ImmersiveShelf) { | 566 IN_PROC_BROWSER_TEST_F(ImmersiveModeControllerAshTest, ImmersiveShelf) { |
512 ui::ScopedAnimationDurationScaleMode zero_duration_mode( | 567 ui::ScopedAnimationDurationScaleMode zero_duration_mode( |
513 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); | 568 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); |
514 ASSERT_TRUE(chrome::UseImmersiveFullscreen()); | 569 ASSERT_TRUE(chrome::UseImmersiveFullscreen()); |
515 | 570 |
516 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); | 571 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 | 608 |
554 // Setting the window property directly toggles immersive mode. | 609 // Setting the window property directly toggles immersive mode. |
555 aura::Window* window = browser_view->GetWidget()->GetNativeWindow(); | 610 aura::Window* window = browser_view->GetWidget()->GetNativeWindow(); |
556 window->SetProperty(ash::internal::kImmersiveModeKey, true); | 611 window->SetProperty(ash::internal::kImmersiveModeKey, true); |
557 EXPECT_TRUE(immersive_controller->IsEnabled()); | 612 EXPECT_TRUE(immersive_controller->IsEnabled()); |
558 window->SetProperty(ash::internal::kImmersiveModeKey, false); | 613 window->SetProperty(ash::internal::kImmersiveModeKey, false); |
559 EXPECT_FALSE(immersive_controller->IsEnabled()); | 614 EXPECT_FALSE(immersive_controller->IsEnabled()); |
560 } | 615 } |
561 | 616 |
562 #endif // defined(OS_CHROMEOS) | 617 #endif // defined(OS_CHROMEOS) |
OLD | NEW |