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

Unified Diff: chrome/test/functional/downloads.py

Issue 5781006: Fix pyauto downloads tests to trigger dangerous downloads to match expectation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 10 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/functional/PYAUTO_TESTS ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/functional/downloads.py
diff --git a/chrome/test/functional/downloads.py b/chrome/test/functional/downloads.py
index 355f6767579df38411bc8a0f1acb0146336bae5d..715ee57f375377efade29f31bfc31f9851a0ae8a 100644
--- a/chrome/test/functional/downloads.py
+++ b/chrome/test/functional/downloads.py
@@ -61,7 +61,7 @@ class DownloadsTest(pyauto.PyUITest):
os.path.exists(crdownload) and os.remove(crdownload)
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')
if self.IsMac():
return os.path.join(sub_path, 'invalid-dummy.dmg')
@@ -158,12 +158,10 @@ class DownloadsTest(pyauto.PyUITest):
def testSaveDangerousFile(self):
"""Verify that we can download and save a dangerous file."""
file_path = self._GetDangerousDownload()
- file_url = self.GetFileURLForPath(file_path)
downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(),
os.path.basename(file_path))
self._ClearLocalDownloadState(downloaded_pkg)
-
- self.DownloadAndWaitForStart(file_url)
+ self._TriggerUnsafeDownload(os.path.basename(file_path))
self.PerformActionOnDownload(self._GetDownloadId(),
'save_dangerous_download')
self.WaitForDownloadToComplete(downloaded_pkg)
@@ -176,12 +174,10 @@ class DownloadsTest(pyauto.PyUITest):
def testDeclineDangerousDownload(self):
"""Verify that we can decline dangerous downloads"""
file_path = self._GetDangerousDownload()
- file_url = self.GetFileURLForPath(file_path)
downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(),
os.path.basename(file_path))
self._ClearLocalDownloadState(downloaded_pkg)
-
- self.DownloadAndWaitForStart(file_url)
+ self._TriggerUnsafeDownload(os.path.basename(file_path))
self.PerformActionOnDownload(self._GetDownloadId(),
'decline_dangerous_download')
self.assertFalse(os.path.exists(downloaded_pkg))
@@ -307,14 +303,41 @@ class DownloadsTest(pyauto.PyUITest):
os.path.join(temp_dir, filename)))
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.
kkania 2010/12/14 01:14:48 How about navigating to an already existing file:/
Nirnimesh 2010/12/14 01:17:20 I think the current approach better mirrors the us
+ 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):
"""Verify that unsafe file should not show up on session restart."""
file_path = self._GetDangerousDownload()
- file_url = self.GetFileURLForPath(file_path)
downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(),
os.path.basename(file_path))
self._ClearLocalDownloadState(downloaded_pkg)
- self.DownloadAndWaitForStart(file_url)
+ self._TriggerUnsafeDownload(os.path.basename(file_path))
self.assertTrue(self.IsDownloadShelfVisible())
# Restart the browser and assert that the download was removed.
self.RestartBrowser(clear_profile=False)
« no previous file with comments | « chrome/test/functional/PYAUTO_TESTS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698