Move render_view_context_menu.* and related files out of tab_contents.
[chromium-blink-merge.git] / chrome / test / pyautolib / plugins_info.py
blob6f5547235652ae27900c5df8ff0c492b696b6a80
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 """Python representation for Chromium Plugins info.
7 This is the info available at about:plugins.
8 Obtain one of these from PyUITestSuite::GetPluginsInfo() call.
10 Example:
11 class MyTest(pyauto.PyUITest):
12 def testBasic(self):
13 info = self.GetPluginsInfo() # fetch plugins snapshot
14 print info.Plugins()
16 See more examples in chrome/test/functional/plugins.py.
17 """
19 import simplejson as json
21 from pyauto_errors import JSONInterfaceError
24 class PluginsInfo(object):
25 """Represent info for Chromium plugins.
27 The info is represented as a list of dictionaries, one for each plugin.
28 """
29 def __init__(self, plugins_dict):
30 """Initialize a PluginsInfo from a json string.
32 Args:
33 plugins_dict: a dictionary returned by the automation command
34 'GetPluginsInfo'.
36 Raises:
37 pyauto_errors.JSONInterfaceError if the automation call returns an error.
38 """
39 # JSON string prepared in GetPluginsInfo() in automation_provider.cc
40 self.pluginsdict = plugins_dict
41 if self.pluginsdict.has_key('error'):
42 raise JSONInterfaceError(self.pluginsdict['error'])
44 def Plugins(self):
45 """Get plugins.
47 Returns:
48 a list of plugins info
49 Sample:
50 [ { u'desc': u'Shockwave Flash 10.0 r45',
51 u'enabled': True,
52 u'mimeTypes': [ { u'description': u'Shockwave Flash',
53 u'fileExtensions': [u'swf'],
54 u'mimeType': u'application/x-shockwave-flash'},
55 { u'description': u'FutureSplash Player',
56 u'fileExtensions': [u'spl'],
57 u'mimeType': u'application/futuresplash'}],
58 u'name': u'Shockwave Flash',
59 u'path': u'/Library/Internet Plug-Ins/Flash Player.plugin',
60 u'version': u'10.0.45.2'},
61 { u'desc': u'Version 1.1.2.9282',
62 u'enabled': True,
63 u'mimeTypes': [ { u'description': u'Google voice and video chat',
64 u'fileExtensions': [u'googletalk'],
65 u'mimeType': u'application/googletalk'}],
66 u'name': u'Google Talk NPAPI Plugin',
67 u'path': u'/Library/Internet Plug-Ins/googletalkbrowserplugin.plugin',
68 u'version': u'1.1.2.9282'},
69 ...,
70 ...,
72 """
73 return self.pluginsdict.get('plugins', [])
75 def PluginForPath(self, path):
76 """Get plugin info for the given plugin path.
78 Returns:
79 a dictionary of info for the plugin.
80 """
81 got = filter(lambda x: x['path'] == path, self.Plugins())
82 if not got: return None
83 return got[0]
85 def PluginForName(self, name):
86 """Get plugin info for the given name.
88 There might be several plugins with the same name.
90 Args:
91 name: the name for which to look for.
93 Returns:
94 a list of info dictionaries for each plugin found with the given name.
95 """
96 return filter(lambda x: x['name'] == name, self.Plugins())
98 def FirstPluginForName(self, name):
99 """Get plugin info for the first plugin with the given name.
101 This is useful in case there are multiple plugins for a name.
103 Args:
104 name: the name for which to look for.
106 Returns:
107 a plugin info dictionary
108 None, if not found
110 all = self.PluginForName(name)
111 if not all: return None
112 return all[0]