This source file includes following definitions.
- state
- set_browser
- browser_
- EnterFullscreen
- ExitFullscreen
- ShouldHideUIForFullscreen
- IsFullscreen
- SetMetroSnapMode
- IsInMetroSnapMode
- EnterFullscreenWithChrome
- IsFullscreenWithChrome
- IsFullscreenWithoutChrome
- GetWindowStateString
- ChangeWindowFullscreenState
- EnterFullscreen
- IsTransitionReentrant
- SetUp
- CreateBrowserWindow
- ChangeWindowFullscreenState
- GetWindowStateString
- VerifyWindowState
- ShouldSkipStateAndEventPair
- GetBrowser
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "base/command_line.h"
#include "build/build_config.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
#include "chrome/browser/ui/fullscreen/fullscreen_controller_state_test.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
#include "content/public/common/url_constants.h"
#include "testing/gtest/include/gtest/gtest.h"
class FullscreenControllerTestWindow : public TestBrowserWindow {
public:
enum WindowState {
NORMAL,
FULLSCREEN,
METRO_SNAP,
TO_NORMAL,
TO_FULLSCREEN,
};
FullscreenControllerTestWindow();
virtual ~FullscreenControllerTestWindow() {}
virtual void EnterFullscreen(const GURL& url,
FullscreenExitBubbleType type) OVERRIDE;
virtual void ExitFullscreen() OVERRIDE;
virtual bool ShouldHideUIForFullscreen() const OVERRIDE;
virtual bool IsFullscreen() const OVERRIDE;
#if defined(OS_WIN)
virtual void SetMetroSnapMode(bool enable) OVERRIDE;
virtual bool IsInMetroSnapMode() const OVERRIDE;
#endif
#if defined(OS_MACOSX)
virtual void EnterFullscreenWithChrome() OVERRIDE;
virtual bool IsFullscreenWithChrome() OVERRIDE;
virtual bool IsFullscreenWithoutChrome() OVERRIDE;
#endif
static const char* GetWindowStateString(WindowState state);
WindowState state() const { return state_; }
void set_browser(Browser* browser) { browser_ = browser; }
void ChangeWindowFullscreenState();
private:
void EnterFullscreen(bool new_mac_with_chrome_mode);
bool IsTransitionReentrant(bool new_fullscreen,
bool new_mac_with_chrome_mode);
WindowState state_;
bool mac_with_chrome_mode_;
Browser* browser_;
};
FullscreenControllerTestWindow::FullscreenControllerTestWindow()
: state_(NORMAL),
mac_with_chrome_mode_(false),
browser_(NULL) {
}
void FullscreenControllerTestWindow::EnterFullscreen(
const GURL& url, FullscreenExitBubbleType type) {
EnterFullscreen(false);
}
void FullscreenControllerTestWindow::ExitFullscreen() {
if (IsFullscreen()) {
state_ = TO_NORMAL;
mac_with_chrome_mode_ = false;
if (IsTransitionReentrant(false, false))
ChangeWindowFullscreenState();
}
}
bool FullscreenControllerTestWindow::ShouldHideUIForFullscreen() const {
return IsFullscreen();
}
bool FullscreenControllerTestWindow::IsFullscreen() const {
#if defined(OS_MACOSX)
return state_ == FULLSCREEN || state_ == TO_FULLSCREEN;
#else
return state_ == FULLSCREEN || state_ == TO_NORMAL;
#endif
}
#if defined(OS_WIN)
void FullscreenControllerTestWindow::SetMetroSnapMode(bool enable) {
if (enable != IsInMetroSnapMode())
state_ = enable ? METRO_SNAP : NORMAL;
if (FullscreenControllerStateTest::IsWindowFullscreenStateChangedReentrant())
ChangeWindowFullscreenState();
}
bool FullscreenControllerTestWindow::IsInMetroSnapMode() const {
return state_ == METRO_SNAP;
}
#endif
#if defined(OS_MACOSX)
void FullscreenControllerTestWindow::EnterFullscreenWithChrome() {
EnterFullscreen(true);
}
bool FullscreenControllerTestWindow::IsFullscreenWithChrome() {
return IsFullscreen() && mac_with_chrome_mode_;
}
bool FullscreenControllerTestWindow::IsFullscreenWithoutChrome() {
return IsFullscreen() && !mac_with_chrome_mode_;
}
#endif
const char* FullscreenControllerTestWindow::GetWindowStateString(
WindowState state) {
switch (state) {
ENUM_TO_STRING(NORMAL);
ENUM_TO_STRING(FULLSCREEN);
ENUM_TO_STRING(METRO_SNAP);
ENUM_TO_STRING(TO_FULLSCREEN);
ENUM_TO_STRING(TO_NORMAL);
default:
NOTREACHED() << "No string for state " << state;
return "WindowState-Unknown";
}
}
void FullscreenControllerTestWindow::ChangeWindowFullscreenState() {
if (state_ == TO_FULLSCREEN)
state_ = FULLSCREEN;
else if (state_ == TO_NORMAL)
state_ = NORMAL;
browser_->WindowFullscreenStateChanged();
}
void FullscreenControllerTestWindow::EnterFullscreen(
bool new_mac_with_chrome_mode) {
bool reentrant = IsTransitionReentrant(true, new_mac_with_chrome_mode);
mac_with_chrome_mode_ = new_mac_with_chrome_mode;
if (!IsFullscreen())
state_ = TO_FULLSCREEN;
if (reentrant)
ChangeWindowFullscreenState();
}
bool FullscreenControllerTestWindow::IsTransitionReentrant(
bool new_fullscreen,
bool new_mac_with_chrome_mode) {
#if defined(OS_MACOSX)
bool mac_with_chrome_mode_changed = new_mac_with_chrome_mode ?
IsFullscreenWithoutChrome() : IsFullscreenWithChrome();
#else
bool mac_with_chrome_mode_changed = false;
#endif
bool fullscreen_changed = (new_fullscreen != IsFullscreen());
if (!fullscreen_changed && !mac_with_chrome_mode_changed)
return false;
if (FullscreenControllerStateTest::IsWindowFullscreenStateChangedReentrant())
return true;
return state_ == FULLSCREEN &&
!fullscreen_changed &&
mac_with_chrome_mode_changed;
}
class FullscreenControllerStateUnitTest : public BrowserWithTestWindowTest,
public FullscreenControllerStateTest {
public:
FullscreenControllerStateUnitTest();
virtual void SetUp() OVERRIDE;
virtual BrowserWindow* CreateBrowserWindow() OVERRIDE;
virtual void ChangeWindowFullscreenState() OVERRIDE;
virtual const char* GetWindowStateString() OVERRIDE;
virtual void VerifyWindowState() OVERRIDE;
protected:
virtual bool ShouldSkipStateAndEventPair(State state, Event event) OVERRIDE;
virtual Browser* GetBrowser() OVERRIDE;
FullscreenControllerTestWindow* window_;
};
FullscreenControllerStateUnitTest::FullscreenControllerStateUnitTest ()
: window_(NULL) {
}
void FullscreenControllerStateUnitTest::SetUp() {
BrowserWithTestWindowTest::SetUp();
window_->set_browser(browser());
}
BrowserWindow* FullscreenControllerStateUnitTest::CreateBrowserWindow() {
window_ = new FullscreenControllerTestWindow();
return window_;
}
void FullscreenControllerStateUnitTest::ChangeWindowFullscreenState() {
window_->ChangeWindowFullscreenState();
}
const char* FullscreenControllerStateUnitTest::GetWindowStateString() {
return FullscreenControllerTestWindow::GetWindowStateString(window_->state());
}
void FullscreenControllerStateUnitTest::VerifyWindowState() {
switch (state()) {
case STATE_NORMAL:
EXPECT_EQ(FullscreenControllerTestWindow::NORMAL,
window_->state()) << GetAndClearDebugLog();
break;
case STATE_BROWSER_FULLSCREEN_NO_CHROME:
case STATE_BROWSER_FULLSCREEN_WITH_CHROME:
case STATE_TAB_FULLSCREEN:
case STATE_TAB_BROWSER_FULLSCREEN:
case STATE_TAB_BROWSER_FULLSCREEN_CHROME:
EXPECT_EQ(FullscreenControllerTestWindow::FULLSCREEN,
window_->state()) << GetAndClearDebugLog();
break;
#if defined(OS_WIN)
case STATE_METRO_SNAP:
EXPECT_EQ(FullscreenControllerTestWindow::METRO_SNAP,
window_->state()) << GetAndClearDebugLog();
break;
#endif
case STATE_TO_NORMAL:
EXPECT_EQ(FullscreenControllerTestWindow::TO_NORMAL,
window_->state()) << GetAndClearDebugLog();
break;
case STATE_TO_BROWSER_FULLSCREEN_NO_CHROME:
case STATE_TO_BROWSER_FULLSCREEN_WITH_CHROME:
case STATE_TO_TAB_FULLSCREEN:
EXPECT_EQ(FullscreenControllerTestWindow::TO_FULLSCREEN,
window_->state()) << GetAndClearDebugLog();
break;
default:
NOTREACHED() << GetAndClearDebugLog();
}
FullscreenControllerStateTest::VerifyWindowState();
}
bool FullscreenControllerStateUnitTest::ShouldSkipStateAndEventPair(
State state, Event event) {
#if defined(OS_MACOSX)
if ((state == STATE_TO_NORMAL ||
state == STATE_TO_BROWSER_FULLSCREEN_NO_CHROME ||
state == STATE_TO_TAB_FULLSCREEN) &&
event == TOGGLE_FULLSCREEN)
return true;
#endif
return FullscreenControllerStateTest::ShouldSkipStateAndEventPair(state,
event);
}
Browser* FullscreenControllerStateUnitTest::GetBrowser() {
return BrowserWithTestWindowTest::browser();
}
TEST_F(FullscreenControllerStateUnitTest, TransitionsForEachState) {
AddTab(browser(), GURL(content::kAboutBlankURL));
TestTransitionsForEachState();
}
#define TEST_EVENT(state, event) \
TEST_F(FullscreenControllerStateUnitTest, state##__##event) { \
AddTab(browser(), GURL(content::kAboutBlankURL)); \
ASSERT_NO_FATAL_FAILURE(TestStateAndEvent(state, event)) \
<< GetAndClearDebugLog(); \
}
#include "chrome/browser/ui/fullscreen/fullscreen_controller_state_tests.h"
TEST_F(FullscreenControllerStateUnitTest,
DISABLED_ToggleTabWhenPendingBrowser) {
if (FullscreenControllerStateTest::IsWindowFullscreenStateChangedReentrant())
return;
AddTab(browser(), GURL(content::kAboutBlankURL));
ASSERT_NO_FATAL_FAILURE(
TransitionToState(STATE_TO_BROWSER_FULLSCREEN_NO_CHROME))
<< GetAndClearDebugLog();
ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_TRUE)) << GetAndClearDebugLog();
ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_FALSE)) << GetAndClearDebugLog();
ASSERT_TRUE(InvokeEvent(WINDOW_CHANGE)) << GetAndClearDebugLog();
}
TEST_F(FullscreenControllerStateUnitTest, DISABLED_ToggleTabWhenPendingTab) {
if (FullscreenControllerStateTest::IsWindowFullscreenStateChangedReentrant())
return;
AddTab(browser(), GURL(content::kAboutBlankURL));
ASSERT_NO_FATAL_FAILURE(
TransitionToState(STATE_TO_TAB_FULLSCREEN))
<< GetAndClearDebugLog();
ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_TRUE)) << GetAndClearDebugLog();
ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_FALSE)) << GetAndClearDebugLog();
ASSERT_TRUE(InvokeEvent(WINDOW_CHANGE)) << GetAndClearDebugLog();
}
TEST_F(FullscreenControllerStateUnitTest, DISABLED_DebugLogStateTables) {
std::ostringstream output;
output << "\n\nTransition Table:";
output << GetTransitionTableAsString();
output << "\n\nInitial transitions:";
output << GetStateTransitionsAsString();
for (int state1_int = 0; state1_int < NUM_STATES; ++state1_int) {
State state1 = static_cast<State>(state1_int);
for (int state2_int = 0; state2_int < NUM_STATES; ++state2_int) {
State state2 = static_cast<State>(state2_int);
if (ShouldSkipStateAndEventPair(state1, EVENT_INVALID) ||
ShouldSkipStateAndEventPair(state2, EVENT_INVALID))
continue;
if (NextTransitionInShortestPath(state1, state2, NUM_STATES).state ==
STATE_INVALID) {
LOG(ERROR) << "Should be skipping state transitions for: "
<< GetStateString(state1) << " " << GetStateString(state2);
}
}
}
output << "\n\nAll transitions:";
output << GetStateTransitionsAsString();
LOG(INFO) << output.str();
}
TEST_F(FullscreenControllerStateUnitTest, ExitFullscreenViaBrowserWindow) {
AddTab(browser(), GURL(content::kAboutBlankURL));
ASSERT_TRUE(InvokeEvent(TOGGLE_FULLSCREEN));
ASSERT_TRUE(InvokeEvent(WINDOW_CHANGE));
ASSERT_TRUE(browser()->window()->IsFullscreen());
browser()->window()->ExitFullscreen();
ChangeWindowFullscreenState();
EXPECT_EQ(FEB_TYPE_NONE,
browser()->fullscreen_controller()->GetFullscreenExitBubbleType());
}
TEST_F(FullscreenControllerStateUnitTest, ExitTabFullscreenViaSwitchingTab) {
AddTab(browser(), GURL(content::kAboutBlankURL));
AddTab(browser(), GURL(content::kAboutBlankURL));
ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_TRUE));
ASSERT_TRUE(InvokeEvent(WINDOW_CHANGE));
ASSERT_TRUE(browser()->window()->IsFullscreen());
browser()->tab_strip_model()->SelectNextTab();
ChangeWindowFullscreenState();
EXPECT_FALSE(browser()->window()->IsFullscreen());
}
TEST_F(FullscreenControllerStateUnitTest, ExitTabFullscreenViaDetachingTab) {
AddTab(browser(), GURL(content::kAboutBlankURL));
AddTab(browser(), GURL(content::kAboutBlankURL));
ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_TRUE));
ASSERT_TRUE(InvokeEvent(WINDOW_CHANGE));
ASSERT_TRUE(browser()->window()->IsFullscreen());
scoped_ptr<content::WebContents> web_contents(
browser()->tab_strip_model()->DetachWebContentsAt(0));
ChangeWindowFullscreenState();
EXPECT_FALSE(browser()->window()->IsFullscreen());
}
TEST_F(FullscreenControllerStateUnitTest, ExitTabFullscreenViaReplacingTab) {
AddTab(browser(), GURL(content::kAboutBlankURL));
ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_TRUE));
ASSERT_TRUE(InvokeEvent(WINDOW_CHANGE));
ASSERT_TRUE(browser()->window()->IsFullscreen());
content::WebContents* new_web_contents = content::WebContents::Create(
content::WebContents::CreateParams(profile()));
scoped_ptr<content::WebContents> old_web_contents(
browser()->tab_strip_model()->ReplaceWebContentsAt(
0, new_web_contents));
ChangeWindowFullscreenState();
EXPECT_FALSE(browser()->window()->IsFullscreen());
}
TEST_F(FullscreenControllerStateUnitTest, OneCapturedFullscreenedTab) {
content::WebContentsDelegate* const wc_delegate =
static_cast<content::WebContentsDelegate*>(browser());
if (!wc_delegate->EmbedsFullscreenWidget()) {
LOG(WARNING) << "Skipping test since fullscreen-within-tab is disabled.";
return;
}
AddTab(browser(), GURL(content::kAboutBlankURL));
AddTab(browser(), GURL(content::kAboutBlankURL));
content::WebContents* const first_tab =
browser()->tab_strip_model()->GetWebContentsAt(0);
content::WebContents* const second_tab =
browser()->tab_strip_model()->GetWebContentsAt(1);
browser()->tab_strip_model()->ActivateTabAt(0, true);
const gfx::Size kCaptureSize(1280, 720);
first_tab->IncrementCapturerCount(kCaptureSize);
ASSERT_FALSE(browser()->window()->IsFullscreen());
ASSERT_FALSE(wc_delegate->IsFullscreenForTabOrPending(first_tab));
ASSERT_FALSE(wc_delegate->IsFullscreenForTabOrPending(second_tab));
ASSERT_FALSE(GetFullscreenController()->IsWindowFullscreenForTabOrPending());
ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_TRUE));
EXPECT_FALSE(browser()->window()->IsFullscreen());
EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(first_tab));
EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(second_tab));
EXPECT_FALSE(GetFullscreenController()->IsWindowFullscreenForTabOrPending());
browser()->tab_strip_model()->ActivateTabAt(1, true);
EXPECT_FALSE(browser()->window()->IsFullscreen());
EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(first_tab));
EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(second_tab));
EXPECT_FALSE(GetFullscreenController()->IsWindowFullscreenForTabOrPending());
#if !defined(OS_MACOSX)
EXPECT_EQ(kCaptureSize, first_tab->GetView()->GetViewBounds().size());
#endif
browser()->tab_strip_model()->ActivateTabAt(0, true);
EXPECT_FALSE(browser()->window()->IsFullscreen());
EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(first_tab));
EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(second_tab));
EXPECT_FALSE(GetFullscreenController()->IsWindowFullscreenForTabOrPending());
ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_FALSE));
EXPECT_FALSE(browser()->window()->IsFullscreen());
EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(first_tab));
EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(second_tab));
EXPECT_FALSE(GetFullscreenController()->IsWindowFullscreenForTabOrPending());
}
TEST_F(FullscreenControllerStateUnitTest, TwoFullscreenedTabsOneCaptured) {
content::WebContentsDelegate* const wc_delegate =
static_cast<content::WebContentsDelegate*>(browser());
if (!wc_delegate->EmbedsFullscreenWidget()) {
LOG(WARNING) << "Skipping test since fullscreen-within-tab is disabled.";
return;
}
AddTab(browser(), GURL(content::kAboutBlankURL));
AddTab(browser(), GURL(content::kAboutBlankURL));
content::WebContents* const first_tab =
browser()->tab_strip_model()->GetWebContentsAt(0);
content::WebContents* const second_tab =
browser()->tab_strip_model()->GetWebContentsAt(1);
browser()->tab_strip_model()->ActivateTabAt(0, true);
const gfx::Size kCaptureSize(1280, 720);
first_tab->IncrementCapturerCount(kCaptureSize);
ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_TRUE));
EXPECT_FALSE(browser()->window()->IsFullscreen());
EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(first_tab));
EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(second_tab));
EXPECT_FALSE(GetFullscreenController()->IsWindowFullscreenForTabOrPending());
browser()->tab_strip_model()->ActivateTabAt(1, true);
ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_TRUE));
ASSERT_TRUE(InvokeEvent(WINDOW_CHANGE));
EXPECT_TRUE(browser()->window()->IsFullscreen());
EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(first_tab));
EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(second_tab));
EXPECT_TRUE(GetFullscreenController()->IsWindowFullscreenForTabOrPending());
ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_FALSE));
ASSERT_TRUE(InvokeEvent(WINDOW_CHANGE));
EXPECT_FALSE(browser()->window()->IsFullscreen());
EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(first_tab));
EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(second_tab));
EXPECT_FALSE(GetFullscreenController()->IsWindowFullscreenForTabOrPending());
browser()->tab_strip_model()->ActivateTabAt(0, true);
ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_FALSE));
EXPECT_FALSE(browser()->window()->IsFullscreen());
EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(first_tab));
EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(second_tab));
EXPECT_FALSE(GetFullscreenController()->IsWindowFullscreenForTabOrPending());
}
TEST_F(FullscreenControllerStateUnitTest,
BackgroundCapturedTabExitsFullscreen) {
content::WebContentsDelegate* const wc_delegate =
static_cast<content::WebContentsDelegate*>(browser());
if (!wc_delegate->EmbedsFullscreenWidget()) {
LOG(WARNING) << "Skipping test since fullscreen-within-tab is disabled.";
return;
}
AddTab(browser(), GURL(content::kAboutBlankURL));
AddTab(browser(), GURL(content::kAboutBlankURL));
content::WebContents* const first_tab =
browser()->tab_strip_model()->GetWebContentsAt(0);
content::WebContents* const second_tab =
browser()->tab_strip_model()->GetWebContentsAt(1);
browser()->tab_strip_model()->ActivateTabAt(0, true);
const gfx::Size kCaptureSize(1280, 720);
first_tab->IncrementCapturerCount(kCaptureSize);
ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_TRUE));
EXPECT_FALSE(browser()->window()->IsFullscreen());
EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(first_tab));
EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(second_tab));
EXPECT_FALSE(GetFullscreenController()->IsWindowFullscreenForTabOrPending());
browser()->tab_strip_model()->ActivateTabAt(1, true);
ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_TRUE));
ASSERT_TRUE(InvokeEvent(WINDOW_CHANGE));
EXPECT_TRUE(browser()->window()->IsFullscreen());
EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(first_tab));
EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(second_tab));
EXPECT_TRUE(GetFullscreenController()->IsWindowFullscreenForTabOrPending());
GetFullscreenController()->ToggleFullscreenModeForTab(first_tab, false);
EXPECT_TRUE(browser()->window()->IsFullscreen());
EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(first_tab));
EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(second_tab));
EXPECT_TRUE(GetFullscreenController()->IsWindowFullscreenForTabOrPending());
ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_FALSE));
ASSERT_TRUE(InvokeEvent(WINDOW_CHANGE));
EXPECT_FALSE(browser()->window()->IsFullscreen());
EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(first_tab));
EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(second_tab));
EXPECT_FALSE(GetFullscreenController()->IsWindowFullscreenForTabOrPending());
}
TEST_F(FullscreenControllerStateUnitTest,
OneCapturedTabFullscreenedBeforeBrowserFullscreen) {
content::WebContentsDelegate* const wc_delegate =
static_cast<content::WebContentsDelegate*>(browser());
if (!wc_delegate->EmbedsFullscreenWidget()) {
LOG(WARNING) << "Skipping test since fullscreen-within-tab is disabled.";
return;
}
AddTab(browser(), GURL(content::kAboutBlankURL));
content::WebContents* const tab =
browser()->tab_strip_model()->GetWebContentsAt(0);
browser()->tab_strip_model()->ActivateTabAt(0, true);
const gfx::Size kCaptureSize(1280, 720);
tab->IncrementCapturerCount(kCaptureSize);
ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_TRUE));
EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(tab));
EXPECT_FALSE(GetFullscreenController()->IsWindowFullscreenForTabOrPending());
EXPECT_FALSE(GetFullscreenController()->IsFullscreenForBrowser());
ASSERT_TRUE(InvokeEvent(TOGGLE_FULLSCREEN));
ASSERT_TRUE(InvokeEvent(WINDOW_CHANGE));
EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(tab));
EXPECT_FALSE(GetFullscreenController()->IsWindowFullscreenForTabOrPending());
EXPECT_TRUE(GetFullscreenController()->IsFullscreenForBrowser());
ASSERT_TRUE(InvokeEvent(TOGGLE_FULLSCREEN));
ASSERT_TRUE(InvokeEvent(WINDOW_CHANGE));
EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(tab));
EXPECT_FALSE(GetFullscreenController()->IsWindowFullscreenForTabOrPending());
EXPECT_FALSE(GetFullscreenController()->IsFullscreenForBrowser());
ASSERT_TRUE(InvokeEvent(TOGGLE_FULLSCREEN));
ASSERT_TRUE(InvokeEvent(WINDOW_CHANGE));
ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_FALSE));
EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(tab));
EXPECT_FALSE(GetFullscreenController()->IsWindowFullscreenForTabOrPending());
EXPECT_TRUE(GetFullscreenController()->IsFullscreenForBrowser());
}
TEST_F(FullscreenControllerStateUnitTest,
CapturedFullscreenedTabTransferredBetweenBrowserWindows) {
content::WebContentsDelegate* const wc_delegate =
static_cast<content::WebContentsDelegate*>(browser());
if (!wc_delegate->EmbedsFullscreenWidget()) {
LOG(WARNING) << "Skipping test since fullscreen-within-tab is disabled.";
return;
}
AddTab(browser(), GURL(content::kAboutBlankURL));
AddTab(browser(), GURL(content::kAboutBlankURL));
content::WebContents* const tab =
browser()->tab_strip_model()->GetWebContentsAt(0);
browser()->tab_strip_model()->ActivateTabAt(0, true);
const gfx::Size kCaptureSize(1280, 720);
tab->IncrementCapturerCount(kCaptureSize);
ASSERT_FALSE(browser()->window()->IsFullscreen());
ASSERT_FALSE(wc_delegate->IsFullscreenForTabOrPending(tab));
ASSERT_FALSE(GetFullscreenController()->IsWindowFullscreenForTabOrPending());
ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_TRUE));
EXPECT_FALSE(browser()->window()->IsFullscreen());
EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(tab));
EXPECT_FALSE(GetFullscreenController()->IsWindowFullscreenForTabOrPending());
const scoped_ptr<BrowserWindow> second_browser_window(CreateBrowserWindow());
const scoped_ptr<Browser> second_browser(CreateBrowser(
browser()->profile(),
browser()->type(),
false,
browser()->host_desktop_type(),
second_browser_window.get()));
AddTab(second_browser.get(), GURL(content::kAboutBlankURL));
content::WebContentsDelegate* const second_wc_delegate =
static_cast<content::WebContentsDelegate*>(second_browser.get());
browser()->tab_strip_model()->DetachWebContentsAt(0);
second_browser->tab_strip_model()->
InsertWebContentsAt(0, tab, TabStripModel::ADD_ACTIVE);
EXPECT_FALSE(browser()->window()->IsFullscreen());
EXPECT_FALSE(second_browser->window()->IsFullscreen());
EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(tab));
EXPECT_TRUE(second_wc_delegate->IsFullscreenForTabOrPending(tab));
EXPECT_FALSE(GetFullscreenController()->IsWindowFullscreenForTabOrPending());
EXPECT_FALSE(second_browser->fullscreen_controller()->
IsWindowFullscreenForTabOrPending());
second_browser->tab_strip_model()->DetachWebContentsAt(0);
browser()->tab_strip_model()->
InsertWebContentsAt(0, tab, TabStripModel::ADD_ACTIVE);
EXPECT_FALSE(browser()->window()->IsFullscreen());
EXPECT_FALSE(second_browser->window()->IsFullscreen());
EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(tab));
EXPECT_TRUE(second_wc_delegate->IsFullscreenForTabOrPending(tab));
EXPECT_FALSE(GetFullscreenController()->IsWindowFullscreenForTabOrPending());
EXPECT_FALSE(second_browser->fullscreen_controller()->
IsWindowFullscreenForTabOrPending());
ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_FALSE));
EXPECT_FALSE(browser()->window()->IsFullscreen());
EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(tab));
EXPECT_FALSE(second_wc_delegate->IsFullscreenForTabOrPending(tab));
EXPECT_FALSE(GetFullscreenController()->IsWindowFullscreenForTabOrPending());
EXPECT_FALSE(second_browser->fullscreen_controller()->
IsWindowFullscreenForTabOrPending());
second_browser->tab_strip_model()->CloseAllTabs();
}