| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CONTENT_COMMON_SANDBOX_MAC_UNITTEST_HELPER_H_ | 5 #ifndef CONTENT_COMMON_SANDBOX_MAC_UNITTEST_HELPER_H_ |
| 6 #define CONTENT_COMMON_SANDBOX_MAC_UNITTEST_HELPER_H_ | 6 #define CONTENT_COMMON_SANDBOX_MAC_UNITTEST_HELPER_H_ |
| 7 | 7 |
| 8 #include "base/test/multiprocess_test.h" | 8 #include "base/test/multiprocess_test.h" |
| 9 #include "content/common/sandbox_mac.h" | 9 #include "content/common/sandbox_mac.h" |
| 10 | 10 |
| 11 namespace sandboxtest { | 11 namespace content { |
| 12 | 12 |
| 13 // Helpers for writing unit tests that runs in the context of the Mac sandbox. | 13 // Helpers for writing unit tests that runs in the context of the Mac sandbox. |
| 14 // | 14 // |
| 15 // How to write a sandboxed test: | 15 // How to write a sandboxed test: |
| 16 // 1. Create a class that inherits from MacSandboxTestCase and overrides | 16 // 1. Create a class that inherits from MacSandboxTestCase and overrides |
| 17 // its functions to run code before or after the sandbox is initialised in a | 17 // its functions to run code before or after the sandbox is initialised in a |
| 18 // subprocess. | 18 // subprocess. |
| 19 // 2. Register the class you just created with the REGISTER_SANDBOX_TEST_CASE() | 19 // 2. Register the class you just created with the REGISTER_SANDBOX_TEST_CASE() |
| 20 // macro. | 20 // macro. |
| 21 // 3. Write a test [using TEST_F()] that inherits from MacSandboxTest and call | 21 // 3. Write a test [using TEST_F()] that inherits from MacSandboxTest and call |
| 22 // one of its helper functions to launch the test. | 22 // one of its helper functions to launch the test. |
| 23 // | 23 // |
| 24 // Example: | 24 // Example: |
| 25 // class TestCaseThatRunsInSandboxedSubprocess : | 25 // class TestCaseThatRunsInSandboxedSubprocess : public MacSandboxTestCase { |
| 26 // public sandboxtest::MacSandboxTestCase { | |
| 27 // public: | 26 // public: |
| 28 // virtual bool SandboxedTest() { | 27 // virtual bool SandboxedTest() { |
| 29 // .. test code that runs in sandbox goes here .. | 28 // .. test code that runs in sandbox goes here .. |
| 30 // return true; // always succeed. | 29 // return true; // always succeed. |
| 31 // } | 30 // } |
| 32 // }; | 31 // }; |
| 33 // | 32 // |
| 34 // // Register the test case you just created. | 33 // // Register the test case you just created. |
| 35 // REGISTER_SANDBOX_TEST_CASE(TestCaseThatRunsInSandboxedSubprocess); | 34 // REGISTER_SANDBOX_TEST_CASE(TestCaseThatRunsInSandboxedSubprocess); |
| 36 // | 35 // |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 // Construction of this class causes a new entry to be placed in a global | 102 // Construction of this class causes a new entry to be placed in a global |
| 104 // map. | 103 // map. |
| 105 template <class T> struct RegisterSandboxTest { | 104 template <class T> struct RegisterSandboxTest { |
| 106 RegisterSandboxTest(const char* test_name) { | 105 RegisterSandboxTest(const char* test_name) { |
| 107 AddSandboxTestCase(test_name, new T); | 106 AddSandboxTestCase(test_name, new T); |
| 108 } | 107 } |
| 109 }; | 108 }; |
| 110 | 109 |
| 111 #define REGISTER_SANDBOX_TEST_CASE(class_name) \ | 110 #define REGISTER_SANDBOX_TEST_CASE(class_name) \ |
| 112 namespace { \ | 111 namespace { \ |
| 113 sandboxtest::internal::RegisterSandboxTest<class_name> \ | 112 content::internal::RegisterSandboxTest<class_name> \ |
| 114 register_test##class_name(#class_name); \ | 113 register_test##class_name(#class_name); \ |
| 115 } // namespace | 114 } // namespace |
| 116 | 115 |
| 117 } // namespace internal | 116 } // namespace internal |
| 118 | 117 |
| 119 } // namespace sandboxtest | 118 } // namespace content |
| 120 | 119 |
| 121 #endif // CONTENT_COMMON_SANDBOX_MAC_UNITTEST_HELPER_H_ | 120 #endif // CONTENT_COMMON_SANDBOX_MAC_UNITTEST_HELPER_H_ |
| OLD | NEW |