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

Side by Side Diff: content/common/sandbox_mac_system_access_unittest.mm

Issue 12279015: Mac Chromium style checker cleanup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
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 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/sys_string_conversions.h" 9 #include "base/sys_string_conversions.h"
10 #include "content/common/sandbox_mac.h" 10 #include "content/common/sandbox_mac.h"
11 #include "content/common/sandbox_mac_unittest_helper.h" 11 #include "content/common/sandbox_mac_unittest_helper.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace content { 14 namespace content {
15 15
16 //--------------------- Clipboard Sandboxing ---------------------- 16 //--------------------- Clipboard Sandboxing ----------------------
17 // Test case for checking sandboxing of clipboard access. 17 // Test case for checking sandboxing of clipboard access.
18 class MacSandboxedClipboardTestCase : public MacSandboxTestCase { 18 class MacSandboxedClipboardTestCase : public MacSandboxTestCase {
19 public: 19 public:
20 MacSandboxedClipboardTestCase(); 20 MacSandboxedClipboardTestCase();
21 virtual ~MacSandboxedClipboardTestCase(); 21 virtual ~MacSandboxedClipboardTestCase();
22 22
23 virtual bool SandboxedTest(); 23 virtual bool SandboxedTest() OVERRIDE;
24 24
25 virtual void SetTestData(const char* test_data); 25 virtual void SetTestData(const char* test_data) OVERRIDE;
26 private: 26 private:
27 NSString* clipboard_name_; 27 NSString* clipboard_name_;
28 }; 28 };
29 29
30 REGISTER_SANDBOX_TEST_CASE(MacSandboxedClipboardTestCase); 30 REGISTER_SANDBOX_TEST_CASE(MacSandboxedClipboardTestCase);
31 31
32 MacSandboxedClipboardTestCase::MacSandboxedClipboardTestCase() : 32 MacSandboxedClipboardTestCase::MacSandboxedClipboardTestCase() :
33 clipboard_name_(nil) {} 33 clipboard_name_(nil) {}
34 34
35 MacSandboxedClipboardTestCase::~MacSandboxedClipboardTestCase() { 35 MacSandboxedClipboardTestCase::~MacSandboxedClipboardTestCase() {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 pasteboard_name.c_str())); 72 pasteboard_name.c_str()));
73 73
74 // After executing the test, the clipboard should still be empty. 74 // After executing the test, the clipboard should still be empty.
75 EXPECT_EQ([[pb types] count], 0U); 75 EXPECT_EQ([[pb types] count], 0U);
76 } 76 }
77 77
78 //--------------------- File Access Sandboxing ---------------------- 78 //--------------------- File Access Sandboxing ----------------------
79 // Test case for checking sandboxing of filesystem apis. 79 // Test case for checking sandboxing of filesystem apis.
80 class MacSandboxedFileAccessTestCase : public MacSandboxTestCase { 80 class MacSandboxedFileAccessTestCase : public MacSandboxTestCase {
81 public: 81 public:
82 virtual bool SandboxedTest(); 82 virtual bool SandboxedTest() OVERRIDE;
83 }; 83 };
84 84
85 REGISTER_SANDBOX_TEST_CASE(MacSandboxedFileAccessTestCase); 85 REGISTER_SANDBOX_TEST_CASE(MacSandboxedFileAccessTestCase);
86 86
87 bool MacSandboxedFileAccessTestCase::SandboxedTest() { 87 bool MacSandboxedFileAccessTestCase::SandboxedTest() {
88 int fdes = open("/etc/passwd", O_RDONLY); 88 int fdes = open("/etc/passwd", O_RDONLY);
89 file_util::ScopedFD file_closer(&fdes); 89 file_util::ScopedFD file_closer(&fdes);
90 return fdes == -1; 90 return fdes == -1;
91 } 91 }
92 92
93 TEST_F(MacSandboxTest, FileAccess) { 93 TEST_F(MacSandboxTest, FileAccess) {
94 EXPECT_TRUE(RunTestInAllSandboxTypes("MacSandboxedFileAccessTestCase", NULL)); 94 EXPECT_TRUE(RunTestInAllSandboxTypes("MacSandboxedFileAccessTestCase", NULL));
95 } 95 }
96 96
97 //--------------------- /dev/urandom Sandboxing ---------------------- 97 //--------------------- /dev/urandom Sandboxing ----------------------
98 // /dev/urandom is available to ppapi sandbox only. 98 // /dev/urandom is available to ppapi sandbox only.
99 class MacSandboxedUrandomTestCase : public MacSandboxTestCase { 99 class MacSandboxedUrandomTestCase : public MacSandboxTestCase {
100 public: 100 public:
101 virtual bool SandboxedTest(); 101 virtual bool SandboxedTest() OVERRIDE;
102 }; 102 };
103 103
104 REGISTER_SANDBOX_TEST_CASE(MacSandboxedUrandomTestCase); 104 REGISTER_SANDBOX_TEST_CASE(MacSandboxedUrandomTestCase);
105 105
106 bool MacSandboxedUrandomTestCase::SandboxedTest() { 106 bool MacSandboxedUrandomTestCase::SandboxedTest() {
107 int fdes = open("/dev/urandom", O_RDONLY); 107 int fdes = open("/dev/urandom", O_RDONLY);
108 file_util::ScopedFD file_closer(&fdes); 108 file_util::ScopedFD file_closer(&fdes);
109 109
110 // Open succeeds under ppapi sandbox, else it is not permitted. 110 // Open succeeds under ppapi sandbox, else it is not permitted.
111 if (test_data_ == "ppapi") { 111 if (test_data_ == "ppapi") {
(...skipping 17 matching lines...) Expand all
129 if (i == SANDBOX_TYPE_PPAPI) { 129 if (i == SANDBOX_TYPE_PPAPI) {
130 EXPECT_TRUE(RunTestInSandbox(i, "MacSandboxedUrandomTestCase", "ppapi")); 130 EXPECT_TRUE(RunTestInSandbox(i, "MacSandboxedUrandomTestCase", "ppapi"));
131 } else { 131 } else {
132 EXPECT_TRUE(RunTestInSandbox(i, "MacSandboxedUrandomTestCase", "")) 132 EXPECT_TRUE(RunTestInSandbox(i, "MacSandboxedUrandomTestCase", ""))
133 << "for sandbox type " << i; 133 << "for sandbox type " << i;
134 } 134 }
135 } 135 }
136 } 136 }
137 137
138 } // namespace content 138 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698