summaryrefslogtreecommitdiffstats
path: root/chrome/test/functional/extensions.py
blob: df462242f77621cd2cb75420a7642ad4a099e9d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/python
# Copyright (c) 2010 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.

"""
This module is a simple qa tool that installs extensions and tests whether the
browser crashes while visiting a list of urls.

Usage: python extensions.py -v

Note: This assumes that there is a directory of extensions in called
'extensions' and that there is a file of newline-separated urls to visit called
'urls.txt' in the same directory as the script.
"""

import glob
import logging
import os
import sys

import pyauto_functional # must be imported before pyauto
import pyauto


class ExtensionsTest(pyauto.PyUITest):
  """Test of extensions."""
  # TODO: provide a way in pyauto to pass args to a test and take these as args
  extensions_dir_ = 'extensions'  # The directory of extensions
  urls_file_ = 'urls.txt'         # The file which holds a list of urls to visit

  def testExtensionCrashes(self):
    """Add top extensions; confirm browser stays up when visiting top urls"""
    self.assertTrue(os.path.exists(self.extensions_dir_),
             'The dir "%s" must exist' % os.path.abspath(self.extensions_dir_))
    self.assertTrue(os.path.exists(self.urls_file_),
             'The file "%s" must exist' % os.path.abspath(self.urls_file_))

    extensions_group_size = 20
    num_urls_to_visit = 100

    extensions = glob.glob(os.path.join(self.extensions_dir_, '*.crx'))
    top_urls = [l.rstrip() for l in open(self.urls_file_).readlines()]

    curr_extension = 0
    num_extensions = len(extensions)

    while curr_extension < num_extensions:
      logging.debug('New group of %d extensions.' % extensions_group_size)
      group_end = curr_extension + extensions_group_size
      for extension in extensions[curr_extension:group_end]:
        logging.debug('Installing extension: %s' % extension)
        self.InstallExtension(pyauto.FilePath(extension), False)

      # Navigate to the top urls and verify there is still one window
      for url in top_urls[:num_urls_to_visit]:
        self.NavigateToURL(url)
      self.assertEqual(1, self.GetBrowserWindowCount(),
                       'Extensions in failing group: %s' %
                        extensions[curr_extension:group_end])
      curr_extension = group_end


if __name__ == '__main__':
  pyauto_functional.Main()