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

Side by Side Diff: base/file_util_unittest.cc

Issue 9055001: Change code in base (primarily unit tests) to use Sleep(TimeDelta). (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Qualify windows Sleep calls to go through PlatformThread. Created 8 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
« no previous file with comments | « base/debug/trace_event_unittest.cc ('k') | base/lazy_instance_unittest.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) 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 "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>
11 #include <tchar.h> 11 #include <tchar.h>
12 #include <winioctl.h> 12 #include <winioctl.h>
13 #endif 13 #endif
14 14
15 #include <algorithm> 15 #include <algorithm>
16 #include <fstream> 16 #include <fstream>
17 #include <set> 17 #include <set>
18 18
19 #include "base/base_paths.h" 19 #include "base/base_paths.h"
20 #include "base/file_path.h" 20 #include "base/file_path.h"
21 #include "base/file_util.h" 21 #include "base/file_util.h"
22 #include "base/path_service.h" 22 #include "base/path_service.h"
23 #include "base/scoped_temp_dir.h" 23 #include "base/scoped_temp_dir.h"
24 #include "base/threading/platform_thread.h" 24 #include "base/threading/platform_thread.h"
25 #include "base/time.h"
26 #include "base/utf_string_conversions.h" 25 #include "base/utf_string_conversions.h"
27 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
28 #include "testing/platform_test.h" 27 #include "testing/platform_test.h"
29 28
30 #if defined(OS_WIN) 29 #if defined(OS_WIN)
31 #include "base/win/scoped_handle.h" 30 #include "base/win/scoped_handle.h"
32 #endif 31 #endif
33 32
34 // This macro helps avoid wrapped lines in the test structs. 33 // This macro helps avoid wrapped lines in the test structs.
35 #define FPL(x) FILE_PATH_LITERAL(x) 34 #define FPL(x) FILE_PATH_LITERAL(x)
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 341
343 // Flaky, http://crbug.com/46246 342 // Flaky, http://crbug.com/46246
344 TEST_F(FileUtilTest, FLAKY_CountFilesCreatedAfter) { 343 TEST_F(FileUtilTest, FLAKY_CountFilesCreatedAfter) {
345 // Create old file (that we don't want to count) 344 // Create old file (that we don't want to count)
346 FilePath old_file_name = 345 FilePath old_file_name =
347 temp_dir_.path().Append(FILE_PATH_LITERAL("Old File.txt")); 346 temp_dir_.path().Append(FILE_PATH_LITERAL("Old File.txt"));
348 CreateTextFile(old_file_name, L"Just call me Mr. Creakybits"); 347 CreateTextFile(old_file_name, L"Just call me Mr. Creakybits");
349 348
350 // Age to perfection 349 // Age to perfection
351 #if defined(OS_WIN) 350 #if defined(OS_WIN)
352 base::PlatformThread::Sleep(100); 351 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100));
353 #elif defined(OS_POSIX) 352 #elif defined(OS_POSIX)
354 // We need to wait at least one second here because the precision of 353 // We need to wait at least one second here because the precision of
355 // file creation time is one second. 354 // file creation time is one second.
356 base::PlatformThread::Sleep(1500); 355 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1500));
357 #endif 356 #endif
358 357
359 // Establish our cutoff time 358 // Establish our cutoff time
360 base::Time now(base::Time::NowFromSystemTime()); 359 base::Time now(base::Time::NowFromSystemTime());
361 EXPECT_EQ(0, file_util::CountFilesCreatedAfter(temp_dir_.path(), now)); 360 EXPECT_EQ(0, file_util::CountFilesCreatedAfter(temp_dir_.path(), now));
362 361
363 // Create a new file (that we do want to count) 362 // Create a new file (that we do want to count)
364 FilePath new_file_name = 363 FilePath new_file_name =
365 temp_dir_.path().Append(FILE_PATH_LITERAL("New File.txt")); 364 temp_dir_.path().Append(FILE_PATH_LITERAL("New File.txt"));
366 CreateTextFile(new_file_name, L"Waaaaaaaaaaaaaah."); 365 CreateTextFile(new_file_name, L"Waaaaaaaaaaaaaah.");
(...skipping 876 matching lines...) Expand 10 before | Expand all | Expand 10 after
1243 EXPECT_TRUE(file_util::PathExists(dest_file2)); 1242 EXPECT_TRUE(file_util::PathExists(dest_file2));
1244 } 1243 }
1245 1244
1246 // TODO(erikkay): implement 1245 // TODO(erikkay): implement
1247 #if defined(OS_WIN) 1246 #if defined(OS_WIN)
1248 TEST_F(FileUtilTest, GetFileCreationLocalTime) { 1247 TEST_F(FileUtilTest, GetFileCreationLocalTime) {
1249 FilePath file_name = temp_dir_.path().Append(L"Test File.txt"); 1248 FilePath file_name = temp_dir_.path().Append(L"Test File.txt");
1250 1249
1251 SYSTEMTIME start_time; 1250 SYSTEMTIME start_time;
1252 GetLocalTime(&start_time); 1251 GetLocalTime(&start_time);
1253 Sleep(100); 1252 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100));
1254 CreateTextFile(file_name, L"New file!"); 1253 CreateTextFile(file_name, L"New file!");
1255 Sleep(100); 1254 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100));
1256 SYSTEMTIME end_time; 1255 SYSTEMTIME end_time;
1257 GetLocalTime(&end_time); 1256 GetLocalTime(&end_time);
1258 1257
1259 SYSTEMTIME file_creation_time; 1258 SYSTEMTIME file_creation_time;
1260 file_util::GetFileCreationLocalTime(file_name.value(), &file_creation_time); 1259 file_util::GetFileCreationLocalTime(file_name.value(), &file_creation_time);
1261 1260
1262 FILETIME start_filetime; 1261 FILETIME start_filetime;
1263 SystemTimeToFileTime(&start_time, &start_filetime); 1262 SystemTimeToFileTime(&start_time, &start_filetime);
1264 FILETIME end_filetime; 1263 FILETIME end_filetime;
1265 SystemTimeToFileTime(&end_time, &end_filetime); 1264 SystemTimeToFileTime(&end_time, &end_filetime);
(...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after
2217 file_util::VerifyPathControlledByUser( 2216 file_util::VerifyPathControlledByUser(
2218 base_dir_, text_file_, uid_, ok_gids_)); 2217 base_dir_, text_file_, uid_, ok_gids_));
2219 EXPECT_TRUE( 2218 EXPECT_TRUE(
2220 file_util::VerifyPathControlledByUser( 2219 file_util::VerifyPathControlledByUser(
2221 sub_dir_, text_file_, uid_, ok_gids_)); 2220 sub_dir_, text_file_, uid_, ok_gids_));
2222 } 2221 }
2223 2222
2224 #endif // defined(OS_POSIX) 2223 #endif // defined(OS_POSIX)
2225 2224
2226 } // namespace 2225 } // namespace
OLDNEW
« no previous file with comments | « base/debug/trace_event_unittest.cc ('k') | base/lazy_instance_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698