Add IDN decoding test for SafeBrowsingBlockingPage
[chromium-blink-merge.git] / tools / android / mempressure.py
blob5c81f3e07006750e699adfad4339515caf467ef6
1 #!/usr/bin/env python
2 # Copyright 2013 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.
6 import collections
7 import logging
8 import optparse
9 import os
10 import sys
12 BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__),
13 os.pardir,
14 os.pardir,
15 'build',
16 'android')
17 sys.path.append(BUILD_ANDROID_DIR)
18 from pylib import android_commands
19 from pylib import constants
20 from pylib import flag_changer
21 from pylib.device import device_errors
22 from pylib.device import device_utils
23 from pylib.device import intent
25 # Browser Constants
26 DEFAULT_BROWSER = 'chrome'
28 # Action Constants
29 ACTION_PACKAGE = 'org.chromium.base'
30 ACTION_TRIM = {
31 'moderate' : ACTION_PACKAGE + '.ACTION_TRIM_MEMORY_MODERATE',
32 'critical' : ACTION_PACKAGE + '.ACTION_TRIM_MEMORY_RUNNING_CRITICAL',
33 'complete' : ACTION_PACKAGE + '.ACTION_TRIM_MEMORY'
35 ACTION_LOW = ACTION_PACKAGE + '.ACTION_LOW_MEMORY'
37 # Command Line Constants
38 ENABLE_TEST_INTENTS_FLAG = '--enable-test-intents'
40 def main(argv):
41 option_parser = optparse.OptionParser()
42 option_parser.add_option('-l',
43 '--low',
44 help='Simulate Activity#onLowMemory()',
45 action='store_true')
46 option_parser.add_option('-t',
47 '--trim',
48 help=('Simulate Activity#onTrimMemory(...) with ' +
49 ', '.join(ACTION_TRIM.keys())),
50 type='string')
51 option_parser.add_option('-b',
52 '--browser',
53 default=DEFAULT_BROWSER,
54 help=('Which browser to use. One of ' +
55 ', '.join(constants.PACKAGE_INFO.keys()) +
56 ' [default: %default]'),
57 type='string')
59 (options, args) = option_parser.parse_args(argv)
61 if len(args) > 1:
62 print 'Unknown argument: ', args[1:]
63 option_parser.print_help()
64 sys.exit(1)
66 if options.low and options.trim:
67 option_parser.error('options --low and --trim are mutually exclusive')
69 if not options.low and not options.trim:
70 option_parser.print_help()
71 sys.exit(1)
73 action = None
74 if options.low:
75 action = ACTION_LOW
76 elif options.trim in ACTION_TRIM.keys():
77 action = ACTION_TRIM[options.trim]
79 if action is None:
80 option_parser.print_help()
81 sys.exit(1)
83 if not options.browser in constants.PACKAGE_INFO.keys():
84 option_parser.error('Unknown browser option ' + options.browser)
86 package_info = constants.PACKAGE_INFO[options.browser]
88 package = package_info.package
89 activity = package_info.activity
91 devices = android_commands.GetAttachedDevices()
92 if not devices:
93 raise device_errors.NoDevicesError()
94 elif len(devices) > 1:
95 logging.warning('Multiple devices attached. Using %s.' % devices[0])
96 device = device_utils.DeviceUtils(devices[0])
98 try:
99 device.EnableRoot()
100 except device_errors.CommandFailedError as e:
101 # Try to change the flags and start the activity anyway.
102 # TODO(jbudorick) Handle this exception appropriately after interface
103 # conversions are finished.
104 logging.error(str(e))
105 flags = flag_changer.FlagChanger(device, package_info.cmdline_file)
106 if ENABLE_TEST_INTENTS_FLAG not in flags.Get():
107 flags.AddFlags([ENABLE_TEST_INTENTS_FLAG])
109 device.StartActivity(intent.Intent(package=package, activity=activity,
110 action=action))
112 if __name__ == '__main__':
113 sys.exit(main(sys.argv))