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

Side by Side Diff: base/file_util_unittest.cc

Issue 437090: Fix race in directory creation on Windows. The... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | base/file_util_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #include <shlobj.h> 10 #include <shlobj.h>
(...skipping 1119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 // Doesn't work to create it on top of a non-dir 1130 // Doesn't work to create it on top of a non-dir
1131 test_path = test_path.Append(FILE_PATH_LITERAL("foobar.txt")); 1131 test_path = test_path.Append(FILE_PATH_LITERAL("foobar.txt"));
1132 EXPECT_FALSE(file_util::PathExists(test_path)); 1132 EXPECT_FALSE(file_util::PathExists(test_path));
1133 CreateTextFile(test_path, L"test file"); 1133 CreateTextFile(test_path, L"test file");
1134 EXPECT_TRUE(file_util::PathExists(test_path)); 1134 EXPECT_TRUE(file_util::PathExists(test_path));
1135 EXPECT_FALSE(file_util::CreateDirectory(test_path)); 1135 EXPECT_FALSE(file_util::CreateDirectory(test_path));
1136 1136
1137 EXPECT_TRUE(file_util::Delete(test_root, true)); 1137 EXPECT_TRUE(file_util::Delete(test_root, true));
1138 EXPECT_FALSE(file_util::PathExists(test_root)); 1138 EXPECT_FALSE(file_util::PathExists(test_root));
1139 EXPECT_FALSE(file_util::PathExists(test_path)); 1139 EXPECT_FALSE(file_util::PathExists(test_path));
1140
1141 // Verify assumptions made by the Windows implementation:
1142 // 1. The current directory always exists.
1143 // 2. The root directory always exists.
1144 ASSERT_TRUE(file_util::DirectoryExists(
1145 FilePath(FilePath::kCurrentDirectory)));
1146 FilePath top_level = test_root;
1147 while (top_level != top_level.DirName()) {
1148 top_level = top_level.DirName();
1149 }
1150 ASSERT_TRUE(file_util::DirectoryExists(top_level));
1151
1152 // Given these assumptions hold, it should be safe to
1153 // test that "creating" these directories succeeds.
1154 EXPECT_TRUE(file_util::CreateDirectory(
1155 FilePath(FilePath::kCurrentDirectory)));
1156 EXPECT_TRUE(file_util::CreateDirectory(top_level));
1140 } 1157 }
1141 1158
1142 TEST_F(FileUtilTest, DetectDirectoryTest) { 1159 TEST_F(FileUtilTest, DetectDirectoryTest) {
1143 // Check a directory 1160 // Check a directory
1144 FilePath test_root = 1161 FilePath test_root =
1145 test_dir_.Append(FILE_PATH_LITERAL("detect_directory_test")); 1162 test_dir_.Append(FILE_PATH_LITERAL("detect_directory_test"));
1146 EXPECT_FALSE(file_util::PathExists(test_root)); 1163 EXPECT_FALSE(file_util::PathExists(test_root));
1147 EXPECT_TRUE(file_util::CreateDirectory(test_root)); 1164 EXPECT_TRUE(file_util::CreateDirectory(test_root));
1148 EXPECT_TRUE(file_util::PathExists(test_root)); 1165 EXPECT_TRUE(file_util::PathExists(test_root));
1149 EXPECT_TRUE(file_util::DirectoryExists(test_root)); 1166 EXPECT_TRUE(file_util::DirectoryExists(test_root));
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 #elif defined(OS_LINUX) 1372 #elif defined(OS_LINUX)
1356 EXPECT_FALSE(file_util::ContainsPath(foo, 1373 EXPECT_FALSE(file_util::ContainsPath(foo,
1357 foo_caps.Append(FILE_PATH_LITERAL("bar.txt")))); 1374 foo_caps.Append(FILE_PATH_LITERAL("bar.txt"))));
1358 #else 1375 #else
1359 // We can't really do this test on osx since the case-sensitivity of the 1376 // We can't really do this test on osx since the case-sensitivity of the
1360 // filesystem is configurable. 1377 // filesystem is configurable.
1361 #endif 1378 #endif
1362 } 1379 }
1363 1380
1364 } // namespace 1381 } // namespace
OLDNEW
« no previous file with comments | « no previous file | base/file_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698