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

Side by Side Diff: functional/downloads.py

Issue 6354004: Fixing search_engines.SearchEnginesTest.testDiscoverSearchEngine (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/test/
Patch Set: '' Created 9 years, 11 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | functional/search_engines.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import commands 6 import commands
7 import filecmp 7 import filecmp
8 import logging 8 import logging
9 import os 9 import os
10 import shutil 10 import shutil
11 import sys 11 import sys
12 import tempfile 12 import tempfile
13 import urllib 13 import urllib
14 14
15 import pyauto_functional # Must be imported before pyauto 15 import pyauto_functional # Must be imported before pyauto
16 import pyauto 16 import pyauto
17 import pyauto_utils 17 import pyauto_utils
18 import test_utils
18 19
19 20
20 class DownloadsTest(pyauto.PyUITest): 21 class DownloadsTest(pyauto.PyUITest):
21 """TestCase for Downloads.""" 22 """TestCase for Downloads."""
22 23
23 def setUp(self): 24 def setUp(self):
24 pyauto.PyUITest.setUp(self) 25 pyauto.PyUITest.setUp(self)
25 # Record all entries in the download dir 26 # Record all entries in the download dir
26 download_dir = self.GetDownloadDirectory().value() 27 download_dir = self.GetDownloadDirectory().value()
27 self._existing_downloads = [] 28 self._existing_downloads = []
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 """Make a file on-the-fly with the given size. Returns the path to the 87 """Make a file on-the-fly with the given size. Returns the path to the
87 file. 88 file.
88 """ 89 """
89 fd, file_path = tempfile.mkstemp(suffix='.zip', prefix='file-downloads-') 90 fd, file_path = tempfile.mkstemp(suffix='.zip', prefix='file-downloads-')
90 os.lseek(fd, size, 0) 91 os.lseek(fd, size, 0)
91 os.write(fd, 'a') 92 os.write(fd, 'a')
92 os.close(fd) 93 os.close(fd)
93 logging.debug('Created temporary file %s of size %d' % (file_path, size)) 94 logging.debug('Created temporary file %s of size %d' % (file_path, size))
94 return file_path 95 return file_path
95 96
96 def _CallFunctionWithNewTimeout(self, new_timeout, function):
97 """Sets the timeout to |new_timeout| and calls |function|.
98
99 This method resets the timeout before returning.
100 """
101 timeout_changer = pyauto.PyUITest.CmdExecutionTimeoutChanger(
102 self, new_timeout)
103 logging.info('Automation execution timeout has been changed to %d. '
104 'If the timeout is large the test might appear to hang.'
105 % new_timeout)
106 function()
107 del timeout_changer
108
109 def _GetAllDownloadIDs(self): 97 def _GetAllDownloadIDs(self):
110 """Return a list of all download ids.""" 98 """Return a list of all download ids."""
111 return [download['id'] for download in self.GetDownloadsInfo().Downloads()] 99 return [download['id'] for download in self.GetDownloadsInfo().Downloads()]
112 100
113 def testNoDownloadWaitingNeeded(self): 101 def testNoDownloadWaitingNeeded(self):
114 """Make sure "wait for downloads" returns quickly if we have none.""" 102 """Make sure "wait for downloads" returns quickly if we have none."""
115 self.WaitForAllDownloadsToComplete() 103 self.WaitForAllDownloadsToComplete()
116 104
117 def testZip(self): 105 def testZip(self):
118 """Download a zip and verify that it downloaded correctly. 106 """Download a zip and verify that it downloaded correctly.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 file_path = self._MakeFile(2**30) 202 file_path = self._MakeFile(2**30)
215 self._DeleteAfterShutdown(file_path) 203 self._DeleteAfterShutdown(file_path)
216 file_url = self.GetFileURLForPath(file_path) 204 file_url = self.GetFileURLForPath(file_path)
217 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), 205 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(),
218 os.path.basename(file_path)) 206 os.path.basename(file_path))
219 self._ClearLocalDownloadState(downloaded_pkg) 207 self._ClearLocalDownloadState(downloaded_pkg)
220 self.DownloadAndWaitForStart(file_url) 208 self.DownloadAndWaitForStart(file_url)
221 self._DeleteAfterShutdown(downloaded_pkg) 209 self._DeleteAfterShutdown(downloaded_pkg)
222 # Waiting for big file to download might exceed automation timeout. 210 # Waiting for big file to download might exceed automation timeout.
223 # Temporarily increase the automation timeout. 211 # Temporarily increase the automation timeout.
224 self._CallFunctionWithNewTimeout(4 * 60 * 1000, # 4 min. 212 test_utils.CallFunctionWithNewTimeout(self, 4 * 60 * 1000, # 4 min.
225 self.WaitForAllDownloadsToComplete) 213 self.WaitForAllDownloadsToComplete)
226 # Verify that the file was correctly downloaded 214 # Verify that the file was correctly downloaded
227 self.assertTrue(os.path.exists(downloaded_pkg), 215 self.assertTrue(os.path.exists(downloaded_pkg),
228 'Downloaded file %s missing.' % downloaded_pkg) 216 'Downloaded file %s missing.' % downloaded_pkg)
229 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg), 217 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg),
230 'Downloaded file %s does not match original' % 218 'Downloaded file %s does not match original' %
231 downloaded_pkg) 219 downloaded_pkg)
232 220
233 def testFileRenaming(self): 221 def testFileRenaming(self):
234 """Test file renaming when downloading a already-existing filename.""" 222 """Test file renaming when downloading a already-existing filename."""
235 test_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads') 223 test_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads')
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 self.assertTrue(pause_dict['is_paused']) 362 self.assertTrue(pause_dict['is_paused'])
375 self.assertTrue(pause_dict['state'] == 'IN_PROGRESS') 363 self.assertTrue(pause_dict['state'] == 'IN_PROGRESS')
376 364
377 # Resume the download and assert it is not paused. 365 # Resume the download and assert it is not paused.
378 resume_dict = self.PerformActionOnDownload(self._GetDownloadId(), 366 resume_dict = self.PerformActionOnDownload(self._GetDownloadId(),
379 'toggle_pause') 367 'toggle_pause')
380 self.assertFalse(resume_dict['is_paused']) 368 self.assertFalse(resume_dict['is_paused'])
381 369
382 # Waiting for big file to download might exceed automation timeout. 370 # Waiting for big file to download might exceed automation timeout.
383 # Temporarily increase the automation timeout. 371 # Temporarily increase the automation timeout.
384 self._CallFunctionWithNewTimeout(2 * 60 * 1000, # 2 min. 372 test_utils.CallFunctionWithNewTimeout(self, 2 * 60 * 1000, # 2 min.
385 self.WaitForAllDownloadsToComplete) 373 self.WaitForAllDownloadsToComplete)
386 374
387 # Verify that the file was correctly downloaded after pause and resume. 375 # Verify that the file was correctly downloaded after pause and resume.
388 self.assertTrue(os.path.exists(downloaded_pkg), 376 self.assertTrue(os.path.exists(downloaded_pkg),
389 'Downloaded file %s missing.' % downloaded_pkg) 377 'Downloaded file %s missing.' % downloaded_pkg)
390 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg), 378 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg),
391 'Downloaded file %s does not match original' % 379 'Downloaded file %s does not match original' %
392 downloaded_pkg) 380 downloaded_pkg)
393 381
394 def testCancelDownload(self): 382 def testCancelDownload(self):
395 """Verify that we can cancel a download.""" 383 """Verify that we can cancel a download."""
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 return 459 return
472 file_path = os.path.join(self.DataDir(), 'downloads', 'a_zip_file.zip') 460 file_path = os.path.join(self.DataDir(), 'downloads', 'a_zip_file.zip')
473 file_url = self.GetFileURLForPath(file_path) 461 file_url = self.GetFileURLForPath(file_path)
474 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), 462 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(),
475 os.path.basename(file_path)) 463 os.path.basename(file_path))
476 os.path.exists(downloaded_pkg) and os.remove(downloaded_pkg) 464 os.path.exists(downloaded_pkg) and os.remove(downloaded_pkg)
477 self.DownloadAndWaitForStart(file_url) 465 self.DownloadAndWaitForStart(file_url)
478 self.WaitForAllDownloadsToComplete() 466 self.WaitForAllDownloadsToComplete()
479 id = self._GetDownloadId() 467 id = self._GetDownloadId()
480 self.PerformActionOnDownload(id, 'toggle_open_files_like_this') 468 self.PerformActionOnDownload(id, 'toggle_open_files_like_this')
481 os.path.exists(downloaded_pkg) and os.remove(downloaded_pkg)
482 # Retesting the flag we set 469 # Retesting the flag we set
483 file_url2 = self.GetFileURLForDataPath(os.path.join('zip', 'test.zip')) 470 file_url2 = self.GetFileURLForDataPath(os.path.join('zip', 'test.zip'))
484 unzip_path = os.path.join(self.GetDownloadDirectory().value(), 471 unzip_path = os.path.join(self.GetDownloadDirectory().value(),
485 'test', 'foo') 472 'test', 'foo')
486 os.path.exists(downloaded_pkg) and os.remove(downloaded_pkg)
487 os.path.exists(unzip_path) and pyauto_utils.RemovePath(unzip_path) 473 os.path.exists(unzip_path) and pyauto_utils.RemovePath(unzip_path)
488 self.DownloadAndWaitForStart(file_url2) 474 self.DownloadAndWaitForStart(file_url2)
489 self.WaitForAllDownloadsToComplete() 475 self.WaitForAllDownloadsToComplete()
490 # When the downloaded zip gets 'opened', a_file.txt will become available. 476 # When the downloaded zip gets 'opened', a_file.txt will become available.
491 self.assertTrue(self.WaitUntil(lambda: os.path.exists(unzip_path)), 477 self.assertTrue(self.WaitUntil(lambda: os.path.exists(unzip_path)),
492 'Did not open the filetype') 478 'Did not open the filetype')
493 os.path.exists(downloaded_pkg) and os.remove(downloaded_pkg) 479 os.path.exists(downloaded_pkg) and os.remove(downloaded_pkg)
494 os.path.exists(unzip_path) and pyauto_utils.RemovePath(unzip_path) 480 os.path.exists(unzip_path) and pyauto_utils.RemovePath(unzip_path)
495 481
496 def testExtendedAttributesOnMac(self): 482 def testExtendedAttributesOnMac(self):
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 581
596 # Verify download in Incognito Window. 582 # Verify download in Incognito Window.
597 # WaitForAllDownloadsToComplete does not wait for incognito downloads 583 # WaitForAllDownloadsToComplete does not wait for incognito downloads
598 self.assertTrue(self.WaitUntil( 584 self.assertTrue(self.WaitUntil(
599 lambda: os.path.exists(downloaded_pkg_incog))) 585 lambda: os.path.exists(downloaded_pkg_incog)))
600 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg_incog)) 586 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg_incog))
601 587
602 588
603 if __name__ == '__main__': 589 if __name__ == '__main__':
604 pyauto_functional.Main() 590 pyauto_functional.Main()
OLDNEW
« no previous file with comments | « no previous file | functional/search_engines.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698