Implement nacl_irt_memory for non-sfi mode.
[chromium-blink-merge.git] / chrome / test / pyautolib / download_info.py
blob44d5705aeddc710f14991f7a78f98caaa1df02c7
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 """DownloadInfo: python representation for downloads visible to Chrome.
7 Obtain one of these from PyUITestSuite::GetDownloadsInfo() call.
9 class MyDownloadsTest(pyauto.PyUITest):
10 def testDownload(self):
11 self.DownloadAndWaitForStart('http://my.url/package.zip')
12 self.WaitForAllDownloadsToComplete()
13 info = self.GetDownloadsInfo()
14 print info.Downloads()
15 self.assertEqual(info.Downloads()[0]['file_name'], 'packge.zip')
17 See more tests in chrome/test/functional/downloads.py.
18 """
20 import os
21 import simplejson as json
22 import sys
24 from pyauto_errors import JSONInterfaceError
27 class DownloadInfo(object):
28 """Represent info about Downloads.
30 The info is represented as a list of DownloadItems. Each DownloadItem is a
31 dictionary with various attributes about a download, like id, file_name,
32 path, state, and so on.
33 """
34 def __init__(self, downloads_dict):
35 """Initialize a DownloadInfo from a string of json.
37 Args:
38 downloads_dict: a dict returned by the IPC command 'GetDownloadsInfo'.
39 A typical dict representing one download looks like:
40 {'downloads': [{'url': 'http://blah/a_file.zip',
41 'file_name': 'a_file.zip',
42 'state': 'COMPLETED',
43 ...,
44 ..., } ] }
46 Raises:
47 pyauto_errors.JSONInterfaceError if the automation call returns an error.
48 """
49 # JSON string prepared in GetDownloadsInfo() in automation_provider.cc
50 self.downloadsdict = downloads_dict
51 if self.downloadsdict.has_key('error'):
52 raise JSONInterfaceError(self.downloadsdict['error'])
54 def Downloads(self):
55 """Info about all downloads.
57 This includes downloads in all states (COMPLETE, IN_PROGRESS, ...).
59 Returns:
60 [downloaditem1, downloaditem2, ...]
61 """
62 return self.downloadsdict.get('downloads', [])
64 def DownloadsInProgress(self):
65 """Info about all downloads in progress.
67 Returns:
68 [downloaditem1, downloaditem2, ...]
69 """
70 return [x for x in self.Downloads() if x['state'] == 'IN_PROGRESS']
72 def DownloadsComplete(self):
73 """Info about all downloads that have completed.
75 Returns:
76 [downloaditem1, downloaditem2, ...]
77 """
78 return [x for x in self.Downloads() if x['state'] == 'COMPLETE']