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
5 # found in the LICENSE file.
7 """Runs semi-automated update testing on a non-rooted device.
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.
12 ./update_verification.py create_app_data --old-apk <path> --app-data <path>
14 The 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.
17 Next, once you have some app data saved, run this script with the test_update
20 ./update_verification.py test_update --old-apk <path> --new-apk <path>
23 This will install the old apk, load the saved app data, install the new apk,
24 and ask the user to verify that all of the app data was preserved.
33 from pylib
import constants
34 from pylib
.device
import device_blacklist
35 from pylib
.device
import device_errors
36 from pylib
.device
import device_utils
37 from pylib
.utils
import apk_helper
38 from pylib
.utils
import run_tests_helper
40 def CreateAppData(device
, old_apk
, app_data
, package_name
):
41 device
.Install(old_apk
)
42 raw_input('Set the application state. Once ready, press enter and '
43 'select "Backup my data" on the device.')
44 device
.adb
.Backup(app_data
, packages
=[package_name
])
45 logging
.critical('Application data saved to %s' % app_data
)
47 def TestUpdate(device
, old_apk
, new_apk
, app_data
, package_name
):
48 device
.Install(old_apk
)
49 device
.adb
.Restore(app_data
)
50 # Restore command is not synchronous
51 raw_input('Select "Restore my data" on the device. Then press enter to '
53 device_path
= device
.GetApplicationPaths(package_name
)
55 raise Exception('Expected package %s to already be installed. '
56 'Package name might have changed!' % package_name
)
58 logging
.info('Verifying that %s can be overinstalled.', new_apk
)
59 device
.adb
.Install(new_apk
, reinstall
=True)
60 logging
.critical('Successfully updated to the new apk. Please verify that '
61 'the application data is preserved.')
64 parser
= argparse
.ArgumentParser(
65 description
="Script to do semi-automated upgrade testing.")
66 parser
.add_argument('-v', '--verbose', action
='count',
67 help='Print verbose log information.')
68 parser
.add_argument('--blacklist-file', help='Device blacklist JSON file.')
69 command_parsers
= parser
.add_subparsers(dest
='command')
71 subparser
= command_parsers
.add_parser('create_app_data')
72 subparser
.add_argument('--old-apk', required
=True,
73 help='Path to apk to update from.')
74 subparser
.add_argument('--app-data', required
=True,
75 help='Path to where the app data backup should be '
77 subparser
.add_argument('--package-name',
78 help='Chrome apk package name.')
80 subparser
= command_parsers
.add_parser('test_update')
81 subparser
.add_argument('--old-apk', required
=True,
82 help='Path to apk to update from.')
83 subparser
.add_argument('--new-apk', required
=True,
84 help='Path to apk to update to.')
85 subparser
.add_argument('--app-data', required
=True,
86 help='Path to where the app data backup is saved.')
87 subparser
.add_argument('--package-name',
88 help='Chrome apk package name.')
90 args
= parser
.parse_args()
91 run_tests_helper
.SetLogLevel(args
.verbose
)
93 if args
.blacklist_file
:
94 blacklist
= device_blacklist
.Blacklist(args
.blacklist_file
)
98 devices
= device_utils
.DeviceUtils
.HealthyDevices(blacklist
)
100 raise device_errors
.NoDevicesError()
102 logging
.info('Using device %s for testing.' % str(device
))
104 package_name
= (args
.package_name
if args
.package_name
105 else apk_helper
.GetPackageName(args
.old_apk
))
106 if args
.command
== 'create_app_data':
107 CreateAppData(device
, args
.old_apk
, args
.app_data
, package_name
)
108 elif args
.command
== 'test_update':
110 device
, args
.old_apk
, args
.new_apk
, args
.app_data
, package_name
)
112 raise Exception('Unknown test command: %s' % args
.command
)
114 if __name__
== '__main__':