OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/common/sandbox_mac_unittest_helper.h" | 5 #include "chrome/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 "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
12 #include "chrome/common/sandbox_mac.h" | 12 #include "chrome/common/sandbox_mac.h" |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 const char* kSandboxTypeKey = "CHROMIUM_SANDBOX_SANDBOX_TYPE"; | 16 const char* kSandboxTypeKey = "CHROMIUM_SANDBOX_SANDBOX_TYPE"; |
17 const char* kSandboxTestNameKey = "CHROMIUM_SANDBOX_TEST_NAME"; | 17 const char* kSandboxTestNameKey = "CHROMIUM_SANDBOX_TEST_NAME"; |
18 const char* kTestDataKey = "CHROMIUM_SANDBOX_USER_DATA"; | 18 const char* kTestDataKey = "CHROMIUM_SANDBOX_USER_DATA"; |
19 | 19 |
20 } // namespace | 20 } // namespace |
21 | 21 |
22 namespace sandboxtest { | 22 namespace sandboxtest { |
23 | 23 |
24 // Support infrastructure for REGISTER_SANDBOX_TEST_CASE macro. | 24 // Support infrastructure for REGISTER_SANDBOX_TEST_CASE macro. |
25 namespace internal { | 25 namespace internal { |
26 | 26 |
| 27 typedef std::map<std::string,MacSandboxTestCase*> SandboxTestMap; |
| 28 |
| 29 // A function that returns a common map from string -> test case class. |
27 SandboxTestMap& GetSandboxTestMap() { | 30 SandboxTestMap& GetSandboxTestMap() { |
28 static SandboxTestMap test_map; | 31 static SandboxTestMap test_map; |
29 return test_map; | 32 return test_map; |
30 } | 33 } |
31 | 34 |
| 35 void AddSandboxTestCase(const char* test_name, MacSandboxTestCase* test_class) { |
| 36 SandboxTestMap& test_map = GetSandboxTestMap(); |
| 37 if (test_map.find(test_name) != test_map.end()) { |
| 38 LOG(ERROR) << "Trying to register duplicate test" << test_name; |
| 39 NOTREACHED(); |
| 40 } |
| 41 test_map[test_name] = test_class; |
| 42 } |
| 43 |
32 } // namespace internal | 44 } // namespace internal |
33 | 45 |
34 bool MacSandboxTest:: RunTestInAllSandboxTypes(const char* test_name, | 46 bool MacSandboxTest:: RunTestInAllSandboxTypes(const char* test_name, |
35 const char* test_data) { | 47 const char* test_data) { |
36 // Go through all the sandbox types, and run the test case in each of them | 48 // Go through all the sandbox types, and run the test case in each of them |
37 // if one fails, abort. | 49 // if one fails, abort. |
38 for(int i = static_cast<int>(sandbox::SANDBOX_TYPE_FIRST_TYPE); | 50 for(int i = static_cast<int>(sandbox::SANDBOX_TYPE_FIRST_TYPE); |
39 i < sandbox::SANDBOX_AFTER_TYPE_LAST_TYPE; | 51 i < sandbox::SANDBOX_AFTER_TYPE_LAST_TYPE; |
40 ++i) { | 52 ++i) { |
41 if (!RunTestInSandbox(static_cast<sandbox::SandboxProcessType>(i), | 53 if (!RunTestInSandbox(static_cast<sandbox::SandboxProcessType>(i), |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 144 |
133 if (!test_case->SandboxedTest()) { | 145 if (!test_case->SandboxedTest()) { |
134 LOG(ERROR) << sandbox_test_name << "Failed sandboxed test"; | 146 LOG(ERROR) << sandbox_test_name << "Failed sandboxed test"; |
135 return -1; | 147 return -1; |
136 } | 148 } |
137 | 149 |
138 return 0; | 150 return 0; |
139 } | 151 } |
140 | 152 |
141 } // namespace | 153 } // namespace |
OLD | NEW |