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.
5 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h"
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"
15 typedef InProcessBrowserTest ZoomBubbleBrowserTest
;
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
21 #define MAYBE_NonImmersiveFullscreen NonImmersiveFullscreen
23 // Test whether the zoom bubble is anchored and whether it is visible when in
24 // non-immersive fullscreen.
25 IN_PROC_BROWSER_TEST_F(ZoomBubbleBrowserTest
, MAYBE_NonImmersiveFullscreen
) {
26 BrowserView
* browser_view
= static_cast<BrowserView
*>(browser()->window());
27 content::WebContents
* web_contents
= browser_view
->GetActiveWebContents();
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());
35 // Entering fullscreen should close the bubble. (We enter into tab fullscreen
36 // here because tab fullscreen is non-immersive even on Chrome OS.)
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(
46 ASSERT_FALSE(browser_view
->immersive_mode_controller()->IsEnabled());
47 EXPECT_FALSE(ZoomBubbleView::IsShowing());
49 // The bubble should not be anchored when it is shown in non-immersive
51 ZoomBubbleView::ShowBubble(web_contents
, true);
52 ASSERT_TRUE(ZoomBubbleView::IsShowing());
53 zoom_bubble
= ZoomBubbleView::GetZoomBubbleForTest();
54 EXPECT_FALSE(zoom_bubble
->GetAnchorView());
56 // Exit fullscreen before ending the test for the sake of sanity.
58 scoped_ptr
<FullscreenNotificationObserver
> waiter(
59 new FullscreenNotificationObserver());
60 chrome::ToggleFullscreenMode(browser());
65 // Immersive fullscreen is CrOS only for now.
66 #if defined(OS_CHROMEOS)
67 // Test whether the zoom bubble is anchored and whether it is visible when in
68 // immersive fullscreen.
69 IN_PROC_BROWSER_TEST_F(ZoomBubbleBrowserTest
, ImmersiveFullscreen
) {
70 BrowserView
* browser_view
= static_cast<BrowserView
*>(browser()->window());
71 content::WebContents
* web_contents
= browser_view
->GetActiveWebContents();
73 ImmersiveModeController
* immersive_controller
=
74 browser_view
->immersive_mode_controller();
75 immersive_controller
->SetupForTest();
77 // Enter immersive fullscreen.
79 scoped_ptr
<FullscreenNotificationObserver
> waiter(
80 new FullscreenNotificationObserver());
81 chrome::ToggleFullscreenMode(browser());
84 ASSERT_TRUE(immersive_controller
->IsEnabled());
85 ASSERT_FALSE(immersive_controller
->IsRevealed());
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());
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());
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());
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());
118 // Exit fullscreen before ending the test for the sake of sanity.
120 scoped_ptr
<FullscreenNotificationObserver
> waiter(
121 new FullscreenNotificationObserver());
122 chrome::ToggleFullscreenMode(browser());
126 #endif // OS_CHROMEOS