#include <stddef.h>
#include <limits>
#include <memory>
#include <vector>
#include "base/command_line.h"
#include "base/run_loop.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_constants.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/mock_render_process_host.h"
#include "content/public/test/navigation_simulator.h"
#include "content/public/test/scoped_web_ui_controller_factory_registration.h"
#include "content/public/test/test_browser_context.h"
#include "content/public/test/test_utils.h"
#include "content/public/test/web_ui_browsertest_util.h"
#include "content/test/storage_partition_test_helpers.h"
#include "content/test/test_render_frame_host.h"
#include "content/test/test_render_view_host.h"
#include "content/test/test_web_contents.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/blink/public/common/frame/frame_policy.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "third_party/blink/public/mojom/frame/frame_owner_properties.mojom.h"
#include "ui/webui/untrusted_web_ui_browsertest_util.h"
namespace content {
class RenderProcessHostUnitTest : public RenderViewHostImplTestHarness { … };
TEST_F(RenderProcessHostUnitTest, GuestsAreNotSuitableHosts) { … }
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(RenderProcessHostUnitTest, RendererProcessLimit) { … }
#endif
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(RenderProcessHostUnitTest, NoRendererProcessLimitOnAndroidOrChromeOS) {
static constexpr size_t kMaxRendererProcessCountForTesting = 82;
std::vector<std::unique_ptr<MockRenderProcessHost>> hosts;
for (size_t i = 0; i < kMaxRendererProcessCountForTesting; ++i) {
hosts.push_back(std::make_unique<MockRenderProcessHost>(browser_context()));
}
GURL test_url("http://foo.com");
EXPECT_FALSE(RenderProcessHostImpl::ShouldTryToUseExistingProcessHost(
browser_context(), test_url));
}
#endif
TEST_F(RenderProcessHostUnitTest, ReuseCommittedSite) { … }
TEST_F(RenderProcessHostUnitTest, IsUnused) { … }
TEST_F(RenderProcessHostUnitTest, ReuseUnmatchedServiceWorkerProcess) { … }
class UnsuitableHostContentBrowserClient : public ContentBrowserClient { … };
TEST_F(RenderProcessHostUnitTest,
DontReuseUnsuitableUnmatchedServiceWorkerProcess) { … }
TEST_F(RenderProcessHostUnitTest, ReuseServiceWorkerProcessForServiceWorker) { … }
TEST_F(RenderProcessHostUnitTest,
ReuseServiceWorkerProcessInProcessPerSitePolicy) { … }
TEST_F(RenderProcessHostUnitTest, DoNotReuseOtherSiteServiceWorkerProcess) { … }
class RenderProcessHostWebUIUnitTest : public RenderProcessHostUnitTest { … };
TEST_F(RenderProcessHostWebUIUnitTest,
DontReuseServiceWorkerProcessForDifferentWebUI) { … }
TEST_F(RenderProcessHostWebUIUnitTest, DontReuseServiceWorkerProcessForWebUrl) { … }
TEST_F(RenderProcessHostWebUIUnitTest,
DontReuseServiceWorkerProcessForSameWebUI) { … }
class RenderProcessHostUntrustedWebUIUnitTest
: public RenderProcessHostUnitTest { … };
TEST_F(RenderProcessHostUntrustedWebUIUnitTest,
DontReuseServiceWorkerProcessForDifferentWebUI) { … }
TEST_F(RenderProcessHostUntrustedWebUIUnitTest,
DontReuseServiceWorkerProcessForWebUrl) { … }
TEST_F(RenderProcessHostUntrustedWebUIUnitTest,
DontReuseServiceWorkerProcessForSameWebUI) { … }
TEST_F(RenderProcessHostUnitTest, DoNotReuseError) { … }
TEST_F(RenderProcessHostUnitTest, ReuseNavigationProcess) { … }
TEST_F(RenderProcessHostUnitTest,
ReuseNavigationProcessRedirectsRendererInitiated) { … }
TEST_F(RenderProcessHostUnitTest,
ReuseNavigationProcessRedirectsBrowserInitiated) { … }
TEST_F(RenderProcessHostUnitTest, ReuseExpectedSiteURLChanges) { … }
class StoragePartitionContentBrowserClient : public ContentBrowserClient { … };
TEST_F(RenderProcessHostUnitTest,
DoNotReuseProcessInDifferentStoragePartition) { … }
TEST_F(RenderProcessHostUnitTest,
DoNotReuseServiceWorkerProcessInDifferentStoragePartition) { … }
TEST_F(RenderProcessHostUnitTest, RendererLockedToSite) { … }
TEST_F(RenderProcessHostUnitTest, ProcessAssignmentDefault) { … }
class SpareRenderProcessHostUnitTest : public RenderViewHostImplTestHarness { … };
SpareProcessMaybeTakeAction;
void ExpectSpareProcessMaybeTakeActionBucket(
const base::HistogramTester& histograms,
SpareProcessMaybeTakeAction expected_action) { … }
SpareProcessRefusedByEmbedderReason;
void ExpectSpareProcessRefusedByEmbedderReason(
const base::HistogramTester& histograms,
SpareProcessRefusedByEmbedderReason reason) { … }
TEST_F(SpareRenderProcessHostUnitTest, TestRendererTaken) { … }
TEST_F(SpareRenderProcessHostUnitTest, TestRendererNotTaken) { … }
class SpareProcessRejectBrowserClient : public ContentBrowserClient { … };
TEST_F(SpareRenderProcessHostUnitTest,
TestSpareProcessRefusedByEmbedderReason) { … }
TEST_F(SpareRenderProcessHostUnitTest, SpareMissing) { … }
TEST_F(SpareRenderProcessHostUnitTest,
SpareShouldNotLaunchInParallelWithOtherProcess) { … }
TEST_F(SpareRenderProcessHostUnitTest, JustBelowProcessLimit) { … }
TEST_F(SpareRenderProcessHostUnitTest, AtProcessLimit) { … }
}