blob: 6f5547235652ae27900c5df8ff0c492b696b6a80 [file] [log] [blame]
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Python representation for Chromium Plugins info.
This is the info available at about:plugins.
Obtain one of these from PyUITestSuite::GetPluginsInfo() call.
class MyTest(pyauto.PyUITest):
def testBasic(self):
info = self.GetPluginsInfo() # fetch plugins snapshot
print info.Plugins()
See more examples in chrome/test/functional/
import simplejson as json
from pyauto_errors import JSONInterfaceError
class PluginsInfo(object):
"""Represent info for Chromium plugins.
The info is represented as a list of dictionaries, one for each plugin.
def __init__(self, plugins_dict):
"""Initialize a PluginsInfo from a json string.
plugins_dict: a dictionary returned by the automation command
pyauto_errors.JSONInterfaceError if the automation call returns an error.
# JSON string prepared in GetPluginsInfo() in
self.pluginsdict = plugins_dict
if self.pluginsdict.has_key('error'):
raise JSONInterfaceError(self.pluginsdict['error'])
def Plugins(self):
"""Get plugins.
a list of plugins info
[ { u'desc': u'Shockwave Flash 10.0 r45',
u'enabled': True,
u'mimeTypes': [ { u'description': u'Shockwave Flash',
u'fileExtensions': [u'swf'],
u'mimeType': u'application/x-shockwave-flash'},
{ u'description': u'FutureSplash Player',
u'fileExtensions': [u'spl'],
u'mimeType': u'application/futuresplash'}],
u'name': u'Shockwave Flash',
u'path': u'/Library/Internet Plug-Ins/Flash Player.plugin',
u'version': u''},
{ u'desc': u'Version',
u'enabled': True,
u'mimeTypes': [ { u'description': u'Google voice and video chat',
u'fileExtensions': [u'googletalk'],
u'mimeType': u'application/googletalk'}],
u'name': u'Google Talk NPAPI Plugin',
u'path': u'/Library/Internet Plug-Ins/googletalkbrowserplugin.plugin',
u'version': u''},
return self.pluginsdict.get('plugins', [])
def PluginForPath(self, path):
"""Get plugin info for the given plugin path.
a dictionary of info for the plugin.
got = filter(lambda x: x['path'] == path, self.Plugins())
if not got: return None
return got[0]
def PluginForName(self, name):
"""Get plugin info for the given name.
There might be several plugins with the same name.
name: the name for which to look for.
a list of info dictionaries for each plugin found with the given name.
return filter(lambda x: x['name'] == name, self.Plugins())
def FirstPluginForName(self, name):
"""Get plugin info for the first plugin with the given name.
This is useful in case there are multiple plugins for a name.
name: the name for which to look for.
a plugin info dictionary
None, if not found
all = self.PluginForName(name)
if not all: return None
return all[0]