chromium/chrome/browser/ui/views/global_media_controls/media_dialog_view_interactive_browsertest.cc

// Copyright 2019 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/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/media/router/chrome_media_router_factory.h"
#include "chrome/browser/media/router/media_router_feature.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/global_media_controls/media_toolbar_button_observer.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/global_media_controls/media_dialog_ui_for_test.h"
#include "chrome/browser/ui/views/global_media_controls/media_dialog_view.h"
#include "chrome/browser/ui/views/global_media_controls/media_dialog_view_observer.h"
#include "chrome/browser/ui/views/global_media_controls/media_toolbar_button_view.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/feature_engagement/public/feature_constants.h"
#include "components/global_media_controls/public/views/media_item_ui_list_view.h"
#include "components/global_media_controls/public/views/media_item_ui_updated_view.h"
#include "components/live_caption/caption_util.h"
#include "components/live_caption/pref_names.h"
#include "components/media_router/browser/media_routes_observer.h"
#include "components/media_router/browser/presentation/web_contents_presentation_manager.h"
#include "components/media_router/browser/test/mock_media_router.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/sessions/content/session_tab_helper.h"
#include "components/soda/constants.h"
#include "content/public/browser/media_session.h"
#include "content/public/browser/presentation_observer.h"
#include "content/public/browser/presentation_request.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_features.h"
#include "content/public/common/isolated_world_ids.h"
#include "content/public/test/back_forward_cache_util.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/media_start_stop_observer.h"
#include "media/base/media_switches.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "services/media_session/public/mojom/media_session.mojom.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/toggle_button.h"
#include "ui/views/view_utils.h"

MediaSessionAction;

// Global Media Controls are not supported on Chrome OS.
#if !BUILDFLAG(IS_CHROMEOS_LACROS)

namespace {

class TestWebContentsPresentationManager
    : public media_router::WebContentsPresentationManager {};

class TestMediaRouter : public media_router::MockMediaRouter {};

}  // anonymous namespace

class MediaDialogViewBrowserTest : public InProcessBrowserTest {};

IN_PROC_BROWSER_TEST_F(MediaDialogViewBrowserTest,
                       ShowsMetadataAndControlsMedia) {}

IN_PROC_BROWSER_TEST_F(MediaDialogViewBrowserTest,
                       ShowsMetadataAndControlsMediaInRTL) {}

IN_PROC_BROWSER_TEST_F(MediaDialogViewBrowserTest, ShowsMultipleMediaSessions) {}

IN_PROC_BROWSER_TEST_F(MediaDialogViewBrowserTest,
                       ClickingOnItemGoesBackToTab) {}

IN_PROC_BROWSER_TEST_F(MediaDialogViewBrowserTest, ShowsCastSession) {}

#if BUILDFLAG(IS_MAC) && defined(ARCH_CPU_ARM64)
// https://crbug.com/1224071
#define MAYBE_PictureInPicture
#else
#define MAYBE_PictureInPicture
#endif
// Test is flaky crbug.com/1213256.
IN_PROC_BROWSER_TEST_F(MediaDialogViewBrowserTest, MAYBE_PictureInPicture) {}

IN_PROC_BROWSER_TEST_F(MediaDialogViewBrowserTest,
                       PictureInPictureButtonVisibility) {}

// Flaky on multiple platforms (crbug.com/1218003,crbug.com/1383904).
IN_PROC_BROWSER_TEST_F(MediaDialogViewBrowserTest,
                       DISABLED_PlayingSessionAlwaysDisplayFirst) {}

// TODO(crbug.com/40898509): Live captioning not supported on Arm64 Windows.
#if BUILDFLAG(IS_WIN) && defined(ARCH_CPU_ARM64) || BUILDFLAG(IS_MAC)
#define MAYBE_LiveCaption
#else
#define MAYBE_LiveCaption
#endif
IN_PROC_BROWSER_TEST_F(MediaDialogViewBrowserTest, MAYBE_LiveCaption) {}

#if (BUILDFLAG(IS_WIN) && defined(ARCH_CPU_ARM64)) || BUILDFLAG(IS_MAC)
// https://crbug.com/1222873
// Flaky on all Mac bots: https://crbug.com/1274967
// TODO(crbug.com/40898509): Renable on WinArm64 when live captioning is
// enabled.
#define MAYBE_LiveCaptionProgressUpdate
#else
#define MAYBE_LiveCaptionProgressUpdate
#endif
IN_PROC_BROWSER_TEST_F(MediaDialogViewBrowserTest,
                       MAYBE_LiveCaptionProgressUpdate) {}

// TODO(crbug.com/1225531, crbug.com/1222873): Flaky.
// TODO(crbug.com/40898509): Renable on WinArm64 when live captioning is
// enabled.
#if (BUILDFLAG(IS_WIN) && defined(ARCH_CPU_ARM64)) || BUILDFLAG(IS_MAC)
#define MAYBE_LiveCaptionShowLanguage
#else
#define MAYBE_LiveCaptionShowLanguage
#endif
IN_PROC_BROWSER_TEST_F(MediaDialogViewBrowserTest,
                       MAYBE_LiveCaptionShowLanguage) {}

IN_PROC_BROWSER_TEST_F(MediaDialogViewBrowserTest, LiveTranslate) {}

class MediaDialogViewWithBackForwardCacheBrowserTest
    : public MediaDialogViewBrowserTest {};

IN_PROC_BROWSER_TEST_F(MediaDialogViewWithBackForwardCacheBrowserTest,
                       PlayAndCache) {}

IN_PROC_BROWSER_TEST_F(MediaDialogViewWithBackForwardCacheBrowserTest,
                       DISABLED_PauseAndCache) {}

IN_PROC_BROWSER_TEST_F(MediaDialogViewWithBackForwardCacheBrowserTest,
                       DISABLED_CacheTwiceAndGoBack) {}

#endif  // !BUILDFLAG(IS_CHROMEOS_LACROS)