#include "content/renderer/render_thread_impl.h"
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <utility>
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/containers/heap_array.h"
#include "base/debug/leak_annotations.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/location.h"
#include "base/memory/discardable_memory.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/field_trial.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "base/test/test_switches.h"
#include "cc/base/switches.h"
#include "content/app/mojo/mojo_init.h"
#include "content/common/in_process_child_thread_params.h"
#include "content/common/pseudonymization_salt.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_host.h"
#include "content/public/browser/child_process_host_delegate.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/renderer/content_renderer_client.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/content_test_suite_base.h"
#include "content/public/test/test_content_client_initializer.h"
#include "content/public/test/test_launcher.h"
#include "content/renderer/render_process_impl.h"
#include "gpu/config/gpu_switches.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/scheduler/test/renderer_scheduler_test_support.h"
#include "third_party/blink/public/platform/scheduler/test/web_mock_thread_scheduler.h"
#include "third_party/blink/public/platform/scheduler/web_thread_scheduler.h"
#include "ui/base/ui_base_switches.h"
#if BUILDFLAG(CONTENT_ENABLE_LEGACY_IPC)
#undef IPC_IPC_MESSAGE_MACROS_H_
#undef IPC_MESSAGE_EXTRA
#define IPC_MESSAGE_IMPL
#include "ipc/ipc_message_macros.h"
#include "ipc/ipc_message_start.h"
#include "ipc/ipc_message_templates_impl.h"
#undef IPC_MESSAGE_START
#define IPC_MESSAGE_START …
IPC_MESSAGE_CONTROL0(TestMsg_QuitRunLoop)
#endif
#ifdef LEAK_SANITIZER
#define WILL_LEAK …
#else
#define WILL_LEAK(NAME) …
#endif
namespace content {
class TestTaskCounter : public base::SingleThreadTaskRunner { … };
#if BUILDFLAG(CONTENT_ENABLE_LEGACY_IPC)
class QuitOnTestMsgFilter : public IPC::MessageFilter {
public:
explicit QuitOnTestMsgFilter(base::OnceClosure quit_closure)
: origin_task_runner_(
blink::scheduler::GetSequencedTaskRunnerForTesting()),
quit_closure_(std::move(quit_closure)) {}
bool OnMessageReceived(const IPC::Message& message) override {
origin_task_runner_->PostTask(FROM_HERE, std::move(quit_closure_));
return true;
}
bool GetSupportedMessageClasses(
std::vector<uint32_t>* supported_message_classes) const override {
supported_message_classes->push_back(TestMsgStart);
return true;
}
private:
~QuitOnTestMsgFilter() override {}
scoped_refptr<base::SequencedTaskRunner> origin_task_runner_;
base::OnceClosure quit_closure_;
};
#endif
class RenderThreadImplBrowserTest : public testing::Test,
public ChildProcessHostDelegate { … };
#if BUILDFLAG(CONTENT_ENABLE_LEGACY_IPC)
TEST_F(RenderThreadImplBrowserTest,
WILL_LEAK(NonResourceDispatchIPCTasksDontGoThroughScheduler)) {
browser_threads_->RunIOThreadUntilIdle();
sender()->Send(new TestMsg_QuitRunLoop());
SetPseudonymizationSalt(0xDEADBEEF);
run_loop_->Run();
EXPECT_EQ(0, test_task_counter_->NumTasksPosted());
}
#endif
TEST_F(RenderThreadImplBrowserTest, RendererIsBackgrounded) { … }
TEST_F(RenderThreadImplBrowserTest, RendererIsHidden) { … }
TEST_F(RenderThreadImplBrowserTest, RendererStateTransitionVisible) { … }
TEST_F(RenderThreadImplBrowserTest, RendererStateTransitionHidden) { … }
TEST_F(RenderThreadImplBrowserTest, RendererStateTransitionBackgrounded) { … }
TEST_F(RenderThreadImplBrowserTest, RendererStateTransitionForegrounded) { … }
}