diff options
author | rdsmith@google.com <rdsmith@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-24 17:59:48 +0000 |
---|---|---|
committer | rdsmith@google.com <rdsmith@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-24 17:59:48 +0000 |
commit | ac167ce76fdb3a98f1ea6aadeb121b8495f8400e (patch) | |
tree | 0f95de451883702df93bc727e2b832da78cbcd0f /base | |
parent | 72938c7179ffe6a6266a7b146387fac67b9c1b21 (diff) | |
download | chromium_src-ac167ce76fdb3a98f1ea6aadeb121b8495f8400e.zip chromium_src-ac167ce76fdb3a98f1ea6aadeb121b8495f8400e.tar.gz chromium_src-ac167ce76fdb3a98f1ea6aadeb121b8495f8400e.tar.bz2 |
Initial conversion of download unit test to browser test with enhanced
download completion detection (DownloadsObserver).
BUG=None
TEST=browser_tests --gtest_filter=DownloadTest.DownloadMimeType
Review URL: http://codereview.chromium.org/4658001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67279 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/test/test_file_util.h | 8 | ||||
-rw-r--r-- | base/test/test_file_util_win.cc | 58 |
2 files changed, 66 insertions, 0 deletions
diff --git a/base/test/test_file_util.h b/base/test/test_file_util.h index 362c525..2de74e7 100644 --- a/base/test/test_file_util.h +++ b/base/test/test_file_util.h @@ -30,6 +30,14 @@ bool EvictFileFromSystemCache(const FilePath& file); bool CopyRecursiveDirNoCache(const FilePath& source_dir, const FilePath& dest_dir); +#if defined(OS_WIN) +// Returns true if the volume supports Alternate Data Streams. +bool VolumeSupportsADS(const FilePath& path); + +// Returns true if the ZoneIdentifier is correctly set to "Internet" (3). +bool HasInternetZoneIdentifier(const FilePath& full_path); +#endif // defined(OS_WIN) + } // namespace file_util #endif // BASE_TEST_TEST_FILE_UTIL_H_ diff --git a/base/test/test_file_util_win.cc b/base/test/test_file_util_win.cc index 8e5b37b..fc3d018 100644 --- a/base/test/test_file_util_win.cc +++ b/base/test/test_file_util_win.cc @@ -4,6 +4,7 @@ #include "base/test/test_file_util.h" +#include <shlwapi.h> #include <windows.h> #include <vector> @@ -173,4 +174,61 @@ bool CopyRecursiveDirNoCache(const FilePath& source_dir, return true; } +// Checks if the volume supports Alternate Data Streams. This is required for +// the Zone Identifier implementation. +bool VolumeSupportsADS(const FilePath& path) { + wchar_t drive[MAX_PATH] = {0}; + wcscpy_s(drive, MAX_PATH, path.value().c_str()); + + if (!PathStripToRootW(drive)) + return false; + + DWORD fs_flags = 0; + if (!GetVolumeInformationW(drive, NULL, 0, 0, NULL, &fs_flags, NULL, 0)) + return false; + + if (fs_flags & FILE_NAMED_STREAMS) + return true; + + return false; +} + +// Return whether the ZoneIdentifier is correctly set to "Internet" (3) +bool HasInternetZoneIdentifier(const FilePath& full_path) { + std::wstring path = full_path.value() + L":Zone.Identifier"; + + // This polling and sleeping here is a very bad pattern. But due to how + // Windows file semantics work it's really hard to do it other way. We are + // reading a file written by a different process, using a different handle. + // Windows does not guarantee that we will get the same contents even after + // the other process closes the handle, flushes the buffers, etc. + for (int i = 0; i < 20; i++) { + PlatformThread::Sleep(1000); + + const DWORD kShare = FILE_SHARE_READ | + FILE_SHARE_WRITE | + FILE_SHARE_DELETE; + HANDLE file = CreateFile(path.c_str(), GENERIC_READ, kShare, NULL, + OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + if (file == INVALID_HANDLE_VALUE) + continue; + + char buffer[100] = {0}; + DWORD read = 0; + BOOL read_result = ::ReadFile(file, buffer, 100, &read, NULL); + CloseHandle(file); + + if (!read_result) + continue; + + const char kIdentifier[] = "[ZoneTransfer]\nZoneId=3"; + if (read != arraysize(kIdentifier)) + continue; + + if (strcmp(kIdentifier, buffer) == 0) + return true; + } + return false; +} + } // namespace file_util |