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 #ifndef CHROME_COMMON_SANDBOX_MAC_UNITTEST_RUNNER_H_ | 5 #ifndef CHROME_COMMON_SANDBOX_MAC_UNITTEST_RUNNER_H_ |
6 #define CHROME_COMMON_SANDBOX_MAC_UNITTEST_RUNNER_H_ | 6 #define CHROME_COMMON_SANDBOX_MAC_UNITTEST_RUNNER_H_ |
7 | 7 |
8 #include "base/multiprocess_test.h" | 8 #include "base/multiprocess_test.h" |
9 #include "chrome/common/sandbox_mac.h" | 9 #include "chrome/common/sandbox_mac.h" |
10 | 10 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 // Returning false from this function will cause the entire test case to fail. | 74 // Returning false from this function will cause the entire test case to fail. |
75 virtual bool BeforeSandboxInit() { return true; }; | 75 virtual bool BeforeSandboxInit() { return true; }; |
76 | 76 |
77 // Code that runs in the sandboxed subprocess when the sandbox has been | 77 // Code that runs in the sandboxed subprocess when the sandbox has been |
78 // enabled. | 78 // enabled. |
79 // Returning false from this function will cause the entire test case to fail. | 79 // Returning false from this function will cause the entire test case to fail. |
80 virtual bool SandboxedTest() = 0; | 80 virtual bool SandboxedTest() = 0; |
81 | 81 |
82 // The data that's passed in the |user_data| parameter of | 82 // The data that's passed in the |user_data| parameter of |
83 // RunTest[s]InSandbox() is passed to this function. | 83 // RunTest[s]InSandbox() is passed to this function. |
84 virtual void SetTestData(const char* test_data) {} | 84 virtual void SetTestData(const char* test_data) { test_data_ = test_data; } |
| 85 |
| 86 protected: |
| 87 std::string test_data_; |
85 }; | 88 }; |
86 | 89 |
87 // Plumbing to support the REGISTER_SANDBOX_TEST_CASE macro. | 90 // Plumbing to support the REGISTER_SANDBOX_TEST_CASE macro. |
88 namespace internal { | 91 namespace internal { |
89 | 92 |
90 typedef std::map<std::string,MacSandboxTestCase*> SandboxTestMap; | 93 // Register a test case with a given name. |
91 | 94 void AddSandboxTestCase(const char* test_name, MacSandboxTestCase* test_class); |
92 // A function that returns a common map from string -> test case class. | |
93 SandboxTestMap& GetSandboxTestMap(); | |
94 | 95 |
95 // Construction of this class causes a new entry to be placed in a global | 96 // Construction of this class causes a new entry to be placed in a global |
96 // map. | 97 // map. |
97 template <class T> struct RegisterSandboxTest { | 98 template <class T> struct RegisterSandboxTest { |
98 RegisterSandboxTest(const char* test_name) { | 99 RegisterSandboxTest(const char* test_name) { |
99 GetSandboxTestMap()[test_name] = new T; | 100 AddSandboxTestCase(test_name, new T); |
100 } | 101 } |
101 }; | 102 }; |
102 | 103 |
103 #define REGISTER_SANDBOX_TEST_CASE(class_name) \ | 104 #define REGISTER_SANDBOX_TEST_CASE(class_name) \ |
104 namespace { \ | 105 namespace { \ |
105 sandboxtest::internal::RegisterSandboxTest<class_name> \ | 106 sandboxtest::internal::RegisterSandboxTest<class_name> \ |
106 register_test##class_name(#class_name); \ | 107 register_test##class_name(#class_name); \ |
107 } // namespace | 108 } // namespace |
108 | 109 |
109 } // namespace internal | 110 } // namespace internal |
110 | 111 |
111 } // namespace sandboxtest | 112 } // namespace sandboxtest |
112 | 113 |
113 #endif // CHROME_COMMON_SANDBOX_MAC_UNITTEST_RUNNER_H_ | 114 #endif // CHROME_COMMON_SANDBOX_MAC_UNITTEST_RUNNER_H_ |
OLD | NEW |