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

Side by Side Diff: base/file_util_unittest.cc

Issue 139373004: Fix CopyFileACL on Windows XP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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) 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 #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 1399 matching lines...) Expand 10 before | Expand all | Expand 10 after
1410 // Set the source file to read-only. 1410 // Set the source file to read-only.
1411 #if defined(OS_WIN) 1411 #if defined(OS_WIN)
1412 // On Windows, it involves setting a bit. 1412 // On Windows, it involves setting a bit.
1413 DWORD attrs = GetFileAttributes(src.value().c_str()); 1413 DWORD attrs = GetFileAttributes(src.value().c_str());
1414 ASSERT_NE(INVALID_FILE_ATTRIBUTES, attrs); 1414 ASSERT_NE(INVALID_FILE_ATTRIBUTES, attrs);
1415 ASSERT_TRUE(SetFileAttributes( 1415 ASSERT_TRUE(SetFileAttributes(
1416 src.value().c_str(), attrs | FILE_ATTRIBUTE_READONLY)); 1416 src.value().c_str(), attrs | FILE_ATTRIBUTE_READONLY));
1417 attrs = GetFileAttributes(src.value().c_str()); 1417 attrs = GetFileAttributes(src.value().c_str());
1418 // Files in the temporary directory should not be indexed ever. If this 1418 // Files in the temporary directory should not be indexed ever. If this
1419 // assumption change, fix this unit test accordingly. 1419 // assumption change, fix this unit test accordingly.
1420 DWORD expected = (FILE_ATTRIBUTE_NOT_CONTENT_INDEXED | 1420 // FILE_ATTRIBUTE_NOT_CONTENT_INDEXED doesn't exist on XP.
1421 FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY); 1421 DWORD expected = FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY;
1422 if (win::GetVersion() >= win::VERSION_VISTA)
1423 expected |= FILE_ATTRIBUTE_NOT_CONTENT_INDEXED;
1422 ASSERT_EQ(expected, attrs); 1424 ASSERT_EQ(expected, attrs);
1423 #else 1425 #else
1424 // On all other platforms, it involves removing the write bit. 1426 // On all other platforms, it involves removing the write bit.
1425 EXPECT_TRUE(SetPosixFilePermissions(src, 0400)); 1427 EXPECT_TRUE(SetPosixFilePermissions(src, 0400));
1426 #endif 1428 #endif
1427 1429
1428 // Copy the file. 1430 // Copy the file.
1429 FilePath dst = temp_dir_.path().Append(FILE_PATH_LITERAL("dst.txt")); 1431 FilePath dst = temp_dir_.path().Append(FILE_PATH_LITERAL("dst.txt"));
1430 ASSERT_TRUE(CopyFile(src, dst)); 1432 ASSERT_TRUE(CopyFile(src, dst));
1431 EXPECT_EQ(file_contents, ReadTextFile(dst)); 1433 EXPECT_EQ(file_contents, ReadTextFile(dst));
1432 1434
1433 #if defined(OS_WIN) 1435 #if defined(OS_WIN)
1434 // While the source file had RO bit set, the copied file doesn't. Other file 1436 // While the source file had RO bit set, the copied file doesn't. Other file
1435 // modes are copied. 1437 // modes are copied.
1436 attrs = GetFileAttributes(src.value().c_str()); 1438 attrs = GetFileAttributes(src.value().c_str());
1437 ASSERT_EQ(expected, attrs); 1439 ASSERT_EQ(expected, attrs);
1438 expected = FILE_ATTRIBUTE_NOT_CONTENT_INDEXED | FILE_ATTRIBUTE_ARCHIVE; 1440 expected = FILE_ATTRIBUTE_ARCHIVE;
1441 if (win::GetVersion() >= win::VERSION_VISTA)
1442 expected |= FILE_ATTRIBUTE_NOT_CONTENT_INDEXED;
1439 attrs = GetFileAttributes(dst.value().c_str()); 1443 attrs = GetFileAttributes(dst.value().c_str());
1440 ASSERT_EQ(expected, attrs); 1444 ASSERT_EQ(expected, attrs);
1441 #elif defined(OS_MACOSX) 1445 #elif defined(OS_MACOSX)
1442 // On OSX, file mode is copied. 1446 // On OSX, file mode is copied.
1443 int mode = 0; 1447 int mode = 0;
1444 EXPECT_TRUE(GetPosixFilePermissions(dst, &mode)); 1448 EXPECT_TRUE(GetPosixFilePermissions(dst, &mode));
1445 EXPECT_EQ(0400, mode & 0600); 1449 EXPECT_EQ(0400, mode & 0600);
1446 #else 1450 #else
1447 // On other POSIX, file mode is not copied. 1451 // On other POSIX, file mode is not copied.
1448 int mode = 0; 1452 int mode = 0;
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after
2382 int fd = OpenContentUriForRead(path); 2386 int fd = OpenContentUriForRead(path);
2383 EXPECT_EQ(-1, fd); 2387 EXPECT_EQ(-1, fd);
2384 } 2388 }
2385 #endif 2389 #endif
2386 2390
2387 #endif // defined(OS_POSIX) 2391 #endif // defined(OS_POSIX)
2388 2392
2389 } // namespace 2393 } // namespace
2390 2394
2391 } // namespace base 2395 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698