1 // Copyright (c) 2012 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 "base/compiler_specific.h"
6 #include "base/strings/utf_string_conversions.h"
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_commands.h"
9 #include "chrome/browser/ui/browser_tabstrip.h"
10 #include "chrome/browser/ui/browser_window.h"
11 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
12 #include "chrome/browser/ui/fullscreen/fullscreen_controller_test.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/test/base/ui_test_utils.h"
15 #include "content/public/browser/render_view_host.h"
16 #include "content/public/browser/web_contents.h"
17 #include "content/public/common/url_constants.h"
18 #include "content/public/test/test_navigation_observer.h"
19 #if defined(OS_MACOSX)
20 #include "base/mac/mac_util.h"
23 using content::kAboutBlankURL
;
24 using content::WebContents
;
25 using content::PAGE_TRANSITION_TYPED
;
27 class FullscreenControllerBrowserTest
: public FullscreenControllerTest
{
30 IN_PROC_BROWSER_TEST_F(FullscreenControllerTest
,
31 PendingMouseLockExitsOnTabSwitch
) {
32 AddTabAtIndex(0, GURL(kAboutBlankURL
), PAGE_TRANSITION_TYPED
);
33 AddTabAtIndex(0, GURL(kAboutBlankURL
), PAGE_TRANSITION_TYPED
);
34 WebContents
* tab1
= browser()->tab_strip_model()->GetActiveWebContents();
36 // Request mouse lock. Bubble is displayed.
37 RequestToLockMouse(true, false);
38 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
40 // Activate current tab. Mouse lock bubble remains.
41 browser()->tab_strip_model()->ActivateTabAt(0, true);
42 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
44 // Activate second tab. Mouse lock bubble clears.
46 MouseLockNotificationObserver mouse_lock_observer
;
47 browser()->tab_strip_model()->ActivateTabAt(1, true);
48 mouse_lock_observer
.Wait();
50 ASSERT_FALSE(IsFullscreenBubbleDisplayed());
52 // Now, test that closing an unrelated tab does not disturb a request.
54 // Request mouse lock. Bubble is displayed.
55 RequestToLockMouse(true, false);
56 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
58 // Close first tab while second active. Mouse lock bubble remains.
59 chrome::CloseWebContents(browser(), tab1
, false);
60 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
63 IN_PROC_BROWSER_TEST_F(FullscreenControllerTest
,
64 PendingMouseLockExitsOnTabClose
) {
66 AddTabAtIndex(0, GURL(kAboutBlankURL
), PAGE_TRANSITION_TYPED
);
67 AddTabAtIndex(0, GURL(kAboutBlankURL
), PAGE_TRANSITION_TYPED
);
69 // Request mouse lock. Bubble is displayed.
70 RequestToLockMouse(true, false);
71 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
73 // Close tab. Bubble is cleared.
75 MouseLockNotificationObserver mouse_lock_observer
;
76 chrome::CloseTab(browser());
77 mouse_lock_observer
.Wait();
79 ASSERT_FALSE(IsFullscreenBubbleDisplayed());