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

Side by Side Diff: base/mac/mac_util_unittest.mm

Issue 2275553005: //base: Make ScopedTempDir::path() a GetPath() with a DCHECK (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments Created 4 years, 3 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
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 <stddef.h> 6 #include <stddef.h>
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/mac/mac_util.h" 9 #include "base/mac/mac_util.h"
10 10
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 EXPECT_STREQ(valid_inputs[i].expected_out, 101 EXPECT_STREQ(valid_inputs[i].expected_out,
102 out.value().c_str()) << "loop: " << i; 102 out.value().c_str()) << "loop: " << i;
103 } 103 }
104 } 104 }
105 105
106 // http://crbug.com/425745 106 // http://crbug.com/425745
107 TEST_F(MacUtilTest, DISABLED_TestExcludeFileFromBackups) { 107 TEST_F(MacUtilTest, DISABLED_TestExcludeFileFromBackups) {
108 // The file must already exist in order to set its exclusion property. 108 // The file must already exist in order to set its exclusion property.
109 ScopedTempDir temp_dir_; 109 ScopedTempDir temp_dir_;
110 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 110 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
111 FilePath dummy_file_path = temp_dir_.path().Append("DummyFile"); 111 FilePath dummy_file_path = temp_dir_.GetPath().Append("DummyFile");
112 const char dummy_data[] = "All your base are belong to us!"; 112 const char dummy_data[] = "All your base are belong to us!";
113 // Dump something real into the file. 113 // Dump something real into the file.
114 ASSERT_EQ(static_cast<int>(arraysize(dummy_data)), 114 ASSERT_EQ(static_cast<int>(arraysize(dummy_data)),
115 WriteFile(dummy_file_path, dummy_data, arraysize(dummy_data))); 115 WriteFile(dummy_file_path, dummy_data, arraysize(dummy_data)));
116 NSString* fileURLString = 116 NSString* fileURLString =
117 [NSString stringWithUTF8String:dummy_file_path.value().c_str()]; 117 [NSString stringWithUTF8String:dummy_file_path.value().c_str()];
118 NSURL* fileURL = [NSURL URLWithString:fileURLString]; 118 NSURL* fileURL = [NSURL URLWithString:fileURLString];
119 // Initial state should be non-excluded. 119 // Initial state should be non-excluded.
120 EXPECT_FALSE(CSBackupIsItemExcluded(base::mac::NSToCFCast(fileURL), NULL)); 120 EXPECT_FALSE(CSBackupIsItemExcluded(base::mac::NSToCFCast(fileURL), NULL));
121 // Exclude the file. 121 // Exclude the file.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 228
229 EXPECT_TRUE(ParseModelIdentifier("MacBookPro6,2", &model, &major, &minor)); 229 EXPECT_TRUE(ParseModelIdentifier("MacBookPro6,2", &model, &major, &minor));
230 EXPECT_EQ(model, "MacBookPro"); 230 EXPECT_EQ(model, "MacBookPro");
231 EXPECT_EQ(6, major); 231 EXPECT_EQ(6, major);
232 EXPECT_EQ(2, minor); 232 EXPECT_EQ(2, minor);
233 } 233 }
234 234
235 TEST_F(MacUtilTest, TestRemoveQuarantineAttribute) { 235 TEST_F(MacUtilTest, TestRemoveQuarantineAttribute) {
236 ScopedTempDir temp_dir_; 236 ScopedTempDir temp_dir_;
237 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 237 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
238 FilePath dummy_folder_path = temp_dir_.path().Append("DummyFolder"); 238 FilePath dummy_folder_path = temp_dir_.GetPath().Append("DummyFolder");
239 ASSERT_TRUE(base::CreateDirectory(dummy_folder_path)); 239 ASSERT_TRUE(base::CreateDirectory(dummy_folder_path));
240 const char* quarantine_str = "0000;4b392bb2;Chromium;|org.chromium.Chromium"; 240 const char* quarantine_str = "0000;4b392bb2;Chromium;|org.chromium.Chromium";
241 const char* file_path_str = dummy_folder_path.value().c_str(); 241 const char* file_path_str = dummy_folder_path.value().c_str();
242 EXPECT_EQ(0, setxattr(file_path_str, "com.apple.quarantine", 242 EXPECT_EQ(0, setxattr(file_path_str, "com.apple.quarantine",
243 quarantine_str, strlen(quarantine_str), 0, 0)); 243 quarantine_str, strlen(quarantine_str), 0, 0));
244 EXPECT_EQ(static_cast<long>(strlen(quarantine_str)), 244 EXPECT_EQ(static_cast<long>(strlen(quarantine_str)),
245 getxattr(file_path_str, "com.apple.quarantine", 245 getxattr(file_path_str, "com.apple.quarantine",
246 NULL, 0, 0, 0)); 246 NULL, 0, 0, 0));
247 EXPECT_TRUE(RemoveQuarantineAttribute(dummy_folder_path)); 247 EXPECT_TRUE(RemoveQuarantineAttribute(dummy_folder_path));
248 EXPECT_EQ(-1, getxattr(file_path_str, "com.apple.quarantine", NULL, 0, 0, 0)); 248 EXPECT_EQ(-1, getxattr(file_path_str, "com.apple.quarantine", NULL, 0, 0, 0));
249 EXPECT_EQ(ENOATTR, errno); 249 EXPECT_EQ(ENOATTR, errno);
250 } 250 }
251 251
252 TEST_F(MacUtilTest, TestRemoveQuarantineAttributeTwice) { 252 TEST_F(MacUtilTest, TestRemoveQuarantineAttributeTwice) {
253 ScopedTempDir temp_dir_; 253 ScopedTempDir temp_dir_;
254 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 254 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
255 FilePath dummy_folder_path = temp_dir_.path().Append("DummyFolder"); 255 FilePath dummy_folder_path = temp_dir_.GetPath().Append("DummyFolder");
256 const char* file_path_str = dummy_folder_path.value().c_str(); 256 const char* file_path_str = dummy_folder_path.value().c_str();
257 ASSERT_TRUE(base::CreateDirectory(dummy_folder_path)); 257 ASSERT_TRUE(base::CreateDirectory(dummy_folder_path));
258 EXPECT_EQ(-1, getxattr(file_path_str, "com.apple.quarantine", NULL, 0, 0, 0)); 258 EXPECT_EQ(-1, getxattr(file_path_str, "com.apple.quarantine", NULL, 0, 0, 0));
259 // No quarantine attribute to begin with, but RemoveQuarantineAttribute still 259 // No quarantine attribute to begin with, but RemoveQuarantineAttribute still
260 // succeeds because in the end the folder still doesn't have the quarantine 260 // succeeds because in the end the folder still doesn't have the quarantine
261 // attribute set. 261 // attribute set.
262 EXPECT_TRUE(RemoveQuarantineAttribute(dummy_folder_path)); 262 EXPECT_TRUE(RemoveQuarantineAttribute(dummy_folder_path));
263 EXPECT_TRUE(RemoveQuarantineAttribute(dummy_folder_path)); 263 EXPECT_TRUE(RemoveQuarantineAttribute(dummy_folder_path));
264 EXPECT_EQ(ENOATTR, errno); 264 EXPECT_EQ(ENOATTR, errno);
265 } 265 }
266 266
267 TEST_F(MacUtilTest, TestRemoveQuarantineAttributeNonExistentPath) { 267 TEST_F(MacUtilTest, TestRemoveQuarantineAttributeNonExistentPath) {
268 ScopedTempDir temp_dir_; 268 ScopedTempDir temp_dir_;
269 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 269 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
270 FilePath non_existent_path = temp_dir_.path().Append("DummyPath"); 270 FilePath non_existent_path = temp_dir_.GetPath().Append("DummyPath");
271 ASSERT_FALSE(PathExists(non_existent_path)); 271 ASSERT_FALSE(PathExists(non_existent_path));
272 EXPECT_FALSE(RemoveQuarantineAttribute(non_existent_path)); 272 EXPECT_FALSE(RemoveQuarantineAttribute(non_existent_path));
273 } 273 }
274 274
275 } // namespace 275 } // namespace
276 276
277 } // namespace mac 277 } // namespace mac
278 } // namespace base 278 } // namespace base
OLDNEW
« no previous file with comments | « base/json/json_value_serializer_unittest.cc ('k') | base/metrics/persistent_histogram_allocator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698