diff options
author | rdsmith@chromium.org <rdsmith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-23 18:08:37 +0000 |
---|---|---|
committer | rdsmith@chromium.org <rdsmith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-23 18:08:37 +0000 |
commit | 656fc926cae6ff497f76364e7183fbba0e97d847 (patch) | |
tree | 59eda8bc185565824e14495f4c69909e888edda2 /base | |
parent | a08f042d3949f928c7cb83ed822e72a58c0e1bf2 (diff) | |
download | chromium_src-656fc926cae6ff497f76364e7183fbba0e97d847.zip chromium_src-656fc926cae6ff497f76364e7183fbba0e97d847.tar.gz chromium_src-656fc926cae6ff497f76364e7183fbba0e97d847.tar.bz2 |
Fix Downloads Windows Zone identifier test.
Changes the setting of the Zone Identifier to not include an unnecessary trailing null byte, modifies the test to check for any of a range of options known to be acceptable to Windows, and makes explicit the restriction the utility test function works under.
BUG=20809
TEST=Test run on windows and successful try bot run (with test enabled).
Review URL: http://codereview.chromium.org/6541003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75762 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/test/test_file_util.h | 3 | ||||
-rw-r--r-- | base/test/test_file_util_win.cc | 54 |
2 files changed, 23 insertions, 34 deletions
diff --git a/base/test/test_file_util.h b/base/test/test_file_util.h index 2de74e7..6a6ae7d 100644 --- a/base/test/test_file_util.h +++ b/base/test/test_file_util.h @@ -35,6 +35,9 @@ bool CopyRecursiveDirNoCache(const FilePath& source_dir, bool VolumeSupportsADS(const FilePath& path); // Returns true if the ZoneIdentifier is correctly set to "Internet" (3). +// Note that this function must be called from the same process as +// the one that set the zone identifier. I.e. don't use it in UI/automation +// based tests. bool HasInternetZoneIdentifier(const FilePath& full_path); #endif // defined(OS_WIN) diff --git a/base/test/test_file_util_win.cc b/base/test/test_file_util_win.cc index 7ca7e84..9820c42 100644 --- a/base/test/test_file_util_win.cc +++ b/base/test/test_file_util_win.cc @@ -194,41 +194,27 @@ bool VolumeSupportsADS(const FilePath& path) { } // Return whether the ZoneIdentifier is correctly set to "Internet" (3) +// Only returns a valid result when called from same process as the +// one that (was supposed to have) set the zone identifier. 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++) { - base::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; + FilePath zone_path(full_path.value() + L":Zone.Identifier"); + std::string zone_path_contents; + if (!file_util::ReadFileToString(zone_path, &zone_path_contents)) + return false; + + static const char kInternetIdentifier[] = "[ZoneTransfer]\nZoneId=3"; + static const size_t kInternetIdentifierSize = + // Don't include null byte in size of identifier. + arraysize(kInternetIdentifier) - 1; + + // Our test is that the initial characters match the above, and that + // the character after the end of the string is eof, null, or newline; any + // of those three will invoke the Window Finder cautionary dialog. + return ((zone_path_contents.compare(0, kInternetIdentifierSize, + kInternetIdentifier) == 0) && + (kInternetIdentifierSize == zone_path_contents.length() || + zone_path_contents[kInternetIdentifierSize] == '\0' || + zone_path_contents[kInternetIdentifierSize] == '\n')); } } // namespace file_util |