Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: content/common/sandbox_mac_unittest_helper.mm

Issue 8589001: Load mac sandbox definitions from resources instead of the bundle. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/common/sandbox_mac_unittest_helper.h" 5 #include "content/common/sandbox_mac_unittest_helper.h"
6 6
7 extern "C" { 7 extern "C" {
8 #include <sandbox.h> 8 #include <sandbox.h>
9 } 9 }
10 10
11 #include <map> 11 #include <map>
12 12
13 #include "base/file_path.h" 13 #include "base/file_path.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "content/common/sandbox_mac.h" 16 #include "content/common/sandbox_mac.h"
17 #include "content/test/test_content_client.h"
17 #include "testing/multiprocess_func_list.h" 18 #include "testing/multiprocess_func_list.h"
18 19
19 using sandbox::Sandbox; 20 using sandbox::Sandbox;
20 21
21 namespace { 22 namespace {
22 23
23 const char* kSandboxTypeKey = "CHROMIUM_SANDBOX_SANDBOX_TYPE"; 24 const char* kSandboxTypeKey = "CHROMIUM_SANDBOX_SANDBOX_TYPE";
24 const char* kSandboxTestNameKey = "CHROMIUM_SANDBOX_TEST_NAME"; 25 const char* kSandboxTestNameKey = "CHROMIUM_SANDBOX_TEST_NAME";
25 const char* kTestDataKey = "CHROMIUM_SANDBOX_USER_DATA"; 26 const char* kTestDataKey = "CHROMIUM_SANDBOX_USER_DATA";
26 27
(...skipping 20 matching lines...) Expand all
47 } 48 }
48 test_map[test_name] = test_class; 49 test_map[test_name] = test_class;
49 } 50 }
50 51
51 } // namespace internal 52 } // namespace internal
52 53
53 bool MacSandboxTest::RunTestInAllSandboxTypes(const char* test_name, 54 bool MacSandboxTest::RunTestInAllSandboxTypes(const char* test_name,
54 const char* test_data) { 55 const char* test_data) {
55 // Go through all the sandbox types, and run the test case in each of them 56 // Go through all the sandbox types, and run the test case in each of them
56 // if one fails, abort. 57 // if one fails, abort.
57 for(int i = static_cast<int>(Sandbox::SANDBOX_TYPE_FIRST_TYPE); 58 for(int i = static_cast<int>(content::SANDBOX_TYPE_FIRST_TYPE);
58 i < Sandbox::SANDBOX_AFTER_TYPE_LAST_TYPE; 59 i < content::SANDBOX_TYPE_AFTER_LAST_TYPE;
59 ++i) { 60 ++i) {
60 61
61 if (!RunTestInSandbox(static_cast<Sandbox::SandboxProcessType>(i), 62 if (!RunTestInSandbox(static_cast<content::SandboxProcessType>(i),
62 test_name, test_data)) { 63 test_name, test_data)) {
63 LOG(ERROR) << "Sandboxed test (" << test_name << ")" << 64 LOG(ERROR) << "Sandboxed test (" << test_name << ")" <<
64 "Failed in sandbox type " << i << 65 "Failed in sandbox type " << i <<
65 "user data: (" << test_data << ")"; 66 "user data: (" << test_data << ")";
66 return false; 67 return false;
67 } 68 }
68 } 69 }
69 return true; 70 return true;
70 } 71 }
71 72
72 bool MacSandboxTest::RunTestInSandbox(Sandbox::SandboxProcessType sandbox_type, 73 bool MacSandboxTest::RunTestInSandbox(content::SandboxProcessType sandbox_type,
73 const char* test_name, 74 const char* test_name,
74 const char* test_data) { 75 const char* test_data) {
75 std::stringstream s; 76 std::stringstream s;
76 s << static_cast<int>(static_cast<int>(sandbox_type)); 77 s << static_cast<int>(static_cast<int>(sandbox_type));
77 setenv(kSandboxTypeKey, s.str().c_str(), 1); 78 setenv(kSandboxTypeKey, s.str().c_str(), 1);
78 setenv(kSandboxTestNameKey, test_name, 1); 79 setenv(kSandboxTestNameKey, test_name, 1);
79 if (test_data) 80 if (test_data)
80 setenv(kTestDataKey, test_data, 1); 81 setenv(kTestDataKey, test_data, 1);
81 82
82 base::ProcessHandle child_process = SpawnChild("mac_sandbox_test_runner", 83 base::ProcessHandle child_process = SpawnChild("mac_sandbox_test_runner",
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 return it->second; 119 return it->second;
119 } 120 }
120 121
121 } // namespace sandboxtest 122 } // namespace sandboxtest
122 123
123 namespace { 124 namespace {
124 125
125 // Main function for driver process that enables the sandbox and runs test 126 // Main function for driver process that enables the sandbox and runs test
126 // code. 127 // code.
127 MULTIPROCESS_TEST_MAIN(mac_sandbox_test_runner) { 128 MULTIPROCESS_TEST_MAIN(mac_sandbox_test_runner) {
129 TestContentClient content_client;
130 content::SetContentClient(&content_client);
128 // Extract parameters. 131 // Extract parameters.
129 char* sandbox_type_str = getenv(kSandboxTypeKey); 132 char* sandbox_type_str = getenv(kSandboxTypeKey);
130 if (!sandbox_type_str) { 133 if (!sandbox_type_str) {
131 LOG(ERROR) << "Sandbox type not specified"; 134 LOG(ERROR) << "Sandbox type not specified";
132 return -1; 135 return -1;
133 } 136 }
134 Sandbox::SandboxProcessType sandbox_type = 137 content::SandboxProcessType sandbox_type =
135 static_cast<Sandbox::SandboxProcessType>(atoi(sandbox_type_str)); 138 static_cast<content::SandboxProcessType>(atoi(sandbox_type_str));
136 char* sandbox_test_name = getenv(kSandboxTestNameKey); 139 char* sandbox_test_name = getenv(kSandboxTestNameKey);
137 if (!sandbox_test_name) { 140 if (!sandbox_test_name) {
138 LOG(ERROR) << "Sandbox test name not specified"; 141 LOG(ERROR) << "Sandbox test name not specified";
139 return -1; 142 return -1;
140 } 143 }
141 144
142 const char* test_data = getenv(kTestDataKey); 145 const char* test_data = getenv(kTestDataKey);
143 146
144 // Find Test Function to run; 147 // Find Test Function to run;
145 scoped_ptr<sandboxtest::MacSandboxTestCase> 148 scoped_ptr<sandboxtest::MacSandboxTestCase>
(...skipping 20 matching lines...) Expand all
166 169
167 if (!test_case->SandboxedTest()) { 170 if (!test_case->SandboxedTest()) {
168 LOG(ERROR) << sandbox_test_name << "Failed sandboxed test"; 171 LOG(ERROR) << sandbox_test_name << "Failed sandboxed test";
169 return -1; 172 return -1;
170 } 173 }
171 174
172 return 0; 175 return 0;
173 } 176 }
174 177
175 } // namespace 178 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698