chromium/chrome/browser/extensions/api/tab_capture/tab_capture_apitest.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 <memory>

#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/feature_list.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/test_timeouts.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/extensions/api/tab_capture/tab_capture_api.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_enums.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#include "chrome/browser/ui/tabs/tab_utils.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/common/content_features.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/switches.h"
#include "extensions/test/extension_test_message_listener.h"
#include "extensions/test/result_catcher.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/gl/gl_switches.h"
#include "url/url_constants.h"

namespace extensions {

namespace {

constexpr char kExtensionId[] =;
constexpr char kValidChromeURL[] =;

class TabCaptureApiTest : public ExtensionApiTest {};

class TabCaptureApiPixelTest : public TabCaptureApiTest {};

// Tests API behaviors, including info queries, and constraints violations.
#if BUILDFLAG(IS_MAC) || defined(MEMORY_SANITIZER)
// TODO(crbug.com/341487291): Flaky on Mac and MSAN builds.
#define MAYBE_ApiTests
#else
#define MAYBE_ApiTests
#endif  // BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_ApiTests) {}

// Tests that tab capture video frames can be received in a VIDEO element.
// Disabled due to flakes on multiple platforms; see https://crbug.com/1040894.
// Disabled due to flakes on Windows GPU bots during teardown, and because
// IsTooIntensiveForThisPlatform prevents this test from actually executing
// anyways; see crbug.com/1241790.
IN_PROC_BROWSER_TEST_F(TabCaptureApiPixelTest,
                       DISABLED_EndToEndWithoutRemoting) {}

// Tests that video frames are captured, transported via WebRTC, and finally
// received in a VIDEO element.  More allowance is provided for color deviation
// because of the additional layers of video processing performed within
// WebRTC.
// Disabled due to flakes on multiple platforms; see https://crbug.com/1040894.
IN_PROC_BROWSER_TEST_F(TabCaptureApiPixelTest, DISABLED_EndToEndThroughWebRTC) {}

// Tests that getUserMedia() is NOT a way to start tab capture.
IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, GetUserMediaTest) {}

// Make sure tabCapture.capture only works if the tab has been granted
// permission via an extension icon click or the extension is allowlisted.
// TODO(crbug.com/40827755): Flaky on all platforms
IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, DISABLED_ActiveTabPermission) {}

// Tests that fullscreen transitions during a tab capture session dispatch
// events to the onStatusChange listener.  The test loads a page that toggles
// fullscreen mode, using the Fullscreen Javascript API, in response to mouse
// clicks.
#if BUILDFLAG(IS_MAC)
// TODO(crbug.com/1392776): Flaky on Mac.
#define MAYBE_FullscreenEvents
#elif defined(MEMORY_SANITIZER)
// TODO(crbug.com/341641151): Deflake test for MSAN.
#define MAYBE_FullscreenEvents
#else
#define MAYBE_FullscreenEvents
#endif  // BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_FullscreenEvents) {}

IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, GrantForChromePages) {}

// Tests that a tab in incognito mode can be captured.
IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, CaptureInSplitIncognitoMode) {}

// Tests that valid constraints allow tab capture to start, while invalid ones
// do not.
#if BUILDFLAG(IS_LINUX) || defined(MEMORY_SANITIZER)
// TODO(crbug.com/343116848): Re-enable this test
#define MAYBE_Constraints
#else
#define MAYBE_Constraints
#endif  // BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_Constraints) {}

#if defined(MEMORY_SANITIZER)
// TODO(crbug.com/341641151): Deflake test for MSAN.
#define MAYBE_TabIndicator
#else
#define MAYBE_TabIndicator
#endif  // BUILDFLAG(IS_MAC)
// Tests that the tab indicator (in the tab strip) is shown during tab capture.
IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_TabIndicator) {}

IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MultipleExtensions) {}

}  // namespace

}  // namespace extensions