blob: 6212263da1681d8645664827fe3ebac870fa2bb3 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2012 The Chromium Authors
[email protected]c2b67262009-05-19 23:32:262// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <string>
6
[email protected]57999812013-02-24 05:40:527#include "base/files/file_path.h"
avib7348942015-12-25 20:57:108#include "build/build_config.h"
[email protected]b9535422012-02-09 01:47:599#include "content/browser/child_process_security_policy_impl.h"
Lukasz Anforowicz2b2699732018-04-12 18:49:1010#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]93ddb3c2012-04-11 21:44:2911#include "content/browser/web_contents/web_contents_impl.h"
Lukasz Anforowicz9e0ce4e2017-09-28 19:09:1512#include "content/public/browser/render_frame_host.h"
[email protected]f3b1a082011-11-18 00:34:3013#include "content/public/browser/render_process_host.h"
[email protected]b39ef1cb2011-10-25 04:46:5514#include "content/public/common/result_codes.h"
Peter Kasting919ce652020-05-07 10:22:3615#include "content/public/test/browser_test.h"
Wez0abfbf512018-03-03 01:54:4516#include "content/public/test/browser_test_utils.h"
[email protected]6e9def12014-03-27 20:23:2817#include "content/public/test/content_browser_test.h"
18#include "content/public/test/content_browser_test_utils.h"
[email protected]de7d61ff2013-08-20 11:30:4119#include "content/shell/browser/shell.h"
[email protected]c2b67262009-05-19 23:32:2620#include "testing/gtest/include/gtest/gtest.h"
21
[email protected]46488322012-10-30 03:22:2022namespace content {
23
[email protected]c2b67262009-05-19 23:32:2624class ChildProcessSecurityPolicyInProcessBrowserTest
[email protected]46488322012-10-30 03:22:2025 : public ContentBrowserTest {
[email protected]c2b67262009-05-19 23:32:2626 public:
dchengfa85b152014-10-28 01:13:4227 void SetUp() override {
Lukasz Anforowicz40066f52018-09-21 21:14:4128 auto* policy = ChildProcessSecurityPolicyImpl::GetInstance();
29 {
30 base::AutoLock lock(policy->lock_);
31 EXPECT_EQ(0u, policy->security_state_.size());
32 }
[email protected]4cdc9a22012-07-26 03:39:3133 ContentBrowserTest::SetUp();
[email protected]c2b67262009-05-19 23:32:2634 }
35
dchengfa85b152014-10-28 01:13:4236 void TearDown() override {
Lukasz Anforowicz40066f52018-09-21 21:14:4137 auto* policy = ChildProcessSecurityPolicyImpl::GetInstance();
38 {
39 base::AutoLock lock(policy->lock_);
40 EXPECT_EQ(0u, policy->security_state_.size());
41 }
[email protected]4cdc9a22012-07-26 03:39:3142 ContentBrowserTest::TearDown();
[email protected]c2b67262009-05-19 23:32:2643 }
44};
45
Xiaohan Wang1ecfd002022-01-19 22:33:1046#if !defined(NDEBUG) && BUILDFLAG(IS_MAC)
Patrick Monette37faeab52024-11-20 19:58:4247#define MAYBE_NoLeak DISABLED_NoLeak
[email protected]7ededb82012-07-26 04:50:3648#else
Patrick Monette37faeab52024-11-20 19:58:4249#define MAYBE_NoLeak NoLeak
[email protected]7ededb82012-07-26 04:50:3650#endif
Patrick Monette37faeab52024-11-20 19:58:4251IN_PROC_BROWSER_TEST_F(ChildProcessSecurityPolicyInProcessBrowserTest,
52 MAYBE_NoLeak) {
[email protected]46488322012-10-30 03:22:2053 GURL url = GetTestUrl("", "simple_page.html");
Lukasz Anforowicz40066f52018-09-21 21:14:4154 auto* policy = ChildProcessSecurityPolicyImpl::GetInstance();
Alex Moshchukaeb20fe32019-09-25 17:40:0155 EXPECT_TRUE(NavigateToURL(shell(), url));
Lukasz Anforowicz40066f52018-09-21 21:14:4156 {
57 base::AutoLock lock(policy->lock_);
Patrick Monette37faeab52024-11-20 19:58:4258 size_t spare_count =
59 content::SpareRenderProcessHostManager::Get().GetSpares().size();
60 EXPECT_EQ(1u + spare_count, policy->security_state_.size());
Lukasz Anforowicz40066f52018-09-21 21:14:4161 }
[email protected]c2b67262009-05-19 23:32:2662
[email protected]46488322012-10-30 03:22:2063 WebContents* web_contents = shell()->web_contents();
Wez0abfbf512018-03-03 01:54:4564 content::RenderProcessHostWatcher exit_observer(
Dave Tapuska327c06c92022-06-13 20:31:5165 web_contents->GetPrimaryMainFrame()->GetProcess(),
Wez0abfbf512018-03-03 01:54:4566 content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
Dave Tapuska327c06c92022-06-13 20:31:5167 web_contents->GetPrimaryMainFrame()->GetProcess()->Shutdown(
68 RESULT_CODE_KILLED);
Wez0abfbf512018-03-03 01:54:4569 exit_observer.Wait();
[email protected]c2b67262009-05-19 23:32:2670
toyoshim6142d96f2016-12-19 09:07:2571 web_contents->GetController().Reload(ReloadType::NORMAL, true);
Lukasz Anforowicz40066f52018-09-21 21:14:4172 {
73 base::AutoLock lock(policy->lock_);
Patrick Monette37faeab52024-11-20 19:58:4274 size_t spare_count =
75 content::SpareRenderProcessHostManager::Get().GetSpares().size();
76 EXPECT_EQ(1u + spare_count, policy->security_state_.size());
Lukasz Anforowicz40066f52018-09-21 21:14:4177 }
[email protected]c2b67262009-05-19 23:32:2678}
[email protected]46488322012-10-30 03:22:2079
80} // namespace content