Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 }; | 88 }; |
| 89 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(valid_inputs); i++) { | 89 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(valid_inputs); i++) { |
| 90 out = GetAppBundlePath(FilePath(valid_inputs[i].in)); | 90 out = GetAppBundlePath(FilePath(valid_inputs[i].in)); |
| 91 EXPECT_FALSE(out.empty()) << "loop: " << i; | 91 EXPECT_FALSE(out.empty()) << "loop: " << i; |
| 92 EXPECT_STREQ(valid_inputs[i].expected_out, | 92 EXPECT_STREQ(valid_inputs[i].expected_out, |
| 93 out.value().c_str()) << "loop: " << i; | 93 out.value().c_str()) << "loop: " << i; |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 TEST_F(MacUtilTest, TestExcludeFileFromBackups) { | 97 TEST_F(MacUtilTest, TestExcludeFileFromBackups) { |
| 98 NSString* homeDirectory = NSHomeDirectory(); | 98 FilePath temp_dir; |
| 99 NSString* dummyFilePath = | 99 ASSERT_TRUE(file_util::CreateNewTempDirectory(FilePath::StringType(), |
| 100 [homeDirectory stringByAppendingPathComponent:@"DummyFile"]; | 100 &temp_dir)); |
|
Mark Mentovai
2011/05/25 19:19:06
Who’s responsible for cleaning up temp_dir? Maybe
mrossetti
2011/05/25 21:12:31
Done.
| |
| 101 const char* dummy_file_path = [dummyFilePath fileSystemRepresentation]; | 101 EXPECT_TRUE(file_util::PathExists(temp_dir)); |
| 102 ASSERT_TRUE(dummy_file_path); | 102 FilePath dummy_file_path = temp_dir.Append("DummyFile"); |
| 103 FilePath file_path(dummy_file_path); | 103 FILE* dummy_file = file_util::OpenFile(dummy_file_path, "w"); |
|
Mark Mentovai
2011/05/25 19:19:06
Put this in a file_util::ScopedFILE to ensure it c
mrossetti
2011/05/25 21:12:31
Eliminated in favor of just using WriteFile.
| |
| 104 // It is not actually necessary to have a physical file in order to | 104 EXPECT_TRUE(dummy_file); |
| 105 // set its exclusion property. | 105 const char dummy_data[] = "All your base are belong to us!"; |
|
Mark Mentovai
2011/05/25 19:19:06
:)
| |
| 106 NSURL* fileURL = [NSURL URLWithString:dummyFilePath]; | 106 EXPECT_TRUE(fwrite(dummy_data, ARRAYSIZE_UNSAFE(dummy_data), 1, dummy_file)); |
|
Mark Mentovai
2011/05/25 19:19:06
Instead of file_util::OpenFile + fwrite + file_uti
Mark Mentovai
2011/05/25 19:19:06
The “safe” arraysize didn’t work here?
mrossetti
2011/05/25 21:12:31
Done.
mrossetti
2011/05/25 21:12:31
Done.
| |
| 107 // Reset the exclusion in case it was set previously. | 107 // The file must already exist in order to set its exclusion property. |
| 108 SetFileBackupExclusion(file_path, false); | 108 NSString* fileURLString = |
| 109 Boolean excludeByPath; | 109 [NSString stringWithUTF8String:dummy_file_path.value().c_str()]; |
| 110 NSURL* fileURL = [NSURL URLWithString:fileURLString]; | |
| 110 // Initial state should be non-excluded. | 111 // Initial state should be non-excluded. |
| 111 EXPECT_FALSE(CSBackupIsItemExcluded((CFURLRef)fileURL, &excludeByPath)); | 112 EXPECT_FALSE(CSBackupIsItemExcluded((CFURLRef)fileURL, NULL)); |
|
Mark Mentovai
2011/05/25 19:19:06
I wonder if this is always true in the temp direct
mrossetti
2011/05/25 21:12:31
It might be different under 10.7 but it comes up n
| |
| 112 // Exclude the file. | 113 // Exclude the file. |
| 113 EXPECT_TRUE(SetFileBackupExclusion(file_path, true)); | 114 EXPECT_TRUE(SetFileBackupExclusion(dummy_file_path)); |
| 114 EXPECT_TRUE(CSBackupIsItemExcluded((CFURLRef)fileURL, &excludeByPath)); | 115 // SetFileBackupExclusion never excludes by path. |
| 115 // Un-exclude the file. | 116 Boolean excluded_by_path = false; |
|
Mark Mentovai
2011/05/25 19:19:06
FALSE
mrossetti
2011/05/25 21:12:31
Yeah, yeah — I'm getting it. ;^)
| |
| 116 EXPECT_TRUE(SetFileBackupExclusion(file_path, false)); | 117 Boolean excluded = |
| 117 EXPECT_FALSE(CSBackupIsItemExcluded((CFURLRef)fileURL, &excludeByPath)); | 118 CSBackupIsItemExcluded((CFURLRef)fileURL, &excluded_by_path); |
| 119 EXPECT_TRUE(excluded); | |
| 120 EXPECT_FALSE(excluded_by_path); | |
| 121 EXPECT_TRUE(file_util::CloseFile(dummy_file)); | |
| 118 } | 122 } |
| 119 | 123 |
| 120 TEST_F(MacUtilTest, TestGetValueFromDictionary) { | 124 TEST_F(MacUtilTest, TestGetValueFromDictionary) { |
| 121 ScopedCFTypeRef<CFMutableDictionaryRef> dict( | 125 ScopedCFTypeRef<CFMutableDictionaryRef> dict( |
| 122 CFDictionaryCreateMutable(0, 0, | 126 CFDictionaryCreateMutable(0, 0, |
| 123 &kCFTypeDictionaryKeyCallBacks, | 127 &kCFTypeDictionaryKeyCallBacks, |
| 124 &kCFTypeDictionaryValueCallBacks)); | 128 &kCFTypeDictionaryValueCallBacks)); |
| 125 CFDictionarySetValue(dict.get(), CFSTR("key"), CFSTR("value")); | 129 CFDictionarySetValue(dict.get(), CFSTR("key"), CFSTR("value")); |
| 126 | 130 |
| 127 EXPECT_TRUE(CFEqual(CFSTR("value"), | 131 EXPECT_TRUE(CFEqual(CFSTR("value"), |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 154 EXPECT_EQ(2U, [array retainCount]); | 158 EXPECT_EQ(2U, [array retainCount]); |
| 155 | 159 |
| 156 NSObjectRelease(array); | 160 NSObjectRelease(array); |
| 157 EXPECT_EQ(1U, [array retainCount]); | 161 EXPECT_EQ(1U, [array retainCount]); |
| 158 } | 162 } |
| 159 | 163 |
| 160 } // namespace | 164 } // namespace |
| 161 | 165 |
| 162 } // namespace mac | 166 } // namespace mac |
| 163 } // namespace base | 167 } // namespace base |
| OLD | NEW |