| 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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 #include <dirent.h> | 6 #include <dirent.h> |
| 7 | 7 |
| 8 extern "C" { | 8 extern "C" { |
| 9 #include <sandbox.h> | 9 #include <sandbox.h> |
| 10 } | 10 } |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 expected.append(kSandboxEscapeSuffix); | 126 expected.append(kSandboxEscapeSuffix); |
| 127 | 127 |
| 128 std::string out; | 128 std::string out; |
| 129 EXPECT_TRUE(Sandbox::QuoteStringForRegex(in_utf8, &out)); | 129 EXPECT_TRUE(Sandbox::QuoteStringForRegex(in_utf8, &out)); |
| 130 EXPECT_EQ(expected, out); | 130 EXPECT_EQ(expected, out); |
| 131 | 131 |
| 132 } | 132 } |
| 133 } | 133 } |
| 134 | 134 |
| 135 // A class to handle auto-deleting a directory. | 135 // A class to handle auto-deleting a directory. |
| 136 class ScopedDirectoryDelete { | 136 struct ScopedDirectoryDelete { |
| 137 public: | |
| 138 inline void operator()(base::FilePath* x) const { | 137 inline void operator()(base::FilePath* x) const { |
| 139 if (x) { | 138 if (x) |
| 140 base::DeleteFile(*x, true); | 139 base::DeleteFile(*x, true); |
| 141 } | |
| 142 } | 140 } |
| 143 }; | 141 }; |
| 144 | 142 |
| 145 typedef scoped_ptr_malloc<base::FilePath, ScopedDirectoryDelete> | 143 typedef scoped_ptr<base::FilePath, ScopedDirectoryDelete> ScopedDirectory; |
| 146 ScopedDirectory; | |
| 147 | 144 |
| 148 TEST_F(MacDirAccessSandboxTest, SandboxAccess) { | 145 TEST_F(MacDirAccessSandboxTest, SandboxAccess) { |
| 149 using base::CreateDirectory; | 146 using base::CreateDirectory; |
| 150 | 147 |
| 151 base::FilePath tmp_dir; | 148 base::FilePath tmp_dir; |
| 152 ASSERT_TRUE(base::CreateNewTempDirectory(base::FilePath::StringType(), | 149 ASSERT_TRUE(base::CreateNewTempDirectory(base::FilePath::StringType(), |
| 153 &tmp_dir)); | 150 &tmp_dir)); |
| 154 // This step is important on OS X since the sandbox only understands "real" | 151 // This step is important on OS X since the sandbox only understands "real" |
| 155 // paths and the paths CreateNewTempDirectory() returns are empirically in | 152 // paths and the paths CreateNewTempDirectory() returns are empirically in |
| 156 // /var which is a symlink to /private/var . | 153 // /var which is a symlink to /private/var . |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 PLOG(ERROR) << "Sandbox breach: was able to write (" | 301 PLOG(ERROR) << "Sandbox breach: was able to write (" |
| 305 << denied_file2.value() | 302 << denied_file2.value() |
| 306 << ")"; | 303 << ")"; |
| 307 return -1; | 304 return -1; |
| 308 } | 305 } |
| 309 | 306 |
| 310 return 0; | 307 return 0; |
| 311 } | 308 } |
| 312 | 309 |
| 313 } // namespace content | 310 } // namespace content |
| OLD | NEW |