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 import logging | 8 import logging |
9 import optparse | 9 import optparse |
10 import os | 10 import os |
(...skipping 11 matching lines...) Expand all Loading... |
22 assert os.path.exists(backup_file), 'Backup failed.' | 22 assert os.path.exists(backup_file), 'Backup failed.' |
23 if data_dir: | 23 if data_dir: |
24 if not os.path.isdir(data_dir): | 24 if not os.path.isdir(data_dir): |
25 os.makedirs(data_dir) | 25 os.makedirs(data_dir) |
26 shutil.move(backup_file, data_dir) | 26 shutil.move(backup_file, data_dir) |
27 backup_file = os.path.join(data_dir, 'backup.ab') | 27 backup_file = os.path.join(data_dir, 'backup.ab') |
28 print 'Application data saved to %s' % backup_file | 28 print 'Application data saved to %s' % backup_file |
29 | 29 |
30 if from_apk: | 30 if from_apk: |
31 logging.info('Installing %s...', from_apk) | 31 logging.info('Installing %s...', from_apk) |
| 32 # TODO(jbudorick) Switch to AdbWrapper.Install on the impl switch. |
32 output = device.old_interface.Install(from_apk, reinstall=True) | 33 output = device.old_interface.Install(from_apk, reinstall=True) |
33 if 'Success' not in output: | 34 if 'Success' not in output: |
34 raise Exception('Unable to install %s. output: %s' % (from_apk, output)) | 35 raise Exception('Unable to install %s. output: %s' % (from_apk, output)) |
35 | 36 |
36 raw_input('Set the application state. Once ready, press enter and ' | 37 raw_input('Set the application state. Once ready, press enter and ' |
37 'select "Backup my data" on the device.') | 38 'select "Backup my data" on the device.') |
38 _BackupAppData(data_dir) | 39 _BackupAppData(data_dir) |
39 | 40 |
40 | 41 |
41 def _VerifyAppUpdate(device, to_apk, app_data, from_apk=None): | 42 def _VerifyAppUpdate(device, to_apk, app_data, from_apk=None): |
42 def _RestoreAppData(): | 43 def _RestoreAppData(): |
43 assert os.path.exists(app_data), 'Backup file does not exist!' | 44 assert os.path.exists(app_data), 'Backup file does not exist!' |
44 device.old_interface.Adb().SendCommand('restore %s' % app_data) | 45 device.old_interface.Adb().SendCommand('restore %s' % app_data) |
45 # It seems restore command is not synchronous. | 46 # It seems restore command is not synchronous. |
46 time.sleep(15) | 47 time.sleep(15) |
47 | 48 |
48 if from_apk: | 49 if from_apk: |
49 logging.info('Installing %s...', from_apk) | 50 logging.info('Installing %s...', from_apk) |
| 51 # TODO(jbudorick) Switch to AdbWrapper.Install on the impl switch. |
50 output = device.old_interface.Install(from_apk, reinstall=True) | 52 output = device.old_interface.Install(from_apk, reinstall=True) |
51 if 'Success' not in output: | 53 if 'Success' not in output: |
52 raise Exception('Unable to install %s. output: %s' % (from_apk, output)) | 54 raise Exception('Unable to install %s. output: %s' % (from_apk, output)) |
53 | 55 |
54 logging.info('Restoring the application data...') | 56 logging.info('Restoring the application data...') |
55 raw_input('Press enter and select "Restore my data" on the device.') | 57 raw_input('Press enter and select "Restore my data" on the device.') |
56 _RestoreAppData() | 58 _RestoreAppData() |
57 | 59 |
58 logging.info('Verifying that %s cannot be installed side-by-side...', | 60 logging.info('Verifying that %s cannot be installed side-by-side...', |
59 to_apk) | 61 to_apk) |
| 62 # TODO(jbudorick) Switch to AdbWrapper.Install on the impl switch. |
60 output = device.old_interface.Install(to_apk) | 63 output = device.old_interface.Install(to_apk) |
61 if 'INSTALL_FAILED_ALREADY_EXISTS' not in output: | 64 if 'INSTALL_FAILED_ALREADY_EXISTS' not in output: |
62 if 'Success' in output: | 65 if 'Success' in output: |
63 raise Exception('Package name has changed! output: %s' % output) | 66 raise Exception('Package name has changed! output: %s' % output) |
64 else: | 67 else: |
65 raise Exception(output) | 68 raise Exception(output) |
66 | 69 |
67 logging.info('Verifying that %s can be overinstalled...', to_apk) | 70 logging.info('Verifying that %s can be overinstalled...', to_apk) |
| 71 # TODO(jbudorick) Switch to AdbWrapper.Install on the impl switch. |
68 output = device.old_interface.Install(to_apk, reinstall=True) | 72 output = device.old_interface.Install(to_apk, reinstall=True) |
69 if 'Success' not in output: | 73 if 'Success' not in output: |
70 raise Exception('Unable to install %s.\n output: %s' % (to_apk, output)) | 74 raise Exception('Unable to install %s.\n output: %s' % (to_apk, output)) |
71 logging.info('Successfully updated to the new apk. Please verify that the ' | 75 logging.info('Successfully updated to the new apk. Please verify that the ' |
72 'the application data is preserved.') | 76 'the application data is preserved.') |
73 | 77 |
74 | 78 |
75 def main(): | 79 def main(): |
76 logger = logging.getLogger() | 80 logger = logging.getLogger() |
77 logger.setLevel(logging.DEBUG) | 81 logger.setLevel(logging.DEBUG) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 parser.print_help(sys.stderr) | 131 parser.print_help(sys.stderr) |
128 parser.error('Missing --to-apk or --app-data.') | 132 parser.error('Missing --to-apk or --app-data.') |
129 assert os.path.isfile(options.to_apk) | 133 assert os.path.isfile(options.to_apk) |
130 assert os.path.isfile(options.app_data) | 134 assert os.path.isfile(options.app_data) |
131 _VerifyAppUpdate(device, options.to_apk, options.app_data, | 135 _VerifyAppUpdate(device, options.to_apk, options.app_data, |
132 from_apk=options.from_apk) | 136 from_apk=options.from_apk) |
133 | 137 |
134 | 138 |
135 if __name__ == '__main__': | 139 if __name__ == '__main__': |
136 main() | 140 main() |
OLD | NEW |