chromium/chrome/browser/ui/exclusive_access/fullscreen_controller_state_unittest.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/command_line.h"
#include "base/memory/raw_ptr.h"
#include "base/test/bind.h"
#include "build/build_config.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/exclusive_access/exclusive_access_context.h"
#include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h"
#include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
#include "chrome/browser/ui/exclusive_access/fullscreen_controller_state_test.h"
#include "chrome/browser/ui/tabs/tab_model.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/common/url_constants.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/display/types/display_constants.h"

// The FullscreenControllerStateUnitTest unit test suite exhastively tests
// the FullscreenController through all permutations of events. The behavior
// of the BrowserWindow is mocked via FullscreenControllerTestWindow.

namespace {

// FullscreenControllerTestWindow ----------------------------------------------

// A BrowserWindow used for testing FullscreenController. The behavior of this
// mock is verified manually by running
// FullscreenControllerStateInteractiveTest.
class FullscreenControllerTestWindow : public TestBrowserWindow,
                                       ExclusiveAccessContext {};

FullscreenControllerTestWindow::FullscreenControllerTestWindow()
    :{}

void FullscreenControllerTestWindow::EnterFullscreen(
    const GURL& url,
    ExclusiveAccessBubbleType type,
    int64_t display_id) {}

void FullscreenControllerTestWindow::ExitFullscreen() {}

bool FullscreenControllerTestWindow::ShouldHideUIForFullscreen() const {}

bool FullscreenControllerTestWindow::IsFullscreen() const {}

// static
const char* FullscreenControllerTestWindow::GetWindowStateString(
    WindowState state) {}

void FullscreenControllerTestWindow::ChangeWindowFullscreenState() {}

void FullscreenControllerTestWindow::EnterFullscreen() {}

bool FullscreenControllerTestWindow::IsTransitionReentrant(
    bool new_fullscreen) {}

ExclusiveAccessContext*
FullscreenControllerTestWindow::GetExclusiveAccessContext() {}

Profile* FullscreenControllerTestWindow::GetProfile() {}

content::WebContents*
FullscreenControllerTestWindow::GetWebContentsForExclusiveAccess() {}

void FullscreenControllerTestWindow::UpdateExclusiveAccessBubble(
    const ExclusiveAccessBubbleParams& params,
    ExclusiveAccessBubbleHideCallback first_hide_callback) {}

bool FullscreenControllerTestWindow::IsExclusiveAccessBubbleDisplayed() const {}

void FullscreenControllerTestWindow::OnExclusiveAccessUserInput() {}

bool FullscreenControllerTestWindow::CanUserExitFullscreen() const {}

}  // namespace

// FullscreenControllerStateUnitTest -------------------------------------------

// Unit test fixture testing Fullscreen Controller through its states. Most of
// the test logic comes from FullscreenControllerStateTest.
class FullscreenControllerStateUnitTest : public BrowserWithTestWindowTest,
                                          public FullscreenControllerStateTest {};

FullscreenControllerStateUnitTest::FullscreenControllerStateUnitTest() =
    default;

void FullscreenControllerStateUnitTest::SetUp() {}

void FullscreenControllerStateUnitTest::TearDown() {}

std::unique_ptr<BrowserWindow>
FullscreenControllerStateUnitTest::CreateBrowserWindow() {}

void FullscreenControllerStateUnitTest::ChangeWindowFullscreenState() {}

const char* FullscreenControllerStateUnitTest::GetWindowStateString() {}

void FullscreenControllerStateUnitTest::VerifyWindowState() {}

bool FullscreenControllerStateUnitTest::ShouldSkipStateAndEventPair(
    State state, Event event) {}

Browser* FullscreenControllerStateUnitTest::GetBrowser() {}

// Soak tests ------------------------------------------------------------------

// Tests all states with all permutations of multiple events to detect lingering
// state issues that would bleed over to other states.
// I.E. for each state test all combinations of events E1, E2, E3.
//
// This produces coverage for event sequences that may happen normally but
// would not be exposed by traversing to each state via TransitionToState().
// TransitionToState() always takes the same path even when multiple paths
// exist.
TEST_F(FullscreenControllerStateUnitTest, TransitionsForEachState) {}


// Individual tests for each pair of state and event ---------------------------

#define TEST_EVENT(state, event)
    // Progress of tests can be examined by inserting the following line:
    // LOG(INFO) << GetAndClearDebugLog(); }

#include "chrome/browser/ui/exclusive_access/fullscreen_controller_state_tests.h"


// Specific one-off tests for known issues -------------------------------------

// TODO(scheib) Toggling Tab fullscreen while pending Tab or
// Browser fullscreen is broken currently http://crbug.com/154196
TEST_F(FullscreenControllerStateUnitTest,
       DISABLED_ToggleTabWhenPendingBrowser) {}

// TODO(scheib) Toggling Tab fullscreen while pending Tab or
// Browser fullscreen is broken currently http://crbug.com/154196
TEST_F(FullscreenControllerStateUnitTest, DISABLED_ToggleTabWhenPendingTab) {}

// Debugging utility: Display the transition tables. Intentionally disabled
TEST_F(FullscreenControllerStateUnitTest, DISABLED_DebugLogStateTables) {}

// Test that the fullscreen exit bubble is closed by
// WindowFullscreenStateChanged() if fullscreen is exited via the
// ExclusiveAccessContext interface.
TEST_F(FullscreenControllerStateUnitTest,
       ExitFullscreenViaExclusiveAccessContext) {}

// Tests that RunOrDeferUntilTransitionIsComplete runs the lambda when nothing
// is happening (no transition in progress).
TEST_F(FullscreenControllerStateUnitTest,
       RunOrDeferUntilTransitionIsCompleteNow) {}

// Tests that RunOrDeferUntilTransitionIsComplete does not run the lambda while
// a transition is in progress and runs it after the transition completes.
TEST_F(FullscreenControllerStateUnitTest,
       RunOrDeferUntilTransitionIsCompleteDefer) {}

TEST_F(FullscreenControllerStateUnitTest, GetFullscreenState) {}

// Test that switching tabs takes the browser out of tab fullscreen.
TEST_F(FullscreenControllerStateUnitTest, ExitTabFullscreenViaSwitchingTab) {}

// Test that switching tabs via detaching the active tab (which is in tab
// fullscreen) takes the browser out of tab fullscreen. This case can
// occur if the user is in both tab fullscreen and immersive browser fullscreen.
TEST_F(FullscreenControllerStateUnitTest, ExitTabFullscreenViaDetachingTab) {}

// Tests that, in a browser configured for Fullscreen-Within-Tab mode,
// fullscreening a screen-captured tab will NOT cause any fullscreen state
// change to the browser window. Furthermore, the test switches between tabs to
// confirm a captured tab will be resized by FullscreenController to the capture
// video resolution once the widget is detached from the UI.
//
// See 'FullscreenWithinTab Note' in fullscreen_controller.h.
TEST_F(FullscreenControllerStateUnitTest, OneCapturedFullscreenedTab) {}

// Tests that, in a browser configured for Fullscreen-Within-Tab mode, more than
// one tab can be in fullscreen mode at the same time without interfering with
// each other.  One tab is being screen-captured and is toggled into fullscreen
// mode, and then the user switches to another tab not being screen-captured and
// fullscreens it.  The first tab's fullscreen toggle does not affect the
// browser window fullscreen, while the second one's does.  Then, the order of
// operations is reversed.
//
// See 'FullscreenWithinTab Note' in fullscreen_controller.h.
TEST_F(FullscreenControllerStateUnitTest, TwoFullscreenedTabsOneCaptured) {}

// Tests that, in a browser configured for Fullscreen-Within-Tab mode, more than
// one tab can be in fullscreen mode at the same time.  This is like the
// TwoFullscreenedTabsOneCaptured test above, except that the screen-captured
// tab exits fullscreen mode while the second tab is still in the foreground.
// When the first tab exits fullscreen, the fullscreen state of the second tab
// and the browser window should remain unchanged.
//
// See 'FullscreenWithinTab Note' in fullscreen_controller.h.
TEST_F(FullscreenControllerStateUnitTest,
       BackgroundCapturedTabExitsFullscreen) {}

// Tests that, in a browser configured for Fullscreen-Within-Tab mode,
// fullscreening a screen-captured tab will NOT cause any fullscreen state
// change to the browser window. Then, toggling Browser Fullscreen mode should
// fullscreen the browser window, but this should behave fully independently of
// the tab's fullscreen state.
//
// See 'FullscreenWithinTab Note' in fullscreen_controller.h.
TEST_F(FullscreenControllerStateUnitTest,
       OneCapturedTabFullscreenedBeforeBrowserFullscreen) {}

// Tests that the tab doesn't enter Fullscreen-Within-Tab mode for hidden
// capture (stay_hidden == true).
TEST_F(FullscreenControllerStateUnitTest, HiddenlyCapturedTabFullscreened) {}

class FullscreenChangeObserver : public content::WebContentsObserver {};

// Tests that going from tab fullscreen -> browser fullscreen causes an explicit
// WasResized to be called on ExitFullscreen while going from tab fullscreen ->
// Normal does not. This ensures that the Resize message we get in the renderer
// will have both the fullscreen change and size change in the same message.
// crbug.com/142427.
TEST_F(FullscreenControllerStateUnitTest, TabToBrowserFullscreenCausesResize) {}

// Tests that the state of a fullscreened, screen-captured tab is preserved if
// the tab is detached from one Browser window and attached to another.
//
// See 'FullscreenWithinTab Note' in fullscreen_controller.h.
TEST_F(FullscreenControllerStateUnitTest,
       CapturedFullscreenedTabTransferredBetweenBrowserWindows) {}