OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 import logging | |
7 import os | |
8 import sys | |
9 | |
10 import pyauto_functional # Must be imported before pyauto | |
11 import pyauto | |
12 | |
13 | |
14 class PluginsCheck(pyauto.PyUITest): | |
15 """TestCase for Plugins.""" | |
16 | |
17 def _ReadPluginsList(self, plugins_list_file): | |
18 """Read test plugins list from a file based on the test platform | |
19 | |
20 File contains list of plugins like, | |
21 [ | |
22 {u'name':'Shockwave Flash', u'enabled':True, u'version':u'10.2.154.9'} | |
23 {u'name':'Chrome PDF Viewer', u'enabled':True, u'version':u''} | |
24 ... | |
25 ] | |
26 """ | |
27 file_path = os.path.join(self.DataDir(), plugins_list_file) | |
28 return self.EvalDataFrom(file_path) | |
29 | |
30 def _RemoveNonApplicablePlugins(self, plugins_list): | |
31 """Removes plugins that do not apply to the given ChromeOS board. | |
32 Note: This function is only run on ChromeOS. | |
33 """ | |
34 new_list = [] | |
35 for plugin in plugins_list: | |
36 if self.ChromeOSBoard() in set(plugin['boards']): | |
37 plugin.pop('boards') | |
38 new_list.append(plugin) | |
39 return new_list | |
40 | |
41 def testPluginsStates(self): | |
42 """Verify plugins' versions and states.""" | |
43 if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome': | |
44 return | |
45 if self.IsWin(): | |
46 plugins_list = self._ReadPluginsList('win_plugins_list.txt') | |
47 elif self.IsMac(): | |
48 plugins_list = self._ReadPluginsList('mac_plugins_list.txt') | |
49 elif self.IsChromeOS(): | |
50 plugins_list = self._ReadPluginsList('chromeos_plugins_list.txt') | |
51 plugins_list = self._RemoveNonApplicablePlugins(plugins_list) | |
52 elif self.IsLinux(): | |
53 # TODO(rohitbm) | |
54 # Add plugins_check support for Linux | |
55 logging.debug('Not performing plugins check on linux') | |
56 return | |
57 | |
58 browser_plugins_list = self.GetPluginsInfo().Plugins() | |
59 for plugin in plugins_list: | |
60 # We will compare the keys available in the plugin list | |
61 found_plugin = False | |
62 for browser_plugin in browser_plugins_list: | |
63 whitelist_keys = plugin.keys() | |
64 if 'unique_key' in plugin: | |
65 unique_key = plugin['unique_key'] | |
66 whitelist_keys.remove('unique_key') | |
67 else: | |
68 unique_key = 'name' | |
69 if browser_plugin[unique_key] == plugin[unique_key]: | |
70 found_plugin = True | |
71 for key in whitelist_keys: | |
72 if browser_plugin[key] != plugin[key]: | |
73 self.assertEqual(browser_plugin[key], plugin[key], 'The following' | |
74 ' plugin attributes do not match the whitelist:' | |
75 '\n\tplugin:\n%s\n\tlist:\n%s' | |
76 % (self.pformat(browser_plugin), self.pformat(plugin))) | |
77 break; | |
78 self.assertTrue(found_plugin, 'The following plugin in the whitelist ' | |
79 'does not match any on the system:\n%s' % self.pformat(plugin)) | |
80 if self.IsChromeOS(): | |
81 self.assertEqual(len(plugins_list), len(browser_plugins_list), | |
82 'The number of plugins on the system do not match the number in the ' | |
83 'whitelist.\n\tSystem list: %s\n\tWhitelist: %s' % | |
84 (self.pformat(browser_plugins_list), self.pformat(plugins_list))) | |
85 | |
86 | |
87 if __name__ == '__main__': | |
88 pyauto_functional.Main() | |
OLD | NEW |