Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg)) | 138 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg)) |
| 139 | 139 |
| 140 def testZipInIncognito(self): | 140 def testZipInIncognito(self): |
| 141 """Download and verify a zip in incognito window.""" | 141 """Download and verify a zip in incognito window.""" |
| 142 test_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads') | 142 test_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads') |
| 143 file_path = os.path.join(test_dir, 'a_zip_file.zip') | 143 file_path = os.path.join(test_dir, 'a_zip_file.zip') |
| 144 file_url = self.GetFileURLForPath(file_path) | 144 file_url = self.GetFileURLForPath(file_path) |
| 145 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), | 145 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), |
| 146 'a_zip_file.zip') | 146 'a_zip_file.zip') |
| 147 self._ClearLocalDownloadState(downloaded_pkg) | 147 self._ClearLocalDownloadState(downloaded_pkg) |
| 148 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) | |
| 148 | 149 |
| 149 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) # open incognito window | 150 # Trigger download and wait in new incognito window. |
| 150 # Downloads from incognito window do not figure in GetDownloadsInfo() | 151 self.DownloadAndWaitForStart(file_url, 1) |
| 151 # since the download manager's list doesn't contain it. | 152 self.WaitForAllDownloadsToComplete(1) |
| 152 # Using WaitUntil is the only resort. | 153 incognito_downloads = self.GetDownloadsInfo(1).Downloads() |
| 153 self.NavigateToURL(file_url, 1, 0) | 154 |
| 154 self.assertTrue(self.WaitUntil(lambda: os.path.exists(downloaded_pkg))) | 155 # Verify that download info exists in the correct profile. |
| 156 self.assertEqual(len(incognito_downloads), 1) | |
| 155 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg)) | 157 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg)) |
| 156 self.assertTrue(self.IsDownloadShelfVisible(1)) | 158 self.assertTrue(self.IsDownloadShelfVisible(1)) |
| 157 | 159 |
| 158 def testSaveDangerousFile(self): | 160 def testSaveDangerousFile(self): |
| 159 """Verify that we can download and save a dangerous file.""" | 161 """Verify that we can download and save a dangerous file.""" |
| 160 file_path = self._GetDangerousDownload() | 162 file_path = self._GetDangerousDownload() |
| 161 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), | 163 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), |
| 162 os.path.basename(file_path)) | 164 os.path.basename(file_path)) |
| 163 self._ClearLocalDownloadState(downloaded_pkg) | 165 self._ClearLocalDownloadState(downloaded_pkg) |
| 164 self._TriggerUnsafeDownload(os.path.basename(file_path)) | 166 self._TriggerUnsafeDownload(os.path.basename(file_path)) |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 525 file_path = self._MakeFile(2**24) | 527 file_path = self._MakeFile(2**24) |
| 526 file_url = self.GetFileURLForPath(file_path) | 528 file_url = self.GetFileURLForPath(file_path) |
| 527 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), | 529 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), |
| 528 os.path.basename(file_path)) | 530 os.path.basename(file_path)) |
| 529 os.path.exists(downloaded_pkg) and os.remove(downloaded_pkg) | 531 os.path.exists(downloaded_pkg) and os.remove(downloaded_pkg) |
| 530 self.DownloadAndWaitForStart(file_url) | 532 self.DownloadAndWaitForStart(file_url) |
| 531 id = self._GetDownloadId() | 533 id = self._GetDownloadId() |
| 532 self.PerformActionOnDownload(id, 'open') | 534 self.PerformActionOnDownload(id, 'open') |
| 533 self.WaitForAllDownloadsToComplete() | 535 self.WaitForAllDownloadsToComplete() |
| 534 unzip_file_name = downloaded_pkg + '.cpgz' | 536 unzip_file_name = downloaded_pkg + '.cpgz' |
| 535 # Verify that the file was correctly downloaded | 537 # Verify that the file was correctly downloaded. |
| 536 self.assertTrue(self.WaitUntil(lambda: os.path.exists(unzip_file_name)), | 538 self.assertTrue(self.WaitUntil(lambda: os.path.exists(unzip_file_name)), |
| 537 'Unzipped folder %s missing.' % unzip_file_name) | 539 'Unzipped folder %s missing.' % unzip_file_name) |
| 538 self.assertTrue(os.path.exists(downloaded_pkg), | 540 self.assertTrue(os.path.exists(downloaded_pkg), |
| 539 'Downloaded file %s missing.' % downloaded_pkg) | 541 'Downloaded file %s missing.' % downloaded_pkg) |
| 540 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg), | 542 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg), |
| 541 'Downloaded file %s does not match original' % | 543 'Downloaded file %s does not match original' % |
| 542 downloaded_pkg) | 544 downloaded_pkg) |
| 543 os.path.exists(file_path) and os.remove(file_path) | 545 os.path.exists(file_path) and os.remove(file_path) |
| 544 os.path.exists(downloaded_pkg) and os.remove(downloaded_pkg) | 546 os.path.exists(downloaded_pkg) and os.remove(downloaded_pkg) |
| 545 os.path.exists(unzip_file_name) and os.remove(unzip_file_name) | 547 os.path.exists(unzip_file_name) and os.remove(unzip_file_name) |
| 546 | 548 |
| 547 def testDownloadPercentage(self): | 549 def testDownloadPercentage(self): |
| 548 """Verify that during downloading, % values increases, | 550 """Verify that during downloading, % values increases, |
| 549 and once download is over, % value is 100""" | 551 and once download is over, % value is 100""" |
| 550 file_path = self._MakeFile(2**24) | 552 file_path = self._MakeFile(2**24) |
| 551 file_url = self.GetFileURLForPath(file_path) | 553 file_url = self.GetFileURLForPath(file_path) |
| 552 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), | 554 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), |
| 553 os.path.basename(file_path)) | 555 os.path.basename(file_path)) |
| 554 os.path.exists(downloaded_pkg) and os.remove(downloaded_pkg) | 556 os.path.exists(downloaded_pkg) and os.remove(downloaded_pkg) |
| 555 self.DownloadAndWaitForStart(file_url) | 557 self.DownloadAndWaitForStart(file_url) |
| 556 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), | 558 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), |
| 557 os.path.basename(file_path)) | 559 os.path.basename(file_path)) |
| 558 downloads = self.GetDownloadsInfo().Downloads() | 560 downloads = self.GetDownloadsInfo().Downloads() |
| 559 old_percentage = downloads[0]['PercentComplete'] | 561 old_percentage = downloads[0]['PercentComplete'] |
| 560 def _PercentInc(): | 562 def _PercentInc(): |
| 561 percent = self.GetDownloadsInfo().Downloads()[0]['PercentComplete'] | 563 percent = self.GetDownloadsInfo().Downloads()[0]['PercentComplete'] |
| 562 return old_percentage == 100 or percent > old_percentage, | 564 return old_percentage == 100 or percent > old_percentage, |
| 563 self.assertTrue(self.WaitUntil(_PercentInc), | 565 self.assertTrue(self.WaitUntil(_PercentInc), |
| 564 msg='Download percentage value is not increasing') | 566 msg='Download percentage value is not increasing') |
| 565 # Once download is completed, percentage is 100 | 567 # Once download is completed, percentage is 100. |
| 566 self.WaitForAllDownloadsToComplete() | 568 self.WaitForAllDownloadsToComplete() |
| 567 downloads = self.GetDownloadsInfo().Downloads() | 569 downloads = self.GetDownloadsInfo().Downloads() |
| 568 self.assertEqual(downloads[0]['PercentComplete'], 100, | 570 self.assertEqual(downloads[0]['PercentComplete'], 100, |
| 569 'Download percentage should be 100 after download completed') | 571 'Download percentage should be 100 after download completed') |
| 570 os.path.exists(file_path) and os.remove(file_path) | 572 os.path.exists(file_path) and os.remove(file_path) |
| 571 os.path.exists(downloaded_pkg) and os.remove(downloaded_pkg) | 573 os.path.exists(downloaded_pkg) and os.remove(downloaded_pkg) |
| 572 | 574 |
| 573 def testDownloadIncognitoAndRegular(self): | 575 def testDownloadIncognitoAndRegular(self): |
| 574 """Download the same zip file in regular and incognito window and | 576 """Download the same zip file in regular and incognito window and |
| 575 verify that it downloaded correctly with same file name appended with | 577 verify that it downloaded correctly with same file name appended with |
| 576 counter for the second download in regular window. | 578 counter for the second download in regular window. |
| 577 """ | 579 """ |
| 578 test_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads') | 580 test_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads') |
| 579 file_path = os.path.join(test_dir, 'a_zip_file.zip') | 581 file_path = os.path.join(test_dir, 'a_zip_file.zip') |
| 580 file_url = self.GetFileURLForPath(file_path) | 582 file_url = self.GetFileURLForPath(file_path) |
| 581 downloaded_pkg_regul = os.path.join(self.GetDownloadDirectory().value(), | 583 downloaded_pkg_regul = os.path.join(self.GetDownloadDirectory().value(), |
| 582 'a_zip_file.zip') | 584 'a_zip_file.zip') |
| 583 downloaded_pkg_incog = os.path.join(self.GetDownloadDirectory().value(), | 585 downloaded_pkg_incog = os.path.join(self.GetDownloadDirectory().value(), |
| 584 'a_zip_file (1).zip') | 586 'a_zip_file (1).zip') |
| 585 self._ClearLocalDownloadState(downloaded_pkg_regul) | 587 self._ClearLocalDownloadState(downloaded_pkg_regul) |
| 586 self._ClearLocalDownloadState(downloaded_pkg_incog) | 588 self._ClearLocalDownloadState(downloaded_pkg_incog) |
| 587 self.NavigateToURL(file_url, 0, 0) | 589 |
| 590 self.DownloadAndWaitForStart(file_url, 0) | |
| 591 self.WaitForAllDownloadsToComplete(0) | |
| 592 | |
| 588 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) | 593 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) |
| 589 self.NavigateToURL(file_url, 1, 0) | 594 self.DownloadAndWaitForStart(file_url, 1) |
| 590 self.WaitForAllDownloadsToComplete() | 595 self.WaitForAllDownloadsToComplete(1) |
| 591 | 596 |
| 592 # Verify download in regular Window. | 597 # Verify download in regular window. |
| 593 self.assertTrue(os.path.exists(downloaded_pkg_regul)) | 598 self.assertTrue(os.path.exists(downloaded_pkg_regul)) |
| 594 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg_regul)) | 599 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg_regul)) |
| 595 | 600 |
| 596 # Verify download in Incognito Window. | 601 # Verify download in incognito window. |
| 597 # WaitForAllDownloadsToComplete does not wait for incognito downloads | 602 # WaitForAllDownloadsToComplete is flaky for this test case. |
|
Nirnimesh
2011/01/15 02:28:04
Please create a bug and cc rdsmith on it. Referenc
| |
| 598 self.assertTrue(self.WaitUntil( | 603 self.assertTrue(self.WaitUntil( |
| 599 lambda: os.path.exists(downloaded_pkg_incog))) | 604 lambda: os.path.exists(downloaded_pkg_incog))) |
| 600 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg_incog)) | 605 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg_incog)) |
| 601 | 606 |
| 602 | 607 |
| 603 if __name__ == '__main__': | 608 if __name__ == '__main__': |
| 604 pyauto_functional.Main() | 609 pyauto_functional.Main() |
| OLD | NEW |