OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #if defined(OS_MACOSX) | 10 #if defined(OS_MACOSX) |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 86 |
87 const FilePath::CharType* kBeforeUnloadFile = | 87 const FilePath::CharType* kBeforeUnloadFile = |
88 FILE_PATH_LITERAL("beforeunload.html"); | 88 FILE_PATH_LITERAL("beforeunload.html"); |
89 | 89 |
90 const FilePath::CharType* kSimpleFile = FILE_PATH_LITERAL("simple.html"); | 90 const FilePath::CharType* kSimpleFile = FILE_PATH_LITERAL("simple.html"); |
91 const FilePath::CharType* kTitle1File = FILE_PATH_LITERAL("title1.html"); | 91 const FilePath::CharType* kTitle1File = FILE_PATH_LITERAL("title1.html"); |
92 const FilePath::CharType* kTitle2File = FILE_PATH_LITERAL("title2.html"); | 92 const FilePath::CharType* kTitle2File = FILE_PATH_LITERAL("title2.html"); |
93 | 93 |
94 const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); | 94 const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); |
95 | 95 |
| 96 const char* kFullscreenMouseLockHTML = |
| 97 "files/fullscreen_mouselock/fullscreen_mouselock.html"; |
| 98 |
96 // Given a page title, returns the expected window caption string. | 99 // Given a page title, returns the expected window caption string. |
97 std::wstring WindowCaptionFromPageTitle(std::wstring page_title) { | 100 std::wstring WindowCaptionFromPageTitle(std::wstring page_title) { |
98 #if defined(OS_MACOSX) || defined(OS_CHROMEOS) | 101 #if defined(OS_MACOSX) || defined(OS_CHROMEOS) |
99 // On Mac or ChromeOS, we don't want to suffix the page title with | 102 // On Mac or ChromeOS, we don't want to suffix the page title with |
100 // the application name. | 103 // the application name. |
101 if (page_title.empty()) { | 104 if (page_title.empty()) { |
102 return UTF16ToWideHack( | 105 return UTF16ToWideHack( |
103 l10n_util::GetStringUTF16(IDS_BROWSER_WINDOW_MAC_TAB_UNTITLED)); | 106 l10n_util::GetStringUTF16(IDS_BROWSER_WINDOW_MAC_TAB_UNTITLED)); |
104 } | 107 } |
105 return page_title; | 108 return page_title; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 public: | 187 public: |
185 FullscreenNotificationObserver() : WindowedNotificationObserver( | 188 FullscreenNotificationObserver() : WindowedNotificationObserver( |
186 chrome::NOTIFICATION_FULLSCREEN_CHANGED, | 189 chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
187 content::NotificationService::AllSources()) {} | 190 content::NotificationService::AllSources()) {} |
188 }; | 191 }; |
189 | 192 |
190 } // namespace | 193 } // namespace |
191 | 194 |
192 class BrowserTest : public ExtensionBrowserTest { | 195 class BrowserTest : public ExtensionBrowserTest { |
193 protected: | 196 protected: |
| 197 virtual void SetUpCommandLine(CommandLine* command_line) { |
| 198 command_line->AppendSwitch(switches::kEnablePointerLock); |
| 199 } |
| 200 |
194 // In RTL locales wrap the page title with RTL embedding characters so that it | 201 // In RTL locales wrap the page title with RTL embedding characters so that it |
195 // matches the value returned by GetWindowTitle(). | 202 // matches the value returned by GetWindowTitle(). |
196 std::wstring LocaleWindowCaptionFromPageTitle( | 203 std::wstring LocaleWindowCaptionFromPageTitle( |
197 const std::wstring& expected_title) { | 204 const std::wstring& expected_title) { |
198 std::wstring page_title = WindowCaptionFromPageTitle(expected_title); | 205 std::wstring page_title = WindowCaptionFromPageTitle(expected_title); |
199 #if defined(OS_WIN) | 206 #if defined(OS_WIN) |
200 std::string locale = g_browser_process->GetApplicationLocale(); | 207 std::string locale = g_browser_process->GetApplicationLocale(); |
201 if (base::i18n::GetTextDirectionForLocale(locale.c_str()) == | 208 if (base::i18n::GetTextDirectionForLocale(locale.c_str()) == |
202 base::i18n::RIGHT_TO_LEFT) { | 209 base::i18n::RIGHT_TO_LEFT) { |
203 base::i18n::WrapStringWithLTRFormatting(&page_title); | 210 base::i18n::WrapStringWithLTRFormatting(&page_title); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 return fullscreen; | 290 return fullscreen; |
284 } | 291 } |
285 | 292 |
286 FullscreenExitBubbleType GetFullscreenExitBubbleType() { | 293 FullscreenExitBubbleType GetFullscreenExitBubbleType() { |
287 return browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); | 294 return browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); |
288 } | 295 } |
289 | 296 |
290 bool IsFullscreenBubbleDisplayed() { | 297 bool IsFullscreenBubbleDisplayed() { |
291 FullscreenExitBubbleType type = | 298 FullscreenExitBubbleType type = |
292 browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); | 299 browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); |
293 // TODO(scheib): Should be FEB_TYPE_NONE, crbug.com/107013 will include fix. | 300 return type != FEB_TYPE_NONE; |
294 return type != FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION; | |
295 } | 301 } |
296 | 302 |
297 bool IsFullscreenBubbleDisplayingButtons() { | 303 bool IsFullscreenBubbleDisplayingButtons() { |
298 FullscreenExitBubbleType type = | 304 FullscreenExitBubbleType type = |
299 browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); | 305 browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); |
300 return fullscreen_bubble::ShowButtonsForType(type); | 306 return fullscreen_bubble::ShowButtonsForType(type); |
301 } | 307 } |
302 | 308 |
303 void AcceptCurrentFullscreenOrMouseLockRequest() { | 309 void AcceptCurrentFullscreenOrMouseLockRequest() { |
304 WebContents* fullscreen_tab = browser()->GetSelectedWebContents(); | 310 WebContents* fullscreen_tab = browser()->GetSelectedWebContents(); |
305 FullscreenExitBubbleType type = | 311 FullscreenExitBubbleType type = |
306 browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); | 312 browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); |
307 browser()->OnAcceptFullscreenPermission(fullscreen_tab->GetURL(), type); | 313 browser()->OnAcceptFullscreenPermission(fullscreen_tab->GetURL(), type); |
308 } | 314 } |
309 | 315 |
| 316 void DenyCurrentFullscreenOrMouseLockRequest() { |
| 317 FullscreenExitBubbleType type = |
| 318 browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); |
| 319 browser()->OnDenyFullscreenPermission(type); |
| 320 } |
| 321 |
310 // Helper method to be called by multiple tests. | 322 // Helper method to be called by multiple tests. |
311 void TestFullscreenMouseLockContentSettings(); | 323 void TestFullscreenMouseLockContentSettings(); |
312 }; | 324 }; |
313 | 325 |
314 // Launch the app on a page with no title, check that the app title was set | 326 // Launch the app on a page with no title, check that the app title was set |
315 // correctly. | 327 // correctly. |
316 IN_PROC_BROWSER_TEST_F(BrowserTest, NoTitle) { | 328 IN_PROC_BROWSER_TEST_F(BrowserTest, NoTitle) { |
317 ui_test_utils::NavigateToURL(browser(), | 329 ui_test_utils::NavigateToURL(browser(), |
318 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), | 330 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
319 FilePath(kTitle1File))); | 331 FilePath(kTitle1File))); |
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1029 | 1041 |
1030 // Request mouse lock and verify the bubble is waiting for user confirmation. | 1042 // Request mouse lock and verify the bubble is waiting for user confirmation. |
1031 RequestToLockMouse(fullscreen_tab, true); | 1043 RequestToLockMouse(fullscreen_tab, true); |
1032 ASSERT_TRUE(IsMouseLockPermissionRequested()); | 1044 ASSERT_TRUE(IsMouseLockPermissionRequested()); |
1033 | 1045 |
1034 // Accept mouse lock and verify bubble no longer shows confirmation buttons. | 1046 // Accept mouse lock and verify bubble no longer shows confirmation buttons. |
1035 AcceptCurrentFullscreenOrMouseLockRequest(); | 1047 AcceptCurrentFullscreenOrMouseLockRequest(); |
1036 ASSERT_FALSE(IsFullscreenBubbleDisplayingButtons()); | 1048 ASSERT_FALSE(IsFullscreenBubbleDisplayingButtons()); |
1037 } | 1049 } |
1038 | 1050 |
1039 // Tests mouse lock fails before fullscreen is entered. | 1051 // Tests mouse lock then fullscreen. |
1040 IN_PROC_BROWSER_TEST_F(BrowserTest, MouseLockThenFullscreen) { | 1052 IN_PROC_BROWSER_TEST_F(BrowserTest, MouseLockThenFullscreen) { |
| 1053 ASSERT_TRUE(test_server()->Start()); |
| 1054 ui_test_utils::NavigateToURL(browser(), |
| 1055 test_server()->GetURL(kFullscreenMouseLockHTML)); |
| 1056 |
1041 WebContents* tab = browser()->GetSelectedWebContents(); | 1057 WebContents* tab = browser()->GetSelectedWebContents(); |
| 1058 |
1042 ASSERT_FALSE(IsFullscreenBubbleDisplayed()); | 1059 ASSERT_FALSE(IsFullscreenBubbleDisplayed()); |
1043 | 1060 |
1044 RequestToLockMouse(tab, true); | 1061 // Lock the mouse without a user gesture, expect no response. |
| 1062 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
| 1063 browser(), ui::VKEY_D, false, false, false, false, |
| 1064 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, |
| 1065 content::NotificationService::AllSources())); |
1045 ASSERT_FALSE(IsFullscreenBubbleDisplayed()); | 1066 ASSERT_FALSE(IsFullscreenBubbleDisplayed()); |
| 1067 ASSERT_FALSE(IsMouseLocked()); |
1046 | 1068 |
| 1069 // Lock the mouse with a user gesture. |
| 1070 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
| 1071 browser(), ui::VKEY_1, false, false, false, false, |
| 1072 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, |
| 1073 content::NotificationService::AllSources())); |
| 1074 ASSERT_TRUE(IsFullscreenBubbleDisplayed()); |
| 1075 ASSERT_FALSE(IsFullscreenPermissionRequested()); |
| 1076 ASSERT_TRUE(IsMouseLockPermissionRequested()); |
| 1077 ASSERT_FALSE(IsMouseLocked()); |
| 1078 |
| 1079 // Accept mouse lock. |
| 1080 AcceptCurrentFullscreenOrMouseLockRequest(); |
| 1081 ASSERT_TRUE(IsMouseLocked()); |
| 1082 ASSERT_FALSE(IsFullscreenBubbleDisplayingButtons()); |
| 1083 |
| 1084 // Enter fullscreen mode, mouse lock should be dropped to present buttons. |
1047 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(tab, true)); | 1085 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(tab, true)); |
1048 ASSERT_TRUE(IsFullscreenPermissionRequested()); | 1086 ASSERT_TRUE(IsFullscreenPermissionRequested()); |
1049 ASSERT_FALSE(IsMouseLockPermissionRequested()); | 1087 ASSERT_FALSE(IsMouseLockPermissionRequested()); |
| 1088 ASSERT_FALSE(IsMouseLocked()); |
| 1089 |
| 1090 // Request mouse lock also, expect fullscreen and mouse lock buttons. |
| 1091 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
| 1092 browser(), ui::VKEY_1, false, false, false, false, |
| 1093 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, |
| 1094 content::NotificationService::AllSources())); |
| 1095 ASSERT_TRUE(IsFullscreenPermissionRequested()); |
| 1096 ASSERT_TRUE(IsMouseLockPermissionRequested()); |
| 1097 ASSERT_FALSE(IsMouseLocked()); |
| 1098 |
| 1099 // Accept fullscreen and mouse lock. |
| 1100 AcceptCurrentFullscreenOrMouseLockRequest(); |
| 1101 ASSERT_TRUE(IsMouseLocked()); |
| 1102 ASSERT_TRUE(IsFullscreenForTabOrPending()); |
| 1103 ASSERT_FALSE(IsFullscreenBubbleDisplayingButtons()); |
| 1104 } |
| 1105 |
| 1106 // Tests mouse lock then fullscreen in same request. |
| 1107 IN_PROC_BROWSER_TEST_F(BrowserTest, MouseLockAndFullscreen) { |
| 1108 ASSERT_TRUE(test_server()->Start()); |
| 1109 ui_test_utils::NavigateToURL(browser(), |
| 1110 test_server()->GetURL(kFullscreenMouseLockHTML)); |
| 1111 |
| 1112 ASSERT_FALSE(IsFullscreenBubbleDisplayed()); |
| 1113 |
| 1114 // Request to lock the mouse and enter fullscreen. |
| 1115 { |
| 1116 FullscreenNotificationObserver fullscreen_observer; |
| 1117 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
| 1118 browser(), ui::VKEY_B, false, true, false, false, |
| 1119 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, |
| 1120 content::NotificationService::AllSources())); |
| 1121 fullscreen_observer.Wait(); |
| 1122 } |
| 1123 ASSERT_TRUE(IsFullscreenBubbleDisplayed()); |
| 1124 ASSERT_TRUE(IsFullscreenPermissionRequested()); |
| 1125 ASSERT_TRUE(IsMouseLockPermissionRequested()); |
| 1126 ASSERT_FALSE(IsMouseLocked()); |
| 1127 ASSERT_TRUE(IsFullscreenForTabOrPending()); |
| 1128 |
| 1129 // Deny both first, to make sure we can. |
| 1130 { |
| 1131 FullscreenNotificationObserver fullscreen_observer; |
| 1132 DenyCurrentFullscreenOrMouseLockRequest(); |
| 1133 fullscreen_observer.Wait(); |
| 1134 } |
| 1135 ASSERT_FALSE(IsMouseLocked()); |
| 1136 ASSERT_FALSE(IsFullscreenForTabOrPending()); |
| 1137 ASSERT_FALSE(IsFullscreenPermissionRequested()); |
| 1138 |
| 1139 // Request to lock the mouse and enter fullscreen. |
| 1140 { |
| 1141 FullscreenNotificationObserver fullscreen_observer; |
| 1142 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
| 1143 browser(), ui::VKEY_B, false, true, false, false, |
| 1144 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED, |
| 1145 content::NotificationService::AllSources())); |
| 1146 fullscreen_observer.Wait(); |
| 1147 } |
| 1148 ASSERT_TRUE(IsFullscreenBubbleDisplayed()); |
| 1149 ASSERT_TRUE(IsFullscreenPermissionRequested()); |
| 1150 ASSERT_TRUE(IsMouseLockPermissionRequested()); |
| 1151 ASSERT_FALSE(IsMouseLocked()); |
| 1152 ASSERT_TRUE(IsFullscreenForTabOrPending()); |
| 1153 |
| 1154 // Accept both, confirm they are enabled and there is no prompt. |
| 1155 AcceptCurrentFullscreenOrMouseLockRequest(); |
| 1156 ASSERT_TRUE(IsMouseLocked()); |
| 1157 ASSERT_TRUE(IsFullscreenForTabOrPending()); |
| 1158 ASSERT_FALSE(IsFullscreenPermissionRequested()); |
1050 } | 1159 } |
1051 | 1160 |
1052 // Helper method to be called by multiple tests. | 1161 // Helper method to be called by multiple tests. |
1053 // Tests Fullscreen and Mouse Lock with varying content settings ALLOW & BLOCK. | 1162 // Tests Fullscreen and Mouse Lock with varying content settings ALLOW & BLOCK. |
1054 void BrowserTest::TestFullscreenMouseLockContentSettings() { | 1163 void BrowserTest::TestFullscreenMouseLockContentSettings() { |
1055 GURL url = test_server()->GetURL("simple.html"); | 1164 GURL url = test_server()->GetURL("simple.html"); |
1056 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED); | 1165 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED); |
1057 WebContents* tab = browser()->GetSelectedWebContents(); | 1166 WebContents* tab = browser()->GetSelectedWebContents(); |
1058 | 1167 |
1059 // Validate that going fullscreen for a URL defaults to asking permision. | 1168 // Validate that going fullscreen for a URL defaults to asking permision. |
(...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1738 | 1847 |
1739 // The normal browser should now have four. | 1848 // The normal browser should now have four. |
1740 EXPECT_EQ(4, browser()->tab_count()); | 1849 EXPECT_EQ(4, browser()->tab_count()); |
1741 | 1850 |
1742 // Close the additional browsers. | 1851 // Close the additional browsers. |
1743 popup_browser->CloseAllTabs(); | 1852 popup_browser->CloseAllTabs(); |
1744 app_browser->CloseAllTabs(); | 1853 app_browser->CloseAllTabs(); |
1745 app_popup_browser->CloseAllTabs(); | 1854 app_popup_browser->CloseAllTabs(); |
1746 } | 1855 } |
1747 #endif | 1856 #endif |
OLD | NEW |