#include "chrome/browser/resource_coordinator/tab_manager.h"
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/memory_pressure_listener.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/simple_test_clock.h"
#include "base/test/simple_test_tick_clock.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/devtools/devtools_window_testing.h"
#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
#include "chrome/browser/media/webrtc/media_stream_capture_indicator.h"
#include "chrome/browser/resource_coordinator/lifecycle_unit_observer.h"
#include "chrome/browser/resource_coordinator/tab_lifecycle_observer.h"
#include "chrome/browser/resource_coordinator/tab_lifecycle_unit.h"
#include "chrome/browser/resource_coordinator/tab_lifecycle_unit_external.h"
#include "chrome/browser/resource_coordinator/tab_manager_features.h"
#include "chrome/browser/resource_coordinator/time.h"
#include "chrome/browser/resource_coordinator/utils.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/find_bar/find_bar_controller.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/memory_pressure/fake_memory_pressure_monitor.h"
#include "components/performance_manager/public/features.h"
#include "content/public/browser/navigation_details.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_process_host_creation_observer.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/fenced_frame_test_util.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h"
#include "net/dns/mock_host_resolver.h"
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom.h"
#include "url/gurl.h"
OpenURLParams;
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) || \
BUILDFLAG(IS_CHROMEOS)
namespace resource_coordinator {
namespace {
constexpr base::TimeDelta kShortDelay = …;
bool IsTabDiscarded(content::WebContents* web_contents) { … }
class ExpectStateTransitionObserver : public LifecycleUnitObserver { … };
class DiscardWaiter : public TabLifecycleObserver { … };
class WindowedRenderProcessHostExitObserver
: public content::RenderProcessHostObserver { … };
}
class TabManagerTest : public InProcessBrowserTest { … };
class TabManagerTestWithTwoTabs : public TabManagerTest { … };
IN_PROC_BROWSER_TEST_F(TabManagerTest, TabManagerBasics) { … }
IN_PROC_BROWSER_TEST_F(TabManagerTest, InvalidOrEmptyURL) { … }
IN_PROC_BROWSER_TEST_F(TabManagerTest, TabDiscardDoneCallback) { … }
IN_PROC_BROWSER_TEST_F(TabManagerTest, ProtectPDFPages) { … }
#if !BUILDFLAG(IS_CHROMEOS_ASH)
IN_PROC_BROWSER_TEST_F(TabManagerTest,
ProtectRecentlyUsedTabsFromUrgentDiscarding) { … }
#endif
IN_PROC_BROWSER_TEST_F(TabManagerTest, ProtectVideoTabs) { … }
#if BUILDFLAG(IS_LINUX) && !defined(NDEBUG)
#define MAYBE_ProtectDevToolsTabsFromDiscarding …
#else
#define MAYBE_ProtectDevToolsTabsFromDiscarding …
#endif
IN_PROC_BROWSER_TEST_F(TabManagerTest,
MAYBE_ProtectDevToolsTabsFromDiscarding) { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS) && defined(ADDRESS_SANITIZER)
#define MAYBE_AutoDiscardable …
#else
#define MAYBE_AutoDiscardable …
#endif
IN_PROC_BROWSER_TEST_F(TabManagerTest, MAYBE_AutoDiscardable) { … }
IN_PROC_BROWSER_TEST_F(TabManagerTestWithTwoTabs,
UrgentFastShutdownSingleTabProcess) { … }
IN_PROC_BROWSER_TEST_F(TabManagerTest, UrgentFastShutdownSharedTabProcess) { … }
IN_PROC_BROWSER_TEST_F(TabManagerTest, UrgentFastShutdownWithUnloadHandler) { … }
IN_PROC_BROWSER_TEST_F(TabManagerTest,
UrgentFastShutdownWithBeforeunloadHandler) { … }
IN_PROC_BROWSER_TEST_F(TabManagerTestWithTwoTabs, TabUrgentDiscardAndNavigate) { … }
IN_PROC_BROWSER_TEST_F(TabManagerTest, DiscardedTabHasNoProcess) { … }
IN_PROC_BROWSER_TEST_F(TabManagerTest,
TabManagerWasDiscardedCrossSiteSubFrame) { … }
class TabManagerFencedFrameTest : public TabManagerTest { … };
IN_PROC_BROWSER_TEST_F(TabManagerFencedFrameTest, TabManagerWasDiscarded) { … }
namespace {
void EnsureTabsInBrowser(Browser* browser, int num_tabs) { … }
Browser* CreateBrowserWithTabs(int num_tabs) { … }
}
#if !defined(NDEBUG) || defined(ADDRESS_SANITIZER)
#define MAYBE_DiscardTabsWithMinimizedWindow …
#else
#define MAYBE_DiscardTabsWithMinimizedWindow …
#endif
IN_PROC_BROWSER_TEST_F(TabManagerTest, MAYBE_DiscardTabsWithMinimizedWindow) { … }
#if !defined(NDEBUG) || defined(ADDRESS_SANITIZER)
#define MAYBE_DiscardTabsWithOccludedWindow …
#else
#define MAYBE_DiscardTabsWithOccludedWindow …
#endif
IN_PROC_BROWSER_TEST_F(TabManagerTest, MAYBE_DiscardTabsWithOccludedWindow) { … }
}
#endif