blob: 06cd2d695422ea53827d32edb174d6a69d3b361d [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 os
[email protected]3de785b42013-01-11 00:13:5430import sys
31import time
32
mikecase798b3dc2015-05-06 18:32:0733from pylib import constants
mikecase06ef7202015-05-23 02:30:0634from pylib.device import device_errors
[email protected]044d79b2014-04-10 19:37:3035from pylib.device import device_utils
mikecase798b3dc2015-05-06 18:32:0736from pylib.utils import apk_helper
37from pylib.utils import run_tests_helper
[email protected]3de785b42013-01-11 00:13:5438
mikecase06ef7202015-05-23 02:30:0639def CreateAppData(device, old_apk, app_data, package_name):
mikecase798b3dc2015-05-06 18:32:0740 device.Install(old_apk)
[email protected]3de785b42013-01-11 00:13:5441 raw_input('Set the application state. Once ready, press enter and '
42 'select "Backup my data" on the device.')
mikecase798b3dc2015-05-06 18:32:0743 device.adb.Backup(app_data, packages=[package_name])
44 logging.critical('Application data saved to %s' % app_data)
[email protected]3de785b42013-01-11 00:13:5445
mikecase06ef7202015-05-23 02:30:0646def TestUpdate(device, old_apk, new_apk, app_data, package_name):
mikecase798b3dc2015-05-06 18:32:0747 device.Install(old_apk)
48 device.adb.Restore(app_data)
49 # Restore command is not synchronous
50 raw_input('Select "Restore my data" on the device. Then press enter to '
51 'continue.')
mikecase798b3dc2015-05-06 18:32:0752 device_path = device.GetApplicationPath(package_name)
53 if not device_path:
54 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.')
67 command_parsers = parser.add_subparsers(dest='command')
[email protected]3de785b42013-01-11 00:13:5468
mikecase798b3dc2015-05-06 18:32:0769 subparser = command_parsers.add_parser('create_app_data')
70 subparser.add_argument('--old-apk', required=True,
mikecase06ef7202015-05-23 02:30:0671 help='Path to apk to update from.')
mikecase798b3dc2015-05-06 18:32:0772 subparser.add_argument('--app-data', required=True,
mikecase06ef7202015-05-23 02:30:0673 help='Path to where the app data backup should be '
mikecase798b3dc2015-05-06 18:32:0774 'saved to.')
mikecase06ef7202015-05-23 02:30:0675 subparser.add_argument('--package-name',
76 help='Chrome apk package name.')
mikecase798b3dc2015-05-06 18:32:0777
78 subparser = command_parsers.add_parser('test_update')
79 subparser.add_argument('--old-apk', required=True,
mikecase06ef7202015-05-23 02:30:0680 help='Path to apk to update from.')
mikecase798b3dc2015-05-06 18:32:0781 subparser.add_argument('--new-apk', required=True,
mikecase06ef7202015-05-23 02:30:0682 help='Path to apk to update to.')
mikecase798b3dc2015-05-06 18:32:0783 subparser.add_argument('--app-data', required=True,
mikecase06ef7202015-05-23 02:30:0684 help='Path to where the app data backup is saved.')
85 subparser.add_argument('--package-name',
86 help='Chrome apk package name.')
mikecase798b3dc2015-05-06 18:32:0787
88 args = parser.parse_args()
89 run_tests_helper.SetLogLevel(args.verbose)
[email protected]3de785b42013-01-11 00:13:5490
jbudorick119e4572015-04-24 17:20:0391 devices = device_utils.DeviceUtils.HealthyDevices()
mikecase06ef7202015-05-23 02:30:0692 if not devices:
93 raise device_errors.NoDevicesError()
jbudorick119e4572015-04-24 17:20:0394 device = devices[0]
mikecase798b3dc2015-05-06 18:32:0795 logging.info('Using device %s for testing.' % str(device))
[email protected]3de785b42013-01-11 00:13:5496
mikecase06ef7202015-05-23 02:30:0697 package_name = (args.package_name if args.package_name
98 else apk_helper.GetPackageName(args.old_apk))
mikecase798b3dc2015-05-06 18:32:0799 if args.command == 'create_app_data':
mikecase06ef7202015-05-23 02:30:06100 CreateAppData(device, args.old_apk, args.app_data, package_name)
mikecase798b3dc2015-05-06 18:32:07101 elif args.command == 'test_update':
mikecase06ef7202015-05-23 02:30:06102 TestUpdate(
103 device, args.old_apk, args.new_apk, args.app_data, package_name)
[email protected]3de785b42013-01-11 00:13:54104 else:
mikecase798b3dc2015-05-06 18:32:07105 raise Exception('Unknown test command: %s' % args.command)
[email protected]3de785b42013-01-11 00:13:54106
107if __name__ == '__main__':
mikecase798b3dc2015-05-06 18:32:07108 sys.exit(main())