Chromium Code Reviews| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 os.close(fd) | 93 os.close(fd) |
| 94 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)) |
| 95 return file_path | 95 return file_path |
| 96 | 96 |
| 97 def _GetAllDownloadIDs(self): | 97 def _GetAllDownloadIDs(self): |
| 98 """Return a list of all download ids.""" | 98 """Return a list of all download ids.""" |
| 99 return [download['id'] for download in self.GetDownloadsInfo().Downloads()] | 99 return [download['id'] for download in self.GetDownloadsInfo().Downloads()] |
| 100 | 100 |
| 101 def testNoDownloadWaitingNeeded(self): | 101 def testNoDownloadWaitingNeeded(self): |
| 102 """Make sure "wait for downloads" returns quickly if we have none.""" | 102 """Make sure "wait for downloads" returns quickly if we have none.""" |
| 103 self.WaitForAllDownloadsToComplete() | 103 self.WaitForAllDownloadsToComplete([]) |
|
Nirnimesh
2011/08/08 17:26:17
See my notes in pyauto.py
This should default to [
dennis_jeffrey
2011/08/08 22:29:51
Done.
| |
| 104 | 104 |
| 105 def testZip(self): | 105 def testZip(self): |
| 106 """Download a zip and verify that it downloaded correctly. | 106 """Download a zip and verify that it downloaded correctly. |
| 107 Also verify that the download shelf showed up. | 107 Also verify that the download shelf showed up. |
| 108 """ | 108 """ |
| 109 test_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads') | 109 test_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads') |
| 110 file_path = os.path.join(test_dir, 'a_zip_file.zip') | 110 file_path = os.path.join(test_dir, 'a_zip_file.zip') |
| 111 file_url = self.GetFileURLForPath(file_path) | 111 file_url = self.GetFileURLForPath(file_path) |
| 112 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), | 112 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), |
| 113 'a_zip_file.zip') | 113 'a_zip_file.zip') |
| 114 self._ClearLocalDownloadState(downloaded_pkg) | 114 self._ClearLocalDownloadState(downloaded_pkg) |
| 115 | 115 |
| 116 pre_download_ids = [x['id'] for x in self.GetDownloadsInfo().Downloads()] | |
| 116 self.DownloadAndWaitForStart(file_url) | 117 self.DownloadAndWaitForStart(file_url) |
| 117 | 118 |
| 118 # Wait for the download to finish. | 119 # Wait for the download to finish. |
| 119 self.WaitForAllDownloadsToComplete() | 120 self.WaitForAllDownloadsToComplete(pre_download_ids) |
| 120 | 121 |
| 121 # Verify that the download shelf is visible | 122 # Verify that the download shelf is visible |
| 122 self.assertTrue(self.IsDownloadShelfVisible()) | 123 self.assertTrue(self.IsDownloadShelfVisible()) |
| 123 | 124 |
| 124 # Verify that the file was correctly downloaded | 125 # Verify that the file was correctly downloaded |
| 125 self.assertTrue(os.path.exists(downloaded_pkg)) | 126 self.assertTrue(os.path.exists(downloaded_pkg)) |
| 126 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg)) | 127 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg)) |
| 127 | 128 |
| 128 def testZipInIncognito(self): | 129 def testZipInIncognito(self): |
| 129 """Download and verify a zip in incognito window.""" | 130 """Download and verify a zip in incognito window.""" |
| 130 test_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads') | 131 test_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads') |
| 131 file_path = os.path.join(test_dir, 'a_zip_file.zip') | 132 file_path = os.path.join(test_dir, 'a_zip_file.zip') |
| 132 file_url = self.GetFileURLForPath(file_path) | 133 file_url = self.GetFileURLForPath(file_path) |
| 133 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), | 134 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), |
| 134 'a_zip_file.zip') | 135 'a_zip_file.zip') |
| 135 self._ClearLocalDownloadState(downloaded_pkg) | 136 self._ClearLocalDownloadState(downloaded_pkg) |
| 136 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) | 137 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) |
| 137 | 138 |
| 138 # Trigger download and wait in new incognito window. | 139 # Trigger download and wait in new incognito window. |
| 139 self.DownloadAndWaitForStart(file_url, 1) | 140 pre_download_ids = [x['id'] |
| 140 self.WaitForAllDownloadsToComplete(1) | 141 for x in self.GetDownloadsInfo(windex=1).Downloads()] |
| 141 # Remove next line when WaitForAllDownloadsToComplete can reliably wait | 142 self.DownloadAndWaitForStart(file_url, windex=1) |
| 142 # for downloads in incognito window. crbug.com/69738 | 143 self.WaitForAllDownloadsToComplete(pre_download_ids, windex=1) |
| 143 self.WaitForDownloadToComplete(downloaded_pkg) | |
| 144 incognito_downloads = self.GetDownloadsInfo(1).Downloads() | 144 incognito_downloads = self.GetDownloadsInfo(1).Downloads() |
| 145 | 145 |
| 146 # Verify that download info exists in the correct profile. | 146 # Verify that download info exists in the correct profile. |
| 147 self.assertEqual(len(incognito_downloads), 1) | 147 self.assertEqual(len(incognito_downloads), 1) |
| 148 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg), | 148 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg), |
| 149 msg='%s (size %d) and %s (size %d) do not match' % ( | 149 msg='%s (size %d) and %s (size %d) do not match' % ( |
| 150 file_path, os.path.getsize(file_path), | 150 file_path, os.path.getsize(file_path), |
| 151 downloaded_pkg, os.path.getsize(downloaded_pkg))) | 151 downloaded_pkg, os.path.getsize(downloaded_pkg))) |
| 152 self.assertTrue(self.IsDownloadShelfVisible(1)) | 152 self.assertTrue(self.IsDownloadShelfVisible(1)) |
| 153 | 153 |
| 154 def testSaveDangerousFile(self): | 154 def testSaveDangerousFile(self): |
| 155 """Verify that we can download and save a dangerous file.""" | 155 """Verify that we can download and save a dangerous file.""" |
| 156 file_path = self._GetDangerousDownload() | 156 file_path = self._GetDangerousDownload() |
| 157 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), | 157 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), |
| 158 os.path.basename(file_path)) | 158 os.path.basename(file_path)) |
| 159 self._ClearLocalDownloadState(downloaded_pkg) | 159 self._ClearLocalDownloadState(downloaded_pkg) |
| 160 pre_download_ids = [x['id'] for x in self.GetDownloadsInfo().Downloads()] | |
| 160 self._TriggerUnsafeDownload(os.path.basename(file_path)) | 161 self._TriggerUnsafeDownload(os.path.basename(file_path)) |
| 161 self.PerformActionOnDownload(self._GetDownloadId(), | 162 self.PerformActionOnDownload(self._GetDownloadId(), |
| 162 'save_dangerous_download') | 163 'save_dangerous_download') |
| 163 self.WaitForDownloadToComplete(downloaded_pkg) | 164 self.WaitForAllDownloadsToComplete(pre_download_ids) |
| 164 | 165 |
| 165 # Verify that the file was downloaded. | 166 # Verify that the file was downloaded. |
| 166 self.assertTrue(os.path.exists(downloaded_pkg)) | 167 self.assertTrue(os.path.exists(downloaded_pkg)) |
| 167 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg)) | 168 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg)) |
| 168 self._DeleteAfterShutdown(downloaded_pkg) | 169 self._DeleteAfterShutdown(downloaded_pkg) |
| 169 | 170 |
| 170 def testDeclineDangerousDownload(self): | 171 def testDeclineDangerousDownload(self): |
| 171 """Verify that we can decline dangerous downloads""" | 172 """Verify that we can decline dangerous downloads""" |
| 172 file_path = self._GetDangerousDownload() | 173 file_path = self._GetDangerousDownload() |
| 173 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), | 174 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), |
| 174 os.path.basename(file_path)) | 175 os.path.basename(file_path)) |
| 175 self._ClearLocalDownloadState(downloaded_pkg) | 176 self._ClearLocalDownloadState(downloaded_pkg) |
| 176 self._TriggerUnsafeDownload(os.path.basename(file_path)) | 177 self._TriggerUnsafeDownload(os.path.basename(file_path)) |
| 177 self.PerformActionOnDownload(self._GetDownloadId(), | 178 self.PerformActionOnDownload(self._GetDownloadId(), |
| 178 'decline_dangerous_download') | 179 'decline_dangerous_download') |
| 179 self.assertFalse(os.path.exists(downloaded_pkg)) | 180 self.assertFalse(os.path.exists(downloaded_pkg)) |
| 180 self.assertFalse(self.GetDownloadsInfo().Downloads()) | 181 self.assertFalse(self.GetDownloadsInfo().Downloads()) |
| 181 self.assertFalse(self.IsDownloadShelfVisible()) | 182 self.assertFalse(self.IsDownloadShelfVisible()) |
| 182 | 183 |
| 183 def testRemoveDownload(self): | 184 def testRemoveDownload(self): |
| 184 """Verify that we can remove a download.""" | 185 """Verify that we can remove a download.""" |
| 185 file_url = self.GetFileURLForDataPath('downloads', 'a_zip_file.zip') | 186 file_url = self.GetFileURLForDataPath('downloads', 'a_zip_file.zip') |
| 186 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), | 187 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), |
| 187 'a_zip_file.zip') | 188 'a_zip_file.zip') |
| 188 self._ClearLocalDownloadState(downloaded_pkg) | 189 self._ClearLocalDownloadState(downloaded_pkg) |
| 189 | 190 |
| 191 pre_download_ids = [x['id'] for x in self.GetDownloadsInfo().Downloads()] | |
| 190 self.DownloadAndWaitForStart(file_url) | 192 self.DownloadAndWaitForStart(file_url) |
| 193 self.WaitForAllDownloadsToComplete(pre_download_ids) | |
| 191 self.PerformActionOnDownload(self._GetDownloadId(), 'remove') | 194 self.PerformActionOnDownload(self._GetDownloadId(), 'remove') |
| 192 | 195 |
| 193 # The download is removed from downloads, but not from the disk. | 196 # The download is removed from downloads, but not from the disk. |
| 194 self.assertFalse(self.GetDownloadsInfo().Downloads()) | 197 self.assertFalse(self.GetDownloadsInfo().Downloads()) |
| 195 self.assertTrue(os.path.exists(downloaded_pkg)) | 198 self.assertTrue(os.path.exists(downloaded_pkg)) |
| 196 self._DeleteAfterShutdown(downloaded_pkg) | 199 self._DeleteAfterShutdown(downloaded_pkg) |
| 197 | 200 |
| 198 def testBigZip(self): | 201 def testBigZip(self): |
| 199 """Verify that we can download a 1GB file. | 202 """Verify that we can download a 1GB file. |
| 200 | 203 |
| 201 This test needs 2 GB of free space, 1 GB for the original zip file and | 204 This test needs 2 GB of free space, 1 GB for the original zip file and |
| 202 another for the downloaded one. | 205 another for the downloaded one. |
| 203 | 206 |
| 204 Note: This test increases automation timeout to 4 min. Things might seem | 207 Note: This test increases automation timeout to 4 min. Things might seem |
| 205 to hang. | 208 to hang. |
| 206 """ | 209 """ |
| 207 # Create a 1 GB file on the fly | 210 # Create a 1 GB file on the fly |
| 208 file_path = self._MakeFile(2**30) | 211 file_path = self._MakeFile(2**30) |
| 209 self._DeleteAfterShutdown(file_path) | 212 self._DeleteAfterShutdown(file_path) |
| 210 file_url = self.GetFileURLForPath(file_path) | 213 file_url = self.GetFileURLForPath(file_path) |
| 211 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), | 214 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), |
| 212 os.path.basename(file_path)) | 215 os.path.basename(file_path)) |
| 213 self._ClearLocalDownloadState(downloaded_pkg) | 216 self._ClearLocalDownloadState(downloaded_pkg) |
| 217 pre_download_ids = [x['id'] for x in self.GetDownloadsInfo().Downloads()] | |
| 214 self.DownloadAndWaitForStart(file_url) | 218 self.DownloadAndWaitForStart(file_url) |
| 215 self._DeleteAfterShutdown(downloaded_pkg) | 219 self._DeleteAfterShutdown(downloaded_pkg) |
| 216 self.WaitForAllDownloadsToComplete(timeout=self.large_test_timeout_ms()); | 220 self.WaitForAllDownloadsToComplete(pre_download_ids, |
| 221 timeout=self.large_test_timeout_ms()); | |
| 217 # Verify that the file was correctly downloaded | 222 # Verify that the file was correctly downloaded |
| 218 self.assertTrue(os.path.exists(downloaded_pkg), | 223 self.assertTrue(os.path.exists(downloaded_pkg), |
| 219 'Downloaded file %s missing.' % downloaded_pkg) | 224 'Downloaded file %s missing.' % downloaded_pkg) |
| 220 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg), | 225 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg), |
| 221 'Downloaded file %s does not match original' % | 226 'Downloaded file %s does not match original' % |
| 222 downloaded_pkg) | 227 downloaded_pkg) |
| 223 | 228 |
| 224 def testFileRenaming(self): | 229 def testFileRenaming(self): |
| 225 """Test file renaming when downloading a already-existing filename.""" | 230 """Test file renaming when downloading a already-existing filename.""" |
| 226 test_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads') | 231 test_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads') |
| 227 file_url = 'file://%s' % os.path.join(test_dir, 'a_zip_file.zip') | 232 file_url = 'file://%s' % os.path.join(test_dir, 'a_zip_file.zip') |
| 228 download_dir = self.GetDownloadDirectory().value() | 233 download_dir = self.GetDownloadDirectory().value() |
| 229 | 234 |
| 235 pre_download_ids = [x['id'] for x in self.GetDownloadsInfo().Downloads()] | |
| 230 num_times = 5 | 236 num_times = 5 |
| 231 assert num_times > 1, 'needs to be > 1 to work' | 237 assert num_times > 1, 'needs to be > 1 to work' |
| 232 renamed_files = [] | 238 renamed_files = [] |
| 233 for i in range(num_times): | 239 for i in range(num_times): |
| 234 expected_filename = os.path.join(download_dir, 'a_zip_file.zip') | 240 expected_filename = os.path.join(download_dir, 'a_zip_file.zip') |
| 235 if i > 0: # Files after first download are renamed. | 241 if i > 0: # Files after first download are renamed. |
| 236 expected_filename = os.path.join(download_dir, | 242 expected_filename = os.path.join(download_dir, |
| 237 'a_zip_file (%d).zip' % i) | 243 'a_zip_file (%d).zip' % i) |
| 238 renamed_files.append(expected_filename) | 244 renamed_files.append(expected_filename) |
| 239 self._ClearLocalDownloadState(expected_filename) | 245 self._ClearLocalDownloadState(expected_filename) |
| 240 self.DownloadAndWaitForStart(file_url) | 246 self.DownloadAndWaitForStart(file_url) |
| 241 | 247 |
| 242 self.WaitForAllDownloadsToComplete() | 248 self.WaitForAllDownloadsToComplete(pre_download_ids) |
| 243 | 249 |
| 244 # Verify that all files exist and have the right name | 250 # Verify that all files exist and have the right name |
| 245 for filename in renamed_files: | 251 for filename in renamed_files: |
| 246 self.assertTrue(os.path.exists(filename)) | 252 self.assertTrue(os.path.exists(filename)) |
| 247 self._DeleteAfterShutdown(filename) | 253 self._DeleteAfterShutdown(filename) |
| 248 | 254 |
| 249 def testCrazyFilenames(self): | 255 def testCrazyFilenames(self): |
| 250 """Test downloading with filenames containing special chars. | 256 """Test downloading with filenames containing special chars. |
| 251 | 257 |
| 252 The files are created on the fly and cleaned after use. | 258 The files are created on the fly and cleaned after use. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 265 # Temp dir for hosting crazy filenames. | 271 # Temp dir for hosting crazy filenames. |
| 266 temp_dir = tempfile.mkdtemp(prefix='download') | 272 temp_dir = tempfile.mkdtemp(prefix='download') |
| 267 self._DeleteAfterShutdown(unicode(temp_dir)) | 273 self._DeleteAfterShutdown(unicode(temp_dir)) |
| 268 # Windows has a dual nature dealing with unicode filenames. | 274 # Windows has a dual nature dealing with unicode filenames. |
| 269 # While the files are internally saved as unicode, there's a non-unicode | 275 # While the files are internally saved as unicode, there's a non-unicode |
| 270 # aware API that returns a locale-dependent coding on the true unicode | 276 # aware API that returns a locale-dependent coding on the true unicode |
| 271 # filenames. This messes up things. | 277 # filenames. This messes up things. |
| 272 # Filesystem-interfacing functions like os.listdir() need to | 278 # Filesystem-interfacing functions like os.listdir() need to |
| 273 # be given unicode strings to "do the right thing" on win. | 279 # be given unicode strings to "do the right thing" on win. |
| 274 # Ref: http://boodebr.org/main/python/all-about-python-and-unicode | 280 # Ref: http://boodebr.org/main/python/all-about-python-and-unicode |
| 281 pre_download_ids = [x['id'] for x in self.GetDownloadsInfo().Downloads()] | |
| 275 for filename in crazy_filenames: # filename is unicode. | 282 for filename in crazy_filenames: # filename is unicode. |
| 276 utf8_filename = filename.encode('utf-8') | 283 utf8_filename = filename.encode('utf-8') |
| 277 file_path = os.path.join(temp_dir, utf8_filename) | 284 file_path = os.path.join(temp_dir, utf8_filename) |
| 278 _CreateFile(os.path.join(temp_dir, filename)) # unicode file. | 285 _CreateFile(os.path.join(temp_dir, filename)) # unicode file. |
| 279 file_url = self.GetFileURLForPath(file_path) | 286 file_url = self.GetFileURLForPath(file_path) |
| 280 downloaded_file = os.path.join(download_dir, filename) | 287 downloaded_file = os.path.join(download_dir, filename) |
| 281 self._ClearLocalDownloadState(downloaded_file) | 288 self._ClearLocalDownloadState(downloaded_file) |
| 282 self.DownloadAndWaitForStart(file_url) | 289 self.DownloadAndWaitForStart(file_url) |
| 283 self.WaitForAllDownloadsToComplete() | 290 self.WaitForAllDownloadsToComplete(pre_download_ids) |
| 284 | 291 |
| 285 # Verify downloads. | 292 # Verify downloads. |
| 286 downloads = self.GetDownloadsInfo().Downloads() | 293 downloads = self.GetDownloadsInfo().Downloads() |
| 287 self.assertEqual(len(downloads), len(crazy_filenames)) | 294 self.assertEqual(len(downloads), len(crazy_filenames)) |
| 288 | 295 |
| 289 for filename in crazy_filenames: | 296 for filename in crazy_filenames: |
| 290 downloaded_file = os.path.join(download_dir, filename) | 297 downloaded_file = os.path.join(download_dir, filename) |
| 291 self.assertTrue(os.path.exists(downloaded_file)) | 298 self.assertTrue(os.path.exists(downloaded_file)) |
| 292 self.assertTrue( # Verify file contents. | 299 self.assertTrue( # Verify file contents. |
| 293 self._EqualFileContents(downloaded_file, | 300 self._EqualFileContents(downloaded_file, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 Note: This test increases automation timeout to 2 min. Things might seem | 335 Note: This test increases automation timeout to 2 min. Things might seem |
| 329 to hang. | 336 to hang. |
| 330 """ | 337 """ |
| 331 # Create a 250 MB file on the fly | 338 # Create a 250 MB file on the fly |
| 332 file_path = self._MakeFile(2**28) | 339 file_path = self._MakeFile(2**28) |
| 333 | 340 |
| 334 file_url = self.GetFileURLForPath(file_path) | 341 file_url = self.GetFileURLForPath(file_path) |
| 335 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), | 342 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), |
| 336 os.path.basename(file_path)) | 343 os.path.basename(file_path)) |
| 337 self._ClearLocalDownloadState(downloaded_pkg) | 344 self._ClearLocalDownloadState(downloaded_pkg) |
| 345 pre_download_ids = [x['id'] for x in self.GetDownloadsInfo().Downloads()] | |
| 338 self.DownloadAndWaitForStart(file_url) | 346 self.DownloadAndWaitForStart(file_url) |
| 339 | 347 |
| 340 self._DeleteAfterShutdown(downloaded_pkg) | 348 self._DeleteAfterShutdown(downloaded_pkg) |
| 341 self._DeleteAfterShutdown(file_path) | 349 self._DeleteAfterShutdown(file_path) |
| 342 | 350 |
| 343 # Pause the download and assert that it is paused. | 351 # Pause the download and assert that it is paused. |
| 344 pause_dict = self.PerformActionOnDownload(self._GetDownloadId(), | 352 pause_dict = self.PerformActionOnDownload(self._GetDownloadId(), |
| 345 'toggle_pause') | 353 'toggle_pause') |
| 346 if pause_dict['state'] == 'COMPLETE': | 354 if pause_dict['state'] == 'COMPLETE': |
| 347 logging.info('The download completed before pause. Stopping test.') | 355 logging.info('The download completed before pause. Stopping test.') |
| 348 return | 356 return |
| 349 | 357 |
| 350 self.assertTrue(pause_dict['is_paused']) | 358 self.assertTrue(pause_dict['is_paused']) |
| 351 self.assertTrue(pause_dict['state'] == 'IN_PROGRESS') | 359 self.assertTrue(pause_dict['state'] == 'IN_PROGRESS') |
| 352 | 360 |
| 353 # Resume the download and assert it is not paused. | 361 # Resume the download and assert it is not paused. |
| 354 resume_dict = self.PerformActionOnDownload(self._GetDownloadId(), | 362 resume_dict = self.PerformActionOnDownload(self._GetDownloadId(), |
| 355 'toggle_pause') | 363 'toggle_pause') |
| 356 self.assertFalse(resume_dict['is_paused']) | 364 self.assertFalse(resume_dict['is_paused']) |
| 357 self.WaitForAllDownloadsToComplete(timeout=self.large_test_timeout_ms()); | 365 self.WaitForAllDownloadsToComplete(pre_download_ids, |
| 366 timeout=self.large_test_timeout_ms()); | |
| 358 | 367 |
| 359 # Verify that the file was correctly downloaded after pause and resume. | 368 # Verify that the file was correctly downloaded after pause and resume. |
| 360 self.assertTrue(os.path.exists(downloaded_pkg), | 369 self.assertTrue(os.path.exists(downloaded_pkg), |
| 361 'Downloaded file %s missing.' % downloaded_pkg) | 370 'Downloaded file %s missing.' % downloaded_pkg) |
| 362 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg), | 371 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg), |
| 363 'Downloaded file %s does not match original' % | 372 'Downloaded file %s does not match original' % |
| 364 downloaded_pkg) | 373 downloaded_pkg) |
| 365 | 374 |
| 366 def testCancelDownload(self): | 375 def testCancelDownload(self): |
| 367 """Verify that we can cancel a download.""" | 376 """Verify that we can cancel a download.""" |
| 368 # Create a big file (250 MB) on the fly, so that the download won't finish | 377 # Create a big file (250 MB) on the fly, so that the download won't finish |
| 369 # before being cancelled. | 378 # before being cancelled. |
| 370 file_path = self._MakeFile(2**28) | 379 file_path = self._MakeFile(2**28) |
| 371 file_url = self.GetFileURLForPath(file_path) | 380 file_url = self.GetFileURLForPath(file_path) |
| 372 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), | 381 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), |
| 373 os.path.basename(file_path)) | 382 os.path.basename(file_path)) |
| 374 self._ClearLocalDownloadState(downloaded_pkg) | 383 self._ClearLocalDownloadState(downloaded_pkg) |
| 384 | |
| 375 self.DownloadAndWaitForStart(file_url) | 385 self.DownloadAndWaitForStart(file_url) |
| 376 self.PerformActionOnDownload(self._GetDownloadId(), 'cancel') | 386 self.PerformActionOnDownload(self._GetDownloadId(), 'cancel') |
| 377 self._DeleteAfterShutdown(file_path) | 387 self._DeleteAfterShutdown(file_path) |
| 378 | 388 |
| 379 state = self.GetDownloadsInfo().Downloads()[0]['state'] | 389 state = self.GetDownloadsInfo().Downloads()[0]['state'] |
| 380 if state == 'COMPLETE': | 390 if state == 'COMPLETE': |
| 381 logging.info('The download completed before cancel. Test stopped.') | 391 logging.info('The download completed before cancel. Test stopped.') |
| 382 return | 392 return |
| 383 | 393 |
| 384 # Verify the download has been cancelled. | 394 # Verify the download has been cancelled. |
| 385 self.assertEqual('CANCELLED', | 395 self.assertEqual('CANCELLED', |
| 386 self.GetDownloadsInfo().Downloads()[0]['state']) | 396 self.GetDownloadsInfo().Downloads()[0]['state']) |
| 387 self.assertFalse(os.path.exists(downloaded_pkg)) | 397 self.assertFalse(os.path.exists(downloaded_pkg)) |
| 388 | 398 |
| 389 def testDownloadsPersistence(self): | 399 def testDownloadsPersistence(self): |
| 390 """Verify that download history persists on session restart.""" | 400 """Verify that download history persists on session restart.""" |
| 391 test_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads') | 401 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')) | 402 file_url = self.GetFileURLForPath(os.path.join(test_dir, 'a_zip_file.zip')) |
| 393 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), | 403 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), |
| 394 'a_zip_file.zip') | 404 'a_zip_file.zip') |
| 395 self._ClearLocalDownloadState(downloaded_pkg) | 405 self._ClearLocalDownloadState(downloaded_pkg) |
| 406 pre_download_ids = [x['id'] for x in self.GetDownloadsInfo().Downloads()] | |
| 396 self.DownloadAndWaitForStart(file_url) | 407 self.DownloadAndWaitForStart(file_url) |
| 397 self.WaitForDownloadToComplete(downloaded_pkg) | 408 self.WaitForAllDownloadsToComplete(pre_download_ids) |
| 398 downloads = self.GetDownloadsInfo().Downloads() | 409 downloads = self.GetDownloadsInfo().Downloads() |
| 399 self.assertEqual(1, len(downloads)) | 410 self.assertEqual(1, len(downloads)) |
| 400 self.assertEqual('a_zip_file.zip', downloads[0]['file_name']) | 411 self.assertEqual('a_zip_file.zip', downloads[0]['file_name']) |
| 401 file_url = downloads[0]['url'] | 412 file_url = downloads[0]['url'] |
| 402 self.RestartBrowser(clear_profile=False) | 413 self.RestartBrowser(clear_profile=False) |
| 403 # Trigger the download service to get loaded after restart. | 414 # Trigger the download service to get loaded after restart. |
| 404 self.NavigateToURL('chrome://downloads/') | 415 self.NavigateToURL('chrome://downloads/') |
| 405 # Verify that there's no download shelf anymore. | 416 # Verify that there's no download shelf anymore. |
| 406 self.assertFalse(self.IsDownloadShelfVisible(), | 417 self.assertFalse(self.IsDownloadShelfVisible(), |
| 407 'Download shelf persisted browser restart.') | 418 'Download shelf persisted browser restart.') |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 433 This test is for mac only. | 444 This test is for mac only. |
| 434 """ | 445 """ |
| 435 if not self.IsMac(): | 446 if not self.IsMac(): |
| 436 logging.info('Skipping testExtendedAttributesOnMac on non-Mac') | 447 logging.info('Skipping testExtendedAttributesOnMac on non-Mac') |
| 437 return | 448 return |
| 438 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), | 449 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), |
| 439 'a_zip_file.zip') | 450 'a_zip_file.zip') |
| 440 self._ClearLocalDownloadState(downloaded_pkg) | 451 self._ClearLocalDownloadState(downloaded_pkg) |
| 441 file_url = 'http://src.chromium.org/viewvc/chrome/trunk/src/chrome/'\ | 452 file_url = 'http://src.chromium.org/viewvc/chrome/trunk/src/chrome/'\ |
| 442 'test/data/downloads/a_zip_file.zip' | 453 'test/data/downloads/a_zip_file.zip' |
| 454 pre_download_ids = [x['id'] for x in self.GetDownloadsInfo().Downloads()] | |
| 443 self.DownloadAndWaitForStart(file_url) | 455 self.DownloadAndWaitForStart(file_url) |
| 444 self.WaitForAllDownloadsToComplete() | 456 self.WaitForAllDownloadsToComplete(pre_download_ids) |
| 445 import xattr | 457 import xattr |
| 446 self.assertTrue('com.apple.quarantine' in xattr.listxattr(downloaded_pkg)) | 458 self.assertTrue('com.apple.quarantine' in xattr.listxattr(downloaded_pkg)) |
| 447 | 459 |
| 448 def testDownloadPercentage(self): | 460 def testDownloadPercentage(self): |
| 449 """Verify that during downloading, % values increases, | 461 """Verify that during downloading, % values increases, |
| 450 and once download is over, % value is 100""" | 462 and once download is over, % value is 100""" |
| 451 file_path = self._MakeFile(2**24) | 463 file_path = self._MakeFile(2**24) |
| 452 file_url = self.GetFileURLForPath(file_path) | 464 file_url = self.GetFileURLForPath(file_path) |
| 453 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), | 465 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), |
| 454 os.path.basename(file_path)) | 466 os.path.basename(file_path)) |
| 455 os.path.exists(downloaded_pkg) and os.remove(downloaded_pkg) | 467 os.path.exists(downloaded_pkg) and os.remove(downloaded_pkg) |
| 468 pre_download_ids = [x['id'] for x in self.GetDownloadsInfo().Downloads()] | |
| 456 self.DownloadAndWaitForStart(file_url) | 469 self.DownloadAndWaitForStart(file_url) |
| 457 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), | 470 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), |
| 458 os.path.basename(file_path)) | 471 os.path.basename(file_path)) |
| 459 downloads = self.GetDownloadsInfo().Downloads() | 472 downloads = self.GetDownloadsInfo().Downloads() |
| 460 old_percentage = downloads[0]['PercentComplete'] | 473 old_percentage = downloads[0]['PercentComplete'] |
| 461 def _PercentInc(): | 474 def _PercentInc(): |
| 462 percent = self.GetDownloadsInfo().Downloads()[0]['PercentComplete'] | 475 percent = self.GetDownloadsInfo().Downloads()[0]['PercentComplete'] |
| 463 return old_percentage == 100 or percent > old_percentage, | 476 return old_percentage == 100 or percent > old_percentage, |
| 464 self.assertTrue(self.WaitUntil(_PercentInc), | 477 self.assertTrue(self.WaitUntil(_PercentInc), |
| 465 msg='Download percentage value is not increasing') | 478 msg='Download percentage value is not increasing') |
| 466 # Once download is completed, percentage is 100. | 479 # Once download is completed, percentage is 100. |
| 467 self.WaitForAllDownloadsToComplete() | 480 self.WaitForAllDownloadsToComplete(pre_download_ids) |
| 468 downloads = self.GetDownloadsInfo().Downloads() | 481 downloads = self.GetDownloadsInfo().Downloads() |
| 469 self.assertEqual(downloads[0]['PercentComplete'], 100, | 482 self.assertEqual(downloads[0]['PercentComplete'], 100, |
| 470 'Download percentage should be 100 after download completed') | 483 'Download percentage should be 100 after download completed') |
| 471 os.path.exists(file_path) and os.remove(file_path) | 484 os.path.exists(file_path) and os.remove(file_path) |
| 472 os.path.exists(downloaded_pkg) and os.remove(downloaded_pkg) | 485 os.path.exists(downloaded_pkg) and os.remove(downloaded_pkg) |
| 473 | 486 |
| 474 def testDownloadIncognitoAndRegular(self): | 487 def testDownloadIncognitoAndRegular(self): |
| 475 """Download the same zip file in regular and incognito window and | 488 """Download the same zip file in regular and incognito window and |
| 476 verify that it downloaded correctly with same file name appended with | 489 verify that it downloaded correctly with same file name appended with |
| 477 counter for the second download in regular window. | 490 counter for the second download in regular window. |
| 478 """ | 491 """ |
| 479 test_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads') | 492 test_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads') |
| 480 file_path = os.path.join(test_dir, 'a_zip_file.zip') | 493 file_path = os.path.join(test_dir, 'a_zip_file.zip') |
| 481 file_url = self.GetFileURLForPath(file_path) | 494 file_url = self.GetFileURLForPath(file_path) |
| 482 downloaded_pkg_regul = os.path.join(self.GetDownloadDirectory().value(), | 495 downloaded_pkg_regul = os.path.join(self.GetDownloadDirectory().value(), |
| 483 'a_zip_file.zip') | 496 'a_zip_file.zip') |
| 484 downloaded_pkg_incog = os.path.join(self.GetDownloadDirectory().value(), | 497 downloaded_pkg_incog = os.path.join(self.GetDownloadDirectory().value(), |
| 485 'a_zip_file (1).zip') | 498 'a_zip_file (1).zip') |
| 486 self._ClearLocalDownloadState(downloaded_pkg_regul) | 499 self._ClearLocalDownloadState(downloaded_pkg_regul) |
| 487 self._ClearLocalDownloadState(downloaded_pkg_incog) | 500 self._ClearLocalDownloadState(downloaded_pkg_incog) |
| 488 | 501 |
| 502 pre_download_ids_0 = [x['id'] | |
| 503 for x in self.GetDownloadsInfo(windex=0).Downloads()] | |
| 489 self.DownloadAndWaitForStart(file_url, 0) | 504 self.DownloadAndWaitForStart(file_url, 0) |
| 490 self.WaitForAllDownloadsToComplete(0) | 505 self.WaitForAllDownloadsToComplete(pre_download_ids_0, windex=0) |
| 491 | 506 |
| 492 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) | 507 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) |
| 508 pre_download_ids_1 = [x['id'] | |
| 509 for x in self.GetDownloadsInfo(windex=1).Downloads()] | |
| 493 self.DownloadAndWaitForStart(file_url, 1) | 510 self.DownloadAndWaitForStart(file_url, 1) |
| 494 self.WaitForAllDownloadsToComplete(1) | 511 self.WaitForAllDownloadsToComplete(pre_download_ids_1, windex=1) |
| 495 | 512 |
| 496 # Verify download in regular window. | 513 # Verify download in regular window. |
| 497 self.assertTrue(os.path.exists(downloaded_pkg_regul)) | 514 self.assertTrue(os.path.exists(downloaded_pkg_regul)) |
| 498 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg_regul)) | 515 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg_regul)) |
| 499 | 516 |
| 500 # Verify download in incognito window. | 517 # Verify download in incognito window. |
| 501 # bug 69738 WaitForAllDownloadsToComplete is flaky for this test case. | 518 # bug 69738 WaitForAllDownloadsToComplete is flaky for this test case. |
| 502 # Using extra WaitUntil until this is resolved. | 519 # Using extra WaitUntil until this is resolved. |
| 503 self.assertTrue(self.WaitUntil( | 520 self.assertTrue(self.WaitUntil( |
| 504 lambda: os.path.exists(downloaded_pkg_incog))) | 521 lambda: os.path.exists(downloaded_pkg_incog))) |
| 505 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg_incog)) | 522 self.assertTrue(self._EqualFileContents(file_path, downloaded_pkg_incog)) |
| 506 | 523 |
| 507 | 524 |
| 508 if __name__ == '__main__': | 525 if __name__ == '__main__': |
| 509 pyauto_functional.Main() | 526 pyauto_functional.Main() |
| OLD | NEW |