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