OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2013 The Chromium Authors. All rights reserved. | 3 # Copyright 2013 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Runs semi-automated update testing on a non-rooted device. | 7 """Runs semi-automated update testing on a non-rooted device. |
8 | 8 |
9 This script will help verify that app data is preserved during an update. | 9 This script will help verify that app data is preserved during an update. |
10 To use this script first run it with the create_app_data option. | 10 To use this script first run it with the create_app_data option. |
(...skipping 17 matching lines...) Expand all Loading... | |
28 import logging | 28 import logging |
29 import os | 29 import os |
30 import sys | 30 import sys |
31 import time | 31 import time |
32 | 32 |
33 from pylib import constants | 33 from pylib import constants |
34 from pylib.device import device_utils | 34 from pylib.device import device_utils |
35 from pylib.utils import apk_helper | 35 from pylib.utils import apk_helper |
36 from pylib.utils import run_tests_helper | 36 from pylib.utils import run_tests_helper |
37 | 37 |
38 def CreateAppData(device, old_apk, app_data): | 38 def CreateAppData(device, old_apk, app_data, package_name): |
39 device.Install(old_apk) | 39 device.Install(old_apk) |
40 raw_input('Set the application state. Once ready, press enter and ' | 40 raw_input('Set the application state. Once ready, press enter and ' |
41 'select "Backup my data" on the device.') | 41 'select "Backup my data" on the device.') |
42 package_name = apk_helper.GetPackageName(old_apk) | |
43 device.adb.Backup(app_data, packages=[package_name]) | 42 device.adb.Backup(app_data, packages=[package_name]) |
44 logging.critical('Application data saved to %s' % app_data) | 43 logging.critical('Application data saved to %s' % app_data) |
45 | 44 |
46 def TestUpdate(device, old_apk, new_apk, app_data): | 45 def TestUpdate(device, old_apk, new_apk, app_data, package_name): |
47 device.Install(old_apk) | 46 device.Install(old_apk) |
48 device.adb.Restore(app_data) | 47 device.adb.Restore(app_data) |
49 # Restore command is not synchronous | 48 # Restore command is not synchronous |
50 raw_input('Select "Restore my data" on the device. Then press enter to ' | 49 raw_input('Select "Restore my data" on the device. Then press enter to ' |
51 'continue.') | 50 'continue.') |
52 | |
53 package_name = apk_helper.GetPackageName(new_apk) | |
54 device_path = device.GetApplicationPath(package_name) | 51 device_path = device.GetApplicationPath(package_name) |
55 if not device_path: | 52 if not device_path: |
56 raise Exception('Expected package %s to already be installed. ' | 53 raise Exception('Expected package %s to already be installed. ' |
57 'Package name might have changed!' % package_name) | 54 'Package name might have changed!' % package_name) |
58 | 55 |
59 logging.info('Verifying that %s can be overinstalled.', new_apk) | 56 logging.info('Verifying that %s can be overinstalled.', new_apk) |
60 device.adb.Install(new_apk, reinstall=True) | 57 device.adb.Install(new_apk, reinstall=True) |
61 logging.critical('Successfully updated to the new apk. Please verify that ' | 58 logging.critical('Successfully updated to the new apk. Please verify that ' |
62 'the application data is preserved.') | 59 'the application data is preserved.') |
63 | 60 |
64 def main(): | 61 def main(): |
65 parser = argparse.ArgumentParser( | 62 parser = argparse.ArgumentParser( |
66 description="Script to do semi-automated upgrade testing.") | 63 description="Script to do semi-automated upgrade testing.") |
67 parser.add_argument('-v', '--verbose', action='count', | 64 parser.add_argument('-v', '--verbose', action='count', |
68 help='Print verbose log information.') | 65 help='Print verbose log information.') |
69 command_parsers = parser.add_subparsers(dest='command') | 66 command_parsers = parser.add_subparsers(dest='command') |
70 | 67 |
71 subparser = command_parsers.add_parser('create_app_data') | 68 subparser = command_parsers.add_parser('create_app_data') |
72 subparser.add_argument('--old-apk', required=True, | 69 subparser.add_argument('--old-apk', required=True, |
73 help='Path to apk to update from.') | 70 help='Path to apk to update from.') |
74 subparser.add_argument('--app-data', required=True, | 71 subparser.add_argument('--app-data', required=True, |
75 help='Path to where the app data backup should be ' | 72 help='Path to where the app data backup should be ' |
76 'saved to.') | 73 'saved to.') |
74 subparser.add_argument('--package-name', | |
75 help='Chrome apk package name.') | |
77 | 76 |
78 subparser = command_parsers.add_parser('test_update') | 77 subparser = command_parsers.add_parser('test_update') |
79 subparser.add_argument('--old-apk', required=True, | 78 subparser.add_argument('--old-apk', required=True, |
80 help='Path to apk to update from.') | 79 help='Path to apk to update from.') |
81 subparser.add_argument('--new-apk', required=True, | 80 subparser.add_argument('--new-apk', required=True, |
82 help='Path to apk to update to.') | 81 help='Path to apk to update to.') |
83 subparser.add_argument('--app-data', required=True, | 82 subparser.add_argument('--app-data', required=True, |
84 help='Path to where the app data backup is saved.') | 83 help='Path to where the app data backup is saved.') |
84 subparser.add_argument('--package-name', | |
85 help='Chrome apk package name.') | |
85 | 86 |
86 args = parser.parse_args() | 87 args = parser.parse_args() |
87 run_tests_helper.SetLogLevel(args.verbose) | 88 run_tests_helper.SetLogLevel(args.verbose) |
88 | 89 |
89 devices = device_utils.DeviceUtils.HealthyDevices() | 90 devices = device_utils.DeviceUtils.HealthyDevices() |
90 device = devices[0] | 91 device = devices[0] |
91 logging.info('Using device %s for testing.' % str(device)) | 92 logging.info('Using device %s for testing.' % str(device)) |
92 | 93 |
93 if args.command == 'create_app_data': | 94 if args.command == 'create_app_data': |
94 CreateAppData(device, args.old_apk, args.app_data) | 95 package_name = (args.package_name if args.package_name |
jbudorick
2015/05/22 23:23:31
nit: do this outside of the if/elif
mikecase (-- gone --)
2015/05/22 23:58:48
Done. Also, fyi, added a change in my latest patc
| |
96 else apk_helper.GetPackageName(args.old_apk)) | |
97 CreateAppData(device, args.old_apk, args.app_data, package_name) | |
95 elif args.command == 'test_update': | 98 elif args.command == 'test_update': |
96 TestUpdate(device, args.old_apk, args.new_apk, args.app_data) | 99 package_name = (args.package_name if args.package_name |
100 else apk_helper.GetPackageName(args.new_apk)) | |
101 TestUpdate( | |
102 device, args.old_apk, args.new_apk, args.app_data, package_name) | |
97 else: | 103 else: |
98 raise Exception('Unknown test command: %s' % args.command) | 104 raise Exception('Unknown test command: %s' % args.command) |
99 | 105 |
100 if __name__ == '__main__': | 106 if __name__ == '__main__': |
101 sys.exit(main()) | 107 sys.exit(main()) |
OLD | NEW |