#include "base/strings/string_number_conversions.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "base/values.h"
#include "build/build_config.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_base.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_content_browser_client.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "content/shell/browser/shell.h"
#include "net/dns/mock_host_resolver.h"
#include "sandbox/policy/features.h"
#include "testing/gtest/include/gtest/gtest.h"
#if BUILDFLAG(IS_WIN)
#include "sandbox/policy/win/sandbox_win.h"
#endif
namespace content {
namespace {
constexpr char kEnabledDomain[] = …;
constexpr char kDisabledDomain[] = …;
bool RendererIsJitless(RenderProcessHost* rph) { … }
#if BUILDFLAG(IS_WIN)
bool RendererHasDynamicCodeMitigation(RenderProcessHost* rph) {
base::Process proc = rph->GetProcess().Duplicate();
base::ProcessId renderer_process_id = proc.Pid();
base::RunLoop run_loop;
base::Value out_args;
sandbox::policy::SandboxWin::GetPolicyDiagnostics(
base::BindLambdaForTesting([&run_loop, &out_args](base::Value args) {
out_args = std::move(args);
run_loop.Quit();
}));
run_loop.Run();
const base::Value::List* process_list = out_args.GetIfList();
CHECK(process_list);
for (const base::Value& process_value : *process_list) {
const base::Value::Dict* process = process_value.GetIfDict();
CHECK(process);
double pid = *process->FindDouble("processId");
if (base::checked_cast<base::ProcessId>(pid) != renderer_process_id) {
continue;
}
std::string mitigations = *process->FindString("desiredMitigations");
uint64_t mask = 0;
CHECK(base::HexStringToUInt64(mitigations, &mask));
return !!(mask & sandbox::MITIGATION_DYNAMIC_CODE_DISABLE);
}
return false;
}
#endif
}
class JitPolicyContentBrowserClient
: public ContentBrowserTestContentBrowserClient { … };
class JitPolicyBrowserTest : public ContentBrowserTest { … };
IN_PROC_BROWSER_TEST_F(JitPolicyBrowserTest, JitDisabledImpliesJitless) { … }
IN_PROC_BROWSER_TEST_F(JitPolicyBrowserTest, JitEnabledImpliesNoJitless) { … }
}