| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/ui/fullscreen_controller_test.h" | |
| 6 | |
| 7 #include "base/command_line.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/fullscreen_controller.h" | |
| 12 #include "chrome/common/chrome_switches.h" | |
| 13 #include "content/public/browser/web_contents.h" | |
| 14 #include "content/public/test/test_navigation_observer.h" | |
| 15 | |
| 16 using content::WebContents; | |
| 17 | |
| 18 const char FullscreenControllerTest::kFullscreenMouseLockHTML[] = | |
| 19 "files/fullscreen_mouselock/fullscreen_mouselock.html"; | |
| 20 | |
| 21 void FullscreenControllerTest::SetUpCommandLine(CommandLine* command_line) { | |
| 22 InProcessBrowserTest::SetUpCommandLine(command_line); | |
| 23 command_line->AppendSwitch(switches::kEnablePointerLock); | |
| 24 } | |
| 25 | |
| 26 void FullscreenControllerTest::ToggleTabFullscreen(bool enter_fullscreen) { | |
| 27 ToggleTabFullscreen_Internal(enter_fullscreen, true); | |
| 28 } | |
| 29 | |
| 30 // |ToggleTabFullscreen| should not need to tolerate the transition failing. | |
| 31 // Most fullscreen tests run sharded in fullscreen_controller_browsertest.cc | |
| 32 // and some flakiness has occurred when calling |ToggleTabFullscreen|, so that | |
| 33 // method has been made robust by retrying if the transition fails. | |
| 34 // The root cause of that flakiness should still be tracked down, see | |
| 35 // http://crbug.com/133831. In the mean time, this method | |
| 36 // allows a fullscreen_controller_interactive_browsertest.cc test to verify | |
| 37 // that when running serially there is no flakiness in the transition. | |
| 38 void FullscreenControllerTest::ToggleTabFullscreenNoRetries( | |
| 39 bool enter_fullscreen) { | |
| 40 ToggleTabFullscreen_Internal(enter_fullscreen, false); | |
| 41 } | |
| 42 | |
| 43 void FullscreenControllerTest::ToggleBrowserFullscreen(bool enter_fullscreen) { | |
| 44 ASSERT_EQ(browser()->window()->IsFullscreen(), !enter_fullscreen); | |
| 45 FullscreenNotificationObserver fullscreen_observer; | |
| 46 | |
| 47 browser()->ToggleFullscreenMode(); | |
| 48 | |
| 49 fullscreen_observer.Wait(); | |
| 50 ASSERT_EQ(browser()->window()->IsFullscreen(), enter_fullscreen); | |
| 51 ASSERT_EQ(IsFullscreenForBrowser(), enter_fullscreen); | |
| 52 } | |
| 53 | |
| 54 void FullscreenControllerTest::RequestToLockMouse( | |
| 55 bool user_gesture, | |
| 56 bool last_unlocked_by_target) { | |
| 57 WebContents* tab = browser()->GetActiveWebContents(); | |
| 58 browser()->RequestToLockMouse(tab, user_gesture, | |
| 59 last_unlocked_by_target); | |
| 60 } | |
| 61 | |
| 62 void FullscreenControllerTest::LostMouseLock() { | |
| 63 browser()->LostMouseLock(); | |
| 64 } | |
| 65 | |
| 66 bool FullscreenControllerTest::SendEscapeToFullscreenController() { | |
| 67 return browser()->fullscreen_controller_->HandleUserPressedEscape(); | |
| 68 } | |
| 69 | |
| 70 bool FullscreenControllerTest::IsFullscreenForBrowser() { | |
| 71 return browser()->fullscreen_controller_->IsFullscreenForBrowser(); | |
| 72 } | |
| 73 | |
| 74 bool FullscreenControllerTest::IsFullscreenForTabOrPending() { | |
| 75 return browser()->IsFullscreenForTabOrPending(); | |
| 76 } | |
| 77 | |
| 78 bool FullscreenControllerTest::IsMouseLockPermissionRequested() { | |
| 79 FullscreenExitBubbleType type = | |
| 80 browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); | |
| 81 bool mouse_lock = false; | |
| 82 fullscreen_bubble::PermissionRequestedByType(type, NULL, &mouse_lock); | |
| 83 return mouse_lock; | |
| 84 } | |
| 85 | |
| 86 bool FullscreenControllerTest::IsFullscreenPermissionRequested() { | |
| 87 FullscreenExitBubbleType type = | |
| 88 browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); | |
| 89 bool fullscreen = false; | |
| 90 fullscreen_bubble::PermissionRequestedByType(type, &fullscreen, NULL); | |
| 91 return fullscreen; | |
| 92 } | |
| 93 | |
| 94 FullscreenExitBubbleType | |
| 95 FullscreenControllerTest::GetFullscreenExitBubbleType() { | |
| 96 return browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); | |
| 97 } | |
| 98 | |
| 99 bool FullscreenControllerTest::IsFullscreenBubbleDisplayed() { | |
| 100 FullscreenExitBubbleType type = | |
| 101 browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); | |
| 102 return type != FEB_TYPE_NONE; | |
| 103 } | |
| 104 | |
| 105 bool FullscreenControllerTest::IsFullscreenBubbleDisplayingButtons() { | |
| 106 FullscreenExitBubbleType type = | |
| 107 browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); | |
| 108 return fullscreen_bubble::ShowButtonsForType(type); | |
| 109 } | |
| 110 | |
| 111 void FullscreenControllerTest::AcceptCurrentFullscreenOrMouseLockRequest() { | |
| 112 WebContents* fullscreen_tab = browser()->GetActiveWebContents(); | |
| 113 FullscreenExitBubbleType type = | |
| 114 browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); | |
| 115 browser()->OnAcceptFullscreenPermission(fullscreen_tab->GetURL(), type); | |
| 116 } | |
| 117 | |
| 118 void FullscreenControllerTest::DenyCurrentFullscreenOrMouseLockRequest() { | |
| 119 FullscreenExitBubbleType type = | |
| 120 browser()->fullscreen_controller_->GetFullscreenExitBubbleType(); | |
| 121 browser()->OnDenyFullscreenPermission(type); | |
| 122 } | |
| 123 | |
| 124 void FullscreenControllerTest::AddTabAtIndexAndWait(int index, const GURL& url, | |
| 125 content::PageTransition transition) { | |
| 126 content::TestNavigationObserver observer( | |
| 127 content::NotificationService::AllSources(), NULL, 1); | |
| 128 | |
| 129 AddTabAtIndex(index, url, transition); | |
| 130 | |
| 131 observer.Wait(); | |
| 132 } | |
| 133 | |
| 134 void FullscreenControllerTest::GoBack() { | |
| 135 content::TestNavigationObserver observer( | |
| 136 content::NotificationService::AllSources(), NULL, 1); | |
| 137 | |
| 138 chrome::GoBack(browser(), CURRENT_TAB); | |
| 139 | |
| 140 observer.Wait(); | |
| 141 } | |
| 142 | |
| 143 void FullscreenControllerTest::Reload() { | |
| 144 content::TestNavigationObserver observer( | |
| 145 content::NotificationService::AllSources(), NULL, 1); | |
| 146 | |
| 147 chrome::Reload(browser(), CURRENT_TAB); | |
| 148 | |
| 149 observer.Wait(); | |
| 150 } | |
| 151 | |
| 152 void FullscreenControllerTest::ToggleTabFullscreen_Internal( | |
| 153 bool enter_fullscreen, bool retry_until_success) { | |
| 154 WebContents* tab = browser()->GetActiveWebContents(); | |
| 155 if (IsFullscreenForBrowser()) { | |
| 156 // Changing tab fullscreen state will not actually change the window | |
| 157 // when browser fullscreen is in effect. | |
| 158 browser()->ToggleFullscreenModeForTab(tab, enter_fullscreen); | |
| 159 } else { // Not in browser fullscreen, expect window to actually change. | |
| 160 ASSERT_NE(browser()->window()->IsFullscreen(), enter_fullscreen); | |
| 161 do { | |
| 162 FullscreenNotificationObserver fullscreen_observer; | |
| 163 browser()->ToggleFullscreenModeForTab(tab, enter_fullscreen); | |
| 164 fullscreen_observer.Wait(); | |
| 165 // Repeat ToggleFullscreenModeForTab until the correct state is entered. | |
| 166 // This addresses flakiness on test bots running many fullscreen | |
| 167 // tests in parallel. | |
| 168 } while (retry_until_success && | |
| 169 browser()->window()->IsFullscreen() != enter_fullscreen); | |
| 170 ASSERT_EQ(browser()->window()->IsFullscreen(), enter_fullscreen); | |
| 171 } | |
| 172 } | |
| OLD | NEW |