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 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 EXPECT_TRUE(dir.Delete()); | 87 EXPECT_TRUE(dir.Delete()); |
88 EXPECT_TRUE(dir.CreateUniqueTempDir()); | 88 EXPECT_TRUE(dir.CreateUniqueTempDir()); |
89 EXPECT_FALSE(dir.CreateUniqueTempDir()); | 89 EXPECT_FALSE(dir.CreateUniqueTempDir()); |
90 ScopedTempDir other_dir; | 90 ScopedTempDir other_dir; |
91 EXPECT_TRUE(other_dir.Set(dir.Take())); | 91 EXPECT_TRUE(other_dir.Set(dir.Take())); |
92 EXPECT_TRUE(dir.CreateUniqueTempDir()); | 92 EXPECT_TRUE(dir.CreateUniqueTempDir()); |
93 EXPECT_FALSE(dir.CreateUniqueTempDir()); | 93 EXPECT_FALSE(dir.CreateUniqueTempDir()); |
94 EXPECT_FALSE(other_dir.CreateUniqueTempDir()); | 94 EXPECT_FALSE(other_dir.CreateUniqueTempDir()); |
95 } | 95 } |
96 | 96 |
97 #if defined(OS_WIN) | |
98 TEST(ScopedTempDir, LockedTempDir) { | |
99 ScopedTempDir dir; | |
100 EXPECT_TRUE(dir.CreateUniqueTempDir()); | |
101 base::File file(dir.path().Append(FILE_PATH_LITERAL("temp")), | |
102 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE); | |
103 EXPECT_TRUE(file.IsValid()); | |
104 EXPECT_EQ(base::File::FILE_OK, file.error_details()); | |
105 EXPECT_FALSE(dir.Delete()); // We should not be able to delete. | |
106 EXPECT_FALSE(dir.path().empty()); // We should still have a valid path. | |
107 file.Close(); | |
108 // Now, we should be able to delete. | |
109 EXPECT_TRUE(dir.Delete()); | |
110 } | |
111 #endif // defined(OS_WIN) | |
112 | |
113 } // namespace base | 97 } // namespace base |
OLD | NEW |