OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """ | 6 """ |
7 This module is a simple qa tool that installs extensions and tests whether the | 7 This module is a simple qa tool that installs extensions and tests whether the |
8 browser crashes while visiting a list of urls. | 8 browser crashes while visiting a list of urls. |
9 | 9 |
10 Usage: python extensions.py -v | 10 Usage: python extensions.py -v |
11 | 11 |
12 Note: This assumes that there is a directory of extensions called 'extensions' | 12 Note: This assumes that there is a directory of extensions called |
13 and that there is a file of newline-separated urls to visit called 'urls.txt' | 13 'extensions-tool' and that there is a file of newline-separated urls to visit |
14 in the same directory as the script. | 14 called 'urls.txt' in the data directory. |
15 """ | 15 """ |
16 | 16 |
17 import glob | 17 import glob |
18 import logging | 18 import logging |
19 import os | 19 import os |
20 import sys | 20 import sys |
21 | 21 |
22 import pyauto_functional # must be imported before pyauto | 22 import pyauto_functional # must be imported before pyauto |
23 import pyauto | 23 import pyauto |
24 | 24 |
25 | 25 |
26 class ExtensionsTest(pyauto.PyUITest): | 26 class ExtensionsTest(pyauto.PyUITest): |
27 """Test of extensions.""" | 27 """Test of extensions.""" |
28 # TODO: provide a way in pyauto to pass args to a test and take these as args | |
29 extensions_dir_ = 'extensions' # The directory of extensions | |
30 urls_file_ = 'urls.txt' # The file which holds a list of urls to visit | |
31 | 28 |
32 def Debug(self): | 29 def Debug(self): |
33 """Test method for experimentation. | 30 """Test method for experimentation. |
34 | 31 |
35 This method is not run automatically. | 32 This method is not run automatically. |
36 """ | 33 """ |
37 while True: | 34 while True: |
38 raw_input('Interact with the browser and hit <enter> to dump history.. ') | 35 raw_input('Interact with the browser and hit <enter> to dump history.. ') |
39 print '*' * 20 | 36 print '*' * 20 |
40 extensions = self.GetExtensionsInfo() | 37 extensions = self.GetExtensionsInfo() |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 for extension_id in new_extension_ids: | 89 for extension_id in new_extension_ids: |
93 self.UninstallExtensionById(extension_id) | 90 self.UninstallExtensionById(extension_id) |
94 | 91 |
95 curr_extension = group_end | 92 curr_extension = group_end |
96 | 93 |
97 # None of the extensions crashed. | 94 # None of the extensions crashed. |
98 return None | 95 return None |
99 | 96 |
100 def testExtensionCrashes(self): | 97 def testExtensionCrashes(self): |
101 """Add top extensions; confirm browser stays up when visiting top urls""" | 98 """Add top extensions; confirm browser stays up when visiting top urls""" |
102 self.assertTrue(os.path.exists(self.extensions_dir_), | 99 # TODO: provide a way in pyauto to pass args to a test - take these as args |
103 'The dir "%s" must exist' % os.path.abspath(self.extensions_dir_)) | 100 extensions_dir = os.path.join(self.DataDir(), 'extensions-tool') |
104 self.assertTrue(os.path.exists(self.urls_file_), | 101 urls_file = os.path.join(self.DataDir(), 'urls.txt') |
105 'The file "%s" must exist' % os.path.abspath(self.urls_file_)) | 102 |
| 103 assert(os.path.exists(extensions_dir), |
| 104 'The dir "%s" must exist' % os.path.abspath(extensions_dir)) |
| 105 assert(os.path.exists(urls_file), |
| 106 'The file "%s" must exist' % os.path.abspath(urls_file)) |
106 | 107 |
107 num_urls_to_visit = 100 | 108 num_urls_to_visit = 100 |
108 extensions_group_size = 20 | 109 extensions_group_size = 20 |
109 | 110 |
110 top_urls = [l.rstrip() for l in | 111 top_urls = [l.rstrip() for l in |
111 open(self.urls_file_).readlines()[:num_urls_to_visit]] | 112 open(urls_file).readlines()[:num_urls_to_visit]] |
112 | 113 |
113 failed_extensions = glob.glob(os.path.join(self.extensions_dir_, '*.crx')) | 114 failed_extensions = glob.glob(os.path.join(extensions_dir, '*.crx')) |
114 group_size = extensions_group_size | 115 group_size = extensions_group_size |
115 | 116 |
116 while(group_size and failed_extensions): | 117 while(group_size and failed_extensions): |
117 failed_extensions = self._ReturnCrashingExtensions( | 118 failed_extensions = self._ReturnCrashingExtensions( |
118 failed_extensions, group_size, top_urls) | 119 failed_extensions, group_size, top_urls) |
119 group_size = group_size // 2 | 120 group_size = group_size // 2 |
120 | 121 |
121 self.assertFalse(failed_extensions, | 122 self.assertFalse(failed_extensions, |
122 'Extension(s) in failing group: %s' % failed_extensions) | 123 'Extension(s) in failing group: %s' % failed_extensions) |
123 | 124 |
124 | 125 |
125 if __name__ == '__main__': | 126 if __name__ == '__main__': |
126 pyauto_functional.Main() | 127 pyauto_functional.Main() |
OLD | NEW |