OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" |
| 6 |
| 7 #include "chrome/browser/ui/browser_commands.h" |
| 8 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" |
| 9 #include "chrome/browser/ui/fullscreen/fullscreen_controller_test.h" |
| 10 #include "chrome/browser/ui/immersive_fullscreen_configuration.h" |
| 11 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 12 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" |
| 13 #include "chrome/test/base/in_process_browser_test.h" |
| 14 #include "chrome/test/base/ui_test_utils.h" |
| 15 |
| 16 #if defined(OS_CHROMEOS) |
| 17 #include "chrome/browser/ui/views/frame/immersive_mode_controller_ash.h" |
| 18 #endif |
| 19 |
| 20 class ZoomBubbleBrowserTest : public InProcessBrowserTest { |
| 21 public: |
| 22 ZoomBubbleBrowserTest() {} |
| 23 virtual ~ZoomBubbleBrowserTest() {} |
| 24 |
| 25 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 26 ImmersiveFullscreenConfiguration::EnableImmersiveFullscreenForTest(); |
| 27 } |
| 28 |
| 29 private: |
| 30 DISALLOW_COPY_AND_ASSIGN(ZoomBubbleBrowserTest); |
| 31 }; |
| 32 |
| 33 // Test whether the zoom bubble is anchored and whether it is visible when in |
| 34 // non-immersive fullscreen. |
| 35 IN_PROC_BROWSER_TEST_F(ZoomBubbleBrowserTest, NonImmersiveFullscreen) { |
| 36 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); |
| 37 content::WebContents* web_contents = browser_view->GetActiveWebContents(); |
| 38 |
| 39 // The zoom bubble should be anchored when not in fullscreen. |
| 40 ZoomBubbleView::ShowBubble(web_contents, false); |
| 41 ASSERT_TRUE(ZoomBubbleView::IsShowing()); |
| 42 const ZoomBubbleView* zoom_bubble = ZoomBubbleView::GetZoomBubbleForTest(); |
| 43 EXPECT_TRUE(zoom_bubble->anchor_view()); |
| 44 |
| 45 // NOTIFICATION_FULLSCREEN_CHANGED is sent asynchronously. Wait for the |
| 46 // notification before testing the zoom bubble visibility. |
| 47 scoped_ptr<FullscreenNotificationObserver> waiter( |
| 48 new FullscreenNotificationObserver()); |
| 49 |
| 50 // Entering fullscreen should close the bubble. (We enter into tab fullscreen |
| 51 // here because tab fullscreen is non-immersive even when |
| 52 // ImmersiveFullscreenConfiguration::UseImmersiveFullscreen()) returns |
| 53 // true. |
| 54 browser()->fullscreen_controller()->ToggleFullscreenModeForTab( |
| 55 web_contents, true); |
| 56 waiter->Wait(); |
| 57 ASSERT_FALSE(browser_view->immersive_mode_controller()->IsEnabled()); |
| 58 EXPECT_FALSE(ZoomBubbleView::IsShowing()); |
| 59 |
| 60 // The bubble should not be anchored when it is shown in non-immersive |
| 61 // fullscreen. |
| 62 ZoomBubbleView::ShowBubble(web_contents, false); |
| 63 ASSERT_TRUE(ZoomBubbleView::IsShowing()); |
| 64 zoom_bubble = ZoomBubbleView::GetZoomBubbleForTest(); |
| 65 EXPECT_FALSE(zoom_bubble->anchor_view()); |
| 66 } |
| 67 |
| 68 // Immersive fullscreen is CrOS only for now. |
| 69 #if defined(OS_CHROMEOS) |
| 70 // Test whether the zoom bubble is anchored and whether it is visible when in |
| 71 // immersive fullscreen. |
| 72 IN_PROC_BROWSER_TEST_F(ZoomBubbleBrowserTest, ImmersiveFullscreen) { |
| 73 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); |
| 74 content::WebContents* web_contents = browser_view->GetActiveWebContents(); |
| 75 |
| 76 ASSERT_TRUE(ImmersiveFullscreenConfiguration::UseImmersiveFullscreen()); |
| 77 ImmersiveModeControllerAsh* immersive_controller = |
| 78 static_cast<ImmersiveModeControllerAsh*>( |
| 79 browser_view->immersive_mode_controller()); |
| 80 immersive_controller->DisableAnimationsForTest(); |
| 81 |
| 82 // Move the mouse out of the way. |
| 83 immersive_controller->SetMouseHoveredForTest(false); |
| 84 |
| 85 // Enter immersive fullscreen. |
| 86 scoped_ptr<FullscreenNotificationObserver> waiter( |
| 87 new FullscreenNotificationObserver()); |
| 88 chrome::ToggleFullscreenMode(browser()); |
| 89 waiter->Wait(); |
| 90 ASSERT_TRUE(immersive_controller->IsEnabled()); |
| 91 ASSERT_FALSE(immersive_controller->IsRevealed()); |
| 92 |
| 93 // The zoom bubble should not be anchored when it is shown in immersive |
| 94 // fullscreen and the top-of-window views are not revealed. |
| 95 ZoomBubbleView::ShowBubble(web_contents, false); |
| 96 ASSERT_TRUE(ZoomBubbleView::IsShowing()); |
| 97 const ZoomBubbleView* zoom_bubble = ZoomBubbleView::GetZoomBubbleForTest(); |
| 98 EXPECT_FALSE(zoom_bubble->anchor_view()); |
| 99 |
| 100 // An immersive reveal should hide the zoom bubble. |
| 101 scoped_ptr<ImmersiveRevealedLock> immersive_reveal_lock( |
| 102 immersive_controller->GetRevealedLock( |
| 103 ImmersiveModeController::ANIMATE_REVEAL_NO)); |
| 104 ASSERT_TRUE(immersive_controller->IsRevealed()); |
| 105 EXPECT_FALSE(ZoomBubbleView::IsShowing()); |
| 106 |
| 107 // The zoom bubble should be anchored when it is shown in immersive fullscreen |
| 108 // and the top-of-window views are revealed. |
| 109 ZoomBubbleView::ShowBubble(web_contents, false); |
| 110 ASSERT_TRUE(ZoomBubbleView::IsShowing()); |
| 111 zoom_bubble = ZoomBubbleView::GetZoomBubbleForTest(); |
| 112 EXPECT_TRUE(zoom_bubble->anchor_view()); |
| 113 |
| 114 // The top-of-window views should not hide till the zoom bubble hides. (It |
| 115 // would be weird if the view to which the zoom bubble is anchored hid while |
| 116 // the zoom bubble was still visible.) |
| 117 immersive_reveal_lock.reset(); |
| 118 EXPECT_TRUE(immersive_controller->IsRevealed()); |
| 119 ZoomBubbleView::CloseBubble(); |
| 120 // The zoom bubble is deleted on a task. |
| 121 content::RunAllPendingInMessageLoop(); |
| 122 EXPECT_FALSE(immersive_controller->IsRevealed()); |
| 123 } |
| 124 #endif // OS_CHROMEOS |
OLD | NEW |