OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2011 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 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 """Download and verify a zip in incognito window.""" | 129 """Download and verify a zip in incognito window.""" |
130 test_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads') | 130 test_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads') |
131 file_path = os.path.join(test_dir, 'a_zip_file.zip') | 131 file_path = os.path.join(test_dir, 'a_zip_file.zip') |
132 file_url = self.GetFileURLForPath(file_path) | 132 file_url = self.GetFileURLForPath(file_path) |
133 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), | 133 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), |
134 'a_zip_file.zip') | 134 'a_zip_file.zip') |
135 self._ClearLocalDownloadState(downloaded_pkg) | 135 self._ClearLocalDownloadState(downloaded_pkg) |
136 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) | 136 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) |
137 | 137 |
138 # Trigger download and wait in new incognito window. | 138 # Trigger download and wait in new incognito window. |
139 self.DownloadAndWaitForStart(file_url, 1) | 139 self.DownloadAndWaitForStart(file_url, windex=1) |
140 self.WaitForAllDownloadsToComplete(1) | 140 self.WaitForAllDownloadsToComplete(windex=1) |
141 # Remove next line when WaitForAllDownloadsToComplete can reliably wait | |
142 # for downloads in incognito window. crbug.com/69738 | |
143 self.WaitForDownloadToComplete(downloaded_pkg) | |
144 incognito_downloads = self.GetDownloadsInfo(1).Downloads() | 141 incognito_downloads = self.GetDownloadsInfo(1).Downloads() |
145 | 142 |
146 # Verify that download info exists in the correct profile. | 143 # Verify that download info exists in the correct profile. |
147 self.assertEqual(len(incognito_downloads), 1) | 144 self.assertEqual(len(incognito_downloads), 1) |
148 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg), | 145 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg), |
149 msg='%s (size %d) and %s (size %d) do not match' % ( | 146 msg='%s (size %d) and %s (size %d) do not match' % ( |
150 file_path, os.path.getsize(file_path), | 147 file_path, os.path.getsize(file_path), |
151 downloaded_pkg, os.path.getsize(downloaded_pkg))) | 148 downloaded_pkg, os.path.getsize(downloaded_pkg))) |
152 self.assertTrue(self.IsDownloadShelfVisible(1)) | 149 self.assertTrue(self.IsDownloadShelfVisible(1)) |
153 | 150 |
154 def testSaveDangerousFile(self): | 151 def testSaveDangerousFile(self): |
155 """Verify that we can download and save a dangerous file.""" | 152 """Verify that we can download and save a dangerous file.""" |
156 file_path = self._GetDangerousDownload() | 153 file_path = self._GetDangerousDownload() |
157 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), | 154 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), |
158 os.path.basename(file_path)) | 155 os.path.basename(file_path)) |
159 self._ClearLocalDownloadState(downloaded_pkg) | 156 self._ClearLocalDownloadState(downloaded_pkg) |
160 self._TriggerUnsafeDownload(os.path.basename(file_path)) | 157 self._TriggerUnsafeDownload(os.path.basename(file_path)) |
161 self.PerformActionOnDownload(self._GetDownloadId(), | 158 self.PerformActionOnDownload(self._GetDownloadId(), |
162 'save_dangerous_download') | 159 'save_dangerous_download') |
163 self.WaitForDownloadToComplete(downloaded_pkg) | 160 self.WaitForAllDownloadsToComplete() |
164 | 161 |
165 # Verify that the file was downloaded. | 162 # Verify that the file was downloaded. |
166 self.assertTrue(os.path.exists(downloaded_pkg)) | 163 self.assertTrue(os.path.exists(downloaded_pkg)) |
167 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg)) | 164 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg)) |
168 self._DeleteAfterShutdown(downloaded_pkg) | 165 self._DeleteAfterShutdown(downloaded_pkg) |
169 | 166 |
170 def testDeclineDangerousDownload(self): | 167 def testDeclineDangerousDownload(self): |
171 """Verify that we can decline dangerous downloads""" | 168 """Verify that we can decline dangerous downloads""" |
172 file_path = self._GetDangerousDownload() | 169 file_path = self._GetDangerousDownload() |
173 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), | 170 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), |
174 os.path.basename(file_path)) | 171 os.path.basename(file_path)) |
175 self._ClearLocalDownloadState(downloaded_pkg) | 172 self._ClearLocalDownloadState(downloaded_pkg) |
176 self._TriggerUnsafeDownload(os.path.basename(file_path)) | 173 self._TriggerUnsafeDownload(os.path.basename(file_path)) |
177 self.PerformActionOnDownload(self._GetDownloadId(), | 174 self.PerformActionOnDownload(self._GetDownloadId(), |
178 'decline_dangerous_download') | 175 'decline_dangerous_download') |
179 self.assertFalse(os.path.exists(downloaded_pkg)) | 176 self.assertFalse(os.path.exists(downloaded_pkg)) |
180 self.assertFalse(self.GetDownloadsInfo().Downloads()) | 177 self.assertFalse(self.GetDownloadsInfo().Downloads()) |
181 self.assertFalse(self.IsDownloadShelfVisible()) | 178 self.assertFalse(self.IsDownloadShelfVisible()) |
182 | 179 |
183 def testRemoveDownload(self): | 180 def testRemoveDownload(self): |
184 """Verify that we can remove a download.""" | 181 """Verify that we can remove a download.""" |
185 file_url = self.GetFileURLForDataPath('downloads', 'a_zip_file.zip') | 182 file_url = self.GetFileURLForDataPath('downloads', 'a_zip_file.zip') |
186 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), | 183 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), |
187 'a_zip_file.zip') | 184 'a_zip_file.zip') |
188 self._ClearLocalDownloadState(downloaded_pkg) | 185 self._ClearLocalDownloadState(downloaded_pkg) |
189 | 186 |
190 self.DownloadAndWaitForStart(file_url) | 187 self.DownloadAndWaitForStart(file_url) |
| 188 self.WaitForAllDownloadsToComplete() |
191 self.PerformActionOnDownload(self._GetDownloadId(), 'remove') | 189 self.PerformActionOnDownload(self._GetDownloadId(), 'remove') |
192 | 190 |
193 # The download is removed from downloads, but not from the disk. | 191 # The download is removed from downloads, but not from the disk. |
194 self.assertFalse(self.GetDownloadsInfo().Downloads()) | 192 self.assertFalse(self.GetDownloadsInfo().Downloads()) |
195 self.assertTrue(os.path.exists(downloaded_pkg)) | 193 self.assertTrue(os.path.exists(downloaded_pkg)) |
196 self._DeleteAfterShutdown(downloaded_pkg) | 194 self._DeleteAfterShutdown(downloaded_pkg) |
197 | 195 |
198 def testBigZip(self): | 196 def testBigZip(self): |
199 """Verify that we can download a 1GB file. | 197 """Verify that we can download a 1GB file. |
200 | 198 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 self.assertFalse(os.path.exists(downloaded_pkg)) | 385 self.assertFalse(os.path.exists(downloaded_pkg)) |
388 | 386 |
389 def testDownloadsPersistence(self): | 387 def testDownloadsPersistence(self): |
390 """Verify that download history persists on session restart.""" | 388 """Verify that download history persists on session restart.""" |
391 test_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads') | 389 test_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads') |
392 file_url = self.GetFileURLForPath(os.path.join(test_dir, 'a_zip_file.zip')) | 390 file_url = self.GetFileURLForPath(os.path.join(test_dir, 'a_zip_file.zip')) |
393 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), | 391 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), |
394 'a_zip_file.zip') | 392 'a_zip_file.zip') |
395 self._ClearLocalDownloadState(downloaded_pkg) | 393 self._ClearLocalDownloadState(downloaded_pkg) |
396 self.DownloadAndWaitForStart(file_url) | 394 self.DownloadAndWaitForStart(file_url) |
397 self.WaitForDownloadToComplete(downloaded_pkg) | 395 self.WaitForAllDownloadsToComplete() |
398 downloads = self.GetDownloadsInfo().Downloads() | 396 downloads = self.GetDownloadsInfo().Downloads() |
399 self.assertEqual(1, len(downloads)) | 397 self.assertEqual(1, len(downloads)) |
400 self.assertEqual('a_zip_file.zip', downloads[0]['file_name']) | 398 self.assertEqual('a_zip_file.zip', downloads[0]['file_name']) |
401 file_url = downloads[0]['url'] | 399 file_url = downloads[0]['url'] |
402 self.RestartBrowser(clear_profile=False) | 400 self.RestartBrowser(clear_profile=False) |
403 # Trigger the download service to get loaded after restart. | 401 # Trigger the download service to get loaded after restart. |
404 self.NavigateToURL('chrome://downloads/') | 402 self.NavigateToURL('chrome://downloads/') |
405 # Verify that there's no download shelf anymore. | 403 # Verify that there's no download shelf anymore. |
406 self.assertFalse(self.IsDownloadShelfVisible(), | 404 self.assertFalse(self.IsDownloadShelfVisible(), |
407 'Download shelf persisted browser restart.') | 405 'Download shelf persisted browser restart.') |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 file_path = os.path.join(test_dir, 'a_zip_file.zip') | 478 file_path = os.path.join(test_dir, 'a_zip_file.zip') |
481 file_url = self.GetFileURLForPath(file_path) | 479 file_url = self.GetFileURLForPath(file_path) |
482 downloaded_pkg_regul = os.path.join(self.GetDownloadDirectory().value(), | 480 downloaded_pkg_regul = os.path.join(self.GetDownloadDirectory().value(), |
483 'a_zip_file.zip') | 481 'a_zip_file.zip') |
484 downloaded_pkg_incog = os.path.join(self.GetDownloadDirectory().value(), | 482 downloaded_pkg_incog = os.path.join(self.GetDownloadDirectory().value(), |
485 'a_zip_file (1).zip') | 483 'a_zip_file (1).zip') |
486 self._ClearLocalDownloadState(downloaded_pkg_regul) | 484 self._ClearLocalDownloadState(downloaded_pkg_regul) |
487 self._ClearLocalDownloadState(downloaded_pkg_incog) | 485 self._ClearLocalDownloadState(downloaded_pkg_incog) |
488 | 486 |
489 self.DownloadAndWaitForStart(file_url, 0) | 487 self.DownloadAndWaitForStart(file_url, 0) |
490 self.WaitForAllDownloadsToComplete(0) | 488 self.WaitForAllDownloadsToComplete(windex=0) |
491 | 489 |
492 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) | 490 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) |
493 self.DownloadAndWaitForStart(file_url, 1) | 491 self.DownloadAndWaitForStart(file_url, 1) |
494 self.WaitForAllDownloadsToComplete(1) | 492 self.WaitForAllDownloadsToComplete(windex=1) |
495 | 493 |
496 # Verify download in regular window. | 494 # Verify download in regular window. |
497 self.assertTrue(os.path.exists(downloaded_pkg_regul)) | 495 self.assertTrue(os.path.exists(downloaded_pkg_regul)) |
498 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg_regul)) | 496 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg_regul)) |
499 | 497 |
500 # Verify download in incognito window. | 498 # Verify download in incognito window. |
501 # bug 69738 WaitForAllDownloadsToComplete is flaky for this test case. | 499 # bug 69738 WaitForAllDownloadsToComplete is flaky for this test case. |
502 # Using extra WaitUntil until this is resolved. | 500 # Using extra WaitUntil until this is resolved. |
503 self.assertTrue(self.WaitUntil( | 501 self.assertTrue(self.WaitUntil( |
504 lambda: os.path.exists(downloaded_pkg_incog))) | 502 lambda: os.path.exists(downloaded_pkg_incog))) |
505 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg_incog)) | 503 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg_incog)) |
506 | 504 |
507 | 505 |
508 if __name__ == '__main__': | 506 if __name__ == '__main__': |
509 pyauto_functional.Main() | 507 pyauto_functional.Main() |
OLD | NEW |