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.
11 class MyTest(pyauto.PyUITest):
13 info = self.GetPluginsInfo() # fetch plugins snapshot
16 See more examples in chrome/test/functional/plugins.py.
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.
29 def __init__(self
, plugins_dict
):
30 """Initialize a PluginsInfo from a json string.
33 plugins_dict: a dictionary returned by the automation command
37 pyauto_errors.JSONInterfaceError if the automation call returns an error.
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'])
48 a list of plugins info
50 [ { u'desc': u'Shockwave Flash 10.0 r45',
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',
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'},
73 return self
.pluginsdict
.get('plugins', [])
75 def PluginForPath(self
, path
):
76 """Get plugin info for the given plugin path.
79 a dictionary of info for the plugin.
81 got
= filter(lambda x
: x
['path'] == path
, self
.Plugins())
82 if not got
: return None
85 def PluginForName(self
, name
):
86 """Get plugin info for the given name.
88 There might be several plugins with the same name.
91 name: the name for which to look for.
94 a list of info dictionaries for each plugin found with the given name.
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.
104 name: the name for which to look for.
107 a plugin info dictionary
110 all
= self
.PluginForName(name
)
111 if not all
: return None