Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / ui / exclusive_access / fullscreen_controller_interactive_browsertest.cc
blobf2f68d0d0afe4d0ffc107273c0bfec006ae6d3fb
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 "build/build_config.h"
6 #include "chrome/browser/fullscreen.h"
7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_commands.h"
10 #include "chrome/browser/ui/browser_window.h"
11 #include "chrome/browser/ui/exclusive_access/fullscreen_controller_test.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/test/base/interactive_test_utils.h"
14 #include "chrome/test/base/ui_test_utils.h"
15 #include "components/content_settings/core/browser/host_content_settings_map.h"
16 #include "content/public/browser/render_view_host.h"
17 #include "content/public/browser/render_widget_host_view.h"
18 #include "content/public/browser/web_contents.h"
19 #include "content/public/common/url_constants.h"
21 using url::kAboutBlankURL;
22 using content::WebContents;
23 using ui::PAGE_TRANSITION_TYPED;
25 namespace {
27 const base::FilePath::CharType* kSimpleFile = FILE_PATH_LITERAL("simple.html");
29 } // namespace
31 class FullscreenControllerInteractiveTest
32 : public FullscreenControllerTest {
33 protected:
35 // Tests that actually make the browser fullscreen have been flaky when
36 // run sharded, and so are restricted here to interactive ui tests.
37 void ToggleTabFullscreen(bool enter_fullscreen);
38 void ToggleTabFullscreenNoRetries(bool enter_fullscreen);
39 void ToggleBrowserFullscreen(bool enter_fullscreen);
41 // IsMouseLocked verifies that the FullscreenController state believes
42 // the mouse is locked. This is possible only for tests that initiate
43 // mouse lock from a renderer process, and uses logic that tests that the
44 // browser has focus. Thus, this can only be used in interactive ui tests
45 // and not on sharded tests.
46 bool IsMouseLocked() {
47 // Verify that IsMouseLocked is consistent between the
48 // Fullscreen Controller and the Render View Host View.
49 EXPECT_TRUE(browser()->IsMouseLocked() ==
50 browser()->tab_strip_model()->GetActiveWebContents()->
51 GetRenderViewHost()->GetView()->IsMouseLocked());
52 return browser()->IsMouseLocked();
55 void TestFullscreenMouseLockContentSettings();
57 private:
58 void ToggleTabFullscreen_Internal(bool enter_fullscreen,
59 bool retry_until_success);
62 void FullscreenControllerInteractiveTest::ToggleTabFullscreen(
63 bool enter_fullscreen) {
64 ToggleTabFullscreen_Internal(enter_fullscreen, true);
67 // |ToggleTabFullscreen| should not need to tolerate the transition failing.
68 // Most fullscreen tests run sharded in fullscreen_controller_browsertest.cc
69 // and some flakiness has occurred when calling |ToggleTabFullscreen|, so that
70 // method has been made robust by retrying if the transition fails.
71 // The root cause of that flakiness should still be tracked down, see
72 // http://crbug.com/133831. In the mean time, this method
73 // allows a fullscreen_controller_interactive_browsertest.cc test to verify
74 // that when running serially there is no flakiness in the transition.
75 void FullscreenControllerInteractiveTest::ToggleTabFullscreenNoRetries(
76 bool enter_fullscreen) {
77 ToggleTabFullscreen_Internal(enter_fullscreen, false);
80 void FullscreenControllerInteractiveTest::ToggleBrowserFullscreen(
81 bool enter_fullscreen) {
82 ASSERT_EQ(browser()->window()->IsFullscreen(), !enter_fullscreen);
83 FullscreenNotificationObserver fullscreen_observer;
85 chrome::ToggleFullscreenMode(browser());
87 fullscreen_observer.Wait();
88 ASSERT_EQ(browser()->window()->IsFullscreen(), enter_fullscreen);
89 ASSERT_EQ(IsFullscreenForBrowser(), enter_fullscreen);
92 // Helper method to be called by multiple tests.
93 // Tests Fullscreen and Mouse Lock with varying content settings ALLOW & BLOCK.
94 void
95 FullscreenControllerInteractiveTest::TestFullscreenMouseLockContentSettings() {
96 GURL url = test_server()->GetURL("simple.html");
97 AddTabAtIndex(0, url, PAGE_TRANSITION_TYPED);
99 // Validate that going fullscreen for a URL defaults to asking permision.
100 ASSERT_FALSE(IsFullscreenPermissionRequested());
101 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true));
102 ASSERT_TRUE(IsFullscreenPermissionRequested());
103 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(false));
105 // Add content setting to ALLOW fullscreen.
106 HostContentSettingsMap* settings_map =
107 browser()->profile()->GetHostContentSettingsMap();
108 ContentSettingsPattern pattern =
109 ContentSettingsPattern::FromURL(url);
110 settings_map->SetContentSetting(
111 pattern, ContentSettingsPattern::Wildcard(),
112 CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string(),
113 CONTENT_SETTING_ALLOW);
115 // Now, fullscreen should not prompt for permission.
116 ASSERT_FALSE(IsFullscreenPermissionRequested());
117 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true));
118 ASSERT_FALSE(IsFullscreenPermissionRequested());
120 // Leaving tab in fullscreen, now test mouse lock ALLOW:
122 // Validate that mouse lock defaults to asking permision.
123 ASSERT_FALSE(IsMouseLockPermissionRequested());
124 RequestToLockMouse(true, false);
125 ASSERT_TRUE(IsMouseLockPermissionRequested());
126 LostMouseLock();
128 // Add content setting to ALLOW mouse lock.
129 settings_map->SetContentSetting(
130 pattern, ContentSettingsPattern::Wildcard(),
131 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string(),
132 CONTENT_SETTING_ALLOW);
134 // Now, mouse lock should not prompt for permission.
135 ASSERT_FALSE(IsMouseLockPermissionRequested());
136 RequestToLockMouse(true, false);
137 ASSERT_FALSE(IsMouseLockPermissionRequested());
138 LostMouseLock();
140 // Leaving tab in fullscreen, now test mouse lock BLOCK:
142 // Add content setting to BLOCK mouse lock.
143 settings_map->SetContentSetting(
144 pattern, ContentSettingsPattern::Wildcard(),
145 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string(),
146 CONTENT_SETTING_BLOCK);
148 // Now, mouse lock should not be pending.
149 ASSERT_FALSE(IsMouseLockPermissionRequested());
150 RequestToLockMouse(true, false);
151 ASSERT_FALSE(IsMouseLockPermissionRequested());
154 void FullscreenControllerInteractiveTest::ToggleTabFullscreen_Internal(
155 bool enter_fullscreen, bool retry_until_success) {
156 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
157 do {
158 FullscreenNotificationObserver fullscreen_observer;
159 if (enter_fullscreen)
160 browser()->EnterFullscreenModeForTab(tab, GURL());
161 else
162 browser()->ExitFullscreenModeForTab(tab);
163 fullscreen_observer.Wait();
164 // Repeat ToggleFullscreenModeForTab until the correct state is entered.
165 // This addresses flakiness on test bots running many fullscreen
166 // tests in parallel.
167 } while (retry_until_success &&
168 !IsFullscreenForBrowser() &&
169 browser()->window()->IsFullscreen() != enter_fullscreen);
170 ASSERT_EQ(IsWindowFullscreenForTabOrPending(), enter_fullscreen);
171 if (!IsFullscreenForBrowser())
172 ASSERT_EQ(browser()->window()->IsFullscreen(), enter_fullscreen);
175 // Tests ///////////////////////////////////////////////////////////////////////
177 // Tests that while in fullscreen creating a new tab will exit fullscreen.
178 // Test is flaky: http://crbug.com/146006
179 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest,
180 DISABLED_TestNewTabExitsFullscreen) {
181 ASSERT_TRUE(test_server()->Start());
183 AddTabAtIndex(0, GURL(url::kAboutBlankURL), PAGE_TRANSITION_TYPED);
185 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true));
188 FullscreenNotificationObserver fullscreen_observer;
189 AddTabAtIndex(1, GURL(url::kAboutBlankURL), PAGE_TRANSITION_TYPED);
190 fullscreen_observer.Wait();
191 ASSERT_FALSE(browser()->window()->IsFullscreen());
195 // Tests a tab exiting fullscreen will bring the browser out of fullscreen.
196 // Test is flaky: http://crbug.com/146006
197 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest,
198 DISABLED_TestTabExitsItselfFromFullscreen) {
199 ASSERT_TRUE(test_server()->Start());
201 AddTabAtIndex(0, GURL(url::kAboutBlankURL), PAGE_TRANSITION_TYPED);
203 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true));
204 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(false));
207 // Tests entering fullscreen and then requesting mouse lock results in
208 // buttons for the user, and that after confirming the buttons are dismissed.
209 // Test is flaky: http://crbug.com/146006
210 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest,
211 DISABLED_TestFullscreenBubbleMouseLockState) {
212 ASSERT_TRUE(test_server()->Start());
214 AddTabAtIndex(0, GURL(url::kAboutBlankURL), PAGE_TRANSITION_TYPED);
215 AddTabAtIndex(1, GURL(url::kAboutBlankURL), PAGE_TRANSITION_TYPED);
217 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true));
219 // Request mouse lock and verify the bubble is waiting for user confirmation.
220 RequestToLockMouse(true, false);
221 ASSERT_TRUE(IsMouseLockPermissionRequested());
223 // Accept mouse lock and verify bubble no longer shows confirmation buttons.
224 AcceptCurrentFullscreenOrMouseLockRequest();
225 ASSERT_FALSE(IsFullscreenBubbleDisplayingButtons());
228 // Tests fullscreen and Mouse Lock with varying content settings ALLOW & BLOCK.
229 // http://crbug.com/146006
230 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest,
231 DISABLED_FullscreenMouseLockContentSettings) {
232 TestFullscreenMouseLockContentSettings();
235 // Tests fullscreen and Mouse Lock with varying content settings ALLOW & BLOCK,
236 // but with the browser initiated in fullscreen mode first.
237 // Test is flaky: http://crbug.com/103912, http://crbug.com/146006
238 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest,
239 DISABLED_BrowserFullscreenMouseLockContentSettings) {
240 // Enter browser fullscreen first.
241 ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(true));
242 TestFullscreenMouseLockContentSettings();
243 ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(false));
246 // Tests Fullscreen entered in Browser, then Tab mode, then exited via Browser.
247 // Test is flaky: http://crbug.com/146006
248 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest,
249 DISABLED_BrowserFullscreenExit) {
250 // Enter browser fullscreen.
251 ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(true));
253 // Enter tab fullscreen.
254 AddTabAtIndex(0, GURL(url::kAboutBlankURL), PAGE_TRANSITION_TYPED);
255 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true));
257 // Exit browser fullscreen.
258 ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(false));
259 ASSERT_FALSE(browser()->window()->IsFullscreen());
262 // Tests Browser Fullscreen remains active after Tab mode entered and exited.
263 // Test is flaky: http://crbug.com/146006
264 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest,
265 DISABLED_BrowserFullscreenAfterTabFSExit) {
266 // Enter browser fullscreen.
267 ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(true));
269 // Enter and then exit tab fullscreen.
270 AddTabAtIndex(0, GURL(url::kAboutBlankURL), PAGE_TRANSITION_TYPED);
271 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true));
272 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(false));
274 // Verify browser fullscreen still active.
275 ASSERT_TRUE(IsFullscreenForBrowser());
278 // Tests fullscreen entered without permision prompt for file:// urls.
279 // Test is flaky: http://crbug.com/146006
280 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest,
281 DISABLED_FullscreenFileURL) {
282 ui_test_utils::NavigateToURL(
283 browser(), ui_test_utils::GetTestUrl(
284 base::FilePath(base::FilePath::kCurrentDirectory),
285 base::FilePath(kSimpleFile)));
287 // Validate that going fullscreen for a file does not ask permision.
288 ASSERT_FALSE(IsFullscreenPermissionRequested());
289 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true));
290 ASSERT_FALSE(IsFullscreenPermissionRequested());
291 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(false));
294 // Tests fullscreen is exited on page navigation.
295 // Test is flaky: http://crbug.com/146006
296 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest,
297 DISABLED_TestTabExitsFullscreenOnNavigation) {
298 ASSERT_TRUE(test_server()->Start());
300 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
301 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true));
302 ui_test_utils::NavigateToURL(browser(), GURL("chrome://newtab"));
304 ASSERT_FALSE(browser()->window()->IsFullscreen());
307 // Tests fullscreen is exited when navigating back.
308 // Test is flaky: http://crbug.com/146006
309 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest,
310 DISABLED_TestTabExitsFullscreenOnGoBack) {
311 ASSERT_TRUE(test_server()->Start());
313 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
314 ui_test_utils::NavigateToURL(browser(), GURL("chrome://newtab"));
316 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true));
318 GoBack();
320 ASSERT_FALSE(browser()->window()->IsFullscreen());
323 // Tests fullscreen is not exited on sub frame navigation.
324 // Test is flaky: http://crbug.com/146006
325 IN_PROC_BROWSER_TEST_F(
326 FullscreenControllerInteractiveTest,
327 DISABLED_TestTabDoesntExitFullscreenOnSubFrameNavigation) {
328 ASSERT_TRUE(test_server()->Start());
330 GURL url(ui_test_utils::GetTestUrl(base::FilePath(
331 base::FilePath::kCurrentDirectory), base::FilePath(kSimpleFile)));
332 GURL url_with_fragment(url.spec() + "#fragment");
334 ui_test_utils::NavigateToURL(browser(), url);
335 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true));
336 ui_test_utils::NavigateToURL(browser(), url_with_fragment);
337 ASSERT_TRUE(IsWindowFullscreenForTabOrPending());
340 // Tests tab fullscreen exits, but browser fullscreen remains, on navigation.
341 // Test is flaky: http://crbug.com/146006
342 IN_PROC_BROWSER_TEST_F(
343 FullscreenControllerInteractiveTest,
344 DISABLED_TestFullscreenFromTabWhenAlreadyInBrowserFullscreenWorks) {
345 ASSERT_TRUE(test_server()->Start());
347 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
348 ui_test_utils::NavigateToURL(browser(), GURL("chrome://newtab"));
350 ASSERT_NO_FATAL_FAILURE(ToggleBrowserFullscreen(true));
351 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true));
353 GoBack();
355 ASSERT_TRUE(IsFullscreenForBrowser());
356 ASSERT_FALSE(IsWindowFullscreenForTabOrPending());
359 #if defined(OS_MACOSX)
360 // http://crbug.com/100467
361 IN_PROC_BROWSER_TEST_F(
362 FullscreenControllerTest, DISABLED_TabEntersPresentationModeFromWindowed) {
363 ASSERT_TRUE(test_server()->Start());
365 AddTabAtIndex(0, GURL(url::kAboutBlankURL), PAGE_TRANSITION_TYPED);
367 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
370 FullscreenNotificationObserver fullscreen_observer;
371 EXPECT_FALSE(browser()->window()->IsFullscreen());
372 EXPECT_FALSE(browser()->window()->IsFullscreenWithToolbar());
373 browser()->EnterFullscreenModeForTab(tab, GURL());
374 fullscreen_observer.Wait();
375 EXPECT_TRUE(browser()->window()->IsFullscreen());
376 EXPECT_FALSE(browser()->window()->IsFullscreenWithToolbar());
380 FullscreenNotificationObserver fullscreen_observer;
381 chrome::ToggleFullscreenMode(browser());
382 fullscreen_observer.Wait();
383 EXPECT_FALSE(browser()->window()->IsFullscreen());
384 EXPECT_FALSE(browser()->window()->IsFullscreenWithToolbar());
387 if (chrome::mac::SupportsSystemFullscreen()) {
388 // Test that tab fullscreen mode doesn't make presentation mode the default
389 // on Lion.
390 FullscreenNotificationObserver fullscreen_observer;
391 chrome::ToggleFullscreenMode(browser());
392 fullscreen_observer.Wait();
393 EXPECT_TRUE(browser()->window()->IsFullscreen());
394 EXPECT_TRUE(browser()->window()->IsFullscreenWithToolbar());
397 #endif
399 // Tests mouse lock can be escaped with ESC key.
400 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest, EscapingMouseLock) {
401 ASSERT_TRUE(test_server()->Start());
402 ui_test_utils::NavigateToURL(browser(),
403 test_server()->GetURL(kFullscreenMouseLockHTML));
405 ASSERT_FALSE(IsFullscreenBubbleDisplayed());
407 // Request to lock the mouse.
409 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
410 browser(), ui::VKEY_1, false, false, false, false,
411 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED,
412 content::NotificationService::AllSources()));
414 ASSERT_FALSE(IsFullscreenPermissionRequested());
415 ASSERT_TRUE(IsMouseLockPermissionRequested());
417 // Escape, no prompts should remain.
418 SendEscapeToFullscreenController();
419 ASSERT_FALSE(IsFullscreenPermissionRequested());
420 ASSERT_FALSE(IsMouseLockPermissionRequested());
422 // Request to lock the mouse.
424 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
425 browser(), ui::VKEY_1, false, false, false, false,
426 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED,
427 content::NotificationService::AllSources()));
429 ASSERT_FALSE(IsFullscreenPermissionRequested());
430 ASSERT_TRUE(IsMouseLockPermissionRequested());
432 // Accept mouse lock, confirm it and that there is no prompt.
433 AcceptCurrentFullscreenOrMouseLockRequest();
434 ASSERT_TRUE(IsMouseLocked());
435 ASSERT_FALSE(IsWindowFullscreenForTabOrPending());
436 ASSERT_FALSE(IsFullscreenPermissionRequested());
437 ASSERT_FALSE(IsMouseLockPermissionRequested());
439 // Escape, confirm we are out of mouse lock with no prompts.
440 SendEscapeToFullscreenController();
441 ASSERT_FALSE(IsMouseLocked());
442 ASSERT_FALSE(IsWindowFullscreenForTabOrPending());
443 ASSERT_FALSE(IsFullscreenPermissionRequested());
444 ASSERT_FALSE(IsMouseLockPermissionRequested());
447 // Tests mouse lock and fullscreen modes can be escaped with ESC key.
448 // Test is flaky: http://crbug.com/146006
449 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest,
450 DISABLED_EscapingMouseLockAndFullscreen) {
451 ASSERT_TRUE(test_server()->Start());
452 ui_test_utils::NavigateToURL(browser(),
453 test_server()->GetURL(kFullscreenMouseLockHTML));
455 ASSERT_FALSE(IsFullscreenBubbleDisplayed());
457 // Request to lock the mouse and enter fullscreen.
459 FullscreenNotificationObserver fullscreen_observer;
460 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
461 browser(), ui::VKEY_B, false, true, false, false,
462 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED,
463 content::NotificationService::AllSources()));
464 fullscreen_observer.Wait();
466 ASSERT_TRUE(IsFullscreenPermissionRequested());
467 ASSERT_TRUE(IsMouseLockPermissionRequested());
469 // Escape, no prompts should remain.
471 FullscreenNotificationObserver fullscreen_observer;
472 SendEscapeToFullscreenController();
473 fullscreen_observer.Wait();
475 ASSERT_FALSE(IsFullscreenPermissionRequested());
476 ASSERT_FALSE(IsMouseLockPermissionRequested());
478 // Request to lock the mouse and enter fullscreen.
480 FullscreenNotificationObserver fullscreen_observer;
481 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
482 browser(), ui::VKEY_B, false, true, false, false,
483 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED,
484 content::NotificationService::AllSources()));
485 fullscreen_observer.Wait();
487 ASSERT_TRUE(IsFullscreenPermissionRequested());
488 ASSERT_TRUE(IsMouseLockPermissionRequested());
490 // Accept both, confirm mouse lock and fullscreen and no prompts.
491 AcceptCurrentFullscreenOrMouseLockRequest();
492 ASSERT_TRUE(IsMouseLocked());
493 ASSERT_TRUE(IsWindowFullscreenForTabOrPending());
494 ASSERT_FALSE(IsFullscreenPermissionRequested());
495 ASSERT_FALSE(IsMouseLockPermissionRequested());
497 // Escape, confirm we are out of mouse lock and fullscreen with no prompts.
499 FullscreenNotificationObserver fullscreen_observer;
500 SendEscapeToFullscreenController();
501 fullscreen_observer.Wait();
503 ASSERT_FALSE(IsMouseLocked());
504 ASSERT_FALSE(IsWindowFullscreenForTabOrPending());
505 ASSERT_FALSE(IsFullscreenPermissionRequested());
506 ASSERT_FALSE(IsMouseLockPermissionRequested());
509 // Tests mouse lock then fullscreen.
510 // Test is flaky: http://crbug.com/146006
511 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest,
512 DISABLED_MouseLockThenFullscreen) {
513 ASSERT_TRUE(test_server()->Start());
514 ui_test_utils::NavigateToURL(browser(),
515 test_server()->GetURL(kFullscreenMouseLockHTML));
517 ASSERT_FALSE(IsFullscreenBubbleDisplayed());
519 // Lock the mouse without a user gesture, expect no response.
520 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
521 browser(), ui::VKEY_D, false, false, false, false,
522 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED,
523 content::NotificationService::AllSources()));
524 ASSERT_FALSE(IsFullscreenBubbleDisplayed());
525 ASSERT_FALSE(IsMouseLocked());
527 // Lock the mouse with a user gesture.
528 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
529 browser(), ui::VKEY_1, false, false, false, false,
530 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED,
531 content::NotificationService::AllSources()));
532 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
533 ASSERT_FALSE(IsFullscreenPermissionRequested());
534 ASSERT_TRUE(IsMouseLockPermissionRequested());
535 ASSERT_FALSE(IsMouseLocked());
537 // Accept mouse lock.
538 AcceptCurrentFullscreenOrMouseLockRequest();
539 ASSERT_TRUE(IsMouseLocked());
540 ASSERT_FALSE(IsFullscreenBubbleDisplayingButtons());
542 // Enter fullscreen mode, mouse lock should be dropped to present buttons.
543 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreen(true));
544 ASSERT_TRUE(IsFullscreenPermissionRequested());
545 ASSERT_FALSE(IsMouseLockPermissionRequested());
546 ASSERT_FALSE(IsMouseLocked());
548 // Request mouse lock also, expect fullscreen and mouse lock buttons.
549 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
550 browser(), ui::VKEY_1, false, false, false, false,
551 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED,
552 content::NotificationService::AllSources()));
553 ASSERT_TRUE(IsFullscreenPermissionRequested());
554 ASSERT_TRUE(IsMouseLockPermissionRequested());
555 ASSERT_FALSE(IsMouseLocked());
557 // Accept fullscreen and mouse lock.
558 AcceptCurrentFullscreenOrMouseLockRequest();
559 ASSERT_TRUE(IsMouseLocked());
560 ASSERT_TRUE(IsWindowFullscreenForTabOrPending());
561 ASSERT_FALSE(IsFullscreenBubbleDisplayingButtons());
564 // Times out sometimes on Linux. http://crbug.com/135115
565 // Mac: http://crbug.com/103912
566 // Windows: Failing flakily on try jobs also.
567 // Tests mouse lock then fullscreen in same request.
568 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest,
569 DISABLED_MouseLockAndFullscreen) {
570 ASSERT_TRUE(test_server()->Start());
571 ui_test_utils::NavigateToURL(browser(),
572 test_server()->GetURL(kFullscreenMouseLockHTML));
574 ASSERT_FALSE(IsFullscreenBubbleDisplayed());
576 // Request to lock the mouse and enter fullscreen.
578 FullscreenNotificationObserver fullscreen_observer;
579 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
580 browser(), ui::VKEY_B, false, true, false, false,
581 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED,
582 content::NotificationService::AllSources()));
583 fullscreen_observer.Wait();
585 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
586 ASSERT_TRUE(IsFullscreenPermissionRequested());
587 ASSERT_TRUE(IsMouseLockPermissionRequested());
588 ASSERT_FALSE(IsMouseLocked());
589 ASSERT_TRUE(IsWindowFullscreenForTabOrPending());
591 // Deny both first, to make sure we can.
593 FullscreenNotificationObserver fullscreen_observer;
594 DenyCurrentFullscreenOrMouseLockRequest();
595 fullscreen_observer.Wait();
597 ASSERT_FALSE(IsMouseLocked());
598 ASSERT_FALSE(IsWindowFullscreenForTabOrPending());
599 ASSERT_FALSE(IsFullscreenPermissionRequested());
601 // Request to lock the mouse and enter fullscreen.
603 FullscreenNotificationObserver fullscreen_observer;
604 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
605 browser(), ui::VKEY_B, false, true, false, false,
606 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED,
607 content::NotificationService::AllSources()));
608 fullscreen_observer.Wait();
610 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
611 ASSERT_TRUE(IsFullscreenPermissionRequested());
612 ASSERT_TRUE(IsMouseLockPermissionRequested());
613 ASSERT_FALSE(IsMouseLocked());
614 ASSERT_TRUE(IsWindowFullscreenForTabOrPending());
616 // Accept both, confirm they are enabled and there is no prompt.
617 AcceptCurrentFullscreenOrMouseLockRequest();
618 ASSERT_TRUE(IsMouseLocked());
619 ASSERT_TRUE(IsWindowFullscreenForTabOrPending());
620 ASSERT_FALSE(IsFullscreenPermissionRequested());
623 // Tests mouse lock and fullscreen for the privileged fullscreen case (e.g.,
624 // embedded flash fullscreen, since the Flash plugin handles user permissions
625 // requests itself).
626 // Test is flaky: http://crbug.com/146006
627 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest,
628 DISABLED_PrivilegedMouseLockAndFullscreen) {
629 ASSERT_TRUE(test_server()->Start());
630 ui_test_utils::NavigateToURL(browser(),
631 test_server()->GetURL(kFullscreenMouseLockHTML));
633 ASSERT_FALSE(IsFullscreenBubbleDisplayed());
635 SetPrivilegedFullscreen(true);
637 // Request to lock the mouse and enter fullscreen.
638 FullscreenNotificationObserver fullscreen_observer;
639 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
640 browser(), ui::VKEY_B, false, true, false, false,
641 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED,
642 content::NotificationService::AllSources()));
643 fullscreen_observer.Wait();
645 // Confirm they are enabled and there is no prompt.
646 ASSERT_FALSE(IsFullscreenBubbleDisplayed());
647 ASSERT_FALSE(IsFullscreenPermissionRequested());
648 ASSERT_FALSE(IsMouseLockPermissionRequested());
649 ASSERT_TRUE(IsMouseLocked());
650 ASSERT_TRUE(IsWindowFullscreenForTabOrPending());
653 // Flaky on Windows, Linux, CrOS: http://crbug.com/159000
654 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_CHROMEOS)
655 #define MAYBE_MouseLockSilentAfterTargetUnlock \
656 DISABLED_MouseLockSilentAfterTargetUnlock
657 #else
658 #define MAYBE_MouseLockSilentAfterTargetUnlock MouseLockSilentAfterTargetUnlock
659 #endif
661 // Tests mouse lock can be exited and re-entered by an application silently
662 // with no UI distraction for users.
663 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest,
664 MAYBE_MouseLockSilentAfterTargetUnlock) {
665 ASSERT_TRUE(test_server()->Start());
666 ui_test_utils::NavigateToURL(browser(),
667 test_server()->GetURL(kFullscreenMouseLockHTML));
669 ASSERT_FALSE(IsFullscreenBubbleDisplayed());
671 // Lock the mouse with a user gesture.
672 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
673 browser(), ui::VKEY_1, false, false, false, false,
674 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED,
675 content::NotificationService::AllSources()));
676 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
677 ASSERT_TRUE(IsMouseLockPermissionRequested());
678 ASSERT_FALSE(IsMouseLocked());
680 // Accept mouse lock.
681 AcceptCurrentFullscreenOrMouseLockRequest();
682 ASSERT_TRUE(IsMouseLocked());
683 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
685 // Unlock the mouse from target, make sure it's unlocked.
686 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
687 browser(), ui::VKEY_U, false, false, false, false,
688 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED,
689 content::NotificationService::AllSources()));
690 ASSERT_FALSE(IsMouseLocked());
691 ASSERT_FALSE(IsFullscreenBubbleDisplayed());
693 // Lock mouse again, make sure it works with no bubble.
694 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
695 browser(), ui::VKEY_1, false, false, false, false,
696 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED,
697 content::NotificationService::AllSources()));
698 ASSERT_TRUE(IsMouseLocked());
699 ASSERT_FALSE(IsFullscreenBubbleDisplayed());
701 // Unlock the mouse again by target.
702 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
703 browser(), ui::VKEY_U, false, false, false, false,
704 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED,
705 content::NotificationService::AllSources()));
706 ASSERT_FALSE(IsMouseLocked());
708 // Lock from target, not user gesture, make sure it works.
709 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
710 browser(), ui::VKEY_D, false, false, false, false,
711 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED,
712 content::NotificationService::AllSources()));
713 ASSERT_TRUE(IsMouseLocked());
714 ASSERT_FALSE(IsFullscreenBubbleDisplayed());
716 // Unlock by escape.
717 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
718 browser(), ui::VKEY_ESCAPE, false, false, false, false,
719 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED,
720 content::NotificationService::AllSources()));
721 ASSERT_FALSE(IsMouseLocked());
723 // Lock the mouse with a user gesture, make sure we see bubble again.
724 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
725 browser(), ui::VKEY_1, false, false, false, false,
726 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED,
727 content::NotificationService::AllSources()));
728 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
729 ASSERT_TRUE(IsMouseLocked());
732 #if defined(OS_WIN) || \
733 (defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA))
734 // These tests are very flaky on Vista.
735 // http://crbug.com/158762
736 // These are flaky on linux_aura.
737 // http://crbug.com/163931
738 #define MAYBE_TestTabExitsMouseLockOnNavigation \
739 DISABLED_TestTabExitsMouseLockOnNavigation
740 #define MAYBE_TestTabExitsMouseLockOnGoBack \
741 DISABLED_TestTabExitsMouseLockOnGoBack
742 #else
743 #define MAYBE_TestTabExitsMouseLockOnNavigation \
744 TestTabExitsMouseLockOnNavigation
745 #define MAYBE_TestTabExitsMouseLockOnGoBack \
746 TestTabExitsMouseLockOnGoBack
747 #endif
749 // Tests mouse lock is exited on page navigation.
750 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest,
751 MAYBE_TestTabExitsMouseLockOnNavigation) {
752 ASSERT_TRUE(test_server()->Start());
753 ui_test_utils::NavigateToURL(browser(),
754 test_server()->GetURL(kFullscreenMouseLockHTML));
756 // Lock the mouse with a user gesture.
757 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
758 browser(), ui::VKEY_1, false, false, false, false,
759 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED,
760 content::NotificationService::AllSources()));
761 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
762 ASSERT_TRUE(IsMouseLockPermissionRequested());
763 ASSERT_FALSE(IsMouseLocked());
765 // Accept mouse lock.
766 AcceptCurrentFullscreenOrMouseLockRequest();
767 ASSERT_TRUE(IsMouseLocked());
769 ui_test_utils::NavigateToURL(browser(), GURL("chrome://newtab"));
771 ASSERT_FALSE(IsMouseLocked());
774 // Tests mouse lock is exited when navigating back.
775 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest,
776 MAYBE_TestTabExitsMouseLockOnGoBack) {
777 ASSERT_TRUE(test_server()->Start());
779 // Navigate twice to provide a place to go back to.
780 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
781 ui_test_utils::NavigateToURL(browser(),
782 test_server()->GetURL(kFullscreenMouseLockHTML));
784 // Lock the mouse with a user gesture.
785 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
786 browser(), ui::VKEY_1, false, false, false, false,
787 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED,
788 content::NotificationService::AllSources()));
789 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
790 ASSERT_TRUE(IsMouseLockPermissionRequested());
791 ASSERT_FALSE(IsMouseLocked());
793 // Accept mouse lock.
794 AcceptCurrentFullscreenOrMouseLockRequest();
795 ASSERT_TRUE(IsMouseLocked());
797 GoBack();
799 ASSERT_FALSE(IsMouseLocked());
802 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
803 // TODO(erg): linux_aura bringup: http://crbug.com/163931
804 #define MAYBE_TestTabDoesntExitMouseLockOnSubFrameNavigation DISABLED_TestTabDoesntExitMouseLockOnSubFrameNavigation
805 #else
806 #define MAYBE_TestTabDoesntExitMouseLockOnSubFrameNavigation TestTabDoesntExitMouseLockOnSubFrameNavigation
807 #endif
809 // Tests mouse lock is not exited on sub frame navigation.
810 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest,
811 MAYBE_TestTabDoesntExitMouseLockOnSubFrameNavigation) {
812 ASSERT_TRUE(test_server()->Start());
814 // Create URLs for test page and test page with #fragment.
815 GURL url(test_server()->GetURL(kFullscreenMouseLockHTML));
816 GURL url_with_fragment(url.spec() + "#fragment");
818 // Navigate to test page.
819 ui_test_utils::NavigateToURL(browser(), url);
821 // Lock the mouse with a user gesture.
822 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
823 browser(), ui::VKEY_1, false, false, false, false,
824 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED,
825 content::NotificationService::AllSources()));
826 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
827 ASSERT_TRUE(IsMouseLockPermissionRequested());
828 ASSERT_FALSE(IsMouseLocked());
830 // Accept mouse lock.
831 AcceptCurrentFullscreenOrMouseLockRequest();
832 ASSERT_TRUE(IsMouseLocked());
834 // Navigate to url with fragment. Mouse lock should persist.
835 ui_test_utils::NavigateToURL(browser(), url_with_fragment);
836 ASSERT_TRUE(IsMouseLocked());
839 // Tests Mouse Lock and Fullscreen are exited upon reload.
840 // http://crbug.com/137486
841 // mac: http://crbug.com/103912
842 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest,
843 DISABLED_ReloadExitsMouseLockAndFullscreen) {
844 ASSERT_TRUE(test_server()->Start());
845 ui_test_utils::NavigateToURL(browser(),
846 test_server()->GetURL(kFullscreenMouseLockHTML));
848 ASSERT_FALSE(IsMouseLockPermissionRequested());
850 // Request mouse lock.
851 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
852 browser(), ui::VKEY_1, false, false, false, false,
853 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED,
854 content::NotificationService::AllSources()));
855 ASSERT_TRUE(IsMouseLockPermissionRequested());
857 // Reload. Mouse lock request should be cleared.
859 MouseLockNotificationObserver mouselock_observer;
860 Reload();
861 mouselock_observer.Wait();
862 ASSERT_FALSE(IsMouseLockPermissionRequested());
865 // Request mouse lock.
866 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
867 browser(), ui::VKEY_1, false, false, false, false,
868 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED,
869 content::NotificationService::AllSources()));
870 ASSERT_TRUE(IsMouseLockPermissionRequested());
872 // Accept mouse lock.
873 AcceptCurrentFullscreenOrMouseLockRequest();
874 ASSERT_TRUE(IsMouseLocked());
875 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
877 // Reload. Mouse should be unlocked.
879 MouseLockNotificationObserver mouselock_observer;
880 Reload();
881 mouselock_observer.Wait();
882 ASSERT_FALSE(IsMouseLocked());
885 // Request to lock the mouse and enter fullscreen.
887 FullscreenNotificationObserver fullscreen_observer;
888 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
889 browser(), ui::VKEY_B, false, true, false, false,
890 chrome::NOTIFICATION_MOUSE_LOCK_CHANGED,
891 content::NotificationService::AllSources()));
892 fullscreen_observer.Wait();
895 // We are fullscreen.
896 ASSERT_TRUE(IsWindowFullscreenForTabOrPending());
898 // Reload. Mouse should be unlocked and fullscreen exited.
900 FullscreenNotificationObserver fullscreen_observer;
901 Reload();
902 fullscreen_observer.Wait();
903 ASSERT_FALSE(IsMouseLocked());
904 ASSERT_FALSE(IsWindowFullscreenForTabOrPending());
908 // Tests ToggleFullscreenModeForTab always causes window to change.
909 // Test is flaky: http://crbug.com/146006
910 IN_PROC_BROWSER_TEST_F(FullscreenControllerInteractiveTest,
911 DISABLED_ToggleFullscreenModeForTab) {
912 // Most fullscreen tests run sharded in fullscreen_controller_browsertest.cc
913 // but flakiness required a while loop in
914 // FullscreenControllerTest::ToggleTabFullscreen. This test verifies that
915 // when running serially there is no flakiness.
916 // This test reproduces the same flow as
917 // TestFullscreenMouseLockContentSettings.
918 // http://crbug.com/133831
920 GURL url = test_server()->GetURL("simple.html");
921 AddTabAtIndex(0, url, PAGE_TRANSITION_TYPED);
923 // Validate that going fullscreen for a URL defaults to asking permision.
924 ASSERT_FALSE(IsFullscreenPermissionRequested());
925 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreenNoRetries(true));
926 ASSERT_TRUE(IsFullscreenPermissionRequested());
927 ASSERT_NO_FATAL_FAILURE(ToggleTabFullscreenNoRetries(false));