| 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" |
| 11 #include "base/mac/foundation_util.h" |
| 11 #include "base/mac/scoped_cftyperef.h" | 12 #include "base/mac/scoped_cftyperef.h" |
| 12 #include "base/memory/scoped_nsobject.h" | 13 #include "base/memory/scoped_nsobject.h" |
| 14 #include "base/scoped_temp_dir.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "testing/platform_test.h" | 16 #include "testing/platform_test.h" |
| 15 | 17 |
| 16 namespace base { | 18 namespace base { |
| 17 namespace mac { | 19 namespace mac { |
| 18 | 20 |
| 19 namespace { | 21 namespace { |
| 20 | 22 |
| 21 typedef PlatformTest MacUtilTest; | 23 typedef PlatformTest MacUtilTest; |
| 22 | 24 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 }; | 90 }; |
| 89 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(valid_inputs); i++) { | 91 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(valid_inputs); i++) { |
| 90 out = GetAppBundlePath(FilePath(valid_inputs[i].in)); | 92 out = GetAppBundlePath(FilePath(valid_inputs[i].in)); |
| 91 EXPECT_FALSE(out.empty()) << "loop: " << i; | 93 EXPECT_FALSE(out.empty()) << "loop: " << i; |
| 92 EXPECT_STREQ(valid_inputs[i].expected_out, | 94 EXPECT_STREQ(valid_inputs[i].expected_out, |
| 93 out.value().c_str()) << "loop: " << i; | 95 out.value().c_str()) << "loop: " << i; |
| 94 } | 96 } |
| 95 } | 97 } |
| 96 | 98 |
| 97 TEST_F(MacUtilTest, TestExcludeFileFromBackups) { | 99 TEST_F(MacUtilTest, TestExcludeFileFromBackups) { |
| 98 NSString* homeDirectory = NSHomeDirectory(); | 100 // The file must already exist in order to set its exclusion property. |
| 99 NSString* dummyFilePath = | 101 ScopedTempDir temp_dir_; |
| 100 [homeDirectory stringByAppendingPathComponent:@"DummyFile"]; | 102 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 101 const char* dummy_file_path = [dummyFilePath fileSystemRepresentation]; | 103 FilePath dummy_file_path = temp_dir_.path().Append("DummyFile"); |
| 102 ASSERT_TRUE(dummy_file_path); | 104 const char dummy_data[] = "All your base are belong to us!"; |
| 103 FilePath file_path(dummy_file_path); | 105 // Dump something real into the file. |
| 104 // It is not actually necessary to have a physical file in order to | 106 ASSERT_EQ(static_cast<int>(arraysize(dummy_data)), |
| 105 // set its exclusion property. | 107 file_util::WriteFile(dummy_file_path, dummy_data, arraysize(dummy_data))); |
| 106 NSURL* fileURL = [NSURL URLWithString:dummyFilePath]; | 108 NSString* fileURLString = |
| 107 // Reset the exclusion in case it was set previously. | 109 [NSString stringWithUTF8String:dummy_file_path.value().c_str()]; |
| 108 SetFileBackupExclusion(file_path, false); | 110 NSURL* fileURL = [NSURL URLWithString:fileURLString]; |
| 109 Boolean excludeByPath; | |
| 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(base::mac::NSToCFCast(fileURL), NULL)); |
| 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; |
| 116 EXPECT_TRUE(SetFileBackupExclusion(file_path, false)); | 117 Boolean excluded = |
| 117 EXPECT_FALSE(CSBackupIsItemExcluded((CFURLRef)fileURL, &excludeByPath)); | 118 CSBackupIsItemExcluded(base::mac::NSToCFCast(fileURL), &excluded_by_path); |
| 119 EXPECT_TRUE(excluded); |
| 120 EXPECT_FALSE(excluded_by_path); |
| 118 } | 121 } |
| 119 | 122 |
| 120 TEST_F(MacUtilTest, TestGetValueFromDictionary) { | 123 TEST_F(MacUtilTest, TestGetValueFromDictionary) { |
| 121 ScopedCFTypeRef<CFMutableDictionaryRef> dict( | 124 ScopedCFTypeRef<CFMutableDictionaryRef> dict( |
| 122 CFDictionaryCreateMutable(0, 0, | 125 CFDictionaryCreateMutable(0, 0, |
| 123 &kCFTypeDictionaryKeyCallBacks, | 126 &kCFTypeDictionaryKeyCallBacks, |
| 124 &kCFTypeDictionaryValueCallBacks)); | 127 &kCFTypeDictionaryValueCallBacks)); |
| 125 CFDictionarySetValue(dict.get(), CFSTR("key"), CFSTR("value")); | 128 CFDictionarySetValue(dict.get(), CFSTR("key"), CFSTR("value")); |
| 126 | 129 |
| 127 EXPECT_TRUE(CFEqual(CFSTR("value"), | 130 EXPECT_TRUE(CFEqual(CFSTR("value"), |
| (...skipping 26 matching lines...) Expand all Loading... |
| 154 EXPECT_EQ(2U, [array retainCount]); | 157 EXPECT_EQ(2U, [array retainCount]); |
| 155 | 158 |
| 156 NSObjectRelease(array); | 159 NSObjectRelease(array); |
| 157 EXPECT_EQ(1U, [array retainCount]); | 160 EXPECT_EQ(1U, [array retainCount]); |
| 158 } | 161 } |
| 159 | 162 |
| 160 } // namespace | 163 } // namespace |
| 161 | 164 |
| 162 } // namespace mac | 165 } // namespace mac |
| 163 } // namespace base | 166 } // namespace base |
| OLD | NEW |