zoom_bubble_view_browsertest.cc revision 23730a6e56a168d1879203e4b3819bb36e3d8f1f
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/views/frame/browser_view.h" 11#include "chrome/browser/ui/views/frame/immersive_mode_controller.h" 12#include "chrome/test/base/in_process_browser_test.h" 13#include "chrome/test/base/ui_test_utils.h" 14 15typedef InProcessBrowserTest ZoomBubbleBrowserTest; 16 17// TODO(linux_aura) http://crbug.com/163931 18#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA) 19#define MAYBE_NonImmersiveFullscreen DISABLED_NonImmersiveFullscreen 20#else 21#define MAYBE_NonImmersiveFullscreen NonImmersiveFullscreen 22#endif 23// Test whether the zoom bubble is anchored and whether it is visible when in 24// non-immersive fullscreen. 25IN_PROC_BROWSER_TEST_F(ZoomBubbleBrowserTest, MAYBE_NonImmersiveFullscreen) { 26 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); 27 content::WebContents* web_contents = browser_view->GetActiveWebContents(); 28 29 // The zoom bubble should be anchored when not in fullscreen. 30 ZoomBubbleView::ShowBubble(web_contents, true); 31 ASSERT_TRUE(ZoomBubbleView::IsShowing()); 32 const ZoomBubbleView* zoom_bubble = ZoomBubbleView::GetZoomBubbleForTest(); 33 EXPECT_TRUE(zoom_bubble->GetAnchorView()); 34 35 // Entering fullscreen should close the bubble. (We enter into tab fullscreen 36 // here because tab fullscreen is non-immersive even on Chrome OS.) 37 { 38 // NOTIFICATION_FULLSCREEN_CHANGED is sent asynchronously. Wait for the 39 // notification before testing the zoom bubble visibility. 40 scoped_ptr<FullscreenNotificationObserver> waiter( 41 new FullscreenNotificationObserver()); 42 browser()->fullscreen_controller()->ToggleFullscreenModeForTab( 43 web_contents, true); 44 waiter->Wait(); 45 } 46 ASSERT_FALSE(browser_view->immersive_mode_controller()->IsEnabled()); 47 EXPECT_FALSE(ZoomBubbleView::IsShowing()); 48 49 // The bubble should not be anchored when it is shown in non-immersive 50 // fullscreen. 51 ZoomBubbleView::ShowBubble(web_contents, true); 52 ASSERT_TRUE(ZoomBubbleView::IsShowing()); 53 zoom_bubble = ZoomBubbleView::GetZoomBubbleForTest(); 54 EXPECT_FALSE(zoom_bubble->GetAnchorView()); 55 56 // Exit fullscreen before ending the test for the sake of sanity. 57 { 58 scoped_ptr<FullscreenNotificationObserver> waiter( 59 new FullscreenNotificationObserver()); 60 chrome::ToggleFullscreenMode(browser()); 61 waiter->Wait(); 62 } 63} 64 65// TODO(zturner): Change this to USE_ASH after fixing the test on Windows. 66#if defined(OS_CHROMEOS) 67// Test whether the zoom bubble is anchored and whether it is visible when in 68// immersive fullscreen. 69IN_PROC_BROWSER_TEST_F(ZoomBubbleBrowserTest, ImmersiveFullscreen) { 70 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); 71 content::WebContents* web_contents = browser_view->GetActiveWebContents(); 72 73 ImmersiveModeController* immersive_controller = 74 browser_view->immersive_mode_controller(); 75 immersive_controller->SetupForTest(); 76 77 // Enter immersive fullscreen. 78 { 79 scoped_ptr<FullscreenNotificationObserver> waiter( 80 new FullscreenNotificationObserver()); 81 chrome::ToggleFullscreenMode(browser()); 82 waiter->Wait(); 83 } 84 ASSERT_TRUE(immersive_controller->IsEnabled()); 85 ASSERT_FALSE(immersive_controller->IsRevealed()); 86 87 // The zoom bubble should not be anchored when it is shown in immersive 88 // fullscreen and the top-of-window views are not revealed. 89 ZoomBubbleView::ShowBubble(web_contents, true); 90 ASSERT_TRUE(ZoomBubbleView::IsShowing()); 91 const ZoomBubbleView* zoom_bubble = ZoomBubbleView::GetZoomBubbleForTest(); 92 EXPECT_FALSE(zoom_bubble->GetAnchorView()); 93 94 // An immersive reveal should hide the zoom bubble. 95 scoped_ptr<ImmersiveRevealedLock> immersive_reveal_lock( 96 immersive_controller->GetRevealedLock( 97 ImmersiveModeController::ANIMATE_REVEAL_NO)); 98 ASSERT_TRUE(immersive_controller->IsRevealed()); 99 EXPECT_FALSE(ZoomBubbleView::IsShowing()); 100 101 // The zoom bubble should be anchored when it is shown in immersive fullscreen 102 // and the top-of-window views are revealed. 103 ZoomBubbleView::ShowBubble(web_contents, true); 104 ASSERT_TRUE(ZoomBubbleView::IsShowing()); 105 zoom_bubble = ZoomBubbleView::GetZoomBubbleForTest(); 106 EXPECT_TRUE(zoom_bubble->GetAnchorView()); 107 108 // The top-of-window views should not hide till the zoom bubble hides. (It 109 // would be weird if the view to which the zoom bubble is anchored hid while 110 // the zoom bubble was still visible.) 111 immersive_reveal_lock.reset(); 112 EXPECT_TRUE(immersive_controller->IsRevealed()); 113 ZoomBubbleView::CloseBubble(); 114 // The zoom bubble is deleted on a task. 115 content::RunAllPendingInMessageLoop(); 116 EXPECT_FALSE(immersive_controller->IsRevealed()); 117 118 // Exit fullscreen before ending the test for the sake of sanity. 119 { 120 scoped_ptr<FullscreenNotificationObserver> waiter( 121 new FullscreenNotificationObserver()); 122 chrome::ToggleFullscreenMode(browser()); 123 waiter->Wait(); 124 } 125} 126#endif // OS_CHROMEOS 127