zoom_bubble_view_browsertest.cc revision a36e5920737c6adbddd3e43b760e5de8431db6e0
1// Copyright 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 20class 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// TODO(linux_aura) http://crbug.com/163931 34#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA) 35#define MAYBE_NonImmersiveFullscreen DISABLED_NonImmersiveFullscreen 36#else 37#define MAYBE_NonImmersiveFullscreen NonImmersiveFullscreen 38#endif 39// Test whether the zoom bubble is anchored and whether it is visible when in 40// non-immersive fullscreen. 41IN_PROC_BROWSER_TEST_F(ZoomBubbleBrowserTest, MAYBE_NonImmersiveFullscreen) { 42 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); 43 content::WebContents* web_contents = browser_view->GetActiveWebContents(); 44 45 // The zoom bubble should be anchored when not in fullscreen. 46 ZoomBubbleView::ShowBubble(web_contents, true); 47 ASSERT_TRUE(ZoomBubbleView::IsShowing()); 48 const ZoomBubbleView* zoom_bubble = ZoomBubbleView::GetZoomBubbleForTest(); 49 EXPECT_TRUE(zoom_bubble->anchor_view()); 50 51 // Entering fullscreen should close the bubble. (We enter into tab fullscreen 52 // here because tab fullscreen is non-immersive even when 53 // ImmersiveFullscreenConfiguration::UseImmersiveFullscreen()) returns 54 // true. 55 { 56 // NOTIFICATION_FULLSCREEN_CHANGED is sent asynchronously. Wait for the 57 // notification before testing the zoom bubble visibility. 58 scoped_ptr<FullscreenNotificationObserver> waiter( 59 new FullscreenNotificationObserver()); 60 browser()->fullscreen_controller()->ToggleFullscreenModeForTab( 61 web_contents, true); 62 waiter->Wait(); 63 } 64 ASSERT_FALSE(browser_view->immersive_mode_controller()->IsEnabled()); 65 EXPECT_FALSE(ZoomBubbleView::IsShowing()); 66 67 // The bubble should not be anchored when it is shown in non-immersive 68 // fullscreen. 69 ZoomBubbleView::ShowBubble(web_contents, true); 70 ASSERT_TRUE(ZoomBubbleView::IsShowing()); 71 zoom_bubble = ZoomBubbleView::GetZoomBubbleForTest(); 72 EXPECT_FALSE(zoom_bubble->anchor_view()); 73 74 // Exit fullscreen before ending the test for the sake of sanity. 75 { 76 scoped_ptr<FullscreenNotificationObserver> waiter( 77 new FullscreenNotificationObserver()); 78 chrome::ToggleFullscreenMode(browser()); 79 waiter->Wait(); 80 } 81} 82 83// Immersive fullscreen is CrOS only for now. 84#if defined(OS_CHROMEOS) 85// Test whether the zoom bubble is anchored and whether it is visible when in 86// immersive fullscreen. 87IN_PROC_BROWSER_TEST_F(ZoomBubbleBrowserTest, ImmersiveFullscreen) { 88 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); 89 content::WebContents* web_contents = browser_view->GetActiveWebContents(); 90 91 ASSERT_TRUE(ImmersiveFullscreenConfiguration::UseImmersiveFullscreen()); 92 ImmersiveModeControllerAsh* immersive_controller = 93 static_cast<ImmersiveModeControllerAsh*>( 94 browser_view->immersive_mode_controller()); 95 immersive_controller->DisableAnimationsForTest(); 96 97 // Move the mouse out of the way. 98 immersive_controller->SetMouseHoveredForTest(false); 99 100 // Enter immersive fullscreen. 101 { 102 scoped_ptr<FullscreenNotificationObserver> waiter( 103 new FullscreenNotificationObserver()); 104 chrome::ToggleFullscreenMode(browser()); 105 waiter->Wait(); 106 } 107 ASSERT_TRUE(immersive_controller->IsEnabled()); 108 ASSERT_FALSE(immersive_controller->IsRevealed()); 109 110 // The zoom bubble should not be anchored when it is shown in immersive 111 // fullscreen and the top-of-window views are not revealed. 112 ZoomBubbleView::ShowBubble(web_contents, true); 113 ASSERT_TRUE(ZoomBubbleView::IsShowing()); 114 const ZoomBubbleView* zoom_bubble = ZoomBubbleView::GetZoomBubbleForTest(); 115 EXPECT_FALSE(zoom_bubble->anchor_view()); 116 117 // An immersive reveal should hide the zoom bubble. 118 scoped_ptr<ImmersiveRevealedLock> immersive_reveal_lock( 119 immersive_controller->GetRevealedLock( 120 ImmersiveModeController::ANIMATE_REVEAL_NO)); 121 ASSERT_TRUE(immersive_controller->IsRevealed()); 122 EXPECT_FALSE(ZoomBubbleView::IsShowing()); 123 124 // The zoom bubble should be anchored when it is shown in immersive fullscreen 125 // and the top-of-window views are revealed. 126 ZoomBubbleView::ShowBubble(web_contents, true); 127 ASSERT_TRUE(ZoomBubbleView::IsShowing()); 128 zoom_bubble = ZoomBubbleView::GetZoomBubbleForTest(); 129 EXPECT_TRUE(zoom_bubble->anchor_view()); 130 131 // The top-of-window views should not hide till the zoom bubble hides. (It 132 // would be weird if the view to which the zoom bubble is anchored hid while 133 // the zoom bubble was still visible.) 134 immersive_reveal_lock.reset(); 135 EXPECT_TRUE(immersive_controller->IsRevealed()); 136 ZoomBubbleView::CloseBubble(); 137 // The zoom bubble is deleted on a task. 138 content::RunAllPendingInMessageLoop(); 139 EXPECT_FALSE(immersive_controller->IsRevealed()); 140 141 // Exit fullscreen before ending the test for the sake of sanity. 142 { 143 scoped_ptr<FullscreenNotificationObserver> waiter( 144 new FullscreenNotificationObserver()); 145 chrome::ToggleFullscreenMode(browser()); 146 waiter->Wait(); 147 } 148} 149#endif // OS_CHROMEOS 150