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 | 6 |
7 #include "base/mac/mac_util.h" | 7 #include "base/mac/mac_util.h" |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 EXPECT_TRUE(ParseModelIdentifier("MacBookPro6,2", &model, &major, &minor)); | 213 EXPECT_TRUE(ParseModelIdentifier("MacBookPro6,2", &model, &major, &minor)); |
214 EXPECT_EQ(model, "MacBookPro"); | 214 EXPECT_EQ(model, "MacBookPro"); |
215 EXPECT_EQ(6, major); | 215 EXPECT_EQ(6, major); |
216 EXPECT_EQ(2, minor); | 216 EXPECT_EQ(2, minor); |
217 } | 217 } |
218 | 218 |
219 TEST_F(MacUtilTest, TestRemoveQuarantineAttribute) { | 219 TEST_F(MacUtilTest, TestRemoveQuarantineAttribute) { |
220 ScopedTempDir temp_dir_; | 220 ScopedTempDir temp_dir_; |
221 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 221 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
222 FilePath dummy_folder_path = temp_dir_.path().Append("DummyFolder"); | 222 FilePath dummy_folder_path = temp_dir_.path().Append("DummyFolder"); |
223 ASSERT_TRUE(file_util::CreateDirectory(dummy_folder_path)); | 223 ASSERT_TRUE(base::CreateDirectory(dummy_folder_path)); |
224 const char* quarantine_str = "0000;4b392bb2;Chromium;|org.chromium.Chromium"; | 224 const char* quarantine_str = "0000;4b392bb2;Chromium;|org.chromium.Chromium"; |
225 const char* file_path_str = dummy_folder_path.value().c_str(); | 225 const char* file_path_str = dummy_folder_path.value().c_str(); |
226 EXPECT_EQ(0, setxattr(file_path_str, "com.apple.quarantine", | 226 EXPECT_EQ(0, setxattr(file_path_str, "com.apple.quarantine", |
227 quarantine_str, strlen(quarantine_str), 0, 0)); | 227 quarantine_str, strlen(quarantine_str), 0, 0)); |
228 EXPECT_EQ(static_cast<long>(strlen(quarantine_str)), | 228 EXPECT_EQ(static_cast<long>(strlen(quarantine_str)), |
229 getxattr(file_path_str, "com.apple.quarantine", | 229 getxattr(file_path_str, "com.apple.quarantine", |
230 NULL, 0, 0, 0)); | 230 NULL, 0, 0, 0)); |
231 EXPECT_TRUE(RemoveQuarantineAttribute(dummy_folder_path)); | 231 EXPECT_TRUE(RemoveQuarantineAttribute(dummy_folder_path)); |
232 EXPECT_EQ(-1, getxattr(file_path_str, "com.apple.quarantine", NULL, 0, 0, 0)); | 232 EXPECT_EQ(-1, getxattr(file_path_str, "com.apple.quarantine", NULL, 0, 0, 0)); |
233 EXPECT_EQ(ENOATTR, errno); | 233 EXPECT_EQ(ENOATTR, errno); |
234 } | 234 } |
235 | 235 |
236 TEST_F(MacUtilTest, TestRemoveQuarantineAttributeTwice) { | 236 TEST_F(MacUtilTest, TestRemoveQuarantineAttributeTwice) { |
237 ScopedTempDir temp_dir_; | 237 ScopedTempDir temp_dir_; |
238 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 238 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
239 FilePath dummy_folder_path = temp_dir_.path().Append("DummyFolder"); | 239 FilePath dummy_folder_path = temp_dir_.path().Append("DummyFolder"); |
240 const char* file_path_str = dummy_folder_path.value().c_str(); | 240 const char* file_path_str = dummy_folder_path.value().c_str(); |
241 ASSERT_TRUE(file_util::CreateDirectory(dummy_folder_path)); | 241 ASSERT_TRUE(base::CreateDirectory(dummy_folder_path)); |
242 EXPECT_EQ(-1, getxattr(file_path_str, "com.apple.quarantine", NULL, 0, 0, 0)); | 242 EXPECT_EQ(-1, getxattr(file_path_str, "com.apple.quarantine", NULL, 0, 0, 0)); |
243 // No quarantine attribute to begin with, but RemoveQuarantineAttribute still | 243 // No quarantine attribute to begin with, but RemoveQuarantineAttribute still |
244 // succeeds because in the end the folder still doesn't have the quarantine | 244 // succeeds because in the end the folder still doesn't have the quarantine |
245 // attribute set. | 245 // attribute set. |
246 EXPECT_TRUE(RemoveQuarantineAttribute(dummy_folder_path)); | 246 EXPECT_TRUE(RemoveQuarantineAttribute(dummy_folder_path)); |
247 EXPECT_TRUE(RemoveQuarantineAttribute(dummy_folder_path)); | 247 EXPECT_TRUE(RemoveQuarantineAttribute(dummy_folder_path)); |
248 EXPECT_EQ(ENOATTR, errno); | 248 EXPECT_EQ(ENOATTR, errno); |
249 } | 249 } |
250 | 250 |
251 TEST_F(MacUtilTest, TestRemoveQuarantineAttributeNonExistentPath) { | 251 TEST_F(MacUtilTest, TestRemoveQuarantineAttributeNonExistentPath) { |
252 ScopedTempDir temp_dir_; | 252 ScopedTempDir temp_dir_; |
253 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 253 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
254 FilePath non_existent_path = temp_dir_.path().Append("DummyPath"); | 254 FilePath non_existent_path = temp_dir_.path().Append("DummyPath"); |
255 ASSERT_FALSE(PathExists(non_existent_path)); | 255 ASSERT_FALSE(PathExists(non_existent_path)); |
256 EXPECT_FALSE(RemoveQuarantineAttribute(non_existent_path)); | 256 EXPECT_FALSE(RemoveQuarantineAttribute(non_existent_path)); |
257 } | 257 } |
258 | 258 |
259 } // namespace | 259 } // namespace |
260 | 260 |
261 } // namespace mac | 261 } // namespace mac |
262 } // namespace base | 262 } // namespace base |
OLD | NEW |