Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | c2b6726 | 2009-05-19 23:32:26 | [diff] [blame] | 2 | // 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] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 7 | #include "base/files/file_path.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 8 | #include "build/build_config.h" |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 9 | #include "content/browser/child_process_security_policy_impl.h" |
Lukasz Anforowicz | 2b269973 | 2018-04-12 18:49:10 | [diff] [blame] | 10 | #include "content/browser/renderer_host/render_process_host_impl.h" |
[email protected] | 93ddb3c | 2012-04-11 21:44:29 | [diff] [blame] | 11 | #include "content/browser/web_contents/web_contents_impl.h" |
Lukasz Anforowicz | 9e0ce4e | 2017-09-28 19:09:15 | [diff] [blame] | 12 | #include "content/public/browser/render_frame_host.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 13 | #include "content/public/browser/render_process_host.h" |
[email protected] | b39ef1cb | 2011-10-25 04:46:55 | [diff] [blame] | 14 | #include "content/public/common/result_codes.h" |
Peter Kasting | 919ce65 | 2020-05-07 10:22:36 | [diff] [blame] | 15 | #include "content/public/test/browser_test.h" |
Wez | 0abfbf51 | 2018-03-03 01:54:45 | [diff] [blame] | 16 | #include "content/public/test/browser_test_utils.h" |
[email protected] | 6e9def1 | 2014-03-27 20:23:28 | [diff] [blame] | 17 | #include "content/public/test/content_browser_test.h" |
18 | #include "content/public/test/content_browser_test_utils.h" | ||||
[email protected] | de7d61ff | 2013-08-20 11:30:41 | [diff] [blame] | 19 | #include "content/shell/browser/shell.h" |
[email protected] | c2b6726 | 2009-05-19 23:32:26 | [diff] [blame] | 20 | #include "testing/gtest/include/gtest/gtest.h" |
21 | |||||
[email protected] | 4648832 | 2012-10-30 03:22:20 | [diff] [blame] | 22 | namespace content { |
23 | |||||
[email protected] | c2b6726 | 2009-05-19 23:32:26 | [diff] [blame] | 24 | class ChildProcessSecurityPolicyInProcessBrowserTest |
[email protected] | 4648832 | 2012-10-30 03:22:20 | [diff] [blame] | 25 | : public ContentBrowserTest { |
[email protected] | c2b6726 | 2009-05-19 23:32:26 | [diff] [blame] | 26 | public: |
dcheng | fa85b15 | 2014-10-28 01:13:42 | [diff] [blame] | 27 | void SetUp() override { |
Lukasz Anforowicz | 40066f5 | 2018-09-21 21:14:41 | [diff] [blame] | 28 | auto* policy = ChildProcessSecurityPolicyImpl::GetInstance(); |
29 | { | ||||
30 | base::AutoLock lock(policy->lock_); | ||||
31 | EXPECT_EQ(0u, policy->security_state_.size()); | ||||
32 | } | ||||
[email protected] | 4cdc9a2 | 2012-07-26 03:39:31 | [diff] [blame] | 33 | ContentBrowserTest::SetUp(); |
[email protected] | c2b6726 | 2009-05-19 23:32:26 | [diff] [blame] | 34 | } |
35 | |||||
dcheng | fa85b15 | 2014-10-28 01:13:42 | [diff] [blame] | 36 | void TearDown() override { |
Lukasz Anforowicz | 40066f5 | 2018-09-21 21:14:41 | [diff] [blame] | 37 | auto* policy = ChildProcessSecurityPolicyImpl::GetInstance(); |
38 | { | ||||
39 | base::AutoLock lock(policy->lock_); | ||||
40 | EXPECT_EQ(0u, policy->security_state_.size()); | ||||
41 | } | ||||
[email protected] | 4cdc9a2 | 2012-07-26 03:39:31 | [diff] [blame] | 42 | ContentBrowserTest::TearDown(); |
[email protected] | c2b6726 | 2009-05-19 23:32:26 | [diff] [blame] | 43 | } |
44 | }; | ||||
45 | |||||
Xiaohan Wang | 1ecfd00 | 2022-01-19 22:33:10 | [diff] [blame] | 46 | #if !defined(NDEBUG) && BUILDFLAG(IS_MAC) |
Patrick Monette | 37faeab5 | 2024-11-20 19:58:42 | [diff] [blame] | 47 | #define MAYBE_NoLeak DISABLED_NoLeak |
[email protected] | 7ededb8 | 2012-07-26 04:50:36 | [diff] [blame] | 48 | #else |
Patrick Monette | 37faeab5 | 2024-11-20 19:58:42 | [diff] [blame] | 49 | #define MAYBE_NoLeak NoLeak |
[email protected] | 7ededb8 | 2012-07-26 04:50:36 | [diff] [blame] | 50 | #endif |
Patrick Monette | 37faeab5 | 2024-11-20 19:58:42 | [diff] [blame] | 51 | IN_PROC_BROWSER_TEST_F(ChildProcessSecurityPolicyInProcessBrowserTest, |
52 | MAYBE_NoLeak) { | ||||
[email protected] | 4648832 | 2012-10-30 03:22:20 | [diff] [blame] | 53 | GURL url = GetTestUrl("", "simple_page.html"); |
Lukasz Anforowicz | 40066f5 | 2018-09-21 21:14:41 | [diff] [blame] | 54 | auto* policy = ChildProcessSecurityPolicyImpl::GetInstance(); |
Alex Moshchuk | aeb20fe3 | 2019-09-25 17:40:01 | [diff] [blame] | 55 | EXPECT_TRUE(NavigateToURL(shell(), url)); |
Lukasz Anforowicz | 40066f5 | 2018-09-21 21:14:41 | [diff] [blame] | 56 | { |
57 | base::AutoLock lock(policy->lock_); | ||||
Patrick Monette | 37faeab5 | 2024-11-20 19:58:42 | [diff] [blame] | 58 | size_t spare_count = |
59 | content::SpareRenderProcessHostManager::Get().GetSpares().size(); | ||||
60 | EXPECT_EQ(1u + spare_count, policy->security_state_.size()); | ||||
Lukasz Anforowicz | 40066f5 | 2018-09-21 21:14:41 | [diff] [blame] | 61 | } |
[email protected] | c2b6726 | 2009-05-19 23:32:26 | [diff] [blame] | 62 | |
[email protected] | 4648832 | 2012-10-30 03:22:20 | [diff] [blame] | 63 | WebContents* web_contents = shell()->web_contents(); |
Wez | 0abfbf51 | 2018-03-03 01:54:45 | [diff] [blame] | 64 | content::RenderProcessHostWatcher exit_observer( |
Dave Tapuska | 327c06c9 | 2022-06-13 20:31:51 | [diff] [blame] | 65 | web_contents->GetPrimaryMainFrame()->GetProcess(), |
Wez | 0abfbf51 | 2018-03-03 01:54:45 | [diff] [blame] | 66 | content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
Dave Tapuska | 327c06c9 | 2022-06-13 20:31:51 | [diff] [blame] | 67 | web_contents->GetPrimaryMainFrame()->GetProcess()->Shutdown( |
68 | RESULT_CODE_KILLED); | ||||
Wez | 0abfbf51 | 2018-03-03 01:54:45 | [diff] [blame] | 69 | exit_observer.Wait(); |
[email protected] | c2b6726 | 2009-05-19 23:32:26 | [diff] [blame] | 70 | |
toyoshim | 6142d96f | 2016-12-19 09:07:25 | [diff] [blame] | 71 | web_contents->GetController().Reload(ReloadType::NORMAL, true); |
Lukasz Anforowicz | 40066f5 | 2018-09-21 21:14:41 | [diff] [blame] | 72 | { |
73 | base::AutoLock lock(policy->lock_); | ||||
Patrick Monette | 37faeab5 | 2024-11-20 19:58:42 | [diff] [blame] | 74 | size_t spare_count = |
75 | content::SpareRenderProcessHostManager::Get().GetSpares().size(); | ||||
76 | EXPECT_EQ(1u + spare_count, policy->security_state_.size()); | ||||
Lukasz Anforowicz | 40066f5 | 2018-09-21 21:14:41 | [diff] [blame] | 77 | } |
[email protected] | c2b6726 | 2009-05-19 23:32:26 | [diff] [blame] | 78 | } |
[email protected] | 4648832 | 2012-10-30 03:22:20 | [diff] [blame] | 79 | |
80 | } // namespace content |