| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 """ | 208 """ |
| 209 # Create a 1 GB file on the fly | 209 # Create a 1 GB file on the fly |
| 210 file_path = self._MakeFile(2**30) | 210 file_path = self._MakeFile(2**30) |
| 211 self._DeleteAfterShutdown(file_path) | 211 self._DeleteAfterShutdown(file_path) |
| 212 file_url = self.GetFileURLForPath(file_path) | 212 file_url = self.GetFileURLForPath(file_path) |
| 213 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), | 213 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), |
| 214 os.path.basename(file_path)) | 214 os.path.basename(file_path)) |
| 215 self._ClearLocalDownloadState(downloaded_pkg) | 215 self._ClearLocalDownloadState(downloaded_pkg) |
| 216 self.DownloadAndWaitForStart(file_url) | 216 self.DownloadAndWaitForStart(file_url) |
| 217 self._DeleteAfterShutdown(downloaded_pkg) | 217 self._DeleteAfterShutdown(downloaded_pkg) |
| 218 # Waiting for big file to download might exceed automation timeout. | 218 self.WaitForAllDownloadsToComplete(timeout=self.large_test_timeout_ms()); |
| 219 # Temporarily increase the automation timeout. | |
| 220 test_utils.CallFunctionWithNewTimeout(self, 4 * 60 * 1000, # 4 min. | |
| 221 self.WaitForAllDownloadsToComplete) | |
| 222 # Verify that the file was correctly downloaded | 219 # Verify that the file was correctly downloaded |
| 223 self.assertTrue(os.path.exists(downloaded_pkg), | 220 self.assertTrue(os.path.exists(downloaded_pkg), |
| 224 'Downloaded file %s missing.' % downloaded_pkg) | 221 'Downloaded file %s missing.' % downloaded_pkg) |
| 225 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg), | 222 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg), |
| 226 'Downloaded file %s does not match original' % | 223 'Downloaded file %s does not match original' % |
| 227 downloaded_pkg) | 224 downloaded_pkg) |
| 228 | 225 |
| 229 def testFileRenaming(self): | 226 def testFileRenaming(self): |
| 230 """Test file renaming when downloading a already-existing filename.""" | 227 """Test file renaming when downloading a already-existing filename.""" |
| 231 test_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads') | 228 test_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads') |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 logging.info('The download completed before pause. Stopping test.') | 349 logging.info('The download completed before pause. Stopping test.') |
| 353 return | 350 return |
| 354 | 351 |
| 355 self.assertTrue(pause_dict['is_paused']) | 352 self.assertTrue(pause_dict['is_paused']) |
| 356 self.assertTrue(pause_dict['state'] == 'IN_PROGRESS') | 353 self.assertTrue(pause_dict['state'] == 'IN_PROGRESS') |
| 357 | 354 |
| 358 # Resume the download and assert it is not paused. | 355 # Resume the download and assert it is not paused. |
| 359 resume_dict = self.PerformActionOnDownload(self._GetDownloadId(), | 356 resume_dict = self.PerformActionOnDownload(self._GetDownloadId(), |
| 360 'toggle_pause') | 357 'toggle_pause') |
| 361 self.assertFalse(resume_dict['is_paused']) | 358 self.assertFalse(resume_dict['is_paused']) |
| 362 | 359 self.WaitForAllDownloadsToComplete(timeout=self.large_test_timeout_ms()); |
| 363 # Waiting for big file to download might exceed automation timeout. | |
| 364 # Temporarily increase the automation timeout. | |
| 365 test_utils.CallFunctionWithNewTimeout(self, 2 * 60 * 1000, # 2 min. | |
| 366 self.WaitForAllDownloadsToComplete) | |
| 367 | 360 |
| 368 # Verify that the file was correctly downloaded after pause and resume. | 361 # Verify that the file was correctly downloaded after pause and resume. |
| 369 self.assertTrue(os.path.exists(downloaded_pkg), | 362 self.assertTrue(os.path.exists(downloaded_pkg), |
| 370 'Downloaded file %s missing.' % downloaded_pkg) | 363 'Downloaded file %s missing.' % downloaded_pkg) |
| 371 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg), | 364 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg), |
| 372 'Downloaded file %s does not match original' % | 365 'Downloaded file %s does not match original' % |
| 373 downloaded_pkg) | 366 downloaded_pkg) |
| 374 | 367 |
| 375 def testCancelDownload(self): | 368 def testCancelDownload(self): |
| 376 """Verify that we can cancel a download.""" | 369 """Verify that we can cancel a download.""" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 # Verify download in incognito window. | 571 # Verify download in incognito window. |
| 579 # bug 69738 WaitForAllDownloadsToComplete is flaky for this test case. | 572 # bug 69738 WaitForAllDownloadsToComplete is flaky for this test case. |
| 580 # Using extra WaitUntil until this is resolved. | 573 # Using extra WaitUntil until this is resolved. |
| 581 self.assertTrue(self.WaitUntil( | 574 self.assertTrue(self.WaitUntil( |
| 582 lambda: os.path.exists(downloaded_pkg_incog))) | 575 lambda: os.path.exists(downloaded_pkg_incog))) |
| 583 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg_incog)) | 576 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg_incog)) |
| 584 | 577 |
| 585 | 578 |
| 586 if __name__ == '__main__': | 579 if __name__ == '__main__': |
| 587 pyauto_functional.Main() | 580 pyauto_functional.Main() |
| OLD | NEW |