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

Side by Side Diff: chrome/test/security_tests/renderer_sandbox_tests_mac.mm

Issue 285283003: Remove flag --test-sandbox (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: changes requested by jln Created 6 years, 6 months 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
OLDNEW
(Empty)
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.
4
5 #import "content/public/common/injection_test_mac.h"
6
7 #import <Cocoa/Cocoa.h>
8
9
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
15 // to justify.
16
17 // Test case for checking sandboxing of clipboard access.
18 bool SandboxTestClipboardTestCase(void) {
19 return [NSPasteboard generalPasteboard] == nil;
20 }
21
22 // Test case for checking sandboxing of filesystem apis.
23 bool SandboxTestFileAccessTestCase(void) {
24 int fdes = open("/etc/passwd", O_RDONLY);
25 if (fdes == -1) {
26 return true;
27 } else {
28 close(fdes);
29 return false;
30 }
31 }
32
33 //--------------------- Test Execution ---------------------
34
35 static LogRendererSandboxTestMessage log_function = NULL;
36
37 static inline void LogInfoMessage(std::string message) {
38 log_function(message, false);
39 }
40
41 static inline void LogErrorMessage(std::string message) {
42 log_function(message, true);
43 }
44
45 @implementation RendererSandboxTestsRunner
46
47 + (void)setLogFunction:(LogRendererSandboxTestMessage)logFunction {
48 log_function = logFunction;
49 }
50
51 + (BOOL)runTests {
52 // A test case entry. One must exist for each test.
53 struct SandboxTestCase {
54 std::string name;
55 bool (*test_function)(void);
56 };
57 const struct SandboxTestCase sandbox_test_cases[] = {
58 #define DEFINE_TEST_CASE(testFunction) { #testFunction, testFunction }
59
60 // The list of registered tests
61 DEFINE_TEST_CASE(SandboxTestClipboardTestCase),
62 DEFINE_TEST_CASE(SandboxTestFileAccessTestCase),
63
64 #undef DEFINE_TEST_CASE
65 // Termination entry
66 { "", NULL }
67 };
68
69 // Execute the tests
70 BOOL tests_passed = YES;
71 for (const struct SandboxTestCase* test_case = sandbox_test_cases;
72 test_case->test_function != NULL;
73 ++test_case) {
74 LogInfoMessage("Running sandbox test: " + test_case->name);
75 if (test_case->test_function()) {
76 LogInfoMessage("Test: " + test_case->name + " - PASSED");
77 } else {
78 LogErrorMessage("Test: " + test_case->name + " - FAILED");
79 tests_passed = NO;
80 }
81 }
82 return tests_passed;
83 }
84
85 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698