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 filecmp | 6 import filecmp |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import shutil | 9 import shutil |
10 import sys | 10 import sys |
11 import tempfile | 11 import tempfile |
12 import time | 12 import time |
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 | 18 |
18 | 19 |
19 class DownloadsTest(pyauto.PyUITest): | 20 class DownloadsTest(pyauto.PyUITest): |
20 """TestCase for Downloads.""" | 21 """TestCase for Downloads.""" |
21 | 22 |
| 23 def setUp(self): |
| 24 pyauto.PyUITest.setUp(self) |
| 25 # Record all entries in the download dir |
| 26 download_dir = self.GetDownloadDirectory().value() |
| 27 self._existing_downloads = [] |
| 28 if os.path.isdir(download_dir): |
| 29 self._existing_downloads += os.listdir(download_dir) |
| 30 |
| 31 def tearDown(self): |
| 32 # Cleanup all files we created in the download dir |
| 33 download_dir = self.GetDownloadDirectory().value() |
| 34 if os.path.isdir(download_dir): |
| 35 for name in os.listdir(download_dir): |
| 36 if name not in self._existing_downloads: |
| 37 pyauto_utils.RemovePath(os.path.join(download_dir, name)) |
| 38 pyauto.PyUITest.tearDown(self) |
| 39 |
22 def _GetDangerousDownload(self): | 40 def _GetDangerousDownload(self): |
23 """Returns the file url for a dangerous download for this OS.""" | 41 """Returns the file url for a dangerous download for this OS.""" |
24 sub_path = os.path.join(self.DataDir(), 'downloads', 'dangerous') | 42 sub_path = os.path.join(self.DataDir(), 'downloads', 'dangerous') |
25 if self.IsMac(): | 43 if self.IsMac(): |
26 return os.path.join(sub_path, 'dangerous.dmg') | 44 return os.path.join(sub_path, 'dangerous.dmg') |
27 return os.path.join(sub_path, 'dangerous.exe') | 45 return os.path.join(sub_path, 'dangerous.exe') |
28 | 46 |
29 def _EqualFileContents(self, file1, file2): | 47 def _EqualFileContents(self, file1, file2): |
30 """Determine if 2 given files have the same contents.""" | 48 """Determine if 2 given files have the same contents.""" |
31 if not (os.path.exists(file1) and os.path.exists(file2)): | 49 if not (os.path.exists(file1) and os.path.exists(file2)): |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 # Trigger the download service to get loaded after restart. | 256 # Trigger the download service to get loaded after restart. |
239 self.NavigateToURL('chrome://downloads/') | 257 self.NavigateToURL('chrome://downloads/') |
240 # Verify that there's no download shelf anymore. | 258 # Verify that there's no download shelf anymore. |
241 self.assertFalse(self.IsDownloadShelfVisible(), | 259 self.assertFalse(self.IsDownloadShelfVisible(), |
242 'Download shelf persisted browser restart.') | 260 'Download shelf persisted browser restart.') |
243 # Verify that the download history persists. | 261 # Verify that the download history persists. |
244 downloads = self.GetDownloadsInfo().Downloads() | 262 downloads = self.GetDownloadsInfo().Downloads() |
245 self.assertEqual(1, len(downloads)) | 263 self.assertEqual(1, len(downloads)) |
246 self.assertEqual('a_zip_file.zip', downloads[0]['file_name']) | 264 self.assertEqual('a_zip_file.zip', downloads[0]['file_name']) |
247 self.assertEqual(file_url, downloads[0]['url']) | 265 self.assertEqual(file_url, downloads[0]['url']) |
| 266 os.path.exists(downloaded_pkg) and os.remove(downloaded_pkg) |
248 | 267 |
249 | 268 |
250 if __name__ == '__main__': | 269 if __name__ == '__main__': |
251 pyauto_functional.Main() | 270 pyauto_functional.Main() |
OLD | NEW |