From 47ea3b4c7b3779b96bfed645227b7ba8d0a66a02 Mon Sep 17 00:00:00 2001 From: "scheib@chromium.org" Date: Mon, 4 Jun 2012 17:30:26 +0000 Subject: Some Mouse Lock tests require the browser to have focus, they must be run from interactive_ui_tests. To reduce code duplication, the mouse lock and fullscreen convenience methods of the browser_browsertest have been moved to a reusable fixture in fullscreen_controller_test. BUG=130358 Review URL: https://chromiumcodereview.appspot.com/10459063 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140316 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/ui/browser.h | 4 +- chrome/browser/ui/browser_browsertest.cc | 654 --------------------- .../ui/fullscreen_controller_browsertest.cc | 267 +++++++++ ...ullscreen_controller_interactive_browsertest.cc | 320 ++++++++++ chrome/browser/ui/fullscreen_controller_test.cc | 116 ++++ chrome/browser/ui/fullscreen_controller_test.h | 63 ++ chrome/chrome_tests.gypi | 4 + 7 files changed, 773 insertions(+), 655 deletions(-) create mode 100644 chrome/browser/ui/fullscreen_controller_browsertest.cc create mode 100644 chrome/browser/ui/fullscreen_controller_interactive_browsertest.cc create mode 100644 chrome/browser/ui/fullscreen_controller_test.cc create mode 100644 chrome/browser/ui/fullscreen_controller_test.h diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h index 05a74418..fe5c1c01 100644 --- a/chrome/browser/ui/browser.h +++ b/chrome/browser/ui/browser.h @@ -833,12 +833,14 @@ class Browser : public TabStripModelDelegate, private: friend class BrowserTest; + friend class FullscreenControllerTest; FRIEND_TEST_ALL_PREFIXES(AppModeTest, EnableAppModeTest); FRIEND_TEST_ALL_PREFIXES(BrowserTest, NoTabsInPopups); FRIEND_TEST_ALL_PREFIXES(BrowserTest, ConvertTabToAppShortcut); FRIEND_TEST_ALL_PREFIXES(BrowserTest, OpenAppWindowLikeNtp); FRIEND_TEST_ALL_PREFIXES(BrowserTest, AppIdSwitch); - FRIEND_TEST_ALL_PREFIXES(BrowserTest, TabEntersPresentationModeFromWindowed); + FRIEND_TEST_ALL_PREFIXES(FullscreenControllerTest, + TabEntersPresentationModeFromWindowed); FRIEND_TEST_ALL_PREFIXES(FullscreenExitBubbleControllerTest, DenyExitsFullscreen); FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, OpenAppShortcutNoPref); diff --git a/chrome/browser/ui/browser_browsertest.cc b/chrome/browser/ui/browser_browsertest.cc index 6979f48..f2e63e0 100644 --- a/chrome/browser/ui/browser_browsertest.cc +++ b/chrome/browser/ui/browser_browsertest.cc @@ -33,8 +33,6 @@ #include "chrome/browser/ui/browser_navigator.h" #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/extensions/application_launch.h" -#include "chrome/browser/ui/fullscreen_controller.h" -#include "chrome/browser/ui/fullscreen_exit_bubble_type.h" #include "chrome/browser/ui/startup/startup_browser_creator.h" #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" @@ -93,15 +91,11 @@ const char* kOpenNewBeforeUnloadPage = const FilePath::CharType* kBeforeUnloadFile = FILE_PATH_LITERAL("beforeunload.html"); -const FilePath::CharType* kSimpleFile = FILE_PATH_LITERAL("simple.html"); const FilePath::CharType* kTitle1File = FILE_PATH_LITERAL("title1.html"); const FilePath::CharType* kTitle2File = FILE_PATH_LITERAL("title2.html"); const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); -const char* kFullscreenMouseLockHTML = - "files/fullscreen_mouselock/fullscreen_mouselock.html"; - // Given a page title, returns the expected window caption string. string16 WindowCaptionFromPageTitle(const string16& page_title) { #if defined(OS_MACOSX) || defined(OS_CHROMEOS) @@ -184,22 +178,6 @@ class TestInterstitialPage : public content::InterstitialPageDelegate { InterstitialPage* interstitial_page_; // Owns us. }; -class FullscreenNotificationObserver - : public ui_test_utils::WindowedNotificationObserver { - public: - FullscreenNotificationObserver() : WindowedNotificationObserver( - chrome::NOTIFICATION_FULLSCREEN_CHANGED, - content::NotificationService::AllSources()) {} -}; - -class MouseLockNotificationObserver - : public ui_test_utils::WindowedNotificationObserver { - public: - MouseLockNotificationObserver() : WindowedNotificationObserver( - chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, - content::NotificationService::AllSources()) {} -}; - } // namespace class BrowserTest : public ExtensionBrowserTest { @@ -239,110 +217,6 @@ class BrowserTest : public ExtensionBrowserTest { NOTREACHED(); return NULL; } - - void ToggleTabFullscreen(WebContents* tab, bool enter_fullscreen) { - if (IsFullscreenForBrowser()) { - // Changing tab fullscreen state will not actually change the window - // when browser fullscreen is in effect. - browser()->ToggleFullscreenModeForTab(tab, enter_fullscreen); - } else { // Not in browser fullscreen, expect window to actually change. - FullscreenNotificationObserver fullscreen_observer; - browser()->ToggleFullscreenModeForTab(tab, enter_fullscreen); - fullscreen_observer.Wait(); - ASSERT_EQ(browser()->window()->IsFullscreen(), enter_fullscreen); - } - } - - void ToggleBrowserFullscreen(bool enter_fullscreen) { - ASSERT_EQ(browser()->window()->IsFullscreen(), !enter_fullscreen); - FullscreenNotificationObserver fullscreen_observer; - - browser()->ToggleFullscreenMode(); - - fullscreen_observer.Wait(); - ASSERT_EQ(browser()->window()->IsFullscreen(), enter_fullscreen); - ASSERT_EQ(IsFullscreenForBrowser(), enter_fullscreen); - } - - void RequestToLockMouse(content::WebContents* tab, - bool user_gesture, - bool last_unlocked_by_target) { - browser()->RequestToLockMouse(tab, user_gesture, - last_unlocked_by_target); - } - - void LostMouseLock() { - browser()->LostMouseLock(); - } - - bool SendEscapeToFullscreenController() { - return browser()->fullscreen_controller_->HandleUserPressedEscape(); - } - - bool IsFullscreenForBrowser() { - return browser()->fullscreen_controller_->IsFullscreenForBrowser(); - } - - bool IsFullscreenForTabOrPending() { - return browser()->IsFullscreenForTabOrPending(); - } - - bool IsMouseLocked() { - // Verify that IsMouseLocked is consistent between the - // Fullscreen Controller and the Render View Host View. - EXPECT_TRUE(browser()->IsMouseLocked() == - browser()->GetSelectedWebContents()-> - GetRenderViewHost()->GetView()->IsMouseLocked()); - return browser()->IsMouseLocked(); - } - - bool IsMouseLockPermissionRequested() { - FullscreenExitBubbleType type = - browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); - bool mouse_lock = false; - fullscreen_bubble::PermissionRequestedByType(type, NULL, &mouse_lock); - return mouse_lock; - } - - bool IsFullscreenPermissionRequested() { - FullscreenExitBubbleType type = - browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); - bool fullscreen = false; - fullscreen_bubble::PermissionRequestedByType(type, &fullscreen, NULL); - return fullscreen; - } - - FullscreenExitBubbleType GetFullscreenExitBubbleType() { - return browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); - } - - bool IsFullscreenBubbleDisplayed() { - FullscreenExitBubbleType type = - browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); - return type != FEB_TYPE_NONE; - } - - bool IsFullscreenBubbleDisplayingButtons() { - FullscreenExitBubbleType type = - browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); - return fullscreen_bubble::ShowButtonsForType(type); - } - - void AcceptCurrentFullscreenOrMouseLockRequest() { - WebContents* fullscreen_tab = browser()->GetSelectedWebContents(); - FullscreenExitBubbleType type = - browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); - browser()->OnAcceptFullscreenPermission(fullscreen_tab->GetURL(), type); - } - - void DenyCurrentFullscreenOrMouseLockRequest() { - FullscreenExitBubbleType type = - browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); - browser()->OnDenyFullscreenPermission(type); - } - - // Helper method to be called by multiple tests. - void TestFullscreenMouseLockContentSettings(); }; // Launch the app on a page with no title, check that the app title was set @@ -1009,534 +883,6 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, PageLanguageDetection) { EXPECT_EQ("fr", helper->language_state().original_language()); } -#if defined(OS_MACOSX) -// http://crbug.com/104265 -#define MAYBE_TestNewTabExitsFullscreen DISABLED_TestNewTabExitsFullscreen -#else -#define MAYBE_TestNewTabExitsFullscreen TestNewTabExitsFullscreen -#endif - -// Tests that while in fullscreen creating a new tab will exit fullscreen. -IN_PROC_BROWSER_TEST_F(BrowserTest, MAYBE_TestNewTabExitsFullscreen) { - ASSERT_TRUE(test_server()->Start()); - - AddTabAtIndex( - 0, GURL(chrome::kAboutBlankURL), content::PAGE_TRANSITION_TYPED); - - WebContents* fullscreen_tab = browser()->GetSelectedWebContents(); - - ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(fullscreen_tab, true)); - - { - FullscreenNotificationObserver fullscreen_observer; - AddTabAtIndex( - 1, GURL(chrome::kAboutBlankURL), content::PAGE_TRANSITION_TYPED); - fullscreen_observer.Wait(); - ASSERT_FALSE(browser()->window()->IsFullscreen()); - } -} - -#if defined(OS_MACOSX) -// http://crbug.com/100467 -#define MAYBE_TestTabExitsItselfFromFullscreen \ - FAILS_TestTabExitsItselfFromFullscreen -#else -#define MAYBE_TestTabExitsItselfFromFullscreen TestTabExitsItselfFromFullscreen -#endif - -// Tests a tab exiting fullscreen will bring the browser out of fullscreen. -IN_PROC_BROWSER_TEST_F(BrowserTest, MAYBE_TestTabExitsItselfFromFullscreen) { - ASSERT_TRUE(test_server()->Start()); - - AddTabAtIndex( - 0, GURL(chrome::kAboutBlankURL), content::PAGE_TRANSITION_TYPED); - - WebContents* fullscreen_tab = browser()->GetSelectedWebContents(); - ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(fullscreen_tab, true)); - ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(fullscreen_tab, false)); -} - -// Tests entering fullscreen and then requesting mouse lock results in -// buttons for the user, and that after confirming the buttons are dismissed. -IN_PROC_BROWSER_TEST_F(BrowserTest, TestFullscreenBubbleMouseLockState) { - ASSERT_TRUE(test_server()->Start()); - - AddTabAtIndex(0, GURL(chrome::kAboutBlankURL), - content::PAGE_TRANSITION_TYPED); - AddTabAtIndex(1, GURL(chrome::kAboutBlankURL), - content::PAGE_TRANSITION_TYPED); - - WebContents* fullscreen_tab = browser()->GetSelectedWebContents(); - - ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(fullscreen_tab, true)); - - // Request mouse lock and verify the bubble is waiting for user confirmation. - RequestToLockMouse(fullscreen_tab, true, false); - ASSERT_TRUE(IsMouseLockPermissionRequested()); - - // Accept mouse lock and verify bubble no longer shows confirmation buttons. - AcceptCurrentFullscreenOrMouseLockRequest(); - ASSERT_FALSE(IsFullscreenBubbleDisplayingButtons()); -} - -// BrowserTest.MouseLockThenFullscreen is flaky on linux and win. -// (http://crbug.com/130358) -#if defined(OS_WIN) || defined(OS_LINUX) -#define MAYBE_MouseLockThenFullscreen DISABLED_MouseLockThenFullscreen -#else -#define MAYBE_MouseLockThenFullscreen MouseLockThenFullscreen -#endif - -// Tests mouse lock then fullscreen. -IN_PROC_BROWSER_TEST_F(BrowserTest, MAYBE_MouseLockThenFullscreen) { - ASSERT_TRUE(test_server()->Start()); - ui_test_utils::NavigateToURL(browser(), - test_server()->GetURL(kFullscreenMouseLockHTML)); - - WebContents* tab = browser()->GetSelectedWebContents(); - - ASSERT_FALSE(IsFullscreenBubbleDisplayed()); - - // Lock the mouse without a user gesture, expect no response. - ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( - browser(), ui::VKEY_D, false, false, false, false, - chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, - content::NotificationService::AllSources())); - ASSERT_FALSE(IsFullscreenBubbleDisplayed()); - ASSERT_FALSE(IsMouseLocked()); - - // Lock the mouse with a user gesture. - ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( - browser(), ui::VKEY_1, false, false, false, false, - chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, - content::NotificationService::AllSources())); - ASSERT_TRUE(IsFullscreenBubbleDisplayed()); - ASSERT_FALSE(IsFullscreenPermissionRequested()); - ASSERT_TRUE(IsMouseLockPermissionRequested()); - ASSERT_FALSE(IsMouseLocked()); - - // Accept mouse lock. - AcceptCurrentFullscreenOrMouseLockRequest(); - ASSERT_TRUE(IsMouseLocked()); - ASSERT_FALSE(IsFullscreenBubbleDisplayingButtons()); - - // Enter fullscreen mode, mouse lock should be dropped to present buttons. - ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(tab, true)); - ASSERT_TRUE(IsFullscreenPermissionRequested()); - ASSERT_FALSE(IsMouseLockPermissionRequested()); - ASSERT_FALSE(IsMouseLocked()); - - // Request mouse lock also, expect fullscreen and mouse lock buttons. - ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( - browser(), ui::VKEY_1, false, false, false, false, - chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, - content::NotificationService::AllSources())); - ASSERT_TRUE(IsFullscreenPermissionRequested()); - ASSERT_TRUE(IsMouseLockPermissionRequested()); - ASSERT_FALSE(IsMouseLocked()); - - // Accept fullscreen and mouse lock. - AcceptCurrentFullscreenOrMouseLockRequest(); - ASSERT_TRUE(IsMouseLocked()); - ASSERT_TRUE(IsFullscreenForTabOrPending()); - ASSERT_FALSE(IsFullscreenBubbleDisplayingButtons()); -} - -// Tests mouse lock then fullscreen in same request. -IN_PROC_BROWSER_TEST_F(BrowserTest, MouseLockAndFullscreen) { - ASSERT_TRUE(test_server()->Start()); - ui_test_utils::NavigateToURL(browser(), - test_server()->GetURL(kFullscreenMouseLockHTML)); - - ASSERT_FALSE(IsFullscreenBubbleDisplayed()); - - // Request to lock the mouse and enter fullscreen. - { - FullscreenNotificationObserver fullscreen_observer; - ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( - browser(), ui::VKEY_B, false, true, false, false, - chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, - content::NotificationService::AllSources())); - fullscreen_observer.Wait(); - } - ASSERT_TRUE(IsFullscreenBubbleDisplayed()); - ASSERT_TRUE(IsFullscreenPermissionRequested()); - ASSERT_TRUE(IsMouseLockPermissionRequested()); - ASSERT_FALSE(IsMouseLocked()); - ASSERT_TRUE(IsFullscreenForTabOrPending()); - - // Deny both first, to make sure we can. - { - FullscreenNotificationObserver fullscreen_observer; - DenyCurrentFullscreenOrMouseLockRequest(); - fullscreen_observer.Wait(); - } - ASSERT_FALSE(IsMouseLocked()); - ASSERT_FALSE(IsFullscreenForTabOrPending()); - ASSERT_FALSE(IsFullscreenPermissionRequested()); - - // Request to lock the mouse and enter fullscreen. - { - FullscreenNotificationObserver fullscreen_observer; - ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( - browser(), ui::VKEY_B, false, true, false, false, - chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, - content::NotificationService::AllSources())); - fullscreen_observer.Wait(); - } - ASSERT_TRUE(IsFullscreenBubbleDisplayed()); - ASSERT_TRUE(IsFullscreenPermissionRequested()); - ASSERT_TRUE(IsMouseLockPermissionRequested()); - ASSERT_FALSE(IsMouseLocked()); - ASSERT_TRUE(IsFullscreenForTabOrPending()); - - // Accept both, confirm they are enabled and there is no prompt. - AcceptCurrentFullscreenOrMouseLockRequest(); - ASSERT_TRUE(IsMouseLocked()); - ASSERT_TRUE(IsFullscreenForTabOrPending()); - ASSERT_FALSE(IsFullscreenPermissionRequested()); -} - -// Tests mouse lock can be escaped with ESC key. -IN_PROC_BROWSER_TEST_F(BrowserTest, EscapingMouseLock) { - ASSERT_TRUE(test_server()->Start()); - ui_test_utils::NavigateToURL(browser(), - test_server()->GetURL(kFullscreenMouseLockHTML)); - - ASSERT_FALSE(IsFullscreenBubbleDisplayed()); - - // Request to lock the mouse. - { - ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( - browser(), ui::VKEY_1, false, false, false, false, - chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, - content::NotificationService::AllSources())); - } - ASSERT_FALSE(IsFullscreenPermissionRequested()); - ASSERT_TRUE(IsMouseLockPermissionRequested()); - - // Escape, no prompts should remain. - SendEscapeToFullscreenController(); - ASSERT_FALSE(IsFullscreenPermissionRequested()); - ASSERT_FALSE(IsMouseLockPermissionRequested()); - - // Request to lock the mouse. - { - ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( - browser(), ui::VKEY_1, false, false, false, false, - chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, - content::NotificationService::AllSources())); - } - ASSERT_FALSE(IsFullscreenPermissionRequested()); - ASSERT_TRUE(IsMouseLockPermissionRequested()); - - // Accept mouse lock, confirm it and that there is no prompt. - AcceptCurrentFullscreenOrMouseLockRequest(); - ASSERT_TRUE(IsMouseLocked()); - ASSERT_FALSE(IsFullscreenForTabOrPending()); - ASSERT_FALSE(IsFullscreenPermissionRequested()); - ASSERT_FALSE(IsMouseLockPermissionRequested()); - - // Escape, confirm we are out of mouse lock with no prompts. - SendEscapeToFullscreenController(); - ASSERT_FALSE(IsMouseLocked()); - ASSERT_FALSE(IsFullscreenForTabOrPending()); - ASSERT_FALSE(IsFullscreenPermissionRequested()); - ASSERT_FALSE(IsMouseLockPermissionRequested()); -} - -// Tests mouse lock and fullscreen modes can be escaped with ESC key. -IN_PROC_BROWSER_TEST_F(BrowserTest, EscapingMouseLockAndFullscreen) { - ASSERT_TRUE(test_server()->Start()); - ui_test_utils::NavigateToURL(browser(), - test_server()->GetURL(kFullscreenMouseLockHTML)); - - ASSERT_FALSE(IsFullscreenBubbleDisplayed()); - - // Request to lock the mouse and enter fullscreen. - { - FullscreenNotificationObserver fullscreen_observer; - ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( - browser(), ui::VKEY_B, false, true, false, false, - chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, - content::NotificationService::AllSources())); - fullscreen_observer.Wait(); - } - ASSERT_TRUE(IsFullscreenPermissionRequested()); - ASSERT_TRUE(IsMouseLockPermissionRequested()); - - // Escape, no prompts should remain. - { - FullscreenNotificationObserver fullscreen_observer; - SendEscapeToFullscreenController(); - fullscreen_observer.Wait(); - } - ASSERT_FALSE(IsFullscreenPermissionRequested()); - ASSERT_FALSE(IsMouseLockPermissionRequested()); - - // Request to lock the mouse and enter fullscreen. - { - FullscreenNotificationObserver fullscreen_observer; - ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( - browser(), ui::VKEY_B, false, true, false, false, - chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, - content::NotificationService::AllSources())); - fullscreen_observer.Wait(); - } - ASSERT_TRUE(IsFullscreenPermissionRequested()); - ASSERT_TRUE(IsMouseLockPermissionRequested()); - - // Accept both, confirm mouse lock and fullscreen and no prompts. - AcceptCurrentFullscreenOrMouseLockRequest(); - ASSERT_TRUE(IsMouseLocked()); - ASSERT_TRUE(IsFullscreenForTabOrPending()); - ASSERT_FALSE(IsFullscreenPermissionRequested()); - ASSERT_FALSE(IsMouseLockPermissionRequested()); - - // Escape, confirm we are out of mouse lock and fullscreen with no prompts. - { - FullscreenNotificationObserver fullscreen_observer; - SendEscapeToFullscreenController(); - fullscreen_observer.Wait(); - } - ASSERT_FALSE(IsMouseLocked()); - ASSERT_FALSE(IsFullscreenForTabOrPending()); - ASSERT_FALSE(IsFullscreenPermissionRequested()); - ASSERT_FALSE(IsMouseLockPermissionRequested()); -} - -IN_PROC_BROWSER_TEST_F(BrowserTest, MouseLockSilentAfterTargetUnlock) { - ASSERT_TRUE(test_server()->Start()); - ui_test_utils::NavigateToURL(browser(), - test_server()->GetURL(kFullscreenMouseLockHTML)); - - ASSERT_FALSE(IsFullscreenBubbleDisplayed()); - - // Lock the mouse with a user gesture. - ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( - browser(), ui::VKEY_1, false, false, false, false, - chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, - content::NotificationService::AllSources())); - ASSERT_TRUE(IsFullscreenBubbleDisplayed()); - ASSERT_TRUE(IsMouseLockPermissionRequested()); - ASSERT_FALSE(IsMouseLocked()); - - // Accept mouse lock. - AcceptCurrentFullscreenOrMouseLockRequest(); - ASSERT_TRUE(IsMouseLocked()); - ASSERT_TRUE(IsFullscreenBubbleDisplayed()); - - // Unlock the mouse from target, make sure it's unloacked - ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( - browser(), ui::VKEY_U, false, false, false, false, - chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, - content::NotificationService::AllSources())); - ASSERT_FALSE(IsMouseLocked()); - ASSERT_FALSE(IsFullscreenBubbleDisplayed()); - - // Lock mouse again, make sure it works with no bubble - ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( - browser(), ui::VKEY_1, false, false, false, false, - chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, - content::NotificationService::AllSources())); - ASSERT_TRUE(IsMouseLocked()); - ASSERT_FALSE(IsFullscreenBubbleDisplayed()); - - // Unlock the mouse again by target - ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( - browser(), ui::VKEY_U, false, false, false, false, - chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, - content::NotificationService::AllSources())); - ASSERT_FALSE(IsMouseLocked()); - - // Lock from target, not user gesture, make sure it works - ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( - browser(), ui::VKEY_D, false, false, false, false, - chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, - content::NotificationService::AllSources())); - ASSERT_TRUE(IsMouseLocked()); - ASSERT_FALSE(IsFullscreenBubbleDisplayed()); - - // Unlock by escape - ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( - browser(), ui::VKEY_ESCAPE, false, false, false, false, - chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, - content::NotificationService::AllSources())); - ASSERT_FALSE(IsMouseLocked()); - - // Lock the mouse with a user gesture, make sure we see bubble again - ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( - browser(), ui::VKEY_1, false, false, false, false, - chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, - content::NotificationService::AllSources())); - ASSERT_TRUE(IsFullscreenBubbleDisplayed()); - ASSERT_TRUE(IsMouseLocked()); -} - -// Helper method to be called by multiple tests. -// Tests Fullscreen and Mouse Lock with varying content settings ALLOW & BLOCK. -void BrowserTest::TestFullscreenMouseLockContentSettings() { - GURL url = test_server()->GetURL("simple.html"); - AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED); - WebContents* tab = browser()->GetSelectedWebContents(); - - // Validate that going fullscreen for a URL defaults to asking permision. - ASSERT_FALSE(IsFullscreenPermissionRequested()); - ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(tab, true)); - ASSERT_TRUE(IsFullscreenPermissionRequested()); - ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(tab, false)); - - // Add content setting to ALLOW fullscreen. - HostContentSettingsMap* settings_map = - browser()->profile()->GetHostContentSettingsMap(); - ContentSettingsPattern pattern = - ContentSettingsPattern::FromURL(url); - settings_map->SetContentSetting( - pattern, ContentSettingsPattern::Wildcard(), - CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string(), - CONTENT_SETTING_ALLOW); - - // Now, fullscreen should not prompt for permission. - ASSERT_FALSE(IsFullscreenPermissionRequested()); - ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(tab, true)); - ASSERT_FALSE(IsFullscreenPermissionRequested()); - - // Leaving tab in fullscreen, now test mouse lock ALLOW: - - // Validate that mouse lock defaults to asking permision. - ASSERT_FALSE(IsMouseLockPermissionRequested()); - ASSERT_FALSE(IsMouseLocked()); - RequestToLockMouse(tab, true, false); - ASSERT_TRUE(IsMouseLockPermissionRequested()); - LostMouseLock(); - - // Add content setting to ALLOW mouse lock. - settings_map->SetContentSetting( - pattern, ContentSettingsPattern::Wildcard(), - CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string(), - CONTENT_SETTING_ALLOW); - - // Now, mouse lock should not prompt for permission. - ASSERT_FALSE(IsMouseLockPermissionRequested()); - RequestToLockMouse(tab, true, false); - ASSERT_FALSE(IsMouseLockPermissionRequested()); - LostMouseLock(); - - // Leaving tab in fullscreen, now test mouse lock BLOCK: - - // Add content setting to BLOCK mouse lock. - settings_map->SetContentSetting( - pattern, ContentSettingsPattern::Wildcard(), - CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string(), - CONTENT_SETTING_BLOCK); - - // Now, mouse lock should not be pending. - ASSERT_FALSE(IsMouseLockPermissionRequested()); - RequestToLockMouse(tab, true, false); - ASSERT_FALSE(IsMouseLockPermissionRequested()); -} - -// Tests fullscreen and Mouse Lock with varying content settings ALLOW & BLOCK. -IN_PROC_BROWSER_TEST_F(BrowserTest, FullscreenMouseLockContentSettings) { - TestFullscreenMouseLockContentSettings(); -} - -// Tests fullscreen and Mouse Lock with varying content settings ALLOW & BLOCK, -// but with the browser initiated in fullscreen mode first. -IN_PROC_BROWSER_TEST_F(BrowserTest, BrowserFullscreenMouseLockContentSettings) { - // Enter browser fullscreen first. - ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(true)); - TestFullscreenMouseLockContentSettings(); - ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(false)); -} - -// Tests Fullscreen entered in Browser, then Tab mode, then exited via Browser. -IN_PROC_BROWSER_TEST_F(BrowserTest, BrowserFullscreenExit) { - // Enter browser fullscreen. - ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(true)); - - // Enter tab fullscreen. - AddTabAtIndex(0, GURL(chrome::kAboutBlankURL), - content::PAGE_TRANSITION_TYPED); - WebContents* fullscreen_tab = browser()->GetSelectedWebContents(); - ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(fullscreen_tab, true)); - - // Exit browser fullscreen. - ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(false)); - ASSERT_FALSE(browser()->window()->IsFullscreen()); -} - -// Tests Browser Fullscreen remains active after Tab mode entered and exited. -IN_PROC_BROWSER_TEST_F(BrowserTest, BrowserFullscreenAfterTabFSExit) { - // Enter browser fullscreen. - ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(true)); - - // Enter and then exit tab fullscreen. - AddTabAtIndex(0, GURL(chrome::kAboutBlankURL), - content::PAGE_TRANSITION_TYPED); - WebContents* fullscreen_tab = browser()->GetSelectedWebContents(); - ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(fullscreen_tab, true)); - ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(fullscreen_tab, false)); - - // Verify browser fullscreen still active. - ASSERT_TRUE(IsFullscreenForBrowser()); -} - -// Tests fullscreen entered without permision prompt for file:// urls. -IN_PROC_BROWSER_TEST_F(BrowserTest, FullscreenFileURL) { - ui_test_utils::NavigateToURL(browser(), - ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), - FilePath(kSimpleFile))); - WebContents* tab = browser()->GetSelectedWebContents(); - - // Validate that going fullscreen for a file does not ask permision. - ASSERT_FALSE(IsFullscreenPermissionRequested()); - ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(tab, true)); - ASSERT_FALSE(IsFullscreenPermissionRequested()); - ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(tab, false)); -} - -#if defined(OS_MACOSX) -// http://crbug.com/100467 -IN_PROC_BROWSER_TEST_F( - BrowserTest, FAILS_TabEntersPresentationModeFromWindowed) { - ASSERT_TRUE(test_server()->Start()); - - AddTabAtIndex( - 0, GURL(chrome::kAboutBlankURL), content::PAGE_TRANSITION_TYPED); - - WebContents* fullscreen_tab = browser()->GetSelectedWebContents(); - - { - FullscreenNotificationObserver fullscreen_observer; - EXPECT_FALSE(browser()->window()->IsFullscreen()); - EXPECT_FALSE(browser()->window()->InPresentationMode()); - browser()->ToggleFullscreenModeForTab(fullscreen_tab, true); - fullscreen_observer.Wait(); - ASSERT_TRUE(browser()->window()->IsFullscreen()); - ASSERT_TRUE(browser()->window()->InPresentationMode()); - } - - { - FullscreenNotificationObserver fullscreen_observer; - browser()->TogglePresentationMode(); - fullscreen_observer.Wait(); - ASSERT_FALSE(browser()->window()->IsFullscreen()); - ASSERT_FALSE(browser()->window()->InPresentationMode()); - } - - if (base::mac::IsOSLionOrLater()) { - // Test that tab fullscreen mode doesn't make presentation mode the default - // on Lion. - FullscreenNotificationObserver fullscreen_observer; - browser()->ToggleFullscreenMode(); - fullscreen_observer.Wait(); - ASSERT_TRUE(browser()->window()->IsFullscreen()); - ASSERT_FALSE(browser()->window()->InPresentationMode()); - } -} -#endif - // Chromeos defaults to restoring the last session, so this test isn't // applicable. #if !defined(OS_CHROMEOS) diff --git a/chrome/browser/ui/fullscreen_controller_browsertest.cc b/chrome/browser/ui/fullscreen_controller_browsertest.cc new file mode 100644 index 0000000..6532762 --- /dev/null +++ b/chrome/browser/ui/fullscreen_controller_browsertest.cc @@ -0,0 +1,267 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/compiler_specific.h" +#include "chrome/browser/content_settings/host_content_settings_map.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/browser_window.h" +#include "chrome/browser/ui/fullscreen_controller_test.h" +#include "content/public/common/url_constants.h" +#if defined(OS_MACOSX) +#include "base/mac/mac_util.h" +#endif + +using content::WebContents; + +namespace { + +const FilePath::CharType* kSimpleFile = FILE_PATH_LITERAL("simple.html"); + +} // namespace + +class FullscreenControllerBrowserTest: public FullscreenControllerTest { + protected: + void TestFullscreenMouseLockContentSettings(); +}; + +#if defined(OS_MACOSX) +// http://crbug.com/104265 +#define MAYBE_TestNewTabExitsFullscreen DISABLED_TestNewTabExitsFullscreen +#else +#define MAYBE_TestNewTabExitsFullscreen TestNewTabExitsFullscreen +#endif + +// Tests that while in fullscreen creating a new tab will exit fullscreen. +IN_PROC_BROWSER_TEST_F(FullscreenControllerTest, + MAYBE_TestNewTabExitsFullscreen) { + ASSERT_TRUE(test_server()->Start()); + + AddTabAtIndex( + 0, GURL(chrome::kAboutBlankURL), content::PAGE_TRANSITION_TYPED); + + WebContents* fullscreen_tab = browser()->GetSelectedWebContents(); + + ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(fullscreen_tab, true)); + + { + FullscreenNotificationObserver fullscreen_observer; + AddTabAtIndex( + 1, GURL(chrome::kAboutBlankURL), content::PAGE_TRANSITION_TYPED); + fullscreen_observer.Wait(); + ASSERT_FALSE(browser()->window()->IsFullscreen()); + } +} + +#if defined(OS_MACOSX) +// http://crbug.com/100467 +#define MAYBE_TestTabExitsItselfFromFullscreen \ + FAILS_TestTabExitsItselfFromFullscreen +#else +#define MAYBE_TestTabExitsItselfFromFullscreen TestTabExitsItselfFromFullscreen +#endif + +// Tests a tab exiting fullscreen will bring the browser out of fullscreen. +IN_PROC_BROWSER_TEST_F(FullscreenControllerTest, + MAYBE_TestTabExitsItselfFromFullscreen) { + ASSERT_TRUE(test_server()->Start()); + + AddTabAtIndex( + 0, GURL(chrome::kAboutBlankURL), content::PAGE_TRANSITION_TYPED); + + WebContents* fullscreen_tab = browser()->GetSelectedWebContents(); + ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(fullscreen_tab, true)); + ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(fullscreen_tab, false)); +} + +// Tests entering fullscreen and then requesting mouse lock results in +// buttons for the user, and that after confirming the buttons are dismissed. +IN_PROC_BROWSER_TEST_F(FullscreenControllerTest, + TestFullscreenBubbleMouseLockState) { + ASSERT_TRUE(test_server()->Start()); + + AddTabAtIndex(0, GURL(chrome::kAboutBlankURL), + content::PAGE_TRANSITION_TYPED); + AddTabAtIndex(1, GURL(chrome::kAboutBlankURL), + content::PAGE_TRANSITION_TYPED); + + WebContents* fullscreen_tab = browser()->GetSelectedWebContents(); + + ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(fullscreen_tab, true)); + + // Request mouse lock and verify the bubble is waiting for user confirmation. + RequestToLockMouse(fullscreen_tab, true, false); + ASSERT_TRUE(IsMouseLockPermissionRequested()); + + // Accept mouse lock and verify bubble no longer shows confirmation buttons. + AcceptCurrentFullscreenOrMouseLockRequest(); + ASSERT_FALSE(IsFullscreenBubbleDisplayingButtons()); +} + +// Helper method to be called by multiple tests. +// Tests Fullscreen and Mouse Lock with varying content settings ALLOW & BLOCK. +void FullscreenControllerBrowserTest::TestFullscreenMouseLockContentSettings() { + GURL url = test_server()->GetURL("simple.html"); + AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED); + WebContents* tab = browser()->GetSelectedWebContents(); + + // Validate that going fullscreen for a URL defaults to asking permision. + ASSERT_FALSE(IsFullscreenPermissionRequested()); + ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(tab, true)); + ASSERT_TRUE(IsFullscreenPermissionRequested()); + ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(tab, false)); + + // Add content setting to ALLOW fullscreen. + HostContentSettingsMap* settings_map = + browser()->profile()->GetHostContentSettingsMap(); + ContentSettingsPattern pattern = + ContentSettingsPattern::FromURL(url); + settings_map->SetContentSetting( + pattern, ContentSettingsPattern::Wildcard(), + CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string(), + CONTENT_SETTING_ALLOW); + + // Now, fullscreen should not prompt for permission. + ASSERT_FALSE(IsFullscreenPermissionRequested()); + ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(tab, true)); + ASSERT_FALSE(IsFullscreenPermissionRequested()); + + // Leaving tab in fullscreen, now test mouse lock ALLOW: + + // Validate that mouse lock defaults to asking permision. + ASSERT_FALSE(IsMouseLockPermissionRequested()); + RequestToLockMouse(tab, true, false); + ASSERT_TRUE(IsMouseLockPermissionRequested()); + LostMouseLock(); + + // Add content setting to ALLOW mouse lock. + settings_map->SetContentSetting( + pattern, ContentSettingsPattern::Wildcard(), + CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string(), + CONTENT_SETTING_ALLOW); + + // Now, mouse lock should not prompt for permission. + ASSERT_FALSE(IsMouseLockPermissionRequested()); + RequestToLockMouse(tab, true, false); + ASSERT_FALSE(IsMouseLockPermissionRequested()); + LostMouseLock(); + + // Leaving tab in fullscreen, now test mouse lock BLOCK: + + // Add content setting to BLOCK mouse lock. + settings_map->SetContentSetting( + pattern, ContentSettingsPattern::Wildcard(), + CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string(), + CONTENT_SETTING_BLOCK); + + // Now, mouse lock should not be pending. + ASSERT_FALSE(IsMouseLockPermissionRequested()); + RequestToLockMouse(tab, true, false); + ASSERT_FALSE(IsMouseLockPermissionRequested()); +} + +// Tests fullscreen and Mouse Lock with varying content settings ALLOW & BLOCK. +IN_PROC_BROWSER_TEST_F(FullscreenControllerBrowserTest, + FullscreenMouseLockContentSettings) { + TestFullscreenMouseLockContentSettings(); +} + +// Tests fullscreen and Mouse Lock with varying content settings ALLOW & BLOCK, +// but with the browser initiated in fullscreen mode first. +IN_PROC_BROWSER_TEST_F(FullscreenControllerBrowserTest, + BrowserFullscreenMouseLockContentSettings) { + // Enter browser fullscreen first. + ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(true)); + TestFullscreenMouseLockContentSettings(); + ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(false)); +} + +// Tests Fullscreen entered in Browser, then Tab mode, then exited via Browser. +IN_PROC_BROWSER_TEST_F(FullscreenControllerTest, BrowserFullscreenExit) { + // Enter browser fullscreen. + ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(true)); + + // Enter tab fullscreen. + AddTabAtIndex(0, GURL(chrome::kAboutBlankURL), + content::PAGE_TRANSITION_TYPED); + WebContents* fullscreen_tab = browser()->GetSelectedWebContents(); + ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(fullscreen_tab, true)); + + // Exit browser fullscreen. + ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(false)); + ASSERT_FALSE(browser()->window()->IsFullscreen()); +} + +// Tests Browser Fullscreen remains active after Tab mode entered and exited. +IN_PROC_BROWSER_TEST_F(FullscreenControllerTest, + BrowserFullscreenAfterTabFSExit) { + // Enter browser fullscreen. + ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(true)); + + // Enter and then exit tab fullscreen. + AddTabAtIndex(0, GURL(chrome::kAboutBlankURL), + content::PAGE_TRANSITION_TYPED); + WebContents* fullscreen_tab = browser()->GetSelectedWebContents(); + ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(fullscreen_tab, true)); + ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(fullscreen_tab, false)); + + // Verify browser fullscreen still active. + ASSERT_TRUE(IsFullscreenForBrowser()); +} + +// Tests fullscreen entered without permision prompt for file:// urls. +IN_PROC_BROWSER_TEST_F(FullscreenControllerTest, FullscreenFileURL) { + ui_test_utils::NavigateToURL(browser(), + ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), + FilePath(kSimpleFile))); + WebContents* tab = browser()->GetSelectedWebContents(); + + // Validate that going fullscreen for a file does not ask permision. + ASSERT_FALSE(IsFullscreenPermissionRequested()); + ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(tab, true)); + ASSERT_FALSE(IsFullscreenPermissionRequested()); + ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(tab, false)); +} + +#if defined(OS_MACOSX) +// http://crbug.com/100467 +IN_PROC_BROWSER_TEST_F( + FullscreenControllerTest, FAILS_TabEntersPresentationModeFromWindowed) { + ASSERT_TRUE(test_server()->Start()); + + AddTabAtIndex( + 0, GURL(chrome::kAboutBlankURL), content::PAGE_TRANSITION_TYPED); + + WebContents* fullscreen_tab = browser()->GetSelectedWebContents(); + + { + FullscreenNotificationObserver fullscreen_observer; + EXPECT_FALSE(browser()->window()->IsFullscreen()); + EXPECT_FALSE(browser()->window()->InPresentationMode()); + browser()->ToggleFullscreenModeForTab(fullscreen_tab, true); + fullscreen_observer.Wait(); + ASSERT_TRUE(browser()->window()->IsFullscreen()); + ASSERT_TRUE(browser()->window()->InPresentationMode()); + } + + { + FullscreenNotificationObserver fullscreen_observer; + browser()->TogglePresentationMode(); + fullscreen_observer.Wait(); + ASSERT_FALSE(browser()->window()->IsFullscreen()); + ASSERT_FALSE(browser()->window()->InPresentationMode()); + } + + if (base::mac::IsOSLionOrLater()) { + // Test that tab fullscreen mode doesn't make presentation mode the default + // on Lion. + FullscreenNotificationObserver fullscreen_observer; + browser()->ToggleFullscreenMode(); + fullscreen_observer.Wait(); + ASSERT_TRUE(browser()->window()->IsFullscreen()); + ASSERT_FALSE(browser()->window()->InPresentationMode()); + } +} +#endif + diff --git a/chrome/browser/ui/fullscreen_controller_interactive_browsertest.cc b/chrome/browser/ui/fullscreen_controller_interactive_browsertest.cc new file mode 100644 index 0000000..43fcec8 --- /dev/null +++ b/chrome/browser/ui/fullscreen_controller_interactive_browsertest.cc @@ -0,0 +1,320 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/fullscreen_controller_test.h" +#include "content/public/browser/render_view_host.h" +#include "content/public/browser/render_widget_host_view.h" +#include "content/public/browser/web_contents.h" + +using content::WebContents; + +class FullscreenControllerInteractiveTest + : public FullscreenControllerTest { + protected: + // IsMouseLocked verifies that the FullscreenController state believes + // the mouse is locked. This is possible only for tests that initiate + // mouse lock from a renderer process, and uses logic that tests that the + // browser has focus. Thus, this can only be used in interactive ui tests + // and not on sharded tests. + bool IsMouseLocked() { + // Verify that IsMouseLocked is consistent between the + // Fullscreen Controller and the Render View Host View. + EXPECT_TRUE(browser()->IsMouseLocked() == + browser()->GetSelectedWebContents()-> + GetRenderViewHost()->GetView()->IsMouseLocked()); + return browser()->IsMouseLocked(); + } +}; + +// Tests mouse lock can be escaped with ESC key. +IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest, EscapingMouseLock) { + ASSERT_TRUE(test_server()->Start()); + ui_test_utils::NavigateToURL(browser(), + test_server()->GetURL(kFullscreenMouseLockHTML)); + + ASSERT_FALSE(IsFullscreenBubbleDisplayed()); + + // Request to lock the mouse. + { + ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( + browser(), ui::VKEY_1, false, false, false, false, + chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, + content::NotificationService::AllSources())); + } + ASSERT_FALSE(IsFullscreenPermissionRequested()); + ASSERT_TRUE(IsMouseLockPermissionRequested()); + + // Escape, no prompts should remain. + SendEscapeToFullscreenController(); + ASSERT_FALSE(IsFullscreenPermissionRequested()); + ASSERT_FALSE(IsMouseLockPermissionRequested()); + + // Request to lock the mouse. + { + ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( + browser(), ui::VKEY_1, false, false, false, false, + chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, + content::NotificationService::AllSources())); + } + ASSERT_FALSE(IsFullscreenPermissionRequested()); + ASSERT_TRUE(IsMouseLockPermissionRequested()); + + // Accept mouse lock, confirm it and that there is no prompt. + AcceptCurrentFullscreenOrMouseLockRequest(); + ASSERT_TRUE(IsMouseLocked()); + ASSERT_FALSE(IsFullscreenForTabOrPending()); + ASSERT_FALSE(IsFullscreenPermissionRequested()); + ASSERT_FALSE(IsMouseLockPermissionRequested()); + + // Escape, confirm we are out of mouse lock with no prompts. + SendEscapeToFullscreenController(); + ASSERT_FALSE(IsMouseLocked()); + ASSERT_FALSE(IsFullscreenForTabOrPending()); + ASSERT_FALSE(IsFullscreenPermissionRequested()); + ASSERT_FALSE(IsMouseLockPermissionRequested()); +} + +// Tests mouse lock and fullscreen modes can be escaped with ESC key. +IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest, + EscapingMouseLockAndFullscreen) { + ASSERT_TRUE(test_server()->Start()); + ui_test_utils::NavigateToURL(browser(), + test_server()->GetURL(kFullscreenMouseLockHTML)); + + ASSERT_FALSE(IsFullscreenBubbleDisplayed()); + + // Request to lock the mouse and enter fullscreen. + { + FullscreenNotificationObserver fullscreen_observer; + ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( + browser(), ui::VKEY_B, false, true, false, false, + chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, + content::NotificationService::AllSources())); + fullscreen_observer.Wait(); + } + ASSERT_TRUE(IsFullscreenPermissionRequested()); + ASSERT_TRUE(IsMouseLockPermissionRequested()); + + // Escape, no prompts should remain. + { + FullscreenNotificationObserver fullscreen_observer; + SendEscapeToFullscreenController(); + fullscreen_observer.Wait(); + } + ASSERT_FALSE(IsFullscreenPermissionRequested()); + ASSERT_FALSE(IsMouseLockPermissionRequested()); + + // Request to lock the mouse and enter fullscreen. + { + FullscreenNotificationObserver fullscreen_observer; + ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( + browser(), ui::VKEY_B, false, true, false, false, + chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, + content::NotificationService::AllSources())); + fullscreen_observer.Wait(); + } + ASSERT_TRUE(IsFullscreenPermissionRequested()); + ASSERT_TRUE(IsMouseLockPermissionRequested()); + + // Accept both, confirm mouse lock and fullscreen and no prompts. + AcceptCurrentFullscreenOrMouseLockRequest(); + ASSERT_TRUE(IsMouseLocked()); + ASSERT_TRUE(IsFullscreenForTabOrPending()); + ASSERT_FALSE(IsFullscreenPermissionRequested()); + ASSERT_FALSE(IsMouseLockPermissionRequested()); + + // Escape, confirm we are out of mouse lock and fullscreen with no prompts. + { + FullscreenNotificationObserver fullscreen_observer; + SendEscapeToFullscreenController(); + fullscreen_observer.Wait(); + } + ASSERT_FALSE(IsMouseLocked()); + ASSERT_FALSE(IsFullscreenForTabOrPending()); + ASSERT_FALSE(IsFullscreenPermissionRequested()); + ASSERT_FALSE(IsMouseLockPermissionRequested()); +} + +// Tests mouse lock then fullscreen. +IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest, + MouseLockThenFullscreen) { + ASSERT_TRUE(test_server()->Start()); + ui_test_utils::NavigateToURL(browser(), + test_server()->GetURL(kFullscreenMouseLockHTML)); + + WebContents* tab = browser()->GetSelectedWebContents(); + + ASSERT_FALSE(IsFullscreenBubbleDisplayed()); + + // Lock the mouse without a user gesture, expect no response. + ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( + browser(), ui::VKEY_D, false, false, false, false, + chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, + content::NotificationService::AllSources())); + ASSERT_FALSE(IsFullscreenBubbleDisplayed()); + ASSERT_FALSE(IsMouseLocked()); + + // Lock the mouse with a user gesture. + ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( + browser(), ui::VKEY_1, false, false, false, false, + chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, + content::NotificationService::AllSources())); + ASSERT_TRUE(IsFullscreenBubbleDisplayed()); + ASSERT_FALSE(IsFullscreenPermissionRequested()); + ASSERT_TRUE(IsMouseLockPermissionRequested()); + ASSERT_FALSE(IsMouseLocked()); + + // Accept mouse lock. + AcceptCurrentFullscreenOrMouseLockRequest(); + ASSERT_TRUE(IsMouseLocked()); + ASSERT_FALSE(IsFullscreenBubbleDisplayingButtons()); + + // Enter fullscreen mode, mouse lock should be dropped to present buttons. + ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(tab, true)); + ASSERT_TRUE(IsFullscreenPermissionRequested()); + ASSERT_FALSE(IsMouseLockPermissionRequested()); + ASSERT_FALSE(IsMouseLocked()); + + // Request mouse lock also, expect fullscreen and mouse lock buttons. + ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( + browser(), ui::VKEY_1, false, false, false, false, + chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, + content::NotificationService::AllSources())); + ASSERT_TRUE(IsFullscreenPermissionRequested()); + ASSERT_TRUE(IsMouseLockPermissionRequested()); + ASSERT_FALSE(IsMouseLocked()); + + // Accept fullscreen and mouse lock. + AcceptCurrentFullscreenOrMouseLockRequest(); + ASSERT_TRUE(IsMouseLocked()); + ASSERT_TRUE(IsFullscreenForTabOrPending()); + ASSERT_FALSE(IsFullscreenBubbleDisplayingButtons()); +} + +// Tests mouse lock then fullscreen in same request. +IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest, + MouseLockAndFullscreen) { + ASSERT_TRUE(test_server()->Start()); + ui_test_utils::NavigateToURL(browser(), + test_server()->GetURL(kFullscreenMouseLockHTML)); + + ASSERT_FALSE(IsFullscreenBubbleDisplayed()); + + // Request to lock the mouse and enter fullscreen. + { + FullscreenNotificationObserver fullscreen_observer; + ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( + browser(), ui::VKEY_B, false, true, false, false, + chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, + content::NotificationService::AllSources())); + fullscreen_observer.Wait(); + } + ASSERT_TRUE(IsFullscreenBubbleDisplayed()); + ASSERT_TRUE(IsFullscreenPermissionRequested()); + ASSERT_TRUE(IsMouseLockPermissionRequested()); + ASSERT_FALSE(IsMouseLocked()); + ASSERT_TRUE(IsFullscreenForTabOrPending()); + + // Deny both first, to make sure we can. + { + FullscreenNotificationObserver fullscreen_observer; + DenyCurrentFullscreenOrMouseLockRequest(); + fullscreen_observer.Wait(); + } + ASSERT_FALSE(IsMouseLocked()); + ASSERT_FALSE(IsFullscreenForTabOrPending()); + ASSERT_FALSE(IsFullscreenPermissionRequested()); + + // Request to lock the mouse and enter fullscreen. + { + FullscreenNotificationObserver fullscreen_observer; + ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( + browser(), ui::VKEY_B, false, true, false, false, + chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, + content::NotificationService::AllSources())); + fullscreen_observer.Wait(); + } + ASSERT_TRUE(IsFullscreenBubbleDisplayed()); + ASSERT_TRUE(IsFullscreenPermissionRequested()); + ASSERT_TRUE(IsMouseLockPermissionRequested()); + ASSERT_FALSE(IsMouseLocked()); + ASSERT_TRUE(IsFullscreenForTabOrPending()); + + // Accept both, confirm they are enabled and there is no prompt. + AcceptCurrentFullscreenOrMouseLockRequest(); + ASSERT_TRUE(IsMouseLocked()); + ASSERT_TRUE(IsFullscreenForTabOrPending()); + ASSERT_FALSE(IsFullscreenPermissionRequested()); +} + +IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest, + MouseLockSilentAfterTargetUnlock) { + ASSERT_TRUE(test_server()->Start()); + ui_test_utils::NavigateToURL(browser(), + test_server()->GetURL(kFullscreenMouseLockHTML)); + + ASSERT_FALSE(IsFullscreenBubbleDisplayed()); + + // Lock the mouse with a user gesture. + ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( + browser(), ui::VKEY_1, false, false, false, false, + chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, + content::NotificationService::AllSources())); + ASSERT_TRUE(IsFullscreenBubbleDisplayed()); + ASSERT_TRUE(IsMouseLockPermissionRequested()); + ASSERT_FALSE(IsMouseLocked()); + + // Accept mouse lock. + AcceptCurrentFullscreenOrMouseLockRequest(); + ASSERT_TRUE(IsMouseLocked()); + ASSERT_TRUE(IsFullscreenBubbleDisplayed()); + + // Unlock the mouse from target, make sure it's unloacked + ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( + browser(), ui::VKEY_U, false, false, false, false, + chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, + content::NotificationService::AllSources())); + ASSERT_FALSE(IsMouseLocked()); + ASSERT_FALSE(IsFullscreenBubbleDisplayed()); + + // Lock mouse again, make sure it works with no bubble + ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( + browser(), ui::VKEY_1, false, false, false, false, + chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, + content::NotificationService::AllSources())); + ASSERT_TRUE(IsMouseLocked()); + ASSERT_FALSE(IsFullscreenBubbleDisplayed()); + + // Unlock the mouse again by target + ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( + browser(), ui::VKEY_U, false, false, false, false, + chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, + content::NotificationService::AllSources())); + ASSERT_FALSE(IsMouseLocked()); + + // Lock from target, not user gesture, make sure it works + ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( + browser(), ui::VKEY_D, false, false, false, false, + chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, + content::NotificationService::AllSources())); + ASSERT_TRUE(IsMouseLocked()); + ASSERT_FALSE(IsFullscreenBubbleDisplayed()); + + // Unlock by escape + ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( + browser(), ui::VKEY_ESCAPE, false, false, false, false, + chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, + content::NotificationService::AllSources())); + ASSERT_FALSE(IsMouseLocked()); + + // Lock the mouse with a user gesture, make sure we see bubble again + ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( + browser(), ui::VKEY_1, false, false, false, false, + chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, + content::NotificationService::AllSources())); + ASSERT_TRUE(IsFullscreenBubbleDisplayed()); + ASSERT_TRUE(IsMouseLocked()); +} + diff --git a/chrome/browser/ui/fullscreen_controller_test.cc b/chrome/browser/ui/fullscreen_controller_test.cc new file mode 100644 index 0000000..d4a67c8 --- /dev/null +++ b/chrome/browser/ui/fullscreen_controller_test.cc @@ -0,0 +1,116 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/fullscreen_controller_test.h" + +#include "base/command_line.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/browser_window.h" +#include "chrome/browser/ui/fullscreen_controller.h" +#include "chrome/common/chrome_switches.h" +#include "content/public/browser/web_contents.h" + +using content::WebContents; + +const char FullscreenControllerTest::kFullscreenMouseLockHTML[] = + "files/fullscreen_mouselock/fullscreen_mouselock.html"; + +void FullscreenControllerTest::SetUpCommandLine(CommandLine* command_line) { + InProcessBrowserTest::SetUpCommandLine(command_line); + command_line->AppendSwitch(switches::kEnablePointerLock); +} + +void FullscreenControllerTest::ToggleTabFullscreen(WebContents* tab, + bool enter_fullscreen) { + if (IsFullscreenForBrowser()) { + // Changing tab fullscreen state will not actually change the window + // when browser fullscreen is in effect. + browser()->ToggleFullscreenModeForTab(tab, enter_fullscreen); + } else { // Not in browser fullscreen, expect window to actually change. + FullscreenNotificationObserver fullscreen_observer; + browser()->ToggleFullscreenModeForTab(tab, enter_fullscreen); + fullscreen_observer.Wait(); + ASSERT_EQ(browser()->window()->IsFullscreen(), enter_fullscreen); + } +} + +void FullscreenControllerTest::ToggleBrowserFullscreen(bool enter_fullscreen) { + ASSERT_EQ(browser()->window()->IsFullscreen(), !enter_fullscreen); + FullscreenNotificationObserver fullscreen_observer; + + browser()->ToggleFullscreenMode(); + + fullscreen_observer.Wait(); + ASSERT_EQ(browser()->window()->IsFullscreen(), enter_fullscreen); + ASSERT_EQ(IsFullscreenForBrowser(), enter_fullscreen); +} + +void FullscreenControllerTest::RequestToLockMouse(WebContents* tab, + bool user_gesture, + bool last_unlocked_by_target) { + browser()->RequestToLockMouse(tab, user_gesture, + last_unlocked_by_target); +} + +void FullscreenControllerTest::LostMouseLock() { + browser()->LostMouseLock(); +} + +bool FullscreenControllerTest::SendEscapeToFullscreenController() { + return browser()->fullscreen_controller_->HandleUserPressedEscape(); +} + +bool FullscreenControllerTest::IsFullscreenForBrowser() { + return browser()->fullscreen_controller_->IsFullscreenForBrowser(); +} + +bool FullscreenControllerTest::IsFullscreenForTabOrPending() { + return browser()->IsFullscreenForTabOrPending(); +} + +bool FullscreenControllerTest::IsMouseLockPermissionRequested() { + FullscreenExitBubbleType type = + browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); + bool mouse_lock = false; + fullscreen_bubble::PermissionRequestedByType(type, NULL, &mouse_lock); + return mouse_lock; +} + +bool FullscreenControllerTest::IsFullscreenPermissionRequested() { + FullscreenExitBubbleType type = + browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); + bool fullscreen = false; + fullscreen_bubble::PermissionRequestedByType(type, &fullscreen, NULL); + return fullscreen; +} + +FullscreenExitBubbleType + FullscreenControllerTest::GetFullscreenExitBubbleType() { + return browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); +} + +bool FullscreenControllerTest::IsFullscreenBubbleDisplayed() { + FullscreenExitBubbleType type = + browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); + return type != FEB_TYPE_NONE; +} + +bool FullscreenControllerTest::IsFullscreenBubbleDisplayingButtons() { + FullscreenExitBubbleType type = + browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); + return fullscreen_bubble::ShowButtonsForType(type); +} + +void FullscreenControllerTest::AcceptCurrentFullscreenOrMouseLockRequest() { + WebContents* fullscreen_tab = browser()->GetSelectedWebContents(); + FullscreenExitBubbleType type = + browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); + browser()->OnAcceptFullscreenPermission(fullscreen_tab->GetURL(), type); +} + +void FullscreenControllerTest::DenyCurrentFullscreenOrMouseLockRequest() { + FullscreenExitBubbleType type = + browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); + browser()->OnDenyFullscreenPermission(type); +} diff --git a/chrome/browser/ui/fullscreen_controller_test.h b/chrome/browser/ui/fullscreen_controller_test.h new file mode 100644 index 0000000..b599583 --- /dev/null +++ b/chrome/browser/ui/fullscreen_controller_test.h @@ -0,0 +1,63 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_FULLSCREEN_CONTROLLER_TEST_H_ +#define CHROME_BROWSER_UI_FULLSCREEN_CONTROLLER_TEST_H_ + +#include "chrome/browser/ui/fullscreen_exit_bubble_type.h" +#include "chrome/common/chrome_notification_types.h" +#include "chrome/test/base/in_process_browser_test.h" +#include "chrome/test/base/ui_test_utils.h" +#include "content/public/browser/notification_service.h" + +// Observer for NOTIFICATION_FULLSCREEN_CHANGED notifications. +class FullscreenNotificationObserver + : public ui_test_utils::WindowedNotificationObserver { + public: + FullscreenNotificationObserver() : WindowedNotificationObserver( + chrome::NOTIFICATION_FULLSCREEN_CHANGED, + content::NotificationService::AllSources()) {} + protected: + DISALLOW_COPY_AND_ASSIGN(FullscreenNotificationObserver); +}; + +// Observer for NOTIFICATION_MOUSE_LOCK_CHANGED notifications. +class MouseLockNotificationObserver + : public ui_test_utils::WindowedNotificationObserver { + public: + MouseLockNotificationObserver() : WindowedNotificationObserver( + chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, + content::NotificationService::AllSources()) {} + protected: + DISALLOW_COPY_AND_ASSIGN(MouseLockNotificationObserver); +}; + +// Test fixture with convenience functions for fullscreen and mouse lock. +class FullscreenControllerTest : public InProcessBrowserTest { + protected: + FullscreenControllerTest() {} + + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE; + void ToggleTabFullscreen(content::WebContents* tab, bool enter_fullscreen); + void ToggleBrowserFullscreen(bool enter_fullscreen); + void RequestToLockMouse(content::WebContents* tab, + bool user_gesture, + bool last_unlocked_by_target); + void LostMouseLock(); + bool SendEscapeToFullscreenController(); + bool IsFullscreenForBrowser(); + bool IsFullscreenForTabOrPending(); + bool IsMouseLockPermissionRequested(); + bool IsFullscreenPermissionRequested(); + FullscreenExitBubbleType GetFullscreenExitBubbleType(); + bool IsFullscreenBubbleDisplayed(); + bool IsFullscreenBubbleDisplayingButtons(); + void AcceptCurrentFullscreenOrMouseLockRequest(); + void DenyCurrentFullscreenOrMouseLockRequest(); + static const char kFullscreenMouseLockHTML[]; + private: + DISALLOW_COPY_AND_ASSIGN(FullscreenControllerTest); +}; + +#endif // CHROME_BROWSER_UI_FULLSCREEN_CONTROLLER_TEST_H_ diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index efa8f16..bb26274 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -167,6 +167,8 @@ 'browser/ui/browser.h', 'browser/ui/cocoa/run_loop_testing.h', 'browser/ui/cocoa/run_loop_testing.mm', + 'browser/ui/fullscreen_controller_test.cc', + 'browser/ui/fullscreen_controller_test.h', 'browser/ui/panels/base_panel_browser_test.cc', 'browser/ui/panels/base_panel_browser_test.h', 'browser/ui/panels/test_panel_mouse_watcher.cc', @@ -480,6 +482,7 @@ 'browser/keyboard_access_browsertest.cc', 'browser/printing/print_dialog_cloud_interative_uitest.cc', 'browser/task_manager/task_manager_browsertest_util.cc', + 'browser/ui/fullscreen_controller_interactive_browsertest.cc', 'browser/ui/gtk/bookmarks/bookmark_bar_gtk_interactive_uitest.cc', 'browser/ui/omnibox/omnibox_view_browsertest.cc', 'browser/ui/panels/detached_panel_browsertest.cc', @@ -2869,6 +2872,7 @@ 'browser/ui/cocoa/applescript/window_applescript_test.mm', 'browser/ui/cocoa/web_intent_sheet_controller_browsertest.mm', 'browser/ui/find_bar/find_bar_host_browsertest.cc', + 'browser/ui/fullscreen_controller_browsertest.cc', 'browser/ui/global_error_service_browsertest.cc', 'browser/ui/gtk/one_click_signin_bubble_gtk_browsertest.cc', 'browser/ui/gtk/view_id_util_browsertest.cc', -- cgit v1.1