chromium/chrome/browser/media/webrtc/conditional_focus_browsertest.cc

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

#include <string>

#include "base/command_line.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/stringprintf.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/media/webrtc/webrtc_browsertest_base.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "third_party/blink/public/common/switches.h"
#include "ui/gl/gl_switches.h"

namespace {

WebContents;

// Capturing page.
const char kCapturingPage[] =;
// Captured page.
const char kCapturedPage[] =;

// The tab to be captured is detected using this string, which is hard-coded
// in the HTML file.
const char kCapturedPageTitle[] =;

enum class FocusEnumValue {};

const char* ToString(FocusEnumValue focus_enum_value) {}

enum class Tab {};

}  // namespace

// Essentially depends on InProcessBrowserTest, but WebRtcTestBase provides
// detection of JS errors.
class ConditionalFocusBrowserTest : public WebRtcTestBase {};

// Flaky on Win bots and on linux release bots http://crbug.com/1264744
#if BUILDFLAG(IS_WIN) || (BUILDFLAG(IS_LINUX) && defined(NDEBUG))
#define MAYBE_CapturedTabFocusedIfNoExplicitCallToFocus
#else
#define MAYBE_CapturedTabFocusedIfNoExplicitCallToFocus
#endif
IN_PROC_BROWSER_TEST_F(ConditionalFocusBrowserTest,
                       MAYBE_CapturedTabFocusedIfNoExplicitCallToFocus) {}

// Flaky on Win bots and on linux release bots http://crbug.com/1264744
#if BUILDFLAG(IS_WIN) || (BUILDFLAG(IS_LINUX) && defined(NDEBUG))
#define MAYBE_CapturedTabFocusedIfExplicitlyCallingFocus
#else
#define MAYBE_CapturedTabFocusedIfExplicitlyCallingFocus
#endif
IN_PROC_BROWSER_TEST_F(ConditionalFocusBrowserTest,
                       MAYBE_CapturedTabFocusedIfExplicitlyCallingFocus) {}

// This class only uses the values of FocusEnumValue that lead to the capturing
// application keeping focus.
class ConditionalFocusBrowserTestWithFocusCapturingApplication
    : public ConditionalFocusBrowserTest,
      public testing::WithParamInterface<FocusEnumValue> {};

INSTANTIATE_TEST_SUITE_P();

// TODO(crbug.com/40913269): Flaky on a TSan bot.
#if BUILDFLAG(IS_LINUX) && defined(THREAD_SANITIZER)
#define MAYBE_CapturedTabNotFocusedIfExplicitlyCallingNoFocus
#else
#define MAYBE_CapturedTabNotFocusedIfExplicitlyCallingNoFocus
#endif
IN_PROC_BROWSER_TEST_P(ConditionalFocusBrowserTestWithFocusCapturingApplication,
                       MAYBE_CapturedTabNotFocusedIfExplicitlyCallingNoFocus) {}

// TODO(crbug.com/40913269): Flaky on a TSan bot.
#if BUILDFLAG(IS_LINUX) && defined(THREAD_SANITIZER)
#define MAYBE_CapturedTabFocusedIfAppWaitsTooLongBeforeCallingFocus
#else
#define MAYBE_CapturedTabFocusedIfAppWaitsTooLongBeforeCallingFocus
#endif
IN_PROC_BROWSER_TEST_P(
    ConditionalFocusBrowserTestWithFocusCapturingApplication,
    MAYBE_CapturedTabFocusedIfAppWaitsTooLongBeforeCallingFocus) {}

// This ensures that we don't have to wait |kConditionalFocusWindowMs| before
// focus occurs. Rather, that is just the hard-limit that is employed in case
// the application attempts abuse by blocking the main thread for too long.
IN_PROC_BROWSER_TEST_F(ConditionalFocusBrowserTest, FocusTriggeredByMicrotask) {}

IN_PROC_BROWSER_TEST_F(ConditionalFocusBrowserTest,
                       UserFocusChangeSuppressesFocusDecision) {}

IN_PROC_BROWSER_TEST_F(ConditionalFocusBrowserTest,
                       ExceptionRaisedIfFocusCalledAfterMicrotaskExecutes) {}

IN_PROC_BROWSER_TEST_F(ConditionalFocusBrowserTest, FocusBeforeCapture) {}

// TODO(crbug.com/40913269): Flaky on a TSan bot.
#if BUILDFLAG(IS_LINUX) && defined(THREAD_SANITIZER)
#define MAYBE_NoFocusBeforeCapture
#else
#define MAYBE_NoFocusBeforeCapture
#endif
IN_PROC_BROWSER_TEST_P(ConditionalFocusBrowserTestWithFocusCapturingApplication,
                       MAYBE_NoFocusBeforeCapture) {}

// TODO(crbug.com/40913269): Flaky on a TSan bot.
#if BUILDFLAG(IS_LINUX) && defined(THREAD_SANITIZER)
#define MAYBE_NoFocusAfterCaptureOverrideFocusBeforeCapture
#else
#define MAYBE_NoFocusAfterCaptureOverrideFocusBeforeCapture
#endif
IN_PROC_BROWSER_TEST_P(ConditionalFocusBrowserTestWithFocusCapturingApplication,
                       MAYBE_NoFocusAfterCaptureOverrideFocusBeforeCapture) {}

// TODO(crbug.com/40913269): Flaky on a TSan bot.
#if BUILDFLAG(IS_LINUX) && defined(THREAD_SANITIZER)
#define MAYBE_FocusAfterCaptureOverrideNoFocusBeforeCapture
#else
#define MAYBE_FocusAfterCaptureOverrideNoFocusBeforeCapture
#endif
IN_PROC_BROWSER_TEST_P(ConditionalFocusBrowserTestWithFocusCapturingApplication,
                       MAYBE_FocusAfterCaptureOverrideNoFocusBeforeCapture) {}