#include "content/public/test/mock_render_process_host.h"
#include <algorithm>
#include <tuple>
#include <utility>
#include <vector>
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/lazy_instance.h"
#include "base/location.h"
#include "base/notreached.h"
#include "base/process/process_handle.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "content/browser/child_process_host_impl.h"
#include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/file_system_access/file_system_access_error.h"
#include "content/browser/process_lock.h"
#include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/common/renderer.mojom.h"
#include "content/public/browser/android/child_process_importance.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/global_request_id.h"
#include "content/public/browser/render_process_host_priority_client.h"
#include "content/public/browser/render_widget_host_iterator.h"
#include "content/public/browser/site_instance.h"
#include "content/test/fake_network_url_loader_factory.h"
#include "media/media_buildflags.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
namespace content {
namespace {
StoragePartitionConfig GetOrCreateStoragePartitionConfig(
BrowserContext* browser_context,
SiteInstance* site_instance) { … }
}
MockRenderProcessHost::MockRenderProcessHost(BrowserContext* browser_context,
bool is_for_guests_only)
: … { … }
MockRenderProcessHost::MockRenderProcessHost(
BrowserContext* browser_context,
const StoragePartitionConfig& storage_partition_config,
bool is_for_guests_only)
: … { … }
MockRenderProcessHost::~MockRenderProcessHost() { … }
void MockRenderProcessHost::SimulateCrash() { … }
void MockRenderProcessHost::SimulateRenderProcessExit(
base::TerminationStatus status,
int exit_code) { … }
void MockRenderProcessHost::SimulateReady() { … }
bool MockRenderProcessHost::Init() { … }
void MockRenderProcessHost::EnableSendQueue() { … }
int MockRenderProcessHost::GetNextRoutingID() { … }
void MockRenderProcessHost::AddRoute(int32_t routing_id,
IPC::Listener* listener) { … }
void MockRenderProcessHost::RemoveRoute(int32_t routing_id) { … }
void MockRenderProcessHost::AddObserver(RenderProcessHostObserver* observer) { … }
void MockRenderProcessHost::RemoveObserver(
RenderProcessHostObserver* observer) { … }
void MockRenderProcessHost::ShutdownForBadMessage(
CrashReportMode crash_report_mode) { … }
void MockRenderProcessHost::UpdateClientPriority(
RenderProcessHostPriorityClient* client) { … }
int MockRenderProcessHost::VisibleClientCount() { … }
unsigned int MockRenderProcessHost::GetFrameDepth() { … }
bool MockRenderProcessHost::GetIntersectsViewport() { … }
bool MockRenderProcessHost::IsForGuestsOnly() { … }
bool MockRenderProcessHost::IsJitDisabled() { … }
bool MockRenderProcessHost::AreV8OptimizationsDisabled() { … }
bool MockRenderProcessHost::IsPdf() { … }
void MockRenderProcessHost::OnMediaStreamAdded() { … }
void MockRenderProcessHost::OnMediaStreamRemoved() { … }
void MockRenderProcessHost::OnForegroundServiceWorkerAdded() { … }
void MockRenderProcessHost::OnForegroundServiceWorkerRemoved() { … }
void MockRenderProcessHost::OnBoostForLoadingAdded() { … }
void MockRenderProcessHost::OnBoostForLoadingRemoved() { … }
StoragePartition* MockRenderProcessHost::GetStoragePartition() { … }
void MockRenderProcessHost::AddWord(const std::u16string& word) { … }
bool MockRenderProcessHost::Shutdown(int exit_code) { … }
bool MockRenderProcessHost::ShutdownRequested() { … }
bool MockRenderProcessHost::FastShutdownIfPossible(size_t page_count,
bool skip_unload_handlers) { … }
bool MockRenderProcessHost::FastShutdownStarted() { … }
const base::Process& MockRenderProcessHost::GetProcess() { … }
bool MockRenderProcessHost::IsReady() { … }
bool MockRenderProcessHost::Send(IPC::Message* msg) { … }
int MockRenderProcessHost::GetID() const { … }
base::SafeRef<RenderProcessHost> MockRenderProcessHost::GetSafeRef() const { … }
bool MockRenderProcessHost::IsInitializedAndNotDead() { … }
bool MockRenderProcessHost::IsDeletingSoon() { … }
void MockRenderProcessHost::SetBlocked(bool blocked) { … }
bool MockRenderProcessHost::IsBlocked() { … }
base::CallbackListSubscription
MockRenderProcessHost::RegisterBlockStateChangedCallback(
const BlockStateChangedCallback& cb) { … }
void MockRenderProcessHost::Cleanup() { … }
void MockRenderProcessHost::AddPendingView() { … }
void MockRenderProcessHost::RemovePendingView() { … }
void MockRenderProcessHost::AddPriorityClient(
RenderProcessHostPriorityClient* priority_client) { … }
void MockRenderProcessHost::RemovePriorityClient(
RenderProcessHostPriorityClient* priority_client) { … }
#if !BUILDFLAG(IS_ANDROID)
void MockRenderProcessHost::SetPriorityOverride(
base::Process::Priority priority) { … }
bool MockRenderProcessHost::HasPriorityOverride() { … }
void MockRenderProcessHost::ClearPriorityOverride() { … }
#endif
#if BUILDFLAG(IS_ANDROID)
ChildProcessImportance MockRenderProcessHost::GetEffectiveImportance() {
NOTIMPLEMENTED();
return ChildProcessImportance::NORMAL;
}
base::android::ChildBindingState
MockRenderProcessHost::GetEffectiveChildBindingState() {
NOTIMPLEMENTED();
return base::android::ChildBindingState::UNBOUND;
}
void MockRenderProcessHost::DumpProcessStack() {}
#endif
void MockRenderProcessHost::SetSuddenTerminationAllowed(bool allowed) { … }
bool MockRenderProcessHost::SuddenTerminationAllowed() { … }
BrowserContext* MockRenderProcessHost::GetBrowserContext() { … }
bool MockRenderProcessHost::InSameStoragePartition(
StoragePartition* partition) { … }
IPC::ChannelProxy* MockRenderProcessHost::GetChannel() { … }
#if BUILDFLAG(CONTENT_ENABLE_LEGACY_IPC)
void MockRenderProcessHost::AddFilter(BrowserMessageFilter* filter) {}
#endif
base::TimeDelta MockRenderProcessHost::GetChildProcessIdleTime() { … }
void MockRenderProcessHost::BindReceiver(
mojo::GenericPendingReceiver receiver) { … }
std::unique_ptr<base::PersistentMemoryAllocator>
MockRenderProcessHost::TakeMetricsAllocator() { … }
const base::TimeTicks& MockRenderProcessHost::GetLastInitTime() { … }
base::Process::Priority MockRenderProcessHost::GetPriority() { … }
std::string MockRenderProcessHost::GetKeepAliveDurations() const { … }
size_t MockRenderProcessHost::GetShutdownDelayRefCount() const { … }
int MockRenderProcessHost::GetRenderFrameHostCount() const { … }
void MockRenderProcessHost::RegisterRenderFrameHost(
const GlobalRenderFrameHostId& render_frame_host_id,
bool is_outermost_main_frame) { … }
void MockRenderProcessHost::UnregisterRenderFrameHost(
const GlobalRenderFrameHostId& render_frame_host_id,
bool is_outermost_main_frame) { … }
void MockRenderProcessHost::ForEachRenderFrameHost(
base::FunctionRef<void(RenderFrameHost*)> on_render_frame_host) { … }
void MockRenderProcessHost::IncrementWorkerRefCount() { … }
void MockRenderProcessHost::DecrementWorkerRefCount() { … }
void MockRenderProcessHost::IncrementPendingReuseRefCount() { … }
void MockRenderProcessHost::DecrementPendingReuseRefCount() { … }
size_t MockRenderProcessHost::GetWorkerRefCount() const { … }
void MockRenderProcessHost::DisableRefCounts() { … }
bool MockRenderProcessHost::AreRefCountsDisabled() { … }
mojom::Renderer* MockRenderProcessHost::GetRendererInterface() { … }
bool MockRenderProcessHost::MayReuseHost() { … }
bool MockRenderProcessHost::IsUnused() { … }
void MockRenderProcessHost::SetIsUsed() { … }
bool MockRenderProcessHost::HostHasNotBeenUsed() { … }
bool MockRenderProcessHost::IsSpare() const { … }
void MockRenderProcessHost::SetProcessLock(
const IsolationContext& isolation_context,
const ProcessLock& process_lock) { … }
ProcessLock MockRenderProcessHost::GetProcessLock() const { … }
bool MockRenderProcessHost::IsProcessLockedToSiteForTesting() { … }
void MockRenderProcessHost::BindCacheStorage(
const network::CrossOriginEmbedderPolicy&,
mojo::PendingRemote<network::mojom::CrossOriginEmbedderPolicyReporter>,
const network::DocumentIsolationPolicy&,
const storage::BucketLocator& bucket_locator,
mojo::PendingReceiver<blink::mojom::CacheStorage> receiver) { … }
void MockRenderProcessHost::BindIndexedDB(
const blink::StorageKey& storage_key,
BucketContext& bucket_context,
mojo::PendingReceiver<blink::mojom::IDBFactory> receiver) { … }
void MockRenderProcessHost::GetSandboxedFileSystemForBucket(
const storage::BucketLocator& bucket,
const std::vector<std::string>& directory_path_components,
blink::mojom::FileSystemAccessManager::GetSandboxedFileSystemCallback
callback) { … }
std::string
MockRenderProcessHost::GetInfoForBrowserContextDestructionCrashReporting() { … }
void MockRenderProcessHost::WriteIntoTrace(
perfetto::TracedProto<TraceProto> proto) const { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
void MockRenderProcessHost::ReinitializeLogging(
uint32_t logging_dest,
base::ScopedFD log_file_descriptor) {
NOTIMPLEMENTED();
}
#endif
uint64_t MockRenderProcessHost::GetPrivateMemoryFootprint() { … }
RenderProcessHost::FilterURLResult MockRenderProcessHost::FilterURL(
bool empty_allowed,
GURL* url) { … }
void MockRenderProcessHost::EnableAudioDebugRecordings(
const base::FilePath& file) { … }
void MockRenderProcessHost::DisableAudioDebugRecordings() { … }
RenderProcessHost::WebRtcStopRtpDumpCallback
MockRenderProcessHost::StartRtpDump(bool incoming,
bool outgoing,
WebRtcRtpPacketCallback packet_callback) { … }
bool MockRenderProcessHost::OnMessageReceived(const IPC::Message& msg) { … }
void MockRenderProcessHost::OnChannelConnected(int32_t peer_pid) { … }
void MockRenderProcessHost::OverrideBinderForTesting(
const std::string& interface_name,
const InterfaceBinder& binder) { … }
void MockRenderProcessHost::OverrideRendererInterfaceForTesting(
std::unique_ptr<mojo::AssociatedRemote<mojom::Renderer>>
renderer_interface) { … }
MockRenderProcessHostFactory::MockRenderProcessHostFactory() = default;
MockRenderProcessHostFactory::~MockRenderProcessHostFactory() = default;
RenderProcessHost* MockRenderProcessHostFactory::CreateRenderProcessHost(
BrowserContext* browser_context,
SiteInstance* site_instance) { … }
void MockRenderProcessHostFactory::Remove(MockRenderProcessHost* host) const { … }
}