blob: bdd49f1a3a24b67c75526c8bb35b702f4e4d991d [file] [log] [blame]
[email protected]3de785b42013-01-11 00:13:541#!/usr/bin/env python
2#
[email protected]f3da04f2013-08-14 18:09:373# Copyright 2013 The Chromium Authors. All rights reserved.
[email protected]3de785b42013-01-11 00:13:544# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
mikecase798b3dc2015-05-06 18:32:077"""Runs semi-automated update testing on a non-rooted device.
8
9This script will help verify that app data is preserved during an update.
10To use this script first run it with the create_app_data option.
11
12./update_verification.py create_app_data --old-apk <path> --app-data <path>
13
14The script will then install the old apk, prompt you to create some app data
15(bookmarks, etc.), and then save the app data in the path you gave it.
16
17Next, once you have some app data saved, run this script with the test_update
18option.
19
20./update_verification.py test_update --old-apk <path> --new-apk <path>
21--app-data <path>
22
23This will install the old apk, load the saved app data, install the new apk,
24and ask the user to verify that all of the app data was preserved.
25"""
26
27import argparse
[email protected]3de785b42013-01-11 00:13:5428import logging
[email protected]3de785b42013-01-11 00:13:5429import sys
[email protected]3de785b42013-01-11 00:13:5430
jbudorick061629442015-09-03 18:00:5731from devil.android import apk_helper
32from devil.android import device_blacklist
33from devil.android import device_errors
34from devil.android import device_utils
35from devil.utils import run_tests_helper
[email protected]3de785b42013-01-11 00:13:5436
mikecase06ef7202015-05-23 02:30:0637def CreateAppData(device, old_apk, app_data, package_name):
mikecase798b3dc2015-05-06 18:32:0738 device.Install(old_apk)
[email protected]3de785b42013-01-11 00:13:5439 raw_input('Set the application state. Once ready, press enter and '
40 'select "Backup my data" on the device.')
mikecase798b3dc2015-05-06 18:32:0741 device.adb.Backup(app_data, packages=[package_name])
jbudorick58b4d362015-09-08 16:44:5942 logging.critical('Application data saved to %s', app_data)
[email protected]3de785b42013-01-11 00:13:5443
mikecase06ef7202015-05-23 02:30:0644def TestUpdate(device, old_apk, new_apk, app_data, package_name):
mikecase798b3dc2015-05-06 18:32:0745 device.Install(old_apk)
46 device.adb.Restore(app_data)
47 # Restore command is not synchronous
48 raw_input('Select "Restore my data" on the device. Then press enter to '
49 'continue.')
mikecase89d5ad72015-06-19 20:43:3950 device_path = device.GetApplicationPaths(package_name)
mikecase798b3dc2015-05-06 18:32:0751 if not device_path:
52 raise Exception('Expected package %s to already be installed. '
53 'Package name might have changed!' % package_name)
[email protected]3de785b42013-01-11 00:13:5454
mikecase798b3dc2015-05-06 18:32:0755 logging.info('Verifying that %s can be overinstalled.', new_apk)
56 device.adb.Install(new_apk, reinstall=True)
57 logging.critical('Successfully updated to the new apk. Please verify that '
58 'the application data is preserved.')
[email protected]3de785b42013-01-11 00:13:5459
60def main():
mikecase798b3dc2015-05-06 18:32:0761 parser = argparse.ArgumentParser(
62 description="Script to do semi-automated upgrade testing.")
63 parser.add_argument('-v', '--verbose', action='count',
64 help='Print verbose log information.')
jbudorickdde688fb2015-08-27 03:00:1765 parser.add_argument('--blacklist-file', help='Device blacklist JSON file.')
mikecase798b3dc2015-05-06 18:32:0766 command_parsers = parser.add_subparsers(dest='command')
[email protected]3de785b42013-01-11 00:13:5467
mikecase798b3dc2015-05-06 18:32:0768 subparser = command_parsers.add_parser('create_app_data')
69 subparser.add_argument('--old-apk', required=True,
mikecase06ef7202015-05-23 02:30:0670 help='Path to apk to update from.')
mikecase798b3dc2015-05-06 18:32:0771 subparser.add_argument('--app-data', required=True,
mikecase06ef7202015-05-23 02:30:0672 help='Path to where the app data backup should be '
mikecase798b3dc2015-05-06 18:32:0773 'saved to.')
mikecase06ef7202015-05-23 02:30:0674 subparser.add_argument('--package-name',
75 help='Chrome apk package name.')
mikecase798b3dc2015-05-06 18:32:0776
77 subparser = command_parsers.add_parser('test_update')
78 subparser.add_argument('--old-apk', required=True,
mikecase06ef7202015-05-23 02:30:0679 help='Path to apk to update from.')
mikecase798b3dc2015-05-06 18:32:0780 subparser.add_argument('--new-apk', required=True,
mikecase06ef7202015-05-23 02:30:0681 help='Path to apk to update to.')
mikecase798b3dc2015-05-06 18:32:0782 subparser.add_argument('--app-data', required=True,
mikecase06ef7202015-05-23 02:30:0683 help='Path to where the app data backup is saved.')
84 subparser.add_argument('--package-name',
85 help='Chrome apk package name.')
mikecase798b3dc2015-05-06 18:32:0786
87 args = parser.parse_args()
88 run_tests_helper.SetLogLevel(args.verbose)
[email protected]3de785b42013-01-11 00:13:5489
jbudoricka583ba32015-09-11 17:23:1990 blacklist = (device_blacklist.Blacklist(args.blacklist_file)
91 if args.blacklist_file
92 else None)
jbudorickdde688fb2015-08-27 03:00:1793
94 devices = device_utils.DeviceUtils.HealthyDevices(blacklist)
mikecase06ef7202015-05-23 02:30:0695 if not devices:
96 raise device_errors.NoDevicesError()
jbudorick119e4572015-04-24 17:20:0397 device = devices[0]
jbudorick58b4d362015-09-08 16:44:5998 logging.info('Using device %s for testing.', str(device))
[email protected]3de785b42013-01-11 00:13:5499
mikecase06ef7202015-05-23 02:30:06100 package_name = (args.package_name if args.package_name
101 else apk_helper.GetPackageName(args.old_apk))
mikecase798b3dc2015-05-06 18:32:07102 if args.command == 'create_app_data':
mikecase06ef7202015-05-23 02:30:06103 CreateAppData(device, args.old_apk, args.app_data, package_name)
mikecase798b3dc2015-05-06 18:32:07104 elif args.command == 'test_update':
mikecase06ef7202015-05-23 02:30:06105 TestUpdate(
106 device, args.old_apk, args.new_apk, args.app_data, package_name)
[email protected]3de785b42013-01-11 00:13:54107 else:
mikecase798b3dc2015-05-06 18:32:07108 raise Exception('Unknown test command: %s' % args.command)
[email protected]3de785b42013-01-11 00:13:54109
110if __name__ == '__main__':
mikecase798b3dc2015-05-06 18:32:07111 sys.exit(main())