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

Side by Side Diff: base/file_util_unittest.cc

Issue 9484003: Cleanup: Deprecate wstring version of file_util::CopyDirectory(). (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 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 | « base/file_util_deprecated.h ('k') | chrome/browser/ui/views/select_file_dialog_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) 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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 {L"/foo/bar./", L""}, 295 {L"/foo/bar./", L""},
296 {L"/foo/bar/filename.extension.extension2", L"extension2"}, 296 {L"/foo/bar/filename.extension.extension2", L"extension2"},
297 {L".", L""}, 297 {L".", L""},
298 {L"..", L""}, 298 {L"..", L""},
299 {L"./foo", L""}, 299 {L"./foo", L""},
300 {L"./foo.extension", L"extension"}, 300 {L"./foo.extension", L"extension"},
301 {L"/foo.extension1/bar.extension2", L"extension2"}, 301 {L"/foo.extension1/bar.extension2", L"extension2"},
302 #endif 302 #endif
303 }; 303 };
304 304
305 #if defined(OS_WIN)
306 // This function has been deprecated on non-Windows.
307 TEST_F(FileUtilTest, GetFileExtensionFromPath) {
308 for (unsigned int i = 0; i < arraysize(extension_cases); ++i) {
309 const extension_case& ext = extension_cases[i];
310 const std::wstring fext = file_util::GetFileExtensionFromPath(ext.path);
311 EXPECT_EQ(ext.extension, fext);
312 }
313 }
314 #endif
315
316 // Test finding the directory component of a path 305 // Test finding the directory component of a path
317 static const struct dir_case { 306 static const struct dir_case {
318 const wchar_t* full_path; 307 const wchar_t* full_path;
319 const wchar_t* directory; 308 const wchar_t* directory;
320 } dir_cases[] = { 309 } dir_cases[] = {
321 #if defined(OS_WIN) 310 #if defined(OS_WIN)
322 {L"C:\\WINDOWS\\system32\\gdi32.dll", L"C:\\WINDOWS\\system32"}, 311 {L"C:\\WINDOWS\\system32\\gdi32.dll", L"C:\\WINDOWS\\system32"},
323 {L"C:\\WINDOWS\\system32\\not_exist_thx_1138", L"C:\\WINDOWS\\system32"}, 312 {L"C:\\WINDOWS\\system32\\not_exist_thx_1138", L"C:\\WINDOWS\\system32"},
324 {L"C:\\WINDOWS\\system32\\", L"C:\\WINDOWS\\system32"}, 313 {L"C:\\WINDOWS\\system32\\", L"C:\\WINDOWS\\system32"},
325 {L"C:\\WINDOWS\\system32\\\\", L"C:\\WINDOWS\\system32"}, 314 {L"C:\\WINDOWS\\system32\\\\", L"C:\\WINDOWS\\system32"},
(...skipping 1115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 1430
1442 // We don't need equivalent functionality outside of Windows. 1431 // We don't need equivalent functionality outside of Windows.
1443 #if defined(OS_WIN) 1432 #if defined(OS_WIN)
1444 TEST_F(FileUtilTest, ResolveShortcutTest) { 1433 TEST_F(FileUtilTest, ResolveShortcutTest) {
1445 FilePath target_file = temp_dir_.path().Append(L"Target.txt"); 1434 FilePath target_file = temp_dir_.path().Append(L"Target.txt");
1446 CreateTextFile(target_file, L"This is the target."); 1435 CreateTextFile(target_file, L"This is the target.");
1447 1436
1448 FilePath link_file = temp_dir_.path().Append(L"Link.lnk"); 1437 FilePath link_file = temp_dir_.path().Append(L"Link.lnk");
1449 1438
1450 HRESULT result; 1439 HRESULT result;
1451 IShellLink *shell = NULL; 1440 IShellLink* shell = NULL;
1452 IPersistFile *persist = NULL; 1441 IPersistFile* persist = NULL;
1453 1442
1454 CoInitialize(NULL); 1443 CoInitialize(NULL);
1455 // Temporarily create a shortcut for test 1444 // Temporarily create a shortcut for test
1456 result = CoCreateInstance(CLSID_ShellLink, NULL, 1445 result = CoCreateInstance(CLSID_ShellLink, NULL,
1457 CLSCTX_INPROC_SERVER, IID_IShellLink, 1446 CLSCTX_INPROC_SERVER, IID_IShellLink,
1458 reinterpret_cast<LPVOID*>(&shell)); 1447 reinterpret_cast<LPVOID*>(&shell));
1459 EXPECT_TRUE(SUCCEEDED(result)); 1448 EXPECT_TRUE(SUCCEEDED(result));
1460 result = shell->QueryInterface(IID_IPersistFile, 1449 result = shell->QueryInterface(IID_IPersistFile,
1461 reinterpret_cast<LPVOID*>(&persist)); 1450 reinterpret_cast<LPVOID*>(&persist));
1462 EXPECT_TRUE(SUCCEEDED(result)); 1451 EXPECT_TRUE(SUCCEEDED(result));
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1572 EXPECT_FALSE(file_util::DirectoryExists(temp_files[i])); 1561 EXPECT_FALSE(file_util::DirectoryExists(temp_files[i]));
1573 } 1562 }
1574 for (int i = 0; i < 3; i++) 1563 for (int i = 0; i < 3; i++)
1575 EXPECT_FALSE(temp_files[i] == temp_files[(i+1)%3]); 1564 EXPECT_FALSE(temp_files[i] == temp_files[(i+1)%3]);
1576 for (int i = 0; i < 3; i++) 1565 for (int i = 0; i < 3; i++)
1577 EXPECT_TRUE(file_util::Delete(temp_files[i], false)); 1566 EXPECT_TRUE(file_util::Delete(temp_files[i], false));
1578 } 1567 }
1579 1568
1580 TEST_F(FileUtilTest, CreateAndOpenTemporaryFileTest) { 1569 TEST_F(FileUtilTest, CreateAndOpenTemporaryFileTest) {
1581 FilePath names[3]; 1570 FilePath names[3];
1582 FILE *fps[3]; 1571 FILE* fps[3];
1583 int i; 1572 int i;
1584 1573
1585 // Create; make sure they are open and exist. 1574 // Create; make sure they are open and exist.
1586 for (i = 0; i < 3; ++i) { 1575 for (i = 0; i < 3; ++i) {
1587 fps[i] = file_util::CreateAndOpenTemporaryFile(&(names[i])); 1576 fps[i] = file_util::CreateAndOpenTemporaryFile(&(names[i]));
1588 ASSERT_TRUE(fps[i]); 1577 ASSERT_TRUE(fps[i]);
1589 EXPECT_TRUE(file_util::PathExists(names[i])); 1578 EXPECT_TRUE(file_util::PathExists(names[i]));
1590 } 1579 }
1591 1580
1592 // Make sure all names are unique. 1581 // Make sure all names are unique.
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
1947 ok_gids_.insert(stat_buf.st_gid); 1936 ok_gids_.insert(stat_buf.st_gid);
1948 bad_gids_.insert(stat_buf.st_gid + 1); 1937 bad_gids_.insert(stat_buf.st_gid + 1);
1949 1938
1950 ASSERT_EQ(uid_, getuid()); // This process should be the owner. 1939 ASSERT_EQ(uid_, getuid()); // This process should be the owner.
1951 1940
1952 // To ensure that umask settings do not cause the initial state 1941 // To ensure that umask settings do not cause the initial state
1953 // of permissions to be different from what we expect, explicitly 1942 // of permissions to be different from what we expect, explicitly
1954 // set permissions on the directories we create. 1943 // set permissions on the directories we create.
1955 // Make all files and directories non-world-writable. 1944 // Make all files and directories non-world-writable.
1956 mode_t enabled_permissions = 1945 mode_t enabled_permissions =
1957 S_IRWXU | // User can read, write, traverse 1946 S_IRWXU | // User can read, write, traverse
1958 S_IRWXG; // Group can read, write, traverse 1947 S_IRWXG; // Group can read, write, traverse
1959 mode_t disabled_permissions = 1948 mode_t disabled_permissions =
1960 S_IRWXO; // Other users can't read, write, traverse. 1949 S_IRWXO; // Other users can't read, write, traverse.
1961 1950
1962 ASSERT_NO_FATAL_FAILURE( 1951 ASSERT_NO_FATAL_FAILURE(
1963 ChangePosixFilePermissions( 1952 ChangePosixFilePermissions(
1964 base_dir_, enabled_permissions, disabled_permissions)); 1953 base_dir_, enabled_permissions, disabled_permissions));
1965 ASSERT_NO_FATAL_FAILURE( 1954 ASSERT_NO_FATAL_FAILURE(
1966 ChangePosixFilePermissions( 1955 ChangePosixFilePermissions(
1967 sub_dir_, enabled_permissions, disabled_permissions)); 1956 sub_dir_, enabled_permissions, disabled_permissions));
1968 } 1957 }
1969 1958
1970 FilePath base_dir_; 1959 FilePath base_dir_;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
2169 2158
2170 EXPECT_TRUE( 2159 EXPECT_TRUE(
2171 file_util::VerifyPathControlledByUser( 2160 file_util::VerifyPathControlledByUser(
2172 base_dir_, sub_dir_, uid_, multiple_gids)); 2161 base_dir_, sub_dir_, uid_, multiple_gids));
2173 EXPECT_TRUE( 2162 EXPECT_TRUE(
2174 file_util::VerifyPathControlledByUser( 2163 file_util::VerifyPathControlledByUser(
2175 base_dir_, text_file_, uid_, multiple_gids)); 2164 base_dir_, text_file_, uid_, multiple_gids));
2176 EXPECT_TRUE( 2165 EXPECT_TRUE(
2177 file_util::VerifyPathControlledByUser( 2166 file_util::VerifyPathControlledByUser(
2178 sub_dir_, text_file_, uid_, multiple_gids)); 2167 sub_dir_, text_file_, uid_, multiple_gids));
2179
2180 } 2168 }
2181 2169
2182 TEST_F(VerifyPathControlledByUserTest, WriteBitChecks) { 2170 TEST_F(VerifyPathControlledByUserTest, WriteBitChecks) {
2183 // Make all files and directories non-world-writable. 2171 // Make all files and directories non-world-writable.
2184 ASSERT_NO_FATAL_FAILURE( 2172 ASSERT_NO_FATAL_FAILURE(
2185 ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH)); 2173 ChangePosixFilePermissions(base_dir_, 0u, S_IWOTH));
2186 ASSERT_NO_FATAL_FAILURE( 2174 ASSERT_NO_FATAL_FAILURE(
2187 ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH)); 2175 ChangePosixFilePermissions(sub_dir_, 0u, S_IWOTH));
2188 ASSERT_NO_FATAL_FAILURE( 2176 ASSERT_NO_FATAL_FAILURE(
2189 ChangePosixFilePermissions(text_file_, 0u, S_IWOTH)); 2177 ChangePosixFilePermissions(text_file_, 0u, S_IWOTH));
2190 2178
2191 // Initialy, we control all parts of the path. 2179 // Initialy, we control all parts of the path.
2192 EXPECT_TRUE( 2180 EXPECT_TRUE(
2193 file_util::VerifyPathControlledByUser( 2181 file_util::VerifyPathControlledByUser(
2194 base_dir_, sub_dir_, uid_, ok_gids_)); 2182 base_dir_, sub_dir_, uid_, ok_gids_));
2195 EXPECT_TRUE( 2183 EXPECT_TRUE(
2196 file_util::VerifyPathControlledByUser( 2184 file_util::VerifyPathControlledByUser(
2197 base_dir_, text_file_, uid_, ok_gids_)); 2185 base_dir_, text_file_, uid_, ok_gids_));
2198 EXPECT_TRUE( 2186 EXPECT_TRUE(
2199 file_util::VerifyPathControlledByUser( 2187 file_util::VerifyPathControlledByUser(
2200 sub_dir_, text_file_, uid_, ok_gids_)); 2188 sub_dir_, text_file_, uid_, ok_gids_));
2201 2189
2202 // Make base_dir_ world-writable. 2190 // Make base_dir_ world-writable.
2203 ASSERT_NO_FATAL_FAILURE( 2191 ASSERT_NO_FATAL_FAILURE(
2204 ChangePosixFilePermissions(base_dir_, S_IWOTH, 0u)); 2192 ChangePosixFilePermissions(base_dir_, S_IWOTH, 0u));
2205 EXPECT_FALSE( 2193 EXPECT_FALSE(
2206 file_util::VerifyPathControlledByUser( 2194 file_util::VerifyPathControlledByUser(
2207 base_dir_, sub_dir_, uid_, ok_gids_)); 2195 base_dir_, sub_dir_, uid_, ok_gids_));
2208 EXPECT_FALSE( 2196 EXPECT_FALSE(
2209 file_util::VerifyPathControlledByUser( 2197 file_util::VerifyPathControlledByUser(
2210 base_dir_, text_file_, uid_, ok_gids_)); 2198 base_dir_, text_file_, uid_, ok_gids_));
2211 EXPECT_TRUE( 2199 EXPECT_TRUE(
2212 file_util::VerifyPathControlledByUser( 2200 file_util::VerifyPathControlledByUser(
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
2275 file_util::VerifyPathControlledByUser( 2263 file_util::VerifyPathControlledByUser(
2276 base_dir_, text_file_, uid_, ok_gids_)); 2264 base_dir_, text_file_, uid_, ok_gids_));
2277 EXPECT_TRUE( 2265 EXPECT_TRUE(
2278 file_util::VerifyPathControlledByUser( 2266 file_util::VerifyPathControlledByUser(
2279 sub_dir_, text_file_, uid_, ok_gids_)); 2267 sub_dir_, text_file_, uid_, ok_gids_));
2280 } 2268 }
2281 2269
2282 #endif // defined(OS_POSIX) 2270 #endif // defined(OS_POSIX)
2283 2271
2284 } // namespace 2272 } // namespace
OLDNEW
« no previous file with comments | « base/file_util_deprecated.h ('k') | chrome/browser/ui/views/select_file_dialog_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698