#include "content/public/test/mock_render_thread.h"
#include <memory>
#include <tuple>
#include "base/logging.h"
#include "base/task/single_thread_task_runner.h"
#include "base/unguessable_token.h"
#include "build/build_config.h"
#include "content/common/associated_interfaces.mojom.h"
#include "content/common/frame.mojom.h"
#include "content/public/renderer/render_thread_observer.h"
#include "content/renderer/render_thread_impl.h"
#include "content/test/test_render_frame.h"
#include "ipc/ipc_message_utils.h"
#include "ipc/ipc_sync_message.h"
#include "ipc/message_filter.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/dom_storage/session_storage_namespace_id.h"
#include "third_party/blink/public/common/user_agent/user_agent_metadata.h"
#include "third_party/blink/public/mojom/page/widget.mojom.h"
#include "third_party/blink/public/mojom/widget/platform_widget.mojom.h"
namespace content {
namespace {
constexpr int32_t kFirstGeneratedRoutingId = …;
static const blink::UserAgentMetadata kUserAgentMetadata;
}
MockRenderThread::MockRenderThread()
: … { … }
MockRenderThread::~MockRenderThread() { … }
#if BUILDFLAG(CONTENT_ENABLE_LEGACY_IPC)
bool MockRenderThread::Send(IPC::Message* msg) {
if (msg->is_reply()) {
if (reply_deserializer_) {
reply_deserializer_->SerializeOutputParameters(*msg);
reply_deserializer_.reset();
}
} else {
if (msg->is_sync()) {
reply_deserializer_ =
static_cast<IPC::SyncMessage*>(msg)->TakeReplyDeserializer();
}
if (msg->routing_id() == MSG_ROUTING_CONTROL)
OnControlMessageReceived(*msg);
else
OnMessageReceived(*msg);
}
delete msg;
return true;
}
IPC::SyncMessageFilter* MockRenderThread::GetSyncMessageFilter() {
return nullptr;
}
void MockRenderThread::AddRoute(int32_t routing_id, IPC::Listener* listener) {}
void MockRenderThread::AttachTaskRunnerToRoute(
int32_t routing_id,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) {}
void MockRenderThread::RemoveRoute(int32_t routing_id) {}
void MockRenderThread::AddFilter(IPC::MessageFilter* filter) {
filter->OnFilterAdded(&sink());
filters_.push_back(base::WrapRefCounted(filter));
}
void MockRenderThread::RemoveFilter(IPC::MessageFilter* filter) {
for (size_t i = 0; i < filters_.size(); ++i) {
if (filters_[i].get() == filter) {
filter->OnFilterRemoved();
filters_.erase(filters_.begin() + i);
return;
}
}
NOTREACHED_IN_MIGRATION() << "filter to be removed not found";
}
#endif
IPC::SyncChannel* MockRenderThread::GetChannel() { … }
std::string MockRenderThread::GetLocale() { … }
scoped_refptr<base::SingleThreadTaskRunner>
MockRenderThread::GetIOTaskRunner() { … }
void MockRenderThread::BindHostReceiver(mojo::GenericPendingReceiver receiver) { … }
bool MockRenderThread::GenerateFrameRoutingID(
int32_t& routing_id,
blink::LocalFrameToken& frame_token,
base::UnguessableToken& devtools_frame_token,
blink::DocumentToken& document_token) { … }
void MockRenderThread::AddObserver(RenderThreadObserver* observer) { … }
void MockRenderThread::RemoveObserver(RenderThreadObserver* observer) { … }
void MockRenderThread::RecordAction(const base::UserMetricsAction& action) { … }
void MockRenderThread::RecordComputedAction(const std::string& action) { … }
int MockRenderThread::PostTaskToAllWebWorkers(base::RepeatingClosure closure) { … }
base::WaitableEvent* MockRenderThread::GetShutdownEvent() { … }
int32_t MockRenderThread::GetClientId() { … }
void MockRenderThread::SetRendererProcessType(
blink::scheduler::WebRendererProcessType type) { … }
blink::WebString MockRenderThread::GetUserAgent() { … }
const blink::UserAgentMetadata& MockRenderThread::GetUserAgentMetadata() { … }
#if BUILDFLAG(IS_WIN)
void MockRenderThread::PreCacheFont(const LOGFONT& log_font) {
}
void MockRenderThread::ReleaseCachedFonts() {
}
#endif
void MockRenderThread::SetFieldTrialGroup(const std::string& trial_name,
const std::string& group_name) { … }
void MockRenderThread::WriteIntoTrace(
perfetto::TracedProto<perfetto::protos::pbzero::RenderProcessHost> proto) { … }
int32_t MockRenderThread::GetNextRoutingID() { … }
mojo::PendingReceiver<blink::mojom::BrowserInterfaceBroker>
MockRenderThread::TakeInitialBrowserInterfaceBrokerReceiverForFrame(
const blink::LocalFrameToken& frame_token) { … }
void MockRenderThread::OnCreateChildFrame(
const blink::LocalFrameToken& child_frame_token,
mojo::PendingAssociatedRemote<mojom::Frame> frame_remote,
mojo::PendingReceiver<blink::mojom::BrowserInterfaceBroker>
browser_interface_broker) { … }
#if BUILDFLAG(CONTENT_ENABLE_LEGACY_IPC)
bool MockRenderThread::OnControlMessageReceived(const IPC::Message& msg) {
for (auto& observer : observers_) {
if (observer.OnControlMessageReceived(msg))
return true;
}
return OnMessageReceived(msg);
}
bool MockRenderThread::OnMessageReceived(const IPC::Message& msg) {
sink_.OnMessageReceived(msg);
return false;
}
#endif
void MockRenderThread::OnCreateWindow(
const mojom::CreateNewWindowParams& params,
mojom::CreateNewWindowReply* reply) { … }
void MockRenderThread::ReleaseAllWebViews() { … }
}