[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[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 | |
| 7 | #include "base/basictypes.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 8 | #include "base/files/file_path.h" |
[email protected] | 3985ba8 | 2010-07-29 21:44:12 | [diff] [blame] | 9 | #include "base/process_util.h" |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 10 | #include "content/browser/child_process_security_policy_impl.h" |
[email protected] | 93ddb3c | 2012-04-11 21:44:29 | [diff] [blame] | 11 | #include "content/browser/web_contents/web_contents_impl.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 12 | #include "content/public/browser/render_process_host.h" |
[email protected] | b39ef1cb | 2011-10-25 04:46:55 | [diff] [blame] | 13 | #include "content/public/common/result_codes.h" |
[email protected] | 4cdc9a2 | 2012-07-26 03:39:31 | [diff] [blame] | 14 | #include "content/shell/shell.h" |
| 15 | #include "content/test/content_browser_test.h" |
| 16 | #include "content/test/content_browser_test_utils.h" |
[email protected] | c2b6726 | 2009-05-19 23:32:26 | [diff] [blame] | 17 | #include "testing/gtest/include/gtest/gtest.h" |
| 18 | |
[email protected] | 4648832 | 2012-10-30 03:22:20 | [diff] [blame] | 19 | namespace content { |
| 20 | |
[email protected] | c2b6726 | 2009-05-19 23:32:26 | [diff] [blame] | 21 | class ChildProcessSecurityPolicyInProcessBrowserTest |
[email protected] | 4648832 | 2012-10-30 03:22:20 | [diff] [blame] | 22 | : public ContentBrowserTest { |
[email protected] | c2b6726 | 2009-05-19 23:32:26 | [diff] [blame] | 23 | public: |
[email protected] | d9c2e51 | 2012-10-25 18:54:36 | [diff] [blame] | 24 | virtual void SetUp() { |
[email protected] | c2b6726 | 2009-05-19 23:32:26 | [diff] [blame] | 25 | EXPECT_EQ( |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 26 | ChildProcessSecurityPolicyImpl::GetInstance()->security_state_.size(), |
| 27 | 0U); |
[email protected] | 4cdc9a2 | 2012-07-26 03:39:31 | [diff] [blame] | 28 | ContentBrowserTest::SetUp(); |
[email protected] | c2b6726 | 2009-05-19 23:32:26 | [diff] [blame] | 29 | } |
| 30 | |
[email protected] | d9c2e51 | 2012-10-25 18:54:36 | [diff] [blame] | 31 | virtual void TearDown() { |
[email protected] | c2b6726 | 2009-05-19 23:32:26 | [diff] [blame] | 32 | EXPECT_EQ( |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 33 | ChildProcessSecurityPolicyImpl::GetInstance()->security_state_.size(), |
| 34 | 0U); |
[email protected] | 4cdc9a2 | 2012-07-26 03:39:31 | [diff] [blame] | 35 | ContentBrowserTest::TearDown(); |
[email protected] | c2b6726 | 2009-05-19 23:32:26 | [diff] [blame] | 36 | } |
| 37 | }; |
| 38 | |
[email protected] | 7ededb8 | 2012-07-26 04:50:36 | [diff] [blame] | 39 | #if !defined(NDEBUG) && defined(OS_MACOSX) |
| 40 | IN_PROC_BROWSER_TEST_F(ChildProcessSecurityPolicyInProcessBrowserTest, DISABLED_NoLeak) { |
| 41 | #else |
[email protected] | c2b6726 | 2009-05-19 23:32:26 | [diff] [blame] | 42 | IN_PROC_BROWSER_TEST_F(ChildProcessSecurityPolicyInProcessBrowserTest, NoLeak) { |
[email protected] | 7ededb8 | 2012-07-26 04:50:36 | [diff] [blame] | 43 | #endif |
[email protected] | 4648832 | 2012-10-30 03:22:20 | [diff] [blame] | 44 | GURL url = GetTestUrl("", "simple_page.html"); |
[email protected] | c2b6726 | 2009-05-19 23:32:26 | [diff] [blame] | 45 | |
[email protected] | 4648832 | 2012-10-30 03:22:20 | [diff] [blame] | 46 | NavigateToURL(shell(), url); |
[email protected] | c2b6726 | 2009-05-19 23:32:26 | [diff] [blame] | 47 | EXPECT_EQ( |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 48 | ChildProcessSecurityPolicyImpl::GetInstance()->security_state_.size(), |
| 49 | 1U); |
[email protected] | c2b6726 | 2009-05-19 23:32:26 | [diff] [blame] | 50 | |
[email protected] | 4648832 | 2012-10-30 03:22:20 | [diff] [blame] | 51 | WebContents* web_contents = shell()->web_contents(); |
[email protected] | 3bbacc5b | 2012-04-17 17:46:15 | [diff] [blame] | 52 | base::KillProcess(web_contents->GetRenderProcessHost()->GetHandle(), |
[email protected] | 4648832 | 2012-10-30 03:22:20 | [diff] [blame] | 53 | RESULT_CODE_KILLED, true); |
[email protected] | c2b6726 | 2009-05-19 23:32:26 | [diff] [blame] | 54 | |
[email protected] | 3bbacc5b | 2012-04-17 17:46:15 | [diff] [blame] | 55 | web_contents->GetController().Reload(true); |
[email protected] | c2b6726 | 2009-05-19 23:32:26 | [diff] [blame] | 56 | EXPECT_EQ( |
[email protected] | 3bbacc5b | 2012-04-17 17:46:15 | [diff] [blame] | 57 | 1U, |
| 58 | ChildProcessSecurityPolicyImpl::GetInstance()->security_state_.size()); |
[email protected] | c2b6726 | 2009-05-19 23:32:26 | [diff] [blame] | 59 | } |
[email protected] | 4648832 | 2012-10-30 03:22:20 | [diff] [blame] | 60 | |
| 61 | } // namespace content |