Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import collections | 5 import collections |
| 6 import copy | 6 import copy |
| 7 import json | |
| 7 import logging | 8 import logging |
| 8 import os | 9 import os |
| 9 import pickle | 10 import pickle |
| 10 import re | 11 import re |
| 11 | 12 |
| 12 from devil.android import apk_helper | 13 from devil.android import apk_helper |
| 13 from devil.android import md5sum | 14 from devil.android import md5sum |
| 14 from pylib import constants | 15 from pylib import constants |
| 15 from pylib.base import base_test_result | 16 from pylib.base import base_test_result |
| 16 from pylib.base import test_exception | 17 from pylib.base import test_exception |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 493 | 494 |
| 494 self._coverage_directory = None | 495 self._coverage_directory = None |
| 495 self._initializeTestCoverageAttributes(args) | 496 self._initializeTestCoverageAttributes(args) |
| 496 | 497 |
| 497 self._store_tombstones = False | 498 self._store_tombstones = False |
| 498 self._initializeTombstonesAttributes(args) | 499 self._initializeTombstonesAttributes(args) |
| 499 | 500 |
| 500 self._should_save_logcat = None | 501 self._should_save_logcat = None |
| 501 self._initializeLogAttributes(args) | 502 self._initializeLogAttributes(args) |
| 502 | 503 |
| 504 self._edit_shared_prefs = [] | |
| 505 self._initializeEditPrefsAttributes(args) | |
| 506 | |
| 503 def _initializeApkAttributes(self, args, error_func): | 507 def _initializeApkAttributes(self, args, error_func): |
| 504 if args.apk_under_test: | 508 if args.apk_under_test: |
| 505 apk_under_test_path = args.apk_under_test | 509 apk_under_test_path = args.apk_under_test |
| 506 if not args.apk_under_test.endswith('.apk'): | 510 if not args.apk_under_test.endswith('.apk'): |
| 507 apk_under_test_path = os.path.join( | 511 apk_under_test_path = os.path.join( |
| 508 constants.GetOutDirectory(), constants.SDK_BUILD_APKS_DIR, | 512 constants.GetOutDirectory(), constants.SDK_BUILD_APKS_DIR, |
| 509 '%s.apk' % args.apk_under_test) | 513 '%s.apk' % args.apk_under_test) |
| 510 | 514 |
| 511 # TODO(jbudorick): Move the realpath up to the argument parser once | 515 # TODO(jbudorick): Move the realpath up to the argument parser once |
| 512 # APK-by-name is no longer supported. | 516 # APK-by-name is no longer supported. |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 668 | 672 |
| 669 def _initializeTestCoverageAttributes(self, args): | 673 def _initializeTestCoverageAttributes(self, args): |
| 670 self._coverage_directory = args.coverage_dir | 674 self._coverage_directory = args.coverage_dir |
| 671 | 675 |
| 672 def _initializeTombstonesAttributes(self, args): | 676 def _initializeTombstonesAttributes(self, args): |
| 673 self._store_tombstones = args.store_tombstones | 677 self._store_tombstones = args.store_tombstones |
| 674 | 678 |
| 675 def _initializeLogAttributes(self, args): | 679 def _initializeLogAttributes(self, args): |
| 676 self._should_save_logcat = bool(args.json_results_file) | 680 self._should_save_logcat = bool(args.json_results_file) |
| 677 | 681 |
| 682 def _initializeEditPrefsAttributes(self, args): | |
| 683 if not hasattr(args, 'shared_prefs_file'): | |
| 684 return | |
| 685 if not isinstance(args.shared_prefs_file, str): | |
| 686 logging.warning("Given non-string for a filepath") | |
| 687 return | |
| 688 | |
| 689 # json.load() loads strings as unicode, which causes issues when trying | |
| 690 # to edit string values in preference files, so convert to Python strings | |
| 691 def unicode_to_str(data): | |
|
jbudorick
2017/02/15 22:38:41
Can we do this with one of the optional arguments
bsheedy
2017/02/16 00:14:39
Yes and no. Setting the encoding argument is only
| |
| 692 if isinstance(data, dict): | |
| 693 return {unicode_to_str(key): unicode_to_str(value) | |
| 694 for key, value in data.iteritems()} | |
| 695 elif isinstance(data, list): | |
| 696 return [unicode_to_str(element) for element in data] | |
| 697 elif isinstance(data, unicode): | |
| 698 return data.encode('utf-8') | |
| 699 return data | |
| 700 | |
| 701 filepath = os.path.abspath(os.path.join( | |
|
jbudorick
2017/02/15 22:38:41
Remove this after the realpath change mentioned in
bsheedy
2017/02/16 18:04:50
Done.
| |
| 702 host_paths.DIR_SOURCE_ROOT, args.shared_prefs_file)) | |
| 703 with open(filepath) as prefs_file: | |
| 704 self._edit_shared_prefs = unicode_to_str(json.load(prefs_file)) | |
| 705 | |
| 678 @property | 706 @property |
| 679 def additional_apks(self): | 707 def additional_apks(self): |
| 680 return self._additional_apks | 708 return self._additional_apks |
| 681 | 709 |
| 682 @property | 710 @property |
| 683 def apk_under_test(self): | 711 def apk_under_test(self): |
| 684 return self._apk_under_test | 712 return self._apk_under_test |
| 685 | 713 |
| 686 @property | 714 @property |
| 687 def apk_under_test_incremental_install_script(self): | 715 def apk_under_test_incremental_install_script(self): |
| 688 return self._apk_under_test_incremental_install_script | 716 return self._apk_under_test_incremental_install_script |
| 689 | 717 |
| 690 @property | 718 @property |
| 691 def coverage_directory(self): | 719 def coverage_directory(self): |
| 692 return self._coverage_directory | 720 return self._coverage_directory |
| 693 | 721 |
| 694 @property | 722 @property |
| 695 def driver_apk(self): | 723 def driver_apk(self): |
| 696 return self._driver_apk | 724 return self._driver_apk |
| 697 | 725 |
| 698 @property | 726 @property |
| 699 def driver_package(self): | 727 def driver_package(self): |
| 700 return self._driver_package | 728 return self._driver_package |
| 701 | 729 |
| 702 @property | 730 @property |
| 703 def driver_name(self): | 731 def driver_name(self): |
| 704 return self._driver_name | 732 return self._driver_name |
| 705 | 733 |
| 706 @property | 734 @property |
| 735 def edit_shared_prefs(self): | |
| 736 return self._edit_shared_prefs | |
| 737 | |
| 738 @property | |
| 707 def flags(self): | 739 def flags(self): |
| 708 return self._flags | 740 return self._flags |
| 709 | 741 |
| 710 @property | 742 @property |
| 711 def should_save_logcat(self): | 743 def should_save_logcat(self): |
| 712 return self._should_save_logcat | 744 return self._should_save_logcat |
| 713 | 745 |
| 714 @property | 746 @property |
| 715 def package_info(self): | 747 def package_info(self): |
| 716 return self._package_info | 748 return self._package_info |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 839 | 871 |
| 840 @staticmethod | 872 @staticmethod |
| 841 def GenerateTestResults( | 873 def GenerateTestResults( |
| 842 result_code, result_bundle, statuses, start_ms, duration_ms): | 874 result_code, result_bundle, statuses, start_ms, duration_ms): |
| 843 return GenerateTestResults(result_code, result_bundle, statuses, | 875 return GenerateTestResults(result_code, result_bundle, statuses, |
| 844 start_ms, duration_ms) | 876 start_ms, duration_ms) |
| 845 | 877 |
| 846 #override | 878 #override |
| 847 def TearDown(self): | 879 def TearDown(self): |
| 848 pass | 880 pass |
| OLD | NEW |