Skip to content
Snippets Groups Projects
Commit e92f3dff authored by nirnimesh@chromium.org's avatar nirnimesh@chromium.org
Browse files

Fix pyauto downloads tests to trigger dangerous downloads to match expectation

It used to be possible to navigate to a dnagerous file type to trigger its
download. Not anymore. Now all downloads where the user initiated it (by
navigating to a URL or clicking on a link) are not marked unsafe even for
unsafe filetypes.

Update the tests to trigger dangerous downloads by navigating to a file which
in turn triggers the dangerous files to download.

BUG=66081, 57875

Review URL: http://codereview.chromium.org/5781006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69093 0039d316-1c4b-4281-b951-d872f2087c98
parent 4d816991
No related merge requests found
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Test Download Multiple files Infobar.</title>
<script>
function RedirectToDangerous() {
filename = window.location.search.split("?")[1];
window.location.href = filename;
}
</script>
</head>
<body onload="RedirectToDangerous();">
<h2>
Should trigger download for an unsafe/dangerous file type.<br>
Filename should be passed as query string.
</h2>
</body>
</html>
...@@ -80,9 +80,6 @@ ...@@ -80,9 +80,6 @@
# crbug.com/50481, crbug.com/54942 # crbug.com/50481, crbug.com/54942
'-downloads.DownloadsTest.testZip', '-downloads.DownloadsTest.testZip',
'-downloads.DownloadsTest.testRemoveDownload', '-downloads.DownloadsTest.testRemoveDownload',
# Unsafe downloads tests broken. crbug.com/66081
'-downloads.DownloadsTest.testDeclineDangerousDownload',
'-downloads.DownloadsTest.testNoUnsafeDownloadsOnRestart',
'-prefs.PrefsTest.testDownloadDirPref', '-prefs.PrefsTest.testDownloadDirPref',
# crbug.com/64269 # crbug.com/64269
'-passwords.PasswordTest.testDisplayAndSavePasswordInfobar', '-passwords.PasswordTest.testDisplayAndSavePasswordInfobar',
...@@ -95,10 +92,6 @@ ...@@ -95,10 +92,6 @@
# codesign tests should run *after* signing. crbug.com/50481 # codesign tests should run *after* signing. crbug.com/50481
'-codesign', '-codesign',
'-content.ContentTest.testThreeWindows', # crbug.com/47457 '-content.ContentTest.testThreeWindows', # crbug.com/47457
'-downloads.DownloadsTest.testSaveDangerousFile', # crbug.com/57875
# Unsafe downloads tests broken. crbug.com/66081
'-downloads.DownloadsTest.testDeclineDangerousDownload',
'-downloads.DownloadsTest.testNoUnsafeDownloadsOnRestart',
], ],
'linux': [ # linux != chromeos 'linux': [ # linux != chromeos
...@@ -107,10 +100,6 @@ ...@@ -107,10 +100,6 @@
'-content.ContentTest.testThreeWindows', # crbug.com/47457 '-content.ContentTest.testThreeWindows', # crbug.com/47457
# crbug.com/64664 # crbug.com/64664
'-databases.DatabasesTest.testReloadActiveTab', '-databases.DatabasesTest.testReloadActiveTab',
# Unsafe downloads tests broken. crbug.com/66081
'-downloads.DownloadsTest.testDeclineDangerousDownload',
'-downloads.DownloadsTest.testNoUnsafeDownloadsOnRestart',
'-downloads.DownloadsTest.testSaveDangerousFile',
# crbug.com/64269 # crbug.com/64269
'-passwords.PasswordTest.testDisplayAndSavePasswordInfobar', '-passwords.PasswordTest.testDisplayAndSavePasswordInfobar',
], ],
...@@ -148,8 +137,5 @@ ...@@ -148,8 +137,5 @@
'-crash_reporter.CrashReporterTest.testRendererCrash', '-crash_reporter.CrashReporterTest.testRendererCrash',
# crbug.com/64269 # crbug.com/64269
'-passwords.PasswordTest.testDisplayAndSavePasswordInfobar', '-passwords.PasswordTest.testDisplayAndSavePasswordInfobar',
# Unsafe downloads tests broken. crbug.com/66081
'-downloads.DownloadsTest.testDeclineDangerousDownload',
'-downloads.DownloadsTest.testSaveDangerousFile',
], ],
} }
...@@ -61,7 +61,7 @@ class DownloadsTest(pyauto.PyUITest): ...@@ -61,7 +61,7 @@ class DownloadsTest(pyauto.PyUITest):
os.path.exists(crdownload) and os.remove(crdownload) os.path.exists(crdownload) and os.remove(crdownload)
def _GetDangerousDownload(self): def _GetDangerousDownload(self):
"""Returns the file url for a dangerous download for this OS.""" """Returns the file path for a dangerous download for this OS."""
sub_path = os.path.join(self.DataDir(), 'downloads', 'dangerous') sub_path = os.path.join(self.DataDir(), 'downloads', 'dangerous')
if self.IsMac(): if self.IsMac():
return os.path.join(sub_path, 'invalid-dummy.dmg') return os.path.join(sub_path, 'invalid-dummy.dmg')
...@@ -158,12 +158,10 @@ class DownloadsTest(pyauto.PyUITest): ...@@ -158,12 +158,10 @@ class DownloadsTest(pyauto.PyUITest):
def testSaveDangerousFile(self): def testSaveDangerousFile(self):
"""Verify that we can download and save a dangerous file.""" """Verify that we can download and save a dangerous file."""
file_path = self._GetDangerousDownload() file_path = self._GetDangerousDownload()
file_url = self.GetFileURLForPath(file_path)
downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(),
os.path.basename(file_path)) os.path.basename(file_path))
self._ClearLocalDownloadState(downloaded_pkg) self._ClearLocalDownloadState(downloaded_pkg)
self._TriggerUnsafeDownload(os.path.basename(file_path))
self.DownloadAndWaitForStart(file_url)
self.PerformActionOnDownload(self._GetDownloadId(), self.PerformActionOnDownload(self._GetDownloadId(),
'save_dangerous_download') 'save_dangerous_download')
self.WaitForDownloadToComplete(downloaded_pkg) self.WaitForDownloadToComplete(downloaded_pkg)
...@@ -176,12 +174,10 @@ class DownloadsTest(pyauto.PyUITest): ...@@ -176,12 +174,10 @@ class DownloadsTest(pyauto.PyUITest):
def testDeclineDangerousDownload(self): def testDeclineDangerousDownload(self):
"""Verify that we can decline dangerous downloads""" """Verify that we can decline dangerous downloads"""
file_path = self._GetDangerousDownload() file_path = self._GetDangerousDownload()
file_url = self.GetFileURLForPath(file_path)
downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(),
os.path.basename(file_path)) os.path.basename(file_path))
self._ClearLocalDownloadState(downloaded_pkg) self._ClearLocalDownloadState(downloaded_pkg)
self._TriggerUnsafeDownload(os.path.basename(file_path))
self.DownloadAndWaitForStart(file_url)
self.PerformActionOnDownload(self._GetDownloadId(), self.PerformActionOnDownload(self._GetDownloadId(),
'decline_dangerous_download') 'decline_dangerous_download')
self.assertFalse(os.path.exists(downloaded_pkg)) self.assertFalse(os.path.exists(downloaded_pkg))
...@@ -307,14 +303,41 @@ class DownloadsTest(pyauto.PyUITest): ...@@ -307,14 +303,41 @@ class DownloadsTest(pyauto.PyUITest):
os.path.join(temp_dir, filename))) os.path.join(temp_dir, filename)))
os.path.exists(downloaded_file) and os.remove(downloaded_file) os.path.exists(downloaded_file) and os.remove(downloaded_file)
def _TriggerUnsafeDownload(self, filename, tab_index=0, windex=0):
"""Trigger download of an unsafe/dangerous filetype.
Files explictly requested by the user (like navigating to a package, or
clicking on a link) aren't marked unsafe.
Only the ones where the user didn't directly initiate a download are
marked unsafe.
Navigates to download-dangerous.html which triggers the download.
Waits until the download starts.
Args:
filename: the name of the file to trigger the download.
This should exist in the 'dangerous' directory.
tab_index: tab index. Default 0.
windex: window index. Default 0.
"""
dangerous_dir = os.path.join(
self.DataDir(), 'downloads', 'dangerous')
assert os.path.isfile(os.path.join(dangerous_dir, filename))
file_url = self.GetFileURLForDataPath(os.path.join(
dangerous_dir, 'download-dangerous.html')) + '?' + filename
num_downloads = len(self.GetDownloadsInfo().Downloads())
self.NavigateToURL(file_url, windex, tab_index)
# It might take a while for the download to kick in, hold on until then.
self.assertTrue(self.WaitUntil(
lambda: len(self.GetDownloadsInfo().Downloads()) == num_downloads + 1))
def testNoUnsafeDownloadsOnRestart(self): def testNoUnsafeDownloadsOnRestart(self):
"""Verify that unsafe file should not show up on session restart.""" """Verify that unsafe file should not show up on session restart."""
file_path = self._GetDangerousDownload() file_path = self._GetDangerousDownload()
file_url = self.GetFileURLForPath(file_path)
downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(),
os.path.basename(file_path)) os.path.basename(file_path))
self._ClearLocalDownloadState(downloaded_pkg) self._ClearLocalDownloadState(downloaded_pkg)
self.DownloadAndWaitForStart(file_url) self._TriggerUnsafeDownload(os.path.basename(file_path))
self.assertTrue(self.IsDownloadShelfVisible()) self.assertTrue(self.IsDownloadShelfVisible())
# Restart the browser and assert that the download was removed. # Restart the browser and assert that the download was removed.
self.RestartBrowser(clear_profile=False) self.RestartBrowser(clear_profile=False)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment