blob: b6e34e68a2b7508aeddb7be140aea73ff5c3d3a5 [file] [log] [blame]
Peter Wenb51e4542021-06-30 17:42:571#!/usr/bin/env vpython3
[email protected]3de785b42013-01-11 00:13:542#
Avi Drissman73a09d12022-09-08 20:33:383# Copyright 2013 The Chromium Authors
[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
jbudorickd28554a2016-01-11 16:22:5931import devil_chromium
32
jbudorick061629442015-09-03 18:00:5733from devil.android import apk_helper
John Budorick8b57e602020-09-01 16:57:5034from devil.android import device_denylist
jbudorick061629442015-09-03 18:00:5735from devil.android import device_errors
36from devil.android import device_utils
37from devil.utils import run_tests_helper
[email protected]3de785b42013-01-11 00:13:5438
Peter Wenb51e4542021-06-30 17:42:5739
mikecase06ef7202015-05-23 02:30:0640def CreateAppData(device, old_apk, app_data, package_name):
mikecase798b3dc2015-05-06 18:32:0741 device.Install(old_apk)
Ben Joyced7822952021-08-17 17:19:0342 input('Set the application state. Once ready, press enter and '
43 'select "Backup my data" on the device.')
mikecase798b3dc2015-05-06 18:32:0744 device.adb.Backup(app_data, packages=[package_name])
jbudorick58b4d362015-09-08 16:44:5945 logging.critical('Application data saved to %s', app_data)
[email protected]3de785b42013-01-11 00:13:5446
mikecase06ef7202015-05-23 02:30:0647def TestUpdate(device, old_apk, new_apk, app_data, package_name):
mikecase798b3dc2015-05-06 18:32:0748 device.Install(old_apk)
49 device.adb.Restore(app_data)
50 # Restore command is not synchronous
Ben Joyced7822952021-08-17 17:19:0351 input('Select "Restore my data" on the device. Then press enter to '
52 'continue.')
Nate Fischerd681a002019-09-17 16:42:0953 if not device.IsApplicationInstalled(package_name):
mikecase798b3dc2015-05-06 18:32:0754 raise Exception('Expected package %s to already be installed. '
55 'Package name might have changed!' % package_name)
[email protected]3de785b42013-01-11 00:13:5456
mikecase798b3dc2015-05-06 18:32:0757 logging.info('Verifying that %s can be overinstalled.', new_apk)
58 device.adb.Install(new_apk, reinstall=True)
59 logging.critical('Successfully updated to the new apk. Please verify that '
60 'the application data is preserved.')
[email protected]3de785b42013-01-11 00:13:5461
62def main():
mikecase798b3dc2015-05-06 18:32:0763 parser = argparse.ArgumentParser(
64 description="Script to do semi-automated upgrade testing.")
65 parser.add_argument('-v', '--verbose', action='count',
66 help='Print verbose log information.')
John Budorick8b57e602020-09-01 16:57:5067 parser.add_argument('--denylist-file', help='Device denylist JSON file.')
mikecase798b3dc2015-05-06 18:32:0768 command_parsers = parser.add_subparsers(dest='command')
[email protected]3de785b42013-01-11 00:13:5469
mikecase798b3dc2015-05-06 18:32:0770 subparser = command_parsers.add_parser('create_app_data')
71 subparser.add_argument('--old-apk', required=True,
mikecase06ef7202015-05-23 02:30:0672 help='Path to apk to update from.')
mikecase798b3dc2015-05-06 18:32:0773 subparser.add_argument('--app-data', required=True,
mikecase06ef7202015-05-23 02:30:0674 help='Path to where the app data backup should be '
mikecase798b3dc2015-05-06 18:32:0775 'saved to.')
mikecase06ef7202015-05-23 02:30:0676 subparser.add_argument('--package-name',
77 help='Chrome apk package name.')
mikecase798b3dc2015-05-06 18:32:0778
79 subparser = command_parsers.add_parser('test_update')
80 subparser.add_argument('--old-apk', required=True,
mikecase06ef7202015-05-23 02:30:0681 help='Path to apk to update from.')
mikecase798b3dc2015-05-06 18:32:0782 subparser.add_argument('--new-apk', required=True,
mikecase06ef7202015-05-23 02:30:0683 help='Path to apk to update to.')
mikecase798b3dc2015-05-06 18:32:0784 subparser.add_argument('--app-data', required=True,
mikecase06ef7202015-05-23 02:30:0685 help='Path to where the app data backup is saved.')
86 subparser.add_argument('--package-name',
87 help='Chrome apk package name.')
mikecase798b3dc2015-05-06 18:32:0788
89 args = parser.parse_args()
90 run_tests_helper.SetLogLevel(args.verbose)
[email protected]3de785b42013-01-11 00:13:5491
jbudorickd28554a2016-01-11 16:22:5992 devil_chromium.Initialize()
93
John Budorick8b57e602020-09-01 16:57:5094 denylist = (device_denylist.Denylist(args.denylist_file)
95 if args.denylist_file else None)
jbudorickdde688fb2015-08-27 03:00:1796
John Budorick8b57e602020-09-01 16:57:5097 devices = device_utils.DeviceUtils.HealthyDevices(denylist)
mikecase06ef7202015-05-23 02:30:0698 if not devices:
99 raise device_errors.NoDevicesError()
jbudorick119e4572015-04-24 17:20:03100 device = devices[0]
jbudorick58b4d362015-09-08 16:44:59101 logging.info('Using device %s for testing.', str(device))
[email protected]3de785b42013-01-11 00:13:54102
mikecase06ef7202015-05-23 02:30:06103 package_name = (args.package_name if args.package_name
104 else apk_helper.GetPackageName(args.old_apk))
mikecase798b3dc2015-05-06 18:32:07105 if args.command == 'create_app_data':
mikecase06ef7202015-05-23 02:30:06106 CreateAppData(device, args.old_apk, args.app_data, package_name)
mikecase798b3dc2015-05-06 18:32:07107 elif args.command == 'test_update':
mikecase06ef7202015-05-23 02:30:06108 TestUpdate(
109 device, args.old_apk, args.new_apk, args.app_data, package_name)
[email protected]3de785b42013-01-11 00:13:54110 else:
mikecase798b3dc2015-05-06 18:32:07111 raise Exception('Unknown test command: %s' % args.command)
[email protected]3de785b42013-01-11 00:13:54112
113if __name__ == '__main__':
mikecase798b3dc2015-05-06 18:32:07114 sys.exit(main())