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
3 // found in the LICENSE file.
5 #import "content/public/common/injection_test_mac.h"
7 #import <Cocoa/Cocoa.h>
10 //--------------------- Sandbox Tests ---------------------
11 // Below is a list of test functions that check the renderer sandbox.
12 // In order for a test function to be executed, it must be added to the
13 // |sandbox_test_cases| array in +[RendererSandboxTestsRunner runTests] below.
14 // TODO(ofri): Consider moving these to another file once there are enough tests
17 // Test case for checking sandboxing of clipboard access.
18 bool SandboxTestClipboardTestCase(void) {
19 return [NSPasteboard generalPasteboard] == nil;
22 // Test case for checking sandboxing of filesystem apis.
23 bool SandboxTestFileAccessTestCase(void) {
24 int fdes = open("/etc/passwd", O_RDONLY);
33 //--------------------- Test Execution ---------------------
35 static LogRendererSandboxTestMessage log_function = NULL;
37 static inline void LogInfoMessage(std::string message) {
38 log_function(message, false);
41 static inline void LogErrorMessage(std::string message) {
42 log_function(message, true);
45 @implementation RendererSandboxTestsRunner
47 + (void)setLogFunction:(LogRendererSandboxTestMessage)logFunction {
48 log_function = logFunction;
52 // A test case entry. One must exist for each test.
53 struct SandboxTestCase {
55 bool (*test_function)(void);
57 const struct SandboxTestCase sandbox_test_cases[] = {
58 #define DEFINE_TEST_CASE(testFunction) { #testFunction, testFunction }
60 // The list of registered tests
61 DEFINE_TEST_CASE(SandboxTestClipboardTestCase),
62 DEFINE_TEST_CASE(SandboxTestFileAccessTestCase),
64 #undef DEFINE_TEST_CASE
70 BOOL tests_passed = YES;
71 for (const struct SandboxTestCase* test_case = sandbox_test_cases;
72 test_case->test_function != NULL;
74 LogInfoMessage("Running sandbox test: " + test_case->name);
75 if (test_case->test_function()) {
76 LogInfoMessage("Test: " + test_case->name + " - PASSED");
78 LogErrorMessage("Test: " + test_case->name + " - FAILED");