Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1352)

Unified Diff: build/android/run_update_verification.py

Issue 11672004: [Android] Add a tool for application update verification. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/run_update_verification.py
diff --git a/build/android/run_update_verification.py b/build/android/run_update_verification.py
new file mode 100755
index 0000000000000000000000000000000000000000..0c11d449f62cd68276aea0bbd497b0a358fd7607
--- /dev/null
+++ b/build/android/run_update_verification.py
@@ -0,0 +1,125 @@
+#!/usr/bin/env python
+#
+# Copyright (c) 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Runs semi-automated update testing on a non-rooted device."""
+import logging
+import optparse
+import os
+import sys
+import time
+
+from pylib import android_commands
+
+
+def _SaveAppData(adb, package_name, from_apk):
+ def _BackupAppData():
+ adb.Adb().SendCommand('backup %s' % package_name)
+ backup_file = os.path.join(os.getcwd(), 'backup.ab')
+ assert os.path.exists(backup_file), 'Backup failed.'
+ print 'Application data saved to %s' % backup_file
+
+ logging.info('Installing %s...', from_apk)
klundberg 2013/01/02 17:23:41 Seems like it should be possible to call _SaveAppD
frankf 2013/01/10 23:15:05 I made from_apk optional for both modes. On 2013/
+ output = adb.Install(from_apk, reinstall=True)
+ if 'Success' not in output:
+ raise Exception('Unable to install %s. output: %s' % (from_apk, output))
+
+ raw_input('Set the application sate. Once ready, press enter and '
klundberg 2013/01/02 17:23:41 sate/state
frankf 2013/01/10 23:15:05 Done.
+ 'select "Backup my data" on the device.')
+ _BackupAppData()
+
+
+def _VerifyAppUpdate(adb, from_apk, to_apk, app_data):
+ def _RestoreAppData():
+ assert os.path.exists(app_data), 'Backup file doesn not exist!'
klundberg 2013/01/02 17:23:41 doesn not/does not
frankf 2013/01/10 23:15:05 Done.
+ adb.Adb().SendCommand('restore %s' % app_data)
+ # It seems restore command is not synchronous.
+ time.sleep(15)
+
+ logging.info('Installing %s...', from_apk)
+ output = adb.Install(from_apk, reinstall=True)
+ if 'Success' not in output:
+ raise Exception('Unable to install %s. output: %s' % (from_apk, output))
+
+ logging.info('Restoring the application data...')
+ raw_input('Press enter and select "Restore my data" on the device.')
+ _RestoreAppData()
+
+ logging.info('Verifying that %s cannot be installed side-by-side...',
+ to_apk)
+ output = adb.Install(to_apk)
+ if 'INSTALL_FAILED_ALREADY_EXISTS' not in output:
+ if 'Success' in output:
+ raise Exception('Package name has changed! output: %s' % output)
+ else:
+ raise Exception(output)
+
+ logging.info('Verifying that %s can replace %s...', from_apk, to_apk)
+ output = adb.Install(to_apk, reinstall=True)
+ if 'Success' not in output:
+ raise Exception('Unable to install %s. Maybe the sign key has changed?'
+ 'output: %s' % (to_apk, output))
+ logging.info('Successfully updated to the new apk. Please verify that the '
+ 'the application data is preserved.')
+
+
+def main():
+ logger = logging.getLogger()
+ logger.setLevel(logging.DEBUG)
+ desc = (
+ 'Performs semi-automated application update verification testing. '
+ 'When given --save, it takes a snapshot of the application data '
+ 'on the device. (A dialog on the device will prompt the user to grant '
+ 'permission to backup the data.) Otherwise, it performs the update '
+ 'testing as follows: '
+ '1. Installs the |from-apk|. '
+ '2. Restores the previously stored snapshot of application data '
+ 'given by |app-data|. '
+ '(A dialog on the device will prompt the user to grant permission to '
+ 'restore the data.) '
+ '3. Verifies that |to-apk| cannot be installed side-by-side. '
+ '4. Verifying that |to-apk| can replace |from-apk|.')
+ parser = optparse.OptionParser(description=desc)
+ parser.add_option('--package-name', help='Package name for the application.')
+ parser.add_option('--save', action='store_true',
+ help=('Save a snapshot of application data. '
+ 'This will be saved as backup.db in the '
+ 'current directory.'))
klundberg 2013/01/02 17:23:41 How about making it possible to specify the file w
frankf 2013/01/10 23:15:05 Done.
+ parser.add_option('--from-apk', help='APK to update from.')
+ parser.add_option('--to-apk', help='APK to update to.')
+ parser.add_option('--app-data',
+ help=('Path to the previously stored '
+ 'application data'))
+ (options, args) = parser.parse_args()
+
+ if args:
+ parser.print_help(sys.stderr)
+ parser.error('Unknown arguments: %s.' % args)
+
+ if len(android_commands.GetAttachedDevices()) != 1:
+ parser.error('Exactly 1 device must be attached.')
+ adb = android_commands.AndroidCommands()
+
+ if not options.from_apk:
+ parser.print_help(sys.stderr)
+ parser.error('Missing --from-apk.')
+
+ if options.save:
+ if not options.package_name:
+ parser.print_help(sys.stderr)
+ parser.error('Missing --package-name.')
+ _SaveAppData(adb, options.package_name, options.from_apk)
+ else:
+ if not options.to_apk or not options.app_data:
+ parser.print_help(sys.stderr)
+ parser.error('Missing --to-apk or --app-data.')
+ assert os.path.exists(options.from_apk)
craigdh 2013/01/02 18:26:20 os.path.isfile instead?
frankf 2013/01/10 23:15:05 Done.
+ assert os.path.exists(options.to_apk)
+ assert os.path.exists(options.app_data)
+ _VerifyAppUpdate(adb, options.from_apk, options.to_apk, options.app_data)
+
+
+if __name__ == '__main__':
+ main()
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698