diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-03 22:35:12 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-03 22:35:12 +0000 |
commit | 7d8bbd0bd7452ef7ae9157688210030554517629 (patch) | |
tree | 52e90dab49fd79d5e7b8960db429e0dc660eb3c3 /chrome/browser/download/download_uitest.cc | |
parent | 5bc862f799bb4e8292c685a04a06fd0fa3ae72db (diff) | |
download | chromium_src-7d8bbd0bd7452ef7ae9157688210030554517629.zip chromium_src-7d8bbd0bd7452ef7ae9157688210030554517629.tar.gz chromium_src-7d8bbd0bd7452ef7ae9157688210030554517629.tar.bz2 |
Sleep and poll (yuck!) in DownloadTest while verifying Internet ZoneIdentifier.
There seems to be no other reliable way to do that due to Windows file semantics.
This should decrease the flakiness.
TEST=Covered by ui_tests.
http://crbug.com/20809
Review URL: http://codereview.chromium.org/192010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25390 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download/download_uitest.cc')
-rw-r--r-- | chrome/browser/download/download_uitest.cc | 62 |
1 files changed, 41 insertions, 21 deletions
diff --git a/chrome/browser/download/download_uitest.cc b/chrome/browser/download/download_uitest.cc index 39fb8b4..46f212f 100644 --- a/chrome/browser/download/download_uitest.cc +++ b/chrome/browser/download/download_uitest.cc @@ -49,26 +49,6 @@ bool VolumeSupportsADS(const std::wstring path) { return false; } - -// Checks if the ZoneIdentifier is correctly set to "Internet" (3) -void CheckZoneIdentifier(const std::wstring full_path) { - const DWORD kShare = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE; - - std::wstring path = full_path + L":Zone.Identifier"; - HANDLE file = CreateFile(path.c_str(), GENERIC_READ, kShare, NULL, - OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); - ASSERT_TRUE(INVALID_HANDLE_VALUE != file); - - char buffer[100] = {0}; - DWORD read = 0; - ASSERT_TRUE(ReadFile(file, buffer, 100, &read, NULL)); - CloseHandle(file); - - const char kIdentifier[] = "[ZoneTransfer]\nZoneId=3"; - ASSERT_EQ(arraysize(kIdentifier), read); - - ASSERT_EQ(0, strcmp(kIdentifier, buffer)); -} #endif // defined(OS_WIN) class DownloadTest : public UITest { @@ -150,6 +130,46 @@ class DownloadTest : public UITest { EXPECT_FALSE(file_util::PathExists(download_path)); } +#if defined(OS_WIN) + // Checks if the ZoneIdentifier is correctly set to "Internet" (3) + void CheckZoneIdentifier(const std::wstring full_path) { + const DWORD kShare = FILE_SHARE_READ | + FILE_SHARE_WRITE | + FILE_SHARE_DELETE; + + std::wstring path = full_path + L":Zone.Identifier"; + HANDLE file = CreateFile(path.c_str(), GENERIC_READ, kShare, NULL, + OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + ASSERT_TRUE(INVALID_HANDLE_VALUE != file); + + // 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 < 10; i++) { + PlatformThread::Sleep(sleep_timeout_ms()); + + 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; + } + + FAIL() << "Could not detect Internet ZoneIndentifier"; + } +#endif // defined(OS_WIN) + FilePath download_prefix_; }; @@ -203,7 +223,7 @@ TEST_F(DownloadTest, NoDownload) { // Download a 0-size file with a content-disposition header, verify that the // download tab opened and the file exists as the filename specified in the // header. This also ensures we properly handle empty file downloads. -TEST_F(DownloadTest, DISABLED_ContentDisposition) { +TEST_F(DownloadTest, ContentDisposition) { FilePath file(FILE_PATH_LITERAL("download-test3.gif")); FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); |